@northtalk/ts 0.1.0 → 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 (54) hide show
  1. package/README.md +9 -5
  2. package/{encoding-DWlbPq-e.js → base64-DORMd3Hv.js} +197 -1368
  3. package/binary-value-CEmh60GC.d.ts +15 -0
  4. package/capabilities-CH0FkRMq.js +1301 -0
  5. package/checker-Dc1jl2WH.js +6657 -0
  6. package/core-DptnvQT9.d.ts +14 -0
  7. package/{debug-D8Z_u244.d.ts → debug-CQBxKnJB.d.ts} +1147 -780
  8. package/debug.d.ts +2 -1
  9. package/debug.js +2 -1
  10. package/driver.d.ts +16 -2
  11. package/driver.js +98 -20
  12. package/encoding-nlrpj-Pb.js +99 -0
  13. package/{engine-CgCMdGGd.js → engine-BGaJ9dAk.js} +7 -5
  14. package/{engine-BPFnHT9N.d.ts → engine-vbYInVYF.d.ts} +3 -3
  15. package/{errors-DHwz1Vho.js → errors-LYJZ_c8h.js} +91 -17
  16. package/{group-B4eyJKTA.js → group-B742gg4T.js} +1490 -7278
  17. package/{sqlite-capability-CrCej3Po.js → http-capability-CSTkw1Yt.js} +255 -5
  18. package/http.d.ts +59 -0
  19. package/http.js +465 -0
  20. package/index.d.ts +23 -17
  21. package/index.js +19 -12
  22. package/manifest-BscyH_rW.d.ts +70 -0
  23. package/{manifest-DKe2Je6Z.js → manifest-DjsxDSuB.js} +11 -90
  24. package/message-layer.d.ts +12 -0
  25. package/message-layer.js +4 -0
  26. package/notify.d.ts +2 -1
  27. package/notify.js +2 -1
  28. package/{objects-MeXIDDFo.d.ts → objects-DJ3QtCCs.d.ts} +23 -8
  29. package/objects-Db7IB5vQ.js +91 -0
  30. package/operation-promises-EgZXG5N_.js +23 -0
  31. package/package.json +9 -1
  32. package/readers-BFPuosPk.d.ts +25 -0
  33. package/{readers-DyjxJEkL.js → readers-CjJHKHvH.js} +6 -3
  34. package/request-pump-binary-DdY3X-yl.js +2246 -0
  35. package/{router-DHPJNvbt.js → router--71qvxtY.js} +8 -6
  36. package/{router-DpDpAJjz.d.ts → router-Zhrw5l__.d.ts} +6 -5
  37. package/session.d.ts +2 -1
  38. package/session.js +58 -24
  39. package/setup.d.ts +2 -1
  40. package/setup.js +8 -4
  41. package/{sha256-0jiTgVJu.js → sha256-B_kyYw3Z.js} +1 -0
  42. package/sqlite.d.ts +3 -4
  43. package/sqlite.js +6 -5
  44. package/{store-capability-CDoVafZL.js → store-capability-OZp4hXmj.js} +10 -7
  45. package/{store-DrYjcoru.js → store-hJrRULMx.js} +3 -2
  46. package/store.d.ts +3 -2
  47. package/store.js +3 -2
  48. package/{user-capability-Cv0oJhhv.js → user-capability-BK4Asg7D.js} +8 -5
  49. package/wasm.d.ts +42 -22
  50. package/wasm.js +330 -46
  51. package/core-eU5KaYkz.d.ts +0 -23
  52. package/readers-Oh4tO2dK.d.ts +0 -57
  53. package/sqlite-capability-C7-SYdD7.d.ts +0 -87
  54. package/user-capability-CLkDsrCX.d.ts +0 -40
package/http.js ADDED
@@ -0,0 +1,465 @@
1
+
2
+ import { F as num, K as text, M as map, d as bytes, i as ScriptError, k as listValues, t as HostError, u as bool } 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 { Buffer } from "node:buffer";
6
+ import { createServer } from "node:http";
7
+ //#region src/http/router.ts
8
+ /** The largest request body the router reads by default: 1 MiB. */
9
+ const HTTP_DEFAULT_MAX_BODY_BYTES = 1048576;
10
+ const hostErrorOf = (code, message) => new ScriptError(code, message);
11
+ const wholeOf = (v) => {
12
+ if (v.kind !== "number") return;
13
+ const n = Number(v.toString());
14
+ return Number.isSafeInteger(n) ? n : void 0;
15
+ };
16
+ const decode = (part) => {
17
+ try {
18
+ return decodeURIComponent(part);
19
+ } catch {
20
+ return part;
21
+ }
22
+ };
23
+ const byCodePoint = (a, b) => a < b ? -1 : a > b ? 1 : 0;
24
+ /** The one argument chapter 7 gives an HTTP Exchange's Delivery, without `exchange`. */
25
+ const requestFields = (method, target, rawHeaders, body) => {
26
+ const q = target.indexOf("?");
27
+ const path = q < 0 ? target : target.slice(0, q);
28
+ const query = /* @__PURE__ */ new Map();
29
+ for (const [k, v] of new URLSearchParams(q < 0 ? "" : target.slice(q + 1))) query.set(k, [...query.get(k) ?? [], v]);
30
+ const headers = /* @__PURE__ */ new Map();
31
+ for (let i = 0; i + 1 < rawHeaders.length; i += 2) {
32
+ const name = rawHeaders[i].toLowerCase();
33
+ headers.set(name, [...headers.get(name) ?? [], rawHeaders[i + 1]]);
34
+ }
35
+ return [
36
+ ["method", text(method.toUpperCase())],
37
+ ["path", text(path)],
38
+ ["segments", listValues(path.split("/").filter(Boolean).map((part) => text(decode(part))))],
39
+ ["query", map([...query].sort(([a], [b]) => byCodePoint(a, b)).map(([k, vs]) => [k, vs.length === 1 ? text(vs[0]) : listValues(vs.map((v) => text(v)))]))],
40
+ ["headers", map([...headers].sort(([a], [b]) => byCodePoint(a, b)).map(([k, vs]) => [k, k === "set-cookie" ? listValues(vs.map((v) => text(v))) : text(vs.join(", "))]))],
41
+ ["body", bytes(body)]
42
+ ];
43
+ };
44
+ const plainAnswer = (res, status) => {
45
+ if (res.headersSent || res.writableEnded || res.destroyed) return;
46
+ const body = `${status === 404 ? "Not Found" : status === 413 ? "Payload Too Large" : status === 503 ? "Service Unavailable" : "Internal Server Error"}\n`;
47
+ res.writeHead(status, {
48
+ "content-type": "text/plain; charset=utf-8",
49
+ "content-length": Buffer.byteLength(body)
50
+ });
51
+ res.end(body);
52
+ };
53
+ const addressKey = (host, port) => `${host} ${port}`;
54
+ const failed = (outcome) => outcome === "unhandled" ? 404 : outcome === "cancelled" || outcome === "dropped" ? 503 : 500;
55
+ const addressValue = (a) => map([["host", text(a.host)], ["port", num(a.port)]]);
56
+ /** Creates the HTTP router. Give `impl` to `httpCapability`, and call `pumped` after each Pump. */
57
+ const createHttpHost = (o = {}) => {
58
+ const log = o.log ?? (() => {});
59
+ const maxBody = o.maxBodyBytes ?? 1048576;
60
+ const exchangeKind = (o.defineObjectKind ?? defineObjectKind)({
61
+ name: "httpExchange",
62
+ props: { closed: {
63
+ get: (x) => bool(x.native.closed),
64
+ getCost: { fuel: 1 },
65
+ shape: shape.bool
66
+ } }
67
+ });
68
+ const groupIds = /* @__PURE__ */ new WeakMap();
69
+ let nextGroup = 0;
70
+ let nextExchange = 0;
71
+ const groupId = (g) => {
72
+ let id = groupIds.get(g);
73
+ if (id === void 0) {
74
+ id = ++nextGroup;
75
+ groupIds.set(g, id);
76
+ }
77
+ return id;
78
+ };
79
+ const ownerKeyOf = (g, script, grant) => JSON.stringify([
80
+ groupId(g),
81
+ script,
82
+ grant
83
+ ]);
84
+ const registrations = /* @__PURE__ */ new Map();
85
+ const byAddress = /* @__PURE__ */ new Map();
86
+ const listeners = /* @__PURE__ */ new Set();
87
+ const exchanges = /* @__PURE__ */ new Map();
88
+ const runs = /* @__PURE__ */ new Map();
89
+ let stopping = false;
90
+ let open = 0;
91
+ const closeListener = (l) => {
92
+ if (!listeners.delete(l)) return;
93
+ if (l.address) byAddress.delete(addressKey(l.address.host, l.address.port));
94
+ if (l.server.listening) {
95
+ l.server.close();
96
+ l.server.closeIdleConnections();
97
+ }
98
+ };
99
+ const remove = (r) => {
100
+ if (registrations.get(r.key) !== r) return;
101
+ registrations.delete(r.key);
102
+ r.listener.registrations.delete(r);
103
+ if (r.listener.registrations.size === 0 && r.listener.address) closeListener(r.listener);
104
+ };
105
+ const answer = (x, status) => {
106
+ if (x.answered) return;
107
+ x.answered = true;
108
+ open--;
109
+ plainAnswer(x.res, status);
110
+ };
111
+ const finish = (x) => {
112
+ const byDelivery = exchanges.get(x.group);
113
+ if (x.delivery) byDelivery?.delete(x.delivery);
114
+ if (x.run) runs.get(x.group)?.delete(x.run);
115
+ if (x.object) try {
116
+ x.group.dispose(x.object);
117
+ } catch {}
118
+ };
119
+ const settle = (x, status, why) => {
120
+ if (!x.answered && status === 500 && why !== void 0) log(`http: ${status} for delivery ${x.delivery}: ${why}`);
121
+ answer(x, status);
122
+ finish(x);
123
+ };
124
+ const deliver = (r, x, fields) => {
125
+ const { group, script: name } = r.owner;
126
+ const id = `x${++nextExchange}`;
127
+ try {
128
+ x.object = group.object(exchangeKind, id, x);
129
+ const script = group.script(name);
130
+ if (!script) throw new HostError("invalid value", `no Script ${name}`);
131
+ x.delivery = script.deliver({
132
+ name: r.message,
133
+ args: [map([...fields, ["exchange", x.object.value]])]
134
+ });
135
+ } catch (error) {
136
+ if (error?.name === "MailboxFull") answer(x, 503);
137
+ else {
138
+ log(`http: delivery to ${name} refused: ${String(error)}`);
139
+ remove(r);
140
+ answer(x, 500);
141
+ }
142
+ if (x.object) try {
143
+ group.dispose(x.object);
144
+ } catch {}
145
+ return;
146
+ }
147
+ let byDelivery = exchanges.get(group);
148
+ if (!byDelivery) {
149
+ byDelivery = /* @__PURE__ */ new Map();
150
+ exchanges.set(group, byDelivery);
151
+ }
152
+ byDelivery.set(x.delivery, x);
153
+ };
154
+ const match = (l, path) => {
155
+ let best;
156
+ for (const r of l.registrations) if (path.startsWith(r.prefix) && (!best || r.prefix.length > best.prefix.length)) best = r;
157
+ return best;
158
+ };
159
+ const handle = (l, req, res) => {
160
+ if (stopping) {
161
+ res.setHeader("connection", "close");
162
+ plainAnswer(res, 503);
163
+ return;
164
+ }
165
+ if (Number(req.headers["content-length"] ?? 0) > maxBody) {
166
+ res.setHeader("connection", "close");
167
+ plainAnswer(res, 413);
168
+ req.resume();
169
+ return;
170
+ }
171
+ const chunks = [];
172
+ let size = 0;
173
+ let tooLarge = false;
174
+ req.on("data", (chunk) => {
175
+ size += chunk.length;
176
+ if (size > maxBody) {
177
+ if (!tooLarge) {
178
+ tooLarge = true;
179
+ res.setHeader("connection", "close");
180
+ plainAnswer(res, 413);
181
+ }
182
+ return;
183
+ }
184
+ chunks.push(chunk);
185
+ });
186
+ req.on("error", () => {});
187
+ req.on("end", () => {
188
+ if (tooLarge || res.destroyed) return;
189
+ const target = req.url ?? "/";
190
+ const path = target.split("?", 1)[0];
191
+ const r = match(l, path);
192
+ if (!r) {
193
+ plainAnswer(res, 404);
194
+ return;
195
+ }
196
+ if (stopping) {
197
+ plainAnswer(res, 503);
198
+ return;
199
+ }
200
+ const x = {
201
+ answered: false,
202
+ closed: false,
203
+ group: r.owner.group,
204
+ res
205
+ };
206
+ open++;
207
+ res.on("close", () => {
208
+ if (!x.answered) x.closed = true;
209
+ });
210
+ deliver(r, x, requestFields(req.method ?? "GET", target, req.rawHeaders, new Uint8Array(Buffer.concat(chunks))));
211
+ });
212
+ };
213
+ const bind = (l, port) => {
214
+ l.server.on("error", (error) => {
215
+ if (l.address) {
216
+ log(`http: listener error: ${String(error)}`);
217
+ return;
218
+ }
219
+ const code = error.code === "EADDRINUSE" ? "address in use" : "bad address";
220
+ for (const { call, registration } of l.pending) {
221
+ remove(registration);
222
+ call.fail(hostErrorOf(code, `${l.host}:${port}: ${error.message}`));
223
+ }
224
+ l.pending = [];
225
+ for (const r of l.registrations) remove(r);
226
+ listeners.delete(l);
227
+ if (port !== 0) byAddress.delete(addressKey(l.host, port));
228
+ });
229
+ l.server.listen(port, l.host, () => {
230
+ const bound = l.server.address();
231
+ const actual = bound && typeof bound === "object" ? bound.port : port;
232
+ l.address = {
233
+ host: l.host,
234
+ port: actual
235
+ };
236
+ byAddress.set(addressKey(l.host, actual), l);
237
+ for (const { call } of l.pending) call.answer(map([["host", text(l.host)], ["port", num(actual)]]));
238
+ l.pending = [];
239
+ if (l.registrations.size === 0 || stopping) closeListener(l);
240
+ });
241
+ };
242
+ const serve = (call, name, prefix, message, options) => {
243
+ const host = options.get("host").asText() ?? o.defaultHost ?? "127.0.0.1";
244
+ const portValue = options.get("port");
245
+ const asked = o.portOverride ?? (portValue.kind === "nothing" ? o.defaultPort ?? 0 : wholeOf(portValue));
246
+ if (asked === void 0 || asked < 0 || asked > 65535 || host === "" || stopping || !(o.allow?.(host, asked, call.binding) ?? true)) {
247
+ call.fail(hostErrorOf("bad address", `${host}:${String(asked)}`));
248
+ return;
249
+ }
250
+ const ownerKey = ownerKeyOf(call.group, call.scriptName, call.grantName);
251
+ const key = JSON.stringify([ownerKey, name]);
252
+ const existing = registrations.get(key);
253
+ if (existing && existing.prefix === prefix && existing.message === message && existing.asked.host === host && existing.asked.port === asked) {
254
+ if (existing.listener.address) call.answer(addressValue(existing.listener.address));
255
+ else existing.listener.pending.push({
256
+ call,
257
+ registration: existing
258
+ });
259
+ return;
260
+ }
261
+ let l = asked === 0 ? void 0 : byAddress.get(addressKey(host, asked));
262
+ if (l) {
263
+ for (const r of l.registrations) if (r.prefix === prefix && r.ownerKey !== ownerKey) {
264
+ call.fail(hostErrorOf("address in use", `${host}:${asked}${prefix} is served by another owner`));
265
+ return;
266
+ }
267
+ }
268
+ const fresh = !l;
269
+ if (!l) {
270
+ const server = createServer();
271
+ l = {
272
+ host,
273
+ pending: [],
274
+ registrations: /* @__PURE__ */ new Set(),
275
+ server
276
+ };
277
+ const listener = l;
278
+ server.on("request", (req, res) => handle(listener, req, res));
279
+ listeners.add(l);
280
+ if (asked !== 0) byAddress.set(addressKey(host, asked), l);
281
+ }
282
+ const registration = {
283
+ asked: {
284
+ host,
285
+ port: asked
286
+ },
287
+ key,
288
+ listener: l,
289
+ message,
290
+ name,
291
+ owner: {
292
+ group: call.group,
293
+ script: call.scriptName,
294
+ grant: call.grantName
295
+ },
296
+ ownerKey,
297
+ prefix
298
+ };
299
+ l.registrations.add(registration);
300
+ registrations.set(key, registration);
301
+ if (existing) {
302
+ existing.listener.registrations.delete(existing);
303
+ if (existing.listener !== l && existing.listener.registrations.size === 0 && existing.listener.address) closeListener(existing.listener);
304
+ }
305
+ if (l.address) call.answer(addressValue(l.address));
306
+ else {
307
+ l.pending.push({
308
+ call,
309
+ registration
310
+ });
311
+ if (fresh) bind(l, asked);
312
+ }
313
+ };
314
+ const unserve = (call, name) => {
315
+ const ownerKey = ownerKeyOf(call.group, call.scriptName, call.grantName);
316
+ const r = registrations.get(JSON.stringify([ownerKey, name]));
317
+ if (r) remove(r);
318
+ };
319
+ const respond = (call, exchange, response) => {
320
+ const x = exchange.native;
321
+ if (exchange.kind.name !== "httpExchange" || !x || x.group !== call.group || call.delivery === void 0 || call.delivery !== x.delivery) throw hostErrorOf("not owner", "this Run did not receive the exchange");
322
+ if (x.answered) throw hostErrorOf("already responded", "the exchange is answered");
323
+ if (x.closed || x.res.destroyed) {
324
+ x.closed = true;
325
+ throw hostErrorOf("exchange closed", "the client has gone");
326
+ }
327
+ const headers = [];
328
+ const given = response.get("headers");
329
+ for (const [k, v] of given.kind === "map" ? given.entries() : []) headers.push([k, v.kind === "list" ? Array.from({ length: v.length }, (_, i) => v.index(i + 1).asText()) : v.asText()]);
330
+ const has = (name) => headers.some(([k]) => k.toLowerCase() === name);
331
+ const body = response.get("body");
332
+ const json = response.get("json");
333
+ let payload = /* @__PURE__ */ new Uint8Array();
334
+ if (json.kind === "text") {
335
+ payload = Buffer.from(json.asText(), "utf8");
336
+ if (!has("content-type")) headers.push(["content-type", "application/json"]);
337
+ } else if (body.kind === "text") {
338
+ payload = Buffer.from(body.asText(), "utf8");
339
+ if (!has("content-type")) headers.push(["content-type", "text/plain; charset=utf-8"]);
340
+ } else if (body.kind === "bytes") payload = body.asBytes();
341
+ const status = wholeOf(response.get("status")) ?? 200;
342
+ try {
343
+ for (const [k, v] of headers) x.res.setHeader(k, v);
344
+ x.res.statusCode = status;
345
+ x.res.setHeader("content-length", payload.byteLength);
346
+ } catch (error) {
347
+ for (const name of x.res.getHeaderNames()) x.res.removeHeader(name);
348
+ throw new HostError("invalid value", `http: unusable response headers: ${String(error)}`);
349
+ }
350
+ x.answered = true;
351
+ open--;
352
+ x.res.end(payload);
353
+ };
354
+ const pumped = (group, result) => {
355
+ const byDelivery = exchanges.get(group);
356
+ let byRun = runs.get(group);
357
+ const ofRun = (run) => {
358
+ const d = run === void 0 ? void 0 : byRun?.get(run);
359
+ return d === void 0 ? void 0 : byDelivery?.get(d);
360
+ };
361
+ for (const report of result.reports) switch (report.kind) {
362
+ case "stop":
363
+ for (const r of registrations.values()) if (r.owner.group === group && r.owner.script === report.script) remove(r);
364
+ break;
365
+ case "run started": {
366
+ const x = report.delivery && byDelivery?.get(report.delivery);
367
+ if (x) {
368
+ x.run = report.run;
369
+ if (!byRun) {
370
+ byRun = /* @__PURE__ */ new Map();
371
+ runs.set(group, byRun);
372
+ }
373
+ byRun.set(report.run, report.delivery);
374
+ }
375
+ break;
376
+ }
377
+ case "run end": {
378
+ const x = report.delivery && byDelivery?.get(report.delivery) || ofRun(report.run);
379
+ if (x && (x.run === void 0 || x.run === report.run)) {
380
+ const why = report.outcome === "completed" ? "the Run ended without responding" : report.error ? `${report.outcome}: ${report.error.code}: ${report.error.message}` : `${report.outcome}${report.limit ? ` (${report.limit})` : ""}`;
381
+ settle(x, failed(report.outcome), why);
382
+ }
383
+ break;
384
+ }
385
+ case "unhandled": {
386
+ const x = byDelivery?.get(report.delivery);
387
+ if (x) settle(x, 404);
388
+ break;
389
+ }
390
+ case "run discarded": {
391
+ const x = ofRun(report.run);
392
+ if (x) settle(x, stopping ? 503 : 500, `run discarded: ${report.reason}`);
393
+ break;
394
+ }
395
+ case "causal work": {
396
+ const x = byDelivery?.get(report.rootDelivery);
397
+ if (x && report.liveRuns === 0 && report.queuedMessages === 0) settle(x, stopping ? 503 : 500, "its work ended without a Run");
398
+ break;
399
+ }
400
+ }
401
+ };
402
+ const detach = (group) => {
403
+ for (const r of registrations.values()) if (r.owner.group === group) remove(r);
404
+ for (const x of exchanges.get(group)?.values() ?? []) answer(x, 503);
405
+ exchanges.delete(group);
406
+ runs.delete(group);
407
+ };
408
+ const stopAccepting = () => {
409
+ stopping = true;
410
+ for (const l of listeners) if (l.server.listening) {
411
+ l.server.close();
412
+ l.server.closeIdleConnections();
413
+ }
414
+ };
415
+ const answerAll = (status) => {
416
+ for (const byDelivery of exchanges.values()) for (const x of byDelivery.values()) answer(x, status);
417
+ };
418
+ const drain = async (ms) => {
419
+ const until = Date.now() + ms;
420
+ while (open > 0 && Date.now() < until) await new Promise((resolve) => setTimeout(resolve, 10));
421
+ answerAll(503);
422
+ };
423
+ const close = async () => {
424
+ stopAccepting();
425
+ answerAll(503);
426
+ const closing = [...listeners].map((l) => new Promise((resolve) => {
427
+ if (!l.server.listening) {
428
+ resolve();
429
+ return;
430
+ }
431
+ l.server.close(() => resolve());
432
+ l.server.closeAllConnections();
433
+ }));
434
+ for (const l of listeners) {
435
+ for (const { call } of l.pending) call.fail(hostErrorOf("bad address", "the Host is closing"));
436
+ l.pending = [];
437
+ }
438
+ listeners.clear();
439
+ byAddress.clear();
440
+ registrations.clear();
441
+ await Promise.all(closing);
442
+ };
443
+ return {
444
+ impl: {
445
+ serve,
446
+ unserve,
447
+ respond
448
+ },
449
+ addresses: () => [...listeners].flatMap((l) => l.address ? [{ ...l.address }] : []),
450
+ close,
451
+ detach,
452
+ drain,
453
+ onPump: (group) => (result) => pumped(group, result),
454
+ get openExchanges() {
455
+ return open;
456
+ },
457
+ pumped,
458
+ get registrations() {
459
+ return registrations.size;
460
+ },
461
+ stopAccepting
462
+ };
463
+ };
464
+ //#endregion
465
+ export { HTTP_DEFAULT_MAX_BODY_BYTES, createHttpHost, requestFields };
package/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { $ as RunAccounting, $t as shape, A as restore, An as TokType, At as Call, B as Outcome, Bt as ImmediateOp, C as Requested, Cn as SemanticNode, Ct as HostObject, D as Settlement, Dn as SourceSpan, Dt as PropDef, E as Script$1, En as SemanticTree, Et as ObjectKindDef, F as codeIdentity, Fn as SyntaxRule, Ft as ErrorDecl, G as callFunction, Gt as ScopeDecl, H as RunRecord, Ht as Operation, I as compileLibrary, In as Trivia, It as FieldShape, J as loadScript, Jt as SegmentGrant, K as defaultLimits, Kt as SegmentContext, Ln as syntaxSelector, Lt as FireOp, M as LibraryOptions, Mn as SyntaxElement, Mt as CoordinatedLifecycle, N as LibrarySource, Nn as SyntaxErrorCode, Nt as Cost, O as Verdict, On as Lexer, Ot as defineObjectKind, P as OperationRef, Pn as SyntaxNode, Pt as EffectResult, Q as CausalWork, Qt as defineCapability, R as LimitName, Rn as syntaxText, Rt as Grant, S as Report, Sn as SemanticName, St as parseInstant, T as RestoreResult, Tn as SemanticToken, Tt as ObjectKind, U as Script, Ut as ReleaseHook, V as Run, Vt as LimitReached, W as UnitLoadError, Wt as ReleaseReason, X as canConvert, Xt as Shape, Y as NotImplementedError, Yt as SegmentLifecycle, Z as waitUs, Zt as SuspendingOp, _ as LoadOptions, _n as ExportKind, _t as range, an as ScriptError, at as Value, b as PumpOptions, bn as NameRole, bt as text, c as CancellationOptions, cn as CodeUnit, ct as civilDate, d as Decided, dn as Instruction, en as HostError, et as RunAncestry, f as Deciding, fn as Operand, ft as list, g as Inspection, gn as BindingKind, gt as quantity, h as GroupOptions, hn as Binding, ht as num, in as MailboxFull, it as Kind, j as Library, jn as Token, jt as CapabilityDef, k as newGroup, kn as Mode, kt as GrantDecls, l as CarryOver, ln as EventBranch, lt as dec, m as Group, mn as disassemble, mt as nothing, nn as LoadDiagnostic, nt as RunStarted, on as Body, ot as bool, p as EffectFailure, pn as UnwindEntry, pt as map, q as deliver, qt as SegmentCoordinator, rn as LoadError, rt as Decimal, sn as BodyKind, st as bytes, tn as HostErrorCode, tt as RunDiscarded, u as Counters, un as EventEntry, ut as instant, v as Message, vn as FunctionContract, vt as record, w as RestoreOptions, wn as SemanticScope, wt as ObjectElements, x as PumpResult, xn as SemanticElement, xt as formatInstant, y as PendingCall, yn as LibraryExport, z as Limits, zt as GrantContext } from "./debug-D8Z_u244.js";
2
- import { a as ManifestSpec, c as decodeJson, i as readDisplay, l as encodeJson, o as MessageDecl, r as decodeValue, s as exportManifest, t as FunctionResolver, u as encodeValue } from "./readers-Oh4tO2dK.js";
3
- import { a as SqliteImpl, c as localeCapability, d as Costs, f as TimerImpl, g as timerCapability, h as consoleCapability, i as SqliteBinding, l as CalendarImpl, m as clockCapability, n as SqlRows, o as sqliteCapability, p as calendarCapability, r as SqlValue, s as LocaleImpl, t as SqlParams, u as ConsoleImpl } from "./sqlite-capability-C7-SYdD7.js";
4
- import { a as storeCapability, i as add, n as userCapability, r as StoreImpl, t as UserImpl } from "./user-capability-CLkDsrCX.js";
5
- import { n as createCore, t as Core } from "./core-eU5KaYkz.js";
1
+
2
+ import { $n as EventEntry, $t as httpCapability, An as Outcome, At as ImmediateOp, B as CausalWork, Bn as canConvert, Bt as SegmentCoordinator, C as Requested, Cn as LibrarySource, Cr as SyntaxNode, Ct as Cost, D as SaveOptions, Dr as syntaxText, Dt as FireOp, En as compileLibrary, Er as syntaxSelector, Et as FieldShape, Fn as callFunction, Ft as PlainResult, G as Decimal, Gn as LoadError, Gt as defineCapability, H as RunAncestry, Hn as HostError, Ht as SegmentLifecycle, I as TsScript, In as defaultLimits, It as ReleaseHook, J as bool, Jn as SendFailedReason, Jt as Group, K as Kind, Kn as MailboxFull, Kt as shape, L as Verdict, Ln as deliver, Lt as ReleaseReason, M as Settlement, Mn as RunRecord, Mt as Operation, N as TsGroup, Nn as Script, Nt as Operations, O as ScriptCodeRequest, On as LimitName, Ot as Grant, Pn as UnitLoadError, Pt as PlainArg, Q as instant, Qn as EventBranch, Qt as HttpImpl, R as newGroup, Rn as loadScript, Rt as ScopeDecl, S as Report, Sn as LibraryOptions, Sr as SyntaxErrorCode, St as CoordinatedLifecycle, T as RestoreResult, Tn as codeIdentity, Tr as Trivia, Tt as ErrorDecl, U as RunDiscarded, Un as HostErrorCode, Ut as Shape, V as RunAccounting, Vn as waitUs, Vt as SegmentGrant, W as RunStarted, Wn as LoadDiagnostic, Wt as SuspendingOp, X as civilDate, Xn as BodyKind, Xt as Versions, Y as bytes, Yn as Body, Yt as Script$1, Z as dec, Zn as CodeUnit, Zt as coreVersions, _ as Message, _n as calendarCapability, _r as Lexer, _t as defineObjectKind, an as SqlParams, ar as BindingKind, at as range, b as PumpResult, bn as timerCapability, br as Token, bt as CapabilityDef, c as CancellationOptions, cn as SqliteBinding, cr as LibraryExport, ct as text, d as Decided, dn as LocaleImpl, dr as SemanticName, dt as parseInstant, en as UserImpl, er as Instruction, et as list, f as Deciding, fn as localeCapability, fr as SemanticNode, ft as HostObject, g as LoadOptions, gn as TimerImpl, gr as SourceSpan, gt as PropDef, h as Inspection, hn as Costs, hr as SemanticTree, ht as ObjectKindDef, in as storeCapability, ir as Binding, it as quantity, jn as Run, jt as LimitReached, k as ScriptSources, kn as Limits, kt as GrantContext, l as CarryOver, ln as SqliteImpl, lr as NameRole, lt as formatInstant, m as GroupOptions, mn as ConsoleImpl, mr as SemanticToken, mt as ObjectKind, nn as StoreImpl, nr as UnwindEntry, nt as nothing, on as SqlRows, or as ExportKind, ot as record, p as EffectFailure, pn as CalendarImpl, pr as SemanticScope, pt as ObjectElements, q as Value, qn as ScriptError, qt as Core, rn as add, rr as disassemble, rt as num, sn as SqlValue, sr as FunctionContract, tn as userCapability, tr as Operand, tt as map, u as Counters, un as sqliteCapability, ur as SemanticElement, ut as nowMicros, v as PendingCall, vn as clockCapability, vr as Mode, vt as GrantDecls, w as RestoreOptions, wn as OperationRef, wr as SyntaxRule, wt as EffectResult, x as PumpedRequest, xn as Library, xr as SyntaxElement, xt as CapabilityDefiner, y as PumpOptions, yn as consoleCapability, yr as TokType, yt as Call, z as restore, zn as NotImplementedError, zt as SegmentContext } from "./debug-CQBxKnJB.js";
3
+ import { a as encodeJson, c as PlainValue, d as toValue, f as talk, i as decodeJson, l as ToValueOptions, n as MessageDecl, o as encodeValue, r as exportManifest, s as FromValueOptions, t as ManifestSpec, u as fromValue } from "./manifest-BscyH_rW.js";
4
+ import { n as createCore, t as TsCore } from "./core-DptnvQT9.js";
5
+ import { a as decodeValue, o as readDisplay, t as FunctionResolver } from "./readers-BFPuosPk.js";
6
6
  //#region src/generated/syntax.d.ts
7
7
  export declare const grammar: {
8
8
  reserved: string[];
@@ -43,7 +43,7 @@ export declare const units: ({
43
43
  calendar: boolean;
44
44
  factor: string[];
45
45
  })[];
46
- declare const diagnosticCodes: readonly ["unknown name", "not a value", "name clash", "duplicate name", "duplicate offer", "not in recovery", "leaves recovery catch", "duplicate key", "unknown kind", "no conversion", "bad number", "pattern too large", "wrong argument count", "wrong argument", "unknown operation", "wrong mode", "missing and wait", "needless and wait", "can't suspend here", "unknown import", "import cycle", "missing grant", "not in a library", "not in a script", "not in a lambda", "not in a guard", "not in a whose", "not in a join", "empty join", "not in a timeout", "empty timeout", "leaves finally", "outside a loop", "veto outside a decision", "after a suspension", "wrong message", "bad suffixes", "can't write", "not a property", "not constant", "default order", "initialiser failed", "nothing to fold", "no item chunk", "capture in repetition", "rest not last", "bits not whole bytes"];
46
+ declare const diagnosticCodes: readonly ["unknown name", "not a value", "name clash", "duplicate name", "duplicate offer", "not in recovery", "leaves recovery catch", "duplicate key", "unknown kind", "no conversion", "bad number", "pattern too large", "wrong argument count", "wrong argument", "wrong labels", "unknown operation", "wrong mode", "missing and wait", "needless and wait", "can't suspend here", "unknown import", "import cycle", "missing grant", "not in a library", "not in a script", "not in a lambda", "not in a guard", "not in a whose", "not in a join", "empty join", "not in a timeout", "empty timeout", "leaves finally", "outside a loop", "veto outside a decision", "after a suspension", "wrong message", "bad suffixes", "can't write", "not a property", "not constant", "default order", "initialiser failed", "nothing to fold", "no item chunk", "capture in repetition", "rest not last", "bits not whole bytes"];
47
47
  export declare const builtins: readonly [{
48
48
  readonly name: "min";
49
49
  readonly kind: "function";
@@ -316,6 +316,22 @@ export declare const builtins: readonly [{
316
316
  readonly total: 2;
317
317
  readonly variadic: false;
318
318
  };
319
+ }, {
320
+ readonly name: "degrees";
321
+ readonly kind: "function";
322
+ readonly contract: {
323
+ readonly required: 1;
324
+ readonly total: 1;
325
+ readonly variadic: false;
326
+ };
327
+ }, {
328
+ readonly name: "radians";
329
+ readonly kind: "function";
330
+ readonly contract: {
331
+ readonly required: 1;
332
+ readonly total: 1;
333
+ readonly variadic: false;
334
+ };
319
335
  }, {
320
336
  readonly name: "random";
321
337
  readonly kind: "function";
@@ -586,16 +602,6 @@ type CheckResult = (SemanticResult & {
586
602
  export declare const checkSyntax: (syntax: SyntaxNode, options?: CheckOptions) => SemanticResult;
587
603
  export declare const checkSource: (source: string, options?: CheckOptions) => CheckResult;
588
604
  //#endregion
589
- //#region src/versions.d.ts
590
- type Versions = {
591
- core: string;
592
- costModel: string;
593
- language: string;
594
- saveFormat: string;
595
- unicode: string;
596
- };
597
- export declare const coreVersions: Versions;
598
- //#endregion
599
605
  //#region src/lowering.d.ts
600
606
  /** A construct whose lowering the Spec leaves unsettled; not a load diagnostic. */
601
607
  export declare class LoweringError extends Error {
@@ -642,4 +648,4 @@ export declare const declarationStart: (root: SyntaxNode, declaration: SyntaxNod
642
648
  //#region src/selectors.d.ts
643
649
  export declare const validMessageSelector: (message: string, arity: number) => boolean;
644
650
  //#endregion
645
- export { type Binding, type BindingKind, type Body, type BodyKind, type CalendarImpl, type Call, type CancellationOptions, type CapabilityDef, type CarryOver, type CausalWork, type CheckOptions, type CheckResult, type CodeUnit, type CompileOptions, type CompileResult, type ConsoleImpl, type CoordinatedLifecycle, type Core, type Cost, type Costs, type Counters, type Decided, type Deciding, Decimal, type Diagnostic, type DiagnosticCode, type EffectFailure, type EffectResult, type EntryKind, type EntryResult, type ErrorDecl, type EventBranch, type EventEntry, type ExportKind, type FieldShape, type FireOp, type FunctionContract, type FunctionResolver, type Grant, type GrantContext, type GrantDecls, Group, type GroupOptions, HostError, type HostErrorCode, type HostObject, type ImmediateOp, type Inspection, type Instruction, type Kind, Lexer, type Library, type LibraryExport, type LibraryOptions, type LibrarySource, type LimitName, LimitReached, type Limits, type LoadDiagnostic, LoadError, type LoadOptions, type LocaleImpl, MailboxFull, type ManifestSpec, type Message, type MessageDecl, type Mode, type NameRole, NotImplementedError, type ObjectElements, type ObjectKind, type ObjectKindDef, type Operand, type Operation, type OperationRef, type Outcome, type ParseResult, type PendingCall, type PropDef, type PumpOptions, type PumpResult, type RecoveringParseResult, type RecoveryDiagnostic, type ReleaseHook, type ReleaseReason, type Report, type Requested, type RestoreOptions, type RestoreResult, Run, type RunAccounting, type RunAncestry, type RunDiscarded, type RunRecord, type RunStarted, type ScopeDecl, Script, ScriptError, Script$1 as ScriptHandle, type SegmentContext, type SegmentCoordinator, type SegmentGrant, type SegmentLifecycle, type SemanticElement, type SemanticName, type SemanticNode, type SemanticResult, type SemanticScope, type SemanticToken, type SemanticTree, type Settlement, type Shape, type SourceSpan, type SqlParams, type SqlRows, type SqlValue, type SqliteBinding, type SqliteImpl, type StoreImpl, type SuspendingOp, type SyntaxElement, type SyntaxErrorCode, type SyntaxNode, type SyntaxRule, type TimerImpl, type TokType, type Token, type Trivia, UnitLoadError, type UnwindEntry, type UserImpl, Value, type Verdict, type Versions, add, bool, bytes, calendarCapability, callFunction, canConvert, civilDate, clockCapability, codeIdentity, compileLibrary, consoleCapability, createCore, dec, decodeJson, decodeValue, defaultLimits, defineCapability, defineObjectKind, deliver, disassemble, encodeJson, encodeValue, exportManifest, formatInstant, instant, list, loadScript, localeCapability, map, newGroup, nothing, num, parseInstant, quantity, range, readDisplay, record, restore, shape, sqliteCapability, storeCapability, syntaxSelector, syntaxText, text, timerCapability, userCapability, waitUs };
651
+ export { type Binding, type BindingKind, type Body, type BodyKind, type CalendarImpl, type Call, type CancellationOptions, type CapabilityDef, type CapabilityDefiner, type CarryOver, type CausalWork, type CheckOptions, type CheckResult, type CodeUnit, type CompileOptions, type CompileResult, Script as CompiledScript, type ConsoleImpl, type CoordinatedLifecycle, type Core, type Cost, type Costs, type Counters, type Decided, type Deciding, Decimal, type Diagnostic, type DiagnosticCode, type EffectFailure, type EffectResult, type EntryKind, type EntryResult, type ErrorDecl, type EventBranch, type EventEntry, type ExportKind, type FieldShape, type FireOp, type FromValueOptions, type FunctionContract, type FunctionResolver, type Grant, type GrantContext, type GrantDecls, type Group, type GroupOptions, HostError, type HostErrorCode, type HostObject, type HttpImpl, type ImmediateOp, type Inspection, type Instruction, type Kind, Lexer, type Library, type LibraryExport, type LibraryOptions, type LibrarySource, type LimitName, LimitReached, type Limits, type LoadDiagnostic, LoadError, type LoadOptions, type LocaleImpl, MailboxFull, type ManifestSpec, type Message, type MessageDecl, type Mode, type NameRole, NotImplementedError, type ObjectElements, type ObjectKind, type ObjectKindDef, type Operand, type Operation, type OperationRef, type Operations, type Outcome, type ParseResult, type PendingCall, type PlainArg, type PlainResult, type PlainValue, type PropDef, type PumpOptions, type PumpResult, type PumpedRequest, type RecoveringParseResult, type RecoveryDiagnostic, type ReleaseHook, type ReleaseReason, type Report, type Requested, type RestoreOptions, type RestoreResult, Run, type RunAccounting, type RunAncestry, type RunDiscarded, type RunRecord, type RunStarted, type SaveOptions, type ScopeDecl, type Script$1 as Script, type ScriptCodeRequest, ScriptError, type ScriptSources, type SegmentContext, type SegmentCoordinator, type SegmentGrant, type SegmentLifecycle, type SemanticElement, type SemanticName, type SemanticNode, type SemanticResult, type SemanticScope, type SemanticToken, type SemanticTree, type SendFailedReason, type Settlement, type Shape, type SourceSpan, type SqlParams, type SqlRows, type SqlValue, type SqliteBinding, type SqliteImpl, type StoreImpl, type SuspendingOp, type SyntaxElement, type SyntaxErrorCode, type SyntaxNode, type SyntaxRule, type TimerImpl, type ToValueOptions, type TokType, type Token, type Trivia, type TsCore, TsGroup, TsScript, UnitLoadError, type UnwindEntry, type UserImpl, Value, type Verdict, type Versions, add, bool, bytes, calendarCapability, callFunction, canConvert, civilDate, clockCapability, codeIdentity, compileLibrary, consoleCapability, coreVersions, createCore, dec, decodeJson, decodeValue, defaultLimits, defineCapability, defineObjectKind, deliver, disassemble, encodeJson, encodeValue, exportManifest, formatInstant, fromValue, httpCapability, instant, list, loadScript, localeCapability, map, newGroup, nothing, nowMicros, num, parseInstant, quantity, range, readDisplay, record, restore, shape, sqliteCapability, storeCapability, syntaxSelector, syntaxText, talk, text, timerCapability, toValue, userCapability, waitUs };
package/index.js CHANGED
@@ -1,18 +1,23 @@
1
- import { $ as builtins, F as quantity, Gt as parseInstant, Ht as formatInstant, L as range, M as num, R as record, S as instant, T as list, V as text, c as bool, f as civilDate, h as dec, i as ScriptError, it as units, j as nothing, k as map, l as bytes, mt as unicodeVersion, n as LoadError, o as Decimal, r as MailboxFull, s as Value, t as HostError, tt as grammar } from "./errors-DHwz1Vho.js";
2
- import { n as exportManifest, o as defineObjectKind } from "./manifest-DKe2Je6Z.js";
3
- import { St as Lexer, dt as costModel, et as disassemble, g as canConvert, gt as LimitReached, l as NotImplementedError, o as validMessageSelector, pt as languageVersion, q as waitUs, t as encodeValue, vt as defineCapability, xt as shape } from "./encoding-DWlbPq-e.js";
4
- import { A as ParseError, C as compileSource, D as checkSyntax, E as checkSource, F as declarationStart, M as parseSource, N as parseSourceRecovering, O as syntaxSelector, S as LoweringError, T as lowerTree, _ as UnitLoadError, b as deliver, d as codeIdentity, f as compileLibrary, g as Script, h as Run, j as parseEntry, k as syntaxText, m as stdlibSources, n as Script$1, r as newGroup, s as restore, t as Group, v as callFunction, w as exportsOf, x as loadScript, y as defaultLimits } from "./group-B4eyJKTA.js";
5
- import { i as readDisplay, t as decodeValue } from "./readers-DyjxJEkL.js";
6
- import { n as decodeJson, r as encodeJson, t as sqliteCapability } from "./sqlite-capability-CrCej3Po.js";
7
- import { n as localeCapability, t as userCapability } from "./user-capability-Cv0oJhhv.js";
8
- import { a as clockCapability, i as calendarCapability, l as timerCapability, o as consoleCapability, r as storeCapability, t as add } from "./store-capability-CDoVafZL.js";
1
+
2
+ import { B as range, F as num, K as text, M as map, O as list, P as nothing, Qt as parseInstant, R as quantity, V as record, Xt as nowMicros, _ as dec, c as Decimal, d as bytes, i as ScriptError, it as builtins, l as Value, lt as units, m as civilDate, n as LoadError, ot as grammar, qt as formatInstant, r as MailboxFull, t as HostError, u as bool, w as instant, yt as unicodeVersion } from "./errors-LYJZ_c8h.js";
3
+ import { t as defineObjectKind } from "./objects-Db7IB5vQ.js";
4
+ import { i as defineCapability, m as Lexer, p as validMessageSelector, t as LimitReached, u as shape } from "./capabilities-CH0FkRMq.js";
5
+ import { a as ParseError, c as parseSourceRecovering, i as syntaxText, n as checkSyntax, o as parseEntry, p as declarationStart, r as syntaxSelector, s as parseSource, t as checkSource } from "./checker-Dc1jl2WH.js";
6
+ import { U as waitUs, Z as disassemble, ct as costModel, r as NotImplementedError, u as canConvert, ut as languageVersion } from "./base64-DORMd3Hv.js";
7
+ import { _ as loadScript, b as exportsOf, c as compileLibrary, d as Run, f as Script, g as deliver, h as defaultLimits, i as restore, m as callFunction, n as TsScript, p as UnitLoadError, r as newGroup, s as codeIdentity, t as TsGroup, u as stdlibSources, v as LoweringError, x as lowerTree, y as compileSource } from "./group-B742gg4T.js";
8
+ import { c as readDisplay, r as decodeValue } from "./readers-CjJHKHvH.js";
9
+ import { t as encodeValue } from "./encoding-nlrpj-Pb.js";
10
+ import { n as exportManifest } from "./manifest-DjsxDSuB.js";
11
+ import { a as fromValue, i as encodeJson, n as sqliteCapability, o as toValue, r as decodeJson, s as talk, t as httpCapability } from "./http-capability-CSTkw1Yt.js";
12
+ import { n as localeCapability, t as userCapability } from "./user-capability-BK4Asg7D.js";
13
+ import { a as clockCapability, i as calendarCapability, l as timerCapability, o as consoleCapability, r as storeCapability, t as add } from "./store-capability-OZp4hXmj.js";
9
14
  //#region src/versions.ts
10
15
  const coreVersions = Object.freeze({
11
16
  language: languageVersion,
12
17
  costModel: String(costModel.version),
13
18
  unicode: unicodeVersion,
14
- core: "ts/0.1.0",
15
- saveFormat: String(9)
19
+ core: "ts/0.2.0",
20
+ saveFormat: String(11)
16
21
  });
17
22
  //#endregion
18
23
  //#region src/core.ts
@@ -27,11 +32,13 @@ const core = Object.freeze({
27
32
  storeCapability,
28
33
  sqliteCapability,
29
34
  userCapability,
35
+ httpCapability,
30
36
  compileLibrary,
31
37
  newGroup,
32
- restore
38
+ restore,
39
+ versions: coreVersions
33
40
  });
34
41
  /** Return the process-wide Core, also used by the free-function helpers. */
35
42
  const createCore = () => core;
36
43
  //#endregion
37
- export { Decimal, Group, HostError, Lexer, LimitReached, LoadError, LoweringError, MailboxFull, NotImplementedError, ParseError, Run, Script, ScriptError, Script$1 as ScriptHandle, UnitLoadError, Value, add, bool, builtins, bytes, calendarCapability, callFunction, canConvert, checkSource, checkSyntax, civilDate, clockCapability, codeIdentity, compileLibrary, compileSource, consoleCapability, coreVersions, createCore, dec, declarationStart, decodeJson, decodeValue, defaultLimits, defineCapability, defineObjectKind, deliver, disassemble, encodeJson, encodeValue, exportManifest, exportsOf, formatInstant, grammar, instant, list, loadScript, localeCapability, lowerTree, map, newGroup, nothing, num, parseEntry, parseInstant, parseSource, parseSourceRecovering, quantity, range, readDisplay, record, restore, shape, sqliteCapability, stdlibSources, storeCapability, syntaxSelector, syntaxText, text, timerCapability, units, userCapability, validMessageSelector, waitUs };
44
+ export { Script as CompiledScript, Decimal, HostError, Lexer, LimitReached, LoadError, LoweringError, MailboxFull, NotImplementedError, ParseError, Run, ScriptError, TsGroup, TsScript, UnitLoadError, Value, add, bool, builtins, bytes, calendarCapability, callFunction, canConvert, checkSource, checkSyntax, civilDate, clockCapability, codeIdentity, compileLibrary, compileSource, consoleCapability, coreVersions, createCore, dec, declarationStart, decodeJson, decodeValue, defaultLimits, defineCapability, defineObjectKind, deliver, disassemble, encodeJson, encodeValue, exportManifest, exportsOf, formatInstant, fromValue, grammar, httpCapability, instant, list, loadScript, localeCapability, lowerTree, map, newGroup, nothing, nowMicros, num, parseEntry, parseInstant, parseSource, parseSourceRecovering, quantity, range, readDisplay, record, restore, shape, sqliteCapability, stdlibSources, storeCapability, syntaxSelector, syntaxText, talk, text, timerCapability, toValue, units, userCapability, validMessageSelector, waitUs };