@trust0/ridb-core 1.7.31 → 1.7.33

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,35 +73,168 @@ declare enum OpType {
73
73
  COUNT = 4,
74
74
  }
75
75
 
76
+ type InternalsRecord = {
77
+ [name: string]: BaseStorage<SchemaTypeRecord>
78
+ };
76
79
  /**
77
- * Represents an IndexDB storage system extending the base storage functionality.
80
+ * ExtractType is a utility type that maps a string representing a basic data type to the actual TypeScript type.
78
81
  *
79
- * @template T - The schema type.
82
+ * @template T - A string literal type representing the basic data type ('string', 'number', 'boolean', 'object', 'array').
83
+ *
84
+ * @example
85
+ * type StringType = ExtractType<'string'>; // StringType is string
86
+ * type NumberType = ExtractType<'number'>; // NumberType is number
87
+ * type BooleanType = ExtractType<'boolean'>; // BooleanType is boolean
88
+ * type ObjectType = ExtractType<'object'>; // ObjectType is object
89
+ * type ArrayType = ExtractType<'array'>; // ArrayType is Array<any>
80
90
  */
81
- declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
82
- /**
83
- * Frees the resources used by the in-memory storage.
84
- */
85
- free(): void;
91
+ type ExtractType<T extends string> =
92
+ T extends "string" ? string :
93
+ T extends "number" ? number :
94
+ T extends "boolean" ? boolean :
95
+ T extends "object" ? object :
96
+ T extends "array" ? any[] :
97
+ undefined;
98
+
99
+ type IsOptional<T> =
100
+ T extends { required: true }
101
+ ? T extends { default: never }
102
+ ? false
103
+ : true
104
+ : true;
105
+
106
+ /**
107
+ * Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
108
+ *
109
+ * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
110
+ *
111
+ * type Document = Doc<Schema>; // Document is { name: string; age: number; }
112
+ */
113
+ type Doc<T extends SchemaType> = {
114
+ [K in keyof T["properties"]]:
115
+ ExtractType<T['properties'][K]['type']>
116
+ } & {
117
+ __version?: number;
118
+ createdAt?: number;
119
+ updatedAt?: number;
120
+ };
121
+
122
+ /**
123
+ * CreateDoc is a utility type for document creation that properly handles required vs optional fields
124
+ * during the creation process. Fields with default values or required: false become optional.
125
+ *
126
+ * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
127
+ */
128
+ type CreateDoc<T extends SchemaType> = {
129
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
130
+ ExtractType<T['properties'][K]['type']>
131
+ } & {
132
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
133
+ ExtractType<T['properties'][K]['type']>
134
+ } & {
135
+ __version?: number;
136
+ createdAt?: number;
137
+ updatedAt?: number;
138
+ };
139
+
140
+ type QueryOptions = {
141
+ limit?: number;
142
+ offset?: number;
143
+ }
144
+
145
+ /**
146
+ * Collection is a class that represents a collection of documents in a database.
147
+ * @template T - A schema type defining the structure of the documents in the collection.
148
+ */
149
+ declare class Collection<T extends SchemaType> {
150
+ /**
151
+ * Finds all documents in the collection.
152
+ *
153
+ * @returns A promise that resolves to an array of documents.
154
+ */
155
+ find(query: QueryType<T>, options?: QueryOptions): Promise<Doc<T>[]>;
156
+ /**
157
+ * count all documents in the collection.
158
+ *
159
+ * @returns A promise that resolves to an array of documents.
160
+ */
161
+ count(query: QueryType<T>, options?: QueryOptions): Promise<number>;
162
+ /**
163
+ * Finds a single document in the collection by its ID.
164
+ *
165
+ * @param id - The ID of the document to find.
166
+ * @returns A promise that resolves to the found document.
167
+ */
168
+ findById(id: string): Promise<Doc<T>>;
169
+ /**
170
+ * Updates a document in the collection by its ID.
171
+ *
172
+ * @param document - A partial document containing the fields to update.
173
+ * @returns A promise that resolves when the update is complete.
174
+ */
175
+ update(document: Partial<Doc<T>>): Promise<void>;
176
+ /**
177
+ * Creates a new document in the collection.
178
+ *
179
+ * @param document - The document to create.
180
+ * @returns A promise that resolves to the created document.
181
+ */
182
+ create(document: CreateDoc<T>): Promise<Doc<T>>;
183
+ /**
184
+ * Deletes a document in the collection by its ID.
185
+ *
186
+ * @param id - The ID of the document to delete.
187
+ * @returns A promise that resolves when the deletion is complete.
188
+ */
189
+ delete(id: string): Promise<void>;
190
+ }
191
+
86
192
 
193
+
194
+
195
+ type BaseStorageOptions = {
196
+ [name:string]:string | boolean | number
197
+ }
198
+
199
+ declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
87
200
  static create<SchemasCreate extends SchemaTypeRecord>(
88
201
  dbName: string,
89
202
  schemas: SchemasCreate,
203
+ options?: BaseStorageOptions
90
204
  ): Promise<
91
- IndexDB<
205
+ BaseStorage<
92
206
  SchemasCreate
93
207
  >
94
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
95
228
  }
96
229
 
97
230
 
98
231
 
99
232
  /**
100
- * Represents an in-memory storage system extending the base storage functionality.
233
+ * Represents an IndexDB storage system extending the base storage functionality.
101
234
  *
102
235
  * @template T - The schema type.
103
236
  */
104
- declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
237
+ declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
105
238
  /**
106
239
  * Frees the resources used by the in-memory storage.
107
240
  */
@@ -111,7 +244,7 @@ declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
111
244
  dbName: string,
112
245
  schemas: SchemasCreate,
113
246
  ): Promise<
114
- InMemory<
247
+ IndexDB<
115
248
  SchemasCreate
116
249
  >
117
250
  >;
@@ -119,88 +252,170 @@ declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
119
252
 
120
253
 
121
254
 
122
- type Hook = (
123
- schema: Schema<SchemaType>,
124
- migration: MigrationPathsForSchema<SchemaType>,
125
- doc: Doc<SchemaType>
126
- ) => Doc<SchemaType>
255
+ type Operators<T> = {
256
+ $gte?: number,
257
+ $gt?: number
258
+ $lt?: number,
259
+ $lte?: number,
260
+ $eq?: T,
261
+ $ne?: T
262
+ };
127
263
 
128
- type BasePluginOptions = {
129
- docCreateHook?: Hook,
130
- docRecoverHook?: Hook
131
- }
264
+ type InOperator<T> = { $in?: T[] };
265
+ type NInOperator<T> = { $nin?: T[] };
132
266
 
133
- declare class BasePlugin implements BasePluginOptions {
134
- docCreateHook?:Hook;
135
- docRecoverHook?:Hook;
267
+ type OperatorOrType<T> = T extends number ?
268
+ T | Operators<T> | InOperator<T> | NInOperator<T> :
269
+ T | InOperator<T> | NInOperator<T>;
270
+
271
+ type LogicalOperators<T extends SchemaType> = {
272
+ $and?: Partial<QueryType<T>>[];
273
+ $or?: Partial<QueryType<T>>[];
274
+ };
275
+
276
+ type QueryType<T extends SchemaType> = ({
277
+ [K in keyof T['properties']as ExtractType<T['properties'][K]['type']> extends undefined ? never : K]?: OperatorOrType<
278
+ ExtractType<
279
+ T['properties'][K]['type']
280
+ >
281
+ >
282
+ } & LogicalOperators<T>) | LogicalOperators<T>[];
283
+
284
+ declare class Query<T extends SchemaType> {
285
+ constructor(query: QueryType<T>, schema:Schema<T>);
286
+ readonly query: QueryType<T>;
136
287
  }
137
288
 
138
289
 
139
290
 
140
291
  /**
141
- * Represents the type definition for a schema.
292
+ * Represents a property within a schema, including various constraints and nested properties.
142
293
  */
143
- type SchemaType = {
294
+ declare class Property {
144
295
  /**
145
- * The version of the schema.
296
+ * The type of the property.
146
297
  */
147
- version: number;
298
+ readonly type: SchemaFieldType;
148
299
 
149
300
  /**
150
- * The primary key of the schema.
301
+ * The version of the property, if applicable.
151
302
  */
152
- primaryKey: string;
303
+ readonly version?: number;
153
304
 
154
305
  /**
155
- * The type of the schema.
156
- */
157
- type: SchemaFieldType;
158
- indexes?: string[];
159
- encrypted?: string[];
160
- /**
161
- * The properties defined in the schema.
306
+ * The primary key of the property, if applicable.
162
307
  */
163
- properties: {
164
- [name: string]: Property;
165
- };
166
- };
167
-
308
+ readonly primaryKey?: string;
168
309
 
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
- declare class Schema<T extends SchemaType> {
186
310
  /**
187
- * The schema definition.
311
+ * An optional array of nested properties for array-type properties.
188
312
  */
189
- schema: Schema<T>;
313
+ readonly items?: Property;
190
314
 
191
315
  /**
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.
316
+ * The maximum number of items for array-type properties, if applicable.
197
317
  */
198
- static create<TS extends SchemaType>(definition: TS): Schema<TS>;
318
+ readonly maxItems?: number;
199
319
 
200
320
  /**
201
- * The version of the schema.
321
+ * The minimum number of items for array-type properties, if applicable.
202
322
  */
203
- readonly version: number;
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;
204
419
 
205
420
  /**
206
421
  * The primary key of the schema.
@@ -293,225 +508,111 @@ type MigrationsParameter<
293
508
 
294
509
 
295
510
 
296
- type Operators<T> = {
297
- $gte?: number,
298
- $gt?: number
299
- $lt?: number,
300
- $lte?: number,
301
- $eq?: T,
302
- $ne?: T
303
- };
511
+ type Hook = (
512
+ schema: Schema<SchemaType>,
513
+ migration: MigrationPathsForSchema<SchemaType>,
514
+ doc: Doc<SchemaType>
515
+ ) => Doc<SchemaType>
304
516
 
305
- type InOperator<T> = { $in?: T[] };
306
- type NInOperator<T> = { $nin?: T[] };
517
+ type BasePluginOptions = {
518
+ docCreateHook?: Hook,
519
+ docRecoverHook?: Hook
520
+ }
307
521
 
308
- type OperatorOrType<T> = T extends number ?
309
- T | Operators<T> | InOperator<T> | NInOperator<T> :
310
- T | InOperator<T> | NInOperator<T>;
522
+ declare class BasePlugin implements BasePluginOptions {
523
+ docCreateHook?:Hook;
524
+ docRecoverHook?:Hook;
525
+ }
311
526
 
312
- type LogicalOperators<T extends SchemaType> = {
313
- $and?: Partial<QueryType<T>>[];
314
- $or?: Partial<QueryType<T>>[];
315
- };
316
527
 
317
- type QueryType<T extends SchemaType> = ({
318
- [K in keyof T['properties']as ExtractType<T['properties'][K]['type']> extends undefined ? never : K]?: OperatorOrType<
319
- ExtractType<
320
- T['properties'][K]['type']
321
- >
322
- >
323
- } & LogicalOperators<T>) | LogicalOperators<T>[];
324
528
 
325
- declare class Query<T extends SchemaType> {
326
- constructor(query: QueryType<T>, schema:Schema<T>);
327
- readonly query: QueryType<T>;
328
- }
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
+ };
329
555
 
330
556
 
331
557
 
332
558
  /**
333
- * Represents a property within a schema, including various constraints and nested properties.
559
+ * Represents an in-memory storage system extending the base storage functionality.
560
+ *
561
+ * @template T - The schema type.
334
562
  */
335
- declare class Property {
336
- /**
337
- * The type of the property.
338
- */
339
- readonly type: SchemaFieldType;
340
-
341
- /**
342
- * The version of the property, if applicable.
343
- */
344
- readonly version?: number;
345
-
346
- /**
347
- * The primary key of the property, if applicable.
348
- */
349
- readonly primaryKey?: string;
350
-
351
- /**
352
- * An optional array of nested properties for array-type properties.
353
- */
354
- readonly items?: Property;
355
-
356
- /**
357
- * The maximum number of items for array-type properties, if applicable.
358
- */
359
- readonly maxItems?: number;
360
-
361
- /**
362
- * The minimum number of items for array-type properties, if applicable.
363
- */
364
- readonly minItems?: number;
365
-
366
- /**
367
- * The maximum length for string-type properties, if applicable.
368
- */
369
- readonly maxLength?: number;
370
-
371
- /**
372
- * The minimum length for string-type properties, if applicable.
373
- */
374
- readonly minLength?: number;
375
-
376
- /**
377
- * An optional array of required fields for object-type properties.
378
- */
379
- readonly required?: boolean;
380
-
563
+ declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
381
564
  /**
382
- * An optional default value for the property.
565
+ * Frees the resources used by the in-memory storage.
383
566
  */
384
- readonly default?: any;
567
+ free(): void;
385
568
 
386
- /**
387
- * An optional map of nested properties for object-type properties.
388
- */
389
- readonly properties?: {
390
- [name: string]: Property;
391
- };
569
+ static create<SchemasCreate extends SchemaTypeRecord>(
570
+ dbName: string,
571
+ schemas: SchemasCreate,
572
+ ): Promise<
573
+ InMemory<
574
+ SchemasCreate
575
+ >
576
+ >;
392
577
  }
393
578
 
394
579
 
395
580
 
396
- type InternalsRecord = {
397
- [name: string]: BaseStorage<SchemaTypeRecord>
398
- };
399
- /**
400
- * ExtractType is a utility type that maps a string representing a basic data type to the actual TypeScript type.
401
- *
402
- * @template T - A string literal type representing the basic data type ('string', 'number', 'boolean', 'object', 'array').
403
- *
404
- * @example
405
- * type StringType = ExtractType<'string'>; // StringType is string
406
- * type NumberType = ExtractType<'number'>; // NumberType is number
407
- * type BooleanType = ExtractType<'boolean'>; // BooleanType is boolean
408
- * type ObjectType = ExtractType<'object'>; // ObjectType is object
409
- * type ArrayType = ExtractType<'array'>; // ArrayType is Array<any>
410
- */
411
- type ExtractType<T extends string> =
412
- T extends "string" ? string :
413
- T extends "number" ? number :
414
- T extends "boolean" ? boolean :
415
- T extends "object" ? object :
416
- T extends "array" ? any[] :
417
- undefined;
418
-
419
- type IsOptional<T> =
420
- T extends { required: true }
421
- ? T extends { default: never }
422
- ? false
423
- : true
424
- : true;
425
-
426
581
  /**
427
- * Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
428
- *
429
- * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
430
- *
431
- * type Document = Doc<Schema>; // Document is { name: string; age: number; }
432
- */
433
- type Doc<T extends SchemaType> = {
434
- [K in keyof T["properties"]]:
435
- ExtractType<T['properties'][K]['type']>
436
- } & {
437
- __version?: number;
438
- createdAt?: number;
439
- updatedAt?: number;
440
- };
441
-
442
- /**
443
- * CreateDoc is a utility type for document creation that properly handles required vs optional fields
444
- * during the creation process. Fields with default values or required: false become optional.
445
- *
446
- * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
582
+ * Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
583
+ * @internal
447
584
  */
448
- type CreateDoc<T extends SchemaType> = {
449
- [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
450
- ExtractType<T['properties'][K]['type']>
451
- } & {
452
- [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
453
- ExtractType<T['properties'][K]['type']>
454
- } & {
455
- __version?: number;
456
- createdAt?: number;
457
- updatedAt?: number;
585
+ type SchemaTypeRecord = {
586
+ [name: string]: SchemaType
458
587
  };
459
588
 
460
- type QueryOptions = {
461
- limit?: number;
462
- offset?: number;
463
- }
464
-
465
- /**
466
- * Collection is a class that represents a collection of documents in a database.
467
- * @template T - A schema type defining the structure of the documents in the collection.
468
- */
469
- declare class Collection<T extends SchemaType> {
470
- /**
471
- * Finds all documents in the collection.
472
- *
473
- * @returns A promise that resolves to an array of documents.
474
- */
475
- find(query: QueryType<T>, options?: QueryOptions): Promise<Doc<T>[]>;
476
- /**
477
- * count all documents in the collection.
478
- *
479
- * @returns A promise that resolves to an array of documents.
480
- */
481
- count(query: QueryType<T>, options?: QueryOptions): Promise<number>;
482
- /**
483
- * Finds a single document in the collection by its ID.
484
- *
485
- * @param id - The ID of the document to find.
486
- * @returns A promise that resolves to the found document.
487
- */
488
- findById(id: string): Promise<Doc<T>>;
489
- /**
490
- * Updates a document in the collection by its ID.
491
- *
492
- * @param document - A partial document containing the fields to update.
493
- * @returns A promise that resolves when the update is complete.
494
- */
495
- update(document: Partial<Doc<T>>): Promise<void>;
496
- /**
497
- * Creates a new document in the collection.
498
- *
499
- * @param document - The document to create.
500
- * @returns A promise that resolves to the created document.
501
- */
502
- create(document: CreateDoc<T>): Promise<Doc<T>>;
503
- /**
504
- * Deletes a document in the collection by its ID.
505
- *
506
- * @param id - The ID of the document to delete.
507
- * @returns A promise that resolves when the deletion is complete.
508
- */
509
- delete(id: string): Promise<void>;
589
+ declare abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
590
+ constructor(
591
+ name: string,
592
+ schemas: Schemas
593
+ );
594
+ abstract start(): Promise<void>;
595
+ abstract close(): Promise<void>;
596
+ abstract count(
597
+ colectionName: keyof Schemas,
598
+ query: QueryType<Schemas[keyof Schemas]>,
599
+ options?: QueryOptions
600
+ ): Promise<number>;
601
+ abstract findDocumentById(
602
+ collectionName: keyof Schemas,
603
+ id: string
604
+ ): Promise<Doc<Schemas[keyof Schemas]> | null>;
605
+ abstract find(
606
+ collectionName: keyof Schemas,
607
+ query: QueryType<Schemas[keyof Schemas]>,
608
+ options?: QueryOptions
609
+ ): Promise<Doc<Schemas[keyof Schemas]>[]>;
610
+ abstract write(
611
+ op: Operation<Schemas[keyof Schemas]>
612
+ ): Promise<Doc<Schemas[keyof Schemas]>>;
510
613
  }
511
614
 
512
615
 
513
-
514
-
515
616
  declare class CoreStorage {
516
617
  /**
517
618
  * @param {any} document
@@ -525,33 +626,6 @@ declare class CoreStorage {
525
626
 
526
627
 
527
628
 
528
- /**
529
- * Represents an operation to be performed on a collection.
530
- *
531
- * @template T - The schema type of the collection.
532
- */
533
- type Operation<T extends SchemaType = SchemaType> = {
534
- /**
535
- * The name of the collection on which the operation will be performed.
536
- */
537
- collection: string,
538
-
539
- /**
540
- * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
541
- */
542
- opType: OpType,
543
-
544
- /**
545
- * The data involved in the operation, conforming to the schema type.
546
- */
547
- data: Doc<T>,
548
-
549
- primaryKeyField?: string,
550
- primaryKey?: string
551
- }
552
-
553
-
554
-
555
629
  /**
556
630
  * Represents a database containing collections of documents.
557
631
  * RIDB extends from this class and is used to expose collections.
@@ -656,103 +730,29 @@ type RIDBModule = {
656
730
 
657
731
 
658
732
 
659
- declare const SchemaFieldType = {
660
- /**
661
- * String type for text data
662
- */
663
- string: 'string' as const,
664
-
665
- /**
666
- * Number type for numeric data (integers and floats)
667
- */
668
- number: 'number' as const,
669
-
670
- /**
671
- * Boolean type for true/false values
672
- */
673
- boolean: 'boolean' as const,
674
-
675
- /**
676
- * Array type for ordered collections of items
677
- */
678
- array: 'array' as const,
679
-
680
- /**
681
- * Object type for nested document structures
682
- */
683
- object: 'object' as const,
684
- };
685
-
686
-
687
-
688
733
  /**
689
- * Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
690
- * @internal
734
+ * Represents an operation to be performed on a collection.
735
+ *
736
+ * @template T - The schema type of the collection.
691
737
  */
692
- type SchemaTypeRecord = {
693
- [name: string]: SchemaType
694
- };
695
-
696
- declare abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
697
- constructor(
698
- name: string,
699
- schemas: Schemas
700
- );
701
- abstract start(): Promise<void>;
702
- abstract close(): Promise<void>;
703
- abstract count(
704
- colectionName: keyof Schemas,
705
- query: QueryType<Schemas[keyof Schemas]>,
706
- options?: QueryOptions
707
- ): Promise<number>;
708
- abstract findDocumentById(
709
- collectionName: keyof Schemas,
710
- id: string
711
- ): Promise<Doc<Schemas[keyof Schemas]> | null>;
712
- abstract find(
713
- collectionName: keyof Schemas,
714
- query: QueryType<Schemas[keyof Schemas]>,
715
- options?: QueryOptions
716
- ): Promise<Doc<Schemas[keyof Schemas]>[]>;
717
- abstract write(
718
- op: Operation<Schemas[keyof Schemas]>
719
- ): Promise<Doc<Schemas[keyof Schemas]>>;
720
- }
738
+ type Operation<T extends SchemaType = SchemaType> = {
739
+ /**
740
+ * The name of the collection on which the operation will be performed.
741
+ */
742
+ collection: string,
721
743
 
744
+ /**
745
+ * The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
746
+ */
747
+ opType: OpType,
722
748
 
723
- type BaseStorageOptions = {
724
- [name:string]:string | boolean | number
725
- }
749
+ /**
750
+ * The data involved in the operation, conforming to the schema type.
751
+ */
752
+ data: Doc<T>,
726
753
 
727
- declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
728
- static create<SchemasCreate extends SchemaTypeRecord>(
729
- dbName: string,
730
- schemas: SchemasCreate,
731
- options?: BaseStorageOptions
732
- ): Promise<
733
- BaseStorage<
734
- SchemasCreate
735
- >
736
- >;
737
- constructor(
738
- dbName: string,
739
- schemas: Schemas,
740
- options?: BaseStorageOptions
741
- );
742
- readonly dbName: string;
743
- readonly schemas: Record<keyof Schemas, Schema<Schemas[keyof Schemas]>>;
744
- readonly options: BaseStorageOptions;
745
- readonly core: CoreStorage;
746
- start(): Promise<void>;
747
- close(): Promise<void>;
748
- count(colectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<number>;
749
- findDocumentById(collectionName: keyof Schemas, id: string): Promise<Doc<Schemas[keyof Schemas]> | null>;
750
- find(collectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>, options?: QueryOptions): Promise<Doc<Schemas[keyof Schemas]>[]>;
751
- write(op: Operation<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>>;
752
- getOption(name: string): string | boolean | number | undefined;
753
- getSchema(name: string): Schema<any>;
754
- //Call addIndexSchemas if you need extra indexing schemas for your database
755
- addIndexSchemas(): null
754
+ primaryKeyField?: string,
755
+ primaryKey?: string
756
756
  }
757
757
 
758
758
 
@@ -867,6 +867,24 @@ 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;
870
888
  readonly __wbg_ridberror_free: (a: number) => void;
871
889
  readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
872
890
  readonly ridberror_type: (a: number, b: number) => void;
@@ -889,34 +907,9 @@ interface InitOutput {
889
907
  readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
890
908
  readonly indexdb_close: (a: number) => number;
891
909
  readonly indexdb_start: (a: number) => number;
892
- readonly __wbg_inmemory_free: (a: number) => void;
893
- readonly inmemory_create: (a: number, b: number, c: number) => number;
894
- readonly inmemory_write: (a: number, b: number) => number;
895
- readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
896
- readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
897
- readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
898
- readonly inmemory_close: (a: number) => number;
899
- readonly inmemory_start: (a: number) => number;
900
- readonly __wbg_baseplugin_free: (a: number) => void;
901
- readonly baseplugin_new: (a: number, b: number, c: number) => void;
902
- readonly baseplugin_name: (a: number) => number;
903
- readonly baseplugin_get_doc_create_hook: (a: number) => number;
904
- readonly baseplugin_get_doc_recover_hook: (a: number) => number;
905
- readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
906
- readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
907
- readonly __wbg_schema_free: (a: number) => void;
908
- readonly schema_validate: (a: number, b: number, c: number) => void;
909
- readonly schema_is_valid: (a: number, b: number) => void;
910
- readonly schema_create: (a: number, b: number) => void;
911
- readonly schema_version: (a: number) => number;
912
- readonly schema_primaryKey: (a: number, b: number) => void;
913
- readonly schema_type: (a: number, b: number) => void;
914
- readonly schema_indexes: (a: number, b: number) => void;
915
- readonly schema_encrypted: (a: number, b: number) => void;
916
- readonly schema_properties: (a: number, b: number) => void;
917
- readonly __wbgt_test_schema_creation_3: (a: number) => void;
918
- readonly __wbgt_test_schema_validation_4: (a: number) => void;
919
- readonly __wbgt_test_invalid_schema_5: (a: number) => void;
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;
920
913
  readonly __wbg_query_free: (a: number) => void;
921
914
  readonly query_new: (a: number, b: number, c: number) => void;
922
915
  readonly query_query: (a: number, b: number) => void;
@@ -924,6 +917,7 @@ interface InitOutput {
924
917
  readonly query_parse: (a: number, b: number) => void;
925
918
  readonly query_process_query: (a: number, b: number, c: number) => void;
926
919
  readonly query_get: (a: number, b: number, c: number, d: number) => void;
920
+ readonly query_has_or_operator: (a: number) => number;
927
921
  readonly __wbgt_test_get_properties_simple_fields_6: (a: number) => void;
928
922
  readonly __wbgt_test_get_properties_with_operators_7: (a: number) => void;
929
923
  readonly __wbgt_test_get_properties_with_logical_operators_8: (a: number) => void;
@@ -965,23 +959,44 @@ interface InitOutput {
965
959
  readonly __wbgt_test_property_creation_0: (a: number) => void;
966
960
  readonly __wbgt_test_property_validation_1: (a: number) => void;
967
961
  readonly __wbgt_test_invalid_property_2: (a: number) => void;
968
- readonly __wbg_collection_free: (a: number) => void;
969
- readonly collection_name: (a: number, b: number) => void;
970
- readonly collection_schema: (a: number, b: number) => void;
971
- readonly collection_find: (a: number, b: number, c: number) => number;
972
- readonly collection_parse_query_options: (a: number, b: number, c: number) => void;
973
- readonly collection_count: (a: number, b: number, c: number) => number;
974
- readonly collection_findById: (a: number, b: number) => number;
975
- readonly collection_update: (a: number, b: number) => number;
976
- readonly collection_create: (a: number, b: number) => number;
977
- readonly collection_delete: (a: number, b: number) => number;
978
- readonly corestorage_new: () => number;
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
+ readonly __wbg_inmemory_free: (a: number) => void;
983
+ readonly inmemory_create: (a: number, b: number, c: number) => number;
984
+ readonly inmemory_write: (a: number, b: number) => number;
985
+ readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
986
+ readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
987
+ readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
988
+ readonly inmemory_close: (a: number) => number;
989
+ readonly inmemory_start: (a: number) => number;
979
990
  readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
980
991
  readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
981
992
  readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
982
- readonly __wbg_queryoptions_free: (a: number) => void;
983
- readonly queryoptions_limit: (a: number, b: number) => void;
984
- readonly queryoptions_offset: (a: number, b: number) => void;
993
+ readonly __wbg_database_free: (a: number) => void;
994
+ readonly database_start: (a: number) => number;
995
+ readonly database_close: (a: number) => number;
996
+ readonly database_started: (a: number) => number;
997
+ readonly database_authenticate: (a: number, b: number, c: number) => number;
998
+ readonly database_collections: (a: number, b: number) => void;
999
+ readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
985
1000
  readonly __wbg_operation_free: (a: number) => void;
986
1001
  readonly operation_collection: (a: number, b: number) => void;
987
1002
  readonly operation_opType: (a: number) => number;
@@ -989,22 +1004,8 @@ interface InitOutput {
989
1004
  readonly operation_primaryKeyField: (a: number) => number;
990
1005
  readonly operation_primaryKey: (a: number) => number;
991
1006
  readonly operation_primaryKeyIndex: (a: number, b: number) => void;
1007
+ readonly corestorage_new: () => number;
992
1008
  readonly __wbg_corestorage_free: (a: number) => void;
993
- readonly __wbg_database_free: (a: number) => void;
994
- readonly database_start: (a: number) => number;
995
- readonly database_close: (a: number) => number;
996
- readonly database_started: (a: number) => number;
997
- readonly database_authenticate: (a: number, b: number, c: number) => number;
998
- readonly database_collections: (a: number, b: number) => void;
999
- readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
1000
- readonly main_js: () => void;
1001
- readonly is_debug_mode: () => number;
1002
- readonly __wbg_basestorage_free: (a: number) => void;
1003
- readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
1004
- readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
1005
- readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
1006
- readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
1007
- readonly basestorage_core: (a: number, b: number) => void;
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;
@@ -1017,16 +1018,15 @@ interface InitOutput {
1017
1018
  readonly __wbindgen_malloc: (a: number, b: number) => number;
1018
1019
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
1019
1020
  readonly __wbindgen_export_2: WebAssembly.Table;
1021
+ readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hcf4fe6fd0b7ccc8d: (a: number, b: number, c: number) => void;
1020
1022
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
1021
- readonly _dyn_core__ops__function__Fn__A_B_C___Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1d7727fe9471ac49: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
1022
- readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4e550b82c2b30c7a: (a: number, b: number, c: number) => void;
1023
- readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hec0cc069f718ed78: (a: number, b: number) => void;
1024
- readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf401bdfdf8c9bdd9: (a: number, b: number, c: number) => void;
1023
+ readonly _dyn_core__ops__function__Fn__A_B_C___Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he6024291054ff5aa: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
1024
+ readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hb6eb1f8e3b5e56e9: (a: number, b: number, c: number) => void;
1025
1025
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
1026
1026
  readonly __wbindgen_exn_store: (a: number) => void;
1027
- readonly wasm_bindgen__convert__closures__invoke0_mut__he68973678185bd11: (a: number, b: number) => void;
1028
- readonly wasm_bindgen__convert__closures__invoke3_mut__h711940be5154e055: (a: number, b: number, c: number, d: number, e: number) => void;
1029
- readonly wasm_bindgen__convert__closures__invoke2_mut__hdfe55fa2a247d1ac: (a: number, b: number, c: number, d: number) => void;
1027
+ readonly wasm_bindgen__convert__closures__invoke0_mut__hff00333f3d941090: (a: number, b: number) => void;
1028
+ readonly wasm_bindgen__convert__closures__invoke3_mut__h703f9c33fd3008bf: (a: number, b: number, c: number, d: number, e: number) => void;
1029
+ readonly wasm_bindgen__convert__closures__invoke2_mut__h97988f5fa0547d24: (a: number, b: number, c: number, d: number) => void;
1030
1030
  readonly __wbindgen_start: () => void;
1031
1031
  }
1032
1032