@arkitektio/bsx 6.9.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/bsx/infer.d.ts.map +1 -1
  2. package/dist/bsx/infer.js +4 -2
  3. package/dist/bsx/infer.js.map +1 -1
  4. package/dist/bsx/language.d.ts.map +1 -1
  5. package/dist/bsx/language.js +14 -10
  6. package/dist/bsx/language.js.map +1 -1
  7. package/dist/bsx/references.d.ts.map +1 -1
  8. package/dist/bsx/references.js +94 -35
  9. package/dist/bsx/references.js.map +1 -1
  10. package/dist/catalogs/index.d.ts +191 -98
  11. package/dist/catalogs/index.d.ts.map +1 -1
  12. package/dist/catalogs/parts/data.d.ts +2 -2
  13. package/dist/catalogs/parts/data.d.ts.map +1 -1
  14. package/dist/catalogs/parts/data.js +2 -3
  15. package/dist/catalogs/parts/data.js.map +1 -1
  16. package/dist/catalogs/parts/feedback.d.ts +6 -6
  17. package/dist/catalogs/parts/forms.d.ts +8 -8
  18. package/dist/catalogs/parts/icons.d.ts +4 -4
  19. package/dist/catalogs/parts/index.d.ts +48 -48
  20. package/dist/catalogs/parts/navigation.d.ts +8 -8
  21. package/dist/catalogs/parts/overlays.d.ts +22 -22
  22. package/dist/catalogs/parts/run.d.ts.map +1 -1
  23. package/dist/catalogs/parts/run.js +4 -5
  24. package/dist/catalogs/parts/run.js.map +1 -1
  25. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  26. package/dist/catalogs/parts/scene.js +7 -14
  27. package/dist/catalogs/parts/scene.js.map +1 -1
  28. package/dist/catalogs/parts/structure.d.ts.map +1 -1
  29. package/dist/catalogs/parts/structure.js +2 -3
  30. package/dist/catalogs/parts/structure.js.map +1 -1
  31. package/dist/catalogs/parts/toast.d.ts.map +1 -1
  32. package/dist/catalogs/parts/toast.js +2 -1
  33. package/dist/catalogs/parts/toast.js.map +1 -1
  34. package/dist/catalogs/props.d.ts +23 -0
  35. package/dist/catalogs/props.d.ts.map +1 -1
  36. package/dist/catalogs/props.js +56 -4
  37. package/dist/catalogs/props.js.map +1 -1
  38. package/dist/catalogs/scene.d.ts +134 -127
  39. package/dist/catalogs/scene.d.ts.map +1 -1
  40. package/dist/catalogs/scene.js +5 -3
  41. package/dist/catalogs/scene.js.map +1 -1
  42. package/dist/catalogs/shadcn.d.ts +79 -41
  43. package/dist/catalogs/shadcn.d.ts.map +1 -1
  44. package/dist/catalogs/shadcn.js +13 -13
  45. package/dist/catalogs/shadcn.js.map +1 -1
  46. package/dist/catalogs/structure.d.ts +9 -2
  47. package/dist/catalogs/structure.d.ts.map +1 -1
  48. package/dist/catalogs/structure.js +1 -1
  49. package/dist/catalogs/structure.js.map +1 -1
  50. package/dist/catalogs/ui.d.ts +935 -892
  51. package/dist/catalogs/ui.d.ts.map +1 -1
  52. package/dist/catalogs/ui.js +16 -14
  53. package/dist/catalogs/ui.js.map +1 -1
  54. package/dist/catalogs/zodToPort.d.ts +9 -0
  55. package/dist/catalogs/zodToPort.d.ts.map +1 -0
  56. package/dist/catalogs/zodToPort.js +156 -0
  57. package/dist/catalogs/zodToPort.js.map +1 -0
  58. package/dist/catalogs.d.ts +4 -1
  59. package/dist/catalogs.d.ts.map +1 -1
  60. package/dist/catalogs.js +3 -0
  61. package/dist/catalogs.js.map +1 -1
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +2 -0
  65. package/dist/index.js.map +1 -1
  66. package/dist/ports/rekuest.d.ts +6 -0
  67. package/dist/ports/rekuest.d.ts.map +1 -1
  68. package/dist/ports/rekuest.js +6 -0
  69. package/dist/ports/rekuest.js.map +1 -1
  70. package/dist/renderer/bloks/data.d.ts +2 -2
  71. package/dist/renderer/bloks/feedback.d.ts +6 -6
  72. package/dist/renderer/bloks/forms.d.ts +8 -8
  73. package/dist/renderer/bloks/icons.d.ts +2 -2
  74. package/dist/renderer/bloks/index.d.ts +48 -48
  75. package/dist/renderer/bloks/navigation.d.ts +8 -8
  76. package/dist/renderer/bloks/overlays.d.ts +22 -22
  77. package/dist/renderer/runtime/components.d.ts +6 -8
  78. package/dist/renderer/runtime/components.d.ts.map +1 -1
  79. package/dist/renderer/runtime/components.js.map +1 -1
  80. package/dist/renderer/runtime/describe.d.ts +5 -12
  81. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  82. package/dist/renderer/runtime/describe.js +25 -89
  83. package/dist/renderer/runtime/describe.js.map +1 -1
  84. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  85. package/dist/renderer/runtime/hooks.js +3 -1
  86. package/dist/renderer/runtime/hooks.js.map +1 -1
  87. package/dist/renderer/runtime/schemas.d.ts +8 -6
  88. package/dist/renderer/runtime/schemas.d.ts.map +1 -1
  89. package/dist/renderer/runtime/schemas.js +40 -16
  90. package/dist/renderer/runtime/schemas.js.map +1 -1
  91. package/dist/shadcn.d.ts +48 -48
  92. package/dist/spec/bsx_v2.json +917 -15
  93. package/dist/spec/catalogs/base@4.json +18712 -5274
  94. package/dist/spec/catalogs/base@4.json.js +18712 -5274
  95. package/dist/spec/catalogs/orkestrator@1.json +532 -126
  96. package/dist/spec/catalogs/orkestrator@1.json.js +532 -126
  97. package/dist/spec/catalogs.d.ts +3 -11
  98. package/dist/spec/catalogs.d.ts.map +1 -1
  99. package/dist/spec/catalogs.js +13 -11
  100. package/dist/spec/catalogs.js.map +1 -1
  101. package/dist/spec/fit.d.ts +21 -0
  102. package/dist/spec/fit.d.ts.map +1 -0
  103. package/dist/spec/fit.js +114 -0
  104. package/dist/spec/fit.js.map +1 -0
  105. package/dist/spec/ports.d.ts +56 -0
  106. package/dist/spec/ports.d.ts.map +1 -0
  107. package/dist/spec/ports.js +174 -0
  108. package/dist/spec/ports.js.map +1 -0
  109. package/dist/spec/vocabulary.json +7 -5
  110. package/dist/spec/vocabulary.json.js +7 -5
  111. package/package.json +1 -1
  112. package/src/bsx/infer.test.ts +1 -1
  113. package/src/bsx/infer.ts +4 -2
  114. package/src/bsx/language.ts +13 -9
  115. package/src/bsx/references.ts +125 -38
  116. package/src/catalogs/parts/data.ts +3 -2
  117. package/src/catalogs/parts/run.ts +9 -7
  118. package/src/catalogs/parts/scene.ts +7 -14
  119. package/src/catalogs/parts/structure.ts +2 -3
  120. package/src/catalogs/parts/toast.ts +5 -1
  121. package/src/catalogs/props.ts +64 -4
  122. package/src/catalogs/scene.ts +5 -3
  123. package/src/catalogs/shadcn.ts +13 -13
  124. package/src/catalogs/structure.ts +1 -1
  125. package/src/catalogs/ui.ts +16 -14
  126. package/src/catalogs/zodToPort.test.ts +96 -0
  127. package/src/catalogs/zodToPort.ts +177 -0
  128. package/src/catalogs.ts +4 -1
  129. package/src/index.ts +2 -0
  130. package/src/ports/rekuest.ts +6 -0
  131. package/src/renderer/runtime/catalog.test.ts +12 -8
  132. package/src/renderer/runtime/components.tsx +5 -8
  133. package/src/renderer/runtime/describe.ts +25 -100
  134. package/src/renderer/runtime/hooks.ts +3 -1
  135. package/src/renderer/runtime/schemas.ts +51 -17
  136. package/src/spec/bsx_v2.json +917 -15
  137. package/src/spec/catalogs/base@4.json +18712 -5274
  138. package/src/spec/catalogs/orkestrator@1.json +532 -126
  139. package/src/spec/catalogs.ts +14 -19
  140. package/src/spec/fit.test.ts +65 -0
  141. package/src/spec/fit.ts +114 -0
  142. package/src/spec/ports.ts +172 -0
  143. package/src/spec/spec.test.ts +5 -2
  144. 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', kind: 'FLOAT', description: 'Where it stands.'}]},
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: kinds, values, the bind kind, event fields and the text prop', () => {
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', required: false, description: 'How far.', values: ['low', 'high']},
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`), as the spec publishes it. */
47
- export type BlokEventField = {key: string; kind: string; description: 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
- * Per `bind` prop, the kind of value the control writes to the path it names
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, unwrapSchema} from './schemas';
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
- kind: string;
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
- * What a `bind` says it writes, by the kind it writes: the ports whose locals
132
- * it may name. Appended to a bind prop's description unless it says so itself.
133
- */
134
- const BIND_WRITES: Readonly<Record<string, string>> = {
135
- BOOL: 'It writes a BOOL: the local is a BOOL port.',
136
- FLOAT: 'It writes a FLOAT: the local is a FLOAT, INT or QUANTITY port.',
137
- STRING: 'It writes a STRING: the local is a STRING, ENUM or DATE port.',
138
- };
139
-
140
- const bindDescription = (description: string | null, kind: string): string | null => {
141
- const writes = BIND_WRITES[kind];
142
- if (!writes || description?.includes('It writes')) return description;
143
- return description ? `${description} ${writes}` : writes;
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
- const bindKind = isBindSchema(schema) ? component.bindKinds?.[key] : undefined;
156
- const kind = component.propKinds?.[key] ?? bindKind ?? zodToSpecKind(schema);
157
- const description = bindKind ? bindDescription(schema.description ?? null, bindKind) : (schema.description ?? null);
158
- const prop: SpecPropJson = {key, kind, required: isRequiredField(schema), description};
159
- const values = kind === 'STRING' ? zodEnumValues(schema) : null;
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 fields = defaultBlokView().components.get(component)?.props.find(prop => prop.key === key)?.event;
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 = z
114
- .union([z.string(), z.number(), z.boolean()])
115
- .transform(value => String(value));
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 checkOperatorSchema = z.enum([
124
- 'truthy',
125
- 'falsy',
126
- 'equals',
127
- 'notEquals',
128
- 'gt',
129
- 'gte',
130
- 'lt',
131
- 'lte',
132
- 'nonEmpty',
133
- ]);
134
-
135
- const checkDescriptorSchema = z.union([
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>;