@utilarium/overcontext 0.0.4-dev.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.
Files changed (87) hide show
  1. package/LICENSE +65 -0
  2. package/README.md +286 -0
  3. package/dist/api/builder.d.ts +26 -0
  4. package/dist/api/builder.js +24 -0
  5. package/dist/api/builder.js.map +1 -0
  6. package/dist/api/context.d.ts +90 -0
  7. package/dist/api/context.js +94 -0
  8. package/dist/api/context.js.map +1 -0
  9. package/dist/api/index.d.ts +6 -0
  10. package/dist/api/query-builder.d.ts +51 -0
  11. package/dist/api/query-builder.js +95 -0
  12. package/dist/api/query-builder.js.map +1 -0
  13. package/dist/api/query.d.ts +32 -0
  14. package/dist/api/search.d.ts +20 -0
  15. package/dist/api/search.js +112 -0
  16. package/dist/api/search.js.map +1 -0
  17. package/dist/api/slug.d.ts +10 -0
  18. package/dist/api/slug.js +55 -0
  19. package/dist/api/slug.js.map +1 -0
  20. package/dist/cli/builder.d.ts +74 -0
  21. package/dist/cli/builder.js +42 -0
  22. package/dist/cli/builder.js.map +1 -0
  23. package/dist/cli/commands.d.ts +53 -0
  24. package/dist/cli/commands.js +57 -0
  25. package/dist/cli/commands.js.map +1 -0
  26. package/dist/cli/formatters.d.ts +15 -0
  27. package/dist/cli/formatters.js +50 -0
  28. package/dist/cli/formatters.js.map +1 -0
  29. package/dist/cli/index.d.ts +3 -0
  30. package/dist/discovery/context-root.d.ts +31 -0
  31. package/dist/discovery/context-root.js +48 -0
  32. package/dist/discovery/context-root.js.map +1 -0
  33. package/dist/discovery/hierarchical-provider.d.ts +13 -0
  34. package/dist/discovery/hierarchical-provider.js +102 -0
  35. package/dist/discovery/hierarchical-provider.js.map +1 -0
  36. package/dist/discovery/index.d.ts +18 -0
  37. package/dist/discovery/index.js +47 -0
  38. package/dist/discovery/index.js.map +1 -0
  39. package/dist/discovery/walker.d.ts +36 -0
  40. package/dist/discovery/walker.js +87 -0
  41. package/dist/discovery/walker.js.map +1 -0
  42. package/dist/index.cjs +1763 -0
  43. package/dist/index.cjs.map +1 -0
  44. package/dist/index.d.ts +9 -0
  45. package/dist/index.js +24 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/namespace/index.d.ts +3 -0
  48. package/dist/namespace/multi-context.d.ts +40 -0
  49. package/dist/namespace/multi-context.js +72 -0
  50. package/dist/namespace/multi-context.js.map +1 -0
  51. package/dist/namespace/resolver.d.ts +33 -0
  52. package/dist/namespace/resolver.js +85 -0
  53. package/dist/namespace/resolver.js.map +1 -0
  54. package/dist/namespace/types.d.ts +41 -0
  55. package/dist/overcontext.d.ts +7 -0
  56. package/dist/schema/base.d.ts +29 -0
  57. package/dist/schema/base.js +24 -0
  58. package/dist/schema/base.js.map +1 -0
  59. package/dist/schema/builder.d.ts +28 -0
  60. package/dist/schema/builder.js +39 -0
  61. package/dist/schema/builder.js.map +1 -0
  62. package/dist/schema/index.d.ts +5 -0
  63. package/dist/schema/inference.d.ts +49 -0
  64. package/dist/schema/inference.js +15 -0
  65. package/dist/schema/inference.js.map +1 -0
  66. package/dist/schema/registry.d.ts +74 -0
  67. package/dist/schema/registry.js +117 -0
  68. package/dist/schema/registry.js.map +1 -0
  69. package/dist/schema/validation.d.ts +26 -0
  70. package/dist/schema/validation.js +51 -0
  71. package/dist/schema/validation.js.map +1 -0
  72. package/dist/storage/errors.d.ts +35 -0
  73. package/dist/storage/errors.js +58 -0
  74. package/dist/storage/errors.js.map +1 -0
  75. package/dist/storage/events.d.ts +50 -0
  76. package/dist/storage/filesystem.d.ts +10 -0
  77. package/dist/storage/filesystem.js +284 -0
  78. package/dist/storage/filesystem.js.map +1 -0
  79. package/dist/storage/index.d.ts +6 -0
  80. package/dist/storage/interface.d.ts +109 -0
  81. package/dist/storage/memory.d.ts +7 -0
  82. package/dist/storage/memory.js +128 -0
  83. package/dist/storage/memory.js.map +1 -0
  84. package/dist/storage/observable.d.ts +6 -0
  85. package/dist/storage/observable.js +98 -0
  86. package/dist/storage/observable.js.map +1 -0
  87. package/package.json +85 -0
@@ -0,0 +1,85 @@
1
+ const createNamespaceResolver = (options)=>{
2
+ const { provider, defaultNamespace = '_default' } = options;
3
+ const configuredNamespaces = new Map();
4
+ // Load initial configurations
5
+ if (options.namespaces) {
6
+ for (const ns of options.namespaces){
7
+ configuredNamespaces.set(ns.id, ns);
8
+ }
9
+ }
10
+ return {
11
+ async resolve (requested) {
12
+ let namespaceIds;
13
+ if (!requested) {
14
+ namespaceIds = [
15
+ defaultNamespace
16
+ ];
17
+ } else if (typeof requested === 'string') {
18
+ namespaceIds = [
19
+ requested
20
+ ];
21
+ } else {
22
+ namespaceIds = requested;
23
+ }
24
+ const references = [];
25
+ const readable = [];
26
+ let primary;
27
+ for(let i = 0; i < namespaceIds.length; i++){
28
+ const nsId = namespaceIds[i];
29
+ const config = configuredNamespaces.get(nsId);
30
+ // Include all requested namespaces, even if they don't exist yet
31
+ const ref = {
32
+ namespace: nsId,
33
+ priority: namespaceIds.length - i,
34
+ searchable: (config === null || config === void 0 ? void 0 : config.active) !== false,
35
+ writable: i === 0
36
+ };
37
+ references.push(ref);
38
+ readable.push(nsId);
39
+ if (!primary) {
40
+ primary = nsId;
41
+ }
42
+ }
43
+ if (!primary) {
44
+ primary = defaultNamespace;
45
+ readable.push(defaultNamespace);
46
+ }
47
+ return {
48
+ primary,
49
+ readable,
50
+ references
51
+ };
52
+ },
53
+ async listAll () {
54
+ const discovered = await provider.listNamespaces();
55
+ const all = new Map();
56
+ // Add configured namespaces
57
+ for (const [id, config] of configuredNamespaces){
58
+ all.set(id, config);
59
+ }
60
+ // Add discovered namespaces
61
+ for (const nsId of discovered){
62
+ if (!all.has(nsId)) {
63
+ all.set(nsId, {
64
+ id: nsId,
65
+ name: nsId,
66
+ active: true
67
+ });
68
+ }
69
+ }
70
+ return Array.from(all.values());
71
+ },
72
+ register (config) {
73
+ configuredNamespaces.set(config.id, config);
74
+ },
75
+ getPrimary () {
76
+ return defaultNamespace;
77
+ },
78
+ async exists (namespace) {
79
+ return configuredNamespaces.has(namespace) || await provider.namespaceExists(namespace);
80
+ }
81
+ };
82
+ };
83
+
84
+ export { createNamespaceResolver };
85
+ //# sourceMappingURL=resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.js","sources":["../../src/namespace/resolver.ts"],"sourcesContent":["import { StorageProvider } from '../storage/interface';\nimport { NamespaceConfig, NamespaceReference, NamespaceResolution } from './types';\n\nexport interface NamespaceResolverOptions {\n /** Storage provider to query for namespaces */\n provider: StorageProvider;\n\n /** Default namespace when none specified */\n defaultNamespace?: string;\n\n /** Pre-configured namespaces */\n namespaces?: NamespaceConfig[];\n}\n\nexport interface NamespaceResolver {\n /**\n * Resolve which namespaces to use for an operation.\n */\n resolve(requested?: string | string[]): Promise<NamespaceResolution>;\n\n /**\n * Get all available namespaces.\n */\n listAll(): Promise<NamespaceConfig[]>;\n\n /**\n * Register a new namespace configuration.\n */\n register(config: NamespaceConfig): void;\n\n /**\n * Get the primary (writable) namespace.\n */\n getPrimary(): string;\n\n /**\n * Check if a namespace exists.\n */\n exists(namespace: string): Promise<boolean>;\n}\n\nexport const createNamespaceResolver = (\n options: NamespaceResolverOptions\n): NamespaceResolver => {\n const { provider, defaultNamespace = '_default' } = options;\n const configuredNamespaces = new Map<string, NamespaceConfig>();\n\n // Load initial configurations\n if (options.namespaces) {\n for (const ns of options.namespaces) {\n configuredNamespaces.set(ns.id, ns);\n }\n }\n\n return {\n async resolve(requested?: string | string[]): Promise<NamespaceResolution> {\n let namespaceIds: string[];\n\n if (!requested) {\n namespaceIds = [defaultNamespace];\n } else if (typeof requested === 'string') {\n namespaceIds = [requested];\n } else {\n namespaceIds = requested;\n }\n\n const references: NamespaceReference[] = [];\n const readable: string[] = [];\n let primary: string | undefined;\n\n for (let i = 0; i < namespaceIds.length; i++) {\n const nsId = namespaceIds[i];\n const config = configuredNamespaces.get(nsId);\n\n // Include all requested namespaces, even if they don't exist yet\n const ref: NamespaceReference = {\n namespace: nsId,\n priority: namespaceIds.length - i, // Earlier = higher priority\n searchable: config?.active !== false,\n writable: i === 0, // Only first is writable\n };\n\n references.push(ref);\n readable.push(nsId);\n\n if (!primary) {\n primary = nsId;\n }\n }\n\n if (!primary) {\n primary = defaultNamespace;\n readable.push(defaultNamespace);\n }\n\n return { primary, readable, references };\n },\n\n async listAll(): Promise<NamespaceConfig[]> {\n const discovered = await provider.listNamespaces();\n const all = new Map<string, NamespaceConfig>();\n\n // Add configured namespaces\n for (const [id, config] of configuredNamespaces) {\n all.set(id, config);\n }\n\n // Add discovered namespaces\n for (const nsId of discovered) {\n if (!all.has(nsId)) {\n all.set(nsId, { id: nsId, name: nsId, active: true });\n }\n }\n\n return Array.from(all.values());\n },\n\n register(config: NamespaceConfig): void {\n configuredNamespaces.set(config.id, config);\n },\n\n getPrimary(): string {\n return defaultNamespace;\n },\n\n async exists(namespace: string): Promise<boolean> {\n return configuredNamespaces.has(namespace) ||\n await provider.namespaceExists(namespace);\n },\n };\n};\n"],"names":["createNamespaceResolver","options","provider","defaultNamespace","configuredNamespaces","Map","namespaces","ns","set","id","resolve","requested","namespaceIds","references","readable","primary","i","length","nsId","config","get","ref","namespace","priority","searchable","active","writable","push","listAll","discovered","listNamespaces","all","has","name","Array","from","values","register","getPrimary","exists","namespaceExists"],"mappings":"AAyCO,MAAMA,0BAA0B,CACnCC,OAAAA,GAAAA;AAEA,IAAA,MAAM,EAAEC,QAAQ,EAAEC,gBAAAA,GAAmB,UAAU,EAAE,GAAGF,OAAAA;AACpD,IAAA,MAAMG,uBAAuB,IAAIC,GAAAA,EAAAA;;IAGjC,IAAIJ,OAAAA,CAAQK,UAAU,EAAE;AACpB,QAAA,KAAK,MAAMC,EAAAA,IAAMN,OAAAA,CAAQK,UAAU,CAAE;AACjCF,YAAAA,oBAAAA,CAAqBI,GAAG,CAACD,EAAAA,CAAGE,EAAE,EAAEF,EAAAA,CAAAA;AACpC,QAAA;AACJ,IAAA;IAEA,OAAO;AACH,QAAA,M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AC1C,QAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Configuration for a namespace.
3
+ */
4
+ export interface NamespaceConfig {
5
+ /** Unique identifier for the namespace */
6
+ id: string;
7
+ /** Human-readable name */
8
+ name: string;
9
+ /** Description of what this namespace contains */
10
+ description?: string;
11
+ /** Parent namespace (for hierarchy) */
12
+ parent?: string;
13
+ /** Tools/projects that use this namespace */
14
+ consumers?: string[];
15
+ /** Whether this namespace is active */
16
+ active?: boolean;
17
+ }
18
+ /**
19
+ * Reference to a namespace with resolution metadata.
20
+ */
21
+ export interface NamespaceReference {
22
+ /** The namespace ID */
23
+ namespace: string;
24
+ /** Priority for merging (higher = preferred) */
25
+ priority: number;
26
+ /** Whether to include in searches */
27
+ searchable: boolean;
28
+ /** Whether writes go to this namespace */
29
+ writable: boolean;
30
+ }
31
+ /**
32
+ * Result of namespace resolution.
33
+ */
34
+ export interface NamespaceResolution {
35
+ /** Primary namespace for writes */
36
+ primary: string;
37
+ /** All namespaces to read from (in priority order) */
38
+ readable: string[];
39
+ /** Resolved namespace references */
40
+ references: NamespaceReference[];
41
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Overcontext - Schema-driven framework for context management
3
+ *
4
+ * This is a placeholder entry point that will be expanded in later steps.
5
+ */
6
+ export * from './schema';
7
+ export * from './storage';
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Metadata that overcontext manages automatically.
4
+ * Consumers don't need to define these.
5
+ */
6
+ export declare const EntityMetadataSchema: z.ZodObject<{
7
+ createdAt: z.ZodOptional<z.ZodDate>;
8
+ updatedAt: z.ZodOptional<z.ZodDate>;
9
+ createdBy: z.ZodOptional<z.ZodString>;
10
+ namespace: z.ZodOptional<z.ZodString>;
11
+ source: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>;
13
+ export type EntityMetadata = z.infer<typeof EntityMetadataSchema>;
14
+ /**
15
+ * The minimal contract every entity must satisfy.
16
+ * Consuming libraries extend this with their own fields.
17
+ */
18
+ export declare const BaseEntitySchema: z.ZodObject<{
19
+ id: z.ZodString;
20
+ name: z.ZodString;
21
+ type: z.ZodString;
22
+ notes: z.ZodOptional<z.ZodString>;
23
+ createdAt: z.ZodOptional<z.ZodDate>;
24
+ updatedAt: z.ZodOptional<z.ZodDate>;
25
+ createdBy: z.ZodOptional<z.ZodString>;
26
+ namespace: z.ZodOptional<z.ZodString>;
27
+ source: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strip>;
29
+ export type BaseEntity = z.infer<typeof BaseEntitySchema>;
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Metadata that overcontext manages automatically.
5
+ * Consumers don't need to define these.
6
+ */ const EntityMetadataSchema = z.object({
7
+ createdAt: z.date().optional(),
8
+ updatedAt: z.date().optional(),
9
+ createdBy: z.string().optional(),
10
+ namespace: z.string().optional(),
11
+ source: z.string().optional()
12
+ });
13
+ /**
14
+ * The minimal contract every entity must satisfy.
15
+ * Consuming libraries extend this with their own fields.
16
+ */ const BaseEntitySchema = z.object({
17
+ /** Unique identifier within the entity type (used as filename) */ id: z.string().min(1),
18
+ /** Human-readable name (used for display and search) */ name: z.string().min(1),
19
+ /** Entity type discriminator (must be a string literal in extensions) */ type: z.string().min(1),
20
+ /** Optional notes - common enough to include in base */ notes: z.string().optional()
21
+ }).merge(EntityMetadataSchema);
22
+
23
+ export { BaseEntitySchema, EntityMetadataSchema };
24
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sources":["../../src/schema/base.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Metadata that overcontext manages automatically.\n * Consumers don't need to define these.\n */\nexport const EntityMetadataSchema = z.object({\n createdAt: z.date().optional(),\n updatedAt: z.date().optional(),\n createdBy: z.string().optional(), // Tool that created this entity\n namespace: z.string().optional(), // Which namespace this came from\n source: z.string().optional(), // File path or storage key\n});\n\nexport type EntityMetadata = z.infer<typeof EntityMetadataSchema>;\n\n/**\n * The minimal contract every entity must satisfy.\n * Consuming libraries extend this with their own fields.\n */\nexport const BaseEntitySchema = z.object({\n /** Unique identifier within the entity type (used as filename) */\n id: z.string().min(1),\n\n /** Human-readable name (used for display and search) */\n name: z.string().min(1),\n\n /** Entity type discriminator (must be a string literal in extensions) */\n type: z.string().min(1),\n\n /** Optional notes - common enough to include in base */\n notes: z.string().optional(),\n}).merge(EntityMetadataSchema);\n\nexport type BaseEntity = z.infer<typeof BaseEntitySchema>;\n"],"names":["EntityMetadataSchema","z","object","createdAt","date","optional","updatedAt","createdBy","string","namespace","source","BaseEntitySchema","id","min","name","type","notes","merge"],"mappings":";;AAEA;;;AAGC,IACM,MAAMA,oBAAAA,GAAuBC,CAAAA,CAAEC,MAAM,CAAC;IACzCC,SAAAA,EAAWF,CAAAA,CAAEG,IAAI,EAAA,CAAGC,QAAQ,EAAA;IAC5BC,SAAAA,EAAWL,CAAAA,CAAEG,IAAI,EAAA,CAAGC,QAAQ,EAAA;IAC5BE,SAAAA,EAAWN,CAAAA,CAAEO,MAAM,EAAA,CAAGH,QAAQ,EAAA;IAC9BI,SAAAA,EAAWR,CAAAA,CAAEO,MAAM,EAAA,CAAGH,QAAQ,EAAA;IAC9BK,MAAAA,EAAQT,CAAAA,CAAEO,MAAM,EAAA,CAAGH,QAAQ;AAC/B,CAAA;AAIA;;;AAGC,IACM,MAAMM,gBAAAA,GAAmBV,CAAAA,CAAEC,MAAM,CAAC;AACrC,uEACAU,EAAAA,EAAIX,CAAAA,CAAEO,MAAM,EAAA,CAAGK,GAAG,CAAC,CAAA,CAAA;AAEnB,6DACAC,IAAAA,EAAMb,CAAAA,CAAEO,MAAM,EAAA,CAAGK,GAAG,CAAC,CAAA,CAAA;AAErB,8EACAE,IAAAA,EAAMd,CAAAA,CAAEO,MAAM,EAAA,CAAGK,GAAG,CAAC,CAAA,CAAA;AAErB,6DACAG,KAAAA,EAAOf,CAAAA,CAAEO,MAAM,GAAGH,QAAQ;AAC9B,CAAA,CAAA,CAAGY,KAAK,CAACjB,oBAAAA;;;;"}
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ import { BaseEntity } from './base';
3
+ /**
4
+ * Type-safe builder for schema maps.
5
+ * Ensures type inference works correctly.
6
+ */
7
+ export type SchemaMapBuilder<T extends Record<string, z.ZodType<BaseEntity>>> = {
8
+ schemas: T;
9
+ types: {
10
+ [K in keyof T]: z.infer<T[K]>;
11
+ };
12
+ };
13
+ /**
14
+ * Create a schema map with proper type inference.
15
+ *
16
+ * @example
17
+ * const { schemas, types } = defineSchemas({
18
+ * person: PersonSchema,
19
+ * project: ProjectSchema,
20
+ * });
21
+ *
22
+ * type Person = typeof types.person; // Inferred from PersonSchema
23
+ */
24
+ export declare const defineSchemas: <T extends Record<string, z.ZodType<BaseEntity>>>(schemas: T) => SchemaMapBuilder<T>;
25
+ /**
26
+ * Helper to check if a schema extends BaseEntity properly.
27
+ */
28
+ export declare const isValidEntitySchema: (schema: z.ZodType<unknown>) => boolean;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Create a schema map with proper type inference.
3
+ *
4
+ * @example
5
+ * const { schemas, types } = defineSchemas({
6
+ * person: PersonSchema,
7
+ * project: ProjectSchema,
8
+ * });
9
+ *
10
+ * type Person = typeof types.person; // Inferred from PersonSchema
11
+ */ const defineSchemas = (schemas)=>{
12
+ return {
13
+ schemas,
14
+ types: {}
15
+ };
16
+ };
17
+ /**
18
+ * Helper to check if a schema extends BaseEntity properly.
19
+ */ const isValidEntitySchema = (schema)=>{
20
+ try {
21
+ // BaseEntitySchema allows extra fields, so we just need id, name, type
22
+ const result = schema.safeParse({
23
+ id: 'test',
24
+ name: 'Test',
25
+ type: 'test'
26
+ });
27
+ // If it fails, it might be because type is a literal
28
+ // Try without type and check if it has the base structure
29
+ if (!result.success) {
30
+ return false;
31
+ }
32
+ return true;
33
+ } catch {
34
+ return false;
35
+ }
36
+ };
37
+
38
+ export { defineSchemas, isValidEntitySchema };
39
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sources":["../../src/schema/builder.ts"],"sourcesContent":["import { z } from 'zod';\nimport { BaseEntity } from './base';\n\n/**\n * Type-safe builder for schema maps.\n * Ensures type inference works correctly.\n */\nexport type SchemaMapBuilder<T extends Record<string, z.ZodType<BaseEntity>>> = {\n schemas: T;\n types: { [K in keyof T]: z.infer<T[K]> };\n};\n\n/**\n * Create a schema map with proper type inference.\n * \n * @example\n * const { schemas, types } = defineSchemas({\n * person: PersonSchema,\n * project: ProjectSchema,\n * });\n * \n * type Person = typeof types.person; // Inferred from PersonSchema\n */\nexport const defineSchemas = <T extends Record<string, z.ZodType<BaseEntity>>>(\n schemas: T\n): SchemaMapBuilder<T> => {\n return {\n schemas,\n types: {} as { [K in keyof T]: z.infer<T[K]> },\n };\n};\n\n/**\n * Helper to check if a schema extends BaseEntity properly.\n */\nexport const isValidEntitySchema = (schema: z.ZodType<unknown>): boolean => {\n try {\n // BaseEntitySchema allows extra fields, so we just need id, name, type\n const result = schema.safeParse({\n id: 'test',\n name: 'Test',\n type: 'test',\n });\n // If it fails, it might be because type is a literal\n // Try without type and check if it has the base structure\n if (!result.success) {\n return false;\n }\n return true;\n } catch {\n return false;\n }\n};\n"],"names":["defineSchemas","schemas","types","isValidEntitySchema","schema","result","safeParse","id","name","type","success"],"mappings":"AAYA;;;;;;;;;;IAWO,MAAMA,aAAAA,GAAgB,CACzBC,OAAAA,GAAAA;IAEA,OAAO;AACHA,QAAAA,OAAAA;AACAC,QAAAA,KAAAA,EAAO;AACX,KAAA;AACJ;AAEA;;IAGO,MAAMC,mBAAAA,GAAsB,CAACC,MAAAA,GAAAA;IAChC,IAAI;;QAEA,MAAMC,MAAAA,GAASD,MAAAA,CAAOE,SAAS,CAAC;YAC5BC,EAAAA,EAAI,MAAA;YACJC,IAAAA,EAAM,MAAA;YACNC,IAAAA,EAAM;AACV,SAAA,CAAA;;;QAGA,IAAI,CAACJ,MAAAA,CAAOK,OAAO,EAAE;YACjB,OAAO,KAAA;AACX,QAAA;QACA,OAAO,IAAA;AACX,IAAA,CAAA,CAAE,OAAM;QACJ,OAAO,KAAA;AACX,IAAA;AACJ;;;;"}
@@ -0,0 +1,5 @@
1
+ export * from './base';
2
+ export * from './inference';
3
+ export * from './validation';
4
+ export * from './registry';
5
+ export * from './builder';
@@ -0,0 +1,49 @@
1
+ import { z } from 'zod';
2
+ import { BaseEntity } from './base';
3
+ /**
4
+ * A valid entity schema must extend BaseEntitySchema.
5
+ * The type field should be a literal (e.g., z.literal('person')).
6
+ */
7
+ export type EntitySchema<T extends BaseEntity = BaseEntity> = z.ZodType<T> & {
8
+ _input: T;
9
+ _output: T;
10
+ };
11
+ /**
12
+ * Helper to create a properly typed entity schema.
13
+ * Ensures the schema extends BaseEntitySchema.
14
+ */
15
+ export declare const createEntitySchema: <TType extends string, TExtension extends z.ZodRawShape>(typeName: TType, extension: TExtension) => z.ZodObject<(("createdAt" | "updatedAt" | "createdBy" | "namespace" | "source" | "type" | "id" | "name" | "notes") & ("type" | keyof TExtension) extends never ? {
16
+ id: z.ZodString;
17
+ name: z.ZodString;
18
+ type: z.ZodString;
19
+ notes: z.ZodOptional<z.ZodString>;
20
+ createdAt: z.ZodOptional<z.ZodDate>;
21
+ updatedAt: z.ZodOptional<z.ZodDate>;
22
+ createdBy: z.ZodOptional<z.ZodString>;
23
+ namespace: z.ZodOptional<z.ZodString>;
24
+ source: z.ZodOptional<z.ZodString>;
25
+ } & {
26
+ type: z.ZodLiteral<TType>;
27
+ } & TExtension : ({
28
+ id: z.ZodString;
29
+ name: z.ZodString;
30
+ type: z.ZodString;
31
+ notes: z.ZodOptional<z.ZodString>;
32
+ createdAt: z.ZodOptional<z.ZodDate>;
33
+ updatedAt: z.ZodOptional<z.ZodDate>;
34
+ createdBy: z.ZodOptional<z.ZodString>;
35
+ namespace: z.ZodOptional<z.ZodString>;
36
+ source: z.ZodOptional<z.ZodString>;
37
+ } extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends "type" | keyof TExtension ? never : K]: T_1[K]; } : never) & ({
38
+ type: z.ZodLiteral<TType>;
39
+ } & TExtension extends infer T_2 extends z.core.util.SomeObject ? { [K_1 in keyof T_2]: T_2[K_1]; } : never)) extends infer T ? { [k in keyof T]: T[k]; } : never, z.core.$strip>;
40
+ /**
41
+ * Extract the type literal from an entity schema.
42
+ */
43
+ export type EntityTypeFromSchema<T extends z.ZodType<BaseEntity>> = T extends z.ZodType<infer U> ? (U extends {
44
+ type: infer TType;
45
+ } ? TType : never) : never;
46
+ /**
47
+ * Extract the full entity type from a schema.
48
+ */
49
+ export type InferEntity<T extends z.ZodType<BaseEntity>> = z.infer<T>;
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ import { BaseEntitySchema } from './base.js';
3
+
4
+ /**
5
+ * Helper to create a properly typed entity schema.
6
+ * Ensures the schema extends BaseEntitySchema.
7
+ */ const createEntitySchema = (typeName, extension)=>{
8
+ return BaseEntitySchema.extend({
9
+ type: z.literal(typeName),
10
+ ...extension
11
+ });
12
+ };
13
+
14
+ export { createEntitySchema };
15
+ //# sourceMappingURL=inference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inference.js","sources":["../../src/schema/inference.ts"],"sourcesContent":["import { z } from 'zod';\nimport { BaseEntitySchema, BaseEntity } from './base';\n\n/**\n * A valid entity schema must extend BaseEntitySchema.\n * The type field should be a literal (e.g., z.literal('person')).\n */\nexport type EntitySchema<T extends BaseEntity = BaseEntity> = z.ZodType<T> & {\n _input: T;\n _output: T;\n};\n\n/**\n * Helper to create a properly typed entity schema.\n * Ensures the schema extends BaseEntitySchema.\n */\nexport const createEntitySchema = <\n TType extends string,\n TExtension extends z.ZodRawShape\n>(\n typeName: TType,\n extension: TExtension\n ) => {\n return BaseEntitySchema.extend({\n type: z.literal(typeName),\n ...extension,\n });\n};\n\n/**\n * Extract the type literal from an entity schema.\n */\nexport type EntityTypeFromSchema<T extends z.ZodType<BaseEntity>> =\n T extends z.ZodType<infer U> ? (U extends { type: infer TType } ? TType : never) : never;\n\n/**\n * Extract the full entity type from a schema.\n */\nexport type InferEntity<T extends z.ZodType<BaseEntity>> = z.infer<T>;\n"],"names":["createEntitySchema","typeName","extension","BaseEntitySchema","extend","type","z","literal"],"mappings":";;;AAYA;;;AAGC,IACM,MAAMA,kBAAAA,GAAqB,CAI1BC,QAAAA,EACAC,SAAAA,GAAAA;IAEJ,OAAOC,gBAAAA,CAAiBC,MAAM,CAAC;QAC3BC,IAAAA,EAAMC,CAAAA,CAAEC,OAAO,CAACN,QAAAA,CAAAA;AAChB,QAAA,GAAGC;AACP,KAAA,CAAA;AACJ;;;;"}
@@ -0,0 +1,74 @@
1
+ import { z } from 'zod';
2
+ import { BaseEntity } from './base';
3
+ import { ValidationResult } from './validation';
4
+ /**
5
+ * A map of entity type names to their Zod schemas.
6
+ */
7
+ export type SchemaMap = Record<string, z.ZodType<BaseEntity>>;
8
+ /**
9
+ * Options for schema registration.
10
+ */
11
+ export interface SchemaRegistrationOptions {
12
+ /** The type name (should match the schema's type literal) */
13
+ type: string;
14
+ /** The Zod schema for this entity type */
15
+ schema: z.ZodType<BaseEntity>;
16
+ /** Plural name for directory (e.g., 'people' for 'person') */
17
+ pluralName?: string;
18
+ /** Additional validation beyond schema */
19
+ customValidator?: (entity: BaseEntity) => ValidationResult<BaseEntity>;
20
+ }
21
+ /**
22
+ * Registered schema with metadata.
23
+ */
24
+ export interface RegisteredSchema {
25
+ type: string;
26
+ schema: z.ZodType<BaseEntity>;
27
+ pluralName: string;
28
+ customValidator?: (entity: BaseEntity) => ValidationResult<BaseEntity>;
29
+ }
30
+ /**
31
+ * Schema registry for managing entity schemas.
32
+ */
33
+ export interface SchemaRegistry {
34
+ /**
35
+ * Register a schema for an entity type.
36
+ */
37
+ register(options: SchemaRegistrationOptions): void;
38
+ /**
39
+ * Register multiple schemas at once.
40
+ */
41
+ registerAll(schemas: SchemaMap): void;
42
+ /**
43
+ * Get the schema for a type.
44
+ */
45
+ get(type: string): RegisteredSchema | undefined;
46
+ /**
47
+ * Check if a type is registered.
48
+ */
49
+ has(type: string): boolean;
50
+ /**
51
+ * Get all registered type names.
52
+ */
53
+ types(): string[];
54
+ /**
55
+ * Get the directory name for a type.
56
+ */
57
+ getDirectoryName(type: string): string | undefined;
58
+ /**
59
+ * Get the type from a directory name.
60
+ */
61
+ getTypeFromDirectory(directory: string): string | undefined;
62
+ /**
63
+ * Validate an entity against its registered schema.
64
+ */
65
+ validate<T extends BaseEntity>(entity: T): ValidationResult<T>;
66
+ /**
67
+ * Validate data as a specific type.
68
+ */
69
+ validateAs<T extends BaseEntity>(type: string, data: unknown): ValidationResult<T>;
70
+ }
71
+ /**
72
+ * Create a new schema registry.
73
+ */
74
+ export declare const createSchemaRegistry: () => SchemaRegistry;
@@ -0,0 +1,117 @@
1
+ import { validateEntity } from './validation.js';
2
+
3
+ /**
4
+ * Default plural name derivation.
5
+ */ const derivePluralName = (type)=>{
6
+ // Simple pluralization rules
7
+ if (type.endsWith('y')) {
8
+ return type.slice(0, -1) + 'ies';
9
+ }
10
+ if (type.endsWith('s') || type.endsWith('x') || type.endsWith('ch') || type.endsWith('sh')) {
11
+ return type + 'es';
12
+ }
13
+ return type + 's';
14
+ };
15
+ /**
16
+ * Create a new schema registry.
17
+ */ const createSchemaRegistry = ()=>{
18
+ const schemas = new Map();
19
+ const directoryToType = new Map();
20
+ const register = (options)=>{
21
+ const { type, schema, pluralName, customValidator } = options;
22
+ const plural = pluralName || derivePluralName(type);
23
+ const registered = {
24
+ type,
25
+ schema,
26
+ pluralName: plural,
27
+ customValidator
28
+ };
29
+ schemas.set(type, registered);
30
+ directoryToType.set(plural, type);
31
+ };
32
+ const registerAll = (schemaMap)=>{
33
+ for (const [type, schema] of Object.entries(schemaMap)){
34
+ register({
35
+ type,
36
+ schema
37
+ });
38
+ }
39
+ };
40
+ const get = (type)=>{
41
+ return schemas.get(type);
42
+ };
43
+ const has = (type)=>{
44
+ return schemas.has(type);
45
+ };
46
+ const types = ()=>{
47
+ return Array.from(schemas.keys());
48
+ };
49
+ const getDirectoryName = (type)=>{
50
+ var _schemas_get;
51
+ return (_schemas_get = schemas.get(type)) === null || _schemas_get === void 0 ? void 0 : _schemas_get.pluralName;
52
+ };
53
+ const getTypeFromDirectory = (directory)=>{
54
+ return directoryToType.get(directory);
55
+ };
56
+ const validate = (entity)=>{
57
+ const registered = schemas.get(entity.type);
58
+ if (!registered) {
59
+ return {
60
+ success: false,
61
+ errors: [
62
+ {
63
+ path: 'type',
64
+ message: `Unknown entity type: ${entity.type}`
65
+ }
66
+ ]
67
+ };
68
+ }
69
+ // Schema validation
70
+ const schemaResult = validateEntity(registered.schema, entity);
71
+ if (!schemaResult.success) {
72
+ return schemaResult;
73
+ }
74
+ // Custom validation
75
+ if (registered.customValidator) {
76
+ return registered.customValidator(entity);
77
+ }
78
+ return {
79
+ success: true,
80
+ data: entity
81
+ };
82
+ };
83
+ const validateAs = (type, data)=>{
84
+ const registered = schemas.get(type);
85
+ if (!registered) {
86
+ return {
87
+ success: false,
88
+ errors: [
89
+ {
90
+ path: 'type',
91
+ message: `Unknown entity type: ${type}`
92
+ }
93
+ ]
94
+ };
95
+ }
96
+ // Add type to data if missing (for convenience when loading from files)
97
+ const withType = typeof data === 'object' && data !== null ? {
98
+ ...data,
99
+ type
100
+ } : data;
101
+ return validateEntity(registered.schema, withType);
102
+ };
103
+ return {
104
+ register,
105
+ registerAll,
106
+ get,
107
+ has,
108
+ types,
109
+ getDirectoryName,
110
+ getTypeFromDirectory,
111
+ validate,
112
+ validateAs
113
+ };
114
+ };
115
+
116
+ export { createSchemaRegistry };
117
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sources":["../../src/schema/registry.ts"],"sourcesContent":["import { z } from 'zod';\nimport { BaseEntity } from './base';\nimport { validateEntity, ValidationResult } from './validation';\n\n/**\n * A map of entity type names to their Zod schemas.\n */\nexport type SchemaMap = Record<string, z.ZodType<BaseEntity>>;\n\n/**\n * Options for schema registration.\n */\nexport interface SchemaRegistrationOptions {\n /** The type name (should match the schema's type literal) */\n type: string;\n\n /** The Zod schema for this entity type */\n schema: z.ZodType<BaseEntity>;\n\n /** Plural name for directory (e.g., 'people' for 'person') */\n pluralName?: string;\n\n /** Additional validation beyond schema */\n customValidator?: (entity: BaseEntity) => ValidationResult<BaseEntity>;\n}\n\n/**\n * Registered schema with metadata.\n */\nexport interface RegisteredSchema {\n type: string;\n schema: z.ZodType<BaseEntity>;\n pluralName: string;\n customValidator?: (entity: BaseEntity) => ValidationResult<BaseEntity>;\n}\n\n/**\n * Schema registry for managing entity schemas.\n */\nexport interface SchemaRegistry {\n /**\n * Register a schema for an entity type.\n */\n register(options: SchemaRegistrationOptions): void;\n\n /**\n * Register multiple schemas at once.\n */\n registerAll(schemas: SchemaMap): void;\n\n /**\n * Get the schema for a type.\n */\n get(type: string): RegisteredSchema | undefined;\n\n /**\n * Check if a type is registered.\n */\n has(type: string): boolean;\n\n /**\n * Get all registered type names.\n */\n types(): string[];\n\n /**\n * Get the directory name for a type.\n */\n getDirectoryName(type: string): string | undefined;\n\n /**\n * Get the type from a directory name.\n */\n getTypeFromDirectory(directory: string): string | undefined;\n\n /**\n * Validate an entity against its registered schema.\n */\n validate<T extends BaseEntity>(entity: T): ValidationResult<T>;\n\n /**\n * Validate data as a specific type.\n */\n validateAs<T extends BaseEntity>(type: string, data: unknown): ValidationResult<T>;\n}\n\n/**\n * Default plural name derivation.\n */\nconst derivePluralName = (type: string): string => {\n // Simple pluralization rules\n if (type.endsWith('y')) {\n return type.slice(0, -1) + 'ies';\n }\n if (type.endsWith('s') || type.endsWith('x') || type.endsWith('ch') || type.endsWith('sh')) {\n return type + 'es';\n }\n return type + 's';\n};\n\n/**\n * Create a new schema registry.\n */\nexport const createSchemaRegistry = (): SchemaRegistry => {\n const schemas = new Map<string, RegisteredSchema>();\n const directoryToType = new Map<string, string>();\n\n const register = (options: SchemaRegistrationOptions): void => {\n const { type, schema, pluralName, customValidator } = options;\n\n const plural = pluralName || derivePluralName(type);\n\n const registered: RegisteredSchema = {\n type,\n schema,\n pluralName: plural,\n customValidator,\n };\n\n schemas.set(type, registered);\n directoryToType.set(plural, type);\n };\n\n const registerAll = (schemaMap: SchemaMap): void => {\n for (const [type, schema] of Object.entries(schemaMap)) {\n register({ type, schema });\n }\n };\n\n const get = (type: string): RegisteredSchema | undefined => {\n return schemas.get(type);\n };\n\n const has = (type: string): boolean => {\n return schemas.has(type);\n };\n\n const types = (): string[] => {\n return Array.from(schemas.keys());\n };\n\n const getDirectoryName = (type: string): string | undefined => {\n return schemas.get(type)?.pluralName;\n };\n\n const getTypeFromDirectory = (directory: string): string | undefined => {\n return directoryToType.get(directory);\n };\n\n const validate = <T extends BaseEntity>(entity: T): ValidationResult<T> => {\n const registered = schemas.get(entity.type);\n\n if (!registered) {\n return {\n success: false,\n errors: [{ path: 'type', message: `Unknown entity type: ${entity.type}` }],\n };\n }\n\n // Schema validation\n const schemaResult = validateEntity(registered.schema, entity);\n if (!schemaResult.success) {\n return schemaResult as ValidationResult<T>;\n }\n\n // Custom validation\n if (registered.customValidator) {\n return registered.customValidator(entity) as ValidationResult<T>;\n }\n\n return { success: true, data: entity };\n };\n\n const validateAs = <T extends BaseEntity>(\n type: string,\n data: unknown\n ): ValidationResult<T> => {\n const registered = schemas.get(type);\n\n if (!registered) {\n return {\n success: false,\n errors: [{ path: 'type', message: `Unknown entity type: ${type}` }],\n };\n }\n\n // Add type to data if missing (for convenience when loading from files)\n const withType = typeof data === 'object' && data !== null\n ? { ...data, type }\n : data;\n\n return validateEntity(registered.schema, withType) as ValidationResult<T>;\n };\n\n return {\n register,\n registerAll,\n get,\n has,\n types,\n getDirectoryName,\n getTypeFromDirectory,\n validate,\n validateAs,\n };\n};\n"],"names":["derivePluralName","type","endsWith","slice","createSchemaRegistry","schemas","Map","directoryToType","register","options","schema","pluralName","customValidator","plural","registered","set","registerAll","schemaMap","Object","entries","get","has","types","Array","from","keys","getDirectoryName","getTypeFromDirectory","directory","validate","entity","success","errors","path","message","schemaResult","validateEntity","data","validateAs","withType"],"mappings":";;AAsFA;;IAGA,MAAMA,mBAAmB,CAACC,IAAAA,GAAAA;;IAEtB,IAAIA,IAAAA,CAAKC,QAAQ,CAAC,GAAA,CAAA,EAAM;AACpB,QAAA,OAAOD,IAAAA,CAAKE,KAAK,CAAC,CAAA,EAAG,EAAC,CAAA,GAAK,KAAA;AAC/B,IAAA;AACA,IAAA,IAAIF,IAAAA,CAAKC,QAAQ,CAAC,GAAA,CAAA,IAAQD,KAAKC,QAAQ,CAAC,GAAA,CAAA,IAAQD,IAAAA,CAAKC,QAAQ,CAAC,IAAA,CAAA,IAASD,IAAAA,CAAKC,QAAQ,CAAC,IAAA,CAAA,EAAO;AACxF,QAAA,OAAOD,IAAAA,GAAO,IAAA;AAClB,IAAA;AACA,IAAA,OAAOA,IAAAA,GAAO,GAAA;AAClB,CAAA;AAEA;;UAGaG,oBAAAA,GAAuB,IAAA;AAChC,IAAA,MAAMC,UAAU,IAAIC,GAAAA,EAAAA;AACpB,IAAA,MAAMC,kBAAkB,IAAID,GAAAA,EAAAA;AAE5B,IAAA,MAAME,WAAW,CAACC,OAAAA,GAAAA;QACd,MAAM,EAAER,IAAI,EAAES,MAAM,EAAEC,UAAU,EAAEC,eAAe,EAAE,GAAGH,OAAAA;QAEtD,MAAMI,MAAAA,GAASF,cAAcX,gBAAAA,CAAiBC,IAAAA,CAAAA;AAE9C,QAAA,MAAMa,UAAAA,GAA+B;AACjCb,YAAAA,IAAAA;AACAS,YAAAA,MAAAA;YACAC,UAAAA,EAAYE,MAAAA;AACZD,YAAAA;AACJ,SAAA;QAEAP,OAAAA,CAAQU,GAAG,CAACd,IAAAA,EAAMa,UAAAA,CAAAA;QAClBP,eAAAA,CAAgBQ,GAAG,CAACF,MAAAA,EAAQZ,IAAAA,CAAA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ACAI,QAAAA,GAAAA;AACAC,QAAAA,GAAAA;AACAC,QAAAA,KAAAA;AACAI,QAAAA,gBAAAA;AACAC,QAAAA,oBAAAA;AACAE,QAAAA,QAAAA;AACAS,QAAAA;AACJ,KAAA;AACJ;;;;"}
@@ -0,0 +1,26 @@
1
+ import { z, ZodError } from 'zod';
2
+ import { BaseEntity } from './base';
3
+ export interface ValidationResult<T> {
4
+ success: boolean;
5
+ data?: T;
6
+ errors?: Array<{
7
+ path: string;
8
+ message: string;
9
+ }>;
10
+ }
11
+ /**
12
+ * Validate that an object satisfies at least the base entity contract.
13
+ */
14
+ export declare const validateBaseEntity: (data: unknown) => ValidationResult<BaseEntity>;
15
+ /**
16
+ * Validate data against a specific schema.
17
+ */
18
+ export declare const validateEntity: <T extends BaseEntity>(schema: z.ZodType<T>, data: unknown) => ValidationResult<T>;
19
+ /**
20
+ * Check if data extends the base entity (has id, name, type).
21
+ */
22
+ export declare const isBaseEntity: (data: unknown) => data is BaseEntity;
23
+ /**
24
+ * Format Zod errors into a readable message.
25
+ */
26
+ export declare const formatValidationErrors: (errors: ZodError) => string;
@@ -0,0 +1,51 @@
1
+ import { BaseEntitySchema } from './base.js';
2
+
3
+ /**
4
+ * Validate that an object satisfies at least the base entity contract.
5
+ */ const validateBaseEntity = (data)=>{
6
+ const result = BaseEntitySchema.safeParse(data);
7
+ if (result.success) {
8
+ return {
9
+ success: true,
10
+ data: result.data
11
+ };
12
+ }
13
+ return {
14
+ success: false,
15
+ errors: result.error.issues.map((e)=>({
16
+ path: e.path.join('.'),
17
+ message: e.message
18
+ }))
19
+ };
20
+ };
21
+ /**
22
+ * Validate data against a specific schema.
23
+ */ const validateEntity = (schema, data)=>{
24
+ const result = schema.safeParse(data);
25
+ if (result.success) {
26
+ return {
27
+ success: true,
28
+ data: result.data
29
+ };
30
+ }
31
+ return {
32
+ success: false,
33
+ errors: result.error.issues.map((e)=>({
34
+ path: e.path.join('.'),
35
+ message: e.message
36
+ }))
37
+ };
38
+ };
39
+ /**
40
+ * Check if data extends the base entity (has id, name, type).
41
+ */ const isBaseEntity = (data)=>{
42
+ return validateBaseEntity(data).success;
43
+ };
44
+ /**
45
+ * Format Zod errors into a readable message.
46
+ */ const formatValidationErrors = (errors)=>{
47
+ return errors.issues.map((e)=>`${e.path.join('.')}: ${e.message}`).join('; ');
48
+ };
49
+
50
+ export { formatValidationErrors, isBaseEntity, validateBaseEntity, validateEntity };
51
+ //# sourceMappingURL=validation.js.map