ic-mops 2.0.0 → 2.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.
- package/commands/build.ts +40 -13
- package/dist/commands/build.js +36 -12
- package/dist/package.json +2 -2
- package/dist/types.d.ts +1 -0
- package/dist/wasm/pkg/nodejs/wasm.d.ts +3 -0
- package/dist/wasm/pkg/nodejs/wasm.js +323 -17
- package/dist/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/nodejs/wasm_bg.wasm.d.ts +6 -1
- package/dist/wasm/pkg/web/wasm.d.ts +10 -1
- package/dist/wasm/pkg/web/wasm.js +300 -21
- package/dist/wasm/pkg/web/wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/web/wasm_bg.wasm.d.ts +6 -1
- package/dist/wasm.d.ts +6 -1
- package/package.json +2 -2
- package/tests/__snapshots__/cli.test.ts.snap +16 -16
- package/tests/build/error/src/Bar.mo +2 -2
- package/tests/build/success/candid/bar.did +1 -0
- package/tests/build/success/mops.toml +8 -3
- package/types.ts +1 -0
- package/wasm/Cargo.toml +2 -5
- package/wasm/pkg/nodejs/wasm.d.ts +3 -0
- package/wasm/pkg/nodejs/wasm.js +323 -17
- package/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
- package/wasm/pkg/nodejs/wasm_bg.wasm.d.ts +6 -1
- package/wasm/pkg/web/wasm.d.ts +10 -1
- package/wasm/pkg/web/wasm.js +300 -21
- package/wasm/pkg/web/wasm_bg.wasm +0 -0
- package/wasm/pkg/web/wasm_bg.wasm.d.ts +6 -1
- package/wasm/src/lib.rs +10 -5
- package/wasm/src/utils.rs +15 -0
- package/wasm/src/wasm_utils.rs +79 -0
- package/wasm.ts +10 -1
package/wasm/pkg/web/wasm.js
CHANGED
|
@@ -1,9 +1,95 @@
|
|
|
1
1
|
let wasm;
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function addToExternrefTable0(obj) {
|
|
4
|
+
const idx = wasm.__externref_table_alloc();
|
|
5
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
6
|
+
return idx;
|
|
7
|
+
}
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
function debugString(val) {
|
|
10
|
+
// primitive types
|
|
11
|
+
const type = typeof val;
|
|
12
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
13
|
+
return `${val}`;
|
|
14
|
+
}
|
|
15
|
+
if (type == 'string') {
|
|
16
|
+
return `"${val}"`;
|
|
17
|
+
}
|
|
18
|
+
if (type == 'symbol') {
|
|
19
|
+
const description = val.description;
|
|
20
|
+
if (description == null) {
|
|
21
|
+
return 'Symbol';
|
|
22
|
+
} else {
|
|
23
|
+
return `Symbol(${description})`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (type == 'function') {
|
|
27
|
+
const name = val.name;
|
|
28
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
29
|
+
return `Function(${name})`;
|
|
30
|
+
} else {
|
|
31
|
+
return 'Function';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// objects
|
|
35
|
+
if (Array.isArray(val)) {
|
|
36
|
+
const length = val.length;
|
|
37
|
+
let debug = '[';
|
|
38
|
+
if (length > 0) {
|
|
39
|
+
debug += debugString(val[0]);
|
|
40
|
+
}
|
|
41
|
+
for(let i = 1; i < length; i++) {
|
|
42
|
+
debug += ', ' + debugString(val[i]);
|
|
43
|
+
}
|
|
44
|
+
debug += ']';
|
|
45
|
+
return debug;
|
|
46
|
+
}
|
|
47
|
+
// Test for built-in
|
|
48
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
49
|
+
let className;
|
|
50
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
51
|
+
className = builtInMatches[1];
|
|
52
|
+
} else {
|
|
53
|
+
// Failed to match the standard '[object ClassName]'
|
|
54
|
+
return toString.call(val);
|
|
55
|
+
}
|
|
56
|
+
if (className == 'Object') {
|
|
57
|
+
// we're a user defined class or Object
|
|
58
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
59
|
+
// easier than looping through ownProperties of `val`.
|
|
60
|
+
try {
|
|
61
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
62
|
+
} catch (_) {
|
|
63
|
+
return 'Object';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// errors
|
|
67
|
+
if (val instanceof Error) {
|
|
68
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
69
|
+
}
|
|
70
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
71
|
+
return className;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
75
|
+
ptr = ptr >>> 0;
|
|
76
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let cachedDataViewMemory0 = null;
|
|
80
|
+
function getDataViewMemory0() {
|
|
81
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
82
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
83
|
+
}
|
|
84
|
+
return cachedDataViewMemory0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getStringFromWasm0(ptr, len) {
|
|
88
|
+
ptr = ptr >>> 0;
|
|
89
|
+
return decodeText(ptr, len);
|
|
90
|
+
}
|
|
6
91
|
|
|
92
|
+
let cachedUint8ArrayMemory0 = null;
|
|
7
93
|
function getUint8ArrayMemory0() {
|
|
8
94
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
9
95
|
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
@@ -11,21 +97,27 @@ function getUint8ArrayMemory0() {
|
|
|
11
97
|
return cachedUint8ArrayMemory0;
|
|
12
98
|
}
|
|
13
99
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
read: arg.length,
|
|
22
|
-
written: buf.length
|
|
23
|
-
};
|
|
100
|
+
function handleError(f, args) {
|
|
101
|
+
try {
|
|
102
|
+
return f.apply(this, args);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
const idx = addToExternrefTable0(e);
|
|
105
|
+
wasm.__wbindgen_exn_store(idx);
|
|
24
106
|
}
|
|
25
107
|
}
|
|
26
108
|
|
|
27
|
-
function
|
|
109
|
+
function isLikeNone(x) {
|
|
110
|
+
return x === undefined || x === null;
|
|
111
|
+
}
|
|
28
112
|
|
|
113
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
114
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
115
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
116
|
+
WASM_VECTOR_LEN = arg.length;
|
|
117
|
+
return ptr;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
29
121
|
if (realloc === undefined) {
|
|
30
122
|
const buf = cachedTextEncoder.encode(arg);
|
|
31
123
|
const ptr = malloc(buf.length, 1) >>> 0;
|
|
@@ -46,7 +138,6 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
46
138
|
if (code > 0x7F) break;
|
|
47
139
|
mem[ptr + offset] = code;
|
|
48
140
|
}
|
|
49
|
-
|
|
50
141
|
if (offset !== len) {
|
|
51
142
|
if (offset !== 0) {
|
|
52
143
|
arg = arg.slice(offset);
|
|
@@ -62,6 +153,59 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
62
153
|
WASM_VECTOR_LEN = offset;
|
|
63
154
|
return ptr;
|
|
64
155
|
}
|
|
156
|
+
|
|
157
|
+
function takeFromExternrefTable0(idx) {
|
|
158
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
159
|
+
wasm.__externref_table_dealloc(idx);
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
164
|
+
cachedTextDecoder.decode();
|
|
165
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
166
|
+
let numBytesDecoded = 0;
|
|
167
|
+
function decodeText(ptr, len) {
|
|
168
|
+
numBytesDecoded += len;
|
|
169
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
170
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
171
|
+
cachedTextDecoder.decode();
|
|
172
|
+
numBytesDecoded = len;
|
|
173
|
+
}
|
|
174
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const cachedTextEncoder = new TextEncoder();
|
|
178
|
+
|
|
179
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
180
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
181
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
182
|
+
view.set(buf);
|
|
183
|
+
return {
|
|
184
|
+
read: arg.length,
|
|
185
|
+
written: buf.length
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let WASM_VECTOR_LEN = 0;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @param {Uint8Array} bytes
|
|
194
|
+
* @param {any} custom_sections
|
|
195
|
+
* @returns {Uint8Array}
|
|
196
|
+
*/
|
|
197
|
+
export function add_custom_sections(bytes, custom_sections) {
|
|
198
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
199
|
+
const len0 = WASM_VECTOR_LEN;
|
|
200
|
+
const ret = wasm.add_custom_sections(ptr0, len0, custom_sections);
|
|
201
|
+
if (ret[3]) {
|
|
202
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
203
|
+
}
|
|
204
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
205
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
206
|
+
return v2;
|
|
207
|
+
}
|
|
208
|
+
|
|
65
209
|
/**
|
|
66
210
|
* @param {string} new_interface
|
|
67
211
|
* @param {string} original_interface
|
|
@@ -83,7 +227,6 @@ async function __wbg_load(module, imports) {
|
|
|
83
227
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
84
228
|
try {
|
|
85
229
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
86
|
-
|
|
87
230
|
} catch (e) {
|
|
88
231
|
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
89
232
|
|
|
@@ -98,13 +241,11 @@ async function __wbg_load(module, imports) {
|
|
|
98
241
|
|
|
99
242
|
const bytes = await module.arrayBuffer();
|
|
100
243
|
return await WebAssembly.instantiate(bytes, imports);
|
|
101
|
-
|
|
102
244
|
} else {
|
|
103
245
|
const instance = await WebAssembly.instantiate(module, imports);
|
|
104
246
|
|
|
105
247
|
if (instance instanceof WebAssembly.Instance) {
|
|
106
248
|
return { instance, module };
|
|
107
|
-
|
|
108
249
|
} else {
|
|
109
250
|
return instance;
|
|
110
251
|
}
|
|
@@ -114,6 +255,147 @@ async function __wbg_load(module, imports) {
|
|
|
114
255
|
function __wbg_get_imports() {
|
|
115
256
|
const imports = {};
|
|
116
257
|
imports.wbg = {};
|
|
258
|
+
imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
|
|
259
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
260
|
+
return ret;
|
|
261
|
+
};
|
|
262
|
+
imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
|
263
|
+
const ret = String(arg1);
|
|
264
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
265
|
+
const len1 = WASM_VECTOR_LEN;
|
|
266
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
267
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
268
|
+
};
|
|
269
|
+
imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) {
|
|
270
|
+
const v = arg0;
|
|
271
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
272
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
273
|
+
};
|
|
274
|
+
imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
|
|
275
|
+
const ret = debugString(arg1);
|
|
276
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
277
|
+
const len1 = WASM_VECTOR_LEN;
|
|
278
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
279
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
280
|
+
};
|
|
281
|
+
imports.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317 = function(arg0, arg1) {
|
|
282
|
+
const ret = arg0 in arg1;
|
|
283
|
+
return ret;
|
|
284
|
+
};
|
|
285
|
+
imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
|
|
286
|
+
const ret = typeof(arg0) === 'function';
|
|
287
|
+
return ret;
|
|
288
|
+
};
|
|
289
|
+
imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
|
|
290
|
+
const val = arg0;
|
|
291
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
292
|
+
return ret;
|
|
293
|
+
};
|
|
294
|
+
imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
|
|
295
|
+
const ret = arg0 === undefined;
|
|
296
|
+
return ret;
|
|
297
|
+
};
|
|
298
|
+
imports.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d = function(arg0, arg1) {
|
|
299
|
+
const ret = arg0 == arg1;
|
|
300
|
+
return ret;
|
|
301
|
+
};
|
|
302
|
+
imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
|
|
303
|
+
const obj = arg1;
|
|
304
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
305
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
306
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
307
|
+
};
|
|
308
|
+
imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
|
|
309
|
+
const obj = arg1;
|
|
310
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
311
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
312
|
+
var len1 = WASM_VECTOR_LEN;
|
|
313
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
314
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
315
|
+
};
|
|
316
|
+
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
317
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
318
|
+
};
|
|
319
|
+
imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
|
|
320
|
+
const ret = arg0.call(arg1);
|
|
321
|
+
return ret;
|
|
322
|
+
}, arguments) };
|
|
323
|
+
imports.wbg.__wbg_done_62ea16af4ce34b24 = function(arg0) {
|
|
324
|
+
const ret = arg0.done;
|
|
325
|
+
return ret;
|
|
326
|
+
};
|
|
327
|
+
imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
|
|
328
|
+
const ret = arg0[arg1 >>> 0];
|
|
329
|
+
return ret;
|
|
330
|
+
};
|
|
331
|
+
imports.wbg.__wbg_get_af9dab7e9603ea93 = function() { return handleError(function (arg0, arg1) {
|
|
332
|
+
const ret = Reflect.get(arg0, arg1);
|
|
333
|
+
return ret;
|
|
334
|
+
}, arguments) };
|
|
335
|
+
imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
|
|
336
|
+
const ret = arg0[arg1];
|
|
337
|
+
return ret;
|
|
338
|
+
};
|
|
339
|
+
imports.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355 = function(arg0) {
|
|
340
|
+
let result;
|
|
341
|
+
try {
|
|
342
|
+
result = arg0 instanceof ArrayBuffer;
|
|
343
|
+
} catch (_) {
|
|
344
|
+
result = false;
|
|
345
|
+
}
|
|
346
|
+
const ret = result;
|
|
347
|
+
return ret;
|
|
348
|
+
};
|
|
349
|
+
imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) {
|
|
350
|
+
let result;
|
|
351
|
+
try {
|
|
352
|
+
result = arg0 instanceof Uint8Array;
|
|
353
|
+
} catch (_) {
|
|
354
|
+
result = false;
|
|
355
|
+
}
|
|
356
|
+
const ret = result;
|
|
357
|
+
return ret;
|
|
358
|
+
};
|
|
359
|
+
imports.wbg.__wbg_isArray_51fd9e6422c0a395 = function(arg0) {
|
|
360
|
+
const ret = Array.isArray(arg0);
|
|
361
|
+
return ret;
|
|
362
|
+
};
|
|
363
|
+
imports.wbg.__wbg_iterator_27b7c8b35ab3e86b = function() {
|
|
364
|
+
const ret = Symbol.iterator;
|
|
365
|
+
return ret;
|
|
366
|
+
};
|
|
367
|
+
imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
|
|
368
|
+
const ret = arg0.length;
|
|
369
|
+
return ret;
|
|
370
|
+
};
|
|
371
|
+
imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) {
|
|
372
|
+
const ret = arg0.length;
|
|
373
|
+
return ret;
|
|
374
|
+
};
|
|
375
|
+
imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) {
|
|
376
|
+
const ret = new Uint8Array(arg0);
|
|
377
|
+
return ret;
|
|
378
|
+
};
|
|
379
|
+
imports.wbg.__wbg_next_138a17bbf04e926c = function(arg0) {
|
|
380
|
+
const ret = arg0.next;
|
|
381
|
+
return ret;
|
|
382
|
+
};
|
|
383
|
+
imports.wbg.__wbg_next_3cfe5c0fe2a4cc53 = function() { return handleError(function (arg0) {
|
|
384
|
+
const ret = arg0.next();
|
|
385
|
+
return ret;
|
|
386
|
+
}, arguments) };
|
|
387
|
+
imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
|
|
388
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
389
|
+
};
|
|
390
|
+
imports.wbg.__wbg_value_57b7b035e117f7ee = function(arg0) {
|
|
391
|
+
const ret = arg0.value;
|
|
392
|
+
return ret;
|
|
393
|
+
};
|
|
394
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
395
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
396
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
397
|
+
return ret;
|
|
398
|
+
};
|
|
117
399
|
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
118
400
|
const table = wasm.__wbindgen_externrefs;
|
|
119
401
|
const offset = table.grow(4);
|
|
@@ -122,7 +404,6 @@ function __wbg_get_imports() {
|
|
|
122
404
|
table.set(offset + 1, null);
|
|
123
405
|
table.set(offset + 2, true);
|
|
124
406
|
table.set(offset + 3, false);
|
|
125
|
-
;
|
|
126
407
|
};
|
|
127
408
|
|
|
128
409
|
return imports;
|
|
@@ -131,6 +412,7 @@ function __wbg_get_imports() {
|
|
|
131
412
|
function __wbg_finalize_init(instance, module) {
|
|
132
413
|
wasm = instance.exports;
|
|
133
414
|
__wbg_init.__wbindgen_wasm_module = module;
|
|
415
|
+
cachedDataViewMemory0 = null;
|
|
134
416
|
cachedUint8ArrayMemory0 = null;
|
|
135
417
|
|
|
136
418
|
|
|
@@ -151,13 +433,10 @@ function initSync(module) {
|
|
|
151
433
|
}
|
|
152
434
|
|
|
153
435
|
const imports = __wbg_get_imports();
|
|
154
|
-
|
|
155
436
|
if (!(module instanceof WebAssembly.Module)) {
|
|
156
437
|
module = new WebAssembly.Module(module);
|
|
157
438
|
}
|
|
158
|
-
|
|
159
439
|
const instance = new WebAssembly.Instance(module, imports);
|
|
160
|
-
|
|
161
440
|
return __wbg_finalize_init(instance, module);
|
|
162
441
|
}
|
|
163
442
|
|
|
Binary file
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const is_candid_compatible: (a: number, b: number, c: number, d: number) => number;
|
|
5
|
-
export const
|
|
5
|
+
export const add_custom_sections: (a: number, b: number, c: any) => [number, number, number, number];
|
|
6
6
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
7
7
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
8
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
9
|
+
export const __externref_table_alloc: () => number;
|
|
10
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
11
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
12
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
8
13
|
export const __wbindgen_start: () => void;
|
package/wasm/src/lib.rs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
+
mod utils;
|
|
2
|
+
mod wasm_utils;
|
|
3
|
+
|
|
1
4
|
use candid_parser::utils::{service_compatible, CandidSource};
|
|
2
5
|
use wasm_bindgen::prelude::*;
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
// pub fn start() {
|
|
6
|
-
// #[cfg(feature = "console_error_panic_hook")]
|
|
7
|
-
// console_error_panic_hook::set_once();
|
|
8
|
-
// }
|
|
7
|
+
use crate::utils::{js_value, JsResult};
|
|
9
8
|
|
|
10
9
|
#[wasm_bindgen]
|
|
11
10
|
pub fn is_candid_compatible(new_interface: &str, original_interface: &str) -> bool {
|
|
@@ -15,3 +14,9 @@ pub fn is_candid_compatible(new_interface: &str, original_interface: &str) -> bo
|
|
|
15
14
|
)
|
|
16
15
|
.is_ok()
|
|
17
16
|
}
|
|
17
|
+
|
|
18
|
+
#[wasm_bindgen]
|
|
19
|
+
pub fn add_custom_sections(bytes: &[u8], custom_sections: JsValue) -> JsResult<Vec<u8>> {
|
|
20
|
+
wasm_utils::add_custom_sections(bytes, js_value(custom_sections)?)
|
|
21
|
+
.map_err(|e| JsError::new(&e.to_string()))
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#![allow(dead_code)]
|
|
2
|
+
|
|
3
|
+
use serde::{de::DeserializeOwned, Serialize};
|
|
4
|
+
use serde_wasm_bindgen::{from_value, to_value};
|
|
5
|
+
use wasm_bindgen::{JsError, JsValue};
|
|
6
|
+
|
|
7
|
+
pub type JsResult<T = JsValue> = Result<T, JsError>;
|
|
8
|
+
|
|
9
|
+
pub fn js_value<T: DeserializeOwned>(value: JsValue) -> Result<T, JsError> {
|
|
10
|
+
from_value(value).map_err(|e| JsError::new(&format!("Deserialization error: {}", e)).into())
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
pub fn js_return<T: Serialize + ?Sized>(value: &T) -> JsResult {
|
|
14
|
+
to_value(value).map_err(|e| JsError::new(&format!("Serialization error: {}", e)))
|
|
15
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
use serde::{Deserialize, Serialize};
|
|
2
|
+
use std::borrow::Cow;
|
|
3
|
+
use std::io::{self, Read};
|
|
4
|
+
use walrus::{Module, RawCustomSection};
|
|
5
|
+
|
|
6
|
+
pub const WASM_MAGIC_BYTES: &[u8] = &[0, 97, 115, 109];
|
|
7
|
+
pub const GZIPPED_WASM_MAGIC_BYTES: &[u8] = &[31, 139, 8];
|
|
8
|
+
|
|
9
|
+
#[derive(Debug)]
|
|
10
|
+
pub enum Error {
|
|
11
|
+
IO(std::io::Error),
|
|
12
|
+
WasmParse(String),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
impl std::fmt::Display for Error {
|
|
16
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
17
|
+
match self {
|
|
18
|
+
Error::IO(e) => write!(f, "IO error: {}", e),
|
|
19
|
+
Error::WasmParse(e) => write!(f, "WASM parse error: {}", e),
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
impl std::error::Error for Error {}
|
|
25
|
+
|
|
26
|
+
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
27
|
+
pub struct CustomSection {
|
|
28
|
+
pub name: String,
|
|
29
|
+
pub data: String,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub fn add_custom_sections(
|
|
33
|
+
bytes: &[u8],
|
|
34
|
+
custom_sections: Vec<CustomSection>,
|
|
35
|
+
) -> Result<Vec<u8>, Error> {
|
|
36
|
+
let mut module = parse_wasm(&bytes, false)?;
|
|
37
|
+
for m in &custom_sections {
|
|
38
|
+
module.customs.remove_raw(&m.name);
|
|
39
|
+
}
|
|
40
|
+
for m in custom_sections {
|
|
41
|
+
module.customs.add(RawCustomSection {
|
|
42
|
+
name: m.name,
|
|
43
|
+
data: m.data.as_bytes().to_vec(),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
Ok(module.emit_wasm())
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pub fn wasm_parser_config(keep_name_section: bool) -> walrus::ModuleConfig {
|
|
50
|
+
let mut config = walrus::ModuleConfig::new();
|
|
51
|
+
config.generate_name_section(keep_name_section);
|
|
52
|
+
config.generate_producers_section(false);
|
|
53
|
+
config
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub fn decompress(bytes: &[u8]) -> Result<Vec<u8>, std::io::Error> {
|
|
57
|
+
let mut decoder = libflate::gzip::Decoder::new(bytes)?;
|
|
58
|
+
let mut decoded_data = Vec::new();
|
|
59
|
+
decoder.read_to_end(&mut decoded_data)?;
|
|
60
|
+
Ok(decoded_data)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
pub fn parse_wasm(bytes: &[u8], keep_name_section: bool) -> Result<Module, Error> {
|
|
64
|
+
let wasm = if bytes.starts_with(WASM_MAGIC_BYTES) {
|
|
65
|
+
Ok(Cow::Borrowed(bytes))
|
|
66
|
+
} else if bytes.starts_with(GZIPPED_WASM_MAGIC_BYTES) {
|
|
67
|
+
decompress(bytes).map(Cow::Owned)
|
|
68
|
+
} else {
|
|
69
|
+
Err(io::Error::new(
|
|
70
|
+
io::ErrorKind::InvalidInput,
|
|
71
|
+
"Input must be either gzipped or uncompressed WASM.",
|
|
72
|
+
))
|
|
73
|
+
}
|
|
74
|
+
.map_err(Error::IO)?;
|
|
75
|
+
let config = wasm_parser_config(keep_name_section);
|
|
76
|
+
config
|
|
77
|
+
.parse(&wasm)
|
|
78
|
+
.map_err(|e| Error::WasmParse(e.to_string()))
|
|
79
|
+
}
|
package/wasm.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
export interface CustomSection {
|
|
2
|
+
name: string;
|
|
3
|
+
data: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
export interface WasmBindings {
|
|
2
|
-
is_candid_compatible: (
|
|
7
|
+
is_candid_compatible: (newCandid: string, originalCandid: string) => boolean;
|
|
8
|
+
add_custom_sections: (
|
|
9
|
+
bytes: Uint8Array,
|
|
10
|
+
customSections: CustomSection[],
|
|
11
|
+
) => Uint8Array;
|
|
3
12
|
}
|
|
4
13
|
|
|
5
14
|
let bindings: WasmBindings | undefined;
|