topazcube 0.0.3 → 0.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.
- package/dist/client.d.ts +82 -0
- package/dist/compress-browser.d.ts +2 -0
- package/dist/compress-buffer.d.ts +2 -0
- package/dist/compress-node.d.ts +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/server.d.ts +99 -0
- package/dist/terminal.d.ts +62 -0
- package/dist/topazcube-client.js +481 -0
- package/dist/topazcube-server.js +740 -0
- package/dist/topazcube.d.ts +2 -0
- package/dist/utils.d.ts +31 -0
- package/package.json +26 -12
- package/src/client.ts +859 -0
- package/src/compress-browser.ts +34 -0
- package/src/compress-node.ts +39 -0
- package/src/server.ts +1111 -0
- package/src/terminal.js +144 -0
- package/src/utils.ts +402 -0
- package/dist/topazcube.js +0 -1527
- package/src/client.js +0 -251
- package/src/server.js +0 -335
- package/src/utils.js +0 -216
- /package/src/{topazcube.js → topazcube.ts} +0 -0
package/dist/topazcube.js
DELETED
|
@@ -1,1527 +0,0 @@
|
|
|
1
|
-
var ee = Object.defineProperty;
|
|
2
|
-
var te = (s, e, t) => e in s ? ee(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
-
var w = (s, e, t) => te(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
/*!
|
|
5
|
-
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
6
|
-
* (c) 2017-2022 Joachim Wester
|
|
7
|
-
* MIT licensed
|
|
8
|
-
*/
|
|
9
|
-
var se = /* @__PURE__ */ function() {
|
|
10
|
-
var s = function(e, t) {
|
|
11
|
-
return s = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(i, n) {
|
|
12
|
-
i.__proto__ = n;
|
|
13
|
-
} || function(i, n) {
|
|
14
|
-
for (var r in n) n.hasOwnProperty(r) && (i[r] = n[r]);
|
|
15
|
-
}, s(e, t);
|
|
16
|
-
};
|
|
17
|
-
return function(e, t) {
|
|
18
|
-
s(e, t);
|
|
19
|
-
function i() {
|
|
20
|
-
this.constructor = e;
|
|
21
|
-
}
|
|
22
|
-
e.prototype = t === null ? Object.create(t) : (i.prototype = t.prototype, new i());
|
|
23
|
-
};
|
|
24
|
-
}(), ie = Object.prototype.hasOwnProperty;
|
|
25
|
-
function C(s, e) {
|
|
26
|
-
return ie.call(s, e);
|
|
27
|
-
}
|
|
28
|
-
function P(s) {
|
|
29
|
-
if (Array.isArray(s)) {
|
|
30
|
-
for (var e = new Array(s.length), t = 0; t < e.length; t++)
|
|
31
|
-
e[t] = "" + t;
|
|
32
|
-
return e;
|
|
33
|
-
}
|
|
34
|
-
if (Object.keys)
|
|
35
|
-
return Object.keys(s);
|
|
36
|
-
var i = [];
|
|
37
|
-
for (var n in s)
|
|
38
|
-
C(s, n) && i.push(n);
|
|
39
|
-
return i;
|
|
40
|
-
}
|
|
41
|
-
function p(s) {
|
|
42
|
-
switch (typeof s) {
|
|
43
|
-
case "object":
|
|
44
|
-
return JSON.parse(JSON.stringify(s));
|
|
45
|
-
//Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
|
46
|
-
case "undefined":
|
|
47
|
-
return null;
|
|
48
|
-
//this is how JSON.stringify behaves for array items
|
|
49
|
-
default:
|
|
50
|
-
return s;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function L(s) {
|
|
54
|
-
for (var e = 0, t = s.length, i; e < t; ) {
|
|
55
|
-
if (i = s.charCodeAt(e), i >= 48 && i <= 57) {
|
|
56
|
-
e++;
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
return !1;
|
|
60
|
-
}
|
|
61
|
-
return !0;
|
|
62
|
-
}
|
|
63
|
-
function y(s) {
|
|
64
|
-
return s.indexOf("/") === -1 && s.indexOf("~") === -1 ? s : s.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
65
|
-
}
|
|
66
|
-
function b(s) {
|
|
67
|
-
return s.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
68
|
-
}
|
|
69
|
-
function R(s) {
|
|
70
|
-
if (s === void 0)
|
|
71
|
-
return !0;
|
|
72
|
-
if (s) {
|
|
73
|
-
if (Array.isArray(s)) {
|
|
74
|
-
for (var e = 0, t = s.length; e < t; e++)
|
|
75
|
-
if (R(s[e]))
|
|
76
|
-
return !0;
|
|
77
|
-
} else if (typeof s == "object") {
|
|
78
|
-
for (var i = P(s), n = i.length, r = 0; r < n; r++)
|
|
79
|
-
if (R(s[i[r]]))
|
|
80
|
-
return !0;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return !1;
|
|
84
|
-
}
|
|
85
|
-
function J(s, e) {
|
|
86
|
-
var t = [s];
|
|
87
|
-
for (var i in e) {
|
|
88
|
-
var n = typeof e[i] == "object" ? JSON.stringify(e[i], null, 2) : e[i];
|
|
89
|
-
typeof n < "u" && t.push(i + ": " + n);
|
|
90
|
-
}
|
|
91
|
-
return t.join(`
|
|
92
|
-
`);
|
|
93
|
-
}
|
|
94
|
-
var Q = (
|
|
95
|
-
/** @class */
|
|
96
|
-
function(s) {
|
|
97
|
-
se(e, s);
|
|
98
|
-
function e(t, i, n, r, h) {
|
|
99
|
-
var o = this.constructor, a = s.call(this, J(t, { name: i, index: n, operation: r, tree: h })) || this;
|
|
100
|
-
return a.name = i, a.index = n, a.operation = r, a.tree = h, Object.setPrototypeOf(a, o.prototype), a.message = J(t, { name: i, index: n, operation: r, tree: h }), a;
|
|
101
|
-
}
|
|
102
|
-
return e;
|
|
103
|
-
}(Error)
|
|
104
|
-
), f = Q, ne = p, v = {
|
|
105
|
-
add: function(s, e, t) {
|
|
106
|
-
return s[e] = this.value, { newDocument: t };
|
|
107
|
-
},
|
|
108
|
-
remove: function(s, e, t) {
|
|
109
|
-
var i = s[e];
|
|
110
|
-
return delete s[e], { newDocument: t, removed: i };
|
|
111
|
-
},
|
|
112
|
-
replace: function(s, e, t) {
|
|
113
|
-
var i = s[e];
|
|
114
|
-
return s[e] = this.value, { newDocument: t, removed: i };
|
|
115
|
-
},
|
|
116
|
-
move: function(s, e, t) {
|
|
117
|
-
var i = T(t, this.path);
|
|
118
|
-
i && (i = p(i));
|
|
119
|
-
var n = x(t, { op: "remove", path: this.from }).removed;
|
|
120
|
-
return x(t, { op: "add", path: this.path, value: n }), { newDocument: t, removed: i };
|
|
121
|
-
},
|
|
122
|
-
copy: function(s, e, t) {
|
|
123
|
-
var i = T(t, this.from);
|
|
124
|
-
return x(t, { op: "add", path: this.path, value: p(i) }), { newDocument: t };
|
|
125
|
-
},
|
|
126
|
-
test: function(s, e, t) {
|
|
127
|
-
return { newDocument: t, test: _(s[e], this.value) };
|
|
128
|
-
},
|
|
129
|
-
_get: function(s, e, t) {
|
|
130
|
-
return this.value = s[e], { newDocument: t };
|
|
131
|
-
}
|
|
132
|
-
}, re = {
|
|
133
|
-
add: function(s, e, t) {
|
|
134
|
-
return L(e) ? s.splice(e, 0, this.value) : s[e] = this.value, { newDocument: t, index: e };
|
|
135
|
-
},
|
|
136
|
-
remove: function(s, e, t) {
|
|
137
|
-
var i = s.splice(e, 1);
|
|
138
|
-
return { newDocument: t, removed: i[0] };
|
|
139
|
-
},
|
|
140
|
-
replace: function(s, e, t) {
|
|
141
|
-
var i = s[e];
|
|
142
|
-
return s[e] = this.value, { newDocument: t, removed: i };
|
|
143
|
-
},
|
|
144
|
-
move: v.move,
|
|
145
|
-
copy: v.copy,
|
|
146
|
-
test: v.test,
|
|
147
|
-
_get: v._get
|
|
148
|
-
};
|
|
149
|
-
function T(s, e) {
|
|
150
|
-
if (e == "")
|
|
151
|
-
return s;
|
|
152
|
-
var t = { op: "_get", path: e };
|
|
153
|
-
return x(s, t), t.value;
|
|
154
|
-
}
|
|
155
|
-
function x(s, e, t, i, n, r) {
|
|
156
|
-
if (t === void 0 && (t = !1), i === void 0 && (i = !0), n === void 0 && (n = !0), r === void 0 && (r = 0), t && (typeof t == "function" ? t(e, 0, s, e.path) : B(e, 0)), e.path === "") {
|
|
157
|
-
var h = { newDocument: s };
|
|
158
|
-
if (e.op === "add")
|
|
159
|
-
return h.newDocument = e.value, h;
|
|
160
|
-
if (e.op === "replace")
|
|
161
|
-
return h.newDocument = e.value, h.removed = s, h;
|
|
162
|
-
if (e.op === "move" || e.op === "copy")
|
|
163
|
-
return h.newDocument = T(s, e.from), e.op === "move" && (h.removed = s), h;
|
|
164
|
-
if (e.op === "test") {
|
|
165
|
-
if (h.test = _(s, e.value), h.test === !1)
|
|
166
|
-
throw new f("Test operation failed", "TEST_OPERATION_FAILED", r, e, s);
|
|
167
|
-
return h.newDocument = s, h;
|
|
168
|
-
} else {
|
|
169
|
-
if (e.op === "remove")
|
|
170
|
-
return h.removed = s, h.newDocument = null, h;
|
|
171
|
-
if (e.op === "_get")
|
|
172
|
-
return e.value = s, h;
|
|
173
|
-
if (t)
|
|
174
|
-
throw new f("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", r, e, s);
|
|
175
|
-
return h;
|
|
176
|
-
}
|
|
177
|
-
} else {
|
|
178
|
-
i || (s = p(s));
|
|
179
|
-
var o = e.path || "", a = o.split("/"), c = s, l = 1, d = a.length, E = void 0, u = void 0, O = void 0;
|
|
180
|
-
for (typeof t == "function" ? O = t : O = B; ; ) {
|
|
181
|
-
if (u = a[l], u && u.indexOf("~") != -1 && (u = b(u)), n && (u == "__proto__" || u == "prototype" && l > 0 && a[l - 1] == "constructor"))
|
|
182
|
-
throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");
|
|
183
|
-
if (t && E === void 0 && (c[u] === void 0 ? E = a.slice(0, l).join("/") : l == d - 1 && (E = e.path), E !== void 0 && O(e, 0, s, E)), l++, Array.isArray(c)) {
|
|
184
|
-
if (u === "-")
|
|
185
|
-
u = c.length;
|
|
186
|
-
else {
|
|
187
|
-
if (t && !L(u))
|
|
188
|
-
throw new f("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index", "OPERATION_PATH_ILLEGAL_ARRAY_INDEX", r, e, s);
|
|
189
|
-
L(u) && (u = ~~u);
|
|
190
|
-
}
|
|
191
|
-
if (l >= d) {
|
|
192
|
-
if (t && e.op === "add" && u > c.length)
|
|
193
|
-
throw new f("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", r, e, s);
|
|
194
|
-
var h = re[e.op].call(e, c, u, s);
|
|
195
|
-
if (h.test === !1)
|
|
196
|
-
throw new f("Test operation failed", "TEST_OPERATION_FAILED", r, e, s);
|
|
197
|
-
return h;
|
|
198
|
-
}
|
|
199
|
-
} else if (l >= d) {
|
|
200
|
-
var h = v[e.op].call(e, c, u, s);
|
|
201
|
-
if (h.test === !1)
|
|
202
|
-
throw new f("Test operation failed", "TEST_OPERATION_FAILED", r, e, s);
|
|
203
|
-
return h;
|
|
204
|
-
}
|
|
205
|
-
if (c = c[u], t && l < d && (!c || typeof c != "object"))
|
|
206
|
-
throw new f("Cannot perform operation at the desired path", "OPERATION_PATH_UNRESOLVABLE", r, e, s);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function H(s, e, t, i, n) {
|
|
211
|
-
if (i === void 0 && (i = !0), n === void 0 && (n = !0), t && !Array.isArray(e))
|
|
212
|
-
throw new f("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
213
|
-
i || (s = p(s));
|
|
214
|
-
for (var r = new Array(e.length), h = 0, o = e.length; h < o; h++)
|
|
215
|
-
r[h] = x(s, e[h], t, !0, n, h), s = r[h].newDocument;
|
|
216
|
-
return r.newDocument = s, r;
|
|
217
|
-
}
|
|
218
|
-
function he(s, e, t) {
|
|
219
|
-
var i = x(s, e);
|
|
220
|
-
if (i.test === !1)
|
|
221
|
-
throw new f("Test operation failed", "TEST_OPERATION_FAILED", t, e, s);
|
|
222
|
-
return i.newDocument;
|
|
223
|
-
}
|
|
224
|
-
function B(s, e, t, i) {
|
|
225
|
-
if (typeof s != "object" || s === null || Array.isArray(s))
|
|
226
|
-
throw new f("Operation is not an object", "OPERATION_NOT_AN_OBJECT", e, s, t);
|
|
227
|
-
if (v[s.op]) {
|
|
228
|
-
if (typeof s.path != "string")
|
|
229
|
-
throw new f("Operation `path` property is not a string", "OPERATION_PATH_INVALID", e, s, t);
|
|
230
|
-
if (s.path.indexOf("/") !== 0 && s.path.length > 0)
|
|
231
|
-
throw new f('Operation `path` property must start with "/"', "OPERATION_PATH_INVALID", e, s, t);
|
|
232
|
-
if ((s.op === "move" || s.op === "copy") && typeof s.from != "string")
|
|
233
|
-
throw new f("Operation `from` property is not present (applicable in `move` and `copy` operations)", "OPERATION_FROM_REQUIRED", e, s, t);
|
|
234
|
-
if ((s.op === "add" || s.op === "replace" || s.op === "test") && s.value === void 0)
|
|
235
|
-
throw new f("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_REQUIRED", e, s, t);
|
|
236
|
-
if ((s.op === "add" || s.op === "replace" || s.op === "test") && R(s.value))
|
|
237
|
-
throw new f("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)", "OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED", e, s, t);
|
|
238
|
-
if (t) {
|
|
239
|
-
if (s.op == "add") {
|
|
240
|
-
var n = s.path.split("/").length, r = i.split("/").length;
|
|
241
|
-
if (n !== r + 1 && n !== r)
|
|
242
|
-
throw new f("Cannot perform an `add` operation at the desired path", "OPERATION_PATH_CANNOT_ADD", e, s, t);
|
|
243
|
-
} else if (s.op === "replace" || s.op === "remove" || s.op === "_get") {
|
|
244
|
-
if (s.path !== i)
|
|
245
|
-
throw new f("Cannot perform the operation at a path that does not exist", "OPERATION_PATH_UNRESOLVABLE", e, s, t);
|
|
246
|
-
} else if (s.op === "move" || s.op === "copy") {
|
|
247
|
-
var h = { op: "_get", path: s.from, value: void 0 }, o = G([h], t);
|
|
248
|
-
if (o && o.name === "OPERATION_PATH_UNRESOLVABLE")
|
|
249
|
-
throw new f("Cannot perform the operation from a path that does not exist", "OPERATION_FROM_UNRESOLVABLE", e, s, t);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
} else throw new f("Operation `op` property is not one of operations defined in RFC-6902", "OPERATION_OP_INVALID", e, s, t);
|
|
253
|
-
}
|
|
254
|
-
function G(s, e, t) {
|
|
255
|
-
try {
|
|
256
|
-
if (!Array.isArray(s))
|
|
257
|
-
throw new f("Patch sequence must be an array", "SEQUENCE_NOT_AN_ARRAY");
|
|
258
|
-
if (e)
|
|
259
|
-
H(p(e), p(s), t || !0);
|
|
260
|
-
else {
|
|
261
|
-
t = t || B;
|
|
262
|
-
for (var i = 0; i < s.length; i++)
|
|
263
|
-
t(s[i], i, e, void 0);
|
|
264
|
-
}
|
|
265
|
-
} catch (n) {
|
|
266
|
-
if (n instanceof f)
|
|
267
|
-
return n;
|
|
268
|
-
throw n;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function _(s, e) {
|
|
272
|
-
if (s === e)
|
|
273
|
-
return !0;
|
|
274
|
-
if (s && e && typeof s == "object" && typeof e == "object") {
|
|
275
|
-
var t = Array.isArray(s), i = Array.isArray(e), n, r, h;
|
|
276
|
-
if (t && i) {
|
|
277
|
-
if (r = s.length, r != e.length)
|
|
278
|
-
return !1;
|
|
279
|
-
for (n = r; n-- !== 0; )
|
|
280
|
-
if (!_(s[n], e[n]))
|
|
281
|
-
return !1;
|
|
282
|
-
return !0;
|
|
283
|
-
}
|
|
284
|
-
if (t != i)
|
|
285
|
-
return !1;
|
|
286
|
-
var o = Object.keys(s);
|
|
287
|
-
if (r = o.length, r !== Object.keys(e).length)
|
|
288
|
-
return !1;
|
|
289
|
-
for (n = r; n-- !== 0; )
|
|
290
|
-
if (!e.hasOwnProperty(o[n]))
|
|
291
|
-
return !1;
|
|
292
|
-
for (n = r; n-- !== 0; )
|
|
293
|
-
if (h = o[n], !_(s[h], e[h]))
|
|
294
|
-
return !1;
|
|
295
|
-
return !0;
|
|
296
|
-
}
|
|
297
|
-
return s !== s && e !== e;
|
|
298
|
-
}
|
|
299
|
-
const oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
300
|
-
__proto__: null,
|
|
301
|
-
JsonPatchError: f,
|
|
302
|
-
_areEquals: _,
|
|
303
|
-
applyOperation: x,
|
|
304
|
-
applyPatch: H,
|
|
305
|
-
applyReducer: he,
|
|
306
|
-
deepClone: ne,
|
|
307
|
-
getValueByPointer: T,
|
|
308
|
-
validate: G,
|
|
309
|
-
validator: B
|
|
310
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
311
|
-
/*!
|
|
312
|
-
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
313
|
-
* (c) 2017-2021 Joachim Wester
|
|
314
|
-
* MIT license
|
|
315
|
-
*/
|
|
316
|
-
var k = /* @__PURE__ */ new WeakMap(), ae = (
|
|
317
|
-
/** @class */
|
|
318
|
-
/* @__PURE__ */ function() {
|
|
319
|
-
function s(e) {
|
|
320
|
-
this.observers = /* @__PURE__ */ new Map(), this.obj = e;
|
|
321
|
-
}
|
|
322
|
-
return s;
|
|
323
|
-
}()
|
|
324
|
-
), ce = (
|
|
325
|
-
/** @class */
|
|
326
|
-
/* @__PURE__ */ function() {
|
|
327
|
-
function s(e, t) {
|
|
328
|
-
this.callback = e, this.observer = t;
|
|
329
|
-
}
|
|
330
|
-
return s;
|
|
331
|
-
}()
|
|
332
|
-
);
|
|
333
|
-
function fe(s) {
|
|
334
|
-
return k.get(s);
|
|
335
|
-
}
|
|
336
|
-
function le(s, e) {
|
|
337
|
-
return s.observers.get(e);
|
|
338
|
-
}
|
|
339
|
-
function de(s, e) {
|
|
340
|
-
s.observers.delete(e.callback);
|
|
341
|
-
}
|
|
342
|
-
function ue(s, e) {
|
|
343
|
-
e.unobserve();
|
|
344
|
-
}
|
|
345
|
-
function we(s, e) {
|
|
346
|
-
var t = [], i, n = fe(s);
|
|
347
|
-
if (!n)
|
|
348
|
-
n = new ae(s), k.set(s, n);
|
|
349
|
-
else {
|
|
350
|
-
var r = le(n, e);
|
|
351
|
-
i = r && r.observer;
|
|
352
|
-
}
|
|
353
|
-
if (i)
|
|
354
|
-
return i;
|
|
355
|
-
if (i = {}, n.value = p(s), e) {
|
|
356
|
-
i.callback = e, i.next = null;
|
|
357
|
-
var h = function() {
|
|
358
|
-
N(i);
|
|
359
|
-
}, o = function() {
|
|
360
|
-
clearTimeout(i.next), i.next = setTimeout(h);
|
|
361
|
-
};
|
|
362
|
-
typeof window < "u" && (window.addEventListener("mouseup", o), window.addEventListener("keyup", o), window.addEventListener("mousedown", o), window.addEventListener("keydown", o), window.addEventListener("change", o));
|
|
363
|
-
}
|
|
364
|
-
return i.patches = t, i.object = s, i.unobserve = function() {
|
|
365
|
-
N(i), clearTimeout(i.next), de(n, i), typeof window < "u" && (window.removeEventListener("mouseup", o), window.removeEventListener("keyup", o), window.removeEventListener("mousedown", o), window.removeEventListener("keydown", o), window.removeEventListener("change", o));
|
|
366
|
-
}, n.observers.set(e, new ce(e, i)), i;
|
|
367
|
-
}
|
|
368
|
-
function N(s, e) {
|
|
369
|
-
e === void 0 && (e = !1);
|
|
370
|
-
var t = k.get(s.object);
|
|
371
|
-
$(t.value, s.object, s.patches, "", e), s.patches.length && H(t.value, s.patches);
|
|
372
|
-
var i = s.patches;
|
|
373
|
-
return i.length > 0 && (s.patches = [], s.callback && s.callback(i)), i;
|
|
374
|
-
}
|
|
375
|
-
function $(s, e, t, i, n) {
|
|
376
|
-
if (e !== s) {
|
|
377
|
-
typeof e.toJSON == "function" && (e = e.toJSON());
|
|
378
|
-
for (var r = P(e), h = P(s), o = !1, a = h.length - 1; a >= 0; a--) {
|
|
379
|
-
var c = h[a], l = s[c];
|
|
380
|
-
if (C(e, c) && !(e[c] === void 0 && l !== void 0 && Array.isArray(e) === !1)) {
|
|
381
|
-
var d = e[c];
|
|
382
|
-
typeof l == "object" && l != null && typeof d == "object" && d != null && Array.isArray(l) === Array.isArray(d) ? $(l, d, t, i + "/" + y(c), n) : l !== d && (n && t.push({ op: "test", path: i + "/" + y(c), value: p(l) }), t.push({ op: "replace", path: i + "/" + y(c), value: p(d) }));
|
|
383
|
-
} else Array.isArray(s) === Array.isArray(e) ? (n && t.push({ op: "test", path: i + "/" + y(c), value: p(l) }), t.push({ op: "remove", path: i + "/" + y(c) }), o = !0) : (n && t.push({ op: "test", path: i, value: s }), t.push({ op: "replace", path: i, value: e }));
|
|
384
|
-
}
|
|
385
|
-
if (!(!o && r.length == h.length))
|
|
386
|
-
for (var a = 0; a < r.length; a++) {
|
|
387
|
-
var c = r[a];
|
|
388
|
-
!C(s, c) && e[c] !== void 0 && t.push({ op: "add", path: i + "/" + y(c), value: p(e[c]) });
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
function ge(s, e, t) {
|
|
393
|
-
t === void 0 && (t = !1);
|
|
394
|
-
var i = [];
|
|
395
|
-
return $(s, e, i, "", t), i;
|
|
396
|
-
}
|
|
397
|
-
const pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
398
|
-
__proto__: null,
|
|
399
|
-
compare: ge,
|
|
400
|
-
generate: N,
|
|
401
|
-
observe: we,
|
|
402
|
-
unobserve: ue
|
|
403
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
404
|
-
Object.assign({}, oe, pe, {
|
|
405
|
-
JsonPatchError: Q,
|
|
406
|
-
deepClone: p,
|
|
407
|
-
escapePathComponent: y,
|
|
408
|
-
unescapePathComponent: b
|
|
409
|
-
});
|
|
410
|
-
function xe(s) {
|
|
411
|
-
const e = s.length;
|
|
412
|
-
let t = 0, i = 0;
|
|
413
|
-
for (; i < e; ) {
|
|
414
|
-
let n = s.charCodeAt(i++);
|
|
415
|
-
if ((n & 4294967168) === 0) {
|
|
416
|
-
t++;
|
|
417
|
-
continue;
|
|
418
|
-
} else if ((n & 4294965248) === 0)
|
|
419
|
-
t += 2;
|
|
420
|
-
else {
|
|
421
|
-
if (n >= 55296 && n <= 56319 && i < e) {
|
|
422
|
-
const r = s.charCodeAt(i);
|
|
423
|
-
(r & 64512) === 56320 && (++i, n = ((n & 1023) << 10) + (r & 1023) + 65536);
|
|
424
|
-
}
|
|
425
|
-
(n & 4294901760) === 0 ? t += 3 : t += 4;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
return t;
|
|
429
|
-
}
|
|
430
|
-
function ye(s, e, t) {
|
|
431
|
-
const i = s.length;
|
|
432
|
-
let n = t, r = 0;
|
|
433
|
-
for (; r < i; ) {
|
|
434
|
-
let h = s.charCodeAt(r++);
|
|
435
|
-
if ((h & 4294967168) === 0) {
|
|
436
|
-
e[n++] = h;
|
|
437
|
-
continue;
|
|
438
|
-
} else if ((h & 4294965248) === 0)
|
|
439
|
-
e[n++] = h >> 6 & 31 | 192;
|
|
440
|
-
else {
|
|
441
|
-
if (h >= 55296 && h <= 56319 && r < i) {
|
|
442
|
-
const o = s.charCodeAt(r);
|
|
443
|
-
(o & 64512) === 56320 && (++r, h = ((h & 1023) << 10) + (o & 1023) + 65536);
|
|
444
|
-
}
|
|
445
|
-
(h & 4294901760) === 0 ? (e[n++] = h >> 12 & 15 | 224, e[n++] = h >> 6 & 63 | 128) : (e[n++] = h >> 18 & 7 | 240, e[n++] = h >> 12 & 63 | 128, e[n++] = h >> 6 & 63 | 128);
|
|
446
|
-
}
|
|
447
|
-
e[n++] = h & 63 | 128;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
const ve = new TextEncoder(), Ee = 50;
|
|
451
|
-
function me(s, e, t) {
|
|
452
|
-
ve.encodeInto(s, e.subarray(t));
|
|
453
|
-
}
|
|
454
|
-
function Ue(s, e, t) {
|
|
455
|
-
s.length > Ee ? me(s, e, t) : ye(s, e, t);
|
|
456
|
-
}
|
|
457
|
-
const Ae = 4096;
|
|
458
|
-
function q(s, e, t) {
|
|
459
|
-
let i = e;
|
|
460
|
-
const n = i + t, r = [];
|
|
461
|
-
let h = "";
|
|
462
|
-
for (; i < n; ) {
|
|
463
|
-
const o = s[i++];
|
|
464
|
-
if ((o & 128) === 0)
|
|
465
|
-
r.push(o);
|
|
466
|
-
else if ((o & 224) === 192) {
|
|
467
|
-
const a = s[i++] & 63;
|
|
468
|
-
r.push((o & 31) << 6 | a);
|
|
469
|
-
} else if ((o & 240) === 224) {
|
|
470
|
-
const a = s[i++] & 63, c = s[i++] & 63;
|
|
471
|
-
r.push((o & 31) << 12 | a << 6 | c);
|
|
472
|
-
} else if ((o & 248) === 240) {
|
|
473
|
-
const a = s[i++] & 63, c = s[i++] & 63, l = s[i++] & 63;
|
|
474
|
-
let d = (o & 7) << 18 | a << 12 | c << 6 | l;
|
|
475
|
-
d > 65535 && (d -= 65536, r.push(d >>> 10 & 1023 | 55296), d = 56320 | d & 1023), r.push(d);
|
|
476
|
-
} else
|
|
477
|
-
r.push(o);
|
|
478
|
-
r.length >= Ae && (h += String.fromCharCode(...r), r.length = 0);
|
|
479
|
-
}
|
|
480
|
-
return r.length > 0 && (h += String.fromCharCode(...r)), h;
|
|
481
|
-
}
|
|
482
|
-
const _e = new TextDecoder(), Se = 200;
|
|
483
|
-
function Te(s, e, t) {
|
|
484
|
-
const i = s.subarray(e, e + t);
|
|
485
|
-
return _e.decode(i);
|
|
486
|
-
}
|
|
487
|
-
function Be(s, e, t) {
|
|
488
|
-
return t > Se ? Te(s, e, t) : q(s, e, t);
|
|
489
|
-
}
|
|
490
|
-
class S {
|
|
491
|
-
constructor(e, t) {
|
|
492
|
-
this.type = e, this.data = t;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
class g extends Error {
|
|
496
|
-
constructor(e) {
|
|
497
|
-
super(e);
|
|
498
|
-
const t = Object.create(g.prototype);
|
|
499
|
-
Object.setPrototypeOf(this, t), Object.defineProperty(this, "name", {
|
|
500
|
-
configurable: !0,
|
|
501
|
-
enumerable: !1,
|
|
502
|
-
value: g.name
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
const m = 4294967295;
|
|
507
|
-
function Ie(s, e, t) {
|
|
508
|
-
const i = t / 4294967296, n = t;
|
|
509
|
-
s.setUint32(e, i), s.setUint32(e + 4, n);
|
|
510
|
-
}
|
|
511
|
-
function Z(s, e, t) {
|
|
512
|
-
const i = Math.floor(t / 4294967296), n = t;
|
|
513
|
-
s.setUint32(e, i), s.setUint32(e + 4, n);
|
|
514
|
-
}
|
|
515
|
-
function V(s, e) {
|
|
516
|
-
const t = s.getInt32(e), i = s.getUint32(e + 4);
|
|
517
|
-
return t * 4294967296 + i;
|
|
518
|
-
}
|
|
519
|
-
function Oe(s, e) {
|
|
520
|
-
const t = s.getUint32(e), i = s.getUint32(e + 4);
|
|
521
|
-
return t * 4294967296 + i;
|
|
522
|
-
}
|
|
523
|
-
const De = -1, Ce = 4294967296 - 1, Pe = 17179869184 - 1;
|
|
524
|
-
function Le({ sec: s, nsec: e }) {
|
|
525
|
-
if (s >= 0 && e >= 0 && s <= Pe)
|
|
526
|
-
if (e === 0 && s <= Ce) {
|
|
527
|
-
const t = new Uint8Array(4);
|
|
528
|
-
return new DataView(t.buffer).setUint32(0, s), t;
|
|
529
|
-
} else {
|
|
530
|
-
const t = s / 4294967296, i = s & 4294967295, n = new Uint8Array(8), r = new DataView(n.buffer);
|
|
531
|
-
return r.setUint32(0, e << 2 | t & 3), r.setUint32(4, i), n;
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
const t = new Uint8Array(12), i = new DataView(t.buffer);
|
|
535
|
-
return i.setUint32(0, e), Z(i, 4, s), t;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
function Re(s) {
|
|
539
|
-
const e = s.getTime(), t = Math.floor(e / 1e3), i = (e - t * 1e3) * 1e6, n = Math.floor(i / 1e9);
|
|
540
|
-
return {
|
|
541
|
-
sec: t + n,
|
|
542
|
-
nsec: i - n * 1e9
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
function Ne(s) {
|
|
546
|
-
if (s instanceof Date) {
|
|
547
|
-
const e = Re(s);
|
|
548
|
-
return Le(e);
|
|
549
|
-
} else
|
|
550
|
-
return null;
|
|
551
|
-
}
|
|
552
|
-
function Me(s) {
|
|
553
|
-
const e = new DataView(s.buffer, s.byteOffset, s.byteLength);
|
|
554
|
-
switch (s.byteLength) {
|
|
555
|
-
case 4:
|
|
556
|
-
return { sec: e.getUint32(0), nsec: 0 };
|
|
557
|
-
case 8: {
|
|
558
|
-
const t = e.getUint32(0), i = e.getUint32(4), n = (t & 3) * 4294967296 + i, r = t >>> 2;
|
|
559
|
-
return { sec: n, nsec: r };
|
|
560
|
-
}
|
|
561
|
-
case 12: {
|
|
562
|
-
const t = V(e, 4), i = e.getUint32(0);
|
|
563
|
-
return { sec: t, nsec: i };
|
|
564
|
-
}
|
|
565
|
-
default:
|
|
566
|
-
throw new g(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
function ze(s) {
|
|
570
|
-
const e = Me(s);
|
|
571
|
-
return new Date(e.sec * 1e3 + e.nsec / 1e6);
|
|
572
|
-
}
|
|
573
|
-
const Fe = {
|
|
574
|
-
type: De,
|
|
575
|
-
encode: Ne,
|
|
576
|
-
decode: ze
|
|
577
|
-
};
|
|
578
|
-
class I {
|
|
579
|
-
constructor() {
|
|
580
|
-
this.builtInEncoders = [], this.builtInDecoders = [], this.encoders = [], this.decoders = [], this.register(Fe);
|
|
581
|
-
}
|
|
582
|
-
register({ type: e, encode: t, decode: i }) {
|
|
583
|
-
if (e >= 0)
|
|
584
|
-
this.encoders[e] = t, this.decoders[e] = i;
|
|
585
|
-
else {
|
|
586
|
-
const n = -1 - e;
|
|
587
|
-
this.builtInEncoders[n] = t, this.builtInDecoders[n] = i;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
tryToEncode(e, t) {
|
|
591
|
-
for (let i = 0; i < this.builtInEncoders.length; i++) {
|
|
592
|
-
const n = this.builtInEncoders[i];
|
|
593
|
-
if (n != null) {
|
|
594
|
-
const r = n(e, t);
|
|
595
|
-
if (r != null) {
|
|
596
|
-
const h = -1 - i;
|
|
597
|
-
return new S(h, r);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
for (let i = 0; i < this.encoders.length; i++) {
|
|
602
|
-
const n = this.encoders[i];
|
|
603
|
-
if (n != null) {
|
|
604
|
-
const r = n(e, t);
|
|
605
|
-
if (r != null) {
|
|
606
|
-
const h = i;
|
|
607
|
-
return new S(h, r);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return e instanceof S ? e : null;
|
|
612
|
-
}
|
|
613
|
-
decode(e, t, i) {
|
|
614
|
-
const n = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
|
|
615
|
-
return n ? n(e, t, i) : new S(t, e);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
I.defaultCodec = new I();
|
|
619
|
-
function He(s) {
|
|
620
|
-
return s instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && s instanceof SharedArrayBuffer;
|
|
621
|
-
}
|
|
622
|
-
function M(s) {
|
|
623
|
-
return s instanceof Uint8Array ? s : ArrayBuffer.isView(s) ? new Uint8Array(s.buffer, s.byteOffset, s.byteLength) : He(s) ? new Uint8Array(s) : Uint8Array.from(s);
|
|
624
|
-
}
|
|
625
|
-
const ke = 100, $e = 2048;
|
|
626
|
-
class K {
|
|
627
|
-
constructor(e) {
|
|
628
|
-
this.entered = !1, this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? I.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.maxDepth = (e == null ? void 0 : e.maxDepth) ?? ke, this.initialBufferSize = (e == null ? void 0 : e.initialBufferSize) ?? $e, this.sortKeys = (e == null ? void 0 : e.sortKeys) ?? !1, this.forceFloat32 = (e == null ? void 0 : e.forceFloat32) ?? !1, this.ignoreUndefined = (e == null ? void 0 : e.ignoreUndefined) ?? !1, this.forceIntegerToFloat = (e == null ? void 0 : e.forceIntegerToFloat) ?? !1, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
|
|
629
|
-
}
|
|
630
|
-
clone() {
|
|
631
|
-
return new K({
|
|
632
|
-
extensionCodec: this.extensionCodec,
|
|
633
|
-
context: this.context,
|
|
634
|
-
useBigInt64: this.useBigInt64,
|
|
635
|
-
maxDepth: this.maxDepth,
|
|
636
|
-
initialBufferSize: this.initialBufferSize,
|
|
637
|
-
sortKeys: this.sortKeys,
|
|
638
|
-
forceFloat32: this.forceFloat32,
|
|
639
|
-
ignoreUndefined: this.ignoreUndefined,
|
|
640
|
-
forceIntegerToFloat: this.forceIntegerToFloat
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
reinitializeState() {
|
|
644
|
-
this.pos = 0;
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
|
|
648
|
-
*
|
|
649
|
-
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
|
|
650
|
-
*/
|
|
651
|
-
encodeSharedRef(e) {
|
|
652
|
-
if (this.entered)
|
|
653
|
-
return this.clone().encodeSharedRef(e);
|
|
654
|
-
try {
|
|
655
|
-
return this.entered = !0, this.reinitializeState(), this.doEncode(e, 1), this.bytes.subarray(0, this.pos);
|
|
656
|
-
} finally {
|
|
657
|
-
this.entered = !1;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
|
|
662
|
-
*/
|
|
663
|
-
encode(e) {
|
|
664
|
-
if (this.entered)
|
|
665
|
-
return this.clone().encode(e);
|
|
666
|
-
try {
|
|
667
|
-
return this.entered = !0, this.reinitializeState(), this.doEncode(e, 1), this.bytes.slice(0, this.pos);
|
|
668
|
-
} finally {
|
|
669
|
-
this.entered = !1;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
doEncode(e, t) {
|
|
673
|
-
if (t > this.maxDepth)
|
|
674
|
-
throw new Error(`Too deep objects in depth ${t}`);
|
|
675
|
-
e == null ? this.encodeNil() : typeof e == "boolean" ? this.encodeBoolean(e) : typeof e == "number" ? this.forceIntegerToFloat ? this.encodeNumberAsFloat(e) : this.encodeNumber(e) : typeof e == "string" ? this.encodeString(e) : this.useBigInt64 && typeof e == "bigint" ? this.encodeBigInt64(e) : this.encodeObject(e, t);
|
|
676
|
-
}
|
|
677
|
-
ensureBufferSizeToWrite(e) {
|
|
678
|
-
const t = this.pos + e;
|
|
679
|
-
this.view.byteLength < t && this.resizeBuffer(t * 2);
|
|
680
|
-
}
|
|
681
|
-
resizeBuffer(e) {
|
|
682
|
-
const t = new ArrayBuffer(e), i = new Uint8Array(t), n = new DataView(t);
|
|
683
|
-
i.set(this.bytes), this.view = n, this.bytes = i;
|
|
684
|
-
}
|
|
685
|
-
encodeNil() {
|
|
686
|
-
this.writeU8(192);
|
|
687
|
-
}
|
|
688
|
-
encodeBoolean(e) {
|
|
689
|
-
e === !1 ? this.writeU8(194) : this.writeU8(195);
|
|
690
|
-
}
|
|
691
|
-
encodeNumber(e) {
|
|
692
|
-
!this.forceIntegerToFloat && Number.isSafeInteger(e) ? e >= 0 ? e < 128 ? this.writeU8(e) : e < 256 ? (this.writeU8(204), this.writeU8(e)) : e < 65536 ? (this.writeU8(205), this.writeU16(e)) : e < 4294967296 ? (this.writeU8(206), this.writeU32(e)) : this.useBigInt64 ? this.encodeNumberAsFloat(e) : (this.writeU8(207), this.writeU64(e)) : e >= -32 ? this.writeU8(224 | e + 32) : e >= -128 ? (this.writeU8(208), this.writeI8(e)) : e >= -32768 ? (this.writeU8(209), this.writeI16(e)) : e >= -2147483648 ? (this.writeU8(210), this.writeI32(e)) : this.useBigInt64 ? this.encodeNumberAsFloat(e) : (this.writeU8(211), this.writeI64(e)) : this.encodeNumberAsFloat(e);
|
|
693
|
-
}
|
|
694
|
-
encodeNumberAsFloat(e) {
|
|
695
|
-
this.forceFloat32 ? (this.writeU8(202), this.writeF32(e)) : (this.writeU8(203), this.writeF64(e));
|
|
696
|
-
}
|
|
697
|
-
encodeBigInt64(e) {
|
|
698
|
-
e >= BigInt(0) ? (this.writeU8(207), this.writeBigUint64(e)) : (this.writeU8(211), this.writeBigInt64(e));
|
|
699
|
-
}
|
|
700
|
-
writeStringHeader(e) {
|
|
701
|
-
if (e < 32)
|
|
702
|
-
this.writeU8(160 + e);
|
|
703
|
-
else if (e < 256)
|
|
704
|
-
this.writeU8(217), this.writeU8(e);
|
|
705
|
-
else if (e < 65536)
|
|
706
|
-
this.writeU8(218), this.writeU16(e);
|
|
707
|
-
else if (e < 4294967296)
|
|
708
|
-
this.writeU8(219), this.writeU32(e);
|
|
709
|
-
else
|
|
710
|
-
throw new Error(`Too long string: ${e} bytes in UTF-8`);
|
|
711
|
-
}
|
|
712
|
-
encodeString(e) {
|
|
713
|
-
const i = xe(e);
|
|
714
|
-
this.ensureBufferSizeToWrite(5 + i), this.writeStringHeader(i), Ue(e, this.bytes, this.pos), this.pos += i;
|
|
715
|
-
}
|
|
716
|
-
encodeObject(e, t) {
|
|
717
|
-
const i = this.extensionCodec.tryToEncode(e, this.context);
|
|
718
|
-
if (i != null)
|
|
719
|
-
this.encodeExtension(i);
|
|
720
|
-
else if (Array.isArray(e))
|
|
721
|
-
this.encodeArray(e, t);
|
|
722
|
-
else if (ArrayBuffer.isView(e))
|
|
723
|
-
this.encodeBinary(e);
|
|
724
|
-
else if (typeof e == "object")
|
|
725
|
-
this.encodeMap(e, t);
|
|
726
|
-
else
|
|
727
|
-
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`);
|
|
728
|
-
}
|
|
729
|
-
encodeBinary(e) {
|
|
730
|
-
const t = e.byteLength;
|
|
731
|
-
if (t < 256)
|
|
732
|
-
this.writeU8(196), this.writeU8(t);
|
|
733
|
-
else if (t < 65536)
|
|
734
|
-
this.writeU8(197), this.writeU16(t);
|
|
735
|
-
else if (t < 4294967296)
|
|
736
|
-
this.writeU8(198), this.writeU32(t);
|
|
737
|
-
else
|
|
738
|
-
throw new Error(`Too large binary: ${t}`);
|
|
739
|
-
const i = M(e);
|
|
740
|
-
this.writeU8a(i);
|
|
741
|
-
}
|
|
742
|
-
encodeArray(e, t) {
|
|
743
|
-
const i = e.length;
|
|
744
|
-
if (i < 16)
|
|
745
|
-
this.writeU8(144 + i);
|
|
746
|
-
else if (i < 65536)
|
|
747
|
-
this.writeU8(220), this.writeU16(i);
|
|
748
|
-
else if (i < 4294967296)
|
|
749
|
-
this.writeU8(221), this.writeU32(i);
|
|
750
|
-
else
|
|
751
|
-
throw new Error(`Too large array: ${i}`);
|
|
752
|
-
for (const n of e)
|
|
753
|
-
this.doEncode(n, t + 1);
|
|
754
|
-
}
|
|
755
|
-
countWithoutUndefined(e, t) {
|
|
756
|
-
let i = 0;
|
|
757
|
-
for (const n of t)
|
|
758
|
-
e[n] !== void 0 && i++;
|
|
759
|
-
return i;
|
|
760
|
-
}
|
|
761
|
-
encodeMap(e, t) {
|
|
762
|
-
const i = Object.keys(e);
|
|
763
|
-
this.sortKeys && i.sort();
|
|
764
|
-
const n = this.ignoreUndefined ? this.countWithoutUndefined(e, i) : i.length;
|
|
765
|
-
if (n < 16)
|
|
766
|
-
this.writeU8(128 + n);
|
|
767
|
-
else if (n < 65536)
|
|
768
|
-
this.writeU8(222), this.writeU16(n);
|
|
769
|
-
else if (n < 4294967296)
|
|
770
|
-
this.writeU8(223), this.writeU32(n);
|
|
771
|
-
else
|
|
772
|
-
throw new Error(`Too large map object: ${n}`);
|
|
773
|
-
for (const r of i) {
|
|
774
|
-
const h = e[r];
|
|
775
|
-
this.ignoreUndefined && h === void 0 || (this.encodeString(r), this.doEncode(h, t + 1));
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
encodeExtension(e) {
|
|
779
|
-
if (typeof e.data == "function") {
|
|
780
|
-
const i = e.data(this.pos + 6), n = i.length;
|
|
781
|
-
if (n >= 4294967296)
|
|
782
|
-
throw new Error(`Too large extension object: ${n}`);
|
|
783
|
-
this.writeU8(201), this.writeU32(n), this.writeI8(e.type), this.writeU8a(i);
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
const t = e.data.length;
|
|
787
|
-
if (t === 1)
|
|
788
|
-
this.writeU8(212);
|
|
789
|
-
else if (t === 2)
|
|
790
|
-
this.writeU8(213);
|
|
791
|
-
else if (t === 4)
|
|
792
|
-
this.writeU8(214);
|
|
793
|
-
else if (t === 8)
|
|
794
|
-
this.writeU8(215);
|
|
795
|
-
else if (t === 16)
|
|
796
|
-
this.writeU8(216);
|
|
797
|
-
else if (t < 256)
|
|
798
|
-
this.writeU8(199), this.writeU8(t);
|
|
799
|
-
else if (t < 65536)
|
|
800
|
-
this.writeU8(200), this.writeU16(t);
|
|
801
|
-
else if (t < 4294967296)
|
|
802
|
-
this.writeU8(201), this.writeU32(t);
|
|
803
|
-
else
|
|
804
|
-
throw new Error(`Too large extension object: ${t}`);
|
|
805
|
-
this.writeI8(e.type), this.writeU8a(e.data);
|
|
806
|
-
}
|
|
807
|
-
writeU8(e) {
|
|
808
|
-
this.ensureBufferSizeToWrite(1), this.view.setUint8(this.pos, e), this.pos++;
|
|
809
|
-
}
|
|
810
|
-
writeU8a(e) {
|
|
811
|
-
const t = e.length;
|
|
812
|
-
this.ensureBufferSizeToWrite(t), this.bytes.set(e, this.pos), this.pos += t;
|
|
813
|
-
}
|
|
814
|
-
writeI8(e) {
|
|
815
|
-
this.ensureBufferSizeToWrite(1), this.view.setInt8(this.pos, e), this.pos++;
|
|
816
|
-
}
|
|
817
|
-
writeU16(e) {
|
|
818
|
-
this.ensureBufferSizeToWrite(2), this.view.setUint16(this.pos, e), this.pos += 2;
|
|
819
|
-
}
|
|
820
|
-
writeI16(e) {
|
|
821
|
-
this.ensureBufferSizeToWrite(2), this.view.setInt16(this.pos, e), this.pos += 2;
|
|
822
|
-
}
|
|
823
|
-
writeU32(e) {
|
|
824
|
-
this.ensureBufferSizeToWrite(4), this.view.setUint32(this.pos, e), this.pos += 4;
|
|
825
|
-
}
|
|
826
|
-
writeI32(e) {
|
|
827
|
-
this.ensureBufferSizeToWrite(4), this.view.setInt32(this.pos, e), this.pos += 4;
|
|
828
|
-
}
|
|
829
|
-
writeF32(e) {
|
|
830
|
-
this.ensureBufferSizeToWrite(4), this.view.setFloat32(this.pos, e), this.pos += 4;
|
|
831
|
-
}
|
|
832
|
-
writeF64(e) {
|
|
833
|
-
this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
|
|
834
|
-
}
|
|
835
|
-
writeU64(e) {
|
|
836
|
-
this.ensureBufferSizeToWrite(8), Ie(this.view, this.pos, e), this.pos += 8;
|
|
837
|
-
}
|
|
838
|
-
writeI64(e) {
|
|
839
|
-
this.ensureBufferSizeToWrite(8), Z(this.view, this.pos, e), this.pos += 8;
|
|
840
|
-
}
|
|
841
|
-
writeBigUint64(e) {
|
|
842
|
-
this.ensureBufferSizeToWrite(8), this.view.setBigUint64(this.pos, e), this.pos += 8;
|
|
843
|
-
}
|
|
844
|
-
writeBigInt64(e) {
|
|
845
|
-
this.ensureBufferSizeToWrite(8), this.view.setBigInt64(this.pos, e), this.pos += 8;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
function Ke(s, e) {
|
|
849
|
-
return new K(e).encodeSharedRef(s);
|
|
850
|
-
}
|
|
851
|
-
function D(s) {
|
|
852
|
-
return `${s < 0 ? "-" : ""}0x${Math.abs(s).toString(16).padStart(2, "0")}`;
|
|
853
|
-
}
|
|
854
|
-
const We = 16, Ye = 16;
|
|
855
|
-
class Je {
|
|
856
|
-
constructor(e = We, t = Ye) {
|
|
857
|
-
this.hit = 0, this.miss = 0, this.maxKeyLength = e, this.maxLengthPerKey = t, this.caches = [];
|
|
858
|
-
for (let i = 0; i < this.maxKeyLength; i++)
|
|
859
|
-
this.caches.push([]);
|
|
860
|
-
}
|
|
861
|
-
canBeCached(e) {
|
|
862
|
-
return e > 0 && e <= this.maxKeyLength;
|
|
863
|
-
}
|
|
864
|
-
find(e, t, i) {
|
|
865
|
-
const n = this.caches[i - 1];
|
|
866
|
-
e: for (const r of n) {
|
|
867
|
-
const h = r.bytes;
|
|
868
|
-
for (let o = 0; o < i; o++)
|
|
869
|
-
if (h[o] !== e[t + o])
|
|
870
|
-
continue e;
|
|
871
|
-
return r.str;
|
|
872
|
-
}
|
|
873
|
-
return null;
|
|
874
|
-
}
|
|
875
|
-
store(e, t) {
|
|
876
|
-
const i = this.caches[e.length - 1], n = { bytes: e, str: t };
|
|
877
|
-
i.length >= this.maxLengthPerKey ? i[Math.random() * i.length | 0] = n : i.push(n);
|
|
878
|
-
}
|
|
879
|
-
decode(e, t, i) {
|
|
880
|
-
const n = this.find(e, t, i);
|
|
881
|
-
if (n != null)
|
|
882
|
-
return this.hit++, n;
|
|
883
|
-
this.miss++;
|
|
884
|
-
const r = q(e, t, i), h = Uint8Array.prototype.slice.call(e, t, t + i);
|
|
885
|
-
return this.store(h, r), r;
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
const z = "array", A = "map_key", j = "map_value", Xe = (s) => {
|
|
889
|
-
if (typeof s == "string" || typeof s == "number")
|
|
890
|
-
return s;
|
|
891
|
-
throw new g("The type of key must be string or number but " + typeof s);
|
|
892
|
-
};
|
|
893
|
-
class be {
|
|
894
|
-
constructor() {
|
|
895
|
-
this.stack = [], this.stackHeadPosition = -1;
|
|
896
|
-
}
|
|
897
|
-
get length() {
|
|
898
|
-
return this.stackHeadPosition + 1;
|
|
899
|
-
}
|
|
900
|
-
top() {
|
|
901
|
-
return this.stack[this.stackHeadPosition];
|
|
902
|
-
}
|
|
903
|
-
pushArrayState(e) {
|
|
904
|
-
const t = this.getUninitializedStateFromPool();
|
|
905
|
-
t.type = z, t.position = 0, t.size = e, t.array = new Array(e);
|
|
906
|
-
}
|
|
907
|
-
pushMapState(e) {
|
|
908
|
-
const t = this.getUninitializedStateFromPool();
|
|
909
|
-
t.type = A, t.readCount = 0, t.size = e, t.map = {};
|
|
910
|
-
}
|
|
911
|
-
getUninitializedStateFromPool() {
|
|
912
|
-
if (this.stackHeadPosition++, this.stackHeadPosition === this.stack.length) {
|
|
913
|
-
const e = {
|
|
914
|
-
type: void 0,
|
|
915
|
-
size: 0,
|
|
916
|
-
array: void 0,
|
|
917
|
-
position: 0,
|
|
918
|
-
readCount: 0,
|
|
919
|
-
map: void 0,
|
|
920
|
-
key: null
|
|
921
|
-
};
|
|
922
|
-
this.stack.push(e);
|
|
923
|
-
}
|
|
924
|
-
return this.stack[this.stackHeadPosition];
|
|
925
|
-
}
|
|
926
|
-
release(e) {
|
|
927
|
-
if (this.stack[this.stackHeadPosition] !== e)
|
|
928
|
-
throw new Error("Invalid stack state. Released state is not on top of the stack.");
|
|
929
|
-
if (e.type === z) {
|
|
930
|
-
const i = e;
|
|
931
|
-
i.size = 0, i.array = void 0, i.position = 0, i.type = void 0;
|
|
932
|
-
}
|
|
933
|
-
if (e.type === A || e.type === j) {
|
|
934
|
-
const i = e;
|
|
935
|
-
i.size = 0, i.map = void 0, i.readCount = 0, i.type = void 0;
|
|
936
|
-
}
|
|
937
|
-
this.stackHeadPosition--;
|
|
938
|
-
}
|
|
939
|
-
reset() {
|
|
940
|
-
this.stack.length = 0, this.stackHeadPosition = -1;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
const U = -1, W = new DataView(new ArrayBuffer(0)), Qe = new Uint8Array(W.buffer);
|
|
944
|
-
try {
|
|
945
|
-
W.getInt8(0);
|
|
946
|
-
} catch (s) {
|
|
947
|
-
if (!(s instanceof RangeError))
|
|
948
|
-
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
949
|
-
}
|
|
950
|
-
const X = new RangeError("Insufficient data"), Ge = new Je();
|
|
951
|
-
class Y {
|
|
952
|
-
constructor(e) {
|
|
953
|
-
this.totalPos = 0, this.pos = 0, this.view = W, this.bytes = Qe, this.headByte = U, this.stack = new be(), this.entered = !1, this.extensionCodec = (e == null ? void 0 : e.extensionCodec) ?? I.defaultCodec, this.context = e == null ? void 0 : e.context, this.useBigInt64 = (e == null ? void 0 : e.useBigInt64) ?? !1, this.rawStrings = (e == null ? void 0 : e.rawStrings) ?? !1, this.maxStrLength = (e == null ? void 0 : e.maxStrLength) ?? m, this.maxBinLength = (e == null ? void 0 : e.maxBinLength) ?? m, this.maxArrayLength = (e == null ? void 0 : e.maxArrayLength) ?? m, this.maxMapLength = (e == null ? void 0 : e.maxMapLength) ?? m, this.maxExtLength = (e == null ? void 0 : e.maxExtLength) ?? m, this.keyDecoder = (e == null ? void 0 : e.keyDecoder) !== void 0 ? e.keyDecoder : Ge, this.mapKeyConverter = (e == null ? void 0 : e.mapKeyConverter) ?? Xe;
|
|
954
|
-
}
|
|
955
|
-
clone() {
|
|
956
|
-
return new Y({
|
|
957
|
-
extensionCodec: this.extensionCodec,
|
|
958
|
-
context: this.context,
|
|
959
|
-
useBigInt64: this.useBigInt64,
|
|
960
|
-
rawStrings: this.rawStrings,
|
|
961
|
-
maxStrLength: this.maxStrLength,
|
|
962
|
-
maxBinLength: this.maxBinLength,
|
|
963
|
-
maxArrayLength: this.maxArrayLength,
|
|
964
|
-
maxMapLength: this.maxMapLength,
|
|
965
|
-
maxExtLength: this.maxExtLength,
|
|
966
|
-
keyDecoder: this.keyDecoder
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
reinitializeState() {
|
|
970
|
-
this.totalPos = 0, this.headByte = U, this.stack.reset();
|
|
971
|
-
}
|
|
972
|
-
setBuffer(e) {
|
|
973
|
-
const t = M(e);
|
|
974
|
-
this.bytes = t, this.view = new DataView(t.buffer, t.byteOffset, t.byteLength), this.pos = 0;
|
|
975
|
-
}
|
|
976
|
-
appendBuffer(e) {
|
|
977
|
-
if (this.headByte === U && !this.hasRemaining(1))
|
|
978
|
-
this.setBuffer(e);
|
|
979
|
-
else {
|
|
980
|
-
const t = this.bytes.subarray(this.pos), i = M(e), n = new Uint8Array(t.length + i.length);
|
|
981
|
-
n.set(t), n.set(i, t.length), this.setBuffer(n);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
hasRemaining(e) {
|
|
985
|
-
return this.view.byteLength - this.pos >= e;
|
|
986
|
-
}
|
|
987
|
-
createExtraByteError(e) {
|
|
988
|
-
const { view: t, pos: i } = this;
|
|
989
|
-
return new RangeError(`Extra ${t.byteLength - i} of ${t.byteLength} byte(s) found at buffer[${e}]`);
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* @throws {@link DecodeError}
|
|
993
|
-
* @throws {@link RangeError}
|
|
994
|
-
*/
|
|
995
|
-
decode(e) {
|
|
996
|
-
if (this.entered)
|
|
997
|
-
return this.clone().decode(e);
|
|
998
|
-
try {
|
|
999
|
-
this.entered = !0, this.reinitializeState(), this.setBuffer(e);
|
|
1000
|
-
const t = this.doDecodeSync();
|
|
1001
|
-
if (this.hasRemaining(1))
|
|
1002
|
-
throw this.createExtraByteError(this.pos);
|
|
1003
|
-
return t;
|
|
1004
|
-
} finally {
|
|
1005
|
-
this.entered = !1;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
*decodeMulti(e) {
|
|
1009
|
-
if (this.entered) {
|
|
1010
|
-
yield* this.clone().decodeMulti(e);
|
|
1011
|
-
return;
|
|
1012
|
-
}
|
|
1013
|
-
try {
|
|
1014
|
-
for (this.entered = !0, this.reinitializeState(), this.setBuffer(e); this.hasRemaining(1); )
|
|
1015
|
-
yield this.doDecodeSync();
|
|
1016
|
-
} finally {
|
|
1017
|
-
this.entered = !1;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
async decodeAsync(e) {
|
|
1021
|
-
if (this.entered)
|
|
1022
|
-
return this.clone().decodeAsync(e);
|
|
1023
|
-
try {
|
|
1024
|
-
this.entered = !0;
|
|
1025
|
-
let t = !1, i;
|
|
1026
|
-
for await (const o of e) {
|
|
1027
|
-
if (t)
|
|
1028
|
-
throw this.entered = !1, this.createExtraByteError(this.totalPos);
|
|
1029
|
-
this.appendBuffer(o);
|
|
1030
|
-
try {
|
|
1031
|
-
i = this.doDecodeSync(), t = !0;
|
|
1032
|
-
} catch (a) {
|
|
1033
|
-
if (!(a instanceof RangeError))
|
|
1034
|
-
throw a;
|
|
1035
|
-
}
|
|
1036
|
-
this.totalPos += this.pos;
|
|
1037
|
-
}
|
|
1038
|
-
if (t) {
|
|
1039
|
-
if (this.hasRemaining(1))
|
|
1040
|
-
throw this.createExtraByteError(this.totalPos);
|
|
1041
|
-
return i;
|
|
1042
|
-
}
|
|
1043
|
-
const { headByte: n, pos: r, totalPos: h } = this;
|
|
1044
|
-
throw new RangeError(`Insufficient data in parsing ${D(n)} at ${h} (${r} in the current buffer)`);
|
|
1045
|
-
} finally {
|
|
1046
|
-
this.entered = !1;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
decodeArrayStream(e) {
|
|
1050
|
-
return this.decodeMultiAsync(e, !0);
|
|
1051
|
-
}
|
|
1052
|
-
decodeStream(e) {
|
|
1053
|
-
return this.decodeMultiAsync(e, !1);
|
|
1054
|
-
}
|
|
1055
|
-
async *decodeMultiAsync(e, t) {
|
|
1056
|
-
if (this.entered) {
|
|
1057
|
-
yield* this.clone().decodeMultiAsync(e, t);
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
try {
|
|
1061
|
-
this.entered = !0;
|
|
1062
|
-
let i = t, n = -1;
|
|
1063
|
-
for await (const r of e) {
|
|
1064
|
-
if (t && n === 0)
|
|
1065
|
-
throw this.createExtraByteError(this.totalPos);
|
|
1066
|
-
this.appendBuffer(r), i && (n = this.readArraySize(), i = !1, this.complete());
|
|
1067
|
-
try {
|
|
1068
|
-
for (; yield this.doDecodeSync(), --n !== 0; )
|
|
1069
|
-
;
|
|
1070
|
-
} catch (h) {
|
|
1071
|
-
if (!(h instanceof RangeError))
|
|
1072
|
-
throw h;
|
|
1073
|
-
}
|
|
1074
|
-
this.totalPos += this.pos;
|
|
1075
|
-
}
|
|
1076
|
-
} finally {
|
|
1077
|
-
this.entered = !1;
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
doDecodeSync() {
|
|
1081
|
-
e: for (; ; ) {
|
|
1082
|
-
const e = this.readHeadByte();
|
|
1083
|
-
let t;
|
|
1084
|
-
if (e >= 224)
|
|
1085
|
-
t = e - 256;
|
|
1086
|
-
else if (e < 192)
|
|
1087
|
-
if (e < 128)
|
|
1088
|
-
t = e;
|
|
1089
|
-
else if (e < 144) {
|
|
1090
|
-
const n = e - 128;
|
|
1091
|
-
if (n !== 0) {
|
|
1092
|
-
this.pushMapState(n), this.complete();
|
|
1093
|
-
continue e;
|
|
1094
|
-
} else
|
|
1095
|
-
t = {};
|
|
1096
|
-
} else if (e < 160) {
|
|
1097
|
-
const n = e - 144;
|
|
1098
|
-
if (n !== 0) {
|
|
1099
|
-
this.pushArrayState(n), this.complete();
|
|
1100
|
-
continue e;
|
|
1101
|
-
} else
|
|
1102
|
-
t = [];
|
|
1103
|
-
} else {
|
|
1104
|
-
const n = e - 160;
|
|
1105
|
-
t = this.decodeString(n, 0);
|
|
1106
|
-
}
|
|
1107
|
-
else if (e === 192)
|
|
1108
|
-
t = null;
|
|
1109
|
-
else if (e === 194)
|
|
1110
|
-
t = !1;
|
|
1111
|
-
else if (e === 195)
|
|
1112
|
-
t = !0;
|
|
1113
|
-
else if (e === 202)
|
|
1114
|
-
t = this.readF32();
|
|
1115
|
-
else if (e === 203)
|
|
1116
|
-
t = this.readF64();
|
|
1117
|
-
else if (e === 204)
|
|
1118
|
-
t = this.readU8();
|
|
1119
|
-
else if (e === 205)
|
|
1120
|
-
t = this.readU16();
|
|
1121
|
-
else if (e === 206)
|
|
1122
|
-
t = this.readU32();
|
|
1123
|
-
else if (e === 207)
|
|
1124
|
-
this.useBigInt64 ? t = this.readU64AsBigInt() : t = this.readU64();
|
|
1125
|
-
else if (e === 208)
|
|
1126
|
-
t = this.readI8();
|
|
1127
|
-
else if (e === 209)
|
|
1128
|
-
t = this.readI16();
|
|
1129
|
-
else if (e === 210)
|
|
1130
|
-
t = this.readI32();
|
|
1131
|
-
else if (e === 211)
|
|
1132
|
-
this.useBigInt64 ? t = this.readI64AsBigInt() : t = this.readI64();
|
|
1133
|
-
else if (e === 217) {
|
|
1134
|
-
const n = this.lookU8();
|
|
1135
|
-
t = this.decodeString(n, 1);
|
|
1136
|
-
} else if (e === 218) {
|
|
1137
|
-
const n = this.lookU16();
|
|
1138
|
-
t = this.decodeString(n, 2);
|
|
1139
|
-
} else if (e === 219) {
|
|
1140
|
-
const n = this.lookU32();
|
|
1141
|
-
t = this.decodeString(n, 4);
|
|
1142
|
-
} else if (e === 220) {
|
|
1143
|
-
const n = this.readU16();
|
|
1144
|
-
if (n !== 0) {
|
|
1145
|
-
this.pushArrayState(n), this.complete();
|
|
1146
|
-
continue e;
|
|
1147
|
-
} else
|
|
1148
|
-
t = [];
|
|
1149
|
-
} else if (e === 221) {
|
|
1150
|
-
const n = this.readU32();
|
|
1151
|
-
if (n !== 0) {
|
|
1152
|
-
this.pushArrayState(n), this.complete();
|
|
1153
|
-
continue e;
|
|
1154
|
-
} else
|
|
1155
|
-
t = [];
|
|
1156
|
-
} else if (e === 222) {
|
|
1157
|
-
const n = this.readU16();
|
|
1158
|
-
if (n !== 0) {
|
|
1159
|
-
this.pushMapState(n), this.complete();
|
|
1160
|
-
continue e;
|
|
1161
|
-
} else
|
|
1162
|
-
t = {};
|
|
1163
|
-
} else if (e === 223) {
|
|
1164
|
-
const n = this.readU32();
|
|
1165
|
-
if (n !== 0) {
|
|
1166
|
-
this.pushMapState(n), this.complete();
|
|
1167
|
-
continue e;
|
|
1168
|
-
} else
|
|
1169
|
-
t = {};
|
|
1170
|
-
} else if (e === 196) {
|
|
1171
|
-
const n = this.lookU8();
|
|
1172
|
-
t = this.decodeBinary(n, 1);
|
|
1173
|
-
} else if (e === 197) {
|
|
1174
|
-
const n = this.lookU16();
|
|
1175
|
-
t = this.decodeBinary(n, 2);
|
|
1176
|
-
} else if (e === 198) {
|
|
1177
|
-
const n = this.lookU32();
|
|
1178
|
-
t = this.decodeBinary(n, 4);
|
|
1179
|
-
} else if (e === 212)
|
|
1180
|
-
t = this.decodeExtension(1, 0);
|
|
1181
|
-
else if (e === 213)
|
|
1182
|
-
t = this.decodeExtension(2, 0);
|
|
1183
|
-
else if (e === 214)
|
|
1184
|
-
t = this.decodeExtension(4, 0);
|
|
1185
|
-
else if (e === 215)
|
|
1186
|
-
t = this.decodeExtension(8, 0);
|
|
1187
|
-
else if (e === 216)
|
|
1188
|
-
t = this.decodeExtension(16, 0);
|
|
1189
|
-
else if (e === 199) {
|
|
1190
|
-
const n = this.lookU8();
|
|
1191
|
-
t = this.decodeExtension(n, 1);
|
|
1192
|
-
} else if (e === 200) {
|
|
1193
|
-
const n = this.lookU16();
|
|
1194
|
-
t = this.decodeExtension(n, 2);
|
|
1195
|
-
} else if (e === 201) {
|
|
1196
|
-
const n = this.lookU32();
|
|
1197
|
-
t = this.decodeExtension(n, 4);
|
|
1198
|
-
} else
|
|
1199
|
-
throw new g(`Unrecognized type byte: ${D(e)}`);
|
|
1200
|
-
this.complete();
|
|
1201
|
-
const i = this.stack;
|
|
1202
|
-
for (; i.length > 0; ) {
|
|
1203
|
-
const n = i.top();
|
|
1204
|
-
if (n.type === z)
|
|
1205
|
-
if (n.array[n.position] = t, n.position++, n.position === n.size)
|
|
1206
|
-
t = n.array, i.release(n);
|
|
1207
|
-
else
|
|
1208
|
-
continue e;
|
|
1209
|
-
else if (n.type === A) {
|
|
1210
|
-
if (t === "__proto__")
|
|
1211
|
-
throw new g("The key __proto__ is not allowed");
|
|
1212
|
-
n.key = this.mapKeyConverter(t), n.type = j;
|
|
1213
|
-
continue e;
|
|
1214
|
-
} else if (n.map[n.key] = t, n.readCount++, n.readCount === n.size)
|
|
1215
|
-
t = n.map, i.release(n);
|
|
1216
|
-
else {
|
|
1217
|
-
n.key = null, n.type = A;
|
|
1218
|
-
continue e;
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
return t;
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
readHeadByte() {
|
|
1225
|
-
return this.headByte === U && (this.headByte = this.readU8()), this.headByte;
|
|
1226
|
-
}
|
|
1227
|
-
complete() {
|
|
1228
|
-
this.headByte = U;
|
|
1229
|
-
}
|
|
1230
|
-
readArraySize() {
|
|
1231
|
-
const e = this.readHeadByte();
|
|
1232
|
-
switch (e) {
|
|
1233
|
-
case 220:
|
|
1234
|
-
return this.readU16();
|
|
1235
|
-
case 221:
|
|
1236
|
-
return this.readU32();
|
|
1237
|
-
default: {
|
|
1238
|
-
if (e < 160)
|
|
1239
|
-
return e - 144;
|
|
1240
|
-
throw new g(`Unrecognized array type byte: ${D(e)}`);
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
pushMapState(e) {
|
|
1245
|
-
if (e > this.maxMapLength)
|
|
1246
|
-
throw new g(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);
|
|
1247
|
-
this.stack.pushMapState(e);
|
|
1248
|
-
}
|
|
1249
|
-
pushArrayState(e) {
|
|
1250
|
-
if (e > this.maxArrayLength)
|
|
1251
|
-
throw new g(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);
|
|
1252
|
-
this.stack.pushArrayState(e);
|
|
1253
|
-
}
|
|
1254
|
-
decodeString(e, t) {
|
|
1255
|
-
return !this.rawStrings || this.stateIsMapKey() ? this.decodeUtf8String(e, t) : this.decodeBinary(e, t);
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* @throws {@link RangeError}
|
|
1259
|
-
*/
|
|
1260
|
-
decodeUtf8String(e, t) {
|
|
1261
|
-
var r;
|
|
1262
|
-
if (e > this.maxStrLength)
|
|
1263
|
-
throw new g(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);
|
|
1264
|
-
if (this.bytes.byteLength < this.pos + t + e)
|
|
1265
|
-
throw X;
|
|
1266
|
-
const i = this.pos + t;
|
|
1267
|
-
let n;
|
|
1268
|
-
return this.stateIsMapKey() && ((r = this.keyDecoder) != null && r.canBeCached(e)) ? n = this.keyDecoder.decode(this.bytes, i, e) : n = Be(this.bytes, i, e), this.pos += t + e, n;
|
|
1269
|
-
}
|
|
1270
|
-
stateIsMapKey() {
|
|
1271
|
-
return this.stack.length > 0 ? this.stack.top().type === A : !1;
|
|
1272
|
-
}
|
|
1273
|
-
/**
|
|
1274
|
-
* @throws {@link RangeError}
|
|
1275
|
-
*/
|
|
1276
|
-
decodeBinary(e, t) {
|
|
1277
|
-
if (e > this.maxBinLength)
|
|
1278
|
-
throw new g(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);
|
|
1279
|
-
if (!this.hasRemaining(e + t))
|
|
1280
|
-
throw X;
|
|
1281
|
-
const i = this.pos + t, n = this.bytes.subarray(i, i + e);
|
|
1282
|
-
return this.pos += t + e, n;
|
|
1283
|
-
}
|
|
1284
|
-
decodeExtension(e, t) {
|
|
1285
|
-
if (e > this.maxExtLength)
|
|
1286
|
-
throw new g(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);
|
|
1287
|
-
const i = this.view.getInt8(this.pos + t), n = this.decodeBinary(
|
|
1288
|
-
e,
|
|
1289
|
-
t + 1
|
|
1290
|
-
/* extType */
|
|
1291
|
-
);
|
|
1292
|
-
return this.extensionCodec.decode(n, i, this.context);
|
|
1293
|
-
}
|
|
1294
|
-
lookU8() {
|
|
1295
|
-
return this.view.getUint8(this.pos);
|
|
1296
|
-
}
|
|
1297
|
-
lookU16() {
|
|
1298
|
-
return this.view.getUint16(this.pos);
|
|
1299
|
-
}
|
|
1300
|
-
lookU32() {
|
|
1301
|
-
return this.view.getUint32(this.pos);
|
|
1302
|
-
}
|
|
1303
|
-
readU8() {
|
|
1304
|
-
const e = this.view.getUint8(this.pos);
|
|
1305
|
-
return this.pos++, e;
|
|
1306
|
-
}
|
|
1307
|
-
readI8() {
|
|
1308
|
-
const e = this.view.getInt8(this.pos);
|
|
1309
|
-
return this.pos++, e;
|
|
1310
|
-
}
|
|
1311
|
-
readU16() {
|
|
1312
|
-
const e = this.view.getUint16(this.pos);
|
|
1313
|
-
return this.pos += 2, e;
|
|
1314
|
-
}
|
|
1315
|
-
readI16() {
|
|
1316
|
-
const e = this.view.getInt16(this.pos);
|
|
1317
|
-
return this.pos += 2, e;
|
|
1318
|
-
}
|
|
1319
|
-
readU32() {
|
|
1320
|
-
const e = this.view.getUint32(this.pos);
|
|
1321
|
-
return this.pos += 4, e;
|
|
1322
|
-
}
|
|
1323
|
-
readI32() {
|
|
1324
|
-
const e = this.view.getInt32(this.pos);
|
|
1325
|
-
return this.pos += 4, e;
|
|
1326
|
-
}
|
|
1327
|
-
readU64() {
|
|
1328
|
-
const e = Oe(this.view, this.pos);
|
|
1329
|
-
return this.pos += 8, e;
|
|
1330
|
-
}
|
|
1331
|
-
readI64() {
|
|
1332
|
-
const e = V(this.view, this.pos);
|
|
1333
|
-
return this.pos += 8, e;
|
|
1334
|
-
}
|
|
1335
|
-
readU64AsBigInt() {
|
|
1336
|
-
const e = this.view.getBigUint64(this.pos);
|
|
1337
|
-
return this.pos += 8, e;
|
|
1338
|
-
}
|
|
1339
|
-
readI64AsBigInt() {
|
|
1340
|
-
const e = this.view.getBigInt64(this.pos);
|
|
1341
|
-
return this.pos += 8, e;
|
|
1342
|
-
}
|
|
1343
|
-
readF32() {
|
|
1344
|
-
const e = this.view.getFloat32(this.pos);
|
|
1345
|
-
return this.pos += 4, e;
|
|
1346
|
-
}
|
|
1347
|
-
readF64() {
|
|
1348
|
-
const e = this.view.getFloat64(this.pos);
|
|
1349
|
-
return this.pos += 8, e;
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
function qe(s, e) {
|
|
1353
|
-
return new Y(e).decode(s);
|
|
1354
|
-
}
|
|
1355
|
-
function F(s, e, t, i = "", n = null) {
|
|
1356
|
-
if (e === null || typeof e != "object")
|
|
1357
|
-
return e;
|
|
1358
|
-
for (const r in e)
|
|
1359
|
-
e[r] = F(s, e[r], t, i + "/" + r, n);
|
|
1360
|
-
return new Proxy(e, {
|
|
1361
|
-
get(r, h) {
|
|
1362
|
-
return Reflect.get(...arguments);
|
|
1363
|
-
},
|
|
1364
|
-
set(r, h, o) {
|
|
1365
|
-
let a = i + "/" + h, c = F(s, o, t, a, n);
|
|
1366
|
-
return t(s, "replace", r, a, c, n), Reflect.set(r, h, c);
|
|
1367
|
-
},
|
|
1368
|
-
deleteProperty(r, h) {
|
|
1369
|
-
let o = i + "/" + h;
|
|
1370
|
-
return delete r[h], t(s, "delete", r, o, null, n), !0;
|
|
1371
|
-
}
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
function Ze(s) {
|
|
1375
|
-
let e = {};
|
|
1376
|
-
return s.o ? e.op = {
|
|
1377
|
-
a: "add",
|
|
1378
|
-
r: "remove",
|
|
1379
|
-
d: "delete",
|
|
1380
|
-
t: "test"
|
|
1381
|
-
}[s.o] : e.op = "replace", e.path = s.p, e.value = s.v, e;
|
|
1382
|
-
}
|
|
1383
|
-
function Ve(s, e, t, i) {
|
|
1384
|
-
let n = { p: t, v: i };
|
|
1385
|
-
return s != "replace" && (n.o = {
|
|
1386
|
-
add: "a",
|
|
1387
|
-
remove: "r",
|
|
1388
|
-
delete: "d",
|
|
1389
|
-
test: "t"
|
|
1390
|
-
}[s]), n;
|
|
1391
|
-
}
|
|
1392
|
-
class et {
|
|
1393
|
-
constructor({
|
|
1394
|
-
url: e
|
|
1395
|
-
// server url
|
|
1396
|
-
}) {
|
|
1397
|
-
w(this, "CYCLE", 100);
|
|
1398
|
-
// update/patch rate in ms
|
|
1399
|
-
w(this, "url", "");
|
|
1400
|
-
w(this, "documents", {});
|
|
1401
|
-
w(this, "autoReconnect", !0);
|
|
1402
|
-
w(this, "allowSync", !0);
|
|
1403
|
-
w(this, "isConnected", !1);
|
|
1404
|
-
w(this, "isConnecting", !1);
|
|
1405
|
-
w(this, "isPatched", !1);
|
|
1406
|
-
w(this, "stats", {
|
|
1407
|
-
send: 0,
|
|
1408
|
-
rec: 0,
|
|
1409
|
-
sendBps: 0,
|
|
1410
|
-
recBps: 0,
|
|
1411
|
-
ping: 0,
|
|
1412
|
-
stdiff: 0
|
|
1413
|
-
// server time difference
|
|
1414
|
-
});
|
|
1415
|
-
w(this, "lastFullState", 0);
|
|
1416
|
-
w(this, "lastPatch", 0);
|
|
1417
|
-
w(this, "le", !0);
|
|
1418
|
-
// Server is little endian
|
|
1419
|
-
w(this, "_documentChanges", {});
|
|
1420
|
-
this.url = e, this.socket = null, this._startLoop();
|
|
1421
|
-
}
|
|
1422
|
-
/*= UPDATE ===================================================================*/
|
|
1423
|
-
_startLoop() {
|
|
1424
|
-
this._loopiv && clearInterval(this._loopiv), this._loopiv = setInterval(() => {
|
|
1425
|
-
this._loop();
|
|
1426
|
-
}, this.CYCLE);
|
|
1427
|
-
}
|
|
1428
|
-
_loop() {
|
|
1429
|
-
this.isConnected && this._sendPatches();
|
|
1430
|
-
}
|
|
1431
|
-
_countLoop() {
|
|
1432
|
-
this._stats.sendBps = this._stats.send, this._stats.recBps = this._stats.rec, this._stats.send = 0, this._stats.rec = 0;
|
|
1433
|
-
}
|
|
1434
|
-
/*= CONNECTION ===============================================================*/
|
|
1435
|
-
subscribe(e) {
|
|
1436
|
-
this.documents[e] = {}, this.send({ c: "sub", n: e });
|
|
1437
|
-
}
|
|
1438
|
-
unsubscribe(e) {
|
|
1439
|
-
this.send({ c: "unsub", n: e }), delete this.documents[e];
|
|
1440
|
-
}
|
|
1441
|
-
connect() {
|
|
1442
|
-
this.isConnecting || (this.isConnecting = !0, this._clear(), console.log("connecting..."), this.socket = new WebSocket(this.url), this.socket.onmessage = async (e) => {
|
|
1443
|
-
let t = await e.data.arrayBuffer();
|
|
1444
|
-
this.stats.rec += t.byteLength;
|
|
1445
|
-
let i = qe(t), n = Date.now();
|
|
1446
|
-
if (i.c == "full") {
|
|
1447
|
-
let r = i.n, h = i.doc;
|
|
1448
|
-
this.documents[r] = h, this.isPatched = !1, this.document = F(r, this.documents[r], this._onDocumentChange.bind(this)), this.isPatched = !1, this.lastFullState = i.t, this.le = i.le, this.onChange(r);
|
|
1449
|
-
} else if (i.c == "patch") {
|
|
1450
|
-
this.lastPatch = i.t;
|
|
1451
|
-
let r = i.n;
|
|
1452
|
-
if (i.doc) {
|
|
1453
|
-
this.isPatched = !0;
|
|
1454
|
-
for (let h of i.doc) {
|
|
1455
|
-
let o = Ze(h);
|
|
1456
|
-
x(this.documents[r], o);
|
|
1457
|
-
}
|
|
1458
|
-
this.isPatched = !1;
|
|
1459
|
-
}
|
|
1460
|
-
this.onChange(r);
|
|
1461
|
-
} else if (i.c == "hello") {
|
|
1462
|
-
n = Date.now();
|
|
1463
|
-
let r = i.ct, h = n - r, o = i.t;
|
|
1464
|
-
this.stats.stdiff = o + h / 2 - n, this.stats.ping = h, console.log("ping", h, "ms", "stdiff", this.stats.stdiff, "ms");
|
|
1465
|
-
}
|
|
1466
|
-
}, this.socket.onclose = (e) => {
|
|
1467
|
-
this.isConnected = !1, this.isConnecting = !1, this.lastFullState = 0, this.socket = null, this.onDisconnect(), this.autoReconnect && setTimeout(() => {
|
|
1468
|
-
this._reconnect();
|
|
1469
|
-
}, 500 + Math.random() * 500);
|
|
1470
|
-
}, this.socket.onerror = (e) => {
|
|
1471
|
-
this.isConnected = !1, this.isConnecting = !1, this.lastFullState = 0, this.socket = null, this.onDisconnect(), this.autoReconnect && setTimeout(() => {
|
|
1472
|
-
this._reconnect();
|
|
1473
|
-
}, 500 + Math.random() * 500);
|
|
1474
|
-
}, this.socket.onopen = (e) => {
|
|
1475
|
-
this.isConnecting = !1, this.isConnected = !0, this.lastFullState = 0, this._ping(), this.onConnect();
|
|
1476
|
-
});
|
|
1477
|
-
}
|
|
1478
|
-
disconnect() {
|
|
1479
|
-
this.isConnected = !1, this.isConnecting = !1, this.lastFullState = 0, this.socket.close(), this.socket = null;
|
|
1480
|
-
}
|
|
1481
|
-
destroy() {
|
|
1482
|
-
this.autoReconnect = !1, this.disconnect(), this.socket = null;
|
|
1483
|
-
}
|
|
1484
|
-
onConnect() {
|
|
1485
|
-
}
|
|
1486
|
-
onDisconnect() {
|
|
1487
|
-
}
|
|
1488
|
-
_clear() {
|
|
1489
|
-
this.stats.sendBps = 0, this.stats.recBps = 0, this.stats.send = 0, this.stats.rec = 0, this.documents = {}, this._documentChanges = {}, this.lastFullState = 0, this.lastPatch = 0, this.isPatched = !1, this.le = !0;
|
|
1490
|
-
}
|
|
1491
|
-
_reconnect() {
|
|
1492
|
-
this.isConnected || this.isConnecting || this.connect();
|
|
1493
|
-
}
|
|
1494
|
-
_ping() {
|
|
1495
|
-
this.isConnected && this.send({ c: "hello", ct: Date.now() });
|
|
1496
|
-
}
|
|
1497
|
-
/*= MESSAGES =================================================================*/
|
|
1498
|
-
onChange(e) {
|
|
1499
|
-
}
|
|
1500
|
-
send(e) {
|
|
1501
|
-
try {
|
|
1502
|
-
let t = Ke(e);
|
|
1503
|
-
this.stats.send += t.byteLength, this.socket.send(t);
|
|
1504
|
-
} catch (t) {
|
|
1505
|
-
console.error("send failed", t);
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
_onDocumentChange(e, t, i, n, r) {
|
|
1509
|
-
this.isPatched || !this.allowSync || n.indexOf("/_") >= 0 || (this._documentChanges[e] || (this._documentChanges[e] = []), this._documentChanges[e].push(Ve(t, i, n, r)));
|
|
1510
|
-
}
|
|
1511
|
-
_sendPatches() {
|
|
1512
|
-
for (let e in this._documentChanges) {
|
|
1513
|
-
let t = this._documentChanges[e];
|
|
1514
|
-
if (t.length == 0)
|
|
1515
|
-
continue;
|
|
1516
|
-
let i = {
|
|
1517
|
-
n: e,
|
|
1518
|
-
c: "sync",
|
|
1519
|
-
ct: Date.now()
|
|
1520
|
-
};
|
|
1521
|
-
t.length > 0 && (i.p = t), this.send(i), this._documentChanges[e].length = 0, this.onChange(e);
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
export {
|
|
1526
|
-
et as default
|
|
1527
|
-
};
|