@asaidimu/anansi 1.3.3 → 1.4.1

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 (5) hide show
  1. package/index.cjs +45 -46
  2. package/index.d.cts +496 -903
  3. package/index.d.ts +496 -903
  4. package/index.js +45 -46
  5. package/package.json +5 -3
package/index.d.cts CHANGED
@@ -1,33 +1,129 @@
1
+ import * as _faker_js_faker from '@faker-js/faker';
1
2
  import { Faker } from '@faker-js/faker';
2
3
  import { QueryDSL, QueryFilter } from '@asaidimu/query';
3
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
- import { z } from 'zod';
5
+ import LightningFS from '@isomorphic-git/lightning-fs';
5
6
 
6
7
  /**
7
- * Schema-related interfaces
8
+ * hints.ts
9
+ *
10
+ * Defines type hints for generating form input controls based on schema field definitions.
11
+ * Each hint type corresponds to a specific input control, providing metadata for code generation.
12
+ */
13
+ /**
14
+ * Hints for generating a file input control.
15
+ */
16
+ type FileHint = {
17
+ type: "file";
18
+ label?: string;
19
+ embed?: boolean;
20
+ mimes?: string | string[];
21
+ size?: {
22
+ max?: number;
23
+ min?: number;
24
+ };
25
+ dimensions?: {
26
+ width: number;
27
+ height: number;
28
+ };
29
+ };
30
+ /**
31
+ * Hints for generating a text-based input control.
32
+ */
33
+ type TextHint = {
34
+ type: "text" | "email" | "tel" | "url" | "textarea";
35
+ label?: string;
36
+ placeholder?: string;
37
+ };
38
+ /**
39
+ * Hints for generating a secret input control (e.g., passwords, API keys).
40
+ */
41
+ type SecretHint = {
42
+ type: "secret";
43
+ label?: string;
44
+ placeholder?: string;
45
+ password?: boolean;
46
+ };
47
+ /**
48
+ * Hints for generating a number-based input control.
49
+ */
50
+ type NumberHint = {
51
+ type: "number" | "range";
52
+ label?: string;
53
+ step?: number;
54
+ };
55
+ /**
56
+ * Hints for generating a boolean input control.
57
+ */
58
+ type BooleanHint = {
59
+ type: "checkbox" | "radio";
60
+ label?: string;
61
+ radioLabels?: {
62
+ true: string;
63
+ false: string;
64
+ };
65
+ };
66
+ /**
67
+ * Hints for generating an enum input control.
68
+ */
69
+ type EnumHint = {
70
+ type: "select" | "radio";
71
+ label?: string;
72
+ };
73
+ /**
74
+ * Hints for generating an array input control.
75
+ */
76
+ type ArrayHint = {
77
+ type: "list";
78
+ label?: string;
79
+ itemHint?: {
80
+ type: string;
81
+ };
82
+ };
83
+ /**
84
+ * Hints for generating a set input control.
85
+ */
86
+ type SetHint = {
87
+ type: "tags";
88
+ label?: string;
89
+ itemHint?: {
90
+ type: string;
91
+ };
92
+ };
93
+ /**
94
+ * Hints for generating an object input control.
95
+ */
96
+ type ObjectHint = {
97
+ type: "group";
98
+ label?: string;
99
+ collapsible?: boolean;
100
+ };
101
+ /**
102
+ * Hints for generating a dynamic input control.
103
+ */
104
+ type DynamicHint = {
105
+ type: "text";
106
+ label?: string;
107
+ };
108
+ /**
109
+ * Union type for all possible input hints.
8
110
  */
111
+ type InputHint = FileHint | TextHint | SecretHint | NumberHint | BooleanHint | EnumHint | ArrayHint | SetHint | ObjectHint | DynamicHint;
9
112
 
10
113
  /**
11
- * Logical operators for constraints and partial indexes.
114
+ * Logical operators for combining constraints or index conditions.
12
115
  */
13
116
  type LogicalOperator = "and" | "or" | "not" | "nor" | "xor";
14
117
  /**
15
118
  * Basic field types supported by the schema system.
16
119
  */
17
- type FieldType = "string" | "number" | "boolean" | "array" | "object" | "dynamic";
120
+ type FieldType = "string" | "number" | "boolean" | "array" | "set" | "enum" | "object" | "record" | "dynamic";
18
121
  /**
19
122
  * Index types for optimizing different query patterns.
20
123
  */
21
124
  type IndexType = "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
22
125
  /**
23
- * Defines a predicate function for data validation.
24
- * @template T The type of the data object.
25
- * @template K The type of the field being validated.
26
- * @param {object} params - The parameters for the predicate.
27
- * @param {T} params.data - The data object being validated.
28
- * @param {keyof T} params.field - The field being validated.
29
- * @param {ConstraintParameters<K>} params.arguments - The constraint parameters.
30
- * @returns {boolean} True if the data is valid, false otherwise.
126
+ * Defines a predicate function for data validation, mapped to a PredicateMap at runtime.
31
127
  */
32
128
  type Predicate = <T, K extends FieldType = any>(params: {
33
129
  data: T;
@@ -35,21 +131,24 @@ type Predicate = <T, K extends FieldType = any>(params: {
35
131
  arguments: PredicateParameters<K>;
36
132
  }) => boolean;
37
133
  /**
38
- * A map of constraint names to predicate functions.
39
- * @template T The type of the data object.
134
+ * A map of predicate names to their validation functions, implemented by the runtime environment.
40
135
  */
41
136
  type PredicateMap = Record<string, Predicate>;
137
+ /**
138
+ * A map of function names to generic functions, used elsewhere in the system.
139
+ */
42
140
  type FunctionMap = Record<string, Function>;
43
- /** @deprecated */
141
+ /** @deprecated Use PredicateMap instead. */
44
142
  type ConstraintsMap = Record<string, Predicate>;
45
143
  /**
46
- * Supported constraint names.
47
- * @template T The type of the constraints map.
144
+ * Names of supported predicates, derived from a PredicateMap.
48
145
  */
49
146
  type PredicateName<T extends PredicateMap = any> = keyof T;
50
147
  /**
51
- * Constraint parameters based on field type.
52
- * @template T The field type.
148
+ * Parameters for predicates, tailored to each field type.
149
+ */
150
+ /**
151
+ * Parameters for predicates, tailored to each field type.
53
152
  */
54
153
  type PredicateParameters<T extends FieldType> = T extends "string" ? string | string[] | RegExp | {
55
154
  field: string;
@@ -58,146 +157,125 @@ type PredicateParameters<T extends FieldType> = T extends "string" ? string | st
58
157
  scale?: number;
59
158
  } | {
60
159
  field: string;
61
- } : T extends "boolean" ? boolean : T extends "array" ? number | {
160
+ } : T extends "boolean" ? boolean : T extends "array" | "set" ? number | {
62
161
  minItems: number;
63
162
  maxItems: number;
64
163
  } : T extends "object" ? {
65
164
  schema: Record<string, unknown>;
66
- } : never;
67
- /** @deprecated */
165
+ } : T extends "record" ? Record<string, unknown> : T extends "dynamic" ? any : never;
166
+ /** @deprecated Use PredicateParameters instead. */
68
167
  type ConstraintParameters<T extends FieldType> = PredicateParameters<T>;
69
168
  /**
70
- * Defines a constraint on a field.
71
- * @template T The field type.
169
+ * Defines a constraint on a field or schema, using a predicate for validation.
72
170
  */
73
171
  type Constraint<T extends FieldType> = {
74
172
  type?: "schema";
75
- /** The predicate function for the constraint */
76
173
  predicate: string;
77
- /** The field the constraint applies to */
78
174
  field?: keyof any;
79
- /** The parameters for the constraint. */
80
175
  parameters?: PredicateParameters<T>;
81
- /** The name of the constraint. */
82
176
  name: string;
83
- /** A description of the constraint. */
84
177
  description?: string;
85
- /** A custom error message for the constraint. */
86
178
  errorMessage?: string;
87
179
  };
88
180
  /**
89
- * Group of constraint rules with a logical operator.
90
- * @template T The field type.
181
+ * Groups multiple constraints with a logical operator for complex validation logic.
91
182
  */
92
183
  interface ConstraintGroup<T extends FieldType> {
93
- /** The name of the constraint. */
94
184
  name: string;
95
- /** The logical operator for the group (AND or OR). */
96
185
  operator: LogicalOperator;
97
- /** The rules in the group, which can be constraints or other constraint groups. */
98
186
  rules: Array<Constraint<T> | ConstraintGroup<T>>;
99
187
  }
100
188
  /**
101
- * Definition of a field within the schema.
102
- * @template T The type of the field.
189
+ * Collection of constraints or groups applied at the schema or nested level.
190
+ */
191
+ type SchemaConstraint<T extends FieldType> = Array<Constraint<T> | ConstraintGroup<T>>;
192
+ /**
193
+ * Defines a field within a schema, including its type, constraints, and nesting.
103
194
  */
104
195
  interface FieldDefinition<T> {
105
- /** The name of the field. */
106
196
  name: string;
107
- /** The type of the field. */
108
197
  type: FieldType;
109
- /** Whether the field is required. */
110
198
  required?: boolean;
111
- /** The constraints on the field. */
112
199
  constraints?: Constraint<any>[];
113
- /** The default value of the field. */
114
200
  default?: T;
115
- /** The type of items in an array field. */
201
+ values?: Array<unknown>;
116
202
  itemsType?: FieldType;
117
- /** The schema for nested objects. */
118
- nestedSchema?: Record<string, FieldDefinition<any>>;
119
- /** Whether the field is deprecated. */
203
+ /** Reference to a nested schema (mini-SchemaDefinition) with optional overrides. */
204
+ nestedSchema?: {
205
+ id: string;
206
+ constraints?: SchemaConstraint<any>;
207
+ indexes?: IndexDefinition[];
208
+ };
120
209
  deprecated?: boolean;
121
- /** A reference to another schema and field. */
122
210
  reference?: {
123
211
  schema: string;
124
212
  field: string;
125
213
  };
126
- /** A description of the field. */
127
214
  description?: string;
128
- /** Whether the field is unique. */
129
215
  unique?: boolean;
216
+ hint?: {
217
+ input: InputHint;
218
+ };
130
219
  }
131
220
  /**
132
- * Condition for partial indexes.
221
+ * Condition for partial indexes, allowing conditional indexing based on field values.
133
222
  */
134
223
  interface PartialIndexCondition {
135
- /** The logical operator for the condition. */
136
224
  operator: LogicalOperator;
137
- /** The field to which condition applies. */
138
225
  field: string;
139
- /** The value to compare against (optional). */
140
226
  value?: any;
141
- /** Nested conditions (optional). */
142
227
  conditions?: PartialIndexCondition[];
143
228
  }
144
229
  /**
145
- * Definition of an index.
230
+ * Defines an index for optimizing queries or enforcing uniqueness.
146
231
  */
147
232
  interface IndexDefinition {
148
- /** The fields included in the index. */
149
233
  fields: string[];
150
- /** The type of the index. */
151
234
  type: IndexType;
152
- /** Whether the index is unique. */
153
235
  unique?: boolean;
154
- /** A partial index condition. */
155
236
  partial?: PartialIndexCondition;
156
- /** A description of the index. */
157
237
  description?: string;
158
- /** Sorting order for the index */
159
238
  order?: "asc" | "desc";
160
- /** A name for the index. */
161
239
  name: string;
162
240
  }
163
241
  /**
164
- * Schema constraint definition.
165
- * @template T The field type.
242
+ * A mini-schema definition for reusable nested structures within a larger schema.
243
+ * Mirrors SchemaDefinition but omits top-level-only properties like version and migrations.
166
244
  */
167
- type SchemaConstraint<T extends FieldType> = Array<Constraint<T> | ConstraintGroup<T>>;
245
+ interface NestedSchemaDefinition {
246
+ name: string;
247
+ description?: string;
248
+ fields: Record<string, FieldDefinition<any>>;
249
+ indexes?: IndexDefinition[];
250
+ constraints?: SchemaConstraint<any>;
251
+ metadata?: Record<string, any>;
252
+ }
168
253
  /**
169
- * Complete schema definition.
254
+ * Defines a complete schema, intended as an atomic unit within a larger domain model.
170
255
  */
171
256
  interface SchemaDefinition {
172
- /** The name of the schema. */
173
257
  name: string;
174
- /** The version of the schema. */
175
258
  version: string;
176
- /** A description of the schema. */
177
259
  description?: string;
178
- /** The field definitions in the schema. */
179
260
  fields: Record<string, FieldDefinition<any>>;
180
- /** The indexes defined for the schema. */
261
+ /** Reusable nested schema definitions, now as mini-SchemaDefinitions. */
262
+ nestedSchemas: Record<string, NestedSchemaDefinition>;
181
263
  indexes?: IndexDefinition[];
182
- /** The constraints defined for the schema. */
183
264
  constraints?: SchemaConstraint<any>;
184
- /** Metadata associated with the schema. */
185
265
  metadata?: Record<string, any>;
186
- /** Dependencies of the schema. */
266
+ /** @deprecated Use dependencies in DomainModel instead. */
187
267
  dependencies?: string[];
188
- /** Migrations associated with the schema. */
189
268
  migrations?: Array<Migration<any>>;
190
- /** A Mock associated with the schema. */
191
- mock?: <T>(faker: Faker) => Generator<T, void, unknown>;
269
+ mock?: <T>(faker: typeof _faker_js_faker) => Generator<T, void, unknown>;
192
270
  }
193
271
  /**
194
- * Defines a change that can be made to a schema.
195
- * @template T The type of the field being changed.
272
+ * Defines a change that can be made to a schema during migration.
273
+ * Updated to support the new NestedSchemaDefinition structure.
196
274
  */
197
275
  type SchemaChange<T> = {
198
276
  type: "modifyProperty";
199
- id: keyof Omit<SchemaDefinition, "fields" | "indexes" | "constraints">;
200
- changes: Partial<Omit<SchemaDefinition, "fields" | "indexes" | "constraints">>;
277
+ id: keyof Omit<SchemaDefinition, "fields" | "indexes" | "constraints" | "nestedSchemas">;
278
+ changes: Partial<Omit<SchemaDefinition, "fields" | "indexes" | "constraints" | "nestedSchemas">>;
201
279
  } | {
202
280
  type: "addField";
203
281
  id: string;
@@ -209,6 +287,11 @@ type SchemaChange<T> = {
209
287
  type: "modifyField";
210
288
  id: string;
211
289
  changes: Partial<FieldDefinition<T>>;
290
+ nestedSchemaChanges?: {
291
+ id?: string;
292
+ constraints?: SchemaConstraint<any>;
293
+ indexes?: IndexDefinition[];
294
+ };
212
295
  } | {
213
296
  type: "addIndex";
214
297
  definition: IndexDefinition;
@@ -232,61 +315,49 @@ type SchemaChange<T> = {
232
315
  } | {
233
316
  type: "deprecateField";
234
317
  id: string;
318
+ } | {
319
+ type: "addNestedSchema";
320
+ id: string;
321
+ definition: NestedSchemaDefinition;
322
+ } | {
323
+ type: "removeNestedSchema";
324
+ id: string;
325
+ } | {
326
+ type: "modifyNestedSchema";
327
+ id: string;
328
+ changes: Partial<NestedSchemaDefinition>;
235
329
  };
236
330
  /**
237
- * Defines a transform function for data migration.
238
- * @template Initial The initial data type.
239
- * @template Next The transformed data type.
240
- * @param {Initial} data - The initial data.
241
- * @returns {Next | Promise<Next>} The transformed data or a promise that resolves to the transformed data.
331
+ * Defines a transform function for data migration between schema versions.
242
332
  */
243
333
  type TransformFunction<Initial, Next> = (data: Initial) => Next | Promise<Next>;
244
334
  /**
245
- * Represents a pair of transformations for data migration (forward and backward).
246
- * @template Initial The initial data type.
247
- * @template Next The transformed data type.
335
+ * Represents a pair of transformations for bidirectional data migration.
248
336
  */
249
337
  interface DataTransform<Initial, Next> {
250
- /** The forward transformation function. */
251
338
  forward: TransformFunction<Initial, Next>;
252
- /** The backward transformation function. */
253
339
  backward: TransformFunction<Next, Initial>;
254
340
  }
255
341
  /**
256
- * Defines a migration, which consists of a series of schema changes and data transforms.
257
- * Each migration is a set of atomic changes that can be applied in a single operation.
258
- * @template T The type of the data being migrated.
342
+ * Defines a migration, consisting of schema changes and data transforms.
259
343
  */
260
344
  interface Migration<T> {
261
- /** A unique identifier for the migration. */
262
345
  id: string;
263
- /** the schema version for which this migration is applicable */
264
346
  schemaVersion: string;
265
- /** A list of schema changes to be applied in the migration. */
266
347
  changes: SchemaChange<T>[];
267
- /** A description of what the migration does. */
268
348
  description: string;
269
- /** The current status of the migration. */
270
349
  status: "pending" | "applied" | "failed";
271
- /** An optional list of schema changes to revert the migration. */
272
350
  rollback?: SchemaChange<T>[];
273
- /**
274
- * A checksum/string/url representing the js file exporting
275
- * the data transforms for this migration.
276
- * Each transform file exports a `DataTransform` object.
277
- */
278
351
  transform: string | DataTransform<any, any>;
279
- /** A timestamp for when the migration was created (in ISO 8601 format). */
280
352
  createdAt: string;
281
- /** @deprecated An optional list of migration IDs that must be applied before this one. */
353
+ /** @deprecated Use dependencies in DomainModel instead. */
282
354
  dependencies?: string[];
283
- /**
284
- * A checksum to ensure the integrity of the migration.
285
- * This is the hash of the stringified/minified version of this object,
286
- * excluding the `checksum` field itself (to avoid circular dependencies).
287
- */
288
355
  checksum: string;
289
356
  }
357
+ /**
358
+ * Generator type for mock data functions (used with Faker).
359
+ */
360
+ type Generator<T, TReturn, TNext> = Iterator<T, TReturn, TNext>;
290
361
 
291
362
  /**
292
363
  * Defines the interface for a migration engine.
@@ -570,6 +641,23 @@ interface SchemaMigrationHelper {
570
641
  * @param changes The changes to apply to the constraint.
571
642
  */
572
643
  modifyConstraint(constraintName: string, changes: Partial<Constraint<any>>): void;
644
+ /**
645
+ * Adds a new nested schema to the schema.
646
+ * @param {string} schemaId - The ID of the nested schema to add.
647
+ * @param {NestedSchemaDefinition} nestedDefinition - The definition of the nested schema to add.
648
+ */
649
+ addNestedSchema(schemaId: string, nestedDefinition: NestedSchemaDefinition): void;
650
+ /**
651
+ * Removes a nested schema from the schema.
652
+ * @param {string} schemaId - The ID of the nested schema to remove.
653
+ */
654
+ removeNestedSchema(schemaId: string): void;
655
+ /**
656
+ * Modifies an existing nested schema in the schema.
657
+ * @param {string} schemaId - The ID of the nested schema to modify.
658
+ * @param {Partial<NestedSchemaDefinition>} changes - The changes to apply to the nested schema.
659
+ */
660
+ modifyNestedSchema(schemaId: string, changes: Partial<NestedSchemaDefinition>): void;
573
661
  /**
574
662
  * Returns the list of changes made through this helper.
575
663
  * @returns An array of schema changes.
@@ -795,45 +883,307 @@ type RegistryLock = {
795
883
  updated: string;
796
884
  hashes: [filepath: string, filehash: string][];
797
885
  };
798
- interface SchemaRegistry {
799
- /** Initialize a new registry */
886
+ interface SchemaRegistryInterface {
887
+ /** Initializes the repository **/
800
888
  init(): Promise<void>;
801
- /** Clone an existing registry from a remote source */
802
- clone(): Promise<void>;
803
889
  /** Create a new schema version */
804
- create(schema: SchemaDefinition): Promise<void>;
890
+ create(_: {
891
+ schema: SchemaDefinition;
892
+ }): Promise<void>;
805
893
  /** Update an existing schema version */
806
- update(schema: SchemaDefinition): Promise<void>;
894
+ update(_: {
895
+ schema: SchemaDefinition;
896
+ }): Promise<void>;
807
897
  /** Delete a schema and its associated branch */
808
- delete(name: string): Promise<void>;
898
+ delete(_: {
899
+ name: string;
900
+ }): Promise<void>;
809
901
  /** List all schemas with their latest version */
810
902
  list(): Promise<{
811
903
  name: string;
812
904
  version: string;
813
905
  }[]>;
814
906
  /** Retrieve schema definition for a specific version (or latest if no version is provided) */
815
- schema(name: string, version?: string, migrations?: boolean): Promise<SchemaDefinition | null>;
907
+ schema(_: {
908
+ name: string;
909
+ version?: string;
910
+ migrations?: boolean;
911
+ }): Promise<SchemaDefinition | null>;
816
912
  /** Get schema statistics (returns the full SchemaIndex) */
817
- stats(schema?: string): Promise<SchemaIndex | RegistryMetadata>;
913
+ stats(_: {
914
+ schema?: string;
915
+ }): Promise<SchemaIndex | RegistryMetadata>;
818
916
  /** Regenerate index & lockfile, then push changes */
819
917
  sync(): Promise<void>;
820
- /** Retrieve all predicate names required by a specific schema version (or latest if no version is provided) */
821
- predicates(name: string, version?: string): Promise<string[]>;
822
918
  /** Retrieve all migrations for a specific schema version (or latest if no version is provided) */
823
- migrations(name: string, version?: string): Promise<Array<Migration<any>>>;
919
+ migrations(_: {
920
+ name: string;
921
+ version?: string;
922
+ }): Promise<Array<Migration<any>>>;
824
923
  /** Retrieve the full history of a schema */
825
- history(name: string): Promise<SchemaDefinition[]>;
924
+ history(_: {
925
+ name: string;
926
+ }): Promise<SchemaDefinition[]>;
826
927
  }
827
928
 
828
929
  /**
829
- * Creates and returns a new SchemaRegistry instance.
830
- * @returns {Promise<SchemaRegistry>} A promise that resolves to the SchemaRegistry instance.
930
+ * Interface for interacting with a remotely hosted repository (e.g., GitHub, GitLab).
831
931
  */
832
- declare function createRegistry(credentials: {
833
- username: string;
834
- password: string;
835
- repository: string;
836
- }, dir?: string, proxy?: string): Promise<SchemaRegistry>;
932
+ interface RemoteRepository {
933
+ /**
934
+ * Creates a new repository on the remote service.
935
+ * @param options.name - The name of the repository.
936
+ * @param options.private - Whether the repository should be private (default: false).
937
+ * @returns A promise resolving to the repository's authenticated URL (e.g., "https://username:token@github.com/username/repo.git").
938
+ * @param options
939
+ */
940
+ create(options: {
941
+ name: string;
942
+ private?: boolean;
943
+ }): Promise<RemoteRepository>;
944
+ /**
945
+ * Checks if a repository exists on the remote service.
946
+ * @param options - Repository lookup details.
947
+ * @param options.name - The name of the repository.
948
+ * @returns A promise resolving to true if the repository exists, false otherwise.
949
+ */
950
+ exists({ name }: {
951
+ name: string;
952
+ }): Promise<boolean>;
953
+ /**
954
+ * Deletes a repository on the remote service.
955
+ */
956
+ remove(): Promise<void>;
957
+ /**
958
+ * Returns a properly formatted authenticated URL for a specific repository.
959
+ * @returns A string representing the auth-enabled URL (e.g., "https://username:token@github.com/username/repo.git").
960
+ */
961
+ authURL(): string;
962
+ /**
963
+ * Returns the plain URL to this repository.
964
+ * @returns A string representing the repository URL (e.g., "https://github.com/username/repo.git").
965
+ * @throws RemoteRepositoryError if no repository is set.
966
+ */
967
+ url(): string;
968
+ credentials(): {
969
+ username: string;
970
+ password: string;
971
+ };
972
+ }
973
+
974
+ declare function createGitSchemaRegistry(rootDir?: string, options?: {
975
+ remote?: RemoteRepository;
976
+ mainBranch?: string;
977
+ createRemote?: boolean;
978
+ author?: {
979
+ name: string;
980
+ email: string;
981
+ };
982
+ proxy?: string;
983
+ cacheTtl?: number;
984
+ }): Promise<SchemaRegistryInterface>;
985
+
986
+ /**
987
+ * Implementation of a schema registry using an in-memory LightningFS.
988
+ * Combines refined filesystem management with original serialization for functions and mocks.
989
+ */
990
+ declare class SchemaRegistry implements SchemaRegistryInterface {
991
+ /** In-memory filesystem instance for storing registry data. */
992
+ fs: LightningFS;
993
+ /** Promise-based API for asynchronous filesystem operations. */
994
+ fsp: LightningFS.PromisifiedFS;
995
+ /** Root directory path in the filesystem (e.g., '/registry'). */
996
+ rootDir: string;
997
+ /**
998
+ * Constructs a new SchemaRegistryImpl instance.
999
+ * @param rootDir - The root directory for the registry (defaults to '/registry').
1000
+ */
1001
+ constructor(rootDir?: string);
1002
+ /**
1003
+ * Ensures the registry is initialized with base files if they don't exist.
1004
+ * Implements refined conditional initialization for idempotency.
1005
+ */
1006
+ init(): Promise<void>;
1007
+ /**
1008
+ * Creates a new schema in the registry.
1009
+ * @param params - Object containing the schema definition.
1010
+ * @throws Error if schema name or version is missing, or if schema already exists.
1011
+ */
1012
+ create({ schema }: {
1013
+ schema: SchemaDefinition;
1014
+ }): Promise<void>;
1015
+ /**
1016
+ * Updates an existing schema in the registry.
1017
+ * @param params - Object containing the updated schema definition.
1018
+ * @throws Error if schema name or version is missing, or if schema doesn't exist.
1019
+ */
1020
+ update({ schema }: {
1021
+ schema: SchemaDefinition;
1022
+ }): Promise<void>;
1023
+ /**
1024
+ * Saves a schema (create or update) with serialization and metadata updates.
1025
+ * @param schema - The schema definition to save.
1026
+ * @param action - Whether this is a create or update operation.
1027
+ * @private - Internal method to reduce duplication in create/update.
1028
+ */
1029
+ private saveSchema;
1030
+ /**
1031
+ * Deletes a schema and all its associated data from the registry.
1032
+ * Implements refined full filesystem cleanup.
1033
+ * @param params - Object containing the schema name to delete.
1034
+ * @throws Error if schema doesn't exist.
1035
+ */
1036
+ delete({ name }: {
1037
+ name: string;
1038
+ }): Promise<void>;
1039
+ /**
1040
+ * Lists all schemas in the registry with their latest versions.
1041
+ * @returns Array of schema names and versions.
1042
+ */
1043
+ list(): Promise<{
1044
+ name: string;
1045
+ version: string;
1046
+ }[]>;
1047
+ /**
1048
+ * Retrieves a schema definition, optionally with a specific version and migrations.
1049
+ * Incorporates original serialization for mocks.
1050
+ * @param params - Object with schema name, optional version, and migrations flag.
1051
+ * @returns Schema definition or null if not found.
1052
+ */
1053
+ schema({ name, version, migrations, }: {
1054
+ name: string;
1055
+ version?: string;
1056
+ migrations?: boolean;
1057
+ }): Promise<SchemaDefinition | null>;
1058
+ /**
1059
+ * Retrieves statistics for a specific schema or the entire registry.
1060
+ * @param params - Optional schema name to get SchemaIndex instead of RegistryMetadata.
1061
+ * @returns SchemaIndex or RegistryMetadata.
1062
+ * @throws Error if specific schema stats requested but schema not found.
1063
+ */
1064
+ stats({ schema, }: {
1065
+ schema?: string;
1066
+ }): Promise<SchemaIndex | RegistryMetadata>;
1067
+ /**
1068
+ * Synchronizes the registry by updating the lockfile with current file hashes.
1069
+ * Implements refined sync behavior.
1070
+ */
1071
+ sync(): Promise<void>;
1072
+ /**
1073
+ * Retrieves migrations for a schema up to a specified version.
1074
+ * Incorporates original serialization for migration transforms.
1075
+ * @param params - Object with schema name and optional version.
1076
+ * @returns Array of migrations, sorted by version.
1077
+ */
1078
+ migrations({ name, version, }: {
1079
+ name: string;
1080
+ version?: string;
1081
+ }): Promise<Array<Migration<any>>>;
1082
+ /**
1083
+ * Retrieves the version history of a schema.
1084
+ * Incorporates original serialization for mocks and migrations.
1085
+ * @param params - Object with schema name.
1086
+ * @returns Array of schema definitions for each version.
1087
+ */
1088
+ history({ name }: {
1089
+ name: string;
1090
+ }): Promise<SchemaDefinition[]>;
1091
+ /**
1092
+ * Processes and stores migrations with serialization of transforms.
1093
+ * Adopts original's approach to handling executable transforms.
1094
+ * @param schemaDir - Directory path for the schema.
1095
+ * @param schema - Schema definition containing migrations.
1096
+ * @returns Array of migration metadata.
1097
+ * @private
1098
+ */
1099
+ private processAndStoreMigrations;
1100
+ /**
1101
+ * Serializes a schema definition, handling mocks as per original.
1102
+ * @param schema - Schema definition to serialize.
1103
+ * @returns JSON string of serialized schema.
1104
+ * @private
1105
+ */
1106
+ private serializeSchema;
1107
+ /**
1108
+ * Deserializes a schema content object, restoring mocks as per original.
1109
+ * @param schemaContent - Raw schema content from JSON.
1110
+ * @returns Deserialized schema definition.
1111
+ * @private
1112
+ */
1113
+ private deserializeSchema;
1114
+ /**
1115
+ * Deserializes a migration content object, restoring transforms as per original.
1116
+ * @param content - Raw migration content from JSON.
1117
+ * @returns Deserialized migration object.
1118
+ * @private
1119
+ */
1120
+ private deserializeMigration;
1121
+ /**
1122
+ * Writes the schema file to the filesystem.
1123
+ * @param schemaDir - Directory path for the schema.
1124
+ * @param content - Serialized schema content.
1125
+ * @returns Path to the written schema file.
1126
+ * @private
1127
+ */
1128
+ private writeSchemaFile;
1129
+ /**
1130
+ * Updates the schema index with new version history and migrations.
1131
+ * @param schemaDir - Directory path for the schema.
1132
+ * @param schema - Schema definition being saved.
1133
+ * @param schemaHash - Hash of the schema content.
1134
+ * @param migrations - Processed migration metadata.
1135
+ * @param action - Whether this is a create or update operation.
1136
+ * @private
1137
+ */
1138
+ private updateIndex;
1139
+ /**
1140
+ * Updates the registry metadata with schema information.
1141
+ * @param schema - Schema definition being saved.
1142
+ * @param action - Whether this is a create or update operation.
1143
+ * @private
1144
+ */
1145
+ private updateRegistryMetadata;
1146
+ /**
1147
+ * Reads the registry metadata from the filesystem.
1148
+ * @returns Parsed RegistryMetadata object.
1149
+ * @private
1150
+ */
1151
+ private readRegistryMetadata;
1152
+ /**
1153
+ * Writes the registry metadata to the filesystem.
1154
+ * @param metadata - RegistryMetadata object to write.
1155
+ * @private
1156
+ */
1157
+ private writeRegistryMetadata;
1158
+ /**
1159
+ * Reads the schema index from the filesystem.
1160
+ * @param name - Name of the schema.
1161
+ * @returns Parsed SchemaIndex object.
1162
+ * @throws Error if schema index not found.
1163
+ * @private
1164
+ */
1165
+ private readSchemaIndex;
1166
+ /**
1167
+ * Checks if a file exists in the filesystem.
1168
+ * @param path - Path to check.
1169
+ * @returns True if file exists, false otherwise.
1170
+ * @private
1171
+ */
1172
+ fileExists(path: string): Promise<boolean>;
1173
+ /**
1174
+ * Recursively removes a directory and its contents.
1175
+ * @param path - Directory path to remove.
1176
+ * @private
1177
+ */
1178
+ private rmdirRecursive;
1179
+ /**
1180
+ * Lists all files recursively in a directory.
1181
+ * @param path - Directory path to scan.
1182
+ * @returns Array of file paths.
1183
+ * @private
1184
+ */
1185
+ private listFilesRecursive;
1186
+ }
837
1187
 
838
1188
  /**
839
1189
  * @fileoverview Provides a MigrationEngine class that handles schema migrations,
@@ -1062,765 +1412,10 @@ declare class MigrationEngine {
1062
1412
  * Helper for building schema migrations with forward and rollback changes.
1063
1413
  * @template T The type of data associated with the schema.
1064
1414
  * @param {Readonly<SchemaDefinition>} schema - The original schema to base the migration on.
1065
- * @returns {Object} An object with methods to build migration changes and retrieve the changes.
1415
+ * @returns {SchemaMigrationHelper} An object with methods to build migration changes and retrieve the changes.
1066
1416
  */
1067
1417
  declare const createSchemaMigrationHelper: <T>(schema: Readonly<SchemaDefinition>) => SchemaMigrationHelper;
1068
1418
 
1069
- declare const MigrationSchema: z.ZodObject<{
1070
- id: z.ZodString;
1071
- schemaVersion: z.ZodString;
1072
- changes: z.ZodArray<z.ZodUnion<[z.ZodObject<{
1073
- type: z.ZodLiteral<"addField">;
1074
- id: z.ZodString;
1075
- definition: any;
1076
- }, "strip", z.ZodTypeAny, {
1077
- type: "addField";
1078
- id: string;
1079
- definition?: any;
1080
- }, {
1081
- type: "addField";
1082
- id: string;
1083
- definition?: any;
1084
- }>, z.ZodObject<{
1085
- type: z.ZodLiteral<"removeField">;
1086
- id: z.ZodString;
1087
- }, "strip", z.ZodTypeAny, {
1088
- type: "removeField";
1089
- id: string;
1090
- }, {
1091
- type: "removeField";
1092
- id: string;
1093
- }>, z.ZodObject<{
1094
- type: z.ZodLiteral<"modifyField">;
1095
- id: z.ZodString;
1096
- changes: any;
1097
- }, "strip", z.ZodTypeAny, {
1098
- type: "modifyField";
1099
- id: string;
1100
- changes?: any;
1101
- }, {
1102
- type: "modifyField";
1103
- id: string;
1104
- changes?: any;
1105
- }>, z.ZodObject<{
1106
- type: z.ZodLiteral<"addIndex">;
1107
- definition: z.ZodObject<{
1108
- fields: z.ZodArray<z.ZodString, "many">;
1109
- type: z.ZodEnum<["normal", "unique", "btree", "hash", "spatial", "fulltext", "gi", "expression", "composite"]>;
1110
- unique: z.ZodOptional<z.ZodBoolean>;
1111
- partial: z.ZodOptional<z.ZodType<any, z.ZodTypeDef, any>>;
1112
- description: z.ZodOptional<z.ZodString>;
1113
- order: z.ZodOptional<z.ZodEnum<["asc", "desc"]>>;
1114
- name: z.ZodOptional<z.ZodString>;
1115
- }, "strip", z.ZodTypeAny, {
1116
- fields: string[];
1117
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1118
- unique?: boolean | undefined;
1119
- name?: string | undefined;
1120
- description?: string | undefined;
1121
- partial?: any;
1122
- order?: "asc" | "desc" | undefined;
1123
- }, {
1124
- fields: string[];
1125
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1126
- unique?: boolean | undefined;
1127
- name?: string | undefined;
1128
- description?: string | undefined;
1129
- partial?: any;
1130
- order?: "asc" | "desc" | undefined;
1131
- }>;
1132
- }, "strip", z.ZodTypeAny, {
1133
- type: "addIndex";
1134
- definition: {
1135
- fields: string[];
1136
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1137
- unique?: boolean | undefined;
1138
- name?: string | undefined;
1139
- description?: string | undefined;
1140
- partial?: any;
1141
- order?: "asc" | "desc" | undefined;
1142
- };
1143
- }, {
1144
- type: "addIndex";
1145
- definition: {
1146
- fields: string[];
1147
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1148
- unique?: boolean | undefined;
1149
- name?: string | undefined;
1150
- description?: string | undefined;
1151
- partial?: any;
1152
- order?: "asc" | "desc" | undefined;
1153
- };
1154
- }>, z.ZodObject<{
1155
- type: z.ZodLiteral<"removeIndex">;
1156
- name: z.ZodString;
1157
- }, "strip", z.ZodTypeAny, {
1158
- name: string;
1159
- type: "removeIndex";
1160
- }, {
1161
- name: string;
1162
- type: "removeIndex";
1163
- }>, z.ZodObject<{
1164
- type: z.ZodLiteral<"modifyIndex">;
1165
- name: z.ZodString;
1166
- changes: z.ZodObject<{
1167
- fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1168
- type: z.ZodOptional<z.ZodEnum<["normal", "unique", "btree", "hash", "spatial", "fulltext", "gi", "expression", "composite"]>>;
1169
- unique: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
1170
- partial: z.ZodOptional<z.ZodOptional<z.ZodType<any, z.ZodTypeDef, any>>>;
1171
- description: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1172
- order: z.ZodOptional<z.ZodOptional<z.ZodEnum<["asc", "desc"]>>>;
1173
- name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1174
- }, "strip", z.ZodTypeAny, {
1175
- unique?: boolean | undefined;
1176
- fields?: string[] | undefined;
1177
- name?: string | undefined;
1178
- description?: string | undefined;
1179
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1180
- partial?: any;
1181
- order?: "asc" | "desc" | undefined;
1182
- }, {
1183
- unique?: boolean | undefined;
1184
- fields?: string[] | undefined;
1185
- name?: string | undefined;
1186
- description?: string | undefined;
1187
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1188
- partial?: any;
1189
- order?: "asc" | "desc" | undefined;
1190
- }>;
1191
- }, "strip", z.ZodTypeAny, {
1192
- name: string;
1193
- type: "modifyIndex";
1194
- changes: {
1195
- unique?: boolean | undefined;
1196
- fields?: string[] | undefined;
1197
- name?: string | undefined;
1198
- description?: string | undefined;
1199
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1200
- partial?: any;
1201
- order?: "asc" | "desc" | undefined;
1202
- };
1203
- }, {
1204
- name: string;
1205
- type: "modifyIndex";
1206
- changes: {
1207
- unique?: boolean | undefined;
1208
- fields?: string[] | undefined;
1209
- name?: string | undefined;
1210
- description?: string | undefined;
1211
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1212
- partial?: any;
1213
- order?: "asc" | "desc" | undefined;
1214
- };
1215
- }>, z.ZodObject<{
1216
- type: z.ZodLiteral<"addConstraint">;
1217
- constraint: z.ZodUnion<[z.ZodObject<{
1218
- type: z.ZodOptional<z.ZodString>;
1219
- name: z.ZodString;
1220
- predicate: z.ZodOptional<z.ZodString>;
1221
- parameters: z.ZodOptional<z.ZodType<(params: any) => boolean, z.ZodTypeDef, (params: any) => boolean>>;
1222
- description: z.ZodOptional<z.ZodString>;
1223
- field: z.ZodOptional<z.ZodString>;
1224
- errorMessage: z.ZodOptional<z.ZodString>;
1225
- }, "strip", z.ZodTypeAny, {
1226
- name: string;
1227
- description?: string | undefined;
1228
- type?: string | undefined;
1229
- predicate?: string | undefined;
1230
- field?: string | undefined;
1231
- parameters?: ((params: any) => boolean) | undefined;
1232
- errorMessage?: string | undefined;
1233
- }, {
1234
- name: string;
1235
- description?: string | undefined;
1236
- type?: string | undefined;
1237
- predicate?: string | undefined;
1238
- field?: string | undefined;
1239
- parameters?: ((params: any) => boolean) | undefined;
1240
- errorMessage?: string | undefined;
1241
- }>, any]>;
1242
- }, "strip", z.ZodTypeAny, {
1243
- type: "addConstraint";
1244
- constraint?: any;
1245
- }, {
1246
- type: "addConstraint";
1247
- constraint?: any;
1248
- }>, z.ZodObject<{
1249
- type: z.ZodLiteral<"removeConstraint">;
1250
- name: z.ZodString;
1251
- }, "strip", z.ZodTypeAny, {
1252
- name: string;
1253
- type: "removeConstraint";
1254
- }, {
1255
- name: string;
1256
- type: "removeConstraint";
1257
- }>, z.ZodObject<{
1258
- type: z.ZodLiteral<"modifyConstraint">;
1259
- name: z.ZodString;
1260
- changes: z.ZodObject<{
1261
- type: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1262
- name: z.ZodOptional<z.ZodString>;
1263
- predicate: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1264
- parameters: z.ZodOptional<z.ZodOptional<z.ZodType<(params: any) => boolean, z.ZodTypeDef, (params: any) => boolean>>>;
1265
- description: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1266
- field: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1267
- errorMessage: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1268
- }, "strip", z.ZodTypeAny, {
1269
- name?: string | undefined;
1270
- description?: string | undefined;
1271
- type?: string | undefined;
1272
- predicate?: string | undefined;
1273
- field?: string | undefined;
1274
- parameters?: ((params: any) => boolean) | undefined;
1275
- errorMessage?: string | undefined;
1276
- }, {
1277
- name?: string | undefined;
1278
- description?: string | undefined;
1279
- type?: string | undefined;
1280
- predicate?: string | undefined;
1281
- field?: string | undefined;
1282
- parameters?: ((params: any) => boolean) | undefined;
1283
- errorMessage?: string | undefined;
1284
- }>;
1285
- }, "strip", z.ZodTypeAny, {
1286
- name: string;
1287
- type: "modifyConstraint";
1288
- changes: {
1289
- name?: string | undefined;
1290
- description?: string | undefined;
1291
- type?: string | undefined;
1292
- predicate?: string | undefined;
1293
- field?: string | undefined;
1294
- parameters?: ((params: any) => boolean) | undefined;
1295
- errorMessage?: string | undefined;
1296
- };
1297
- }, {
1298
- name: string;
1299
- type: "modifyConstraint";
1300
- changes: {
1301
- name?: string | undefined;
1302
- description?: string | undefined;
1303
- type?: string | undefined;
1304
- predicate?: string | undefined;
1305
- field?: string | undefined;
1306
- parameters?: ((params: any) => boolean) | undefined;
1307
- errorMessage?: string | undefined;
1308
- };
1309
- }>, z.ZodObject<{
1310
- type: z.ZodLiteral<"deprecateField">;
1311
- id: z.ZodString;
1312
- }, "strip", z.ZodTypeAny, {
1313
- type: "deprecateField";
1314
- id: string;
1315
- }, {
1316
- type: "deprecateField";
1317
- id: string;
1318
- }>]>, "many">;
1319
- description: z.ZodString;
1320
- status: z.ZodEnum<["pending", "applied", "failed"]>;
1321
- rollback: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodObject<{
1322
- type: z.ZodLiteral<"addField">;
1323
- id: z.ZodString;
1324
- definition: any;
1325
- }, "strip", z.ZodTypeAny, {
1326
- type: "addField";
1327
- id: string;
1328
- definition?: any;
1329
- }, {
1330
- type: "addField";
1331
- id: string;
1332
- definition?: any;
1333
- }>, z.ZodObject<{
1334
- type: z.ZodLiteral<"removeField">;
1335
- id: z.ZodString;
1336
- }, "strip", z.ZodTypeAny, {
1337
- type: "removeField";
1338
- id: string;
1339
- }, {
1340
- type: "removeField";
1341
- id: string;
1342
- }>, z.ZodObject<{
1343
- type: z.ZodLiteral<"modifyField">;
1344
- id: z.ZodString;
1345
- changes: any;
1346
- }, "strip", z.ZodTypeAny, {
1347
- type: "modifyField";
1348
- id: string;
1349
- changes?: any;
1350
- }, {
1351
- type: "modifyField";
1352
- id: string;
1353
- changes?: any;
1354
- }>, z.ZodObject<{
1355
- type: z.ZodLiteral<"addIndex">;
1356
- definition: z.ZodObject<{
1357
- fields: z.ZodArray<z.ZodString, "many">;
1358
- type: z.ZodEnum<["normal", "unique", "btree", "hash", "spatial", "fulltext", "gi", "expression", "composite"]>;
1359
- unique: z.ZodOptional<z.ZodBoolean>;
1360
- partial: z.ZodOptional<z.ZodType<any, z.ZodTypeDef, any>>;
1361
- description: z.ZodOptional<z.ZodString>;
1362
- order: z.ZodOptional<z.ZodEnum<["asc", "desc"]>>;
1363
- name: z.ZodOptional<z.ZodString>;
1364
- }, "strip", z.ZodTypeAny, {
1365
- fields: string[];
1366
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1367
- unique?: boolean | undefined;
1368
- name?: string | undefined;
1369
- description?: string | undefined;
1370
- partial?: any;
1371
- order?: "asc" | "desc" | undefined;
1372
- }, {
1373
- fields: string[];
1374
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1375
- unique?: boolean | undefined;
1376
- name?: string | undefined;
1377
- description?: string | undefined;
1378
- partial?: any;
1379
- order?: "asc" | "desc" | undefined;
1380
- }>;
1381
- }, "strip", z.ZodTypeAny, {
1382
- type: "addIndex";
1383
- definition: {
1384
- fields: string[];
1385
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1386
- unique?: boolean | undefined;
1387
- name?: string | undefined;
1388
- description?: string | undefined;
1389
- partial?: any;
1390
- order?: "asc" | "desc" | undefined;
1391
- };
1392
- }, {
1393
- type: "addIndex";
1394
- definition: {
1395
- fields: string[];
1396
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1397
- unique?: boolean | undefined;
1398
- name?: string | undefined;
1399
- description?: string | undefined;
1400
- partial?: any;
1401
- order?: "asc" | "desc" | undefined;
1402
- };
1403
- }>, z.ZodObject<{
1404
- type: z.ZodLiteral<"removeIndex">;
1405
- name: z.ZodString;
1406
- }, "strip", z.ZodTypeAny, {
1407
- name: string;
1408
- type: "removeIndex";
1409
- }, {
1410
- name: string;
1411
- type: "removeIndex";
1412
- }>, z.ZodObject<{
1413
- type: z.ZodLiteral<"modifyIndex">;
1414
- name: z.ZodString;
1415
- changes: z.ZodObject<{
1416
- fields: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1417
- type: z.ZodOptional<z.ZodEnum<["normal", "unique", "btree", "hash", "spatial", "fulltext", "gi", "expression", "composite"]>>;
1418
- unique: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
1419
- partial: z.ZodOptional<z.ZodOptional<z.ZodType<any, z.ZodTypeDef, any>>>;
1420
- description: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1421
- order: z.ZodOptional<z.ZodOptional<z.ZodEnum<["asc", "desc"]>>>;
1422
- name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1423
- }, "strip", z.ZodTypeAny, {
1424
- unique?: boolean | undefined;
1425
- fields?: string[] | undefined;
1426
- name?: string | undefined;
1427
- description?: string | undefined;
1428
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1429
- partial?: any;
1430
- order?: "asc" | "desc" | undefined;
1431
- }, {
1432
- unique?: boolean | undefined;
1433
- fields?: string[] | undefined;
1434
- name?: string | undefined;
1435
- description?: string | undefined;
1436
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1437
- partial?: any;
1438
- order?: "asc" | "desc" | undefined;
1439
- }>;
1440
- }, "strip", z.ZodTypeAny, {
1441
- name: string;
1442
- type: "modifyIndex";
1443
- changes: {
1444
- unique?: boolean | undefined;
1445
- fields?: string[] | undefined;
1446
- name?: string | undefined;
1447
- description?: string | undefined;
1448
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1449
- partial?: any;
1450
- order?: "asc" | "desc" | undefined;
1451
- };
1452
- }, {
1453
- name: string;
1454
- type: "modifyIndex";
1455
- changes: {
1456
- unique?: boolean | undefined;
1457
- fields?: string[] | undefined;
1458
- name?: string | undefined;
1459
- description?: string | undefined;
1460
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1461
- partial?: any;
1462
- order?: "asc" | "desc" | undefined;
1463
- };
1464
- }>, z.ZodObject<{
1465
- type: z.ZodLiteral<"addConstraint">;
1466
- constraint: z.ZodUnion<[z.ZodObject<{
1467
- type: z.ZodOptional<z.ZodString>;
1468
- name: z.ZodString;
1469
- predicate: z.ZodOptional<z.ZodString>;
1470
- parameters: z.ZodOptional<z.ZodType<(params: any) => boolean, z.ZodTypeDef, (params: any) => boolean>>;
1471
- description: z.ZodOptional<z.ZodString>;
1472
- field: z.ZodOptional<z.ZodString>;
1473
- errorMessage: z.ZodOptional<z.ZodString>;
1474
- }, "strip", z.ZodTypeAny, {
1475
- name: string;
1476
- description?: string | undefined;
1477
- type?: string | undefined;
1478
- predicate?: string | undefined;
1479
- field?: string | undefined;
1480
- parameters?: ((params: any) => boolean) | undefined;
1481
- errorMessage?: string | undefined;
1482
- }, {
1483
- name: string;
1484
- description?: string | undefined;
1485
- type?: string | undefined;
1486
- predicate?: string | undefined;
1487
- field?: string | undefined;
1488
- parameters?: ((params: any) => boolean) | undefined;
1489
- errorMessage?: string | undefined;
1490
- }>, any]>;
1491
- }, "strip", z.ZodTypeAny, {
1492
- type: "addConstraint";
1493
- constraint?: any;
1494
- }, {
1495
- type: "addConstraint";
1496
- constraint?: any;
1497
- }>, z.ZodObject<{
1498
- type: z.ZodLiteral<"removeConstraint">;
1499
- name: z.ZodString;
1500
- }, "strip", z.ZodTypeAny, {
1501
- name: string;
1502
- type: "removeConstraint";
1503
- }, {
1504
- name: string;
1505
- type: "removeConstraint";
1506
- }>, z.ZodObject<{
1507
- type: z.ZodLiteral<"modifyConstraint">;
1508
- name: z.ZodString;
1509
- changes: z.ZodObject<{
1510
- type: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1511
- name: z.ZodOptional<z.ZodString>;
1512
- predicate: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1513
- parameters: z.ZodOptional<z.ZodOptional<z.ZodType<(params: any) => boolean, z.ZodTypeDef, (params: any) => boolean>>>;
1514
- description: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1515
- field: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1516
- errorMessage: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1517
- }, "strip", z.ZodTypeAny, {
1518
- name?: string | undefined;
1519
- description?: string | undefined;
1520
- type?: string | undefined;
1521
- predicate?: string | undefined;
1522
- field?: string | undefined;
1523
- parameters?: ((params: any) => boolean) | undefined;
1524
- errorMessage?: string | undefined;
1525
- }, {
1526
- name?: string | undefined;
1527
- description?: string | undefined;
1528
- type?: string | undefined;
1529
- predicate?: string | undefined;
1530
- field?: string | undefined;
1531
- parameters?: ((params: any) => boolean) | undefined;
1532
- errorMessage?: string | undefined;
1533
- }>;
1534
- }, "strip", z.ZodTypeAny, {
1535
- name: string;
1536
- type: "modifyConstraint";
1537
- changes: {
1538
- name?: string | undefined;
1539
- description?: string | undefined;
1540
- type?: string | undefined;
1541
- predicate?: string | undefined;
1542
- field?: string | undefined;
1543
- parameters?: ((params: any) => boolean) | undefined;
1544
- errorMessage?: string | undefined;
1545
- };
1546
- }, {
1547
- name: string;
1548
- type: "modifyConstraint";
1549
- changes: {
1550
- name?: string | undefined;
1551
- description?: string | undefined;
1552
- type?: string | undefined;
1553
- predicate?: string | undefined;
1554
- field?: string | undefined;
1555
- parameters?: ((params: any) => boolean) | undefined;
1556
- errorMessage?: string | undefined;
1557
- };
1558
- }>, z.ZodObject<{
1559
- type: z.ZodLiteral<"deprecateField">;
1560
- id: z.ZodString;
1561
- }, "strip", z.ZodTypeAny, {
1562
- type: "deprecateField";
1563
- id: string;
1564
- }, {
1565
- type: "deprecateField";
1566
- id: string;
1567
- }>]>, "many">>;
1568
- transform: z.ZodUnknown;
1569
- createdAt: z.ZodString;
1570
- checksum: z.ZodOptional<z.ZodString>;
1571
- }, "strip", z.ZodTypeAny, {
1572
- description: string;
1573
- changes: ({
1574
- type: "addField";
1575
- id: string;
1576
- definition?: any;
1577
- } | {
1578
- type: "removeField";
1579
- id: string;
1580
- } | {
1581
- type: "modifyField";
1582
- id: string;
1583
- changes?: any;
1584
- } | {
1585
- type: "addIndex";
1586
- definition: {
1587
- fields: string[];
1588
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1589
- unique?: boolean | undefined;
1590
- name?: string | undefined;
1591
- description?: string | undefined;
1592
- partial?: any;
1593
- order?: "asc" | "desc" | undefined;
1594
- };
1595
- } | {
1596
- name: string;
1597
- type: "removeIndex";
1598
- } | {
1599
- name: string;
1600
- type: "modifyIndex";
1601
- changes: {
1602
- unique?: boolean | undefined;
1603
- fields?: string[] | undefined;
1604
- name?: string | undefined;
1605
- description?: string | undefined;
1606
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1607
- partial?: any;
1608
- order?: "asc" | "desc" | undefined;
1609
- };
1610
- } | {
1611
- type: "addConstraint";
1612
- constraint?: any;
1613
- } | {
1614
- name: string;
1615
- type: "removeConstraint";
1616
- } | {
1617
- name: string;
1618
- type: "modifyConstraint";
1619
- changes: {
1620
- name?: string | undefined;
1621
- description?: string | undefined;
1622
- type?: string | undefined;
1623
- predicate?: string | undefined;
1624
- field?: string | undefined;
1625
- parameters?: ((params: any) => boolean) | undefined;
1626
- errorMessage?: string | undefined;
1627
- };
1628
- } | {
1629
- type: "deprecateField";
1630
- id: string;
1631
- })[];
1632
- status: "pending" | "applied" | "failed";
1633
- id: string;
1634
- schemaVersion: string;
1635
- createdAt: string;
1636
- rollback?: ({
1637
- type: "addField";
1638
- id: string;
1639
- definition?: any;
1640
- } | {
1641
- type: "removeField";
1642
- id: string;
1643
- } | {
1644
- type: "modifyField";
1645
- id: string;
1646
- changes?: any;
1647
- } | {
1648
- type: "addIndex";
1649
- definition: {
1650
- fields: string[];
1651
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1652
- unique?: boolean | undefined;
1653
- name?: string | undefined;
1654
- description?: string | undefined;
1655
- partial?: any;
1656
- order?: "asc" | "desc" | undefined;
1657
- };
1658
- } | {
1659
- name: string;
1660
- type: "removeIndex";
1661
- } | {
1662
- name: string;
1663
- type: "modifyIndex";
1664
- changes: {
1665
- unique?: boolean | undefined;
1666
- fields?: string[] | undefined;
1667
- name?: string | undefined;
1668
- description?: string | undefined;
1669
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1670
- partial?: any;
1671
- order?: "asc" | "desc" | undefined;
1672
- };
1673
- } | {
1674
- type: "addConstraint";
1675
- constraint?: any;
1676
- } | {
1677
- name: string;
1678
- type: "removeConstraint";
1679
- } | {
1680
- name: string;
1681
- type: "modifyConstraint";
1682
- changes: {
1683
- name?: string | undefined;
1684
- description?: string | undefined;
1685
- type?: string | undefined;
1686
- predicate?: string | undefined;
1687
- field?: string | undefined;
1688
- parameters?: ((params: any) => boolean) | undefined;
1689
- errorMessage?: string | undefined;
1690
- };
1691
- } | {
1692
- type: "deprecateField";
1693
- id: string;
1694
- })[] | undefined;
1695
- transform?: unknown;
1696
- checksum?: string | undefined;
1697
- }, {
1698
- description: string;
1699
- changes: ({
1700
- type: "addField";
1701
- id: string;
1702
- definition?: any;
1703
- } | {
1704
- type: "removeField";
1705
- id: string;
1706
- } | {
1707
- type: "modifyField";
1708
- id: string;
1709
- changes?: any;
1710
- } | {
1711
- type: "addIndex";
1712
- definition: {
1713
- fields: string[];
1714
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1715
- unique?: boolean | undefined;
1716
- name?: string | undefined;
1717
- description?: string | undefined;
1718
- partial?: any;
1719
- order?: "asc" | "desc" | undefined;
1720
- };
1721
- } | {
1722
- name: string;
1723
- type: "removeIndex";
1724
- } | {
1725
- name: string;
1726
- type: "modifyIndex";
1727
- changes: {
1728
- unique?: boolean | undefined;
1729
- fields?: string[] | undefined;
1730
- name?: string | undefined;
1731
- description?: string | undefined;
1732
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1733
- partial?: any;
1734
- order?: "asc" | "desc" | undefined;
1735
- };
1736
- } | {
1737
- type: "addConstraint";
1738
- constraint?: any;
1739
- } | {
1740
- name: string;
1741
- type: "removeConstraint";
1742
- } | {
1743
- name: string;
1744
- type: "modifyConstraint";
1745
- changes: {
1746
- name?: string | undefined;
1747
- description?: string | undefined;
1748
- type?: string | undefined;
1749
- predicate?: string | undefined;
1750
- field?: string | undefined;
1751
- parameters?: ((params: any) => boolean) | undefined;
1752
- errorMessage?: string | undefined;
1753
- };
1754
- } | {
1755
- type: "deprecateField";
1756
- id: string;
1757
- })[];
1758
- status: "pending" | "applied" | "failed";
1759
- id: string;
1760
- schemaVersion: string;
1761
- createdAt: string;
1762
- rollback?: ({
1763
- type: "addField";
1764
- id: string;
1765
- definition?: any;
1766
- } | {
1767
- type: "removeField";
1768
- id: string;
1769
- } | {
1770
- type: "modifyField";
1771
- id: string;
1772
- changes?: any;
1773
- } | {
1774
- type: "addIndex";
1775
- definition: {
1776
- fields: string[];
1777
- type: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite";
1778
- unique?: boolean | undefined;
1779
- name?: string | undefined;
1780
- description?: string | undefined;
1781
- partial?: any;
1782
- order?: "asc" | "desc" | undefined;
1783
- };
1784
- } | {
1785
- name: string;
1786
- type: "removeIndex";
1787
- } | {
1788
- name: string;
1789
- type: "modifyIndex";
1790
- changes: {
1791
- unique?: boolean | undefined;
1792
- fields?: string[] | undefined;
1793
- name?: string | undefined;
1794
- description?: string | undefined;
1795
- type?: "normal" | "unique" | "btree" | "hash" | "spatial" | "fulltext" | "gi" | "expression" | "composite" | undefined;
1796
- partial?: any;
1797
- order?: "asc" | "desc" | undefined;
1798
- };
1799
- } | {
1800
- type: "addConstraint";
1801
- constraint?: any;
1802
- } | {
1803
- name: string;
1804
- type: "removeConstraint";
1805
- } | {
1806
- name: string;
1807
- type: "modifyConstraint";
1808
- changes: {
1809
- name?: string | undefined;
1810
- description?: string | undefined;
1811
- type?: string | undefined;
1812
- predicate?: string | undefined;
1813
- field?: string | undefined;
1814
- parameters?: ((params: any) => boolean) | undefined;
1815
- errorMessage?: string | undefined;
1816
- };
1817
- } | {
1818
- type: "deprecateField";
1819
- id: string;
1820
- })[] | undefined;
1821
- transform?: unknown;
1822
- checksum?: string | undefined;
1823
- }>;
1824
1419
  declare function validateMigration<T>(change: any): change is Migration<T>;
1825
1420
  declare function validateSchemaChange<T>(change: any): change is SchemaChange<T>;
1826
1421
  declare function validateSchemaDefinition(schema: any): schema is SchemaDefinition;
@@ -1845,28 +1440,26 @@ declare function deepMerge<T extends object>(target: T, update: Partial<T>): T;
1845
1440
  /**
1846
1441
  * Converts a SchemaDefinition to TypeScript type definitions
1847
1442
  *
1848
- * This function analyzes a schema definition and generates appropriate TypeScript
1849
- * type declarations. It handles nested objects, arrays, references, and all primitive types
1850
- * defined in the schema system.
1443
+ * Analyzes a schema definition and generates TypeScript type declarations for the main schema,
1444
+ * nested schemas, and union types for enum-like constraints. Uses capitalized field.name for field names,
1445
+ * capitalized nestedSchema.name for type names, and ignores UUID keys. Handles required/optional fields,
1446
+ * union types, primitives, arrays, sets, references, and nested structures with strict type safety.
1851
1447
  *
1852
- * @param {SchemaDefinition} schema - The schema definition to convert to TypeScript types
1853
- * @param {boolean} [includeComments=true] - Whether to include JSDoc comments from schema descriptions
1854
- * @param {boolean} [exportTypes=true] - Whether to export the generated types
1855
- * @returns {string} TypeScript type definitions as a string
1448
+ * @param schema - The schema definition to convert
1449
+ * @param includeComments - Whether to include JSDoc comments (default: true)
1450
+ * @param exportTypes - Whether to export the generated types (default: true)
1451
+ * @returns TypeScript type definitions as a string
1856
1452
  */
1857
1453
  declare function schemaToTypes(schema: SchemaDefinition, includeComments?: boolean, exportTypes?: boolean): string;
1858
1454
  /**
1859
1455
  * Generates a TypeScript interface for validating schema data
1860
- *
1861
- * This function creates a validation interface with methods that
1862
- * correspond to the schema constraints.
1863
- *
1864
- * @param {SchemaDefinition} schema - The schema definition
1865
- * @param {boolean} [exportType=true] - Whether to export the generated interface
1866
- * @returns {string} TypeScript interface definition for validation
1867
1456
  */
1868
1457
  declare function generateValidationInterface(schema: SchemaDefinition, exportType?: boolean): string;
1869
1458
 
1459
+ /**
1460
+ * Serializes constraint parameters for error messages, handling special types like RegExp.
1461
+ */
1462
+ declare function serializeParams(params: any): string;
1870
1463
  /**
1871
1464
  * Creates a Standard Schema validator that conforms to the StandardSchemaV1 interface.
1872
1465
  * The validator uses a closure pattern to maintain internal state and avoid prop drilling.
@@ -1914,4 +1507,4 @@ declare function docgen(schema: SchemaDefinition, options?: {
1914
1507
  faker?: Faker;
1915
1508
  }): string;
1916
1509
 
1917
- export { type Constraint, type ConstraintGroup, type ConstraintParameters, type ConstraintsMap, type DataTransform, type FieldDefinition, type FieldType, type FunctionMap, type IndexDefinition, type IndexType, JsonPatchError, type LogicalOperator, type Migration, MigrationEngine, type MigrationEngineInterface, MigrationError, MigrationErrorCode, type MigrationMetadata, MigrationSchema, type PartialIndexCondition, type PatchOperation, type Persistence, type PersistenceCollection, type PersistenceEvent, type PersistenceEventType, type PersistenceTransaction, type Predicate, type PredicateMap, type PredicateName, type PredicateParameters, type RegistryLock, type RegistryMetadata, type Schema, type SchemaChange, type SchemaConstraint, type SchemaDefinition, type SchemaEvent, type SchemaEventType, type SchemaIndex, type SchemaMetadata, type SchemaMigrationHelper, type SchemaRegistry, type SchemaVersion, type TransformFunction, applyPatch, calculateNextVersion, compareSemanticVersions, createPatch, createRegistry, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, docgen, generateSHA256Hash, generateValidationInterface, normalizePath, schemaChangeToPatch, schemaToTypes, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };
1510
+ export { type Constraint, type ConstraintGroup, type ConstraintParameters, type ConstraintsMap, type DataTransform, type FieldDefinition, type FieldType, type FunctionMap, type IndexDefinition, type IndexType, JsonPatchError, type LogicalOperator, type Migration, MigrationEngine, type MigrationEngineInterface, MigrationError, MigrationErrorCode, type MigrationMetadata, type NestedSchemaDefinition, type PartialIndexCondition, type PatchOperation, type Persistence, type PersistenceCollection, type PersistenceEvent, type PersistenceEventType, type PersistenceTransaction, type Predicate, type PredicateMap, type PredicateName, type PredicateParameters, type RegistryLock, type RegistryMetadata, type RemoteRepository, type Schema, type SchemaChange, type SchemaConstraint, type SchemaDefinition, type SchemaEvent, type SchemaEventType, type SchemaIndex, type SchemaMetadata, type SchemaMigrationHelper, SchemaRegistry, type SchemaRegistryInterface, type SchemaVersion, type TransformFunction, applyPatch, calculateNextVersion, compareSemanticVersions, createGitSchemaRegistry, createPatch, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, docgen, generateSHA256Hash, generateValidationInterface, normalizePath, schemaChangeToPatch, schemaToTypes, serializeParams, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };