braid-text 0.2.29 → 0.2.31

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 CHANGED
@@ -105,7 +105,11 @@ http_server.on("request", (req, res) => {
105
105
  apply_remote_update: ({ state, patches }) => {
106
106
 
107
107
  // Apply the incoming state or patches to local text here.
108
-
108
+ //
109
+ // Example data:
110
+ // state: "Hello World" // The new text
111
+ // patches: [{ range: [5, 5], content: " World" }] // Patches that create the new text
112
+ //
109
113
  // Then return the new state of textarea as a string:
110
114
  return new_state
111
115
  },
@@ -114,8 +118,8 @@ http_server.on("request", (req, res) => {
114
118
  // Compute diff between prev_state ^ and the current textarea string, such as:
115
119
  //
116
120
  // var patches = [{
117
- // range: [5:5],
118
- // content: " World"
121
+ // range: [5, 5], // The range from position 5 to position 5
122
+ // content: " World" // is replaced with the string " World"
119
123
  // }]
120
124
  //
121
125
  // ...to insert something after a prev_state of "Hello".
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- let { Doc, OpLog, Branch } = require("./dt.js")
2
+ let { Doc, OpLog, Branch } = require("@braid.org/diamond-types-node")
3
3
  let braidify = require("braid-http").http_server
4
4
  let fs = require("fs")
5
5
 
@@ -176,31 +176,11 @@ braid_text.serve = async (req, res, options = {}) => {
176
176
  } catch (e) {
177
177
  console.log(`${req.method} ERROR: ${e.stack}`)
178
178
  if (e.message?.startsWith(MISSING_PARENT_VERSION)) {
179
- // we couldn't apply the version, because we're missing its parents,
180
- // we want to send a 4XX error, so the client will resend this request later,
179
+ // we couldn't apply the version, because we're missing its parents;
180
+ // we want to send some kind of error that gives the client faith,
181
+ // that resending this request later may work,
181
182
  // hopefully after we've received the necessary parents.
182
-
183
- // here are some 4XX error code options..
184
- //
185
- // - 425 Too Early
186
- // - pros: our message is too early
187
- // - cons: associated with some "Early-Data" http thing, which we're not using
188
- // - 400 Bad Request
189
- // - pros: pretty generic
190
- // - cons: implies client shouldn't resend as-is
191
- // - 409 Conflict
192
- // - pros: doesn't imply modifications needed
193
- // - cons: the message is not conflicting with anything
194
- // - 412 Precondition Failed
195
- // - pros: kindof true.. the precondition of having another version has failed..
196
- // - cons: not strictly true, as this code is associated with http's If-Unmodified-Since stuff
197
- // - 422 Unprocessable Content
198
- // - pros: it's true
199
- // - cons: implies client shouldn't resend as-is (at least, it says that here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422)
200
- // - 428 Precondition Required
201
- // - pros: the name sounds right
202
- // - cons: typically implies that the request was missing an http conditional field like If-Match. that is to say, it implies that the request is missing a precondition, not that the server is missing a precondition
203
- return done_my_turn(400, e.message, 'Missing Parents', { 'Retry-After': '1' })
183
+ return done_my_turn(309, e.message, 'Missing Parents', { 'Retry-After': '1' })
204
184
  } else {
205
185
  return done_my_turn(500, "The server failed to apply this version. The error generated was: " + e)
206
186
  }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.29",
3
+ "version": "0.2.31",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",
7
7
  "homepage": "https://braid.org",
8
8
  "dependencies": {
9
+ "@braid.org/diamond-types-node": "^2.0.0",
9
10
  "braid-http": "^1.3.74"
10
11
  }
11
12
  }
package/test/test.html CHANGED
@@ -61,6 +61,21 @@ async function runTest(testName, testFunction, expectedResult) {
61
61
  }
62
62
  }
63
63
 
64
+ runTest(
65
+ "test error code when missing parents",
66
+ async () => {
67
+ let key = 'test-' + Math.random().toString(36).slice(2)
68
+ let r = await braid_fetch(`/${key}`, {
69
+ method: 'PUT',
70
+ version: ['hi-1'],
71
+ parents: ['missing-0'],
72
+ body: 'xx'
73
+ })
74
+ return r.status + ' ' + r.ok
75
+ },
76
+ '309 false'
77
+ )
78
+
64
79
  runTest(
65
80
  "test subscribing starting at a version using simpleton",
66
81
  async () => {
package/dt.js DELETED
@@ -1,944 +0,0 @@
1
- // this file is from a build of https://github.com/josephg/diamond-types,
2
- // along with dt_bg.wasm;
3
- // these are published under the ISC license.
4
-
5
- let imports = {};
6
- imports['__wbindgen_placeholder__'] = module.exports;
7
- let wasm;
8
- const { TextDecoder, TextEncoder } = require(`util`);
9
-
10
- function addToExternrefTable0(obj) {
11
- const idx = wasm.__externref_table_alloc();
12
- wasm.__wbindgen_export_2.set(idx, obj);
13
- return idx;
14
- }
15
-
16
- function handleError(f, args) {
17
- try {
18
- return f.apply(this, args);
19
- } catch (e) {
20
- const idx = addToExternrefTable0(e);
21
- wasm.__wbindgen_exn_store(idx);
22
- }
23
- }
24
-
25
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
26
-
27
- cachedTextDecoder.decode();
28
-
29
- let cachedUint8ArrayMemory0 = null;
30
-
31
- function getUint8ArrayMemory0() {
32
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
33
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
34
- }
35
- return cachedUint8ArrayMemory0;
36
- }
37
-
38
- function getStringFromWasm0(ptr, len) {
39
- ptr = ptr >>> 0;
40
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
41
- }
42
-
43
- let WASM_VECTOR_LEN = 0;
44
-
45
- let cachedTextEncoder = new TextEncoder('utf-8');
46
-
47
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
48
- ? function (arg, view) {
49
- return cachedTextEncoder.encodeInto(arg, view);
50
- }
51
- : function (arg, view) {
52
- const buf = cachedTextEncoder.encode(arg);
53
- view.set(buf);
54
- return {
55
- read: arg.length,
56
- written: buf.length
57
- };
58
- });
59
-
60
- function passStringToWasm0(arg, malloc, realloc) {
61
-
62
- if (realloc === undefined) {
63
- const buf = cachedTextEncoder.encode(arg);
64
- const ptr = malloc(buf.length, 1) >>> 0;
65
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
66
- WASM_VECTOR_LEN = buf.length;
67
- return ptr;
68
- }
69
-
70
- let len = arg.length;
71
- let ptr = malloc(len, 1) >>> 0;
72
-
73
- const mem = getUint8ArrayMemory0();
74
-
75
- let offset = 0;
76
-
77
- for (; offset < len; offset++) {
78
- const code = arg.charCodeAt(offset);
79
- if (code > 0x7F) break;
80
- mem[ptr + offset] = code;
81
- }
82
-
83
- if (offset !== len) {
84
- if (offset !== 0) {
85
- arg = arg.slice(offset);
86
- }
87
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
88
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
89
- const ret = encodeString(arg, view);
90
-
91
- offset += ret.written;
92
- ptr = realloc(ptr, len, offset, 1) >>> 0;
93
- }
94
-
95
- WASM_VECTOR_LEN = offset;
96
- return ptr;
97
- }
98
-
99
- let cachedDataViewMemory0 = null;
100
-
101
- function getDataViewMemory0() {
102
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
103
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
104
- }
105
- return cachedDataViewMemory0;
106
- }
107
-
108
- function isLikeNone(x) {
109
- return x === undefined || x === null;
110
- }
111
-
112
- function _assertClass(instance, klass) {
113
- if (!(instance instanceof klass)) {
114
- throw new Error(`expected instance of ${klass.name}`);
115
- }
116
- }
117
-
118
- let cachedUint32ArrayMemory0 = null;
119
-
120
- function getUint32ArrayMemory0() {
121
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
122
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
123
- }
124
- return cachedUint32ArrayMemory0;
125
- }
126
-
127
- function passArray32ToWasm0(arg, malloc) {
128
- const ptr = malloc(arg.length * 4, 4) >>> 0;
129
- getUint32ArrayMemory0().set(arg, ptr / 4);
130
- WASM_VECTOR_LEN = arg.length;
131
- return ptr;
132
- }
133
-
134
- function getArrayU32FromWasm0(ptr, len) {
135
- ptr = ptr >>> 0;
136
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
137
- }
138
-
139
- function takeFromExternrefTable0(idx) {
140
- const value = wasm.__wbindgen_export_2.get(idx);
141
- wasm.__externref_table_dealloc(idx);
142
- return value;
143
- }
144
-
145
- function getArrayU8FromWasm0(ptr, len) {
146
- ptr = ptr >>> 0;
147
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
148
- }
149
-
150
- function passArray8ToWasm0(arg, malloc) {
151
- const ptr = malloc(arg.length * 1, 1) >>> 0;
152
- getUint8ArrayMemory0().set(arg, ptr / 1);
153
- WASM_VECTOR_LEN = arg.length;
154
- return ptr;
155
- }
156
-
157
- const BranchFinalization = (typeof FinalizationRegistry === 'undefined')
158
- ? { register: () => {}, unregister: () => {} }
159
- : new FinalizationRegistry(ptr => wasm.__wbg_branch_free(ptr >>> 0, 1));
160
-
161
- class Branch {
162
-
163
- static __wrap(ptr) {
164
- ptr = ptr >>> 0;
165
- const obj = Object.create(Branch.prototype);
166
- obj.__wbg_ptr = ptr;
167
- BranchFinalization.register(obj, obj.__wbg_ptr, obj);
168
- return obj;
169
- }
170
-
171
- __destroy_into_raw() {
172
- const ptr = this.__wbg_ptr;
173
- this.__wbg_ptr = 0;
174
- BranchFinalization.unregister(this);
175
- return ptr;
176
- }
177
-
178
- free() {
179
- const ptr = this.__destroy_into_raw();
180
- wasm.__wbg_branch_free(ptr, 0);
181
- }
182
- constructor() {
183
- const ret = wasm.branch_new();
184
- this.__wbg_ptr = ret >>> 0;
185
- BranchFinalization.register(this, this.__wbg_ptr, this);
186
- return this;
187
- }
188
- /**
189
- * @param {OpLog} oplog
190
- * @returns {Branch}
191
- */
192
- static all(oplog) {
193
- _assertClass(oplog, OpLog);
194
- const ret = wasm.branch_all(oplog.__wbg_ptr);
195
- return Branch.__wrap(ret);
196
- }
197
- /**
198
- * @returns {string}
199
- */
200
- get() {
201
- let deferred1_0;
202
- let deferred1_1;
203
- try {
204
- const ret = wasm.branch_get(this.__wbg_ptr);
205
- deferred1_0 = ret[0];
206
- deferred1_1 = ret[1];
207
- return getStringFromWasm0(ret[0], ret[1]);
208
- } finally {
209
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
210
- }
211
- }
212
- /**
213
- * Merge in from some named point in time
214
- * @param {OpLog} ops
215
- * @param {Uint32Array | null} [branch]
216
- */
217
- merge(ops, branch) {
218
- _assertClass(ops, OpLog);
219
- var ptr0 = isLikeNone(branch) ? 0 : passArray32ToWasm0(branch, wasm.__wbindgen_malloc);
220
- var len0 = WASM_VECTOR_LEN;
221
- wasm.branch_merge(this.__wbg_ptr, ops.__wbg_ptr, ptr0, len0);
222
- }
223
- /**
224
- * @returns {Uint32Array}
225
- */
226
- getLocalVersion() {
227
- const ret = wasm.branch_getLocalVersion(this.__wbg_ptr);
228
- var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
229
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
230
- return v1;
231
- }
232
- /**
233
- * @param {number} pos_wchars
234
- * @returns {number}
235
- */
236
- wCharsToChars(pos_wchars) {
237
- const ret = wasm.branch_wCharsToChars(this.__wbg_ptr, pos_wchars);
238
- return ret >>> 0;
239
- }
240
- /**
241
- * @param {number} pos_chars
242
- * @returns {number}
243
- */
244
- charsToWchars(pos_chars) {
245
- const ret = wasm.branch_charsToWchars(this.__wbg_ptr, pos_chars);
246
- return ret >>> 0;
247
- }
248
- }
249
- module.exports.Branch = Branch;
250
-
251
- const DocFinalization = (typeof FinalizationRegistry === 'undefined')
252
- ? { register: () => {}, unregister: () => {} }
253
- : new FinalizationRegistry(ptr => wasm.__wbg_doc_free(ptr >>> 0, 1));
254
-
255
- class Doc {
256
-
257
- static __wrap(ptr) {
258
- ptr = ptr >>> 0;
259
- const obj = Object.create(Doc.prototype);
260
- obj.__wbg_ptr = ptr;
261
- DocFinalization.register(obj, obj.__wbg_ptr, obj);
262
- return obj;
263
- }
264
-
265
- __destroy_into_raw() {
266
- const ptr = this.__wbg_ptr;
267
- this.__wbg_ptr = 0;
268
- DocFinalization.unregister(this);
269
- return ptr;
270
- }
271
-
272
- free() {
273
- const ptr = this.__destroy_into_raw();
274
- wasm.__wbg_doc_free(ptr, 0);
275
- }
276
- /**
277
- * @param {string | null} [agent_name]
278
- */
279
- constructor(agent_name) {
280
- var ptr0 = isLikeNone(agent_name) ? 0 : passStringToWasm0(agent_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
281
- var len0 = WASM_VECTOR_LEN;
282
- const ret = wasm.doc_new(ptr0, len0);
283
- this.__wbg_ptr = ret >>> 0;
284
- DocFinalization.register(this, this.__wbg_ptr, this);
285
- return this;
286
- }
287
- /**
288
- * @param {number} pos
289
- * @param {string} content
290
- */
291
- ins(pos, content) {
292
- const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
293
- const len0 = WASM_VECTOR_LEN;
294
- wasm.doc_ins(this.__wbg_ptr, pos, ptr0, len0);
295
- }
296
- /**
297
- * @param {number} pos
298
- * @param {number} del_span
299
- */
300
- del(pos, del_span) {
301
- wasm.doc_del(this.__wbg_ptr, pos, del_span);
302
- }
303
- /**
304
- * @returns {number}
305
- */
306
- len() {
307
- const ret = wasm.doc_len(this.__wbg_ptr);
308
- return ret >>> 0;
309
- }
310
- /**
311
- * @returns {boolean}
312
- */
313
- is_empty() {
314
- const ret = wasm.doc_is_empty(this.__wbg_ptr);
315
- return ret !== 0;
316
- }
317
- /**
318
- * @returns {string}
319
- */
320
- get() {
321
- let deferred1_0;
322
- let deferred1_1;
323
- try {
324
- const ret = wasm.doc_get(this.__wbg_ptr);
325
- deferred1_0 = ret[0];
326
- deferred1_1 = ret[1];
327
- return getStringFromWasm0(ret[0], ret[1]);
328
- } finally {
329
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
330
- }
331
- }
332
- /**
333
- * @param {Uint32Array} branch
334
- */
335
- merge(branch) {
336
- const ptr0 = passArray32ToWasm0(branch, wasm.__wbindgen_malloc);
337
- const len0 = WASM_VECTOR_LEN;
338
- wasm.doc_merge(this.__wbg_ptr, ptr0, len0);
339
- }
340
- /**
341
- * @returns {Uint8Array}
342
- */
343
- toBytes() {
344
- const ret = wasm.doc_toBytes(this.__wbg_ptr);
345
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
346
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
347
- return v1;
348
- }
349
- /**
350
- * @param {Uint32Array} from_version
351
- * @returns {Uint8Array}
352
- */
353
- getPatchSince(from_version) {
354
- const ptr0 = passArray32ToWasm0(from_version, wasm.__wbindgen_malloc);
355
- const len0 = WASM_VECTOR_LEN;
356
- const ret = wasm.doc_getPatchSince(this.__wbg_ptr, ptr0, len0);
357
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
358
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
359
- return v2;
360
- }
361
- /**
362
- * @param {Uint8Array} bytes
363
- * @param {string | null} [agent_name]
364
- * @returns {Doc}
365
- */
366
- static fromBytes(bytes, agent_name) {
367
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
368
- const len0 = WASM_VECTOR_LEN;
369
- var ptr1 = isLikeNone(agent_name) ? 0 : passStringToWasm0(agent_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
370
- var len1 = WASM_VECTOR_LEN;
371
- const ret = wasm.doc_fromBytes(ptr0, len0, ptr1, len1);
372
- return Doc.__wrap(ret);
373
- }
374
- /**
375
- * @param {Uint8Array} bytes
376
- * @returns {Uint32Array}
377
- */
378
- mergeBytes(bytes) {
379
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
380
- const len0 = WASM_VECTOR_LEN;
381
- const ret = wasm.doc_mergeBytes(this.__wbg_ptr, ptr0, len0);
382
- if (ret[3]) {
383
- throw takeFromExternrefTable0(ret[2]);
384
- }
385
- var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
386
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
387
- return v2;
388
- }
389
- /**
390
- * @param {Uint32Array} frontier
391
- * @returns {any}
392
- */
393
- getOpsSince(frontier) {
394
- const ptr0 = passArray32ToWasm0(frontier, wasm.__wbindgen_malloc);
395
- const len0 = WASM_VECTOR_LEN;
396
- const ret = wasm.doc_getOpsSince(this.__wbg_ptr, ptr0, len0);
397
- if (ret[2]) {
398
- throw takeFromExternrefTable0(ret[1]);
399
- }
400
- return takeFromExternrefTable0(ret[0]);
401
- }
402
- /**
403
- * @returns {Uint32Array}
404
- */
405
- getLocalVersion() {
406
- const ret = wasm.doc_getLocalVersion(this.__wbg_ptr);
407
- var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
408
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
409
- return v1;
410
- }
411
- /**
412
- * @param {Uint32Array} time
413
- * @returns {any}
414
- */
415
- localToRemoteVersion(time) {
416
- const ptr0 = passArray32ToWasm0(time, wasm.__wbindgen_malloc);
417
- const len0 = WASM_VECTOR_LEN;
418
- const ret = wasm.doc_localToRemoteVersion(this.__wbg_ptr, ptr0, len0);
419
- if (ret[2]) {
420
- throw takeFromExternrefTable0(ret[1]);
421
- }
422
- return takeFromExternrefTable0(ret[0]);
423
- }
424
- /**
425
- * @returns {any}
426
- */
427
- getRemoteVersion() {
428
- const ret = wasm.doc_getRemoteVersion(this.__wbg_ptr);
429
- if (ret[2]) {
430
- throw takeFromExternrefTable0(ret[1]);
431
- }
432
- return takeFromExternrefTable0(ret[0]);
433
- }
434
- /**
435
- * @param {Uint32Array} from_version
436
- * @returns {any}
437
- */
438
- xfSince(from_version) {
439
- const ptr0 = passArray32ToWasm0(from_version, wasm.__wbindgen_malloc);
440
- const len0 = WASM_VECTOR_LEN;
441
- const ret = wasm.doc_xfSince(this.__wbg_ptr, ptr0, len0);
442
- if (ret[2]) {
443
- throw takeFromExternrefTable0(ret[1]);
444
- }
445
- return takeFromExternrefTable0(ret[0]);
446
- }
447
- /**
448
- * @returns {any}
449
- */
450
- getHistory() {
451
- const ret = wasm.doc_getHistory(this.__wbg_ptr);
452
- if (ret[2]) {
453
- throw takeFromExternrefTable0(ret[1]);
454
- }
455
- return takeFromExternrefTable0(ret[0]);
456
- }
457
- /**
458
- * @param {Uint32Array} a
459
- * @param {Uint32Array} b
460
- * @returns {Uint32Array}
461
- */
462
- mergeVersions(a, b) {
463
- const ptr0 = passArray32ToWasm0(a, wasm.__wbindgen_malloc);
464
- const len0 = WASM_VECTOR_LEN;
465
- const ptr1 = passArray32ToWasm0(b, wasm.__wbindgen_malloc);
466
- const len1 = WASM_VECTOR_LEN;
467
- const ret = wasm.doc_mergeVersions(this.__wbg_ptr, ptr0, len0, ptr1, len1);
468
- var v3 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
469
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
470
- return v3;
471
- }
472
- /**
473
- * @param {number} pos_wchars
474
- * @returns {number}
475
- */
476
- wCharsToChars(pos_wchars) {
477
- const ret = wasm.doc_wCharsToChars(this.__wbg_ptr, pos_wchars);
478
- return ret >>> 0;
479
- }
480
- /**
481
- * @param {number} pos_chars
482
- * @returns {number}
483
- */
484
- charsToWchars(pos_chars) {
485
- const ret = wasm.doc_charsToWchars(this.__wbg_ptr, pos_chars);
486
- return ret >>> 0;
487
- }
488
- }
489
- module.exports.Doc = Doc;
490
-
491
- const OpLogFinalization = (typeof FinalizationRegistry === 'undefined')
492
- ? { register: () => {}, unregister: () => {} }
493
- : new FinalizationRegistry(ptr => wasm.__wbg_oplog_free(ptr >>> 0, 1));
494
-
495
- class OpLog {
496
-
497
- static __wrap(ptr) {
498
- ptr = ptr >>> 0;
499
- const obj = Object.create(OpLog.prototype);
500
- obj.__wbg_ptr = ptr;
501
- OpLogFinalization.register(obj, obj.__wbg_ptr, obj);
502
- return obj;
503
- }
504
-
505
- __destroy_into_raw() {
506
- const ptr = this.__wbg_ptr;
507
- this.__wbg_ptr = 0;
508
- OpLogFinalization.unregister(this);
509
- return ptr;
510
- }
511
-
512
- free() {
513
- const ptr = this.__destroy_into_raw();
514
- wasm.__wbg_oplog_free(ptr, 0);
515
- }
516
- /**
517
- * @param {string | null} [agent_name]
518
- */
519
- constructor(agent_name) {
520
- var ptr0 = isLikeNone(agent_name) ? 0 : passStringToWasm0(agent_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
521
- var len0 = WASM_VECTOR_LEN;
522
- const ret = wasm.oplog_new(ptr0, len0);
523
- this.__wbg_ptr = ret >>> 0;
524
- OpLogFinalization.register(this, this.__wbg_ptr, this);
525
- return this;
526
- }
527
- /**
528
- * @param {string} agent
529
- */
530
- setAgent(agent) {
531
- const ptr0 = passStringToWasm0(agent, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
532
- const len0 = WASM_VECTOR_LEN;
533
- wasm.oplog_setAgent(this.__wbg_ptr, ptr0, len0);
534
- }
535
- /**
536
- * @returns {OpLog}
537
- */
538
- clone() {
539
- const ret = wasm.oplog_clone(this.__wbg_ptr);
540
- return OpLog.__wrap(ret);
541
- }
542
- /**
543
- * @param {number} pos
544
- * @param {string} content
545
- * @param {Uint32Array | null} [parents_in]
546
- * @returns {number}
547
- */
548
- ins(pos, content, parents_in) {
549
- const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
550
- const len0 = WASM_VECTOR_LEN;
551
- var ptr1 = isLikeNone(parents_in) ? 0 : passArray32ToWasm0(parents_in, wasm.__wbindgen_malloc);
552
- var len1 = WASM_VECTOR_LEN;
553
- const ret = wasm.oplog_ins(this.__wbg_ptr, pos, ptr0, len0, ptr1, len1);
554
- return ret >>> 0;
555
- }
556
- /**
557
- * @param {number} pos
558
- * @param {number} len
559
- * @param {Uint32Array | null} [parents_in]
560
- * @returns {number}
561
- */
562
- del(pos, len, parents_in) {
563
- var ptr0 = isLikeNone(parents_in) ? 0 : passArray32ToWasm0(parents_in, wasm.__wbindgen_malloc);
564
- var len0 = WASM_VECTOR_LEN;
565
- const ret = wasm.oplog_del(this.__wbg_ptr, pos, len, ptr0, len0);
566
- return ret >>> 0;
567
- }
568
- /**
569
- * @returns {Branch}
570
- */
571
- checkout() {
572
- const ret = wasm.oplog_checkout(this.__wbg_ptr);
573
- return Branch.__wrap(ret);
574
- }
575
- /**
576
- * @returns {any}
577
- */
578
- getOps() {
579
- const ret = wasm.oplog_getOps(this.__wbg_ptr);
580
- if (ret[2]) {
581
- throw takeFromExternrefTable0(ret[1]);
582
- }
583
- return takeFromExternrefTable0(ret[0]);
584
- }
585
- /**
586
- * @param {Uint32Array} frontier
587
- * @returns {any}
588
- */
589
- getOpsSince(frontier) {
590
- const ptr0 = passArray32ToWasm0(frontier, wasm.__wbindgen_malloc);
591
- const len0 = WASM_VECTOR_LEN;
592
- const ret = wasm.oplog_getOpsSince(this.__wbg_ptr, ptr0, len0);
593
- if (ret[2]) {
594
- throw takeFromExternrefTable0(ret[1]);
595
- }
596
- return takeFromExternrefTable0(ret[0]);
597
- }
598
- /**
599
- * @returns {any}
600
- */
601
- getHistory() {
602
- const ret = wasm.oplog_getHistory(this.__wbg_ptr);
603
- if (ret[2]) {
604
- throw takeFromExternrefTable0(ret[1]);
605
- }
606
- return takeFromExternrefTable0(ret[0]);
607
- }
608
- /**
609
- * @returns {Uint32Array}
610
- */
611
- getLocalVersion() {
612
- const ret = wasm.oplog_getLocalVersion(this.__wbg_ptr);
613
- var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
614
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
615
- return v1;
616
- }
617
- /**
618
- * @param {Uint32Array} version
619
- * @returns {any}
620
- */
621
- localToRemoteVersion(version) {
622
- const ptr0 = passArray32ToWasm0(version, wasm.__wbindgen_malloc);
623
- const len0 = WASM_VECTOR_LEN;
624
- const ret = wasm.oplog_localToRemoteVersion(this.__wbg_ptr, ptr0, len0);
625
- if (ret[2]) {
626
- throw takeFromExternrefTable0(ret[1]);
627
- }
628
- return takeFromExternrefTable0(ret[0]);
629
- }
630
- /**
631
- * @returns {any}
632
- */
633
- getRemoteVersion() {
634
- const ret = wasm.oplog_getRemoteVersion(this.__wbg_ptr);
635
- if (ret[2]) {
636
- throw takeFromExternrefTable0(ret[1]);
637
- }
638
- return takeFromExternrefTable0(ret[0]);
639
- }
640
- /**
641
- * @returns {Uint8Array}
642
- */
643
- toBytes() {
644
- const ret = wasm.oplog_toBytes(this.__wbg_ptr);
645
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
646
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
647
- return v1;
648
- }
649
- /**
650
- * @param {Uint32Array} from_version
651
- * @returns {Uint8Array}
652
- */
653
- getPatchSince(from_version) {
654
- const ptr0 = passArray32ToWasm0(from_version, wasm.__wbindgen_malloc);
655
- const len0 = WASM_VECTOR_LEN;
656
- const ret = wasm.oplog_getPatchSince(this.__wbg_ptr, ptr0, len0);
657
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
658
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
659
- return v2;
660
- }
661
- /**
662
- * @param {Uint8Array} bytes
663
- * @param {string | null} [agent_name]
664
- * @returns {OpLog}
665
- */
666
- static fromBytes(bytes, agent_name) {
667
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
668
- const len0 = WASM_VECTOR_LEN;
669
- var ptr1 = isLikeNone(agent_name) ? 0 : passStringToWasm0(agent_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
670
- var len1 = WASM_VECTOR_LEN;
671
- const ret = wasm.oplog_fromBytes(ptr0, len0, ptr1, len1);
672
- return OpLog.__wrap(ret);
673
- }
674
- /**
675
- * Decode bytes, and add (merge in) any missing operations.
676
- * @param {Uint8Array} bytes
677
- * @returns {any}
678
- */
679
- addFromBytes(bytes) {
680
- const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
681
- const len0 = WASM_VECTOR_LEN;
682
- const ret = wasm.oplog_addFromBytes(this.__wbg_ptr, ptr0, len0);
683
- if (ret[2]) {
684
- throw takeFromExternrefTable0(ret[1]);
685
- }
686
- return takeFromExternrefTable0(ret[0]);
687
- }
688
- /**
689
- * @returns {any}
690
- */
691
- getXF() {
692
- const ret = wasm.oplog_getXF(this.__wbg_ptr);
693
- if (ret[2]) {
694
- throw takeFromExternrefTable0(ret[1]);
695
- }
696
- return takeFromExternrefTable0(ret[0]);
697
- }
698
- /**
699
- * @param {Uint32Array} from_version
700
- * @returns {any}
701
- */
702
- getXFSince(from_version) {
703
- const ptr0 = passArray32ToWasm0(from_version, wasm.__wbindgen_malloc);
704
- const len0 = WASM_VECTOR_LEN;
705
- const ret = wasm.oplog_getXFSince(this.__wbg_ptr, ptr0, len0);
706
- if (ret[2]) {
707
- throw takeFromExternrefTable0(ret[1]);
708
- }
709
- return takeFromExternrefTable0(ret[0]);
710
- }
711
- /**
712
- * @param {Uint32Array} a
713
- * @param {Uint32Array} b
714
- * @returns {Uint32Array}
715
- */
716
- mergeVersions(a, b) {
717
- const ptr0 = passArray32ToWasm0(a, wasm.__wbindgen_malloc);
718
- const len0 = WASM_VECTOR_LEN;
719
- const ptr1 = passArray32ToWasm0(b, wasm.__wbindgen_malloc);
720
- const len1 = WASM_VECTOR_LEN;
721
- const ret = wasm.oplog_mergeVersions(this.__wbg_ptr, ptr0, len0, ptr1, len1);
722
- var v3 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
723
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
724
- return v3;
725
- }
726
- }
727
- module.exports.OpLog = OpLog;
728
-
729
- module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
730
- const ret = arg0.buffer;
731
- return ret;
732
- };
733
-
734
- module.exports.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
735
- const ret = arg0.call(arg1);
736
- return ret;
737
- }, arguments) };
738
-
739
- module.exports.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
740
- const ret = arg0.call(arg1, arg2);
741
- return ret;
742
- }, arguments) };
743
-
744
- module.exports.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
745
- const ret = arg0.crypto;
746
- return ret;
747
- };
748
-
749
- module.exports.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
750
- let deferred0_0;
751
- let deferred0_1;
752
- try {
753
- deferred0_0 = arg0;
754
- deferred0_1 = arg1;
755
- console.error(getStringFromWasm0(arg0, arg1));
756
- } finally {
757
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
758
- }
759
- };
760
-
761
- module.exports.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
762
- arg0.getRandomValues(arg1);
763
- }, arguments) };
764
-
765
- module.exports.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
766
- const ret = arg0.msCrypto;
767
- return ret;
768
- };
769
-
770
- module.exports.__wbg_new_405e22f390576ce2 = function() {
771
- const ret = new Object();
772
- return ret;
773
- };
774
-
775
- module.exports.__wbg_new_78feb108b6472713 = function() {
776
- const ret = new Array();
777
- return ret;
778
- };
779
-
780
- module.exports.__wbg_new_8a6f238a6ece86ea = function() {
781
- const ret = new Error();
782
- return ret;
783
- };
784
-
785
- module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
786
- const ret = new Uint8Array(arg0);
787
- return ret;
788
- };
789
-
790
- module.exports.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
791
- const ret = new Function(getStringFromWasm0(arg0, arg1));
792
- return ret;
793
- };
794
-
795
- module.exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
796
- const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
797
- return ret;
798
- };
799
-
800
- module.exports.__wbg_newwithlength_a381634e90c276d4 = function(arg0) {
801
- const ret = new Uint8Array(arg0 >>> 0);
802
- return ret;
803
- };
804
-
805
- module.exports.__wbg_node_905d3e251edff8a2 = function(arg0) {
806
- const ret = arg0.node;
807
- return ret;
808
- };
809
-
810
- module.exports.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
811
- const ret = arg0.process;
812
- return ret;
813
- };
814
-
815
- module.exports.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
816
- arg0.randomFillSync(arg1);
817
- }, arguments) };
818
-
819
- module.exports.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
820
- const ret = module.require;
821
- return ret;
822
- }, arguments) };
823
-
824
- module.exports.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
825
- arg0[arg1 >>> 0] = arg2;
826
- };
827
-
828
- module.exports.__wbg_set_3fda3bac07393de4 = function(arg0, arg1, arg2) {
829
- arg0[arg1] = arg2;
830
- };
831
-
832
- module.exports.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
833
- arg0.set(arg1, arg2 >>> 0);
834
- };
835
-
836
- module.exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
837
- const ret = arg1.stack;
838
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
839
- const len1 = WASM_VECTOR_LEN;
840
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
841
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
842
- };
843
-
844
- module.exports.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
845
- const ret = typeof global === 'undefined' ? null : global;
846
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
847
- };
848
-
849
- module.exports.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
850
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
851
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
852
- };
853
-
854
- module.exports.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
855
- const ret = typeof self === 'undefined' ? null : self;
856
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
857
- };
858
-
859
- module.exports.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
860
- const ret = typeof window === 'undefined' ? null : window;
861
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
862
- };
863
-
864
- module.exports.__wbg_subarray_aa9065fa9dc5df96 = function(arg0, arg1, arg2) {
865
- const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
866
- return ret;
867
- };
868
-
869
- module.exports.__wbg_versions_c01dfd4722a88165 = function(arg0) {
870
- const ret = arg0.versions;
871
- return ret;
872
- };
873
-
874
- module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
875
- const ret = BigInt.asUintN(64, arg0);
876
- return ret;
877
- };
878
-
879
- module.exports.__wbindgen_error_new = function(arg0, arg1) {
880
- const ret = new Error(getStringFromWasm0(arg0, arg1));
881
- return ret;
882
- };
883
-
884
- module.exports.__wbindgen_init_externref_table = function() {
885
- const table = wasm.__wbindgen_export_2;
886
- const offset = table.grow(4);
887
- table.set(0, undefined);
888
- table.set(offset + 0, undefined);
889
- table.set(offset + 1, null);
890
- table.set(offset + 2, true);
891
- table.set(offset + 3, false);
892
- ;
893
- };
894
-
895
- module.exports.__wbindgen_is_function = function(arg0) {
896
- const ret = typeof(arg0) === 'function';
897
- return ret;
898
- };
899
-
900
- module.exports.__wbindgen_is_object = function(arg0) {
901
- const val = arg0;
902
- const ret = typeof(val) === 'object' && val !== null;
903
- return ret;
904
- };
905
-
906
- module.exports.__wbindgen_is_string = function(arg0) {
907
- const ret = typeof(arg0) === 'string';
908
- return ret;
909
- };
910
-
911
- module.exports.__wbindgen_is_undefined = function(arg0) {
912
- const ret = arg0 === undefined;
913
- return ret;
914
- };
915
-
916
- module.exports.__wbindgen_memory = function() {
917
- const ret = wasm.memory;
918
- return ret;
919
- };
920
-
921
- module.exports.__wbindgen_number_new = function(arg0) {
922
- const ret = arg0;
923
- return ret;
924
- };
925
-
926
- module.exports.__wbindgen_string_new = function(arg0, arg1) {
927
- const ret = getStringFromWasm0(arg0, arg1);
928
- return ret;
929
- };
930
-
931
- module.exports.__wbindgen_throw = function(arg0, arg1) {
932
- throw new Error(getStringFromWasm0(arg0, arg1));
933
- };
934
-
935
- const path = require('path').join(__dirname, 'dt_bg.wasm');
936
- const bytes = require('fs').readFileSync(path);
937
-
938
- const wasmModule = new WebAssembly.Module(bytes);
939
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
940
- wasm = wasmInstance.exports;
941
- module.exports.__wasm = wasm;
942
-
943
- wasm.__wbindgen_start();
944
-
package/dt_bg.wasm DELETED
Binary file