@atolljs/core 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/contract/memoryDevtools.d.ts +30 -0
- package/dist/contract/sharedMemory.d.ts +4 -2
- package/dist/contract/types.d.ts +11 -0
- package/dist/devtools.d.ts +127 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +19 -17
- package/dist/index10.js +29 -14
- package/dist/index11.js +14 -307
- package/dist/index12.js +29 -50
- package/dist/index13.js +46 -60
- package/dist/index14.js +56 -22
- package/dist/index15.js +332 -55
- package/dist/index16.js +246 -45
- package/dist/index17.js +56 -51
- package/dist/index18.js +9 -39
- package/dist/index19.js +56 -80
- package/dist/index20.js +24 -53
- package/dist/index21.js +56 -52
- package/dist/index22.js +48 -0
- package/dist/index23.js +68 -0
- package/dist/index24.js +41 -0
- package/dist/index25.js +46 -0
- package/dist/index26.js +113 -0
- package/dist/index27.js +60 -0
- package/dist/index28.js +57 -0
- package/dist/index5.js +135 -64
- package/dist/index6.js +160 -35
- package/dist/index7.js +45 -503
- package/dist/index8.js +513 -19
- package/dist/index9.js +19 -33
- package/dist/pool/dedicatedWorker.d.ts +63 -0
- package/dist/pool/devtoolsCommands.d.ts +54 -0
- package/dist/pool/subWorkerClient.d.ts +50 -0
- package/dist/pool/workerChannel.d.ts +44 -0
- package/dist/pool/workerClient.d.ts +36 -8
- package/dist/pool/workerPool.d.ts +10 -1
- package/dist/reactive.d.ts +15 -0
- package/dist/reactiveGraph.d.ts +9 -0
- package/dist/userTiming.d.ts +27 -0
- package/package.json +4 -3
- package/src/contract/memoryDevtools.ts +249 -0
- package/src/contract/sharedMemory.ts +20 -6
- package/src/contract/types.ts +11 -0
- package/src/devtools.ts +251 -6
- package/src/index.ts +13 -1
- package/src/log.ts +22 -0
- package/src/observable.ts +16 -3
- package/src/pool/dedicatedWorker.ts +332 -0
- package/src/pool/devtoolsCommands.ts +165 -0
- package/src/pool/subWorkerClient.ts +70 -0
- package/src/pool/workerChannel.ts +99 -0
- package/src/pool/workerClient.ts +61 -15
- package/src/pool/workerPool.ts +75 -45
- package/src/reactive.ts +87 -12
- package/src/reactiveGraph.ts +91 -0
- package/src/testing/inProcessWorker.ts +4 -3
- package/src/userTiming.ts +71 -0
- package/src/worker/workerBootstrap.ts +33 -5
package/dist/index7.js
CHANGED
|
@@ -1,510 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
f64: 8,
|
|
39
|
-
i64: 8,
|
|
40
|
-
u64: 8
|
|
41
|
-
}, C = (e) => typeof e == "string" ? S[e] : "string" in e ? e.string : 1, w = (e) => typeof e == "string" ? S[e] : 1;
|
|
42
|
-
function T(e) {
|
|
43
|
-
let t = {}, n = {}, i = 0;
|
|
44
|
-
for (let a of Object.keys(e)) {
|
|
45
|
-
let o = r(e[a], String(a));
|
|
46
|
-
n[a] = o, i = p(i, w(o)), t[a] = i, i += C(o);
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
layout: n,
|
|
50
|
-
offsets: t,
|
|
51
|
-
recordSize: m(i)
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
var E = {
|
|
55
|
-
number: () => ({
|
|
56
|
-
kind: "number",
|
|
57
|
-
byteLength: 8
|
|
58
|
-
}),
|
|
59
|
-
boolean: () => ({
|
|
60
|
-
kind: "boolean",
|
|
61
|
-
byteLength: 8
|
|
62
|
-
}),
|
|
63
|
-
string: (e) => {
|
|
64
|
-
let { schema: t, maxBytes: n } = e;
|
|
65
|
-
if (n !== void 0) return {
|
|
66
|
-
kind: "string",
|
|
67
|
-
byteLength: 4 + n,
|
|
68
|
-
schema: t
|
|
69
|
-
};
|
|
70
|
-
let r = t ? o(t) : null;
|
|
71
|
-
if (r !== null) return {
|
|
72
|
-
kind: "string",
|
|
73
|
-
byteLength: 4 + r,
|
|
74
|
-
schema: t
|
|
75
|
-
};
|
|
76
|
-
throw TypeError("field.string: pass { maxBytes } or a schema carrying a byte budget — reef.string(n) / z.string().meta({ bytes: n })");
|
|
77
|
-
},
|
|
78
|
-
object: (e) => {
|
|
79
|
-
let { schema: t, maxBytes: n } = e;
|
|
80
|
-
if (n === void 0 && t) {
|
|
81
|
-
let e = a(t);
|
|
82
|
-
if (e) {
|
|
83
|
-
let { layout: n, offsets: r, recordSize: i } = T(e);
|
|
84
|
-
return {
|
|
85
|
-
kind: "object",
|
|
86
|
-
byteLength: 8 + i,
|
|
87
|
-
schema: t,
|
|
88
|
-
layout: n,
|
|
89
|
-
offsets: r,
|
|
90
|
-
recordSize: i
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
throw TypeError("field.object: schema can't derive a fixed byte width (not a zod object of fixed-width members) — pass { maxBytes } for codec-encoded storage");
|
|
94
|
-
}
|
|
95
|
-
if (n === void 0) throw TypeError("field.object: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
|
|
96
|
-
return {
|
|
97
|
-
kind: "object",
|
|
98
|
-
byteLength: 4 + n,
|
|
99
|
-
schema: t
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
array: (e) => {
|
|
103
|
-
let { schema: t, maxBytes: n } = e;
|
|
104
|
-
if (n === void 0 && t) {
|
|
105
|
-
let e = i(t);
|
|
106
|
-
if (e) {
|
|
107
|
-
if (e.capacity === null) throw TypeError("field.array: z.array() needs .max(n) or .length(n) — bounded arrays are fixed-width");
|
|
108
|
-
let n;
|
|
109
|
-
try {
|
|
110
|
-
n = r(e.element, "array element");
|
|
111
|
-
} catch (e) {
|
|
112
|
-
throw TypeError(`field.array: element isn't a fixed-width member — use field.list for arrays of records (${e.message})`);
|
|
113
|
-
}
|
|
114
|
-
let i = p(C(n), w(n));
|
|
115
|
-
return {
|
|
116
|
-
kind: "array",
|
|
117
|
-
byteLength: 8 + e.capacity * i,
|
|
118
|
-
schema: t,
|
|
119
|
-
element: n,
|
|
120
|
-
elementStride: i,
|
|
121
|
-
capacity: e.capacity
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
throw TypeError("field.array: schema can't derive a fixed byte width (not a bounded zod array) — pass { maxBytes } for codec-encoded storage");
|
|
1
|
+
import { devtoolsEnabled as e, emitDevtools as t, previewValue as n } from "./index5.js";
|
|
2
|
+
//#region src/log.ts
|
|
3
|
+
var r = {
|
|
4
|
+
trace: 0,
|
|
5
|
+
debug: 1,
|
|
6
|
+
info: 2,
|
|
7
|
+
warn: 3,
|
|
8
|
+
error: 4,
|
|
9
|
+
off: 5
|
|
10
|
+
}, i = typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "worker" : "main", a = ({ level: e, scope: t, message: n, data: r, thread: i, at: a }) => {
|
|
11
|
+
let o = `[${(a / 1e3).toFixed(2)}s ${i}:${t}]`, s = e === "error" ? console.error : e === "warn" ? console.warn : e === "info" ? console.info : console.debug;
|
|
12
|
+
r === void 0 ? s(`${o} ${n}`) : s(`${o} ${n}`, r);
|
|
13
|
+
}, o = "info", s = a, c = (e) => {
|
|
14
|
+
o = e;
|
|
15
|
+
}, l = () => o, u = (e) => {
|
|
16
|
+
s = e ?? a;
|
|
17
|
+
}, d = !1;
|
|
18
|
+
function f(a, c, l, u) {
|
|
19
|
+
if (!(r[a] < r[o]) && (s({
|
|
20
|
+
level: a,
|
|
21
|
+
scope: c,
|
|
22
|
+
message: l,
|
|
23
|
+
data: u,
|
|
24
|
+
thread: i,
|
|
25
|
+
at: performance.now()
|
|
26
|
+
}), !d && e())) {
|
|
27
|
+
d = !0;
|
|
28
|
+
try {
|
|
29
|
+
t({
|
|
30
|
+
type: "log",
|
|
31
|
+
level: a,
|
|
32
|
+
scope: c,
|
|
33
|
+
message: l,
|
|
34
|
+
...u === void 0 ? {} : { data: n(u, 1024) }
|
|
35
|
+
});
|
|
36
|
+
} finally {
|
|
37
|
+
d = !1;
|
|
125
38
|
}
|
|
126
|
-
if (n === void 0) throw TypeError("field.array: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
|
|
127
|
-
return {
|
|
128
|
-
kind: "array",
|
|
129
|
-
byteLength: 4 + n,
|
|
130
|
-
schema: t
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
int32Array: ({ length: e }) => ({
|
|
134
|
-
kind: "Int32",
|
|
135
|
-
byteLength: e * 4
|
|
136
|
-
}),
|
|
137
|
-
float64Array: ({ length: e }) => ({
|
|
138
|
-
kind: "Float64",
|
|
139
|
-
byteLength: e * 8
|
|
140
|
-
}),
|
|
141
|
-
bigInt64Array: ({ length: e }) => ({
|
|
142
|
-
kind: "BigInt64",
|
|
143
|
-
byteLength: e * 8
|
|
144
|
-
}),
|
|
145
|
-
uint8Array: ({ length: e }) => ({
|
|
146
|
-
kind: "Uint8",
|
|
147
|
-
byteLength: e
|
|
148
|
-
}),
|
|
149
|
-
list: ({ schema: e, count: t }) => {
|
|
150
|
-
let n = a(e);
|
|
151
|
-
if (!n) throw TypeError("field.list: schema must be a reef.object() of fixed-width members");
|
|
152
|
-
let { layout: r, offsets: i, recordSize: o } = T(n);
|
|
153
|
-
return {
|
|
154
|
-
kind: "list",
|
|
155
|
-
byteLength: o * t,
|
|
156
|
-
schema: e,
|
|
157
|
-
layout: r,
|
|
158
|
-
offsets: i,
|
|
159
|
-
recordSize: o,
|
|
160
|
-
count: t
|
|
161
|
-
};
|
|
162
39
|
}
|
|
163
|
-
}, D = {
|
|
164
|
-
Int32: Int32Array,
|
|
165
|
-
Float64: Float64Array,
|
|
166
|
-
BigInt64: BigInt64Array,
|
|
167
|
-
Uint8: Uint8Array
|
|
168
|
-
};
|
|
169
|
-
x("number", (e, t, n) => {
|
|
170
|
-
let r = new Float64Array(t.buffer, n, 1);
|
|
171
|
-
return {
|
|
172
|
-
byteOffset: n,
|
|
173
|
-
byteLength: e.byteLength,
|
|
174
|
-
read: () => r[0],
|
|
175
|
-
write: (e) => {
|
|
176
|
-
r[0] = e;
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
}), x("boolean", (e, t, n) => {
|
|
180
|
-
let r = new Uint8Array(t.buffer, n, 1);
|
|
181
|
-
return {
|
|
182
|
-
byteOffset: n,
|
|
183
|
-
byteLength: e.byteLength,
|
|
184
|
-
read: () => r[0] === 1,
|
|
185
|
-
write: (e) => {
|
|
186
|
-
r[0] = +!!e;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
});
|
|
190
|
-
for (let e of Object.keys(D)) x(e, (t, n, r) => {
|
|
191
|
-
let i = D[e], a = new i(n.buffer, r, t.byteLength / i.BYTES_PER_ELEMENT);
|
|
192
|
-
return {
|
|
193
|
-
byteOffset: r,
|
|
194
|
-
byteLength: t.byteLength,
|
|
195
|
-
read: () => a,
|
|
196
|
-
write: (e) => a.set(e)
|
|
197
|
-
};
|
|
198
|
-
});
|
|
199
|
-
x("string", (e, t, n) => {
|
|
200
|
-
let r = new TextEncoder(), i = new TextDecoder(), a = e.byteLength - 4, o = new Uint32Array(t.buffer, n, 1), s = (e) => {
|
|
201
|
-
if (e.byteLength > a) throw Error(`Encoded value of ${e.byteLength} bytes exceeds field capacity of ${a} bytes at offset ${n}`);
|
|
202
|
-
o[0] = e.byteLength, new Uint8Array(t.buffer, n + 4, e.byteLength).set(e);
|
|
203
|
-
}, c = () => new Uint8Array(t.buffer, n + 4, o[0]).slice();
|
|
204
|
-
return {
|
|
205
|
-
byteOffset: n,
|
|
206
|
-
byteLength: e.byteLength,
|
|
207
|
-
read: () => i.decode(c()),
|
|
208
|
-
write: (t) => s(r.encode(e.schema ? e.schema.parse(t) : t))
|
|
209
|
-
};
|
|
210
|
-
});
|
|
211
|
-
function O(e) {
|
|
212
|
-
let t = new DataView(e.buffer), n = new Uint8Array(e.buffer), r = new TextEncoder(), i = new TextDecoder(), a = {
|
|
213
|
-
i8: {
|
|
214
|
-
get: (e) => t.getInt8(e),
|
|
215
|
-
set: (e, n) => t.setInt8(e, n)
|
|
216
|
-
},
|
|
217
|
-
u8: {
|
|
218
|
-
get: (e) => t.getUint8(e),
|
|
219
|
-
set: (e, n) => t.setUint8(e, n)
|
|
220
|
-
},
|
|
221
|
-
i16: {
|
|
222
|
-
get: (e) => t.getInt16(e),
|
|
223
|
-
set: (e, n) => t.setInt16(e, n)
|
|
224
|
-
},
|
|
225
|
-
u16: {
|
|
226
|
-
get: (e) => t.getUint16(e),
|
|
227
|
-
set: (e, n) => t.setUint16(e, n)
|
|
228
|
-
},
|
|
229
|
-
i32: {
|
|
230
|
-
get: (e) => t.getInt32(e),
|
|
231
|
-
set: (e, n) => t.setInt32(e, n)
|
|
232
|
-
},
|
|
233
|
-
u32: {
|
|
234
|
-
get: (e) => t.getUint32(e),
|
|
235
|
-
set: (e, n) => t.setUint32(e, n)
|
|
236
|
-
},
|
|
237
|
-
f32: {
|
|
238
|
-
get: (e) => t.getFloat32(e),
|
|
239
|
-
set: (e, n) => t.setFloat32(e, n)
|
|
240
|
-
},
|
|
241
|
-
f64: {
|
|
242
|
-
get: (e) => t.getFloat64(e),
|
|
243
|
-
set: (e, n) => t.setFloat64(e, n)
|
|
244
|
-
},
|
|
245
|
-
i64: {
|
|
246
|
-
get: (e) => t.getBigInt64(e),
|
|
247
|
-
set: (e, n) => t.setBigInt64(e, n)
|
|
248
|
-
},
|
|
249
|
-
u64: {
|
|
250
|
-
get: (e) => t.getBigUint64(e),
|
|
251
|
-
set: (e, n) => t.setBigUint64(e, n)
|
|
252
|
-
}
|
|
253
|
-
}, o = (e, t) => {
|
|
254
|
-
let r = n.indexOf(0, e), a = r === -1 || r - e >= t ? t : r - e;
|
|
255
|
-
return i.decode(n.slice(e, e + a));
|
|
256
|
-
}, s = /* @__PURE__ */ new Uint8Array(64), c = (e, t, i) => {
|
|
257
|
-
s.length < t && (s = new Uint8Array(t));
|
|
258
|
-
let { read: a, written: o } = r.encodeInto(i, s);
|
|
259
|
-
if (a < i.length || o > t) throw Error(`String exceeds inline field capacity of ${t} bytes`);
|
|
260
|
-
n.set(s.subarray(0, o), e), o < t && n.fill(0, e + o, e + t);
|
|
261
|
-
}, l = (e) => {
|
|
262
|
-
if (typeof e == "string") {
|
|
263
|
-
let t = a[e];
|
|
264
|
-
return {
|
|
265
|
-
get: (e) => t.get(e),
|
|
266
|
-
set: (e, n) => t.set(e, n)
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
return "bool" in e ? {
|
|
270
|
-
get: (e) => !!t.getUint8(e),
|
|
271
|
-
set: (e, n) => t.setUint8(e, +!!n)
|
|
272
|
-
} : {
|
|
273
|
-
get: (t) => o(t, e.string),
|
|
274
|
-
set: (t, n) => c(t, e.string, n)
|
|
275
|
-
};
|
|
276
|
-
};
|
|
277
|
-
return {
|
|
278
|
-
ops: l,
|
|
279
|
-
compile: (e, t) => {
|
|
280
|
-
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
|
|
281
|
-
for (let i of Object.keys(e)) {
|
|
282
|
-
let { get: a, set: o } = l(e[i]), s = t[i];
|
|
283
|
-
n.set(i, (e, t) => {
|
|
284
|
-
t[i] = a(e + s);
|
|
285
|
-
}), r.set(i, (e, t) => o(e + s, t[i]));
|
|
286
|
-
}
|
|
287
|
-
let i = [...n.values()], a = [...r.values()];
|
|
288
|
-
return {
|
|
289
|
-
read(e, t = {}, r) {
|
|
290
|
-
if (r) for (let i of r) n.get(i)(e, t);
|
|
291
|
-
else for (let n of i) n(e, t);
|
|
292
|
-
return t;
|
|
293
|
-
},
|
|
294
|
-
write(e, t, n) {
|
|
295
|
-
if (n) for (let i of n) r.get(i)(e, t);
|
|
296
|
-
else for (let n of a) n(e, t);
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
40
|
}
|
|
302
|
-
|
|
303
|
-
let { schema: r, byteLength: i, kind: a } = e, o = e;
|
|
304
|
-
if (o.layout && o.offsets && o.recordSize !== void 0) {
|
|
305
|
-
let e = new Uint32Array(t.buffer, n, 2), a = n + 8, s = O(t).compile(o.layout, o.offsets);
|
|
306
|
-
return {
|
|
307
|
-
byteOffset: n,
|
|
308
|
-
byteLength: i,
|
|
309
|
-
read: () => e[0] ? s.read(a, {}) : void 0,
|
|
310
|
-
write: (t) => {
|
|
311
|
-
s.write(a, r ? r.parse(t) : t), e[0] = 1;
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
if (o.element !== void 0 && o.elementStride !== void 0 && o.capacity !== void 0) {
|
|
316
|
-
let e = new Uint32Array(t.buffer, n, 1), a = new Uint32Array(t.buffer, n + 4, 1), s = O(t).ops(o.element), c = o.elementStride, l = o.capacity, u = n + 8;
|
|
317
|
-
return {
|
|
318
|
-
byteOffset: n,
|
|
319
|
-
byteLength: i,
|
|
320
|
-
read: () => {
|
|
321
|
-
if (!e[0]) return;
|
|
322
|
-
let t = a[0];
|
|
323
|
-
return Array.from({ length: t }, (e, t) => s.get(u + t * c));
|
|
324
|
-
},
|
|
325
|
-
write: (t) => {
|
|
326
|
-
let n = r ? r.parse(t) : t;
|
|
327
|
-
if (n.length > l) throw Error(`${n.length} elements exceeds array capacity of ${l}`);
|
|
328
|
-
n.forEach((e, t) => s.set(u + t * c, e)), a[0] = n.length, e[0] = 1;
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
let s = i - 4, c = new Uint32Array(t.buffer, n, 1), l = (e) => {
|
|
333
|
-
if (e.byteLength > s) throw Error(`Encoded value of ${e.byteLength} bytes exceeds field capacity of ${s} bytes at offset ${n}`);
|
|
334
|
-
c[0] = e.byteLength, new Uint8Array(t.buffer, n + 4, e.byteLength).set(e);
|
|
335
|
-
}, u = () => new Uint8Array(t.buffer, n + 4, c[0]).slice();
|
|
336
|
-
return {
|
|
337
|
-
byteOffset: n,
|
|
338
|
-
byteLength: i,
|
|
339
|
-
read: () => {
|
|
340
|
-
let e = u();
|
|
341
|
-
if (e.byteLength === 0) return;
|
|
342
|
-
let n = t.codec.decode(e);
|
|
343
|
-
return r ? r.parse(n) : n;
|
|
344
|
-
},
|
|
345
|
-
write: (e) => l(t.codec.encode(r ? r.parse(e) : e))
|
|
346
|
-
};
|
|
347
|
-
};
|
|
348
|
-
x("object", k), x("array", k);
|
|
349
|
-
function A(e, t, n) {
|
|
350
|
-
let r = e, { offsets: i, recordSize: a, count: o } = r, l = O(t).compile(r.layout, i), u = (e) => {
|
|
351
|
-
if (e < 0 || e >= o) throw RangeError(`Record index ${e} out of bounds (0..${o - 1})`);
|
|
352
|
-
}, d = (e, t = {}, r) => (u(e), l.read(n + e * a, t, r)), f = (e, t, r) => {
|
|
353
|
-
u(e), l.write(n + e * a, t, r);
|
|
354
|
-
};
|
|
41
|
+
function p(e) {
|
|
355
42
|
return {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
writeAt: f,
|
|
362
|
-
commit: () => {
|
|
363
|
-
if (t.version) {
|
|
364
|
-
let e = Atomics.add(t.version.view, t.version.index, 1);
|
|
365
|
-
Atomics.notify(t.version.view, t.version.index), t.path && s() && c({
|
|
366
|
-
type: "memory:write",
|
|
367
|
-
path: t.path,
|
|
368
|
-
version: e + 1
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
read: () => Array.from({ length: o }, (e, t) => d(t)),
|
|
373
|
-
write: (e) => {
|
|
374
|
-
if (e.length > o) throw Error(`${e.length} records exceeds list array capacity of ${o}`);
|
|
375
|
-
e.forEach((e, t) => f(t, e));
|
|
376
|
-
}
|
|
43
|
+
trace: (t, n) => f("trace", e, t, n),
|
|
44
|
+
debug: (t, n) => f("debug", e, t, n),
|
|
45
|
+
info: (t, n) => f("info", e, t, n),
|
|
46
|
+
warn: (t, n) => f("warn", e, t, n),
|
|
47
|
+
error: (t, n) => f("error", e, t, n)
|
|
377
48
|
};
|
|
378
49
|
}
|
|
379
|
-
|
|
380
|
-
var j = [];
|
|
381
|
-
function M(e) {
|
|
382
|
-
let t = {};
|
|
383
|
-
for (let [n, r] of Object.entries(e)) t[n] = h(r) ? N(r) : Object.fromEntries(Object.entries(r).map(([e, t]) => [e, N(t)]));
|
|
384
|
-
return t;
|
|
385
|
-
}
|
|
386
|
-
function N(e) {
|
|
387
|
-
if (e.schema) return e.schema;
|
|
388
|
-
switch (e.kind) {
|
|
389
|
-
case "number": return t(n.number());
|
|
390
|
-
case "boolean": return t(n.boolean());
|
|
391
|
-
case "string": return t(n.string());
|
|
392
|
-
case "Int32": return t(n.instanceof(Int32Array));
|
|
393
|
-
case "Float64": return t(n.instanceof(Float64Array));
|
|
394
|
-
case "BigInt64": return t(n.instanceof(BigInt64Array));
|
|
395
|
-
case "Uint8": return t(n.instanceof(Uint8Array));
|
|
396
|
-
default: return t(n.unknown());
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
var P = class {
|
|
400
|
-
totalBytes;
|
|
401
|
-
spec;
|
|
402
|
-
schemas;
|
|
403
|
-
codec;
|
|
404
|
-
plugins;
|
|
405
|
-
entries;
|
|
406
|
-
offsets = /* @__PURE__ */ new Map();
|
|
407
|
-
versionOffset;
|
|
408
|
-
connectors = /* @__PURE__ */ new Map();
|
|
409
|
-
boundListeners = /* @__PURE__ */ new Set();
|
|
410
|
-
isBound = !1;
|
|
411
|
-
boundBuffer;
|
|
412
|
-
constructor(t, n = {}) {
|
|
413
|
-
this.spec = t, this.codec = n.codec ?? e, this.plugins = n.plugins, this.entries = g(t), this.schemas = M(t);
|
|
414
|
-
let r = 0;
|
|
415
|
-
for (let { path: e, descriptor: t } of this.entries) r = m(r), this.offsets.set(e, r), r += t.byteLength;
|
|
416
|
-
this.versionOffset = m(r), this.totalBytes = this.versionOffset + m(this.entries.length * 4), j.push(this), d.info(`contract defined: ${this.entries.length} field(s), ${l(this.totalBytes)}`, {
|
|
417
|
-
fields: Object.fromEntries(this.entries.map((e) => [e.path, `${e.descriptor.kind}@${this.offsets.get(e.path)?.toLocaleString()}+${l(e.descriptor.byteLength)}`])),
|
|
418
|
-
pluginOverrides: Object.keys(this.plugins ?? {})
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
bind(e) {
|
|
422
|
-
this.connectors.clear();
|
|
423
|
-
let t = new Int32Array(e, this.versionOffset, this.entries.length);
|
|
424
|
-
this.entries.forEach(({ path: n, descriptor: r }, i) => {
|
|
425
|
-
let a = this.plugins?.[r.kind] ?? b.get(r.kind);
|
|
426
|
-
if (!a) throw Error(`Unknown shared memory field kind: ${r.kind}`);
|
|
427
|
-
d.debug(`bind "${n}" (${r.kind}, ${l(r.byteLength)}) via ${this.plugins?.[r.kind] ? "plugin" : "built-in"} factory`);
|
|
428
|
-
let o = a(r, {
|
|
429
|
-
buffer: e,
|
|
430
|
-
codec: this.codec,
|
|
431
|
-
version: {
|
|
432
|
-
view: t,
|
|
433
|
-
index: i
|
|
434
|
-
},
|
|
435
|
-
path: n
|
|
436
|
-
}, this.offsets.get(n));
|
|
437
|
-
this.connectors.set(n, {
|
|
438
|
-
...o,
|
|
439
|
-
write: (e) => {
|
|
440
|
-
o.write(e);
|
|
441
|
-
let r = Atomics.add(t, i, 1);
|
|
442
|
-
Atomics.notify(t, i), s() && c({
|
|
443
|
-
type: "memory:write",
|
|
444
|
-
path: n,
|
|
445
|
-
version: r + 1
|
|
446
|
-
});
|
|
447
|
-
},
|
|
448
|
-
_version: {
|
|
449
|
-
view: t,
|
|
450
|
-
index: i
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
}), s() && c({
|
|
454
|
-
type: "memory:bind",
|
|
455
|
-
fields: this.entries.map((e, t) => [t, e.path]),
|
|
456
|
-
totalBytes: this.totalBytes
|
|
457
|
-
}), this.isBound = !0, this.boundBuffer = e;
|
|
458
|
-
for (let e of [...this.boundListeners]) e();
|
|
459
|
-
}
|
|
460
|
-
get bound() {
|
|
461
|
-
return this.isBound;
|
|
462
|
-
}
|
|
463
|
-
get buffer() {
|
|
464
|
-
if (!this.boundBuffer) throw Error("Shared memory contract is not bound to a buffer on this thread.");
|
|
465
|
-
return this.boundBuffer;
|
|
466
|
-
}
|
|
467
|
-
fields() {
|
|
468
|
-
return this.entries.map(({ path: e, descriptor: t }) => ({
|
|
469
|
-
path: e,
|
|
470
|
-
byteOffset: this.offsets.get(e),
|
|
471
|
-
byteLength: t.byteLength
|
|
472
|
-
}));
|
|
473
|
-
}
|
|
474
|
-
onBound(e) {
|
|
475
|
-
return this.isBound ? (e(), () => {}) : (this.boundListeners.add(e), () => this.boundListeners.delete(e));
|
|
476
|
-
}
|
|
477
|
-
connector(e) {
|
|
478
|
-
let t = String(e), n = this.connectors.get(t);
|
|
479
|
-
if (!n) throw Error(`Shared memory field "${t}" was accessed before the buffer was bound on this thread.`);
|
|
480
|
-
return n;
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
function F(e, t = {}) {
|
|
484
|
-
let n = new P(e, t);
|
|
485
|
-
for (let [t, r] of Object.entries(e)) if (h(r)) Object.defineProperty(n, t, {
|
|
486
|
-
enumerable: !0,
|
|
487
|
-
get: () => n.connector(t)
|
|
488
|
-
});
|
|
489
|
-
else {
|
|
490
|
-
let e = {};
|
|
491
|
-
for (let i of Object.keys(r)) Object.defineProperty(e, i, {
|
|
492
|
-
enumerable: !0,
|
|
493
|
-
get: () => n.connector(`${t}.${i}`)
|
|
494
|
-
});
|
|
495
|
-
Object.defineProperty(n, t, {
|
|
496
|
-
enumerable: !0,
|
|
497
|
-
get: () => e
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
return n;
|
|
501
|
-
}
|
|
502
|
-
function I(e) {
|
|
503
|
-
for (let t of j) t.bind(e);
|
|
504
|
-
d.info(`bound ${j.length} contract(s) — ${l(e.byteLength)} buffer`);
|
|
505
|
-
}
|
|
506
|
-
function L() {
|
|
507
|
-
return j.length;
|
|
508
|
-
}
|
|
50
|
+
var m = (e) => e >= 1 << 20 ? `${(e / (1 << 20)).toFixed(1)}MB` : e >= 1024 ? `${(e / 1024).toFixed(1)}KB` : `${e}B`;
|
|
509
51
|
//#endregion
|
|
510
|
-
export {
|
|
52
|
+
export { m as fmtBytes, l as getLogLevel, f as log, p as scoped, c as setLogLevel, u as setLogSink };
|