@atolljs/core 0.1.0 → 0.1.1
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 +159 -59
- package/dist/contract/listSchema.d.ts +47 -0
- package/dist/contract/msgpackCodec.d.ts +7 -0
- package/dist/contract/msgpackrCodec.d.ts +2 -0
- package/dist/contract/mz.d.ts +43 -0
- package/dist/contract/sharedMemory.d.ts +350 -0
- package/dist/contract/types.d.ts +131 -0
- package/dist/contract/zod.d.ts +53 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +18 -18
- package/dist/index10.js +14 -178
- package/dist/index11.js +188 -47
- package/dist/index12.js +45 -59
- package/dist/index13.js +59 -20
- package/dist/index14.js +24 -60
- package/dist/index15.js +56 -43
- package/dist/index16.js +45 -41
- package/dist/index17.js +42 -38
- package/dist/index18.js +36 -55
- package/dist/index19.js +52 -47
- package/dist/index20.js +48 -51
- package/dist/index21.js +59 -0
- package/dist/index3.js +24 -117
- package/dist/index4.js +116 -34
- package/dist/index5.js +32 -473
- package/dist/index6.js +489 -19
- package/dist/index7.js +19 -6
- package/dist/index8.js +6 -33
- package/dist/index9.js +29 -14
- package/dist/log.d.ts +35 -0
- package/dist/observable.d.ts +30 -0
- package/dist/pool/errors.d.ts +16 -0
- package/dist/pool/memory.d.ts +19 -0
- package/dist/pool/workerClient.d.ts +80 -0
- package/dist/pool/workerPool.d.ts +115 -0
- package/dist/reactive.d.ts +46 -0
- package/dist/service.d.ts +181 -0
- package/dist/shared/sharedWorkerClient.d.ts +35 -0
- package/dist/shared/sharedWorkerHost.d.ts +21 -0
- package/dist/task.d.ts +40 -0
- package/dist/worker/defineWorker.d.ts +63 -0
- package/dist/worker/registry.d.ts +8 -0
- package/dist/worker/workerBootstrap.d.ts +1 -0
- package/package.json +14 -2
- package/src/contract/listSchema.ts +13 -8
- package/src/contract/mz.ts +1 -1
- package/src/contract/sharedMemory.ts +28 -1
- package/src/contract/types.ts +21 -0
- package/src/contract/zod.ts +44 -0
- package/src/index.ts +2 -1
- package/src/pool/workerPool.ts +27 -1
package/dist/index6.js
CHANGED
|
@@ -1,23 +1,493 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { msgpackrCodec as e } from "./index2.js";
|
|
2
|
+
import { z as t } from "./index3.js";
|
|
3
|
+
import { memberToSpec as n, zodArrayInfo as r, zodObjectShape as i, zodStringBytes as a } from "./index4.js";
|
|
4
|
+
import { fmtBytes as o, scoped as s } from "./index5.js";
|
|
5
|
+
//#region src/contract/sharedMemory.ts
|
|
6
|
+
var c = s("memory"), l = 8, u = (e, t) => e + t - 1 & ~(t - 1), d = (e) => u(e, l), f = (e) => typeof e == "object" && !!e && typeof e.kind == "string" && typeof e.byteLength == "number";
|
|
7
|
+
function p(e) {
|
|
8
|
+
let t = [];
|
|
9
|
+
for (let [n, r] of Object.entries(e)) if (f(r)) t.push({
|
|
10
|
+
path: n,
|
|
11
|
+
descriptor: r
|
|
12
|
+
});
|
|
13
|
+
else for (let [e, i] of Object.entries(r)) {
|
|
14
|
+
if (!f(i)) throw TypeError(`shared memory "${n}.${e}" is not a field descriptor — intent groups nest one level only`);
|
|
15
|
+
t.push({
|
|
16
|
+
path: `${n}.${e}`,
|
|
17
|
+
descriptor: i
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
}
|
|
22
|
+
var m = new TextEncoder(), h = new TextDecoder(), g = {
|
|
23
|
+
encode: (e) => m.encode(JSON.stringify(e)),
|
|
24
|
+
decode: (e) => JSON.parse(h.decode(e))
|
|
25
|
+
}, _ = /* @__PURE__ */ new Map();
|
|
26
|
+
function v(e, t) {
|
|
27
|
+
_.set(e, t);
|
|
28
|
+
}
|
|
29
|
+
var y = {
|
|
30
|
+
i8: 1,
|
|
31
|
+
u8: 1,
|
|
32
|
+
i16: 2,
|
|
33
|
+
u16: 2,
|
|
34
|
+
i32: 4,
|
|
35
|
+
u32: 4,
|
|
36
|
+
f32: 4,
|
|
37
|
+
f64: 8,
|
|
38
|
+
i64: 8,
|
|
39
|
+
u64: 8
|
|
40
|
+
}, b = (e) => typeof e == "string" ? y[e] : "string" in e ? e.string : 1, x = (e) => typeof e == "string" ? y[e] : 1;
|
|
41
|
+
function S(e) {
|
|
42
|
+
let t = {}, r = {}, i = 0;
|
|
43
|
+
for (let a of Object.keys(e)) {
|
|
44
|
+
let o = n(e[a], String(a));
|
|
45
|
+
r[a] = o, i = u(i, x(o)), t[a] = i, i += b(o);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
layout: r,
|
|
49
|
+
offsets: t,
|
|
50
|
+
recordSize: d(i)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var C = {
|
|
54
|
+
number: () => ({
|
|
55
|
+
kind: "number",
|
|
56
|
+
byteLength: 8
|
|
57
|
+
}),
|
|
58
|
+
boolean: () => ({
|
|
59
|
+
kind: "boolean",
|
|
60
|
+
byteLength: 8
|
|
61
|
+
}),
|
|
62
|
+
string: (e) => {
|
|
63
|
+
let { schema: t, maxBytes: n } = e;
|
|
64
|
+
if (n !== void 0) return {
|
|
65
|
+
kind: "string",
|
|
66
|
+
byteLength: 4 + n,
|
|
67
|
+
schema: t
|
|
68
|
+
};
|
|
69
|
+
let r = t ? a(t) : null;
|
|
70
|
+
if (r !== null) return {
|
|
71
|
+
kind: "string",
|
|
72
|
+
byteLength: 4 + r,
|
|
73
|
+
schema: t
|
|
74
|
+
};
|
|
75
|
+
throw TypeError("field.string: pass { maxBytes } or a schema carrying a byte budget — mz.string(n) / z.string().meta({ bytes: n })");
|
|
76
|
+
},
|
|
77
|
+
object: (e) => {
|
|
78
|
+
let { schema: t, maxBytes: n } = e;
|
|
79
|
+
if (n === void 0 && t) {
|
|
80
|
+
let e = i(t);
|
|
81
|
+
if (e) {
|
|
82
|
+
let { layout: n, offsets: r, recordSize: i } = S(e);
|
|
83
|
+
return {
|
|
84
|
+
kind: "object",
|
|
85
|
+
byteLength: 8 + i,
|
|
86
|
+
schema: t,
|
|
87
|
+
layout: n,
|
|
88
|
+
offsets: r,
|
|
89
|
+
recordSize: i
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
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");
|
|
93
|
+
}
|
|
94
|
+
if (n === void 0) throw TypeError("field.object: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
|
|
95
|
+
return {
|
|
96
|
+
kind: "object",
|
|
97
|
+
byteLength: 4 + n,
|
|
98
|
+
schema: t
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
array: (e) => {
|
|
102
|
+
let { schema: t, maxBytes: i } = e;
|
|
103
|
+
if (i === void 0 && t) {
|
|
104
|
+
let e = r(t);
|
|
105
|
+
if (e) {
|
|
106
|
+
if (e.capacity === null) throw TypeError("field.array: z.array() needs .max(n) or .length(n) — bounded arrays are fixed-width");
|
|
107
|
+
let r;
|
|
108
|
+
try {
|
|
109
|
+
r = n(e.element, "array element");
|
|
110
|
+
} catch (e) {
|
|
111
|
+
throw TypeError(`field.array: element isn't a fixed-width member — use field.list for arrays of records (${e.message})`);
|
|
112
|
+
}
|
|
113
|
+
let i = u(b(r), x(r));
|
|
114
|
+
return {
|
|
115
|
+
kind: "array",
|
|
116
|
+
byteLength: 8 + e.capacity * i,
|
|
117
|
+
schema: t,
|
|
118
|
+
element: r,
|
|
119
|
+
elementStride: i,
|
|
120
|
+
capacity: e.capacity
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
throw TypeError("field.array: schema can't derive a fixed byte width (not a bounded zod array) — pass { maxBytes } for codec-encoded storage");
|
|
124
|
+
}
|
|
125
|
+
if (i === void 0) throw TypeError("field.array: pass { schema } for a fixed-layout field or { maxBytes } for a codec-encoded field");
|
|
126
|
+
return {
|
|
127
|
+
kind: "array",
|
|
128
|
+
byteLength: 4 + i,
|
|
129
|
+
schema: t
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
int32Array: ({ length: e }) => ({
|
|
133
|
+
kind: "Int32",
|
|
134
|
+
byteLength: e * 4
|
|
135
|
+
}),
|
|
136
|
+
float64Array: ({ length: e }) => ({
|
|
137
|
+
kind: "Float64",
|
|
138
|
+
byteLength: e * 8
|
|
139
|
+
}),
|
|
140
|
+
bigInt64Array: ({ length: e }) => ({
|
|
141
|
+
kind: "BigInt64",
|
|
142
|
+
byteLength: e * 8
|
|
143
|
+
}),
|
|
144
|
+
uint8Array: ({ length: e }) => ({
|
|
145
|
+
kind: "Uint8",
|
|
146
|
+
byteLength: e
|
|
147
|
+
}),
|
|
148
|
+
list: ({ schema: e, count: t }) => {
|
|
149
|
+
let n = i(e);
|
|
150
|
+
if (!n) throw TypeError("field.list: schema must be an mz.object() of fixed-width members");
|
|
151
|
+
let { layout: r, offsets: a, recordSize: o } = S(n);
|
|
152
|
+
return {
|
|
153
|
+
kind: "list",
|
|
154
|
+
byteLength: o * t,
|
|
155
|
+
schema: e,
|
|
156
|
+
layout: r,
|
|
157
|
+
offsets: a,
|
|
158
|
+
recordSize: o,
|
|
159
|
+
count: t
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}, w = {
|
|
163
|
+
Int32: Int32Array,
|
|
164
|
+
Float64: Float64Array,
|
|
165
|
+
BigInt64: BigInt64Array,
|
|
166
|
+
Uint8: Uint8Array
|
|
19
167
|
};
|
|
168
|
+
v("number", (e, t, n) => {
|
|
169
|
+
let r = new Float64Array(t.buffer, n, 1);
|
|
170
|
+
return {
|
|
171
|
+
byteOffset: n,
|
|
172
|
+
byteLength: e.byteLength,
|
|
173
|
+
read: () => r[0],
|
|
174
|
+
write: (e) => {
|
|
175
|
+
r[0] = e;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}), v("boolean", (e, t, n) => {
|
|
179
|
+
let r = new Uint8Array(t.buffer, n, 1);
|
|
180
|
+
return {
|
|
181
|
+
byteOffset: n,
|
|
182
|
+
byteLength: e.byteLength,
|
|
183
|
+
read: () => r[0] === 1,
|
|
184
|
+
write: (e) => {
|
|
185
|
+
r[0] = +!!e;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
for (let e of Object.keys(w)) v(e, (t, n, r) => {
|
|
190
|
+
let i = w[e], a = new i(n.buffer, r, t.byteLength / i.BYTES_PER_ELEMENT);
|
|
191
|
+
return {
|
|
192
|
+
byteOffset: r,
|
|
193
|
+
byteLength: t.byteLength,
|
|
194
|
+
read: () => a,
|
|
195
|
+
write: (e) => a.set(e)
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
v("string", (e, t, n) => {
|
|
199
|
+
let r = new TextEncoder(), i = new TextDecoder(), a = e.byteLength - 4, o = new Uint32Array(t.buffer, n, 1), s = (e) => {
|
|
200
|
+
if (e.byteLength > a) throw Error(`Encoded value of ${e.byteLength} bytes exceeds field capacity of ${a} bytes at offset ${n}`);
|
|
201
|
+
o[0] = e.byteLength, new Uint8Array(t.buffer, n + 4, e.byteLength).set(e);
|
|
202
|
+
}, c = () => new Uint8Array(t.buffer, n + 4, o[0]).slice();
|
|
203
|
+
return {
|
|
204
|
+
byteOffset: n,
|
|
205
|
+
byteLength: e.byteLength,
|
|
206
|
+
read: () => i.decode(c()),
|
|
207
|
+
write: (t) => s(r.encode(e.schema ? e.schema.parse(t) : t))
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
function T(e) {
|
|
211
|
+
let t = new DataView(e.buffer), n = new Uint8Array(e.buffer), r = new TextEncoder(), i = new TextDecoder(), a = {
|
|
212
|
+
i8: {
|
|
213
|
+
get: (e) => t.getInt8(e),
|
|
214
|
+
set: (e, n) => t.setInt8(e, n)
|
|
215
|
+
},
|
|
216
|
+
u8: {
|
|
217
|
+
get: (e) => t.getUint8(e),
|
|
218
|
+
set: (e, n) => t.setUint8(e, n)
|
|
219
|
+
},
|
|
220
|
+
i16: {
|
|
221
|
+
get: (e) => t.getInt16(e),
|
|
222
|
+
set: (e, n) => t.setInt16(e, n)
|
|
223
|
+
},
|
|
224
|
+
u16: {
|
|
225
|
+
get: (e) => t.getUint16(e),
|
|
226
|
+
set: (e, n) => t.setUint16(e, n)
|
|
227
|
+
},
|
|
228
|
+
i32: {
|
|
229
|
+
get: (e) => t.getInt32(e),
|
|
230
|
+
set: (e, n) => t.setInt32(e, n)
|
|
231
|
+
},
|
|
232
|
+
u32: {
|
|
233
|
+
get: (e) => t.getUint32(e),
|
|
234
|
+
set: (e, n) => t.setUint32(e, n)
|
|
235
|
+
},
|
|
236
|
+
f32: {
|
|
237
|
+
get: (e) => t.getFloat32(e),
|
|
238
|
+
set: (e, n) => t.setFloat32(e, n)
|
|
239
|
+
},
|
|
240
|
+
f64: {
|
|
241
|
+
get: (e) => t.getFloat64(e),
|
|
242
|
+
set: (e, n) => t.setFloat64(e, n)
|
|
243
|
+
},
|
|
244
|
+
i64: {
|
|
245
|
+
get: (e) => t.getBigInt64(e),
|
|
246
|
+
set: (e, n) => t.setBigInt64(e, n)
|
|
247
|
+
},
|
|
248
|
+
u64: {
|
|
249
|
+
get: (e) => t.getBigUint64(e),
|
|
250
|
+
set: (e, n) => t.setBigUint64(e, n)
|
|
251
|
+
}
|
|
252
|
+
}, o = (e, t) => {
|
|
253
|
+
let r = n.indexOf(0, e), a = r === -1 || r - e >= t ? t : r - e;
|
|
254
|
+
return i.decode(n.slice(e, e + a));
|
|
255
|
+
}, s = /* @__PURE__ */ new Uint8Array(64), c = (e, t, i) => {
|
|
256
|
+
s.length < t && (s = new Uint8Array(t));
|
|
257
|
+
let { read: a, written: o } = r.encodeInto(i, s);
|
|
258
|
+
if (a < i.length || o > t) throw Error(`String exceeds inline field capacity of ${t} bytes`);
|
|
259
|
+
n.set(s.subarray(0, o), e), o < t && n.fill(0, e + o, e + t);
|
|
260
|
+
}, l = (e) => {
|
|
261
|
+
if (typeof e == "string") {
|
|
262
|
+
let t = a[e];
|
|
263
|
+
return {
|
|
264
|
+
get: (e) => t.get(e),
|
|
265
|
+
set: (e, n) => t.set(e, n)
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
return "bool" in e ? {
|
|
269
|
+
get: (e) => !!t.getUint8(e),
|
|
270
|
+
set: (e, n) => t.setUint8(e, +!!n)
|
|
271
|
+
} : {
|
|
272
|
+
get: (t) => o(t, e.string),
|
|
273
|
+
set: (t, n) => c(t, e.string, n)
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
return {
|
|
277
|
+
ops: l,
|
|
278
|
+
compile: (e, t) => {
|
|
279
|
+
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
|
|
280
|
+
for (let i of Object.keys(e)) {
|
|
281
|
+
let { get: a, set: o } = l(e[i]), s = t[i];
|
|
282
|
+
n.set(i, (e, t) => {
|
|
283
|
+
t[i] = a(e + s);
|
|
284
|
+
}), r.set(i, (e, t) => o(e + s, t[i]));
|
|
285
|
+
}
|
|
286
|
+
let i = [...n.values()], a = [...r.values()];
|
|
287
|
+
return {
|
|
288
|
+
read(e, t = {}, r) {
|
|
289
|
+
if (r) for (let i of r) n.get(i)(e, t);
|
|
290
|
+
else for (let n of i) n(e, t);
|
|
291
|
+
return t;
|
|
292
|
+
},
|
|
293
|
+
write(e, t, n) {
|
|
294
|
+
if (n) for (let i of n) r.get(i)(e, t);
|
|
295
|
+
else for (let n of a) n(e, t);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
var E = (e, t, n) => {
|
|
302
|
+
let { schema: r, byteLength: i, kind: a } = e, o = e;
|
|
303
|
+
if (o.layout && o.offsets && o.recordSize !== void 0) {
|
|
304
|
+
let e = new Uint32Array(t.buffer, n, 2), a = n + 8, s = T(t).compile(o.layout, o.offsets);
|
|
305
|
+
return {
|
|
306
|
+
byteOffset: n,
|
|
307
|
+
byteLength: i,
|
|
308
|
+
read: () => e[0] ? s.read(a, {}) : void 0,
|
|
309
|
+
write: (t) => {
|
|
310
|
+
s.write(a, r ? r.parse(t) : t), e[0] = 1;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
if (o.element !== void 0 && o.elementStride !== void 0 && o.capacity !== void 0) {
|
|
315
|
+
let e = new Uint32Array(t.buffer, n, 1), a = new Uint32Array(t.buffer, n + 4, 1), s = T(t).ops(o.element), c = o.elementStride, l = o.capacity, u = n + 8;
|
|
316
|
+
return {
|
|
317
|
+
byteOffset: n,
|
|
318
|
+
byteLength: i,
|
|
319
|
+
read: () => {
|
|
320
|
+
if (!e[0]) return;
|
|
321
|
+
let t = a[0];
|
|
322
|
+
return Array.from({ length: t }, (e, t) => s.get(u + t * c));
|
|
323
|
+
},
|
|
324
|
+
write: (t) => {
|
|
325
|
+
let n = r ? r.parse(t) : t;
|
|
326
|
+
if (n.length > l) throw Error(`${n.length} elements exceeds array capacity of ${l}`);
|
|
327
|
+
n.forEach((e, t) => s.set(u + t * c, e)), a[0] = n.length, e[0] = 1;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
let s = i - 4, c = new Uint32Array(t.buffer, n, 1), l = (e) => {
|
|
332
|
+
if (e.byteLength > s) throw Error(`Encoded value of ${e.byteLength} bytes exceeds field capacity of ${s} bytes at offset ${n}`);
|
|
333
|
+
c[0] = e.byteLength, new Uint8Array(t.buffer, n + 4, e.byteLength).set(e);
|
|
334
|
+
}, u = () => new Uint8Array(t.buffer, n + 4, c[0]).slice();
|
|
335
|
+
return {
|
|
336
|
+
byteOffset: n,
|
|
337
|
+
byteLength: i,
|
|
338
|
+
read: () => {
|
|
339
|
+
let e = u();
|
|
340
|
+
if (e.byteLength === 0) return;
|
|
341
|
+
let n = t.codec.decode(e);
|
|
342
|
+
return r ? r.parse(n) : n;
|
|
343
|
+
},
|
|
344
|
+
write: (e) => l(t.codec.encode(r ? r.parse(e) : e))
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
v("object", E), v("array", E);
|
|
348
|
+
function D(e, t, n) {
|
|
349
|
+
let r = e, { offsets: i, recordSize: a, count: o } = r, s = T(t).compile(r.layout, i), c = (e) => {
|
|
350
|
+
if (e < 0 || e >= o) throw RangeError(`Record index ${e} out of bounds (0..${o - 1})`);
|
|
351
|
+
}, l = (e, t = {}, r) => (c(e), s.read(n + e * a, t, r)), u = (e, t, r) => {
|
|
352
|
+
c(e), s.write(n + e * a, t, r);
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
byteOffset: n,
|
|
356
|
+
byteLength: e.byteLength,
|
|
357
|
+
recordCount: o,
|
|
358
|
+
recordSize: a,
|
|
359
|
+
readAt: l,
|
|
360
|
+
writeAt: u,
|
|
361
|
+
commit: () => {
|
|
362
|
+
t.version && (Atomics.add(t.version.view, t.version.index, 1), Atomics.notify(t.version.view, t.version.index));
|
|
363
|
+
},
|
|
364
|
+
read: () => Array.from({ length: o }, (e, t) => l(t)),
|
|
365
|
+
write: (e) => {
|
|
366
|
+
if (e.length > o) throw Error(`${e.length} records exceeds list array capacity of ${o}`);
|
|
367
|
+
e.forEach((e, t) => u(t, e));
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
v("list", D);
|
|
372
|
+
var O = [];
|
|
373
|
+
function k(e) {
|
|
374
|
+
let t = {};
|
|
375
|
+
for (let [n, r] of Object.entries(e)) t[n] = f(r) ? A(r) : Object.fromEntries(Object.entries(r).map(([e, t]) => [e, A(t)]));
|
|
376
|
+
return t;
|
|
377
|
+
}
|
|
378
|
+
function A(e) {
|
|
379
|
+
if (e.schema) return e.schema;
|
|
380
|
+
switch (e.kind) {
|
|
381
|
+
case "number": return t.number();
|
|
382
|
+
case "boolean": return t.boolean();
|
|
383
|
+
case "string": return t.string();
|
|
384
|
+
case "Int32": return t.instanceof(Int32Array);
|
|
385
|
+
case "Float64": return t.instanceof(Float64Array);
|
|
386
|
+
case "BigInt64": return t.instanceof(BigInt64Array);
|
|
387
|
+
case "Uint8": return t.instanceof(Uint8Array);
|
|
388
|
+
default: return t.unknown();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
var j = class {
|
|
392
|
+
totalBytes;
|
|
393
|
+
spec;
|
|
394
|
+
schemas;
|
|
395
|
+
codec;
|
|
396
|
+
plugins;
|
|
397
|
+
entries;
|
|
398
|
+
offsets = /* @__PURE__ */ new Map();
|
|
399
|
+
versionOffset;
|
|
400
|
+
connectors = /* @__PURE__ */ new Map();
|
|
401
|
+
boundListeners = /* @__PURE__ */ new Set();
|
|
402
|
+
isBound = !1;
|
|
403
|
+
boundBuffer;
|
|
404
|
+
constructor(t, n = {}) {
|
|
405
|
+
this.spec = t, this.codec = n.codec ?? e, this.plugins = n.plugins, this.entries = p(t), this.schemas = k(t);
|
|
406
|
+
let r = 0;
|
|
407
|
+
for (let { path: e, descriptor: t } of this.entries) r = d(r), this.offsets.set(e, r), r += t.byteLength;
|
|
408
|
+
this.versionOffset = d(r), this.totalBytes = this.versionOffset + d(this.entries.length * 4), O.push(this), c.info(`contract defined: ${this.entries.length} field(s), ${o(this.totalBytes)}`, {
|
|
409
|
+
fields: Object.fromEntries(this.entries.map((e) => [e.path, `${e.descriptor.kind}@${this.offsets.get(e.path)?.toLocaleString()}+${o(e.descriptor.byteLength)}`])),
|
|
410
|
+
pluginOverrides: Object.keys(this.plugins ?? {})
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
bind(e) {
|
|
414
|
+
this.connectors.clear();
|
|
415
|
+
let t = new Int32Array(e, this.versionOffset, this.entries.length);
|
|
416
|
+
this.entries.forEach(({ path: n, descriptor: r }, i) => {
|
|
417
|
+
let a = this.plugins?.[r.kind] ?? _.get(r.kind);
|
|
418
|
+
if (!a) throw Error(`Unknown shared memory field kind: ${r.kind}`);
|
|
419
|
+
c.debug(`bind "${n}" (${r.kind}, ${o(r.byteLength)}) via ${this.plugins?.[r.kind] ? "plugin" : "built-in"} factory`);
|
|
420
|
+
let s = a(r, {
|
|
421
|
+
buffer: e,
|
|
422
|
+
codec: this.codec,
|
|
423
|
+
version: {
|
|
424
|
+
view: t,
|
|
425
|
+
index: i
|
|
426
|
+
}
|
|
427
|
+
}, this.offsets.get(n));
|
|
428
|
+
this.connectors.set(n, {
|
|
429
|
+
...s,
|
|
430
|
+
write: (e) => {
|
|
431
|
+
s.write(e), Atomics.add(t, i, 1), Atomics.notify(t, i);
|
|
432
|
+
},
|
|
433
|
+
_version: {
|
|
434
|
+
view: t,
|
|
435
|
+
index: i
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}), this.isBound = !0, this.boundBuffer = e;
|
|
439
|
+
for (let e of [...this.boundListeners]) e();
|
|
440
|
+
}
|
|
441
|
+
get bound() {
|
|
442
|
+
return this.isBound;
|
|
443
|
+
}
|
|
444
|
+
get buffer() {
|
|
445
|
+
if (!this.boundBuffer) throw Error("Shared memory contract is not bound to a buffer on this thread.");
|
|
446
|
+
return this.boundBuffer;
|
|
447
|
+
}
|
|
448
|
+
fields() {
|
|
449
|
+
return this.entries.map(({ path: e, descriptor: t }) => ({
|
|
450
|
+
path: e,
|
|
451
|
+
byteOffset: this.offsets.get(e),
|
|
452
|
+
byteLength: t.byteLength
|
|
453
|
+
}));
|
|
454
|
+
}
|
|
455
|
+
onBound(e) {
|
|
456
|
+
return this.isBound ? (e(), () => {}) : (this.boundListeners.add(e), () => this.boundListeners.delete(e));
|
|
457
|
+
}
|
|
458
|
+
connector(e) {
|
|
459
|
+
let t = String(e), n = this.connectors.get(t);
|
|
460
|
+
if (!n) throw Error(`Shared memory field "${t}" was accessed before the buffer was bound on this thread.`);
|
|
461
|
+
return n;
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
function M(e, t = {}) {
|
|
465
|
+
let n = new j(e, t);
|
|
466
|
+
for (let [t, r] of Object.entries(e)) if (f(r)) Object.defineProperty(n, t, {
|
|
467
|
+
enumerable: !0,
|
|
468
|
+
get: () => n.connector(t)
|
|
469
|
+
});
|
|
470
|
+
else {
|
|
471
|
+
let e = {};
|
|
472
|
+
for (let i of Object.keys(r)) Object.defineProperty(e, i, {
|
|
473
|
+
enumerable: !0,
|
|
474
|
+
get: () => n.connector(`${t}.${i}`)
|
|
475
|
+
});
|
|
476
|
+
Object.defineProperty(n, t, {
|
|
477
|
+
enumerable: !0,
|
|
478
|
+
get: () => e
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
return n;
|
|
482
|
+
}
|
|
483
|
+
function N(e) {
|
|
484
|
+
for (let t of O) t.bind(e);
|
|
485
|
+
c.info(`bound ${O.length} contract(s) — ${o(e.byteLength)} buffer`);
|
|
486
|
+
}
|
|
487
|
+
function P() {
|
|
488
|
+
return O.length;
|
|
489
|
+
}
|
|
20
490
|
//#endregion
|
|
21
|
-
export {
|
|
491
|
+
export { j as SharedMemory, N as bindSharedMemories, M as defineSharedMemory, C as field, P as getDefinedSharedMemoryCount, g as jsonCodec, v as registerConnectorFactory };
|
|
22
492
|
|
|
23
493
|
//# sourceMappingURL=index6.js.map
|
package/dist/index7.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/contract/
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { z as e } from "./index3.js";
|
|
2
|
+
//#region src/contract/mz.ts
|
|
3
|
+
var t = {
|
|
4
|
+
i8: () => e.number().int().min(-128).max(127),
|
|
5
|
+
u8: () => e.number().int().min(0).max(255),
|
|
6
|
+
i16: () => e.number().int().min(-32768).max(32767),
|
|
7
|
+
u16: () => e.number().int().min(0).max(65535),
|
|
8
|
+
i32: () => e.int32(),
|
|
9
|
+
u32: () => e.uint32(),
|
|
10
|
+
f32: () => e.float32(),
|
|
11
|
+
f64: () => e.float64(),
|
|
12
|
+
i64: () => e.int64(),
|
|
13
|
+
u64: () => e.uint64(),
|
|
14
|
+
int: (t, n) => e.number().int().min(t).max(n),
|
|
15
|
+
boolean: () => e.boolean(),
|
|
16
|
+
string: (t) => e.string().refine((e) => new TextEncoder().encode(e).byteLength <= t, `exceeds ${t} UTF-8 bytes`).meta({ bytes: t }),
|
|
17
|
+
object: (t) => e.object(t),
|
|
18
|
+
array: (t) => e.array(t)
|
|
6
19
|
};
|
|
7
20
|
//#endregion
|
|
8
|
-
export {
|
|
21
|
+
export { t as mz };
|
|
9
22
|
|
|
10
23
|
//# sourceMappingURL=index7.js.map
|
package/dist/index8.js
CHANGED
|
@@ -1,37 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let t = e.initialPages ?? 16;
|
|
7
|
-
this.maxPages = e.maximumPages ?? 16384, this.memory = new WebAssembly.Memory({
|
|
8
|
-
initial: t,
|
|
9
|
-
maximum: this.maxPages,
|
|
10
|
-
shared: !0
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
ensureCapacity(e) {
|
|
14
|
-
let t = this.memory.buffer.byteLength;
|
|
15
|
-
if (t >= e) return;
|
|
16
|
-
let n = e - t, r = Math.ceil(n / 65536);
|
|
17
|
-
if (this.memory.buffer.byteLength / 65536 + r > this.maxPages) throw Error(`Cannot grow memory: exceeds maximum page limit of ${this.maxPages}`);
|
|
18
|
-
this.memory.grow(r);
|
|
19
|
-
}
|
|
20
|
-
getView(e, t = 0, n) {
|
|
21
|
-
let r = this.memory.buffer;
|
|
22
|
-
switch (e) {
|
|
23
|
-
case "Int32": return new Int32Array(r, t, n);
|
|
24
|
-
case "Float64": return new Float64Array(r, t, n);
|
|
25
|
-
case "BigInt64": return new BigInt64Array(r, t, n);
|
|
26
|
-
case "Uint8": return new Uint8Array(r, t, n);
|
|
27
|
-
default: throw Error(`Unsupported view type: ${e}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
getBuffer() {
|
|
31
|
-
return this.memory.buffer;
|
|
32
|
-
}
|
|
1
|
+
import { decode as e, encode as t } from "@msgpack/msgpack";
|
|
2
|
+
//#region src/contract/msgpackCodec.ts
|
|
3
|
+
var n = {
|
|
4
|
+
encode: t,
|
|
5
|
+
decode: e
|
|
33
6
|
};
|
|
34
7
|
//#endregion
|
|
35
|
-
export {
|
|
8
|
+
export { n as msgpackCodec };
|
|
36
9
|
|
|
37
10
|
//# sourceMappingURL=index8.js.map
|
package/dist/index9.js
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
//#region src/pool/
|
|
2
|
-
var e = class
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//#region src/pool/memory.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
memory;
|
|
4
|
+
maxPages;
|
|
5
|
+
constructor(e = {}) {
|
|
6
|
+
let t = e.initialPages ?? 16;
|
|
7
|
+
this.maxPages = e.maximumPages ?? 16384, this.memory = new WebAssembly.Memory({
|
|
8
|
+
initial: t,
|
|
9
|
+
maximum: this.maxPages,
|
|
10
|
+
shared: !0
|
|
11
|
+
});
|
|
5
12
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
ensureCapacity(e) {
|
|
14
|
+
let t = this.memory.buffer.byteLength;
|
|
15
|
+
if (t >= e) return;
|
|
16
|
+
let n = e - t, r = Math.ceil(n / 65536);
|
|
17
|
+
if (this.memory.buffer.byteLength / 65536 + r > this.maxPages) throw Error(`Cannot grow memory: exceeds maximum page limit of ${this.maxPages}`);
|
|
18
|
+
this.memory.grow(r);
|
|
9
19
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
getView(e, t = 0, n) {
|
|
21
|
+
let r = this.memory.buffer;
|
|
22
|
+
switch (e) {
|
|
23
|
+
case "Int32": return new Int32Array(r, t, n);
|
|
24
|
+
case "Float64": return new Float64Array(r, t, n);
|
|
25
|
+
case "BigInt64": return new BigInt64Array(r, t, n);
|
|
26
|
+
case "Uint8": return new Uint8Array(r, t, n);
|
|
27
|
+
default: throw Error(`Unsupported view type: ${e}`);
|
|
28
|
+
}
|
|
13
29
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
super(e), this.name = "WorkerCrashedError";
|
|
30
|
+
getBuffer() {
|
|
31
|
+
return this.memory.buffer;
|
|
17
32
|
}
|
|
18
33
|
};
|
|
19
34
|
//#endregion
|
|
20
|
-
export { e as
|
|
35
|
+
export { e as MemoryManager };
|
|
21
36
|
|
|
22
37
|
//# sourceMappingURL=index9.js.map
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scoped, leveled logging for the SDK. Default level is `info` — lifecycle
|
|
3
|
+
* events (pool spawn, memory bind, seed phases) are always visible; `debug`
|
|
4
|
+
* adds per-task dispatch/completion and `trace` adds per-message detail.
|
|
5
|
+
*
|
|
6
|
+
* import { setLogLevel } from '…/index';
|
|
7
|
+
* setLogLevel('debug'); // or 'trace', 'warn', 'off'
|
|
8
|
+
*/
|
|
9
|
+
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off';
|
|
10
|
+
export interface LogEntry {
|
|
11
|
+
level: LogLevel;
|
|
12
|
+
scope: string;
|
|
13
|
+
message: string;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
/** Which side of the boundary emitted this entry. */
|
|
16
|
+
thread: 'main' | 'worker';
|
|
17
|
+
/** performance.now() at emission — useful for sequencing across threads. */
|
|
18
|
+
at: number;
|
|
19
|
+
}
|
|
20
|
+
export type LogSink = (entry: LogEntry) => void;
|
|
21
|
+
export declare const setLogLevel: (level: LogLevel) => void;
|
|
22
|
+
export declare const getLogLevel: () => LogLevel;
|
|
23
|
+
/** Replace the console sink (e.g. collect entries for a UI panel); null restores it. */
|
|
24
|
+
export declare const setLogSink: (custom: LogSink | null) => void;
|
|
25
|
+
export declare function log(level: Exclude<LogLevel, 'off'>, scope: string, message: string, data?: unknown): void;
|
|
26
|
+
/** A logger bound to a subsystem scope: `poolLog.info('spawned')`. */
|
|
27
|
+
export declare function scoped(scope: string): {
|
|
28
|
+
trace: (message: string, data?: unknown) => void;
|
|
29
|
+
debug: (message: string, data?: unknown) => void;
|
|
30
|
+
info: (message: string, data?: unknown) => void;
|
|
31
|
+
warn: (message: string, data?: unknown) => void;
|
|
32
|
+
error: (message: string, data?: unknown) => void;
|
|
33
|
+
};
|
|
34
|
+
/** Compact byte formatting for log output. */
|
|
35
|
+
export declare const fmtBytes: (bytes: number) => string;
|