@kbve/droid 0.1.1 → 0.1.2

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.
Files changed (120) hide show
  1. package/droid.mjs +2311 -203
  2. package/index.d.ts +3 -0
  3. package/lib/agents/api-types.d.ts +121 -0
  4. package/lib/agents/api-types.d.ts.map +1 -0
  5. package/lib/agents/auth/init.d.ts +8 -0
  6. package/lib/agents/auth/init.d.ts.map +1 -0
  7. package/lib/agents/cache.d.ts +9 -0
  8. package/lib/agents/cache.d.ts.map +1 -0
  9. package/lib/agents/client/callGuildVault.d.ts +3 -0
  10. package/lib/agents/client/callGuildVault.d.ts.map +1 -0
  11. package/lib/agents/client/callJson.d.ts +3 -0
  12. package/lib/agents/client/callJson.d.ts.map +1 -0
  13. package/lib/agents/config.d.ts +36 -0
  14. package/lib/agents/config.d.ts.map +1 -0
  15. package/lib/agents/constants.d.ts +11 -0
  16. package/lib/agents/constants.d.ts.map +1 -0
  17. package/lib/agents/createAgents.d.ts +4 -0
  18. package/lib/agents/createAgents.d.ts.map +1 -0
  19. package/lib/agents/ctx.d.ts +46 -0
  20. package/lib/agents/ctx.d.ts.map +1 -0
  21. package/lib/agents/discord/bot.d.ts +21 -0
  22. package/lib/agents/discord/bot.d.ts.map +1 -0
  23. package/lib/agents/discord/guilds.d.ts +8 -0
  24. package/lib/agents/discord/guilds.d.ts.map +1 -0
  25. package/lib/agents/formDrafts.d.ts +5 -0
  26. package/lib/agents/formDrafts.d.ts.map +1 -0
  27. package/lib/agents/generated/agents-schema.d.ts +73 -0
  28. package/lib/agents/generated/agents-schema.d.ts.map +1 -0
  29. package/lib/agents/generated/discordsh-agents-schema.d.ts +71 -0
  30. package/lib/agents/generated/discordsh-agents-schema.d.ts.map +1 -0
  31. package/lib/agents/github/backfill.d.ts +23 -0
  32. package/lib/agents/github/backfill.d.ts.map +1 -0
  33. package/lib/agents/github/events.d.ts +10 -0
  34. package/lib/agents/github/events.d.ts.map +1 -0
  35. package/lib/agents/github/pat.d.ts +13 -0
  36. package/lib/agents/github/pat.d.ts.map +1 -0
  37. package/lib/agents/github/repoConfig.d.ts +25 -0
  38. package/lib/agents/github/repoConfig.d.ts.map +1 -0
  39. package/lib/agents/github/tokens.d.ts +22 -0
  40. package/lib/agents/github/tokens.d.ts.map +1 -0
  41. package/lib/agents/github/webhook.d.ts +37 -0
  42. package/lib/agents/github/webhook.d.ts.map +1 -0
  43. package/lib/agents/index.d.ts +8 -0
  44. package/lib/agents/index.d.ts.map +1 -0
  45. package/lib/agents/state/atoms.d.ts +122 -0
  46. package/lib/agents/state/atoms.d.ts.map +1 -0
  47. package/lib/agents/types.d.ts +65 -0
  48. package/lib/agents/types.d.ts.map +1 -0
  49. package/lib/gateway/SupabaseGateway.d.ts.map +1 -1
  50. package/lib/gateway/types.d.ts +1 -1
  51. package/lib/gateway/types.d.ts.map +1 -1
  52. package/lib/workers/canvas-worker.js +6 -449
  53. package/lib/workers/data.d.ts.map +1 -1
  54. package/lib/workers/db-worker.d.ts +2 -2
  55. package/lib/workers/db-worker.d.ts.map +1 -1
  56. package/lib/workers/db-worker.js +14 -4170
  57. package/lib/workers/main.d.ts +0 -2
  58. package/lib/workers/main.d.ts.map +1 -1
  59. package/lib/workers/supabase-db-worker.js +11 -9325
  60. package/lib/workers/supabase-shared-worker.js +13 -12623
  61. package/lib/workers/ws-worker.d.ts +1 -2
  62. package/lib/workers/ws-worker.d.ts.map +1 -1
  63. package/lib/workers/ws-worker.js +6 -333
  64. package/main.js +5622 -4786
  65. package/package.json +2 -1
  66. package/src/index.ts +3 -0
  67. package/src/lib/agents/api-types.ts +170 -0
  68. package/src/lib/agents/auth/init.ts +200 -0
  69. package/src/lib/agents/cache.ts +127 -0
  70. package/src/lib/agents/client/callGuildVault.ts +71 -0
  71. package/src/lib/agents/client/callJson.ts +64 -0
  72. package/src/lib/agents/config.ts +83 -0
  73. package/src/lib/agents/constants.ts +11 -0
  74. package/src/lib/agents/createAgents.ts +62 -0
  75. package/src/lib/agents/ctx.ts +63 -0
  76. package/src/lib/agents/discord/bot.ts +169 -0
  77. package/src/lib/agents/discord/guilds.ts +106 -0
  78. package/src/lib/agents/formDrafts.ts +55 -0
  79. package/src/lib/agents/generated/agents-schema.ts +155 -0
  80. package/src/lib/agents/generated/discordsh-agents-schema.ts +96 -0
  81. package/src/lib/agents/github/backfill.ts +126 -0
  82. package/src/lib/agents/github/events.ts +131 -0
  83. package/src/lib/agents/github/pat.ts +150 -0
  84. package/src/lib/agents/github/repoConfig.ts +240 -0
  85. package/src/lib/agents/github/tokens.ts +222 -0
  86. package/src/lib/agents/github/webhook.ts +349 -0
  87. package/src/lib/agents/index.ts +35 -0
  88. package/src/lib/agents/state/atoms.ts +122 -0
  89. package/src/lib/agents/types.ts +83 -0
  90. package/src/lib/api.ts +71 -0
  91. package/src/lib/gateway/SupabaseGateway.ts +55 -2
  92. package/src/lib/gateway/WorkerCommunication.ts +1 -1
  93. package/src/lib/gateway/capabilities.spec.ts +144 -0
  94. package/src/lib/gateway/types.ts +97 -70
  95. package/src/lib/mod/module/supabase/mod-supabase.ts +10 -5
  96. package/src/lib/state/auth.ts +121 -3
  97. package/src/lib/state/bento.spec.ts +76 -0
  98. package/src/lib/state/bento.ts +51 -0
  99. package/src/lib/state/index.ts +64 -0
  100. package/src/lib/state/profile-sync.ts +214 -0
  101. package/src/lib/state/profile.ts +155 -0
  102. package/src/lib/state/staff.ts +128 -0
  103. package/src/lib/state/sync-bus.ts +109 -0
  104. package/src/lib/state/welcome-toast.spec.ts +101 -0
  105. package/src/lib/sw-recovery.spec.ts +165 -0
  106. package/src/lib/sw-recovery.ts +141 -0
  107. package/src/lib/types/event-schemas.spec.ts +120 -0
  108. package/src/lib/types/event-types.spec.ts +5 -2
  109. package/src/lib/types/event-types.ts +74 -0
  110. package/src/lib/workers/data.ts +5 -1
  111. package/src/lib/workers/db-worker.ts +34 -8
  112. package/src/lib/workers/main.ts +3 -18
  113. package/src/lib/workers/supabase-db-worker.ts +25 -3
  114. package/src/lib/workers/supabase-shared-worker.ts +43 -8
  115. package/src/lib/workers/ws-worker.spec.ts +41 -0
  116. package/src/lib/workers/ws-worker.ts +121 -28
  117. package/workers/main.js +2 -12
  118. package/comlink.js +0 -247
  119. package/index.js +0 -9263
  120. package/reference.js +0 -719
package/reference.js DELETED
@@ -1,719 +0,0 @@
1
- var N = {}, E = {}, j;
2
- function L() {
3
- if (j) return E;
4
- j = 1, Object.defineProperty(E, "__esModule", { value: !0 }), E.BitWidth = void 0;
5
- var o;
6
- return (function(e) {
7
- e[e.WIDTH8 = 0] = "WIDTH8", e[e.WIDTH16 = 1] = "WIDTH16", e[e.WIDTH32 = 2] = "WIDTH32", e[e.WIDTH64 = 3] = "WIDTH64";
8
- })(o || (E.BitWidth = o = {})), E;
9
- }
10
- var b = {}, x;
11
- function A() {
12
- if (x) return b;
13
- x = 1, Object.defineProperty(b, "__esModule", { value: !0 }), b.paddingSize = b.fromByteWidth = b.uwidth = b.fwidth = b.iwidth = b.toByteWidth = void 0;
14
- const o = L();
15
- function e(p) {
16
- return 1 << p;
17
- }
18
- b.toByteWidth = e;
19
- function T(p) {
20
- return p >= -128 && p <= 127 ? o.BitWidth.WIDTH8 : p >= -32768 && p <= 32767 ? o.BitWidth.WIDTH16 : p >= -2147483648 && p <= 2147483647 ? o.BitWidth.WIDTH32 : o.BitWidth.WIDTH64;
21
- }
22
- b.iwidth = T;
23
- function f(p) {
24
- return p === Math.fround(p) ? o.BitWidth.WIDTH32 : o.BitWidth.WIDTH64;
25
- }
26
- b.fwidth = f;
27
- function W(p) {
28
- return p <= 255 ? o.BitWidth.WIDTH8 : p <= 65535 ? o.BitWidth.WIDTH16 : p <= 4294967295 ? o.BitWidth.WIDTH32 : o.BitWidth.WIDTH64;
29
- }
30
- b.uwidth = W;
31
- function I(p) {
32
- return p === 1 ? o.BitWidth.WIDTH8 : p === 2 ? o.BitWidth.WIDTH16 : p === 4 ? o.BitWidth.WIDTH32 : o.BitWidth.WIDTH64;
33
- }
34
- b.fromByteWidth = I;
35
- function V(p, t) {
36
- return ~p + 1 & t - 1;
37
- }
38
- return b.paddingSize = V, b;
39
- }
40
- var B = {}, H;
41
- function F() {
42
- if (H) return B;
43
- H = 1, Object.defineProperty(B, "__esModule", { value: !0 }), B.toUTF8Array = B.fromUTF8Array = void 0;
44
- function o(T) {
45
- return new TextDecoder().decode(T);
46
- }
47
- B.fromUTF8Array = o;
48
- function e(T) {
49
- return new TextEncoder().encode(T);
50
- }
51
- return B.toUTF8Array = e, B;
52
- }
53
- var m = {}, K;
54
- function C() {
55
- if (K) return m;
56
- K = 1, Object.defineProperty(m, "__esModule", { value: !0 }), m.ValueType = void 0;
57
- var o;
58
- return (function(e) {
59
- e[e.NULL = 0] = "NULL", e[e.INT = 1] = "INT", e[e.UINT = 2] = "UINT", e[e.FLOAT = 3] = "FLOAT", e[e.KEY = 4] = "KEY", e[e.STRING = 5] = "STRING", e[e.INDIRECT_INT = 6] = "INDIRECT_INT", e[e.INDIRECT_UINT = 7] = "INDIRECT_UINT", e[e.INDIRECT_FLOAT = 8] = "INDIRECT_FLOAT", e[e.MAP = 9] = "MAP", e[e.VECTOR = 10] = "VECTOR", e[e.VECTOR_INT = 11] = "VECTOR_INT", e[e.VECTOR_UINT = 12] = "VECTOR_UINT", e[e.VECTOR_FLOAT = 13] = "VECTOR_FLOAT", e[e.VECTOR_KEY = 14] = "VECTOR_KEY", e[e.VECTOR_STRING_DEPRECATED = 15] = "VECTOR_STRING_DEPRECATED", e[e.VECTOR_INT2 = 16] = "VECTOR_INT2", e[e.VECTOR_UINT2 = 17] = "VECTOR_UINT2", e[e.VECTOR_FLOAT2 = 18] = "VECTOR_FLOAT2", e[e.VECTOR_INT3 = 19] = "VECTOR_INT3", e[e.VECTOR_UINT3 = 20] = "VECTOR_UINT3", e[e.VECTOR_FLOAT3 = 21] = "VECTOR_FLOAT3", e[e.VECTOR_INT4 = 22] = "VECTOR_INT4", e[e.VECTOR_UINT4 = 23] = "VECTOR_UINT4", e[e.VECTOR_FLOAT4 = 24] = "VECTOR_FLOAT4", e[e.BLOB = 25] = "BLOB", e[e.BOOL = 26] = "BOOL", e[e.VECTOR_BOOL = 36] = "VECTOR_BOOL";
60
- })(o || (m.ValueType = o = {})), m;
61
- }
62
- var y = {}, $;
63
- function v() {
64
- if ($) return y;
65
- $ = 1, Object.defineProperty(y, "__esModule", { value: !0 }), y.packedType = y.fixedTypedVectorElementSize = y.fixedTypedVectorElementType = y.typedVectorElementType = y.toTypedVector = y.isAVector = y.isFixedTypedVector = y.isTypedVector = y.isTypedVectorElement = y.isIndirectNumber = y.isNumber = y.isInline = void 0;
66
- const o = C();
67
- function e(h) {
68
- return h === o.ValueType.BOOL || h <= o.ValueType.FLOAT;
69
- }
70
- y.isInline = e;
71
- function T(h) {
72
- return h >= o.ValueType.INT && h <= o.ValueType.FLOAT;
73
- }
74
- y.isNumber = T;
75
- function f(h) {
76
- return h >= o.ValueType.INDIRECT_INT && h <= o.ValueType.INDIRECT_FLOAT;
77
- }
78
- y.isIndirectNumber = f;
79
- function W(h) {
80
- return h === o.ValueType.BOOL || h >= o.ValueType.INT && h <= o.ValueType.STRING;
81
- }
82
- y.isTypedVectorElement = W;
83
- function I(h) {
84
- return h === o.ValueType.VECTOR_BOOL || h >= o.ValueType.VECTOR_INT && h <= o.ValueType.VECTOR_STRING_DEPRECATED;
85
- }
86
- y.isTypedVector = I;
87
- function V(h) {
88
- return h >= o.ValueType.VECTOR_INT2 && h <= o.ValueType.VECTOR_FLOAT4;
89
- }
90
- y.isFixedTypedVector = V;
91
- function p(h) {
92
- return I(h) || V(h) || h === o.ValueType.VECTOR;
93
- }
94
- y.isAVector = p;
95
- function t(h, a) {
96
- if (a === 0)
97
- return h - o.ValueType.INT + o.ValueType.VECTOR_INT;
98
- if (a === 2)
99
- return h - o.ValueType.INT + o.ValueType.VECTOR_INT2;
100
- if (a === 3)
101
- return h - o.ValueType.INT + o.ValueType.VECTOR_INT3;
102
- if (a === 4)
103
- return h - o.ValueType.INT + o.ValueType.VECTOR_INT4;
104
- throw "Unexpected length " + a;
105
- }
106
- y.toTypedVector = t;
107
- function n(h) {
108
- return h - o.ValueType.VECTOR_INT + o.ValueType.INT;
109
- }
110
- y.typedVectorElementType = n;
111
- function s(h) {
112
- return (h - o.ValueType.VECTOR_INT2) % 3 + o.ValueType.INT;
113
- }
114
- y.fixedTypedVectorElementType = s;
115
- function i(h) {
116
- return ((h - o.ValueType.VECTOR_INT2) / 3 >> 0) + 2;
117
- }
118
- y.fixedTypedVectorElementSize = i;
119
- function r(h, a) {
120
- return a | h << 2;
121
- }
122
- return y.packedType = r, y;
123
- }
124
- var R = {}, M;
125
- function G() {
126
- if (M) return R;
127
- M = 1, Object.defineProperty(R, "__esModule", { value: !0 }), R.StackValue = void 0;
128
- const o = L(), e = A(), T = C(), f = v();
129
- class W {
130
- constructor(V, p, t, n = null, s = 0) {
131
- this.builder = V, this.type = p, this.width = t, this.value = n, this.offset = s;
132
- }
133
- elementWidth(V, p) {
134
- if ((0, f.isInline)(this.type))
135
- return this.width;
136
- for (let t = 0; t < 4; t++) {
137
- const n = 1 << t, i = V + (0, e.paddingSize)(V, n) + p * n - this.offset, r = (0, e.uwidth)(i);
138
- if (1 << r === n)
139
- return r;
140
- }
141
- throw `Element is unknown. Size: ${V} at index: ${p}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
142
- }
143
- writeToBuffer(V) {
144
- const p = this.builder.computeOffset(V);
145
- if (this.type === T.ValueType.FLOAT)
146
- this.width === o.BitWidth.WIDTH32 ? this.builder.view.setFloat32(this.builder.offset, this.value, !0) : this.builder.view.setFloat64(this.builder.offset, this.value, !0);
147
- else if (this.type === T.ValueType.INT) {
148
- const t = (0, e.fromByteWidth)(V);
149
- this.builder.pushInt(this.value, t);
150
- } else if (this.type === T.ValueType.UINT) {
151
- const t = (0, e.fromByteWidth)(V);
152
- this.builder.pushUInt(this.value, t);
153
- } else if (this.type === T.ValueType.NULL)
154
- this.builder.pushInt(0, this.width);
155
- else if (this.type === T.ValueType.BOOL)
156
- this.builder.pushInt(this.value ? 1 : 0, this.width);
157
- else
158
- throw `Unexpected type: ${this.type}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
159
- this.offset = p;
160
- }
161
- storedWidth(V = o.BitWidth.WIDTH8) {
162
- return (0, f.isInline)(this.type) ? Math.max(V, this.width) : this.width;
163
- }
164
- storedPackedType(V = o.BitWidth.WIDTH8) {
165
- return (0, f.packedType)(this.type, this.storedWidth(V));
166
- }
167
- isOffset() {
168
- return !(0, f.isInline)(this.type);
169
- }
170
- }
171
- return R.StackValue = W, R;
172
- }
173
- var q;
174
- function J() {
175
- if (q) return N;
176
- q = 1, Object.defineProperty(N, "__esModule", { value: !0 }), N.Builder = void 0;
177
- const o = L(), e = A(), T = F(), f = C(), W = v(), I = G();
178
- class V {
179
- constructor(t = 2048, n = !0, s = !0, i = !0) {
180
- this.dedupStrings = n, this.dedupKeys = s, this.dedupKeyVectors = i, this.stack = [], this.stackPointers = [], this.offset = 0, this.finished = !1, this.stringLookup = {}, this.keyLookup = {}, this.keyVectorLookup = {}, this.indirectIntLookup = {}, this.indirectUIntLookup = {}, this.indirectFloatLookup = {}, this.buffer = new ArrayBuffer(t > 0 ? t : 2048), this.view = new DataView(this.buffer);
181
- }
182
- align(t) {
183
- const n = (0, e.toByteWidth)(t);
184
- return this.offset += (0, e.paddingSize)(this.offset, n), n;
185
- }
186
- computeOffset(t) {
187
- const n = this.offset + t;
188
- let s = this.buffer.byteLength;
189
- const i = s;
190
- for (; s < n; )
191
- s <<= 1;
192
- if (i < s) {
193
- const r = this.buffer;
194
- this.buffer = new ArrayBuffer(s), this.view = new DataView(this.buffer), new Uint8Array(this.buffer).set(new Uint8Array(r), 0);
195
- }
196
- return n;
197
- }
198
- pushInt(t, n) {
199
- if (n === o.BitWidth.WIDTH8)
200
- this.view.setInt8(this.offset, t);
201
- else if (n === o.BitWidth.WIDTH16)
202
- this.view.setInt16(this.offset, t, !0);
203
- else if (n === o.BitWidth.WIDTH32)
204
- this.view.setInt32(this.offset, t, !0);
205
- else if (n === o.BitWidth.WIDTH64)
206
- this.view.setBigInt64(this.offset, BigInt(t), !0);
207
- else
208
- throw `Unexpected width: ${n} for value: ${t}`;
209
- }
210
- pushUInt(t, n) {
211
- if (n === o.BitWidth.WIDTH8)
212
- this.view.setUint8(this.offset, t);
213
- else if (n === o.BitWidth.WIDTH16)
214
- this.view.setUint16(this.offset, t, !0);
215
- else if (n === o.BitWidth.WIDTH32)
216
- this.view.setUint32(this.offset, t, !0);
217
- else if (n === o.BitWidth.WIDTH64)
218
- this.view.setBigUint64(this.offset, BigInt(t), !0);
219
- else
220
- throw `Unexpected width: ${n} for value: ${t}`;
221
- }
222
- writeInt(t, n) {
223
- const s = this.computeOffset(n);
224
- this.pushInt(t, (0, e.fromByteWidth)(n)), this.offset = s;
225
- }
226
- writeUInt(t, n) {
227
- const s = this.computeOffset(n);
228
- this.pushUInt(t, (0, e.fromByteWidth)(n)), this.offset = s;
229
- }
230
- writeBlob(t) {
231
- const n = t.byteLength, s = (0, e.uwidth)(n), i = this.align(s);
232
- this.writeUInt(n, i);
233
- const r = this.offset, h = this.computeOffset(n);
234
- new Uint8Array(this.buffer).set(new Uint8Array(t), r), this.stack.push(this.offsetStackValue(r, f.ValueType.BLOB, s)), this.offset = h;
235
- }
236
- writeString(t) {
237
- if (this.dedupStrings && Object.prototype.hasOwnProperty.call(this.stringLookup, t)) {
238
- this.stack.push(this.stringLookup[t]);
239
- return;
240
- }
241
- const n = (0, T.toUTF8Array)(t), s = n.length, i = (0, e.uwidth)(s), r = this.align(i);
242
- this.writeUInt(s, r);
243
- const h = this.offset, a = this.computeOffset(s + 1);
244
- new Uint8Array(this.buffer).set(n, h);
245
- const l = this.offsetStackValue(h, f.ValueType.STRING, i);
246
- this.stack.push(l), this.dedupStrings && (this.stringLookup[t] = l), this.offset = a;
247
- }
248
- writeKey(t) {
249
- if (this.dedupKeys && Object.prototype.hasOwnProperty.call(this.keyLookup, t)) {
250
- this.stack.push(this.keyLookup[t]);
251
- return;
252
- }
253
- const n = (0, T.toUTF8Array)(t), s = n.length, i = this.computeOffset(s + 1);
254
- new Uint8Array(this.buffer).set(n, this.offset);
255
- const r = this.offsetStackValue(this.offset, f.ValueType.KEY, o.BitWidth.WIDTH8);
256
- this.stack.push(r), this.dedupKeys && (this.keyLookup[t] = r), this.offset = i;
257
- }
258
- writeStackValue(t, n) {
259
- const s = this.computeOffset(n);
260
- if (t.isOffset()) {
261
- const i = this.offset - t.offset;
262
- if (n === 8 || BigInt(i) < BigInt(1) << BigInt(n * 8))
263
- this.writeUInt(i, n);
264
- else
265
- throw `Unexpected size ${n}. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new`;
266
- } else
267
- t.writeToBuffer(n);
268
- this.offset = s;
269
- }
270
- integrityCheckOnValueAddition() {
271
- if (this.finished)
272
- throw "Adding values after finish is prohibited";
273
- if (this.stackPointers.length !== 0 && this.stackPointers[this.stackPointers.length - 1].isVector === !1 && this.stack[this.stack.length - 1].type !== f.ValueType.KEY)
274
- throw "Adding value to a map before adding a key is prohibited";
275
- }
276
- integrityCheckOnKeyAddition() {
277
- if (this.finished)
278
- throw "Adding values after finish is prohibited";
279
- if (this.stackPointers.length === 0 || this.stackPointers[this.stackPointers.length - 1].isVector)
280
- throw "Adding key before starting a map is prohibited";
281
- }
282
- startVector() {
283
- this.stackPointers.push({ stackPosition: this.stack.length, isVector: !0 });
284
- }
285
- startMap(t = !1) {
286
- this.stackPointers.push({ stackPosition: this.stack.length, isVector: !1, presorted: t });
287
- }
288
- endVector(t) {
289
- const n = this.stack.length - t.stackPosition, s = this.createVector(t.stackPosition, n, 1);
290
- this.stack.splice(t.stackPosition, n), this.stack.push(s);
291
- }
292
- endMap(t) {
293
- t.presorted || this.sort(t);
294
- let n = "";
295
- for (let h = t.stackPosition; h < this.stack.length; h += 2)
296
- n += `,${this.stack[h].offset}`;
297
- const s = this.stack.length - t.stackPosition >> 1;
298
- this.dedupKeyVectors && !Object.prototype.hasOwnProperty.call(this.keyVectorLookup, n) && (this.keyVectorLookup[n] = this.createVector(t.stackPosition, s, 2));
299
- const i = this.dedupKeyVectors ? this.keyVectorLookup[n] : this.createVector(t.stackPosition, s, 2), r = this.createVector(t.stackPosition + 1, s, 2, i);
300
- this.stack.splice(t.stackPosition, s << 1), this.stack.push(r);
301
- }
302
- sort(t) {
303
- const n = this.view, s = this.stack;
304
- function i(c, d) {
305
- if (c.type !== f.ValueType.KEY || d.type !== f.ValueType.KEY)
306
- throw `Stack values are not keys ${c} | ${d}. Check if you combined [addKey] with add... method calls properly.`;
307
- let u, k, O = 0;
308
- do {
309
- if (u = n.getUint8(c.offset + O), k = n.getUint8(d.offset + O), k < u)
310
- return !0;
311
- if (u < k)
312
- return !1;
313
- O += 1;
314
- } while (u !== 0 && k !== 0);
315
- return !1;
316
- }
317
- function r(c, d, u) {
318
- if (d === u)
319
- return;
320
- const k = c[d], O = c[d + 1];
321
- c[d] = c[u], c[d + 1] = c[u + 1], c[u] = k, c[u + 1] = O;
322
- }
323
- function h() {
324
- for (let c = t.stackPosition; c < s.length; c += 2) {
325
- let d = c;
326
- for (let u = c + 2; u < s.length; u += 2)
327
- i(s[d], s[u]) && (d = u);
328
- d !== c && r(s, d, c);
329
- }
330
- }
331
- function a(c, d) {
332
- if (c.type !== f.ValueType.KEY || d.type !== f.ValueType.KEY)
333
- throw `Stack values are not keys ${c} | ${d}. Check if you combined [addKey] with add... method calls properly.`;
334
- if (c.offset === d.offset)
335
- return !1;
336
- let u, k, O = 0;
337
- do {
338
- if (u = n.getUint8(c.offset + O), k = n.getUint8(d.offset + O), u < k)
339
- return !0;
340
- if (k < u)
341
- return !1;
342
- O += 1;
343
- } while (u !== 0 && k !== 0);
344
- return !1;
345
- }
346
- function l(c, d) {
347
- if (c < d) {
348
- const u = c + (d - c >> 2) * 2, k = s[u];
349
- let O = c, w = d;
350
- do {
351
- for (; a(s[O], k); )
352
- O += 2;
353
- for (; a(k, s[w]); )
354
- w -= 2;
355
- O <= w && (r(s, O, w), O += 2, w -= 2);
356
- } while (O <= w);
357
- l(c, w), l(O, d);
358
- }
359
- }
360
- let g = !0;
361
- for (let c = t.stackPosition; c < this.stack.length - 2; c += 2)
362
- if (i(this.stack[c], this.stack[c + 2])) {
363
- g = !1;
364
- break;
365
- }
366
- g || (this.stack.length - t.stackPosition > 40 ? l(t.stackPosition, this.stack.length - 2) : h());
367
- }
368
- end() {
369
- if (this.stackPointers.length < 1)
370
- return;
371
- const t = this.stackPointers.pop();
372
- t.isVector ? this.endVector(t) : this.endMap(t);
373
- }
374
- createVector(t, n, s, i = null) {
375
- let r = (0, e.uwidth)(n), h = 1;
376
- if (i !== null) {
377
- const u = i.elementWidth(this.offset, 0);
378
- u > r && (r = u), h += 2;
379
- }
380
- let a = f.ValueType.KEY, l = i === null;
381
- for (let u = t; u < this.stack.length; u += s) {
382
- const k = this.stack[u].elementWidth(this.offset, u + h);
383
- k > r && (r = k), u === t ? (a = this.stack[u].type, l = l && (0, W.isTypedVectorElement)(a)) : a !== this.stack[u].type && (l = !1);
384
- }
385
- const g = this.align(r), c = l && (0, W.isNumber)(a) && n >= 2 && n <= 4;
386
- i !== null && (this.writeStackValue(i, g), this.writeUInt(1 << i.width, g)), c || this.writeUInt(n, g);
387
- const d = this.offset;
388
- for (let u = t; u < this.stack.length; u += s)
389
- this.writeStackValue(this.stack[u], g);
390
- if (!l)
391
- for (let u = t; u < this.stack.length; u += s)
392
- this.writeUInt(this.stack[u].storedPackedType(), 1);
393
- if (i !== null)
394
- return this.offsetStackValue(d, f.ValueType.MAP, r);
395
- if (l) {
396
- const u = (0, W.toTypedVector)(a, c ? n : 0);
397
- return this.offsetStackValue(d, u, r);
398
- }
399
- return this.offsetStackValue(d, f.ValueType.VECTOR, r);
400
- }
401
- nullStackValue() {
402
- return new I.StackValue(this, f.ValueType.NULL, o.BitWidth.WIDTH8);
403
- }
404
- boolStackValue(t) {
405
- return new I.StackValue(this, f.ValueType.BOOL, o.BitWidth.WIDTH8, t);
406
- }
407
- intStackValue(t) {
408
- return new I.StackValue(this, f.ValueType.INT, (0, e.iwidth)(t), t);
409
- }
410
- uintStackValue(t) {
411
- return new I.StackValue(this, f.ValueType.UINT, (0, e.uwidth)(t), t);
412
- }
413
- floatStackValue(t) {
414
- return new I.StackValue(this, f.ValueType.FLOAT, (0, e.fwidth)(t), t);
415
- }
416
- offsetStackValue(t, n, s) {
417
- return new I.StackValue(this, n, s, null, t);
418
- }
419
- finishBuffer() {
420
- if (this.stack.length !== 1)
421
- throw `Stack has to be exactly 1, but it is ${this.stack.length}. You have to end all started vectors and maps before calling [finish]`;
422
- const t = this.stack[0], n = this.align(t.elementWidth(this.offset, 0));
423
- this.writeStackValue(t, n), this.writeUInt(t.storedPackedType(), 1), this.writeUInt(n, 1), this.finished = !0;
424
- }
425
- add(t) {
426
- if (this.integrityCheckOnValueAddition(), typeof t > "u")
427
- throw "You need to provide a value";
428
- if (t === null)
429
- this.stack.push(this.nullStackValue());
430
- else if (typeof t == "boolean")
431
- this.stack.push(this.boolStackValue(t));
432
- else if (typeof t == "bigint")
433
- this.stack.push(this.intStackValue(t));
434
- else if (typeof t == "number")
435
- Number.isInteger(t) ? this.stack.push(this.intStackValue(t)) : this.stack.push(this.floatStackValue(t));
436
- else if (ArrayBuffer.isView(t))
437
- this.writeBlob(t.buffer);
438
- else if (typeof t == "string" || t instanceof String)
439
- this.writeString(t);
440
- else if (Array.isArray(t)) {
441
- this.startVector();
442
- for (let n = 0; n < t.length; n++)
443
- this.add(t[n]);
444
- this.end();
445
- } else if (typeof t == "object") {
446
- const n = Object.getOwnPropertyNames(t).sort();
447
- this.startMap(!0);
448
- for (let s = 0; s < n.length; s++) {
449
- const i = n[s];
450
- this.addKey(i), this.add(t[i]);
451
- }
452
- this.end();
453
- } else
454
- throw `Unexpected value input ${t}`;
455
- }
456
- finish() {
457
- this.finished || this.finishBuffer();
458
- const t = this.buffer.slice(0, this.offset);
459
- return new Uint8Array(t);
460
- }
461
- isFinished() {
462
- return this.finished;
463
- }
464
- addKey(t) {
465
- this.integrityCheckOnKeyAddition(), this.writeKey(t);
466
- }
467
- addInt(t, n = !1, s = !1) {
468
- if (this.integrityCheckOnValueAddition(), !n) {
469
- this.stack.push(this.intStackValue(t));
470
- return;
471
- }
472
- if (s && Object.prototype.hasOwnProperty.call(this.indirectIntLookup, t)) {
473
- this.stack.push(this.indirectIntLookup[t]);
474
- return;
475
- }
476
- const i = this.intStackValue(t), r = this.align(i.width), h = this.computeOffset(r), a = this.offset;
477
- i.writeToBuffer(r);
478
- const l = this.offsetStackValue(a, f.ValueType.INDIRECT_INT, i.width);
479
- this.stack.push(l), this.offset = h, s && (this.indirectIntLookup[t] = l);
480
- }
481
- addUInt(t, n = !1, s = !1) {
482
- if (this.integrityCheckOnValueAddition(), !n) {
483
- this.stack.push(this.uintStackValue(t));
484
- return;
485
- }
486
- if (s && Object.prototype.hasOwnProperty.call(this.indirectUIntLookup, t)) {
487
- this.stack.push(this.indirectUIntLookup[t]);
488
- return;
489
- }
490
- const i = this.uintStackValue(t), r = this.align(i.width), h = this.computeOffset(r), a = this.offset;
491
- i.writeToBuffer(r);
492
- const l = this.offsetStackValue(a, f.ValueType.INDIRECT_UINT, i.width);
493
- this.stack.push(l), this.offset = h, s && (this.indirectUIntLookup[t] = l);
494
- }
495
- addFloat(t, n = !1, s = !1) {
496
- if (this.integrityCheckOnValueAddition(), !n) {
497
- this.stack.push(this.floatStackValue(t));
498
- return;
499
- }
500
- if (s && Object.prototype.hasOwnProperty.call(this.indirectFloatLookup, t)) {
501
- this.stack.push(this.indirectFloatLookup[t]);
502
- return;
503
- }
504
- const i = this.floatStackValue(t), r = this.align(i.width), h = this.computeOffset(r), a = this.offset;
505
- i.writeToBuffer(r);
506
- const l = this.offsetStackValue(a, f.ValueType.INDIRECT_FLOAT, i.width);
507
- this.stack.push(l), this.offset = h, s && (this.indirectFloatLookup[t] = l);
508
- }
509
- }
510
- return N.Builder = V, N;
511
- }
512
- var Z = J(), U = {}, _ = {}, Y;
513
- function Q() {
514
- if (Y) return _;
515
- Y = 1, Object.defineProperty(_, "__esModule", { value: !0 }), _.keyForIndex = _.diffKeys = _.keyIndex = _.indirect = _.readFloat = _.readUInt = _.readInt = _.validateOffset = void 0;
516
- const o = L(), e = A(), T = F();
517
- function f(i, r, h) {
518
- if (i.byteLength <= r + h || (r & (0, e.toByteWidth)(h) - 1) !== 0)
519
- throw "Bad offset: " + r + ", width: " + h;
520
- }
521
- _.validateOffset = f;
522
- function W(i, r, h) {
523
- return h < 2 ? h < 1 ? i.getInt8(r) : i.getInt16(r, !0) : h < 3 ? i.getInt32(r, !0) : i.setBigInt64 === void 0 ? BigInt(i.getUint32(r, !0)) + (BigInt(i.getUint32(r + 4, !0)) << BigInt(32)) : i.getBigInt64(r, !0);
524
- }
525
- _.readInt = W;
526
- function I(i, r, h) {
527
- return h < 2 ? h < 1 ? i.getUint8(r) : i.getUint16(r, !0) : h < 3 ? i.getUint32(r, !0) : i.getBigUint64 === void 0 ? BigInt(i.getUint32(r, !0)) + (BigInt(i.getUint32(r + 4, !0)) << BigInt(32)) : i.getBigUint64(r, !0);
528
- }
529
- _.readUInt = I;
530
- function V(i, r, h) {
531
- if (h < o.BitWidth.WIDTH32)
532
- throw "Bad width: " + h;
533
- return h === o.BitWidth.WIDTH32 ? i.getFloat32(r, !0) : i.getFloat64(r, !0);
534
- }
535
- _.readFloat = V;
536
- function p(i, r, h) {
537
- const a = I(i, r, h);
538
- return r - a;
539
- }
540
- _.indirect = p;
541
- function t(i, r, h, a, l, g) {
542
- const c = (0, T.toUTF8Array)(i), d = p(r, h, a) - l * 3, u = (0, e.fromByteWidth)(l), k = d - Number(I(r, d, u)), O = Number(I(r, d + l, u));
543
- let w = 0, D = g - 1;
544
- for (; w <= D; ) {
545
- const S = D + w >> 1, P = n(c, S, r, k, O);
546
- if (P === 0)
547
- return S;
548
- P < 0 ? D = S - 1 : w = S + 1;
549
- }
550
- return null;
551
- }
552
- _.keyIndex = t;
553
- function n(i, r, h, a, l) {
554
- const g = a + r * l, c = g - Number(I(h, g, (0, e.fromByteWidth)(l)));
555
- for (let d = 0; d < i.length; d++) {
556
- const u = i[d] - h.getUint8(c + d);
557
- if (u !== 0)
558
- return u;
559
- }
560
- return h.getUint8(c + i.length) === 0 ? 0 : -1;
561
- }
562
- _.diffKeys = n;
563
- function s(i, r, h, a, l) {
564
- const g = p(r, h, a) - l * 3, c = (0, e.fromByteWidth)(l), d = g - Number(I(r, g, c)), u = Number(I(r, g + l, c)), k = d + i * u, O = k - Number(I(r, k, (0, e.fromByteWidth)(u)));
565
- let w = 0;
566
- for (; r.getUint8(O + w) !== 0; )
567
- w++;
568
- return (0, T.fromUTF8Array)(new Uint8Array(r.buffer, O, w));
569
- }
570
- return _.keyForIndex = s, _;
571
- }
572
- var z;
573
- function X() {
574
- if (z) return U;
575
- z = 1, Object.defineProperty(U, "__esModule", { value: !0 }), U.Reference = U.toReference = void 0;
576
- const o = A(), e = C(), T = v(), f = Q(), W = F(), I = L();
577
- function V(n) {
578
- const s = n.byteLength;
579
- if (s < 3)
580
- throw "Buffer needs to be bigger than 3";
581
- const i = new DataView(n), r = i.getUint8(s - 1), h = i.getUint8(s - 2), a = (0, o.fromByteWidth)(r), l = s - r - 2;
582
- return new t(i, l, a, h, "/");
583
- }
584
- U.toReference = V;
585
- function p(n, s, i, r, h, a, l, g) {
586
- const c = (0, f.indirect)(i, r, h), d = c + n * a, u = i.getUint8(c + l * a + n);
587
- return new t(i, d, (0, o.fromByteWidth)(a), u, `${g}/${s}`);
588
- }
589
- class t {
590
- constructor(s, i, r, h, a) {
591
- this.dataView = s, this.offset = i, this.parentWidth = r, this.packedType = h, this.path = a, this._length = -1, this.byteWidth = 1 << (h & 3), this.valueType = h >> 2;
592
- }
593
- isNull() {
594
- return this.valueType === e.ValueType.NULL;
595
- }
596
- isNumber() {
597
- return (0, T.isNumber)(this.valueType) || (0, T.isIndirectNumber)(this.valueType);
598
- }
599
- isFloat() {
600
- return e.ValueType.FLOAT === this.valueType || e.ValueType.INDIRECT_FLOAT === this.valueType;
601
- }
602
- isInt() {
603
- return this.isNumber() && !this.isFloat();
604
- }
605
- isString() {
606
- return e.ValueType.STRING === this.valueType || e.ValueType.KEY === this.valueType;
607
- }
608
- isBool() {
609
- return e.ValueType.BOOL === this.valueType;
610
- }
611
- isBlob() {
612
- return e.ValueType.BLOB === this.valueType;
613
- }
614
- isVector() {
615
- return (0, T.isAVector)(this.valueType);
616
- }
617
- isMap() {
618
- return e.ValueType.MAP === this.valueType;
619
- }
620
- boolValue() {
621
- return this.isBool() ? (0, f.readInt)(this.dataView, this.offset, this.parentWidth) > 0 : null;
622
- }
623
- intValue() {
624
- return this.valueType === e.ValueType.INT ? (0, f.readInt)(this.dataView, this.offset, this.parentWidth) : this.valueType === e.ValueType.UINT ? (0, f.readUInt)(this.dataView, this.offset, this.parentWidth) : this.valueType === e.ValueType.INDIRECT_INT ? (0, f.readInt)(this.dataView, (0, f.indirect)(this.dataView, this.offset, this.parentWidth), (0, o.fromByteWidth)(this.byteWidth)) : this.valueType === e.ValueType.INDIRECT_UINT ? (0, f.readUInt)(this.dataView, (0, f.indirect)(this.dataView, this.offset, this.parentWidth), (0, o.fromByteWidth)(this.byteWidth)) : null;
625
- }
626
- floatValue() {
627
- return this.valueType === e.ValueType.FLOAT ? (0, f.readFloat)(this.dataView, this.offset, this.parentWidth) : this.valueType === e.ValueType.INDIRECT_FLOAT ? (0, f.readFloat)(this.dataView, (0, f.indirect)(this.dataView, this.offset, this.parentWidth), (0, o.fromByteWidth)(this.byteWidth)) : null;
628
- }
629
- numericValue() {
630
- return this.floatValue() || this.intValue();
631
- }
632
- stringValue() {
633
- if (this.valueType === e.ValueType.STRING || this.valueType === e.ValueType.KEY) {
634
- const s = (0, f.indirect)(this.dataView, this.offset, this.parentWidth);
635
- return (0, W.fromUTF8Array)(new Uint8Array(this.dataView.buffer, s, this.length()));
636
- }
637
- return null;
638
- }
639
- blobValue() {
640
- if (this.isBlob()) {
641
- const s = (0, f.indirect)(this.dataView, this.offset, this.parentWidth);
642
- return new Uint8Array(this.dataView.buffer, s, this.length());
643
- }
644
- return null;
645
- }
646
- get(s) {
647
- const i = this.length();
648
- if (Number.isInteger(s) && (0, T.isAVector)(this.valueType)) {
649
- if (s >= i || s < 0)
650
- throw `Key: [${s}] is not applicable on ${this.path} of ${this.valueType} length: ${i}`;
651
- const r = (0, f.indirect)(this.dataView, this.offset, this.parentWidth), h = r + s * this.byteWidth;
652
- let a = this.dataView.getUint8(r + i * this.byteWidth + s);
653
- if ((0, T.isTypedVector)(this.valueType)) {
654
- const l = (0, T.typedVectorElementType)(this.valueType);
655
- a = (0, T.packedType)(l, I.BitWidth.WIDTH8);
656
- } else if ((0, T.isFixedTypedVector)(this.valueType)) {
657
- const l = (0, T.fixedTypedVectorElementType)(this.valueType);
658
- a = (0, T.packedType)(l, I.BitWidth.WIDTH8);
659
- }
660
- return new t(this.dataView, h, (0, o.fromByteWidth)(this.byteWidth), a, `${this.path}[${s}]`);
661
- }
662
- if (typeof s == "string") {
663
- const r = (0, f.keyIndex)(s, this.dataView, this.offset, this.parentWidth, this.byteWidth, i);
664
- if (r !== null)
665
- return p(r, s, this.dataView, this.offset, this.parentWidth, this.byteWidth, i, this.path);
666
- }
667
- throw `Key [${s}] is not applicable on ${this.path} of ${this.valueType}`;
668
- }
669
- length() {
670
- let s;
671
- if (this._length > -1)
672
- return this._length;
673
- if ((0, T.isFixedTypedVector)(this.valueType))
674
- this._length = (0, T.fixedTypedVectorElementSize)(this.valueType);
675
- else if (this.valueType === e.ValueType.BLOB || this.valueType === e.ValueType.MAP || (0, T.isAVector)(this.valueType))
676
- this._length = (0, f.readUInt)(this.dataView, (0, f.indirect)(this.dataView, this.offset, this.parentWidth) - this.byteWidth, (0, o.fromByteWidth)(this.byteWidth));
677
- else if (this.valueType === e.ValueType.NULL)
678
- this._length = 0;
679
- else if (this.valueType === e.ValueType.STRING) {
680
- const i = (0, f.indirect)(this.dataView, this.offset, this.parentWidth);
681
- let r = this.byteWidth;
682
- for (s = (0, f.readUInt)(this.dataView, i - r, (0, o.fromByteWidth)(this.byteWidth)); this.dataView.getInt8(i + s) !== 0; )
683
- r <<= 1, s = (0, f.readUInt)(this.dataView, i - r, (0, o.fromByteWidth)(this.byteWidth));
684
- this._length = s;
685
- } else if (this.valueType === e.ValueType.KEY) {
686
- const i = (0, f.indirect)(this.dataView, this.offset, this.parentWidth);
687
- for (s = 1; this.dataView.getInt8(i + s) !== 0; )
688
- s++;
689
- this._length = s;
690
- } else
691
- this._length = 1;
692
- return Number(this._length);
693
- }
694
- toObject() {
695
- const s = this.length();
696
- if (this.isVector()) {
697
- const i = [];
698
- for (let r = 0; r < s; r++)
699
- i.push(this.get(r).toObject());
700
- return i;
701
- }
702
- if (this.isMap()) {
703
- const i = {};
704
- for (let r = 0; r < s; r++) {
705
- const h = (0, f.keyForIndex)(r, this.dataView, this.offset, this.parentWidth, this.byteWidth);
706
- i[h] = p(r, h, this.dataView, this.offset, this.parentWidth, this.byteWidth, s, this.path).toObject();
707
- }
708
- return i;
709
- }
710
- return this.isNull() ? null : this.isBool() ? this.boolValue() : this.isNumber() ? this.numericValue() : this.blobValue() || this.stringValue();
711
- }
712
- }
713
- return U.Reference = t, U;
714
- }
715
- var tt = X();
716
- export {
717
- Z as b,
718
- tt as r
719
- };