1use std::result::Result as StdResult;
2
3use crate::Request as EdgeRequest;
4
5use js_sys::JsString;
6use wasm_bindgen::{closure::Closure, prelude::*};
7
8#[wasm_bindgen]
9extern "C" {
10 #[wasm_bindgen (extends = ::js_sys::Object, js_name = DurableObjectId)]
11 pub type JsObjectId;
12
13 #[wasm_bindgen(method, js_class = "JsObjectId", js_name = toString)]
14 pub fn to_string(this: &JsObjectId) -> JsString;
15
16 #[wasm_bindgen (extends = ::js_sys::Object, js_name = DurableObject)]
17 pub type ObjectStub;
18
19 #[wasm_bindgen (extends = ::js_sys::Object, js_name = DurableObjectNamespace)]
20 pub type ObjectNamespace;
21
22 #[wasm_bindgen (extends = ::js_sys::Object, js_name = DurableObjectState)]
23 pub type ObjectState;
24
25 #[wasm_bindgen(method, getter, js_class = "DurableObjectState", js_name = id)]
26 pub fn id_internal(this: &ObjectState) -> JsObjectId;
27
28 #[wasm_bindgen(method, getter, js_class = "DurableObjectState", js_name = storage)]
29 pub fn storage_internal(this: &ObjectState) -> ObjectStorage;
30
31 #[wasm_bindgen (catch, method, js_class = "DurableObjectNamespace", js_name = idFromName)]
32 pub fn id_from_name_internal(
33 this: &ObjectNamespace,
34 name: &str,
35 ) -> StdResult<JsObjectId, JsValue>;
36
37 #[wasm_bindgen (catch, method, js_class = "ObjectNamespace", js_name = idFromString)]
38 pub fn id_from_string_internal(
39 this: &ObjectNamespace,
40 string: &str,
41 ) -> StdResult<JsObjectId, JsValue>;
42
43 #[wasm_bindgen (catch, method, js_class = "DurableObjectNamespace", js_name = newUniqueId)]
44 pub fn new_unique_id_internal(this: &ObjectNamespace) -> StdResult<JsObjectId, JsValue>;
45
46 #[wasm_bindgen (catch, method, js_class = "DurableObjectNamespace", js_name = newUniqueId)]
47 pub fn new_unique_id_with_options_internal(
48 this: &ObjectNamespace,
49 options: &JsValue,
50 ) -> StdResult<JsObjectId, JsValue>;
51
52 #[wasm_bindgen (catch, method, js_class = "DurableObjectNamespace", js_name = get)]
53 pub fn get_internal(this: &ObjectNamespace, id: &JsObjectId) -> StdResult<ObjectStub, JsValue>;
54
55 #[wasm_bindgen (method, js_class = "DurableObject", js_name = fetch)]
56 pub fn fetch_with_request_internal(this: &ObjectStub, req: &EdgeRequest) -> ::js_sys::Promise;
57
58 #[wasm_bindgen (method, js_class = "DurableObject", js_name = fetch)]
59 pub fn fetch_with_str_internal(this: &ObjectStub, url: &str) -> ::js_sys::Promise;
60}
61
62#[wasm_bindgen]
63extern "C" {
64 #[wasm_bindgen (extends = ::js_sys::Object, js_name = DurableObjectStorage)]
65 pub type ObjectStorage;
66
67 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = get)]
68 pub fn get_internal(this: &ObjectStorage, key: &str) -> StdResult<::js_sys::Promise, JsValue>;
69
70 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = get)]
71 pub fn get_multiple_internal(
72 this: &ObjectStorage,
73 keys: Vec<JsValue>,
74 ) -> StdResult<::js_sys::Promise, JsValue>;
75
76 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = put)]
77 pub fn put_internal(
78 this: &ObjectStorage,
79 key: &str,
80 value: JsValue,
81 ) -> StdResult<::js_sys::Promise, JsValue>;
82
83 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = put)]
84 pub fn put_multiple_internal(
85 this: &ObjectStorage,
86 value: JsValue,
87 ) -> StdResult<::js_sys::Promise, JsValue>;
88
89 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = delete)]
90 pub fn delete_internal(
91 this: &ObjectStorage,
92 key: &str,
93 ) -> StdResult<::js_sys::Promise, JsValue>;
94
95 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = delete)]
96 pub fn delete_multiple_internal(
97 this: &ObjectStorage,
98 keys: Vec<JsValue>,
99 ) -> StdResult<::js_sys::Promise, JsValue>;
100
101 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = deleteAll)]
102 pub fn delete_all_internal(this: &ObjectStorage) -> StdResult<::js_sys::Promise, JsValue>;
103
104 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = list)]
105 pub fn list_internal(this: &ObjectStorage) -> StdResult<::js_sys::Promise, JsValue>;
106
107 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = list)]
108 pub fn list_with_options_internal(
109 this: &ObjectStorage,
110 options: ::js_sys::Object,
111 ) -> StdResult<::js_sys::Promise, JsValue>;
112
113 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = transaction)]
114 pub fn transaction_internal(
115 this: &ObjectStorage,
116 closure: &Closure<dyn FnMut(ObjectTransaction)>,
117 ) -> StdResult<::js_sys::Promise, JsValue>;
118
119 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = getAlarm)]
120 pub fn get_alarm_internal(
121 this: &ObjectStorage,
122 options: ::js_sys::Object,
123 ) -> StdResult<::js_sys::Promise, JsValue>;
124
125 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = setAlarm)]
126 pub fn set_alarm_internal(
127 this: &ObjectStorage,
128 scheduled_time: ::js_sys::Date,
129 options: ::js_sys::Object,
130 ) -> StdResult<::js_sys::Promise, JsValue>;
131
132 #[wasm_bindgen(catch, method, js_class = "DurableObjectStorage", js_name = deleteAlarm)]
133 pub fn delete_alarm_internal(
134 this: &ObjectStorage,
135 options: ::js_sys::Object,
136 ) -> StdResult<::js_sys::Promise, JsValue>;
137}
138
139#[wasm_bindgen]
140extern "C" {
141 #[wasm_bindgen(extends = ::js_sys::Object, js_name = DurableObjectTransaction)]
142 pub type ObjectTransaction;
143
144 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = get)]
145 pub fn get_internal(
146 this: &ObjectTransaction,
147 key: &str,
148 ) -> StdResult<::js_sys::Promise, JsValue>;
149
150 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = get)]
151 pub fn get_multiple_internal(
152 this: &ObjectTransaction,
153 keys: Vec<JsValue>,
154 ) -> StdResult<::js_sys::Promise, JsValue>;
155
156 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = put)]
157 pub fn put_internal(
158 this: &ObjectTransaction,
159 key: &str,
160 value: JsValue,
161 ) -> StdResult<::js_sys::Promise, JsValue>;
162
163 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = put)]
164 pub fn put_multiple_internal(
165 this: &ObjectTransaction,
166 value: JsValue,
167 ) -> StdResult<::js_sys::Promise, JsValue>;
168
169 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = delete)]
170 pub fn delete_internal(
171 this: &ObjectTransaction,
172 key: &str,
173 ) -> StdResult<::js_sys::Promise, JsValue>;
174
175 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = delete)]
176 pub fn delete_multiple_internal(
177 this: &ObjectTransaction,
178 keys: Vec<JsValue>,
179 ) -> StdResult<::js_sys::Promise, JsValue>;
180
181 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = deleteAll)]
182 pub fn delete_all_internal(this: &ObjectTransaction) -> StdResult<::js_sys::Promise, JsValue>;
183
184 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = list)]
185 pub fn list_internal(this: &ObjectTransaction) -> StdResult<::js_sys::Promise, JsValue>;
186
187 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = list)]
188 pub fn list_with_options_internal(
189 this: &ObjectTransaction,
190 options: ::js_sys::Object,
191 ) -> StdResult<::js_sys::Promise, JsValue>;
192
193 #[wasm_bindgen(catch, method, js_class = "DurableObjectTransaction", js_name = rollback)]
194 pub fn rollback_internal(this: &ObjectTransaction) -> StdResult<(), JsValue>;
195}