@bradensbay/globals-core 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/src/allocator.d.ts +78 -0
- package/dist/src/allocator.d.ts.map +1 -0
- package/dist/src/allocator.js +211 -0
- package/dist/src/allocator.js.map +1 -0
- package/dist/src/arena.d.ts +81 -0
- package/dist/src/arena.d.ts.map +1 -0
- package/dist/src/arena.js +224 -0
- package/dist/src/arena.js.map +1 -0
- package/dist/src/checksum.d.ts +5 -0
- package/dist/src/checksum.d.ts.map +1 -0
- package/dist/src/checksum.js +35 -0
- package/dist/src/checksum.js.map +1 -0
- package/dist/src/draft.d.ts +48 -0
- package/dist/src/draft.d.ts.map +1 -0
- package/dist/src/draft.js +427 -0
- package/dist/src/draft.js.map +1 -0
- package/dist/src/errors.d.ts +56 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +69 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/external.d.ts +52 -0
- package/dist/src/external.d.ts.map +1 -0
- package/dist/src/external.js +68 -0
- package/dist/src/external.js.map +1 -0
- package/dist/src/hamt.d.ts +87 -0
- package/dist/src/hamt.d.ts.map +1 -0
- package/dist/src/hamt.js +643 -0
- package/dist/src/hamt.js.map +1 -0
- package/dist/src/history.d.ts +45 -0
- package/dist/src/history.d.ts.map +1 -0
- package/dist/src/history.js +49 -0
- package/dist/src/history.js.map +1 -0
- package/dist/src/index.d.ts +55 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +38 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/inspect.d.ts +74 -0
- package/dist/src/inspect.d.ts.map +1 -0
- package/dist/src/inspect.js +127 -0
- package/dist/src/inspect.js.map +1 -0
- package/dist/src/layout.d.ts +130 -0
- package/dist/src/layout.d.ts.map +1 -0
- package/dist/src/layout.js +149 -0
- package/dist/src/layout.js.map +1 -0
- package/dist/src/liveness.d.ts +48 -0
- package/dist/src/liveness.d.ts.map +1 -0
- package/dist/src/liveness.js +92 -0
- package/dist/src/liveness.js.map +1 -0
- package/dist/src/owner.d.ts +130 -0
- package/dist/src/owner.d.ts.map +1 -0
- package/dist/src/owner.js +368 -0
- package/dist/src/owner.js.map +1 -0
- package/dist/src/reader.d.ts +122 -0
- package/dist/src/reader.d.ts.map +1 -0
- package/dist/src/reader.js +325 -0
- package/dist/src/reader.js.map +1 -0
- package/dist/src/readers.d.ts +60 -0
- package/dist/src/readers.d.ts.map +1 -0
- package/dist/src/readers.js +122 -0
- package/dist/src/readers.js.map +1 -0
- package/dist/src/retained.d.ts +39 -0
- package/dist/src/retained.d.ts.map +1 -0
- package/dist/src/retained.js +99 -0
- package/dist/src/retained.js.map +1 -0
- package/dist/src/schema.d.ts +82 -0
- package/dist/src/schema.d.ts.map +1 -0
- package/dist/src/schema.js +18 -0
- package/dist/src/schema.js.map +1 -0
- package/dist/src/store.d.ts +83 -0
- package/dist/src/store.d.ts.map +1 -0
- package/dist/src/store.js +127 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/strings.d.ts +37 -0
- package/dist/src/strings.d.ts.map +1 -0
- package/dist/src/strings.js +144 -0
- package/dist/src/strings.js.map +1 -0
- package/dist/src/tags.d.ts +47 -0
- package/dist/src/tags.d.ts.map +1 -0
- package/dist/src/tags.js +53 -0
- package/dist/src/tags.js.map +1 -0
- package/dist/src/values.d.ts +90 -0
- package/dist/src/values.d.ts.map +1 -0
- package/dist/src/values.js +458 -0
- package/dist/src/values.js.map +1 -0
- package/dist/src/vector.d.ts +64 -0
- package/dist/src/vector.d.ts.map +1 -0
- package/dist/src/vector.js +387 -0
- package/dist/src/vector.js.map +1 -0
- package/dist/src/verify.d.ts +38 -0
- package/dist/src/verify.d.ts.map +1 -0
- package/dist/src/verify.js +179 -0
- package/dist/src/verify.js.map +1 -0
- package/dist/src/view.d.ts +66 -0
- package/dist/src/view.d.ts.map +1 -0
- package/dist/src/view.js +278 -0
- package/dist/src/view.js.map +1 -0
- package/package.json +28 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { Tag } from "./tags.js";
|
|
2
|
+
import { UnencodableValueError } from "./errors.js";
|
|
3
|
+
import { EMPTY_NODE, emptyNode, hamtAssoc, hamtDissoc, hamtGet, hamtKeyStrings, keyHash, } from "./hamt.js";
|
|
4
|
+
import { emptyVector, vectorAssoc, vectorFromSlots, vectorGet, vectorLength, vectorNodes, } from "./vector.js";
|
|
5
|
+
import { collectBlocks, decodeValue, encodeString, encodeValue, } from "./values.js";
|
|
6
|
+
/**
|
|
7
|
+
* A draft, in the style of immer.
|
|
8
|
+
*
|
|
9
|
+
* You mutate it and nothing published moves. On finalisation only the paths you touched are
|
|
10
|
+
* rebuilt: a HAMT assoc copies at most seven nodes, a vector assoc copies one path, and every
|
|
11
|
+
* subtree you did not touch keeps its existing arena offset. That is what makes retaining
|
|
12
|
+
* several versions affordable, and it is the phase 2 exit criterion.
|
|
13
|
+
*
|
|
14
|
+
* What a draft deliberately does not do is alias. Assigning a value you read out of the store
|
|
15
|
+
* into a second position encodes a copy rather than sharing nodes, because sharing would need
|
|
16
|
+
* reference counting to reclaim correctly and every write would pay for a case almost no
|
|
17
|
+
* application has.
|
|
18
|
+
*/
|
|
19
|
+
const DELETED = Symbol("globals.deleted");
|
|
20
|
+
const STATE = Symbol("globals.draftState");
|
|
21
|
+
function isContainer(slot) {
|
|
22
|
+
return slot.tag === Tag.Object || slot.tag === Tag.Array;
|
|
23
|
+
}
|
|
24
|
+
export function createDraft(context, base) {
|
|
25
|
+
const state = {
|
|
26
|
+
base,
|
|
27
|
+
modifications: new Map(),
|
|
28
|
+
children: new Map(),
|
|
29
|
+
dirty: false,
|
|
30
|
+
length: undefined,
|
|
31
|
+
};
|
|
32
|
+
const proxy = base.tag === Tag.Array ? createArrayProxy(context, state) : createObjectProxy(context, state);
|
|
33
|
+
return { state, proxy };
|
|
34
|
+
}
|
|
35
|
+
export function draftStateOf(value) {
|
|
36
|
+
if (value === null || typeof value !== "object")
|
|
37
|
+
return undefined;
|
|
38
|
+
const state = value[STATE];
|
|
39
|
+
return state === undefined ? undefined : state;
|
|
40
|
+
}
|
|
41
|
+
function isDirty(state) {
|
|
42
|
+
if (state.dirty)
|
|
43
|
+
return true;
|
|
44
|
+
for (const child of state.children.values()) {
|
|
45
|
+
if (isDirty(child.state))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Reading through a draft
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
function childSlot(context, state, key) {
|
|
54
|
+
if (state.base.tag === Tag.Array) {
|
|
55
|
+
return vectorGet(context.arena, state.base.payload, Number(key));
|
|
56
|
+
}
|
|
57
|
+
if (state.base.tag !== Tag.Object)
|
|
58
|
+
return undefined;
|
|
59
|
+
const keySlot = encodeString(context, String(key));
|
|
60
|
+
return hamtGet(context.arena, state.base.payload, keySlot, keyHash(context.arena, keySlot));
|
|
61
|
+
}
|
|
62
|
+
function readThrough(context, state, key) {
|
|
63
|
+
if (state.modifications.has(key)) {
|
|
64
|
+
const value = state.modifications.get(key);
|
|
65
|
+
return value === DELETED ? undefined : value;
|
|
66
|
+
}
|
|
67
|
+
const existing = state.children.get(key);
|
|
68
|
+
if (existing !== undefined)
|
|
69
|
+
return existing.proxy;
|
|
70
|
+
const slot = childSlot(context, state, key);
|
|
71
|
+
if (slot === undefined)
|
|
72
|
+
return undefined;
|
|
73
|
+
if (isContainer(slot)) {
|
|
74
|
+
// Creating a child draft does not mark anything dirty, so merely reading a nested object
|
|
75
|
+
// costs nothing at commit time.
|
|
76
|
+
const child = createDraft(context, slot);
|
|
77
|
+
state.children.set(key, child);
|
|
78
|
+
return child.proxy;
|
|
79
|
+
}
|
|
80
|
+
return decodeValue(context.arena, slot);
|
|
81
|
+
}
|
|
82
|
+
function draftKeys(context, state) {
|
|
83
|
+
const base = state.base.tag === Tag.Object && state.base.payload !== EMPTY_NODE
|
|
84
|
+
? hamtKeyStrings(context.arena, state.base.payload)
|
|
85
|
+
: [];
|
|
86
|
+
const keys = base.filter((key) => state.modifications.get(key) !== DELETED);
|
|
87
|
+
for (const [key, value] of state.modifications) {
|
|
88
|
+
if (value === DELETED)
|
|
89
|
+
continue;
|
|
90
|
+
const name = String(key);
|
|
91
|
+
if (!keys.includes(name))
|
|
92
|
+
keys.push(name);
|
|
93
|
+
}
|
|
94
|
+
return keys;
|
|
95
|
+
}
|
|
96
|
+
function toIndex(property) {
|
|
97
|
+
return /^\d+$/.test(property) ? Number(property) : undefined;
|
|
98
|
+
}
|
|
99
|
+
function draftLength(context, state) {
|
|
100
|
+
if (state.length !== undefined)
|
|
101
|
+
return state.length;
|
|
102
|
+
return vectorLength(context.arena, state.base.payload);
|
|
103
|
+
}
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Proxies
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
function createObjectProxy(context, state) {
|
|
108
|
+
return new Proxy({}, {
|
|
109
|
+
get(_target, property) {
|
|
110
|
+
if (property === STATE)
|
|
111
|
+
return state;
|
|
112
|
+
if (typeof property === "symbol")
|
|
113
|
+
return undefined;
|
|
114
|
+
return readThrough(context, state, property);
|
|
115
|
+
},
|
|
116
|
+
set(_target, property, value) {
|
|
117
|
+
if (typeof property === "symbol") {
|
|
118
|
+
throw new UnencodableValueError(value, "symbol keys have no cross process identity");
|
|
119
|
+
}
|
|
120
|
+
state.modifications.set(property, value);
|
|
121
|
+
state.children.delete(property);
|
|
122
|
+
state.dirty = true;
|
|
123
|
+
return true;
|
|
124
|
+
},
|
|
125
|
+
deleteProperty(_target, property) {
|
|
126
|
+
if (typeof property === "symbol")
|
|
127
|
+
return true;
|
|
128
|
+
state.modifications.set(property, DELETED);
|
|
129
|
+
state.children.delete(property);
|
|
130
|
+
state.dirty = true;
|
|
131
|
+
return true;
|
|
132
|
+
},
|
|
133
|
+
has(_target, property) {
|
|
134
|
+
if (typeof property === "symbol")
|
|
135
|
+
return false;
|
|
136
|
+
if (state.modifications.has(property))
|
|
137
|
+
return state.modifications.get(property) !== DELETED;
|
|
138
|
+
return childSlot(context, state, property) !== undefined;
|
|
139
|
+
},
|
|
140
|
+
ownKeys() {
|
|
141
|
+
return draftKeys(context, state);
|
|
142
|
+
},
|
|
143
|
+
getOwnPropertyDescriptor(_target, property) {
|
|
144
|
+
if (typeof property === "symbol")
|
|
145
|
+
return undefined;
|
|
146
|
+
if (!draftKeys(context, state).includes(property))
|
|
147
|
+
return undefined;
|
|
148
|
+
return {
|
|
149
|
+
configurable: true,
|
|
150
|
+
enumerable: true,
|
|
151
|
+
writable: true,
|
|
152
|
+
value: readThrough(context, state, property),
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Array operations that cannot be expressed as a path copy.
|
|
159
|
+
*
|
|
160
|
+
* They materialise the array, apply the operation, and rebuild. That is linear in the array
|
|
161
|
+
* length rather than logarithmic, which the documentation states rather than hides. Index
|
|
162
|
+
* assignment, push, and pop stay on the fast path.
|
|
163
|
+
*/
|
|
164
|
+
const REBUILD_METHODS = new Set(["splice", "unshift", "shift", "sort", "reverse", "fill", "copyWithin"]);
|
|
165
|
+
function createArrayProxy(context, state) {
|
|
166
|
+
return new Proxy([], {
|
|
167
|
+
get(_target, property) {
|
|
168
|
+
if (property === STATE)
|
|
169
|
+
return state;
|
|
170
|
+
if (property === "length")
|
|
171
|
+
return draftLength(context, state);
|
|
172
|
+
if (typeof property === "symbol") {
|
|
173
|
+
if (property !== Symbol.iterator)
|
|
174
|
+
return undefined;
|
|
175
|
+
return function* iterate() {
|
|
176
|
+
const length = draftLength(context, state);
|
|
177
|
+
for (let i = 0; i < length; i += 1)
|
|
178
|
+
yield readThrough(context, state, i);
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const index = toIndex(property);
|
|
182
|
+
if (index !== undefined)
|
|
183
|
+
return readThrough(context, state, index);
|
|
184
|
+
if (property === "push") {
|
|
185
|
+
return (...values) => {
|
|
186
|
+
let length = draftLength(context, state);
|
|
187
|
+
for (const value of values) {
|
|
188
|
+
state.modifications.set(length, value);
|
|
189
|
+
length += 1;
|
|
190
|
+
}
|
|
191
|
+
state.length = length;
|
|
192
|
+
state.dirty = true;
|
|
193
|
+
return length;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (property === "pop") {
|
|
197
|
+
return () => {
|
|
198
|
+
const length = draftLength(context, state);
|
|
199
|
+
if (length === 0)
|
|
200
|
+
return undefined;
|
|
201
|
+
const value = toPlain(context, readThrough(context, state, length - 1));
|
|
202
|
+
state.modifications.delete(length - 1);
|
|
203
|
+
state.children.delete(length - 1);
|
|
204
|
+
state.length = length - 1;
|
|
205
|
+
state.dirty = true;
|
|
206
|
+
return value;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
if (REBUILD_METHODS.has(property)) {
|
|
210
|
+
return (...args) => {
|
|
211
|
+
const materialised = materialise(context, state);
|
|
212
|
+
const method = Array.prototype[property];
|
|
213
|
+
const result = method.apply(materialised, args);
|
|
214
|
+
state.modifications.clear();
|
|
215
|
+
state.children.clear();
|
|
216
|
+
materialised.forEach((value, index) => state.modifications.set(index, value));
|
|
217
|
+
state.length = materialised.length;
|
|
218
|
+
state.dirty = true;
|
|
219
|
+
return result;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
// Everything else is a read only Array.prototype method. Materialising is honest: the
|
|
223
|
+
// alternative is a partial reimplementation of the array protocol that differs from it
|
|
224
|
+
// in ways nobody documents.
|
|
225
|
+
const materialised = materialise(context, state);
|
|
226
|
+
const value = materialised[property];
|
|
227
|
+
return typeof value === "function" ? value.bind(materialised) : value;
|
|
228
|
+
},
|
|
229
|
+
set(_target, property, value) {
|
|
230
|
+
if (property === "length") {
|
|
231
|
+
state.length = Number(value);
|
|
232
|
+
state.dirty = true;
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
if (typeof property === "symbol")
|
|
236
|
+
return true;
|
|
237
|
+
const index = toIndex(property);
|
|
238
|
+
if (index === undefined)
|
|
239
|
+
return true;
|
|
240
|
+
state.modifications.set(index, value);
|
|
241
|
+
state.children.delete(index);
|
|
242
|
+
if (index >= draftLength(context, state))
|
|
243
|
+
state.length = index + 1;
|
|
244
|
+
state.dirty = true;
|
|
245
|
+
return true;
|
|
246
|
+
},
|
|
247
|
+
has(_target, property) {
|
|
248
|
+
if (property === "length")
|
|
249
|
+
return true;
|
|
250
|
+
if (typeof property === "symbol")
|
|
251
|
+
return false;
|
|
252
|
+
const index = toIndex(property);
|
|
253
|
+
return index !== undefined && index < draftLength(context, state);
|
|
254
|
+
},
|
|
255
|
+
ownKeys() {
|
|
256
|
+
const length = draftLength(context, state);
|
|
257
|
+
return [...Array.from({ length }, (_unused, index) => String(index)), "length"];
|
|
258
|
+
},
|
|
259
|
+
getOwnPropertyDescriptor(_target, property) {
|
|
260
|
+
if (property === "length") {
|
|
261
|
+
return {
|
|
262
|
+
configurable: false,
|
|
263
|
+
enumerable: false,
|
|
264
|
+
writable: true,
|
|
265
|
+
value: draftLength(context, state),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (typeof property === "symbol")
|
|
269
|
+
return undefined;
|
|
270
|
+
const index = toIndex(property);
|
|
271
|
+
if (index === undefined || index >= draftLength(context, state))
|
|
272
|
+
return undefined;
|
|
273
|
+
return {
|
|
274
|
+
configurable: true,
|
|
275
|
+
enumerable: true,
|
|
276
|
+
writable: true,
|
|
277
|
+
value: readThrough(context, state, index),
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
// Materialising
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
/**
|
|
286
|
+
* Turn a draft, or anything containing one, into a plain JavaScript value.
|
|
287
|
+
*
|
|
288
|
+
* This runs entirely on the JavaScript heap. Finalising the draft into the arena first and
|
|
289
|
+
* decoding the result would be simpler to write and would leak: the intermediate nodes would
|
|
290
|
+
* be allocated, never referenced by a published root, and never retired.
|
|
291
|
+
*/
|
|
292
|
+
function toPlain(context, value) {
|
|
293
|
+
const state = draftStateOf(value);
|
|
294
|
+
if (state !== undefined)
|
|
295
|
+
return materialiseState(context, state);
|
|
296
|
+
return value;
|
|
297
|
+
}
|
|
298
|
+
function materialise(context, state) {
|
|
299
|
+
const length = draftLength(context, state);
|
|
300
|
+
const out = [];
|
|
301
|
+
for (let i = 0; i < length; i += 1)
|
|
302
|
+
out.push(toPlain(context, readThrough(context, state, i)));
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
function materialiseState(context, state) {
|
|
306
|
+
if (state.base.tag === Tag.Array)
|
|
307
|
+
return materialise(context, state);
|
|
308
|
+
const out = {};
|
|
309
|
+
for (const key of draftKeys(context, state)) {
|
|
310
|
+
out[key] = toPlain(context, readThrough(context, state, key));
|
|
311
|
+
}
|
|
312
|
+
return out;
|
|
313
|
+
}
|
|
314
|
+
// ---------------------------------------------------------------------------
|
|
315
|
+
// Finalising
|
|
316
|
+
// ---------------------------------------------------------------------------
|
|
317
|
+
/**
|
|
318
|
+
* Turn a draft back into a slot.
|
|
319
|
+
*
|
|
320
|
+
* A clean draft returns its base slot unchanged, which is how untouched subtrees keep their
|
|
321
|
+
* arena nodes. A dirty one applies its modifications through assoc, so only the copied path
|
|
322
|
+
* is new and every replaced node lands on the retire list.
|
|
323
|
+
*/
|
|
324
|
+
export function finalizeState(context, state) {
|
|
325
|
+
if (!isDirty(state))
|
|
326
|
+
return state.base;
|
|
327
|
+
return state.base.tag === Tag.Array
|
|
328
|
+
? finalizeArray(context, state)
|
|
329
|
+
: finalizeObject(context, state);
|
|
330
|
+
}
|
|
331
|
+
function retireSubtree(context, slot) {
|
|
332
|
+
for (const block of collectBlocks(context.arena, slot))
|
|
333
|
+
context.retired.push(block);
|
|
334
|
+
}
|
|
335
|
+
function finalizeObject(context, state) {
|
|
336
|
+
let node = state.base.tag === Tag.Object ? state.base.payload : emptyNode(context);
|
|
337
|
+
// Nested drafts first. Each one retires its own replaced nodes, so the old child slot needs
|
|
338
|
+
// no separate retirement here.
|
|
339
|
+
for (const [key, child] of state.children) {
|
|
340
|
+
if (state.modifications.has(key) || !isDirty(child.state))
|
|
341
|
+
continue;
|
|
342
|
+
const keySlot = encodeString(context, String(key));
|
|
343
|
+
node = hamtAssoc(context, node, keySlot, keyHash(context.arena, keySlot), finalizeState(context, child.state));
|
|
344
|
+
}
|
|
345
|
+
for (const [key, value] of state.modifications) {
|
|
346
|
+
const keySlot = encodeString(context, String(key));
|
|
347
|
+
const hash = keyHash(context.arena, keySlot);
|
|
348
|
+
const previous = hamtGet(context.arena, node, keySlot, hash);
|
|
349
|
+
node =
|
|
350
|
+
value === DELETED
|
|
351
|
+
? hamtDissoc(context, node, keySlot, hash)
|
|
352
|
+
: hamtAssoc(context, node, keySlot, hash, encodeValue(context, toPlain(context, value)));
|
|
353
|
+
// The old value is unreachable from the new version, because drafts never alias.
|
|
354
|
+
if (previous !== undefined)
|
|
355
|
+
retireSubtree(context, previous);
|
|
356
|
+
}
|
|
357
|
+
return { tag: Tag.Object, payload: node };
|
|
358
|
+
}
|
|
359
|
+
function finalizeArray(context, state) {
|
|
360
|
+
const baseLength = vectorLength(context.arena, state.base.payload);
|
|
361
|
+
const targetLength = draftLength(context, state);
|
|
362
|
+
const indexWritesOnly = targetLength === baseLength &&
|
|
363
|
+
[...state.modifications.entries()].every(([key, value]) => typeof key === "number" && key < baseLength && value !== DELETED);
|
|
364
|
+
// In place index updates are the case worth optimising, because that is what a table of
|
|
365
|
+
// rows does on every edit. Anything that changes the length rebuilds.
|
|
366
|
+
if (indexWritesOnly) {
|
|
367
|
+
let vector = state.base.payload;
|
|
368
|
+
for (const [key, child] of state.children) {
|
|
369
|
+
if (state.modifications.has(key) || !isDirty(child.state))
|
|
370
|
+
continue;
|
|
371
|
+
vector = vectorAssoc(context, vector, Number(key), finalizeState(context, child.state));
|
|
372
|
+
}
|
|
373
|
+
for (const [key, value] of state.modifications) {
|
|
374
|
+
const index = Number(key);
|
|
375
|
+
const previous = vectorGet(context.arena, vector, index);
|
|
376
|
+
vector = vectorAssoc(context, vector, index, encodeValue(context, toPlain(context, value)));
|
|
377
|
+
if (previous !== undefined)
|
|
378
|
+
retireSubtree(context, previous);
|
|
379
|
+
}
|
|
380
|
+
return { tag: Tag.Array, payload: vector };
|
|
381
|
+
}
|
|
382
|
+
const slots = [];
|
|
383
|
+
const carried = new Set();
|
|
384
|
+
for (let index = 0; index < targetLength; index += 1) {
|
|
385
|
+
if (state.modifications.has(index)) {
|
|
386
|
+
const value = state.modifications.get(index);
|
|
387
|
+
slots.push(value === DELETED
|
|
388
|
+
? { tag: Tag.Undefined, payload: 0 }
|
|
389
|
+
: encodeValue(context, toPlain(context, value)));
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
const child = state.children.get(index);
|
|
393
|
+
if (child !== undefined && isDirty(child.state)) {
|
|
394
|
+
slots.push(finalizeState(context, child.state));
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const existing = vectorGet(context.arena, state.base.payload, index);
|
|
398
|
+
if (existing === undefined) {
|
|
399
|
+
slots.push({ tag: Tag.Undefined, payload: 0 });
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
// Carried over unchanged, so this element must not be retired with the old spine.
|
|
403
|
+
carried.add(index);
|
|
404
|
+
slots.push(existing);
|
|
405
|
+
}
|
|
406
|
+
const rebuilt = vectorFromSlots(context, slots);
|
|
407
|
+
// The old spine is garbage. Its elements are only garbage where they were replaced or
|
|
408
|
+
// truncated away, because the rebuilt vector references the carried ones.
|
|
409
|
+
for (let index = 0; index < baseLength; index += 1) {
|
|
410
|
+
if (carried.has(index))
|
|
411
|
+
continue;
|
|
412
|
+
const existing = vectorGet(context.arena, state.base.payload, index);
|
|
413
|
+
if (existing !== undefined)
|
|
414
|
+
retireSubtree(context, existing);
|
|
415
|
+
}
|
|
416
|
+
for (const node of vectorNodes(context.arena, state.base.payload))
|
|
417
|
+
context.retired.push(node);
|
|
418
|
+
return { tag: Tag.Array, payload: rebuilt };
|
|
419
|
+
}
|
|
420
|
+
export function emptyObjectSlot(context) {
|
|
421
|
+
return { tag: Tag.Object, payload: emptyNode(context) };
|
|
422
|
+
}
|
|
423
|
+
export function emptyArraySlot(context) {
|
|
424
|
+
return { tag: Tag.Array, payload: emptyVector(context) };
|
|
425
|
+
}
|
|
426
|
+
export { STATE as DRAFT_STATE, DELETED as DRAFT_DELETED };
|
|
427
|
+
//# sourceMappingURL=draft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../../src/draft.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,OAAO,EACP,cAAc,EACd,OAAO,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,EACf,SAAS,EACT,YAAY,EACZ,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAsB3C,SAAS,WAAW,CAAC,IAAU;IAC7B,OAAO,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC;AA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AS;YAAE,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE9F,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAqB;IACnD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAqB;IAClD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;AAC3D,CAAC;AAED,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,OAAO,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every failure in this package is one of these. A decoder that cannot prove an offset is
|
|
3
|
+
* valid throws rather than dereferencing it, which is the fail closed rule the trust model
|
|
4
|
+
* depends on.
|
|
5
|
+
*/
|
|
6
|
+
/** Base class, so callers can catch every arena failure with one clause. */
|
|
7
|
+
export declare class GlobalsError extends Error {
|
|
8
|
+
constructor(message: string, options?: {
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The snapshot you are holding refers to a version the owner has reclaimed. This is the
|
|
14
|
+
* expected outcome for a reader that stopped advancing while the writer ran past the
|
|
15
|
+
* retention cap. Reacquire a snapshot.
|
|
16
|
+
*/
|
|
17
|
+
export declare class StaleSnapshotError extends GlobalsError {
|
|
18
|
+
readonly versionId: number;
|
|
19
|
+
readonly reclaimFloor: number;
|
|
20
|
+
constructor(versionId: number, reclaimFloor: number);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A read found something that cannot be produced by a correct writer: a bad offset, a
|
|
24
|
+
* block header that does not match, a tag with no meaning. Treat this as a security event
|
|
25
|
+
* as well as a bug, because any window mapping the arena can cause it.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ArenaCorruptError extends GlobalsError {
|
|
28
|
+
readonly detail: {
|
|
29
|
+
offset?: number;
|
|
30
|
+
expected?: number;
|
|
31
|
+
actual?: number;
|
|
32
|
+
};
|
|
33
|
+
constructor(message: string, detail?: {
|
|
34
|
+
offset?: number;
|
|
35
|
+
expected?: number;
|
|
36
|
+
actual?: number;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** The arena has no room and cannot grow further. */
|
|
40
|
+
export declare class ArenaFullError extends GlobalsError {
|
|
41
|
+
readonly requestedBytes: number;
|
|
42
|
+
readonly capacityBytes: number;
|
|
43
|
+
constructor(requestedBytes: number, capacityBytes: number);
|
|
44
|
+
}
|
|
45
|
+
/** Every reader slot is claimed. Raise maxReaders, or find the reader that never released. */
|
|
46
|
+
export declare class NoReaderSlotError extends GlobalsError {
|
|
47
|
+
readonly maxReaders: number;
|
|
48
|
+
constructor(maxReaders: number);
|
|
49
|
+
}
|
|
50
|
+
/** A value was handed to the writer that the current type ladder cannot encode. */
|
|
51
|
+
export declare class UnencodableValueError extends GlobalsError {
|
|
52
|
+
readonly value: unknown;
|
|
53
|
+
readonly reason: string;
|
|
54
|
+
constructor(value: unknown, reason: string);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,4EAA4E;AAC5E,qBAAa,YAAa,SAAQ,KAAK;IACrC,YAA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in this package is one of these. A decoder that cannot prove an offset is
|
|
3
|
+
* valid throws rather than dereferencing it, which is the fail closed rule the trust model
|
|
4
|
+
* depends on.
|
|
5
|
+
*/
|
|
6
|
+
/** Base class, so callers can catch every arena failure with one clause. */
|
|
7
|
+
export class GlobalsError extends Error {
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message, options);
|
|
10
|
+
this.name = new.target.name;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The snapshot you are holding refers to a version the owner has reclaimed. This is the
|
|
15
|
+
* expected outcome for a reader that stopped advancing while the writer ran past the
|
|
16
|
+
* retention cap. Reacquire a snapshot.
|
|
17
|
+
*/
|
|
18
|
+
export class StaleSnapshotError extends GlobalsError {
|
|
19
|
+
versionId;
|
|
20
|
+
reclaimFloor;
|
|
21
|
+
constructor(versionId, reclaimFloor) {
|
|
22
|
+
super(`snapshot for version ${versionId} was reclaimed, the oldest retained version is ` +
|
|
23
|
+
`${reclaimFloor}. Reacquire a snapshot.`);
|
|
24
|
+
this.versionId = versionId;
|
|
25
|
+
this.reclaimFloor = reclaimFloor;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A read found something that cannot be produced by a correct writer: a bad offset, a
|
|
30
|
+
* block header that does not match, a tag with no meaning. Treat this as a security event
|
|
31
|
+
* as well as a bug, because any window mapping the arena can cause it.
|
|
32
|
+
*/
|
|
33
|
+
export class ArenaCorruptError extends GlobalsError {
|
|
34
|
+
detail;
|
|
35
|
+
constructor(message, detail = {}) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.detail = detail;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The arena has no room and cannot grow further. */
|
|
41
|
+
export class ArenaFullError extends GlobalsError {
|
|
42
|
+
requestedBytes;
|
|
43
|
+
capacityBytes;
|
|
44
|
+
constructor(requestedBytes, capacityBytes) {
|
|
45
|
+
super(`cannot allocate ${requestedBytes} bytes, the arena capacity of ${capacityBytes} ` +
|
|
46
|
+
"bytes is exhausted");
|
|
47
|
+
this.requestedBytes = requestedBytes;
|
|
48
|
+
this.capacityBytes = capacityBytes;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Every reader slot is claimed. Raise maxReaders, or find the reader that never released. */
|
|
52
|
+
export class NoReaderSlotError extends GlobalsError {
|
|
53
|
+
maxReaders;
|
|
54
|
+
constructor(maxReaders) {
|
|
55
|
+
super(`all ${maxReaders} reader slots are claimed`);
|
|
56
|
+
this.maxReaders = maxReaders;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** A value was handed to the writer that the current type ladder cannot encode. */
|
|
60
|
+
export class UnencodableValueError extends GlobalsError {
|
|
61
|
+
value;
|
|
62
|
+
reason;
|
|
63
|
+
constructor(value, reason) {
|
|
64
|
+
super(`cannot encode value: ${reason}`);
|
|
65
|
+
this.value = value;
|
|
66
|
+
this.reason = reason;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,4EAA4E;AAC5E,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAEvC,SAAS;IACT,YAAY;IAFvB,YACW,SAAiB,EACjB,YAAoB;QAE7B,KAAK,CACH,wBAAwB,SAAS,iDAAiD;YAChF,GAAG,YAAY,yBAAyB,CAC3C,CAAC;yBANO,SAAS;4BACT,YAAY;IAMvB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IAGtC,MAAM;IAFjB,YACE,OAAe,EACN,MAAM,GAA4D,EAAE;QAE7E,KAAK,CAAC,OAAO,CAAC,CAAC;sBAFN,MAAM;IAGjB,CAAC;CACF;AAED,qDAAqD;AACrD,MAAM,OAAO,cAAe,SAAQ,YAAY;IAEnC,cAAc;IACd,aAAa;IAFxB,YACW,cAAsB,EACtB,aAAqB;QAE9B,KAAK,CACH,mBAAmB,cAAc,iCAAiC,aAAa,GAAG;YAChF,oBAAoB,CACvB,CAAC;8BANO,cAAc;6BACd,aAAa;IAMxB,CAAC;CACF;AAED,8FAA8F;AAC9F,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IAC5B,UAAU;IAA/B,YAAqB,UAAkB;QACrC,KAAK,CAAC,OAAO,UAAU,2BAA2B,CAAC,CAAC;0BADjC,UAAU;IAE/B,CAAC;CACF;AAED,mFAAmF;AACnF,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IAE1C,KAAK;IACL,MAAM;IAFjB,YACW,KAAc,EACd,MAAc;QAEvB,KAAK,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC;qBAH/B,KAAK;sBACL,MAAM;IAGjB,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ExternalRef } from "./values.js";
|
|
2
|
+
/**
|
|
3
|
+
* The escape hatch.
|
|
4
|
+
*
|
|
5
|
+
* Some values cannot go in shared memory: a class instance whose prototype carries
|
|
6
|
+
* behaviour, a value keyed on object identity, a blob too large to be worth copying into the
|
|
7
|
+
* arena. The plan calls for those to reach an asynchronous replicated tier through a visibly
|
|
8
|
+
* different API, so the boundary between synchronous and asynchronous is legible in the
|
|
9
|
+
* calling code rather than a runtime surprise.
|
|
10
|
+
*
|
|
11
|
+
* That is what this is. A value stored here is reachable through a promise and nothing else.
|
|
12
|
+
* There is no accessor that looks synchronous, because the whole point is that you can see
|
|
13
|
+
* from the call site which tier you are on.
|
|
14
|
+
*
|
|
15
|
+
* const handle = tier.put(bigThing);
|
|
16
|
+
* store.update((draft) => { draft.attachment = handle; });
|
|
17
|
+
*
|
|
18
|
+
* // In any process, later:
|
|
19
|
+
* const value = await tier.get(snapshot.attachment);
|
|
20
|
+
*
|
|
21
|
+
* The handle that lands in shared state is an integer. The value itself lives on the owner
|
|
22
|
+
* heap and is replicated to readers by whatever transport the integration supplies, which in
|
|
23
|
+
* Electron is ordinary asynchronous IPC.
|
|
24
|
+
*/
|
|
25
|
+
export interface ExternalTransport {
|
|
26
|
+
/** Ask the owner for the value behind a handle. */
|
|
27
|
+
fetch(handle: number): Promise<unknown>;
|
|
28
|
+
}
|
|
29
|
+
export declare class ExternalTier {
|
|
30
|
+
#private;
|
|
31
|
+
/**
|
|
32
|
+
* @param transport How a reader fetches a value it does not own. Omitted in the owner,
|
|
33
|
+
* which holds every value itself.
|
|
34
|
+
*/
|
|
35
|
+
constructor(transport?: ExternalTransport);
|
|
36
|
+
/** Owner side. Store a value and get a handle that can go into shared state. */
|
|
37
|
+
put(value: unknown): ExternalRef;
|
|
38
|
+
/** Owner side. Drop a value. Reading its handle afterwards rejects. */
|
|
39
|
+
drop(reference: ExternalRef | number): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Read a value. Asynchronous in every process, including the owner, so that moving code
|
|
42
|
+
* between the owner and a window does not change whether it compiles.
|
|
43
|
+
*/
|
|
44
|
+
get(reference: ExternalRef | number): Promise<unknown>;
|
|
45
|
+
/** Owner side. Serve a fetch from another process. */
|
|
46
|
+
serve(handle: number): unknown;
|
|
47
|
+
/** Forget every cached replica. Called when the owner generation changes. */
|
|
48
|
+
invalidate(): void;
|
|
49
|
+
get size(): number;
|
|
50
|
+
}
|
|
51
|
+
export { ExternalRef };
|
|
52
|
+
//# sourceMappingURL=external.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,iBAAiB;IAChC,mDAAmD;IACnD,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC;AAED,qBAAa,YAAY;;IAMvB;;;OAGG;IACH,YAAY,SAAS,CAAC,EAAE,iBAAiB,EAExC;IAED,gFAAgF;IAChF,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAK/B;IAED,uEAAuE;IACvE,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO,CAI7C;IAED;;;OAGG;IACG,GAAG,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAuB3D;IAED,sDAAsD;IACtD,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAK7B;IAED,6EAA6E;IAC7E,UAAU,IAAI,IAAI,CAEjB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|