@northtalk/ts 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +55 -2
- package/UNICODE-LICENSE.txt +39 -0
- package/core-eU5KaYkz.d.ts +23 -0
- package/debug-D8Z_u244.d.ts +2698 -0
- package/debug.d.ts +2 -0
- package/debug.js +1 -0
- package/driver.d.ts +27 -0
- package/driver.js +74 -0
- package/encoding-DWlbPq-e.js +7792 -0
- package/engine-BPFnHT9N.d.ts +86 -0
- package/engine-CgCMdGGd.js +324 -0
- package/errors-DHwz1Vho.js +3661 -0
- package/group-B4eyJKTA.js +15958 -0
- package/index.d.ts +645 -0
- package/index.js +37 -0
- package/manifest-DKe2Je6Z.js +208 -0
- package/notify.d.ts +2 -0
- package/notify.js +1 -0
- package/objects-MeXIDDFo.d.ts +625 -0
- package/package.json +62 -4
- package/readers-DyjxJEkL.js +479 -0
- package/readers-Oh4tO2dK.d.ts +57 -0
- package/router-DHPJNvbt.js +341 -0
- package/router-DpDpAJjz.d.ts +54 -0
- package/session.d.ts +8 -0
- package/session.js +3476 -0
- package/setup.d.ts +2 -0
- package/setup.js +189 -0
- package/sha256-0jiTgVJu.js +123 -0
- package/sqlite-capability-C7-SYdD7.d.ts +87 -0
- package/sqlite-capability-CrCej3Po.js +478 -0
- package/sqlite.d.ts +75 -0
- package/sqlite.js +528 -0
- package/store-DrYjcoru.js +59 -0
- package/store-capability-CDoVafZL.js +387 -0
- package/store.d.ts +20 -0
- package/store.js +3 -0
- package/user-capability-CLkDsrCX.d.ts +40 -0
- package/user-capability-Cv0oJhhv.js +273 -0
- package/wasm.d.ts +223 -0
- package/wasm.js +1453 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { At as Call, Kt as SegmentContext, Pt as EffectResult, at as Value, zt as GrantContext } from "./debug-D8Z_u244.js";
|
|
2
|
+
import { r as StoreImpl } from "./user-capability-CLkDsrCX.js";
|
|
3
|
+
import { i as WatchLimits, n as RouterOptions, t as NotificationRouter } from "./router-DpDpAJjz.js";
|
|
4
|
+
//#region src/store/engine.d.ts
|
|
5
|
+
/** A Store's limits, each counted by logical size (chapter 8). */
|
|
6
|
+
type StoreQuotas = {
|
|
7
|
+
/** The most keys it holds. */
|
|
8
|
+
keys: number;
|
|
9
|
+
/** The most its keys and values may total. */
|
|
10
|
+
size: number;
|
|
11
|
+
/** The largest value. */
|
|
12
|
+
value: number;
|
|
13
|
+
};
|
|
14
|
+
/** The Session Store's quotas (chapter 12, The Session Store). */
|
|
15
|
+
declare const sessionQuotas: StoreQuotas;
|
|
16
|
+
/** The Session Store's notification limits (Store Notifications, The Session Host). */
|
|
17
|
+
declare const sessionWatchLimits: WatchLimits;
|
|
18
|
+
/** Where Stores' committed contents are kept, by Store name. */
|
|
19
|
+
type StoreBackend = {
|
|
20
|
+
/** Every key and value of a Store, read once, when the Store is first used. */
|
|
21
|
+
load(store: string): Iterable<readonly [string, Value]>;
|
|
22
|
+
/**
|
|
23
|
+
* Applies one commit's changes to every Store it wrote at once: by Store
|
|
24
|
+
* name, each key's new value, with Nothing deleting it. Throws, leaving
|
|
25
|
+
* every Store unchanged, if it can't; throws `StoreStateUnknownError` if
|
|
26
|
+
* it can't tell whether some Stores changed.
|
|
27
|
+
*/
|
|
28
|
+
save(changes: ReadonlyMap<string, ReadonlyMap<string, Value>>): void;
|
|
29
|
+
};
|
|
30
|
+
/** A backend's commit that may have changed some of its Stores. */
|
|
31
|
+
declare class StoreStateUnknownError extends Error {
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
/** Why a Host command on a Store's contents was refused. */
|
|
35
|
+
declare class StoreContentsError extends Error {
|
|
36
|
+
name: string;
|
|
37
|
+
}
|
|
38
|
+
/** A Store's contents as one JSON object, in key order, with no white space. */
|
|
39
|
+
declare const encodeContents: (entries: readonly (readonly [string, Value])[]) => string;
|
|
40
|
+
/** Contents written by `encodeContents`. Throws on anything else. */
|
|
41
|
+
declare const decodeContents: (source: string) => [string, Value][];
|
|
42
|
+
/** Every Store a Host keeps through one backend, as one `StoreImpl`. */
|
|
43
|
+
declare class Stores implements StoreImpl {
|
|
44
|
+
private readonly backend;
|
|
45
|
+
readonly quotas: StoreQuotas;
|
|
46
|
+
readonly router: NotificationRouter;
|
|
47
|
+
private readonly revisions;
|
|
48
|
+
private readonly contents;
|
|
49
|
+
private readonly segments;
|
|
50
|
+
private readonly groups;
|
|
51
|
+
private nextGroup;
|
|
52
|
+
constructor(backend: StoreBackend, quotas: StoreQuotas, watchLimits?: WatchLimits, admitted?: RouterOptions['admitted']);
|
|
53
|
+
watch(call: Call<string>, name: string, prefix: string, message: string): void;
|
|
54
|
+
unwatch(call: Call<string>, name: string): void;
|
|
55
|
+
release(context: GrantContext<string>): void;
|
|
56
|
+
begin(context: SegmentContext<string>): EffectResult;
|
|
57
|
+
commit(context: SegmentContext<string>): EffectResult;
|
|
58
|
+
rollback(context: SegmentContext<string>): EffectResult;
|
|
59
|
+
get(call: Call<string>, key: string, fallback?: Value): Value;
|
|
60
|
+
keys(call: Call<string>, prefix?: string): Value;
|
|
61
|
+
set(call: Call<string>, key: string, value: Value): void;
|
|
62
|
+
delete(call: Call<string>, key: string): void;
|
|
63
|
+
swap(call: Call<string>, key: string, expected: Value, replacement: Value): boolean;
|
|
64
|
+
increment(call: Call<string>, key: string, by?: Value): Value;
|
|
65
|
+
/** A Store's committed contents, in key order. */
|
|
66
|
+
entries(store: string): [string, Value][];
|
|
67
|
+
/** Replaces a Store's contents, between Pumps. */
|
|
68
|
+
replace(store: string, entries: readonly (readonly [string, Value])[]): void;
|
|
69
|
+
/** Empties a Store, between Pumps. */
|
|
70
|
+
clear(store: string): void;
|
|
71
|
+
private bump;
|
|
72
|
+
private committed;
|
|
73
|
+
private put;
|
|
74
|
+
private changesTo;
|
|
75
|
+
private segmentKey;
|
|
76
|
+
private own;
|
|
77
|
+
private others;
|
|
78
|
+
private segment;
|
|
79
|
+
private seen;
|
|
80
|
+
private storable;
|
|
81
|
+
private unreserved;
|
|
82
|
+
private write;
|
|
83
|
+
private grows;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { Stores as a, sessionQuotas as c, StoreStateUnknownError as i, sessionWatchLimits as l, StoreContentsError as n, decodeContents as o, StoreQuotas as r, encodeContents as s, StoreBackend as t };
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { E as listValues, V as text, a as invalidValue, h as dec, j as nothing } from "./errors-DHwz1Vho.js";
|
|
2
|
+
import { Q as sizeOf, n as quoteJSON, t as encodeValue, ut as compareText } from "./encoding-DWlbPq-e.js";
|
|
3
|
+
import { n as decodeValueMembers } from "./readers-DyjxJEkL.js";
|
|
4
|
+
import { n as hostScriptError, t as add } from "./store-capability-CDoVafZL.js";
|
|
5
|
+
import { n as createRouter, t as changed } from "./router-DHPJNvbt.js";
|
|
6
|
+
//#region src/store/engine.ts
|
|
7
|
+
/** The Session Store's quotas (chapter 12, The Session Store). */
|
|
8
|
+
const sessionQuotas = Object.freeze({
|
|
9
|
+
size: 1048576,
|
|
10
|
+
keys: 1e3,
|
|
11
|
+
value: 65536
|
|
12
|
+
});
|
|
13
|
+
/** The Session Store's notification limits (Store Notifications, The Session Host). */
|
|
14
|
+
const sessionWatchLimits = Object.freeze({
|
|
15
|
+
watches: 100,
|
|
16
|
+
watchSize: 65536,
|
|
17
|
+
pending: 1e3,
|
|
18
|
+
pendingSize: 1048576
|
|
19
|
+
});
|
|
20
|
+
/** A backend's commit that may have changed some of its Stores. */
|
|
21
|
+
var StoreStateUnknownError = class extends Error {
|
|
22
|
+
name = "StoreStateUnknownError";
|
|
23
|
+
};
|
|
24
|
+
const absent = (v) => v === void 0 || v.kind === "nothing";
|
|
25
|
+
const entrySize = (key, value) => sizeOf(text(key)) + sizeOf(value);
|
|
26
|
+
const amount = (v) => v.kind === "number" || v.kind === "quantity";
|
|
27
|
+
/** A Host Object anywhere in a value: its Object Kind. */
|
|
28
|
+
const objectKind = (value) => {
|
|
29
|
+
const work = [value];
|
|
30
|
+
while (work.length) {
|
|
31
|
+
const v = work.pop();
|
|
32
|
+
if (v.kind === "object") return v.asObjectRef().kind;
|
|
33
|
+
if (v.kind === "list") for (let i = 1; i <= v.length; i++) work.push(v.index(i));
|
|
34
|
+
else if (v.kind === "map") work.push(...v.entries().map(([, item]) => item));
|
|
35
|
+
else if (v.kind === "range") {
|
|
36
|
+
const { from, to } = v.asRange();
|
|
37
|
+
work.push(from, to);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/** Why a Host command on a Store's contents was refused. */
|
|
42
|
+
var StoreContentsError = class extends Error {
|
|
43
|
+
name = "StoreContentsError";
|
|
44
|
+
};
|
|
45
|
+
/** A Store's contents as one JSON object, in key order, with no white space. */
|
|
46
|
+
const encodeContents = (entries) => `{${entries.map(([key, value]) => `${quoteJSON(key)}:${encodeValue(value)}`).join(",")}}`;
|
|
47
|
+
/** Contents written by `encodeContents`. Throws on anything else. */
|
|
48
|
+
const decodeContents = (source) => decodeValueMembers(source);
|
|
49
|
+
/** Every Store a Host keeps through one backend, as one `StoreImpl`. */
|
|
50
|
+
var Stores = class {
|
|
51
|
+
backend;
|
|
52
|
+
quotas;
|
|
53
|
+
router;
|
|
54
|
+
revisions = /* @__PURE__ */ new Map();
|
|
55
|
+
contents = /* @__PURE__ */ new Map();
|
|
56
|
+
segments = /* @__PURE__ */ new Map();
|
|
57
|
+
groups = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
nextGroup = 0;
|
|
59
|
+
constructor(backend, quotas, watchLimits = sessionWatchLimits, admitted) {
|
|
60
|
+
this.backend = backend;
|
|
61
|
+
this.quotas = quotas;
|
|
62
|
+
this.router = createRouter({
|
|
63
|
+
admitted,
|
|
64
|
+
limits: () => watchLimits,
|
|
65
|
+
revision: (store) => (this.revisions.get(store) ?? 0n).toString()
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
watch(call, name, prefix, message) {
|
|
69
|
+
this.router.watch(call, name, prefix, message);
|
|
70
|
+
}
|
|
71
|
+
unwatch(call, name) {
|
|
72
|
+
this.router.unwatch(call, name);
|
|
73
|
+
}
|
|
74
|
+
release(context) {
|
|
75
|
+
this.router.release(context);
|
|
76
|
+
}
|
|
77
|
+
begin(context) {
|
|
78
|
+
const segment = /* @__PURE__ */ new Map();
|
|
79
|
+
if (typeof context.binding === "string") {
|
|
80
|
+
this.committed(context.binding);
|
|
81
|
+
segment.set(context.binding, /* @__PURE__ */ new Map());
|
|
82
|
+
}
|
|
83
|
+
this.segments.set(this.segmentKey(context), segment);
|
|
84
|
+
return { status: "ok" };
|
|
85
|
+
}
|
|
86
|
+
commit(context) {
|
|
87
|
+
const segment = this.segments.get(this.segmentKey(context));
|
|
88
|
+
this.segments.delete(this.segmentKey(context));
|
|
89
|
+
const changes = /* @__PURE__ */ new Map();
|
|
90
|
+
try {
|
|
91
|
+
for (const [store, keys] of segment ?? []) {
|
|
92
|
+
const contents = this.committed(store);
|
|
93
|
+
const values = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const [key, pending] of keys) values.set(key, applied(pending.set ?? contents.entries.get(key), pending.deltas) ?? nothing);
|
|
95
|
+
if (values.size) changes.set(store, values);
|
|
96
|
+
}
|
|
97
|
+
if (changes.size) this.backend.save(changes);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error instanceof StoreStateUnknownError) {
|
|
100
|
+
for (const store of changes.keys()) this.contents.delete(store);
|
|
101
|
+
return {
|
|
102
|
+
status: "unknown",
|
|
103
|
+
detail: error.message
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
status: "failed",
|
|
108
|
+
detail: error.message
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
for (const [store, values] of [...changes].sort(([a], [b]) => compareText(a, b))) this.router.commit(store, () => {
|
|
112
|
+
const contents = this.committed(store);
|
|
113
|
+
const keys = [];
|
|
114
|
+
for (const [key, value] of values) {
|
|
115
|
+
if (changed(contents.entries.get(key), value)) keys.push(key);
|
|
116
|
+
this.put(contents, key, absent(value) ? void 0 : value);
|
|
117
|
+
}
|
|
118
|
+
this.bump(store, keys);
|
|
119
|
+
return keys;
|
|
120
|
+
});
|
|
121
|
+
return { status: "ok" };
|
|
122
|
+
}
|
|
123
|
+
rollback(context) {
|
|
124
|
+
this.segments.delete(this.segmentKey(context));
|
|
125
|
+
return { status: "ok" };
|
|
126
|
+
}
|
|
127
|
+
get(call, key, fallback) {
|
|
128
|
+
return this.seen(call, key) ?? fallback ?? nothing;
|
|
129
|
+
}
|
|
130
|
+
keys(call, prefix = "") {
|
|
131
|
+
const store = storeName(call.binding);
|
|
132
|
+
const own = this.own(call, store);
|
|
133
|
+
const keys = new Set(this.committed(store).entries.keys());
|
|
134
|
+
for (const key of own?.keys() ?? []) keys.add(key);
|
|
135
|
+
return listValues([...keys].filter((key) => key.startsWith(prefix) && this.seen(call, key)).sort(compareText).map((key) => text(key)));
|
|
136
|
+
}
|
|
137
|
+
set(call, key, value) {
|
|
138
|
+
this.storable(value);
|
|
139
|
+
this.write(call, key, value);
|
|
140
|
+
}
|
|
141
|
+
delete(call, key) {
|
|
142
|
+
this.write(call, key, nothing);
|
|
143
|
+
}
|
|
144
|
+
swap(call, key, expected, replacement) {
|
|
145
|
+
this.storable(replacement);
|
|
146
|
+
const store = storeName(call.binding);
|
|
147
|
+
this.unreserved(call, store, key, true);
|
|
148
|
+
if (!(this.seen(call, key) ?? nothing).equals(expected)) return false;
|
|
149
|
+
this.write(call, key, replacement);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
increment(call, key, by) {
|
|
153
|
+
const delta = absent(by) ? ONE : by;
|
|
154
|
+
const store = storeName(call.binding);
|
|
155
|
+
this.unreserved(call, store, key, false);
|
|
156
|
+
const seen = this.seen(call, key);
|
|
157
|
+
if (seen && !amount(seen)) throw hostScriptError("wrong kind", [
|
|
158
|
+
["expected", text("number")],
|
|
159
|
+
["got", text(seen.kind)],
|
|
160
|
+
["value", seen]
|
|
161
|
+
]);
|
|
162
|
+
const result = seen ? add(seen, delta) : delta;
|
|
163
|
+
const own = this.own(call, store)?.get(key);
|
|
164
|
+
if (own?.set === void 0) {
|
|
165
|
+
let projected = this.committed(store).entries.get(key);
|
|
166
|
+
for (const keys of this.others(call, store)) projected = applied(projected, keys.get(key)?.deltas ?? []);
|
|
167
|
+
applied(projected, [...own?.deltas ?? [], delta]);
|
|
168
|
+
}
|
|
169
|
+
const next = {
|
|
170
|
+
...own,
|
|
171
|
+
deltas: [...own?.deltas ?? [], delta]
|
|
172
|
+
};
|
|
173
|
+
this.grows(call, store, key, next, seen ? void 0 : delta);
|
|
174
|
+
this.segment(call, store).set(key, next);
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
/** A Store's committed contents, in key order. */
|
|
178
|
+
entries(store) {
|
|
179
|
+
return [...this.committed(store).entries].sort(([a], [b]) => compareText(a, b));
|
|
180
|
+
}
|
|
181
|
+
/** Replaces a Store's contents, between Pumps. */
|
|
182
|
+
replace(store, entries) {
|
|
183
|
+
if ([...this.segments.values()].some((s) => s.has(store))) throw new StoreContentsError("A Segment is writing to the Store");
|
|
184
|
+
const next = {
|
|
185
|
+
entries: /* @__PURE__ */ new Map(),
|
|
186
|
+
size: 0
|
|
187
|
+
};
|
|
188
|
+
for (const [key, value] of entries) {
|
|
189
|
+
if (key === "" || next.entries.has(key)) throw new StoreContentsError("Store keys must be distinct, nonempty text");
|
|
190
|
+
if (objectKind(value) !== void 0 || value.kind === "function") throw new StoreContentsError("A Store keeps only data values");
|
|
191
|
+
if (sizeOf(value) > this.quotas.value) throw new StoreContentsError("A value is past the Store’s value limit");
|
|
192
|
+
if (!absent(value)) this.put(next, key, value);
|
|
193
|
+
}
|
|
194
|
+
if (next.entries.size > this.quotas.keys || next.size > this.quotas.size) throw new StoreContentsError("The contents are past the Store’s quotas");
|
|
195
|
+
this.router.commit(store, () => {
|
|
196
|
+
const changes = this.changesTo(store, next);
|
|
197
|
+
const keys = [...changes].filter(([key, value]) => changed(this.committed(store).entries.get(key), value)).map(([key]) => key);
|
|
198
|
+
this.backend.save(/* @__PURE__ */ new Map([[store, changes]]));
|
|
199
|
+
this.contents.set(store, next);
|
|
200
|
+
this.bump(store, keys);
|
|
201
|
+
return keys;
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** Empties a Store, between Pumps. */
|
|
205
|
+
clear(store) {
|
|
206
|
+
this.replace(store, []);
|
|
207
|
+
}
|
|
208
|
+
bump(store, keys) {
|
|
209
|
+
if (keys.length) this.revisions.set(store, (this.revisions.get(store) ?? 0n) + 1n);
|
|
210
|
+
}
|
|
211
|
+
committed(store) {
|
|
212
|
+
let contents = this.contents.get(store);
|
|
213
|
+
if (!contents) {
|
|
214
|
+
contents = {
|
|
215
|
+
entries: /* @__PURE__ */ new Map(),
|
|
216
|
+
size: 0
|
|
217
|
+
};
|
|
218
|
+
for (const [key, value] of this.backend.load(store)) this.put(contents, key, value);
|
|
219
|
+
this.contents.set(store, contents);
|
|
220
|
+
}
|
|
221
|
+
return contents;
|
|
222
|
+
}
|
|
223
|
+
put(contents, key, value) {
|
|
224
|
+
const old = contents.entries.get(key);
|
|
225
|
+
if (old) {
|
|
226
|
+
contents.size -= entrySize(key, old);
|
|
227
|
+
contents.entries.delete(key);
|
|
228
|
+
}
|
|
229
|
+
if (value) {
|
|
230
|
+
contents.size += entrySize(key, value);
|
|
231
|
+
contents.entries.set(key, value);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
changesTo(store, next) {
|
|
235
|
+
const changes = /* @__PURE__ */ new Map();
|
|
236
|
+
for (const key of this.committed(store).entries.keys()) if (!next.entries.has(key)) changes.set(key, nothing);
|
|
237
|
+
for (const [key, value] of next.entries) changes.set(key, value);
|
|
238
|
+
return changes;
|
|
239
|
+
}
|
|
240
|
+
segmentKey(at) {
|
|
241
|
+
let group = this.groups.get(at.group);
|
|
242
|
+
if (group === void 0) {
|
|
243
|
+
group = this.nextGroup++;
|
|
244
|
+
this.groups.set(at.group, group);
|
|
245
|
+
}
|
|
246
|
+
return `${group} ${at.segmentId}`;
|
|
247
|
+
}
|
|
248
|
+
own(call, store) {
|
|
249
|
+
return this.segments.get(this.segmentKey(call))?.get(store);
|
|
250
|
+
}
|
|
251
|
+
others(call, store) {
|
|
252
|
+
const mine = this.segmentKey(call);
|
|
253
|
+
return [...this.segments].filter(([id, segment]) => id !== mine && segment.has(store)).map(([, segment]) => segment.get(store));
|
|
254
|
+
}
|
|
255
|
+
segment(call, store) {
|
|
256
|
+
const segment = this.segments.get(this.segmentKey(call));
|
|
257
|
+
if (!segment) throw new Error("A Store write outside its Segment");
|
|
258
|
+
let keys = segment.get(store);
|
|
259
|
+
if (!keys) {
|
|
260
|
+
this.committed(store);
|
|
261
|
+
keys = /* @__PURE__ */ new Map();
|
|
262
|
+
segment.set(store, keys);
|
|
263
|
+
}
|
|
264
|
+
return keys;
|
|
265
|
+
}
|
|
266
|
+
seen(call, key) {
|
|
267
|
+
const store = storeName(call.binding);
|
|
268
|
+
const committed = this.committed(store).entries.get(key);
|
|
269
|
+
const pending = this.own(call, store)?.get(key);
|
|
270
|
+
return pending ? applied(pending.set ?? committed, pending.deltas) : committed;
|
|
271
|
+
}
|
|
272
|
+
storable(value) {
|
|
273
|
+
const kind = objectKind(value);
|
|
274
|
+
if (kind !== void 0) throw hostScriptError("can't store", [["kind", text(kind)]]);
|
|
275
|
+
}
|
|
276
|
+
unreserved(call, store, key, replacing) {
|
|
277
|
+
for (const keys of this.others(call, store)) {
|
|
278
|
+
const pending = keys.get(key);
|
|
279
|
+
if (pending && (replacing || pending.set !== void 0)) throw hostScriptError("store busy", [["key", text(key)]]);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
write(call, key, value) {
|
|
283
|
+
const store = storeName(call.binding);
|
|
284
|
+
this.unreserved(call, store, key, true);
|
|
285
|
+
const next = {
|
|
286
|
+
set: value,
|
|
287
|
+
deltas: []
|
|
288
|
+
};
|
|
289
|
+
this.grows(call, store, key, next, absent(value) ? void 0 : value);
|
|
290
|
+
this.segment(call, store).set(key, next);
|
|
291
|
+
}
|
|
292
|
+
grows(call, store, key, next, written) {
|
|
293
|
+
if (written && sizeOf(written) > this.quotas.value) throw hostScriptError("store full", [["limit", text("value")]]);
|
|
294
|
+
const contents = this.committed(store);
|
|
295
|
+
const mine = new Map(this.own(call, store));
|
|
296
|
+
mine.set(key, next);
|
|
297
|
+
let keys = contents.entries.size;
|
|
298
|
+
let size = contents.size;
|
|
299
|
+
for (const pending of [...this.others(call, store), mine]) {
|
|
300
|
+
let grownKeys = 0;
|
|
301
|
+
let grownSize = 0;
|
|
302
|
+
for (const [k, p] of pending) {
|
|
303
|
+
const old = contents.entries.get(k);
|
|
304
|
+
const base = p.set === void 0 ? old : p.set;
|
|
305
|
+
const value = absent(base) ? p.deltas[0] : base;
|
|
306
|
+
grownKeys += (value ? 1 : 0) - (old ? 1 : 0);
|
|
307
|
+
grownSize += (value ? entrySize(k, value) : 0) - (old ? entrySize(k, old) : 0);
|
|
308
|
+
}
|
|
309
|
+
keys += Math.max(0, grownKeys);
|
|
310
|
+
size += Math.max(0, grownSize);
|
|
311
|
+
}
|
|
312
|
+
if (keys > this.quotas.keys) throw hostScriptError("store full", [["limit", text("keys")]]);
|
|
313
|
+
if (size > this.quotas.size) throw hostScriptError("store full", [["limit", text("size")]]);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const ONE = dec("1");
|
|
317
|
+
const applied = (value, deltas) => {
|
|
318
|
+
let current = absent(value) ? void 0 : value;
|
|
319
|
+
for (const delta of deltas) current = current === void 0 ? delta : add(current, delta);
|
|
320
|
+
return current;
|
|
321
|
+
};
|
|
322
|
+
const storeName = (binding) => typeof binding === "string" ? binding : invalidValue("A Store’s binding is its name, as text");
|
|
323
|
+
//#endregion
|
|
324
|
+
export { encodeContents as a, decodeContents as i, StoreStateUnknownError as n, sessionQuotas as o, Stores as r, sessionWatchLimits as s, StoreContentsError as t };
|