@kaskad/schema 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 +217 -0
- package/esm2022/index.js +17 -0
- package/esm2022/index.js.map +1 -0
- package/esm2022/kaskad-schema.js +5 -0
- package/esm2022/kaskad-schema.js.map +1 -0
- package/esm2022/lib/load/load-schema.js +16 -0
- package/esm2022/lib/load/load-schema.js.map +1 -0
- package/esm2022/lib/load/load-templates.js +136 -0
- package/esm2022/lib/load/load-templates.js.map +1 -0
- package/esm2022/lib/load/register-declared-type.js +28 -0
- package/esm2022/lib/load/register-declared-type.js.map +1 -0
- package/esm2022/lib/load/schema-component-extractor.js +101 -0
- package/esm2022/lib/load/schema-component-extractor.js.map +1 -0
- package/esm2022/lib/load/template-registry.js +51 -0
- package/esm2022/lib/load/template-registry.js.map +1 -0
- package/esm2022/lib/types/component-definition.js +1 -0
- package/esm2022/lib/types/component-definition.js.map +1 -0
- package/esm2022/lib/types/component-schema.js +1 -0
- package/esm2022/lib/types/component-schema.js.map +1 -0
- package/esm2022/lib/types/raw-schemas.js +3 -0
- package/esm2022/lib/types/raw-schemas.js.map +1 -0
- package/esm2022/lib/types/template-raw-definition.js +1 -0
- package/esm2022/lib/types/template-raw-definition.js.map +1 -0
- package/esm2022/lib/unfolding/computation/unfold-computation-schema.js +70 -0
- package/esm2022/lib/unfolding/computation/unfold-computation-schema.js.map +1 -0
- package/esm2022/lib/unfolding/computation/unfold-for-new-syntax.js +147 -0
- package/esm2022/lib/unfolding/computation/unfold-for-new-syntax.js.map +1 -0
- package/esm2022/lib/unfolding/computation/unfold-for.js +45 -0
- package/esm2022/lib/unfolding/computation/unfold-for.js.map +1 -0
- package/esm2022/lib/unfolding/computation/unfold-if.js +18 -0
- package/esm2022/lib/unfolding/computation/unfold-if.js.map +1 -0
- package/esm2022/lib/unfolding/computation/unfold-import.js +26 -0
- package/esm2022/lib/unfolding/computation/unfold-import.js.map +1 -0
- package/esm2022/lib/unfolding/computation/unfold-interpolation.js +44 -0
- package/esm2022/lib/unfolding/computation/unfold-interpolation.js.map +1 -0
- package/esm2022/lib/unfolding/parse-binding-shorthand.js +40 -0
- package/esm2022/lib/unfolding/parse-binding-shorthand.js.map +1 -0
- package/esm2022/lib/unfolding/parse-property-key-shorthand.js +9 -0
- package/esm2022/lib/unfolding/parse-property-key-shorthand.js.map +1 -0
- package/esm2022/lib/unfolding/parse-value-type.js +115 -0
- package/esm2022/lib/unfolding/parse-value-type.js.map +1 -0
- package/esm2022/lib/unfolding/to-full-notation.js +124 -0
- package/esm2022/lib/unfolding/to-full-notation.js.map +1 -0
- package/esm2022/lib/unfolding/unfold-flat-wrapper-notation.js +72 -0
- package/esm2022/lib/unfolding/unfold-flat-wrapper-notation.js.map +1 -0
- package/esm2022/lib/unfolding/unfold-node-schema.js +35 -0
- package/esm2022/lib/unfolding/unfold-node-schema.js.map +1 -0
- package/esm2022/lib/unfolding/unfold-property.js +21 -0
- package/esm2022/lib/unfolding/unfold-property.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/index.js +11 -0
- package/esm2022/lib/unfolding/value/handlers/index.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-array.js +9 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-array.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-boolean.js +8 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-boolean.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-command.js +22 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-command.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-component-schema.js +14 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-component-schema.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-component.js +66 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-component.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-map.js +13 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-map.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-number.js +11 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-number.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-object.js +15 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-object.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-set.js +6 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-set.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-shape.js +13 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-shape.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-string.js +8 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-string.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-unknown.js +4 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-unknown.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-variant-shape.js +61 -0
- package/esm2022/lib/unfolding/value/handlers/unfold-variant-shape.js.map +1 -0
- package/esm2022/lib/unfolding/value/handlers/validate-props.js +20 -0
- package/esm2022/lib/unfolding/value/handlers/validate-props.js.map +1 -0
- package/esm2022/lib/unfolding/value/throw-unfold-value-error.js +11 -0
- package/esm2022/lib/unfolding/value/throw-unfold-value-error.js.map +1 -0
- package/esm2022/lib/unfolding/value/unfold-node-value.js +30 -0
- package/esm2022/lib/unfolding/value/unfold-node-value.js.map +1 -0
- package/esm2022/lib/util/is-object.js +4 -0
- package/esm2022/lib/util/is-object.js.map +1 -0
- package/esm2022/lib/util/stringify-object.js +4 -0
- package/esm2022/lib/util/stringify-object.js.map +1 -0
- package/esm2022/lib/util/unfold-component-definitions.js +21 -0
- package/esm2022/lib/util/unfold-component-definitions.js.map +1 -0
- package/index.d.ts +16 -0
- package/kaskad-schema.d.ts +5 -0
- package/lib/load/load-schema.d.ts +3 -0
- package/lib/load/load-templates.d.ts +2 -0
- package/lib/load/register-declared-type.d.ts +1 -0
- package/lib/load/schema-component-extractor.d.ts +2 -0
- package/lib/load/template-registry.d.ts +16 -0
- package/lib/types/component-definition.d.ts +5 -0
- package/lib/types/component-schema.d.ts +26 -0
- package/lib/types/raw-schemas.d.ts +25 -0
- package/lib/types/template-raw-definition.d.ts +7 -0
- package/lib/unfolding/computation/unfold-computation-schema.d.ts +2 -0
- package/lib/unfolding/computation/unfold-for-new-syntax.d.ts +6 -0
- package/lib/unfolding/computation/unfold-for.d.ts +2 -0
- package/lib/unfolding/computation/unfold-if.d.ts +3 -0
- package/lib/unfolding/computation/unfold-import.d.ts +2 -0
- package/lib/unfolding/computation/unfold-interpolation.d.ts +3 -0
- package/lib/unfolding/parse-binding-shorthand.d.ts +3 -0
- package/lib/unfolding/parse-property-key-shorthand.d.ts +2 -0
- package/lib/unfolding/parse-value-type.d.ts +2 -0
- package/lib/unfolding/to-full-notation.d.ts +8 -0
- package/lib/unfolding/unfold-flat-wrapper-notation.d.ts +13 -0
- package/lib/unfolding/unfold-node-schema.d.ts +3 -0
- package/lib/unfolding/unfold-property.d.ts +2 -0
- package/lib/unfolding/value/handlers/index.d.ts +10 -0
- package/lib/unfolding/value/handlers/unfold-array.d.ts +3 -0
- package/lib/unfolding/value/handlers/unfold-boolean.d.ts +2 -0
- package/lib/unfolding/value/handlers/unfold-command.d.ts +3 -0
- package/lib/unfolding/value/handlers/unfold-component-schema.d.ts +4 -0
- package/lib/unfolding/value/handlers/unfold-component.d.ts +3 -0
- package/lib/unfolding/value/handlers/unfold-map.d.ts +3 -0
- package/lib/unfolding/value/handlers/unfold-number.d.ts +2 -0
- package/lib/unfolding/value/handlers/unfold-object.d.ts +3 -0
- package/lib/unfolding/value/handlers/unfold-set.d.ts +3 -0
- package/lib/unfolding/value/handlers/unfold-shape.d.ts +3 -0
- package/lib/unfolding/value/handlers/unfold-string.d.ts +2 -0
- package/lib/unfolding/value/handlers/unfold-unknown.d.ts +2 -0
- package/lib/unfolding/value/handlers/unfold-variant-shape.d.ts +3 -0
- package/lib/unfolding/value/handlers/validate-props.d.ts +2 -0
- package/lib/unfolding/value/throw-unfold-value-error.d.ts +2 -0
- package/lib/unfolding/value/unfold-node-value.d.ts +8 -0
- package/lib/util/is-object.d.ts +1 -0
- package/lib/util/stringify-object.d.ts +1 -0
- package/lib/util/unfold-component-definitions.d.ts +4 -0
- package/package.json +28 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { DefinitionStore } from '@kaskad/definition';
|
|
2
|
+
import { NodeTypes, } from '@kaskad/types';
|
|
3
|
+
export function parseValueType(type) {
|
|
4
|
+
type = type.replaceAll(' ', '');
|
|
5
|
+
if (type.startsWith('(') && type.endsWith(')')) {
|
|
6
|
+
return createCommandType(type.slice(1, -1));
|
|
7
|
+
}
|
|
8
|
+
// Check for map type first (but not just '{}')
|
|
9
|
+
if (type.endsWith('{}') && type !== '{}') {
|
|
10
|
+
const rest = type.slice(0, -2);
|
|
11
|
+
return {
|
|
12
|
+
type: 'map',
|
|
13
|
+
item: parseValueType(rest),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
// Check for set type
|
|
17
|
+
if (type.endsWith('#')) {
|
|
18
|
+
const rest = type.slice(0, -1);
|
|
19
|
+
return {
|
|
20
|
+
type: 'set',
|
|
21
|
+
item: parseValueType(rest),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (type.endsWith('[]')) {
|
|
25
|
+
const rest = type.slice(0, -2);
|
|
26
|
+
return {
|
|
27
|
+
type: 'array',
|
|
28
|
+
item: parseValueType(rest),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Check for object type after map/array to handle {} and complex object types
|
|
32
|
+
if (type.startsWith('{') && type.endsWith('}')) {
|
|
33
|
+
return createObjectType(type.slice(1, -1));
|
|
34
|
+
}
|
|
35
|
+
return createSimpleType(type);
|
|
36
|
+
}
|
|
37
|
+
function createObjectType(type) {
|
|
38
|
+
const fieldsPairs = splitTypesByComma(type);
|
|
39
|
+
const fields = fieldsPairs.reduce((acc, str) => {
|
|
40
|
+
if (!str)
|
|
41
|
+
return acc; // Handle empty object case
|
|
42
|
+
const colonIndex = str.indexOf(':');
|
|
43
|
+
const errorPrefix = `Invalid object field definition: "${str}"`;
|
|
44
|
+
if (colonIndex === -1) {
|
|
45
|
+
throw new Error(`${errorPrefix} - expected format "fieldName:type"`);
|
|
46
|
+
}
|
|
47
|
+
const fieldKey = str.substring(0, colonIndex);
|
|
48
|
+
const fieldType = str.substring(colonIndex + 1);
|
|
49
|
+
if (!fieldKey) {
|
|
50
|
+
throw new Error(`${errorPrefix} - field name cannot be empty`);
|
|
51
|
+
}
|
|
52
|
+
if (!fieldType) {
|
|
53
|
+
throw new Error(`${errorPrefix} - field type cannot be empty`);
|
|
54
|
+
}
|
|
55
|
+
acc[fieldKey] = parseValueType(fieldType);
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
return {
|
|
59
|
+
type: 'object',
|
|
60
|
+
fields,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function createCommandType(type) {
|
|
64
|
+
const args = splitTypesByComma(type).filter(Boolean);
|
|
65
|
+
return {
|
|
66
|
+
type: 'command',
|
|
67
|
+
args: args.map(parseValueType),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function createSimpleType(type) {
|
|
71
|
+
if (NodeTypes.includes(type)) {
|
|
72
|
+
return { type };
|
|
73
|
+
}
|
|
74
|
+
if (type in DefinitionStore.getInstance().shapes) {
|
|
75
|
+
return {
|
|
76
|
+
type: 'shape',
|
|
77
|
+
shapeType: type,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (type in DefinitionStore.getInstance().variantShapes) {
|
|
81
|
+
return {
|
|
82
|
+
type: 'variantShape',
|
|
83
|
+
shapeType: type,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`Unknown type '${type}'`);
|
|
87
|
+
}
|
|
88
|
+
function splitTypesByComma(str) {
|
|
89
|
+
const pairs = [];
|
|
90
|
+
let braceCount = 0;
|
|
91
|
+
let part = '';
|
|
92
|
+
for (let i = 0; i < str.length; i++) {
|
|
93
|
+
const char = str[i];
|
|
94
|
+
if (char === '{') {
|
|
95
|
+
braceCount++;
|
|
96
|
+
part += char;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (char === '}') {
|
|
100
|
+
braceCount--;
|
|
101
|
+
part += char;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (char === ',' && braceCount === 0) {
|
|
105
|
+
pairs.push(part);
|
|
106
|
+
part = '';
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
part += char;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
pairs.push(part);
|
|
113
|
+
return pairs;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=parse-value-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-value-type.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/unfolding/parse-value-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAGL,SAAS,GAKV,MAAM,eAAe,CAAC;AAEvB,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAEhC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,+CAA+C;IAC/C,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACzC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC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;YACb,SAAS,EAAE,IAAI;SACE,CAAC;IACtB,CAAC;IAED,IAAI,IAAI,IAAI,eAAe,CAAC,WAAW,EAAE,CAAC,aAAa,EAAE,CAAC;QACxD,OAAO;YACL,IAAI,EAAE,cAAc;YACpB,SAAS,EAAE,IAAI;SACS,CAAC;IAC7B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QAEpB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,UAAU,EAAE,CAAC;YACb,IAAI,IAAI,IAAI,CAAC;YACb,SAAS;QACX,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,UAAU,EAAE,CAAC;YACb,IAAI,IAAI,IAAI,CAAC;YACb,SAAS;QACX,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACrC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,IAAI,GAAG,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,IAAI,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjB,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { DefinitionStore } from '@kaskad/definition';\nimport {\n CommandValueType,\n NodeType,\n NodeTypes,\n ObjectValueType,\n ShapeValueType,\n ValueType,\n VariantShapeValueType,\n} from '@kaskad/types';\n\nexport function parseValueType(type: string): ValueType {\n type = type.replaceAll(' ', '');\n\n if (type.startsWith('(') && type.endsWith(')')) {\n return createCommandType(type.slice(1, -1));\n }\n\n // Check for map type first (but not just '{}')\n if (type.endsWith('{}') && type !== '{}') {\n const rest = type.slice(0, -2);\n return {\n type: 'map',\n item: parseValueType(rest),\n };\n }\n\n // Check for set type\n if (type.endsWith('#')) {\n const rest = type.slice(0, -1);\n return {\n type: 'set',\n item: parseValueType(rest),\n };\n }\n\n if (type.endsWith('[]')) {\n const rest = type.slice(0, -2);\n return {\n type: 'array',\n item: parseValueType(rest),\n };\n }\n\n // Check for object type after map/array to handle {} and complex object types\n if (type.startsWith('{') && type.endsWith('}')) {\n return createObjectType(type.slice(1, -1));\n }\n\n return createSimpleType(type as NodeType);\n}\n\nfunction createObjectType(type: string): ObjectValueType {\n const fieldsPairs = splitTypesByComma(type);\n\n const fields = fieldsPairs.reduce<Record<string, ValueType>>((acc, str) => {\n if (!str) return acc; // Handle empty object case\n\n const colonIndex = str.indexOf(':');\n const errorPrefix = `Invalid object field definition: \"${str}\"`;\n\n if (colonIndex === -1) {\n throw new Error(`${errorPrefix} - expected format \"fieldName:type\"`);\n }\n\n const fieldKey = str.substring(0, colonIndex);\n const fieldType = str.substring(colonIndex + 1);\n\n if (!fieldKey) {\n throw new Error(`${errorPrefix} - field name cannot be empty`);\n }\n\n if (!fieldType) {\n throw new Error(`${errorPrefix} - field type cannot be empty`);\n }\n\n acc[fieldKey] = parseValueType(fieldType);\n return acc;\n }, {});\n\n return {\n type: 'object',\n fields,\n } satisfies ObjectValueType;\n}\n\nfunction createCommandType(type: string): CommandValueType {\n const args = splitTypesByComma(type).filter(Boolean);\n\n return {\n type: 'command',\n args: args.map(parseValueType),\n } satisfies CommandValueType;\n}\n\nfunction createSimpleType(type: NodeType): ValueType {\n if (NodeTypes.includes(type)) {\n return { type } as ValueType;\n }\n\n if (type in DefinitionStore.getInstance().shapes) {\n return {\n type: 'shape',\n shapeType: type,\n } as ShapeValueType;\n }\n\n if (type in DefinitionStore.getInstance().variantShapes) {\n return {\n type: 'variantShape',\n shapeType: type,\n } as VariantShapeValueType;\n }\n\n throw new Error(`Unknown type '${type}'`);\n}\n\nfunction splitTypesByComma(str: string): string[] {\n const pairs: string[] = [];\n\n let braceCount = 0;\n let part = '';\n\n for (let i = 0; i < str.length; i++) {\n const char = str[i];\n\n if (char === '{') {\n braceCount++;\n part += char;\n continue;\n }\n\n if (char === '}') {\n braceCount--;\n part += char;\n continue;\n }\n\n if (char === ',' && braceCount === 0) {\n pairs.push(part);\n part = '';\n } else {\n part += char;\n }\n }\n\n pairs.push(part);\n\n return pairs;\n}\n"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isBindingShorthand, parseBindingShorthand } from './parse-binding-shorthand';
|
|
2
|
+
import { extractWrappers, hasWrappers, unfoldFlatWrappers } from './unfold-flat-wrapper-notation';
|
|
3
|
+
export function toFullNotation(nodeSchema, valueType) {
|
|
4
|
+
const rawNode = {
|
|
5
|
+
_valueType: valueType,
|
|
6
|
+
_value: null,
|
|
7
|
+
_computation: null,
|
|
8
|
+
_binding: null,
|
|
9
|
+
};
|
|
10
|
+
if (nodeSchema === null) {
|
|
11
|
+
rawNode._value = null;
|
|
12
|
+
return rawNode;
|
|
13
|
+
}
|
|
14
|
+
if (typeof nodeSchema === 'string') {
|
|
15
|
+
if (nodeSchema.includes('{{') && nodeSchema.includes('}}')) {
|
|
16
|
+
rawNode._computation = nodeSchema;
|
|
17
|
+
return rawNode;
|
|
18
|
+
}
|
|
19
|
+
if (nodeSchema === '=>') {
|
|
20
|
+
rawNode._value = '=>';
|
|
21
|
+
return rawNode;
|
|
22
|
+
}
|
|
23
|
+
if (nodeSchema.startsWith('=> ')) {
|
|
24
|
+
rawNode._computation = nodeSchema;
|
|
25
|
+
return rawNode;
|
|
26
|
+
}
|
|
27
|
+
if (isBindingShorthand(nodeSchema)) {
|
|
28
|
+
const binding = parseBindingShorthand(nodeSchema);
|
|
29
|
+
if (binding) {
|
|
30
|
+
rawNode._binding = binding;
|
|
31
|
+
return rawNode;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(nodeSchema) && valueType.type === 'string') {
|
|
36
|
+
const desugared = desugarStringArray(nodeSchema);
|
|
37
|
+
return toFullNotation(desugared, valueType);
|
|
38
|
+
}
|
|
39
|
+
if (typeof nodeSchema !== 'object') {
|
|
40
|
+
rawNode._value = nodeSchema;
|
|
41
|
+
return rawNode;
|
|
42
|
+
}
|
|
43
|
+
if ('computationType' in nodeSchema) {
|
|
44
|
+
rawNode._computation = nodeSchema;
|
|
45
|
+
return rawNode;
|
|
46
|
+
}
|
|
47
|
+
if ('bindingType' in nodeSchema) {
|
|
48
|
+
rawNode._binding = nodeSchema;
|
|
49
|
+
return rawNode;
|
|
50
|
+
}
|
|
51
|
+
const isFullNotation = ['_valueType', '_value', '_computation', '_binding'].some((key) => key in nodeSchema);
|
|
52
|
+
if (isFullNotation) {
|
|
53
|
+
if ('_value' in nodeSchema)
|
|
54
|
+
rawNode._value = nodeSchema._value;
|
|
55
|
+
if ('_computation' in nodeSchema)
|
|
56
|
+
rawNode._computation = nodeSchema._computation;
|
|
57
|
+
if ('_binding' in nodeSchema)
|
|
58
|
+
rawNode._binding = nodeSchema._binding;
|
|
59
|
+
return rawNode;
|
|
60
|
+
}
|
|
61
|
+
// detect 'if' short notation
|
|
62
|
+
// TODO: change to _if to isolate keyword)
|
|
63
|
+
if ('if' in nodeSchema) {
|
|
64
|
+
const computation = {
|
|
65
|
+
computationType: 'if',
|
|
66
|
+
if: nodeSchema.if,
|
|
67
|
+
then: null,
|
|
68
|
+
else: null,
|
|
69
|
+
};
|
|
70
|
+
if (!('then' in nodeSchema) && !('else' in nodeSchema)) {
|
|
71
|
+
const { if: _, ...thenSchema } = nodeSchema;
|
|
72
|
+
computation['then'] = thenSchema;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if ('then' in nodeSchema) {
|
|
76
|
+
computation['then'] = nodeSchema['then'];
|
|
77
|
+
}
|
|
78
|
+
if ('else' in nodeSchema) {
|
|
79
|
+
computation['else'] = nodeSchema['else'];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
rawNode._computation = computation;
|
|
83
|
+
return rawNode;
|
|
84
|
+
}
|
|
85
|
+
// detect new 'for' syntax
|
|
86
|
+
if ('for' in nodeSchema) {
|
|
87
|
+
rawNode._computation = nodeSchema;
|
|
88
|
+
return rawNode;
|
|
89
|
+
}
|
|
90
|
+
if ('templateUrl' in nodeSchema) {
|
|
91
|
+
const schema = nodeSchema;
|
|
92
|
+
if (hasWrappers(schema)) {
|
|
93
|
+
const [wrappers, cleanedSchema] = extractWrappers(schema);
|
|
94
|
+
return unfoldFlatWrappers(wrappers, toFullNotation(cleanedSchema, valueType), rawNode);
|
|
95
|
+
}
|
|
96
|
+
const { templateUrl: path, ...rest } = nodeSchema;
|
|
97
|
+
rawNode._computation = { computationType: 'template', path, ...rest };
|
|
98
|
+
return rawNode;
|
|
99
|
+
}
|
|
100
|
+
if (hasWrappers(nodeSchema)) {
|
|
101
|
+
const [wrappers, cleanedSchema] = extractWrappers(nodeSchema);
|
|
102
|
+
return unfoldFlatWrappers(wrappers, toFullNotation(cleanedSchema, valueType), rawNode);
|
|
103
|
+
}
|
|
104
|
+
rawNode._value = nodeSchema;
|
|
105
|
+
return rawNode;
|
|
106
|
+
}
|
|
107
|
+
function desugarStringArray(items) {
|
|
108
|
+
if (items.length === 0)
|
|
109
|
+
return '';
|
|
110
|
+
if (items.length === 1)
|
|
111
|
+
return items[0];
|
|
112
|
+
for (const item of items) {
|
|
113
|
+
if (typeof item !== 'string') {
|
|
114
|
+
throw new Error(`styleClass array items must be strings, got ${typeof item}: ${JSON.stringify(item)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const strings = items;
|
|
118
|
+
const hasFormula = strings.some((s) => s.startsWith('=> '));
|
|
119
|
+
if (!hasFormula)
|
|
120
|
+
return strings.join(' ');
|
|
121
|
+
const parts = strings.map((s) => (s.startsWith('=> ') ? s.slice(3) : `'${s}'`));
|
|
122
|
+
return `=> concat([${parts.join(', ')}], ' ')`;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=to-full-notation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-full-notation.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/unfolding/to-full-notation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AASlG,MAAM,UAAU,cAAc,CAAC,UAAmB,EAAE,SAAoB;IACtE,MAAM,OAAO,GAAY;QACvB,UAAU,EAAE,SAAS;QACrB,MAAM,EAAE,IAAI;QACZ,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,IAAI;KACf,CAAC;IAEF,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;QACtB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3D,OAAO,CAAC,YAAY,GAAG,UAAU,CAAC;YAClC,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;YACtB,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,YAAY,GAAG,UAAU,CAAC;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K,CAAC,CAAC,CAAC;IAE5D,IAAI,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE1C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChF,OAAO,cAAc,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;AACjD,CAAC","sourcesContent":["import { BindingSchema, ValueType } from '@kaskad/types';\n\nimport { ComponentRecipe, TemplateRecipe } from '../types/component-schema';\nimport { isBindingShorthand, parseBindingShorthand } from './parse-binding-shorthand';\nimport { extractWrappers, hasWrappers, unfoldFlatWrappers } from './unfold-flat-wrapper-notation';\n\nexport type RawNode = {\n _valueType: ValueType;\n _value: unknown;\n _computation: unknown;\n _binding: unknown;\n};\n\nexport function toFullNotation(nodeSchema: unknown, valueType: ValueType): RawNode {\n const rawNode: RawNode = {\n _valueType: valueType,\n _value: null,\n _computation: null,\n _binding: null,\n };\n\n if (nodeSchema === null) {\n rawNode._value = null;\n return rawNode;\n }\n\n if (typeof nodeSchema === 'string') {\n if (nodeSchema.includes('{{') && nodeSchema.includes('}}')) {\n rawNode._computation = nodeSchema;\n return rawNode;\n }\n\n if (nodeSchema === '=>') {\n rawNode._value = '=>';\n return rawNode;\n }\n\n if (nodeSchema.startsWith('=> ')) {\n rawNode._computation = nodeSchema;\n return rawNode;\n }\n\n if (isBindingShorthand(nodeSchema)) {\n const binding = parseBindingShorthand(nodeSchema);\n if (binding) {\n rawNode._binding = binding;\n return rawNode;\n }\n }\n }\n\n if (Array.isArray(nodeSchema) && valueType.type === 'string') {\n const desugared = desugarStringArray(nodeSchema);\n return toFullNotation(desugared, valueType);\n }\n\n if (typeof nodeSchema !== 'object') {\n rawNode._value = nodeSchema;\n return rawNode;\n }\n\n if ('computationType' in nodeSchema) {\n rawNode._computation = nodeSchema;\n return rawNode;\n }\n\n if ('bindingType' in nodeSchema) {\n rawNode._binding = nodeSchema as BindingSchema;\n return rawNode;\n }\n\n const isFullNotation = ['_valueType', '_value', '_computation', '_binding'].some((key) => key in nodeSchema);\n if (isFullNotation) {\n if ('_value' in nodeSchema) rawNode._value = nodeSchema._value;\n if ('_computation' in nodeSchema) rawNode._computation = nodeSchema._computation;\n if ('_binding' in nodeSchema) rawNode._binding = nodeSchema._binding as BindingSchema;\n return rawNode;\n }\n\n // detect 'if' short notation\n // TODO: change to _if to isolate keyword)\n if ('if' in nodeSchema) {\n const computation: Record<string, unknown> = {\n computationType: 'if',\n if: nodeSchema.if,\n then: null,\n else: null,\n };\n\n if (!('then' in nodeSchema) && !('else' in nodeSchema)) {\n const { if: _, ...thenSchema } = nodeSchema;\n computation['then'] = thenSchema;\n } else {\n if ('then' in nodeSchema) {\n computation['then'] = nodeSchema['then'];\n }\n if ('else' in nodeSchema) {\n computation['else'] = nodeSchema['else'];\n }\n }\n\n rawNode._computation = computation;\n return rawNode;\n }\n\n // detect new 'for' syntax\n if ('for' in nodeSchema) {\n rawNode._computation = nodeSchema;\n return rawNode;\n }\n\n if ('templateUrl' in nodeSchema) {\n const schema = nodeSchema as TemplateRecipe;\n if (hasWrappers(schema)) {\n const [wrappers, cleanedSchema] = extractWrappers(schema);\n return unfoldFlatWrappers(wrappers, toFullNotation(cleanedSchema, valueType), rawNode);\n }\n\n const { templateUrl: path, ...rest } = nodeSchema;\n rawNode._computation = { computationType: 'template', path, ...rest };\n\n return rawNode;\n }\n\n if (hasWrappers(nodeSchema as ComponentRecipe)) {\n const [wrappers, cleanedSchema] = extractWrappers(nodeSchema as ComponentRecipe);\n return unfoldFlatWrappers(wrappers, toFullNotation(cleanedSchema, valueType), rawNode);\n }\n\n rawNode._value = nodeSchema;\n return rawNode;\n}\n\nfunction desugarStringArray(items: unknown[]): string {\n if (items.length === 0) return '';\n if (items.length === 1) return items[0] as string;\n\n for (const item of items) {\n if (typeof item !== 'string') {\n throw new Error(`styleClass array items must be strings, got ${typeof item}: ${JSON.stringify(item)}`);\n }\n }\n\n const strings = items as string[];\n const hasFormula = strings.some((s) => s.startsWith('=> '));\n\n if (!hasFormula) return strings.join(' ');\n\n const parts = strings.map((s) => (s.startsWith('=> ') ? s.slice(3) : `'${s}'`));\n return `=> concat([${parts.join(', ')}], ' ')`;\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DefinitionStore } from '@kaskad/definition';
|
|
2
|
+
import { isObject } from '../util/is-object';
|
|
3
|
+
export const WrapperPrefix = '+';
|
|
4
|
+
export const PathSymbol = '/';
|
|
5
|
+
export function unfoldFlatWrappers(wrappers, schema, resultingNode) {
|
|
6
|
+
const composed = wrappers
|
|
7
|
+
.reverse()
|
|
8
|
+
.reduce((composed, wrapper) => unfoldWrapper(wrapper, composed), schema);
|
|
9
|
+
if ('computationType' in composed) {
|
|
10
|
+
resultingNode._computation = composed;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
resultingNode._value = composed;
|
|
14
|
+
}
|
|
15
|
+
return resultingNode;
|
|
16
|
+
}
|
|
17
|
+
function unfoldWrapper(wrapper, schema) {
|
|
18
|
+
const [componentType, props] = wrapper;
|
|
19
|
+
if (componentType.includes(PathSymbol)) {
|
|
20
|
+
return {
|
|
21
|
+
computationType: 'template',
|
|
22
|
+
path: componentType,
|
|
23
|
+
...props,
|
|
24
|
+
slot: schema,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const slot = getComponentSlot(componentType);
|
|
28
|
+
return {
|
|
29
|
+
componentType,
|
|
30
|
+
...props,
|
|
31
|
+
[slot]: {
|
|
32
|
+
...schema,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getComponentSlot(wrapperType) {
|
|
37
|
+
const props = DefinitionStore.getInstance().getComputedComponentContract(wrapperType);
|
|
38
|
+
const componentSlots = Object.entries(props)
|
|
39
|
+
.filter(([, prop]) => prop.valueType.type === 'component')
|
|
40
|
+
.map(([key]) => key);
|
|
41
|
+
if (!componentSlots.length) {
|
|
42
|
+
throw new Error(`No component slot found for wrapper: "${wrapperType}"`);
|
|
43
|
+
}
|
|
44
|
+
if (componentSlots.length > 1) {
|
|
45
|
+
const defaultSlot = DefinitionStore.getInstance().getComponent(wrapperType)?.defaultSlot;
|
|
46
|
+
if (!defaultSlot) {
|
|
47
|
+
throw new Error(`Multiple component slots found for wrapper: "${wrapperType}". Please specify a default slot.`);
|
|
48
|
+
}
|
|
49
|
+
return defaultSlot;
|
|
50
|
+
}
|
|
51
|
+
return componentSlots[0];
|
|
52
|
+
}
|
|
53
|
+
export function extractWrappers(schema) {
|
|
54
|
+
const wrappers = [];
|
|
55
|
+
const shallow = { ...schema };
|
|
56
|
+
for (const key in shallow) {
|
|
57
|
+
if (key.startsWith(WrapperPrefix)) {
|
|
58
|
+
const wrapperType = key.slice(1);
|
|
59
|
+
const wrapperProps = shallow[key] || {};
|
|
60
|
+
if (!isObject(wrapperProps)) {
|
|
61
|
+
throw new Error(`Properties for wrapper "${wrapperType}" must be an object`);
|
|
62
|
+
}
|
|
63
|
+
wrappers.push([wrapperType, wrapperProps]);
|
|
64
|
+
delete shallow[key];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return [wrappers, shallow];
|
|
68
|
+
}
|
|
69
|
+
export function hasWrappers(schema) {
|
|
70
|
+
return Object.keys(schema).some((key) => key.startsWith(WrapperPrefix));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=unfold-flat-wrapper-notation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-flat-wrapper-notation.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/unfolding/unfold-flat-wrapper-notation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAA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IAAI,CAAC,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;YAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAwC;IAClE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import { DefinitionStore } from '@kaskad/definition';\n\nimport { ComponentRecipe, TemplateRecipe } from '../types/component-schema';\nimport { isObject } from '../util/is-object';\nimport { RawNode } from './to-full-notation';\n\ntype WrapperEntity = [string, Record<string, unknown>];\n\ntype ComposedSchema =\n | ComponentRecipe\n | RawNode\n | {\n computationType: string;\n [x: string]: unknown;\n };\n\nexport const WrapperPrefix = '+';\nexport const PathSymbol = '/';\n\nexport function unfoldFlatWrappers(wrappers: WrapperEntity[], schema: ComposedSchema, resultingNode: RawNode): RawNode {\n const composed = wrappers\n .reverse()\n .reduce<ComposedSchema>((composed, wrapper) => unfoldWrapper(wrapper, composed), schema);\n\n if ('computationType' in composed) {\n resultingNode._computation = composed;\n } else {\n resultingNode._value = composed;\n }\n\n return resultingNode;\n}\n\nfunction unfoldWrapper(wrapper: WrapperEntity, schema: ComposedSchema): ComposedSchema {\n const [componentType, props] = wrapper;\n\n if (componentType.includes(PathSymbol)) {\n return {\n computationType: 'template',\n path: componentType,\n ...props,\n slot: schema,\n };\n }\n\n const slot = getComponentSlot(componentType);\n\n return {\n componentType,\n ...props,\n [slot]: {\n ...schema,\n },\n };\n}\n\nfunction getComponentSlot(wrapperType: string): string {\n const props = DefinitionStore.getInstance().getComputedComponentContract(wrapperType);\n\n const componentSlots = Object.entries(props)\n .filter(([, prop]) => prop.valueType.type === 'component')\n .map(([key]) => key);\n\n if (!componentSlots.length) {\n throw new Error(`No component slot found for wrapper: \"${wrapperType}\"`);\n }\n\n if (componentSlots.length > 1) {\n const defaultSlot = DefinitionStore.getInstance().getComponent(wrapperType)?.defaultSlot;\n if (!defaultSlot) {\n throw new Error(`Multiple component slots found for wrapper: \"${wrapperType}\". Please specify a default slot.`);\n }\n return defaultSlot;\n }\n\n return componentSlots[0];\n}\n\nexport function extractWrappers(\n schema: ComponentRecipe | TemplateRecipe,\n): [WrapperEntity[], ComponentRecipe | TemplateRecipe] {\n const wrappers: WrapperEntity[] = [];\n\n const shallow = { ...schema };\n\n for (const key in shallow) {\n if (key.startsWith(WrapperPrefix)) {\n const wrapperType = key.slice(1);\n const wrapperProps = shallow[key] || {};\n\n if (!isObject(wrapperProps)) {\n throw new Error(`Properties for wrapper \"${wrapperType}\" must be an object`);\n }\n\n wrappers.push([wrapperType, wrapperProps]);\n delete shallow[key];\n }\n }\n\n return [wrappers, shallow];\n}\n\nexport function hasWrappers(schema: ComponentRecipe | TemplateRecipe): boolean {\n return Object.keys(schema).some((key) => key.startsWith(WrapperPrefix));\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isObject } from '../util/is-object';
|
|
2
|
+
import { unfoldComputationSchema } from './computation/unfold-computation-schema';
|
|
3
|
+
import { toFullNotation } from './to-full-notation';
|
|
4
|
+
import { unfoldValue } from './value/unfold-node-value';
|
|
5
|
+
export function unfoldNodeSchema(rawSchema, valueType, nodePath = []) {
|
|
6
|
+
if (isUnfoldedNodeSchema(rawSchema)) {
|
|
7
|
+
return rawSchema;
|
|
8
|
+
}
|
|
9
|
+
const node = {
|
|
10
|
+
valueType,
|
|
11
|
+
value: null,
|
|
12
|
+
computation: null,
|
|
13
|
+
binding: null,
|
|
14
|
+
[Symbol.for('type')]: 'NodeSchema',
|
|
15
|
+
};
|
|
16
|
+
const nodeSchema = toFullNotation(rawSchema, valueType);
|
|
17
|
+
if ('_binding' in nodeSchema) {
|
|
18
|
+
node.binding = nodeSchema['_binding'];
|
|
19
|
+
}
|
|
20
|
+
if ('_computation' in nodeSchema) {
|
|
21
|
+
node.computation = unfoldComputationSchema(nodeSchema._computation);
|
|
22
|
+
}
|
|
23
|
+
if ('_value' in nodeSchema) {
|
|
24
|
+
node.value = unfoldValue({
|
|
25
|
+
rawValue: nodeSchema._value,
|
|
26
|
+
valueType,
|
|
27
|
+
nodePath,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return node;
|
|
31
|
+
}
|
|
32
|
+
export function isUnfoldedNodeSchema(nodeSchema) {
|
|
33
|
+
return isObject(nodeSchema) && ['valueType', 'value', 'computation', 'binding'].every((key) => key in nodeSchema);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=unfold-node-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-node-schema.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/unfolding/unfold-node-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,UAAU,gBAAgB,CAAC,SAAkB,EAAE,SAAoB,EAAE,WAAqB,EAAE;IAChG,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,GAAmB;QAC3B,SAAS;QACT,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,YAAY;KACnC,CAAC;IAEF,MAAM,UAAU,GAAG,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAExD,IAAI,UAAU,IAAI,UAAU,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,UAAU,CAAkB,CAAC;IACzD,CAAC;IACD,IAAI,cAAc,IAAI,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,uBAAuB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,QAAQ,IAAI,UAAU,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;YACvB,QAAQ,EAAE,UAAU,CAAC,MAAM;YAC3B,SAAS;YACT,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAkB,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAmB;IACtD,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC;AACpH,CAAC","sourcesContent":["import { BindingSchema, NodePath, NodeSchema, NodeSchemaBase, ValueType } from '@kaskad/types';\n\nimport { isObject } from '../util/is-object';\nimport { unfoldComputationSchema } from './computation/unfold-computation-schema';\nimport { toFullNotation } from './to-full-notation';\nimport { unfoldValue } from './value/unfold-node-value';\n\nexport function unfoldNodeSchema(rawSchema: unknown, valueType: ValueType, nodePath: NodePath = []): NodeSchema {\n if (isUnfoldedNodeSchema(rawSchema)) {\n return rawSchema;\n }\n\n const node: NodeSchemaBase = {\n valueType,\n value: null,\n computation: null,\n binding: null,\n [Symbol.for('type')]: 'NodeSchema',\n };\n\n const nodeSchema = toFullNotation(rawSchema, valueType);\n\n if ('_binding' in nodeSchema) {\n node.binding = nodeSchema['_binding'] as BindingSchema;\n }\n if ('_computation' in nodeSchema) {\n node.computation = unfoldComputationSchema(nodeSchema._computation);\n }\n if ('_value' in nodeSchema) {\n node.value = unfoldValue({\n rawValue: nodeSchema._value,\n valueType,\n nodePath,\n });\n }\n\n return node as NodeSchema;\n}\n\nexport function isUnfoldedNodeSchema(nodeSchema: unknown): nodeSchema is NodeSchema {\n return isObject(nodeSchema) && ['valueType', 'value', 'computation', 'binding'].every((key) => key in nodeSchema);\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isObject } from '../util/is-object';
|
|
2
|
+
import { parsePropertyKeyShorthand } from './parse-property-key-shorthand';
|
|
3
|
+
import { toFullNotation } from './to-full-notation';
|
|
4
|
+
import { isUnfoldedNodeSchema, unfoldNodeSchema } from './unfold-node-schema';
|
|
5
|
+
export function unfoldProperty(keyEx, rawSchema) {
|
|
6
|
+
if (isUnfoldedNodeSchema(rawSchema)) {
|
|
7
|
+
return [keyEx, rawSchema];
|
|
8
|
+
}
|
|
9
|
+
if (keyEx.includes('@')) {
|
|
10
|
+
const [key, valueType] = parsePropertyKeyShorthand(keyEx);
|
|
11
|
+
const nodeSchema = unfoldNodeSchema(toFullNotation(rawSchema, valueType), valueType, [key]);
|
|
12
|
+
return [key, nodeSchema];
|
|
13
|
+
}
|
|
14
|
+
if (isObject(rawSchema) && '_valueType' in rawSchema) {
|
|
15
|
+
const valueType = rawSchema['_valueType']; // TODO: check if valueType is valid
|
|
16
|
+
const nodeSchema = unfoldNodeSchema(rawSchema, valueType, [keyEx]);
|
|
17
|
+
return [keyEx, nodeSchema];
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Cannot unfold node schema. Invalid schema notation ${JSON.stringify(rawSchema)} for key "${keyEx}"`);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=unfold-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-property.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/unfolding/unfold-property.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,SAAkB;IAC9D,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;QACpC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;QAC1D,MAAM,UAAU,GAAG,gBAAgB,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5F,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ,CAAC,SAAS,CAAC,IAAI,YAAY,IAAI,SAAS,EAAE,CAAC;QACrD,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAc,CAAC,CAAC,oCAAoC;QAC5F,MAAM,UAAU,GAAG,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QACnE,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,sDAAsD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,aAAa,KAAK,GAAG,CAAC,CAAC;AACxH,CAAC","sourcesContent":["import { NodeSchema, ValueType } from '@kaskad/types';\n\nimport { isObject } from '../util/is-object';\nimport { parsePropertyKeyShorthand } from './parse-property-key-shorthand';\nimport { toFullNotation } from './to-full-notation';\nimport { isUnfoldedNodeSchema, unfoldNodeSchema } from './unfold-node-schema';\n\nexport function unfoldProperty(keyEx: string, rawSchema: unknown): [string, NodeSchema] {\n if (isUnfoldedNodeSchema(rawSchema)) {\n return [keyEx, rawSchema];\n }\n if (keyEx.includes('@')) {\n const [key, valueType] = parsePropertyKeyShorthand(keyEx);\n const nodeSchema = unfoldNodeSchema(toFullNotation(rawSchema, valueType), valueType, [key]);\n return [key, nodeSchema];\n }\n\n if (isObject(rawSchema) && '_valueType' in rawSchema) {\n const valueType = rawSchema['_valueType'] as ValueType; // TODO: check if valueType is valid\n const nodeSchema = unfoldNodeSchema(rawSchema, valueType, [keyEx]);\n return [keyEx, nodeSchema];\n }\n\n throw new Error(`Cannot unfold node schema. Invalid schema notation ${JSON.stringify(rawSchema)} for key \"${keyEx}\"`);\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './unfold-boolean';
|
|
2
|
+
export * from './unfold-number';
|
|
3
|
+
export * from './unfold-string';
|
|
4
|
+
export * from './unfold-unknown';
|
|
5
|
+
export * from './unfold-array';
|
|
6
|
+
export * from './unfold-map';
|
|
7
|
+
export * from './unfold-object';
|
|
8
|
+
export * from './unfold-command';
|
|
9
|
+
export * from './unfold-component-schema';
|
|
10
|
+
export * from './unfold-component';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './unfold-boolean';\nexport * from './unfold-number';\nexport * from './unfold-string';\nexport * from './unfold-unknown';\nexport * from './unfold-array';\nexport * from './unfold-map';\nexport * from './unfold-object';\nexport * from './unfold-command';\nexport * from './unfold-component-schema';\nexport * from './unfold-component';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { unfoldNodeSchema } from '../../unfold-node-schema';
|
|
2
|
+
import { throwUnfoldError } from '../throw-unfold-value-error';
|
|
3
|
+
export function unfoldArray(ctx) {
|
|
4
|
+
if (!Array.isArray(ctx.rawValue)) {
|
|
5
|
+
throwUnfoldError(ctx);
|
|
6
|
+
}
|
|
7
|
+
return ctx.rawValue.map((item, index) => unfoldNodeSchema(item, ctx.valueType.item, [...ctx.nodePath, index]));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=unfold-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-array.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-array.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,UAAU,WAAW,CAAC,GAA8B;IACxD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACjH,CAAC","sourcesContent":["import { ArrayValueType } from '@kaskad/types';\n\nimport { unfoldNodeSchema } from '../../unfold-node-schema';\nimport { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldArray(ctx: UnfoldCtx<ArrayValueType>) {\n if (!Array.isArray(ctx.rawValue)) {\n throwUnfoldError(ctx);\n }\n\n return ctx.rawValue.map((item, index) => unfoldNodeSchema(item, ctx.valueType.item, [...ctx.nodePath, index]));\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-boolean.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAc,EAAE,EAAE;IAC9C,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACtC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC;AACtB,CAAC,CAAC","sourcesContent":["import { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport const unfoldBoolean = (ctx: UnfoldCtx) => {\n if (typeof ctx.rawValue !== 'boolean') {\n throwUnfoldError(ctx);\n }\n return ctx.rawValue;\n};\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isObject } from '../../../util/is-object';
|
|
2
|
+
import { throwUnfoldError } from '../throw-unfold-value-error';
|
|
3
|
+
export function unfoldCommand(ctx) {
|
|
4
|
+
const rawValue = ctx.rawValue;
|
|
5
|
+
if (typeof rawValue === 'string') {
|
|
6
|
+
return { runnerType: 'js', target: rawValue, owner: null };
|
|
7
|
+
}
|
|
8
|
+
if (isObject(rawValue) && 'runnerType' in rawValue && 'target' in rawValue) {
|
|
9
|
+
if (typeof rawValue['runnerType'] !== 'string') {
|
|
10
|
+
throw new Error(`Command schema is invalid. Field "runnerType" must be string.`);
|
|
11
|
+
}
|
|
12
|
+
if (!rawValue['target']) {
|
|
13
|
+
throw new Error(`Command schema is invalid. Field "target" must be defined.`);
|
|
14
|
+
}
|
|
15
|
+
return rawValue;
|
|
16
|
+
}
|
|
17
|
+
if (typeof rawValue === 'function') {
|
|
18
|
+
return { runnerType: 'inline', target: rawValue, owner: null };
|
|
19
|
+
}
|
|
20
|
+
throwUnfoldError(ctx);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=unfold-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-command.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,UAAU,aAAa,CAAC,GAAgC;IAC5D,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAE9B,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC7D,CAAC;IAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,YAAY,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAAC;QAC3E,IAAI,OAAO,QAAQ,CAAC,YAAY,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;QACnF,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,CAAC;QACD,OAAO,QAAwB,CAAC;IAClC,CAAC;IAED,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC1E,CAAC;IAED,gBAAgB,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC","sourcesContent":["import { AnyFn, CommandValue, CommandValueType } from '@kaskad/types';\n\nimport { isObject } from '../../../util/is-object';\nimport { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldCommand(ctx: UnfoldCtx<CommandValueType>): CommandValue {\n const rawValue = ctx.rawValue;\n\n if (typeof rawValue === 'string') {\n return { runnerType: 'js', target: rawValue, owner: null };\n }\n\n if (isObject(rawValue) && 'runnerType' in rawValue && 'target' in rawValue) {\n if (typeof rawValue['runnerType'] !== 'string') {\n throw new Error(`Command schema is invalid. Field \"runnerType\" must be string.`);\n }\n if (!rawValue['target']) {\n throw new Error(`Command schema is invalid. Field \"target\" must be defined.`);\n }\n return rawValue as CommandValue;\n }\n\n if (typeof rawValue === 'function') {\n return { runnerType: 'inline', target: rawValue as AnyFn, owner: null };\n }\n\n throwUnfoldError(ctx);\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isObject } from '../../../util/is-object';
|
|
2
|
+
import { validateProps } from './validate-props';
|
|
3
|
+
export function unfoldComponentSchema(ctx) {
|
|
4
|
+
if (!isObject(ctx.rawValue)) {
|
|
5
|
+
throw new Error('Unfolded component schema type');
|
|
6
|
+
}
|
|
7
|
+
const componentRawSchema = ctx.rawValue;
|
|
8
|
+
if (!componentRawSchema.componentType) {
|
|
9
|
+
componentRawSchema.componentType = 'browser.Element';
|
|
10
|
+
}
|
|
11
|
+
validateProps(componentRawSchema);
|
|
12
|
+
return componentRawSchema;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=unfold-component-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-component-schema.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-component-schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,UAAU,qBAAqB,CAAC,GAAwC;IAC5E,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,kBAAkB,GAAG,GAAG,CAAC,QAA2B,CAAC;IAE3D,IAAI,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC;QACtC,kBAAkB,CAAC,aAAa,GAAG,iBAAiB,CAAC;IACvD,CAAC;IAED,aAAa,CAAC,kBAAkB,CAAC,CAAC;IAElC,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["import { ComponentSchemaValueType } from '@kaskad/types';\n\nimport { ComponentRecipe } from '../../../types/component-schema';\nimport { isObject } from '../../../util/is-object';\nimport { UnfoldCtx } from '../unfold-node-value';\nimport { validateProps } from './validate-props';\n\nexport function unfoldComponentSchema(ctx: UnfoldCtx<ComponentSchemaValueType>) {\n if (!isObject(ctx.rawValue)) {\n throw new Error('Unfolded component schema type');\n }\n const componentRawSchema = ctx.rawValue as ComponentRecipe;\n\n if (!componentRawSchema.componentType) {\n componentRawSchema.componentType = 'browser.Element';\n }\n\n validateProps(componentRawSchema);\n\n return componentRawSchema;\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Delimiters } from '@kaskad/config';
|
|
2
|
+
import { DefinitionStore } from '@kaskad/definition';
|
|
3
|
+
import { isObject } from '../../../util/is-object';
|
|
4
|
+
import { unfoldNodeSchema } from '../../unfold-node-schema';
|
|
5
|
+
import { unfoldProperty } from '../../unfold-property';
|
|
6
|
+
import { throwUnfoldError } from '../throw-unfold-value-error';
|
|
7
|
+
import { validateProps } from './validate-props';
|
|
8
|
+
export function unfoldComponent(ctx) {
|
|
9
|
+
if (typeof ctx.rawValue === 'string' && ctx.rawValue.startsWith('csid-')) {
|
|
10
|
+
return ctx.rawValue;
|
|
11
|
+
}
|
|
12
|
+
if (!isObject(ctx.rawValue)) {
|
|
13
|
+
throwUnfoldError(ctx);
|
|
14
|
+
}
|
|
15
|
+
const componentRawSchema = ctx.rawValue;
|
|
16
|
+
if (!componentRawSchema.componentType) {
|
|
17
|
+
componentRawSchema.componentType = 'browser.Element';
|
|
18
|
+
}
|
|
19
|
+
validateProps(componentRawSchema);
|
|
20
|
+
const properties = DefinitionStore.getInstance().getComputedComponentContract(componentRawSchema.componentType);
|
|
21
|
+
const props = new Map();
|
|
22
|
+
for (const [key, baseSchema] of Object.entries(properties)) {
|
|
23
|
+
if (!(key in componentRawSchema)) {
|
|
24
|
+
props.set(key, baseSchema);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const unfoldedRawSchema = unfoldNodeSchema(componentRawSchema[key], baseSchema.valueType, [...ctx.nodePath, key]);
|
|
28
|
+
const node = {
|
|
29
|
+
valueType: baseSchema.valueType,
|
|
30
|
+
value: unfoldedRawSchema.value ?? baseSchema.value,
|
|
31
|
+
computation: unfoldedRawSchema.computation || baseSchema.computation,
|
|
32
|
+
binding: unfoldedRawSchema.binding || baseSchema.binding,
|
|
33
|
+
};
|
|
34
|
+
props.set(key, node);
|
|
35
|
+
}
|
|
36
|
+
const variables = new Map();
|
|
37
|
+
for (const [keyEx, schema] of Object.entries(componentRawSchema)) {
|
|
38
|
+
if (!keyEx.startsWith(Delimiters.Variable)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const variableKeyEx = keyEx.slice(Delimiters.Variable.length);
|
|
42
|
+
const [key, unfolded] = unfoldProperty(variableKeyEx, schema);
|
|
43
|
+
variables.set(key, unfolded);
|
|
44
|
+
}
|
|
45
|
+
const rawHandlers = componentRawSchema.onNodeChange || [];
|
|
46
|
+
const onNodeChange = rawHandlers.map((handler) => {
|
|
47
|
+
if (!handler.selector) {
|
|
48
|
+
throw new Error(`onNodeChange handler "${JSON.stringify(handler)}" is missing required selector.`);
|
|
49
|
+
}
|
|
50
|
+
if (!handler.command) {
|
|
51
|
+
throw new Error(`onNodeChange handler "${JSON.stringify(handler)}" is missing required command.`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
selector: handler.selector,
|
|
55
|
+
command: unfoldNodeSchema(handler.command, { type: 'command' }, ctx.nodePath),
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
componentType: componentRawSchema.componentType,
|
|
60
|
+
ref: componentRawSchema.ref || '',
|
|
61
|
+
props,
|
|
62
|
+
variables,
|
|
63
|
+
onNodeChange,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=unfold-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unfold-component.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,UAAU,eAAe,CAAC,GAAc;IAC5C,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzE,OAAO,G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;QAC/C,GAAG,EAAE,kBAAkB,CAAC,GAAG,IAAI,EAAE;QACjC,KAAK;QACL,SAAS;QACT,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import { Delimiters } from '@kaskad/config';\nimport { DefinitionStore } from '@kaskad/definition';\nimport { ComponentNodeValue, NodeChangeHandlerSchema, NodeSchema } from '@kaskad/types';\n\nimport { ComponentRecipe } from '../../../types/component-schema';\nimport { isObject } from '../../../util/is-object';\nimport { unfoldNodeSchema } from '../../unfold-node-schema';\nimport { unfoldProperty } from '../../unfold-property';\nimport { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\nimport { validateProps } from './validate-props';\n\nexport function unfoldComponent(ctx: UnfoldCtx): ComponentNodeValue {\n if (typeof ctx.rawValue === 'string' && ctx.rawValue.startsWith('csid-')) {\n return ctx.rawValue;\n }\n if (!isObject(ctx.rawValue)) {\n throwUnfoldError(ctx);\n }\n\n const componentRawSchema = ctx.rawValue as ComponentRecipe;\n\n if (!componentRawSchema.componentType) {\n componentRawSchema.componentType = 'browser.Element';\n }\n\n validateProps(componentRawSchema);\n\n const properties = DefinitionStore.getInstance().getComputedComponentContract(componentRawSchema.componentType);\n\n const props = new Map<string, NodeSchema>();\n for (const [key, baseSchema] of Object.entries(properties)) {\n if (!(key in componentRawSchema)) {\n props.set(key, baseSchema);\n continue;\n }\n\n const unfoldedRawSchema = unfoldNodeSchema(componentRawSchema[key], baseSchema.valueType, [...ctx.nodePath, key]);\n\n const node = {\n valueType: baseSchema.valueType,\n value: unfoldedRawSchema.value ?? baseSchema.value,\n computation: unfoldedRawSchema.computation || baseSchema.computation,\n binding: unfoldedRawSchema.binding || baseSchema.binding,\n } as NodeSchema;\n\n props.set(key, node);\n }\n\n const variables = new Map<string, NodeSchema>();\n for (const [keyEx, schema] of Object.entries(componentRawSchema)) {\n if (!keyEx.startsWith(Delimiters.Variable)) {\n continue;\n }\n\n const variableKeyEx = keyEx.slice(Delimiters.Variable.length);\n const [key, unfolded] = unfoldProperty(variableKeyEx, schema);\n variables.set(key, unfolded);\n }\n\n const rawHandlers = componentRawSchema.onNodeChange || [];\n const onNodeChange: NodeChangeHandlerSchema[] = rawHandlers.map((handler) => {\n if (!handler.selector) {\n throw new Error(`onNodeChange handler \"${JSON.stringify(handler)}\" is missing required selector.`);\n }\n if (!handler.command) {\n throw new Error(`onNodeChange handler \"${JSON.stringify(handler)}\" is missing required command.`);\n }\n\n return {\n selector: handler.selector,\n command: unfoldNodeSchema(handler.command, { type: 'command' }, ctx.nodePath),\n };\n });\n\n return {\n componentType: componentRawSchema.componentType,\n ref: componentRawSchema.ref || '',\n props,\n variables,\n onNodeChange,\n };\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isObject } from '../../../util/is-object';
|
|
2
|
+
import { unfoldNodeSchema } from '../../unfold-node-schema';
|
|
3
|
+
import { throwUnfoldError } from '../throw-unfold-value-error';
|
|
4
|
+
export function unfoldMap(ctx) {
|
|
5
|
+
if (!isObject(ctx.rawValue)) {
|
|
6
|
+
throwUnfoldError(ctx);
|
|
7
|
+
}
|
|
8
|
+
return Object.entries(ctx.rawValue).reduce((structure, [key, child]) => {
|
|
9
|
+
structure[key] = unfoldNodeSchema(child, ctx.valueType.item, [...ctx.nodePath, key]);
|
|
10
|
+
return structure;
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=unfold-map.js.map
|