@trust0/ridb-core 1.7.33 → 1.7.35

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.
@@ -38,16 +38,6 @@ declare function __wbgtest_console_warn(args: Array<any>): void;
38
38
  */
39
39
  declare function __wbgtest_console_error(args: Array<any>): void;
40
40
  /**
41
- */
42
- declare enum Errors {
43
- Error = 0,
44
- HookError = 1,
45
- QueryError = 2,
46
- SerializationError = 3,
47
- ValidationError = 4,
48
- AuthenticationError = 5,
49
- }
50
- /**
51
41
  * Represents the type of operation to be performed on the collection.
52
42
  */
53
43
  declare enum OpType {
@@ -72,6 +62,132 @@ declare enum OpType {
72
62
  */
73
63
  COUNT = 4,
74
64
  }
65
+ /**
66
+ */
67
+ declare enum Errors {
68
+ Error = 0,
69
+ HookError = 1,
70
+ QueryError = 2,
71
+ SerializationError = 3,
72
+ ValidationError = 4,
73
+ AuthenticationError = 5,
74
+ }
75
+
76
+ /**
77
+ * Represents a property within a schema, including various constraints and nested properties.
78
+ */
79
+ declare class Property {
80
+ /**
81
+ * The type of the property.
82
+ */
83
+ readonly type: SchemaFieldType;
84
+
85
+ /**
86
+ * The version of the property, if applicable.
87
+ */
88
+ readonly version?: number;
89
+
90
+ /**
91
+ * The primary key of the property, if applicable.
92
+ */
93
+ readonly primaryKey?: string;
94
+
95
+ /**
96
+ * An optional array of nested properties for array-type properties.
97
+ */
98
+ readonly items?: Property;
99
+
100
+ /**
101
+ * The maximum number of items for array-type properties, if applicable.
102
+ */
103
+ readonly maxItems?: number;
104
+
105
+ /**
106
+ * The minimum number of items for array-type properties, if applicable.
107
+ */
108
+ readonly minItems?: number;
109
+
110
+ /**
111
+ * The maximum length for string-type properties, if applicable.
112
+ */
113
+ readonly maxLength?: number;
114
+
115
+ /**
116
+ * The minimum length for string-type properties, if applicable.
117
+ */
118
+ readonly minLength?: number;
119
+
120
+ /**
121
+ * An optional array of required fields for object-type properties.
122
+ */
123
+ readonly required?: boolean;
124
+
125
+ /**
126
+ * An optional default value for the property.
127
+ */
128
+ readonly default?: any;
129
+
130
+ /**
131
+ * An optional map of nested properties for object-type properties.
132
+ */
133
+ readonly properties?: {
134
+ [name: string]: Property;
135
+ };
136
+ }
137
+
138
+
139
+
140
+ declare const SchemaFieldType = {
141
+ /**
142
+ * String type for text data
143
+ */
144
+ string: 'string' as const,
145
+
146
+ /**
147
+ * Number type for numeric data (integers and floats)
148
+ */
149
+ number: 'number' as const,
150
+
151
+ /**
152
+ * Boolean type for true/false values
153
+ */
154
+ boolean: 'boolean' as const,
155
+
156
+ /**
157
+ * Array type for ordered collections of items
158
+ */
159
+ array: 'array' as const,
160
+
161
+ /**
162
+ * Object type for nested document structures
163
+ */
164
+ object: 'object' as const,
165
+ };
166
+
167
+
168
+
169
+ /**
170
+ * Represents an IndexDB storage system extending the base storage functionality.
171
+ *
172
+ * @template T - The schema type.
173
+ */
174
+ declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
175
+ /**
176
+ * Frees the resources used by the in-memory storage.
177
+ */
178
+ free(): void;
179
+
180
+ static create<SchemasCreate extends SchemaTypeRecord>(
181
+ dbName: string,
182
+ schemas: SchemasCreate,
183
+ ): Promise<
184
+ IndexDB<
185
+ SchemasCreate
186
+ >
187
+ >;
188
+ }
189
+
190
+
75
191
 
76
192
  type InternalsRecord = {
77
193
  [name: string]: BaseStorage<SchemaTypeRecord>
@@ -192,62 +308,42 @@ declare class Collection<T extends SchemaType> {
192
308
 
193
309
 
194
310
 
195
- type BaseStorageOptions = {
196
- [name:string]:string | boolean | number
197
- }
198
-
199
- declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
200
- static create<SchemasCreate extends SchemaTypeRecord>(
201
- dbName: string,
202
- schemas: SchemasCreate,
203
- options?: BaseStorageOptions
204
- ): Promise<
205
- BaseStorage<
206
- SchemasCreate
207
- >
208
- >;
209
- constructor(
210
- dbName: string,
211
- schemas: Schemas,
212
- options?: BaseStorageOptions
213
- );
214
- readonly dbName: string;
215
- readonly schemas: Record<keyof Schemas, Schema<Schemas[keyof Schemas]>>;
216
- readonly options: BaseStorageOptions;
217
- readonly core: CoreStorage;
218
- start(): Promise<void>;
219
- close(): Promise<void>;
220
- count(colectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<number>;
221
- findDocumentById(collectionName: keyof Schemas, id: string): Promise<Doc<Schemas[keyof Schemas]> | null>;
222
- find(collectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<Doc<Schemas[keyof Schemas]>[]>;
223
- write(op: Operation<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>>;
224
- getOption(name: string): string | boolean | number | undefined;
225
- getSchema(name: string): Schema<any>;
226
- //Call addIndexSchemas if you need extra indexing schemas for your database
227
- addIndexSchemas(): null
311
+ declare class CoreStorage {
312
+ /**
313
+ * @param {any} document
314
+ * @param {Query} query
315
+ * @returns {boolean}
316
+ */
317
+ matchesQuery(document: any, query: Query<any>): boolean;
318
+ getPrimaryKeyTyped(value: any): string | number;
319
+ getIndexes(schema: Schema<any>, op: Operation): string[];
228
320
  }
229
321
 
230
322
 
231
323
 
232
324
  /**
233
- * Represents an IndexDB storage system extending the base storage functionality.
325
+ * Represents an operation to be performed on a collection.
234
326
  *
235
- * @template T - The schema type.
327
+ * @template T - The schema type of the collection.
236
328
  */
237
- declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
329
+ type Operation<T extends SchemaType = SchemaType> = {
238
330
  /**
239
- * Frees the resources used by the in-memory storage.
331
+ * The name of the collection on which the operation will be performed.
240
332
  */
241
- free(): void;
333
+ collection: string,
242
334
 
243
- static create<SchemasCreate extends SchemaTypeRecord>(
244
- dbName: string,
245
- schemas: SchemasCreate,
246
- ): Promise<
247
- IndexDB<
248
- SchemasCreate
249
- >
250
- >;
335
+ /**
336
+ * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
337
+ */
338
+ opType: OpType,
339
+
340
+ /**
341
+ * The data involved in the operation, conforming to the schema type.
342
+ */
343
+ data: Doc<T>,
344
+
345
+ primaryKeyField?: string,
346
+ primaryKey?: string
251
347
  }
252
348
 
253
349
 
@@ -288,200 +384,28 @@ declare class Query<T extends SchemaType> {
288
384
 
289
385
 
290
386
 
291
- /**
292
- * Represents a property within a schema, including various constraints and nested properties.
293
- */
294
- declare class Property {
295
- /**
296
- * The type of the property.
297
- */
298
- readonly type: SchemaFieldType;
299
-
300
- /**
301
- * The version of the property, if applicable.
302
- */
303
- readonly version?: number;
387
+ type EnumerateUpTo<
388
+ N extends number,
389
+ Acc extends number[] = []
390
+ > = Acc['length'] extends N ?
391
+ Acc[number]:
392
+ EnumerateUpTo<N, [...Acc, Acc['length']]> ;
304
393
 
305
- /**
306
- * The primary key of the property, if applicable.
307
- */
308
- readonly primaryKey?: string;
394
+ type EnumerateFrom1To<
395
+ N extends number
396
+ > = Exclude<EnumerateUpTo<N>,0> | (N extends 0 ? never : N);
309
397
 
310
- /**
311
- * An optional array of nested properties for array-type properties.
312
- */
313
- readonly items?: Property;
398
+ type IsVersionGreaterThan0<
399
+ V extends number
400
+ > = V extends 0 ? false : true;
314
401
 
315
- /**
316
- * The maximum number of items for array-type properties, if applicable.
317
- */
318
- readonly maxItems?: number;
402
+ type AnyVersionGreaterThan1<
403
+ T extends Record<string, SchemaType>
404
+ > = true extends {
405
+ [K in keyof T]: IsVersionGreaterThan0<T[K]['version']>;
406
+ } [keyof T] ? true : false;
319
407
 
320
- /**
321
- * The minimum number of items for array-type properties, if applicable.
322
- */
323
- readonly minItems?: number;
324
-
325
- /**
326
- * The maximum length for string-type properties, if applicable.
327
- */
328
- readonly maxLength?: number;
329
-
330
- /**
331
- * The minimum length for string-type properties, if applicable.
332
- */
333
- readonly minLength?: number;
334
-
335
- /**
336
- * An optional array of required fields for object-type properties.
337
- */
338
- readonly required?: boolean;
339
-
340
- /**
341
- * An optional default value for the property.
342
- */
343
- readonly default?: any;
344
-
345
- /**
346
- * An optional map of nested properties for object-type properties.
347
- */
348
- readonly properties?: {
349
- [name: string]: Property;
350
- };
351
- }
352
-
353
-
354
-
355
- /**
356
- * Represents the type definition for a schema.
357
- */
358
- type SchemaType = {
359
- /**
360
- * The version of the schema.
361
- */
362
- version: number;
363
-
364
- /**
365
- * The primary key of the schema.
366
- */
367
- primaryKey: string;
368
-
369
- /**
370
- * The type of the schema.
371
- */
372
- type: SchemaFieldType;
373
- indexes?: string[];
374
- encrypted?: string[];
375
- /**
376
- * The properties defined in the schema.
377
- */
378
- properties: {
379
- [name: string]: Property;
380
- };
381
- };
382
-
383
-
384
- /**
385
- * Represents a schema, including its definition and related methods.
386
- * You may be trying to build a storage, in any other can u won't need access tho this class.
387
- * Check this example
388
- *
389
- * ```typescript
390
- * class MyStorage extends <T extends SchemaTypeRecord> extends BaseStorage<T> {
391
- * example() {
392
- * const schema: Schema<any> = this.getSchema("mySchema")
393
- * }
394
- * }
395
- * ```
396
- * You alwayswill have access to getSchema through the Storage class.
397
- *
398
- * @template T - The schema type.
399
- */
400
- declare class Schema<T extends SchemaType> {
401
- /**
402
- * The schema definition.
403
- */
404
- schema: Schema<T>;
405
-
406
- /**
407
- * Creates a new `Schema` instance from the provided definition.
408
- *
409
- * @template TS - The schema type.
410
- * @param {TS} defi, Debugnition - The schema definition.
411
- * @returns {Schema<TS>} The created `Schema` instance.
412
- */
413
- static create<TS extends SchemaType>(definition: TS): Schema<TS>;
414
-
415
- /**
416
- * The version of the schema.
417
- */
418
- readonly version: number;
419
-
420
- /**
421
- * The primary key of the schema.
422
- */
423
- readonly primaryKey: string;
424
-
425
- /**
426
- * The type of the schema.
427
- */
428
- readonly type: SchemaFieldType;
429
-
430
- /**
431
- * An optional array of indexes.
432
- */
433
- /**
434
- * An optional array of indexes.
435
- */
436
- readonly indexes?: (Extract<keyof T, string>)[];
437
-
438
- /**
439
- * An optional array of encrypted fields.
440
- */
441
- readonly encrypted?: (Extract<keyof T, string>)[];
442
-
443
- /**
444
- * The properties defined in the schema.
445
- */
446
- readonly properties: {
447
- [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];
448
- } & {
449
- [K in keyof T['properties'] as T['properties'][K]['required'] extends false ? never : K]: T['properties'][K];
450
- };
451
- /**
452
- * Converts the schema to a JSON representation.
453
- *
454
- * @returns {SchemaType} The JSON representation of the schema.
455
- */
456
- toJSON(): SchemaType;
457
-
458
- validate(document: Doc<Schema<T>>): boolean;
459
- }
460
-
461
-
462
-
463
- type EnumerateUpTo<
464
- N extends number,
465
- Acc extends number[] = []
466
- > = Acc['length'] extends N ?
467
- Acc[number]:
468
- EnumerateUpTo<N, [...Acc, Acc['length']]> ;
469
-
470
- type EnumerateFrom1To<
471
- N extends number
472
- > = Exclude<EnumerateUpTo<N>,0> | (N extends 0 ? never : N);
473
-
474
- type IsVersionGreaterThan0<
475
- V extends number
476
- > = V extends 0 ? false : true;
477
-
478
- type AnyVersionGreaterThan1<
479
- T extends Record<string, SchemaType>
480
- > = true extends {
481
- [K in keyof T]: IsVersionGreaterThan0<T[K]['version']>;
482
- } [keyof T] ? true : false;
483
-
484
- type MigrationFunction<T extends SchemaType> = (doc: Doc <T> ) => Doc <T>
408
+ type MigrationFunction<T extends SchemaType> = (doc: Doc <T> ) => Doc <T>
485
409
 
486
410
  type MigrationPathsForSchema<
487
411
  T extends SchemaType
@@ -508,53 +432,6 @@ type MigrationsParameter<
508
432
 
509
433
 
510
434
 
511
- type Hook = (
512
- schema: Schema<SchemaType>,
513
- migration: MigrationPathsForSchema<SchemaType>,
514
- doc: Doc<SchemaType>
515
- ) => Doc<SchemaType>
516
-
517
- type BasePluginOptions = {
518
- docCreateHook?: Hook,
519
- docRecoverHook?: Hook
520
- }
521
-
522
- declare class BasePlugin implements BasePluginOptions {
523
- docCreateHook?:Hook;
524
- docRecoverHook?:Hook;
525
- }
526
-
527
-
528
-
529
- declare const SchemaFieldType = {
530
- /**
531
- * String type for text data
532
- */
533
- string: 'string' as const,
534
-
535
- /**
536
- * Number type for numeric data (integers and floats)
537
- */
538
- number: 'number' as const,
539
-
540
- /**
541
- * Boolean type for true/false values
542
- */
543
- boolean: 'boolean' as const,
544
-
545
- /**
546
- * Array type for ordered collections of items
547
- */
548
- array: 'array' as const,
549
-
550
- /**
551
- * Object type for nested document structures
552
- */
553
- object: 'object' as const,
554
- };
555
-
556
-
557
-
558
435
  /**
559
436
  * Represents an in-memory storage system extending the base storage functionality.
560
437
  *
@@ -613,15 +490,39 @@ declare abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
613
490
  }
614
491
 
615
492
 
616
- declare class CoreStorage {
617
- /**
618
- * @param {any} document
619
- * @param {Query} query
620
- * @returns {boolean}
621
- */
622
- matchesQuery(document: any, query: Query<any>): boolean;
623
- getPrimaryKeyTyped(value: any): string | number;
624
- getIndexes(schema: Schema<any>, op: Operation): string[];
493
+ type BaseStorageOptions = {
494
+ [name:string]:string | boolean | number
495
+ }
496
+
497
+ declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
498
+ static create<SchemasCreate extends SchemaTypeRecord>(
499
+ dbName: string,
500
+ schemas: SchemasCreate,
501
+ options?: BaseStorageOptions
502
+ ): Promise<
503
+ BaseStorage<
504
+ SchemasCreate
505
+ >
506
+ >;
507
+ constructor(
508
+ dbName: string,
509
+ schemas: Schemas,
510
+ options?: BaseStorageOptions
511
+ );
512
+ readonly dbName: string;
513
+ readonly schemas: Record<keyof Schemas, Schema<Schemas[keyof Schemas]>>;
514
+ readonly options: BaseStorageOptions;
515
+ readonly core: CoreStorage;
516
+ start(): Promise<void>;
517
+ close(): Promise<void>;
518
+ count(colectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<number>;
519
+ findDocumentById(collectionName: keyof Schemas, id: string): Promise<Doc<Schemas[keyof Schemas]> | null>;
520
+ find(collectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<Doc<Schemas[keyof Schemas]>[]>;
521
+ write(op: Operation<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>>;
522
+ getOption(name: string): string | boolean | number | undefined;
523
+ getSchema(name: string): Schema<any>;
524
+ //Call addIndexSchemas if you need extra indexing schemas for your database
525
+ addIndexSchemas(): null
625
526
  }
626
527
 
627
528
 
@@ -658,101 +559,200 @@ declare class CoreStorage {
658
559
  declare class Database<T extends SchemaTypeRecord> {
659
560
 
660
561
  /**
661
- * Creates a new `Database` instance with the provided schemas and storage module.
562
+ * Creates a new `Database` instance with the provided schemas and storage module.
563
+ *
564
+ * @template TS - A record of schema types.
565
+ * @param {TS} schemas - The schemas to use for the collections.
566
+ * @param migrations
567
+ * @param plugins
568
+ * @param options
569
+ * @param password
570
+ * @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
571
+ */
572
+ static create<TS extends SchemaTypeRecord>(
573
+ db_name: string,
574
+ schemas: TS,
575
+ migrations: MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>,
576
+ plugins:Array<typeof BasePlugin>,
577
+ options: RIDBModule,
578
+ password?:string,
579
+ storage?: BaseStorage<TS>
580
+ ): Promise<Database<TS>>;
581
+
582
+ authenticate(password: string): Promise<boolean>;
583
+
584
+ /**
585
+ * The collections in the database.
586
+ *
587
+ * This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
588
+ */
589
+ readonly collections: {
590
+ [name in keyof T]: Collection<Schema<T[name]>>
591
+ }
592
+
593
+ readonly started: boolean;
594
+
595
+ /**
596
+ * Starts the database.
597
+ *
598
+ * @returns {Promise<void>} A promise that resolves when the database is started.
599
+ */
600
+ start(): Promise<void>;
601
+
602
+ /**
603
+ * Closes the database.
604
+ *
605
+ * @returns {Promise<void>} A promise that resolves when the database is closed.
606
+ */
607
+ close(): Promise<void>;
608
+ }
609
+
610
+ /**
611
+ * Represents a function type for creating storage with the provided schema type records.
612
+ *
613
+ * @template T - The schema type record.
614
+ * @param {T} records - The schema type records.
615
+ * @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
616
+ */
617
+ type CreateStorage = <T extends SchemaTypeRecord>(
618
+ records: T
619
+ ) => Promise<BaseStorage<T>>;
620
+
621
+ /**
622
+ * Represents a storage module with a method for creating storage.
623
+ */
624
+ type RIDBModule = {
625
+
626
+ /**
627
+ * Plugin constructors array
628
+ */
629
+ apply: (plugins:Array<typeof BasePlugin>) => Array<BasePlugin>;
630
+ };
631
+
632
+
633
+
634
+ type Hook = (
635
+ schema: Schema<SchemaType>,
636
+ migration: MigrationPathsForSchema<SchemaType>,
637
+ doc: Doc<SchemaType>
638
+ ) => Doc<SchemaType>
639
+
640
+ type BasePluginOptions = {
641
+ docCreateHook?: Hook,
642
+ docRecoverHook?: Hook
643
+ }
644
+
645
+ declare class BasePlugin implements BasePluginOptions {
646
+ docCreateHook?:Hook;
647
+ docRecoverHook?:Hook;
648
+ }
649
+
650
+
651
+
652
+ /**
653
+ * Represents the type definition for a schema.
654
+ */
655
+ type SchemaType = {
656
+ /**
657
+ * The version of the schema.
658
+ */
659
+ version: number;
660
+
661
+ /**
662
+ * The primary key of the schema.
663
+ */
664
+ primaryKey: string;
665
+
666
+ /**
667
+ * The type of the schema.
668
+ */
669
+ type: SchemaFieldType;
670
+ indexes?: string[];
671
+ encrypted?: string[];
672
+ /**
673
+ * The properties defined in the schema.
674
+ */
675
+ properties: {
676
+ [name: string]: Property;
677
+ };
678
+ };
679
+
680
+
681
+ /**
682
+ * Represents a schema, including its definition and related methods.
683
+ * You may be trying to build a storage, in any other can u won't need access tho this class.
684
+ * Check this example
685
+ *
686
+ * ```typescript
687
+ * class MyStorage extends <T extends SchemaTypeRecord> extends BaseStorage<T> {
688
+ * example() {
689
+ * const schema: Schema<any> = this.getSchema("mySchema")
690
+ * }
691
+ * }
692
+ * ```
693
+ * You alwayswill have access to getSchema through the Storage class.
694
+ *
695
+ * @template T - The schema type.
696
+ */
697
+ declare class Schema<T extends SchemaType> {
698
+ /**
699
+ * The schema definition.
700
+ */
701
+ schema: Schema<T>;
702
+
703
+ /**
704
+ * Creates a new `Schema` instance from the provided definition.
662
705
  *
663
- * @template TS - A record of schema types.
664
- * @param {TS} schemas - The schemas to use for the collections.
665
- * @param migrations
666
- * @param plugins
667
- * @param options
668
- * @param password
669
- * @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
706
+ * @template TS - The schema type.
707
+ * @param {TS} defi, Debugnition - The schema definition.
708
+ * @returns {Schema<TS>} The created `Schema` instance.
670
709
  */
671
- static create<TS extends SchemaTypeRecord>(
672
- db_name: string,
673
- schemas: TS,
674
- migrations: MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>,
675
- plugins:Array<typeof BasePlugin>,
676
- options: RIDBModule,
677
- password?:string,
678
- storage?: BaseStorage<TS>
679
- ): Promise<Database<TS>>;
680
-
681
- authenticate(password: string): Promise<boolean>;
710
+ static create<TS extends SchemaType>(definition: TS): Schema<TS>;
682
711
 
683
712
  /**
684
- * The collections in the database.
685
- *
686
- * This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
713
+ * The version of the schema.
687
714
  */
688
- readonly collections: {
689
- [name in keyof T]: Collection<Schema<T[name]>>
690
- }
691
-
692
- readonly started: boolean;
715
+ readonly version: number;
693
716
 
694
717
  /**
695
- * Starts the database.
696
- *
697
- * @returns {Promise<void>} A promise that resolves when the database is started.
718
+ * The primary key of the schema.
698
719
  */
699
- start(): Promise<void>;
720
+ readonly primaryKey: string;
700
721
 
701
722
  /**
702
- * Closes the database.
703
- *
704
- * @returns {Promise<void>} A promise that resolves when the database is closed.
723
+ * The type of the schema.
705
724
  */
706
- close(): Promise<void>;
707
- }
708
-
709
- /**
710
- * Represents a function type for creating storage with the provided schema type records.
711
- *
712
- * @template T - The schema type record.
713
- * @param {T} records - The schema type records.
714
- * @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
715
- */
716
- type CreateStorage = <T extends SchemaTypeRecord>(
717
- records: T
718
- ) => Promise<BaseStorage<T>>;
719
-
720
- /**
721
- * Represents a storage module with a method for creating storage.
722
- */
723
- type RIDBModule = {
725
+ readonly type: SchemaFieldType;
724
726
 
725
727
  /**
726
- * Plugin constructors array
728
+ * An optional array of indexes.
727
729
  */
728
- apply: (plugins:Array<typeof BasePlugin>) => Array<BasePlugin>;
729
- };
730
-
731
-
732
-
733
- /**
734
- * Represents an operation to be performed on a collection.
735
- *
736
- * @template T - The schema type of the collection.
737
- */
738
- type Operation<T extends SchemaType = SchemaType> = {
739
730
  /**
740
- * The name of the collection on which the operation will be performed.
731
+ * An optional array of indexes.
741
732
  */
742
- collection: string,
733
+ readonly indexes?: (Extract<keyof T, string>)[];
743
734
 
744
735
  /**
745
- * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
736
+ * An optional array of encrypted fields.
746
737
  */
747
- opType: OpType,
738
+ readonly encrypted?: (Extract<keyof T, string>)[];
748
739
 
749
740
  /**
750
- * The data involved in the operation, conforming to the schema type.
741
+ * The properties defined in the schema.
751
742
  */
752
- data: Doc<T>,
743
+ readonly properties: {
744
+ [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];
745
+ } & {
746
+ [K in keyof T['properties'] as T['properties'][K]['required'] extends false ? never : K]: T['properties'][K];
747
+ };
748
+ /**
749
+ * Converts the schema to a JSON representation.
750
+ *
751
+ * @returns {SchemaType} The JSON representation of the schema.
752
+ */
753
+ toJSON(): SchemaType;
753
754
 
754
- primaryKeyField?: string,
755
- primaryKey?: string
755
+ validate(document: Doc<Schema<T>>): boolean;
756
756
  }
757
757
 
758
758
 
@@ -867,36 +867,18 @@ 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 __wbg_basestorage_free: (a: number) => void;
881
- readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
882
- readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
883
- readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
884
- readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
885
- readonly basestorage_core: (a: number, b: number) => void;
886
- readonly main_js: () => void;
887
- readonly is_debug_mode: () => number;
888
- readonly __wbg_ridberror_free: (a: number) => void;
889
- readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
890
- readonly ridberror_type: (a: number, b: number) => void;
891
- readonly ridberror_code: (a: number) => number;
892
- readonly ridberror_message: (a: number, b: number) => void;
893
- readonly ridberror_from: (a: number) => number;
894
- readonly ridberror_error: (a: number, b: number, c: number) => number;
895
- readonly ridberror_query: (a: number, b: number, c: number) => number;
896
- readonly ridberror_authentication: (a: number, b: number, c: number) => number;
897
- readonly ridberror_serialisation: (a: number, b: number, c: number) => number;
898
- readonly ridberror_validation: (a: number, b: number, c: number) => number;
899
- readonly ridberror_hook: (a: number, b: number, c: number) => number;
870
+ readonly __wbg_property_free: (a: number) => void;
871
+ readonly property_is_valid: (a: number, b: number) => void;
872
+ readonly property_type: (a: number) => number;
873
+ readonly property_items: (a: number, b: number) => void;
874
+ readonly property_maxItems: (a: number, b: number) => void;
875
+ readonly property_minItems: (a: number, b: number) => void;
876
+ readonly property_maxLength: (a: number, b: number) => void;
877
+ readonly property_minLength: (a: number, b: number) => void;
878
+ readonly property_properties: (a: number, b: number) => void;
879
+ readonly __wbgt_test_property_creation_0: (a: number) => void;
880
+ readonly __wbgt_test_property_validation_1: (a: number) => void;
881
+ readonly __wbgt_test_invalid_property_2: (a: number) => void;
900
882
  readonly __wbg_indexdb_free: (a: number) => void;
901
883
  readonly indexdb_get_stores: (a: number, b: number) => void;
902
884
  readonly indexdb_get_store: (a: number, b: number, c: number, d: number) => void;
@@ -907,9 +889,28 @@ interface InitOutput {
907
889
  readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
908
890
  readonly indexdb_close: (a: number) => number;
909
891
  readonly indexdb_start: (a: number) => number;
910
- readonly __wbg_queryoptions_free: (a: number) => void;
911
- readonly queryoptions_limit: (a: number, b: number) => void;
912
- readonly queryoptions_offset: (a: number, b: number) => void;
892
+ readonly __wbg_collection_free: (a: number) => void;
893
+ readonly collection_name: (a: number, b: number) => void;
894
+ readonly collection_schema: (a: number, b: number) => void;
895
+ readonly collection_find: (a: number, b: number, c: number) => number;
896
+ readonly collection_parse_query_options: (a: number, b: number, c: number) => void;
897
+ readonly collection_count: (a: number, b: number, c: number) => number;
898
+ readonly collection_findById: (a: number, b: number) => number;
899
+ readonly collection_update: (a: number, b: number) => number;
900
+ readonly collection_create: (a: number, b: number) => number;
901
+ readonly collection_delete: (a: number, b: number) => number;
902
+ readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
903
+ readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
904
+ readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
905
+ readonly __wbg_operation_free: (a: number) => void;
906
+ readonly operation_collection: (a: number, b: number) => void;
907
+ readonly operation_opType: (a: number) => number;
908
+ readonly operation_data: (a: number) => number;
909
+ readonly operation_primaryKeyField: (a: number) => number;
910
+ readonly operation_primaryKey: (a: number) => number;
911
+ readonly operation_primaryKeyIndex: (a: number, b: number) => void;
912
+ readonly corestorage_new: () => number;
913
+ readonly __wbg_corestorage_free: (a: number) => void;
913
914
  readonly __wbg_query_free: (a: number) => void;
914
915
  readonly query_new: (a: number, b: number, c: number) => void;
915
916
  readonly query_query: (a: number, b: number) => void;
@@ -947,38 +948,6 @@ interface InitOutput {
947
948
  readonly __wbgt_test_query_parse_eq_operator_wrong_type_32: (a: number) => void;
948
949
  readonly __wbgt_test_query_parse_ne_operator_33: (a: number) => void;
949
950
  readonly __wbgt_test_query_parse_ne_operator_wrong_type_34: (a: number) => void;
950
- readonly __wbg_property_free: (a: number) => void;
951
- readonly property_is_valid: (a: number, b: number) => void;
952
- readonly property_type: (a: number) => number;
953
- readonly property_items: (a: number, b: number) => void;
954
- readonly property_maxItems: (a: number, b: number) => void;
955
- readonly property_minItems: (a: number, b: number) => void;
956
- readonly property_maxLength: (a: number, b: number) => void;
957
- readonly property_minLength: (a: number, b: number) => void;
958
- readonly property_properties: (a: number, b: number) => void;
959
- readonly __wbgt_test_property_creation_0: (a: number) => void;
960
- readonly __wbgt_test_property_validation_1: (a: number) => void;
961
- readonly __wbgt_test_invalid_property_2: (a: number) => void;
962
- readonly __wbg_schema_free: (a: number) => void;
963
- readonly schema_validate: (a: number, b: number, c: number) => void;
964
- readonly schema_is_valid: (a: number, b: number) => void;
965
- readonly schema_create: (a: number, b: number) => void;
966
- readonly schema_version: (a: number) => number;
967
- readonly schema_primaryKey: (a: number, b: number) => void;
968
- readonly schema_type: (a: number, b: number) => void;
969
- readonly schema_indexes: (a: number, b: number) => void;
970
- readonly schema_encrypted: (a: number, b: number) => void;
971
- readonly schema_properties: (a: number, b: number) => void;
972
- readonly __wbgt_test_schema_creation_3: (a: number) => void;
973
- readonly __wbgt_test_schema_validation_4: (a: number) => void;
974
- readonly __wbgt_test_invalid_schema_5: (a: number) => void;
975
- readonly __wbg_baseplugin_free: (a: number) => void;
976
- readonly baseplugin_new: (a: number, b: number, c: number) => void;
977
- readonly baseplugin_name: (a: number) => number;
978
- readonly baseplugin_get_doc_create_hook: (a: number) => number;
979
- readonly baseplugin_get_doc_recover_hook: (a: number) => number;
980
- readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
981
- readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
982
951
  readonly __wbg_inmemory_free: (a: number) => void;
983
952
  readonly inmemory_create: (a: number, b: number, c: number) => number;
984
953
  readonly inmemory_write: (a: number, b: number) => number;
@@ -987,9 +956,14 @@ interface InitOutput {
987
956
  readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
988
957
  readonly inmemory_close: (a: number) => number;
989
958
  readonly inmemory_start: (a: number) => number;
990
- readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
991
- readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
992
- readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
959
+ readonly main_js: () => void;
960
+ readonly is_debug_mode: () => number;
961
+ readonly __wbg_basestorage_free: (a: number) => void;
962
+ readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
963
+ readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
964
+ readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
965
+ readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
966
+ readonly basestorage_core: (a: number, b: number) => void;
993
967
  readonly __wbg_database_free: (a: number) => void;
994
968
  readonly database_start: (a: number) => number;
995
969
  readonly database_close: (a: number) => number;
@@ -997,15 +971,41 @@ interface InitOutput {
997
971
  readonly database_authenticate: (a: number, b: number, c: number) => number;
998
972
  readonly database_collections: (a: number, b: number) => void;
999
973
  readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
1000
- readonly __wbg_operation_free: (a: number) => void;
1001
- readonly operation_collection: (a: number, b: number) => void;
1002
- readonly operation_opType: (a: number) => number;
1003
- readonly operation_data: (a: number) => number;
1004
- readonly operation_primaryKeyField: (a: number) => number;
1005
- readonly operation_primaryKey: (a: number) => number;
1006
- readonly operation_primaryKeyIndex: (a: number, b: number) => void;
1007
- readonly corestorage_new: () => number;
1008
- readonly __wbg_corestorage_free: (a: number) => void;
974
+ readonly __wbg_queryoptions_free: (a: number) => void;
975
+ readonly queryoptions_limit: (a: number, b: number) => void;
976
+ readonly queryoptions_offset: (a: number, b: number) => void;
977
+ readonly __wbg_baseplugin_free: (a: number) => void;
978
+ readonly baseplugin_new: (a: number, b: number, c: number) => void;
979
+ readonly baseplugin_name: (a: number) => number;
980
+ readonly baseplugin_get_doc_create_hook: (a: number) => number;
981
+ readonly baseplugin_get_doc_recover_hook: (a: number) => number;
982
+ readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
983
+ readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
984
+ readonly __wbg_ridberror_free: (a: number) => void;
985
+ readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
986
+ readonly ridberror_type: (a: number, b: number) => void;
987
+ readonly ridberror_code: (a: number) => number;
988
+ readonly ridberror_message: (a: number, b: number) => void;
989
+ readonly ridberror_from: (a: number) => number;
990
+ readonly ridberror_error: (a: number, b: number, c: number) => number;
991
+ readonly ridberror_query: (a: number, b: number, c: number) => number;
992
+ readonly ridberror_authentication: (a: number, b: number, c: number) => number;
993
+ readonly ridberror_serialisation: (a: number, b: number, c: number) => number;
994
+ readonly ridberror_validation: (a: number, b: number, c: number) => number;
995
+ readonly ridberror_hook: (a: number, b: number, c: number) => number;
996
+ readonly __wbg_schema_free: (a: number) => void;
997
+ readonly schema_validate: (a: number, b: number, c: number) => void;
998
+ readonly schema_is_valid: (a: number, b: number) => void;
999
+ readonly schema_create: (a: number, b: number) => void;
1000
+ readonly schema_version: (a: number) => number;
1001
+ readonly schema_primaryKey: (a: number, b: number) => void;
1002
+ readonly schema_type: (a: number, b: number) => void;
1003
+ readonly schema_indexes: (a: number, b: number) => void;
1004
+ readonly schema_encrypted: (a: number, b: number) => void;
1005
+ readonly schema_properties: (a: number, b: number) => void;
1006
+ readonly __wbgt_test_schema_creation_3: (a: number) => void;
1007
+ readonly __wbgt_test_schema_validation_4: (a: number) => void;
1008
+ readonly __wbgt_test_invalid_schema_5: (a: number) => void;
1009
1009
  readonly __wbg_wasmbindgentestcontext_free: (a: number) => void;
1010
1010
  readonly wasmbindgentestcontext_new: () => number;
1011
1011
  readonly wasmbindgentestcontext_args: (a: number, b: number, c: number) => void;