@hiveforge/hivemind-mcp 2.2.0 → 2.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 +18 -9
- package/dist/cli.js +193 -2
- package/dist/cli.js.map +1 -1
- package/dist/mcp/index.d.ts +8 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/tool-generator.d.ts +108 -0
- package/dist/mcp/tool-generator.d.ts.map +1 -0
- package/dist/mcp/tool-generator.js +245 -0
- package/dist/mcp/tool-generator.js.map +1 -0
- package/dist/parser/markdown.d.ts +9 -0
- package/dist/parser/markdown.d.ts.map +1 -1
- package/dist/parser/markdown.js +13 -2
- package/dist/parser/markdown.js.map +1 -1
- package/dist/server.d.ts +8 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +66 -199
- package/dist/server.js.map +1 -1
- package/dist/templates/builtin/worldbuilding.d.ts +20 -0
- package/dist/templates/builtin/worldbuilding.d.ts.map +1 -0
- package/dist/templates/builtin/worldbuilding.js +464 -0
- package/dist/templates/builtin/worldbuilding.js.map +1 -0
- package/dist/templates/detector.d.ts +51 -0
- package/dist/templates/detector.d.ts.map +1 -0
- package/dist/templates/detector.js +71 -0
- package/dist/templates/detector.js.map +1 -0
- package/dist/templates/folder-mapper.d.ts +66 -0
- package/dist/templates/folder-mapper.d.ts.map +1 -0
- package/dist/templates/folder-mapper.js +148 -0
- package/dist/templates/folder-mapper.js.map +1 -0
- package/dist/templates/index.d.ts +15 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +15 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/loader.d.ts +115 -0
- package/dist/templates/loader.d.ts.map +1 -0
- package/dist/templates/loader.js +202 -0
- package/dist/templates/loader.js.map +1 -0
- package/dist/templates/registry.d.ts +97 -0
- package/dist/templates/registry.d.ts.map +1 -0
- package/dist/templates/registry.js +141 -0
- package/dist/templates/registry.js.map +1 -0
- package/dist/templates/schema-factory.d.ts +76 -0
- package/dist/templates/schema-factory.d.ts.map +1 -0
- package/dist/templates/schema-factory.js +171 -0
- package/dist/templates/schema-factory.js.map +1 -0
- package/dist/templates/types.d.ts +12 -0
- package/dist/templates/types.d.ts.map +1 -1
- package/dist/templates/validator.d.ts +200 -0
- package/dist/templates/validator.d.ts.map +1 -0
- package/dist/templates/validator.js +136 -0
- package/dist/templates/validator.js.map +1 -0
- package/dist/types/index.d.ts +57 -21
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +39 -15
- package/dist/types/index.js.map +1 -1
- package/dist/vault/reader.d.ts.map +1 -1
- package/dist/vault/reader.js +15 -1
- package/dist/vault/reader.js.map +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template registry for managing template lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* Provides centralized template management with O(1) lookups
|
|
5
|
+
* and validation on registration.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Manages registered templates with fast lookups.
|
|
9
|
+
*
|
|
10
|
+
* Singleton pattern ensures consistent state across the application.
|
|
11
|
+
* Validates templates on registration and provides O(1) entity type lookups.
|
|
12
|
+
*/
|
|
13
|
+
export class TemplateRegistry {
|
|
14
|
+
/** Map from template ID to registry entry */
|
|
15
|
+
templates = new Map();
|
|
16
|
+
/** ID of the currently active template */
|
|
17
|
+
activeTemplateId = null;
|
|
18
|
+
/**
|
|
19
|
+
* Registers a template in the registry.
|
|
20
|
+
*
|
|
21
|
+
* Validates the template definition and creates optimized lookup maps.
|
|
22
|
+
*
|
|
23
|
+
* @param template - Template definition to register
|
|
24
|
+
* @param source - Source of the template (builtin or config)
|
|
25
|
+
* @throws {Error} If template with this ID is already registered
|
|
26
|
+
*/
|
|
27
|
+
register(template, source) {
|
|
28
|
+
if (this.templates.has(template.id)) {
|
|
29
|
+
throw new Error(`Template "${template.id}" is already registered`);
|
|
30
|
+
}
|
|
31
|
+
// Create entity type lookup map for O(1) access
|
|
32
|
+
const entityTypeMap = new Map();
|
|
33
|
+
for (const entityType of template.entityTypes) {
|
|
34
|
+
if (entityTypeMap.has(entityType.name)) {
|
|
35
|
+
throw new Error(`Duplicate entity type "${entityType.name}" in template "${template.id}"`);
|
|
36
|
+
}
|
|
37
|
+
entityTypeMap.set(entityType.name, entityType);
|
|
38
|
+
}
|
|
39
|
+
const entry = {
|
|
40
|
+
...template,
|
|
41
|
+
source,
|
|
42
|
+
entityTypeMap,
|
|
43
|
+
};
|
|
44
|
+
this.templates.set(template.id, entry);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the active template by ID.
|
|
48
|
+
*
|
|
49
|
+
* @param templateId - ID of template to activate
|
|
50
|
+
* @throws {Error} If template ID is not registered
|
|
51
|
+
*/
|
|
52
|
+
activate(templateId) {
|
|
53
|
+
if (!this.templates.has(templateId)) {
|
|
54
|
+
throw new Error(`Cannot activate template "${templateId}": not registered. ` +
|
|
55
|
+
`Available templates: ${Array.from(this.templates.keys()).join(', ')}`);
|
|
56
|
+
}
|
|
57
|
+
this.activeTemplateId = templateId;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets the currently active template.
|
|
61
|
+
*
|
|
62
|
+
* @returns Active template entry, or null if no template is active
|
|
63
|
+
*/
|
|
64
|
+
getActive() {
|
|
65
|
+
if (this.activeTemplateId === null) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return this.templates.get(this.activeTemplateId) ?? null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets a template by ID.
|
|
72
|
+
*
|
|
73
|
+
* @param templateId - Template ID to retrieve
|
|
74
|
+
* @returns Template entry if found, undefined otherwise
|
|
75
|
+
*/
|
|
76
|
+
get(templateId) {
|
|
77
|
+
return this.templates.get(templateId);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a template is registered.
|
|
81
|
+
*
|
|
82
|
+
* @param templateId - Template ID to check
|
|
83
|
+
* @returns True if template exists in registry
|
|
84
|
+
*/
|
|
85
|
+
has(templateId) {
|
|
86
|
+
return this.templates.has(templateId);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Lists all registered template IDs.
|
|
90
|
+
*
|
|
91
|
+
* @returns Array of template IDs
|
|
92
|
+
*/
|
|
93
|
+
listTemplates() {
|
|
94
|
+
return Array.from(this.templates.keys());
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets an entity type config from the active template.
|
|
98
|
+
*
|
|
99
|
+
* O(1) lookup using the entity type map.
|
|
100
|
+
*
|
|
101
|
+
* @param name - Entity type name to retrieve
|
|
102
|
+
* @returns Entity type config if found, undefined otherwise
|
|
103
|
+
* @throws {Error} If no template is active
|
|
104
|
+
*/
|
|
105
|
+
getEntityType(name) {
|
|
106
|
+
const active = this.getActive();
|
|
107
|
+
if (!active) {
|
|
108
|
+
throw new Error('Cannot get entity type: no active template');
|
|
109
|
+
}
|
|
110
|
+
return active.entityTypeMap.get(name);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets all entity type configs from the active template.
|
|
114
|
+
*
|
|
115
|
+
* @returns Array of entity type configs
|
|
116
|
+
* @throws {Error} If no template is active
|
|
117
|
+
*/
|
|
118
|
+
getEntityTypes() {
|
|
119
|
+
const active = this.getActive();
|
|
120
|
+
if (!active) {
|
|
121
|
+
throw new Error('Cannot get entity types: no active template');
|
|
122
|
+
}
|
|
123
|
+
return active.entityTypes;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Clears all registered templates and resets active template.
|
|
127
|
+
*
|
|
128
|
+
* Primarily for testing purposes.
|
|
129
|
+
*/
|
|
130
|
+
clear() {
|
|
131
|
+
this.templates.clear();
|
|
132
|
+
this.activeTemplateId = null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Singleton instance of the template registry.
|
|
137
|
+
*
|
|
138
|
+
* Use this throughout the application for consistent template state.
|
|
139
|
+
*/
|
|
140
|
+
export const templateRegistry = new TemplateRegistry();
|
|
141
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/templates/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAC3B,6CAA6C;IACrC,SAAS,GAAG,IAAI,GAAG,EAAiC,CAAC;IAE7D,0CAA0C;IAClC,gBAAgB,GAAkB,IAAI,CAAC;IAE/C;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAA4B,EAAE,MAAsB;QAC3D,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,aAAa,QAAQ,CAAC,EAAE,yBAAyB,CAAC,CAAC;QACrE,CAAC;QAED,gDAAgD;QAChD,MAAM,aAAa,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC1D,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC9C,IAAI,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvC,MAAM,IAAI,KAAK,CACb,0BAA0B,UAAU,CAAC,IAAI,kBAAkB,QAAQ,CAAC,EAAE,GAAG,CAC1E,CAAC;YACJ,CAAC;YACD,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,KAAK,GAA0B;YACnC,GAAG,QAAQ;YACX,MAAM;YACN,aAAa;SACd,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;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cAAc;QACZ,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC/B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema factory for dynamically generating Zod schemas from entity type configurations.
|
|
3
|
+
*
|
|
4
|
+
* This module is the core of the template system's runtime validation - it transforms
|
|
5
|
+
* user-defined EntityTypeConfig objects into Zod schemas that extend the base entity
|
|
6
|
+
* schema with custom fields.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import type { EntityTypeConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create a complete Zod schema for an entity type from its configuration.
|
|
12
|
+
*
|
|
13
|
+
* The generated schema extends BaseFrontmatterSchema with:
|
|
14
|
+
* - Type literal enforcement (type must match entity type name)
|
|
15
|
+
* - All custom fields from the entity config
|
|
16
|
+
*
|
|
17
|
+
* @param config - Entity type configuration
|
|
18
|
+
* @returns Zod schema that validates entities of this type
|
|
19
|
+
*/
|
|
20
|
+
export declare function createEntitySchema(config: EntityTypeConfig): z.ZodObject<any>;
|
|
21
|
+
/**
|
|
22
|
+
* Factory class for managing schema generation with caching.
|
|
23
|
+
*
|
|
24
|
+
* Generates Zod schemas once per entity type and caches them for performance.
|
|
25
|
+
* Useful when validating multiple entities of the same type.
|
|
26
|
+
*/
|
|
27
|
+
export declare class SchemaFactory {
|
|
28
|
+
private schemaCache;
|
|
29
|
+
/**
|
|
30
|
+
* Get or create a schema for an entity type.
|
|
31
|
+
*
|
|
32
|
+
* If a schema for this entity type has been generated before, returns the
|
|
33
|
+
* cached version. Otherwise, generates and caches a new schema.
|
|
34
|
+
*
|
|
35
|
+
* @param config - Entity type configuration
|
|
36
|
+
* @returns Cached or newly generated Zod schema
|
|
37
|
+
*/
|
|
38
|
+
getSchema(config: EntityTypeConfig): z.ZodObject<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Generate schemas for multiple entity types at once.
|
|
41
|
+
*
|
|
42
|
+
* Useful for bulk schema generation (e.g., when loading a template).
|
|
43
|
+
* Returns a map of entity type name to schema.
|
|
44
|
+
*
|
|
45
|
+
* @param configs - Array of entity type configurations
|
|
46
|
+
* @returns Map from entity type name to Zod schema
|
|
47
|
+
*/
|
|
48
|
+
generateSchemas(configs: EntityTypeConfig[]): Map<string, z.ZodObject<any>>;
|
|
49
|
+
/**
|
|
50
|
+
* Clear the schema cache.
|
|
51
|
+
*
|
|
52
|
+
* Useful for testing or when entity type configurations change at runtime.
|
|
53
|
+
*/
|
|
54
|
+
clearCache(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get the number of cached schemas.
|
|
57
|
+
*
|
|
58
|
+
* @returns Number of schemas currently cached
|
|
59
|
+
*/
|
|
60
|
+
getCacheSize(): number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Singleton instance of SchemaFactory for shared caching across the application.
|
|
64
|
+
*/
|
|
65
|
+
export declare const schemaFactory: SchemaFactory;
|
|
66
|
+
/**
|
|
67
|
+
* Type helper to infer TypeScript type from generated entity schema.
|
|
68
|
+
*
|
|
69
|
+
* Usage:
|
|
70
|
+
* ```ts
|
|
71
|
+
* const characterSchema = createEntitySchema(characterConfig);
|
|
72
|
+
* type Character = InferEntityType<typeof characterSchema>;
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export type InferEntityType<T extends z.ZodObject<any>> = z.infer<T>;
|
|
76
|
+
//# sourceMappingURL=schema-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-factory.d.ts","sourceRoot":"","sources":["../../src/templates/schema-factory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAA0B,MAAM,YAAY,CAAC;AA2F3E;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAe7E;AAED;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,CAA4C;IAE/D;;;;;;;;OAQG;IACH,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;IAWrD;;;;;;;;OAQG;IACH,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAU3E;;;;OAIG;IACH,UAAU,IAAI,IAAI;IAIlB;;;;OAIG;IACH,YAAY,IAAI,MAAM;CAGvB;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,eAAsB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema factory for dynamically generating Zod schemas from entity type configurations.
|
|
3
|
+
*
|
|
4
|
+
* This module is the core of the template system's runtime validation - it transforms
|
|
5
|
+
* user-defined EntityTypeConfig objects into Zod schemas that extend the base entity
|
|
6
|
+
* schema with custom fields.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { BaseFrontmatterSchema } from '../types/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Build a Zod schema for a primitive field type.
|
|
12
|
+
* Used for array item types and standalone fields.
|
|
13
|
+
*/
|
|
14
|
+
function buildPrimitiveSchema(type) {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case 'string':
|
|
17
|
+
return z.string();
|
|
18
|
+
case 'number':
|
|
19
|
+
return z.number();
|
|
20
|
+
case 'boolean':
|
|
21
|
+
return z.boolean();
|
|
22
|
+
case 'date':
|
|
23
|
+
return z.string(); // ISO 8601 date string
|
|
24
|
+
case 'record':
|
|
25
|
+
return z.record(z.string(), z.any());
|
|
26
|
+
default:
|
|
27
|
+
// For enum/array types used as primitives, fall back to string
|
|
28
|
+
return z.string();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build a Zod schema for a single field based on its configuration.
|
|
33
|
+
*
|
|
34
|
+
* Handles all field types: string, number, boolean, enum, array, date, record.
|
|
35
|
+
* Applies required/optional modifiers and default values.
|
|
36
|
+
*/
|
|
37
|
+
function buildFieldSchema(field) {
|
|
38
|
+
let schema;
|
|
39
|
+
switch (field.type) {
|
|
40
|
+
case 'string':
|
|
41
|
+
schema = z.string();
|
|
42
|
+
break;
|
|
43
|
+
case 'number':
|
|
44
|
+
schema = z.number();
|
|
45
|
+
break;
|
|
46
|
+
case 'boolean':
|
|
47
|
+
schema = z.boolean();
|
|
48
|
+
break;
|
|
49
|
+
case 'enum':
|
|
50
|
+
if (!field.enumValues || field.enumValues.length === 0) {
|
|
51
|
+
throw new Error(`Field "${field.name}" of type enum must specify enumValues`);
|
|
52
|
+
}
|
|
53
|
+
// Build enum schema from first value + rest
|
|
54
|
+
schema = z.enum([field.enumValues[0], ...field.enumValues.slice(1)]);
|
|
55
|
+
break;
|
|
56
|
+
case 'array':
|
|
57
|
+
// Determine the item type (default to string if not specified)
|
|
58
|
+
const itemType = field.arrayItemType || 'string';
|
|
59
|
+
const itemSchema = buildPrimitiveSchema(itemType);
|
|
60
|
+
schema = z.array(itemSchema);
|
|
61
|
+
break;
|
|
62
|
+
case 'date':
|
|
63
|
+
// ISO 8601 date string
|
|
64
|
+
schema = z.string();
|
|
65
|
+
break;
|
|
66
|
+
case 'record':
|
|
67
|
+
// Key-value pairs
|
|
68
|
+
schema = z.record(z.string(), z.any());
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
// Fallback for unknown types
|
|
72
|
+
schema = z.any();
|
|
73
|
+
}
|
|
74
|
+
// Apply optional/required modifiers
|
|
75
|
+
// Fields are optional by default unless explicitly marked required
|
|
76
|
+
if (!field.required) {
|
|
77
|
+
schema = schema.optional();
|
|
78
|
+
}
|
|
79
|
+
// Apply default value if provided
|
|
80
|
+
if (field.default !== undefined) {
|
|
81
|
+
schema = schema.default(field.default);
|
|
82
|
+
}
|
|
83
|
+
return schema;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a complete Zod schema for an entity type from its configuration.
|
|
87
|
+
*
|
|
88
|
+
* The generated schema extends BaseFrontmatterSchema with:
|
|
89
|
+
* - Type literal enforcement (type must match entity type name)
|
|
90
|
+
* - All custom fields from the entity config
|
|
91
|
+
*
|
|
92
|
+
* @param config - Entity type configuration
|
|
93
|
+
* @returns Zod schema that validates entities of this type
|
|
94
|
+
*/
|
|
95
|
+
export function createEntitySchema(config) {
|
|
96
|
+
// Build the shape for custom fields
|
|
97
|
+
const customFields = {};
|
|
98
|
+
for (const field of config.fields) {
|
|
99
|
+
customFields[field.name] = buildFieldSchema(field);
|
|
100
|
+
}
|
|
101
|
+
// Extend BaseFrontmatterSchema with custom fields and enforce type literal
|
|
102
|
+
const schema = BaseFrontmatterSchema.extend({
|
|
103
|
+
type: z.literal(config.name), // Enforce this specific entity type
|
|
104
|
+
...customFields,
|
|
105
|
+
});
|
|
106
|
+
return schema;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Factory class for managing schema generation with caching.
|
|
110
|
+
*
|
|
111
|
+
* Generates Zod schemas once per entity type and caches them for performance.
|
|
112
|
+
* Useful when validating multiple entities of the same type.
|
|
113
|
+
*/
|
|
114
|
+
export class SchemaFactory {
|
|
115
|
+
schemaCache = new Map();
|
|
116
|
+
/**
|
|
117
|
+
* Get or create a schema for an entity type.
|
|
118
|
+
*
|
|
119
|
+
* If a schema for this entity type has been generated before, returns the
|
|
120
|
+
* cached version. Otherwise, generates and caches a new schema.
|
|
121
|
+
*
|
|
122
|
+
* @param config - Entity type configuration
|
|
123
|
+
* @returns Cached or newly generated Zod schema
|
|
124
|
+
*/
|
|
125
|
+
getSchema(config) {
|
|
126
|
+
const cached = this.schemaCache.get(config.name);
|
|
127
|
+
if (cached) {
|
|
128
|
+
return cached;
|
|
129
|
+
}
|
|
130
|
+
const schema = createEntitySchema(config);
|
|
131
|
+
this.schemaCache.set(config.name, schema);
|
|
132
|
+
return schema;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Generate schemas for multiple entity types at once.
|
|
136
|
+
*
|
|
137
|
+
* Useful for bulk schema generation (e.g., when loading a template).
|
|
138
|
+
* Returns a map of entity type name to schema.
|
|
139
|
+
*
|
|
140
|
+
* @param configs - Array of entity type configurations
|
|
141
|
+
* @returns Map from entity type name to Zod schema
|
|
142
|
+
*/
|
|
143
|
+
generateSchemas(configs) {
|
|
144
|
+
const schemas = new Map();
|
|
145
|
+
for (const config of configs) {
|
|
146
|
+
schemas.set(config.name, this.getSchema(config));
|
|
147
|
+
}
|
|
148
|
+
return schemas;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Clear the schema cache.
|
|
152
|
+
*
|
|
153
|
+
* Useful for testing or when entity type configurations change at runtime.
|
|
154
|
+
*/
|
|
155
|
+
clearCache() {
|
|
156
|
+
this.schemaCache.clear();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the number of cached schemas.
|
|
160
|
+
*
|
|
161
|
+
* @returns Number of schemas currently cached
|
|
162
|
+
*/
|
|
163
|
+
getCacheSize() {
|
|
164
|
+
return this.schemaCache.size;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Singleton instance of SchemaFactory for shared caching across the application.
|
|
169
|
+
*/
|
|
170
|
+
export const schemaFactory = new SchemaFactory();
|
|
171
|
+
//# sourceMappingURL=schema-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-factory.js","sourceRoot":"","sources":["../../src/templates/schema-factory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;GAGG;AACH,SAAS,oBAAoB,CAAC,IAAe;IAC3C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,QAAQ;YACX,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,SAAS;YACZ,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QACrB,KAAK,MAAM;YACT,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,uBAAuB;QAC5C,KAAK,QAAQ;YACX,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACvC;YACE,+DAA+D;YAC/D,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;IACtB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAkB;IAC1C,IAAI,MAAoB,CAAC;IAEzB,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM;QAER,KAAK,QAAQ;YACX,MAA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EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;OAIG;IACH,UAAU;QACR,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -99,4 +99,16 @@ export interface TemplateRegistryEntry extends TemplateDefinition {
|
|
|
99
99
|
/** Fast lookup map from entity type name to config */
|
|
100
100
|
entityTypeMap: Map<string, EntityTypeConfig>;
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Mapping from folder name/pattern to entity type.
|
|
104
|
+
*
|
|
105
|
+
* Used by FolderMapper to infer entity types from file paths.
|
|
106
|
+
* Supports both exact folder name matches and glob-like patterns.
|
|
107
|
+
*/
|
|
108
|
+
export interface FolderMapping {
|
|
109
|
+
/** Folder name or pattern to match (case-insensitive) */
|
|
110
|
+
pattern: string;
|
|
111
|
+
/** Entity type to assign when pattern matches */
|
|
112
|
+
entityType: string;
|
|
113
|
+
}
|
|
102
114
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/templates/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,GACP,MAAM,GACN,QAAQ,CAAC;AAEb;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,IAAI,EAAE,MAAM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C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,6CAA6C;IAC7C,WAAW,EAAE,gBAAgB,EAAE,CAAC;CACjC;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,SAAS,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAEjC,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,wDAAwD;IACxD,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAE7B,sDAAsD;IACtD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC9C;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAEhB,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template configuration validation using Zod.
|
|
3
|
+
*
|
|
4
|
+
* Provides schema validation for template configs to fail fast at startup
|
|
5
|
+
* before schema generation, ensuring user configs are valid.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import type { TemplateConfig } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Zod schema for field configuration validation.
|
|
11
|
+
*
|
|
12
|
+
* Validates:
|
|
13
|
+
* - Field names are camelCase alphanumeric
|
|
14
|
+
* - Type is one of the supported FieldType values
|
|
15
|
+
* - Enum fields have enumValues defined
|
|
16
|
+
* - Array fields have valid arrayItemType
|
|
17
|
+
*/
|
|
18
|
+
export declare const FieldConfigSchema: z.ZodObject<{
|
|
19
|
+
name: z.ZodString;
|
|
20
|
+
type: z.ZodEnum<{
|
|
21
|
+
string: "string";
|
|
22
|
+
number: "number";
|
|
23
|
+
boolean: "boolean";
|
|
24
|
+
enum: "enum";
|
|
25
|
+
array: "array";
|
|
26
|
+
date: "date";
|
|
27
|
+
record: "record";
|
|
28
|
+
}>;
|
|
29
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
31
|
+
enumValues: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
32
|
+
arrayItemType: z.ZodOptional<z.ZodEnum<{
|
|
33
|
+
string: "string";
|
|
34
|
+
number: "number";
|
|
35
|
+
boolean: "boolean";
|
|
36
|
+
enum: "enum";
|
|
37
|
+
array: "array";
|
|
38
|
+
date: "date";
|
|
39
|
+
record: "record";
|
|
40
|
+
}>>;
|
|
41
|
+
description: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
/**
|
|
44
|
+
* Zod schema for entity type configuration validation.
|
|
45
|
+
*
|
|
46
|
+
* Validates:
|
|
47
|
+
* - Entity type names are lowercase alphanumeric
|
|
48
|
+
* - Display names and plural names are provided
|
|
49
|
+
* - Fields array is valid
|
|
50
|
+
*/
|
|
51
|
+
export declare const EntityTypeConfigSchema: z.ZodObject<{
|
|
52
|
+
name: z.ZodString;
|
|
53
|
+
displayName: z.ZodString;
|
|
54
|
+
pluralName: z.ZodString;
|
|
55
|
+
description: z.ZodOptional<z.ZodString>;
|
|
56
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
57
|
+
name: z.ZodString;
|
|
58
|
+
type: z.ZodEnum<{
|
|
59
|
+
string: "string";
|
|
60
|
+
number: "number";
|
|
61
|
+
boolean: "boolean";
|
|
62
|
+
enum: "enum";
|
|
63
|
+
array: "array";
|
|
64
|
+
date: "date";
|
|
65
|
+
record: "record";
|
|
66
|
+
}>;
|
|
67
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
68
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
69
|
+
enumValues: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
|
+
arrayItemType: z.ZodOptional<z.ZodEnum<{
|
|
71
|
+
string: "string";
|
|
72
|
+
number: "number";
|
|
73
|
+
boolean: "boolean";
|
|
74
|
+
enum: "enum";
|
|
75
|
+
array: "array";
|
|
76
|
+
date: "date";
|
|
77
|
+
record: "record";
|
|
78
|
+
}>>;
|
|
79
|
+
description: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>>;
|
|
81
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
/**
|
|
84
|
+
* Zod schema for template definition validation.
|
|
85
|
+
*
|
|
86
|
+
* Validates:
|
|
87
|
+
* - Template ID is lowercase alphanumeric with hyphens
|
|
88
|
+
* - Version follows semantic versioning (X.Y.Z)
|
|
89
|
+
* - Entity types array is valid and non-empty
|
|
90
|
+
*/
|
|
91
|
+
export declare const TemplateDefinitionSchema: z.ZodObject<{
|
|
92
|
+
id: z.ZodString;
|
|
93
|
+
name: z.ZodString;
|
|
94
|
+
version: z.ZodString;
|
|
95
|
+
description: z.ZodOptional<z.ZodString>;
|
|
96
|
+
entityTypes: z.ZodArray<z.ZodObject<{
|
|
97
|
+
name: z.ZodString;
|
|
98
|
+
displayName: z.ZodString;
|
|
99
|
+
pluralName: z.ZodString;
|
|
100
|
+
description: z.ZodOptional<z.ZodString>;
|
|
101
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
102
|
+
name: z.ZodString;
|
|
103
|
+
type: z.ZodEnum<{
|
|
104
|
+
string: "string";
|
|
105
|
+
number: "number";
|
|
106
|
+
boolean: "boolean";
|
|
107
|
+
enum: "enum";
|
|
108
|
+
array: "array";
|
|
109
|
+
date: "date";
|
|
110
|
+
record: "record";
|
|
111
|
+
}>;
|
|
112
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
114
|
+
enumValues: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
115
|
+
arrayItemType: z.ZodOptional<z.ZodEnum<{
|
|
116
|
+
string: "string";
|
|
117
|
+
number: "number";
|
|
118
|
+
boolean: "boolean";
|
|
119
|
+
enum: "enum";
|
|
120
|
+
array: "array";
|
|
121
|
+
date: "date";
|
|
122
|
+
record: "record";
|
|
123
|
+
}>>;
|
|
124
|
+
description: z.ZodOptional<z.ZodString>;
|
|
125
|
+
}, z.core.$strip>>;
|
|
126
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
127
|
+
}, z.core.$strip>>;
|
|
128
|
+
}, z.core.$strip>;
|
|
129
|
+
/**
|
|
130
|
+
* Zod schema for full template configuration validation.
|
|
131
|
+
*
|
|
132
|
+
* Validates:
|
|
133
|
+
* - Templates array (if provided) contains valid templates
|
|
134
|
+
* - activeTemplate is specified
|
|
135
|
+
*/
|
|
136
|
+
export declare const TemplateConfigSchema: z.ZodObject<{
|
|
137
|
+
templates: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
138
|
+
id: z.ZodString;
|
|
139
|
+
name: z.ZodString;
|
|
140
|
+
version: z.ZodString;
|
|
141
|
+
description: z.ZodOptional<z.ZodString>;
|
|
142
|
+
entityTypes: z.ZodArray<z.ZodObject<{
|
|
143
|
+
name: z.ZodString;
|
|
144
|
+
displayName: z.ZodString;
|
|
145
|
+
pluralName: z.ZodString;
|
|
146
|
+
description: z.ZodOptional<z.ZodString>;
|
|
147
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
148
|
+
name: z.ZodString;
|
|
149
|
+
type: z.ZodEnum<{
|
|
150
|
+
string: "string";
|
|
151
|
+
number: "number";
|
|
152
|
+
boolean: "boolean";
|
|
153
|
+
enum: "enum";
|
|
154
|
+
array: "array";
|
|
155
|
+
date: "date";
|
|
156
|
+
record: "record";
|
|
157
|
+
}>;
|
|
158
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
159
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
160
|
+
enumValues: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
161
|
+
arrayItemType: z.ZodOptional<z.ZodEnum<{
|
|
162
|
+
string: "string";
|
|
163
|
+
number: "number";
|
|
164
|
+
boolean: "boolean";
|
|
165
|
+
enum: "enum";
|
|
166
|
+
array: "array";
|
|
167
|
+
date: "date";
|
|
168
|
+
record: "record";
|
|
169
|
+
}>>;
|
|
170
|
+
description: z.ZodOptional<z.ZodString>;
|
|
171
|
+
}, z.core.$strip>>;
|
|
172
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.core.$strip>>;
|
|
174
|
+
}, z.core.$strip>>>;
|
|
175
|
+
activeTemplate: z.ZodString;
|
|
176
|
+
}, z.core.$strip>;
|
|
177
|
+
/**
|
|
178
|
+
* Custom error class for template validation failures.
|
|
179
|
+
*
|
|
180
|
+
* Provides structured error information and user-friendly messages.
|
|
181
|
+
*/
|
|
182
|
+
export declare class TemplateValidationError extends Error {
|
|
183
|
+
readonly issues: z.ZodIssue[];
|
|
184
|
+
constructor(message: string, issues: z.ZodIssue[]);
|
|
185
|
+
/**
|
|
186
|
+
* Converts Zod validation issues to a user-friendly error message.
|
|
187
|
+
*
|
|
188
|
+
* @returns Formatted error message with all validation issues
|
|
189
|
+
*/
|
|
190
|
+
toUserMessage(): string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Validates template configuration against schema.
|
|
194
|
+
*
|
|
195
|
+
* @param config - Template configuration to validate
|
|
196
|
+
* @returns Validated and typed configuration
|
|
197
|
+
* @throws {TemplateValidationError} If validation fails with details of all issues
|
|
198
|
+
*/
|
|
199
|
+
export declare function validateTemplateConfig(config: unknown): TemplateConfig;
|
|
200
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/templates/validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAIV,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;iBAgCM,CAAC;AAErC;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAaK,CAAC;AAEzC;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgBK,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGK,CAAC;AAEvC;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;aAG9B,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;gBADpC,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAMtC;;;;OAIG;IACH,aAAa,IAAI,MAAM;CAUxB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,cAAc,CAQtE"}
|