@trust0/ridb-core 1.5.6 → 1.6.0

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,42 +73,197 @@ export enum OpType {
73
73
  COUNT = 4,
74
74
  }
75
75
 
76
- export class CoreStorage {
76
+ /**
77
+ * Represents a property within a schema, including various constraints and nested properties.
78
+ */
79
+ export class Property {
77
80
  /**
78
- * @param {any} document
79
- * @param {Query} query
80
- * @returns {boolean}
81
- */
82
- matchesQuery(document: any, query: Query<any>): boolean;
83
- getPrimaryKeyTyped(value: any): string | number;
84
- getIndexes(schema: Schema<any>, op: Operation): string[];
81
+ * The type of the property.
82
+ */
83
+ readonly type: string;
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
+ };
85
136
  }
86
137
 
87
138
 
88
139
 
89
140
  /**
90
- * Represents an operation to be performed on a collection.
91
- *
92
- * @template T - The schema type of the collection.
141
+ * Represents the type definition for a schema.
93
142
  */
94
- export type Operation<T extends SchemaType = SchemaType> = {
143
+ export type SchemaType = {
95
144
  /**
96
- * The name of the collection on which the operation will be performed.
145
+ * The version of the schema.
97
146
  */
98
- collection: string,
147
+ version: number;
99
148
 
100
149
  /**
101
- * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
150
+ * The primary key of the schema.
102
151
  */
103
- opType: OpType,
152
+ primaryKey: string;
104
153
 
105
154
  /**
106
- * The data involved in the operation, conforming to the schema type.
155
+ * The type of the schema.
107
156
  */
108
- data: Doc<T>,
157
+ type: string;
158
+ indexes?: string[];
159
+ encrypted?: string[];
160
+ /**
161
+ * The properties defined in the schema.
162
+ */
163
+ properties: {
164
+ [name: string]: Property;
165
+ };
166
+ };
109
167
 
110
- primaryKeyField?: string,
111
- primaryKey?: string
168
+
169
+ /**
170
+ * Represents a schema, including its definition and related methods.
171
+ * You may be trying to build a storage, in any other can u won't need access tho this class.
172
+ * Check this example
173
+ *
174
+ * ```typescript
175
+ * class MyStorage extends <T extends SchemaTypeRecord> extends BaseStorage<T> {
176
+ * example() {
177
+ * const schema: Schema<any> = this.getSchema("mySchema")
178
+ * }
179
+ * }
180
+ * ```
181
+ * You alwayswill have access to getSchema through the Storage class.
182
+ *
183
+ * @template T - The schema type.
184
+ */
185
+ export class Schema<T extends SchemaType> {
186
+ /**
187
+ * The schema definition.
188
+ */
189
+ schema: Schema<T>;
190
+
191
+ /**
192
+ * Creates a new `Schema` instance from the provided definition.
193
+ *
194
+ * @template TS - The schema type.
195
+ * @param {TS} defi, Debugnition - The schema definition.
196
+ * @returns {Schema<TS>} The created `Schema` instance.
197
+ */
198
+ static create<TS extends SchemaType>(definition: TS): Schema<TS>;
199
+
200
+ /**
201
+ * The version of the schema.
202
+ */
203
+ readonly version: number;
204
+
205
+ /**
206
+ * The primary key of the schema.
207
+ */
208
+ readonly primaryKey: string;
209
+
210
+ /**
211
+ * The type of the schema.
212
+ */
213
+ readonly type: string;
214
+
215
+ /**
216
+ * An optional array of indexes.
217
+ */
218
+ /**
219
+ * An optional array of indexes.
220
+ */
221
+ readonly indexes?: (Extract<keyof T, string>)[];
222
+
223
+ /**
224
+ * An optional array of encrypted fields.
225
+ */
226
+ readonly encrypted?: (Extract<keyof T, string>)[];
227
+
228
+ /**
229
+ * The properties defined in the schema.
230
+ */
231
+ readonly properties: {
232
+ [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];
233
+ } & {
234
+ [K in keyof T['properties'] as T['properties'][K]['required'] extends false ? never : K]: T['properties'][K];
235
+ };
236
+ /**
237
+ * Converts the schema to a JSON representation.
238
+ *
239
+ * @returns {SchemaType} The JSON representation of the schema.
240
+ */
241
+ toJSON(): SchemaType;
242
+
243
+ validate(document: Doc<Schema<T>>): boolean;
244
+ }
245
+
246
+
247
+
248
+ /**
249
+ * Represents an IndexDB storage system extending the base storage functionality.
250
+ *
251
+ * @template T - The schema type.
252
+ */
253
+ export class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
254
+ /**
255
+ * Frees the resources used by the in-memory storage.
256
+ */
257
+ free(): void;
258
+
259
+ static create<SchemasCreate extends SchemaTypeRecord>(
260
+ dbName: string,
261
+ schemas: SchemasCreate,
262
+ ): Promise<
263
+ IndexDB<
264
+ SchemasCreate
265
+ >
266
+ >;
112
267
  }
113
268
 
114
269
 
@@ -149,43 +304,6 @@ export class Query<T extends SchemaType> {
149
304
 
150
305
 
151
306
 
152
- export type BaseStorageOptions = {
153
- [name:string]:string | boolean | number
154
- }
155
-
156
- export class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
157
- static create<SchemasCreate extends SchemaTypeRecord>(
158
- dbName: string,
159
- schemas: SchemasCreate,
160
- options?: BaseStorageOptions
161
- ): Promise<
162
- BaseStorage<
163
- SchemasCreate
164
- >
165
- >;
166
- constructor(
167
- dbName: string,
168
- schemas: Schemas,
169
- options?: BaseStorageOptions
170
- );
171
- readonly dbName: string;
172
- readonly schemas: Record<keyof Schemas, Schema<Schemas[keyof Schemas]>>;
173
- readonly options: BaseStorageOptions;
174
- readonly core: CoreStorage;
175
- start(): Promise<void>;
176
- close(): Promise<void>;
177
- count(colectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<number>;
178
- findDocumentById(collectionName: keyof Schemas, id: string): Promise<Doc<Schemas[keyof Schemas]> | null>;
179
- find(collectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<Doc<Schemas[keyof Schemas]>[]>;
180
- write(op: Operation<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>>;
181
- getOption(name: string): string | boolean | number | undefined;
182
- getSchema(name: string): Schema<any>;
183
- //Call addIndexSchemas if you need extra indexing schemas for your database
184
- addIndexSchemas(): null
185
- }
186
-
187
-
188
-
189
307
  /**
190
308
  * Represents a database containing collections of documents.
191
309
  * RIDB extends from this class and is used to expose collections.
@@ -290,57 +408,11 @@ export type RIDBModule = {
290
408
 
291
409
 
292
410
 
293
- /**
294
- * Represents an in-memory storage system extending the base storage functionality.
295
- *
296
- * @template T - The schema type.
297
- */
298
- export class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
299
- /**
300
- * Frees the resources used by the in-memory storage.
301
- */
302
- free(): void;
303
-
304
- static create<SchemasCreate extends SchemaTypeRecord>(
305
- dbName: string,
306
- schemas: SchemasCreate,
307
- ): Promise<
308
- InMemory<
309
- SchemasCreate
310
- >
311
- >;
312
- }
313
-
314
-
315
-
316
- /**
317
- * Represents an IndexDB storage system extending the base storage functionality.
318
- *
319
- * @template T - The schema type.
320
- */
321
- export class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
322
- /**
323
- * Frees the resources used by the in-memory storage.
324
- */
325
- free(): void;
326
-
327
- static create<SchemasCreate extends SchemaTypeRecord>(
328
- dbName: string,
329
- schemas: SchemasCreate,
330
- ): Promise<
331
- IndexDB<
332
- SchemasCreate
333
- >
334
- >;
335
- }
336
-
337
-
338
-
339
- type Hook = (
340
- schema: Schema<SchemaType>,
341
- migration: MigrationPathsForSchema<SchemaType>,
342
- doc: Doc<SchemaType>
343
- ) => Doc<SchemaType>
411
+ type Hook = (
412
+ schema: Schema<SchemaType>,
413
+ migration: MigrationPathsForSchema<SchemaType>,
414
+ doc: Doc<SchemaType>
415
+ ) => Doc<SchemaType>
344
416
 
345
417
  type BasePluginOptions = {
346
418
  docCreateHook?: Hook,
@@ -354,213 +426,46 @@ export class BasePlugin implements BasePluginOptions {
354
426
 
355
427
 
356
428
 
357
- /**
358
- * Represents the type definition for a schema.
359
- */
360
- export type SchemaType = {
361
- /**
362
- * The version of the schema.
363
- */
364
- version: number;
365
-
429
+ export class CoreStorage {
366
430
  /**
367
- * The primary key of the schema.
368
- */
369
- primaryKey: string;
431
+ * @param {any} document
432
+ * @param {Query} query
433
+ * @returns {boolean}
434
+ */
435
+ matchesQuery(document: any, query: Query<any>): boolean;
436
+ getPrimaryKeyTyped(value: any): string | number;
437
+ getIndexes(schema: Schema<any>, op: Operation): string[];
438
+ }
370
439
 
371
- /**
372
- * The type of the schema.
373
- */
374
- type: string;
375
- indexes?: string[];
376
- encrypted?: string[];
377
- /**
378
- * The properties defined in the schema.
379
- */
380
- properties: {
381
- [name: string]: Property;
382
- };
383
- };
384
440
 
385
441
 
386
442
  /**
387
- * Represents a schema, including its definition and related methods.
388
- * You may be trying to build a storage, in any other can u won't need access tho this class.
389
- * Check this example
390
- *
391
- * ```typescript
392
- * class MyStorage extends <T extends SchemaTypeRecord> extends BaseStorage<T> {
393
- * example() {
394
- * const schema: Schema<any> = this.getSchema("mySchema")
395
- * }
396
- * }
397
- * ```
398
- * You alwayswill have access to getSchema through the Storage class.
399
- *
400
- * @template T - The schema type.
443
+ * Represents an operation to be performed on a collection.
444
+ *
445
+ * @template T - The schema type of the collection.
401
446
  */
402
- export class Schema<T extends SchemaType> {
403
- /**
404
- * The schema definition.
405
- */
406
- schema: Schema<T>;
407
-
408
- /**
409
- * Creates a new `Schema` instance from the provided definition.
410
- *
411
- * @template TS - The schema type.
412
- * @param {TS} defi, Debugnition - The schema definition.
413
- * @returns {Schema<TS>} The created `Schema` instance.
414
- */
415
- static create<TS extends SchemaType>(definition: TS): Schema<TS>;
416
-
417
- /**
418
- * The version of the schema.
419
- */
420
- readonly version: number;
421
-
422
- /**
423
- * The primary key of the schema.
424
- */
425
- readonly primaryKey: string;
426
-
427
- /**
428
- * The type of the schema.
429
- */
430
- readonly type: string;
431
-
432
- /**
433
- * An optional array of indexes.
434
- */
447
+ export type Operation<T extends SchemaType = SchemaType> = {
435
448
  /**
436
- * An optional array of indexes.
449
+ * The name of the collection on which the operation will be performed.
437
450
  */
438
- readonly indexes?: (Extract<keyof T, string>)[];
451
+ collection: string,
439
452
 
440
453
  /**
441
- * An optional array of encrypted fields.
454
+ * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
442
455
  */
443
- readonly encrypted?: (Extract<keyof T, string>)[];
456
+ opType: OpType,
444
457
 
445
458
  /**
446
- * The properties defined in the schema.
447
- */
448
- readonly properties: {
449
- [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];
450
- } & {
451
- [K in keyof T['properties'] as T['properties'][K]['required'] extends false ? never : K]: T['properties'][K];
452
- };
453
- /**
454
- * Converts the schema to a JSON representation.
455
- *
456
- * @returns {SchemaType} The JSON representation of the schema.
459
+ * The data involved in the operation, conforming to the schema type.
457
460
  */
458
- toJSON(): SchemaType;
459
-
460
- validate(document: Doc<Schema<T>>): boolean;
461
- }
462
-
463
-
464
-
465
- export type InternalsRecord = {
466
- [name: string]: BaseStorage<SchemaTypeRecord>
467
- };
468
- /**
469
- * ExtractType is a utility type that maps a string representing a basic data type to the actual TypeScript type.
470
- *
471
- * @template T - A string literal type representing the basic data type ('string', 'number', 'boolean', 'object', 'array').
472
- *
473
- * @example
474
- * type StringType = ExtractType<'string'>; // StringType is string
475
- * type NumberType = ExtractType<'number'>; // NumberType is number
476
- * type BooleanType = ExtractType<'boolean'>; // BooleanType is boolean
477
- * type ObjectType = ExtractType<'object'>; // ObjectType is object
478
- * type ArrayType = ExtractType<'array'>; // ArrayType is Array<any>
479
- */
480
- export type ExtractType<T extends string> =
481
- T extends "string" ? string :
482
- T extends "number" ? number :
483
- T extends "boolean" ? boolean :
484
- T extends "object" ? object :
485
- T extends "array" ? any[] :
486
- never;
487
-
488
- export type IsOptional<T> = T extends { required: false } ? true :
489
- T extends { default: any } ? true : false;
490
-
491
- /**
492
- * Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
493
- *
494
- * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
495
- *
496
- * type Document = Doc<Schema>; // Document is { name: string; age: number; }
497
- */
498
- export type Doc<T extends SchemaType> = {
499
- [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
500
- ExtractType<T["properties"][K]["type"]>
501
- } & {
502
- [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends false ? K : never]:
503
- ExtractType<T["properties"][K]["type"]>
504
- } & {
505
- __version?: number;
506
- };
507
-
508
- export type QueryOptions = {
509
- limit?: number;
510
- offset?: number;
511
- }
461
+ data: Doc<T>,
512
462
 
513
- /**
514
- * Collection is a class that represents a collection of documents in a database.
515
- * @template T - A schema type defining the structure of the documents in the collection.
516
- */
517
- export class Collection<T extends SchemaType> {
518
- /**
519
- * Finds all documents in the collection.
520
- *
521
- * @returns A promise that resolves to an array of documents.
522
- */
523
- find(query: QueryType<T>, options?: QueryOptions): Promise<Doc<T>[]>;
524
- /**
525
- * count all documents in the collection.
526
- *
527
- * @returns A promise that resolves to an array of documents.
528
- */
529
- count(query: QueryType<T>, options?: QueryOptions): Promise<number>;
530
- /**
531
- * Finds a single document in the collection by its ID.
532
- *
533
- * @param id - The ID of the document to find.
534
- * @returns A promise that resolves to the found document.
535
- */
536
- findById(id: string): Promise<Doc<T>>;
537
- /**
538
- * Updates a document in the collection by its ID.
539
- *
540
- * @param id - The ID of the document to update.
541
- * @param document - A partial document containing the fields to update.
542
- * @returns A promise that resolves when the update is complete.
543
- */
544
- update(document: Partial<Doc<T>>): Promise<void>;
545
- /**
546
- * Creates a new document in the collection.
547
- *
548
- * @param document - The document to create.
549
- * @returns A promise that resolves to the created document.
550
- */
551
- create(document: Doc<T>): Promise<Doc<T>>;
552
- /**
553
- * Deletes a document in the collection by its ID.
554
- *
555
- * @param id - The ID of the document to delete.
556
- * @returns A promise that resolves when the deletion is complete.
557
- */
558
- delete(id: string): Promise<void>;
463
+ primaryKeyField?: string,
464
+ primaryKey?: string
559
465
  }
560
466
 
561
467
 
562
468
 
563
-
564
469
  export type EnumerateUpTo<
565
470
  N extends number,
566
471
  Acc extends number[] = []
@@ -609,70 +514,105 @@ export type MigrationsParameter<
609
514
 
610
515
 
611
516
 
517
+ export type InternalsRecord = {
518
+ [name: string]: BaseStorage<SchemaTypeRecord>
519
+ };
612
520
  /**
613
- * Represents a property within a schema, including various constraints and nested properties.
521
+ * ExtractType is a utility type that maps a string representing a basic data type to the actual TypeScript type.
522
+ *
523
+ * @template T - A string literal type representing the basic data type ('string', 'number', 'boolean', 'object', 'array').
524
+ *
525
+ * @example
526
+ * type StringType = ExtractType<'string'>; // StringType is string
527
+ * type NumberType = ExtractType<'number'>; // NumberType is number
528
+ * type BooleanType = ExtractType<'boolean'>; // BooleanType is boolean
529
+ * type ObjectType = ExtractType<'object'>; // ObjectType is object
530
+ * type ArrayType = ExtractType<'array'>; // ArrayType is Array<any>
614
531
  */
615
- export class Property {
616
- /**
617
- * The type of the property.
618
- */
619
- readonly type: string;
620
-
621
- /**
622
- * The version of the property, if applicable.
623
- */
624
- readonly version?: number;
625
-
626
- /**
627
- * The primary key of the property, if applicable.
628
- */
629
- readonly primaryKey?: string;
630
-
631
- /**
632
- * An optional array of nested properties for array-type properties.
633
- */
634
- readonly items?: Property;
635
-
636
- /**
637
- * The maximum number of items for array-type properties, if applicable.
638
- */
639
- readonly maxItems?: number;
640
-
641
- /**
642
- * The minimum number of items for array-type properties, if applicable.
643
- */
644
- readonly minItems?: number;
645
-
646
- /**
647
- * The maximum length for string-type properties, if applicable.
648
- */
649
- readonly maxLength?: number;
532
+ export type ExtractType<T extends string> =
533
+ T extends "string" ? string :
534
+ T extends "number" ? number :
535
+ T extends "boolean" ? boolean :
536
+ T extends "object" ? object :
537
+ T extends "array" ? any[] :
538
+ never;
650
539
 
651
- /**
652
- * The minimum length for string-type properties, if applicable.
653
- */
654
- readonly minLength?: number;
540
+ export type IsOptional<T> = T extends { required: false } ? true :
541
+ T extends { default: any } ? true : false;
655
542
 
656
- /**
657
- * An optional array of required fields for object-type properties.
658
- */
659
- readonly required?: boolean;
543
+ /**
544
+ * Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
545
+ *
546
+ * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
547
+ *
548
+ * type Document = Doc<Schema>; // Document is { name: string; age: number; }
549
+ */
550
+ export type Doc<T extends SchemaType> = {
551
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
552
+ ExtractType<T["properties"][K]["type"]>
553
+ } & {
554
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends false ? K : never]:
555
+ ExtractType<T["properties"][K]["type"]>
556
+ } & {
557
+ __version?: number;
558
+ };
660
559
 
661
- /**
662
- * An optional default value for the property.
663
- */
664
- readonly default?: any;
560
+ export type QueryOptions = {
561
+ limit?: number;
562
+ offset?: number;
563
+ }
665
564
 
666
- /**
667
- * An optional map of nested properties for object-type properties.
668
- */
669
- readonly properties?: {
670
- [name: string]: Property;
671
- };
565
+ /**
566
+ * Collection is a class that represents a collection of documents in a database.
567
+ * @template T - A schema type defining the structure of the documents in the collection.
568
+ */
569
+ export class Collection<T extends SchemaType> {
570
+ /**
571
+ * Finds all documents in the collection.
572
+ *
573
+ * @returns A promise that resolves to an array of documents.
574
+ */
575
+ find(query: QueryType<T>, options?: QueryOptions): Promise<Doc<T>[]>;
576
+ /**
577
+ * count all documents in the collection.
578
+ *
579
+ * @returns A promise that resolves to an array of documents.
580
+ */
581
+ count(query: QueryType<T>, options?: QueryOptions): Promise<number>;
582
+ /**
583
+ * Finds a single document in the collection by its ID.
584
+ *
585
+ * @param id - The ID of the document to find.
586
+ * @returns A promise that resolves to the found document.
587
+ */
588
+ findById(id: string): Promise<Doc<T>>;
589
+ /**
590
+ * Updates a document in the collection by its ID.
591
+ *
592
+ * @param id - The ID of the document to update.
593
+ * @param document - A partial document containing the fields to update.
594
+ * @returns A promise that resolves when the update is complete.
595
+ */
596
+ update(document: Partial<Doc<T>>): Promise<void>;
597
+ /**
598
+ * Creates a new document in the collection.
599
+ *
600
+ * @param document - The document to create.
601
+ * @returns A promise that resolves to the created document.
602
+ */
603
+ create(document: Doc<T>): Promise<Doc<T>>;
604
+ /**
605
+ * Deletes a document in the collection by its ID.
606
+ *
607
+ * @param id - The ID of the document to delete.
608
+ * @returns A promise that resolves when the deletion is complete.
609
+ */
610
+ delete(id: string): Promise<void>;
672
611
  }
673
612
 
674
613
 
675
614
 
615
+
676
616
  /**
677
617
  * Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
678
618
  */
@@ -706,6 +646,66 @@ export abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
706
646
  ): Promise<Doc<Schemas[keyof Schemas]>>;
707
647
  }
708
648
 
649
+
650
+ /**
651
+ * Represents an in-memory storage system extending the base storage functionality.
652
+ *
653
+ * @template T - The schema type.
654
+ */
655
+ export class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
656
+ /**
657
+ * Frees the resources used by the in-memory storage.
658
+ */
659
+ free(): void;
660
+
661
+ static create<SchemasCreate extends SchemaTypeRecord>(
662
+ dbName: string,
663
+ schemas: SchemasCreate,
664
+ ): Promise<
665
+ InMemory<
666
+ SchemasCreate
667
+ >
668
+ >;
669
+ }
670
+
671
+
672
+
673
+ export type BaseStorageOptions = {
674
+ [name:string]:string | boolean | number
675
+ }
676
+
677
+ export class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
678
+ static create<SchemasCreate extends SchemaTypeRecord>(
679
+ dbName: string,
680
+ schemas: SchemasCreate,
681
+ options?: BaseStorageOptions
682
+ ): Promise<
683
+ BaseStorage<
684
+ SchemasCreate
685
+ >
686
+ >;
687
+ constructor(
688
+ dbName: string,
689
+ schemas: Schemas,
690
+ options?: BaseStorageOptions
691
+ );
692
+ readonly dbName: string;
693
+ readonly schemas: Record<keyof Schemas, Schema<Schemas[keyof Schemas]>>;
694
+ readonly options: BaseStorageOptions;
695
+ readonly core: CoreStorage;
696
+ start(): Promise<void>;
697
+ close(): Promise<void>;
698
+ count(colectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<number>;
699
+ findDocumentById(collectionName: keyof Schemas, id: string): Promise<Doc<Schemas[keyof Schemas]> | null>;
700
+ find(collectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<Doc<Schemas[keyof Schemas]>[]>;
701
+ write(op: Operation<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>>;
702
+ getOption(name: string): string | boolean | number | undefined;
703
+ getSchema(name: string): Schema<any>;
704
+ //Call addIndexSchemas if you need extra indexing schemas for your database
705
+ addIndexSchemas(): null
706
+ }
707
+
708
+
709
709
  /**
710
710
  */
711
711
  export class RIDBError {
@@ -817,20 +817,41 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
817
817
 
818
818
  export interface InitOutput {
819
819
  readonly memory: WebAssembly.Memory;
820
- readonly corestorage_new: () => number;
821
- readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
822
- readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
823
- readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
824
- readonly __wbg_operation_free: (a: number) => void;
825
- readonly operation_collection: (a: number, b: number) => void;
826
- readonly operation_opType: (a: number) => number;
827
- readonly operation_data: (a: number) => number;
828
- readonly operation_primaryKeyField: (a: number) => number;
829
- readonly operation_primaryKey: (a: number) => number;
830
- readonly operation_primaryKeyIndex: (a: number, b: number) => void;
831
- readonly main_js: () => void;
832
- readonly is_debug_mode: () => number;
833
- readonly __wbg_corestorage_free: (a: number) => void;
820
+ readonly __wbg_property_free: (a: number) => void;
821
+ readonly property_is_valid: (a: number, b: number) => void;
822
+ readonly property_type: (a: number) => number;
823
+ readonly property_items: (a: number, b: number) => void;
824
+ readonly property_maxItems: (a: number, b: number) => void;
825
+ readonly property_minItems: (a: number, b: number) => void;
826
+ readonly property_maxLength: (a: number, b: number) => void;
827
+ readonly property_minLength: (a: number, b: number) => void;
828
+ readonly property_properties: (a: number, b: number) => void;
829
+ readonly __wbgt_test_property_creation_0: (a: number) => void;
830
+ readonly __wbgt_test_property_validation_1: (a: number) => void;
831
+ readonly __wbgt_test_invalid_property_2: (a: number) => void;
832
+ readonly __wbg_schema_free: (a: number) => void;
833
+ readonly schema_validate: (a: number, b: number, c: number) => void;
834
+ readonly schema_is_valid: (a: number, b: number) => void;
835
+ readonly schema_create: (a: number, b: number) => void;
836
+ readonly schema_version: (a: number) => number;
837
+ readonly schema_primaryKey: (a: number, b: number) => void;
838
+ readonly schema_type: (a: number, b: number) => void;
839
+ readonly schema_indexes: (a: number, b: number) => void;
840
+ readonly schema_encrypted: (a: number, b: number) => void;
841
+ readonly schema_properties: (a: number, b: number) => void;
842
+ readonly __wbgt_test_schema_creation_3: (a: number) => void;
843
+ readonly __wbgt_test_schema_validation_4: (a: number) => void;
844
+ readonly __wbgt_test_invalid_schema_5: (a: number) => void;
845
+ readonly __wbg_indexdb_free: (a: number) => void;
846
+ readonly indexdb_get_stores: (a: number, b: number) => void;
847
+ readonly indexdb_get_store: (a: number, b: number, c: number, d: number) => void;
848
+ readonly indexdb_create: (a: number, b: number, c: number) => number;
849
+ readonly indexdb_write: (a: number, b: number) => number;
850
+ readonly indexdb_find: (a: number, b: number, c: number, d: number, e: number) => number;
851
+ readonly indexdb_findDocumentById: (a: number, b: number, c: number, d: number) => number;
852
+ readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
853
+ readonly indexdb_close: (a: number) => number;
854
+ readonly indexdb_start: (a: number) => number;
834
855
  readonly __wbg_query_free: (a: number) => void;
835
856
  readonly query_new: (a: number, b: number, c: number) => void;
836
857
  readonly query_query: (a: number, b: number) => void;
@@ -867,12 +888,6 @@ export interface InitOutput {
867
888
  readonly __wbgt_test_query_parse_eq_operator_wrong_type_32: (a: number) => void;
868
889
  readonly __wbgt_test_query_parse_ne_operator_33: (a: number) => void;
869
890
  readonly __wbgt_test_query_parse_ne_operator_wrong_type_34: (a: number) => void;
870
- readonly __wbg_basestorage_free: (a: number) => void;
871
- readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
872
- readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
873
- readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
874
- readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
875
- readonly basestorage_core: (a: number, b: number) => void;
876
891
  readonly __wbg_ridberror_free: (a: number) => void;
877
892
  readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
878
893
  readonly ridberror_type: (a: number, b: number) => void;
@@ -892,27 +907,6 @@ export interface InitOutput {
892
907
  readonly database_authenticate: (a: number, b: number, c: number) => number;
893
908
  readonly database_collections: (a: number, b: number) => void;
894
909
  readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
895
- readonly __wbg_queryoptions_free: (a: number) => void;
896
- readonly queryoptions_limit: (a: number, b: number) => void;
897
- readonly queryoptions_offset: (a: number, b: number) => void;
898
- readonly __wbg_inmemory_free: (a: number) => void;
899
- readonly inmemory_create: (a: number, b: number, c: number) => number;
900
- readonly inmemory_write: (a: number, b: number) => number;
901
- readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
902
- readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
903
- readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
904
- readonly inmemory_close: (a: number) => number;
905
- readonly inmemory_start: (a: number) => number;
906
- readonly __wbg_indexdb_free: (a: number) => void;
907
- readonly indexdb_get_stores: (a: number, b: number) => void;
908
- readonly indexdb_get_store: (a: number, b: number, c: number, d: number) => void;
909
- readonly indexdb_create: (a: number, b: number, c: number) => number;
910
- readonly indexdb_write: (a: number, b: number) => number;
911
- readonly indexdb_find: (a: number, b: number, c: number, d: number, e: number) => number;
912
- readonly indexdb_findDocumentById: (a: number, b: number, c: number, d: number) => number;
913
- readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
914
- readonly indexdb_close: (a: number) => number;
915
- readonly indexdb_start: (a: number) => number;
916
910
  readonly __wbg_baseplugin_free: (a: number) => void;
917
911
  readonly baseplugin_new: (a: number, b: number, c: number) => void;
918
912
  readonly baseplugin_name: (a: number) => number;
@@ -920,19 +914,23 @@ export interface InitOutput {
920
914
  readonly baseplugin_get_doc_recover_hook: (a: number) => number;
921
915
  readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
922
916
  readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
923
- readonly __wbg_schema_free: (a: number) => void;
924
- readonly schema_validate: (a: number, b: number, c: number) => void;
925
- readonly schema_is_valid: (a: number, b: number) => void;
926
- readonly schema_create: (a: number, b: number) => void;
927
- readonly schema_version: (a: number) => number;
928
- readonly schema_primaryKey: (a: number, b: number) => void;
929
- readonly schema_type: (a: number, b: number) => void;
930
- readonly schema_indexes: (a: number, b: number) => void;
931
- readonly schema_encrypted: (a: number, b: number) => void;
932
- readonly schema_properties: (a: number, b: number) => void;
933
- readonly __wbgt_test_schema_creation_3: (a: number) => void;
934
- readonly __wbgt_test_schema_validation_4: (a: number) => void;
935
- readonly __wbgt_test_invalid_schema_5: (a: number) => void;
917
+ readonly corestorage_new: () => number;
918
+ readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
919
+ readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
920
+ readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
921
+ readonly __wbg_queryoptions_free: (a: number) => void;
922
+ readonly queryoptions_limit: (a: number, b: number) => void;
923
+ readonly queryoptions_offset: (a: number, b: number) => void;
924
+ readonly __wbg_operation_free: (a: number) => void;
925
+ readonly operation_collection: (a: number, b: number) => void;
926
+ readonly operation_opType: (a: number) => number;
927
+ readonly operation_data: (a: number) => number;
928
+ readonly operation_primaryKeyField: (a: number) => number;
929
+ readonly operation_primaryKey: (a: number) => number;
930
+ readonly operation_primaryKeyIndex: (a: number, b: number) => void;
931
+ readonly main_js: () => void;
932
+ readonly is_debug_mode: () => number;
933
+ readonly __wbg_corestorage_free: (a: number) => void;
936
934
  readonly __wbg_collection_free: (a: number) => void;
937
935
  readonly collection_name: (a: number, b: number) => void;
938
936
  readonly collection_schema: (a: number, b: number) => void;
@@ -943,18 +941,20 @@ export interface InitOutput {
943
941
  readonly collection_update: (a: number, b: number) => number;
944
942
  readonly collection_create: (a: number, b: number) => number;
945
943
  readonly collection_delete: (a: number, b: number) => number;
946
- readonly __wbg_property_free: (a: number) => void;
947
- readonly property_is_valid: (a: number, b: number) => void;
948
- readonly property_type: (a: number) => number;
949
- readonly property_items: (a: number, b: number) => void;
950
- readonly property_maxItems: (a: number, b: number) => void;
951
- readonly property_minItems: (a: number, b: number) => void;
952
- readonly property_maxLength: (a: number, b: number) => void;
953
- readonly property_minLength: (a: number, b: number) => void;
954
- readonly property_properties: (a: number, b: number) => void;
955
- readonly __wbgt_test_property_creation_0: (a: number) => void;
956
- readonly __wbgt_test_property_validation_1: (a: number) => void;
957
- readonly __wbgt_test_invalid_property_2: (a: number) => void;
944
+ readonly __wbg_inmemory_free: (a: number) => void;
945
+ readonly inmemory_create: (a: number, b: number, c: number) => number;
946
+ readonly inmemory_write: (a: number, b: number) => number;
947
+ readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
948
+ readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
949
+ readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
950
+ readonly inmemory_close: (a: number) => number;
951
+ readonly inmemory_start: (a: number) => number;
952
+ readonly __wbg_basestorage_free: (a: number) => void;
953
+ readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
954
+ readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
955
+ readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
956
+ readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
957
+ readonly basestorage_core: (a: number, b: number) => void;
958
958
  readonly __wbg_wasmbindgentestcontext_free: (a: number) => void;
959
959
  readonly wasmbindgentestcontext_new: () => number;
960
960
  readonly wasmbindgentestcontext_args: (a: number, b: number, c: number) => void;
@@ -967,16 +967,16 @@ export interface InitOutput {
967
967
  readonly __wbindgen_malloc: (a: number, b: number) => number;
968
968
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
969
969
  readonly __wbindgen_export_2: WebAssembly.Table;
970
- readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h231d9c59fed64ed4: (a: number, b: number, c: number) => void;
970
+ readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h7b5749f7e109cebe: (a: number, b: number, c: number) => number;
971
+ readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7f5c1429da4fe71: (a: number, b: number, c: number) => void;
971
972
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
972
- readonly _dyn_core__ops__function__Fn__A_B_C___Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h33ba438d7169a89a: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
973
- readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h8d2923cd4e648893: (a: number, b: number, c: number) => number;
974
- readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf066437ba5ed1b74: (a: number, b: number, c: number) => void;
973
+ readonly _dyn_core__ops__function__Fn__A_B_C___Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h86ed325a024a630d: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
974
+ readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h002fe7d5dfec328e: (a: number, b: number, c: number) => void;
975
975
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
976
976
  readonly __wbindgen_exn_store: (a: number) => void;
977
- readonly wasm_bindgen__convert__closures__invoke0_mut__hf4bced6426ca6f31: (a: number, b: number) => void;
978
- readonly wasm_bindgen__convert__closures__invoke3_mut__h425269a7185d1f5b: (a: number, b: number, c: number, d: number, e: number) => void;
979
- readonly wasm_bindgen__convert__closures__invoke2_mut__h1b9fff078715ef14: (a: number, b: number, c: number, d: number) => void;
977
+ readonly wasm_bindgen__convert__closures__invoke0_mut__h66fab07c914fb475: (a: number, b: number) => void;
978
+ readonly wasm_bindgen__convert__closures__invoke3_mut__h4628b33c4840333b: (a: number, b: number, c: number, d: number, e: number) => void;
979
+ readonly wasm_bindgen__convert__closures__invoke2_mut__h52532ff5a9b6e10e: (a: number, b: number, c: number, d: number) => void;
980
980
  readonly __wbindgen_start: () => void;
981
981
  }
982
982