@json-render/core 0.0.1
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/README.md +184 -0
- package/dist/index.d.mts +746 -0
- package/dist/index.d.ts +746 -0
- package/dist/index.js +727 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +673 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,746 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dynamic value - can be a literal or a path reference to data model
|
|
5
|
+
*/
|
|
6
|
+
type DynamicValue<T = unknown> = T | {
|
|
7
|
+
path: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Dynamic string value
|
|
11
|
+
*/
|
|
12
|
+
type DynamicString = DynamicValue<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Dynamic number value
|
|
15
|
+
*/
|
|
16
|
+
type DynamicNumber = DynamicValue<number>;
|
|
17
|
+
/**
|
|
18
|
+
* Dynamic boolean value
|
|
19
|
+
*/
|
|
20
|
+
type DynamicBoolean = DynamicValue<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Zod schema for dynamic values
|
|
23
|
+
*/
|
|
24
|
+
declare const DynamicValueSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodObject<{
|
|
25
|
+
path: z.ZodString;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
path: string;
|
|
28
|
+
}, {
|
|
29
|
+
path: string;
|
|
30
|
+
}>]>;
|
|
31
|
+
declare const DynamicStringSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
32
|
+
path: z.ZodString;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
path: string;
|
|
35
|
+
}, {
|
|
36
|
+
path: string;
|
|
37
|
+
}>]>;
|
|
38
|
+
declare const DynamicNumberSchema: z.ZodUnion<[z.ZodNumber, z.ZodObject<{
|
|
39
|
+
path: z.ZodString;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
path: string;
|
|
42
|
+
}, {
|
|
43
|
+
path: string;
|
|
44
|
+
}>]>;
|
|
45
|
+
declare const DynamicBooleanSchema: z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
|
|
46
|
+
path: z.ZodString;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
path: string;
|
|
49
|
+
}, {
|
|
50
|
+
path: string;
|
|
51
|
+
}>]>;
|
|
52
|
+
/**
|
|
53
|
+
* Base UI element structure for v2
|
|
54
|
+
*/
|
|
55
|
+
interface UIElement<T extends string = string, P = Record<string, unknown>> {
|
|
56
|
+
/** Unique key for reconciliation */
|
|
57
|
+
key: string;
|
|
58
|
+
/** Component type from the catalog */
|
|
59
|
+
type: T;
|
|
60
|
+
/** Component props */
|
|
61
|
+
props: P;
|
|
62
|
+
/** Child element keys (flat structure) */
|
|
63
|
+
children?: string[];
|
|
64
|
+
/** Parent element key (null for root) */
|
|
65
|
+
parentKey?: string | null;
|
|
66
|
+
/** Visibility condition */
|
|
67
|
+
visible?: VisibilityCondition;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Visibility condition types
|
|
71
|
+
*/
|
|
72
|
+
type VisibilityCondition = boolean | {
|
|
73
|
+
path: string;
|
|
74
|
+
} | {
|
|
75
|
+
auth: 'signedIn' | 'signedOut';
|
|
76
|
+
} | LogicExpression;
|
|
77
|
+
/**
|
|
78
|
+
* Logic expression for complex conditions
|
|
79
|
+
*/
|
|
80
|
+
type LogicExpression = {
|
|
81
|
+
and: LogicExpression[];
|
|
82
|
+
} | {
|
|
83
|
+
or: LogicExpression[];
|
|
84
|
+
} | {
|
|
85
|
+
not: LogicExpression;
|
|
86
|
+
} | {
|
|
87
|
+
path: string;
|
|
88
|
+
} | {
|
|
89
|
+
eq: [DynamicValue, DynamicValue];
|
|
90
|
+
} | {
|
|
91
|
+
neq: [DynamicValue, DynamicValue];
|
|
92
|
+
} | {
|
|
93
|
+
gt: [DynamicValue<number>, DynamicValue<number>];
|
|
94
|
+
} | {
|
|
95
|
+
gte: [DynamicValue<number>, DynamicValue<number>];
|
|
96
|
+
} | {
|
|
97
|
+
lt: [DynamicValue<number>, DynamicValue<number>];
|
|
98
|
+
} | {
|
|
99
|
+
lte: [DynamicValue<number>, DynamicValue<number>];
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Flat UI tree structure (optimized for LLM generation)
|
|
103
|
+
*/
|
|
104
|
+
interface UITree {
|
|
105
|
+
/** Root element key */
|
|
106
|
+
root: string;
|
|
107
|
+
/** Flat map of elements by key */
|
|
108
|
+
elements: Record<string, UIElement>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Auth state for visibility evaluation
|
|
112
|
+
*/
|
|
113
|
+
interface AuthState {
|
|
114
|
+
isSignedIn: boolean;
|
|
115
|
+
user?: Record<string, unknown>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Data model type
|
|
119
|
+
*/
|
|
120
|
+
type DataModel = Record<string, unknown>;
|
|
121
|
+
/**
|
|
122
|
+
* Component schema definition using Zod
|
|
123
|
+
*/
|
|
124
|
+
type ComponentSchema = z.ZodType<Record<string, unknown>>;
|
|
125
|
+
/**
|
|
126
|
+
* Validation mode for catalog validation
|
|
127
|
+
*/
|
|
128
|
+
type ValidationMode = 'strict' | 'warn' | 'ignore';
|
|
129
|
+
/**
|
|
130
|
+
* JSON patch operation types
|
|
131
|
+
*/
|
|
132
|
+
type PatchOp = 'add' | 'remove' | 'replace' | 'set';
|
|
133
|
+
/**
|
|
134
|
+
* JSON patch operation
|
|
135
|
+
*/
|
|
136
|
+
interface JsonPatch {
|
|
137
|
+
op: PatchOp;
|
|
138
|
+
path: string;
|
|
139
|
+
value?: unknown;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Resolve a dynamic value against a data model
|
|
143
|
+
*/
|
|
144
|
+
declare function resolveDynamicValue<T>(value: DynamicValue<T>, dataModel: DataModel): T | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Get a value from an object by JSON Pointer path
|
|
147
|
+
*/
|
|
148
|
+
declare function getByPath(obj: unknown, path: string): unknown;
|
|
149
|
+
/**
|
|
150
|
+
* Set a value in an object by JSON Pointer path
|
|
151
|
+
*/
|
|
152
|
+
declare function setByPath(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Logic expression schema (recursive)
|
|
156
|
+
* Using a more permissive schema that aligns with runtime behavior
|
|
157
|
+
*/
|
|
158
|
+
declare const LogicExpressionSchema: z.ZodType<LogicExpression>;
|
|
159
|
+
/**
|
|
160
|
+
* Visibility condition schema
|
|
161
|
+
*/
|
|
162
|
+
declare const VisibilityConditionSchema: z.ZodType<VisibilityCondition>;
|
|
163
|
+
/**
|
|
164
|
+
* Context for evaluating visibility
|
|
165
|
+
*/
|
|
166
|
+
interface VisibilityContext {
|
|
167
|
+
dataModel: DataModel;
|
|
168
|
+
authState?: AuthState;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Evaluate a logic expression against data and auth state
|
|
172
|
+
*/
|
|
173
|
+
declare function evaluateLogicExpression(expr: LogicExpression, ctx: VisibilityContext): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Evaluate a visibility condition
|
|
176
|
+
*/
|
|
177
|
+
declare function evaluateVisibility(condition: VisibilityCondition | undefined, ctx: VisibilityContext): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Helper to create visibility conditions
|
|
180
|
+
*/
|
|
181
|
+
declare const visibility: {
|
|
182
|
+
/** Always visible */
|
|
183
|
+
always: true;
|
|
184
|
+
/** Never visible */
|
|
185
|
+
never: false;
|
|
186
|
+
/** Visible when path is truthy */
|
|
187
|
+
when: (path: string) => VisibilityCondition;
|
|
188
|
+
/** Visible when signed in */
|
|
189
|
+
signedIn: {
|
|
190
|
+
readonly auth: "signedIn";
|
|
191
|
+
};
|
|
192
|
+
/** Visible when signed out */
|
|
193
|
+
signedOut: {
|
|
194
|
+
readonly auth: "signedOut";
|
|
195
|
+
};
|
|
196
|
+
/** AND multiple conditions */
|
|
197
|
+
and: (...conditions: LogicExpression[]) => LogicExpression;
|
|
198
|
+
/** OR multiple conditions */
|
|
199
|
+
or: (...conditions: LogicExpression[]) => LogicExpression;
|
|
200
|
+
/** NOT a condition */
|
|
201
|
+
not: (condition: LogicExpression) => LogicExpression;
|
|
202
|
+
/** Equality check */
|
|
203
|
+
eq: (left: DynamicValue, right: DynamicValue) => LogicExpression;
|
|
204
|
+
/** Not equal check */
|
|
205
|
+
neq: (left: DynamicValue, right: DynamicValue) => LogicExpression;
|
|
206
|
+
/** Greater than */
|
|
207
|
+
gt: (left: DynamicValue<number>, right: DynamicValue<number>) => LogicExpression;
|
|
208
|
+
/** Greater than or equal */
|
|
209
|
+
gte: (left: DynamicValue<number>, right: DynamicValue<number>) => LogicExpression;
|
|
210
|
+
/** Less than */
|
|
211
|
+
lt: (left: DynamicValue<number>, right: DynamicValue<number>) => LogicExpression;
|
|
212
|
+
/** Less than or equal */
|
|
213
|
+
lte: (left: DynamicValue<number>, right: DynamicValue<number>) => LogicExpression;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Confirmation dialog configuration
|
|
218
|
+
*/
|
|
219
|
+
interface ActionConfirm {
|
|
220
|
+
title: string;
|
|
221
|
+
message: string;
|
|
222
|
+
confirmLabel?: string;
|
|
223
|
+
cancelLabel?: string;
|
|
224
|
+
variant?: 'default' | 'danger';
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Action success handler
|
|
228
|
+
*/
|
|
229
|
+
type ActionOnSuccess = {
|
|
230
|
+
navigate: string;
|
|
231
|
+
} | {
|
|
232
|
+
set: Record<string, unknown>;
|
|
233
|
+
} | {
|
|
234
|
+
action: string;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Action error handler
|
|
238
|
+
*/
|
|
239
|
+
type ActionOnError = {
|
|
240
|
+
set: Record<string, unknown>;
|
|
241
|
+
} | {
|
|
242
|
+
action: string;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Rich action definition
|
|
246
|
+
*/
|
|
247
|
+
interface Action {
|
|
248
|
+
/** Action name (must be in catalog) */
|
|
249
|
+
name: string;
|
|
250
|
+
/** Parameters to pass to the action handler */
|
|
251
|
+
params?: Record<string, DynamicValue>;
|
|
252
|
+
/** Confirmation dialog before execution */
|
|
253
|
+
confirm?: ActionConfirm;
|
|
254
|
+
/** Handler after successful execution */
|
|
255
|
+
onSuccess?: ActionOnSuccess;
|
|
256
|
+
/** Handler after failed execution */
|
|
257
|
+
onError?: ActionOnError;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Schema for action confirmation
|
|
261
|
+
*/
|
|
262
|
+
declare const ActionConfirmSchema: z.ZodObject<{
|
|
263
|
+
title: z.ZodString;
|
|
264
|
+
message: z.ZodString;
|
|
265
|
+
confirmLabel: z.ZodOptional<z.ZodString>;
|
|
266
|
+
cancelLabel: z.ZodOptional<z.ZodString>;
|
|
267
|
+
variant: z.ZodOptional<z.ZodEnum<["default", "danger"]>>;
|
|
268
|
+
}, "strip", z.ZodTypeAny, {
|
|
269
|
+
message: string;
|
|
270
|
+
title: string;
|
|
271
|
+
confirmLabel?: string | undefined;
|
|
272
|
+
cancelLabel?: string | undefined;
|
|
273
|
+
variant?: "default" | "danger" | undefined;
|
|
274
|
+
}, {
|
|
275
|
+
message: string;
|
|
276
|
+
title: string;
|
|
277
|
+
confirmLabel?: string | undefined;
|
|
278
|
+
cancelLabel?: string | undefined;
|
|
279
|
+
variant?: "default" | "danger" | undefined;
|
|
280
|
+
}>;
|
|
281
|
+
/**
|
|
282
|
+
* Schema for success handlers
|
|
283
|
+
*/
|
|
284
|
+
declare const ActionOnSuccessSchema: z.ZodUnion<[z.ZodObject<{
|
|
285
|
+
navigate: z.ZodString;
|
|
286
|
+
}, "strip", z.ZodTypeAny, {
|
|
287
|
+
navigate: string;
|
|
288
|
+
}, {
|
|
289
|
+
navigate: string;
|
|
290
|
+
}>, z.ZodObject<{
|
|
291
|
+
set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
292
|
+
}, "strip", z.ZodTypeAny, {
|
|
293
|
+
set: Record<string, unknown>;
|
|
294
|
+
}, {
|
|
295
|
+
set: Record<string, unknown>;
|
|
296
|
+
}>, z.ZodObject<{
|
|
297
|
+
action: z.ZodString;
|
|
298
|
+
}, "strip", z.ZodTypeAny, {
|
|
299
|
+
action: string;
|
|
300
|
+
}, {
|
|
301
|
+
action: string;
|
|
302
|
+
}>]>;
|
|
303
|
+
/**
|
|
304
|
+
* Schema for error handlers
|
|
305
|
+
*/
|
|
306
|
+
declare const ActionOnErrorSchema: z.ZodUnion<[z.ZodObject<{
|
|
307
|
+
set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
308
|
+
}, "strip", z.ZodTypeAny, {
|
|
309
|
+
set: Record<string, unknown>;
|
|
310
|
+
}, {
|
|
311
|
+
set: Record<string, unknown>;
|
|
312
|
+
}>, z.ZodObject<{
|
|
313
|
+
action: z.ZodString;
|
|
314
|
+
}, "strip", z.ZodTypeAny, {
|
|
315
|
+
action: string;
|
|
316
|
+
}, {
|
|
317
|
+
action: string;
|
|
318
|
+
}>]>;
|
|
319
|
+
/**
|
|
320
|
+
* Full action schema
|
|
321
|
+
*/
|
|
322
|
+
declare const ActionSchema: z.ZodObject<{
|
|
323
|
+
name: z.ZodString;
|
|
324
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodObject<{
|
|
325
|
+
path: z.ZodString;
|
|
326
|
+
}, "strip", z.ZodTypeAny, {
|
|
327
|
+
path: string;
|
|
328
|
+
}, {
|
|
329
|
+
path: string;
|
|
330
|
+
}>]>>>;
|
|
331
|
+
confirm: z.ZodOptional<z.ZodObject<{
|
|
332
|
+
title: z.ZodString;
|
|
333
|
+
message: z.ZodString;
|
|
334
|
+
confirmLabel: z.ZodOptional<z.ZodString>;
|
|
335
|
+
cancelLabel: z.ZodOptional<z.ZodString>;
|
|
336
|
+
variant: z.ZodOptional<z.ZodEnum<["default", "danger"]>>;
|
|
337
|
+
}, "strip", z.ZodTypeAny, {
|
|
338
|
+
message: string;
|
|
339
|
+
title: string;
|
|
340
|
+
confirmLabel?: string | undefined;
|
|
341
|
+
cancelLabel?: string | undefined;
|
|
342
|
+
variant?: "default" | "danger" | undefined;
|
|
343
|
+
}, {
|
|
344
|
+
message: string;
|
|
345
|
+
title: string;
|
|
346
|
+
confirmLabel?: string | undefined;
|
|
347
|
+
cancelLabel?: string | undefined;
|
|
348
|
+
variant?: "default" | "danger" | undefined;
|
|
349
|
+
}>>;
|
|
350
|
+
onSuccess: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
351
|
+
navigate: z.ZodString;
|
|
352
|
+
}, "strip", z.ZodTypeAny, {
|
|
353
|
+
navigate: string;
|
|
354
|
+
}, {
|
|
355
|
+
navigate: string;
|
|
356
|
+
}>, z.ZodObject<{
|
|
357
|
+
set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
358
|
+
}, "strip", z.ZodTypeAny, {
|
|
359
|
+
set: Record<string, unknown>;
|
|
360
|
+
}, {
|
|
361
|
+
set: Record<string, unknown>;
|
|
362
|
+
}>, z.ZodObject<{
|
|
363
|
+
action: z.ZodString;
|
|
364
|
+
}, "strip", z.ZodTypeAny, {
|
|
365
|
+
action: string;
|
|
366
|
+
}, {
|
|
367
|
+
action: string;
|
|
368
|
+
}>]>>;
|
|
369
|
+
onError: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
|
|
370
|
+
set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
371
|
+
}, "strip", z.ZodTypeAny, {
|
|
372
|
+
set: Record<string, unknown>;
|
|
373
|
+
}, {
|
|
374
|
+
set: Record<string, unknown>;
|
|
375
|
+
}>, z.ZodObject<{
|
|
376
|
+
action: z.ZodString;
|
|
377
|
+
}, "strip", z.ZodTypeAny, {
|
|
378
|
+
action: string;
|
|
379
|
+
}, {
|
|
380
|
+
action: string;
|
|
381
|
+
}>]>>;
|
|
382
|
+
}, "strip", z.ZodTypeAny, {
|
|
383
|
+
name: string;
|
|
384
|
+
params?: Record<string, string | number | boolean | {
|
|
385
|
+
path: string;
|
|
386
|
+
} | null> | undefined;
|
|
387
|
+
confirm?: {
|
|
388
|
+
message: string;
|
|
389
|
+
title: string;
|
|
390
|
+
confirmLabel?: string | undefined;
|
|
391
|
+
cancelLabel?: string | undefined;
|
|
392
|
+
variant?: "default" | "danger" | undefined;
|
|
393
|
+
} | undefined;
|
|
394
|
+
onSuccess?: {
|
|
395
|
+
navigate: string;
|
|
396
|
+
} | {
|
|
397
|
+
set: Record<string, unknown>;
|
|
398
|
+
} | {
|
|
399
|
+
action: string;
|
|
400
|
+
} | undefined;
|
|
401
|
+
onError?: {
|
|
402
|
+
set: Record<string, unknown>;
|
|
403
|
+
} | {
|
|
404
|
+
action: string;
|
|
405
|
+
} | undefined;
|
|
406
|
+
}, {
|
|
407
|
+
name: string;
|
|
408
|
+
params?: Record<string, string | number | boolean | {
|
|
409
|
+
path: string;
|
|
410
|
+
} | null> | undefined;
|
|
411
|
+
confirm?: {
|
|
412
|
+
message: string;
|
|
413
|
+
title: string;
|
|
414
|
+
confirmLabel?: string | undefined;
|
|
415
|
+
cancelLabel?: string | undefined;
|
|
416
|
+
variant?: "default" | "danger" | undefined;
|
|
417
|
+
} | undefined;
|
|
418
|
+
onSuccess?: {
|
|
419
|
+
navigate: string;
|
|
420
|
+
} | {
|
|
421
|
+
set: Record<string, unknown>;
|
|
422
|
+
} | {
|
|
423
|
+
action: string;
|
|
424
|
+
} | undefined;
|
|
425
|
+
onError?: {
|
|
426
|
+
set: Record<string, unknown>;
|
|
427
|
+
} | {
|
|
428
|
+
action: string;
|
|
429
|
+
} | undefined;
|
|
430
|
+
}>;
|
|
431
|
+
/**
|
|
432
|
+
* Action handler function signature
|
|
433
|
+
*/
|
|
434
|
+
type ActionHandler<TParams = Record<string, unknown>, TResult = unknown> = (params: TParams) => Promise<TResult> | TResult;
|
|
435
|
+
/**
|
|
436
|
+
* Action definition in catalog
|
|
437
|
+
*/
|
|
438
|
+
interface ActionDefinition<TParams = Record<string, unknown>> {
|
|
439
|
+
/** Zod schema for params validation */
|
|
440
|
+
params?: z.ZodType<TParams>;
|
|
441
|
+
/** Description for AI */
|
|
442
|
+
description?: string;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Resolved action with all dynamic values resolved
|
|
446
|
+
*/
|
|
447
|
+
interface ResolvedAction {
|
|
448
|
+
name: string;
|
|
449
|
+
params: Record<string, unknown>;
|
|
450
|
+
confirm?: ActionConfirm;
|
|
451
|
+
onSuccess?: ActionOnSuccess;
|
|
452
|
+
onError?: ActionOnError;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Resolve all dynamic values in an action
|
|
456
|
+
*/
|
|
457
|
+
declare function resolveAction(action: Action, dataModel: DataModel): ResolvedAction;
|
|
458
|
+
/**
|
|
459
|
+
* Interpolate ${path} expressions in a string
|
|
460
|
+
*/
|
|
461
|
+
declare function interpolateString(template: string, dataModel: DataModel): string;
|
|
462
|
+
/**
|
|
463
|
+
* Context for action execution
|
|
464
|
+
*/
|
|
465
|
+
interface ActionExecutionContext {
|
|
466
|
+
/** The resolved action */
|
|
467
|
+
action: ResolvedAction;
|
|
468
|
+
/** The action handler from the host */
|
|
469
|
+
handler: ActionHandler;
|
|
470
|
+
/** Function to update data model */
|
|
471
|
+
setData: (path: string, value: unknown) => void;
|
|
472
|
+
/** Function to navigate */
|
|
473
|
+
navigate?: (path: string) => void;
|
|
474
|
+
/** Function to execute another action */
|
|
475
|
+
executeAction?: (name: string) => Promise<void>;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Execute an action with all callbacks
|
|
479
|
+
*/
|
|
480
|
+
declare function executeAction(ctx: ActionExecutionContext): Promise<void>;
|
|
481
|
+
/**
|
|
482
|
+
* Helper to create actions
|
|
483
|
+
*/
|
|
484
|
+
declare const action: {
|
|
485
|
+
/** Create a simple action */
|
|
486
|
+
simple: (name: string, params?: Record<string, DynamicValue>) => Action;
|
|
487
|
+
/** Create an action with confirmation */
|
|
488
|
+
withConfirm: (name: string, confirm: ActionConfirm, params?: Record<string, DynamicValue>) => Action;
|
|
489
|
+
/** Create an action with success handler */
|
|
490
|
+
withSuccess: (name: string, onSuccess: ActionOnSuccess, params?: Record<string, DynamicValue>) => Action;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Validation check definition
|
|
495
|
+
*/
|
|
496
|
+
interface ValidationCheck {
|
|
497
|
+
/** Function name (built-in or from catalog) */
|
|
498
|
+
fn: string;
|
|
499
|
+
/** Additional arguments for the function */
|
|
500
|
+
args?: Record<string, DynamicValue>;
|
|
501
|
+
/** Error message to display if check fails */
|
|
502
|
+
message: string;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Validation configuration for a field
|
|
506
|
+
*/
|
|
507
|
+
interface ValidationConfig {
|
|
508
|
+
/** Array of checks to run */
|
|
509
|
+
checks?: ValidationCheck[];
|
|
510
|
+
/** When to run validation */
|
|
511
|
+
validateOn?: 'change' | 'blur' | 'submit';
|
|
512
|
+
/** Condition for when validation is enabled */
|
|
513
|
+
enabled?: LogicExpression;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Schema for validation check
|
|
517
|
+
*/
|
|
518
|
+
declare const ValidationCheckSchema: z.ZodObject<{
|
|
519
|
+
fn: z.ZodString;
|
|
520
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodObject<{
|
|
521
|
+
path: z.ZodString;
|
|
522
|
+
}, "strip", z.ZodTypeAny, {
|
|
523
|
+
path: string;
|
|
524
|
+
}, {
|
|
525
|
+
path: string;
|
|
526
|
+
}>]>>>;
|
|
527
|
+
message: z.ZodString;
|
|
528
|
+
}, "strip", z.ZodTypeAny, {
|
|
529
|
+
message: string;
|
|
530
|
+
fn: string;
|
|
531
|
+
args?: Record<string, string | number | boolean | {
|
|
532
|
+
path: string;
|
|
533
|
+
} | null> | undefined;
|
|
534
|
+
}, {
|
|
535
|
+
message: string;
|
|
536
|
+
fn: string;
|
|
537
|
+
args?: Record<string, string | number | boolean | {
|
|
538
|
+
path: string;
|
|
539
|
+
} | null> | undefined;
|
|
540
|
+
}>;
|
|
541
|
+
/**
|
|
542
|
+
* Schema for validation config
|
|
543
|
+
*/
|
|
544
|
+
declare const ValidationConfigSchema: z.ZodObject<{
|
|
545
|
+
checks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
546
|
+
fn: z.ZodString;
|
|
547
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodObject<{
|
|
548
|
+
path: z.ZodString;
|
|
549
|
+
}, "strip", z.ZodTypeAny, {
|
|
550
|
+
path: string;
|
|
551
|
+
}, {
|
|
552
|
+
path: string;
|
|
553
|
+
}>]>>>;
|
|
554
|
+
message: z.ZodString;
|
|
555
|
+
}, "strip", z.ZodTypeAny, {
|
|
556
|
+
message: string;
|
|
557
|
+
fn: string;
|
|
558
|
+
args?: Record<string, string | number | boolean | {
|
|
559
|
+
path: string;
|
|
560
|
+
} | null> | undefined;
|
|
561
|
+
}, {
|
|
562
|
+
message: string;
|
|
563
|
+
fn: string;
|
|
564
|
+
args?: Record<string, string | number | boolean | {
|
|
565
|
+
path: string;
|
|
566
|
+
} | null> | undefined;
|
|
567
|
+
}>, "many">>;
|
|
568
|
+
validateOn: z.ZodOptional<z.ZodEnum<["change", "blur", "submit"]>>;
|
|
569
|
+
enabled: z.ZodOptional<z.ZodType<LogicExpression, z.ZodTypeDef, LogicExpression>>;
|
|
570
|
+
}, "strip", z.ZodTypeAny, {
|
|
571
|
+
checks?: {
|
|
572
|
+
message: string;
|
|
573
|
+
fn: string;
|
|
574
|
+
args?: Record<string, string | number | boolean | {
|
|
575
|
+
path: string;
|
|
576
|
+
} | null> | undefined;
|
|
577
|
+
}[] | undefined;
|
|
578
|
+
validateOn?: "change" | "blur" | "submit" | undefined;
|
|
579
|
+
enabled?: LogicExpression | undefined;
|
|
580
|
+
}, {
|
|
581
|
+
checks?: {
|
|
582
|
+
message: string;
|
|
583
|
+
fn: string;
|
|
584
|
+
args?: Record<string, string | number | boolean | {
|
|
585
|
+
path: string;
|
|
586
|
+
} | null> | undefined;
|
|
587
|
+
}[] | undefined;
|
|
588
|
+
validateOn?: "change" | "blur" | "submit" | undefined;
|
|
589
|
+
enabled?: LogicExpression | undefined;
|
|
590
|
+
}>;
|
|
591
|
+
/**
|
|
592
|
+
* Validation function signature
|
|
593
|
+
*/
|
|
594
|
+
type ValidationFunction = (value: unknown, args?: Record<string, unknown>) => boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Validation function definition in catalog
|
|
597
|
+
*/
|
|
598
|
+
interface ValidationFunctionDefinition {
|
|
599
|
+
/** The validation function */
|
|
600
|
+
validate: ValidationFunction;
|
|
601
|
+
/** Description for AI */
|
|
602
|
+
description?: string;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Built-in validation functions
|
|
606
|
+
*/
|
|
607
|
+
declare const builtInValidationFunctions: Record<string, ValidationFunction>;
|
|
608
|
+
/**
|
|
609
|
+
* Validation result for a single check
|
|
610
|
+
*/
|
|
611
|
+
interface ValidationCheckResult {
|
|
612
|
+
fn: string;
|
|
613
|
+
valid: boolean;
|
|
614
|
+
message: string;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Full validation result for a field
|
|
618
|
+
*/
|
|
619
|
+
interface ValidationResult {
|
|
620
|
+
valid: boolean;
|
|
621
|
+
errors: string[];
|
|
622
|
+
checks: ValidationCheckResult[];
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Context for running validation
|
|
626
|
+
*/
|
|
627
|
+
interface ValidationContext {
|
|
628
|
+
/** Current value to validate */
|
|
629
|
+
value: unknown;
|
|
630
|
+
/** Full data model for resolving paths */
|
|
631
|
+
dataModel: DataModel;
|
|
632
|
+
/** Custom validation functions from catalog */
|
|
633
|
+
customFunctions?: Record<string, ValidationFunction>;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Run a single validation check
|
|
637
|
+
*/
|
|
638
|
+
declare function runValidationCheck(check: ValidationCheck, ctx: ValidationContext): ValidationCheckResult;
|
|
639
|
+
/**
|
|
640
|
+
* Run all validation checks for a field
|
|
641
|
+
*/
|
|
642
|
+
declare function runValidation(config: ValidationConfig, ctx: ValidationContext & {
|
|
643
|
+
authState?: {
|
|
644
|
+
isSignedIn: boolean;
|
|
645
|
+
};
|
|
646
|
+
}): ValidationResult;
|
|
647
|
+
/**
|
|
648
|
+
* Helper to create validation checks
|
|
649
|
+
*/
|
|
650
|
+
declare const check: {
|
|
651
|
+
required: (message?: string) => ValidationCheck;
|
|
652
|
+
email: (message?: string) => ValidationCheck;
|
|
653
|
+
minLength: (min: number, message?: string) => ValidationCheck;
|
|
654
|
+
maxLength: (max: number, message?: string) => ValidationCheck;
|
|
655
|
+
pattern: (pattern: string, message?: string) => ValidationCheck;
|
|
656
|
+
min: (min: number, message?: string) => ValidationCheck;
|
|
657
|
+
max: (max: number, message?: string) => ValidationCheck;
|
|
658
|
+
url: (message?: string) => ValidationCheck;
|
|
659
|
+
matches: (otherPath: string, message?: string) => ValidationCheck;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Component definition with visibility and validation support
|
|
664
|
+
*/
|
|
665
|
+
interface ComponentDefinition<TProps extends ComponentSchema = ComponentSchema> {
|
|
666
|
+
/** Zod schema for component props */
|
|
667
|
+
props: TProps;
|
|
668
|
+
/** Whether this component can have children */
|
|
669
|
+
hasChildren?: boolean;
|
|
670
|
+
/** Description for AI generation */
|
|
671
|
+
description?: string;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Catalog configuration
|
|
675
|
+
*/
|
|
676
|
+
interface CatalogConfig<TComponents extends Record<string, ComponentDefinition> = Record<string, ComponentDefinition>, TActions extends Record<string, ActionDefinition> = Record<string, ActionDefinition>, TFunctions extends Record<string, ValidationFunction> = Record<string, ValidationFunction>> {
|
|
677
|
+
/** Catalog name */
|
|
678
|
+
name?: string;
|
|
679
|
+
/** Component definitions */
|
|
680
|
+
components: TComponents;
|
|
681
|
+
/** Action definitions with param schemas */
|
|
682
|
+
actions?: TActions;
|
|
683
|
+
/** Custom validation functions */
|
|
684
|
+
functions?: TFunctions;
|
|
685
|
+
/** Validation mode */
|
|
686
|
+
validation?: ValidationMode;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Catalog instance
|
|
690
|
+
*/
|
|
691
|
+
interface Catalog<TComponents extends Record<string, ComponentDefinition> = Record<string, ComponentDefinition>, TActions extends Record<string, ActionDefinition> = Record<string, ActionDefinition>, TFunctions extends Record<string, ValidationFunction> = Record<string, ValidationFunction>> {
|
|
692
|
+
/** Catalog name */
|
|
693
|
+
readonly name: string;
|
|
694
|
+
/** Component names */
|
|
695
|
+
readonly componentNames: (keyof TComponents)[];
|
|
696
|
+
/** Action names */
|
|
697
|
+
readonly actionNames: (keyof TActions)[];
|
|
698
|
+
/** Function names */
|
|
699
|
+
readonly functionNames: (keyof TFunctions)[];
|
|
700
|
+
/** Validation mode */
|
|
701
|
+
readonly validation: ValidationMode;
|
|
702
|
+
/** Component definitions */
|
|
703
|
+
readonly components: TComponents;
|
|
704
|
+
/** Action definitions */
|
|
705
|
+
readonly actions: TActions;
|
|
706
|
+
/** Custom validation functions */
|
|
707
|
+
readonly functions: TFunctions;
|
|
708
|
+
/** Full element schema for AI generation */
|
|
709
|
+
readonly elementSchema: z.ZodType<UIElement>;
|
|
710
|
+
/** Full UI tree schema */
|
|
711
|
+
readonly treeSchema: z.ZodType<UITree>;
|
|
712
|
+
/** Check if component exists */
|
|
713
|
+
hasComponent(type: string): boolean;
|
|
714
|
+
/** Check if action exists */
|
|
715
|
+
hasAction(name: string): boolean;
|
|
716
|
+
/** Check if function exists */
|
|
717
|
+
hasFunction(name: string): boolean;
|
|
718
|
+
/** Validate an element */
|
|
719
|
+
validateElement(element: unknown): {
|
|
720
|
+
success: boolean;
|
|
721
|
+
data?: UIElement;
|
|
722
|
+
error?: z.ZodError;
|
|
723
|
+
};
|
|
724
|
+
/** Validate a UI tree */
|
|
725
|
+
validateTree(tree: unknown): {
|
|
726
|
+
success: boolean;
|
|
727
|
+
data?: UITree;
|
|
728
|
+
error?: z.ZodError;
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Create a v2 catalog with visibility, actions, and validation support
|
|
733
|
+
*/
|
|
734
|
+
declare function createCatalog<TComponents extends Record<string, ComponentDefinition>, TActions extends Record<string, ActionDefinition> = Record<string, ActionDefinition>, TFunctions extends Record<string, ValidationFunction> = Record<string, ValidationFunction>>(config: CatalogConfig<TComponents, TActions, TFunctions>): Catalog<TComponents, TActions, TFunctions>;
|
|
735
|
+
/**
|
|
736
|
+
* Generate a prompt for AI that describes the catalog
|
|
737
|
+
*/
|
|
738
|
+
declare function generateCatalogPrompt<TComponents extends Record<string, ComponentDefinition>, TActions extends Record<string, ActionDefinition>, TFunctions extends Record<string, ValidationFunction>>(catalog: Catalog<TComponents, TActions, TFunctions>): string;
|
|
739
|
+
/**
|
|
740
|
+
* Type helper to infer component props from catalog
|
|
741
|
+
*/
|
|
742
|
+
type InferCatalogComponentProps<C extends Catalog<Record<string, ComponentDefinition>>> = {
|
|
743
|
+
[K in keyof C['components']]: z.infer<C['components'][K]['props']>;
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
export { type Action, type ActionConfirm, ActionConfirmSchema, type ActionDefinition, type ActionExecutionContext, type ActionHandler, type ActionOnError, ActionOnErrorSchema, type ActionOnSuccess, ActionOnSuccessSchema, ActionSchema, type AuthState, type Catalog, type CatalogConfig, type ComponentDefinition, type ComponentSchema, type DataModel, type DynamicBoolean, DynamicBooleanSchema, type DynamicNumber, DynamicNumberSchema, type DynamicString, DynamicStringSchema, type DynamicValue, DynamicValueSchema, type InferCatalogComponentProps, type JsonPatch, type LogicExpression, LogicExpressionSchema, type PatchOp, type ResolvedAction, type UIElement, type UITree, type ValidationCheck, type ValidationCheckResult, ValidationCheckSchema, type ValidationConfig, ValidationConfigSchema, type ValidationContext, type ValidationFunction, type ValidationFunctionDefinition, type ValidationMode, type ValidationResult, type VisibilityCondition, VisibilityConditionSchema, type VisibilityContext, action, builtInValidationFunctions, check, createCatalog, evaluateLogicExpression, evaluateVisibility, executeAction, generateCatalogPrompt, getByPath, interpolateString, resolveAction, resolveDynamicValue, runValidation, runValidationCheck, setByPath, visibility };
|