@trust0/ridb-core 1.7.32 → 1.7.34

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,209 +73,6 @@ declare enum Errors {
73
73
  AuthenticationError = 5,
74
74
  }
75
75
 
76
- /**
77
- * Represents the type definition for a schema.
78
- */
79
- type SchemaType = {
80
- /**
81
- * The version of the schema.
82
- */
83
- version: number;
84
-
85
- /**
86
- * The primary key of the schema.
87
- */
88
- primaryKey: string;
89
-
90
- /**
91
- * The type of the schema.
92
- */
93
- type: SchemaFieldType;
94
- indexes?: string[];
95
- encrypted?: string[];
96
- /**
97
- * The properties defined in the schema.
98
- */
99
- properties: {
100
- [name: string]: Property;
101
- };
102
- };
103
-
104
-
105
- /**
106
- * Represents a schema, including its definition and related methods.
107
- * You may be trying to build a storage, in any other can u won't need access tho this class.
108
- * Check this example
109
- *
110
- * ```typescript
111
- * class MyStorage extends <T extends SchemaTypeRecord> extends BaseStorage<T> {
112
- * example() {
113
- * const schema: Schema<any> = this.getSchema("mySchema")
114
- * }
115
- * }
116
- * ```
117
- * You alwayswill have access to getSchema through the Storage class.
118
- *
119
- * @template T - The schema type.
120
- */
121
- declare class Schema<T extends SchemaType> {
122
- /**
123
- * The schema definition.
124
- */
125
- schema: Schema<T>;
126
-
127
- /**
128
- * Creates a new `Schema` instance from the provided definition.
129
- *
130
- * @template TS - The schema type.
131
- * @param {TS} defi, Debugnition - The schema definition.
132
- * @returns {Schema<TS>} The created `Schema` instance.
133
- */
134
- static create<TS extends SchemaType>(definition: TS): Schema<TS>;
135
-
136
- /**
137
- * The version of the schema.
138
- */
139
- readonly version: number;
140
-
141
- /**
142
- * The primary key of the schema.
143
- */
144
- readonly primaryKey: string;
145
-
146
- /**
147
- * The type of the schema.
148
- */
149
- readonly type: SchemaFieldType;
150
-
151
- /**
152
- * An optional array of indexes.
153
- */
154
- /**
155
- * An optional array of indexes.
156
- */
157
- readonly indexes?: (Extract<keyof T, string>)[];
158
-
159
- /**
160
- * An optional array of encrypted fields.
161
- */
162
- readonly encrypted?: (Extract<keyof T, string>)[];
163
-
164
- /**
165
- * The properties defined in the schema.
166
- */
167
- readonly properties: {
168
- [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];
169
- } & {
170
- [K in keyof T['properties'] as T['properties'][K]['required'] extends false ? never : K]: T['properties'][K];
171
- };
172
- /**
173
- * Converts the schema to a JSON representation.
174
- *
175
- * @returns {SchemaType} The JSON representation of the schema.
176
- */
177
- toJSON(): SchemaType;
178
-
179
- validate(document: Doc<Schema<T>>): boolean;
180
- }
181
-
182
-
183
-
184
- type EnumerateUpTo<
185
- N extends number,
186
- Acc extends number[] = []
187
- > = Acc['length'] extends N ?
188
- Acc[number]:
189
- EnumerateUpTo<N, [...Acc, Acc['length']]> ;
190
-
191
- type EnumerateFrom1To<
192
- N extends number
193
- > = Exclude<EnumerateUpTo<N>,0> | (N extends 0 ? never : N);
194
-
195
- type IsVersionGreaterThan0<
196
- V extends number
197
- > = V extends 0 ? false : true;
198
-
199
- type AnyVersionGreaterThan1<
200
- T extends Record<string, SchemaType>
201
- > = true extends {
202
- [K in keyof T]: IsVersionGreaterThan0<T[K]['version']>;
203
- } [keyof T] ? true : false;
204
-
205
- type MigrationFunction<T extends SchemaType> = (doc: Doc <T> ) => Doc <T>
206
-
207
- type MigrationPathsForSchema<
208
- T extends SchemaType
209
- > = T['version'] extends 0 ? {}: // No migrations needed for version 1
210
- {
211
- [K in EnumerateFrom1To < T['version'] > ]: MigrationFunction<T> ;
212
- };
213
-
214
- type MigrationPathsForSchemas<
215
- T extends SchemaTypeRecord
216
- > = {
217
- [K in keyof T]: MigrationPathsForSchema<T[K]>;
218
- };
219
-
220
- type MigrationsParameter<
221
- T extends SchemaTypeRecord
222
- > = AnyVersionGreaterThan1<T> extends true ?
223
- {
224
- migrations: MigrationPathsForSchemas<T>
225
- }:
226
- {
227
- migrations?: never
228
- };
229
-
230
-
231
-
232
- type Hook = (
233
- schema: Schema<SchemaType>,
234
- migration: MigrationPathsForSchema<SchemaType>,
235
- doc: Doc<SchemaType>
236
- ) => Doc<SchemaType>
237
-
238
- type BasePluginOptions = {
239
- docCreateHook?: Hook,
240
- docRecoverHook?: Hook
241
- }
242
-
243
- declare class BasePlugin implements BasePluginOptions {
244
- docCreateHook?:Hook;
245
- docRecoverHook?:Hook;
246
- }
247
-
248
-
249
-
250
- declare const SchemaFieldType = {
251
- /**
252
- * String type for text data
253
- */
254
- string: 'string' as const,
255
-
256
- /**
257
- * Number type for numeric data (integers and floats)
258
- */
259
- number: 'number' as const,
260
-
261
- /**
262
- * Boolean type for true/false values
263
- */
264
- boolean: 'boolean' as const,
265
-
266
- /**
267
- * Array type for ordered collections of items
268
- */
269
- array: 'array' as const,
270
-
271
- /**
272
- * Object type for nested document structures
273
- */
274
- object: 'object' as const,
275
- };
276
-
277
-
278
-
279
76
  type InternalsRecord = {
280
77
  [name: string]: BaseStorage<SchemaTypeRecord>
281
78
  };
@@ -395,6 +192,46 @@ declare class Collection<T extends SchemaType> {
395
192
 
396
193
 
397
194
 
195
+ declare class CoreStorage {
196
+ /**
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
+ }
205
+
206
+
207
+
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
+ /**
215
+ * The name of the collection on which the operation will be performed.
216
+ */
217
+ collection: string,
218
+
219
+ /**
220
+ * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
221
+ */
222
+ opType: OpType,
223
+
224
+ /**
225
+ * The data involved in the operation, conforming to the schema type.
226
+ */
227
+ data: Doc<T>,
228
+
229
+ primaryKeyField?: string,
230
+ primaryKey?: string
231
+ }
232
+
233
+
234
+
398
235
  type BaseStorageOptions = {
399
236
  [name:string]:string | boolean | number
400
237
  }
@@ -433,24 +270,123 @@ declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInter
433
270
 
434
271
 
435
272
  /**
436
- * Represents an IndexDB storage system extending the base storage functionality.
437
- *
438
- * @template T - The schema type.
439
- */
440
- declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
441
- /**
442
- * Frees the resources used by the in-memory storage.
443
- */
444
- free(): void;
445
-
446
- static create<SchemasCreate extends SchemaTypeRecord>(
447
- dbName: string,
448
- schemas: SchemasCreate,
449
- ): Promise<
450
- IndexDB<
451
- SchemasCreate
452
- >
453
- >;
273
+ * Represents a database containing collections of documents.
274
+ * RIDB extends from this class and is used to expose collections.
275
+ *
276
+ * So if you specify:
277
+ * ```typescript
278
+ * const db = new RIDB(
279
+ * {
280
+ * schemas: {
281
+ * demo: {
282
+ * version: 0,
283
+ * primaryKey: 'id',
284
+ * type: SchemaFieldType.object,
285
+ * properties: {
286
+ * id: {
287
+ * type: SchemaFieldType.string,
288
+ * maxLength: 60
289
+ * }
290
+ * }
291
+ * }
292
+ * } as const
293
+ * }
294
+ * )
295
+ * ```
296
+ *
297
+ * The collection will be available as `db.collections.demo` and all the methods for the collection (find, count, findById, update, create, delete) will be available.
298
+ *
299
+ * @template T - A record of schema types.
300
+ */
301
+ declare class Database<T extends SchemaTypeRecord> {
302
+
303
+ /**
304
+ * Creates a new `Database` instance with the provided schemas and storage module.
305
+ *
306
+ * @template TS - A record of schema types.
307
+ * @param {TS} schemas - The schemas to use for the collections.
308
+ * @param migrations
309
+ * @param plugins
310
+ * @param options
311
+ * @param password
312
+ * @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
313
+ */
314
+ static create<TS extends SchemaTypeRecord>(
315
+ db_name: string,
316
+ schemas: TS,
317
+ migrations: MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>,
318
+ plugins:Array<typeof BasePlugin>,
319
+ options: RIDBModule,
320
+ password?:string,
321
+ storage?: BaseStorage<TS>
322
+ ): Promise<Database<TS>>;
323
+
324
+ authenticate(password: string): Promise<boolean>;
325
+
326
+ /**
327
+ * The collections in the database.
328
+ *
329
+ * This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
330
+ */
331
+ readonly collections: {
332
+ [name in keyof T]: Collection<Schema<T[name]>>
333
+ }
334
+
335
+ readonly started: boolean;
336
+
337
+ /**
338
+ * Starts the database.
339
+ *
340
+ * @returns {Promise<void>} A promise that resolves when the database is started.
341
+ */
342
+ start(): Promise<void>;
343
+
344
+ /**
345
+ * Closes the database.
346
+ *
347
+ * @returns {Promise<void>} A promise that resolves when the database is closed.
348
+ */
349
+ close(): Promise<void>;
350
+ }
351
+
352
+ /**
353
+ * Represents a function type for creating storage with the provided schema type records.
354
+ *
355
+ * @template T - The schema type record.
356
+ * @param {T} records - The schema type records.
357
+ * @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
358
+ */
359
+ type CreateStorage = <T extends SchemaTypeRecord>(
360
+ records: T
361
+ ) => Promise<BaseStorage<T>>;
362
+
363
+ /**
364
+ * Represents a storage module with a method for creating storage.
365
+ */
366
+ type RIDBModule = {
367
+
368
+ /**
369
+ * Plugin constructors array
370
+ */
371
+ apply: (plugins:Array<typeof BasePlugin>) => Array<BasePlugin>;
372
+ };
373
+
374
+
375
+
376
+ type Hook = (
377
+ schema: Schema<SchemaType>,
378
+ migration: MigrationPathsForSchema<SchemaType>,
379
+ doc: Doc<SchemaType>
380
+ ) => Doc<SchemaType>
381
+
382
+ type BasePluginOptions = {
383
+ docCreateHook?: Hook,
384
+ docRecoverHook?: Hook
385
+ }
386
+
387
+ declare class BasePlugin implements BasePluginOptions {
388
+ docCreateHook?:Hook;
389
+ docRecoverHook?:Hook;
454
390
  }
455
391
 
456
392
 
@@ -492,232 +428,244 @@ declare class Query<T extends SchemaType> {
492
428
 
493
429
 
494
430
  /**
495
- * Represents a property within a schema, including various constraints and nested properties.
431
+ * Represents an in-memory storage system extending the base storage functionality.
432
+ *
433
+ * @template T - The schema type.
496
434
  */
497
- declare class Property {
435
+ declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
498
436
  /**
499
- * The type of the property.
437
+ * Frees the resources used by the in-memory storage.
500
438
  */
501
- readonly type: SchemaFieldType;
439
+ free(): void;
440
+
441
+ static create<SchemasCreate extends SchemaTypeRecord>(
442
+ dbName: string,
443
+ schemas: SchemasCreate,
444
+ ): Promise<
445
+ InMemory<
446
+ SchemasCreate
447
+ >
448
+ >;
449
+ }
450
+
451
+
452
+
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;
473
+
474
+ type MigrationFunction<T extends SchemaType> = (doc: Doc <T> ) => Doc <T>
475
+
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
+
483
+ type MigrationPathsForSchemas<
484
+ T extends SchemaTypeRecord
485
+ > = {
486
+ [K in keyof T]: MigrationPathsForSchema<T[K]>;
487
+ };
488
+
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
+
500
+
501
+ /**
502
+ * Represents the type definition for a schema.
503
+ */
504
+ type SchemaType = {
505
+ /**
506
+ * The version of the schema.
507
+ */
508
+ version: number;
502
509
 
503
510
  /**
504
- * The version of the property, if applicable.
511
+ * The primary key of the schema.
505
512
  */
506
- readonly version?: number;
513
+ primaryKey: string;
507
514
 
508
515
  /**
509
- * The primary key of the property, if applicable.
516
+ * The type of the schema.
510
517
  */
511
- readonly primaryKey?: string;
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
+ };
527
+ };
512
528
 
529
+
530
+ /**
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.
545
+ */
546
+ declare class Schema<T extends SchemaType> {
513
547
  /**
514
- * An optional array of nested properties for array-type properties.
548
+ * The schema definition.
515
549
  */
516
- readonly items?: Property;
550
+ schema: Schema<T>;
517
551
 
518
552
  /**
519
- * The maximum number of items for array-type properties, if applicable.
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.
520
558
  */
521
- readonly maxItems?: number;
559
+ static create<TS extends SchemaType>(definition: TS): Schema<TS>;
522
560
 
523
561
  /**
524
- * The minimum number of items for array-type properties, if applicable.
562
+ * The version of the schema.
525
563
  */
526
- readonly minItems?: number;
564
+ readonly version: number;
527
565
 
528
566
  /**
529
- * The maximum length for string-type properties, if applicable.
567
+ * The primary key of the schema.
530
568
  */
531
- readonly maxLength?: number;
569
+ readonly primaryKey: string;
532
570
 
533
571
  /**
534
- * The minimum length for string-type properties, if applicable.
572
+ * The type of the schema.
535
573
  */
536
- readonly minLength?: number;
574
+ readonly type: SchemaFieldType;
537
575
 
538
576
  /**
539
- * An optional array of required fields for object-type properties.
577
+ * An optional array of indexes.
540
578
  */
541
- readonly required?: boolean;
579
+ /**
580
+ * An optional array of indexes.
581
+ */
582
+ readonly indexes?: (Extract<keyof T, string>)[];
542
583
 
543
584
  /**
544
- * An optional default value for the property.
585
+ * An optional array of encrypted fields.
545
586
  */
546
- readonly default?: any;
587
+ readonly encrypted?: (Extract<keyof T, string>)[];
547
588
 
548
589
  /**
549
- * An optional map of nested properties for object-type properties.
590
+ * The properties defined in the schema.
550
591
  */
551
- readonly properties?: {
552
- [name: string]: Property;
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];
553
596
  };
554
- }
555
-
556
-
557
-
558
- /**
559
- * Represents an in-memory storage system extending the base storage functionality.
560
- *
561
- * @template T - The schema type.
562
- */
563
- declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
564
597
  /**
565
- * Frees the resources used by the in-memory storage.
598
+ * Converts the schema to a JSON representation.
599
+ *
600
+ * @returns {SchemaType} The JSON representation of the schema.
566
601
  */
567
- free(): void;
568
-
569
- static create<SchemasCreate extends SchemaTypeRecord>(
570
- dbName: string,
571
- schemas: SchemasCreate,
572
- ): Promise<
573
- InMemory<
574
- SchemasCreate
575
- >
576
- >;
577
- }
578
-
579
-
602
+ toJSON(): SchemaType;
580
603
 
581
- declare class CoreStorage {
582
- /**
583
- * @param {any} document
584
- * @param {Query} query
585
- * @returns {boolean}
586
- */
587
- matchesQuery(document: any, query: Query<any>): boolean;
588
- getPrimaryKeyTyped(value: any): string | number;
589
- getIndexes(schema: Schema<any>, op: Operation): string[];
604
+ validate(document: Doc<Schema<T>>): boolean;
590
605
  }
591
606
 
592
607
 
593
608
 
594
609
  /**
595
- * Represents a database containing collections of documents.
596
- * RIDB extends from this class and is used to expose collections.
597
- *
598
- * So if you specify:
599
- * ```typescript
600
- * const db = new RIDB(
601
- * {
602
- * schemas: {
603
- * demo: {
604
- * version: 0,
605
- * primaryKey: 'id',
606
- * type: SchemaFieldType.object,
607
- * properties: {
608
- * id: {
609
- * type: SchemaFieldType.string,
610
- * maxLength: 60
611
- * }
612
- * }
613
- * }
614
- * } as const
615
- * }
616
- * )
617
- * ```
618
- *
619
- * The collection will be available as `db.collections.demo` and all the methods for the collection (find, count, findById, update, create, delete) will be available.
620
- *
621
- * @template T - A record of schema types.
610
+ * Represents a property within a schema, including various constraints and nested properties.
622
611
  */
623
- declare class Database<T extends SchemaTypeRecord> {
624
-
612
+ declare class Property {
625
613
  /**
626
- * Creates a new `Database` instance with the provided schemas and storage module.
627
- *
628
- * @template TS - A record of schema types.
629
- * @param {TS} schemas - The schemas to use for the collections.
630
- * @param migrations
631
- * @param plugins
632
- * @param options
633
- * @param password
634
- * @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
614
+ * The type of the property.
635
615
  */
636
- static create<TS extends SchemaTypeRecord>(
637
- db_name: string,
638
- schemas: TS,
639
- migrations: MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>,
640
- plugins:Array<typeof BasePlugin>,
641
- options: RIDBModule,
642
- password?:string,
643
- storage?: BaseStorage<TS>
644
- ): Promise<Database<TS>>;
616
+ readonly type: SchemaFieldType;
645
617
 
646
- authenticate(password: string): Promise<boolean>;
618
+ /**
619
+ * The version of the property, if applicable.
620
+ */
621
+ readonly version?: number;
647
622
 
648
623
  /**
649
- * The collections in the database.
650
- *
651
- * This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
624
+ * The primary key of the property, if applicable.
652
625
  */
653
- readonly collections: {
654
- [name in keyof T]: Collection<Schema<T[name]>>
655
- }
626
+ readonly primaryKey?: string;
656
627
 
657
- readonly started: boolean;
628
+ /**
629
+ * An optional array of nested properties for array-type properties.
630
+ */
631
+ readonly items?: Property;
658
632
 
659
633
  /**
660
- * Starts the database.
661
- *
662
- * @returns {Promise<void>} A promise that resolves when the database is started.
634
+ * The maximum number of items for array-type properties, if applicable.
663
635
  */
664
- start(): Promise<void>;
636
+ readonly maxItems?: number;
665
637
 
666
638
  /**
667
- * Closes the database.
668
- *
669
- * @returns {Promise<void>} A promise that resolves when the database is closed.
639
+ * The minimum number of items for array-type properties, if applicable.
670
640
  */
671
- close(): Promise<void>;
672
- }
673
-
674
- /**
675
- * Represents a function type for creating storage with the provided schema type records.
676
- *
677
- * @template T - The schema type record.
678
- * @param {T} records - The schema type records.
679
- * @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
680
- */
681
- type CreateStorage = <T extends SchemaTypeRecord>(
682
- records: T
683
- ) => Promise<BaseStorage<T>>;
684
-
685
- /**
686
- * Represents a storage module with a method for creating storage.
687
- */
688
- type RIDBModule = {
641
+ readonly minItems?: number;
689
642
 
690
643
  /**
691
- * Plugin constructors array
644
+ * The maximum length for string-type properties, if applicable.
692
645
  */
693
- apply: (plugins:Array<typeof BasePlugin>) => Array<BasePlugin>;
694
- };
695
-
696
-
646
+ readonly maxLength?: number;
697
647
 
698
- /**
699
- * Represents an operation to be performed on a collection.
700
- *
701
- * @template T - The schema type of the collection.
702
- */
703
- type Operation<T extends SchemaType = SchemaType> = {
704
648
  /**
705
- * The name of the collection on which the operation will be performed.
649
+ * The minimum length for string-type properties, if applicable.
706
650
  */
707
- collection: string,
651
+ readonly minLength?: number;
708
652
 
709
653
  /**
710
- * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
654
+ * An optional array of required fields for object-type properties.
711
655
  */
712
- opType: OpType,
656
+ readonly required?: boolean;
713
657
 
714
658
  /**
715
- * The data involved in the operation, conforming to the schema type.
659
+ * An optional default value for the property.
716
660
  */
717
- data: Doc<T>,
661
+ readonly default?: any;
718
662
 
719
- primaryKeyField?: string,
720
- primaryKey?: string
663
+ /**
664
+ * An optional map of nested properties for object-type properties.
665
+ */
666
+ readonly properties?: {
667
+ [name: string]: Property;
668
+ };
721
669
  }
722
670
 
723
671
 
@@ -756,6 +704,58 @@ declare abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
756
704
  ): Promise<Doc<Schemas[keyof Schemas]>>;
757
705
  }
758
706
 
707
+
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
+ };
734
+
735
+
736
+
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;
747
+
748
+ static create<SchemasCreate extends SchemaTypeRecord>(
749
+ dbName: string,
750
+ schemas: SchemasCreate,
751
+ ): Promise<
752
+ IndexDB<
753
+ SchemasCreate
754
+ >
755
+ >;
756
+ }
757
+
758
+
759
759
  /**
760
760
  */
761
761
  declare class RIDBError {
@@ -867,26 +867,6 @@ type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Modul
867
867
 
868
868
  interface InitOutput {
869
869
  readonly memory: WebAssembly.Memory;
870
- readonly __wbg_schema_free: (a: number) => void;
871
- readonly schema_validate: (a: number, b: number, c: number) => void;
872
- readonly schema_is_valid: (a: number, b: number) => void;
873
- readonly schema_create: (a: number, b: number) => void;
874
- readonly schema_version: (a: number) => number;
875
- readonly schema_primaryKey: (a: number, b: number) => void;
876
- readonly schema_type: (a: number, b: number) => void;
877
- readonly schema_indexes: (a: number, b: number) => void;
878
- readonly schema_encrypted: (a: number, b: number) => void;
879
- readonly schema_properties: (a: number, b: number) => void;
880
- readonly __wbgt_test_schema_creation_3: (a: number) => void;
881
- readonly __wbgt_test_schema_validation_4: (a: number) => void;
882
- readonly __wbgt_test_invalid_schema_5: (a: number) => void;
883
- readonly __wbg_baseplugin_free: (a: number) => void;
884
- readonly baseplugin_new: (a: number, b: number, c: number) => void;
885
- readonly baseplugin_name: (a: number) => number;
886
- readonly baseplugin_get_doc_create_hook: (a: number) => number;
887
- readonly baseplugin_get_doc_recover_hook: (a: number) => number;
888
- readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
889
- readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
890
870
  readonly __wbg_collection_free: (a: number) => void;
891
871
  readonly collection_name: (a: number, b: number) => void;
892
872
  readonly collection_schema: (a: number, b: number) => void;
@@ -897,39 +877,41 @@ interface InitOutput {
897
877
  readonly collection_update: (a: number, b: number) => number;
898
878
  readonly collection_create: (a: number, b: number) => number;
899
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;
900
892
  readonly __wbg_basestorage_free: (a: number) => void;
901
893
  readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
902
894
  readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
903
895
  readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
904
896
  readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
905
897
  readonly basestorage_core: (a: number, b: number) => void;
906
- readonly main_js: () => void;
907
- readonly is_debug_mode: () => number;
908
- readonly __wbg_ridberror_free: (a: number) => void;
909
- readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
910
- readonly ridberror_type: (a: number, b: number) => void;
911
- readonly ridberror_code: (a: number) => number;
912
- readonly ridberror_message: (a: number, b: number) => void;
913
- readonly ridberror_from: (a: number) => number;
914
- readonly ridberror_error: (a: number, b: number, c: number) => number;
915
- readonly ridberror_query: (a: number, b: number, c: number) => number;
916
- readonly ridberror_authentication: (a: number, b: number, c: number) => number;
917
- readonly ridberror_serialisation: (a: number, b: number, c: number) => number;
918
- readonly ridberror_validation: (a: number, b: number, c: number) => number;
919
- readonly ridberror_hook: (a: number, b: number, c: number) => number;
920
- readonly __wbg_indexdb_free: (a: number) => void;
921
- readonly indexdb_get_stores: (a: number, b: number) => void;
922
- readonly indexdb_get_store: (a: number, b: number, c: number, d: number) => void;
923
- readonly indexdb_create: (a: number, b: number, c: number) => number;
924
- readonly indexdb_write: (a: number, b: number) => number;
925
- readonly indexdb_find: (a: number, b: number, c: number, d: number, e: number) => number;
926
- readonly indexdb_findDocumentById: (a: number, b: number, c: number, d: number) => number;
927
- readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
928
- readonly indexdb_close: (a: number) => number;
929
- readonly indexdb_start: (a: number) => number;
898
+ readonly __wbg_database_free: (a: number) => void;
899
+ readonly database_start: (a: number) => number;
900
+ readonly database_close: (a: number) => number;
901
+ readonly database_started: (a: number) => number;
902
+ readonly database_authenticate: (a: number, b: number, c: number) => number;
903
+ readonly database_collections: (a: number, b: number) => void;
904
+ readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
930
905
  readonly __wbg_queryoptions_free: (a: number) => void;
931
906
  readonly queryoptions_limit: (a: number, b: number) => void;
932
907
  readonly queryoptions_offset: (a: number, b: number) => void;
908
+ readonly __wbg_baseplugin_free: (a: number) => void;
909
+ readonly baseplugin_new: (a: number, b: number, c: number) => void;
910
+ readonly baseplugin_name: (a: number) => number;
911
+ readonly baseplugin_get_doc_create_hook: (a: number) => number;
912
+ readonly baseplugin_get_doc_recover_hook: (a: number) => number;
913
+ readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
914
+ readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
933
915
  readonly __wbg_query_free: (a: number) => void;
934
916
  readonly query_new: (a: number, b: number, c: number) => void;
935
917
  readonly query_query: (a: number, b: number) => void;
@@ -937,6 +919,7 @@ interface InitOutput {
937
919
  readonly query_parse: (a: number, b: number) => void;
938
920
  readonly query_process_query: (a: number, b: number, c: number) => void;
939
921
  readonly query_get: (a: number, b: number, c: number, d: number) => void;
922
+ readonly query_has_or_operator: (a: number) => number;
940
923
  readonly __wbgt_test_get_properties_simple_fields_6: (a: number) => void;
941
924
  readonly __wbgt_test_get_properties_with_operators_7: (a: number) => void;
942
925
  readonly __wbgt_test_get_properties_with_logical_operators_8: (a: number) => void;
@@ -966,6 +949,41 @@ interface InitOutput {
966
949
  readonly __wbgt_test_query_parse_eq_operator_wrong_type_32: (a: number) => void;
967
950
  readonly __wbgt_test_query_parse_ne_operator_33: (a: number) => void;
968
951
  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;
969
987
  readonly __wbg_property_free: (a: number) => void;
970
988
  readonly property_is_valid: (a: number, b: number) => void;
971
989
  readonly property_type: (a: number) => number;
@@ -978,33 +996,16 @@ interface InitOutput {
978
996
  readonly __wbgt_test_property_creation_0: (a: number) => void;
979
997
  readonly __wbgt_test_property_validation_1: (a: number) => void;
980
998
  readonly __wbgt_test_invalid_property_2: (a: number) => void;
981
- readonly __wbg_inmemory_free: (a: number) => void;
982
- readonly inmemory_create: (a: number, b: number, c: number) => number;
983
- readonly inmemory_write: (a: number, b: number) => number;
984
- readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
985
- readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
986
- readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
987
- readonly inmemory_close: (a: number) => number;
988
- readonly inmemory_start: (a: number) => number;
989
- readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
990
- readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
991
- readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
992
- readonly __wbg_database_free: (a: number) => void;
993
- readonly database_start: (a: number) => number;
994
- readonly database_close: (a: number) => number;
995
- readonly database_started: (a: number) => number;
996
- readonly database_authenticate: (a: number, b: number, c: number) => number;
997
- readonly database_collections: (a: number, b: number) => void;
998
- readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
999
- readonly __wbg_operation_free: (a: number) => void;
1000
- readonly operation_collection: (a: number, b: number) => void;
1001
- readonly operation_opType: (a: number) => number;
1002
- readonly operation_data: (a: number) => number;
1003
- readonly operation_primaryKeyField: (a: number) => number;
1004
- readonly operation_primaryKey: (a: number) => number;
1005
- readonly operation_primaryKeyIndex: (a: number, b: number) => void;
1006
- readonly corestorage_new: () => number;
1007
- readonly __wbg_corestorage_free: (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;
1008
1009
  readonly __wbg_wasmbindgentestcontext_free: (a: number) => void;
1009
1010
  readonly wasmbindgentestcontext_new: () => number;
1010
1011
  readonly wasmbindgentestcontext_args: (a: number, b: number, c: number) => void;