@niscorp/nova 0.2.0 → 0.2.2

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 (111) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +56 -13
  3. package/SHELL_DOCS.md +13 -4
  4. package/dist/adapters/dom/components/index.cjs +4 -51
  5. package/dist/adapters/dom/components/index.cjs.map +1 -1
  6. package/dist/adapters/dom/index.cjs +22 -686
  7. package/dist/adapters/dom/index.cjs.map +1 -1
  8. package/dist/adapters/dom/index.js +2 -2
  9. package/dist/adapters/dom/server.cjs +14 -411
  10. package/dist/adapters/dom/server.cjs.map +1 -1
  11. package/dist/adapters/dom/server.js +2 -2
  12. package/dist/adapters/react/components/index.cjs +87 -562
  13. package/dist/adapters/react/components/index.cjs.map +1 -1
  14. package/dist/adapters/react/components/index.d.cts +2 -2
  15. package/dist/adapters/react/components/index.d.ts +2 -2
  16. package/dist/adapters/react/components/index.js +3 -3
  17. package/dist/adapters/react/index.cjs +97 -1815
  18. package/dist/adapters/react/index.cjs.map +1 -1
  19. package/dist/adapters/react/index.js +3 -3
  20. package/dist/adapters/tty/components/index.cjs +3 -44
  21. package/dist/adapters/tty/components/index.cjs.map +1 -1
  22. package/dist/adapters/tty/index.cjs +13 -5
  23. package/dist/adapters/tty/index.cjs.map +1 -1
  24. package/dist/adapters/tty/index.js +1 -1
  25. package/dist/adapters/vue/components/index.cjs +88 -639
  26. package/dist/adapters/vue/components/index.cjs.map +1 -1
  27. package/dist/adapters/vue/components/index.d.cts +10 -10
  28. package/dist/adapters/vue/components/index.d.ts +10 -10
  29. package/dist/adapters/vue/components/index.js +3 -3
  30. package/dist/adapters/vue/index.cjs +96 -962
  31. package/dist/adapters/vue/index.cjs.map +1 -1
  32. package/dist/adapters/vue/index.js +4 -4
  33. package/dist/agent/index.cjs +13 -151
  34. package/dist/agent/index.cjs.map +1 -1
  35. package/dist/chunk-3IPM5QBT.cjs +436 -0
  36. package/dist/chunk-3IPM5QBT.cjs.map +1 -0
  37. package/dist/chunk-5AF72LOE.cjs +97 -0
  38. package/dist/chunk-5AF72LOE.cjs.map +1 -0
  39. package/dist/chunk-5YQIAS4V.cjs +184 -0
  40. package/dist/chunk-5YQIAS4V.cjs.map +1 -0
  41. package/dist/chunk-D4PUWBN6.cjs +72 -0
  42. package/dist/chunk-D4PUWBN6.cjs.map +1 -0
  43. package/dist/{chunk-RYIIIXDX.js → chunk-DU2VIJAF.js} +57 -15
  44. package/dist/chunk-DU2VIJAF.js.map +1 -0
  45. package/dist/{chunk-VU6NNCEJ.js → chunk-F2H7WP6R.js} +4 -4
  46. package/dist/{chunk-VU6NNCEJ.js.map → chunk-F2H7WP6R.js.map} +1 -1
  47. package/dist/chunk-FSUMCJAR.cjs +646 -0
  48. package/dist/chunk-FSUMCJAR.cjs.map +1 -0
  49. package/dist/{chunk-QXQCPH33.js → chunk-G4LSLLGI.js} +4 -4
  50. package/dist/{chunk-QXQCPH33.js.map → chunk-G4LSLLGI.js.map} +1 -1
  51. package/dist/chunk-GV7UC3SS.cjs +33 -0
  52. package/dist/chunk-GV7UC3SS.cjs.map +1 -0
  53. package/dist/chunk-IZ2UU5UL.cjs +808 -0
  54. package/dist/chunk-IZ2UU5UL.cjs.map +1 -0
  55. package/dist/chunk-KOYRJXTI.cjs +123 -0
  56. package/dist/chunk-KOYRJXTI.cjs.map +1 -0
  57. package/dist/chunk-KW34ZKF5.cjs +12 -0
  58. package/dist/chunk-KW34ZKF5.cjs.map +1 -0
  59. package/dist/chunk-OE527MXF.cjs +49 -0
  60. package/dist/chunk-OE527MXF.cjs.map +1 -0
  61. package/dist/chunk-OO247V4J.cjs +2117 -0
  62. package/dist/chunk-OO247V4J.cjs.map +1 -0
  63. package/dist/chunk-PMKWYOOX.cjs +64 -0
  64. package/dist/chunk-PMKWYOOX.cjs.map +1 -0
  65. package/dist/chunk-PNQY6OFB.cjs +132 -0
  66. package/dist/chunk-PNQY6OFB.cjs.map +1 -0
  67. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  68. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  69. package/dist/{chunk-MHW5VEIM.js → chunk-SVNK5NIK.js} +3 -3
  70. package/dist/{chunk-MHW5VEIM.js.map → chunk-SVNK5NIK.js.map} +1 -1
  71. package/dist/chunk-TMLNVU5W.cjs +318 -0
  72. package/dist/chunk-TMLNVU5W.cjs.map +1 -0
  73. package/dist/chunk-TRJYDVWK.cjs +623 -0
  74. package/dist/chunk-TRJYDVWK.cjs.map +1 -0
  75. package/dist/chunk-UGG7MCX4.cjs +34 -0
  76. package/dist/chunk-UGG7MCX4.cjs.map +1 -0
  77. package/dist/{chunk-UDCXGDLQ.js → chunk-VOD5JA4D.js} +3 -3
  78. package/dist/{chunk-UDCXGDLQ.js.map → chunk-VOD5JA4D.js.map} +1 -1
  79. package/dist/chunk-WGPFR7MN.cjs +808 -0
  80. package/dist/chunk-WGPFR7MN.cjs.map +1 -0
  81. package/dist/chunk-WGZZKCJQ.cjs +157 -0
  82. package/dist/chunk-WGZZKCJQ.cjs.map +1 -0
  83. package/dist/chunk-XQTI4Q4I.js +178 -0
  84. package/dist/chunk-XQTI4Q4I.js.map +1 -0
  85. package/dist/devtools/index.cjs +13 -697
  86. package/dist/devtools/index.cjs.map +1 -1
  87. package/dist/document/index.cjs +56 -301
  88. package/dist/document/index.cjs.map +1 -1
  89. package/dist/examples/index.cjs +1161 -0
  90. package/dist/examples/index.cjs.map +1 -0
  91. package/dist/examples/index.d.cts +63 -0
  92. package/dist/examples/index.d.ts +63 -0
  93. package/dist/examples/index.js +1158 -0
  94. package/dist/examples/index.js.map +1 -0
  95. package/dist/i18n/index.cjs +44 -292
  96. package/dist/i18n/index.cjs.map +1 -1
  97. package/dist/i18n/index.js +2 -176
  98. package/dist/i18n/index.js.map +1 -1
  99. package/dist/index.cjs +335 -3911
  100. package/dist/index.cjs.map +1 -1
  101. package/dist/index.d.cts +5 -1
  102. package/dist/index.d.ts +5 -1
  103. package/dist/index.js +1 -1
  104. package/dist/migrations/index.cjs +7 -590
  105. package/dist/migrations/index.cjs.map +1 -1
  106. package/dist/reflect/index.cjs +85 -994
  107. package/dist/reflect/index.cjs.map +1 -1
  108. package/package.json +19 -8
  109. package/dist/chunk-RYIIIXDX.js.map +0 -1
  110. package/dist/{primitive-props-CGoJvmcH.d.cts → primitive-props-Cl5jiC8g.d.cts} +5 -5
  111. package/dist/{primitive-props-CGoJvmcH.d.ts → primitive-props-Cl5jiC8g.d.ts} +5 -5
@@ -0,0 +1,646 @@
1
+ 'use strict';
2
+
3
+ var chunkD4PUWBN6_cjs = require('./chunk-D4PUWBN6.cjs');
4
+ var chunkKW34ZKF5_cjs = require('./chunk-KW34ZKF5.cjs');
5
+ var zod = require('zod');
6
+
7
+ // src/shared/errors.ts
8
+ var ErrorCodes = {
9
+ render: "RENDER_ERROR",
10
+ componentNotFound: "COMPONENT_NOT_FOUND",
11
+ layoutRefNotFound: "LAYOUT_REF_NOT_FOUND",
12
+ definitionValidation: "DEFINITION_VALIDATION_ERROR",
13
+ unknownAction: "UNKNOWN_ACTION",
14
+ unknownFragment: "UNKNOWN_FRAGMENT",
15
+ unknownFunction: "UNKNOWN_FUNCTION",
16
+ shellDisposed: "SHELL_DISPOSED",
17
+ lifecycle: "LIFECYCLE_ERROR",
18
+ mutation: "MUTATION_ERROR",
19
+ runaway: "RUNAWAY_CHAIN"
20
+ };
21
+ var NovaError = class extends Error {
22
+ code;
23
+ context;
24
+ constructor(code, message, context, options) {
25
+ super(message, options);
26
+ this.name = "NovaError";
27
+ this.code = code;
28
+ this.context = context;
29
+ }
30
+ };
31
+ var RenderError = class extends NovaError {
32
+ constructor(message, context, options) {
33
+ super(ErrorCodes.render, message, context, options);
34
+ this.name = "RenderError";
35
+ }
36
+ };
37
+ var ComponentNotFoundError = class extends NovaError {
38
+ constructor(message, context, options) {
39
+ super(ErrorCodes.componentNotFound, message, context, options);
40
+ this.name = "ComponentNotFoundError";
41
+ }
42
+ };
43
+ var LayoutRefNotFoundError = class extends NovaError {
44
+ constructor(message, context, options) {
45
+ super(ErrorCodes.layoutRefNotFound, message, context, options);
46
+ this.name = "LayoutRefNotFoundError";
47
+ }
48
+ };
49
+ var DefinitionValidationError = class extends NovaError {
50
+ constructor(message, context, options) {
51
+ super(ErrorCodes.definitionValidation, message, context, options);
52
+ this.name = "DefinitionValidationError";
53
+ }
54
+ };
55
+ var UnknownActionError = class extends NovaError {
56
+ constructor(message, context, options) {
57
+ super(ErrorCodes.unknownAction, message, context, options);
58
+ this.name = "UnknownActionError";
59
+ }
60
+ };
61
+ var UnknownFragmentError = class extends NovaError {
62
+ constructor(message, context, options) {
63
+ super(ErrorCodes.unknownFragment, message, context, options);
64
+ this.name = "UnknownFragmentError";
65
+ }
66
+ };
67
+ var ShellDisposedError = class extends NovaError {
68
+ constructor(message, context, options) {
69
+ super(ErrorCodes.shellDisposed, message, context, options);
70
+ this.name = "ShellDisposedError";
71
+ }
72
+ };
73
+ var UnknownFunctionError = class extends NovaError {
74
+ constructor(name, options) {
75
+ super(
76
+ ErrorCodes.unknownFunction,
77
+ `Unknown function: "${name}". Is it registered in shell config's \`functions\` map?`,
78
+ { name },
79
+ options
80
+ );
81
+ this.name = "UnknownFunctionError";
82
+ }
83
+ };
84
+ var LifecycleError = class extends NovaError {
85
+ constructor(message, context, options) {
86
+ super(ErrorCodes.lifecycle, message, context, options);
87
+ this.name = "LifecycleError";
88
+ }
89
+ };
90
+ var MutationError = class extends NovaError {
91
+ constructor(message, context, options) {
92
+ super(ErrorCodes.mutation, message, context, options);
93
+ this.name = "MutationError";
94
+ }
95
+ };
96
+
97
+ // src/shared/bindings/paths.ts
98
+ var splitPath = (path) => {
99
+ if (path.length === 0) return [];
100
+ return path.split(".");
101
+ };
102
+ var isIndex = (segment) => /^\d+$/.test(segment);
103
+ var cloneContainer = (value, nextSegment) => {
104
+ if (chunkKW34ZKF5_cjs.isArray(value)) return value.slice();
105
+ if (chunkKW34ZKF5_cjs.isObject(value)) return { ...value };
106
+ if (nextSegment !== void 0 && isIndex(nextSegment)) return [];
107
+ return {};
108
+ };
109
+ var writeSegment = (container, segment, value) => {
110
+ if (chunkKW34ZKF5_cjs.isArray(container)) {
111
+ if (isIndex(segment)) {
112
+ const index = Number.parseInt(segment, 10);
113
+ container[index] = value;
114
+ }
115
+ return;
116
+ }
117
+ container[segment] = value;
118
+ };
119
+ var readSegment = (container, segment) => {
120
+ if (chunkKW34ZKF5_cjs.isArray(container)) {
121
+ if (!isIndex(segment)) return void 0;
122
+ const index = Number.parseInt(segment, 10);
123
+ return container[index];
124
+ }
125
+ return container[segment];
126
+ };
127
+ var getPath = (data, path) => {
128
+ const segments = splitPath(path);
129
+ let current = data;
130
+ for (const segment of segments) {
131
+ if (current === void 0 || current === null) return void 0;
132
+ if (chunkKW34ZKF5_cjs.isArray(current)) {
133
+ if (isIndex(segment)) {
134
+ const index = Number.parseInt(segment, 10);
135
+ current = current[index];
136
+ continue;
137
+ }
138
+ if (segment === "length") {
139
+ current = current.length;
140
+ continue;
141
+ }
142
+ return void 0;
143
+ }
144
+ if (chunkKW34ZKF5_cjs.isObject(current)) {
145
+ if (segment in current) {
146
+ current = current[segment];
147
+ continue;
148
+ }
149
+ return void 0;
150
+ }
151
+ return void 0;
152
+ }
153
+ return current;
154
+ };
155
+ var setPath = (data, path, value) => {
156
+ const segments = splitPath(path);
157
+ if (segments.length === 0) return value;
158
+ const root = cloneContainer(data, segments[0]);
159
+ let parent = root;
160
+ for (let i = 0; i < segments.length - 1; i += 1) {
161
+ const segment = segments[i];
162
+ const nextSegment = segments[i + 1];
163
+ if (segment === void 0) continue;
164
+ const existing = readSegment(parent, segment);
165
+ const cloned = cloneContainer(existing, nextSegment);
166
+ writeSegment(parent, segment, cloned);
167
+ parent = cloned;
168
+ }
169
+ const last = segments[segments.length - 1];
170
+ if (last !== void 0) writeSegment(parent, last, value);
171
+ return root;
172
+ };
173
+ var deletePath = (data, path) => {
174
+ const segments = splitPath(path);
175
+ if (segments.length === 0) return void 0;
176
+ const root = cloneContainer(data, segments[0]);
177
+ let parent = root;
178
+ for (let i = 0; i < segments.length - 1; i += 1) {
179
+ const segment = segments[i];
180
+ const nextSegment = segments[i + 1];
181
+ if (segment === void 0) continue;
182
+ const existing = readSegment(parent, segment);
183
+ if (existing === void 0 || existing === null) return root;
184
+ const cloned = cloneContainer(existing, nextSegment);
185
+ writeSegment(parent, segment, cloned);
186
+ parent = cloned;
187
+ }
188
+ const last = segments[segments.length - 1];
189
+ if (last === void 0) return root;
190
+ if (chunkKW34ZKF5_cjs.isArray(parent)) {
191
+ if (isIndex(last)) {
192
+ const index = Number.parseInt(last, 10);
193
+ parent.splice(index, 1);
194
+ }
195
+ } else {
196
+ delete parent[last];
197
+ }
198
+ return root;
199
+ };
200
+ var SetByValueSchema = zod.z.object({
201
+ set: zod.z.string().describe('Data path to write to, e.g. "user.name" or "items.0.title".'),
202
+ value: zod.z.unknown().describe("Literal value to write at the path.")
203
+ }).strict().describe("Set a field at a path to a literal value.");
204
+ var SetByFromSchema = zod.z.object({
205
+ set: zod.z.string().describe("Data path to write to."),
206
+ from: zod.z.string().describe("Data path (or template path) to read the value from.")
207
+ }).strict().describe("Set a field at a path by copying from another path.");
208
+ var setValueOp = {
209
+ key: "set",
210
+ schema: SetByValueSchema,
211
+ match: (mutation) => chunkKW34ZKF5_cjs.hasKey(mutation, "set") && chunkKW34ZKF5_cjs.hasKey(mutation, "value"),
212
+ apply: (data, mutation) => {
213
+ const next = setPath(data, mutation.set, mutation.value);
214
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
215
+ }
216
+ };
217
+ var setFromOp = {
218
+ key: "set",
219
+ schema: SetByFromSchema,
220
+ match: (mutation) => chunkKW34ZKF5_cjs.hasKey(mutation, "set") && chunkKW34ZKF5_cjs.hasKey(mutation, "from"),
221
+ apply: (data, mutation) => {
222
+ const value = getPath(data, mutation.from);
223
+ const next = setPath(data, mutation.set, value);
224
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
225
+ }
226
+ };
227
+ var ToggleSchema = zod.z.object({
228
+ toggle: zod.z.string().describe("Boolean data path to flip.")
229
+ }).strict().describe("Flip a boolean at the given path.");
230
+ var toggleOp = {
231
+ key: "toggle",
232
+ schema: ToggleSchema,
233
+ apply: (data, mutation) => {
234
+ const current = getPath(data, mutation.toggle);
235
+ const flipped = !(current === true);
236
+ const next = setPath(data, mutation.toggle, flipped);
237
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
238
+ }
239
+ };
240
+ var IncrementSchema = zod.z.object({
241
+ increment: zod.z.string().describe("Numeric data path to increment."),
242
+ by: zod.z.number().optional().describe("Amount to increment by; defaults to 1.")
243
+ }).strict().describe("Increment a numeric field.");
244
+ var incrementOp = {
245
+ key: "increment",
246
+ schema: IncrementSchema,
247
+ apply: (data, mutation) => {
248
+ const current = getPath(data, mutation.increment);
249
+ const base = typeof current === "number" ? current : 0;
250
+ const by = mutation.by ?? 1;
251
+ const next = setPath(data, mutation.increment, base + by);
252
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
253
+ }
254
+ };
255
+ var DecrementSchema = zod.z.object({
256
+ decrement: zod.z.string().describe("Numeric data path to decrement."),
257
+ by: zod.z.number().optional().describe("Amount to decrement by; defaults to 1.")
258
+ }).strict().describe("Decrement a numeric field.");
259
+ var decrementOp = {
260
+ key: "decrement",
261
+ schema: DecrementSchema,
262
+ apply: (data, mutation) => {
263
+ const current = getPath(data, mutation.decrement);
264
+ const base = typeof current === "number" ? current : 0;
265
+ const by = mutation.by ?? 1;
266
+ const next = setPath(data, mutation.decrement, base - by);
267
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
268
+ }
269
+ };
270
+ var PushSchema = zod.z.object({
271
+ push: zod.z.string().describe("Array data path to append to."),
272
+ value: zod.z.unknown().optional().describe("Value to append.")
273
+ }).strict().describe("Append a value to an array field.");
274
+ var pushOp = {
275
+ key: "push",
276
+ schema: PushSchema,
277
+ // Guard against the PushEffect navigation effect whose `push` is an object.
278
+ match: (mutation) => typeof mutation.push === "string",
279
+ apply: (data, mutation, ctx) => {
280
+ const current = getPath(data, mutation.push);
281
+ if (current !== void 0 && !chunkKW34ZKF5_cjs.isArray(current)) {
282
+ if (ctx.strict) {
283
+ throw new MutationError(
284
+ `push: path "${mutation.push}" is not an array`,
285
+ { op: "push", path: mutation.push, reason: "wrong-type" }
286
+ );
287
+ }
288
+ return data;
289
+ }
290
+ if (current === void 0 && ctx.strict) {
291
+ throw new MutationError(
292
+ `push: path "${mutation.push}" does not exist`,
293
+ { op: "push", path: mutation.push, reason: "missing" }
294
+ );
295
+ }
296
+ const arr = chunkKW34ZKF5_cjs.isArray(current) ? current.slice() : [];
297
+ arr.push(mutation.value);
298
+ const next = setPath(data, mutation.push, arr);
299
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
300
+ }
301
+ };
302
+ var PopSchema = zod.z.object({
303
+ pop: zod.z.string().describe("Array data path to remove the last element from.")
304
+ }).strict().describe("Remove the last element from an array field.");
305
+ var popOp = {
306
+ key: "pop",
307
+ schema: PopSchema,
308
+ // Guard against the PopEffect whose `pop` is the literal `true`.
309
+ match: (mutation) => typeof mutation.pop === "string",
310
+ apply: (data, mutation, ctx) => {
311
+ const current = getPath(data, mutation.pop);
312
+ if (!chunkKW34ZKF5_cjs.isArray(current)) {
313
+ if (ctx.strict) {
314
+ throw new MutationError(
315
+ `pop: path "${mutation.pop}" ${current === void 0 ? "does not exist" : "is not an array"}`,
316
+ { op: "pop", path: mutation.pop, reason: current === void 0 ? "missing" : "wrong-type" }
317
+ );
318
+ }
319
+ return data;
320
+ }
321
+ const arr = current.slice();
322
+ arr.pop();
323
+ const next = setPath(data, mutation.pop, arr);
324
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
325
+ }
326
+ };
327
+ var RemoveAtSchema = zod.z.object({
328
+ removeAt: zod.z.string().describe("Array data path to remove an element from."),
329
+ index: zod.z.union([zod.z.number().int(), zod.z.string()]).describe('Index to remove. A string is a template (e.g. "{{@event.payload}}") resolved before applying.')
330
+ }).strict().describe("Remove an element at a specific index of an array field.");
331
+ var removeAtOp = {
332
+ key: "removeAt",
333
+ schema: RemoveAtSchema,
334
+ apply: (data, mutation, ctx) => {
335
+ const current = getPath(data, mutation.removeAt);
336
+ if (!chunkKW34ZKF5_cjs.isArray(current)) {
337
+ if (ctx.strict) {
338
+ throw new MutationError(
339
+ `removeAt: path "${mutation.removeAt}" ${current === void 0 ? "does not exist" : "is not an array"}`,
340
+ {
341
+ op: "removeAt",
342
+ path: mutation.removeAt,
343
+ reason: current === void 0 ? "missing" : "wrong-type"
344
+ }
345
+ );
346
+ }
347
+ return data;
348
+ }
349
+ const index = Number(mutation.index);
350
+ if (!Number.isInteger(index)) return data;
351
+ const arr = current.slice();
352
+ arr.splice(index, 1);
353
+ const next = setPath(data, mutation.removeAt, arr);
354
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
355
+ }
356
+ };
357
+ var MoveSchema = zod.z.object({
358
+ move: zod.z.string().describe("Array data path to reorder within."),
359
+ from: zod.z.union([zod.z.number().int(), zod.z.string()]).describe('Index to move. A string is a template (e.g. "{{@event.payload}}") resolved before applying.'),
360
+ to: zod.z.union([zod.z.number().int(), zod.z.string()]).describe("Destination index. A string is a template resolved before applying.")
361
+ }).strict().describe("Move an array element from one index to another.");
362
+ var moveOp = {
363
+ key: "move",
364
+ schema: MoveSchema,
365
+ apply: (data, mutation, ctx) => {
366
+ const current = getPath(data, mutation.move);
367
+ if (!chunkKW34ZKF5_cjs.isArray(current)) {
368
+ if (ctx.strict) {
369
+ throw new MutationError(
370
+ `move: path "${mutation.move}" ${current === void 0 ? "does not exist" : "is not an array"}`,
371
+ {
372
+ op: "move",
373
+ path: mutation.move,
374
+ reason: current === void 0 ? "missing" : "wrong-type"
375
+ }
376
+ );
377
+ }
378
+ return data;
379
+ }
380
+ const from = Number(mutation.from);
381
+ const to = Number(mutation.to);
382
+ if (!Number.isInteger(from) || !Number.isInteger(to)) return data;
383
+ if (from < 0 || from >= current.length) return data;
384
+ const arr = current.slice();
385
+ const [item] = arr.splice(from, 1);
386
+ arr.splice(Math.max(0, Math.min(to, arr.length)), 0, item);
387
+ const next = setPath(data, mutation.move, arr);
388
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
389
+ }
390
+ };
391
+ var ClearSchema = zod.z.object({
392
+ clear: zod.z.string().describe("Array or object data path to clear.")
393
+ }).strict().describe("Clear an array or object field.");
394
+ var clearOp = {
395
+ key: "clear",
396
+ schema: ClearSchema,
397
+ apply: (data, mutation, ctx) => {
398
+ const current = getPath(data, mutation.clear);
399
+ if (chunkKW34ZKF5_cjs.isArray(current)) {
400
+ const next2 = setPath(data, mutation.clear, []);
401
+ return chunkKW34ZKF5_cjs.isObject(next2) ? next2 : data;
402
+ }
403
+ if (chunkKW34ZKF5_cjs.isObject(current)) {
404
+ const next2 = setPath(data, mutation.clear, {});
405
+ return chunkKW34ZKF5_cjs.isObject(next2) ? next2 : data;
406
+ }
407
+ if (ctx.strict) {
408
+ throw new MutationError(
409
+ `clear: path "${mutation.clear}" ${current === void 0 ? "does not exist" : "is not an array or object"}`,
410
+ {
411
+ op: "clear",
412
+ path: mutation.clear,
413
+ reason: current === void 0 ? "missing" : "wrong-type"
414
+ }
415
+ );
416
+ }
417
+ const next = deletePath(data, mutation.clear);
418
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
419
+ }
420
+ };
421
+ var ResetSchema = zod.z.object({
422
+ reset: zod.z.string().describe("Data path to reset to its initial (definition.data) value.")
423
+ }).strict().describe("Reset a field to its initial value from the action definition.");
424
+ var resetOp = {
425
+ key: "reset",
426
+ schema: ResetSchema,
427
+ apply: (data, mutation, ctx) => {
428
+ const initialValue = getPath(ctx.initial, mutation.reset);
429
+ const next = setPath(data, mutation.reset, initialValue);
430
+ return chunkKW34ZKF5_cjs.isObject(next) ? next : data;
431
+ }
432
+ };
433
+
434
+ // src/action/mutations/ops/index.ts
435
+ var OPS = [
436
+ setValueOp,
437
+ setFromOp,
438
+ toggleOp,
439
+ incrementOp,
440
+ decrementOp,
441
+ pushOp,
442
+ popOp,
443
+ removeAtOp,
444
+ moveOp,
445
+ clearOp,
446
+ resetOp
447
+ ];
448
+ var MutationSchema = zod.z.union(
449
+ OPS.map((op) => op.schema)
450
+ ).describe("A single immutable mutation applied to the action data.");
451
+
452
+ // src/action/mutations/registry.ts
453
+ var toDispatchOp = (op) => ({
454
+ key: op.key,
455
+ match: op.match ?? ((mutation) => chunkKW34ZKF5_cjs.hasKey(mutation, op.key)),
456
+ run: (data, mutation, ctx) => op.apply(data, op.schema.parse(mutation), ctx)
457
+ });
458
+ var DISPATCH = OPS.map(toDispatchOp);
459
+ var findOp = (mutation) => {
460
+ for (const op of DISPATCH) {
461
+ if (op.match(mutation)) return op;
462
+ }
463
+ return void 0;
464
+ };
465
+ var buildCtx = (opts) => ({
466
+ initial: opts.initial ?? {},
467
+ strict: opts.strict ?? false
468
+ });
469
+ var applyMutations = (data, mutations, opts = {}) => {
470
+ if (mutations.length === 0) return data;
471
+ const ctx = buildCtx(opts);
472
+ let current = data;
473
+ for (const mutation of mutations) {
474
+ if (!chunkKW34ZKF5_cjs.isObject(mutation)) continue;
475
+ const op = findOp(mutation);
476
+ if (op === void 0) continue;
477
+ current = op.run(current, mutation, ctx);
478
+ }
479
+ return current;
480
+ };
481
+ var HttpEndpointSchema = zod.z.object({
482
+ url: zod.z.string().describe('Template URL, e.g. "/api/users/{{$.userId}}".'),
483
+ method: zod.z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).describe("HTTP method."),
484
+ headers: zod.z.record(zod.z.string(), zod.z.string()).optional().describe("Static request headers."),
485
+ request: zod.z.unknown().optional().describe(
486
+ 'Transform config run by the injected evaluator over the ACTION DATA to build the request body \u2014 EVALUATED ON EVERY CALL, so body values can follow screen state. Static parts are literal JSON; a dynamic part is an evaluator op over the data root, e.g. { "q": { "$ref": "$.search" } } makes body field q carry the current $.search each call. Requires an injected transform.'
487
+ ),
488
+ response: zod.z.unknown().optional().describe(
489
+ "Transform config run by the injected evaluator over the reply as received (`$` is the reply \u2014 object, array, or scalar) to produce the value stored at `target`. Requires an injected transform."
490
+ ),
491
+ target: zod.z.string().optional().describe("Data path to store the result at on success."),
492
+ errorTarget: zod.z.string().optional().describe("Data path to store the error at on failure."),
493
+ timeoutMs: zod.z.number().int().positive().optional().describe("How long to wait for the reply, in ms, before the call fails to onError. Defaults to the shell default (30000). Set it on an endpoint that is slow by nature \u2014 a model call that may take minutes.")
494
+ }).strict().describe("A named HTTP call. `request`/`response` shape the body/reply via the injected transform.");
495
+ var FunctionEndpointSchema = zod.z.object({
496
+ fn: zod.z.string().describe(
497
+ "Key of a function registered in `ShellConfig.functions`. The host must register the name before the action runs."
498
+ ),
499
+ target: zod.z.string().optional().describe("Data path to store the return value at on success."),
500
+ errorTarget: zod.z.string().optional().describe("Data path to store the error at on failure."),
501
+ timeoutMs: zod.z.number().int().positive().optional().describe("How long to wait for the reply, in ms, before the call fails to onError. Defaults to the shell default (30000). Set it on an endpoint that is slow by nature \u2014 a model call that may take minutes.")
502
+ }).strict().describe("A named local function call. Handler is provided via `ShellConfig.functions`.");
503
+ var EndpointConfigSchema = zod.z.union([HttpEndpointSchema, FunctionEndpointSchema]).describe("An endpoint \u2014 either an HTTP call or a local function.");
504
+ var StepSchema = zod.z.lazy(
505
+ () => zod.z.union([MutationSchema, EffectSchema]).describe("A step is either a mutation or an effect.")
506
+ );
507
+ var CallEffectSchema = zod.z.lazy(
508
+ () => zod.z.object({
509
+ call: zod.z.string().describe("Name of the endpoint to invoke."),
510
+ onSuccess: zod.z.array(StepSchema).optional().describe("Steps to run after a successful response."),
511
+ onError: zod.z.array(StepSchema).optional().describe("Steps to run after an error response (with @error scope available).")
512
+ }).strict().describe("Invoke a named endpoint with optional success/error step branches.")
513
+ );
514
+ var EmitEffectSchema = zod.z.object({
515
+ emit: zod.z.object({
516
+ channel: zod.z.string().describe("Channel name to publish on."),
517
+ payload: zod.z.unknown().optional().describe("Payload to publish; templates are resolved against the current data.")
518
+ }).strict().describe("Channel + payload to publish.")
519
+ }).strict().describe("Publish a payload to a message channel.");
520
+ var PushEffectSchema = zod.z.object({
521
+ push: zod.z.object({
522
+ action: zod.z.string().describe("Definition id of the action to push onto a canvas \u2014 MUST be an id that actually exists (an unknown id fails at click time, invisible to a mount check)."),
523
+ canvas: zod.z.string().optional().describe("Canvas id to push onto; defaults to the current canvas."),
524
+ input: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Initial input merged into the new action data. Keys must belong to the target action's declared input contract \u2014 invented keys are silently useless."),
525
+ with: zod.z.array(zod.z.string()).optional().describe("Fragment ids to compose the action with before it is instantiated. Each wraps the action (the action fills its `{ slot }`) and contributes its triggers/data; the action wins on conflict. See ActionFragment.")
526
+ }).strict().describe("Push parameters.")
527
+ }).strict().describe("Push a new action onto a canvas (escapes via onNavigate callback).");
528
+ var PopEffectSchema = zod.z.object({
529
+ pop: zod.z.literal(true).describe("Sentinel literal \u2014 must be true.")
530
+ }).strict().describe("Pop the current action (escapes via onNavigate callback).");
531
+ var ReplaceEffectSchema = zod.z.object({
532
+ replace: zod.z.object({
533
+ action: zod.z.string().describe("Definition id of the replacement action."),
534
+ canvas: zod.z.string().optional().describe("Canvas id to replace on; defaults to the current canvas."),
535
+ input: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Initial input merged into the new action data."),
536
+ with: zod.z.array(zod.z.string()).optional().describe("Fragment ids to compose the action with before it is instantiated. Each wraps the action (the action fills its `{ slot }`) and contributes its triggers/data; the action wins on conflict. See ActionFragment.")
537
+ }).strict().describe("Replace parameters.")
538
+ }).strict().describe("Replace the current action (escapes via onNavigate callback).");
539
+ var PopToEffectSchema = zod.z.object({
540
+ popTo: zod.z.object({
541
+ canvas: zod.z.string().optional().describe("Canvas id to pop on; defaults to the current canvas."),
542
+ instance: zod.z.string().describe("Pop the canvas until this instance id is on top (no-op if absent).")
543
+ }).strict().describe("Pop-to-instance parameters.")
544
+ }).strict().describe("Pop a canvas down to a given instance (escapes via onNavigate callback).");
545
+ var ResetToEffectSchema = zod.z.object({
546
+ resetTo: zod.z.object({
547
+ action: zod.z.string().describe("Definition id of the new root action."),
548
+ canvas: zod.z.string().optional().describe("Canvas id to reset; defaults to the current canvas."),
549
+ input: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Initial input merged into the new root action."),
550
+ with: zod.z.array(zod.z.string()).optional().describe("Fragment ids to compose the action with. See ActionFragment.")
551
+ }).strict().describe("Reset parameters.")
552
+ }).strict().describe("Clear a canvas and push a single new root action (escapes via onNavigate callback).");
553
+ var RemoveInstanceEffectSchema = zod.z.object({
554
+ removeInstance: zod.z.object({
555
+ canvas: zod.z.string().optional().describe("Canvas id to remove from; defaults to the current canvas."),
556
+ instance: zod.z.string().describe("Instance id to unmount and drop from the stack (no-op if absent).")
557
+ }).strict().describe("Remove-instance parameters.")
558
+ }).strict().describe("Remove one instance anywhere in a canvas stack (escapes via onNavigate callback).");
559
+ var RemoveSelfEffectSchema = zod.z.object({
560
+ removeSelf: zod.z.literal(true).describe("Sentinel literal \u2014 must be true. Removes the firing instance (desugars to removeInstance).")
561
+ }).strict().describe("Close the firing instance \u2014 the list-card X (escapes via onNavigate callback).");
562
+ var ReconcileEffectSchema = zod.z.object({
563
+ reconcile: zod.z.object({
564
+ to: zod.z.string().describe('Binding to the desired list, e.g. "$.tools" \u2014 an array of rows; anything else is an empty list.'),
565
+ action: zod.z.string().describe('The row field naming the action to place, e.g. "tool_id". Rows without it are skipped.'),
566
+ input: zod.z.string().optional().describe("The row field holding that action's input (an object), if any."),
567
+ canvas: zod.z.string().optional().describe("Canvas id to reconcile; defaults to the current canvas."),
568
+ own: zod.z.enum(["pushed", "canvas"]).optional().describe('What this step may remove: "pushed" (default) only what this action placed there; "canvas" everything on it \u2014 for an action that owns the canvas outright.'),
569
+ with: zod.z.array(zod.z.string()).optional().describe("Fragment ids to compose each placed action with. See ActionFragment.")
570
+ }).strict().describe("Reconcile parameters.")
571
+ }).strict().describe("Make a canvas hold exactly the actions a list names: push the missing, remove the unlisted, keep the rest mounted (escapes via onNavigate callback).");
572
+ var ReloadEffectSchema = zod.z.object({
573
+ reload: zod.z.literal(true).describe("Sentinel literal \u2014 must be true. Re-runs this instance's mount hook.")
574
+ }).strict().describe("Re-read the firing instance in place \u2014 the list-card open.");
575
+ var EffectSchema = zod.z.lazy(
576
+ () => zod.z.union([CallEffectSchema, EmitEffectSchema, PushEffectSchema, PopEffectSchema, ReplaceEffectSchema, PopToEffectSchema, ResetToEffectSchema, RemoveInstanceEffectSchema, RemoveSelfEffectSchema, ReconcileEffectSchema, ReloadEffectSchema]).describe("An effect that touches the outside world.")
577
+ );
578
+ var LifecycleConfigSchema = zod.z.object({
579
+ mount: zod.z.array(StepSchema).optional().describe("Steps to run when the action mounts."),
580
+ unmount: zod.z.array(StepSchema).optional().describe("Steps to run when the action unmounts."),
581
+ suspend: zod.z.array(StepSchema).optional().describe("Steps to run when the action is suspended."),
582
+ resume: zod.z.array(StepSchema).optional().describe("Steps to run when the action resumes.")
583
+ }).strict().describe("Lifecycle hooks for the action runtime state machine.");
584
+ var TriggerConfigSchema = zod.z.object({
585
+ event: zod.z.string().optional().describe(`UI event type to listen for: "ui:click" (activations, incl. table rows), "ui:model" (an input's value changed), "ui:key".`),
586
+ message: zod.z.string().optional().describe("Message bus channel name to listen on (fired by an `emit` step, possibly from another action)."),
587
+ ref: zod.z.string().optional().describe("Component ref to filter events by \u2014 MUST match a `ref` carried by a node in this action's layout; a trigger on a ref no layout node carries never fires."),
588
+ key: zod.z.string().optional().describe('Key to filter "ui:key" events by, e.g. "ArrowDown".'),
589
+ do: zod.z.array(StepSchema).describe(`Ordered steps to execute when the trigger fires. Steps may reference the firing event as "@event" \u2014 "@event.payload" is the fired value (a table row click: the row's clickKey/rowKey field; an input's ui:model: the typed text).`)
590
+ }).strict().refine((trigger) => trigger.event !== void 0 || trigger.message !== void 0, {
591
+ message: 'A trigger must specify either "event" or "message".'
592
+ }).describe("Binds an event or message source to an ordered sequence of steps.");
593
+ var ActionDefinitionSchema = zod.z.object({
594
+ id: zod.z.string().describe("Stable definition id."),
595
+ name: zod.z.string().optional().describe("Human-readable name."),
596
+ description: zod.z.string().optional().describe("Free-form description."),
597
+ title: zod.z.string().optional().describe(
598
+ "A resolvable label for this instance, evaluated against its own data (e.g. '{{$.view.record.name}}'). Exposed as `instance.title` on a canvas's actionLayout scope so stack-nav chrome can label crumbs/tabs; falls back to `name` then the action id."
599
+ ),
600
+ layout: zod.z.union([zod.z.string(), chunkD4PUWBN6_cjs.LayoutNodeSchema]).optional().describe("Either a layout id stored in the layout store, or an inline LayoutNode."),
601
+ data: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Static default data merged with input on mount."),
602
+ input: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe(
603
+ "JSON Schema of the data keys an opener may seed when loading this action \u2014 its public, openable-input contract (author in Zod, convert with z.toJSONSchema). Fields must be a subset of `data`. Descriptive only: the runtime does not validate loads against it."
604
+ ),
605
+ triggers: zod.z.array(TriggerConfigSchema).optional().describe("Event/message triggers."),
606
+ endpoints: zod.z.record(zod.z.string(), EndpointConfigSchema).optional().describe("Named endpoints \u2014 HTTP calls or local functions."),
607
+ lifecycle: LifecycleConfigSchema.optional().describe("Lifecycle hooks.")
608
+ }).strict().describe("Definition of an action: layout + data + behavior.");
609
+ var ActionFragmentSchema = zod.z.object({
610
+ kind: zod.z.literal("fragment").describe("Discriminator \u2014 marks this as an abstract, merge-only fragment."),
611
+ id: zod.z.string().describe("Stable fragment id, referenced from a push/replace `with: [...]`."),
612
+ name: zod.z.string().optional().describe("Human-readable name."),
613
+ description: zod.z.string().optional().describe("Free-form description."),
614
+ layout: zod.z.union([zod.z.string(), chunkD4PUWBN6_cjs.LayoutNodeSchema]).optional().describe('The wrapping (chrome) layout, or a layout id. Put a `{ slot: "body" }` node where the composing action\'s own layout is dropped in.'),
615
+ data: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Partial default data; deep-merged under the action (the action wins on conflict)."),
616
+ triggers: zod.z.array(TriggerConfigSchema).optional().describe("Pre-wired triggers (e.g. a modal's close/cancel). Concatenated before the action's triggers."),
617
+ endpoints: zod.z.record(zod.z.string(), EndpointConfigSchema).optional().describe("Named endpoints, merged under the action (the action wins on a name clash)."),
618
+ lifecycle: LifecycleConfigSchema.optional().describe("Lifecycle hooks; per-hook steps run before the action's.")
619
+ }).strict().describe("A reusable partial action \u2014 layout + wired behavior \u2014 merged into a concrete action at a push `with`. Abstract: only exists merged, never instantiated alone.");
620
+
621
+ exports.ActionDefinitionSchema = ActionDefinitionSchema;
622
+ exports.ActionFragmentSchema = ActionFragmentSchema;
623
+ exports.ComponentNotFoundError = ComponentNotFoundError;
624
+ exports.DefinitionValidationError = DefinitionValidationError;
625
+ exports.EffectSchema = EffectSchema;
626
+ exports.EndpointConfigSchema = EndpointConfigSchema;
627
+ exports.ErrorCodes = ErrorCodes;
628
+ exports.LayoutRefNotFoundError = LayoutRefNotFoundError;
629
+ exports.LifecycleConfigSchema = LifecycleConfigSchema;
630
+ exports.LifecycleError = LifecycleError;
631
+ exports.MutationError = MutationError;
632
+ exports.MutationSchema = MutationSchema;
633
+ exports.NovaError = NovaError;
634
+ exports.OPS = OPS;
635
+ exports.RenderError = RenderError;
636
+ exports.ShellDisposedError = ShellDisposedError;
637
+ exports.StepSchema = StepSchema;
638
+ exports.TriggerConfigSchema = TriggerConfigSchema;
639
+ exports.UnknownActionError = UnknownActionError;
640
+ exports.UnknownFragmentError = UnknownFragmentError;
641
+ exports.UnknownFunctionError = UnknownFunctionError;
642
+ exports.applyMutations = applyMutations;
643
+ exports.getPath = getPath;
644
+ exports.setPath = setPath;
645
+ //# sourceMappingURL=chunk-FSUMCJAR.cjs.map
646
+ //# sourceMappingURL=chunk-FSUMCJAR.cjs.map