@kaskad/definition 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.
@@ -1,7 +1,22 @@
1
1
  import { Delimiters } from '@kaskad/config';
2
2
  import { findChildValueType } from '@kaskad/types';
3
- import { memoize } from './util/memoize';
4
- export class DefinitionStore {
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic memoize requires `any` for function parameter contravariance
5
+ function memoize(fn) {
6
+ const cache = new Map();
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- must match generic constraint
8
+ return function (...args) {
9
+ const key = args.join(',');
10
+ if (cache.has(key)) {
11
+ return structuredClone(cache.get(key));
12
+ }
13
+ const result = fn.apply(this, args);
14
+ cache.set(key, result);
15
+ return structuredClone(result);
16
+ };
17
+ }
18
+
19
+ class DefinitionStore {
5
20
  static instance;
6
21
  shapes = {};
7
22
  variantShapes = {};
@@ -141,4 +156,10 @@ export class DefinitionStore {
141
156
  return Object.keys(this.commands);
142
157
  }
143
158
  }
144
- //# sourceMappingURL=definition-store.js.map
159
+
160
+ /**
161
+ * Generated bundle index. Do not edit.
162
+ */
163
+
164
+ export { DefinitionStore, memoize };
165
+ //# sourceMappingURL=kaskad-definition.mjs.map
@@ -0,0 +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,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,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askad/types": "0.0.1",
7
- "@kaskad/config": "0.0.1",
6
+ "@kaskad/types": "0.0.2",
7
+ "@kaskad/config": "0.0.2",
8
8
  "vite": "7.3.1",
9
9
  "@analogjs/vite-plugin-angular": "2.1.3",
10
10
  "@nx/vite": "22.4.5"
11
11
  },
12
12
  "sideEffects": false,
13
- "module": "esm2022/kaskad-definition.js",
14
- "typings": "kaskad-definition.d.ts",
13
+ "module": "fesm2022/kaskad-definition.mjs",
14
+ "typings": "types/kaskad-definition.d.ts",
15
15
  "exports": {
16
16
  "./package.json": {
17
17
  "default": "./package.json"
18
18
  },
19
19
  ".": {
20
- "types": "./kaskad-definition.d.ts",
21
- "default": "./esm2022/kaskad-definition.js"
20
+ "types": "./types/kaskad-definition.d.ts",
21
+ "default": "./fesm2022/kaskad-definition.mjs"
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
25
  "tslib": "^2.3.0"
26
26
  }
27
- }
27
+ }
@@ -1,9 +1,31 @@
1
- import { NodeSchema, ObjectValueType, ValueType } from '@kaskad/types';
2
- import { CommandDefinition } from './types/command';
3
- import { ComponentDefinition } from './types/component';
4
- import { ShapeDefinition } from './types/shape';
5
- import { VariantShapeDefinition } from './types/variant-shape';
6
- export declare class DefinitionStore {
1
+ import { ValueType, NodeSchema, ObjectValueType } from '@kaskad/types';
2
+
3
+ interface ShapeDefinition {
4
+ properties: Record<string, ValueType>;
5
+ }
6
+
7
+ interface VariantShapeDefinition {
8
+ commonProperties: Record<string, ValueType>;
9
+ kinds: Record<string, Record<string, ValueType>>;
10
+ }
11
+
12
+ type CommandContext = {
13
+ componentId: string;
14
+ };
15
+ type CommandExecute<TResult> = (ctx: CommandContext, ...params: any[]) => TResult | Promise<TResult>;
16
+ type CommandDefinition = {
17
+ execute: CommandExecute<unknown>;
18
+ };
19
+
20
+ interface ComponentDefinition {
21
+ readonly traits?: string[];
22
+ readonly properties: Record<string, NodeSchema>;
23
+ readonly defaultSlot?: string;
24
+ }
25
+
26
+ declare function memoize<T extends (...args: any[]) => unknown>(fn: T): T;
27
+
28
+ declare class DefinitionStore {
7
29
  private static instance;
8
30
  shapes: {
9
31
  [shapeType: string]: ShapeDefinition;
@@ -38,3 +60,6 @@ export declare class DefinitionStore {
38
60
  getCommand(commandType: string): CommandDefinition;
39
61
  getCommandNames(): string[];
40
62
  }
63
+
64
+ export { DefinitionStore, memoize };
65
+ export type { CommandContext, CommandDefinition, CommandExecute, ComponentDefinition, ShapeDefinition, VariantShapeDefinition };
package/esm2022/index.js DELETED
@@ -1,7 +0,0 @@
1
- export * from './lib/types/shape';
2
- export * from './lib/types/variant-shape';
3
- export * from './lib/types/command';
4
- export * from './lib/types/component';
5
- export * from './lib/util/memoize';
6
- export * from './lib/definition-store';
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/definition/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from './lib/types/shape';\nexport * from './lib/types/variant-shape';\nexport * from './lib/types/command';\nexport * from './lib/types/component';\nexport * from './lib/util/memoize';\nexport * from './lib/definition-store';\n"]}
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- export * from './index';
5
- //# sourceMappingURL=kaskad-definition.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kaskad-definition.js","sourceRoot":"","sources":["../../../../libs/definition/src/kaskad-definition.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC","sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"definition-store.js","sourceRoot":"","sources":["../../../../../libs/definition/src/lib/definition-store.ts"],"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AAW,CAAC,WAA8C;QACxD,KAAK,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YACpE,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,UAAU,CAAC,WAAmB,EAAE,UAA6B;QAC3D,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC;IAC1C,CAAC;IAED,UAAU,CAAC,WAAmB;QAC5B,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACrD,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,sBAAsB,WAAW,iBAAiB,CAAC,CAAC;QACtE,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,eAAe;QACb,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;CACF","sourcesContent":["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"]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../../../libs/definition/src/lib/types/command.ts"],"names":[],"mappings":"","sourcesContent":["export type CommandContext = {\n componentId: string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CommandExecute<TResult> = (ctx: CommandContext, ...params: any[]) => TResult | Promise<TResult>;\n\nexport type CommandDefinition = {\n execute: CommandExecute<unknown>;\n};\n"]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=component.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../../libs/definition/src/lib/types/component.ts"],"names":[],"mappings":"","sourcesContent":["import { NodeSchema } from '@kaskad/types';\n\nexport interface ComponentDefinition {\n readonly traits?: string[];\n readonly properties: Record<string, NodeSchema>;\n readonly defaultSlot?: string;\n}\n"]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=shape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shape.js","sourceRoot":"","sources":["../../../../../../libs/definition/src/lib/types/shape.ts"],"names":[],"mappings":"","sourcesContent":["import { ValueType } from '@kaskad/types';\n\nexport interface ShapeDefinition {\n properties: Record<string, ValueType>;\n}\n"]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=variant-shape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"variant-shape.js","sourceRoot":"","sources":["../../../../../../libs/definition/src/lib/types/variant-shape.ts"],"names":[],"mappings":"","sourcesContent":["import { ValueType } from '@kaskad/types';\n\nexport interface VariantShapeDefinition {\n commonProperties: Record<string, ValueType>;\n kinds: Record<string, Record<string, ValueType>>;\n}\n"]}
@@ -1,15 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic memoize requires `any` for function parameter contravariance
2
- export function memoize(fn) {
3
- const cache = new Map();
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- must match generic constraint
5
- return function (...args) {
6
- const key = args.join(',');
7
- if (cache.has(key)) {
8
- return structuredClone(cache.get(key));
9
- }
10
- const result = fn.apply(this, args);
11
- cache.set(key, result);
12
- return structuredClone(result);
13
- };
14
- }
15
- //# sourceMappingURL=memoize.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../../../../../libs/definition/src/lib/util/memoize.ts"],"names":[],"mappings":"AAAA,sIAAsI;AACtI,MAAM,UAAU,OAAO,CAAwC,EAAK;IAClE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;IAExB,+FAA+F;IAC/F,OAAO,UAAyB,GAAG,IAAW;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3B,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,OAAO,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACpC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACvB,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,CAAM,CAAC;AACT,CAAC","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"]}
package/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from './lib/types/shape';
2
- export * from './lib/types/variant-shape';
3
- export * from './lib/types/command';
4
- export * from './lib/types/component';
5
- export * from './lib/util/memoize';
6
- export * from './lib/definition-store';
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- /// <amd-module name="@kaskad/definition" />
5
- export * from './index';
@@ -1,7 +0,0 @@
1
- export type CommandContext = {
2
- componentId: string;
3
- };
4
- export type CommandExecute<TResult> = (ctx: CommandContext, ...params: any[]) => TResult | Promise<TResult>;
5
- export type CommandDefinition = {
6
- execute: CommandExecute<unknown>;
7
- };
@@ -1,6 +0,0 @@
1
- import { NodeSchema } from '@kaskad/types';
2
- export interface ComponentDefinition {
3
- readonly traits?: string[];
4
- readonly properties: Record<string, NodeSchema>;
5
- readonly defaultSlot?: string;
6
- }
@@ -1,4 +0,0 @@
1
- import { ValueType } from '@kaskad/types';
2
- export interface ShapeDefinition {
3
- properties: Record<string, ValueType>;
4
- }
@@ -1,5 +0,0 @@
1
- import { ValueType } from '@kaskad/types';
2
- export interface VariantShapeDefinition {
3
- commonProperties: Record<string, ValueType>;
4
- kinds: Record<string, Record<string, ValueType>>;
5
- }
@@ -1 +0,0 @@
1
- export declare function memoize<T extends (...args: any[]) => unknown>(fn: T): T;