@asaidimu/anansi 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/index.cjs +46 -1415
  2. package/index.d.cts +98 -2
  3. package/index.d.ts +98 -2
  4. package/index.js +46 -1364
  5. package/package.json +1 -1
package/index.d.cts CHANGED
@@ -286,7 +286,7 @@ interface Migration<T> {
286
286
  * Defines the interface for a migration engine.
287
287
  * The migration engine is responsible for applying, rolling back, and tracking schema migrations.
288
288
  */
289
- interface MigrationEngine<T> {
289
+ interface MigrationEngineInterface<T> {
290
290
  /**
291
291
  * Applies all pending migrations.
292
292
  * @returns A promise that resolves when all migrations are applied.
@@ -413,6 +413,98 @@ declare function createPatch(oldObj: any, newObj: any): PatchOperation[];
413
413
  */
414
414
  declare function schemaChangeToPatch(change: SchemaChange<any>, schema: SchemaDefinition): PatchOperation[];
415
415
 
416
+ /**
417
+ * Schema event types.
418
+ */
419
+ type SchemaEventType = SchemaEvent["type"];
420
+ /**
421
+ * Represents a schema event.
422
+ */
423
+ type SchemaEvent = {
424
+ type: "migration:started";
425
+ description: string;
426
+ currentVersion: string;
427
+ changes: SchemaChange<any>[];
428
+ dryRun?: boolean;
429
+ } | {
430
+ type: "migration:committed";
431
+ currentVersion: string;
432
+ previousVersion: string;
433
+ changes: SchemaChange<any>[];
434
+ dryRun?: boolean;
435
+ } | {
436
+ type: "migration:rollingBack";
437
+ currentVersion: string;
438
+ targetVersion: string;
439
+ changes: SchemaChange<any>[];
440
+ dryRun?: boolean;
441
+ } | {
442
+ type: "migration:rolledBack";
443
+ currentVersion: string;
444
+ previousVersion: string;
445
+ changes: SchemaChange<any>[];
446
+ dryRun?: boolean;
447
+ } | {
448
+ type: "migration:ended";
449
+ currentVersion: string;
450
+ status: "committed" | "rolledBack";
451
+ };
452
+ /**
453
+ * Schema interface for managing schema evolution.
454
+ * @template T The type of data associated with the schema.
455
+ */
456
+ interface Schema<T = any> {
457
+ /**
458
+ * Subscribes to schema events. The listener will be called for each event.
459
+ * @param event The type of schema event to subscribe to.
460
+ * @param listener The listener function that receives the schema event.
461
+ * @returns A function that, when called, unsubscribes the listener.
462
+ */
463
+ subscribe(event: SchemaEventType, listener: (event: SchemaEvent) => void): () => void;
464
+ /**
465
+ * Returns a read-only copy of the schema definition.
466
+ * @returns A read-only version of the current schema definition.
467
+ */
468
+ definition(): Readonly<SchemaDefinition>;
469
+ /**
470
+ * Returns a promise that resolves to a read-only copy of the migration history.
471
+ * @returns A promise that resolves to a read-only array of migrations.
472
+ */
473
+ migrations(): Promise<Readonly<Migration<any>[]>>;
474
+ /**
475
+ * Exports the schema state (definition and migrations) as a JSON string.
476
+ * @returns A JSON string representation of the schema state.
477
+ */
478
+ export(): string;
479
+ /**
480
+ * Imports the schema state (definition and migrations) from a JSON string.
481
+ * @param json The JSON string representing the schema state to import.
482
+ * @throws Error if the imported state is invalid.
483
+ */
484
+ import(json: string): void;
485
+ /**
486
+ * Creates a migration from a list of changes.
487
+ * @param description A description of the migration.
488
+ * @param changes A list of schema changes to apply.
489
+ * @param dryRun Indicates whether the migration should actually be executed
490
+ * @throws Error if the changes are not valid.
491
+ * @returns A promise that resolves when the migration is complete.
492
+ */
493
+ migrate(description: string, changes: SchemaChange<T>[], dryRun?: boolean): Promise<void>;
494
+ /**
495
+ * Rolls back a migration.
496
+ * @param version The version to rollback from. If not specified, rolls back the last migration.
497
+ * @throws Error if the rollback cannot be performed.
498
+ * @returns A promise that resolves when the rollback is complete.
499
+ */
500
+ rollback(version?: string): Promise<void>;
501
+ /**
502
+ * Creates a migration helper to assist in creating a migration.
503
+ * @param description A description of the migration.
504
+ * @returns A `SchemaMigrationHelper` instance to build the migration.
505
+ */
506
+ migrationHelper(description: string): SchemaMigrationHelper;
507
+ }
416
508
  /**
417
509
  * Helper for building schema migrations.
418
510
  * @template T The type of data associated with the schema.
@@ -1600,4 +1692,8 @@ declare function compareSemanticVersions(a: string, b: string): number;
1600
1692
  */
1601
1693
  declare function sortSemanticVars(vars: string[]): string[];
1602
1694
 
1603
- 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, type MigrationEngine, 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 SchemaChange, type SchemaConstraint, type SchemaDefinition, type SchemaIndex, type SchemaMetadata, type SchemaRegistry, type SchemaVersion, type TransformFunction, applyPatch, calculateNextVersion, compareSemanticVersions, createPatch, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, generateSHA256Hash, normalizePath, schemaChangeToPatch, schemaToTypes, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };
1695
+ declare function docgen(schema: SchemaDefinition, options?: {
1696
+ faker?: Faker;
1697
+ }): string;
1698
+
1699
+ 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, 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, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, docgen, generateSHA256Hash, normalizePath, schemaChangeToPatch, schemaToTypes, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };
package/index.d.ts CHANGED
@@ -286,7 +286,7 @@ interface Migration<T> {
286
286
  * Defines the interface for a migration engine.
287
287
  * The migration engine is responsible for applying, rolling back, and tracking schema migrations.
288
288
  */
289
- interface MigrationEngine<T> {
289
+ interface MigrationEngineInterface<T> {
290
290
  /**
291
291
  * Applies all pending migrations.
292
292
  * @returns A promise that resolves when all migrations are applied.
@@ -413,6 +413,98 @@ declare function createPatch(oldObj: any, newObj: any): PatchOperation[];
413
413
  */
414
414
  declare function schemaChangeToPatch(change: SchemaChange<any>, schema: SchemaDefinition): PatchOperation[];
415
415
 
416
+ /**
417
+ * Schema event types.
418
+ */
419
+ type SchemaEventType = SchemaEvent["type"];
420
+ /**
421
+ * Represents a schema event.
422
+ */
423
+ type SchemaEvent = {
424
+ type: "migration:started";
425
+ description: string;
426
+ currentVersion: string;
427
+ changes: SchemaChange<any>[];
428
+ dryRun?: boolean;
429
+ } | {
430
+ type: "migration:committed";
431
+ currentVersion: string;
432
+ previousVersion: string;
433
+ changes: SchemaChange<any>[];
434
+ dryRun?: boolean;
435
+ } | {
436
+ type: "migration:rollingBack";
437
+ currentVersion: string;
438
+ targetVersion: string;
439
+ changes: SchemaChange<any>[];
440
+ dryRun?: boolean;
441
+ } | {
442
+ type: "migration:rolledBack";
443
+ currentVersion: string;
444
+ previousVersion: string;
445
+ changes: SchemaChange<any>[];
446
+ dryRun?: boolean;
447
+ } | {
448
+ type: "migration:ended";
449
+ currentVersion: string;
450
+ status: "committed" | "rolledBack";
451
+ };
452
+ /**
453
+ * Schema interface for managing schema evolution.
454
+ * @template T The type of data associated with the schema.
455
+ */
456
+ interface Schema<T = any> {
457
+ /**
458
+ * Subscribes to schema events. The listener will be called for each event.
459
+ * @param event The type of schema event to subscribe to.
460
+ * @param listener The listener function that receives the schema event.
461
+ * @returns A function that, when called, unsubscribes the listener.
462
+ */
463
+ subscribe(event: SchemaEventType, listener: (event: SchemaEvent) => void): () => void;
464
+ /**
465
+ * Returns a read-only copy of the schema definition.
466
+ * @returns A read-only version of the current schema definition.
467
+ */
468
+ definition(): Readonly<SchemaDefinition>;
469
+ /**
470
+ * Returns a promise that resolves to a read-only copy of the migration history.
471
+ * @returns A promise that resolves to a read-only array of migrations.
472
+ */
473
+ migrations(): Promise<Readonly<Migration<any>[]>>;
474
+ /**
475
+ * Exports the schema state (definition and migrations) as a JSON string.
476
+ * @returns A JSON string representation of the schema state.
477
+ */
478
+ export(): string;
479
+ /**
480
+ * Imports the schema state (definition and migrations) from a JSON string.
481
+ * @param json The JSON string representing the schema state to import.
482
+ * @throws Error if the imported state is invalid.
483
+ */
484
+ import(json: string): void;
485
+ /**
486
+ * Creates a migration from a list of changes.
487
+ * @param description A description of the migration.
488
+ * @param changes A list of schema changes to apply.
489
+ * @param dryRun Indicates whether the migration should actually be executed
490
+ * @throws Error if the changes are not valid.
491
+ * @returns A promise that resolves when the migration is complete.
492
+ */
493
+ migrate(description: string, changes: SchemaChange<T>[], dryRun?: boolean): Promise<void>;
494
+ /**
495
+ * Rolls back a migration.
496
+ * @param version The version to rollback from. If not specified, rolls back the last migration.
497
+ * @throws Error if the rollback cannot be performed.
498
+ * @returns A promise that resolves when the rollback is complete.
499
+ */
500
+ rollback(version?: string): Promise<void>;
501
+ /**
502
+ * Creates a migration helper to assist in creating a migration.
503
+ * @param description A description of the migration.
504
+ * @returns A `SchemaMigrationHelper` instance to build the migration.
505
+ */
506
+ migrationHelper(description: string): SchemaMigrationHelper;
507
+ }
416
508
  /**
417
509
  * Helper for building schema migrations.
418
510
  * @template T The type of data associated with the schema.
@@ -1600,4 +1692,8 @@ declare function compareSemanticVersions(a: string, b: string): number;
1600
1692
  */
1601
1693
  declare function sortSemanticVars(vars: string[]): string[];
1602
1694
 
1603
- 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, type MigrationEngine, 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 SchemaChange, type SchemaConstraint, type SchemaDefinition, type SchemaIndex, type SchemaMetadata, type SchemaRegistry, type SchemaVersion, type TransformFunction, applyPatch, calculateNextVersion, compareSemanticVersions, createPatch, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, generateSHA256Hash, normalizePath, schemaChangeToPatch, schemaToTypes, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };
1695
+ declare function docgen(schema: SchemaDefinition, options?: {
1696
+ faker?: Faker;
1697
+ }): string;
1698
+
1699
+ 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, 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, createSchemaMigrationHelper, createStandardSchemaValidator, deepMerge, docgen, generateSHA256Hash, normalizePath, schemaChangeToPatch, schemaToTypes, sortSemanticVars, validate, validateMigration, validateSchemaChange, validateSchemaDefinition };