@kaskad/definition 0.0.6 → 0.0.8
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.
|
@@ -44,7 +44,7 @@ class DefinitionStore {
|
|
|
44
44
|
getShape(shapeType) {
|
|
45
45
|
const definition = this.shapes[shapeType];
|
|
46
46
|
if (!definition) {
|
|
47
|
-
throw new Error(`Shape "${shapeType}" is not registered
|
|
47
|
+
throw new Error(`Shape "${shapeType}" is not registered`);
|
|
48
48
|
}
|
|
49
49
|
return {
|
|
50
50
|
type: 'object',
|
|
@@ -67,7 +67,7 @@ class DefinitionStore {
|
|
|
67
67
|
getVariantShape(shapeType, kind) {
|
|
68
68
|
const definition = this.variantShapes[shapeType];
|
|
69
69
|
if (!definition) {
|
|
70
|
-
throw new Error(`VariantShape "${shapeType}" is not registered
|
|
70
|
+
throw new Error(`VariantShape "${shapeType}" is not registered`);
|
|
71
71
|
}
|
|
72
72
|
const kindProperties = definition.kinds[kind];
|
|
73
73
|
return {
|
|
@@ -89,7 +89,7 @@ class DefinitionStore {
|
|
|
89
89
|
getComponent(componentType) {
|
|
90
90
|
const componentDefinition = this.components[componentType];
|
|
91
91
|
if (!componentDefinition) {
|
|
92
|
-
throw new Error(`Component with type "${componentType}" is not found
|
|
92
|
+
throw new Error(`Component with type "${componentType}" is not found`);
|
|
93
93
|
}
|
|
94
94
|
return componentDefinition;
|
|
95
95
|
}
|
|
@@ -118,7 +118,7 @@ class DefinitionStore {
|
|
|
118
118
|
}
|
|
119
119
|
for (const [key, prop] of Object.entries(propMap)) {
|
|
120
120
|
if (!prop.valueType) {
|
|
121
|
-
throw new Error(`Property "${key}" in component "${componentType}" has no valueType
|
|
121
|
+
throw new Error(`Property "${key}" in component "${componentType}" has no valueType`);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
return structuredClone(propMap);
|
|
@@ -127,7 +127,7 @@ class DefinitionStore {
|
|
|
127
127
|
const [node, ...rest] = path.split(Delimiters.NodePath);
|
|
128
128
|
const description = this.getComputedComponentContract(componentType)[node];
|
|
129
129
|
if (!description) {
|
|
130
|
-
throw new Error(`Property "${path}" is not found in component "${componentType}"
|
|
130
|
+
throw new Error(`Property "${path}" is not found in component "${componentType}"`);
|
|
131
131
|
}
|
|
132
132
|
return findChildValueType(description.valueType, rest);
|
|
133
133
|
}
|
|
@@ -148,7 +148,7 @@ class DefinitionStore {
|
|
|
148
148
|
getCommand(commandType) {
|
|
149
149
|
const commandDefinition = this.commands[commandType];
|
|
150
150
|
if (!commandDefinition) {
|
|
151
|
-
throw new Error(`Command with type "${commandType}" is not found
|
|
151
|
+
throw new Error(`Command with type "${commandType}" is not found`);
|
|
152
152
|
}
|
|
153
153
|
return commandDefinition;
|
|
154
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kaskad-definition.mjs","sources":["../../../../libs/definition/src/lib/util/memoize.ts","../../../../libs/definition/src/lib/definition-store.ts","../../../../libs/definition/src/kaskad-definition.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic memoize requires `any` for function parameter contravariance\nexport function memoize<T extends (...args: any[]) => unknown>(fn: T): T {\n const cache = new Map();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- must match generic constraint\n return function (this: unknown, ...args: any[]) {\n const key = args.join(',');\n\n if (cache.has(key)) {\n return structuredClone(cache.get(key));\n }\n\n const result = fn.apply(this, args);\n cache.set(key, result);\n return structuredClone(result);\n } as T;\n}\n","import { Delimiters } from '@kaskad/config';\nimport { findChildValueType, NodeSchema, ObjectValueType, ValueType } from '@kaskad/types';\n\nimport { CommandDefinition } from './types/command';\nimport { ComponentDefinition } from './types/component';\nimport { ShapeDefinition } from './types/shape';\nimport { VariantShapeDefinition } from './types/variant-shape';\nimport { memoize } from './util/memoize';\n\nexport class DefinitionStore {\n private static instance: DefinitionStore;\n shapes: { [shapeType: string]: ShapeDefinition } = {};\n variantShapes: { [shapeType: string]: VariantShapeDefinition } = {};\n components: { [componentType: string]: ComponentDefinition } = {};\n commands: { [commandType: string]: CommandDefinition } = {};\n\n private constructor() {\n this.getComponentTraits = memoize(this.getComponentTraits.bind(this));\n this.getComputedComponentContract = memoize(this.getComputedComponentContract.bind(this));\n }\n\n static getInstance(): DefinitionStore {\n if (!DefinitionStore.instance) {\n DefinitionStore.instance = new DefinitionStore();\n }\n return DefinitionStore.instance;\n }\n\n static reset() {\n DefinitionStore.instance = new DefinitionStore();\n\n return DefinitionStore.instance;\n }\n\n setShape(shapeType: string, properties: Record<string, ValueType>) {\n this.shapes[shapeType] = {\n properties,\n };\n }\n\n getShape(shapeType: string): ObjectValueType {\n const definition = this.shapes[shapeType];\n if (!definition) {\n throw new Error(`Shape \"${shapeType}\" is not registered.`);\n }\n\n return {\n type: 'object',\n fields: definition.properties,\n };\n }\n\n setVariantShape(shapeType: string, commonProperties: Record<string, ValueType>) {\n this.variantShapes[shapeType] = {\n commonProperties,\n kinds: {},\n };\n }\n\n setVariantShapeKind(shapeType: string, kind: string, properties: Record<string, ValueType>): void {\n const definition = this.variantShapes[shapeType];\n if (!definition) {\n throw new Error(`VariantShape \"${shapeType}\" is not registered`);\n }\n definition.kinds[kind] = properties;\n }\n\n getVariantShape(shapeType: string, kind: string): ObjectValueType {\n const definition = this.variantShapes[shapeType];\n if (!definition) {\n throw new Error(`VariantShape \"${shapeType}\" is not registered.`);\n }\n\n const kindProperties = definition.kinds[kind];\n\n return {\n type: 'object',\n fields: {\n ...definition.commonProperties,\n ...kindProperties,\n },\n };\n }\n\n setComponent(componentType: string, componentDefinition: ComponentDefinition): void {\n this.components[componentType] = componentDefinition;\n }\n\n setComponents(componentDefinitions: Record<string, ComponentDefinition>): void {\n for (const [componentType, componentDefinition] of Object.entries(componentDefinitions)) {\n this.setComponent(componentType, componentDefinition);\n }\n }\n\n getComponent(componentType: string): ComponentDefinition {\n const componentDefinition = this.components[componentType];\n if (!componentDefinition) {\n throw new Error(`Component with type \"${componentType}\" is not found.`);\n }\n return componentDefinition;\n }\n\n getComponentTraits(componentType: string): string[] {\n const description = this.getComponent(componentType);\n const traits = description.traits || [];\n const superTraits = traits.flatMap((trait) => this.getComponentTraits(trait));\n const result = [...superTraits, ...traits, componentType];\n\n return [...new Set(result)];\n }\n\n getComputedComponentContract(componentType: string): Record<string, NodeSchema> {\n const traits = this.getComponentTraits(componentType);\n const contracts = traits.map((trait) => this.getComponent(trait).properties);\n\n const propMap: Record<string, NodeSchema> = {};\n\n for (const contract of contracts) {\n for (const [key, prop] of Object.entries(contract)) {\n if (!propMap[key]) {\n propMap[key] = prop;\n continue;\n }\n\n const existingProp = propMap[key];\n if (existingProp) {\n propMap[key] = { ...existingProp, ...prop };\n }\n }\n }\n\n for (const [key, prop] of Object.entries(propMap)) {\n if (!prop.valueType) {\n throw new Error(`Property \"${key}\" in component \"${componentType}\" has no valueType.`);\n }\n }\n\n return structuredClone(propMap);\n }\n\n getNodeValueType(componentType: string, path: string): ValueType {\n const [node, ...rest] = path.split(Delimiters.NodePath);\n\n const description = this.getComputedComponentContract(componentType)[node];\n if (!description) {\n throw new Error(`Property \"${path}\" is not found in component \"${componentType}\".`);\n }\n return findChildValueType(description.valueType, rest);\n }\n\n hasComponentWithType(componentType: string): boolean {\n return !!this.components[componentType];\n }\n\n getComponentTypes(): string[] {\n return Object.keys(this.components);\n }\n\n setCommands(definitions: Record<string, CommandDefinition>): void {\n for (const [commandType, definition] of Object.entries(definitions)) {\n this.setCommand(commandType, definition);\n }\n }\n\n setCommand(commandType: string, definition: CommandDefinition): void {\n this.commands[commandType] = definition;\n }\n\n getCommand(commandType: string): CommandDefinition {\n const commandDefinition = this.commands[commandType];\n if (!commandDefinition) {\n throw new Error(`Command with type \"${commandType}\" is not found.`);\n }\n\n return commandDefinition;\n }\n\n getCommandNames(): string[] {\n return Object.keys(this.commands);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAAA;AACM,SAAU,OA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C,UAAU,CAAC,aAAa,CAAC;;IAGzC,iBAAiB,GAAA;QACf,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;;AAGrC,IAAA,WAAW,CAAC,WAA8C,EAAA;AACxD,QAAA,KAAK,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;AACnE,YAAA,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC;;;IAI5C,UAAU,CAAC,WAAmB,EAAE,UAA6B,EAAA;AAC3D,QAAA,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,UAAU;;AAGzC,IAAA,UAAU,CAAC,WAAmB,EAAA;QAC5B,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;QACpD,IAAI,CAAC,iBAAiB,EAAE;AACtB,YAAA,MAAM,IAAI,KAAK,CAAC,sBAAsB,WAAW,CAAA,eAAA,CAAiB,CAAC;;AAGrE,QAAA,OAAO,iBAAiB;;IAG1B,eAAe,GAAA;QACb,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;;AAEpC;;ACpLD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"kaskad-definition.mjs","sources":["../../../../libs/definition/src/lib/util/memoize.ts","../../../../libs/definition/src/lib/definition-store.ts","../../../../libs/definition/src/kaskad-definition.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic memoize requires `any` for function parameter contravariance\nexport function memoize<T extends (...args: any[]) => unknown>(fn: T): T {\n const cache = new Map();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- must match generic constraint\n return function (this: unknown, ...args: any[]) {\n const key = args.join(',');\n\n if (cache.has(key)) {\n return structuredClone(cache.get(key));\n }\n\n const result = fn.apply(this, args);\n cache.set(key, result);\n return structuredClone(result);\n } as T;\n}\n","import { Delimiters } from '@kaskad/config';\nimport { findChildValueType, NodeSchema, ObjectValueType, ValueType } from '@kaskad/types';\n\nimport { CommandDefinition } from './types/command';\nimport { ComponentDefinition } from './types/component';\nimport { ShapeDefinition } from './types/shape';\nimport { VariantShapeDefinition } from './types/variant-shape';\nimport { memoize } from './util/memoize';\n\nexport class DefinitionStore {\n private static instance: DefinitionStore;\n shapes: { [shapeType: string]: ShapeDefinition } = {};\n variantShapes: { [shapeType: string]: VariantShapeDefinition } = {};\n components: { [componentType: string]: ComponentDefinition } = {};\n commands: { [commandType: string]: CommandDefinition } = {};\n\n private constructor() {\n this.getComponentTraits = memoize(this.getComponentTraits.bind(this));\n this.getComputedComponentContract = memoize(this.getComputedComponentContract.bind(this));\n }\n\n static getInstance(): DefinitionStore {\n if (!DefinitionStore.instance) {\n DefinitionStore.instance = new DefinitionStore();\n }\n return DefinitionStore.instance;\n }\n\n static reset() {\n DefinitionStore.instance = new DefinitionStore();\n\n return DefinitionStore.instance;\n }\n\n setShape(shapeType: string, properties: Record<string, ValueType>) {\n this.shapes[shapeType] = {\n properties,\n };\n }\n\n getShape(shapeType: string): ObjectValueType {\n const definition = this.shapes[shapeType];\n if (!definition) {\n throw new Error(`Shape \"${shapeType}\" is not registered`);\n }\n\n return {\n type: 'object',\n fields: definition.properties,\n };\n }\n\n setVariantShape(shapeType: string, commonProperties: Record<string, ValueType>) {\n this.variantShapes[shapeType] = {\n commonProperties,\n kinds: {},\n };\n }\n\n setVariantShapeKind(shapeType: string, kind: string, properties: Record<string, ValueType>): void {\n const definition = this.variantShapes[shapeType];\n if (!definition) {\n throw new Error(`VariantShape \"${shapeType}\" is not registered`);\n }\n definition.kinds[kind] = properties;\n }\n\n getVariantShape(shapeType: string, kind: string): ObjectValueType {\n const definition = this.variantShapes[shapeType];\n if (!definition) {\n throw new Error(`VariantShape \"${shapeType}\" is not registered`);\n }\n\n const kindProperties = definition.kinds[kind];\n\n return {\n type: 'object',\n fields: {\n ...definition.commonProperties,\n ...kindProperties,\n },\n };\n }\n\n setComponent(componentType: string, componentDefinition: ComponentDefinition): void {\n this.components[componentType] = componentDefinition;\n }\n\n setComponents(componentDefinitions: Record<string, ComponentDefinition>): void {\n for (const [componentType, componentDefinition] of Object.entries(componentDefinitions)) {\n this.setComponent(componentType, componentDefinition);\n }\n }\n\n getComponent(componentType: string): ComponentDefinition {\n const componentDefinition = this.components[componentType];\n if (!componentDefinition) {\n throw new Error(`Component with type \"${componentType}\" is not found`);\n }\n return componentDefinition;\n }\n\n getComponentTraits(componentType: string): string[] {\n const description = this.getComponent(componentType);\n const traits = description.traits || [];\n const superTraits = traits.flatMap((trait) => this.getComponentTraits(trait));\n const result = [...superTraits, ...traits, componentType];\n\n return [...new Set(result)];\n }\n\n getComputedComponentContract(componentType: string): Record<string, NodeSchema> {\n const traits = this.getComponentTraits(componentType);\n const contracts = traits.map((trait) => this.getComponent(trait).properties);\n\n const propMap: Record<string, NodeSchema> = {};\n\n for (const contract of contracts) {\n for (const [key, prop] of Object.entries(contract)) {\n if (!propMap[key]) {\n propMap[key] = prop;\n continue;\n }\n\n const existingProp = propMap[key];\n if (existingProp) {\n propMap[key] = { ...existingProp, ...prop };\n }\n }\n }\n\n for (const [key, prop] of Object.entries(propMap)) {\n if (!prop.valueType) {\n throw new Error(`Property \"${key}\" in component \"${componentType}\" has no valueType`);\n }\n }\n\n return structuredClone(propMap);\n }\n\n getNodeValueType(componentType: string, path: string): ValueType {\n const [node, ...rest] = path.split(Delimiters.NodePath);\n\n const description = this.getComputedComponentContract(componentType)[node];\n if (!description) {\n throw new Error(`Property \"${path}\" is not found in component \"${componentType}\"`);\n }\n return findChildValueType(description.valueType, rest);\n }\n\n hasComponentWithType(componentType: string): boolean {\n return !!this.components[componentType];\n }\n\n getComponentTypes(): string[] {\n return Object.keys(this.components);\n }\n\n setCommands(definitions: Record<string, CommandDefinition>): void {\n for (const [commandType, definition] of Object.entries(definitions)) {\n this.setCommand(commandType, definition);\n }\n }\n\n setCommand(commandType: string, definition: CommandDefinition): void {\n this.commands[commandType] = definition;\n }\n\n getCommand(commandType: string): CommandDefinition {\n const commandDefinition = this.commands[commandType];\n if (!commandDefinition) {\n throw new Error(`Command with type \"${commandType}\" is not found`);\n }\n\n return commandDefinition;\n }\n\n getCommandNames(): string[] {\n return Object.keys(this.commands);\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAAA;AACM,SAAU,OAAO,CAAwC,EAAK,EAAA;AAClE,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAE;;IAGvB,OAAO,UAAyB,GAAG,IAAW,EAAA;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAE1B,QAAA,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YAClB,OAAO,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;;QAGxC,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AACnC,QAAA,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;AACtB,QAAA,OAAO,eAAe,CAAC,MAAM,CAAC;AAChC,KAAM;AACR;;MCPa,eAAe,CAAA;IAClB,OAAO,QAAQ;IACvB,MAAM,GAA6C,EAAE;IACrD,aAAa,GAAoD,EAAE;IACnE,UAAU,GAAqD,EAAE;IACjE,QAAQ,GAAiD,EAAE;AAE3D,IAAA,WAAA,GAAA;AACE,QAAA,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrE,QAAA,IAAI,CAAC,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;AAG3F,IAAA,OAAO,WAAW,GAAA;AAChB,QAAA,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;AAC7B,Y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|
|
6
|
-
"@kaskad/types": "0.0.
|
|
7
|
-
"@kaskad/config": "0.0.
|
|
6
|
+
"@kaskad/types": "0.0.8",
|
|
7
|
+
"@kaskad/config": "0.0.8"
|
|
8
8
|
},
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"module": "fesm2022/kaskad-definition.mjs",
|