constructa-core 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,6 +21,10 @@ Use `defineGenerator()` for developer-authored executable implementations. An im
21
21
 
22
22
  `GeneratorDefinition<Output>` carries output information only at compile time; emitted definitions remain plain JSON data. Factories should use `createGeneratorDefinition()` so literal fields are preserved and the resulting definition is portable. Implementations receive randomness and child generation through `GenerationContext`; they must not use global randomness or built-in-specific execution switches.
23
23
 
24
+ ## Registry
25
+
26
+ `createRegistry()` is advanced infrastructure. Register trusted implementations explicitly with `register()`. Duplicate type IDs fail without changing registry state; `replace()` is the deliberate replacement path and requires the type to already be registered. `lookup(type, path?)` resolves a registered implementation without a central built-in switch. Unknown IDs throw a dependency `UNKNOWN_GENERATOR` error at the supplied definition path plus `type`, with safe registered-type diagnostics. `snapshot()` returns an immutable, type-sorted registry view with the same lookup behavior; later registry changes do not affect it. Dispatch remains a separate concern.
27
+
24
28
  ## Dependency Boundary
25
29
 
26
30
  `constructa-schema` is the only Constructa runtime dependency that `constructa-core` may depend on.
package/dist/index.d.ts CHANGED
@@ -22,6 +22,22 @@ type GeneratorImplementation<Definition extends GeneratorDefinition$1<Output>, O
22
22
  readonly context: GenerationContext;
23
23
  }) => Output;
24
24
  };
25
+ type RegisteredGenerator = {
26
+ readonly type: string;
27
+ readonly version: number;
28
+ };
29
+ type GeneratorRegistrySnapshot = {
30
+ readonly generators: readonly RegisteredGenerator[];
31
+ readonly lookup: (type: string, path?: ValidationPath$1) => GeneratorImplementation<GeneratorDefinition$1, unknown>;
32
+ };
33
+ type GeneratorRegistry = {
34
+ register: <Definition extends GeneratorDefinition$1<Output>, Output>(implementation: GeneratorImplementation<Definition, Output>) => void;
35
+ replace: <Definition extends GeneratorDefinition$1<Output>, Output>(implementation: GeneratorImplementation<Definition, Output>) => void;
36
+ lookup: (type: string, path?: ValidationPath$1) => GeneratorImplementation<GeneratorDefinition$1, unknown>;
37
+ snapshot: () => GeneratorRegistrySnapshot;
38
+ };
39
+ /** Creates advanced registry infrastructure. Normal factories do not require it. */
40
+ declare function createRegistry(): GeneratorRegistry;
25
41
  /**
26
42
  * Defines a trusted, developer-authored generator implementation. This API has
27
43
  * no dependency on a particular validation library.
@@ -40,5 +56,5 @@ declare function invokeGeneratorImplementation<Definition extends GeneratorDefin
40
56
  readonly path?: ValidationPath$1;
41
57
  }): Output;
42
58
  //#endregion
43
- export { GenerationContext, type GeneratorDefinition, GeneratorDependency, GeneratorImplementation, type Infer, RandomSource, type ValidationIssue, type ValidationPath, createGeneratorDefinition, defineGenerator, invokeGeneratorImplementation };
59
+ export { GenerationContext, type GeneratorDefinition, GeneratorDependency, GeneratorImplementation, GeneratorRegistry, GeneratorRegistrySnapshot, type Infer, RandomSource, RegisteredGenerator, type ValidationIssue, type ValidationPath, createGeneratorDefinition, createRegistry, defineGenerator, invokeGeneratorImplementation };
44
60
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;KAgBY;EACV;;;KAIU;WACD,QAAQ;WACR,gBAAgB,QACvB,YAAY,sBAAoB,YAC7B;;KAGK;WACD;WACA,MAAM;;KAGL,wBACV,mBAAmB,sBAAoB,SACvC;WAES;WACA;WACA,qBACP,iCACY;WACL,uBACP,YAAY,wBACA;WACL,WAAW;aACT,YAAY;aACZ,SAAS;QACd;;;;;;iBAOQ,sBACR,mBAAmB,sBAAoB,SAC7C,QAEA,gBAAgB,wBAAwB,YAAY,UACnD,wBAAwB,YAAY;;iBAMvB,0BACd,cACM,mBAAmB,sBAAoB,SAC7C,YAAY,aAAa;;;;;;iBAUX,8BACd,mBAAmB,sBAAoB,SACvC,QAEA,gBAAgB,wBAAwB,YAAY,SACpD;WACW,YAAY;WACZ,SAAS;WACT,OAAO;IAEjB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;KAgBY;EACV;;;KAIU;WACD,QAAQ;WACR,gBAAgB,QACvB,YAAY,sBAAoB,YAC7B;;KAGK;WACD;WACA,MAAM;;KAGL,wBACV,mBAAmB,sBAAoB,SACvC;WAES;WACA;WACA,qBACP,iCACY;WACL,uBACP,YAAY,wBACA;WACL,WAAW;aACT,YAAY;aACZ,SAAS;QACd;;KAGI;WACD;WACA;;KAGC;WACD,qBAAqB;WACrB,SACP,cACA,OAAO,qBACJ,wBAAwB;;KAGnB;EACV,WAAW,mBAAmB,sBAAoB,SAAS,QACzD,gBAAgB,wBAAwB,YAAY;EAEtD,UAAU,mBAAmB,sBAAoB,SAAS,QACxD,gBAAgB,wBAAwB,YAAY;EAEtD,SACE,cACA,OAAO,qBACJ,wBAAwB;EAC7B,gBAAgB;;;iBAUF,kBAAkB;;;;;iBAoDlB,sBACR,mBAAmB,sBAAoB,SAC7C,QAEA,gBAAgB,wBAAwB,YAAY,UACnD,wBAAwB,YAAY;;iBAMvB,0BACd,cACM,mBAAmB,sBAAoB,SAC7C,YAAY,aAAa;;;;;;iBAUX,8BACd,mBAAmB,sBAAoB,SACvC,QAEA,gBAAgB,wBAAwB,YAAY,SACpD;WACW,YAAY;WACZ,SAAS;WACT,OAAO;IAEjB"}
package/dist/index.js CHANGED
@@ -1,5 +1,32 @@
1
1
  import { ConstructaError, assertGeneratorDefinition, normalizeConstructaError } from "constructa-schema";
2
2
  //#region src/index.ts
3
+ const RESERVED_GENERATOR_TYPE_IDS = /* @__PURE__ */ new Set([
4
+ "__proto__",
5
+ "constructor",
6
+ "prototype"
7
+ ]);
8
+ /** Creates advanced registry infrastructure. Normal factories do not require it. */
9
+ function createRegistry() {
10
+ const implementations = /* @__PURE__ */ new Map();
11
+ return {
12
+ register(implementation) {
13
+ assertRegistryImplementation(implementation);
14
+ if (implementations.has(implementation.type)) throw registryError("DUPLICATE_GENERATOR", ["type"], `A generator with type "${implementation.type}" is already registered.`);
15
+ implementations.set(implementation.type, freezeImplementation(implementation));
16
+ },
17
+ replace(implementation) {
18
+ assertRegistryImplementation(implementation);
19
+ if (!implementations.has(implementation.type)) throw registryError("UNKNOWN_GENERATOR", ["type"], `No generator with type "${implementation.type}" is registered.`);
20
+ implementations.set(implementation.type, freezeImplementation(implementation));
21
+ },
22
+ lookup(type, path = []) {
23
+ return lookupImplementation(implementations, type, path);
24
+ },
25
+ snapshot() {
26
+ return createRegistrySnapshot(implementations);
27
+ }
28
+ };
29
+ }
3
30
  /**
4
31
  * Defines a trusted, developer-authored generator implementation. This API has
5
32
  * no dependency on a particular validation library.
@@ -68,10 +95,54 @@ function assertGeneratorImplementation(implementation) {
68
95
  if (typeof implementation.generate !== "function") throw new TypeError("generate must be a function");
69
96
  if (implementation.analyzeDependencies !== void 0 && typeof implementation.analyzeDependencies !== "function") throw new TypeError("analyzeDependencies must be a function when present");
70
97
  }
98
+ function assertRegistryImplementation(implementation) {
99
+ try {
100
+ assertGeneratorImplementation(implementation);
101
+ } catch {
102
+ throw registryError("INVALID_CONFIGURATION", ["implementation"], "Generator implementation is invalid.");
103
+ }
104
+ if (RESERVED_GENERATOR_TYPE_IDS.has(implementation.type)) throw registryError("INVALID_CONFIGURATION", ["type"], `Generator type "${implementation.type}" is reserved.`);
105
+ }
106
+ function freezeImplementation(implementation) {
107
+ return Object.freeze({ ...implementation });
108
+ }
109
+ function createRegistrySnapshot(implementations) {
110
+ const snapshotImplementations = new Map(implementations);
111
+ const generators = [...snapshotImplementations.values()].map(({ type, version }) => Object.freeze({
112
+ type,
113
+ version
114
+ })).sort((left, right) => left.type.localeCompare(right.type));
115
+ return Object.freeze({
116
+ generators: Object.freeze(generators),
117
+ lookup(type, path = []) {
118
+ return lookupImplementation(snapshotImplementations, type, path);
119
+ }
120
+ });
121
+ }
122
+ function lookupImplementation(implementations, type, path) {
123
+ const implementation = implementations.get(type);
124
+ if (implementation !== void 0) return implementation;
125
+ const registeredTypes = [...implementations.keys()].sort((left, right) => left.localeCompare(right));
126
+ throw new ConstructaError({
127
+ kind: "dependency",
128
+ code: "UNKNOWN_GENERATOR",
129
+ path: [...path, "type"],
130
+ message: `No generator with type "${type}" is registered.`,
131
+ details: { registeredTypes }
132
+ });
133
+ }
134
+ function registryError(code, path, message) {
135
+ return new ConstructaError({
136
+ kind: "configuration",
137
+ code,
138
+ path,
139
+ message
140
+ });
141
+ }
71
142
  function isStableTypeId(value) {
72
143
  return /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u.test(value);
73
144
  }
74
145
  //#endregion
75
- export { createGeneratorDefinition, defineGenerator, invokeGeneratorImplementation };
146
+ export { createGeneratorDefinition, createRegistry, defineGenerator, invokeGeneratorImplementation };
76
147
 
77
148
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n assertGeneratorDefinition,\n ConstructaError,\n type GeneratorDefinition,\n normalizeConstructaError,\n type ValidationIssue,\n type ValidationPath,\n} from \"constructa-schema\";\n\nexport type {\n GeneratorDefinition,\n Infer,\n ValidationIssue,\n ValidationPath,\n} from \"constructa-schema\";\n\nexport type RandomSource = {\n next(): number;\n};\n\n/** Services supplied by the engine. Implementations must not use global randomness. */\nexport type GenerationContext = {\n readonly random: RandomSource;\n readonly generateChild: <Output>(\n definition: GeneratorDefinition<Output>,\n ) => Output;\n};\n\nexport type GeneratorDependency = {\n readonly typeId: string;\n readonly path: ValidationPath;\n};\n\nexport type GeneratorImplementation<\n Definition extends GeneratorDefinition<Output>,\n Output,\n> = {\n readonly type: string;\n readonly version: number;\n readonly validateDefinition: (\n definition: unknown,\n ) => readonly ValidationIssue[];\n readonly analyzeDependencies?: (\n definition: Definition,\n ) => readonly GeneratorDependency[];\n readonly generate: (input: {\n readonly definition: Definition;\n readonly context: GenerationContext;\n }) => Output;\n};\n\n/**\n * Defines a trusted, developer-authored generator implementation. This API has\n * no dependency on a particular validation library.\n */\nexport function defineGenerator<\n const Definition extends GeneratorDefinition<Output>,\n Output,\n>(\n implementation: GeneratorImplementation<Definition, Output>,\n): GeneratorImplementation<Definition, Output> {\n assertGeneratorImplementation(implementation);\n return implementation;\n}\n\n/** Builds a portable definition while preserving literal fields and output inference. */\nexport function createGeneratorDefinition<\n Output,\n const Definition extends GeneratorDefinition<Output>,\n>(definition: Definition): Definition {\n assertGeneratorDefinition(definition);\n return definition;\n}\n\n/**\n * Invokes one validated implementation. Registry lookup and dispatch are added\n * later; this function keeps validation and execution failure normalization in\n * the same shared contract today.\n */\nexport function invokeGeneratorImplementation<\n Definition extends GeneratorDefinition<Output>,\n Output,\n>(\n implementation: GeneratorImplementation<Definition, Output>,\n input: {\n readonly definition: Definition;\n readonly context: GenerationContext;\n readonly path?: ValidationPath;\n },\n): Output {\n const path = input.path ?? [];\n let issues: readonly ValidationIssue[];\n\n try {\n issues = implementation.validateDefinition(input.definition);\n } catch (cause) {\n throw normalizeConstructaError(cause, {\n kind: \"configuration\",\n code: \"INVALID_CONFIGURATION\",\n path,\n message: \"Generator definition validation failed.\",\n });\n }\n\n if (issues.length > 0) {\n const [issue] = issues;\n if (issue !== undefined) {\n throw new ConstructaError({\n kind: \"configuration\",\n code: \"INVALID_CONFIGURATION\",\n path: [...path, ...issue.path],\n message: issue.message,\n details: { issueCode: issue.code },\n });\n }\n\n throw new ConstructaError({\n kind: \"system\",\n code: \"EXECUTION_FAILED\",\n path,\n message: \"Generator validation returned an invalid result.\",\n });\n }\n\n try {\n return implementation.generate({\n definition: input.definition,\n context: input.context,\n });\n } catch (cause) {\n throw normalizeConstructaError(cause, {\n kind: \"execution\",\n code: \"EXECUTION_FAILED\",\n path,\n message: \"Generator execution failed.\",\n });\n }\n}\n\nfunction assertGeneratorImplementation(implementation: {\n readonly type: string;\n readonly version: number;\n readonly validateDefinition: unknown;\n readonly analyzeDependencies?: unknown;\n readonly generate: unknown;\n}): void {\n if (!isStableTypeId(implementation.type)) {\n throw new TypeError(\"generator type must be a stable lowercase identifier\");\n }\n if (\n !Number.isSafeInteger(implementation.version) ||\n implementation.version < 1\n ) {\n throw new TypeError(\"generator version must be a positive safe integer\");\n }\n if (typeof implementation.validateDefinition !== \"function\") {\n throw new TypeError(\"validateDefinition must be a function\");\n }\n if (typeof implementation.generate !== \"function\") {\n throw new TypeError(\"generate must be a function\");\n }\n if (\n implementation.analyzeDependencies !== undefined &&\n typeof implementation.analyzeDependencies !== \"function\"\n ) {\n throw new TypeError(\"analyzeDependencies must be a function when present\");\n }\n}\n\nfunction isStableTypeId(value: string): boolean {\n return /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u.test(value);\n}\n"],"mappings":";;;;;;AAuDA,SAAgB,gBAId,gBAC6C;CAC7C,8BAA8B,cAAc;CAC5C,OAAO;AACT;;AAGA,SAAgB,0BAGd,YAAoC;CACpC,0BAA0B,UAAU;CACpC,OAAO;AACT;;;;;;AAOA,SAAgB,8BAId,gBACA,OAKQ;CACR,MAAM,OAAO,MAAM,QAAQ,CAAC;CAC5B,IAAI;CAEJ,IAAI;EACF,SAAS,eAAe,mBAAmB,MAAM,UAAU;CAC7D,SAAS,OAAO;EACd,MAAM,yBAAyB,OAAO;GACpC,MAAM;GACN,MAAM;GACN;GACA,SAAS;EACX,CAAC;CACH;CAEA,IAAI,OAAO,SAAS,GAAG;EACrB,MAAM,CAAC,SAAS;EAChB,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,gBAAgB;GACxB,MAAM;GACN,MAAM;GACN,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,IAAI;GAC7B,SAAS,MAAM;GACf,SAAS,EAAE,WAAW,MAAM,KAAK;EACnC,CAAC;EAGH,MAAM,IAAI,gBAAgB;GACxB,MAAM;GACN,MAAM;GACN;GACA,SAAS;EACX,CAAC;CACH;CAEA,IAAI;EACF,OAAO,eAAe,SAAS;GAC7B,YAAY,MAAM;GAClB,SAAS,MAAM;EACjB,CAAC;CACH,SAAS,OAAO;EACd,MAAM,yBAAyB,OAAO;GACpC,MAAM;GACN,MAAM;GACN;GACA,SAAS;EACX,CAAC;CACH;AACF;AAEA,SAAS,8BAA8B,gBAM9B;CACP,IAAI,CAAC,eAAe,eAAe,IAAI,GACrC,MAAM,IAAI,UAAU,sDAAsD;CAE5E,IACE,CAAC,OAAO,cAAc,eAAe,OAAO,KAC5C,eAAe,UAAU,GAEzB,MAAM,IAAI,UAAU,mDAAmD;CAEzE,IAAI,OAAO,eAAe,uBAAuB,YAC/C,MAAM,IAAI,UAAU,uCAAuC;CAE7D,IAAI,OAAO,eAAe,aAAa,YACrC,MAAM,IAAI,UAAU,6BAA6B;CAEnD,IACE,eAAe,wBAAwB,KAAA,KACvC,OAAO,eAAe,wBAAwB,YAE9C,MAAM,IAAI,UAAU,qDAAqD;AAE7E;AAEA,SAAS,eAAe,OAAwB;CAC9C,OAAO,uCAAuC,KAAK,KAAK;AAC1D"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n assertGeneratorDefinition,\n ConstructaError,\n type GeneratorDefinition,\n normalizeConstructaError,\n type ValidationIssue,\n type ValidationPath,\n} from \"constructa-schema\";\n\nexport type {\n GeneratorDefinition,\n Infer,\n ValidationIssue,\n ValidationPath,\n} from \"constructa-schema\";\n\nexport type RandomSource = {\n next(): number;\n};\n\n/** Services supplied by the engine. Implementations must not use global randomness. */\nexport type GenerationContext = {\n readonly random: RandomSource;\n readonly generateChild: <Output>(\n definition: GeneratorDefinition<Output>,\n ) => Output;\n};\n\nexport type GeneratorDependency = {\n readonly typeId: string;\n readonly path: ValidationPath;\n};\n\nexport type GeneratorImplementation<\n Definition extends GeneratorDefinition<Output>,\n Output,\n> = {\n readonly type: string;\n readonly version: number;\n readonly validateDefinition: (\n definition: unknown,\n ) => readonly ValidationIssue[];\n readonly analyzeDependencies?: (\n definition: Definition,\n ) => readonly GeneratorDependency[];\n readonly generate: (input: {\n readonly definition: Definition;\n readonly context: GenerationContext;\n }) => Output;\n};\n\nexport type RegisteredGenerator = {\n readonly type: string;\n readonly version: number;\n};\n\nexport type GeneratorRegistrySnapshot = {\n readonly generators: readonly RegisteredGenerator[];\n readonly lookup: (\n type: string,\n path?: ValidationPath,\n ) => GeneratorImplementation<GeneratorDefinition, unknown>;\n};\n\nexport type GeneratorRegistry = {\n register: <Definition extends GeneratorDefinition<Output>, Output>(\n implementation: GeneratorImplementation<Definition, Output>,\n ) => void;\n replace: <Definition extends GeneratorDefinition<Output>, Output>(\n implementation: GeneratorImplementation<Definition, Output>,\n ) => void;\n lookup: (\n type: string,\n path?: ValidationPath,\n ) => GeneratorImplementation<GeneratorDefinition, unknown>;\n snapshot: () => GeneratorRegistrySnapshot;\n};\n\nconst RESERVED_GENERATOR_TYPE_IDS = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n]);\n\n/** Creates advanced registry infrastructure. Normal factories do not require it. */\nexport function createRegistry(): GeneratorRegistry {\n const implementations = new Map<\n string,\n GeneratorImplementation<GeneratorDefinition, unknown>\n >();\n\n return {\n register(implementation) {\n assertRegistryImplementation(implementation);\n if (implementations.has(implementation.type)) {\n throw registryError(\n \"DUPLICATE_GENERATOR\",\n [\"type\"],\n `A generator with type \"${implementation.type}\" is already registered.`,\n );\n }\n implementations.set(\n implementation.type,\n freezeImplementation(\n implementation,\n ) as unknown as GeneratorImplementation<GeneratorDefinition, unknown>,\n );\n },\n replace(implementation) {\n assertRegistryImplementation(implementation);\n if (!implementations.has(implementation.type)) {\n throw registryError(\n \"UNKNOWN_GENERATOR\",\n [\"type\"],\n `No generator with type \"${implementation.type}\" is registered.`,\n );\n }\n implementations.set(\n implementation.type,\n freezeImplementation(\n implementation,\n ) as unknown as GeneratorImplementation<GeneratorDefinition, unknown>,\n );\n },\n lookup(type, path = []) {\n return lookupImplementation(implementations, type, path);\n },\n snapshot() {\n return createRegistrySnapshot(implementations);\n },\n };\n}\n\n/**\n * Defines a trusted, developer-authored generator implementation. This API has\n * no dependency on a particular validation library.\n */\nexport function defineGenerator<\n const Definition extends GeneratorDefinition<Output>,\n Output,\n>(\n implementation: GeneratorImplementation<Definition, Output>,\n): GeneratorImplementation<Definition, Output> {\n assertGeneratorImplementation(implementation);\n return implementation;\n}\n\n/** Builds a portable definition while preserving literal fields and output inference. */\nexport function createGeneratorDefinition<\n Output,\n const Definition extends GeneratorDefinition<Output>,\n>(definition: Definition): Definition {\n assertGeneratorDefinition(definition);\n return definition;\n}\n\n/**\n * Invokes one validated implementation. Registry lookup and dispatch are added\n * later; this function keeps validation and execution failure normalization in\n * the same shared contract today.\n */\nexport function invokeGeneratorImplementation<\n Definition extends GeneratorDefinition<Output>,\n Output,\n>(\n implementation: GeneratorImplementation<Definition, Output>,\n input: {\n readonly definition: Definition;\n readonly context: GenerationContext;\n readonly path?: ValidationPath;\n },\n): Output {\n const path = input.path ?? [];\n let issues: readonly ValidationIssue[];\n\n try {\n issues = implementation.validateDefinition(input.definition);\n } catch (cause) {\n throw normalizeConstructaError(cause, {\n kind: \"configuration\",\n code: \"INVALID_CONFIGURATION\",\n path,\n message: \"Generator definition validation failed.\",\n });\n }\n\n if (issues.length > 0) {\n const [issue] = issues;\n if (issue !== undefined) {\n throw new ConstructaError({\n kind: \"configuration\",\n code: \"INVALID_CONFIGURATION\",\n path: [...path, ...issue.path],\n message: issue.message,\n details: { issueCode: issue.code },\n });\n }\n\n throw new ConstructaError({\n kind: \"system\",\n code: \"EXECUTION_FAILED\",\n path,\n message: \"Generator validation returned an invalid result.\",\n });\n }\n\n try {\n return implementation.generate({\n definition: input.definition,\n context: input.context,\n });\n } catch (cause) {\n throw normalizeConstructaError(cause, {\n kind: \"execution\",\n code: \"EXECUTION_FAILED\",\n path,\n message: \"Generator execution failed.\",\n });\n }\n}\n\nfunction assertGeneratorImplementation(implementation: {\n readonly type: string;\n readonly version: number;\n readonly validateDefinition: unknown;\n readonly analyzeDependencies?: unknown;\n readonly generate: unknown;\n}): void {\n if (!isStableTypeId(implementation.type)) {\n throw new TypeError(\"generator type must be a stable lowercase identifier\");\n }\n if (\n !Number.isSafeInteger(implementation.version) ||\n implementation.version < 1\n ) {\n throw new TypeError(\"generator version must be a positive safe integer\");\n }\n if (typeof implementation.validateDefinition !== \"function\") {\n throw new TypeError(\"validateDefinition must be a function\");\n }\n if (typeof implementation.generate !== \"function\") {\n throw new TypeError(\"generate must be a function\");\n }\n if (\n implementation.analyzeDependencies !== undefined &&\n typeof implementation.analyzeDependencies !== \"function\"\n ) {\n throw new TypeError(\"analyzeDependencies must be a function when present\");\n }\n}\n\nfunction assertRegistryImplementation(implementation: {\n readonly type: string;\n readonly version: number;\n readonly validateDefinition: unknown;\n readonly analyzeDependencies?: unknown;\n readonly generate: unknown;\n}): void {\n try {\n assertGeneratorImplementation(implementation);\n } catch {\n throw registryError(\n \"INVALID_CONFIGURATION\",\n [\"implementation\"],\n \"Generator implementation is invalid.\",\n );\n }\n if (RESERVED_GENERATOR_TYPE_IDS.has(implementation.type)) {\n throw registryError(\n \"INVALID_CONFIGURATION\",\n [\"type\"],\n `Generator type \"${implementation.type}\" is reserved.`,\n );\n }\n}\n\nfunction freezeImplementation<\n Definition extends GeneratorDefinition<Output>,\n Output,\n>(\n implementation: GeneratorImplementation<Definition, Output>,\n): GeneratorImplementation<Definition, Output> {\n return Object.freeze({ ...implementation });\n}\n\nfunction createRegistrySnapshot(\n implementations: ReadonlyMap<\n string,\n GeneratorImplementation<GeneratorDefinition, unknown>\n >,\n): GeneratorRegistrySnapshot {\n const snapshotImplementations = new Map(implementations);\n const generators = [...snapshotImplementations.values()]\n .map(({ type, version }) => Object.freeze({ type, version }))\n .sort((left, right) => left.type.localeCompare(right.type));\n\n return Object.freeze({\n generators: Object.freeze(generators),\n lookup(type: string, path: ValidationPath = []) {\n return lookupImplementation(snapshotImplementations, type, path);\n },\n });\n}\n\nfunction lookupImplementation(\n implementations: ReadonlyMap<\n string,\n GeneratorImplementation<GeneratorDefinition, unknown>\n >,\n type: string,\n path: ValidationPath,\n): GeneratorImplementation<GeneratorDefinition, unknown> {\n const implementation = implementations.get(type);\n if (implementation !== undefined) return implementation;\n\n const registeredTypes = [...implementations.keys()].sort((left, right) =>\n left.localeCompare(right),\n );\n throw new ConstructaError({\n kind: \"dependency\",\n code: \"UNKNOWN_GENERATOR\",\n path: [...path, \"type\"],\n message: `No generator with type \"${type}\" is registered.`,\n details: { registeredTypes },\n });\n}\n\nfunction registryError(\n code: \"DUPLICATE_GENERATOR\" | \"INVALID_CONFIGURATION\" | \"UNKNOWN_GENERATOR\",\n path: ValidationPath,\n message: string,\n): ConstructaError {\n return new ConstructaError({ kind: \"configuration\", code, path, message });\n}\n\nfunction isStableTypeId(value: string): boolean {\n return /^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u.test(value);\n}\n"],"mappings":";;AA8EA,MAAM,8CAA8B,IAAI,IAAI;CAC1C;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,iBAAoC;CAClD,MAAM,kCAAkB,IAAI,IAG1B;CAEF,OAAO;EACL,SAAS,gBAAgB;GACvB,6BAA6B,cAAc;GAC3C,IAAI,gBAAgB,IAAI,eAAe,IAAI,GACzC,MAAM,cACJ,uBACA,CAAC,MAAM,GACP,0BAA0B,eAAe,KAAK,yBAChD;GAEF,gBAAgB,IACd,eAAe,MACf,qBACE,cACF,CACF;EACF;EACA,QAAQ,gBAAgB;GACtB,6BAA6B,cAAc;GAC3C,IAAI,CAAC,gBAAgB,IAAI,eAAe,IAAI,GAC1C,MAAM,cACJ,qBACA,CAAC,MAAM,GACP,2BAA2B,eAAe,KAAK,iBACjD;GAEF,gBAAgB,IACd,eAAe,MACf,qBACE,cACF,CACF;EACF;EACA,OAAO,MAAM,OAAO,CAAC,GAAG;GACtB,OAAO,qBAAqB,iBAAiB,MAAM,IAAI;EACzD;EACA,WAAW;GACT,OAAO,uBAAuB,eAAe;EAC/C;CACF;AACF;;;;;AAMA,SAAgB,gBAId,gBAC6C;CAC7C,8BAA8B,cAAc;CAC5C,OAAO;AACT;;AAGA,SAAgB,0BAGd,YA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AwB;CAC9C,OAAO,uCAAuC,KAAK,KAAK;AAC1D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "constructa-core",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "The UI-agnostic Constructa generator execution engine.",
5
5
  "private": false,
6
6
  "license": "MIT",