@trust0/ridb-core 1.7.34 → 1.7.36

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.
@@ -73,182 +73,183 @@ declare enum Errors {
73
73
  AuthenticationError = 5,
74
74
  }
75
75
 
76
- type InternalsRecord = {
77
- [name: string]: BaseStorage<SchemaTypeRecord>
76
+ declare const SchemaFieldType = {
77
+ /**
78
+ * String type for text data
79
+ */
80
+ string: 'string' as const,
81
+
82
+ /**
83
+ * Number type for numeric data (integers and floats)
84
+ */
85
+ number: 'number' as const,
86
+
87
+ /**
88
+ * Boolean type for true/false values
89
+ */
90
+ boolean: 'boolean' as const,
91
+
92
+ /**
93
+ * Array type for ordered collections of items
94
+ */
95
+ array: 'array' as const,
96
+
97
+ /**
98
+ * Object type for nested document structures
99
+ */
100
+ object: 'object' as const,
78
101
  };
79
- /**
80
- * ExtractType is a utility type that maps a string representing a basic data type to the actual TypeScript type.
81
- *
82
- * @template T - A string literal type representing the basic data type ('string', 'number', 'boolean', 'object', 'array').
83
- *
84
- * @example
85
- * type StringType = ExtractType<'string'>; // StringType is string
86
- * type NumberType = ExtractType<'number'>; // NumberType is number
87
- * type BooleanType = ExtractType<'boolean'>; // BooleanType is boolean
88
- * type ObjectType = ExtractType<'object'>; // ObjectType is object
89
- * type ArrayType = ExtractType<'array'>; // ArrayType is Array<any>
90
- */
91
- type ExtractType<T extends string> =
92
- T extends "string" ? string :
93
- T extends "number" ? number :
94
- T extends "boolean" ? boolean :
95
- T extends "object" ? object :
96
- T extends "array" ? any[] :
97
- undefined;
98
102
 
99
- type IsOptional<T> =
100
- T extends { required: true }
101
- ? T extends { default: never }
102
- ? false
103
- : true
104
- : true;
105
103
 
106
- /**
107
- * Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
108
- *
109
- * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
110
- *
111
- * type Document = Doc<Schema>; // Document is { name: string; age: number; }
112
- */
113
- type Doc<T extends SchemaType> = {
114
- [K in keyof T["properties"]]:
115
- ExtractType<T['properties'][K]['type']>
116
- } & {
117
- __version?: number;
118
- createdAt?: number;
119
- updatedAt?: number;
120
- };
121
104
 
122
105
  /**
123
- * CreateDoc is a utility type for document creation that properly handles required vs optional fields
124
- * during the creation process. Fields with default values or required: false become optional.
125
- *
126
- * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
106
+ * Represents the type definition for a schema.
127
107
  */
128
- type CreateDoc<T extends SchemaType> = {
129
- [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
130
- ExtractType<T['properties'][K]['type']>
131
- } & {
132
- [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
133
- ExtractType<T['properties'][K]['type']>
134
- } & {
135
- __version?: number;
136
- createdAt?: number;
137
- updatedAt?: number;
108
+ type SchemaType = {
109
+ /**
110
+ * The version of the schema.
111
+ */
112
+ version: number;
113
+
114
+ /**
115
+ * The primary key of the schema.
116
+ */
117
+ primaryKey: string;
118
+
119
+ /**
120
+ * The type of the schema.
121
+ */
122
+ type: SchemaFieldType;
123
+ indexes?: string[];
124
+ encrypted?: string[];
125
+ /**
126
+ * The properties defined in the schema.
127
+ */
128
+ properties: {
129
+ [name: string]: Property;
130
+ };
138
131
  };
139
132
 
140
- type QueryOptions = {
141
- limit?: number;
142
- offset?: number;
143
- }
144
133
 
145
134
  /**
146
- * Collection is a class that represents a collection of documents in a database.
147
- * @template T - A schema type defining the structure of the documents in the collection.
135
+ * Represents a schema, including its definition and related methods.
136
+ * You may be trying to build a storage, in any other can u won't need access tho this class.
137
+ * Check this example
138
+ *
139
+ * ```typescript
140
+ * class MyStorage extends <T extends SchemaTypeRecord> extends BaseStorage<T> {
141
+ * example() {
142
+ * const schema: Schema<any> = this.getSchema("mySchema")
143
+ * }
144
+ * }
145
+ * ```
146
+ * You alwayswill have access to getSchema through the Storage class.
147
+ *
148
+ * @template T - The schema type.
148
149
  */
149
- declare class Collection<T extends SchemaType> {
150
- /**
151
- * Finds all documents in the collection.
152
- *
153
- * @returns A promise that resolves to an array of documents.
154
- */
155
- find(query: QueryType<T>, options?: QueryOptions): Promise<Doc<T>[]>;
156
- /**
157
- * count all documents in the collection.
158
- *
159
- * @returns A promise that resolves to an array of documents.
160
- */
161
- count(query: QueryType<T>, options?: QueryOptions): Promise<number>;
162
- /**
163
- * Finds a single document in the collection by its ID.
164
- *
165
- * @param id - The ID of the document to find.
166
- * @returns A promise that resolves to the found document.
167
- */
168
- findById(id: string): Promise<Doc<T>>;
169
- /**
170
- * Updates a document in the collection by its ID.
171
- *
172
- * @param document - A partial document containing the fields to update.
173
- * @returns A promise that resolves when the update is complete.
174
- */
175
- update(document: Partial<Doc<T>>): Promise<void>;
176
- /**
177
- * Creates a new document in the collection.
178
- *
179
- * @param document - The document to create.
180
- * @returns A promise that resolves to the created document.
181
- */
182
- create(document: CreateDoc<T>): Promise<Doc<T>>;
183
- /**
184
- * Deletes a document in the collection by its ID.
185
- *
186
- * @param id - The ID of the document to delete.
187
- * @returns A promise that resolves when the deletion is complete.
188
- */
189
- delete(id: string): Promise<void>;
190
- }
191
-
192
-
150
+ declare class Schema<T extends SchemaType> {
151
+ /**
152
+ * The schema definition.
153
+ */
154
+ schema: Schema<T>;
193
155
 
156
+ /**
157
+ * Creates a new `Schema` instance from the provided definition.
158
+ *
159
+ * @template TS - The schema type.
160
+ * @param {TS} defi, Debugnition - The schema definition.
161
+ * @returns {Schema<TS>} The created `Schema` instance.
162
+ */
163
+ static create<TS extends SchemaType>(definition: TS): Schema<TS>;
194
164
 
195
- declare class CoreStorage {
196
165
  /**
197
- * @param {any} document
198
- * @param {Query} query
199
- * @returns {boolean}
200
- */
201
- matchesQuery(document: any, query: Query<any>): boolean;
202
- getPrimaryKeyTyped(value: any): string | number;
203
- getIndexes(schema: Schema<any>, op: Operation): string[];
204
- }
166
+ * The version of the schema.
167
+ */
168
+ readonly version: number;
205
169
 
170
+ /**
171
+ * The primary key of the schema.
172
+ */
173
+ readonly primaryKey: string;
206
174
 
175
+ /**
176
+ * The type of the schema.
177
+ */
178
+ readonly type: SchemaFieldType;
207
179
 
208
- /**
209
- * Represents an operation to be performed on a collection.
210
- *
211
- * @template T - The schema type of the collection.
212
- */
213
- type Operation<T extends SchemaType = SchemaType> = {
214
180
  /**
215
- * The name of the collection on which the operation will be performed.
181
+ * An optional array of indexes.
216
182
  */
217
- collection: string,
183
+ /**
184
+ * An optional array of indexes.
185
+ */
186
+ readonly indexes?: (Extract<keyof T, string>)[];
218
187
 
219
188
  /**
220
- * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
189
+ * An optional array of encrypted fields.
221
190
  */
222
- opType: OpType,
191
+ readonly encrypted?: (Extract<keyof T, string>)[];
223
192
 
224
193
  /**
225
- * The data involved in the operation, conforming to the schema type.
194
+ * The properties defined in the schema.
226
195
  */
227
- data: Doc<T>,
196
+ readonly properties: {
197
+ [K in keyof T['properties'] as T['properties'][K]['required'] extends false | (T['properties'][K]['default'] extends undefined ? true: false) ? K : never]?: T['properties'][K];
198
+ } & {
199
+ [K in keyof T['properties'] as T['properties'][K]['required'] extends false ? never : K]: T['properties'][K];
200
+ };
201
+ /**
202
+ * Converts the schema to a JSON representation.
203
+ *
204
+ * @returns {SchemaType} The JSON representation of the schema.
205
+ */
206
+ toJSON(): SchemaType;
228
207
 
229
- primaryKeyField?: string,
230
- primaryKey?: string
208
+ validate(document: Doc<Schema<T>>): boolean;
231
209
  }
232
210
 
233
211
 
234
212
 
235
- type BaseStorageOptions = {
236
- [name:string]:string | boolean | number
237
- }
213
+ /**
214
+ * Represents an in-memory storage system extending the base storage functionality.
215
+ *
216
+ * @template T - The schema type.
217
+ */
218
+ declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
219
+ /**
220
+ * Frees the resources used by the in-memory storage.
221
+ */
222
+ free(): void;
238
223
 
239
- declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
240
224
  static create<SchemasCreate extends SchemaTypeRecord>(
241
225
  dbName: string,
242
226
  schemas: SchemasCreate,
243
- options?: BaseStorageOptions
244
227
  ): Promise<
245
- BaseStorage<
228
+ InMemory<
246
229
  SchemasCreate
247
230
  >
248
231
  >;
249
- constructor(
250
- dbName: string,
251
- schemas: Schemas,
232
+ }
233
+
234
+
235
+
236
+ type BaseStorageOptions = {
237
+ [name:string]:string | boolean | number
238
+ }
239
+
240
+ declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
241
+ static create<SchemasCreate extends SchemaTypeRecord>(
242
+ dbName: string,
243
+ schemas: SchemasCreate,
244
+ options?: BaseStorageOptions
245
+ ): Promise<
246
+ BaseStorage<
247
+ SchemasCreate
248
+ >
249
+ >;
250
+ constructor(
251
+ dbName: string,
252
+ schemas: Schemas,
252
253
  options?: BaseStorageOptions
253
254
  );
254
255
  readonly dbName: string;
@@ -391,48 +392,12 @@ declare class BasePlugin implements BasePluginOptions {
391
392
 
392
393
 
393
394
 
394
- type Operators<T> = {
395
- $gte?: number,
396
- $gt?: number
397
- $lt?: number,
398
- $lte?: number,
399
- $eq?: T,
400
- $ne?: T
401
- };
402
-
403
- type InOperator<T> = { $in?: T[] };
404
- type NInOperator<T> = { $nin?: T[] };
405
-
406
- type OperatorOrType<T> = T extends number ?
407
- T | Operators<T> | InOperator<T> | NInOperator<T> :
408
- T | InOperator<T> | NInOperator<T>;
409
-
410
- type LogicalOperators<T extends SchemaType> = {
411
- $and?: Partial<QueryType<T>>[];
412
- $or?: Partial<QueryType<T>>[];
413
- };
414
-
415
- type QueryType<T extends SchemaType> = ({
416
- [K in keyof T['properties']as ExtractType<T['properties'][K]['type']> extends undefined ? never : K]?: OperatorOrType<
417
- ExtractType<
418
- T['properties'][K]['type']
419
- >
420
- >
421
- } & LogicalOperators<T>) | LogicalOperators<T>[];
422
-
423
- declare class Query<T extends SchemaType> {
424
- constructor(query: QueryType<T>, schema:Schema<T>);
425
- readonly query: QueryType<T>;
426
- }
427
-
428
-
429
-
430
395
  /**
431
- * Represents an in-memory storage system extending the base storage functionality.
396
+ * Represents an IndexDB storage system extending the base storage functionality.
432
397
  *
433
398
  * @template T - The schema type.
434
399
  */
435
- declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
400
+ declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
436
401
  /**
437
402
  * Frees the resources used by the in-memory storage.
438
403
  */
@@ -442,7 +407,7 @@ declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
442
407
  dbName: string,
443
408
  schemas: SchemasCreate,
444
409
  ): Promise<
445
- InMemory<
410
+ IndexDB<
446
411
  SchemasCreate
447
412
  >
448
413
  >;
@@ -450,158 +415,170 @@ declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
450
415
 
451
416
 
452
417
 
453
- type EnumerateUpTo<
454
- N extends number,
455
- Acc extends number[] = []
456
- > = Acc['length'] extends N ?
457
- Acc[number]:
458
- EnumerateUpTo<N, [...Acc, Acc['length']]> ;
459
-
460
- type EnumerateFrom1To<
461
- N extends number
462
- > = Exclude<EnumerateUpTo<N>,0> | (N extends 0 ? never : N);
463
-
464
- type IsVersionGreaterThan0<
465
- V extends number
466
- > = V extends 0 ? false : true;
467
-
468
- type AnyVersionGreaterThan1<
469
- T extends Record<string, SchemaType>
470
- > = true extends {
471
- [K in keyof T]: IsVersionGreaterThan0<T[K]['version']>;
472
- } [keyof T] ? true : false;
418
+ declare class CoreStorage {
419
+ /**
420
+ * @param {any} document
421
+ * @param {Query} query
422
+ * @returns {boolean}
423
+ */
424
+ matchesQuery(document: any, query: Query<any>): boolean;
425
+ getPrimaryKeyTyped(value: any): string | number;
426
+ getIndexes(schema: Schema<any>, op: Operation): string[];
427
+ }
473
428
 
474
- type MigrationFunction<T extends SchemaType> = (doc: Doc <T> ) => Doc <T>
475
429
 
476
- type MigrationPathsForSchema<
477
- T extends SchemaType
478
- > = T['version'] extends 0 ? {}: // No migrations needed for version 1
479
- {
480
- [K in EnumerateFrom1To < T['version'] > ]: MigrationFunction<T> ;
481
- };
482
430
 
483
- type MigrationPathsForSchemas<
484
- T extends SchemaTypeRecord
485
- > = {
486
- [K in keyof T]: MigrationPathsForSchema<T[K]>;
431
+ type InternalsRecord = {
432
+ [name: string]: BaseStorage<SchemaTypeRecord>
487
433
  };
434
+ /**
435
+ * ExtractType is a utility type that maps a string representing a basic data type to the actual TypeScript type.
436
+ *
437
+ * @template T - A string literal type representing the basic data type ('string', 'number', 'boolean', 'object', 'array').
438
+ *
439
+ * @example
440
+ * type StringType = ExtractType<'string'>; // StringType is string
441
+ * type NumberType = ExtractType<'number'>; // NumberType is number
442
+ * type BooleanType = ExtractType<'boolean'>; // BooleanType is boolean
443
+ * type ObjectType = ExtractType<'object'>; // ObjectType is object
444
+ * type ArrayType = ExtractType<'array'>; // ArrayType is Array<any>
445
+ */
446
+ type ExtractType<T extends string> =
447
+ T extends "string" ? string :
448
+ T extends "number" ? number :
449
+ T extends "boolean" ? boolean :
450
+ T extends "object" ? object :
451
+ T extends "array" ? any[] :
452
+ undefined;
488
453
 
489
- type MigrationsParameter<
490
- T extends SchemaTypeRecord
491
- > = AnyVersionGreaterThan1<T> extends true ?
492
- {
493
- migrations: MigrationPathsForSchemas<T>
494
- }:
495
- {
496
- migrations?: never
497
- };
498
-
499
-
454
+ type IsOptional<T> =
455
+ T extends { required: true }
456
+ ? T extends { default: never }
457
+ ? false
458
+ : true
459
+ : true;
500
460
 
501
461
  /**
502
- * Represents the type definition for a schema.
462
+ * Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
463
+ *
464
+ * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
465
+ *
466
+ * type Document = Doc<Schema>; // Document is { name: string; age: number; }
503
467
  */
504
- type SchemaType = {
505
- /**
506
- * The version of the schema.
507
- */
508
- version: number;
509
-
510
- /**
511
- * The primary key of the schema.
512
- */
513
- primaryKey: string;
468
+ type Doc<T extends SchemaType> = {
469
+ [K in keyof T["properties"]]:
470
+ ExtractType<T['properties'][K]['type']>
471
+ } & {
472
+ __version?: number;
473
+ createdAt?: number;
474
+ updatedAt?: number;
475
+ };
514
476
 
515
- /**
516
- * The type of the schema.
517
- */
518
- type: SchemaFieldType;
519
- indexes?: string[];
520
- encrypted?: string[];
521
- /**
522
- * The properties defined in the schema.
523
- */
524
- properties: {
525
- [name: string]: Property;
526
- };
477
+ /**
478
+ * CreateDoc is a utility type for document creation that properly handles required vs optional fields
479
+ * during the creation process. Fields with default values or required: false become optional.
480
+ *
481
+ * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
482
+ */
483
+ type CreateDoc<T extends SchemaType> = {
484
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
485
+ ExtractType<T['properties'][K]['type']>
486
+ } & {
487
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
488
+ ExtractType<T['properties'][K]['type']>
489
+ } & {
490
+ __version?: number;
491
+ createdAt?: number;
492
+ updatedAt?: number;
527
493
  };
528
494
 
495
+ type QueryOptions = {
496
+ limit?: number;
497
+ offset?: number;
498
+ }
529
499
 
530
500
  /**
531
- * Represents a schema, including its definition and related methods.
532
- * You may be trying to build a storage, in any other can u won't need access tho this class.
533
- * Check this example
534
- *
535
- * ```typescript
536
- * class MyStorage extends <T extends SchemaTypeRecord> extends BaseStorage<T> {
537
- * example() {
538
- * const schema: Schema<any> = this.getSchema("mySchema")
539
- * }
540
- * }
541
- * ```
542
- * You alwayswill have access to getSchema through the Storage class.
543
- *
544
- * @template T - The schema type.
501
+ * Collection is a class that represents a collection of documents in a database.
502
+ * @template T - A schema type defining the structure of the documents in the collection.
545
503
  */
546
- declare class Schema<T extends SchemaType> {
547
- /**
548
- * The schema definition.
549
- */
550
- schema: Schema<T>;
504
+ declare class Collection<T extends SchemaType> {
505
+ /**
506
+ * Finds all documents in the collection.
507
+ *
508
+ * @returns A promise that resolves to an array of documents.
509
+ */
510
+ find(query: QueryType<T>, options?: QueryOptions): Promise<Doc<T>[]>;
511
+ /**
512
+ * count all documents in the collection.
513
+ *
514
+ * @returns A promise that resolves to an array of documents.
515
+ */
516
+ count(query: QueryType<T>, options?: QueryOptions): Promise<number>;
517
+ /**
518
+ * Finds a single document in the collection by its ID.
519
+ *
520
+ * @param id - The ID of the document to find.
521
+ * @returns A promise that resolves to the found document.
522
+ */
523
+ findById(id: string): Promise<Doc<T>>;
524
+ /**
525
+ * Updates a document in the collection by its ID.
526
+ *
527
+ * @param document - A partial document containing the fields to update.
528
+ * @returns A promise that resolves when the update is complete.
529
+ */
530
+ update(document: Partial<Doc<T>>): Promise<void>;
531
+ /**
532
+ * Creates a new document in the collection.
533
+ *
534
+ * @param document - The document to create.
535
+ * @returns A promise that resolves to the created document.
536
+ */
537
+ create(document: CreateDoc<T>): Promise<Doc<T>>;
538
+ /**
539
+ * Deletes a document in the collection by its ID.
540
+ *
541
+ * @param id - The ID of the document to delete.
542
+ * @returns A promise that resolves when the deletion is complete.
543
+ */
544
+ delete(id: string): Promise<void>;
545
+ }
551
546
 
552
- /**
553
- * Creates a new `Schema` instance from the provided definition.
554
- *
555
- * @template TS - The schema type.
556
- * @param {TS} defi, Debugnition - The schema definition.
557
- * @returns {Schema<TS>} The created `Schema` instance.
558
- */
559
- static create<TS extends SchemaType>(definition: TS): Schema<TS>;
560
547
 
561
- /**
562
- * The version of the schema.
563
- */
564
- readonly version: number;
565
548
 
566
- /**
567
- * The primary key of the schema.
568
- */
569
- readonly primaryKey: string;
570
549
 
571
- /**
572
- * The type of the schema.
573
- */
574
- readonly type: SchemaFieldType;
550
+ type Operators<T> = {
551
+ $gte?: number,
552
+ $gt?: number
553
+ $lt?: number,
554
+ $lte?: number,
555
+ $eq?: T,
556
+ $ne?: T
557
+ };
575
558
 
576
- /**
577
- * An optional array of indexes.
578
- */
579
- /**
580
- * An optional array of indexes.
581
- */
582
- readonly indexes?: (Extract<keyof T, string>)[];
559
+ type InOperator<T> = { $in?: T[] };
560
+ type NInOperator<T> = { $nin?: T[] };
583
561
 
584
- /**
585
- * An optional array of encrypted fields.
586
- */
587
- readonly encrypted?: (Extract<keyof T, string>)[];
562
+ type OperatorOrType<T> = T extends number ?
563
+ T | Operators<T> | InOperator<T> | NInOperator<T> :
564
+ T | InOperator<T> | NInOperator<T>;
588
565
 
589
- /**
590
- * The properties defined in the schema.
591
- */
592
- readonly properties: {
593
- [K in keyof T['properties'] as T['properties'][K]['required'] extends false | (T['properties'][K]['default'] extends undefined ? true: false) ? K : never]?: T['properties'][K];
594
- } & {
595
- [K in keyof T['properties'] as T['properties'][K]['required'] extends false ? never : K]: T['properties'][K];
596
- };
597
- /**
598
- * Converts the schema to a JSON representation.
599
- *
600
- * @returns {SchemaType} The JSON representation of the schema.
601
- */
602
- toJSON(): SchemaType;
566
+ type LogicalOperators<T extends SchemaType> = {
567
+ $and?: Partial<QueryType<T>>[];
568
+ $or?: Partial<QueryType<T>>[];
569
+ };
603
570
 
604
- validate(document: Doc<Schema<T>>): boolean;
571
+ type QueryType<T extends SchemaType> = ({
572
+ [K in keyof T['properties']as ExtractType<T['properties'][K]['type']> extends undefined ? never : K]?: OperatorOrType<
573
+ ExtractType<
574
+ T['properties'][K]['type']
575
+ >
576
+ >
577
+ } & LogicalOperators<T>) | LogicalOperators<T>[];
578
+
579
+ declare class Query<T extends SchemaType> {
580
+ constructor(query: QueryType<T>, schema:Schema<T>);
581
+ readonly query: QueryType<T>;
605
582
  }
606
583
 
607
584
 
@@ -670,6 +647,33 @@ declare class Property {
670
647
 
671
648
 
672
649
 
650
+ /**
651
+ * Represents an operation to be performed on a collection.
652
+ *
653
+ * @template T - The schema type of the collection.
654
+ */
655
+ type Operation<T extends SchemaType = SchemaType> = {
656
+ /**
657
+ * The name of the collection on which the operation will be performed.
658
+ */
659
+ collection: string,
660
+
661
+ /**
662
+ * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
663
+ */
664
+ opType: OpType,
665
+
666
+ /**
667
+ * The data involved in the operation, conforming to the schema type.
668
+ */
669
+ data: Doc<T>,
670
+
671
+ primaryKeyField?: string,
672
+ primaryKey?: string
673
+ }
674
+
675
+
676
+
673
677
  /**
674
678
  * Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
675
679
  * @internal
@@ -705,55 +709,51 @@ declare abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
705
709
  }
706
710
 
707
711
 
708
- declare const SchemaFieldType = {
709
- /**
710
- * String type for text data
711
- */
712
- string: 'string' as const,
713
-
714
- /**
715
- * Number type for numeric data (integers and floats)
716
- */
717
- number: 'number' as const,
718
-
719
- /**
720
- * Boolean type for true/false values
721
- */
722
- boolean: 'boolean' as const,
723
-
724
- /**
725
- * Array type for ordered collections of items
726
- */
727
- array: 'array' as const,
728
-
729
- /**
730
- * Object type for nested document structures
731
- */
732
- object: 'object' as const,
733
- };
712
+ type EnumerateUpTo<
713
+ N extends number,
714
+ Acc extends number[] = []
715
+ > = Acc['length'] extends N ?
716
+ Acc[number]:
717
+ EnumerateUpTo<N, [...Acc, Acc['length']]> ;
718
+
719
+ type EnumerateFrom1To<
720
+ N extends number
721
+ > = Exclude<EnumerateUpTo<N>,0> | (N extends 0 ? never : N);
734
722
 
723
+ type IsVersionGreaterThan0<
724
+ V extends number
725
+ > = V extends 0 ? false : true;
735
726
 
727
+ type AnyVersionGreaterThan1<
728
+ T extends Record<string, SchemaType>
729
+ > = true extends {
730
+ [K in keyof T]: IsVersionGreaterThan0<T[K]['version']>;
731
+ } [keyof T] ? true : false;
736
732
 
737
- /**
738
- * Represents an IndexDB storage system extending the base storage functionality.
739
- *
740
- * @template T - The schema type.
741
- */
742
- declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
743
- /**
744
- * Frees the resources used by the in-memory storage.
745
- */
746
- free(): void;
733
+ type MigrationFunction<T extends SchemaType> = (doc: Doc <T> ) => Doc <T>
747
734
 
748
- static create<SchemasCreate extends SchemaTypeRecord>(
749
- dbName: string,
750
- schemas: SchemasCreate,
751
- ): Promise<
752
- IndexDB<
753
- SchemasCreate
754
- >
755
- >;
756
- }
735
+ type MigrationPathsForSchema<
736
+ T extends SchemaType
737
+ > = T['version'] extends 0 ? {}: // No migrations needed for version 1
738
+ {
739
+ [K in EnumerateFrom1To < T['version'] > ]: MigrationFunction<T> ;
740
+ };
741
+
742
+ type MigrationPathsForSchemas<
743
+ T extends SchemaTypeRecord
744
+ > = {
745
+ [K in keyof T]: MigrationPathsForSchema<T[K]>;
746
+ };
747
+
748
+ type MigrationsParameter<
749
+ T extends SchemaTypeRecord
750
+ > = AnyVersionGreaterThan1<T> extends true ?
751
+ {
752
+ migrations: MigrationPathsForSchemas<T>
753
+ }:
754
+ {
755
+ migrations?: never
756
+ };
757
757
 
758
758
 
759
759
  /**
@@ -867,28 +867,41 @@ type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Modul
867
867
 
868
868
  interface InitOutput {
869
869
  readonly memory: WebAssembly.Memory;
870
- readonly __wbg_collection_free: (a: number) => void;
871
- readonly collection_name: (a: number, b: number) => void;
872
- readonly collection_schema: (a: number, b: number) => void;
873
- readonly collection_find: (a: number, b: number, c: number) => number;
874
- readonly collection_parse_query_options: (a: number, b: number, c: number) => void;
875
- readonly collection_count: (a: number, b: number, c: number) => number;
876
- readonly collection_findById: (a: number, b: number) => number;
877
- readonly collection_update: (a: number, b: number) => number;
878
- readonly collection_create: (a: number, b: number) => number;
879
- readonly collection_delete: (a: number, b: number) => number;
880
- readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
881
- readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
882
- readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
883
- readonly __wbg_operation_free: (a: number) => void;
884
- readonly operation_collection: (a: number, b: number) => void;
885
- readonly operation_opType: (a: number) => number;
886
- readonly operation_data: (a: number) => number;
887
- readonly operation_primaryKeyField: (a: number) => number;
888
- readonly operation_primaryKey: (a: number) => number;
889
- readonly operation_primaryKeyIndex: (a: number, b: number) => void;
890
- readonly corestorage_new: () => number;
891
- readonly __wbg_corestorage_free: (a: number) => void;
870
+ readonly __wbg_ridberror_free: (a: number) => void;
871
+ readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
872
+ readonly ridberror_type: (a: number, b: number) => void;
873
+ readonly ridberror_code: (a: number) => number;
874
+ readonly ridberror_message: (a: number, b: number) => void;
875
+ readonly ridberror_from: (a: number) => number;
876
+ readonly ridberror_error: (a: number, b: number, c: number) => number;
877
+ readonly ridberror_query: (a: number, b: number, c: number) => number;
878
+ readonly ridberror_authentication: (a: number, b: number, c: number) => number;
879
+ readonly ridberror_serialisation: (a: number, b: number, c: number) => number;
880
+ readonly ridberror_validation: (a: number, b: number, c: number) => number;
881
+ readonly ridberror_hook: (a: number, b: number, c: number) => number;
882
+ readonly __wbg_schema_free: (a: number) => void;
883
+ readonly schema_validate: (a: number, b: number, c: number) => void;
884
+ readonly schema_is_valid: (a: number, b: number) => void;
885
+ readonly schema_create: (a: number, b: number) => void;
886
+ readonly schema_version: (a: number) => number;
887
+ readonly schema_primaryKey: (a: number, b: number) => void;
888
+ readonly schema_type: (a: number, b: number) => void;
889
+ readonly schema_indexes: (a: number, b: number) => void;
890
+ readonly schema_encrypted: (a: number, b: number) => void;
891
+ readonly schema_properties: (a: number, b: number) => void;
892
+ readonly __wbgt_test_schema_creation_3: (a: number) => void;
893
+ readonly __wbgt_test_schema_validation_4: (a: number) => void;
894
+ readonly __wbgt_test_invalid_schema_5: (a: number) => void;
895
+ readonly main_js: () => void;
896
+ readonly is_debug_mode: () => number;
897
+ readonly __wbg_inmemory_free: (a: number) => void;
898
+ readonly inmemory_create: (a: number, b: number, c: number) => number;
899
+ readonly inmemory_write: (a: number, b: number) => number;
900
+ readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
901
+ readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
902
+ readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
903
+ readonly inmemory_close: (a: number) => number;
904
+ readonly inmemory_start: (a: number) => number;
892
905
  readonly __wbg_basestorage_free: (a: number) => void;
893
906
  readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
894
907
  readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
@@ -902,9 +915,6 @@ interface InitOutput {
902
915
  readonly database_authenticate: (a: number, b: number, c: number) => number;
903
916
  readonly database_collections: (a: number, b: number) => void;
904
917
  readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
905
- readonly __wbg_queryoptions_free: (a: number) => void;
906
- readonly queryoptions_limit: (a: number, b: number) => void;
907
- readonly queryoptions_offset: (a: number, b: number) => void;
908
918
  readonly __wbg_baseplugin_free: (a: number) => void;
909
919
  readonly baseplugin_new: (a: number, b: number, c: number) => void;
910
920
  readonly baseplugin_name: (a: number) => number;
@@ -912,6 +922,35 @@ interface InitOutput {
912
922
  readonly baseplugin_get_doc_recover_hook: (a: number) => number;
913
923
  readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
914
924
  readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
925
+ readonly __wbg_indexdb_free: (a: number) => void;
926
+ readonly indexdb_get_stores: (a: number, b: number) => void;
927
+ readonly indexdb_get_store: (a: number, b: number, c: number, d: number) => void;
928
+ readonly indexdb_get_store_readonly: (a: number, b: number, c: number, d: number) => void;
929
+ readonly indexdb_create: (a: number, b: number, c: number) => number;
930
+ readonly indexdb_write: (a: number, b: number) => number;
931
+ readonly indexdb_find: (a: number, b: number, c: number, d: number, e: number) => number;
932
+ readonly indexdb_findDocumentById: (a: number, b: number, c: number, d: number) => number;
933
+ readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
934
+ readonly indexdb_close: (a: number) => number;
935
+ readonly indexdb_start: (a: number) => number;
936
+ readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
937
+ readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
938
+ readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
939
+ readonly __wbg_queryoptions_free: (a: number) => void;
940
+ readonly queryoptions_limit: (a: number, b: number) => void;
941
+ readonly queryoptions_offset: (a: number, b: number) => void;
942
+ readonly corestorage_new: () => number;
943
+ readonly __wbg_corestorage_free: (a: number) => void;
944
+ readonly __wbg_collection_free: (a: number) => void;
945
+ readonly collection_name: (a: number, b: number) => void;
946
+ readonly collection_schema: (a: number, b: number) => void;
947
+ readonly collection_find: (a: number, b: number, c: number) => number;
948
+ readonly collection_parse_query_options: (a: number, b: number, c: number) => void;
949
+ readonly collection_count: (a: number, b: number, c: number) => number;
950
+ readonly collection_findById: (a: number, b: number) => number;
951
+ readonly collection_update: (a: number, b: number) => number;
952
+ readonly collection_create: (a: number, b: number) => number;
953
+ readonly collection_delete: (a: number, b: number) => number;
915
954
  readonly __wbg_query_free: (a: number) => void;
916
955
  readonly query_new: (a: number, b: number, c: number) => void;
917
956
  readonly query_query: (a: number, b: number) => void;
@@ -949,41 +988,6 @@ interface InitOutput {
949
988
  readonly __wbgt_test_query_parse_eq_operator_wrong_type_32: (a: number) => void;
950
989
  readonly __wbgt_test_query_parse_ne_operator_33: (a: number) => void;
951
990
  readonly __wbgt_test_query_parse_ne_operator_wrong_type_34: (a: number) => void;
952
- readonly __wbg_inmemory_free: (a: number) => void;
953
- readonly inmemory_create: (a: number, b: number, c: number) => number;
954
- readonly inmemory_write: (a: number, b: number) => number;
955
- readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
956
- readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
957
- readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
958
- readonly inmemory_close: (a: number) => number;
959
- readonly inmemory_start: (a: number) => number;
960
- readonly main_js: () => void;
961
- readonly is_debug_mode: () => number;
962
- readonly __wbg_ridberror_free: (a: number) => void;
963
- readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
964
- readonly ridberror_type: (a: number, b: number) => void;
965
- readonly ridberror_code: (a: number) => number;
966
- readonly ridberror_message: (a: number, b: number) => void;
967
- readonly ridberror_from: (a: number) => number;
968
- readonly ridberror_error: (a: number, b: number, c: number) => number;
969
- readonly ridberror_query: (a: number, b: number, c: number) => number;
970
- readonly ridberror_authentication: (a: number, b: number, c: number) => number;
971
- readonly ridberror_serialisation: (a: number, b: number, c: number) => number;
972
- readonly ridberror_validation: (a: number, b: number, c: number) => number;
973
- readonly ridberror_hook: (a: number, b: number, c: number) => number;
974
- readonly __wbg_schema_free: (a: number) => void;
975
- readonly schema_validate: (a: number, b: number, c: number) => void;
976
- readonly schema_is_valid: (a: number, b: number) => void;
977
- readonly schema_create: (a: number, b: number) => void;
978
- readonly schema_version: (a: number) => number;
979
- readonly schema_primaryKey: (a: number, b: number) => void;
980
- readonly schema_type: (a: number, b: number) => void;
981
- readonly schema_indexes: (a: number, b: number) => void;
982
- readonly schema_encrypted: (a: number, b: number) => void;
983
- readonly schema_properties: (a: number, b: number) => void;
984
- readonly __wbgt_test_schema_creation_3: (a: number) => void;
985
- readonly __wbgt_test_schema_validation_4: (a: number) => void;
986
- readonly __wbgt_test_invalid_schema_5: (a: number) => void;
987
991
  readonly __wbg_property_free: (a: number) => void;
988
992
  readonly property_is_valid: (a: number, b: number) => void;
989
993
  readonly property_type: (a: number) => number;
@@ -996,16 +1000,13 @@ interface InitOutput {
996
1000
  readonly __wbgt_test_property_creation_0: (a: number) => void;
997
1001
  readonly __wbgt_test_property_validation_1: (a: number) => void;
998
1002
  readonly __wbgt_test_invalid_property_2: (a: number) => void;
999
- readonly __wbg_indexdb_free: (a: number) => void;
1000
- readonly indexdb_get_stores: (a: number, b: number) => void;
1001
- readonly indexdb_get_store: (a: number, b: number, c: number, d: number) => void;
1002
- readonly indexdb_create: (a: number, b: number, c: number) => number;
1003
- readonly indexdb_write: (a: number, b: number) => number;
1004
- readonly indexdb_find: (a: number, b: number, c: number, d: number, e: number) => number;
1005
- readonly indexdb_findDocumentById: (a: number, b: number, c: number, d: number) => number;
1006
- readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
1007
- readonly indexdb_close: (a: number) => number;
1008
- readonly indexdb_start: (a: number) => number;
1003
+ readonly __wbg_operation_free: (a: number) => void;
1004
+ readonly operation_collection: (a: number, b: number) => void;
1005
+ readonly operation_opType: (a: number) => number;
1006
+ readonly operation_data: (a: number) => number;
1007
+ readonly operation_primaryKeyField: (a: number) => number;
1008
+ readonly operation_primaryKey: (a: number) => number;
1009
+ readonly operation_primaryKeyIndex: (a: number, b: number) => void;
1009
1010
  readonly __wbg_wasmbindgentestcontext_free: (a: number) => void;
1010
1011
  readonly wasmbindgentestcontext_new: () => number;
1011
1012
  readonly wasmbindgentestcontext_args: (a: number, b: number, c: number) => void;