@arkitektio/bsx 6.9.0 → 7.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/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +4 -2
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +14 -10
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +94 -35
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/index.d.ts +191 -98
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/parts/data.d.ts +2 -2
- package/dist/catalogs/parts/data.d.ts.map +1 -1
- package/dist/catalogs/parts/data.js +2 -3
- package/dist/catalogs/parts/data.js.map +1 -1
- package/dist/catalogs/parts/feedback.d.ts +6 -6
- package/dist/catalogs/parts/forms.d.ts +8 -8
- package/dist/catalogs/parts/icons.d.ts +4 -4
- package/dist/catalogs/parts/index.d.ts +48 -48
- package/dist/catalogs/parts/navigation.d.ts +8 -8
- package/dist/catalogs/parts/overlays.d.ts +22 -22
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/run.js +4 -5
- package/dist/catalogs/parts/run.js.map +1 -1
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +7 -14
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/structure.d.ts.map +1 -1
- package/dist/catalogs/parts/structure.js +2 -3
- package/dist/catalogs/parts/structure.js.map +1 -1
- package/dist/catalogs/parts/toast.d.ts.map +1 -1
- package/dist/catalogs/parts/toast.js +2 -1
- package/dist/catalogs/parts/toast.js.map +1 -1
- package/dist/catalogs/props.d.ts +23 -0
- package/dist/catalogs/props.d.ts.map +1 -1
- package/dist/catalogs/props.js +56 -4
- package/dist/catalogs/props.js.map +1 -1
- package/dist/catalogs/scene.d.ts +134 -127
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/scene.js +5 -3
- package/dist/catalogs/scene.js.map +1 -1
- package/dist/catalogs/shadcn.d.ts +79 -41
- package/dist/catalogs/shadcn.d.ts.map +1 -1
- package/dist/catalogs/shadcn.js +13 -13
- package/dist/catalogs/shadcn.js.map +1 -1
- package/dist/catalogs/structure.d.ts +9 -2
- package/dist/catalogs/structure.d.ts.map +1 -1
- package/dist/catalogs/structure.js +1 -1
- package/dist/catalogs/structure.js.map +1 -1
- package/dist/catalogs/ui.d.ts +935 -892
- package/dist/catalogs/ui.d.ts.map +1 -1
- package/dist/catalogs/ui.js +16 -14
- package/dist/catalogs/ui.js.map +1 -1
- package/dist/catalogs/zodToPort.d.ts +9 -0
- package/dist/catalogs/zodToPort.d.ts.map +1 -0
- package/dist/catalogs/zodToPort.js +156 -0
- package/dist/catalogs/zodToPort.js.map +1 -0
- package/dist/catalogs.d.ts +4 -1
- package/dist/catalogs.d.ts.map +1 -1
- package/dist/catalogs.js +3 -0
- package/dist/catalogs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/ports/rekuest.d.ts +6 -0
- package/dist/ports/rekuest.d.ts.map +1 -1
- package/dist/ports/rekuest.js +6 -0
- package/dist/ports/rekuest.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +2 -2
- package/dist/renderer/bloks/feedback.d.ts +6 -6
- package/dist/renderer/bloks/forms.d.ts +8 -8
- package/dist/renderer/bloks/icons.d.ts +2 -2
- package/dist/renderer/bloks/index.d.ts +48 -48
- package/dist/renderer/bloks/navigation.d.ts +8 -8
- package/dist/renderer/bloks/overlays.d.ts +22 -22
- package/dist/renderer/runtime/components.d.ts +6 -8
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +5 -12
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +25 -89
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +3 -1
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/schemas.d.ts +8 -6
- package/dist/renderer/runtime/schemas.d.ts.map +1 -1
- package/dist/renderer/runtime/schemas.js +40 -16
- package/dist/renderer/runtime/schemas.js.map +1 -1
- package/dist/shadcn.d.ts +48 -48
- package/dist/spec/bsx_v2.json +917 -15
- package/dist/spec/catalogs/base@4.json +18712 -5274
- package/dist/spec/catalogs/base@4.json.js +18712 -5274
- package/dist/spec/catalogs/orkestrator@1.json +6132 -127
- package/dist/spec/catalogs/orkestrator@1.json.js +6132 -127
- package/dist/spec/catalogs.d.ts +3 -11
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +13 -11
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/fit.d.ts +21 -0
- package/dist/spec/fit.d.ts.map +1 -0
- package/dist/spec/fit.js +114 -0
- package/dist/spec/fit.js.map +1 -0
- package/dist/spec/ports.d.ts +56 -0
- package/dist/spec/ports.d.ts.map +1 -0
- package/dist/spec/ports.js +174 -0
- package/dist/spec/ports.js.map +1 -0
- package/dist/spec/vocabulary.json +7 -5
- package/dist/spec/vocabulary.json.js +7 -5
- package/package.json +1 -1
- package/src/bsx/infer.test.ts +1 -1
- package/src/bsx/infer.ts +4 -2
- package/src/bsx/language.ts +13 -9
- package/src/bsx/references.ts +125 -38
- package/src/catalogs/parts/data.ts +3 -2
- package/src/catalogs/parts/run.ts +9 -7
- package/src/catalogs/parts/scene.ts +7 -14
- package/src/catalogs/parts/structure.ts +2 -3
- package/src/catalogs/parts/toast.ts +5 -1
- package/src/catalogs/props.ts +64 -4
- package/src/catalogs/scene.ts +5 -3
- package/src/catalogs/shadcn.ts +13 -13
- package/src/catalogs/structure.ts +1 -1
- package/src/catalogs/ui.ts +16 -14
- package/src/catalogs/zodToPort.test.ts +96 -0
- package/src/catalogs/zodToPort.ts +177 -0
- package/src/catalogs.ts +4 -1
- package/src/index.ts +2 -0
- package/src/ports/rekuest.ts +6 -0
- package/src/renderer/runtime/catalog.test.ts +12 -8
- package/src/renderer/runtime/components.tsx +5 -8
- package/src/renderer/runtime/describe.ts +25 -100
- package/src/renderer/runtime/hooks.ts +3 -1
- package/src/renderer/runtime/schemas.ts +51 -17
- package/src/spec/bsx_v2.json +917 -15
- package/src/spec/catalogs/base@4.json +18712 -5274
- package/src/spec/catalogs/orkestrator@1.json +6132 -127
- package/src/spec/catalogs.ts +14 -19
- package/src/spec/fit.test.ts +65 -0
- package/src/spec/fit.ts +114 -0
- package/src/spec/ports.ts +172 -0
- package/src/spec/spec.test.ts +5 -2
- package/src/spec/vocabulary.json +7 -5
|
@@ -18,8 +18,8 @@ const contract = defineBlokCatalog({
|
|
|
18
18
|
onTurn: actionProp('Runs when turned.'),
|
|
19
19
|
})
|
|
20
20
|
.describe('A knob.'),
|
|
21
|
-
bindKinds: {bind: 'FLOAT'},
|
|
22
|
-
events: {onTurn: [{key: 'value',
|
|
21
|
+
bindKinds: {bind: {kind: 'FLOAT'}},
|
|
22
|
+
events: {onTurn: [{key: 'value', port: z.number(), description: 'Where it stands.'}]},
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
25
|
});
|
|
@@ -56,7 +56,7 @@ describe('implementBlokCatalog', () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
describe('describeBlokContract', () => {
|
|
59
|
-
it('writes the spec JSON:
|
|
59
|
+
it('writes the spec JSON: each prop\'s port (choices, a binding, a callback\'s payload) and the text prop', () => {
|
|
60
60
|
expect(describeBlokContract(contract)).toEqual({
|
|
61
61
|
name: 'demo',
|
|
62
62
|
version: 1,
|
|
@@ -73,14 +73,13 @@ describe('describeBlokContract', () => {
|
|
|
73
73
|
not_downstream_of: [],
|
|
74
74
|
text_prop: null,
|
|
75
75
|
props: [
|
|
76
|
-
{key: 'bind', kind: 'FLOAT', required: false, description: expect.any(String)},
|
|
77
|
-
{key: 'level', kind: 'STRING',
|
|
76
|
+
{key: 'bind', port: {kind: 'BINDING', children: [{key: '...', kind: 'FLOAT'}]}, required: false, description: expect.any(String)},
|
|
77
|
+
{key: 'level', port: {kind: 'STRING', choices: [{value: 'low'}, {value: 'high'}]}, required: false, description: 'How far.'},
|
|
78
78
|
{
|
|
79
79
|
key: 'onTurn',
|
|
80
|
-
kind: 'CALLBACK',
|
|
80
|
+
port: {kind: 'CALLBACK', children: [{key: 'value', kind: 'FLOAT', description: 'Where it stands.'}]},
|
|
81
81
|
required: false,
|
|
82
82
|
description: 'Runs when turned.',
|
|
83
|
-
event: [{key: 'value', kind: 'FLOAT', description: 'Where it stands.'}],
|
|
84
83
|
},
|
|
85
84
|
],
|
|
86
85
|
},
|
|
@@ -94,9 +93,14 @@ describe('describeBlokContract', () => {
|
|
|
94
93
|
downstream_of: [],
|
|
95
94
|
not_downstream_of: [],
|
|
96
95
|
text_prop: 'text',
|
|
97
|
-
props: [{key: 'text', kind: 'STRING', required: false, description: 'What it says.'}],
|
|
96
|
+
props: [{key: 'text', port: {kind: 'STRING'}, required: false, description: 'What it says.'}],
|
|
98
97
|
},
|
|
99
98
|
],
|
|
100
99
|
});
|
|
101
100
|
});
|
|
101
|
+
|
|
102
|
+
it('refuses a prop no port says', () => {
|
|
103
|
+
const untyped = defineBlokCatalog({name: 'odd', description: '', components: {Odd: {schema: z.object({any: z.unknown()})}}});
|
|
104
|
+
expect(() => describeBlokContract(untyped)).toThrow(/<Odd> any/);
|
|
105
|
+
});
|
|
102
106
|
});
|
|
@@ -7,6 +7,7 @@ import {BlokNodeStateContext, type BlokNodeState} from './nodeState';
|
|
|
7
7
|
import {readScopedPath, useBlokScope} from './scope';
|
|
8
8
|
import {READY, combineStatus, type BlokSourceStatus} from './status';
|
|
9
9
|
import type {BlokComponentNode, BlokComponentProp, BlokObjectSchema} from './types';
|
|
10
|
+
import type {SpecPort} from '../../spec/ports';
|
|
10
11
|
|
|
11
12
|
export type BlokRenderArgs<TSchema extends BlokObjectSchema = BlokObjectSchema> = {
|
|
12
13
|
props: ReadonlyArray<BlokComponentProp>;
|
|
@@ -43,8 +44,8 @@ export type BlokComponentPlacement = {
|
|
|
43
44
|
/** Props the server holds to more than their shape: an `ASSET` prop names a file its app registered. */
|
|
44
45
|
export type BlokPropKind = 'ASSET';
|
|
45
46
|
|
|
46
|
-
/** A field of what a callback is called with (`event.value`),
|
|
47
|
-
export type BlokEventField = {key: string;
|
|
47
|
+
/** A field of what a callback is called with (`event.value`): its port, or a zod schema of it. */
|
|
48
|
+
export type BlokEventField = {key: string; port: SpecPort | z.ZodTypeAny; description: string};
|
|
48
49
|
|
|
49
50
|
type BlokComponentApi = {
|
|
50
51
|
/** Set when the component renders declared children its schema has no `children` prop for. */
|
|
@@ -61,12 +62,8 @@ type BlokComponentApi = {
|
|
|
61
62
|
textProp?: string;
|
|
62
63
|
/** Per callback prop, the fields of the event it is called with (`[]`: none). */
|
|
63
64
|
events?: Readonly<Record<string, readonly BlokEventField[]>>;
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
* (`Slider.bind` writes a FLOAT): what the spec publishes as the prop's kind,
|
|
67
|
-
* where the schema itself only says "a path".
|
|
68
|
-
*/
|
|
69
|
-
bindKinds?: Readonly<Record<string, string>>;
|
|
65
|
+
/** Per `bind` prop, what the control writes (`Slider.bind`: a FLOAT): its port, or a zod schema of it. */
|
|
66
|
+
bindKinds?: Readonly<Record<string, SpecPort | z.ZodTypeAny>>;
|
|
70
67
|
/** The blok kinds it may be placed in (`assign`); any kind when left out. */
|
|
71
68
|
kinds?: readonly string[];
|
|
72
69
|
/** The service it needs where it is drawn (`mikro`): without it a notice shows in its place. */
|
|
@@ -2,7 +2,9 @@ import * as z from 'zod';
|
|
|
2
2
|
import type {BlokCatalogContract} from './catalog';
|
|
3
3
|
import type {BlokComponentContext, BlokComponentContract} from './components';
|
|
4
4
|
import {isRequiredField} from './preflight';
|
|
5
|
-
import {isActionSchema, isBindSchema
|
|
5
|
+
import {isActionSchema, isBindSchema} from './schemas';
|
|
6
|
+
import {asPort, zodToPort} from '../../catalogs/zodToPort';
|
|
7
|
+
import {ASSET, BINDING, CALLBACK, ITEM_KEY, portJson, type SpecPort} from '../../spec/ports';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* A contract in the spec's terms: what a catalog file (`spec/catalogs/base@4.json`,
|
|
@@ -13,15 +15,12 @@ import {isActionSchema, isBindSchema, unwrapSchema} from './schemas';
|
|
|
13
15
|
* catalog is published as it (`blokCatalogSpec`).
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
|
-
export type SpecValueKind = 'STRING' | 'INT' | 'FLOAT' | 'BOOL' | 'DICT' | 'LIST' | 'ANY' | 'CALLBACK' | 'ASSET';
|
|
17
|
-
|
|
18
18
|
export type SpecPropJson = {
|
|
19
19
|
key: string;
|
|
20
|
-
|
|
20
|
+
/** The port the prop is typed by (`spec/ports.ts`); never open for a drawn component. */
|
|
21
|
+
port: Record<string, unknown> | null;
|
|
21
22
|
required: boolean;
|
|
22
23
|
description: string | null;
|
|
23
|
-
values?: string[];
|
|
24
|
-
event?: Array<{key: string; kind: string; description: string}>;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
26
|
export type SpecComponentJson = {
|
|
@@ -52,95 +51,25 @@ export type SpecCatalogJson = {
|
|
|
52
51
|
components: SpecComponentJson[];
|
|
53
52
|
};
|
|
54
53
|
|
|
55
|
-
const INT_FORMATS = new Set(['safeint', 'int32', 'uint32', 'int64', 'uint64']);
|
|
56
|
-
|
|
57
|
-
type ZodDef = {
|
|
58
|
-
type?: string;
|
|
59
|
-
format?: string;
|
|
60
|
-
in?: z.ZodTypeAny;
|
|
61
|
-
options?: z.ZodTypeAny[];
|
|
62
|
-
values?: unknown[];
|
|
63
|
-
entries?: Record<string, unknown>;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const defOf = (schema: z.ZodTypeAny): ZodDef => (schema as unknown as {def?: ZodDef}).def ?? {};
|
|
67
|
-
|
|
68
|
-
/** Through optional/nullable/default wrappers and transforms (`pipe`). */
|
|
69
|
-
const unwrapForKind = (schema: z.ZodTypeAny): z.ZodTypeAny => {
|
|
70
|
-
let current = unwrapSchema(schema);
|
|
71
|
-
for (let depth = 0; depth < 8; depth += 1) {
|
|
72
|
-
const def = defOf(current);
|
|
73
|
-
if (def.type !== 'pipe' || !def.in) return current;
|
|
74
|
-
current = unwrapSchema(def.in);
|
|
75
|
-
}
|
|
76
|
-
return current;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/** The closed set of strings a `z.enum` prop takes, through its wrappers; null for any other schema. */
|
|
80
|
-
export const zodEnumValues = (schema: z.ZodTypeAny): string[] | null => {
|
|
81
|
-
const def = defOf(unwrapForKind(schema));
|
|
82
|
-
if (def.type !== 'enum' || !def.entries) return null;
|
|
83
|
-
const values = Object.values(def.entries);
|
|
84
|
-
return values.every((value): value is string => typeof value === 'string') ? values : null;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/** The spec's value kind for a zod schema; a shape it has no word for is `ANY`. */
|
|
88
|
-
export const zodToSpecKind = (schema: z.ZodTypeAny): SpecValueKind => {
|
|
89
|
-
// Action props are `z.custom(...)` under a brand: check before the type switch.
|
|
90
|
-
if (isActionSchema(schema)) return 'CALLBACK';
|
|
91
|
-
const def = defOf(unwrapForKind(schema));
|
|
92
|
-
switch (def.type) {
|
|
93
|
-
case 'string':
|
|
94
|
-
case 'enum':
|
|
95
|
-
case 'template_literal':
|
|
96
|
-
return 'STRING';
|
|
97
|
-
case 'literal': {
|
|
98
|
-
const values = def.values ?? [];
|
|
99
|
-
if (values.every(value => typeof value === 'string')) return 'STRING';
|
|
100
|
-
if (values.every(value => typeof value === 'boolean')) return 'BOOL';
|
|
101
|
-
if (values.every(value => typeof value === 'number')) return 'FLOAT';
|
|
102
|
-
return 'ANY';
|
|
103
|
-
}
|
|
104
|
-
case 'number':
|
|
105
|
-
return def.format && INT_FORMATS.has(def.format) ? 'INT' : 'FLOAT';
|
|
106
|
-
case 'boolean':
|
|
107
|
-
return 'BOOL';
|
|
108
|
-
case 'array':
|
|
109
|
-
case 'tuple':
|
|
110
|
-
case 'set':
|
|
111
|
-
return 'LIST';
|
|
112
|
-
case 'object':
|
|
113
|
-
case 'record':
|
|
114
|
-
case 'map':
|
|
115
|
-
return 'DICT';
|
|
116
|
-
case 'union': {
|
|
117
|
-
const kinds = new Set((def.options ?? []).map(zodToSpecKind));
|
|
118
|
-
return kinds.size === 1 ? [...kinds][0] : 'ANY';
|
|
119
|
-
}
|
|
120
|
-
default:
|
|
121
|
-
return 'ANY';
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
54
|
const CONTEXT: Record<BlokComponentContext, SpecComponentJson['context']> = {panel: 'PANEL', scene: 'SCENE', logo: 'LOGO'};
|
|
126
55
|
|
|
127
56
|
const byKey = <T extends {key: string}>(left: T, right: T) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0);
|
|
128
57
|
const byName = <T extends {name: string}>(left: T, right: T) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
129
58
|
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
return
|
|
59
|
+
/** A prop's port: a callback's payload, a binding's value, an asset, else its schema's. */
|
|
60
|
+
export const blokPropPort = (name: string, key: string, schema: z.ZodTypeAny, component: BlokComponentContract): SpecPort => {
|
|
61
|
+
const where = `<${name}> ${key}`;
|
|
62
|
+
if (isActionSchema(schema)) {
|
|
63
|
+
const fields = component.events?.[key] ?? [];
|
|
64
|
+
return {kind: CALLBACK, children: fields.map(field => ({key: field.key, ...asPort(field.port, `${where} event.${field.key}`), description: field.description}))};
|
|
65
|
+
}
|
|
66
|
+
if (isBindSchema(schema)) {
|
|
67
|
+
const writes = component.bindKinds?.[key];
|
|
68
|
+
if (!writes) throw new Error(`${where}: a bind prop says what it writes (bindKinds)`);
|
|
69
|
+
return {kind: BINDING, children: [{key: ITEM_KEY, ...asPort(writes, where)}]};
|
|
70
|
+
}
|
|
71
|
+
if (component.propKinds?.[key] === ASSET) return {kind: ASSET};
|
|
72
|
+
return zodToPort(schema, where);
|
|
144
73
|
};
|
|
145
74
|
|
|
146
75
|
/** `children` is no prop in the spec: `accepts_children` says a component takes them. */
|
|
@@ -151,16 +80,12 @@ export const describeBlokComponent = (name: string, component: BlokComponentCont
|
|
|
151
80
|
const placement = component.placement ?? {};
|
|
152
81
|
const props = Object.entries(shape)
|
|
153
82
|
.filter(([key]) => key !== CHILDREN)
|
|
154
|
-
.map(([key, schema]): SpecPropJson => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (values) prop.values = values;
|
|
161
|
-
if (kind === 'CALLBACK') prop.event = [...(component.events?.[key] ?? [])];
|
|
162
|
-
return prop;
|
|
163
|
-
})
|
|
83
|
+
.map(([key, schema]): SpecPropJson => ({
|
|
84
|
+
key,
|
|
85
|
+
port: portJson(blokPropPort(name, key, schema, component)),
|
|
86
|
+
required: isRequiredField(schema),
|
|
87
|
+
description: schema.description ?? null,
|
|
88
|
+
}))
|
|
164
89
|
.sort(byKey);
|
|
165
90
|
return {
|
|
166
91
|
name,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {CALLBACK} from '../../spec/ports';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import {z} from 'zod';
|
|
3
4
|
import {useShallow} from 'zustand/react/shallow';
|
|
@@ -312,7 +313,8 @@ export const BLOK_EVENT_ROOT = 'event';
|
|
|
312
313
|
* every other event is handed over as the component built it.
|
|
313
314
|
*/
|
|
314
315
|
export const shapeEvent = (component: string, key: string, payload: unknown): unknown => {
|
|
315
|
-
const
|
|
316
|
+
const port = defaultBlokView().components.get(component)?.props.find(prop => prop.key === key)?.port;
|
|
317
|
+
const fields = port?.kind === CALLBACK ? (port.children ?? []) : null;
|
|
316
318
|
if (fields && fields.length === 1 && fields[0].key === 'value') {
|
|
317
319
|
const wrapped =
|
|
318
320
|
payload !== null && typeof payload === 'object' && !Array.isArray(payload) && Object.keys(payload).length === 1 && 'value' in payload;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {z} from 'zod';
|
|
2
|
+
import {TEXT_PORT, type SpecPort} from '../../spec/ports';
|
|
2
3
|
import type {
|
|
3
4
|
BlokActionArgument,
|
|
4
5
|
BlokAgentCall,
|
|
@@ -104,15 +105,37 @@ export const markBindSchema = <TSchema extends z.ZodTypeAny>(schema: TSchema): T
|
|
|
104
105
|
export const isBindSchema = (schema: z.ZodTypeAny | undefined): boolean =>
|
|
105
106
|
schema !== undefined && (bindSchemaRegistry.has(schema) || bindSchemaRegistry.has(unwrapSchema(schema)));
|
|
106
107
|
|
|
108
|
+
/**
|
|
109
|
+
* What a schema publishes as its port where its zod shape says less (a pipe, a
|
|
110
|
+
* reference object). Keyed by the schema object; looked up at every unwrap
|
|
111
|
+
* step, since `.describe()` clones only the outer wrapper.
|
|
112
|
+
*/
|
|
113
|
+
const portSchemaRegistry = new WeakMap<object, SpecPort>();
|
|
114
|
+
|
|
115
|
+
/** Publish `schema` as `port` (a recursive or opaque shape the converter cannot read). */
|
|
116
|
+
export const markPortSchema = <TSchema extends z.ZodTypeAny>(schema: TSchema, port: SpecPort): TSchema => {
|
|
117
|
+
portSchemaRegistry.set(schema, port);
|
|
118
|
+
return schema;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Publish `schema` as a STRUCTURE of `identifier` (`*`: any). */
|
|
122
|
+
export const markStructureSchema = <TSchema extends z.ZodTypeAny>(schema: TSchema, identifier: string): TSchema =>
|
|
123
|
+
markPortSchema(schema, {kind: 'STRUCTURE', identifier});
|
|
124
|
+
|
|
125
|
+
/** Publish `schema` as text: `UNION(STRING, INT, FLOAT, BOOL)`. */
|
|
126
|
+
export const markTextSchema = <TSchema extends z.ZodTypeAny>(schema: TSchema): TSchema => markPortSchema(schema, TEXT_PORT);
|
|
127
|
+
|
|
128
|
+
export const markedPort = (schema: z.ZodTypeAny): SpecPort | undefined => portSchemaRegistry.get(schema);
|
|
129
|
+
|
|
107
130
|
const actionValueSchema = markActionSchema(
|
|
108
131
|
z.custom<() => void>(value => typeof value === 'function', {
|
|
109
132
|
message: 'Expected action handler',
|
|
110
133
|
}),
|
|
111
134
|
);
|
|
112
135
|
|
|
113
|
-
const dynamicTextSchema =
|
|
114
|
-
.union([z.string(), z.number(), z.boolean()])
|
|
115
|
-
|
|
136
|
+
const dynamicTextSchema = markTextSchema(
|
|
137
|
+
z.union([z.string(), z.number(), z.boolean()]).transform(value => String(value)),
|
|
138
|
+
);
|
|
116
139
|
|
|
117
140
|
/**
|
|
118
141
|
* Client-side contract for `checks` — a declarative guard list that disables an
|
|
@@ -120,19 +143,30 @@ const dynamicTextSchema = z
|
|
|
120
143
|
* boolean, a data-model path (truthy test), or an explicit
|
|
121
144
|
* `{path | util_call, operator, value}` predicate.
|
|
122
145
|
*/
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
'
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
const CHECK_OPERATORS = ['truthy', 'falsy', 'equals', 'notEquals', 'gt', 'gte', 'lt', 'lte', 'nonEmpty'] as const;
|
|
147
|
+
|
|
148
|
+
const checkOperatorSchema = z.enum(CHECK_OPERATORS);
|
|
149
|
+
|
|
150
|
+
/** A check as an author writes one; a `util_call` inside a literal is the renderer's, not published. */
|
|
151
|
+
const CHECK_PORT: SpecPort = {
|
|
152
|
+
kind: 'UNION',
|
|
153
|
+
children: [
|
|
154
|
+
{key: '0', kind: 'BOOL'},
|
|
155
|
+
{key: '1', kind: 'STRING'},
|
|
156
|
+
{
|
|
157
|
+
key: '2',
|
|
158
|
+
kind: 'MODEL',
|
|
159
|
+
children: [
|
|
160
|
+
{key: 'path', kind: 'STRING', nullable: true},
|
|
161
|
+
{key: 'operator', kind: 'STRING', nullable: true, choices: CHECK_OPERATORS.map(value => ({value}))},
|
|
162
|
+
{key: 'value', ...TEXT_PORT, nullable: true},
|
|
163
|
+
{key: 'message', kind: 'STRING', nullable: true},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const checkDescriptorSchema = markPortSchema(z.union([
|
|
136
170
|
z.boolean(),
|
|
137
171
|
z.string(),
|
|
138
172
|
z.object({
|
|
@@ -142,7 +176,7 @@ const checkDescriptorSchema = z.union([
|
|
|
142
176
|
value: z.unknown().optional(),
|
|
143
177
|
message: z.string().optional(),
|
|
144
178
|
}),
|
|
145
|
-
]);
|
|
179
|
+
]), CHECK_PORT);
|
|
146
180
|
|
|
147
181
|
export type BlokCheckDescriptor = z.infer<typeof checkDescriptorSchema>;
|
|
148
182
|
export type BlokCheckOperator = z.infer<typeof checkOperatorSchema>;
|