@kaskad/schema 0.0.1 → 0.0.2
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/fesm2022/kaskad-schema.mjs +1368 -0
- package/fesm2022/kaskad-schema.mjs.map +1 -0
- package/package.json +9 -9
- package/types/kaskad-schema.d.ts +125 -0
- package/esm2022/index.js +0 -17
- package/esm2022/index.js.map +0 -1
- package/esm2022/kaskad-schema.js +0 -5
- package/esm2022/kaskad-schema.js.map +0 -1
- package/esm2022/lib/load/load-schema.js +0 -16
- package/esm2022/lib/load/load-schema.js.map +0 -1
- package/esm2022/lib/load/load-templates.js +0 -136
- package/esm2022/lib/load/load-templates.js.map +0 -1
- package/esm2022/lib/load/register-declared-type.js +0 -28
- package/esm2022/lib/load/register-declared-type.js.map +0 -1
- package/esm2022/lib/load/schema-component-extractor.js +0 -101
- package/esm2022/lib/load/schema-component-extractor.js.map +0 -1
- package/esm2022/lib/load/template-registry.js +0 -51
- package/esm2022/lib/load/template-registry.js.map +0 -1
- package/esm2022/lib/types/component-definition.js +0 -1
- package/esm2022/lib/types/component-definition.js.map +0 -1
- package/esm2022/lib/types/component-schema.js +0 -1
- package/esm2022/lib/types/component-schema.js.map +0 -1
- package/esm2022/lib/types/raw-schemas.js +0 -3
- package/esm2022/lib/types/raw-schemas.js.map +0 -1
- package/esm2022/lib/types/template-raw-definition.js +0 -1
- package/esm2022/lib/types/template-raw-definition.js.map +0 -1
- package/esm2022/lib/unfolding/computation/unfold-computation-schema.js +0 -70
- package/esm2022/lib/unfolding/computation/unfold-computation-schema.js.map +0 -1
- package/esm2022/lib/unfolding/computation/unfold-for-new-syntax.js +0 -147
- package/esm2022/lib/unfolding/computation/unfold-for-new-syntax.js.map +0 -1
- package/esm2022/lib/unfolding/computation/unfold-for.js +0 -45
- package/esm2022/lib/unfolding/computation/unfold-for.js.map +0 -1
- package/esm2022/lib/unfolding/computation/unfold-if.js +0 -18
- package/esm2022/lib/unfolding/computation/unfold-if.js.map +0 -1
- package/esm2022/lib/unfolding/computation/unfold-import.js +0 -26
- package/esm2022/lib/unfolding/computation/unfold-import.js.map +0 -1
- package/esm2022/lib/unfolding/computation/unfold-interpolation.js +0 -44
- package/esm2022/lib/unfolding/computation/unfold-interpolation.js.map +0 -1
- package/esm2022/lib/unfolding/parse-binding-shorthand.js +0 -40
- package/esm2022/lib/unfolding/parse-binding-shorthand.js.map +0 -1
- package/esm2022/lib/unfolding/parse-property-key-shorthand.js +0 -9
- package/esm2022/lib/unfolding/parse-property-key-shorthand.js.map +0 -1
- package/esm2022/lib/unfolding/parse-value-type.js +0 -115
- package/esm2022/lib/unfolding/parse-value-type.js.map +0 -1
- package/esm2022/lib/unfolding/to-full-notation.js +0 -124
- package/esm2022/lib/unfolding/to-full-notation.js.map +0 -1
- package/esm2022/lib/unfolding/unfold-flat-wrapper-notation.js +0 -72
- package/esm2022/lib/unfolding/unfold-flat-wrapper-notation.js.map +0 -1
- package/esm2022/lib/unfolding/unfold-node-schema.js +0 -35
- package/esm2022/lib/unfolding/unfold-node-schema.js.map +0 -1
- package/esm2022/lib/unfolding/unfold-property.js +0 -21
- package/esm2022/lib/unfolding/unfold-property.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/index.js +0 -11
- package/esm2022/lib/unfolding/value/handlers/index.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-array.js +0 -9
- package/esm2022/lib/unfolding/value/handlers/unfold-array.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-boolean.js +0 -8
- package/esm2022/lib/unfolding/value/handlers/unfold-boolean.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-command.js +0 -22
- package/esm2022/lib/unfolding/value/handlers/unfold-command.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-component-schema.js +0 -14
- package/esm2022/lib/unfolding/value/handlers/unfold-component-schema.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-component.js +0 -66
- package/esm2022/lib/unfolding/value/handlers/unfold-component.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-map.js +0 -13
- package/esm2022/lib/unfolding/value/handlers/unfold-map.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-number.js +0 -11
- package/esm2022/lib/unfolding/value/handlers/unfold-number.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-object.js +0 -15
- package/esm2022/lib/unfolding/value/handlers/unfold-object.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-set.js +0 -6
- package/esm2022/lib/unfolding/value/handlers/unfold-set.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-shape.js +0 -13
- package/esm2022/lib/unfolding/value/handlers/unfold-shape.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-string.js +0 -8
- package/esm2022/lib/unfolding/value/handlers/unfold-string.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-unknown.js +0 -4
- package/esm2022/lib/unfolding/value/handlers/unfold-unknown.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/unfold-variant-shape.js +0 -61
- package/esm2022/lib/unfolding/value/handlers/unfold-variant-shape.js.map +0 -1
- package/esm2022/lib/unfolding/value/handlers/validate-props.js +0 -20
- package/esm2022/lib/unfolding/value/handlers/validate-props.js.map +0 -1
- package/esm2022/lib/unfolding/value/throw-unfold-value-error.js +0 -11
- package/esm2022/lib/unfolding/value/throw-unfold-value-error.js.map +0 -1
- package/esm2022/lib/unfolding/value/unfold-node-value.js +0 -30
- package/esm2022/lib/unfolding/value/unfold-node-value.js.map +0 -1
- package/esm2022/lib/util/is-object.js +0 -4
- package/esm2022/lib/util/is-object.js.map +0 -1
- package/esm2022/lib/util/stringify-object.js +0 -4
- package/esm2022/lib/util/stringify-object.js.map +0 -1
- package/esm2022/lib/util/unfold-component-definitions.js +0 -21
- package/esm2022/lib/util/unfold-component-definitions.js.map +0 -1
- package/index.d.ts +0 -16
- package/kaskad-schema.d.ts +0 -5
- package/lib/load/load-schema.d.ts +0 -3
- package/lib/load/load-templates.d.ts +0 -2
- package/lib/load/register-declared-type.d.ts +0 -1
- package/lib/load/schema-component-extractor.d.ts +0 -2
- package/lib/load/template-registry.d.ts +0 -16
- package/lib/types/component-definition.d.ts +0 -5
- package/lib/types/component-schema.d.ts +0 -26
- package/lib/types/raw-schemas.d.ts +0 -25
- package/lib/types/template-raw-definition.d.ts +0 -7
- package/lib/unfolding/computation/unfold-computation-schema.d.ts +0 -2
- package/lib/unfolding/computation/unfold-for-new-syntax.d.ts +0 -6
- package/lib/unfolding/computation/unfold-for.d.ts +0 -2
- package/lib/unfolding/computation/unfold-if.d.ts +0 -3
- package/lib/unfolding/computation/unfold-import.d.ts +0 -2
- package/lib/unfolding/computation/unfold-interpolation.d.ts +0 -3
- package/lib/unfolding/parse-binding-shorthand.d.ts +0 -3
- package/lib/unfolding/parse-property-key-shorthand.d.ts +0 -2
- package/lib/unfolding/parse-value-type.d.ts +0 -2
- package/lib/unfolding/to-full-notation.d.ts +0 -8
- package/lib/unfolding/unfold-flat-wrapper-notation.d.ts +0 -13
- package/lib/unfolding/unfold-node-schema.d.ts +0 -3
- package/lib/unfolding/unfold-property.d.ts +0 -2
- package/lib/unfolding/value/handlers/index.d.ts +0 -10
- package/lib/unfolding/value/handlers/unfold-array.d.ts +0 -3
- package/lib/unfolding/value/handlers/unfold-boolean.d.ts +0 -2
- package/lib/unfolding/value/handlers/unfold-command.d.ts +0 -3
- package/lib/unfolding/value/handlers/unfold-component-schema.d.ts +0 -4
- package/lib/unfolding/value/handlers/unfold-component.d.ts +0 -3
- package/lib/unfolding/value/handlers/unfold-map.d.ts +0 -3
- package/lib/unfolding/value/handlers/unfold-number.d.ts +0 -2
- package/lib/unfolding/value/handlers/unfold-object.d.ts +0 -3
- package/lib/unfolding/value/handlers/unfold-set.d.ts +0 -3
- package/lib/unfolding/value/handlers/unfold-shape.d.ts +0 -3
- package/lib/unfolding/value/handlers/unfold-string.d.ts +0 -2
- package/lib/unfolding/value/handlers/unfold-unknown.d.ts +0 -2
- package/lib/unfolding/value/handlers/unfold-variant-shape.d.ts +0 -3
- package/lib/unfolding/value/handlers/validate-props.d.ts +0 -2
- package/lib/unfolding/value/throw-unfold-value-error.d.ts +0 -2
- package/lib/unfolding/value/unfold-node-value.d.ts +0 -8
- package/lib/util/is-object.d.ts +0 -1
- package/lib/util/stringify-object.d.ts +0 -1
- package/lib/util/unfold-component-definitions.d.ts +0 -4
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-templates.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/load/load-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAIrC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAElF,SAAS,kBAAkB,CAAC,QAAiC;IAC3D,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,KAAK,CAA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AI,GAAG,KAAK,aAAa,EAAE,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,uCAAuC,OAAO,GAAG,EAAE,CAAC,CAAC;YACvE,CAAC;YACD,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;gBACtB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;oBAC5B,MAAM,IAAI,KAAK,CAAC,8CAA8C,OAAO,GAAG,EAAE,CAAC,CAAC;gBAC9E,CAAC;gBACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;YACD,SAAS;QACX,CAAC;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACvB,SAAS;QACX,CAAC;QAED,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC;QAED,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { log } from '@kaskad/config';\n\nimport { ComponentRecipe, TemplateRecipe } from '../types/component-schema';\nimport { TemplateRecipeDefinition } from '../types/template-raw-definition';\nimport { PathSymbol, WrapperPrefix } from '../unfolding/unfold-flat-wrapper-notation';\nimport { unfoldNodeSchema } from '../unfolding/unfold-node-schema';\nimport { isObject } from '../util/is-object';\nimport { loadRecipe } from './load-schema';\nimport { registerDeclaredType } from './register-declared-type';\nimport { extractComponentTypes } from './schema-component-extractor';\nimport { templateRegistry } from './template-registry';\n\nconst reservedKeys = new Set(['importTypes', 'types', 'contract', 'defaultSlot']);\n\nfunction isTypeOnlyTemplate(template: Record<string, unknown>): boolean {\n const contentKeys = Object.keys(template).filter((k) => !reservedKeys.has(k));\n return contentKeys.length > 0 && contentKeys.every((k) => k.includes('.'));\n}\n\nexport async function loadTemplates(recipe: TemplateRecipe | ComponentRecipe) {\n // Pass 1: Recursively load all templates and register types immediately\n const allTemplates = new Map<string, TemplateRecipeDefinition>();\n await collectAllTemplates(recipe, allTemplates);\n\n // Register types from the root recipe (after all dependencies are loaded)\n const rootTypes = (recipe as TemplateRecipeDefinition).types;\n if (rootTypes) {\n for (const [key, value] of Object.entries(rootTypes)) {\n if (typeof value === 'string' || isObject(value)) {\n registerDeclaredType(key, value as string | Record<string, string>);\n }\n }\n }\n\n // Pass 2: Unfold and register all templates (types are already registered)\n for (const [url, template] of allTemplates) {\n try {\n const {\n types: _types,\n importTypes: _importTypes,\n contract: _contract,\n defaultSlot: _defaultSlot,\n ...rootRawSchema\n } = template;\n\n // Skip unfolding for type-only templates (all keys are namespaced)\n if (isTypeOnlyTemplate(template)) {\n templateRegistry.set(url, template, new Set(), extractUrls(template));\n continue;\n }\n\n const schema = unfoldNodeSchema(rootRawSchema, { type: 'component' });\n const componentTypes = extractComponentTypes(schema);\n const dependencies = extractUrls(template);\n templateRegistry.set(url, template, componentTypes, dependencies);\n } catch (e) {\n log.error(`Failed to resolve template: ${url}`, e);\n throw new Error(`Failed to resolve template: ${url}`, { cause: e });\n }\n }\n}\n\nasync function collectAllTemplates(\n recipe: TemplateRecipe | ComponentRecipe,\n collected: Map<string, TemplateRecipeDefinition>,\n): Promise<void> {\n const urls = extractUrls(recipe);\n const newUrls = Array.from(urls).filter((url) => !templateRegistry.has(url) && !collected.has(url));\n\n if (newUrls.length === 0) return;\n\n const templates = await Promise.all(newUrls.map((url) => loadRecipe(url)));\n\n // Register types immediately after loading (before recursive collection)\n const pending = new Map<string, string | Record<string, string>>();\n\n for (const template of templates) {\n const isTypeOnlyFile = isTypeOnlyTemplate(template);\n const typesToRegister = isTypeOnlyFile ? template : (template.types ?? {});\n\n for (const [key, value] of Object.entries(typesToRegister)) {\n if (key === 'importTypes') continue;\n\n if (isTypeOnlyFile && !key.includes('.')) {\n throw new Error(`Invalid key \"${key}\" in type-only file. Type names must be namespaced (e.g., \"app.MyType\")`);\n }\n\n if (typeof value !== 'string' && !isObject(value)) {\n throw new Error(`Invalid type definition for \"${key}\". Expected string or object, got ${typeof value}`);\n }\n\n pending.set(key, value as string | Record<string, string>);\n }\n }\n\n // Register with retries to handle forward references between types\n let lastSize = -1;\n while (pending.size > 0 && pending.size !== lastSize) {\n lastSize = pending.size;\n for (const [key, value] of pending) {\n try {\n registerDeclaredType(key, value);\n pending.delete(key);\n } catch {\n // Will retry after other types are registered\n }\n }\n }\n\n for (const [key, value] of pending) {\n try {\n registerDeclaredType(key, value);\n } catch (e) {\n throw new Error(`Failed to register type \"${key}\"`, { cause: e });\n }\n }\n\n for (let i = 0; i < newUrls.length; i++) {\n collected.set(newUrls[i], templates[i]);\n }\n\n // Recursively collect from loaded templates\n await Promise.all(templates.map((t) => collectAllTemplates(t, collected)));\n}\n\nfunction extractUrls(value: unknown, urls: Set<string> = new Set()): Set<string> {\n if (value == null) return urls;\n\n if (Array.isArray(value)) {\n value.forEach((item) => extractUrls(item, urls));\n return urls;\n }\n\n if (!isObject(value)) return urls;\n\n if ('_defer' in value) return urls;\n\n for (const [key, val] of Object.entries(value)) {\n if (key.startsWith(WrapperPrefix) && key.includes(PathSymbol)) {\n urls.add(key.slice(1));\n }\n\n if (key === 'importTypes') {\n if (!Array.isArray(val)) {\n throw new Error(`\"importTypes\" must be an array, got ${typeof val}`);\n }\n for (const url of val) {\n if (typeof url !== 'string') {\n throw new Error(`\"importTypes\" entries must be strings, got ${typeof url}`);\n }\n urls.add(url);\n }\n continue;\n }\n\n if (typeof val !== 'string') {\n extractUrls(val, urls);\n continue;\n }\n\n if (key === 'templateUrl') {\n urls.add(val);\n }\n\n extractUrls(val, urls);\n }\n\n return urls;\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DefinitionStore } from '@kaskad/definition';
|
|
2
|
-
import { parseValueType } from '../unfolding/parse-value-type';
|
|
3
|
-
export function registerDeclaredType(name, definition) {
|
|
4
|
-
let properties;
|
|
5
|
-
if (typeof definition === 'string') {
|
|
6
|
-
const parsed = parseValueType(definition);
|
|
7
|
-
if (parsed.type !== 'object') {
|
|
8
|
-
throw new Error(`Type "${name}" must be an object type, got "${parsed.type}"`);
|
|
9
|
-
}
|
|
10
|
-
properties = parsed.fields;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
properties = {};
|
|
14
|
-
for (const [propName, propType] of Object.entries(definition)) {
|
|
15
|
-
properties[propName] = parseValueType(propType);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const store = DefinitionStore.getInstance();
|
|
19
|
-
const existing = store.shapes[name];
|
|
20
|
-
if (existing && !isEqualType(existing.properties, properties)) {
|
|
21
|
-
throw new Error(`Type "${name}" is already defined with a different shape`);
|
|
22
|
-
}
|
|
23
|
-
store.setShape(name, properties);
|
|
24
|
-
}
|
|
25
|
-
function isEqualType(a, b) {
|
|
26
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=register-declared-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register-declared-type.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/load/register-declared-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,UAA2C;IAC5F,IAAI,UAAqC,CAAC;IAE1C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,kCAAkC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QACjF,CAAC;QACD,UAAU,GAAI,MAA0B,CAAC,MAAM,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,UAAU,GAAG,EAAE,CAAC;QAChB,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9D,UAAU,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEpC,IAAI,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,6CAA6C,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,CAA4B,EAAE,CAA4B;IAC7E,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { DefinitionStore } from '@kaskad/definition';\nimport { ObjectValueType, ValueType } from '@kaskad/types';\n\nimport { parseValueType } from '../unfolding/parse-value-type';\n\nexport function registerDeclaredType(name: string, definition: string | Record<string, string>): void {\n let properties: Record<string, ValueType>;\n\n if (typeof definition === 'string') {\n const parsed = parseValueType(definition);\n if (parsed.type !== 'object') {\n throw new Error(`Type \"${name}\" must be an object type, got \"${parsed.type}\"`);\n }\n properties = (parsed as ObjectValueType).fields;\n } else {\n properties = {};\n for (const [propName, propType] of Object.entries(definition)) {\n properties[propName] = parseValueType(propType);\n }\n }\n\n const store = DefinitionStore.getInstance();\n const existing = store.shapes[name];\n\n if (existing && !isEqualType(existing.properties, properties)) {\n throw new Error(`Type \"${name}\" is already defined with a different shape`);\n }\n\n store.setShape(name, properties);\n}\n\nfunction isEqualType(a: Record<string, ValueType>, b: Record<string, ValueType>): boolean {\n return JSON.stringify(a) === JSON.stringify(b);\n}\n"]}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { isForComputation, isIfComputation, isSwitchComputation, isTemplateComputation, } from '@kaskad/types';
|
|
2
|
-
import { isObject } from '../util/is-object';
|
|
3
|
-
export function extractComponentTypes(schema, types = new Set()) {
|
|
4
|
-
extractFromValue(schema, types);
|
|
5
|
-
extractFromComputations(schema, types);
|
|
6
|
-
return types;
|
|
7
|
-
}
|
|
8
|
-
function extractFromValue(schema, types) {
|
|
9
|
-
if (!schema.value) {
|
|
10
|
-
return types;
|
|
11
|
-
}
|
|
12
|
-
const type = schema.valueType.type;
|
|
13
|
-
if (type === 'component') {
|
|
14
|
-
const componentSchema = schema;
|
|
15
|
-
if (!isObject(componentSchema.value)) {
|
|
16
|
-
return types;
|
|
17
|
-
}
|
|
18
|
-
types.add(componentSchema.value.componentType);
|
|
19
|
-
for (const prop of componentSchema.value.props.values()) {
|
|
20
|
-
extractComponentTypes(prop, types);
|
|
21
|
-
}
|
|
22
|
-
for (const variable of componentSchema.value.variables.values()) {
|
|
23
|
-
extractComponentTypes(variable, types);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (type === 'componentSchema' || type === 'unknown') {
|
|
27
|
-
const componentSchema = schema;
|
|
28
|
-
if (isObject(componentSchema.value) && 'componentType' in componentSchema.value) {
|
|
29
|
-
extractFromRawComponentSchema(componentSchema.value, types);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (type === 'array') {
|
|
33
|
-
const arraySchema = schema;
|
|
34
|
-
for (const item of arraySchema.value || []) {
|
|
35
|
-
extractComponentTypes(item, types);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (type === 'object' || type === 'map') {
|
|
39
|
-
const objectSchema = schema;
|
|
40
|
-
for (const prop of Object.values(objectSchema.value || {})) {
|
|
41
|
-
extractComponentTypes(prop, types);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return types;
|
|
45
|
-
}
|
|
46
|
-
function extractFromComputations(schema, types) {
|
|
47
|
-
if (!schema.computation) {
|
|
48
|
-
return types;
|
|
49
|
-
}
|
|
50
|
-
if (isSwitchComputation(schema.computation)) {
|
|
51
|
-
for (const caseItem of schema.computation.cases) {
|
|
52
|
-
extractComponentTypes(caseItem.then, types);
|
|
53
|
-
}
|
|
54
|
-
extractComponentTypes(schema.computation.default, types);
|
|
55
|
-
}
|
|
56
|
-
if (isIfComputation(schema.computation)) {
|
|
57
|
-
extractComponentTypes(schema.computation.then, types);
|
|
58
|
-
extractComponentTypes(schema.computation.else, types);
|
|
59
|
-
}
|
|
60
|
-
if (isForComputation(schema.computation)) {
|
|
61
|
-
extractComponentTypes(schema.computation.yield, types);
|
|
62
|
-
}
|
|
63
|
-
if (isTemplateComputation(schema.computation)) {
|
|
64
|
-
if (schema.computation.defer) {
|
|
65
|
-
if (schema.computation.defer.placeholder) {
|
|
66
|
-
extractComponentTypes(schema.computation.defer.placeholder, types);
|
|
67
|
-
}
|
|
68
|
-
if (schema.computation.defer.error) {
|
|
69
|
-
extractComponentTypes(schema.computation.defer.error, types);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
for (const variable of Object.values(schema.computation.contractVariables)) {
|
|
73
|
-
if (isObject(variable) || Array.isArray(variable)) {
|
|
74
|
-
extractFromRawComponentSchema(variable, types);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return types;
|
|
79
|
-
}
|
|
80
|
-
function extractFromRawComponentSchema(schema, types) {
|
|
81
|
-
if (Array.isArray(schema)) {
|
|
82
|
-
for (const item of schema) {
|
|
83
|
-
if (isObject(item) || Array.isArray(item)) {
|
|
84
|
-
extractFromRawComponentSchema(item, types);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return types;
|
|
88
|
-
}
|
|
89
|
-
if (isObject(schema)) {
|
|
90
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
91
|
-
if (key === 'componentType' && typeof value === 'string') {
|
|
92
|
-
types.add(value);
|
|
93
|
-
}
|
|
94
|
-
if (isObject(value) || Array.isArray(value)) {
|
|
95
|
-
extractFromRawComponentSchema(value, types);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return types;
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=schema-component-extractor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-component-extractor.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/load/schema-component-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,qBAAqB,GAGtB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,UAAU,qBAAqB,CAAC,MAAkB,EAAE,QAAqB,IAAI,GAAG,EAAE;IACtF,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChC,uBAAuB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAEvC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAkB,EAAE,KAAkB;IAC9D,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;IAEnC,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzB,MAAM,eAAe,GAAG,MAA6B,CAAC;QACtD,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,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ourcesContent":["import {\n ArrayNodeSchema,\n ComponentNodeSchema,\n ComponentSchemaNodeSchema,\n isForComputation,\n isIfComputation,\n isSwitchComputation,\n isTemplateComputation,\n NodeSchema,\n ObjectNodeSchema,\n} from '@kaskad/types';\n\nimport { isObject } from '../util/is-object';\n\nexport function extractComponentTypes(schema: NodeSchema, types: Set<string> = new Set()): Set<string> {\n extractFromValue(schema, types);\n extractFromComputations(schema, types);\n\n return types;\n}\n\nfunction extractFromValue(schema: NodeSchema, types: Set<string>) {\n if (!schema.value) {\n return types;\n }\n\n const type = schema.valueType.type;\n\n if (type === 'component') {\n const componentSchema = schema as ComponentNodeSchema;\n if (!isObject(componentSchema.value)) {\n return types;\n }\n\n types.add(componentSchema.value.componentType);\n\n for (const prop of componentSchema.value.props.values()) {\n extractComponentTypes(prop, types);\n }\n for (const variable of componentSchema.value.variables.values()) {\n extractComponentTypes(variable, types);\n }\n }\n\n if (type === 'componentSchema' || type === 'unknown') {\n const componentSchema = schema as ComponentSchemaNodeSchema;\n\n if (isObject(componentSchema.value) && 'componentType' in componentSchema.value) {\n extractFromRawComponentSchema(componentSchema.value, types);\n }\n }\n\n if (type === 'array') {\n const arraySchema = schema as ArrayNodeSchema;\n for (const item of arraySchema.value || []) {\n extractComponentTypes(item, types);\n }\n }\n\n if (type === 'object' || type === 'map') {\n const objectSchema = schema as ObjectNodeSchema;\n for (const prop of Object.values(objectSchema.value || {})) {\n extractComponentTypes(prop, types);\n }\n }\n\n return types;\n}\n\nfunction extractFromComputations(schema: NodeSchema, types: Set<string>) {\n if (!schema.computation) {\n return types;\n }\n\n if (isSwitchComputation(schema.computation)) {\n for (const caseItem of schema.computation.cases) {\n extractComponentTypes(caseItem.then, types);\n }\n extractComponentTypes(schema.computation.default, types);\n }\n\n if (isIfComputation(schema.computation)) {\n extractComponentTypes(schema.computation.then, types);\n extractComponentTypes(schema.computation.else, types);\n }\n\n if (isForComputation(schema.computation)) {\n extractComponentTypes(schema.computation.yield as NodeSchema, types);\n }\n\n if (isTemplateComputation(schema.computation)) {\n if (schema.computation.defer) {\n if (schema.computation.defer.placeholder) {\n extractComponentTypes(schema.computation.defer.placeholder, types);\n }\n if (schema.computation.defer.error) {\n extractComponentTypes(schema.computation.defer.error, types);\n }\n }\n\n for (const variable of Object.values(schema.computation.contractVariables)) {\n if (isObject(variable) || Array.isArray(variable)) {\n extractFromRawComponentSchema(variable, types);\n }\n }\n }\n\n return types;\n}\n\nfunction extractFromRawComponentSchema(schema: Record<string, unknown> | unknown[], types: Set<string>): Set<string> {\n if (Array.isArray(schema)) {\n for (const item of schema) {\n if (isObject(item) || Array.isArray(item)) {\n extractFromRawComponentSchema(item, types);\n }\n }\n return types;\n }\n\n if (isObject(schema)) {\n for (const [key, value] of Object.entries(schema)) {\n if (key === 'componentType' && typeof value === 'string') {\n types.add(value);\n }\n if (isObject(value) || Array.isArray(value)) {\n extractFromRawComponentSchema(value, types);\n }\n }\n }\n\n return types;\n}\n"]}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const templateRegistry = {
|
|
2
|
-
entries: new Map(),
|
|
3
|
-
get(url) {
|
|
4
|
-
return this.entries.get(url);
|
|
5
|
-
},
|
|
6
|
-
getAggregatedComponentTypes(url) {
|
|
7
|
-
const aggregated = new Set();
|
|
8
|
-
const visited = new Set();
|
|
9
|
-
const collect = (currentUrl) => {
|
|
10
|
-
if (visited.has(currentUrl))
|
|
11
|
-
return;
|
|
12
|
-
visited.add(currentUrl);
|
|
13
|
-
const entry = this.entries.get(currentUrl);
|
|
14
|
-
if (!entry)
|
|
15
|
-
return;
|
|
16
|
-
// Add own component types
|
|
17
|
-
for (const type of entry.ownComponentTypes) {
|
|
18
|
-
aggregated.add(type);
|
|
19
|
-
}
|
|
20
|
-
// Recursively collect from dependencies
|
|
21
|
-
for (const depUrl of entry.dependencies) {
|
|
22
|
-
collect(depUrl);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
collect(url);
|
|
26
|
-
return aggregated;
|
|
27
|
-
},
|
|
28
|
-
getAllComponentTypes() {
|
|
29
|
-
const allTypes = new Set();
|
|
30
|
-
for (const entry of this.entries.values()) {
|
|
31
|
-
for (const type of entry.ownComponentTypes) {
|
|
32
|
-
allTypes.add(type);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return allTypes;
|
|
36
|
-
},
|
|
37
|
-
set(url, recipe, ownComponentTypes, dependencies) {
|
|
38
|
-
this.entries.set(url, {
|
|
39
|
-
recipe,
|
|
40
|
-
ownComponentTypes,
|
|
41
|
-
dependencies: dependencies || new Set(),
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
has(url) {
|
|
45
|
-
return this.entries.has(url);
|
|
46
|
-
},
|
|
47
|
-
reset() {
|
|
48
|
-
this.entries.clear();
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
//# sourceMappingURL=template-registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template-registry.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/load/template-registry.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,IAAI,GAAG,EAAyB;IAEzC,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,2BAA2B,CAAC,GAAW;QACrC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;QACrC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;QAElC,MAAM,OAAO,GAAG,CAAC,UAAkB,EAAE,EAAE;YACrC,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;gBAAE,OAAO;YACpC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAExB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC3C,IAAI,CAAC,KAAK;gBAAE,OAAO;YAEnB,0BAA0B;YAC1B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;gBAC3C,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;YAED,wCAAwC;YACxC,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;gBACxC,OAAO,CAAC,MAAM,CAAC,CAAC;YAClB,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,oBAAoB;QAClB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;QAEnC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;gBAC3C,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,MAAgC,EAAE,iBAA8B,EAAE,YAA0B;QAC3G,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE;YACpB,MAAM;YACN,iBAAiB;YACjB,YAAY,EAAE,YAAY,IAAI,IAAI,GAAG,EAAE;SACxC,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF,CAAC","sourcesContent":["import { TemplateRecipeDefinition } from '../types/template-raw-definition';\n\ninterface TemplateEntry {\n recipe: TemplateRecipeDefinition;\n ownComponentTypes: Set<string>;\n dependencies: Set<string>;\n}\n\nexport const templateRegistry = {\n entries: new Map<string, TemplateEntry>(),\n\n get(url: string): TemplateEntry | undefined {\n return this.entries.get(url);\n },\n\n getAggregatedComponentTypes(url: string): Set<string> {\n const aggregated = new Set<string>();\n const visited = new Set<string>();\n\n const collect = (currentUrl: string) => {\n if (visited.has(currentUrl)) return;\n visited.add(currentUrl);\n\n const entry = this.entries.get(currentUrl);\n if (!entry) return;\n\n // Add own component types\n for (const type of entry.ownComponentTypes) {\n aggregated.add(type);\n }\n\n // Recursively collect from dependencies\n for (const depUrl of entry.dependencies) {\n collect(depUrl);\n }\n };\n\n collect(url);\n return aggregated;\n },\n\n getAllComponentTypes(): Set<string> {\n const allTypes = new Set<string>();\n\n for (const entry of this.entries.values()) {\n for (const type of entry.ownComponentTypes) {\n allTypes.add(type);\n }\n }\n\n return allTypes;\n },\n\n set(url: string, recipe: TemplateRecipeDefinition, ownComponentTypes: Set<string>, dependencies?: Set<string>) {\n this.entries.set(url, {\n recipe,\n ownComponentTypes,\n dependencies: dependencies || new Set(),\n });\n },\n\n has(url: string): boolean {\n return this.entries.has(url);\n },\n\n reset() {\n this.entries.clear();\n },\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=component-definition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component-definition.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/types/component-definition.ts"],"names":[],"mappings":"","sourcesContent":["export type ComponentRawDefinition = {\n readonly traits?: string[];\n readonly properties: Record<string, unknown>;\n readonly defaultSlot?: string;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=component-schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component-schema.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/types/component-schema.ts"],"names":[],"mappings":"","sourcesContent":["import { ComponentRef } from '@kaskad/types';\n\nexport type Defer = {\n placeholder?: { componentType: string } & { [key: string]: unknown };\n error?: { componentType: string } & { [key: string]: unknown };\n};\n\nexport interface NodeChangeHandlerRecipe {\n selector: string;\n command: unknown;\n}\n\nexport interface ComponentRecipe {\n ref?: ComponentRef;\n componentType: string;\n onNodeChange?: NodeChangeHandlerRecipe[];\n [propOrVariable: string]: unknown;\n}\n\nexport type TemplateRecipe = Omit<ComponentRecipe, 'componentType'> & {\n templateUrl: string;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"raw-schemas.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/types/raw-schemas.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,kEAAkE","sourcesContent":["// Recipe types used for unfolding\n// These types represent the raw input format before normalization\n\nexport type FormulaComputationRecipe = {\n formula: string;\n};\n\nexport type ForComputationRecipe = {\n items: unknown[];\n as?: {\n item: unknown;\n index: unknown;\n first?: unknown;\n last?: unknown;\n };\n yield: unknown;\n};\n\nexport type IfComputationRecipe = Record<'if' | 'then' | 'else', unknown> | ({ if: unknown } & Record<string, unknown>);\n\nexport type SwitchComputationRecipe = {\n computationType: 'switch';\n source: unknown;\n cases: { equals: unknown; then: unknown }[];\n default: unknown;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=template-raw-definition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template-raw-definition.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/types/template-raw-definition.ts"],"names":[],"mappings":"","sourcesContent":["import { ComponentRecipe } from './component-schema';\n\nexport interface TemplateRecipeDefinition extends ComponentRecipe {\n types?: Record<string, string | Record<string, string>>;\n importTypes?: string[];\n contract?: Record<string, string>;\n defaultSlot?: string;\n}\n"]}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { isObject } from '../../util/is-object';
|
|
2
|
-
import { stringifyObject } from '../../util/stringify-object';
|
|
3
|
-
import { unfoldNodeSchema } from '../unfold-node-schema';
|
|
4
|
-
import { unfoldForComputationSchema as unfoldFor } from './unfold-for';
|
|
5
|
-
import { unfoldForWithNewSyntax } from './unfold-for-new-syntax';
|
|
6
|
-
import { unfoldIfComputationSchema as unfoldIf } from './unfold-if';
|
|
7
|
-
import { unfoldImportComputationSchema as unfoldTemplate } from './unfold-import';
|
|
8
|
-
import { replaceInterpolationsInFormula, unfoldInterpolationComputationSchema } from './unfold-interpolation';
|
|
9
|
-
const unfoldFormula = (schema) => {
|
|
10
|
-
const result = {
|
|
11
|
-
computationType: 'formula',
|
|
12
|
-
formula: schema.formula,
|
|
13
|
-
[Symbol.for('type')]: 'ComputationSchema',
|
|
14
|
-
};
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
const unfoldSwitch = (schema) => {
|
|
18
|
-
return {
|
|
19
|
-
computationType: 'switch',
|
|
20
|
-
source: unfoldNodeSchema(schema.source, { type: 'unknown' }, []),
|
|
21
|
-
cases: schema.cases.map((c) => {
|
|
22
|
-
return {
|
|
23
|
-
equals: c.equals,
|
|
24
|
-
then: unfoldNodeSchema(c.then, { type: 'componentSchema' }),
|
|
25
|
-
};
|
|
26
|
-
}),
|
|
27
|
-
default: unfoldNodeSchema(schema.default, { type: 'componentSchema' }),
|
|
28
|
-
[Symbol.for('type')]: 'ComputationSchema',
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export function unfoldComputationSchema(schema) {
|
|
32
|
-
if (typeof schema === 'string') {
|
|
33
|
-
if (schema.startsWith('=> ')) {
|
|
34
|
-
let formula = schema.slice(3);
|
|
35
|
-
if (formula.includes('{{')) {
|
|
36
|
-
formula = replaceInterpolationsInFormula(formula);
|
|
37
|
-
}
|
|
38
|
-
return { computationType: 'formula', formula };
|
|
39
|
-
}
|
|
40
|
-
if (schema.includes('{{') && schema.includes('}}')) {
|
|
41
|
-
return unfoldInterpolationComputationSchema(schema);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Check for new for-loop syntax (before computationType check)
|
|
45
|
-
if (isObject(schema) && 'for' in schema && !('computationType' in schema)) {
|
|
46
|
-
return unfoldForWithNewSyntax(schema);
|
|
47
|
-
}
|
|
48
|
-
if (!isObject(schema) || !('computationType' in schema)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
if (isUnfoldedComputationSchema(schema)) {
|
|
52
|
-
return schema;
|
|
53
|
-
}
|
|
54
|
-
const computationUnfolders = {
|
|
55
|
-
formula: (schema) => unfoldFormula(schema),
|
|
56
|
-
for: (schema) => unfoldFor(schema),
|
|
57
|
-
template: (schema) => unfoldTemplate(schema),
|
|
58
|
-
if: (schema) => unfoldIf(schema),
|
|
59
|
-
switch: (schema) => unfoldSwitch(schema),
|
|
60
|
-
};
|
|
61
|
-
const unfolder = computationUnfolders[schema['computationType']];
|
|
62
|
-
if (unfolder) {
|
|
63
|
-
return unfolder(schema);
|
|
64
|
-
}
|
|
65
|
-
throw new Error(`Unable to unfold computation schema.\n${stringifyObject('Schema', schema)}`);
|
|
66
|
-
}
|
|
67
|
-
function isUnfoldedComputationSchema(schema) {
|
|
68
|
-
return isObject(schema) && Symbol.for('type') in schema;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=unfold-computation-schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unfold-computation-schema.js","sourceRoot":"","sources":["../../../../../../../libs/schema/src/lib/unfolding/computation/unfold-computation-schema.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,0BAA0B,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,yBAAyB,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpE,O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oB,CAAC,MAAM,CAAC,iBAAiB,CAAW,CAAC,CAAC;IAC3E,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,yCAAyC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;AAChG,CAAC;AAED,SAAS,2BAA2B,CAAC,MAAe;IAClD,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC;AAC1D,CAAC","sourcesContent":["import {\n ComponentSchemaNodeSchema,\n ComputationSchema,\n FormulaComputationSchema,\n SwitchComputationSchema,\n} from '@kaskad/types';\n\nimport { FormulaComputationRecipe, IfComputationRecipe, SwitchComputationRecipe } from '../../types/raw-schemas';\nimport { isObject } from '../../util/is-object';\nimport { stringifyObject } from '../../util/stringify-object';\nimport { unfoldNodeSchema } from '../unfold-node-schema';\nimport { unfoldForComputationSchema as unfoldFor } from './unfold-for';\nimport { unfoldForWithNewSyntax } from './unfold-for-new-syntax';\nimport { unfoldIfComputationSchema as unfoldIf } from './unfold-if';\nimport { unfoldImportComputationSchema as unfoldTemplate } from './unfold-import';\nimport { replaceInterpolationsInFormula, unfoldInterpolationComputationSchema } from './unfold-interpolation';\n\nconst unfoldFormula = (schema: FormulaComputationRecipe): ComputationSchema => {\n const result: FormulaComputationSchema = {\n computationType: 'formula',\n formula: schema.formula,\n [Symbol.for('type')]: 'ComputationSchema',\n };\n return result;\n};\n\nconst unfoldSwitch = (schema: SwitchComputationRecipe): SwitchComputationSchema => {\n return {\n computationType: 'switch',\n source: unfoldNodeSchema(schema.source, { type: 'unknown' }, []),\n cases: schema.cases.map((c) => {\n return {\n equals: c.equals,\n then: unfoldNodeSchema(c.then, { type: 'componentSchema' }) as ComponentSchemaNodeSchema,\n };\n }),\n default: unfoldNodeSchema(schema.default, { type: 'componentSchema' }) as ComponentSchemaNodeSchema,\n [Symbol.for('type')]: 'ComputationSchema',\n };\n};\n\nexport function unfoldComputationSchema(schema: unknown): ComputationSchema | null {\n if (typeof schema === 'string') {\n if (schema.startsWith('=> ')) {\n let formula = schema.slice(3);\n if (formula.includes('{{')) {\n formula = replaceInterpolationsInFormula(formula);\n }\n return { computationType: 'formula', formula } as FormulaComputationSchema;\n }\n\n if (schema.includes('{{') && schema.includes('}}')) {\n return unfoldInterpolationComputationSchema(schema);\n }\n }\n\n // Check for new for-loop syntax (before computationType check)\n if (isObject(schema) && 'for' in schema && !('computationType' in schema)) {\n return unfoldForWithNewSyntax(schema);\n }\n\n if (!isObject(schema) || !('computationType' in schema)) {\n return null;\n }\n\n if (isUnfoldedComputationSchema(schema)) {\n return schema;\n }\n\n const computationUnfolders: Record<string, (schema: unknown) => ComputationSchema | null> = {\n formula: (schema) => unfoldFormula(schema as FormulaComputationRecipe),\n for: (schema) => unfoldFor(schema),\n template: (schema) => unfoldTemplate(schema),\n if: (schema) => unfoldIf(schema as IfComputationRecipe),\n switch: (schema) => unfoldSwitch(schema as SwitchComputationRecipe),\n };\n\n const unfolder = computationUnfolders[schema['computationType'] as string];\n if (unfolder) {\n return unfolder(schema);\n }\n\n throw new Error(`Unable to unfold computation schema.\\n${stringifyObject('Schema', schema)}`);\n}\n\nfunction isUnfoldedComputationSchema(schema: unknown): schema is ComputationSchema {\n return isObject(schema) && Symbol.for('type') in schema;\n}\n"]}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { isObject } from '../../util/is-object';
|
|
2
|
-
import { parseValueType } from '../parse-value-type';
|
|
3
|
-
import { unfoldNodeSchema } from '../unfold-node-schema';
|
|
4
|
-
/**
|
|
5
|
-
* Parses metadata object from the `with` clause
|
|
6
|
-
* Example: "index: $i, first: $isFirst, last: $isLast"
|
|
7
|
-
*/
|
|
8
|
-
function parseMetadata(str) {
|
|
9
|
-
const result = {};
|
|
10
|
-
const trimmed = str.trim();
|
|
11
|
-
if (!trimmed) {
|
|
12
|
-
throw new Error('Empty metadata block. Omit "with" clause if no metadata is needed.');
|
|
13
|
-
}
|
|
14
|
-
const pairs = trimmed.split(',').map((s) => s.trim());
|
|
15
|
-
for (const pair of pairs) {
|
|
16
|
-
const colonIndex = pair.indexOf(':');
|
|
17
|
-
if (colonIndex === -1) {
|
|
18
|
-
throw new Error(`Invalid metadata pair: "${pair}". Expected format: "key: $value"`);
|
|
19
|
-
}
|
|
20
|
-
const key = pair.slice(0, colonIndex).trim();
|
|
21
|
-
const value = pair.slice(colonIndex + 1).trim();
|
|
22
|
-
if (!['index', 'first', 'last'].includes(key)) {
|
|
23
|
-
throw new Error(`Invalid metadata key: "${key}". Only "index", "first", and "last" are allowed.`);
|
|
24
|
-
}
|
|
25
|
-
if (!value || !value.startsWith('$')) {
|
|
26
|
-
throw new Error(`Invalid metadata value: "${value}". Must be a variable starting with $.`);
|
|
27
|
-
}
|
|
28
|
-
result[key] = value.slice(1); // Remove $
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Parses a single for-loop specification
|
|
34
|
-
* Example: "$row@Row of $rows with { index: $i, first: $isFirst } trackBy $row.id"
|
|
35
|
-
*/
|
|
36
|
-
function parseForSpec(spec) {
|
|
37
|
-
const trimmed = spec.trim();
|
|
38
|
-
// First, extract trackBy if present at the end
|
|
39
|
-
// trackBy uses $variable or $variable.property syntax (e.g., "$item" or "$item.id")
|
|
40
|
-
let trackBy = null;
|
|
41
|
-
let specWithoutTrackBy = trimmed;
|
|
42
|
-
const trackByMatch = trimmed.match(/\s+trackBy\s+(\$\w+(?:\.\w+)*)$/);
|
|
43
|
-
if (trackByMatch) {
|
|
44
|
-
const trackByValue = trackByMatch[1].trim();
|
|
45
|
-
specWithoutTrackBy = trimmed.slice(0, trackByMatch.index).trim();
|
|
46
|
-
// Parse the $variable.property syntax
|
|
47
|
-
const pathMatch = trackByValue.match(/^\$(\w+)((?:\.\w+)*)$/);
|
|
48
|
-
if (!pathMatch) {
|
|
49
|
-
throw new Error(`Invalid trackBy syntax: ${trackByValue}. Expected format: $variable or $variable.property`);
|
|
50
|
-
}
|
|
51
|
-
const variableName = pathMatch[1]; // e.g., "item"
|
|
52
|
-
const propertyPath = pathMatch[2]; // e.g., ".id" or ""
|
|
53
|
-
// We'll validate against itemName after parsing the main pattern
|
|
54
|
-
// Store both parts temporarily - validation happens after we know itemName
|
|
55
|
-
trackBy = `${variableName}${propertyPath}`;
|
|
56
|
-
}
|
|
57
|
-
// Pattern: $item@Type of $items with { metadata }
|
|
58
|
-
// ^^^^^ ^^^^ ^^^^^^ ^^^^^^^^^^^^^^^
|
|
59
|
-
// name type expr metadata (optional)
|
|
60
|
-
// Note: Type can include dots for namespaced types like "app.table.Row"
|
|
61
|
-
const pattern = /^\$(\w+)@([\w.[\]{}:,\s]+)\s+of\s+(.+?)(?:\s+with\s*\{([^}]+)})?$/;
|
|
62
|
-
const match = specWithoutTrackBy.match(pattern);
|
|
63
|
-
if (!match) {
|
|
64
|
-
throw new Error(`Invalid for-loop syntax: "${spec}". Expected format: "$item@Type of $items" or "$item@Type of $items with { index: $i }"`);
|
|
65
|
-
}
|
|
66
|
-
const [, itemName, typeStr, itemsExpr, metadataStr] = match;
|
|
67
|
-
// Validate and process trackBy
|
|
68
|
-
// null = no trackBy specified (use index)
|
|
69
|
-
// "" = trackBy $var (use item value directly for primitives)
|
|
70
|
-
// "id" or "user.id" = trackBy $var.property (use property path)
|
|
71
|
-
let processedTrackBy = null;
|
|
72
|
-
if (trackBy !== null) {
|
|
73
|
-
// trackBy is in format "variableName" or "variableName.property.path"
|
|
74
|
-
const parts = trackBy.split('.');
|
|
75
|
-
const variableName = parts[0];
|
|
76
|
-
// Validate that trackBy references the loop variable
|
|
77
|
-
if (variableName !== itemName) {
|
|
78
|
-
throw new Error(`trackBy must reference loop variable $${itemName}, got $${variableName}`);
|
|
79
|
-
}
|
|
80
|
-
// Extract the property path (everything after the variable name)
|
|
81
|
-
// If parts.length === 1, it's just the variable (primitive array) -> "" (use item value)
|
|
82
|
-
// If parts.length > 1, it's a property path -> "id" or "user.id"
|
|
83
|
-
processedTrackBy = parts.length > 1 ? parts.slice(1).join('.') : '';
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
itemName,
|
|
87
|
-
itemType: typeStr.trim(),
|
|
88
|
-
itemsExpr,
|
|
89
|
-
metadata: metadataStr ? parseMetadata(metadataStr) : {},
|
|
90
|
-
trackBy: processedTrackBy,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Unfolds the new for-loop syntax into a ForComputationSchema
|
|
95
|
-
* Supports: for: "$item@Type of $items" or for: ["$item1@Type1 of $items1", "$item2@Type2 of $items2"]
|
|
96
|
-
*/
|
|
97
|
-
export function unfoldForWithNewSyntax(schema) {
|
|
98
|
-
if (!isObject(schema) || !('for' in schema)) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
const forSpec = schema['for'];
|
|
102
|
-
const specs = Array.isArray(forSpec) ? forSpec : [forSpec];
|
|
103
|
-
if (specs.length === 0) {
|
|
104
|
-
throw new Error('For-loop requires at least one dimension');
|
|
105
|
-
}
|
|
106
|
-
const dimensions = specs.map((spec) => {
|
|
107
|
-
if (typeof spec !== 'string') {
|
|
108
|
-
throw new Error(`Invalid for-loop spec: ${JSON.stringify(spec)}. Must be a string.`);
|
|
109
|
-
}
|
|
110
|
-
const parsed = parseForSpec(spec);
|
|
111
|
-
// Parse the type annotation
|
|
112
|
-
// The type can be either:
|
|
113
|
-
// 1. An item type (e.g., "string") - we need to wrap in array
|
|
114
|
-
// 2. Already an array type (e.g., "string[]") - use as-is
|
|
115
|
-
const parsedType = parseValueType(parsed.itemType);
|
|
116
|
-
const itemsType = parsedType.type === 'array' ? parsedType : { type: 'array', item: parsedType };
|
|
117
|
-
return {
|
|
118
|
-
items: unfoldNodeSchema(parsed.itemsExpr, itemsType, []),
|
|
119
|
-
itemsType,
|
|
120
|
-
item: unfoldNodeSchema(parsed.itemName, { type: 'string' }, []),
|
|
121
|
-
index: unfoldNodeSchema(parsed.metadata.index || 'index', { type: 'string' }, []),
|
|
122
|
-
first: unfoldNodeSchema(parsed.metadata.first || null, { type: 'string' }, []),
|
|
123
|
-
last: unfoldNodeSchema(parsed.metadata.last || null, { type: 'string' }, []),
|
|
124
|
-
// trackBy: null = use index, property path (e.g., "id") = extract from item
|
|
125
|
-
trackBy: unfoldNodeSchema(parsed.trackBy, { type: 'string' }, []),
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
// Extract yield: either explicit 'yield' property or all other properties (inline yield)
|
|
129
|
-
let yieldSchema;
|
|
130
|
-
if ('yield' in schema) {
|
|
131
|
-
yieldSchema = schema['yield'];
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
// Inline yield: all properties except 'for'
|
|
135
|
-
const { for: _, ...rest } = schema;
|
|
136
|
-
yieldSchema = rest;
|
|
137
|
-
}
|
|
138
|
-
const normalizedYield = unfoldNodeSchema(yieldSchema, { type: 'componentSchema' }, []);
|
|
139
|
-
const result = {
|
|
140
|
-
computationType: 'for',
|
|
141
|
-
dimensions,
|
|
142
|
-
yield: normalizedYield,
|
|
143
|
-
[Symbol.for('type')]: 'ComputationSchema',
|
|
144
|
-
};
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
//# sourceMappingURL=unfold-for-new-syntax.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unfold-for-new-syntax.js","sourceRoot":"","sources":["../../../../../../../libs/schema/src/lib/unfolding/computation/unfold-for-new-syntax.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAczD;;;GAGG;AACH,SAAS,aAAa,CAAC,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AC9E,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YAC5E,4EAA4E;YAC5E,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;SAClE,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,yFAAyF;IACzF,IAAI,WAAoB,CAAC;IACzB,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACtB,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,4CAA4C;QAC5C,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAiC,CAAC;QAC9D,WAAW,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,MAAM,eAAe,GAAG,gBAAgB,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;IAEvF,MAAM,MAAM,GAAyB;QACnC,eAAe,EAAE,KAAK;QACtB,UAAU;QACV,KAAK,EAAE,eAAe;QACtB,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB;KAC1C,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ComputationSchema, ForComputationSchema } from '@kaskad/types';\n\nimport { isObject } from '../../util/is-object';\nimport { parseValueType } from '../parse-value-type';\nimport { unfoldNodeSchema } from '../unfold-node-schema';\n\ninterface ParsedForSpec {\n itemName: string;\n itemType: string;\n itemsExpr: unknown;\n metadata: {\n index?: string;\n first?: string;\n last?: string;\n };\n trackBy: string | null;\n}\n\n/**\n * Parses metadata object from the `with` clause\n * Example: \"index: $i, first: $isFirst, last: $isLast\"\n */\nfunction parseMetadata(str: string): { index?: string; first?: string; last?: string } {\n const result: { index?: string; first?: string; last?: string } = {};\n const trimmed = str.trim();\n\n if (!trimmed) {\n throw new Error('Empty metadata block. Omit \"with\" clause if no metadata is needed.');\n }\n\n const pairs = trimmed.split(',').map((s) => s.trim());\n\n for (const pair of pairs) {\n const colonIndex = pair.indexOf(':');\n if (colonIndex === -1) {\n throw new Error(`Invalid metadata pair: \"${pair}\". Expected format: \"key: $value\"`);\n }\n\n const key = pair.slice(0, colonIndex).trim();\n const value = pair.slice(colonIndex + 1).trim();\n\n if (!['index', 'first', 'last'].includes(key)) {\n throw new Error(`Invalid metadata key: \"${key}\". Only \"index\", \"first\", and \"last\" are allowed.`);\n }\n\n if (!value || !value.startsWith('$')) {\n throw new Error(`Invalid metadata value: \"${value}\". Must be a variable starting with $.`);\n }\n\n result[key as 'index' | 'first' | 'last'] = value.slice(1); // Remove $\n }\n\n return result;\n}\n\n/**\n * Parses a single for-loop specification\n * Example: \"$row@Row of $rows with { index: $i, first: $isFirst } trackBy $row.id\"\n */\nfunction parseForSpec(spec: string): ParsedForSpec {\n const trimmed = spec.trim();\n\n // First, extract trackBy if present at the end\n // trackBy uses $variable or $variable.property syntax (e.g., \"$item\" or \"$item.id\")\n let trackBy: string | null = null;\n let specWithoutTrackBy = trimmed;\n\n const trackByMatch = trimmed.match(/\\s+trackBy\\s+(\\$\\w+(?:\\.\\w+)*)$/);\n if (trackByMatch) {\n const trackByValue = trackByMatch[1].trim();\n specWithoutTrackBy = trimmed.slice(0, trackByMatch.index).trim();\n\n // Parse the $variable.property syntax\n const pathMatch = trackByValue.match(/^\\$(\\w+)((?:\\.\\w+)*)$/);\n if (!pathMatch) {\n throw new Error(`Invalid trackBy syntax: ${trackByValue}. Expected format: $variable or $variable.property`);\n }\n\n const variableName = pathMatch[1]; // e.g., \"item\"\n const propertyPath = pathMatch[2]; // e.g., \".id\" or \"\"\n\n // We'll validate against itemName after parsing the main pattern\n // Store both parts temporarily - validation happens after we know itemName\n trackBy = `${variableName}${propertyPath}`;\n }\n\n // Pattern: $item@Type of $items with { metadata }\n // ^^^^^ ^^^^ ^^^^^^ ^^^^^^^^^^^^^^^\n // name type expr metadata (optional)\n // Note: Type can include dots for namespaced types like \"app.table.Row\"\n const pattern = /^\\$(\\w+)@([\\w.[\\]{}:,\\s]+)\\s+of\\s+(.+?)(?:\\s+with\\s*\\{([^}]+)})?$/;\n const match = specWithoutTrackBy.match(pattern);\n\n if (!match) {\n throw new Error(\n `Invalid for-loop syntax: \"${spec}\". Expected format: \"$item@Type of $items\" or \"$item@Type of $items with { index: $i }\"`,\n );\n }\n\n const [, itemName, typeStr, itemsExpr, metadataStr] = match;\n\n // Validate and process trackBy\n // null = no trackBy specified (use index)\n // \"\" = trackBy $var (use item value directly for primitives)\n // \"id\" or \"user.id\" = trackBy $var.property (use property path)\n let processedTrackBy: string | null = null;\n if (trackBy !== null) {\n // trackBy is in format \"variableName\" or \"variableName.property.path\"\n const parts = trackBy.split('.');\n const variableName = parts[0];\n\n // Validate that trackBy references the loop variable\n if (variableName !== itemName) {\n throw new Error(`trackBy must reference loop variable $${itemName}, got $${variableName}`);\n }\n\n // Extract the property path (everything after the variable name)\n // If parts.length === 1, it's just the variable (primitive array) -> \"\" (use item value)\n // If parts.length > 1, it's a property path -> \"id\" or \"user.id\"\n processedTrackBy = parts.length > 1 ? parts.slice(1).join('.') : '';\n }\n\n return {\n itemName,\n itemType: typeStr.trim(),\n itemsExpr,\n metadata: metadataStr ? parseMetadata(metadataStr) : {},\n trackBy: processedTrackBy,\n };\n}\n\n/**\n * Unfolds the new for-loop syntax into a ForComputationSchema\n * Supports: for: \"$item@Type of $items\" or for: [\"$item1@Type1 of $items1\", \"$item2@Type2 of $items2\"]\n */\nexport function unfoldForWithNewSyntax(schema: unknown): ComputationSchema | null {\n if (!isObject(schema) || !('for' in schema)) {\n return null;\n }\n\n const forSpec = schema['for'];\n const specs = Array.isArray(forSpec) ? forSpec : [forSpec];\n\n if (specs.length === 0) {\n throw new Error('For-loop requires at least one dimension');\n }\n\n const dimensions = specs.map((spec) => {\n if (typeof spec !== 'string') {\n throw new Error(`Invalid for-loop spec: ${JSON.stringify(spec)}. Must be a string.`);\n }\n\n const parsed = parseForSpec(spec);\n\n // Parse the type annotation\n // The type can be either:\n // 1. An item type (e.g., \"string\") - we need to wrap in array\n // 2. Already an array type (e.g., \"string[]\") - use as-is\n const parsedType = parseValueType(parsed.itemType);\n const itemsType = parsedType.type === 'array' ? parsedType : { type: 'array' as const, item: parsedType };\n\n return {\n items: unfoldNodeSchema(parsed.itemsExpr, itemsType, []),\n itemsType,\n item: unfoldNodeSchema(parsed.itemName, { type: 'string' }, []),\n index: unfoldNodeSchema(parsed.metadata.index || 'index', { type: 'string' }, []),\n first: unfoldNodeSchema(parsed.metadata.first || null, { type: 'string' }, []),\n last: unfoldNodeSchema(parsed.metadata.last || null, { type: 'string' }, []),\n // trackBy: null = use index, property path (e.g., \"id\") = extract from item\n trackBy: unfoldNodeSchema(parsed.trackBy, { type: 'string' }, []),\n };\n });\n\n // Extract yield: either explicit 'yield' property or all other properties (inline yield)\n let yieldSchema: unknown;\n if ('yield' in schema) {\n yieldSchema = schema['yield'];\n } else {\n // Inline yield: all properties except 'for'\n const { for: _, ...rest } = schema as Record<string, unknown>;\n yieldSchema = rest;\n }\n\n const normalizedYield = unfoldNodeSchema(yieldSchema, { type: 'componentSchema' }, []);\n\n const result: ForComputationSchema = {\n computationType: 'for',\n dimensions,\n yield: normalizedYield,\n [Symbol.for('type')]: 'ComputationSchema',\n };\n\n return result;\n}\n"]}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { isObject } from '../../util/is-object';
|
|
2
|
-
import { parsePropertyKeyShorthand } from '../parse-property-key-shorthand';
|
|
3
|
-
import { unfoldNodeSchema } from '../unfold-node-schema';
|
|
4
|
-
export function unfoldForComputationSchema(schema) {
|
|
5
|
-
if (!isObject(schema) || !('computationType' in schema)) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
let rawDimensions = schema['dimensions'];
|
|
9
|
-
if (rawDimensions) {
|
|
10
|
-
if (!Array.isArray(rawDimensions)) {
|
|
11
|
-
throw new Error(`Invalid dimensions schema "${JSON.stringify(rawDimensions)}". It must be an array.`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
// schema can be a flat object if only one dimension is defined
|
|
16
|
-
rawDimensions = [schema];
|
|
17
|
-
}
|
|
18
|
-
const dimensions = rawDimensions.map((dimension) => {
|
|
19
|
-
const { item = 'item', index = 'index', first = null, last = null } = dimension.as || {};
|
|
20
|
-
const itemsKey = Object.keys(dimension).find((key) => key.startsWith('items'));
|
|
21
|
-
const [items, itemsType] = parsePropertyKeyShorthand(itemsKey ?? '');
|
|
22
|
-
if (items !== 'items') {
|
|
23
|
-
throw new Error(`Computation "for" requires "items" field: ${JSON.stringify(schema)}`);
|
|
24
|
-
}
|
|
25
|
-
const itemsArr = dimension[itemsKey];
|
|
26
|
-
return {
|
|
27
|
-
items: unfoldNodeSchema(itemsArr, itemsType, []),
|
|
28
|
-
itemsType,
|
|
29
|
-
item: unfoldNodeSchema(item, { type: 'string' }, []),
|
|
30
|
-
index: unfoldNodeSchema(index, { type: 'string' }, []),
|
|
31
|
-
first: unfoldNodeSchema(first, { type: 'string' }, []),
|
|
32
|
-
last: unfoldNodeSchema(last, { type: 'string' }, []),
|
|
33
|
-
trackBy: unfoldNodeSchema(null, { type: 'unknown' }, []),
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
const normalizedYield = unfoldNodeSchema(schema['yield'], { type: 'unknown' }, []);
|
|
37
|
-
const result = {
|
|
38
|
-
computationType: 'for',
|
|
39
|
-
dimensions,
|
|
40
|
-
yield: normalizedYield,
|
|
41
|
-
[Symbol.for('type')]: 'ComputationSchema',
|
|
42
|
-
};
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=unfold-for.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"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,EAAE,CAAC,CAAC;QACrE,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,6CAA6C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACzF,CAAC;QAED,MAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QAErC,OAAO;YACL,KAAK,EAAE,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC;YAChD,SAAS;YACT,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACpD,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACtD,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACtD,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACpD,OAAO,EAAE,gBAAgB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;SACzD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;IAEnF,MAAM,MAAM,GAAyB;QACnC,eAAe,EAAE,KAAK;QACtB,UAAU;QACV,KAAK,EAAE,eAAe;QACtB,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB;KAC1C,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ComputationSchema, ForComputationSchema } from '@kaskad/types';\n\nimport { ForComputationRecipe } from '../../types/raw-schemas';\nimport { isObject } from '../../util/is-object';\nimport { parsePropertyKeyShorthand } from '../parse-property-key-shorthand';\nimport { unfoldNodeSchema } from '../unfold-node-schema';\n\nexport function unfoldForComputationSchema(schema: unknown): ComputationSchema | null {\n if (!isObject(schema) || !('computationType' in schema)) {\n return null;\n }\n let rawDimensions = schema['dimensions'] as ForComputationRecipe[];\n if (rawDimensions) {\n if (!Array.isArray(rawDimensions)) {\n throw new Error(`Invalid dimensions schema \"${JSON.stringify(rawDimensions)}\". It must be an array.`);\n }\n } else {\n // schema can be a flat object if only one dimension is defined\n rawDimensions = [schema as ForComputationRecipe];\n }\n\n const dimensions = rawDimensions.map((dimension) => {\n const { item = 'item', index = 'index', first = null, last = null } = dimension.as || {};\n\n const itemsKey = Object.keys(dimension).find((key) => key.startsWith('items')) as keyof typeof dimension;\n\n const [items, itemsType] = parsePropertyKeyShorthand(itemsKey ?? '');\n if (items !== 'items') {\n throw new Error(`Computation \"for\" requires \"items\" field: ${JSON.stringify(schema)}`);\n }\n\n const itemsArr = dimension[itemsKey];\n\n return {\n items: unfoldNodeSchema(itemsArr, itemsType, []),\n itemsType,\n item: unfoldNodeSchema(item, { type: 'string' }, []),\n index: unfoldNodeSchema(index, { type: 'string' }, []),\n first: unfoldNodeSchema(first, { type: 'string' }, []),\n last: unfoldNodeSchema(last, { type: 'string' }, []),\n trackBy: unfoldNodeSchema(null, { type: 'unknown' }, []),\n };\n });\n\n const normalizedYield = unfoldNodeSchema(schema['yield'], { type: 'unknown' }, []);\n\n const result: ForComputationSchema = {\n computationType: 'for',\n dimensions,\n yield: normalizedYield,\n [Symbol.for('type')]: 'ComputationSchema',\n };\n return result;\n}\n"]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { unfoldNodeSchema } from '../unfold-node-schema';
|
|
2
|
-
export function unfoldIfComputationSchema(schema) {
|
|
3
|
-
if (schema.if === undefined) {
|
|
4
|
-
throw new Error('If computation requires the "if" field.');
|
|
5
|
-
}
|
|
6
|
-
const result = {
|
|
7
|
-
computationType: 'if',
|
|
8
|
-
if: unfoldNodeSchema(schema.if, { type: 'boolean' }, []),
|
|
9
|
-
then: createBranch(schema.then),
|
|
10
|
-
else: createBranch(schema.else),
|
|
11
|
-
[Symbol.for('type')]: 'ComputationSchema',
|
|
12
|
-
};
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
function createBranch(schema = null) {
|
|
16
|
-
return unfoldNodeSchema(schema, { type: 'componentSchema' }, []);
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=unfold-if.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unfold-if.js","sourceRoot":"","sources":["../../../../../../../libs/schema/src/lib/unfolding/computation/unfold-if.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,UAAU,yBAAyB,CAAC,MAA2B;IACnE,IAAI,MAAM,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,MAAM,GAAwB;QAClC,eAAe,EAAE,IAAI;QACrB,EAAE,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QACxD,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;QAC/B,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC;QAC/B,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,mBAAmB;KAC1C,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,SAAkB,IAAI;IAC1C,OAAO,gBAAgB,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { ComputationSchema, IfComputationSchema } from '@kaskad/types';\n\nimport { IfComputationRecipe } from '../../types/raw-schemas';\nimport { unfoldNodeSchema } from '../unfold-node-schema';\n\nexport function unfoldIfComputationSchema(schema: IfComputationRecipe): ComputationSchema {\n if (schema.if === undefined) {\n throw new Error('If computation requires the \"if\" field.');\n }\n\n const result: IfComputationSchema = {\n computationType: 'if',\n if: unfoldNodeSchema(schema.if, { type: 'boolean' }, []),\n then: createBranch(schema.then),\n else: createBranch(schema.else),\n [Symbol.for('type')]: 'ComputationSchema',\n };\n return result;\n}\n\nfunction createBranch(schema: unknown = null) {\n return unfoldNodeSchema(schema, { type: 'componentSchema' }, []);\n}\n"]}
|