@atolljs/core 0.1.6 → 0.1.8
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 +6 -2
- package/dist/contract/types.d.ts +13 -0
- package/dist/devtools.d.ts +346 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +19 -16
- package/dist/index10.js +28 -184
- package/dist/index11.js +18 -48
- package/dist/index12.js +29 -63
- package/dist/index13.js +49 -24
- package/dist/index14.js +57 -59
- package/dist/index15.js +335 -45
- package/dist/index16.js +242 -47
- package/dist/index17.js +57 -38
- package/dist/index18.js +9 -86
- package/dist/index19.js +58 -48
- package/dist/index20.js +24 -56
- package/dist/index21.js +61 -0
- 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 +227 -35
- package/dist/index6.js +143 -471
- package/dist/index7.js +51 -20
- package/dist/index8.js +507 -27
- package/dist/index9.js +19 -18
- 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 +38 -8
- package/dist/pool/workerPool.d.ts +13 -0
- package/dist/reactive.d.ts +15 -0
- package/dist/reactiveGraph.d.ts +9 -0
- package/dist/userTiming.d.ts +27 -0
- package/package.json +2 -1
- package/src/contract/memoryDevtools.ts +249 -0
- package/src/contract/sharedMemory.ts +39 -9
- package/src/contract/types.ts +13 -0
- package/src/devtools.ts +735 -0
- package/src/index.ts +27 -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 +64 -15
- package/src/pool/workerPool.ts +115 -36
- 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 +29 -3
package/dist/index6.js
CHANGED
|
@@ -1,491 +1,163 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
descriptor: r
|
|
12
|
-
});
|
|
13
|
-
else for (let [e, i] of Object.entries(r)) {
|
|
14
|
-
if (!p(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
|
-
});
|
|
1
|
+
import { emitDevtools as e, previewValue as t, registerDevtoolsCommand as n } from "./index5.js";
|
|
2
|
+
//#region src/contract/memoryDevtools.ts
|
|
3
|
+
var r = /* @__PURE__ */ new Map(), i = () => [], a = !1, o = 5, s = 16, c = (e) => {
|
|
4
|
+
let n = e;
|
|
5
|
+
if (typeof n.readAt == "function" && typeof n.recordCount == "number") {
|
|
6
|
+
let e = Array.from({ length: Math.min(o, n.recordCount) }, (e, t) => n.readAt(t));
|
|
7
|
+
return t({
|
|
8
|
+
records: n.recordCount,
|
|
9
|
+
head: e
|
|
10
|
+
}, 1024);
|
|
19
11
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
decode: (e) => JSON.parse(g.decode(e))
|
|
25
|
-
}, v = /* @__PURE__ */ new Map();
|
|
26
|
-
function y(e, t) {
|
|
27
|
-
v.set(e, t);
|
|
28
|
-
}
|
|
29
|
-
var b = {
|
|
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
|
-
}, x = (e) => typeof e == "string" ? b[e] : "string" in e ? e.string : 1, S = (e) => typeof e == "string" ? b[e] : 1;
|
|
41
|
-
function C(e) {
|
|
42
|
-
let t = {}, n = {}, i = 0;
|
|
43
|
-
for (let a of Object.keys(e)) {
|
|
44
|
-
let o = r(e[a], String(a));
|
|
45
|
-
n[a] = o, i = d(i, S(o)), t[a] = i, i += x(o);
|
|
12
|
+
let r = e.read();
|
|
13
|
+
if (ArrayBuffer.isView(r) && !(r instanceof DataView)) {
|
|
14
|
+
let e = r, t = Array.from({ length: Math.min(s, e.length) }, (t, n) => typeof e[n] == "bigint" ? `${e[n]}n` : e[n]);
|
|
15
|
+
return `${r.constructor.name}(${e.length}) ${JSON.stringify(t)}${e.length > s ? "…" : ""}`;
|
|
46
16
|
}
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
17
|
+
return t(r, 1024);
|
|
18
|
+
}, l = (e, t) => e.connector(t), u = (e) => e._version ? Atomics.load(e._version.view, e._version.index) : 0, d = (e) => {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(e);
|
|
21
|
+
} catch {
|
|
22
|
+
return e;
|
|
23
|
+
}
|
|
24
|
+
}, f = (e) => typeof e == "number" ? e : typeof e == "bigint" ? Number(e) : null, p = (e) => {
|
|
25
|
+
let n = e.trim();
|
|
26
|
+
if (n === "change") return {
|
|
27
|
+
text: n,
|
|
28
|
+
test: () => !0
|
|
51
29
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 ? o(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 — reef.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 = a(t);
|
|
81
|
-
if (e) {
|
|
82
|
-
let { layout: n, offsets: r, recordSize: i } = C(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: n } = e;
|
|
103
|
-
if (n === void 0 && t) {
|
|
104
|
-
let e = i(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 n;
|
|
108
|
-
try {
|
|
109
|
-
n = r(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 = d(x(n), S(n));
|
|
114
|
-
return {
|
|
115
|
-
kind: "array",
|
|
116
|
-
byteLength: 8 + e.capacity * i,
|
|
117
|
-
schema: t,
|
|
118
|
-
element: n,
|
|
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 (n === 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 + n,
|
|
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 = a(e);
|
|
150
|
-
if (!n) throw TypeError("field.list: schema must be a reef.object() of fixed-width members");
|
|
151
|
-
let { layout: r, offsets: i, recordSize: o } = C(n);
|
|
30
|
+
let r = /^(>=|<=|==|!=|>|<)\s*(.+)$/.exec(n);
|
|
31
|
+
if (!r) throw Error(`memory.watch: bad rule '${e}' — use change, > n, < n, >= n, <= n, == v, != v`);
|
|
32
|
+
let [, i, a] = r;
|
|
33
|
+
if (i === "==" || i === "!=") {
|
|
34
|
+
let e = d(a), r = (n) => typeof n == "object" && n ? t(n) === t(e) : Object.is(n, e) || typeof n == "bigint" && Number(n) === e;
|
|
152
35
|
return {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
schema: e,
|
|
156
|
-
layout: r,
|
|
157
|
-
offsets: i,
|
|
158
|
-
recordSize: o,
|
|
159
|
-
count: t
|
|
36
|
+
text: n,
|
|
37
|
+
test: i === "==" ? r : (e) => !r(e)
|
|
160
38
|
};
|
|
161
39
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
}
|
|
40
|
+
let o = Number(a);
|
|
41
|
+
if (!Number.isFinite(o)) throw Error(`memory.watch: '${a}' is not a number`);
|
|
42
|
+
let s = {
|
|
43
|
+
">": (e) => e > o,
|
|
44
|
+
"<": (e) => e < o,
|
|
45
|
+
">=": (e) => e >= o,
|
|
46
|
+
"<=": (e) => e <= o
|
|
177
47
|
};
|
|
178
|
-
}), y("boolean", (e, t, n) => {
|
|
179
|
-
let r = new Uint8Array(t.buffer, n, 1);
|
|
180
48
|
return {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
r[0] = +!!e;
|
|
49
|
+
text: n,
|
|
50
|
+
test: (e) => {
|
|
51
|
+
let t = f(e);
|
|
52
|
+
return t !== null && s[i](t);
|
|
186
53
|
}
|
|
187
54
|
};
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
let
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
};
|
|
55
|
+
}, m = (t, n, r, i, a) => {
|
|
56
|
+
let o = r.seen.get(t);
|
|
57
|
+
if (o && o.version >= a) return;
|
|
58
|
+
let s = r.rule.text === "change", l = typeof i.readAt == "function", u, d;
|
|
59
|
+
try {
|
|
60
|
+
d = c(i), u = s || l ? void 0 : i.read();
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
r.seen.set(t, {
|
|
65
|
+
version: a,
|
|
66
|
+
preview: d
|
|
67
|
+
}), (s ? d !== o?.preview : !l && r.rule.test(u)) && (r.hits++, e({
|
|
68
|
+
type: "memory:watch-hit",
|
|
69
|
+
path: n,
|
|
70
|
+
version: a,
|
|
71
|
+
value: d,
|
|
72
|
+
rule: r.rule.text
|
|
73
|
+
}));
|
|
74
|
+
}, h = (e, t, n) => {
|
|
75
|
+
let i = r.get(t);
|
|
76
|
+
i && m(e, t, i, l(e, t), n);
|
|
77
|
+
}, g = (e, t) => {
|
|
78
|
+
let n = !1, r = () => {
|
|
79
|
+
for (let n of i()) {
|
|
80
|
+
if (!n.bound) continue;
|
|
81
|
+
let r;
|
|
82
|
+
try {
|
|
83
|
+
r = l(n, e);
|
|
84
|
+
} catch {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
m(n, e, t, r, u(r));
|
|
267
88
|
}
|
|
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
89
|
};
|
|
276
|
-
return {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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);
|
|
90
|
+
if (typeof Atomics.waitAsync == "function") return (async () => {
|
|
91
|
+
for (; !n;) {
|
|
92
|
+
let t = i().find((t) => {
|
|
93
|
+
try {
|
|
94
|
+
return t.bound && l(t, e)._version !== void 0;
|
|
95
|
+
} catch {
|
|
96
|
+
return !1;
|
|
296
97
|
}
|
|
297
|
-
};
|
|
98
|
+
}), a = t ? l(t, e)._version : void 0;
|
|
99
|
+
if (a) {
|
|
100
|
+
let e = Atomics.waitAsync(a.view, a.index, Atomics.load(a.view, a.index), 250);
|
|
101
|
+
e.async && await e.value;
|
|
102
|
+
} else await new Promise((e) => setTimeout(e, 250));
|
|
103
|
+
n || r();
|
|
298
104
|
}
|
|
105
|
+
})(), () => {
|
|
106
|
+
n = !0;
|
|
299
107
|
};
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
n.forEach((e, t) => s.set(u + t * c, e)), a[0] = n.length, e[0] = 1;
|
|
108
|
+
let a = setInterval(r, 50);
|
|
109
|
+
return a.unref?.(), () => {
|
|
110
|
+
n = !0, clearInterval(a);
|
|
111
|
+
};
|
|
112
|
+
}, _ = () => [...r.entries()].map(([e, t]) => ({
|
|
113
|
+
path: e,
|
|
114
|
+
rule: t.rule.text,
|
|
115
|
+
hits: t.hits
|
|
116
|
+
})), v = (e) => {
|
|
117
|
+
i = e, !a && (a = !0, n("memory.read", () => {
|
|
118
|
+
let e = [];
|
|
119
|
+
return i().forEach((t, n) => {
|
|
120
|
+
if (t.bound) for (let { path: r } of t.fields()) try {
|
|
121
|
+
let i = l(t, r);
|
|
122
|
+
e.push({
|
|
123
|
+
path: r,
|
|
124
|
+
value: c(i),
|
|
125
|
+
version: u(i),
|
|
126
|
+
contract: n
|
|
127
|
+
});
|
|
128
|
+
} catch (t) {
|
|
129
|
+
e.push({
|
|
130
|
+
path: r,
|
|
131
|
+
value: `[unreadable: ${t.message}]`,
|
|
132
|
+
version: -1,
|
|
133
|
+
contract: n
|
|
134
|
+
});
|
|
328
135
|
}
|
|
136
|
+
}), e;
|
|
137
|
+
}), n("memory.watch", (e) => {
|
|
138
|
+
let t = String(e.path ?? "");
|
|
139
|
+
if (!t) throw Error("memory.watch: `path` is required");
|
|
140
|
+
if (!i().some((e) => e.fields().some((e) => e.path === t))) throw Error(`memory.watch: no contract defines a field '${t}'`);
|
|
141
|
+
let n = p(String(e.rule ?? "change"));
|
|
142
|
+
r.get(t)?.stop();
|
|
143
|
+
let a = {
|
|
144
|
+
rule: n,
|
|
145
|
+
seen: /* @__PURE__ */ new WeakMap(),
|
|
146
|
+
stop: () => {},
|
|
147
|
+
hits: 0
|
|
329
148
|
};
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
y("object", D), y("array", D);
|
|
348
|
-
function O(e, t, n) {
|
|
349
|
-
let r = e, { offsets: i, recordSize: a, count: o } = r, s = E(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
|
-
y("list", O);
|
|
372
|
-
var k = [];
|
|
373
|
-
function A(e) {
|
|
374
|
-
let t = {};
|
|
375
|
-
for (let [n, r] of Object.entries(e)) t[n] = p(r) ? j(r) : Object.fromEntries(Object.entries(r).map(([e, t]) => [e, j(t)]));
|
|
376
|
-
return t;
|
|
377
|
-
}
|
|
378
|
-
function j(e) {
|
|
379
|
-
if (e.schema) return e.schema;
|
|
380
|
-
switch (e.kind) {
|
|
381
|
-
case "number": return t(n.number());
|
|
382
|
-
case "boolean": return t(n.boolean());
|
|
383
|
-
case "string": return t(n.string());
|
|
384
|
-
case "Int32": return t(n.instanceof(Int32Array));
|
|
385
|
-
case "Float64": return t(n.instanceof(Float64Array));
|
|
386
|
-
case "BigInt64": return t(n.instanceof(BigInt64Array));
|
|
387
|
-
case "Uint8": return t(n.instanceof(Uint8Array));
|
|
388
|
-
default: return t(n.unknown());
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
var M = 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 = m(t), this.schemas = A(t);
|
|
406
|
-
let r = 0;
|
|
407
|
-
for (let { path: e, descriptor: t } of this.entries) r = f(r), this.offsets.set(e, r), r += t.byteLength;
|
|
408
|
-
this.versionOffset = f(r), this.totalBytes = this.versionOffset + f(this.entries.length * 4), k.push(this), l.info(`contract defined: ${this.entries.length} field(s), ${s(this.totalBytes)}`, {
|
|
409
|
-
fields: Object.fromEntries(this.entries.map((e) => [e.path, `${e.descriptor.kind}@${this.offsets.get(e.path)?.toLocaleString()}+${s(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] ?? v.get(r.kind);
|
|
418
|
-
if (!a) throw Error(`Unknown shared memory field kind: ${r.kind}`);
|
|
419
|
-
l.debug(`bind "${n}" (${r.kind}, ${s(r.byteLength)}) via ${this.plugins?.[r.kind] ? "plugin" : "built-in"} factory`);
|
|
420
|
-
let o = 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
|
-
...o,
|
|
430
|
-
write: (e) => {
|
|
431
|
-
o.write(e), Atomics.add(t, i, 1), Atomics.notify(t, i);
|
|
432
|
-
},
|
|
433
|
-
_version: {
|
|
434
|
-
view: t,
|
|
435
|
-
index: i
|
|
436
|
-
}
|
|
149
|
+
for (let e of i()) if (e.bound) try {
|
|
150
|
+
let n = l(e, t);
|
|
151
|
+
a.seen.set(e, {
|
|
152
|
+
version: u(n),
|
|
153
|
+
preview: c(n)
|
|
437
154
|
});
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
return
|
|
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
|
-
}
|
|
155
|
+
} catch {}
|
|
156
|
+
return r.set(t, a), a.stop = g(t, a), _();
|
|
157
|
+
}), n("memory.unwatch", (e) => {
|
|
158
|
+
let t = String(e.path ?? "");
|
|
159
|
+
return r.get(t)?.stop(), r.delete(t), _();
|
|
160
|
+
}), n("memory.watches", () => _()));
|
|
463
161
|
};
|
|
464
|
-
function N(e, t = {}) {
|
|
465
|
-
let n = new M(e, t);
|
|
466
|
-
for (let [t, r] of Object.entries(e)) if (p(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 P(e) {
|
|
484
|
-
for (let t of k) t.bind(e);
|
|
485
|
-
l.info(`bound ${k.length} contract(s) — ${s(e.byteLength)} buffer`);
|
|
486
|
-
}
|
|
487
|
-
function F() {
|
|
488
|
-
return k.length;
|
|
489
|
-
}
|
|
490
162
|
//#endregion
|
|
491
|
-
export {
|
|
163
|
+
export { h as checkWatchOnWrite, v as ensureMemoryCommands, c as fieldPreview, r as memoryWatches, p as parseWatchRule };
|