@animagram/state-engine 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @animagram/state-engine
2
+
3
+ > ⚠️ This package is currently under development. API may change.
4
+
5
+ WASM binding for [state-engine](https://github.com/animagram-jp/state-engine).
@@ -0,0 +1,51 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class StateEngine {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ delete(key: string): boolean;
8
+ exists(key: string): boolean;
9
+ get(key: string): any;
10
+ constructor(manifest_dir: string, files: object);
11
+ set(key: string, value: string, ttl?: number | null): boolean;
12
+ }
13
+
14
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
15
+
16
+ export interface InitOutput {
17
+ readonly memory: WebAssembly.Memory;
18
+ readonly __wbg_stateengine_free: (a: number, b: number) => void;
19
+ readonly stateengine_delete: (a: number, b: number, c: number) => [number, number, number];
20
+ readonly stateengine_exists: (a: number, b: number, c: number) => [number, number, number];
21
+ readonly stateengine_get: (a: number, b: number, c: number) => [number, number, number];
22
+ readonly stateengine_new: (a: number, b: number, c: any) => number;
23
+ readonly stateengine_set: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
24
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
25
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
26
+ readonly __wbindgen_externrefs: WebAssembly.Table;
27
+ readonly __externref_table_dealloc: (a: number) => void;
28
+ readonly __wbindgen_start: () => void;
29
+ }
30
+
31
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
32
+
33
+ /**
34
+ * Instantiates the given `module`, which can either be bytes or
35
+ * a precompiled `WebAssembly.Module`.
36
+ *
37
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
38
+ *
39
+ * @returns {InitOutput}
40
+ */
41
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
42
+
43
+ /**
44
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
45
+ * for everything else, calls `WebAssembly.instantiate` directly.
46
+ *
47
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
48
+ *
49
+ * @returns {Promise<InitOutput>}
50
+ */
51
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/js_binding.js ADDED
@@ -0,0 +1,332 @@
1
+ /* @ts-self-types="./js_binding.d.ts" */
2
+
3
+ export class StateEngine {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ StateEngineFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_stateengine_free(ptr, 0);
13
+ }
14
+ /**
15
+ * @param {string} key
16
+ * @returns {boolean}
17
+ */
18
+ delete(key) {
19
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
20
+ const len0 = WASM_VECTOR_LEN;
21
+ const ret = wasm.stateengine_delete(this.__wbg_ptr, ptr0, len0);
22
+ if (ret[2]) {
23
+ throw takeFromExternrefTable0(ret[1]);
24
+ }
25
+ return ret[0] !== 0;
26
+ }
27
+ /**
28
+ * @param {string} key
29
+ * @returns {boolean}
30
+ */
31
+ exists(key) {
32
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
33
+ const len0 = WASM_VECTOR_LEN;
34
+ const ret = wasm.stateengine_exists(this.__wbg_ptr, ptr0, len0);
35
+ if (ret[2]) {
36
+ throw takeFromExternrefTable0(ret[1]);
37
+ }
38
+ return ret[0] !== 0;
39
+ }
40
+ /**
41
+ * @param {string} key
42
+ * @returns {any}
43
+ */
44
+ get(key) {
45
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ const ret = wasm.stateengine_get(this.__wbg_ptr, ptr0, len0);
48
+ if (ret[2]) {
49
+ throw takeFromExternrefTable0(ret[1]);
50
+ }
51
+ return takeFromExternrefTable0(ret[0]);
52
+ }
53
+ /**
54
+ * @param {string} manifest_dir
55
+ * @param {object} files
56
+ */
57
+ constructor(manifest_dir, files) {
58
+ const ptr0 = passStringToWasm0(manifest_dir, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
59
+ const len0 = WASM_VECTOR_LEN;
60
+ const ret = wasm.stateengine_new(ptr0, len0, files);
61
+ this.__wbg_ptr = ret >>> 0;
62
+ StateEngineFinalization.register(this, this.__wbg_ptr, this);
63
+ return this;
64
+ }
65
+ /**
66
+ * @param {string} key
67
+ * @param {string} value
68
+ * @param {number | null} [ttl]
69
+ * @returns {boolean}
70
+ */
71
+ set(key, value, ttl) {
72
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
73
+ const len0 = WASM_VECTOR_LEN;
74
+ const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
75
+ const len1 = WASM_VECTOR_LEN;
76
+ const ret = wasm.stateengine_set(this.__wbg_ptr, ptr0, len0, ptr1, len1, isLikeNone(ttl) ? 0x100000001 : (ttl) >>> 0);
77
+ if (ret[2]) {
78
+ throw takeFromExternrefTable0(ret[1]);
79
+ }
80
+ return ret[0] !== 0;
81
+ }
82
+ }
83
+ if (Symbol.dispose) StateEngine.prototype[Symbol.dispose] = StateEngine.prototype.free;
84
+
85
+ function __wbg_get_imports() {
86
+ const import0 = {
87
+ __proto__: null,
88
+ __wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
89
+ const obj = arg1;
90
+ const ret = typeof(obj) === 'string' ? obj : undefined;
91
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
92
+ var len1 = WASM_VECTOR_LEN;
93
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
94
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
95
+ },
96
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
97
+ throw new Error(getStringFromWasm0(arg0, arg1));
98
+ },
99
+ __wbg_entries_e8a20ff8c9757101: function(arg0) {
100
+ const ret = Object.entries(arg0);
101
+ return ret;
102
+ },
103
+ __wbg_from_4bdf88943703fd48: function(arg0) {
104
+ const ret = Array.from(arg0);
105
+ return ret;
106
+ },
107
+ __wbg_get_a8ee5c45dabc1b3b: function(arg0, arg1) {
108
+ const ret = arg0[arg1 >>> 0];
109
+ return ret;
110
+ },
111
+ __wbg_get_unchecked_329cfe50afab7352: function(arg0, arg1) {
112
+ const ret = arg0[arg1 >>> 0];
113
+ return ret;
114
+ },
115
+ __wbg_length_b3416cf66a5452c8: function(arg0) {
116
+ const ret = arg0.length;
117
+ return ret;
118
+ },
119
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
120
+ // Cast intrinsic for `Ref(String) -> Externref`.
121
+ const ret = getStringFromWasm0(arg0, arg1);
122
+ return ret;
123
+ },
124
+ __wbindgen_init_externref_table: function() {
125
+ const table = wasm.__wbindgen_externrefs;
126
+ const offset = table.grow(4);
127
+ table.set(0, undefined);
128
+ table.set(offset + 0, undefined);
129
+ table.set(offset + 1, null);
130
+ table.set(offset + 2, true);
131
+ table.set(offset + 3, false);
132
+ },
133
+ };
134
+ return {
135
+ __proto__: null,
136
+ "./js_binding_bg.js": import0,
137
+ };
138
+ }
139
+
140
+ const StateEngineFinalization = (typeof FinalizationRegistry === 'undefined')
141
+ ? { register: () => {}, unregister: () => {} }
142
+ : new FinalizationRegistry(ptr => wasm.__wbg_stateengine_free(ptr >>> 0, 1));
143
+
144
+ let cachedDataViewMemory0 = null;
145
+ function getDataViewMemory0() {
146
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
147
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
148
+ }
149
+ return cachedDataViewMemory0;
150
+ }
151
+
152
+ function getStringFromWasm0(ptr, len) {
153
+ ptr = ptr >>> 0;
154
+ return decodeText(ptr, len);
155
+ }
156
+
157
+ let cachedUint8ArrayMemory0 = null;
158
+ function getUint8ArrayMemory0() {
159
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
160
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
161
+ }
162
+ return cachedUint8ArrayMemory0;
163
+ }
164
+
165
+ function isLikeNone(x) {
166
+ return x === undefined || x === null;
167
+ }
168
+
169
+ function passStringToWasm0(arg, malloc, realloc) {
170
+ if (realloc === undefined) {
171
+ const buf = cachedTextEncoder.encode(arg);
172
+ const ptr = malloc(buf.length, 1) >>> 0;
173
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
174
+ WASM_VECTOR_LEN = buf.length;
175
+ return ptr;
176
+ }
177
+
178
+ let len = arg.length;
179
+ let ptr = malloc(len, 1) >>> 0;
180
+
181
+ const mem = getUint8ArrayMemory0();
182
+
183
+ let offset = 0;
184
+
185
+ for (; offset < len; offset++) {
186
+ const code = arg.charCodeAt(offset);
187
+ if (code > 0x7F) break;
188
+ mem[ptr + offset] = code;
189
+ }
190
+ if (offset !== len) {
191
+ if (offset !== 0) {
192
+ arg = arg.slice(offset);
193
+ }
194
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
195
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
196
+ const ret = cachedTextEncoder.encodeInto(arg, view);
197
+
198
+ offset += ret.written;
199
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
200
+ }
201
+
202
+ WASM_VECTOR_LEN = offset;
203
+ return ptr;
204
+ }
205
+
206
+ function takeFromExternrefTable0(idx) {
207
+ const value = wasm.__wbindgen_externrefs.get(idx);
208
+ wasm.__externref_table_dealloc(idx);
209
+ return value;
210
+ }
211
+
212
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
213
+ cachedTextDecoder.decode();
214
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
215
+ let numBytesDecoded = 0;
216
+ function decodeText(ptr, len) {
217
+ numBytesDecoded += len;
218
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
219
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
220
+ cachedTextDecoder.decode();
221
+ numBytesDecoded = len;
222
+ }
223
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
224
+ }
225
+
226
+ const cachedTextEncoder = new TextEncoder();
227
+
228
+ if (!('encodeInto' in cachedTextEncoder)) {
229
+ cachedTextEncoder.encodeInto = function (arg, view) {
230
+ const buf = cachedTextEncoder.encode(arg);
231
+ view.set(buf);
232
+ return {
233
+ read: arg.length,
234
+ written: buf.length
235
+ };
236
+ };
237
+ }
238
+
239
+ let WASM_VECTOR_LEN = 0;
240
+
241
+ let wasmModule, wasm;
242
+ function __wbg_finalize_init(instance, module) {
243
+ wasm = instance.exports;
244
+ wasmModule = module;
245
+ cachedDataViewMemory0 = null;
246
+ cachedUint8ArrayMemory0 = null;
247
+ wasm.__wbindgen_start();
248
+ return wasm;
249
+ }
250
+
251
+ async function __wbg_load(module, imports) {
252
+ if (typeof Response === 'function' && module instanceof Response) {
253
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
254
+ try {
255
+ return await WebAssembly.instantiateStreaming(module, imports);
256
+ } catch (e) {
257
+ const validResponse = module.ok && expectedResponseType(module.type);
258
+
259
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
260
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
261
+
262
+ } else { throw e; }
263
+ }
264
+ }
265
+
266
+ const bytes = await module.arrayBuffer();
267
+ return await WebAssembly.instantiate(bytes, imports);
268
+ } else {
269
+ const instance = await WebAssembly.instantiate(module, imports);
270
+
271
+ if (instance instanceof WebAssembly.Instance) {
272
+ return { instance, module };
273
+ } else {
274
+ return instance;
275
+ }
276
+ }
277
+
278
+ function expectedResponseType(type) {
279
+ switch (type) {
280
+ case 'basic': case 'cors': case 'default': return true;
281
+ }
282
+ return false;
283
+ }
284
+ }
285
+
286
+ function initSync(module) {
287
+ if (wasm !== undefined) return wasm;
288
+
289
+
290
+ if (module !== undefined) {
291
+ if (Object.getPrototypeOf(module) === Object.prototype) {
292
+ ({module} = module)
293
+ } else {
294
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
295
+ }
296
+ }
297
+
298
+ const imports = __wbg_get_imports();
299
+ if (!(module instanceof WebAssembly.Module)) {
300
+ module = new WebAssembly.Module(module);
301
+ }
302
+ const instance = new WebAssembly.Instance(module, imports);
303
+ return __wbg_finalize_init(instance, module);
304
+ }
305
+
306
+ async function __wbg_init(module_or_path) {
307
+ if (wasm !== undefined) return wasm;
308
+
309
+
310
+ if (module_or_path !== undefined) {
311
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
312
+ ({module_or_path} = module_or_path)
313
+ } else {
314
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
315
+ }
316
+ }
317
+
318
+ if (module_or_path === undefined) {
319
+ module_or_path = new URL('js_binding_bg.wasm', import.meta.url);
320
+ }
321
+ const imports = __wbg_get_imports();
322
+
323
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
324
+ module_or_path = fetch(module_or_path);
325
+ }
326
+
327
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
328
+
329
+ return __wbg_finalize_init(instance, module);
330
+ }
331
+
332
+ export { initSync, __wbg_init as default };
Binary file
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@animagram/state-engine",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Andyou <andyou@animagram.jp>"
6
+ ],
7
+ "description": "Declarative state data management system for process",
8
+ "version": "0.1.0",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/animagram-jp/state-engine"
13
+ },
14
+ "files": [
15
+ "js_binding_bg.wasm",
16
+ "js_binding.js",
17
+ "js_binding.d.ts"
18
+ ],
19
+ "main": "js_binding.js",
20
+ "types": "js_binding.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ]
24
+ }