@unyt/datex 0.0.1

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.
Files changed (69) hide show
  1. package/README.md +28 -0
  2. package/esm/_dnt.shims.d.ts +29 -0
  3. package/esm/_dnt.shims.d.ts.map +1 -0
  4. package/esm/_dnt.shims.js +87 -0
  5. package/esm/_dnt.test_shims.d.ts.map +1 -0
  6. package/esm/deno.json +24 -0
  7. package/esm/deps/jsr.io/@std/assert/1.0.6/almost_equals.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@std/assert/1.0.6/array_includes.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@std/assert/1.0.6/assert.d.ts.map +1 -0
  10. package/esm/deps/jsr.io/@std/assert/1.0.6/assertion_error.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/assert/1.0.6/equal.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@std/assert/1.0.6/equals.d.ts.map +1 -0
  13. package/esm/deps/jsr.io/@std/assert/1.0.6/exists.d.ts.map +1 -0
  14. package/esm/deps/jsr.io/@std/assert/1.0.6/fail.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/assert/1.0.6/false.d.ts.map +1 -0
  16. package/esm/deps/jsr.io/@std/assert/1.0.6/greater.d.ts.map +1 -0
  17. package/esm/deps/jsr.io/@std/assert/1.0.6/greater_or_equal.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@std/assert/1.0.6/instance_of.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@std/assert/1.0.6/is_error.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@std/assert/1.0.6/less.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@std/assert/1.0.6/less_or_equal.d.ts.map +1 -0
  22. package/esm/deps/jsr.io/@std/assert/1.0.6/match.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@std/assert/1.0.6/mod.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@std/assert/1.0.6/not_equals.d.ts.map +1 -0
  25. package/esm/deps/jsr.io/@std/assert/1.0.6/not_instance_of.d.ts.map +1 -0
  26. package/esm/deps/jsr.io/@std/assert/1.0.6/not_match.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@std/assert/1.0.6/not_strict_equals.d.ts.map +1 -0
  28. package/esm/deps/jsr.io/@std/assert/1.0.6/object_match.d.ts.map +1 -0
  29. package/esm/deps/jsr.io/@std/assert/1.0.6/rejects.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@std/assert/1.0.6/strict_equals.d.ts.map +1 -0
  31. package/esm/deps/jsr.io/@std/assert/1.0.6/string_includes.d.ts.map +1 -0
  32. package/esm/deps/jsr.io/@std/assert/1.0.6/throws.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@std/assert/1.0.6/unimplemented.d.ts.map +1 -0
  34. package/esm/deps/jsr.io/@std/assert/1.0.6/unreachable.d.ts.map +1 -0
  35. package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
  37. package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
  38. package/esm/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
  40. package/esm/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
  41. package/esm/package.json +3 -0
  42. package/esm/rs-lib/datex-core/Cargo.toml +34 -0
  43. package/esm/src/datex-core/datex_core_js.generated.d.ts +78 -0
  44. package/esm/src/datex-core/datex_core_js.generated.d.ts.map +1 -0
  45. package/esm/src/datex-core/datex_core_js.generated.js +611 -0
  46. package/esm/src/datex-core/datex_core_js_bg.wasm +0 -0
  47. package/esm/src/datex-core.d.ts +2 -0
  48. package/esm/src/datex-core.d.ts.map +1 -0
  49. package/esm/src/datex-core.js +3 -0
  50. package/esm/src/mod.d.ts +11 -0
  51. package/esm/src/mod.d.ts.map +1 -0
  52. package/esm/src/mod.js +10 -0
  53. package/esm/src/runtime/runtime.d.ts +16 -0
  54. package/esm/src/runtime/runtime.d.ts.map +1 -0
  55. package/esm/src/runtime/runtime.js +49 -0
  56. package/esm/src/utils/js-runtime-compat/js-runtime-interface.d.ts +7 -0
  57. package/esm/src/utils/js-runtime-compat/js-runtime-interface.d.ts.map +1 -0
  58. package/esm/src/utils/js-runtime-compat/js-runtime-interface.js +1 -0
  59. package/esm/src/utils/js-runtime-compat/runtime.d.ts +3 -0
  60. package/esm/src/utils/js-runtime-compat/runtime.d.ts.map +1 -0
  61. package/esm/src/utils/js-runtime-compat/runtime.js +34 -0
  62. package/esm/src/utils/js-runtime-compat/runtimes/browser.d.ts +7 -0
  63. package/esm/src/utils/js-runtime-compat/runtimes/browser.d.ts.map +1 -0
  64. package/esm/src/utils/js-runtime-compat/runtimes/browser.js +20 -0
  65. package/esm/src/utils/js-runtime-compat/runtimes/deno.d.ts +7 -0
  66. package/esm/src/utils/js-runtime-compat/runtimes/deno.d.ts.map +1 -0
  67. package/esm/src/utils/js-runtime-compat/runtimes/deno.js +17 -0
  68. package/esm/test/init.test.d.ts.map +1 -0
  69. package/package.json +36 -0
@@ -0,0 +1,611 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _WasmBuildLoader_instances, _WasmBuildLoader_options, _WasmBuildLoader_lastLoadPromise, _WasmBuildLoader_instantiated, _WasmBuildLoader_instantiate;
13
+ // @generated file from wasmbuild -- do not edit
14
+ import * as dntShim from "../../_dnt.shims.js";
15
+ // @ts-nocheck: generated
16
+ // deno-lint-ignore-file
17
+ // deno-fmt-ignore-file
18
+ // source-hash: b6d93fb83902454473c56ac4cba2637a3b7b11a9
19
+ let wasm;
20
+ const heap = new Array(128).fill(undefined);
21
+ heap.push(undefined, null, true, false);
22
+ function getObject(idx) {
23
+ return heap[idx];
24
+ }
25
+ let heap_next = heap.length;
26
+ function dropObject(idx) {
27
+ if (idx < 132)
28
+ return;
29
+ heap[idx] = heap_next;
30
+ heap_next = idx;
31
+ }
32
+ function takeObject(idx) {
33
+ const ret = getObject(idx);
34
+ dropObject(idx);
35
+ return ret;
36
+ }
37
+ const cachedTextDecoder = typeof TextDecoder !== "undefined"
38
+ ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true })
39
+ : {
40
+ decode: () => {
41
+ throw Error("TextDecoder not available");
42
+ },
43
+ };
44
+ if (typeof TextDecoder !== "undefined")
45
+ cachedTextDecoder.decode();
46
+ let cachedUint8Memory0 = null;
47
+ function getUint8Memory0() {
48
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
49
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
50
+ }
51
+ return cachedUint8Memory0;
52
+ }
53
+ function getStringFromWasm0(ptr, len) {
54
+ ptr = ptr >>> 0;
55
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
56
+ }
57
+ function addHeapObject(obj) {
58
+ if (heap_next === heap.length)
59
+ heap.push(heap.length + 1);
60
+ const idx = heap_next;
61
+ heap_next = heap[idx];
62
+ heap[idx] = obj;
63
+ return idx;
64
+ }
65
+ let cachedInt32Memory0 = null;
66
+ function getInt32Memory0() {
67
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
68
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
69
+ }
70
+ return cachedInt32Memory0;
71
+ }
72
+ let cachedUint32Memory0 = null;
73
+ function getUint32Memory0() {
74
+ if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
75
+ cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
76
+ }
77
+ return cachedUint32Memory0;
78
+ }
79
+ function getArrayJsValueFromWasm0(ptr, len) {
80
+ ptr = ptr >>> 0;
81
+ const mem = getUint32Memory0();
82
+ const slice = mem.subarray(ptr / 4, ptr / 4 + len);
83
+ const result = [];
84
+ for (let i = 0; i < slice.length; i++) {
85
+ result.push(takeObject(slice[i]));
86
+ }
87
+ return result;
88
+ }
89
+ /**
90
+ * @returns {JSRuntime}
91
+ */
92
+ export function init_runtime() {
93
+ const ret = wasm.init_runtime();
94
+ return JSRuntime.__wrap(ret);
95
+ }
96
+ let WASM_VECTOR_LEN = 0;
97
+ const cachedTextEncoder = typeof TextEncoder !== "undefined"
98
+ ? new TextEncoder("utf-8")
99
+ : {
100
+ encode: () => {
101
+ throw Error("TextEncoder not available");
102
+ },
103
+ };
104
+ const encodeString = function (arg, view) {
105
+ return cachedTextEncoder.encodeInto(arg, view);
106
+ };
107
+ function passStringToWasm0(arg, malloc, realloc) {
108
+ if (realloc === undefined) {
109
+ const buf = cachedTextEncoder.encode(arg);
110
+ const ptr = malloc(buf.length, 1) >>> 0;
111
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
112
+ WASM_VECTOR_LEN = buf.length;
113
+ return ptr;
114
+ }
115
+ let len = arg.length;
116
+ let ptr = malloc(len, 1) >>> 0;
117
+ const mem = getUint8Memory0();
118
+ let offset = 0;
119
+ for (; offset < len; offset++) {
120
+ const code = arg.charCodeAt(offset);
121
+ if (code > 0x7F)
122
+ break;
123
+ mem[ptr + offset] = code;
124
+ }
125
+ if (offset !== len) {
126
+ if (offset !== 0) {
127
+ arg = arg.slice(offset);
128
+ }
129
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
130
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
131
+ const ret = encodeString(arg, view);
132
+ offset += ret.written;
133
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
134
+ }
135
+ WASM_VECTOR_LEN = offset;
136
+ return ptr;
137
+ }
138
+ /**
139
+ * @param {string} datex_script
140
+ */
141
+ export function compile(datex_script) {
142
+ const ptr0 = passStringToWasm0(datex_script, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
143
+ const len0 = WASM_VECTOR_LEN;
144
+ wasm.compile(ptr0, len0);
145
+ }
146
+ function passArray8ToWasm0(arg, malloc) {
147
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
148
+ getUint8Memory0().set(arg, ptr / 1);
149
+ WASM_VECTOR_LEN = arg.length;
150
+ return ptr;
151
+ }
152
+ /**
153
+ * @param {Uint8Array} dxb
154
+ * @param {boolean} formatted
155
+ * @param {boolean} colorized
156
+ * @param {boolean} resolve_slots
157
+ * @returns {string}
158
+ */
159
+ export function decompile(dxb, formatted, colorized, resolve_slots) {
160
+ let deferred2_0;
161
+ let deferred2_1;
162
+ try {
163
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
164
+ const ptr0 = passArray8ToWasm0(dxb, wasm.__wbindgen_malloc);
165
+ const len0 = WASM_VECTOR_LEN;
166
+ wasm.decompile(retptr, ptr0, len0, formatted, colorized, resolve_slots);
167
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
168
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
169
+ deferred2_0 = r0;
170
+ deferred2_1 = r1;
171
+ return getStringFromWasm0(r0, r1);
172
+ }
173
+ finally {
174
+ wasm.__wbindgen_add_to_stack_pointer(16);
175
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
176
+ }
177
+ }
178
+ const JSMemoryFinalization = (typeof FinalizationRegistry === "undefined")
179
+ ? { register: () => { }, unregister: () => { } }
180
+ : new FinalizationRegistry((ptr) => wasm.__wbg_jsmemory_free(ptr >>> 0));
181
+ /** */
182
+ export class JSMemory {
183
+ static __wrap(ptr) {
184
+ ptr = ptr >>> 0;
185
+ const obj = Object.create(JSMemory.prototype);
186
+ obj.__wbg_ptr = ptr;
187
+ JSMemoryFinalization.register(obj, obj.__wbg_ptr, obj);
188
+ return obj;
189
+ }
190
+ __destroy_into_raw() {
191
+ const ptr = this.__wbg_ptr;
192
+ this.__wbg_ptr = 0;
193
+ JSMemoryFinalization.unregister(this);
194
+ return ptr;
195
+ }
196
+ free() {
197
+ const ptr = this.__destroy_into_raw();
198
+ wasm.__wbg_jsmemory_free(ptr);
199
+ }
200
+ /**
201
+ * @param {Uint8Array} address
202
+ * @returns {JSPointer | undefined}
203
+ */
204
+ get_pointer_by_id(address) {
205
+ const ret = wasm.jsmemory_get_pointer_by_id(this.__wbg_ptr, addHeapObject(address));
206
+ return ret === 0 ? undefined : JSPointer.__wrap(ret);
207
+ }
208
+ /**
209
+ * @returns {(Uint8Array)[]}
210
+ */
211
+ get_pointer_ids() {
212
+ try {
213
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
214
+ wasm.jsmemory_get_pointer_ids(retptr, this.__wbg_ptr);
215
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
216
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
217
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
218
+ wasm.__wbindgen_free(r0, r1 * 4, 4);
219
+ return v1;
220
+ }
221
+ finally {
222
+ wasm.__wbindgen_add_to_stack_pointer(16);
223
+ }
224
+ }
225
+ }
226
+ const JSPointerFinalization = (typeof FinalizationRegistry === "undefined")
227
+ ? { register: () => { }, unregister: () => { } }
228
+ : new FinalizationRegistry((ptr) => wasm.__wbg_jspointer_free(ptr >>> 0));
229
+ /** */
230
+ export class JSPointer {
231
+ static __wrap(ptr) {
232
+ ptr = ptr >>> 0;
233
+ const obj = Object.create(JSPointer.prototype);
234
+ obj.__wbg_ptr = ptr;
235
+ JSPointerFinalization.register(obj, obj.__wbg_ptr, obj);
236
+ return obj;
237
+ }
238
+ __destroy_into_raw() {
239
+ const ptr = this.__wbg_ptr;
240
+ this.__wbg_ptr = 0;
241
+ JSPointerFinalization.unregister(this);
242
+ return ptr;
243
+ }
244
+ free() {
245
+ const ptr = this.__destroy_into_raw();
246
+ wasm.__wbg_jspointer_free(ptr);
247
+ }
248
+ }
249
+ const JSRuntimeFinalization = (typeof FinalizationRegistry === "undefined")
250
+ ? { register: () => { }, unregister: () => { } }
251
+ : new FinalizationRegistry((ptr) => wasm.__wbg_jsruntime_free(ptr >>> 0));
252
+ /** */
253
+ export class JSRuntime {
254
+ static __wrap(ptr) {
255
+ ptr = ptr >>> 0;
256
+ const obj = Object.create(JSRuntime.prototype);
257
+ obj.__wbg_ptr = ptr;
258
+ JSRuntimeFinalization.register(obj, obj.__wbg_ptr, obj);
259
+ return obj;
260
+ }
261
+ __destroy_into_raw() {
262
+ const ptr = this.__wbg_ptr;
263
+ this.__wbg_ptr = 0;
264
+ JSRuntimeFinalization.unregister(this);
265
+ return ptr;
266
+ }
267
+ free() {
268
+ const ptr = this.__destroy_into_raw();
269
+ wasm.__wbg_jsruntime_free(ptr);
270
+ }
271
+ /**
272
+ * @returns {string}
273
+ */
274
+ get version() {
275
+ let deferred1_0;
276
+ let deferred1_1;
277
+ try {
278
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
279
+ wasm.jsruntime_version(retptr, this.__wbg_ptr);
280
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
281
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
282
+ deferred1_0 = r0;
283
+ deferred1_1 = r1;
284
+ return getStringFromWasm0(r0, r1);
285
+ }
286
+ finally {
287
+ wasm.__wbindgen_add_to_stack_pointer(16);
288
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
289
+ }
290
+ }
291
+ /**
292
+ * @returns {JSMemory}
293
+ */
294
+ get memory() {
295
+ const ret = wasm.jsruntime_memory(this.__wbg_ptr);
296
+ return JSMemory.__wrap(ret);
297
+ }
298
+ }
299
+ const imports = {
300
+ __wbindgen_placeholder__: {
301
+ __wbindgen_object_drop_ref: function (arg0) {
302
+ takeObject(arg0);
303
+ },
304
+ __wbindgen_string_new: function (arg0, arg1) {
305
+ const ret = getStringFromWasm0(arg0, arg1);
306
+ return addHeapObject(ret);
307
+ },
308
+ __wbg_log_5bb5f88f245d7762: function (arg0) {
309
+ console.log(getObject(arg0));
310
+ },
311
+ __wbg_buffer_12d079cc21e14bdb: function (arg0) {
312
+ const ret = getObject(arg0).buffer;
313
+ return addHeapObject(ret);
314
+ },
315
+ __wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb: function (arg0, arg1, arg2) {
316
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
317
+ return addHeapObject(ret);
318
+ },
319
+ __wbg_new_63b92bc8671ed464: function (arg0) {
320
+ const ret = new Uint8Array(getObject(arg0));
321
+ return addHeapObject(ret);
322
+ },
323
+ __wbg_set_a47bac70306a19a7: function (arg0, arg1, arg2) {
324
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
325
+ },
326
+ __wbg_length_c20a40f15020d68a: function (arg0) {
327
+ const ret = getObject(arg0).length;
328
+ return ret;
329
+ },
330
+ __wbindgen_throw: function (arg0, arg1) {
331
+ throw new Error(getStringFromWasm0(arg0, arg1));
332
+ },
333
+ __wbindgen_memory: function () {
334
+ const ret = wasm.memory;
335
+ return addHeapObject(ret);
336
+ },
337
+ },
338
+ };
339
+ class WasmBuildLoader {
340
+ constructor(options) {
341
+ _WasmBuildLoader_instances.add(this);
342
+ _WasmBuildLoader_options.set(this, void 0);
343
+ _WasmBuildLoader_lastLoadPromise.set(this, void 0);
344
+ _WasmBuildLoader_instantiated.set(this, void 0);
345
+ __classPrivateFieldSet(this, _WasmBuildLoader_options, options, "f");
346
+ }
347
+ get instance() {
348
+ return __classPrivateFieldGet(this, _WasmBuildLoader_instantiated, "f")?.instance;
349
+ }
350
+ get module() {
351
+ return __classPrivateFieldGet(this, _WasmBuildLoader_instantiated, "f")?.module;
352
+ }
353
+ load(url, decompress) {
354
+ if (__classPrivateFieldGet(this, _WasmBuildLoader_instantiated, "f")) {
355
+ return Promise.resolve(__classPrivateFieldGet(this, _WasmBuildLoader_instantiated, "f"));
356
+ }
357
+ else if (__classPrivateFieldGet(this, _WasmBuildLoader_lastLoadPromise, "f") == null) {
358
+ __classPrivateFieldSet(this, _WasmBuildLoader_lastLoadPromise, (async () => {
359
+ try {
360
+ __classPrivateFieldSet(this, _WasmBuildLoader_instantiated, await __classPrivateFieldGet(this, _WasmBuildLoader_instances, "m", _WasmBuildLoader_instantiate).call(this, url, decompress), "f");
361
+ return __classPrivateFieldGet(this, _WasmBuildLoader_instantiated, "f");
362
+ }
363
+ finally {
364
+ __classPrivateFieldSet(this, _WasmBuildLoader_lastLoadPromise, undefined, "f");
365
+ }
366
+ })(), "f");
367
+ }
368
+ return __classPrivateFieldGet(this, _WasmBuildLoader_lastLoadPromise, "f");
369
+ }
370
+ }
371
+ _WasmBuildLoader_options = new WeakMap(), _WasmBuildLoader_lastLoadPromise = new WeakMap(), _WasmBuildLoader_instantiated = new WeakMap(), _WasmBuildLoader_instances = new WeakSet(), _WasmBuildLoader_instantiate = async function _WasmBuildLoader_instantiate(url, decompress) {
372
+ const imports = __classPrivateFieldGet(this, _WasmBuildLoader_options, "f").imports;
373
+ if (__classPrivateFieldGet(this, _WasmBuildLoader_options, "f").cache != null && url.protocol !== "file:") {
374
+ try {
375
+ const result = await __classPrivateFieldGet(this, _WasmBuildLoader_options, "f").cache(url, decompress ?? ((bytes) => bytes));
376
+ if (result instanceof URL) {
377
+ url = result;
378
+ decompress = undefined; // already decompressed
379
+ }
380
+ else if (result != null) {
381
+ return WebAssembly.instantiate(result, imports);
382
+ }
383
+ }
384
+ catch {
385
+ // ignore if caching ever fails (ex. when on deploy)
386
+ }
387
+ }
388
+ const isFile = url.protocol === "file:";
389
+ // make file urls work in Node via dnt
390
+ const isNode = globalThis.process?.versions?.node != null;
391
+ if (isFile && typeof dntShim.Deno !== "object") {
392
+ throw new Error("Loading local files are not supported in this environment");
393
+ }
394
+ if (isNode && isFile) {
395
+ // the deno global will be shimmed by dnt
396
+ const wasmCode = await dntShim.Deno.readFile(url);
397
+ return WebAssembly.instantiate(decompress ? decompress(wasmCode) : wasmCode, imports);
398
+ }
399
+ switch (url.protocol) {
400
+ case "file:":
401
+ case "https:":
402
+ case "http:": {
403
+ const wasmResponse = await fetchWithRetries(url);
404
+ if (decompress) {
405
+ const wasmCode = new Uint8Array(await wasmResponse.arrayBuffer());
406
+ return WebAssembly.instantiate(decompress(wasmCode), imports);
407
+ }
408
+ if (isFile ||
409
+ wasmResponse.headers.get("content-type")?.toLowerCase()
410
+ .startsWith("application/wasm")) {
411
+ return WebAssembly.instantiateStreaming(wasmResponse, imports);
412
+ }
413
+ else {
414
+ return WebAssembly.instantiate(await wasmResponse.arrayBuffer(), imports);
415
+ }
416
+ }
417
+ default:
418
+ throw new Error(`Unsupported protocol: ${url.protocol}`);
419
+ }
420
+ };
421
+ const isNodeOrDeno = typeof dntShim.Deno === "object" ||
422
+ (typeof process !== "undefined" && process.versions != null &&
423
+ process.versions.node != null);
424
+ const loader = new WasmBuildLoader({
425
+ imports,
426
+ cache: isNodeOrDeno ? cacheToLocalDir : undefined,
427
+ });
428
+ export async function instantiate(opts) {
429
+ return (await instantiateWithInstance(opts)).exports;
430
+ }
431
+ export async function instantiateWithInstance(opts) {
432
+ const { instance } = await loader.load(opts?.url ?? new URL("datex_core_js_bg.wasm", import.meta.url), opts?.decompress);
433
+ wasm = wasm ?? instance.exports;
434
+ cachedInt32Memory0 = cachedInt32Memory0 ??
435
+ new Int32Array(wasm.memory.buffer);
436
+ cachedUint8Memory0 = cachedUint8Memory0 ??
437
+ new Uint8Array(wasm.memory.buffer);
438
+ return {
439
+ instance,
440
+ exports: getWasmInstanceExports(),
441
+ };
442
+ }
443
+ function getWasmInstanceExports() {
444
+ return { init_runtime, compile, decompile, JSMemory, JSPointer, JSRuntime };
445
+ }
446
+ export function isInstantiated() {
447
+ return loader.instance != null;
448
+ }
449
+ export async function cacheToLocalDir(url, decompress) {
450
+ const localPath = await getUrlLocalPath(url);
451
+ if (localPath == null) {
452
+ return undefined;
453
+ }
454
+ if (!await exists(localPath)) {
455
+ const fileBytes = decompress(new Uint8Array(await getUrlBytes(url)));
456
+ try {
457
+ await dntShim.Deno.writeFile(localPath, fileBytes);
458
+ }
459
+ catch {
460
+ // ignore and return the wasm bytes
461
+ return fileBytes;
462
+ }
463
+ }
464
+ return toFileUrl(localPath);
465
+ }
466
+ async function getUrlLocalPath(url) {
467
+ try {
468
+ const dataDirPath = await getInitializedLocalDataDirPath();
469
+ const hash = await getUrlHash(url);
470
+ return `${dataDirPath}/${hash}.wasm`;
471
+ }
472
+ catch {
473
+ return undefined;
474
+ }
475
+ }
476
+ async function getInitializedLocalDataDirPath() {
477
+ const dataDir = localDataDir();
478
+ if (dataDir == null) {
479
+ throw new Error(`Could not find local data directory.`);
480
+ }
481
+ const dirPath = `${dataDir}/deno-wasmbuild`;
482
+ await ensureDir(dirPath);
483
+ return dirPath;
484
+ }
485
+ async function exists(filePath) {
486
+ try {
487
+ await dntShim.Deno.lstat(filePath);
488
+ return true;
489
+ }
490
+ catch (error) {
491
+ if (error instanceof dntShim.Deno.errors.NotFound) {
492
+ return false;
493
+ }
494
+ throw error;
495
+ }
496
+ }
497
+ async function ensureDir(dir) {
498
+ try {
499
+ const fileInfo = await dntShim.Deno.lstat(dir);
500
+ if (!fileInfo.isDirectory) {
501
+ throw new Error(`Path was not a directory '${dir}'`);
502
+ }
503
+ }
504
+ catch (err) {
505
+ if (err instanceof dntShim.Deno.errors.NotFound) {
506
+ // if dir not exists. then create it.
507
+ await dntShim.Deno.mkdir(dir, { recursive: true });
508
+ return;
509
+ }
510
+ throw err;
511
+ }
512
+ }
513
+ async function getUrlHash(url) {
514
+ // Taken from MDN: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
515
+ const hashBuffer = await dntShim.crypto.subtle.digest("SHA-256", new TextEncoder().encode(url.href));
516
+ // convert buffer to byte array
517
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
518
+ // convert bytes to hex string
519
+ const hashHex = hashArray
520
+ .map((b) => b.toString(16).padStart(2, "0"))
521
+ .join("");
522
+ return hashHex;
523
+ }
524
+ async function getUrlBytes(url) {
525
+ const response = await fetchWithRetries(url);
526
+ return await response.arrayBuffer();
527
+ }
528
+ // the below is extracted from deno_std/path
529
+ const WHITESPACE_ENCODINGS = {
530
+ "\u0009": "%09",
531
+ "\u000A": "%0A",
532
+ "\u000B": "%0B",
533
+ "\u000C": "%0C",
534
+ "\u000D": "%0D",
535
+ "\u0020": "%20",
536
+ };
537
+ function encodeWhitespace(string) {
538
+ return string.replaceAll(/[\s]/g, (c) => {
539
+ return WHITESPACE_ENCODINGS[c] ?? c;
540
+ });
541
+ }
542
+ function toFileUrl(path) {
543
+ return dntShim.Deno.build.os === "windows"
544
+ ? windowsToFileUrl(path)
545
+ : posixToFileUrl(path);
546
+ }
547
+ function posixToFileUrl(path) {
548
+ const url = new URL("file:///");
549
+ url.pathname = encodeWhitespace(path.replace(/%/g, "%25").replace(/\\/g, "%5C"));
550
+ return url;
551
+ }
552
+ function windowsToFileUrl(path) {
553
+ const [, hostname, pathname] = path.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/);
554
+ const url = new URL("file:///");
555
+ url.pathname = encodeWhitespace(pathname.replace(/%/g, "%25"));
556
+ if (hostname != null && hostname != "localhost") {
557
+ url.hostname = hostname;
558
+ if (!url.hostname) {
559
+ throw new TypeError("Invalid hostname.");
560
+ }
561
+ }
562
+ return url;
563
+ }
564
+ export async function fetchWithRetries(url, maxRetries = 5) {
565
+ let sleepMs = 250;
566
+ let iterationCount = 0;
567
+ while (true) {
568
+ iterationCount++;
569
+ try {
570
+ const res = await dntShim.fetch(url);
571
+ if (res.ok || iterationCount > maxRetries) {
572
+ return res;
573
+ }
574
+ }
575
+ catch (err) {
576
+ if (iterationCount > maxRetries) {
577
+ throw err;
578
+ }
579
+ }
580
+ console.warn(`Failed fetching. Retrying in ${sleepMs}ms...`);
581
+ await new Promise((resolve) => dntShim.setTimeout(resolve, sleepMs));
582
+ sleepMs = Math.min(sleepMs * 2, 10000);
583
+ }
584
+ }
585
+ // MIT License - Copyright (c) justjavac.
586
+ // https://github.com/justjavac/deno_dirs/blob/e8c001bbef558f08fd486d444af391729b0b8068/data_local_dir/mod.ts
587
+ function localDataDir() {
588
+ switch (dntShim.Deno.build.os) {
589
+ case "linux": {
590
+ const xdg = dntShim.Deno.env.get("XDG_DATA_HOME");
591
+ if (xdg) {
592
+ return xdg;
593
+ }
594
+ const home = dntShim.Deno.env.get("HOME");
595
+ if (home) {
596
+ return `${home}/.local/share`;
597
+ }
598
+ break;
599
+ }
600
+ case "darwin": {
601
+ const home = dntShim.Deno.env.get("HOME");
602
+ if (home) {
603
+ return `${home}/Library/Application Support`;
604
+ }
605
+ break;
606
+ }
607
+ case "windows":
608
+ return dntShim.Deno.env.get("LOCALAPPDATA") ?? undefined;
609
+ }
610
+ return undefined;
611
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./datex-core/datex_core_js.generated.js";
2
+ //# sourceMappingURL=datex-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datex-core.d.ts","sourceRoot":"","sources":["../../src/src/datex-core.ts"],"names":[],"mappings":"AACA,cAAc,yCAAyC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { instantiate } from "./datex-core/datex_core_js.generated.js";
2
+ export * from "./datex-core/datex_core_js.generated.js";
3
+ await instantiate();
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @module mod.ts
3
+ * @description
4
+ * This modules exports a instance of the DATEX runtime.
5
+ */
6
+ import { Runtime } from "./runtime/runtime.js";
7
+ /**
8
+ * The default instance of the Datex runtime.
9
+ */
10
+ export declare const Datex: Runtime;
11
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/src/mod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,OAAuB,CAAC"}
package/esm/src/mod.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module mod.ts
3
+ * @description
4
+ * This modules exports a instance of the DATEX runtime.
5
+ */
6
+ import { Runtime } from "./runtime/runtime.js";
7
+ /**
8
+ * The default instance of the Datex runtime.
9
+ */
10
+ export const Datex = new Runtime();
@@ -0,0 +1,16 @@
1
+ import type { JSMemory, JSRuntime } from "../datex-core/datex_core_js.generated";
2
+ export declare class Runtime {
3
+ #private;
4
+ readonly js_version: string;
5
+ /**
6
+ * properties from #runtime
7
+ */
8
+ get version(): string;
9
+ get memory(): JSMemory;
10
+ /**
11
+ * @internal only used for debugging
12
+ */
13
+ get _runtime(): JSRuntime;
14
+ constructor();
15
+ }
16
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/src/runtime/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,QAAQ,EACR,SAAS,EACZ,MAAM,uCAAuC,CAAC;AAS/C,qBAAa,OAAO;;IAChB,SAAgB,UAAU,SAAW;IAKrC;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,MAAM,IAAI,QAAQ,CAErB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,SAAS,CAExB;;CAMJ"}