@positronic/core 0.0.52 → 0.0.53
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/src/dsl/{loop-messages.js → agent-messages.js} +21 -21
- package/dist/src/dsl/brain-runner.js +6 -6
- package/dist/src/dsl/brain-state-machine.js +2 -2
- package/dist/src/dsl/brain.js +5 -1912
- package/dist/src/dsl/builder/brain.js +944 -0
- package/dist/src/dsl/builder/step.js +75 -0
- package/dist/src/dsl/constants.js +9 -10
- package/dist/src/dsl/create-brain.js +63 -0
- package/dist/src/dsl/definitions/blocks.js +1 -0
- package/dist/src/dsl/definitions/brain-types.js +4 -0
- package/dist/src/dsl/definitions/events.js +2 -0
- package/dist/src/dsl/definitions/run-params.js +1 -0
- package/dist/src/dsl/definitions/steps.js +2 -0
- package/dist/src/dsl/execution/constants.js +14 -0
- package/dist/src/dsl/execution/event-stream.js +1638 -0
- package/dist/src/dsl/execution/retry.js +298 -0
- package/dist/src/dsl/types.js +2 -2
- package/dist/src/index.js +5 -3
- package/dist/src/tools/index.js +181 -0
- package/dist/src/ui/component-utils.js +107 -0
- package/dist/src/ui/generate-page-html.js +36 -0
- package/dist/src/ui/generate-ui.js +601 -0
- package/dist/src/ui/types.js +165 -0
- package/dist/src/ui/validate-form.js +428 -0
- package/dist/src/yaml/data-validator.js +302 -0
- package/dist/src/yaml/index.js +9 -0
- package/dist/src/yaml/parser.js +224 -0
- package/dist/src/yaml/schema-extractor.js +330 -0
- package/dist/src/yaml/type-inference.js +210 -0
- package/dist/src/yaml/types.js +12 -0
- package/dist/types/clients/types.d.ts +42 -0
- package/dist/types/clients/types.d.ts.map +1 -1
- package/dist/types/dsl/agent-messages.d.ts +18 -0
- package/dist/types/dsl/agent-messages.d.ts.map +1 -0
- package/dist/types/dsl/brain-runner.d.ts +2 -2
- package/dist/types/dsl/brain-runner.d.ts.map +1 -1
- package/dist/types/dsl/brain-state-machine.d.ts.map +1 -1
- package/dist/types/dsl/brain.d.ts +7 -273
- package/dist/types/dsl/brain.d.ts.map +1 -1
- package/dist/types/dsl/builder/brain.d.ts +200 -0
- package/dist/types/dsl/builder/brain.d.ts.map +1 -0
- package/dist/types/dsl/builder/step.d.ts +15 -0
- package/dist/types/dsl/builder/step.d.ts.map +1 -0
- package/dist/types/dsl/constants.d.ts +8 -9
- package/dist/types/dsl/constants.d.ts.map +1 -1
- package/dist/types/dsl/create-brain.d.ts +80 -0
- package/dist/types/dsl/create-brain.d.ts.map +1 -0
- package/dist/types/dsl/definitions/blocks.d.ts +62 -0
- package/dist/types/dsl/definitions/blocks.d.ts.map +1 -0
- package/dist/types/dsl/definitions/brain-types.d.ts +33 -0
- package/dist/types/dsl/definitions/brain-types.d.ts.map +1 -0
- package/dist/types/dsl/definitions/events.d.ts +129 -0
- package/dist/types/dsl/definitions/events.d.ts.map +1 -0
- package/dist/types/dsl/definitions/run-params.d.ts +26 -0
- package/dist/types/dsl/definitions/run-params.d.ts.map +1 -0
- package/dist/types/dsl/definitions/steps.d.ts +20 -0
- package/dist/types/dsl/definitions/steps.d.ts.map +1 -0
- package/dist/types/dsl/example-webhook.d.ts +1 -1
- package/dist/types/dsl/example-webhook.d.ts.map +1 -1
- package/dist/types/dsl/execution/constants.d.ts +16 -0
- package/dist/types/dsl/execution/constants.d.ts.map +1 -0
- package/dist/types/dsl/execution/event-stream.d.ts +44 -0
- package/dist/types/dsl/execution/event-stream.d.ts.map +1 -0
- package/dist/types/dsl/execution/retry.d.ts +30 -0
- package/dist/types/dsl/execution/retry.d.ts.map +1 -0
- package/dist/types/dsl/types.d.ts +35 -14
- package/dist/types/dsl/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tools/index.d.ts +33 -0
- package/dist/types/tools/index.d.ts.map +1 -0
- package/dist/types/ui/component-utils.d.ts +19 -0
- package/dist/types/ui/component-utils.d.ts.map +1 -0
- package/dist/types/ui/generate-page-html.d.ts +39 -0
- package/dist/types/ui/generate-page-html.d.ts.map +1 -0
- package/dist/types/ui/generate-ui.d.ts +47 -0
- package/dist/types/ui/generate-ui.d.ts.map +1 -0
- package/dist/types/ui/types.d.ts +138 -0
- package/dist/types/ui/types.d.ts.map +1 -0
- package/dist/types/ui/validate-form.d.ts +45 -0
- package/dist/types/ui/validate-form.d.ts.map +1 -0
- package/dist/types/yaml/data-validator.d.ts +35 -0
- package/dist/types/yaml/data-validator.d.ts.map +1 -0
- package/dist/types/yaml/index.d.ts +11 -0
- package/dist/types/yaml/index.d.ts.map +1 -0
- package/dist/types/yaml/parser.d.ts +20 -0
- package/dist/types/yaml/parser.d.ts.map +1 -0
- package/dist/types/yaml/schema-extractor.d.ts +29 -0
- package/dist/types/yaml/schema-extractor.d.ts.map +1 -0
- package/dist/types/yaml/type-inference.d.ts +50 -0
- package/dist/types/yaml/type-inference.d.ts.map +1 -0
- package/dist/types/yaml/types.d.ts +89 -0
- package/dist/types/yaml/types.d.ts.map +1 -0
- package/package.json +4 -2
- package/dist/types/dsl/loop-messages.d.ts +0 -18
- package/dist/types/dsl/loop-messages.d.ts.map +0 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data validator for YAML templates.
|
|
3
|
+
*
|
|
4
|
+
* Validates that template bindings (like {{email.subject}}) reference
|
|
5
|
+
* valid paths in the provided data structure.
|
|
6
|
+
*/ function _array_like_to_array(arr, len) {
|
|
7
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
8
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
9
|
+
return arr2;
|
|
10
|
+
}
|
|
11
|
+
function _array_with_holes(arr) {
|
|
12
|
+
if (Array.isArray(arr)) return arr;
|
|
13
|
+
}
|
|
14
|
+
function _iterable_to_array_limit(arr, i) {
|
|
15
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
16
|
+
if (_i == null) return;
|
|
17
|
+
var _arr = [];
|
|
18
|
+
var _n = true;
|
|
19
|
+
var _d = false;
|
|
20
|
+
var _s, _e;
|
|
21
|
+
try {
|
|
22
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
23
|
+
_arr.push(_s.value);
|
|
24
|
+
if (i && _arr.length === i) break;
|
|
25
|
+
}
|
|
26
|
+
} catch (err) {
|
|
27
|
+
_d = true;
|
|
28
|
+
_e = err;
|
|
29
|
+
} finally{
|
|
30
|
+
try {
|
|
31
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
32
|
+
} finally{
|
|
33
|
+
if (_d) throw _e;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return _arr;
|
|
37
|
+
}
|
|
38
|
+
function _non_iterable_rest() {
|
|
39
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
40
|
+
}
|
|
41
|
+
function _sliced_to_array(arr, i) {
|
|
42
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
43
|
+
}
|
|
44
|
+
function _type_of(obj) {
|
|
45
|
+
"@swc/helpers - typeof";
|
|
46
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
47
|
+
}
|
|
48
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
49
|
+
if (!o) return;
|
|
50
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
51
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
52
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
53
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
54
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Infer a DataType from a sample JavaScript value.
|
|
58
|
+
*/ export function inferDataType(value) {
|
|
59
|
+
if (value === null) {
|
|
60
|
+
return {
|
|
61
|
+
kind: 'primitive',
|
|
62
|
+
type: 'null'
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (typeof value === 'string') {
|
|
66
|
+
return {
|
|
67
|
+
kind: 'primitive',
|
|
68
|
+
type: 'string'
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (typeof value === 'number') {
|
|
72
|
+
return {
|
|
73
|
+
kind: 'primitive',
|
|
74
|
+
type: 'number'
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (typeof value === 'boolean') {
|
|
78
|
+
return {
|
|
79
|
+
kind: 'primitive',
|
|
80
|
+
type: 'boolean'
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
if (value.length === 0) {
|
|
85
|
+
return {
|
|
86
|
+
kind: 'array',
|
|
87
|
+
elementType: {
|
|
88
|
+
kind: 'unknown'
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Infer element type from first element
|
|
93
|
+
return {
|
|
94
|
+
kind: 'array',
|
|
95
|
+
elementType: inferDataType(value[0])
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object') {
|
|
99
|
+
var properties = {};
|
|
100
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
101
|
+
try {
|
|
102
|
+
for(var _iterator = Object.entries(value)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
103
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], val = _step_value[1];
|
|
104
|
+
properties[key] = inferDataType(val);
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
_didIteratorError = true;
|
|
108
|
+
_iteratorError = err;
|
|
109
|
+
} finally{
|
|
110
|
+
try {
|
|
111
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
112
|
+
_iterator.return();
|
|
113
|
+
}
|
|
114
|
+
} finally{
|
|
115
|
+
if (_didIteratorError) {
|
|
116
|
+
throw _iteratorError;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
kind: 'object',
|
|
122
|
+
properties: properties
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
kind: 'unknown'
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Resolve a binding path against a data type, considering loop context.
|
|
131
|
+
*
|
|
132
|
+
* @param path - The binding path like "email.subject" or "emails"
|
|
133
|
+
* @param rootType - The root data type
|
|
134
|
+
* @param loopContext - Map of loop variable names to their types
|
|
135
|
+
* @returns The resolved DataType or null if path is invalid
|
|
136
|
+
*/ export function resolvePathType(path, rootType, loopContext) {
|
|
137
|
+
var segments = path.split('.');
|
|
138
|
+
var firstSegment = segments[0];
|
|
139
|
+
// Check if first segment is a loop variable
|
|
140
|
+
if (loopContext.has(firstSegment)) {
|
|
141
|
+
var current = loopContext.get(firstSegment);
|
|
142
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
143
|
+
try {
|
|
144
|
+
for(var _iterator = segments.slice(1)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
145
|
+
var segment = _step.value;
|
|
146
|
+
if (current.kind !== 'object') {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
if (!(segment in current.properties)) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
current = current.properties[segment];
|
|
153
|
+
}
|
|
154
|
+
} catch (err) {
|
|
155
|
+
_didIteratorError = true;
|
|
156
|
+
_iteratorError = err;
|
|
157
|
+
} finally{
|
|
158
|
+
try {
|
|
159
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
160
|
+
_iterator.return();
|
|
161
|
+
}
|
|
162
|
+
} finally{
|
|
163
|
+
if (_didIteratorError) {
|
|
164
|
+
throw _iteratorError;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return current;
|
|
169
|
+
}
|
|
170
|
+
// Otherwise resolve against root type
|
|
171
|
+
var current1 = rootType;
|
|
172
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
173
|
+
try {
|
|
174
|
+
for(var _iterator1 = segments[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
175
|
+
var segment1 = _step1.value;
|
|
176
|
+
if (current1.kind !== 'object') {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
if (!(segment1 in current1.properties)) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
current1 = current1.properties[segment1];
|
|
183
|
+
}
|
|
184
|
+
} catch (err) {
|
|
185
|
+
_didIteratorError1 = true;
|
|
186
|
+
_iteratorError1 = err;
|
|
187
|
+
} finally{
|
|
188
|
+
try {
|
|
189
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
190
|
+
_iterator1.return();
|
|
191
|
+
}
|
|
192
|
+
} finally{
|
|
193
|
+
if (_didIteratorError1) {
|
|
194
|
+
throw _iteratorError1;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return current1;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Validate all data bindings in a component tree.
|
|
202
|
+
*
|
|
203
|
+
* @param root - The root ComponentNode
|
|
204
|
+
* @param dataType - The inferred type of the available data
|
|
205
|
+
* @returns ValidationResult with any errors found
|
|
206
|
+
*/ export function validateDataBindings(root, dataType) {
|
|
207
|
+
var errors = [];
|
|
208
|
+
function validateNode(node, loopContext) {
|
|
209
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
210
|
+
try {
|
|
211
|
+
// Check all props for bindings
|
|
212
|
+
for(var _iterator = Object.entries(node.props)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
213
|
+
var _step_value = _sliced_to_array(_step.value, 2), propName = _step_value[0], propValue = _step_value[1];
|
|
214
|
+
if (propValue.type === 'binding') {
|
|
215
|
+
var resolved = resolvePathType(propValue.path, dataType, loopContext);
|
|
216
|
+
if (resolved === null) {
|
|
217
|
+
errors.push({
|
|
218
|
+
type: 'invalid-binding',
|
|
219
|
+
message: 'Invalid binding path "{{'.concat(propValue.path, '}}" in ').concat(node.component, ".").concat(propName),
|
|
220
|
+
path: propValue.path
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
} catch (err) {
|
|
226
|
+
_didIteratorError = true;
|
|
227
|
+
_iteratorError = err;
|
|
228
|
+
} finally{
|
|
229
|
+
try {
|
|
230
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
231
|
+
_iterator.return();
|
|
232
|
+
}
|
|
233
|
+
} finally{
|
|
234
|
+
if (_didIteratorError) {
|
|
235
|
+
throw _iteratorError;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// Handle List/Each components that create loop context
|
|
240
|
+
if (node.component === 'List' || node.component === 'Each') {
|
|
241
|
+
var itemsProp = node.props.items;
|
|
242
|
+
var asProp = node.props.as;
|
|
243
|
+
if ((itemsProp === null || itemsProp === void 0 ? void 0 : itemsProp.type) === 'binding') {
|
|
244
|
+
var itemsType = resolvePathType(itemsProp.path, dataType, loopContext);
|
|
245
|
+
if (itemsType && itemsType.kind === 'array') {
|
|
246
|
+
// Create new loop context with the loop variable
|
|
247
|
+
var varName = (asProp === null || asProp === void 0 ? void 0 : asProp.type) === 'literal' && typeof asProp.value === 'string' ? asProp.value : 'item';
|
|
248
|
+
var newContext = new Map(loopContext);
|
|
249
|
+
newContext.set(varName, itemsType.elementType);
|
|
250
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
251
|
+
try {
|
|
252
|
+
// Validate children with the new context
|
|
253
|
+
for(var _iterator1 = node.children[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
254
|
+
var child = _step1.value;
|
|
255
|
+
validateNode(child, newContext);
|
|
256
|
+
}
|
|
257
|
+
} catch (err) {
|
|
258
|
+
_didIteratorError1 = true;
|
|
259
|
+
_iteratorError1 = err;
|
|
260
|
+
} finally{
|
|
261
|
+
try {
|
|
262
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
263
|
+
_iterator1.return();
|
|
264
|
+
}
|
|
265
|
+
} finally{
|
|
266
|
+
if (_didIteratorError1) {
|
|
267
|
+
throw _iteratorError1;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
276
|
+
try {
|
|
277
|
+
// Validate children with current context
|
|
278
|
+
for(var _iterator2 = node.children[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
279
|
+
var child1 = _step2.value;
|
|
280
|
+
validateNode(child1, loopContext);
|
|
281
|
+
}
|
|
282
|
+
} catch (err) {
|
|
283
|
+
_didIteratorError2 = true;
|
|
284
|
+
_iteratorError2 = err;
|
|
285
|
+
} finally{
|
|
286
|
+
try {
|
|
287
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
288
|
+
_iterator2.return();
|
|
289
|
+
}
|
|
290
|
+
} finally{
|
|
291
|
+
if (_didIteratorError2) {
|
|
292
|
+
throw _iteratorError2;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
validateNode(root, new Map());
|
|
298
|
+
return {
|
|
299
|
+
valid: errors.length === 0,
|
|
300
|
+
errors: errors
|
|
301
|
+
};
|
|
302
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML-based UI generation module.
|
|
3
|
+
*
|
|
4
|
+
* Provides parsing, validation, and type inference for YAML UI templates.
|
|
5
|
+
*/ export * from './types.js';
|
|
6
|
+
export { parseTemplate, stringifyTemplate } from './parser.js';
|
|
7
|
+
export { inferDataType, resolvePathType, validateDataBindings } from './data-validator.js';
|
|
8
|
+
export { extractFormSchema, fieldsToShape, validateAgainstZod } from './schema-extractor.js';
|
|
9
|
+
export { describeDataShape, inferTypeWithExamples } from './type-inference.js';
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML parser for UI templates.
|
|
3
|
+
*
|
|
4
|
+
* Parses YAML strings into a ComponentNode AST. Uses the {{path}} syntax
|
|
5
|
+
* to detect binding expressions that will be resolved at render time.
|
|
6
|
+
*/ function _array_like_to_array(arr, len) {
|
|
7
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
8
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
9
|
+
return arr2;
|
|
10
|
+
}
|
|
11
|
+
function _array_with_holes(arr) {
|
|
12
|
+
if (Array.isArray(arr)) return arr;
|
|
13
|
+
}
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _iterable_to_array_limit(arr, i) {
|
|
28
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
29
|
+
if (_i == null) return;
|
|
30
|
+
var _arr = [];
|
|
31
|
+
var _n = true;
|
|
32
|
+
var _d = false;
|
|
33
|
+
var _s, _e;
|
|
34
|
+
try {
|
|
35
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
36
|
+
_arr.push(_s.value);
|
|
37
|
+
if (i && _arr.length === i) break;
|
|
38
|
+
}
|
|
39
|
+
} catch (err) {
|
|
40
|
+
_d = true;
|
|
41
|
+
_e = err;
|
|
42
|
+
} finally{
|
|
43
|
+
try {
|
|
44
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
45
|
+
} finally{
|
|
46
|
+
if (_d) throw _e;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return _arr;
|
|
50
|
+
}
|
|
51
|
+
function _non_iterable_rest() {
|
|
52
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
53
|
+
}
|
|
54
|
+
function _sliced_to_array(arr, i) {
|
|
55
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
56
|
+
}
|
|
57
|
+
function _type_of(obj) {
|
|
58
|
+
"@swc/helpers - typeof";
|
|
59
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
60
|
+
}
|
|
61
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
62
|
+
if (!o) return;
|
|
63
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
64
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
65
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
66
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
67
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
68
|
+
}
|
|
69
|
+
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
|
|
70
|
+
// Regex to match binding expressions like {{path}} or {{item.field}}
|
|
71
|
+
var BINDING_REGEX = /^\{\{(.+)\}\}$/;
|
|
72
|
+
/**
|
|
73
|
+
* Parse a prop value from YAML into either a binding or literal.
|
|
74
|
+
*/ function parsePropValue(value) {
|
|
75
|
+
if (typeof value === 'string') {
|
|
76
|
+
var match = value.match(BINDING_REGEX);
|
|
77
|
+
if (match) {
|
|
78
|
+
return {
|
|
79
|
+
type: 'binding',
|
|
80
|
+
path: match[1].trim()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
type: 'literal',
|
|
85
|
+
value: value
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (typeof value === 'number' || typeof value === 'boolean' || value === null) {
|
|
89
|
+
return {
|
|
90
|
+
type: 'literal',
|
|
91
|
+
value: value
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// For arrays or objects that aren't component definitions, treat as literals
|
|
95
|
+
return {
|
|
96
|
+
type: 'literal',
|
|
97
|
+
value: String(value)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Parse a single component node from the YAML object.
|
|
102
|
+
*
|
|
103
|
+
* YAML format:
|
|
104
|
+
* ```yaml
|
|
105
|
+
* Form:
|
|
106
|
+
* action: "/submit"
|
|
107
|
+
* children:
|
|
108
|
+
* - Input:
|
|
109
|
+
* name: "email"
|
|
110
|
+
* label: "{{labels.email}}"
|
|
111
|
+
* ```
|
|
112
|
+
*/ function parseComponentNode(obj) {
|
|
113
|
+
var keys = Object.keys(obj);
|
|
114
|
+
if (keys.length !== 1) {
|
|
115
|
+
throw new Error("Component object must have exactly one key (the component name), got: ".concat(keys.join(', ')));
|
|
116
|
+
}
|
|
117
|
+
var component = keys[0];
|
|
118
|
+
var propsOrChildren = obj[component];
|
|
119
|
+
// Handle case where component has no props (just the name)
|
|
120
|
+
if (propsOrChildren === null || propsOrChildren === undefined) {
|
|
121
|
+
return {
|
|
122
|
+
component: component,
|
|
123
|
+
props: {},
|
|
124
|
+
children: []
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if ((typeof propsOrChildren === "undefined" ? "undefined" : _type_of(propsOrChildren)) !== 'object' || Array.isArray(propsOrChildren)) {
|
|
128
|
+
throw new Error('Component "'.concat(component, '" props must be an object, got: ').concat(typeof propsOrChildren === "undefined" ? "undefined" : _type_of(propsOrChildren)));
|
|
129
|
+
}
|
|
130
|
+
var rawProps = propsOrChildren;
|
|
131
|
+
var props = {};
|
|
132
|
+
var children = [];
|
|
133
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
134
|
+
try {
|
|
135
|
+
for(var _iterator = Object.entries(rawProps)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
136
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
137
|
+
if (key === 'children') {
|
|
138
|
+
// Children is an array of component nodes
|
|
139
|
+
if (!Array.isArray(value)) {
|
|
140
|
+
throw new Error('"children" must be an array in component "'.concat(component, '"'));
|
|
141
|
+
}
|
|
142
|
+
children = value.map(function(child) {
|
|
143
|
+
if ((typeof child === "undefined" ? "undefined" : _type_of(child)) !== 'object' || child === null) {
|
|
144
|
+
throw new Error('Child must be a component object in "'.concat(component, '"'));
|
|
145
|
+
}
|
|
146
|
+
return parseComponentNode(child);
|
|
147
|
+
});
|
|
148
|
+
} else {
|
|
149
|
+
// Regular prop
|
|
150
|
+
props[key] = parsePropValue(value);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
_didIteratorError = true;
|
|
155
|
+
_iteratorError = err;
|
|
156
|
+
} finally{
|
|
157
|
+
try {
|
|
158
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
159
|
+
_iterator.return();
|
|
160
|
+
}
|
|
161
|
+
} finally{
|
|
162
|
+
if (_didIteratorError) {
|
|
163
|
+
throw _iteratorError;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
component: component,
|
|
169
|
+
props: props,
|
|
170
|
+
children: children
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Parse a YAML template string into a Template AST.
|
|
175
|
+
*
|
|
176
|
+
* @param yamlString - The YAML template to parse
|
|
177
|
+
* @returns The parsed Template with root ComponentNode
|
|
178
|
+
* @throws Error if YAML is invalid or doesn't match expected structure
|
|
179
|
+
*/ export function parseTemplate(yamlString) {
|
|
180
|
+
var parsed = parseYaml(yamlString);
|
|
181
|
+
if ((typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) !== 'object' || parsed === null) {
|
|
182
|
+
throw new Error('Template must be a YAML object');
|
|
183
|
+
}
|
|
184
|
+
var root = parseComponentNode(parsed);
|
|
185
|
+
return {
|
|
186
|
+
root: root
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Convert a Template back to YAML string (for debugging).
|
|
191
|
+
*/ export function stringifyTemplate(template) {
|
|
192
|
+
function nodeToObject(node) {
|
|
193
|
+
var propsObj = {};
|
|
194
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
195
|
+
try {
|
|
196
|
+
for(var _iterator = Object.entries(node.props)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
197
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], propValue = _step_value[1];
|
|
198
|
+
if (propValue.type === 'binding') {
|
|
199
|
+
propsObj[key] = "{{".concat(propValue.path, "}}");
|
|
200
|
+
} else {
|
|
201
|
+
propsObj[key] = propValue.value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} catch (err) {
|
|
205
|
+
_didIteratorError = true;
|
|
206
|
+
_iteratorError = err;
|
|
207
|
+
} finally{
|
|
208
|
+
try {
|
|
209
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
210
|
+
_iterator.return();
|
|
211
|
+
}
|
|
212
|
+
} finally{
|
|
213
|
+
if (_didIteratorError) {
|
|
214
|
+
throw _iteratorError;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (node.children.length > 0) {
|
|
219
|
+
propsObj.children = node.children.map(nodeToObject);
|
|
220
|
+
}
|
|
221
|
+
return _define_property({}, node.component, Object.keys(propsObj).length > 0 ? propsObj : null);
|
|
222
|
+
}
|
|
223
|
+
return stringifyYaml(nodeToObject(template.root));
|
|
224
|
+
}
|