@rustledger/wasm 1.0.0-rc.5
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 +173 -0
- package/package.json +32 -0
- package/rustledger_wasm.d.ts +413 -0
- package/rustledger_wasm.js +828 -0
- package/rustledger_wasm_bg.wasm +0 -0
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
function addHeapObject(obj) {
|
|
4
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
5
|
+
const idx = heap_next;
|
|
6
|
+
heap_next = heap[idx];
|
|
7
|
+
|
|
8
|
+
heap[idx] = obj;
|
|
9
|
+
return idx;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function dropObject(idx) {
|
|
13
|
+
if (idx < 132) return;
|
|
14
|
+
heap[idx] = heap_next;
|
|
15
|
+
heap_next = idx;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let cachedDataViewMemory0 = null;
|
|
19
|
+
function getDataViewMemory0() {
|
|
20
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
21
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
22
|
+
}
|
|
23
|
+
return cachedDataViewMemory0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getStringFromWasm0(ptr, len) {
|
|
27
|
+
ptr = ptr >>> 0;
|
|
28
|
+
return decodeText(ptr, len);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let cachedUint8ArrayMemory0 = null;
|
|
32
|
+
function getUint8ArrayMemory0() {
|
|
33
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
34
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
35
|
+
}
|
|
36
|
+
return cachedUint8ArrayMemory0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getObject(idx) { return heap[idx]; }
|
|
40
|
+
|
|
41
|
+
let heap = new Array(128).fill(undefined);
|
|
42
|
+
heap.push(undefined, null, true, false);
|
|
43
|
+
|
|
44
|
+
let heap_next = heap.length;
|
|
45
|
+
|
|
46
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
47
|
+
if (realloc === undefined) {
|
|
48
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
49
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
50
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
51
|
+
WASM_VECTOR_LEN = buf.length;
|
|
52
|
+
return ptr;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let len = arg.length;
|
|
56
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
57
|
+
|
|
58
|
+
const mem = getUint8ArrayMemory0();
|
|
59
|
+
|
|
60
|
+
let offset = 0;
|
|
61
|
+
|
|
62
|
+
for (; offset < len; offset++) {
|
|
63
|
+
const code = arg.charCodeAt(offset);
|
|
64
|
+
if (code > 0x7F) break;
|
|
65
|
+
mem[ptr + offset] = code;
|
|
66
|
+
}
|
|
67
|
+
if (offset !== len) {
|
|
68
|
+
if (offset !== 0) {
|
|
69
|
+
arg = arg.slice(offset);
|
|
70
|
+
}
|
|
71
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
72
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
73
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
74
|
+
|
|
75
|
+
offset += ret.written;
|
|
76
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
WASM_VECTOR_LEN = offset;
|
|
80
|
+
return ptr;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function takeObject(idx) {
|
|
84
|
+
const ret = getObject(idx);
|
|
85
|
+
dropObject(idx);
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
90
|
+
cachedTextDecoder.decode();
|
|
91
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
92
|
+
let numBytesDecoded = 0;
|
|
93
|
+
function decodeText(ptr, len) {
|
|
94
|
+
numBytesDecoded += len;
|
|
95
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
96
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
97
|
+
cachedTextDecoder.decode();
|
|
98
|
+
numBytesDecoded = len;
|
|
99
|
+
}
|
|
100
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const cachedTextEncoder = new TextEncoder();
|
|
104
|
+
|
|
105
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
106
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
107
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
108
|
+
view.set(buf);
|
|
109
|
+
return {
|
|
110
|
+
read: arg.length,
|
|
111
|
+
written: buf.length
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let WASM_VECTOR_LEN = 0;
|
|
117
|
+
|
|
118
|
+
const ParsedLedgerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
119
|
+
? { register: () => {}, unregister: () => {} }
|
|
120
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_parsedledger_free(ptr >>> 0, 1));
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A parsed and validated ledger that caches the parse result.
|
|
124
|
+
*
|
|
125
|
+
* Use this class when you need to perform multiple operations on the same
|
|
126
|
+
* source without re-parsing each time.
|
|
127
|
+
*
|
|
128
|
+
* # Example (JavaScript)
|
|
129
|
+
*
|
|
130
|
+
* ```javascript
|
|
131
|
+
* const ledger = new ParsedLedger(source);
|
|
132
|
+
* if (ledger.isValid()) {
|
|
133
|
+
* const balances = ledger.query("BALANCES");
|
|
134
|
+
* const formatted = ledger.format();
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export class ParsedLedger {
|
|
139
|
+
__destroy_into_raw() {
|
|
140
|
+
const ptr = this.__wbg_ptr;
|
|
141
|
+
this.__wbg_ptr = 0;
|
|
142
|
+
ParsedLedgerFinalization.unregister(this);
|
|
143
|
+
return ptr;
|
|
144
|
+
}
|
|
145
|
+
free() {
|
|
146
|
+
const ptr = this.__destroy_into_raw();
|
|
147
|
+
wasm.__wbg_parsedledger_free(ptr, 0);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get all errors (parse + validation).
|
|
151
|
+
* @returns {any}
|
|
152
|
+
*/
|
|
153
|
+
getErrors() {
|
|
154
|
+
try {
|
|
155
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
156
|
+
wasm.parsedledger_getErrors(retptr, this.__wbg_ptr);
|
|
157
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
158
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
159
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
160
|
+
if (r2) {
|
|
161
|
+
throw takeObject(r1);
|
|
162
|
+
}
|
|
163
|
+
return takeObject(r0);
|
|
164
|
+
} finally {
|
|
165
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Run a native plugin on this ledger.
|
|
170
|
+
* @param {string} plugin_name
|
|
171
|
+
* @returns {any}
|
|
172
|
+
*/
|
|
173
|
+
runPlugin(plugin_name) {
|
|
174
|
+
try {
|
|
175
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
176
|
+
const ptr0 = passStringToWasm0(plugin_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
177
|
+
const len0 = WASM_VECTOR_LEN;
|
|
178
|
+
wasm.parsedledger_runPlugin(retptr, this.__wbg_ptr, ptr0, len0);
|
|
179
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
180
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
181
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
182
|
+
if (r2) {
|
|
183
|
+
throw takeObject(r1);
|
|
184
|
+
}
|
|
185
|
+
return takeObject(r0);
|
|
186
|
+
} finally {
|
|
187
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Expand pad directives.
|
|
192
|
+
* @returns {any}
|
|
193
|
+
*/
|
|
194
|
+
expandPads() {
|
|
195
|
+
try {
|
|
196
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
197
|
+
wasm.parsedledger_expandPads(retptr, this.__wbg_ptr);
|
|
198
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
199
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
200
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
201
|
+
if (r2) {
|
|
202
|
+
throw takeObject(r1);
|
|
203
|
+
}
|
|
204
|
+
return takeObject(r0);
|
|
205
|
+
} finally {
|
|
206
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get the ledger options.
|
|
211
|
+
* @returns {any}
|
|
212
|
+
*/
|
|
213
|
+
getOptions() {
|
|
214
|
+
try {
|
|
215
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
216
|
+
wasm.parsedledger_getOptions(retptr, this.__wbg_ptr);
|
|
217
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
218
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
219
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
220
|
+
if (r2) {
|
|
221
|
+
throw takeObject(r1);
|
|
222
|
+
}
|
|
223
|
+
return takeObject(r0);
|
|
224
|
+
} finally {
|
|
225
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get the parsed directives.
|
|
230
|
+
* @returns {any}
|
|
231
|
+
*/
|
|
232
|
+
getDirectives() {
|
|
233
|
+
try {
|
|
234
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
235
|
+
wasm.parsedledger_getDirectives(retptr, this.__wbg_ptr);
|
|
236
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
237
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
238
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
239
|
+
if (r2) {
|
|
240
|
+
throw takeObject(r1);
|
|
241
|
+
}
|
|
242
|
+
return takeObject(r0);
|
|
243
|
+
} finally {
|
|
244
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get the number of directives.
|
|
249
|
+
* @returns {number}
|
|
250
|
+
*/
|
|
251
|
+
directiveCount() {
|
|
252
|
+
const ret = wasm.parsedledger_directiveCount(this.__wbg_ptr);
|
|
253
|
+
return ret >>> 0;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get parse errors only.
|
|
257
|
+
* @returns {any}
|
|
258
|
+
*/
|
|
259
|
+
getParseErrors() {
|
|
260
|
+
try {
|
|
261
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
262
|
+
wasm.parsedledger_getParseErrors(retptr, this.__wbg_ptr);
|
|
263
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
264
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
265
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
266
|
+
if (r2) {
|
|
267
|
+
throw takeObject(r1);
|
|
268
|
+
}
|
|
269
|
+
return takeObject(r0);
|
|
270
|
+
} finally {
|
|
271
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get validation errors only.
|
|
276
|
+
* @returns {any}
|
|
277
|
+
*/
|
|
278
|
+
getValidationErrors() {
|
|
279
|
+
try {
|
|
280
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
281
|
+
wasm.parsedledger_getValidationErrors(retptr, this.__wbg_ptr);
|
|
282
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
283
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
284
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
285
|
+
if (r2) {
|
|
286
|
+
throw takeObject(r1);
|
|
287
|
+
}
|
|
288
|
+
return takeObject(r0);
|
|
289
|
+
} finally {
|
|
290
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Create a new `ParsedLedger` from source text.
|
|
295
|
+
*
|
|
296
|
+
* Parses, interpolates, and validates the source. Call `isValid()` to check for errors.
|
|
297
|
+
* @param {string} source
|
|
298
|
+
*/
|
|
299
|
+
constructor(source) {
|
|
300
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
301
|
+
const len0 = WASM_VECTOR_LEN;
|
|
302
|
+
const ret = wasm.parsedledger_new(ptr0, len0);
|
|
303
|
+
this.__wbg_ptr = ret >>> 0;
|
|
304
|
+
ParsedLedgerFinalization.register(this, this.__wbg_ptr, this);
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Run a BQL query on this ledger.
|
|
309
|
+
* @param {string} query_str
|
|
310
|
+
* @returns {any}
|
|
311
|
+
*/
|
|
312
|
+
query(query_str) {
|
|
313
|
+
try {
|
|
314
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
315
|
+
const ptr0 = passStringToWasm0(query_str, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
316
|
+
const len0 = WASM_VECTOR_LEN;
|
|
317
|
+
wasm.parsedledger_query(retptr, this.__wbg_ptr, ptr0, len0);
|
|
318
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
319
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
320
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
321
|
+
if (r2) {
|
|
322
|
+
throw takeObject(r1);
|
|
323
|
+
}
|
|
324
|
+
return takeObject(r0);
|
|
325
|
+
} finally {
|
|
326
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Format the ledger source.
|
|
331
|
+
* @returns {any}
|
|
332
|
+
*/
|
|
333
|
+
format() {
|
|
334
|
+
try {
|
|
335
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
336
|
+
wasm.parsedledger_format(retptr, this.__wbg_ptr);
|
|
337
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
338
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
339
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
340
|
+
if (r2) {
|
|
341
|
+
throw takeObject(r1);
|
|
342
|
+
}
|
|
343
|
+
return takeObject(r0);
|
|
344
|
+
} finally {
|
|
345
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Get account balances (shorthand for query("BALANCES")).
|
|
350
|
+
* @returns {any}
|
|
351
|
+
*/
|
|
352
|
+
balances() {
|
|
353
|
+
try {
|
|
354
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
355
|
+
wasm.parsedledger_balances(retptr, this.__wbg_ptr);
|
|
356
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
357
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
358
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
359
|
+
if (r2) {
|
|
360
|
+
throw takeObject(r1);
|
|
361
|
+
}
|
|
362
|
+
return takeObject(r0);
|
|
363
|
+
} finally {
|
|
364
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Check if the ledger is valid (no parse or validation errors).
|
|
369
|
+
* @returns {boolean}
|
|
370
|
+
*/
|
|
371
|
+
isValid() {
|
|
372
|
+
const ret = wasm.parsedledger_isValid(this.__wbg_ptr);
|
|
373
|
+
return ret !== 0;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (Symbol.dispose) ParsedLedger.prototype[Symbol.dispose] = ParsedLedger.prototype.free;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Calculate account balances.
|
|
380
|
+
*
|
|
381
|
+
* Shorthand for `query(source, "BALANCES")`.
|
|
382
|
+
* @param {string} source
|
|
383
|
+
* @returns {any}
|
|
384
|
+
*/
|
|
385
|
+
export function balances(source) {
|
|
386
|
+
try {
|
|
387
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
388
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
389
|
+
const len0 = WASM_VECTOR_LEN;
|
|
390
|
+
wasm.balances(retptr, ptr0, len0);
|
|
391
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
392
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
393
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
394
|
+
if (r2) {
|
|
395
|
+
throw takeObject(r1);
|
|
396
|
+
}
|
|
397
|
+
return takeObject(r0);
|
|
398
|
+
} finally {
|
|
399
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Get BQL query completions at cursor position.
|
|
405
|
+
*
|
|
406
|
+
* Returns context-aware completions for the BQL query language.
|
|
407
|
+
* @param {string} partial_query
|
|
408
|
+
* @param {number} cursor_pos
|
|
409
|
+
* @returns {any}
|
|
410
|
+
*/
|
|
411
|
+
export function bqlCompletions(partial_query, cursor_pos) {
|
|
412
|
+
try {
|
|
413
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
414
|
+
const ptr0 = passStringToWasm0(partial_query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
415
|
+
const len0 = WASM_VECTOR_LEN;
|
|
416
|
+
wasm.bqlCompletions(retptr, ptr0, len0, cursor_pos);
|
|
417
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
418
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
419
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
420
|
+
if (r2) {
|
|
421
|
+
throw takeObject(r1);
|
|
422
|
+
}
|
|
423
|
+
return takeObject(r0);
|
|
424
|
+
} finally {
|
|
425
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Process pad directives and expand them.
|
|
431
|
+
*
|
|
432
|
+
* Returns directives with pad-generated transactions included.
|
|
433
|
+
* @param {string} source
|
|
434
|
+
* @returns {any}
|
|
435
|
+
*/
|
|
436
|
+
export function expandPads(source) {
|
|
437
|
+
try {
|
|
438
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
439
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
440
|
+
const len0 = WASM_VECTOR_LEN;
|
|
441
|
+
wasm.expandPads(retptr, ptr0, len0);
|
|
442
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
443
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
444
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
445
|
+
if (r2) {
|
|
446
|
+
throw takeObject(r1);
|
|
447
|
+
}
|
|
448
|
+
return takeObject(r0);
|
|
449
|
+
} finally {
|
|
450
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Format a Beancount source string.
|
|
456
|
+
*
|
|
457
|
+
* Parses and reformats with consistent alignment.
|
|
458
|
+
* Returns a `FormatResult` with the formatted source or errors.
|
|
459
|
+
* @param {string} source
|
|
460
|
+
* @returns {any}
|
|
461
|
+
*/
|
|
462
|
+
export function format(source) {
|
|
463
|
+
try {
|
|
464
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
465
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
466
|
+
const len0 = WASM_VECTOR_LEN;
|
|
467
|
+
wasm.format(retptr, ptr0, len0);
|
|
468
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
469
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
470
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
471
|
+
if (r2) {
|
|
472
|
+
throw takeObject(r1);
|
|
473
|
+
}
|
|
474
|
+
return takeObject(r0);
|
|
475
|
+
} finally {
|
|
476
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Initialize the WASM module.
|
|
482
|
+
*
|
|
483
|
+
* This sets up panic hooks for better error messages in the browser console.
|
|
484
|
+
* Call this once before using any other functions.
|
|
485
|
+
*/
|
|
486
|
+
export function init() {
|
|
487
|
+
wasm.init();
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* List available native plugins.
|
|
492
|
+
*
|
|
493
|
+
* Returns an array of `PluginInfo` objects with name and description.
|
|
494
|
+
* @returns {any}
|
|
495
|
+
*/
|
|
496
|
+
export function listPlugins() {
|
|
497
|
+
try {
|
|
498
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
499
|
+
wasm.listPlugins(retptr);
|
|
500
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
501
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
502
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
503
|
+
if (r2) {
|
|
504
|
+
throw takeObject(r1);
|
|
505
|
+
}
|
|
506
|
+
return takeObject(r0);
|
|
507
|
+
} finally {
|
|
508
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Parse a Beancount source string.
|
|
514
|
+
*
|
|
515
|
+
* Returns a `ParseResult` with the parsed ledger and any errors.
|
|
516
|
+
* @param {string} source
|
|
517
|
+
* @returns {any}
|
|
518
|
+
*/
|
|
519
|
+
export function parse(source) {
|
|
520
|
+
try {
|
|
521
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
522
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
523
|
+
const len0 = WASM_VECTOR_LEN;
|
|
524
|
+
wasm.parse(retptr, ptr0, len0);
|
|
525
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
526
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
527
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
528
|
+
if (r2) {
|
|
529
|
+
throw takeObject(r1);
|
|
530
|
+
}
|
|
531
|
+
return takeObject(r0);
|
|
532
|
+
} finally {
|
|
533
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Run a BQL query on a Beancount source string.
|
|
539
|
+
*
|
|
540
|
+
* Parses the source, interpolates, then executes the query.
|
|
541
|
+
* Returns a `QueryResult` with columns, rows, and any errors.
|
|
542
|
+
* @param {string} source
|
|
543
|
+
* @param {string} query_str
|
|
544
|
+
* @returns {any}
|
|
545
|
+
*/
|
|
546
|
+
export function query(source, query_str) {
|
|
547
|
+
try {
|
|
548
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
549
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
550
|
+
const len0 = WASM_VECTOR_LEN;
|
|
551
|
+
const ptr1 = passStringToWasm0(query_str, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
552
|
+
const len1 = WASM_VECTOR_LEN;
|
|
553
|
+
wasm.query(retptr, ptr0, len0, ptr1, len1);
|
|
554
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
555
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
556
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
557
|
+
if (r2) {
|
|
558
|
+
throw takeObject(r1);
|
|
559
|
+
}
|
|
560
|
+
return takeObject(r0);
|
|
561
|
+
} finally {
|
|
562
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Run a native plugin on the source.
|
|
568
|
+
*
|
|
569
|
+
* Available plugins can be listed with `listPlugins()`.
|
|
570
|
+
* @param {string} source
|
|
571
|
+
* @param {string} plugin_name
|
|
572
|
+
* @returns {any}
|
|
573
|
+
*/
|
|
574
|
+
export function runPlugin(source, plugin_name) {
|
|
575
|
+
try {
|
|
576
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
577
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
578
|
+
const len0 = WASM_VECTOR_LEN;
|
|
579
|
+
const ptr1 = passStringToWasm0(plugin_name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
580
|
+
const len1 = WASM_VECTOR_LEN;
|
|
581
|
+
wasm.runPlugin(retptr, ptr0, len0, ptr1, len1);
|
|
582
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
583
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
584
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
585
|
+
if (r2) {
|
|
586
|
+
throw takeObject(r1);
|
|
587
|
+
}
|
|
588
|
+
return takeObject(r0);
|
|
589
|
+
} finally {
|
|
590
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Validate a Beancount source string.
|
|
596
|
+
*
|
|
597
|
+
* Parses, interpolates, and validates in one step.
|
|
598
|
+
* Returns a `ValidationResult` indicating whether the ledger is valid.
|
|
599
|
+
* @param {string} source
|
|
600
|
+
* @returns {any}
|
|
601
|
+
*/
|
|
602
|
+
export function validateSource(source) {
|
|
603
|
+
try {
|
|
604
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
605
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
606
|
+
const len0 = WASM_VECTOR_LEN;
|
|
607
|
+
wasm.validateSource(retptr, ptr0, len0);
|
|
608
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
609
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
610
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
611
|
+
if (r2) {
|
|
612
|
+
throw takeObject(r1);
|
|
613
|
+
}
|
|
614
|
+
return takeObject(r0);
|
|
615
|
+
} finally {
|
|
616
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Get version information.
|
|
622
|
+
*
|
|
623
|
+
* Returns the version string of the rustledger-wasm package.
|
|
624
|
+
* @returns {string}
|
|
625
|
+
*/
|
|
626
|
+
export function version() {
|
|
627
|
+
let deferred1_0;
|
|
628
|
+
let deferred1_1;
|
|
629
|
+
try {
|
|
630
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
631
|
+
wasm.version(retptr);
|
|
632
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
633
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
634
|
+
deferred1_0 = r0;
|
|
635
|
+
deferred1_1 = r1;
|
|
636
|
+
return getStringFromWasm0(r0, r1);
|
|
637
|
+
} finally {
|
|
638
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
639
|
+
wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
644
|
+
|
|
645
|
+
async function __wbg_load(module, imports) {
|
|
646
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
647
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
648
|
+
try {
|
|
649
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
650
|
+
} catch (e) {
|
|
651
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
652
|
+
|
|
653
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
654
|
+
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);
|
|
655
|
+
|
|
656
|
+
} else {
|
|
657
|
+
throw e;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const bytes = await module.arrayBuffer();
|
|
663
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
664
|
+
} else {
|
|
665
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
666
|
+
|
|
667
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
668
|
+
return { instance, module };
|
|
669
|
+
} else {
|
|
670
|
+
return instance;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function __wbg_get_imports() {
|
|
676
|
+
const imports = {};
|
|
677
|
+
imports.wbg = {};
|
|
678
|
+
imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
|
|
679
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
680
|
+
return addHeapObject(ret);
|
|
681
|
+
};
|
|
682
|
+
imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
|
683
|
+
const ret = String(getObject(arg1));
|
|
684
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
685
|
+
const len1 = WASM_VECTOR_LEN;
|
|
686
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
687
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
688
|
+
};
|
|
689
|
+
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
690
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
691
|
+
};
|
|
692
|
+
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
693
|
+
let deferred0_0;
|
|
694
|
+
let deferred0_1;
|
|
695
|
+
try {
|
|
696
|
+
deferred0_0 = arg0;
|
|
697
|
+
deferred0_1 = arg1;
|
|
698
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
699
|
+
} finally {
|
|
700
|
+
wasm.__wbindgen_export3(deferred0_0, deferred0_1, 1);
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
imports.wbg.__wbg_getTime_ad1e9878a735af08 = function(arg0) {
|
|
704
|
+
const ret = getObject(arg0).getTime();
|
|
705
|
+
return ret;
|
|
706
|
+
};
|
|
707
|
+
imports.wbg.__wbg_getTimezoneOffset_45389e26d6f46823 = function(arg0) {
|
|
708
|
+
const ret = getObject(arg0).getTimezoneOffset();
|
|
709
|
+
return ret;
|
|
710
|
+
};
|
|
711
|
+
imports.wbg.__wbg_new_0_23cedd11d9b40c9d = function() {
|
|
712
|
+
const ret = new Date();
|
|
713
|
+
return addHeapObject(ret);
|
|
714
|
+
};
|
|
715
|
+
imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
|
|
716
|
+
const ret = new Object();
|
|
717
|
+
return addHeapObject(ret);
|
|
718
|
+
};
|
|
719
|
+
imports.wbg.__wbg_new_25f239778d6112b9 = function() {
|
|
720
|
+
const ret = new Array();
|
|
721
|
+
return addHeapObject(ret);
|
|
722
|
+
};
|
|
723
|
+
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
|
724
|
+
const ret = new Error();
|
|
725
|
+
return addHeapObject(ret);
|
|
726
|
+
};
|
|
727
|
+
imports.wbg.__wbg_new_b2db8aa2650f793a = function(arg0) {
|
|
728
|
+
const ret = new Date(getObject(arg0));
|
|
729
|
+
return addHeapObject(ret);
|
|
730
|
+
};
|
|
731
|
+
imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
|
|
732
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
733
|
+
};
|
|
734
|
+
imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
|
|
735
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
736
|
+
};
|
|
737
|
+
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
738
|
+
const ret = getObject(arg1).stack;
|
|
739
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
740
|
+
const len1 = WASM_VECTOR_LEN;
|
|
741
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
742
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
743
|
+
};
|
|
744
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
745
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
746
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
747
|
+
return addHeapObject(ret);
|
|
748
|
+
};
|
|
749
|
+
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
750
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
751
|
+
const ret = arg0;
|
|
752
|
+
return addHeapObject(ret);
|
|
753
|
+
};
|
|
754
|
+
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
755
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
756
|
+
const ret = arg0;
|
|
757
|
+
return addHeapObject(ret);
|
|
758
|
+
};
|
|
759
|
+
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
760
|
+
const ret = getObject(arg0);
|
|
761
|
+
return addHeapObject(ret);
|
|
762
|
+
};
|
|
763
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
764
|
+
takeObject(arg0);
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
return imports;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
function __wbg_finalize_init(instance, module) {
|
|
771
|
+
wasm = instance.exports;
|
|
772
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
773
|
+
cachedDataViewMemory0 = null;
|
|
774
|
+
cachedUint8ArrayMemory0 = null;
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
wasm.__wbindgen_start();
|
|
778
|
+
return wasm;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function initSync(module) {
|
|
782
|
+
if (wasm !== undefined) return wasm;
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
if (typeof module !== 'undefined') {
|
|
786
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
787
|
+
({module} = module)
|
|
788
|
+
} else {
|
|
789
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const imports = __wbg_get_imports();
|
|
794
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
795
|
+
module = new WebAssembly.Module(module);
|
|
796
|
+
}
|
|
797
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
798
|
+
return __wbg_finalize_init(instance, module);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
async function __wbg_init(module_or_path) {
|
|
802
|
+
if (wasm !== undefined) return wasm;
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
if (typeof module_or_path !== 'undefined') {
|
|
806
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
807
|
+
({module_or_path} = module_or_path)
|
|
808
|
+
} else {
|
|
809
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (typeof module_or_path === 'undefined') {
|
|
814
|
+
module_or_path = new URL('rustledger_wasm_bg.wasm', import.meta.url);
|
|
815
|
+
}
|
|
816
|
+
const imports = __wbg_get_imports();
|
|
817
|
+
|
|
818
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
819
|
+
module_or_path = fetch(module_or_path);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
823
|
+
|
|
824
|
+
return __wbg_finalize_init(instance, module);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
export { initSync };
|
|
828
|
+
export default __wbg_init;
|