@almadar/core 10.129.0 → 11.0.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/dist/behavior-package.d.ts +49 -11
- package/dist/behavior-package.js +1 -1
- package/dist/{orbital-CkFdDS9f.d.ts → builders-BhnofAik.d.ts} +5966 -7116
- package/dist/builders.d.ts +6 -6
- package/dist/builders.js +7 -6
- package/dist/{bus-CcbB__oo.d.ts → bus-BrRFWDQK.d.ts} +270 -354
- package/dist/chunk-347APWFM.js +286 -0
- package/dist/chunk-347APWFM.js.map +1 -0
- package/dist/chunk-3URQAGD7.js +98 -0
- package/dist/chunk-3URQAGD7.js.map +1 -0
- package/dist/chunk-7GHJU5WI.js +39 -0
- package/dist/chunk-7GHJU5WI.js.map +1 -0
- package/dist/chunk-B4MNHGBP.js +8 -0
- package/dist/chunk-B4MNHGBP.js.map +1 -0
- package/dist/{chunk-KDMV222Q.js → chunk-F6KHUW7T.js} +304 -373
- package/dist/chunk-F6KHUW7T.js.map +1 -0
- package/dist/chunk-FGT5OS2Y.js +918 -0
- package/dist/chunk-FGT5OS2Y.js.map +1 -0
- package/dist/chunk-FQLEAMAB.js +24 -0
- package/dist/chunk-FQLEAMAB.js.map +1 -0
- package/dist/chunk-HEXOGHQ4.js +3264 -0
- package/dist/chunk-HEXOGHQ4.js.map +1 -0
- package/dist/chunk-JCD6GLBX.js +412 -0
- package/dist/chunk-JCD6GLBX.js.map +1 -0
- package/dist/{chunk-QUOTJULD.js → chunk-MGLG2XLD.js} +20 -219
- package/dist/chunk-MGLG2XLD.js.map +1 -0
- package/dist/chunk-MTBEBSNO.js +1293 -0
- package/dist/chunk-MTBEBSNO.js.map +1 -0
- package/dist/{chunk-X4SC7FGF.js → chunk-RGACZEYC.js} +99 -96
- package/dist/chunk-RGACZEYC.js.map +1 -0
- package/dist/{chunk-RYPVOI6H.js → chunk-UZPYYI37.js} +524 -26
- package/dist/{chunk-RYPVOI6H.js.map → chunk-UZPYYI37.js.map} +1 -1
- package/dist/chunk-VG7BRFUD.js +152 -0
- package/dist/chunk-VG7BRFUD.js.map +1 -0
- package/dist/chunk-Y2DYZPP5.js +2329 -0
- package/dist/chunk-Y2DYZPP5.js.map +1 -0
- package/dist/chunk-ZEI7C32D.js +1566 -0
- package/dist/chunk-ZEI7C32D.js.map +1 -0
- package/dist/{domain-Dz3jP-UM.d.ts → domain-CfKPpXCP.d.ts} +51 -51
- package/dist/{effect-result-Bebwu9yT.d.ts → effect-result-DPERsn_v.d.ts} +641 -851
- package/dist/{effect-CiEVLsZz.d.ts → effect-wP-IdRt2.d.ts} +236 -443
- package/dist/{expression-D0Fs0riG.d.ts → expression-DirYKz-f.d.ts} +5 -13
- package/dist/factory/index.d.ts +7 -144
- package/dist/factory/index.js +8 -8
- package/dist/factory-runtime/index.d.ts +7 -6
- package/dist/factory-runtime/index.js +527 -8
- package/dist/factory-runtime/index.js.map +1 -1
- package/dist/fixtures.d.ts +9 -11
- package/dist/fixtures.js +12 -8
- package/dist/fixtures.js.map +1 -1
- package/dist/i18n/index.d.ts +15 -19
- package/dist/i18n/index.js +2 -1
- package/dist/{index-BC-Jycqj.d.ts → index-DomgmRBG.d.ts} +29 -729
- package/dist/index.d.ts +69 -247
- package/dist/index.js +322 -986
- package/dist/index.js.map +1 -1
- package/dist/kernel-wire.d.ts +3 -3
- package/dist/kernel-wire.js +3 -79
- package/dist/kernel-wire.js.map +1 -1
- package/dist/language/constructs.json +22 -2
- package/dist/language/program-types.json +203 -22
- package/dist/language/protocols.json +46 -0
- package/dist/language/ui-vocabulary.json +1697 -0
- package/dist/language/validation-codes.json +1205 -1215
- package/dist/language/vocabulary.json +44 -8
- package/dist/language-data.d.ts +7 -4
- package/dist/language-data.js +20 -14
- package/dist/language-data.js.map +1 -1
- package/dist/patterns/component-mapping.json +11 -1
- package/dist/patterns/definitions.d.ts +2 -2
- package/dist/patterns/definitions.js +1 -1
- package/dist/patterns/event-contracts.json +1 -15
- package/dist/patterns/index.d.ts +24 -120
- package/dist/patterns/index.js +3 -3
- package/dist/patterns/patterns-registry.json +522 -24
- package/dist/patterns/registry.json +522 -24
- package/dist/trait-CzG9M89M.d.ts +3519 -0
- package/dist/types/index.d.ts +9 -10
- package/dist/types/index.js +11 -5
- package/dist/{types-DGwrltUF.d.ts → types-BHlTjwWd.d.ts} +3 -3
- package/fixtures/events-wire/client-effects-by-trait/response.json +0 -18
- package/fixtures/events-wire/client-effects-provenance/response.json +0 -18
- package/fixtures/events-wire/effect-results-every-kind/response.json +2 -27
- package/fixtures/events-wire/navigate-1/response.json +8 -5
- package/fixtures/events-wire/navigate-2/response.json +11 -8
- package/fixtures/events-wire/navigate-3/response.json +14 -11
- package/fixtures/events-wire/navigate-back/response.json +7 -4
- package/fixtures/events-wire/render-ui-3/response.json +12 -9
- package/fixtures/events-wire/render-ui-clear/response.json +0 -7
- package/fixtures/events-wire/sse-stream/response.json +0 -20
- package/fixtures/events-wire/sse-stream/stream.json +0 -20
- package/fixtures/events-wire/stateless-traits/response.json +14 -5
- package/fixtures/kernel-wire/golden/basic-entity.json +1687 -0
- package/fixtures/kernel-wire/golden/entity-rerender.json +743 -0
- package/fixtures/kernel-wire/golden/rollback.json +793 -0
- package/fixtures/kernel-wire/golden/tick-counter.json +1538 -0
- package/fixtures/kernel-wire/golden/two-orbital-chore.json +847 -0
- package/fixtures/kernel-wire/golden/two-orbital-task.json +457 -0
- package/fixtures/kernel-wire/played-step.json +136 -0
- package/fixtures/kernel-wire/scripts/basic-entity.json +28 -0
- package/fixtures/kernel-wire/scripts/entity-rerender.json +13 -0
- package/fixtures/kernel-wire/scripts/rollback.json +53 -0
- package/fixtures/kernel-wire/scripts/tick-counter.json +26 -0
- package/fixtures/kernel-wire/scripts/two-orbital-chore.json +9 -0
- package/fixtures/kernel-wire/scripts/two-orbital-task.json +9 -0
- package/package.json +28 -19
- package/dist/builders-DmZE5By0.d.ts +0 -2663
- package/dist/chunk-45I2O4SJ.js +0 -4646
- package/dist/chunk-45I2O4SJ.js.map +0 -1
- package/dist/chunk-6LR43Z5E.js +0 -3061
- package/dist/chunk-6LR43Z5E.js.map +0 -1
- package/dist/chunk-GIUA3NUJ.js +0 -809
- package/dist/chunk-GIUA3NUJ.js.map +0 -1
- package/dist/chunk-GTY53NS5.js +0 -1908
- package/dist/chunk-GTY53NS5.js.map +0 -1
- package/dist/chunk-JOHDVS6J.js +0 -1614
- package/dist/chunk-JOHDVS6J.js.map +0 -1
- package/dist/chunk-KDMV222Q.js.map +0 -1
- package/dist/chunk-QRHJUS3D.js +0 -23
- package/dist/chunk-QRHJUS3D.js.map +0 -1
- package/dist/chunk-QUOTJULD.js.map +0 -1
- package/dist/chunk-V5VNGRVU.js +0 -66
- package/dist/chunk-V5VNGRVU.js.map +0 -1
- package/dist/chunk-X4SC7FGF.js.map +0 -1
- package/dist/entityAccess-BPSz1i2n.d.ts +0 -80
- package/dist/mock/index.d.ts +0 -153
- package/dist/mock/index.js +0 -190
- package/dist/mock/index.js.map +0 -1
- package/dist/schema-T5RT5s6H.d.ts +0 -282
- package/dist/state-machine/index.d.ts +0 -359
- package/dist/state-machine/index.js +0 -3
- package/dist/state-machine/index.js.map +0 -1
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { setOwn } from './chunk-B4MNHGBP.js';
|
|
2
|
+
import { JsonValueSchema } from './chunk-7GHJU5WI.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
var SExprDataSchema = z.lazy(
|
|
6
|
+
() => z.union([SExprAtomSchema, z.array(SExprDataSchema)])
|
|
7
|
+
);
|
|
8
|
+
var SExprAtomSchema = z.union([
|
|
9
|
+
z.string(),
|
|
10
|
+
z.number(),
|
|
11
|
+
z.boolean(),
|
|
12
|
+
z.null(),
|
|
13
|
+
z.record(z.string(), SExprDataSchema)
|
|
14
|
+
// Objects for payload data
|
|
15
|
+
]);
|
|
16
|
+
var SExprSchema = z.lazy(
|
|
17
|
+
() => z.union([
|
|
18
|
+
SExprAtomSchema,
|
|
19
|
+
z.array(SExprDataSchema).min(1).refine(
|
|
20
|
+
(arr) => typeof arr[0] === "string",
|
|
21
|
+
{ message: "S-expression array must have a string operator as first element" }
|
|
22
|
+
)
|
|
23
|
+
])
|
|
24
|
+
);
|
|
25
|
+
var ExpressionSchema = SExprSchema;
|
|
26
|
+
var SExprListSchema = z.array(SExprSchema);
|
|
27
|
+
function isSExpr(value) {
|
|
28
|
+
return Array.isArray(value) && value.length > 0 && typeof value[0] === "string";
|
|
29
|
+
}
|
|
30
|
+
function isSExprAtom(value) {
|
|
31
|
+
if (value === null) return true;
|
|
32
|
+
if (Array.isArray(value)) return false;
|
|
33
|
+
const type = typeof value;
|
|
34
|
+
return type === "string" || type === "number" || type === "boolean" || type === "object";
|
|
35
|
+
}
|
|
36
|
+
function isBinding(value) {
|
|
37
|
+
return typeof value === "string" && value.startsWith("@");
|
|
38
|
+
}
|
|
39
|
+
function isSExprCall(value) {
|
|
40
|
+
return isSExpr(value);
|
|
41
|
+
}
|
|
42
|
+
var CORE_BINDINGS = ["entity", "payload", "state", "now", "config", "computed", "trait", "user", "callsitePayload", "pages", "currentTheme"];
|
|
43
|
+
function parseBinding(binding) {
|
|
44
|
+
if (!binding.startsWith("@")) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const withoutPrefix = binding.slice(1);
|
|
48
|
+
const parts = withoutPrefix.split(".");
|
|
49
|
+
if (parts.length === 0 || parts[0] === "") {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const root = parts[0];
|
|
53
|
+
const path = parts.slice(1);
|
|
54
|
+
const isCore = CORE_BINDINGS.includes(root);
|
|
55
|
+
return {
|
|
56
|
+
type: isCore ? "core" : "entity",
|
|
57
|
+
root,
|
|
58
|
+
path,
|
|
59
|
+
original: binding
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function isValidBinding(binding) {
|
|
63
|
+
const parsed = parseBinding(binding);
|
|
64
|
+
if (!parsed) return false;
|
|
65
|
+
if (parsed.type === "core") {
|
|
66
|
+
if (parsed.root === "state" || parsed.root === "now") {
|
|
67
|
+
return parsed.path.length === 0;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return parsed.path.length > 0;
|
|
72
|
+
}
|
|
73
|
+
function getOperator(expr) {
|
|
74
|
+
if (!isSExpr(expr)) return null;
|
|
75
|
+
return expr[0];
|
|
76
|
+
}
|
|
77
|
+
function formatSExpr(expr) {
|
|
78
|
+
if (expr === null) return "null";
|
|
79
|
+
if (typeof expr === "string") return isBinding(expr) ? expr : JSON.stringify(expr);
|
|
80
|
+
if (typeof expr === "number" || typeof expr === "boolean") return String(expr);
|
|
81
|
+
if (Array.isArray(expr)) {
|
|
82
|
+
const quoted = quoteBodyOf(expr);
|
|
83
|
+
if (quoted !== void 0) return `(${QUOTE_HEAD} ${formatSExpr(decodeQuoteBody(quoted))})`;
|
|
84
|
+
const qq = quasiquoteOf(expr);
|
|
85
|
+
if (qq !== void 0) return `(${QUASIQUOTE_HEAD} ${formatTemplate(decodeQuoteBody(qq.body), qq.holes)})`;
|
|
86
|
+
const op = getOperator(expr);
|
|
87
|
+
if (op !== null) return `(${[op, ...expr.slice(1).map(formatSExpr)].join(" ")})`;
|
|
88
|
+
return `[${expr.map(formatSExpr).join(" ")}]`;
|
|
89
|
+
}
|
|
90
|
+
const entries = Object.keys(expr).sort().map((k) => `${k}: ${formatSExpr(expr[k])}`);
|
|
91
|
+
return entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`;
|
|
92
|
+
}
|
|
93
|
+
function getArgs(expr) {
|
|
94
|
+
if (!isSExpr(expr)) return [];
|
|
95
|
+
return expr.slice(1);
|
|
96
|
+
}
|
|
97
|
+
function sexpr(operator, ...args) {
|
|
98
|
+
return [operator, ...args];
|
|
99
|
+
}
|
|
100
|
+
function walkSExpr(expr, visitor, parent = null, index = 0) {
|
|
101
|
+
visitor(expr, parent, index);
|
|
102
|
+
if (isSExpr(expr)) {
|
|
103
|
+
for (let i = 0; i < expr.length; i++) {
|
|
104
|
+
walkSExpr(expr[i], visitor, expr, i);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function collectBindings(expr) {
|
|
109
|
+
const bindings = [];
|
|
110
|
+
walkSExpr(expr, (node) => {
|
|
111
|
+
if (isBinding(node)) {
|
|
112
|
+
bindings.push(node);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return bindings;
|
|
116
|
+
}
|
|
117
|
+
function isEventPayloadValue(value) {
|
|
118
|
+
if (value === null) return true;
|
|
119
|
+
const kind = typeof value;
|
|
120
|
+
if (kind === "string" || kind === "number" || kind === "boolean") return true;
|
|
121
|
+
if (Array.isArray(value)) return value.every((item) => isEventPayloadValue(item));
|
|
122
|
+
if (kind === "object" && typeof value === "object" && !(value instanceof Date)) {
|
|
123
|
+
return Object.values(value).every((item) => isEventPayloadValue(item));
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
var EventPayloadValueSchema = JsonValueSchema;
|
|
128
|
+
var EventPayloadSchema = z.record(z.string(), JsonValueSchema);
|
|
129
|
+
function isStaticallyFalse(expr, resolve) {
|
|
130
|
+
const known = (e) => {
|
|
131
|
+
if (typeof e === "string" && e.startsWith("@") && resolve !== void 0) {
|
|
132
|
+
const value2 = resolve(e);
|
|
133
|
+
return value2 === void 0 ? e : value2;
|
|
134
|
+
}
|
|
135
|
+
return e;
|
|
136
|
+
};
|
|
137
|
+
const isLiteral = (e) => e === null || typeof e === "boolean" || typeof e === "number" || typeof e === "string" && !e.startsWith("@");
|
|
138
|
+
const value = known(expr);
|
|
139
|
+
if (value === false || value === null) return true;
|
|
140
|
+
if (typeof value === "number") return value === 0;
|
|
141
|
+
if (typeof value === "string") return value === "";
|
|
142
|
+
if (Array.isArray(value)) {
|
|
143
|
+
const op = value[0];
|
|
144
|
+
if (typeof op !== "string") return value.length === 0;
|
|
145
|
+
const args = value.slice(1);
|
|
146
|
+
switch (op) {
|
|
147
|
+
case "and":
|
|
148
|
+
return args.some((a) => isStaticallyFalse(a, resolve));
|
|
149
|
+
case "or":
|
|
150
|
+
return args.length > 0 && args.every((a) => isStaticallyFalse(a, resolve));
|
|
151
|
+
case "not":
|
|
152
|
+
return args.length === 1 && known(args[0]) === true;
|
|
153
|
+
case "==":
|
|
154
|
+
case "!=": {
|
|
155
|
+
if (args.length !== 2) return false;
|
|
156
|
+
const [l, r] = [known(args[0]), known(args[1])];
|
|
157
|
+
if (!isLiteral(l) || !isLiteral(r)) return false;
|
|
158
|
+
return l === r === (op === "!=");
|
|
159
|
+
}
|
|
160
|
+
default:
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (typeof value === "object") return Object.keys(value).length === 0;
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
var QUOTE_HEAD = "quote";
|
|
168
|
+
function canonicalQuoteValue(expr) {
|
|
169
|
+
if (Array.isArray(expr)) return expr.map(canonicalQuoteValue);
|
|
170
|
+
if (expr !== null && typeof expr === "object") {
|
|
171
|
+
const out = {};
|
|
172
|
+
for (const key of Object.keys(expr).sort()) setOwn(out, key, canonicalQuoteValue(expr[key]));
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
return expr;
|
|
176
|
+
}
|
|
177
|
+
function encodeQuoteBody(expr) {
|
|
178
|
+
return JSON.stringify(canonicalQuoteValue(expr)).replace(/@/g, "\\u0040");
|
|
179
|
+
}
|
|
180
|
+
function decodeQuoteBody(body) {
|
|
181
|
+
const value = JSON.parse(body);
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
function quoteExpr(expr) {
|
|
185
|
+
return [QUOTE_HEAD, encodeQuoteBody(expr)];
|
|
186
|
+
}
|
|
187
|
+
function decodeQuotedValue(expr) {
|
|
188
|
+
const body = quoteBodyOf(expr);
|
|
189
|
+
return body === void 0 ? expr : decodeQuoteBody(body);
|
|
190
|
+
}
|
|
191
|
+
function quoteBodyOf(expr) {
|
|
192
|
+
return Array.isArray(expr) && expr.length === 2 && expr[0] === QUOTE_HEAD && typeof expr[1] === "string" ? expr[1] : void 0;
|
|
193
|
+
}
|
|
194
|
+
var QUASIQUOTE_HEAD = "quasiquote";
|
|
195
|
+
var UNQUOTE_HEAD = "unquote";
|
|
196
|
+
function isHeadedCall(expr, head) {
|
|
197
|
+
return Array.isArray(expr) && expr.length > 0 && expr[0] === head;
|
|
198
|
+
}
|
|
199
|
+
function containsHead(expr, head) {
|
|
200
|
+
if (isHeadedCall(expr, head)) return true;
|
|
201
|
+
if (Array.isArray(expr)) return expr.some((e) => containsHead(e, head));
|
|
202
|
+
if (expr !== null && typeof expr === "object") return Object.values(expr).some((e) => containsHead(e, head));
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
function extractHoles(expr, holes) {
|
|
206
|
+
if (isHeadedCall(expr, QUASIQUOTE_HEAD)) throw new Error("quasiquote: nested quasiquote is not supported");
|
|
207
|
+
if (isHeadedCall(expr, UNQUOTE_HEAD)) {
|
|
208
|
+
if (expr.length !== 2) throw new Error("quasiquote: (unquote e) takes exactly one expression");
|
|
209
|
+
if (containsHead(expr[1], UNQUOTE_HEAD)) throw new Error("quasiquote: unquote inside an unquote");
|
|
210
|
+
holes.push(expr[1]);
|
|
211
|
+
return [UNQUOTE_HEAD, holes.length - 1];
|
|
212
|
+
}
|
|
213
|
+
if (Array.isArray(expr)) return expr.map((e) => extractHoles(e, holes));
|
|
214
|
+
if (expr !== null && typeof expr === "object") {
|
|
215
|
+
const out = {};
|
|
216
|
+
for (const k of Object.keys(expr).sort()) setOwn(out, k, extractHoles(expr[k], holes));
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
return expr;
|
|
220
|
+
}
|
|
221
|
+
function quasiquoteExpr(template) {
|
|
222
|
+
const holes = [];
|
|
223
|
+
const body = encodeQuoteBody(extractHoles(template, holes));
|
|
224
|
+
return [QUASIQUOTE_HEAD, body, ...holes];
|
|
225
|
+
}
|
|
226
|
+
function quasiquoteOf(expr) {
|
|
227
|
+
if (!Array.isArray(expr) || expr.length < 2 || expr[0] !== QUASIQUOTE_HEAD || typeof expr[1] !== "string") {
|
|
228
|
+
return void 0;
|
|
229
|
+
}
|
|
230
|
+
return { body: expr[1], holes: expr.slice(2) };
|
|
231
|
+
}
|
|
232
|
+
function countMarkers(expr) {
|
|
233
|
+
if (isHeadedCall(expr, UNQUOTE_HEAD) && expr.length === 2 && typeof expr[1] === "number") return 1;
|
|
234
|
+
if (Array.isArray(expr)) return expr.reduce((n, e) => n + countMarkers(e), 0);
|
|
235
|
+
if (expr !== null && typeof expr === "object") return Object.values(expr).reduce((n, e) => n + countMarkers(e), 0);
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
function fillMarkers(expr, values) {
|
|
239
|
+
if (isHeadedCall(expr, UNQUOTE_HEAD) && expr.length === 2 && typeof expr[1] === "number") return values[expr[1]];
|
|
240
|
+
if (Array.isArray(expr)) return expr.map((e) => fillMarkers(e, values));
|
|
241
|
+
if (expr !== null && typeof expr === "object") {
|
|
242
|
+
const out = {};
|
|
243
|
+
for (const [k, v] of Object.entries(expr)) setOwn(out, k, fillMarkers(v, values));
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
return expr;
|
|
247
|
+
}
|
|
248
|
+
function toProgramData(value) {
|
|
249
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
if (Array.isArray(value)) return value.map((v) => toProgramData(v));
|
|
253
|
+
if (typeof value === "object" && !(value instanceof Date) && Object.getPrototypeOf(value) === Object.prototype) {
|
|
254
|
+
const out = {};
|
|
255
|
+
for (const [k, v] of Object.entries(value)) setOwn(out, k, toProgramData(v));
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
throw new Error(`quasiquote: a hole evaluated to a ${typeof value} value, which cannot be held as program data`);
|
|
259
|
+
}
|
|
260
|
+
function instantiateQuasiquote(body, values) {
|
|
261
|
+
const template = decodeQuoteBody(body);
|
|
262
|
+
const holes = countMarkers(template);
|
|
263
|
+
if (holes !== values.length) {
|
|
264
|
+
throw new Error(`quasiquote: template has ${holes} hole(s), got ${values.length} value(s)`);
|
|
265
|
+
}
|
|
266
|
+
return fillMarkers(template, values);
|
|
267
|
+
}
|
|
268
|
+
function formatTemplate(expr, holes) {
|
|
269
|
+
if (isHeadedCall(expr, UNQUOTE_HEAD) && expr.length === 2 && typeof expr[1] === "number") {
|
|
270
|
+
return `(${UNQUOTE_HEAD} ${formatSExpr(holes[expr[1]])})`;
|
|
271
|
+
}
|
|
272
|
+
if (Array.isArray(expr)) {
|
|
273
|
+
const op = getOperator(expr);
|
|
274
|
+
if (op !== null) return `(${[op, ...expr.slice(1).map((e) => formatTemplate(e, holes))].join(" ")})`;
|
|
275
|
+
return `[${expr.map((e) => formatTemplate(e, holes)).join(" ")}]`;
|
|
276
|
+
}
|
|
277
|
+
if (expr !== null && typeof expr === "object") {
|
|
278
|
+
const entries = Object.keys(expr).sort().map((k) => `${k}: ${formatTemplate(expr[k], holes)}`);
|
|
279
|
+
return entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`;
|
|
280
|
+
}
|
|
281
|
+
return formatSExpr(expr);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export { CORE_BINDINGS, EventPayloadSchema, EventPayloadValueSchema, ExpressionSchema, QUASIQUOTE_HEAD, QUOTE_HEAD, SExprAtomSchema, SExprDataSchema, SExprListSchema, SExprSchema, UNQUOTE_HEAD, collectBindings, decodeQuoteBody, decodeQuotedValue, encodeQuoteBody, formatSExpr, getArgs, getOperator, instantiateQuasiquote, isBinding, isEventPayloadValue, isSExpr, isSExprAtom, isSExprCall, isStaticallyFalse, isValidBinding, parseBinding, quasiquoteExpr, quasiquoteOf, quoteBodyOf, quoteExpr, sexpr, toProgramData, walkSExpr };
|
|
285
|
+
//# sourceMappingURL=chunk-347APWFM.js.map
|
|
286
|
+
//# sourceMappingURL=chunk-347APWFM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/expression.ts"],"names":["value"],"mappings":";;;;AA2DO,IAAM,kBAAoC,CAAA,CAAE,IAAA;AAAA,EAAK,MACtD,EAAE,KAAA,CAAM,CAAC,iBAAiB,CAAA,CAAE,KAAA,CAAM,eAAe,CAAC,CAAC;AACrD;AAMO,IAAM,eAAA,GAAwC,EAAE,KAAA,CAAM;AAAA,EAC3D,EAAE,MAAA,EAAO;AAAA,EACT,EAAE,MAAA,EAAO;AAAA,EACT,EAAE,OAAA,EAAQ;AAAA,EACV,EAAE,IAAA,EAAK;AAAA,EACP,CAAA,CAAE,MAAA,CAAO,CAAA,CAAE,MAAA,IAAU,eAAe;AAAA;AACtC,CAAC;AAQM,IAAM,cAAgC,CAAA,CAAE,IAAA;AAAA,EAAK,MAClD,EAAE,KAAA,CAAM;AAAA,IACN,eAAA;AAAA,IACA,EACG,KAAA,CAAM,eAAe,CAAA,CACrB,GAAA,CAAI,CAAC,CAAA,CACL,MAAA;AAAA,MACC,CAAC,GAAA,KAAQ,OAAO,GAAA,CAAI,CAAC,CAAA,KAAM,QAAA;AAAA,MAC3B,EAAE,SAAS,iEAAA;AAAkE;AAC/E,GACH;AACH;AAQO,IAAM,gBAAA,GAA0C;AAGhD,IAAM,eAAA,GAAsC,CAAA,CAAE,KAAA,CAAM,WAAW;AAa/D,SAAS,QAAQ,KAAA,EAAuC;AAC7D,EAAA,OACE,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,IACnB,KAAA,CAAM,SAAS,CAAA,IACf,OAAO,KAAA,CAAM,CAAC,CAAA,KAAM,QAAA;AAExB;AAmBO,SAAS,YAAY,KAAA,EAAyC;AACnE,EAAA,IAAI,KAAA,KAAU,MAAM,OAAO,IAAA;AAC3B,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,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CAAA;AAC3B,IAAA,IAAI,EAAA,KAAO,MAAM,OAAO,CAAA,CAAA,EAAI,CAAC,EAAA,EAAI,GAAG,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,CAAE,IAAI,CAAC,CAAA,KAAM,eAAe,CAAA,EAAG,KAAK,CAAC,CAAC,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA;AACjG,IAAA,OAAO,CAAA,CAAA,EAAI,IAAA,CAAK,GAAA,CAAI,CAAC,CAAA,KAAM,cAAA,CAAe,CAAA,EAAG,KAAK,CAAC,CAAA,CAAE,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA;AAAA,EAChE;AACA,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAA,EAAU;AAC7C,IAAA,MAAM,UAAU,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA,CAAE,IAAA,GAAO,GAAA,CAAI,CAAC,MAAM,CAAA,EAAG,CAAC,KAAK,cAAA,CAAe,IAAA,CAAK,CAAC,CAAA,EAAG,KAAK,CAAC,CAAA,CAAE,CAAA;AAC7F,IAAA,OAAO,OAAA,CAAQ,WAAW,CAAA,GAAI,IAAA,GAAO,KAAK,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,EAAA,CAAA;AAAA,EAC9D;AACA,EAAA,OAAO,YAAY,IAAI,CAAA;AACzB","file":"chunk-347APWFM.js","sourcesContent":["/**\n * S-Expression Types\n *\n * Defines the S-Expression type system for guards, effects, and computed values.\n * S-expressions are JSON arrays where the first element is an operator string.\n *\n * @example\n * // Guard: health > 0\n * [\">\", \"@entity.health\", 0]\n *\n * // Effect: set x to x + vx\n * [\"set\", \"@entity.x\", [\"+\", \"@entity.x\", \"@entity.vx\"]]\n *\n * @packageDocumentation\n */\n\nimport { z } from 'zod';\nimport { setOwn } from './own-key.js';\nimport { JsonValueSchema, type JsonValue, type RuntimeValue } from './json.js';\n\n// ============================================================================\n// S-Expression Type\n// ============================================================================\n\n/**\n * S-Expression type - recursive structure representing expressions.\n *\n * An S-expression is either:\n * - A literal value (string, number, boolean, null)\n * - An object literal (for payload data, props, etc.)\n * - A binding reference (string starting with @)\n * - A call expression (array with operator as first element)\n */\n/** Object literal branch of an S-expression atom (payload data, props, etc.). */\nexport interface SExprObject {\n [key: string]: SExpr;\n}\nexport type SExprAtom = string | number | boolean | null | SExprObject;\nexport type SExpr = SExprAtom | SExpr[];\n\n/**\n * Expression type - S-expressions only.\n * Used for guards, computed values, and effect expressions.\n *\n * NOTE: Legacy string format is no longer supported.\n * All expressions must be S-expression arrays.\n */\nexport type Expression = SExpr;\n\n// ============================================================================\n// S-Expression Schema (Zod)\n// ============================================================================\n\n/**\n * Recursive schema for s-expr-shaped DATA in literal positions (object\n * values, effect arguments). Unlike `SExprSchema`, arrays may be empty or\n * non-operator-headed — literal data lists (`children: []`, `tiles: [...]`)\n * are valid here; only call positions get the operator-head refine.\n */\nexport const SExprDataSchema: z.ZodType<SExpr> = z.lazy(() =>\n z.union([SExprAtomSchema, z.array(SExprDataSchema)]),\n);\n\n/**\n * Schema for atomic S-expression values (non-array)\n * Includes objects for payload data, props, etc.\n */\nexport const SExprAtomSchema: z.ZodType<SExprAtom> = z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.record(z.string(), SExprDataSchema), // Objects for payload data\n]);\n\n/**\n * Recursive schema for S-expressions: an atom, or a call — an array whose first element is its\n * string operator. A call's arguments are data (`SExprDataSchema`): an argument array without\n * an operator head is a literal list, as both evaluators read it (an inlined config list in\n * `[\"array/nth\", [{…}, {…}], \"@entity.i\"]`).\n */\nexport const SExprSchema: z.ZodType<SExpr> = z.lazy(() =>\n z.union([\n SExprAtomSchema,\n z\n .array(SExprDataSchema)\n .min(1)\n .refine(\n (arr) => typeof arr[0] === 'string',\n { message: 'S-expression array must have a string operator as first element' }\n ),\n ])\n);\n\n/**\n * Schema for Expression type - S-expressions only.\n * S-expressions are arrays with operator as first element.\n *\n * NOTE: Legacy string format is no longer supported.\n */\nexport const ExpressionSchema: z.ZodType<Expression> = SExprSchema;\n\n/** A list of propositions (`@invariant`, `@ensures`), named so declaration emit does not expand it at every use. */\nexport const SExprListSchema: z.ZodType<SExpr[]> = z.array(SExprSchema);\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Type guard for S-expression detection.\n * 100% reliable - structural check, no regex or keyword matching.\n *\n * @param value - Value to check\n * @returns true if value is an S-expression (array with string operator)\n */\nexport function isSExpr(value: RuntimeValue): value is SExpr[] {\n return (\n Array.isArray(value) &&\n value.length > 0 &&\n typeof value[0] === 'string'\n );\n}\n\n/**\n * Type guard for S-expression atoms (non-array values).\n * \n * Validates that a value is an S-expression atom (literal value).\n * Includes null, strings, numbers, booleans, and objects. Used to\n * distinguish atomic values from S-expression calls (arrays).\n * \n * @param {RuntimeValue} value - Value to check\n * @returns {boolean} True if value is an S-expression atom, false otherwise\n *\n * @example\n * isSExprAtom('hello'); // returns true\n * isSExprAtom(42); // returns true\n * isSExprAtom(null); // returns true\n * isSExprAtom({ key: 'value' }); // returns true\n * isSExprAtom(['+', 1, 2]); // returns false\n */\nexport function isSExprAtom(value: RuntimeValue): value is SExprAtom {\n if (value === null) return true;\n if (Array.isArray(value)) return false;\n const type = typeof value;\n return type === 'string' || type === 'number' || type === 'boolean' || type === 'object';\n}\n\n/**\n * Checks if a value is a binding reference.\n * \n * Validates that a string is a binding reference (starts with @).\n * Bindings reference runtime values like @entity.health, @payload.amount, @now.\n * Used for identifying bindings in S-expressions and validation.\n * \n * @param {RuntimeValue} value - Value to check\n * @returns {boolean} True if value is a binding reference, false otherwise\n *\n * @example\n * isBinding('@entity.health'); // returns true\n * isBinding('@payload.amount'); // returns true\n * isBinding('not-a-binding'); // returns false\n * isBinding(123); // returns false\n */\nexport function isBinding(value: RuntimeValue): value is string {\n return typeof value === 'string' && value.startsWith('@');\n}\n\n/**\n * Checks if a value is a valid S-expression call (array with operator).\n * \n * Alias for isSExpr() - validates S-expression call structure.\n * Used to distinguish between S-expression calls and atom values.\n * \n * @param {RuntimeValue} value - Value to check\n * @returns {boolean} True if value is a valid S-expression call, false otherwise\n *\n * @example\n * isSExprCall(['+', 1, 2]); // returns true\n * isSExprCall(['set', '@entity.health', 100]); // returns true\n * isSExprCall('not-a-call'); // returns false\n */\nexport function isSExprCall(value: RuntimeValue): value is SExpr[] {\n return isSExpr(value);\n}\n\n// ============================================================================\n// Binding Parsing\n// ============================================================================\n\n/**\n * Parsed binding reference\n */\nexport interface ParsedBinding {\n /** Type of binding: core (@entity, @payload, @state, @now) or entity (@EntityName) */\n type: 'core' | 'entity';\n /** The root binding name (entity, payload, state, now, or EntityName) */\n root: string;\n /** Path segments after the root (e.g., ['health'] for @entity.health) */\n path: string[];\n /** Full original binding string */\n original: string;\n}\n\n/**\n * Core bindings that are always available.\n * Phase 4.5 adds: config, computed, trait (for behavior support).\n * `user` is the authenticated user / agent context (see binding.ts) and is\n * read-only in guards/effects/ticks — atoms reference `@user.id` and\n * `@user.role` for ownership / role-based gating.\n * `callsitePayload` is the call-site-captured event payload emitted by the\n * compiler's inline-trait hoisting; the runtime BindingResolver resolves it\n * at the composing effect.\n * `pages` / `currentTheme` are render-resolved schema sigils (effect-only,\n * see `orbital-rust/crates/orbital-compiler/src/phases/resolve.rs`):\n * substituted from the host orbital's schema (`@pages` → its `NavItem[]`\n * nav array, `@currentTheme` → its `data-theme` key) before codegen — they\n * never survive as live bindings past that substitution pass.\n */\nexport const CORE_BINDINGS = ['entity', 'payload', 'state', 'now', 'config', 'computed', 'trait', 'user', 'callsitePayload', 'pages', 'currentTheme'] as const;\nexport type CoreBinding = (typeof CORE_BINDINGS)[number];\n\n/**\n * Parses a binding reference into its components.\n * \n * Deconstructs a binding string (e.g., '@entity.health') into its constituent\n * parts: type, root, path, and original string. Does NOT use regex - uses\n * structured string operations for reliability and maintainability.\n * \n * @param {string} binding - Binding string starting with @\n * @returns {ParsedBinding | null} Parsed binding object or null if invalid\n * \n * @example\n * parseBinding('@entity.health'); // returns { type: 'core', root: 'entity', path: ['health'], original: '@entity.health' }\n * parseBinding('@User.name'); // returns { type: 'entity', root: 'User', path: ['name'], original: '@User.name' }\n * parseBinding('not-a-binding'); // returns null\n */\nexport function parseBinding(binding: string): ParsedBinding | null {\n if (!binding.startsWith('@')) {\n return null;\n }\n\n // Remove @ prefix\n const withoutPrefix = binding.slice(1);\n\n // Split by dots\n const parts = withoutPrefix.split('.');\n\n if (parts.length === 0 || parts[0] === '') {\n return null;\n }\n\n const root = parts[0];\n const path = parts.slice(1);\n\n // Determine if core binding or entity reference\n const isCore = (CORE_BINDINGS as readonly string[]).includes(root);\n\n return {\n type: isCore ? 'core' : 'entity',\n root,\n path,\n original: binding,\n };\n}\n\n/**\n * Validate a binding reference format.\n *\n * @param binding - Binding string to validate\n * @returns true if valid binding format\n */\nexport function isValidBinding(binding: string): boolean {\n const parsed = parseBinding(binding);\n if (!parsed) return false;\n\n // Core bindings: @entity, @payload, @state, @now (optionally with path)\n // @state and @now don't have paths\n if (parsed.type === 'core') {\n if (parsed.root === 'state' || parsed.root === 'now') {\n return parsed.path.length === 0;\n }\n // @entity and @payload can have paths\n return true;\n }\n\n // Entity bindings: @EntityName.field - must have at least one path segment\n return parsed.path.length > 0;\n}\n\n// ============================================================================\n// S-Expression Utilities\n// ============================================================================\n\n/**\n * Get the operator from an S-expression call.\n *\n * @param expr - S-expression array\n * @returns The operator string or null if not a valid call\n */\nexport function getOperator(expr: SExpr): string | null {\n if (!isSExpr(expr)) return null;\n return expr[0] as string;\n}\n\n/** Where a node sits in its S-expression: argument indices of calls/arrays, keys of object literals. */\nexport type SExprPath = ReadonlyArray<number | string>;\n\n/**\n * One step of a traced evaluation. `enter`/`exit` bracket a node's evaluation\n * (`exit` carries its value or error); `iter` marks a node re-entered (a lambda\n * body per item); `skip` marks an argument the operator never evaluated\n * (short-circuited `and`/`or`, the untaken `if` branch).\n */\nexport interface EvalStep {\n kind: 'enter' | 'exit' | 'iter' | 'skip';\n path: SExprPath;\n value?: RuntimeValue;\n error?: string;\n}\n\nexport type EvalTrace = EvalStep[];\n\n/**\n * Print an S-expression in `.lolo` surface form: calls as `(op args…)`,\n * bindings bare, strings quoted, objects `{ k: v }` (keys sorted), literal arrays `[a b]`.\n * Structural only — a string-headed array is a call, as in {@link isSExpr}.\n */\nexport function formatSExpr(expr: SExpr): string {\n if (expr === null) return 'null';\n if (typeof expr === 'string') return isBinding(expr) ? expr : JSON.stringify(expr);\n if (typeof expr === 'number' || typeof expr === 'boolean') return String(expr);\n if (Array.isArray(expr)) {\n const quoted = quoteBodyOf(expr);\n if (quoted !== undefined) return `(${QUOTE_HEAD} ${formatSExpr(decodeQuoteBody(quoted))})`;\n const qq = quasiquoteOf(expr);\n if (qq !== undefined) return `(${QUASIQUOTE_HEAD} ${formatTemplate(decodeQuoteBody(qq.body), qq.holes)})`;\n const op = getOperator(expr);\n if (op !== null) return `(${[op, ...expr.slice(1).map(formatSExpr)].join(' ')})`;\n return `[${expr.map(formatSExpr).join(' ')}]`;\n }\n const entries = Object.keys(expr).sort().map((k) => `${k}: ${formatSExpr(expr[k])}`);\n return entries.length === 0 ? '{}' : `{ ${entries.join(', ')} }`;\n}\n\n/**\n * Get the arguments from an S-expression call.\n *\n * @param expr - S-expression array\n * @returns Array of arguments (empty if not a valid call)\n */\nexport function getArgs(expr: SExpr): SExpr[] {\n if (!isSExpr(expr)) return [];\n return expr.slice(1);\n}\n\n/**\n * Create an S-expression call.\n *\n * @param operator - The operator string\n * @param args - Arguments to the operator\n * @returns S-expression array\n */\nexport function sexpr(operator: string, ...args: SExpr[]): SExpr[] {\n return [operator, ...args];\n}\n\n/**\n * Walk an S-expression tree and apply a visitor function to each node.\n *\n * @param expr - S-expression to walk\n * @param visitor - Function to call on each node\n */\nexport function walkSExpr(\n expr: SExpr,\n visitor: (node: SExpr, parent: SExpr[] | null, index: number) => void,\n parent: SExpr[] | null = null,\n index: number = 0\n): void {\n visitor(expr, parent, index);\n\n if (isSExpr(expr)) {\n for (let i = 0; i < expr.length; i++) {\n walkSExpr(expr[i], visitor, expr, i);\n }\n }\n}\n\n/**\n * Collect all bindings referenced in an S-expression.\n *\n * @param expr - S-expression to analyze\n * @returns Array of binding strings found\n */\nexport function collectBindings(expr: SExpr): string[] {\n const bindings: string[] = [];\n\n walkSExpr(expr, (node) => {\n if (isBinding(node)) {\n bindings.push(node);\n }\n });\n\n return bindings;\n}\n\n// ============================================================================\n// Type Exports\n// ============================================================================\n\nexport type SExprInput = z.input<typeof SExprSchema>;\nexport type ExpressionInput = z.input<typeof ExpressionSchema>;\n\n// ============================================================================\n// Runtime Evaluation Types\n// ============================================================================\n\n/** Evaluation context for guards and s-expressions. Recursive. */\nexport interface EvalContext {\n [key: string]: string | number | boolean | Date | null | string[] | EvalContext | undefined;\n}\n\n/**\n * A single value carried by an event payload field: a JSON value. A date is its ISO string, an absent\n * field is an absent key; `Date` and `undefined` never travel on the wire.\n */\nexport type EventPayloadValue = JsonValue;\n\n/**\n * Typed event payload: a JSON object, assignable to the bus's `EventPayload` parameter without casts.\n */\nexport interface EventPayload {\n [key: string]: EventPayloadValue;\n}\n\n/**\n * Runtime guard for `EventPayloadValue` — narrows interpreter-produced\n * `unknown` values at typed substrate boundaries (e.g. `TraceContext.emit`).\n */\nexport function isEventPayloadValue(value: RuntimeValue): value is EventPayloadValue {\n if (value === null) return true;\n const kind = typeof value;\n if (kind === 'string' || kind === 'number' || kind === 'boolean') return true;\n if (Array.isArray(value)) return value.every((item: RuntimeValue) => isEventPayloadValue(item));\n if (kind === 'object' && typeof value === 'object' && !(value instanceof Date)) {\n return Object.values(value).every((item: RuntimeValue) => isEventPayloadValue(item));\n }\n return false;\n}\n\n/** Zod twin of `EventPayloadValue` — the one runtime validator for a bus-emit payload slot. */\nexport const EventPayloadValueSchema: z.ZodType<EventPayloadValue> = JsonValueSchema;\n\n/** Zod twin of `EventPayload` — the wire shape of a bus event's `payload`. */\nexport const EventPayloadSchema: z.ZodType<EventPayload> = z.record(z.string(), JsonValueSchema);\n\n/**\n * Allowed leaf value for `LogMeta`. Mirrors `EventPayloadValue` shape so\n * the same row/list data flows through logs without manual flattening,\n * with `Error` added since structured logs carry exception detail.\n */\nexport type LogMetaValue =\n | string\n | number\n | boolean\n | Date\n | null\n | undefined\n | Error\n | LogMeta\n | readonly LogMetaValue[];\n\n/** Structured log/event metadata. Recursive to support nested log data. */\nexport interface LogMeta {\n [key: string]: LogMetaValue;\n}\n\n/**\n * True when `expr` provably evaluates falsy — the twin of orbital-core's\n * `SExpression::is_statically_false`, one table on both paths. Conservative:\n * anything undecidable returns `false` (\"not provably false\"). `resolve`\n * turns a binding (`@config.selfFetch`) into its known literal value, or\n * `undefined` when unknown — the JS path keeps config bindings in guards\n * where Rust inlines them.\n */\nexport function isStaticallyFalse(expr: SExpr, resolve?: (binding: string) => SExprAtom | undefined): boolean {\n const known = (e: SExpr): SExpr => {\n if (typeof e === 'string' && e.startsWith('@') && resolve !== undefined) {\n const value = resolve(e);\n return value === undefined ? e : value;\n }\n return e;\n };\n const isLiteral = (e: SExpr): boolean =>\n e === null || typeof e === 'boolean' || typeof e === 'number' || (typeof e === 'string' && !e.startsWith('@'));\n const value = known(expr);\n if (value === false || value === null) return true;\n if (typeof value === 'number') return value === 0;\n if (typeof value === 'string') return value === '';\n if (Array.isArray(value)) {\n const op = value[0];\n if (typeof op !== 'string') return value.length === 0;\n const args = value.slice(1);\n switch (op) {\n case 'and': return args.some((a) => isStaticallyFalse(a, resolve));\n case 'or': return args.length > 0 && args.every((a) => isStaticallyFalse(a, resolve));\n case 'not': return args.length === 1 && known(args[0]) === true;\n case '==':\n case '!=': {\n if (args.length !== 2) return false;\n const [l, r] = [known(args[0]), known(args[1])];\n if (!isLiteral(l) || !isLiteral(r)) return false;\n return (l === r) === (op === '!=');\n }\n default: return false;\n }\n }\n if (typeof value === 'object') return Object.keys(value).length === 0;\n return false;\n}\n\n\n// ============================================================================\n// quote — an S-expression held as data (G-CROSS-041)\n// ============================================================================\n\n/** The special form that holds an S-expression as data: `(quote x)`. */\nexport const QUOTE_HEAD = 'quote';\n\nfunction canonicalQuoteValue(expr: SExpr): SExpr {\n if (Array.isArray(expr)) return expr.map(canonicalQuoteValue);\n if (expr !== null && typeof expr === 'object') {\n const out: SExprObject = {};\n for (const key of Object.keys(expr).sort()) setOwn(out, key, canonicalQuoteValue(expr[key]));\n return out;\n }\n return expr;\n}\n\n/**\n * The IR body of `(quote x)`: canonical JSON of `x` (object keys sorted) with\n * every `@` written as the JSON escape `@`. The body therefore carries no\n * raw `@`, so no binding interpolation, scan or rewrite can reach inside it;\n * any JSON parser restores the original. orbital-core's\n * `schema::quote::encode_quote_body` produces the same bytes.\n */\nexport function encodeQuoteBody(expr: SExpr): string {\n return JSON.stringify(canonicalQuoteValue(expr)).replace(/@/g, '\\\\u0040');\n}\n\n/** Decode a `(quote x)` body back to `x`. */\nexport function decodeQuoteBody(body: string): SExpr {\n const value: SExpr = JSON.parse(body);\n return value;\n}\n\n/** The IR call `[\"quote\", <body>]` for `expr`. */\nexport function quoteExpr(expr: SExpr): [typeof QUOTE_HEAD, string] {\n return [QUOTE_HEAD, encodeQuoteBody(expr)];\n}\n\n/**\n * The data a quoted value stands for: `decodeQuoteBody` of the body when\n * `expr` is a `(quote x)` call, else `expr` unchanged. One level per call —\n * binding path resolution applies it per step, so `(quote …)` nested inside\n * the decoded data decodes there when the path reaches it.\n */\nexport function decodeQuotedValue(expr: SExpr): SExpr;\nexport function decodeQuotedValue(expr: RuntimeValue): RuntimeValue;\nexport function decodeQuotedValue(expr: RuntimeValue): RuntimeValue {\n const body = quoteBodyOf(expr);\n return body === undefined ? expr : decodeQuoteBody(body);\n}\n\n/** The encoded body when `expr` is a `(quote x)` call, else undefined. */\nexport function quoteBodyOf(expr: RuntimeValue): string | undefined {\n return Array.isArray(expr) && expr.length === 2 && expr[0] === QUOTE_HEAD && typeof expr[1] === 'string'\n ? expr[1]\n : undefined;\n}\n\n// ============================================================================\n// quasiquote — a quoted template with live `(unquote e)` holes\n// ============================================================================\n\n/** A quoted template: `(quasiquote x)`. */\nexport const QUASIQUOTE_HEAD = 'quasiquote';\n/** A live hole inside a quasiquote template: `(unquote e)`. */\nexport const UNQUOTE_HEAD = 'unquote';\n\nfunction isHeadedCall(expr: SExpr, head: string): expr is SExpr[] {\n return Array.isArray(expr) && expr.length > 0 && expr[0] === head;\n}\n\nfunction containsHead(expr: SExpr, head: string): boolean {\n if (isHeadedCall(expr, head)) return true;\n if (Array.isArray(expr)) return expr.some((e) => containsHead(e, head));\n if (expr !== null && typeof expr === 'object') return Object.values(expr).some((e) => containsHead(e, head));\n return false;\n}\n\nfunction extractHoles(expr: SExpr, holes: SExpr[]): SExpr {\n if (isHeadedCall(expr, QUASIQUOTE_HEAD)) throw new Error('quasiquote: nested quasiquote is not supported');\n if (isHeadedCall(expr, UNQUOTE_HEAD)) {\n if (expr.length !== 2) throw new Error('quasiquote: (unquote e) takes exactly one expression');\n if (containsHead(expr[1], UNQUOTE_HEAD)) throw new Error('quasiquote: unquote inside an unquote');\n holes.push(expr[1]);\n return [UNQUOTE_HEAD, holes.length - 1];\n }\n if (Array.isArray(expr)) return expr.map((e) => extractHoles(e, holes));\n if (expr !== null && typeof expr === 'object') {\n // Canonical key order, so hole numbering matches the body bytes on every path.\n const out: SExprObject = {};\n for (const k of Object.keys(expr).sort()) setOwn(out, k, extractHoles(expr[k], holes));\n return out;\n }\n return expr;\n}\n\n/**\n * The IR call `[\"quasiquote\", <body>, hole0, hole1, …]` for `template`. The\n * body is a quote body in which each `(unquote e)` became the marker\n * `[\"unquote\", i]`; hole `i` is `e`, left live so bindings resolve in it.\n * orbital-core's `schema::quote::quasiquote_expr` produces the same IR.\n */\nexport function quasiquoteExpr(template: SExpr): [typeof QUASIQUOTE_HEAD, string, ...SExpr[]] {\n const holes: SExpr[] = [];\n const body = encodeQuoteBody(extractHoles(template, holes));\n return [QUASIQUOTE_HEAD, body, ...holes];\n}\n\n/** The body and holes when `expr` is a `(quasiquote x)` call, else undefined. */\nexport function quasiquoteOf(expr: SExpr): { body: string; holes: SExpr[] } | undefined {\n if (!Array.isArray(expr) || expr.length < 2 || expr[0] !== QUASIQUOTE_HEAD || typeof expr[1] !== 'string') {\n return undefined;\n }\n return { body: expr[1], holes: expr.slice(2) };\n}\n\nfunction countMarkers(expr: SExpr): number {\n if (isHeadedCall(expr, UNQUOTE_HEAD) && expr.length === 2 && typeof expr[1] === 'number') return 1;\n if (Array.isArray(expr)) return expr.reduce<number>((n, e) => n + countMarkers(e), 0);\n if (expr !== null && typeof expr === 'object') return Object.values(expr).reduce<number>((n, e) => n + countMarkers(e), 0);\n return 0;\n}\n\nfunction fillMarkers(expr: SExpr, values: readonly SExpr[]): SExpr {\n if (isHeadedCall(expr, UNQUOTE_HEAD) && expr.length === 2 && typeof expr[1] === 'number') return values[expr[1]];\n if (Array.isArray(expr)) return expr.map((e) => fillMarkers(e, values));\n if (expr !== null && typeof expr === 'object') {\n const out: SExprObject = {};\n for (const [k, v] of Object.entries(expr)) setOwn(out, k, fillMarkers(v, values));\n return out;\n }\n return expr;\n}\n\n/**\n * A hole's evaluated value as program data: JSON scalars, arrays and plain\n * objects pass; anything a program cannot hold (a function, a Date, …) throws.\n * Both paths guard `(quasiquote …)` holes with this — orbital-core's\n * `QuasiquoteOp` refuses a lambda the same way.\n */\nexport function toProgramData(value: RuntimeValue): SExpr {\n if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n if (Array.isArray(value)) return value.map((v: RuntimeValue) => toProgramData(v));\n if (typeof value === 'object' && !(value instanceof Date) && Object.getPrototypeOf(value) === Object.prototype) {\n const out: SExprObject = {};\n for (const [k, v] of Object.entries(value)) setOwn(out, k, toProgramData(v));\n return out;\n }\n throw new Error(`quasiquote: a hole evaluated to a ${typeof value} value, which cannot be held as program data`);\n}\n\n/** Decode a quasiquote body and splice `values` (the evaluated holes, in order) into it. */\nexport function instantiateQuasiquote(body: string, values: readonly SExpr[]): SExpr {\n const template = decodeQuoteBody(body);\n const holes = countMarkers(template);\n if (holes !== values.length) {\n throw new Error(`quasiquote: template has ${holes} hole(s), got ${values.length} value(s)`);\n }\n return fillMarkers(template, values);\n}\n\nfunction formatTemplate(expr: SExpr, holes: readonly SExpr[]): string {\n if (isHeadedCall(expr, UNQUOTE_HEAD) && expr.length === 2 && typeof expr[1] === 'number') {\n return `(${UNQUOTE_HEAD} ${formatSExpr(holes[expr[1]])})`;\n }\n if (Array.isArray(expr)) {\n const op = getOperator(expr);\n if (op !== null) return `(${[op, ...expr.slice(1).map((e) => formatTemplate(e, holes))].join(' ')})`;\n return `[${expr.map((e) => formatTemplate(e, holes)).join(' ')}]`;\n }\n if (expr !== null && typeof expr === 'object') {\n const entries = Object.keys(expr).sort().map((k) => `${k}: ${formatTemplate(expr[k], holes)}`);\n return entries.length === 0 ? '{}' : `{ ${entries.join(', ')} }`;\n }\n return formatSExpr(expr);\n}\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { isEventResponse } from './chunk-MTBEBSNO.js';
|
|
2
|
+
import { EventPayloadSchema } from './chunk-347APWFM.js';
|
|
3
|
+
import { EventIdSchema, TraitIdSchema, OrbitalIdSchema } from './chunk-VG7BRFUD.js';
|
|
4
|
+
import { JsonValueSchema } from './chunk-7GHJU5WI.js';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
var BusEventSourceSchema = z.object({
|
|
8
|
+
orbital: z.string().optional(),
|
|
9
|
+
orbitalId: OrbitalIdSchema.optional(),
|
|
10
|
+
trait: z.string().optional(),
|
|
11
|
+
traitId: TraitIdSchema.optional(),
|
|
12
|
+
eventId: EventIdSchema.optional(),
|
|
13
|
+
transition: z.string().optional(),
|
|
14
|
+
tick: z.string().optional(),
|
|
15
|
+
fromBridge: z.boolean().optional(),
|
|
16
|
+
dispatched: z.boolean().optional(),
|
|
17
|
+
originClientId: z.string().optional(),
|
|
18
|
+
pendingKey: z.string().optional(),
|
|
19
|
+
persistSuccess: z.boolean().optional(),
|
|
20
|
+
instanceKey: z.string().optional()
|
|
21
|
+
});
|
|
22
|
+
var DeliveryRecordSchema = z.object({
|
|
23
|
+
event: z.string(),
|
|
24
|
+
payload: EventPayloadSchema.optional(),
|
|
25
|
+
source: BusEventSourceSchema
|
|
26
|
+
});
|
|
27
|
+
var DispatchLogSchema = z.object({
|
|
28
|
+
prevEvents: z.array(DeliveryRecordSchema),
|
|
29
|
+
prevStates: z.array(z.string())
|
|
30
|
+
});
|
|
31
|
+
var EmittedEventSchema = z.object({
|
|
32
|
+
event: z.string(),
|
|
33
|
+
payload: EventPayloadSchema.optional(),
|
|
34
|
+
source: BusEventSourceSchema.optional()
|
|
35
|
+
});
|
|
36
|
+
var ClientRenderUITupleSchema = z.tuple([z.literal("render-ui"), z.string(), z.record(z.string(), JsonValueSchema).nullable()]);
|
|
37
|
+
var ClientNavigateTupleSchema = z.union([
|
|
38
|
+
z.tuple([z.literal("navigate"), z.string()]),
|
|
39
|
+
z.tuple([z.literal("navigate"), z.string(), z.record(z.string(), z.string()).nullable()]),
|
|
40
|
+
z.tuple([
|
|
41
|
+
z.literal("navigate"),
|
|
42
|
+
z.string(),
|
|
43
|
+
z.record(z.string(), z.string()).nullable(),
|
|
44
|
+
z.object({ crumb: z.string().optional() })
|
|
45
|
+
])
|
|
46
|
+
]);
|
|
47
|
+
var ClientNavigateBackTupleSchema = z.tuple([z.literal("navigate-back")]);
|
|
48
|
+
var HostAskCompletionSchema = z.object({
|
|
49
|
+
trait: z.string(),
|
|
50
|
+
entityId: z.string().optional(),
|
|
51
|
+
key: z.string().optional(),
|
|
52
|
+
success: z.string().optional(),
|
|
53
|
+
failure: z.string().optional()
|
|
54
|
+
}).strict();
|
|
55
|
+
var ClientHostAskTupleSchema = z.union([
|
|
56
|
+
z.tuple([z.literal("host-ask"), z.string(), z.array(JsonValueSchema)]),
|
|
57
|
+
z.tuple([z.literal("host-ask"), z.string(), z.array(JsonValueSchema), HostAskCompletionSchema])
|
|
58
|
+
]);
|
|
59
|
+
var ClientEffectTupleSchema = z.union([
|
|
60
|
+
ClientRenderUITupleSchema,
|
|
61
|
+
ClientNavigateTupleSchema,
|
|
62
|
+
ClientNavigateBackTupleSchema,
|
|
63
|
+
ClientHostAskTupleSchema
|
|
64
|
+
]);
|
|
65
|
+
var LIFECYCLE_EVENTS = ["INIT", "LOAD", "$MOUNT"];
|
|
66
|
+
var UNMOUNT_EVENT = "$UNMOUNT";
|
|
67
|
+
function normalizeEventKey(eventKey) {
|
|
68
|
+
if (!eventKey) return "";
|
|
69
|
+
return eventKey.startsWith("UI:") ? eventKey.slice(3) : eventKey;
|
|
70
|
+
}
|
|
71
|
+
function tickEventKey(tickName) {
|
|
72
|
+
return `$TICK_${tickName}`;
|
|
73
|
+
}
|
|
74
|
+
var MountSeedSchema = z.object({ trait: z.string(), event: z.enum(LIFECYCLE_EVENTS) });
|
|
75
|
+
var EventStreamItemSchema = z.union([
|
|
76
|
+
z.object({ type: z.literal("event"), data: EmittedEventSchema, timestamp: z.number() }),
|
|
77
|
+
z.object({ type: z.literal("effect"), data: ClientEffectTupleSchema, timestamp: z.number() }),
|
|
78
|
+
z.object({ type: z.literal("complete"), data: z.custom((v) => JsonValueSchema.safeParse(v).success && isEventResponse(JsonValueSchema.parse(v))), timestamp: z.number() }),
|
|
79
|
+
z.object({ type: z.literal("error"), data: z.object({ message: z.string() }), timestamp: z.number() })
|
|
80
|
+
]);
|
|
81
|
+
var ServerTopologySchema = z.enum(["stateless", "stateful"]);
|
|
82
|
+
var OrbitalRegisterResponseSchema = z.object({
|
|
83
|
+
success: z.boolean(),
|
|
84
|
+
topology: ServerTopologySchema.optional(),
|
|
85
|
+
message: z.string().optional(),
|
|
86
|
+
orbitals: z.array(z.string()).optional(),
|
|
87
|
+
error: z.string().optional()
|
|
88
|
+
});
|
|
89
|
+
var LiveBroadcastItemSchema = z.object({
|
|
90
|
+
event: z.string(),
|
|
91
|
+
payload: EventPayloadSchema.optional(),
|
|
92
|
+
source: BusEventSourceSchema,
|
|
93
|
+
originClientId: z.string().optional()
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export { BusEventSourceSchema, ClientEffectTupleSchema, ClientHostAskTupleSchema, ClientNavigateBackTupleSchema, ClientNavigateTupleSchema, ClientRenderUITupleSchema, DeliveryRecordSchema, DispatchLogSchema, EmittedEventSchema, EventStreamItemSchema, HostAskCompletionSchema, LIFECYCLE_EVENTS, LiveBroadcastItemSchema, MountSeedSchema, OrbitalRegisterResponseSchema, ServerTopologySchema, UNMOUNT_EVENT, normalizeEventKey, tickEventKey };
|
|
97
|
+
//# sourceMappingURL=chunk-3URQAGD7.js.map
|
|
98
|
+
//# sourceMappingURL=chunk-3URQAGD7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/bus.ts"],"names":[],"mappings":";;;;;;AA8MO,IAAM,oBAAA,GAA0D,EAAE,MAAA,CAAO;AAAA,EAC9E,OAAA,EAAS,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC7B,SAAA,EAAW,gBAAgB,QAAA,EAAS;AAAA,EACpC,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC3B,OAAA,EAAS,cAAc,QAAA,EAAS;AAAA,EAChC,OAAA,EAAS,cAAc,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,IAAA,EAAM,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC1B,UAAA,EAAY,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAA,EAAS;AAAA,EACjC,UAAA,EAAY,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAA,EAAS;AAAA,EACjC,cAAA,EAAgB,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACpC,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AAC,CAAC,CAAC,CAAA,EAAG,SAAA,EAAW,CAAA,CAAE,MAAA,IAAU,CAAA;AAAA,EACxL,CAAA,CAAE,OAAO,EAAE,IAAA,EAAM,EAAE,OAAA,CAAQ,OAAO,CAAA,EAAG,IAAA,EAAM,CAAA,CAAE,MAAA,CAAO,EAAE,OAAA,EAAS,CAAA,CAAE,QAAO,EAAG,GAAG,SAAA,EAAW,CAAA,CAAE,MAAA,EAAO,EAAG;AACvG,CAAC;AAuDM,IAAM,uBAAuB,CAAA,CAAE,IAAA,CAAK,CAAC,WAAA,EAAa,UAAU,CAAC;AAW7D,IAAM,6BAAA,GAA4E,EAAE,MAAA,CAAO;AAAA,EAChG,OAAA,EAAS,EAAE,OAAA,EAAQ;AAAA,EACnB,QAAA,EAAU,qBAAqB,QAAA,EAAS;AAAA,EACxC,OAAA,EAAS,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC7B,UAAU,CAAA,CAAE,KAAA,CAAM,EAAE,MAAA,EAAQ,EAAE,QAAA,EAAS;AAAA,EACvC,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACpB,CAAC;AAyBM,IAAM,uBAAA,GAAgE,EAAE,MAAA,CAAO;AAAA,EACpF,KAAA,EAAO,EAAE,MAAA,EAAO;AAAA,EAChB,OAAA,EAAS,mBAAmB,QAAA,EAAS;AAAA,EACrC,MAAA,EAAQ,oBAAA;AAAA,EACR,cAAA,EAAgB,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AAC7B,CAAC","file":"chunk-3URQAGD7.js","sourcesContent":["/**\n * Bus Event Types (framework concept)\n *\n * Canonical event shape for Almadar's cross-package event bus. Hoisted into\n * `@almadar/core` so `@almadar/ui`, `@almadar/runtime`, and generated code\n * all agree on the same structure. Replaces the previously divergent\n * `KFlowEvent` (ui) and `RuntimeEvent` (runtime) definitions.\n *\n * @packageDocumentation\n */\n\nimport { z } from \"zod\";\nimport { EventPayloadSchema, SExprDataSchema, type EventPayload, type SExpr } from \"./expression.js\";\nimport { OrbitalIdSchema, TraitIdSchema, EventIdSchema, type OrbitalId, type TraitId, type EventId } from \"./identity.js\";\nimport { RowSetRefSchema, type RowSetRef } from \"./row-set.js\";\nimport { EntityRowSchema, type EntityRow } from \"./entity.js\";\nimport { RawUserClaimsSchema, type RawUserClaims, type UserContext } from \"./user.js\";\nimport type { RowQueryPage } from \"../service-types.js\";\nimport { ServerEffectResultSchema, type ServerEffectResult } from \"./effect-result.js\";\nimport type { ExternalInput } from \"../access/contract.js\";\nimport { JsonValueSchema, type JsonObject, type JsonValue } from \"./json.js\";\nimport { isEventResponse, type ClientEffectByTrait, type EventRequest, type EventResponse, type FrameDelta, type HopEffect, type HopEffectStatus, type TransitionHop, type TransitionRejection, type TransitionRejectionCode } from \"../generated/kernel-wire.js\";\n\nexport type { ClientEffectByTrait, HopEffect, HopEffectStatus, TransitionHop, TransitionRejection, TransitionRejectionCode };\n\n/**\n * Declared event key. A trait's event names (INIT, SAVE, CLOSE,\n * CONFIRM_REMOVE, ...) flow through the orbital schema and the UI as\n * strings; this alias marks \"this string is a declared event key, not\n * arbitrary text.\"\n *\n * Component props typed as `EventKey` are detected by the pattern-sync\n * tool (`tools/almadar-pattern-sync/parser.ts`) via a TS-type lookup and\n * marked as `kind: \"event\"` in the patterns registry\n * (`@almadar/patterns`). Consumers of the registry — the Rust compiler's\n * inline phase and the `@almadar/runtime` preprocess — read that marker\n * to apply call-site `events: { OLD: NEW }` renames to render-ui trees\n * without name-matching heuristics.\n *\n * Plain alias over `string`. Not branded because event keys originate\n * from user data at runtime (orb schema literals, bus emits), so cast\n * friction would buy nothing. The value of the alias is at the type\n * surface — it's a marker the pattern-sync tool can find via\n * `getSymbolAtLocation`.\n */\nexport type EventKey = string;\n\n/**\n * Phantom-typed brand for declarative bus-emit props on UI components.\n *\n * Used by component authors to BOTH mark a prop as a bus-event reference\n * AND document the payload shape that the component will fire onto the\n * bus when that prop is bound. Authors write:\n *\n * // Tabs.tsx\n * export interface TabsProps {\n * tabChangeEvent?: EventEmit<{ tabId: string }>;\n * }\n *\n * Consumers see only the structural `string` (no UX impact: passing a\n * literal `\"TAB_CHANGED\"` keeps working). The phantom `P` parameter\n * carries the bus-payload schema at the type level for pattern-sync to\n * extract.\n *\n * Pattern-sync (`tools/almadar-pattern-sync/parser.ts`) detects this\n * brand via TS type-lookup (mirrors how it detects `EventKey`) and\n * writes two registry fields per prop:\n * - `kind: \"event-ref\"` — the discriminant rules read in lolo / orb\n * validator to know \"this prop's string value is a bus event name.\"\n * - `emitPayloadSchema` — the structural shape of `P`, serialized as\n * the same JSON-Schema-shaped record Almadar uses for trait\n * `payloadSchema`. Validator rules cross-check this against the\n * trait's declared `emits { EVENT { ... } }` payload to catch mismatches\n * at parse / validate time instead of runtime.\n *\n * Example payload bus emission inside the component (no wrapper —\n * `EventEmit<P>` erases to `string`):\n *\n * if (tabChangeEvent) eventBus.emit(`UI:${tabChangeEvent}`, { tabId });\n *\n * The brand is structurally an unused optional readonly property; TS\n * never asks for it at construction, so authors and consumers never\n * see it.\n */\nexport type EventEmit<P> = string & { readonly __emitPayload?: P };\n\n/**\n * Phantom-typed brand for declarative bus-listen props on UI components.\n *\n * Mirror of `EventEmit<P>`. Used by future patterns where a UI component\n * subscribes to a bus event and forwards its payload upward via prop\n * (e.g. an editor pattern that listens for `EXTERNAL_RESET` and exposes\n * the consumed payload to the parent). Pattern-sync detects this brand\n * the same way as `EventEmit<P>` and writes:\n * - `kind: \"event-listen\"` (or a sub-discriminant of `event-ref`)\n * - `listenPayloadSchema` with the structural shape of `P`\n *\n * Validator rules use this to verify the trait the prop is bound to\n * actually emits a payload of the expected shape.\n *\n * Reserved for symmetry; no @almadar/ui component uses it as of this\n * commit. Add usages incrementally as patterns require them.\n */\nexport type EventListen<P> = string & { readonly __listenPayload?: P };\n\n// NOTE: The phantom entity-inlet brands `EntityInlet`/`EntityRecord`/\n// `EntityCollection` were removed in the entity-row clean slate. There is now\n// ONE entity type — `EntityRow` (`./entity`), used directly: a single record is\n// `EntityRow`, a collection is `readonly EntityRow[]`. pattern-sync detects an\n// entity prop by the `EntityRow` type identity and derives record-vs-collection\n// from array-vs-not, so no brand is needed.\n\n/**\n * Identifies the origin of a bus event. Used by cross-trait listeners to\n * filter emits from specific orbitals, traits, transitions, or ticks.\n *\n * `transition` and `tick` are optional runtime-internal details; most\n * consumers only care about `orbital` and `trait`.\n */\nexport type BusEventSource = {\n orbital?: string;\n /** V4 dual-carry id sibling of `orbital` — stable across an orbital rename. */\n orbitalId?: OrbitalId;\n trait?: string;\n /** V4 dual-carry id sibling of `trait` — stable across a trait rename. */\n traitId?: TraitId;\n /** V4 dual-carry id of the emitted event — stable across an event rename. */\n eventId?: EventId;\n transition?: string;\n tick?: string;\n /**\n * True when the orbital bridge re-broadcasts an event onto the bus\n * (any source — both echoes of the dispatched event and server-side\n * cascade emits via `(emit X)` / `fetch.emit.success`). Cross-trait\n * listeners filter on this flag so the click-time qualified emit\n * (which has no `fromBridge`) doesn't double-fire alongside the\n * post-server bridge confirmation. See `dispatched` for the narrower\n * \"echo of the just-dispatched event\" signal.\n */\n fromBridge?: boolean;\n /**\n * True ONLY for bridge echoes the receiving tab already processed, so\n * the originating trait's self-subscription skips them instead of\n * re-dispatching its own echo (infinite loop / double execution).\n * Set by path 1 of useOrbitalBridge (compiled shell — echo of the\n * just-dispatched event; server-side cascade emits there carry\n * `fromBridge: true` but NOT `dispatched`, so they still reach the\n * source trait's transition handler, e.g. `loading -> browsing` on a\n * fetch's `emit.success`) and by ServerBridge (runtime path — stamped\n * on exactly one response-cascade echo per event the dispatch delivered\n * locally on the bare key, `stampLocallyDeliveredEchoes`; server-only\n * results stay unstamped). Cross-trait `listens` never filter on this\n * flag, so their delivery is unaffected. Push-leg events from OTHER\n * tabs (multiplayer) are never stamped.\n */\n dispatched?: boolean;\n /**\n * The client that originated the dispatch whose effects emitted this\n * event (from `EventRequest.clientId`); absent for headless\n * dispatches (ticks, circuit-router probes, walkers). The server-side\n * listens fan-out skips client-originated cascade emits — under dual\n * execution the originating client relays every cascade hop through the\n * bridge itself, so the server dispatching the same hop double-ran it\n * (one Send persisted two rows). Headless topology keeps the fan-out:\n * there is no client to drive the circuit.\n */\n originClientId?: string;\n /**\n * Per-activation key a UI control stamps on the event it emits, so it can\n * show its own busy state for exactly as long as the dispatches that event\n * started are in flight (`@almadar/ui` lib/pendingDispatch). Never set by\n * the bridge or the server.\n */\n pendingKey?: string;\n /**\n * Set by a server-role kernel on a `persist` effect's `emit.success` envelope: the one emit a live-push\n * host (`setLiveBroadcastSink`) also fans out to every other connected client.\n */\n persistSuccess?: boolean;\n /**\n * The row of the emitting trait's entity that made the emit, when the trait's rows are addressed by a `per`\n * listener. A listener with a `per` clause evaluates its own key; one without ignores this.\n */\n instanceKey?: string;\n};\n\n// The third type param is `object` on schemas nesting a branded-id\n// `.refine(<type predicate>)` field: the refine's parsed INPUT is a plain\n// `string`, not the branded output type, so the input/output-equal default\n// `z.ZodType<T>` mis-typechecks. `object` is what the wire actually carries\n// (a JSON body) — never `unknown`.\n\n/** The delivery a transition is processing: `@event`, and one element of `@prevEvents` (Runtime Spec Clause 5.5). */\nexport type DeliveryRecord = {\n event: string;\n payload?: EventPayload;\n source: BusEventSource;\n};\n\n/** A trait's log so far in a dispatch that began elsewhere (`@prevEvents` / `@prevStates`), carried on the request. */\nexport type DispatchLog = {\n prevEvents: DeliveryRecord[];\n prevStates: string[];\n};\n\n/** Zod twin of `BusEventSource`. */\nexport const BusEventSourceSchema: z.ZodType<BusEventSource, object> = z.object({\n orbital: z.string().optional(),\n orbitalId: OrbitalIdSchema.optional(),\n trait: z.string().optional(),\n traitId: TraitIdSchema.optional(),\n eventId: EventIdSchema.optional(),\n transition: z.string().optional(),\n tick: z.string().optional(),\n fromBridge: z.boolean().optional(),\n dispatched: z.boolean().optional(),\n originClientId: z.string().optional(),\n pendingKey: z.string().optional(),\n persistSuccess: z.boolean().optional(),\n instanceKey: z.string().optional(),\n});\n\n/** Zod twin of `DeliveryRecord`. */\nexport const DeliveryRecordSchema: z.ZodType<DeliveryRecord, object> = z.object({\n event: z.string(),\n payload: EventPayloadSchema.optional(),\n source: BusEventSourceSchema,\n});\n\n/** Zod twin of `DispatchLog`. */\nexport const DispatchLogSchema: z.ZodType<DispatchLog, object> = z.object({\n prevEvents: z.array(DeliveryRecordSchema),\n prevStates: z.array(z.string()),\n});\n\n/**\n * An event flowing on the bus.\n *\n * The `source` field is structured so cross-trait listeners can match\n * `event.source?.orbital === 'X' && event.source?.trait === 'Y'` without\n * parsing a delimiter.\n */\nexport type BusEvent = {\n /** Event type identifier (e.g., 'CartItemLoaded', 'TASK_COMPLETED') */\n type: EventKey;\n /** Optional structured payload */\n payload?: EventPayload;\n /** Timestamp when the event was emitted */\n timestamp: number;\n /** Optional origin info for filtering */\n source?: BusEventSource;\n};\n\n/** Bus event listener callback. */\nexport type BusEventListener = (event: BusEvent) => void;\n\n/** Returned by `on()` / `once()` to detach a listener. */\nexport type Unsubscribe = () => void;\n\n/**\n * One event a transition's effects emitted, carried back to the client to\n * re-dispatch (in order) so the state machine advances through the\n * cascade without server-side recursion. Named/shaped to match the\n * generated compiled-path `EmittedEvent` (orbital-shell-typescript's\n * `shared/types.ts`) so the two execution paths agree on one shape.\n */\nexport type EmittedEvent = {\n event: string;\n payload?: EventPayload;\n source?: BusEventSource;\n};\n\n/** Zod twin of `EmittedEvent`. Third type param `object`, see `BusEventSourceSchema`. */\nexport const EmittedEventSchema: z.ZodType<EmittedEvent, object> = z.object({\n event: z.string(),\n payload: EventPayloadSchema.optional(),\n source: BusEventSourceSchema.optional(),\n});\n\n// ============================================================================\n// Client-effect wire grammar\n// ============================================================================\n\n/**\n * Client-side effect tuple shipped in `EventResponse.clientEffectsByTrait`.\n * Restricted to the effect kinds the client knows how to apply to the\n * UI: render-ui (slot mutation, including the `toast` slot that carries\n * what used to be the separate notify effect) and navigate (route change).\n * Server-only effects (persist, set, fetch, ...) execute on the server and\n * surface their results via `effectResults` and `emittedEvents`, not here.\n *\n * Shape note: `render-ui` takes a slot and a pattern (G-CROSS-257); `navigate`'s\n * optional argument may surface as `null` rather than absent (an empty slot is `null` on the wire: `JSON.stringify` and the Rust serializer both write it). The local union spells those\n * variants out explicitly so consumers (ServerBridge.tsx parser, debugger\n * inspector) get accurate completions instead of `unknown[]`.\n *\n * `slot` is a plain `string` in this wire shape (not `UISlot`'s literal\n * union) because the runtime forwards the raw string from the trait's\n * `(render-ui slot ...)` SExpr without re-validating against the registry —\n * registry validation lives in `orbital validate` / `lolo` parse, not here.\n */\nexport type ClientRenderUITuple = ['render-ui', string, JsonObject | null];\n\nexport type ClientNavigateTuple =\n | ['navigate', string]\n | ['navigate', string, Record<string, string> | null]\n | ['navigate', string, Record<string, string> | null, { crumb?: string }];\n\nexport type ClientNavigateBackTuple = ['navigate-back'];\n\n/** A `runsOn: client` host-port effect (`auth/sign-out`, `audio/*`) the client host answers; its arguments are resolved. */\nexport type ClientHostAskTuple = ['host-ask', string, JsonValue[]] | ['host-ask', string, JsonValue[], HostAskCompletion];\n\n/**\n * The return address of a `host-ask` that declared `emit` routes (EXEC-DIST-13): the host answers once by dispatching\n * the event of the outcome it reached to `trait` (on `entityId` when the frame is a row); an absent route fires nothing.\n */\nexport type HostAskCompletion = {\n trait: string;\n entityId?: string;\n key?: string;\n success?: string;\n failure?: string;\n};\n\nexport type ClientEffectTuple =\n | ClientRenderUITuple\n | ClientNavigateTuple\n | ClientNavigateBackTuple\n | ClientHostAskTuple;\n\n/** Zod twin of `ClientRenderUITuple`. */\nexport const ClientRenderUITupleSchema = z.tuple([z.literal('render-ui'), z.string(), z.record(z.string(), JsonValueSchema).nullable()]);\n\n/** Zod twin of `ClientNavigateTuple` — one variant per fixed arity (2/3/4), unioned. */\nexport const ClientNavigateTupleSchema = z.union([\n z.tuple([z.literal('navigate'), z.string()]),\n z.tuple([z.literal('navigate'), z.string(), z.record(z.string(), z.string()).nullable()]),\n z.tuple([\n z.literal('navigate'),\n z.string(),\n z.record(z.string(), z.string()).nullable(),\n z.object({ crumb: z.string().optional() }),\n ]),\n]);\n\n/** Zod twin of `ClientNavigateBackTuple`. */\nexport const ClientNavigateBackTupleSchema = z.tuple([z.literal('navigate-back')]);\n\n/** Zod twin of `ClientHostAskTuple`. */\nexport const HostAskCompletionSchema = z.object({\n trait: z.string(),\n entityId: z.string().optional(),\n key: z.string().optional(),\n success: z.string().optional(),\n failure: z.string().optional(),\n}).strict();\n\nexport const ClientHostAskTupleSchema = z.union([\n z.tuple([z.literal('host-ask'), z.string(), z.array(JsonValueSchema)]),\n z.tuple([z.literal('host-ask'), z.string(), z.array(JsonValueSchema), HostAskCompletionSchema]),\n]);\n\n/** Zod twin of `ClientEffectTuple`. */\nexport const ClientEffectTupleSchema: z.ZodType<ClientEffectTuple> = z.union([\n ClientRenderUITupleSchema,\n ClientNavigateTupleSchema,\n ClientNavigateBackTupleSchema,\n ClientHostAskTupleSchema,\n]);\n\n// ============================================================================\n// Event dispatch wire (single owner — canonical = the TS runtime)\n// ============================================================================\n\n/** The lifecycle events a trait runs when it enters a page (the first it handles). */\nexport const LIFECYCLE_EVENTS = [\"INIT\", \"LOAD\", \"$MOUNT\"] as const;\n\n/** Wire-only event a client sends when a trait leaves the page; the server stops counting it as mounted. */\nexport const UNMOUNT_EVENT = '$UNMOUNT';\n\n/** An event key without its `UI:` bus prefix. */\nexport function normalizeEventKey(eventKey: string): string {\n if (!eventKey) return '';\n return eventKey.startsWith('UI:') ? eventKey.slice(3) : eventKey;\n}\n\n/** The event a tick firing carries on the wire (`EventRequest.event` of a `runTick` leg). */\nexport function tickEventKey(tickName: string): string {\n return `$TICK_${tickName}`;\n}\nexport type LifecycleEvent = (typeof LIFECYCLE_EVENTS)[number];\n\n/** One trait of a mount batch and the lifecycle event it runs. */\nexport type MountSeed = {\n trait: string;\n event: LifecycleEvent;\n};\n\nexport const MountSeedSchema = z.object({ trait: z.string(), event: z.enum(LIFECYCLE_EVENTS) });\n\n/**\n * A request on the outside-client input channel (`POST /:orbital/inputs`): an\n * API caller, an agent acting as the user, an MCP client. Only an event the\n * target trait declares as an external input (`listens { EVENT -> external { … } }`)\n * is dispatched; anything else is refused with `not-an-external-input`.\n */\nexport type ExternalInputRequest = {\n targetTrait: string;\n event: string;\n payload?: EventPayload;\n user?: RawUserClaims;\n entityId?: string;\n};\n\nexport type EventStreamItem =\n | { type: 'event'; data: EmittedEvent; timestamp: number }\n | { type: 'effect'; data: ClientEffectTuple; timestamp: number }\n | { type: 'complete'; data: EventResponse; timestamp: number }\n | { type: 'error'; data: { message: string }; timestamp: number };\n\nexport const EventStreamItemSchema = z.union([\n z.object({ type: z.literal('event'), data: EmittedEventSchema, timestamp: z.number() }),\n z.object({ type: z.literal('effect'), data: ClientEffectTupleSchema, timestamp: z.number() }),\n z.object({ type: z.literal('complete'), data: z.custom<EventResponse>((v) => JsonValueSchema.safeParse(v).success && isEventResponse(JsonValueSchema.parse(v))), timestamp: z.number() }),\n z.object({ type: z.literal('error'), data: z.object({ message: z.string() }), timestamp: z.number() }),\n]);\n\n/** How a host answered a `program/dispatch` event request: the response, or the route's failure code and status. */\nexport type DispatchRequestOutcome =\n | { ok: true; response: EventResponse; streamItems?: EventStreamItem[] }\n | { ok: false; error: string; code: string; status: number };\n\n/**\n * What a host lends one service call so the service can act in the running app\n * AS THE CALLER (an agent operating the app for the signed-in user): the\n * declared inputs, the outside-client input channel, and a read that applies the\n * entity's `@read` policy. Built per call, bound to the caller's identity and\n * position; every dispatch is a full, ordinary dispatch (guards, policies,\n * listens). The interpreter and the compiled server each supply one.\n */\nexport interface ServiceHostPorts {\n /** The orbital and trait whose `call-service` is running. */\n caller: { orbital: string; trait: string };\n inputs(): ExternalInput[];\n /** The entities `read` serves: every persisted entity of the program (`readableEntitiesOf`). */\n readableEntities(): string[];\n dispatchInput(orbital: string, request: Omit<ExternalInputRequest, 'user'>): Promise<EventResponse>;\n read(entity: string): Promise<EntityRow[]>;\n /**\n * A `program/dispatch` event request (owner, 2026-10-21): dispatch `request` on `orbital` as the HTTP events\n * route does (`input: true` admits only a declared external input, as the inputs route). `request` is what the kernel\n * parsed (`EventRequest::from_dispatch`); its `user` is the dispatch's viewer when the call names one.\n * A host that does not serve event requests leaves it out.\n */\n supportsDispatchStream?: true;\n dispatchRequest?(orbital: string, request: EventRequest, input: boolean, stream?: boolean): Promise<DispatchRequestOutcome>;\n /** A `program/dispatch { inbound }` delivery through the inbound route, credential check and answer path. */\n deliverInbound?(name: string, delivery: { headers: Readonly<Record<string, string>>; rawBody: string }): Promise<{ status: number; body: string }>;\n /** The host's last `steps` traced dispatch steps, oldest first; a host that keeps no trace leaves it out. */\n trace?(steps: number): JsonValue[];\n /** A `program/resolve-rows` ask: `reference` resolved for the identity bound to `clientId`'s session (none: the anonymous viewer), `@read` applied by the kernel's one resolver. */\n resolveRows?(reference: RowSetRef, clientId: string | undefined): Promise<RowQueryPage>;\n /**\n * Deliver one message of the running call to the caller's tab, live, as the\n * call site's `emit.onMessage` event source-stamped to the caller. A no-op\n * when the call site declares no `onMessage`.\n */\n message(payload: EventPayload): void;\n}\n\n// ============================================================================\n// Register wire (client → server schema registration)\n// ============================================================================\n\n/**\n * Where circuit state lives between events (`docs/Almadar_Runtime_Stateless_Stateful_PLAN.md` §1a):\n * `'stateless'` = the client carries it on every request, `'stateful'` = the server holds it.\n */\nexport type ServerTopology = 'stateless' | 'stateful';\n\nexport const ServerTopologySchema = z.enum(['stateless', 'stateful']);\n\n/** `POST /register` response. `topology` absent = a server that predates the declaration. */\nexport interface OrbitalRegisterResponse {\n success: boolean;\n topology?: ServerTopology;\n message?: string;\n orbitals?: string[];\n error?: string;\n}\n\nexport const OrbitalRegisterResponseSchema: z.ZodType<OrbitalRegisterResponse, object> = z.object({\n success: z.boolean(),\n topology: ServerTopologySchema.optional(),\n message: z.string().optional(),\n orbitals: z.array(z.string()).optional(),\n error: z.string().optional(),\n});\n\n// ============================================================================\n// Live broadcast wire (server → other connected clients)\n// ============================================================================\n\n/**\n * One persist-envelope success emit, handed to the live-broadcast sink\n * (`OrbitalServerRuntime.setLiveBroadcastSink`) and relayed to every OTHER\n * connected client. Fired only from the `persist` effect's `emit:{success}`\n * envelope (batch and single-op) — never from the generic emit funnel — so\n * transport layers can fan it out without matching on event names. Promoted\n * from `@almadar/runtime`'s own `LiveBroadcastItem` (canonical per Program\n * A's \"converge on the TS runtime\" ruling) so `orbital-server`'s `GET\n * /api/events` broadcast mirrors the same shape.\n */\nexport interface LiveBroadcastItem {\n event: string;\n payload?: EventPayload;\n source: BusEventSource;\n /** `clientId` of the request that produced this emit; excluded from delivery by the transport. */\n originClientId?: string;\n}\n\n/** Zod twin of `LiveBroadcastItem`. Third type param `object`, see `BusEventSourceSchema`. */\nexport const LiveBroadcastItemSchema: z.ZodType<LiveBroadcastItem, object> = z.object({\n event: z.string(),\n payload: EventPayloadSchema.optional(),\n source: BusEventSourceSchema,\n originClientId: z.string().optional(),\n});\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/types/json.ts
|
|
4
|
+
var JsonValueSchema = z.lazy(
|
|
5
|
+
() => z.union([z.string(), z.number(), z.boolean(), z.null(), z.array(JsonValueSchema), z.record(z.string(), JsonValueSchema)])
|
|
6
|
+
);
|
|
7
|
+
function isJsonPrimitive(value) {
|
|
8
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
9
|
+
}
|
|
10
|
+
function isJsonObject(value) {
|
|
11
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function isJsonArray(value) {
|
|
14
|
+
return Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function jsonFormOf(value) {
|
|
17
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
18
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
19
|
+
if (typeof value === "bigint") throw new TypeError("A bigint has no JSON form");
|
|
20
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol") return void 0;
|
|
21
|
+
if (value instanceof Date) return value.toISOString();
|
|
22
|
+
if (Array.isArray(value)) return value.map((item) => jsonFormOf(item) ?? null);
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const [key, item] of Object.entries(value)) {
|
|
25
|
+
const form = jsonFormOf(item);
|
|
26
|
+
if (form !== void 0) out[key] = form;
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
function toPayloadValue(value) {
|
|
31
|
+
if (value === null || value === void 0) return null;
|
|
32
|
+
const form = jsonFormOf(value);
|
|
33
|
+
if (form === void 0) throw new TypeError("A function has no JSON form");
|
|
34
|
+
return form;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { JsonValueSchema, isJsonArray, isJsonObject, isJsonPrimitive, toPayloadValue };
|
|
38
|
+
//# sourceMappingURL=chunk-7GHJU5WI.js.map
|
|
39
|
+
//# sourceMappingURL=chunk-7GHJU5WI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/json.ts"],"names":[],"mappings":";;;AA4CO,IAAM,kBAAwC,CAAA,CAAE,IAAA;AAAA,EAAK,MAC1D,CAAA,CAAE,KAAA,CAAM,CAAC,CAAA,CAAE,MAAA,EAAO,EAAG,CAAA,CAAE,MAAA,EAAO,EAAG,CAAA,CAAE,OAAA,EAAQ,EAAG,CAAA,CAAE,IAAA,EAAK,EAAG,CAAA,CAAE,KAAA,CAAM,eAAe,CAAA,EAAG,CAAA,CAAE,MAAA,CAAO,CAAA,CAAE,MAAA,EAAO,EAAG,eAAe,CAAC,CAAC;AAC1H;AA+BO,SAAS,gBACd,KAAA,EAC2C;AAC3C,EAAA,OACE,KAAA,KAAU,QACP,OAAO,KAAA,KAAU,YACjB,OAAO,KAAA,KAAU,QAAA,IACjB,OAAO,KAAA,KAAU,SAAA;AAExB;AAKO,SAAS,aAAa,KAAA,E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IAAA;AAClD,EAAA,MAAM,IAAA,GAAO,WAAW,KAAK,CAAA;AAC7B,EAAA,IAAI,IAAA,KAAS,MAAA,EAAW,MAAM,IAAI,UAAU,6BAA6B,CAAA;AACzE,EAAA,OAAO,IAAA;AACT","file":"chunk-7GHJU5WI.js","sourcesContent":["/**\n * JSON primitives — the universal \"data crossed a boundary\" type.\n *\n * Every value that arrives over the wire from an LLM (tool-call args),\n * from disk (workspace files), or from an HTTP body before\n * domain-specific validation is a `JsonValue`. Narrow with a typed\n * predicate (`is`-guard) at the boundary; don't widen back to `unknown`.\n *\n * `JsonObject` and `ToolArgs` are aliases for the common\n * `Record<string, JsonValue>` shape. `ToolArgs` is the name the\n * agent surface uses for LLM-emitted tool-call arguments; `JsonObject`\n * is the general-purpose alias. They are the same type — the alias\n * exists so call sites read at the right semantic level.\n *\n * Why not `Record<string, unknown>`? Two reasons. (1) `unknown` widens\n * back to anything, which defeats the purpose of typing the boundary.\n * (2) The `@almadar/eslint-plugin/no-record-string-unknown` rule blocks\n * the wider form — `JsonValue`-based records are the typed answer.\n *\n * @packageDocumentation\n */\n\nimport { z } from 'zod';\nimport type { EventPayloadValue } from './expression.js';\n\n/**\n * Recursive JSON value union — every shape JSON can carry.\n */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue };\n\n/**\n * JSON object — keyed string→JsonValue. The wire form of arbitrary\n * structured data. Replaces `Record<string, unknown>` at typed\n * boundaries (LLM emits, file reads, HTTP bodies).\n */\nexport type JsonObject = { [key: string]: JsonValue };\n\n/** Zod schema for JsonValue — the one boundary validator for parsed-JSON slots. */\nexport const JsonValueSchema: z.ZodType<JsonValue> = z.lazy(() =>\n z.union([z.string(), z.number(), z.boolean(), z.null(), z.array(JsonValueSchema), z.record(z.string(), JsonValueSchema)]),\n);\n\n/**\n * LLM tool-call arguments — same shape as `JsonObject`, named for the\n * agent-surface call site. Each tool's `execute(args: ToolArgs)`\n * receives this and narrows via an `is`-guard predicate before any\n * field access.\n */\nexport type ToolArgs = JsonObject;\n\n/**\n * Universal type-guard input — every runtime value shape a predicate can\n * be handed, enumerated instead of `unknown` (the repo bans `unknown`\n * even at guard boundaries). Primitives cover every `typeof` result;\n * `object` covers arrays, records, class instances, and functions.\n */\nexport type RuntimeValue =\n | string\n | number\n | bigint\n | boolean\n | symbol\n | Date\n | null\n | undefined\n | object;\n\n/**\n * Type guard: is the given value a JSON primitive (non-array,\n * non-object)? Used by walkers that decide whether to recurse.\n */\nexport function isJsonPrimitive(\n value: JsonValue,\n): value is string | number | boolean | null {\n return (\n value === null\n || typeof value === 'string'\n || typeof value === 'number'\n || typeof value === 'boolean'\n );\n}\n\n/**\n * Type guard: is the given value a JSON object (non-array, non-null)?\n */\nexport function isJsonObject(value: JsonValue): value is JsonObject {\n return (\n value !== null\n && typeof value === 'object'\n && !Array.isArray(value)\n );\n}\n\n/**\n * Type guard: is the given value a JSON array?\n */\nexport function isJsonArray(value: JsonValue): value is JsonValue[] {\n return Array.isArray(value);\n}\n\n/** The JSON form of a runtime value, as `JSON.stringify` would write it; `undefined` when JSON drops the value (undefined, function, symbol). */\nfunction jsonFormOf(value: RuntimeValue): JsonValue | undefined {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return value;\n if (typeof value === 'number') return Number.isFinite(value) ? value : null;\n if (typeof value === 'bigint') throw new TypeError('A bigint has no JSON form');\n if (value === undefined || typeof value === 'function' || typeof value === 'symbol') return undefined;\n if (value instanceof Date) return value.toISOString();\n if (Array.isArray(value)) return value.map((item: RuntimeValue) => jsonFormOf(item) ?? null);\n const out: JsonObject = {};\n for (const [key, item] of Object.entries(value)) {\n const form = jsonFormOf(item);\n if (form !== undefined) out[key] = form;\n }\n return out;\n}\n\n/**\n * A rich value the UI hands back (a program schema, a selected node) as an event payload value:\n * its JSON form, which is what the event wire carries. `JsonValue` is a payload value.\n */\nexport function toPayloadValue(value: object | null | undefined): EventPayloadValue {\n if (value === null || value === undefined) return null;\n const form = jsonFormOf(value);\n if (form === undefined) throw new TypeError('A function has no JSON form');\n return form;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/types/own-key.ts
|
|
2
|
+
function setOwn(target, key, value) {
|
|
3
|
+
Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { setOwn };
|
|
7
|
+
//# sourceMappingURL=chunk-B4MNHGBP.js.map
|
|
8
|
+
//# sourceMappingURL=chunk-B4MNHGBP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/own-key.ts"],"names":[],"mappings":";AACO,SAAS,MAAA,CAAU,MAAA,EAAgC,GAAA,EAAa,KAAA,EAAgB;AACrF,EAAA,MAAA,CAAO,cAAA,CAAe,MAAA,EAAQ,GAAA,EAAK,EAAE,KAAA,EAAO,QAAA,EAAU,IAAA,EAAM,UAAA,EAAY,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,CAAA;AACpG","file":"chunk-B4MNHGBP.js","sourcesContent":["/** Writes `key` as an own data property, so `\"__proto__\"` is an ordinary key and never the prototype setter. */\nexport function setOwn<T>(target: { [key in string]: T }, key: string, value: T): void {\n Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });\n}\n"]}
|