fast-publicodes 0.0.0 → 1.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.
@@ -0,0 +1,633 @@
1
+ /* @ts-self-types="./fast_publicodes.d.ts" */
2
+
3
+ /**
4
+ * The engine, taking rules, options and situations as JSON.
5
+ *
6
+ * Calls report the warnings they raised as `warnings`: the text of a warning not sent before,
7
+ * which takes the next index in the table the caller keeps, or the index of one already sent.
8
+ * `warningsReset` asks the caller to empty its table first.
9
+ */
10
+ export class Engine {
11
+ static __wrap(ptr) {
12
+ const obj = Object.create(Engine.prototype);
13
+ obj.__wbg_ptr = ptr;
14
+ EngineFinalization.register(obj, obj.__wbg_ptr, obj);
15
+ return obj;
16
+ }
17
+ __destroy_into_raw() {
18
+ const ptr = this.__wbg_ptr;
19
+ this.__wbg_ptr = 0;
20
+ EngineFinalization.unregister(this);
21
+ return ptr;
22
+ }
23
+ free() {
24
+ const ptr = this.__destroy_into_raw();
25
+ wasm.__wbg_engine_free(ptr, 0);
26
+ }
27
+ /**
28
+ * Returns `{ possibilities }`, as JSON, or `{ error }`.
29
+ * @param {string} name
30
+ * @returns {object}
31
+ */
32
+ applicablePossibilities(name) {
33
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
34
+ const len0 = WASM_VECTOR_LEN;
35
+ const ret = wasm.engine_applicablePossibilities(this.__wbg_ptr, ptr0, len0);
36
+ return takeObject(ret);
37
+ }
38
+ /**
39
+ * `evaluate`, for `getRule(rule).suggestions[name]`.
40
+ * @param {string} rule
41
+ * @param {string} name
42
+ * @returns {object}
43
+ */
44
+ evaluateSuggestion(rule, name) {
45
+ const ptr0 = passStringToWasm0(rule, wasm.__wbindgen_export, wasm.__wbindgen_export2);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
48
+ const len1 = WASM_VECTOR_LEN;
49
+ const ret = wasm.engine_evaluateSuggestion(this.__wbg_ptr, ptr0, len0, ptr1, len1);
50
+ return takeObject(ret);
51
+ }
52
+ /**
53
+ * Returns `{ nodeValue, index }`, `index` locating it in `evaluations`, with `unit` the index
54
+ * of its unit in the table the caller keeps, or `newUnit` when it is new and takes the next
55
+ * index, after `unitsReset` asks the caller to empty its table; or `{ error }`. `text` is
56
+ * JSON when `json`.
57
+ * @param {string} text
58
+ * @param {boolean} json
59
+ * @returns {object}
60
+ */
61
+ evaluate(text, json) {
62
+ try {
63
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
64
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ wasm.engine_evaluate(retptr, this.__wbg_ptr, ptr0, len0, json);
67
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
68
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
69
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
70
+ if (r2) {
71
+ throw takeObject(r1);
72
+ }
73
+ return takeObject(r0);
74
+ } finally {
75
+ wasm.__wbindgen_add_to_stack_pointer(16);
76
+ }
77
+ }
78
+ /**
79
+ * A handle on the expressions evaluated since the cache was last reset, for
80
+ * `missingVariables`.
81
+ * @returns {EvaluationsHandle}
82
+ */
83
+ evaluations() {
84
+ const ret = wasm.engine_evaluations(this.__wbg_ptr);
85
+ return EvaluationsHandle.__wrap(ret);
86
+ }
87
+ /**
88
+ * @returns {boolean}
89
+ */
90
+ inversionFail() {
91
+ const ret = wasm.engine_inversionFail(this.__wbg_ptr);
92
+ return ret !== 0;
93
+ }
94
+ /**
95
+ * The missing variables of the evaluation at `index` in `evaluations`.
96
+ * @param {EvaluationsHandle} evaluations
97
+ * @param {number} index
98
+ * @returns {object}
99
+ */
100
+ missingVariables(evaluations, index) {
101
+ _assertClass(evaluations, EvaluationsHandle);
102
+ const ret = wasm.engine_missingVariables(this.__wbg_ptr, evaluations.__wbg_ptr, index);
103
+ return takeObject(ret);
104
+ }
105
+ /**
106
+ * `get_today` gives the date `durée` defaults to, as `dd/mm/yyyy`. Fails with the error as
107
+ * JSON `{ name, message, dottedName, warnings }`.
108
+ * @param {string} rules
109
+ * @param {string} options
110
+ * @param {Function} get_today
111
+ * @param {Function | null} [get_unit_key]
112
+ */
113
+ constructor(rules, options, get_today, get_unit_key) {
114
+ try {
115
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
116
+ const ptr0 = passStringToWasm0(rules, wasm.__wbindgen_export, wasm.__wbindgen_export2);
117
+ const len0 = WASM_VECTOR_LEN;
118
+ const ptr1 = passStringToWasm0(options, wasm.__wbindgen_export, wasm.__wbindgen_export2);
119
+ const len1 = WASM_VECTOR_LEN;
120
+ wasm.engine_new(retptr, ptr0, len0, ptr1, len1, addHeapObject(get_today), isLikeNone(get_unit_key) ? 0 : addHeapObject(get_unit_key));
121
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
122
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
123
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
124
+ if (r2) {
125
+ throw takeObject(r1);
126
+ }
127
+ this.__wbg_ptr = r0;
128
+ EngineFinalization.register(this, this.__wbg_ptr, this);
129
+ return this;
130
+ } finally {
131
+ wasm.__wbindgen_add_to_stack_pointer(16);
132
+ }
133
+ }
134
+ resetCache() {
135
+ wasm.engine_resetCache(this.__wbg_ptr);
136
+ }
137
+ /**
138
+ * The names of the public rules, in definition order.
139
+ * @returns {string[]}
140
+ */
141
+ ruleNames() {
142
+ try {
143
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
144
+ wasm.engine_ruleNames(retptr, this.__wbg_ptr);
145
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
146
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
147
+ var v1 = getArrayJsValueFromWasm0(r0, r1);
148
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
149
+ return v1;
150
+ } finally {
151
+ wasm.__wbindgen_add_to_stack_pointer(16);
152
+ }
153
+ }
154
+ /**
155
+ * Returns `{ rule }`, the rule node with its inferred type and the names of its suggestions,
156
+ * as JSON, or `{ error }`.
157
+ * @param {string} name
158
+ * @returns {object}
159
+ */
160
+ rule(name) {
161
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
162
+ const len0 = WASM_VECTOR_LEN;
163
+ const ret = wasm.engine_rule(this.__wbg_ptr, ptr0, len0);
164
+ return takeObject(ret);
165
+ }
166
+ /**
167
+ * Returns `{ accepted }`, the names the situation gains, or `{ error, situationReset,
168
+ * accepted }`.
169
+ * @param {string} situation
170
+ * @param {boolean} keep_previous
171
+ * @param {boolean} strict
172
+ * @returns {object}
173
+ */
174
+ setSituation(situation, keep_previous, strict) {
175
+ try {
176
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
177
+ const ptr0 = passStringToWasm0(situation, wasm.__wbindgen_export, wasm.__wbindgen_export2);
178
+ const len0 = WASM_VECTOR_LEN;
179
+ wasm.engine_setSituation(retptr, this.__wbg_ptr, ptr0, len0, keep_previous, strict);
180
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
181
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
182
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
183
+ if (r2) {
184
+ throw takeObject(r1);
185
+ }
186
+ return takeObject(r0);
187
+ } finally {
188
+ wasm.__wbindgen_add_to_stack_pointer(16);
189
+ }
190
+ }
191
+ /**
192
+ * @param {boolean} copy_cache
193
+ * @returns {Engine}
194
+ */
195
+ shallowCopy(copy_cache) {
196
+ const ret = wasm.engine_shallowCopy(this.__wbg_ptr, copy_cache);
197
+ return Engine.__wrap(ret);
198
+ }
199
+ /**
200
+ * Returns the warnings raised by building the engine.
201
+ * @returns {object}
202
+ */
203
+ takeWarnings() {
204
+ const ret = wasm.engine_takeWarnings(this.__wbg_ptr);
205
+ return takeObject(ret);
206
+ }
207
+ }
208
+ if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
209
+
210
+ /**
211
+ * The expressions evaluated since the cache was last reset, for `missingVariables`.
212
+ */
213
+ export class EvaluationsHandle {
214
+ static __wrap(ptr) {
215
+ const obj = Object.create(EvaluationsHandle.prototype);
216
+ obj.__wbg_ptr = ptr;
217
+ EvaluationsHandleFinalization.register(obj, obj.__wbg_ptr, obj);
218
+ return obj;
219
+ }
220
+ __destroy_into_raw() {
221
+ const ptr = this.__wbg_ptr;
222
+ this.__wbg_ptr = 0;
223
+ EvaluationsHandleFinalization.unregister(this);
224
+ return ptr;
225
+ }
226
+ free() {
227
+ const ptr = this.__destroy_into_raw();
228
+ wasm.__wbg_evaluationshandle_free(ptr, 0);
229
+ }
230
+ }
231
+ if (Symbol.dispose) EvaluationsHandle.prototype[Symbol.dispose] = EvaluationsHandle.prototype.free;
232
+
233
+ /**
234
+ * `parseExpression`: returns `{ expression }`, as JSON, or `{ error }`.
235
+ * @param {string} expression
236
+ * @param {string} dotted_name
237
+ * @returns {object}
238
+ */
239
+ export function parseExpression(expression, dotted_name) {
240
+ const ptr0 = passStringToWasm0(expression, wasm.__wbindgen_export, wasm.__wbindgen_export2);
241
+ const len0 = WASM_VECTOR_LEN;
242
+ const ptr1 = passStringToWasm0(dotted_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
243
+ const len1 = WASM_VECTOR_LEN;
244
+ const ret = wasm.parseExpression(ptr0, len0, ptr1, len1);
245
+ return takeObject(ret);
246
+ }
247
+ function __wbg_get_imports() {
248
+ const import0 = {
249
+ __proto__: null,
250
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
251
+ const ret = Error(getStringFromWasm0(arg0, arg1));
252
+ return addHeapObject(ret);
253
+ },
254
+ __wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
255
+ const ret = debugString(getObject(arg1));
256
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
257
+ const len1 = WASM_VECTOR_LEN;
258
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
259
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
260
+ },
261
+ __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
262
+ const obj = getObject(arg1);
263
+ const ret = typeof(obj) === 'string' ? obj : undefined;
264
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
265
+ var len1 = WASM_VECTOR_LEN;
266
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
267
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
268
+ },
269
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
270
+ throw new Error(getStringFromWasm0(arg0, arg1));
271
+ },
272
+ __wbg_call_187d372bd5fdd4aa: function() { return handleError(function (arg0, arg1, arg2) {
273
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
274
+ return addHeapObject(ret);
275
+ }, arguments); },
276
+ __wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
277
+ const ret = getObject(arg0).call(getObject(arg1));
278
+ return addHeapObject(ret);
279
+ }, arguments); },
280
+ __wbg_get_31af05bd4842a84f: function() { return handleError(function (arg0, arg1) {
281
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
282
+ return addHeapObject(ret);
283
+ }, arguments); },
284
+ __wbg_message_5f8387f0c32b90a7: function(arg0) {
285
+ const ret = getObject(arg0).message;
286
+ return addHeapObject(ret);
287
+ },
288
+ __wbg_new_617a8cdb8bb1130e: function() {
289
+ const ret = new Object();
290
+ return addHeapObject(ret);
291
+ },
292
+ __wbg_new_ee2291f50781bf1d: function() {
293
+ const ret = new Array();
294
+ return addHeapObject(ret);
295
+ },
296
+ __wbg_push_2baf45db356cf468: function(arg0, arg1) {
297
+ const ret = getObject(arg0).push(getObject(arg1));
298
+ return ret;
299
+ },
300
+ __wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
301
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
302
+ return ret;
303
+ }, arguments); },
304
+ __wbindgen_generic_0000000000000001: function(arg0) {
305
+ // Cast intrinsic for `F64 -> Externref`.
306
+ const ret = arg0;
307
+ return addHeapObject(ret);
308
+ },
309
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
310
+ // Cast intrinsic for `Ref(String) -> Externref`.
311
+ const ret = getStringFromWasm0(arg0, arg1);
312
+ return addHeapObject(ret);
313
+ },
314
+ __wbindgen_object_drop_ref: function(arg0) {
315
+ takeObject(arg0);
316
+ },
317
+ };
318
+ return {
319
+ __proto__: null,
320
+ "./fast_publicodes_bg.js": import0,
321
+ };
322
+ }
323
+
324
+ const EngineFinalization = (typeof FinalizationRegistry === 'undefined')
325
+ ? { register: () => {}, unregister: () => {} }
326
+ : new FinalizationRegistry(ptr => wasm.__wbg_engine_free(ptr, 1));
327
+ const EvaluationsHandleFinalization = (typeof FinalizationRegistry === 'undefined')
328
+ ? { register: () => {}, unregister: () => {} }
329
+ : new FinalizationRegistry(ptr => wasm.__wbg_evaluationshandle_free(ptr, 1));
330
+
331
+ function addHeapObject(obj) {
332
+ if (heap_next === heap.length) heap.push(heap.length + 1);
333
+ const idx = heap_next;
334
+ heap_next = heap[idx];
335
+
336
+ heap[idx] = obj;
337
+ return idx;
338
+ }
339
+
340
+ function _assertClass(instance, klass) {
341
+ if (!(instance instanceof klass)) {
342
+ throw new Error(`expected instance of ${klass.name}`);
343
+ }
344
+ }
345
+
346
+ function debugString(val) {
347
+ // primitive types
348
+ const type = typeof val;
349
+ if (type == 'number' || type == 'boolean' || val == null) {
350
+ return `${val}`;
351
+ }
352
+ if (type == 'string') {
353
+ return `"${val}"`;
354
+ }
355
+ if (type == 'symbol') {
356
+ const description = val.description;
357
+ if (description == null) {
358
+ return 'Symbol';
359
+ } else {
360
+ return `Symbol(${description})`;
361
+ }
362
+ }
363
+ if (type == 'function') {
364
+ const name = val.name;
365
+ if (typeof name == 'string' && name.length > 0) {
366
+ return `Function(${name})`;
367
+ } else {
368
+ return 'Function';
369
+ }
370
+ }
371
+ // objects
372
+ if (Array.isArray(val)) {
373
+ const length = val.length;
374
+ let debug = '[';
375
+ if (length > 0) {
376
+ debug += debugString(val[0]);
377
+ }
378
+ for(let i = 1; i < length; i++) {
379
+ debug += ', ' + debugString(val[i]);
380
+ }
381
+ debug += ']';
382
+ return debug;
383
+ }
384
+ // Test for built-in
385
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
386
+ let className;
387
+ if (builtInMatches && builtInMatches.length > 1) {
388
+ className = builtInMatches[1];
389
+ } else {
390
+ // Failed to match the standard '[object ClassName]'
391
+ return toString.call(val);
392
+ }
393
+ if (className == 'Object') {
394
+ // we're a user defined class or Object
395
+ // JSON.stringify avoids problems with cycles, and is generally much
396
+ // easier than looping through ownProperties of `val`.
397
+ try {
398
+ return 'Object(' + JSON.stringify(val) + ')';
399
+ } catch (_) {
400
+ return 'Object';
401
+ }
402
+ }
403
+ // errors
404
+ if (val instanceof Error) {
405
+ return `${val.name}: ${val.message}\n${val.stack}`;
406
+ }
407
+ // TODO we could test for more things here, like `Set`s and `Map`s.
408
+ return className;
409
+ }
410
+
411
+ function dropObject(idx) {
412
+ if (idx < 1028) return;
413
+ heap[idx] = heap_next;
414
+ heap_next = idx;
415
+ }
416
+
417
+ function getArrayJsValueFromWasm0(ptr, len) {
418
+ ptr = ptr >>> 0;
419
+ const mem = getDataViewMemory0();
420
+ const result = [];
421
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
422
+ result.push(takeObject(mem.getUint32(i, true)));
423
+ }
424
+ return result;
425
+ }
426
+
427
+ let cachedDataViewMemory0 = null;
428
+ function getDataViewMemory0() {
429
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
430
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
431
+ }
432
+ return cachedDataViewMemory0;
433
+ }
434
+
435
+ function getStringFromWasm0(ptr, len) {
436
+ return decodeText(ptr >>> 0, len);
437
+ }
438
+
439
+ let cachedUint8ArrayMemory0 = null;
440
+ function getUint8ArrayMemory0() {
441
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
442
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
443
+ }
444
+ return cachedUint8ArrayMemory0;
445
+ }
446
+
447
+ function getObject(idx) { return heap[idx]; }
448
+
449
+ function handleError(f, args) {
450
+ try {
451
+ return f.apply(this, args);
452
+ } catch (e) {
453
+ wasm.__wbindgen_export3(addHeapObject(e));
454
+ }
455
+ }
456
+
457
+ let heap = new Array(1024).fill(undefined);
458
+ heap.push(undefined, null, true, false);
459
+
460
+ let heap_next = heap.length;
461
+
462
+ function isLikeNone(x) {
463
+ return x === undefined || x === null;
464
+ }
465
+
466
+ function passStringToWasm0(arg, malloc, realloc) {
467
+ if (realloc === undefined) {
468
+ const buf = cachedTextEncoder.encode(arg);
469
+ const ptr = malloc(buf.length, 1) >>> 0;
470
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
471
+ WASM_VECTOR_LEN = buf.length;
472
+ return ptr;
473
+ }
474
+
475
+ let len = arg.length;
476
+ let ptr = malloc(len, 1) >>> 0;
477
+
478
+ const mem = getUint8ArrayMemory0();
479
+
480
+ let offset = 0;
481
+
482
+ for (; offset < len; offset++) {
483
+ const code = arg.charCodeAt(offset);
484
+ if (code > 0x7F) break;
485
+ mem[ptr + offset] = code;
486
+ }
487
+ if (offset !== len) {
488
+ if (offset !== 0) {
489
+ arg = arg.slice(offset);
490
+ }
491
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
492
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
493
+ const ret = cachedTextEncoder.encodeInto(arg, view);
494
+
495
+ offset += ret.written;
496
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
497
+ }
498
+
499
+ WASM_VECTOR_LEN = offset;
500
+ return ptr;
501
+ }
502
+
503
+ function takeObject(idx) {
504
+ const ret = getObject(idx);
505
+ dropObject(idx);
506
+ return ret;
507
+ }
508
+
509
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
510
+ cachedTextDecoder.decode();
511
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
512
+ let numBytesDecoded = 0;
513
+ function decodeText(ptr, len) {
514
+ numBytesDecoded += len;
515
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
516
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
517
+ cachedTextDecoder.decode();
518
+ numBytesDecoded = len;
519
+ }
520
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
521
+ }
522
+
523
+ const cachedTextEncoder = new TextEncoder();
524
+
525
+ if (!('encodeInto' in cachedTextEncoder)) {
526
+ cachedTextEncoder.encodeInto = function (arg, view) {
527
+ const buf = cachedTextEncoder.encode(arg);
528
+ view.set(buf);
529
+ return {
530
+ read: arg.length,
531
+ written: buf.length
532
+ };
533
+ };
534
+ }
535
+
536
+ let WASM_VECTOR_LEN = 0;
537
+
538
+ let wasmModule, wasmInstance, wasm;
539
+ function __wbg_finalize_init(instance, module) {
540
+ wasmInstance = instance;
541
+ wasm = instance.exports;
542
+ wasmModule = module;
543
+ cachedDataViewMemory0 = null;
544
+ cachedUint8ArrayMemory0 = null;
545
+ return wasm;
546
+ }
547
+
548
+ async function __wbg_load(module, imports) {
549
+ if (typeof Response === 'function' && module instanceof Response) {
550
+ if (!module.ok) {
551
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
552
+ }
553
+
554
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
555
+ try {
556
+ return await WebAssembly.instantiateStreaming(module, imports);
557
+ } catch (e) {
558
+ const validResponse = expectedResponseType(module.type);
559
+
560
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
561
+ 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);
562
+
563
+ } else { throw e; }
564
+ }
565
+ }
566
+
567
+ const bytes = await module.arrayBuffer();
568
+ return await WebAssembly.instantiate(bytes, imports);
569
+ } else {
570
+ const instance = await WebAssembly.instantiate(module, imports);
571
+
572
+ if (instance instanceof WebAssembly.Instance) {
573
+ return { instance, module };
574
+ } else {
575
+ return instance;
576
+ }
577
+ }
578
+
579
+ function expectedResponseType(type) {
580
+ switch (type) {
581
+ case 'basic': case 'cors': case 'default': return true;
582
+ }
583
+ return false;
584
+ }
585
+ }
586
+
587
+ function initSync(module) {
588
+ if (wasm !== undefined) return wasm;
589
+
590
+
591
+ if (module !== undefined) {
592
+ if (Object.getPrototypeOf(module) === Object.prototype) {
593
+ ({module} = module)
594
+ } else {
595
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
596
+ }
597
+ }
598
+
599
+ const imports = __wbg_get_imports();
600
+ if (!(module instanceof WebAssembly.Module)) {
601
+ module = new WebAssembly.Module(module);
602
+ }
603
+ const instance = new WebAssembly.Instance(module, imports);
604
+ return __wbg_finalize_init(instance, module);
605
+ }
606
+
607
+ async function __wbg_init(module_or_path) {
608
+ if (wasm !== undefined) return wasm;
609
+
610
+
611
+ if (module_or_path !== undefined) {
612
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
613
+ ({module_or_path} = module_or_path)
614
+ } else {
615
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
616
+ }
617
+ }
618
+
619
+ if (module_or_path === undefined) {
620
+ module_or_path = new URL('fast_publicodes_bg.wasm', import.meta.url);
621
+ }
622
+ const imports = __wbg_get_imports();
623
+
624
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
625
+ module_or_path = fetch(module_or_path);
626
+ }
627
+
628
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
629
+
630
+ return __wbg_finalize_init(instance, module);
631
+ }
632
+
633
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,24 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_engine_free: (a: number, b: number) => void;
5
+ export const __wbg_evaluationshandle_free: (a: number, b: number) => void;
6
+ export const engine_applicablePossibilities: (a: number, b: number, c: number) => number;
7
+ export const engine_evaluate: (a: number, b: number, c: number, d: number, e: number) => void;
8
+ export const engine_evaluateSuggestion: (a: number, b: number, c: number, d: number, e: number) => number;
9
+ export const engine_evaluations: (a: number) => number;
10
+ export const engine_inversionFail: (a: number) => number;
11
+ export const engine_missingVariables: (a: number, b: number, c: number) => number;
12
+ export const engine_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
13
+ export const engine_resetCache: (a: number) => void;
14
+ export const engine_rule: (a: number, b: number, c: number) => number;
15
+ export const engine_ruleNames: (a: number, b: number) => void;
16
+ export const engine_setSituation: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
17
+ export const engine_shallowCopy: (a: number, b: number) => number;
18
+ export const engine_takeWarnings: (a: number) => number;
19
+ export const parseExpression: (a: number, b: number, c: number, d: number) => number;
20
+ export const __wbindgen_export: (a: number, b: number) => number;
21
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
22
+ export const __wbindgen_export3: (a: number) => void;
23
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
24
+ export const __wbindgen_export4: (a: number, b: number, c: number) => void;