@asaidimu/anansi 1.1.0 → 1.2.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 +40 -1834
  2. package/index.d.cts +2 -319
  3. package/index.d.ts +2 -319
  4. package/index.js +22 -1828
  5. package/package.json +1 -1
package/index.d.cts CHANGED
@@ -282,36 +282,11 @@ interface Migration<T> {
282
282
  checksum: string;
283
283
  }
284
284
 
285
- type schemaDefinition_Constraint<T extends FieldType> = Constraint<T>;
286
- type schemaDefinition_ConstraintGroup<T extends FieldType> = ConstraintGroup<T>;
287
- type schemaDefinition_ConstraintParameters<T extends FieldType> = ConstraintParameters<T>;
288
- type schemaDefinition_ConstraintsMap = ConstraintsMap;
289
- type schemaDefinition_DataTransform<Initial, Next> = DataTransform<Initial, Next>;
290
- type schemaDefinition_FieldDefinition<T> = FieldDefinition<T>;
291
- type schemaDefinition_FieldType = FieldType;
292
- type schemaDefinition_FunctionMap = FunctionMap;
293
- type schemaDefinition_IndexDefinition = IndexDefinition;
294
- type schemaDefinition_IndexType = IndexType;
295
- type schemaDefinition_LogicalOperator = LogicalOperator;
296
- type schemaDefinition_Migration<T> = Migration<T>;
297
- type schemaDefinition_PartialIndexCondition = PartialIndexCondition;
298
- type schemaDefinition_Predicate = Predicate;
299
- type schemaDefinition_PredicateMap = PredicateMap;
300
- type schemaDefinition_PredicateName<T extends PredicateMap = any> = PredicateName<T>;
301
- type schemaDefinition_PredicateParameters<T extends FieldType> = PredicateParameters<T>;
302
- type schemaDefinition_SchemaChange<T> = SchemaChange<T>;
303
- type schemaDefinition_SchemaConstraint<T extends FieldType> = SchemaConstraint<T>;
304
- type schemaDefinition_SchemaDefinition = SchemaDefinition;
305
- type schemaDefinition_TransformFunction<Initial, Next> = TransformFunction<Initial, Next>;
306
- declare namespace schemaDefinition {
307
- export type { schemaDefinition_Constraint as Constraint, schemaDefinition_ConstraintGroup as ConstraintGroup, schemaDefinition_ConstraintParameters as ConstraintParameters, schemaDefinition_ConstraintsMap as ConstraintsMap, schemaDefinition_DataTransform as DataTransform, schemaDefinition_FieldDefinition as FieldDefinition, schemaDefinition_FieldType as FieldType, schemaDefinition_FunctionMap as FunctionMap, schemaDefinition_IndexDefinition as IndexDefinition, schemaDefinition_IndexType as IndexType, schemaDefinition_LogicalOperator as LogicalOperator, schemaDefinition_Migration as Migration, schemaDefinition_PartialIndexCondition as PartialIndexCondition, schemaDefinition_Predicate as Predicate, schemaDefinition_PredicateMap as PredicateMap, schemaDefinition_PredicateName as PredicateName, schemaDefinition_PredicateParameters as PredicateParameters, schemaDefinition_SchemaChange as SchemaChange, schemaDefinition_SchemaConstraint as SchemaConstraint, schemaDefinition_SchemaDefinition as SchemaDefinition, schemaDefinition_TransformFunction as TransformFunction };
308
- }
309
-
310
285
  /**
311
286
  * Defines the interface for a migration engine.
312
287
  * The migration engine is responsible for applying, rolling back, and tracking schema migrations.
313
288
  */
314
- interface MigrationEngine$1<T> {
289
+ interface MigrationEngine<T> {
315
290
  /**
316
291
  * Applies all pending migrations.
317
292
  * @returns A promise that resolves when all migrations are applied.
@@ -362,10 +337,6 @@ interface MigrationEngine$1<T> {
362
337
  removeMigration(migrationId: string): Promise<void>;
363
338
  }
364
339
 
365
- declare namespace migrations {
366
- export type { MigrationEngine$1 as MigrationEngine };
367
- }
368
-
369
340
  /**
370
341
  * @module JsonPatch
371
342
  * @description A library for creating and applying JSON Patch operations according to RFC 6902
@@ -442,17 +413,6 @@ declare function createPatch(oldObj: any, newObj: any): PatchOperation[];
442
413
  */
443
414
  declare function schemaChangeToPatch(change: SchemaChange<any>, schema: SchemaDefinition): PatchOperation[];
444
415
 
445
- type patch_JsonPatchError = JsonPatchError;
446
- declare const patch_JsonPatchError: typeof JsonPatchError;
447
- type patch_PatchOperation = PatchOperation;
448
- declare const patch_applyPatch: typeof applyPatch;
449
- declare const patch_createPatch: typeof createPatch;
450
- declare const patch_normalizePath: typeof normalizePath;
451
- declare const patch_schemaChangeToPatch: typeof schemaChangeToPatch;
452
- declare namespace patch {
453
- export { patch_JsonPatchError as JsonPatchError, type patch_PatchOperation as PatchOperation, patch_applyPatch as applyPatch, patch_createPatch as createPatch, patch_normalizePath as normalizePath, patch_schemaChangeToPatch as schemaChangeToPatch };
454
- }
455
-
456
416
  /**
457
417
  * Helper for building schema migrations.
458
418
  * @template T The type of data associated with the schema.
@@ -702,15 +662,6 @@ interface PersistenceEvent<DataType> {
702
662
  context?: Record<string, any>;
703
663
  }
704
664
 
705
- type persistence_Persistence<FunctionMap> = Persistence<FunctionMap>;
706
- type persistence_PersistenceCollection<T, FunctionMap> = PersistenceCollection<T, FunctionMap>;
707
- type persistence_PersistenceEvent<DataType> = PersistenceEvent<DataType>;
708
- type persistence_PersistenceEventType = PersistenceEventType;
709
- type persistence_PersistenceTransaction<F> = PersistenceTransaction<F>;
710
- declare namespace persistence {
711
- export type { persistence_Persistence as Persistence, persistence_PersistenceCollection as PersistenceCollection, persistence_PersistenceEvent as PersistenceEvent, persistence_PersistenceEventType as PersistenceEventType, persistence_PersistenceTransaction as PersistenceTransaction };
712
- }
713
-
714
665
  type SchemaIndex = {
715
666
  schema: string;
716
667
  version: string;
@@ -776,45 +727,6 @@ interface SchemaRegistry {
776
727
  history(name: string): Promise<SchemaDefinition[]>;
777
728
  }
778
729
 
779
- type registry_MigrationMetadata = MigrationMetadata;
780
- type registry_RegistryLock = RegistryLock;
781
- type registry_RegistryMetadata = RegistryMetadata;
782
- type registry_SchemaIndex = SchemaIndex;
783
- type registry_SchemaMetadata = SchemaMetadata;
784
- type registry_SchemaRegistry = SchemaRegistry;
785
- type registry_SchemaVersion = SchemaVersion;
786
- declare namespace registry {
787
- export type { registry_MigrationMetadata as MigrationMetadata, registry_RegistryLock as RegistryLock, registry_RegistryMetadata as RegistryMetadata, registry_SchemaIndex as SchemaIndex, registry_SchemaMetadata as SchemaMetadata, registry_SchemaRegistry as SchemaRegistry, registry_SchemaVersion as SchemaVersion };
788
- }
789
-
790
- /**
791
- * Creates an ephemeral persistence instance with in-memory storage.
792
- * @template {PredicateMap} Predicates
793
- * @template FunctionMap
794
- * @param {FunctionMap} functionMap - Map of function names to their implementations
795
- * @param {Predicates} predicateMap - Map of predicate names to their implementations
796
- * @returns {Persistence<FunctionMap>} A persistence instance
797
- */
798
- declare function createEphemeralPersistence<Predicates extends PredicateMap, FunctionMap>(functionMap: FunctionMap, predicateMap: Predicates): Persistence<FunctionMap>;
799
-
800
- declare namespace index$3 {
801
- export { createEphemeralPersistence as default };
802
- }
803
-
804
- /**
805
- * Creates and returns a new SchemaRegistry instance.
806
- * @returns {Promise<SchemaRegistry>} A promise that resolves to the SchemaRegistry instance.
807
- */
808
- declare function createRegistry(credentials: {
809
- username: string;
810
- password: string;
811
- repository: string;
812
- }, dir?: string, proxy?: string): Promise<SchemaRegistry>;
813
-
814
- declare namespace index$2 {
815
- export { createRegistry as default };
816
- }
817
-
818
730
  /**
819
731
  * @fileoverview Provides a MigrationEngine class that handles schema migrations,
820
732
  * including validation, checksum generation, and migration application.
@@ -853,198 +765,6 @@ declare enum MigrationErrorCode {
853
765
  ROLLBACK_ERROR = "ROLLBACK_ERROR",
854
766
  MISSING_TRANSFORM = "MISSING_TRANSFORM"
855
767
  }
856
- /**
857
- * @class MigrationEngine
858
- * @param {SchemaDefinition} currentSchema - The current schema definition
859
- * @param {Array<Migration<any>>} [migrations] - Optional array of migrations
860
- * @throws {MigrationError} If the initial schema or migrations are invalid
861
- */
862
- declare class MigrationEngine {
863
- private currentSchema;
864
- private history;
865
- private migrations;
866
- private isProcessing;
867
- /**
868
- * @constructor
869
- * @param {SchemaDefinition} currentSchema - The current schema definition
870
- * @param {Array<Migration<any>>} [migrations] - Optional array of migrations
871
- */
872
- constructor(currentSchema: SchemaDefinition, migrations?: Array<Migration<any>>, history?: Array<SchemaDefinition>);
873
- /**
874
- * Gets the current state of the migration helper
875
- * @returns {Object} Current state containing schema, history, and migrations
876
- * @example
877
- * ```javascript
878
- * const state = migrationEngine.data();
879
- * // state contains currentSchema, history, and migrations
880
- * ```
881
- */
882
- data(): {
883
- schema: SchemaDefinition;
884
- history: SchemaDefinition[];
885
- migrations: Migration<any>[];
886
- };
887
- /**
888
- * Generates a SHA-256 checksum for a migration
889
- * @private
890
- * @param {Omit<Migration<any>, "checksum">} migration - The migration object
891
- * @returns {Promise<string>} The generated checksum
892
- * @throws {MigrationError} If checksum generation fails
893
- */
894
- private generateChecksum;
895
- /**
896
- * Adds a new migration to the engine
897
- * @async
898
- * @param {Object} opts - Options for the new migration
899
- * @param {SchemaChange<any>[]} opts.changes - Array of schema changes
900
- * @param {string} opts.description - Description of the migration
901
- * @param {SchemaChange<any>[]} [opts.rollback] - Optional rollback changes
902
- * @param {DataTransform<any, any>} [opts.transform] - Optional data transform
903
- * @throws {MigrationError} If adding the migration fails
904
- */
905
- add(opts: {
906
- changes: SchemaChange<any>[];
907
- description: string;
908
- rollback?: SchemaChange<any>[];
909
- transform?: string | DataTransform<any, any>;
910
- }): Promise<void>;
911
- /**
912
- * Performs a dry run of the migration
913
- * @async
914
- * @param {ReadableStream<any>} input - Input data stream
915
- * @param {"forward" | "backward"} direction - Direction of migration
916
- * @param {version} version - Version to rollback to
917
- * @returns {Promise<Object>} Object containing newSchema and dataPreview
918
- * @throws {MigrationError} If dry run fails
919
- */
920
- dryRun(input: ReadableStream<any>, direction: "forward" | "backward", version?: string): Promise<{
921
- newSchema: SchemaDefinition;
922
- dataPreview: ReadableStream<any>;
923
- }>;
924
- /**
925
- * Gets relevant migrations based on direction
926
- * @private
927
- * @param {"forward" | "backward"} direction - Direction of migration
928
- * @returns {Array<Migration<any>>} Relevant migrations
929
- */
930
- private getRelevantMigrations;
931
- /**
932
- * Applies schema changes to a given schema
933
- * @private
934
- * @param {SchemaDefinition} schema - The schema to modify
935
- * @param {SchemaChange<any>[]} changes - Array of schema changes
936
- * @param {string} [migrationId] - ID of the migration
937
- * @returns {SchemaDefinition} Modified schema
938
- * @throws {MigrationError} If applying changes fails
939
- */
940
- private applySchemaChanges;
941
- /**
942
- * Prepares the list of pending migrations for application
943
- * @async
944
- * @returns {Promise<Array<Migration<any>>} List of pending migrations
945
- * @throws {MigrationError} If preparation fails
946
- */
947
- prepareMigration(): Promise<Array<Migration<any>>>;
948
- /**
949
- * Applies pending migrations
950
- * @async
951
- * @param {ReadableStream<any>} input - Input data stream
952
- * @returns {Promise<ReadableStream<any>>} Transformed data stream
953
- * @throws {MigrationError} If migration fails
954
- */
955
- migrate(input: ReadableStream<any>): Promise<ReadableStream<any>>;
956
- /**
957
- * Validates migrations by checking their checksums
958
- * @private
959
- * @async
960
- * @param {Array<Migration<any>>} migrations - Migrations to validate
961
- * @throws {MigrationError} If validation fails
962
- */
963
- private validateMigrations;
964
- /**
965
- * Marks migrations as applied
966
- * @private
967
- * @param {Array<Migration<any>>} migrations - Migrations to mark as applied
968
- */
969
- private markMigrationsApplied;
970
- /**
971
- * Rolls back the last applied migration
972
- * @async
973
- * @param {ReadableStream<any>} input - Input data stream
974
- * @returns {Promise<ReadableStream<any>>} Transformed data stream
975
- */
976
- rollback(input: ReadableStream<any>): Promise<ReadableStream<any>>;
977
- /**
978
- * Rolls back to a specific schema version
979
- * @async
980
- * @param {string} targetVersion - Target schema version
981
- * @param {ReadableStream<any>} input - Input data stream
982
- * @returns {Promise<ReadableStream<any>>} Transformed data stream
983
- * @throws {Error} If target version is not found
984
- */
985
- rollbackToVersion(targetVersion: string, input: ReadableStream<any>): Promise<ReadableStream<any>>;
986
- /**
987
- * Processes a list of migrations on a data stream, applying transformations
988
- * in the specified direction (forward or backward).
989
- *
990
- * @static
991
- * @async
992
- * @param {ReadableStream<any>} input - The input data stream to process
993
- * @param {"forward" | "backward"} direction - Direction of migration (either "forward" or "backward")
994
- * @param {Array<Migration<any>>} migrations - Array of Migration objects to process
995
- * @returns {Promise<ReadableStream<any>>} Transformed data stream
996
- * @throws {MigrationError} If any migration processing fails
997
- */
998
- static processMigrationList(input: ReadableStream<any>, direction: "forward" | "backward", migrations: Migration<any>[]): Promise<ReadableStream<any>>;
999
- /**
1000
- * Resolves the transform function for a given migration in the specified direction.
1001
- *
1002
- * @private
1003
- * @async
1004
- * @param {Migration<any>} migration - The migration to resolve the transform for
1005
- * @param {"forward" | "backward"} direction - Direction of migration
1006
- * @returns {Promise<TransformFunction<any, any>>} Resolved transform function
1007
- * @throws {MigrationError} If transform resolution fails
1008
- */
1009
- private static resolveTransform;
1010
- /**
1011
- * Resolves a transform function from a remote URL.
1012
- *
1013
- * @private
1014
- * @async
1015
- * @param {string} url - URL of the transform module
1016
- * @param {"forward" | "backward"} direction - Direction of migration
1017
- * @returns {Promise<TransformFunction<any, any>>} Resolved transform function
1018
- * @throws {MigrationError} If resolution fails
1019
- */
1020
- private static resolveRemoteTransform;
1021
- /**
1022
- * Resolves a transform function from a local module path.
1023
- *
1024
- * @private
1025
- * @async
1026
- * @param {string} path - Local module path
1027
- * @param {"forward" | "backward"} direction - Direction of migration
1028
- * @returns {Promise<TransformFunction<any, any>>} Resolved transform function
1029
- * @throws {MigrationError} If resolution fails
1030
- */
1031
- private static resolveLocalTransform;
1032
- /**
1033
- * Transforms the schema either forward or backward
1034
- * @private
1035
- * @param {"forward" | "backward"} direction - Direction of transformation
1036
- * @throws {Error} If transformation fails
1037
- */
1038
- private transformSchema;
1039
- }
1040
-
1041
- type index$1_MigrationError = MigrationError;
1042
- declare const index$1_MigrationError: typeof MigrationError;
1043
- type index$1_MigrationErrorCode = MigrationErrorCode;
1044
- declare const index$1_MigrationErrorCode: typeof MigrationErrorCode;
1045
- declare namespace index$1 {
1046
- export { index$1_MigrationError as MigrationError, index$1_MigrationErrorCode as MigrationErrorCode, MigrationEngine as default };
1047
- }
1048
768
 
1049
769
  /**
1050
770
  * Helper for building schema migrations with forward and rollback changes.
@@ -1814,16 +1534,6 @@ declare function validateSchemaChange<T>(change: any): change is SchemaChange<T>
1814
1534
  declare function validateSchemaDefinition(schema: any): schema is SchemaDefinition;
1815
1535
  declare const validate: typeof validateSchemaDefinition;
1816
1536
 
1817
- declare const index_MigrationSchema: typeof MigrationSchema;
1818
- declare const index_createSchemaMigrationHelper: typeof createSchemaMigrationHelper;
1819
- declare const index_validate: typeof validate;
1820
- declare const index_validateMigration: typeof validateMigration;
1821
- declare const index_validateSchemaChange: typeof validateSchemaChange;
1822
- declare const index_validateSchemaDefinition: typeof validateSchemaDefinition;
1823
- declare namespace index {
1824
- export { index_MigrationSchema as MigrationSchema, index_createSchemaMigrationHelper as createSchemaMigrationHelper, index_validate as validate, index_validateMigration as validateMigration, index_validateSchemaChange as validateSchemaChange, index_validateSchemaDefinition as validateSchemaDefinition };
1825
- }
1826
-
1827
1537
  /**
1828
1538
  * Generates a SHA-256 hash of the input string.
1829
1539
  *
@@ -1832,11 +1542,6 @@ declare namespace index {
1832
1542
  */
1833
1543
  declare const generateSHA256Hash: (input: string) => Promise<string>;
1834
1544
 
1835
- declare const crypto_generateSHA256Hash: typeof generateSHA256Hash;
1836
- declare namespace crypto {
1837
- export { crypto_generateSHA256Hash as generateSHA256Hash };
1838
- }
1839
-
1840
1545
  /**
1841
1546
  * Deeply merges a partial update into a target object
1842
1547
  * @param target The complete target object
@@ -1845,11 +1550,6 @@ declare namespace crypto {
1845
1550
  */
1846
1551
  declare function deepMerge<T extends object>(target: T, update: Partial<T>): T;
1847
1552
 
1848
- declare const merge_deepMerge: typeof deepMerge;
1849
- declare namespace merge {
1850
- export { merge_deepMerge as deepMerge };
1851
- }
1852
-
1853
1553
  /**
1854
1554
  * Converts a schema definition into TypeScript type definitions
1855
1555
  * @param schema - The schema definition
@@ -1857,11 +1557,6 @@ declare namespace merge {
1857
1557
  */
1858
1558
  declare function schemaToTypes(schema: SchemaDefinition): string;
1859
1559
 
1860
- declare const typegen_schemaToTypes: typeof schemaToTypes;
1861
- declare namespace typegen {
1862
- export { schemaToTypes as default, typegen_schemaToTypes as schemaToTypes };
1863
- }
1864
-
1865
1560
  /**
1866
1561
  * Creates a Standard Schema validator that conforms to the StandardSchemaV1 interface.
1867
1562
  * The validator uses a closure pattern to maintain internal state and avoid prop drilling.
@@ -1881,11 +1576,6 @@ declare namespace typegen {
1881
1576
  */
1882
1577
  declare function createStandardSchemaValidator<T extends Record<string, any>>(schema: SchemaDefinition, constraintsMap: PredicateMap): StandardSchemaV1<T, T>;
1883
1578
 
1884
- declare const validator_createStandardSchemaValidator: typeof createStandardSchemaValidator;
1885
- declare namespace validator {
1886
- export { validator_createStandardSchemaValidator as createStandardSchemaValidator };
1887
- }
1888
-
1889
1579
  /**
1890
1580
  * Calculates the next version number based on schema changes.
1891
1581
  * @param currentVersion - Current semantic version string
@@ -1910,11 +1600,4 @@ declare function compareSemanticVersions(a: string, b: string): number;
1910
1600
  */
1911
1601
  declare function sortSemanticVars(vars: string[]): string[];
1912
1602
 
1913
- declare const version_calculateNextVersion: typeof calculateNextVersion;
1914
- declare const version_compareSemanticVersions: typeof compareSemanticVersions;
1915
- declare const version_sortSemanticVars: typeof sortSemanticVars;
1916
- declare namespace version {
1917
- export { version_calculateNextVersion as calculateNextVersion, version_compareSemanticVersions as compareSemanticVersions, version_sortSemanticVars as sortSemanticVars };
1918
- }
1919
-
1920
- export { migrations as MigrationTypes, persistence as PersistenceTypes, registry as RegistryType, schemaDefinition as SchemaTypes, crypto, merge, index$1 as migration, patch, index$3 as persistence, index$2 as registry, index as schema, typegen, validator, version };
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 };