@northtalk/ts 0.0.0-stage → 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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -2
  3. package/UNICODE-LICENSE.txt +39 -0
  4. package/base64-DORMd3Hv.js +6621 -0
  5. package/binary-value-CEmh60GC.d.ts +15 -0
  6. package/capabilities-CH0FkRMq.js +1301 -0
  7. package/checker-Dc1jl2WH.js +6657 -0
  8. package/core-DptnvQT9.d.ts +14 -0
  9. package/debug-CQBxKnJB.d.ts +3065 -0
  10. package/debug.d.ts +3 -0
  11. package/debug.js +2 -0
  12. package/driver.d.ts +41 -0
  13. package/driver.js +152 -0
  14. package/encoding-nlrpj-Pb.js +99 -0
  15. package/engine-BGaJ9dAk.js +326 -0
  16. package/engine-vbYInVYF.d.ts +86 -0
  17. package/errors-LYJZ_c8h.js +3735 -0
  18. package/group-B742gg4T.js +10170 -0
  19. package/http-capability-CSTkw1Yt.js +728 -0
  20. package/http.d.ts +59 -0
  21. package/http.js +465 -0
  22. package/index.d.ts +651 -0
  23. package/index.js +44 -0
  24. package/manifest-BscyH_rW.d.ts +70 -0
  25. package/manifest-DjsxDSuB.js +129 -0
  26. package/message-layer.d.ts +12 -0
  27. package/message-layer.js +4 -0
  28. package/notify.d.ts +3 -0
  29. package/notify.js +2 -0
  30. package/objects-DJ3QtCCs.d.ts +640 -0
  31. package/objects-Db7IB5vQ.js +91 -0
  32. package/operation-promises-EgZXG5N_.js +23 -0
  33. package/package.json +70 -4
  34. package/readers-BFPuosPk.d.ts +25 -0
  35. package/readers-CjJHKHvH.js +482 -0
  36. package/request-pump-binary-DdY3X-yl.js +2246 -0
  37. package/router--71qvxtY.js +343 -0
  38. package/router-Zhrw5l__.d.ts +55 -0
  39. package/session.d.ts +9 -0
  40. package/session.js +3510 -0
  41. package/setup.d.ts +3 -0
  42. package/setup.js +193 -0
  43. package/sha256-B_kyYw3Z.js +124 -0
  44. package/sqlite.d.ts +74 -0
  45. package/sqlite.js +529 -0
  46. package/store-capability-OZp4hXmj.js +390 -0
  47. package/store-hJrRULMx.js +60 -0
  48. package/store.d.ts +21 -0
  49. package/store.js +4 -0
  50. package/user-capability-BK4Asg7D.js +276 -0
  51. package/wasm.d.ts +243 -0
  52. package/wasm.js +1737 -0
package/setup.d.ts ADDED
@@ -0,0 +1,3 @@
1
+
2
+ import { A as shapeOf, C as Setup, D as capabilityOperations, E as buildSetupGroup, M as tsCore, O as immutableSetup, S as OperationSpec, T as ShapeSpec, b as MissingCapabilityError, j as shapeSpec, k as operationDeclarations, w as SetupGroup, x as ObjectRefSpec, y as CaseCore } from "./objects-DJ3QtCCs.js";
3
+ export { CaseCore, MissingCapabilityError, ObjectRefSpec, OperationSpec, Setup, SetupGroup, ShapeSpec, buildSetupGroup, capabilityOperations, immutableSetup, operationDeclarations, shapeOf, shapeSpec, tsCore };
package/setup.js ADDED
@@ -0,0 +1,193 @@
1
+
2
+ import { n as LoadError } from "./errors-LYJZ_c8h.js";
3
+ import { t as defineObjectKind } from "./objects-Db7IB5vQ.js";
4
+ import { u as shape } from "./capabilities-CH0FkRMq.js";
5
+ import { c as compileLibrary, i as restore, l as replacementLibraries, r as newGroup } from "./group-B742gg4T.js";
6
+ //#region src/setup.ts
7
+ const operationDeclarations = (capabilities) => {
8
+ const declarations = Object.create(null);
9
+ for (const [name, capability] of capabilities) declarations[name] = Object.fromEntries([...capability.operations].map(([operation, op]) => [operation, {
10
+ args: op.args ?? [],
11
+ mode: op.mode,
12
+ ...op.labels?.length ? { labels: op.labels } : {},
13
+ ...op.command ? { command: true } : {}
14
+ }]));
15
+ return declarations;
16
+ };
17
+ const tsCore = {
18
+ compileLibrary,
19
+ defineObjectKind,
20
+ newGroup,
21
+ replacementLibraries,
22
+ restore
23
+ };
24
+ const compileLibraries = (readSource, setup, declarations, core = tsCore) => {
25
+ const out = /* @__PURE__ */ new Map();
26
+ let pending = setup.libraries ?? [];
27
+ while (pending.length) {
28
+ const failed = [];
29
+ for (const library of pending) try {
30
+ const done = [...out.values()].filter((l) => !(l instanceof LoadError));
31
+ out.set(library.name, core.compileLibrary({
32
+ ...library,
33
+ source: library.text ?? readSource(library.source)
34
+ }, done, declarations));
35
+ } catch (error) {
36
+ if (!(error instanceof LoadError)) throw error;
37
+ out.set(library.name, error);
38
+ failed.push(library);
39
+ }
40
+ if (failed.length === pending.length) break;
41
+ pending = failed;
42
+ }
43
+ return out;
44
+ };
45
+ const shapeSpec = (s) => {
46
+ switch (s.k) {
47
+ case "kind": return s.kind;
48
+ case "any":
49
+ case "value": return s.k;
50
+ case "quantity": return { quantity: s.unit };
51
+ case "unitKind": return { unitKind: s.kind };
52
+ case "object": return { object: s.kind };
53
+ case "list": return { list: shapeSpec(s.of) };
54
+ case "oneOf": return { oneOf: s.of.map(shapeSpec) };
55
+ case "optional": return { optional: shapeSpec(s.of) };
56
+ case "map": return {
57
+ map: s.fields.map((f) => ({
58
+ key: f.key,
59
+ optional: f.optional,
60
+ shape: shapeSpec(f.shape)
61
+ })),
62
+ open: s.open
63
+ };
64
+ }
65
+ };
66
+ const capabilityOperations = (capabilities) => capabilities.flatMap((c) => [...c.operations].map(([name, op]) => ({
67
+ capability: c.name,
68
+ name,
69
+ mode: op.mode,
70
+ args: (op.args ?? []).map(shapeSpec),
71
+ cost: { ...op.cost },
72
+ ...op.labels?.length ? { labels: [...op.labels] } : {},
73
+ ...op.command ? { command: true } : {},
74
+ ...op.result ? { result: shapeSpec(op.result) } : {},
75
+ ...op.errors ? { errors: op.errors.map((e) => ({
76
+ code: e.code,
77
+ fields: Object.entries(e.fields ?? {}).map(([key, field]) => ({
78
+ key,
79
+ ..."shape" in field ? {
80
+ optional: true,
81
+ shape: shapeSpec(field.shape)
82
+ } : { shape: shapeSpec(field) }
83
+ }))
84
+ })) } : {}
85
+ })));
86
+ /** Freeze a new declaration without modifying any previous Session Setup. */
87
+ const immutableSetup = (setup) => {
88
+ const freeze = (value) => {
89
+ if (value && typeof value === "object" && !Object.isFrozen(value)) {
90
+ for (const child of Object.values(value)) freeze(child);
91
+ Object.freeze(value);
92
+ }
93
+ };
94
+ freeze(setup);
95
+ return setup;
96
+ };
97
+ /** Make a Group whose Scripts are loaded only when the Host requests them. */
98
+ const buildSetupGroup = (setup, capabilities, options) => {
99
+ const core = options.core ?? tsCore;
100
+ const group = core.newGroup({
101
+ name: options.name,
102
+ session: options.session,
103
+ trace: options.trace,
104
+ ...setup.seed === void 0 ? {} : { seed: BigInt(setup.seed) }
105
+ });
106
+ const readSource = options.readSource ?? ((file) => {
107
+ throw new Error(`No source reader for ${file}`);
108
+ });
109
+ const declarations = operationDeclarations(capabilities);
110
+ const libraries = compileLibraries(readSource, setup, declarations, core);
111
+ const bound = /* @__PURE__ */ new Map();
112
+ const objectOf = (o) => {
113
+ const found = options.resolveObject?.(o.kind, o.id);
114
+ if (!found) throw new Error(`case.toml has no object ${o.kind} ${o.id}`);
115
+ return found;
116
+ };
117
+ return {
118
+ group,
119
+ libraries,
120
+ declarations,
121
+ grants: bound,
122
+ load(group, name, objects) {
123
+ const script = setup.scripts?.find((s) => s.name === name);
124
+ if (!script) throw new Error(`case.toml has no Script ${name}`);
125
+ const grants = Object.create(null);
126
+ for (const [granted, g] of Object.entries(script.grants ?? {})) {
127
+ const capability = capabilities.get(g.capability ?? granted);
128
+ if (!capability) throw new MissingCapabilityError(g.capability ?? granted);
129
+ if (g.coordinator !== void 0 && !capability.coordinator) throw new Error(`${capability.name} can't take a coordinator in case.toml`);
130
+ const make = () => capability.grant(g.ops, g.binding ?? (capability.name === "locale" ? "und" : void 0));
131
+ grants[granted] = options.withCoordinator ? options.withCoordinator(g.coordinator, make) : make();
132
+ }
133
+ bound.set(script.name, grants);
134
+ return group.load({
135
+ grants,
136
+ grantsAsUsed: script.grantsAsUsed,
137
+ name: script.name,
138
+ source: script.text ?? readSource(script.source),
139
+ limits: script.limits,
140
+ objects: objects ?? Object.fromEntries(Object.entries(script.objects ?? {}).map(([name, o]) => [name, objectOf(o)])),
141
+ ...script.owner ? { owner: objectOf(script.owner) } : {}
142
+ });
143
+ }
144
+ };
145
+ };
146
+ /** The caller decides whether an unavailable Capability is deferred or refused. */
147
+ var MissingCapabilityError = class extends Error {
148
+ capability;
149
+ constructor(capability) {
150
+ super(`the Standard Capability ${capability}`);
151
+ this.capability = capability;
152
+ }
153
+ };
154
+ const kinds = {
155
+ any: shape.any,
156
+ value: shape.value,
157
+ nothing: shape.nothing,
158
+ boolean: shape.bool,
159
+ number: shape.number,
160
+ text: shape.text,
161
+ bytes: shape.bytes,
162
+ instant: shape.instant,
163
+ "civil date": shape.civilDate,
164
+ range: shape.range,
165
+ pattern: shape.pattern,
166
+ function: shape.function
167
+ };
168
+ const shapeOf = (s) => {
169
+ if (typeof s === "string") {
170
+ const k = kinds[s];
171
+ if (!k) throw new Error(`Unknown Shape ${s}`);
172
+ return k;
173
+ }
174
+ if ("quantity" in s) return shape.quantityOf(s.quantity);
175
+ if ("unitKind" in s) return shape.quantityKind(s.unitKind);
176
+ if ("object" in s) return {
177
+ k: "object",
178
+ kind: s.object
179
+ };
180
+ if ("list" in s) return shape.listOf(shapeOf(s.list));
181
+ if ("oneOf" in s) return shape.oneOf(...s.oneOf.map(shapeOf));
182
+ if ("optional" in s) return shape.optional(shapeOf(s.optional));
183
+ if ("map" in s) {
184
+ const fields = Object.fromEntries(s.map.map((f) => [f.key, f.optional ? {
185
+ shape: shapeOf(f.shape),
186
+ optional: true
187
+ } : shapeOf(f.shape)]));
188
+ return s.open ? shape.openMap(fields) : shape.map(fields);
189
+ }
190
+ throw new Error("Unknown Shape");
191
+ };
192
+ //#endregion
193
+ export { MissingCapabilityError, buildSetupGroup, capabilityOperations, immutableSetup, operationDeclarations, shapeOf, shapeSpec, tsCore };
@@ -0,0 +1,124 @@
1
+
2
+ //#region src/sha256.ts
3
+ const K = new Uint32Array([
4
+ 1116352408,
5
+ 1899447441,
6
+ 3049323471,
7
+ 3921009573,
8
+ 961987163,
9
+ 1508970993,
10
+ 2453635748,
11
+ 2870763221,
12
+ 3624381080,
13
+ 310598401,
14
+ 607225278,
15
+ 1426881987,
16
+ 1925078388,
17
+ 2162078206,
18
+ 2614888103,
19
+ 3248222580,
20
+ 3835390401,
21
+ 4022224774,
22
+ 264347078,
23
+ 604807628,
24
+ 770255983,
25
+ 1249150122,
26
+ 1555081692,
27
+ 1996064986,
28
+ 2554220882,
29
+ 2821834349,
30
+ 2952996808,
31
+ 3210313671,
32
+ 3336571891,
33
+ 3584528711,
34
+ 113926993,
35
+ 338241895,
36
+ 666307205,
37
+ 773529912,
38
+ 1294757372,
39
+ 1396182291,
40
+ 1695183700,
41
+ 1986661051,
42
+ 2177026350,
43
+ 2456956037,
44
+ 2730485921,
45
+ 2820302411,
46
+ 3259730800,
47
+ 3345764771,
48
+ 3516065817,
49
+ 3600352804,
50
+ 4094571909,
51
+ 275423344,
52
+ 430227734,
53
+ 506948616,
54
+ 659060556,
55
+ 883997877,
56
+ 958139571,
57
+ 1322822218,
58
+ 1537002063,
59
+ 1747873779,
60
+ 1955562222,
61
+ 2024104815,
62
+ 2227730452,
63
+ 2361852424,
64
+ 2428436474,
65
+ 2756734187,
66
+ 3204031479,
67
+ 3329325298
68
+ ]);
69
+ const rotr = (x, n) => x >>> n | x << 32 - n;
70
+ const sha256 = (input) => {
71
+ const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
72
+ const length = bytes.length;
73
+ const padded = new Uint8Array(Math.ceil((length + 9) / 64) * 64);
74
+ padded.set(bytes);
75
+ padded[length] = 128;
76
+ const view = new DataView(padded.buffer);
77
+ view.setUint32(padded.length - 8, Math.floor(length / 536870912));
78
+ view.setUint32(padded.length - 4, length * 8 >>> 0);
79
+ const h = new Uint32Array([
80
+ 1779033703,
81
+ 3144134277,
82
+ 1013904242,
83
+ 2773480762,
84
+ 1359893119,
85
+ 2600822924,
86
+ 528734635,
87
+ 1541459225
88
+ ]);
89
+ const w = /* @__PURE__ */ new Uint32Array(64);
90
+ for (let block = 0; block < padded.length; block += 64) {
91
+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(block + i * 4);
92
+ for (let i = 16; i < 64; i++) {
93
+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
94
+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
95
+ w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
96
+ }
97
+ let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];
98
+ for (let i = 0; i < 64; i++) {
99
+ const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
100
+ const ch = e & f ^ ~e & g;
101
+ const t1 = hh + s1 + ch + K[i] + w[i] >>> 0;
102
+ const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
103
+ hh = g;
104
+ g = f;
105
+ f = e;
106
+ e = d + t1 >>> 0;
107
+ d = c;
108
+ c = b;
109
+ b = a;
110
+ a = t1 + t2 >>> 0;
111
+ }
112
+ h[0] = h[0] + a >>> 0;
113
+ h[1] = h[1] + b >>> 0;
114
+ h[2] = h[2] + c >>> 0;
115
+ h[3] = h[3] + d >>> 0;
116
+ h[4] = h[4] + e >>> 0;
117
+ h[5] = h[5] + f >>> 0;
118
+ h[6] = h[6] + g >>> 0;
119
+ h[7] = h[7] + hh >>> 0;
120
+ }
121
+ return Array.from(h, (x) => x.toString(16).padStart(8, "0")).join("");
122
+ };
123
+ //#endregion
124
+ export { sha256 as t };
package/sqlite.d.ts ADDED
@@ -0,0 +1,74 @@
1
+
2
+ import { Bt as SegmentCoordinator, an as SqlParams, cn as SqliteBinding, ln as SqliteImpl, nn as StoreImpl, on as SqlRows, yt as Call } from "./debug-CQBxKnJB.js";
3
+ import { a as Stores, r as StoreQuotas } from "./engine-vbYInVYF.js";
4
+ //#region src/sqlite/database.d.ts
5
+ /** The table that keeps a database's Stores, which no `sqlite` Grant may use. */
6
+ export declare const STORE_TABLE = "store";
7
+ type SqliteDatabaseOptions = {
8
+ /** Keep Stores in the database, with these quotas, on its coordinator. */
9
+ readonly stores?: StoreQuotas;
10
+ };
11
+ /** The Stores a database keeps: the `store` implementation and the Host's commands. */
12
+ type SqliteStores = StoreImpl & Pick<Stores, 'clear' | 'entries' | 'replace' | 'router'>;
13
+ /** One database a Host offers through `sqlite`, and the Stores it may keep. */
14
+ export declare class SqliteDatabase {
15
+ /** Every Grant on the database, and its Stores, map to this coordinator. */
16
+ readonly coordinator: SegmentCoordinator;
17
+ /** The Stores, for `storeCapability`, when the database keeps them. */
18
+ readonly stores?: SqliteStores;
19
+ private readonly lock;
20
+ private readonly reader;
21
+ private readonly writer;
22
+ private readonly engine?;
23
+ private readonly counts;
24
+ private holder?;
25
+ private savepoints;
26
+ private committing?;
27
+ private shared;
28
+ private readonly groups;
29
+ private nextGroup;
30
+ constructor(path: string, options?: SqliteDatabaseOptions);
31
+ /**
32
+ * Marks the database as offered through `sqlite`, as `sqliteDatabases`
33
+ * does. From then on a Store write takes the write lock at its call, so a
34
+ * Store's commit never finds it held (ADR 0070). Until then, a Store's
35
+ * commit takes the lock only for the commit.
36
+ */
37
+ shareWithSqlite(): void;
38
+ /** Runs SQL directly, outside every Segment and with no authorizer, as for a migration. */
39
+ exec(sql: string): void;
40
+ /** Closes the database, discarding any Segment's uncommitted changes. */
41
+ close(): void;
42
+ query(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number): SqlRows;
43
+ change(call: Call<SqliteBinding>, sql: string, params: SqlParams, max: number): SqlRows & {
44
+ readonly changes: number;
45
+ };
46
+ begin(call: Call<SqliteBinding>): void;
47
+ commit(call: Call<SqliteBinding>): void;
48
+ rollback(call: Call<SqliteBinding>): void;
49
+ private beginSegment;
50
+ private commitSegment;
51
+ private rollbackSegment;
52
+ private key;
53
+ private acquire;
54
+ private held;
55
+ private publish;
56
+ private abandon;
57
+ private changeCounts;
58
+ private statement;
59
+ private prepareOne;
60
+ private storeBackend;
61
+ private storeWrite;
62
+ private storeOperations;
63
+ }
64
+ /** Opens or creates the database at `path`, which the process holds until `close`. */
65
+ export declare const openSqliteDatabase: (path: string, options?: SqliteDatabaseOptions) => SqliteDatabase;
66
+ //#endregion
67
+ //#region src/sqlite/index.d.ts
68
+ /**
69
+ * The implementation over the Host's databases, by the name a binding gives.
70
+ * Each database's Store writes then take its write lock at their call.
71
+ */
72
+ export declare const sqliteDatabases: (databases: Readonly<Record<string, SqliteDatabase>>) => SqliteImpl;
73
+ //#endregion
74
+ export type { SqliteDatabaseOptions, SqliteStores };