@trust0/ridb-core 1.7.22 → 1.7.24
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.
- package/README.md +1 -1
- package/build/ridb_core.d.ts +382 -382
- package/build/ridb_core.js +129 -129
- package/build/ridb_core.mjs +129 -129
- package/build/ridb_core_bg.mjs +1 -1
- package/package.json +2 -2
package/build/ridb_core.d.ts
CHANGED
|
@@ -87,157 +87,132 @@ declare class CoreStorage {
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* Represents
|
|
90
|
+
* Represents a database containing collections of documents.
|
|
91
|
+
* RIDB extends from this class and is used to expose collections.
|
|
92
|
+
*
|
|
93
|
+
* So if you specify:
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const db = new RIDB(
|
|
96
|
+
* {
|
|
97
|
+
* schemas: {
|
|
98
|
+
* demo: {
|
|
99
|
+
* version: 0,
|
|
100
|
+
* primaryKey: 'id',
|
|
101
|
+
* type: SchemaFieldType.object,
|
|
102
|
+
* properties: {
|
|
103
|
+
* id: {
|
|
104
|
+
* type: SchemaFieldType.string,
|
|
105
|
+
* maxLength: 60
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
* } as const
|
|
110
|
+
* }
|
|
111
|
+
* )
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* The collection will be available as `db.collections.demo` and all the methods for the collection (find, count, findById, update, create, delete) will be available.
|
|
91
115
|
*
|
|
92
|
-
* @template T -
|
|
116
|
+
* @template T - A record of schema types.
|
|
93
117
|
*/
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* The name of the collection on which the operation will be performed.
|
|
97
|
-
*/
|
|
98
|
-
collection: string,
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
|
|
102
|
-
*/
|
|
103
|
-
opType: OpType,
|
|
118
|
+
declare class Database<T extends SchemaTypeRecord> {
|
|
104
119
|
|
|
105
120
|
/**
|
|
106
|
-
*
|
|
121
|
+
* Creates a new `Database` instance with the provided schemas and storage module.
|
|
122
|
+
*
|
|
123
|
+
* @template TS - A record of schema types.
|
|
124
|
+
* @param {TS} schemas - The schemas to use for the collections.
|
|
125
|
+
* @param migrations
|
|
126
|
+
* @param plugins
|
|
127
|
+
* @param options
|
|
128
|
+
* @param password
|
|
129
|
+
* @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
|
|
107
130
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* String type for text data
|
|
119
|
-
*/
|
|
120
|
-
string: 'string' as const,
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Number type for numeric data (integers and floats)
|
|
124
|
-
*/
|
|
125
|
-
number: 'number' as const,
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Boolean type for true/false values
|
|
129
|
-
*/
|
|
130
|
-
boolean: 'boolean' as const,
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Array type for ordered collections of items
|
|
134
|
-
*/
|
|
135
|
-
array: 'array' as const,
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Object type for nested document structures
|
|
139
|
-
*/
|
|
140
|
-
object: 'object' as const,
|
|
141
|
-
};
|
|
142
|
-
|
|
131
|
+
static create<TS extends SchemaTypeRecord>(
|
|
132
|
+
db_name: string,
|
|
133
|
+
schemas: TS,
|
|
134
|
+
migrations: MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>,
|
|
135
|
+
plugins:Array<typeof BasePlugin>,
|
|
136
|
+
options: RIDBModule,
|
|
137
|
+
password?:string,
|
|
138
|
+
storage?: BaseStorage<TS>
|
|
139
|
+
): Promise<Database<TS>>;
|
|
143
140
|
|
|
141
|
+
authenticate(password: string): Promise<boolean>;
|
|
144
142
|
|
|
145
|
-
/**
|
|
146
|
-
* Represents a property within a schema, including various constraints and nested properties.
|
|
147
|
-
*/
|
|
148
|
-
declare class Property {
|
|
149
143
|
/**
|
|
150
|
-
* The
|
|
144
|
+
* The collections in the database.
|
|
145
|
+
*
|
|
146
|
+
* This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
|
|
151
147
|
*/
|
|
152
|
-
readonly
|
|
148
|
+
readonly collections: {
|
|
149
|
+
[name in keyof T]: Collection<Schema<T[name]>>
|
|
150
|
+
}
|
|
153
151
|
|
|
154
|
-
|
|
155
|
-
* The version of the property, if applicable.
|
|
156
|
-
*/
|
|
157
|
-
readonly version?: number;
|
|
152
|
+
readonly started: boolean;
|
|
158
153
|
|
|
159
154
|
/**
|
|
160
|
-
*
|
|
155
|
+
* Starts the database.
|
|
156
|
+
*
|
|
157
|
+
* @returns {Promise<void>} A promise that resolves when the database is started.
|
|
161
158
|
*/
|
|
162
|
-
|
|
159
|
+
start(): Promise<void>;
|
|
163
160
|
|
|
164
161
|
/**
|
|
165
|
-
*
|
|
162
|
+
* Closes the database.
|
|
163
|
+
*
|
|
164
|
+
* @returns {Promise<void>} A promise that resolves when the database is closed.
|
|
166
165
|
*/
|
|
167
|
-
|
|
166
|
+
close(): Promise<void>;
|
|
167
|
+
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Represents a function type for creating storage with the provided schema type records.
|
|
171
|
+
*
|
|
172
|
+
* @template T - The schema type record.
|
|
173
|
+
* @param {T} records - The schema type records.
|
|
174
|
+
* @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
|
|
175
|
+
*/
|
|
176
|
+
type CreateStorage = <T extends SchemaTypeRecord>(
|
|
177
|
+
records: T
|
|
178
|
+
) => Promise<BaseStorage<T>>;
|
|
173
179
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Represents a storage module with a method for creating storage.
|
|
182
|
+
*/
|
|
183
|
+
type RIDBModule = {
|
|
178
184
|
|
|
179
185
|
/**
|
|
180
|
-
*
|
|
186
|
+
* Plugin constructors array
|
|
181
187
|
*/
|
|
182
|
-
|
|
188
|
+
apply: (plugins:Array<typeof BasePlugin>) => Array<BasePlugin>;
|
|
189
|
+
};
|
|
190
|
+
|
|
183
191
|
|
|
184
|
-
/**
|
|
185
|
-
* The minimum length for string-type properties, if applicable.
|
|
186
|
-
*/
|
|
187
|
-
readonly minLength?: number;
|
|
188
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Represents an operation to be performed on a collection.
|
|
195
|
+
*
|
|
196
|
+
* @template T - The schema type of the collection.
|
|
197
|
+
*/
|
|
198
|
+
type Operation<T extends SchemaType = SchemaType> = {
|
|
189
199
|
/**
|
|
190
|
-
*
|
|
200
|
+
* The name of the collection on which the operation will be performed.
|
|
191
201
|
*/
|
|
192
|
-
|
|
202
|
+
collection: string,
|
|
193
203
|
|
|
194
204
|
/**
|
|
195
|
-
*
|
|
205
|
+
* The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
|
|
196
206
|
*/
|
|
197
|
-
|
|
207
|
+
opType: OpType,
|
|
198
208
|
|
|
199
209
|
/**
|
|
200
|
-
*
|
|
210
|
+
* The data involved in the operation, conforming to the schema type.
|
|
201
211
|
*/
|
|
202
|
-
|
|
203
|
-
[name: string]: Property;
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
type Operators<T> = {
|
|
210
|
-
$gte?: number,
|
|
211
|
-
$gt?: number
|
|
212
|
-
$lt?: number,
|
|
213
|
-
$lte?: number,
|
|
214
|
-
$eq?: T,
|
|
215
|
-
$ne?: T
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
type InOperator<T> = { $in?: T[] };
|
|
219
|
-
type NInOperator<T> = { $nin?: T[] };
|
|
220
|
-
|
|
221
|
-
type OperatorOrType<T> = T extends number ?
|
|
222
|
-
T | Operators<T> | InOperator<T> | NInOperator<T> :
|
|
223
|
-
T | InOperator<T> | NInOperator<T>;
|
|
224
|
-
|
|
225
|
-
type LogicalOperators<T extends SchemaType> = {
|
|
226
|
-
$and?: Partial<QueryType<T>>[];
|
|
227
|
-
$or?: Partial<QueryType<T>>[];
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
type QueryType<T extends SchemaType> = ({
|
|
231
|
-
[K in keyof T['properties']as ExtractType<T['properties'][K]['type']> extends undefined ? never : K]?: OperatorOrType<
|
|
232
|
-
ExtractType<
|
|
233
|
-
T['properties'][K]['type']
|
|
234
|
-
>
|
|
235
|
-
>
|
|
236
|
-
} & LogicalOperators<T>) | LogicalOperators<T>[];
|
|
212
|
+
data: Doc<T>,
|
|
237
213
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
readonly query: QueryType<T>;
|
|
214
|
+
primaryKeyField?: string,
|
|
215
|
+
primaryKey?: string
|
|
241
216
|
}
|
|
242
217
|
|
|
243
218
|
|
|
@@ -338,7 +313,6 @@ declare class Collection<T extends SchemaType> {
|
|
|
338
313
|
/**
|
|
339
314
|
* Updates a document in the collection by its ID.
|
|
340
315
|
*
|
|
341
|
-
* @param id - The ID of the document to update.
|
|
342
316
|
* @param document - A partial document containing the fields to update.
|
|
343
317
|
* @returns A promise that resolves when the update is complete.
|
|
344
318
|
*/
|
|
@@ -399,66 +373,38 @@ declare class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInter
|
|
|
399
373
|
|
|
400
374
|
|
|
401
375
|
|
|
402
|
-
type
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
docRecoverHook?: Hook
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
declare class BasePlugin implements BasePluginOptions {
|
|
414
|
-
docCreateHook?:Hook;
|
|
415
|
-
docRecoverHook?:Hook;
|
|
416
|
-
}
|
|
376
|
+
type Operators<T> = {
|
|
377
|
+
$gte?: number,
|
|
378
|
+
$gt?: number
|
|
379
|
+
$lt?: number,
|
|
380
|
+
$lte?: number,
|
|
381
|
+
$eq?: T,
|
|
382
|
+
$ne?: T
|
|
383
|
+
};
|
|
417
384
|
|
|
385
|
+
type InOperator<T> = { $in?: T[] };
|
|
386
|
+
type NInOperator<T> = { $nin?: T[] };
|
|
418
387
|
|
|
388
|
+
type OperatorOrType<T> = T extends number ?
|
|
389
|
+
T | Operators<T> | InOperator<T> | NInOperator<T> :
|
|
390
|
+
T | InOperator<T> | NInOperator<T>;
|
|
419
391
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
*/
|
|
425
|
-
declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
|
|
426
|
-
/**
|
|
427
|
-
* Frees the resources used by the in-memory storage.
|
|
428
|
-
*/
|
|
429
|
-
free(): void;
|
|
392
|
+
type LogicalOperators<T extends SchemaType> = {
|
|
393
|
+
$and?: Partial<QueryType<T>>[];
|
|
394
|
+
$or?: Partial<QueryType<T>>[];
|
|
395
|
+
};
|
|
430
396
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
IndexDB<
|
|
436
|
-
SchemasCreate
|
|
397
|
+
type QueryType<T extends SchemaType> = ({
|
|
398
|
+
[K in keyof T['properties']as ExtractType<T['properties'][K]['type']> extends undefined ? never : K]?: OperatorOrType<
|
|
399
|
+
ExtractType<
|
|
400
|
+
T['properties'][K]['type']
|
|
437
401
|
>
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Represents an in-memory storage system extending the base storage functionality.
|
|
445
|
-
*
|
|
446
|
-
* @template T - The schema type.
|
|
447
|
-
*/
|
|
448
|
-
declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
|
|
449
|
-
/**
|
|
450
|
-
* Frees the resources used by the in-memory storage.
|
|
451
|
-
*/
|
|
452
|
-
free(): void;
|
|
402
|
+
>
|
|
403
|
+
} & LogicalOperators<T>) | LogicalOperators<T>[];
|
|
453
404
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
): Promise<
|
|
458
|
-
InMemory<
|
|
459
|
-
SchemasCreate
|
|
460
|
-
>
|
|
461
|
-
>;
|
|
405
|
+
declare class Query<T extends SchemaType> {
|
|
406
|
+
constructor(query: QueryType<T>, schema:Schema<T>);
|
|
407
|
+
readonly query: QueryType<T>;
|
|
462
408
|
}
|
|
463
409
|
|
|
464
410
|
|
|
@@ -571,8 +517,127 @@ declare class Schema<T extends SchemaType> {
|
|
|
571
517
|
|
|
572
518
|
|
|
573
519
|
|
|
520
|
+
type EnumerateUpTo<
|
|
521
|
+
N extends number,
|
|
522
|
+
Acc extends number[] = []
|
|
523
|
+
> = Acc['length'] extends N ?
|
|
524
|
+
Acc[number]:
|
|
525
|
+
EnumerateUpTo<N, [...Acc, Acc['length']]> ;
|
|
526
|
+
|
|
527
|
+
type EnumerateFrom1To<
|
|
528
|
+
N extends number
|
|
529
|
+
> = Exclude<EnumerateUpTo<N>,0> | (N extends 0 ? never : N);
|
|
530
|
+
|
|
531
|
+
type IsVersionGreaterThan0<
|
|
532
|
+
V extends number
|
|
533
|
+
> = V extends 0 ? false : true;
|
|
534
|
+
|
|
535
|
+
type AnyVersionGreaterThan1<
|
|
536
|
+
T extends Record<string, SchemaType>
|
|
537
|
+
> = true extends {
|
|
538
|
+
[K in keyof T]: IsVersionGreaterThan0<T[K]['version']>;
|
|
539
|
+
} [keyof T] ? true : false;
|
|
540
|
+
|
|
541
|
+
type MigrationFunction<T extends SchemaType> = (doc: Doc <T> ) => Doc <T>
|
|
542
|
+
|
|
543
|
+
type MigrationPathsForSchema<
|
|
544
|
+
T extends SchemaType
|
|
545
|
+
> = T['version'] extends 0 ? {}: // No migrations needed for version 1
|
|
546
|
+
{
|
|
547
|
+
[K in EnumerateFrom1To < T['version'] > ]: MigrationFunction<T> ;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
type MigrationPathsForSchemas<
|
|
551
|
+
T extends SchemaTypeRecord
|
|
552
|
+
> = {
|
|
553
|
+
[K in keyof T]: MigrationPathsForSchema<T[K]>;
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
type MigrationsParameter<
|
|
557
|
+
T extends SchemaTypeRecord
|
|
558
|
+
> = AnyVersionGreaterThan1<T> extends true ?
|
|
559
|
+
{
|
|
560
|
+
migrations: MigrationPathsForSchemas<T>
|
|
561
|
+
}:
|
|
562
|
+
{
|
|
563
|
+
migrations?: never
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
type Hook = (
|
|
569
|
+
schema: Schema<SchemaType>,
|
|
570
|
+
migration: MigrationPathsForSchema<SchemaType>,
|
|
571
|
+
doc: Doc<SchemaType>
|
|
572
|
+
) => Doc<SchemaType>
|
|
573
|
+
|
|
574
|
+
type BasePluginOptions = {
|
|
575
|
+
docCreateHook?: Hook,
|
|
576
|
+
docRecoverHook?: Hook
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
declare class BasePlugin implements BasePluginOptions {
|
|
580
|
+
docCreateHook?:Hook;
|
|
581
|
+
docRecoverHook?:Hook;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
declare const SchemaFieldType = {
|
|
587
|
+
/**
|
|
588
|
+
* String type for text data
|
|
589
|
+
*/
|
|
590
|
+
string: 'string' as const,
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Number type for numeric data (integers and floats)
|
|
594
|
+
*/
|
|
595
|
+
number: 'number' as const,
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Boolean type for true/false values
|
|
599
|
+
*/
|
|
600
|
+
boolean: 'boolean' as const,
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Array type for ordered collections of items
|
|
604
|
+
*/
|
|
605
|
+
array: 'array' as const,
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Object type for nested document structures
|
|
609
|
+
*/
|
|
610
|
+
object: 'object' as const,
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Represents an in-memory storage system extending the base storage functionality.
|
|
617
|
+
*
|
|
618
|
+
* @template T - The schema type.
|
|
619
|
+
*/
|
|
620
|
+
declare class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
|
|
621
|
+
/**
|
|
622
|
+
* Frees the resources used by the in-memory storage.
|
|
623
|
+
*/
|
|
624
|
+
free(): void;
|
|
625
|
+
|
|
626
|
+
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
627
|
+
dbName: string,
|
|
628
|
+
schemas: SchemasCreate,
|
|
629
|
+
): Promise<
|
|
630
|
+
InMemory<
|
|
631
|
+
SchemasCreate
|
|
632
|
+
>
|
|
633
|
+
>;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
574
638
|
/**
|
|
575
639
|
* Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
|
|
640
|
+
* @internal
|
|
576
641
|
*/
|
|
577
642
|
type SchemaTypeRecord = {
|
|
578
643
|
[name: string]: SchemaType
|
|
@@ -586,174 +651,109 @@ declare abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
|
|
|
586
651
|
abstract start(): Promise<void>;
|
|
587
652
|
abstract close(): Promise<void>;
|
|
588
653
|
abstract count(
|
|
589
|
-
colectionName: keyof Schemas,
|
|
590
|
-
query: QueryType<Schemas[keyof Schemas]>,
|
|
591
|
-
options?: QueryOptions
|
|
592
|
-
): Promise<number>;
|
|
593
|
-
abstract findDocumentById(
|
|
594
|
-
collectionName: keyof Schemas,
|
|
595
|
-
id: string
|
|
596
|
-
): Promise<Doc<Schemas[keyof Schemas]> | null>;
|
|
597
|
-
abstract find(
|
|
598
|
-
collectionName: keyof Schemas,
|
|
599
|
-
query: QueryType<Schemas[keyof Schemas]>,
|
|
600
|
-
options?: QueryOptions
|
|
601
|
-
): Promise<Doc<Schemas[keyof Schemas]>[]>;
|
|
602
|
-
abstract write(
|
|
603
|
-
op: Operation<Schemas[keyof Schemas]>
|
|
604
|
-
): Promise<Doc<Schemas[keyof Schemas]>>;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Represents a database containing collections of documents.
|
|
610
|
-
* RIDB extends from this class and is used to expose collections.
|
|
611
|
-
*
|
|
612
|
-
* So if you specify:
|
|
613
|
-
* ```typescript
|
|
614
|
-
* const db = new RIDB(
|
|
615
|
-
* {
|
|
616
|
-
* schemas: {
|
|
617
|
-
* demo: {
|
|
618
|
-
* version: 0,
|
|
619
|
-
* primaryKey: 'id',
|
|
620
|
-
* type: SchemaFieldType.object,
|
|
621
|
-
* properties: {
|
|
622
|
-
* id: {
|
|
623
|
-
* type: SchemaFieldType.string,
|
|
624
|
-
* maxLength: 60
|
|
625
|
-
* }
|
|
626
|
-
* }
|
|
627
|
-
* }
|
|
628
|
-
* } as const
|
|
629
|
-
* }
|
|
630
|
-
* )
|
|
631
|
-
* ```
|
|
632
|
-
*
|
|
633
|
-
* The collection will be available as `db.collections.demo` and all the methods for the collection (find, count, findById, update, create, delete) will be available.
|
|
634
|
-
*
|
|
635
|
-
* @template T - A record of schema types.
|
|
636
|
-
*/
|
|
637
|
-
declare class Database<T extends SchemaTypeRecord> {
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
* Creates a new `Database` instance with the provided schemas and storage module.
|
|
641
|
-
*
|
|
642
|
-
* @template TS - A record of schema types.
|
|
643
|
-
* @param {TS} schemas - The schemas to use for the collections.
|
|
644
|
-
* @param migrations
|
|
645
|
-
* @param plugins
|
|
646
|
-
* @param options
|
|
647
|
-
* @param password
|
|
648
|
-
* @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
|
|
649
|
-
*/
|
|
650
|
-
static create<TS extends SchemaTypeRecord>(
|
|
651
|
-
db_name: string,
|
|
652
|
-
schemas: TS,
|
|
653
|
-
migrations: MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>,
|
|
654
|
-
plugins:Array<typeof BasePlugin>,
|
|
655
|
-
options: RIDBModule,
|
|
656
|
-
password?:string,
|
|
657
|
-
storage?: BaseStorage<TS>
|
|
658
|
-
): Promise<Database<TS>>;
|
|
659
|
-
|
|
660
|
-
authenticate(password: string): Promise<boolean>;
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* The collections in the database.
|
|
664
|
-
*
|
|
665
|
-
* This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
|
|
666
|
-
*/
|
|
667
|
-
readonly collections: {
|
|
668
|
-
[name in keyof T]: Collection<Schema<T[name]>>
|
|
669
|
-
}
|
|
654
|
+
colectionName: keyof Schemas,
|
|
655
|
+
query: QueryType<Schemas[keyof Schemas]>,
|
|
656
|
+
options?: QueryOptions
|
|
657
|
+
): Promise<number>;
|
|
658
|
+
abstract findDocumentById(
|
|
659
|
+
collectionName: keyof Schemas,
|
|
660
|
+
id: string
|
|
661
|
+
): Promise<Doc<Schemas[keyof Schemas]> | null>;
|
|
662
|
+
abstract find(
|
|
663
|
+
collectionName: keyof Schemas,
|
|
664
|
+
query: QueryType<Schemas[keyof Schemas]>,
|
|
665
|
+
options?: QueryOptions
|
|
666
|
+
): Promise<Doc<Schemas[keyof Schemas]>[]>;
|
|
667
|
+
abstract write(
|
|
668
|
+
op: Operation<Schemas[keyof Schemas]>
|
|
669
|
+
): Promise<Doc<Schemas[keyof Schemas]>>;
|
|
670
|
+
}
|
|
670
671
|
|
|
671
|
-
readonly started: boolean;
|
|
672
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Represents an IndexDB storage system extending the base storage functionality.
|
|
675
|
+
*
|
|
676
|
+
* @template T - The schema type.
|
|
677
|
+
*/
|
|
678
|
+
declare class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
|
|
673
679
|
/**
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
* @returns {Promise<void>} A promise that resolves when the database is started.
|
|
680
|
+
* Frees the resources used by the in-memory storage.
|
|
677
681
|
*/
|
|
678
|
-
|
|
682
|
+
free(): void;
|
|
679
683
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
684
|
+
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
685
|
+
dbName: string,
|
|
686
|
+
schemas: SchemasCreate,
|
|
687
|
+
): Promise<
|
|
688
|
+
IndexDB<
|
|
689
|
+
SchemasCreate
|
|
690
|
+
>
|
|
691
|
+
>;
|
|
686
692
|
}
|
|
687
693
|
|
|
688
|
-
|
|
689
|
-
* Represents a function type for creating storage with the provided schema type records.
|
|
690
|
-
*
|
|
691
|
-
* @template T - The schema type record.
|
|
692
|
-
* @param {T} records - The schema type records.
|
|
693
|
-
* @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
|
|
694
|
-
*/
|
|
695
|
-
type CreateStorage = <T extends SchemaTypeRecord>(
|
|
696
|
-
records: T
|
|
697
|
-
) => Promise<BaseStorage<T>>;
|
|
694
|
+
|
|
698
695
|
|
|
699
696
|
/**
|
|
700
|
-
* Represents a
|
|
697
|
+
* Represents a property within a schema, including various constraints and nested properties.
|
|
701
698
|
*/
|
|
702
|
-
|
|
703
|
-
|
|
699
|
+
declare class Property {
|
|
704
700
|
/**
|
|
705
|
-
*
|
|
701
|
+
* The type of the property.
|
|
706
702
|
*/
|
|
707
|
-
|
|
708
|
-
};
|
|
703
|
+
readonly type: SchemaFieldType;
|
|
709
704
|
|
|
705
|
+
/**
|
|
706
|
+
* The version of the property, if applicable.
|
|
707
|
+
*/
|
|
708
|
+
readonly version?: number;
|
|
710
709
|
|
|
710
|
+
/**
|
|
711
|
+
* The primary key of the property, if applicable.
|
|
712
|
+
*/
|
|
713
|
+
readonly primaryKey?: string;
|
|
711
714
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
Acc[number]:
|
|
717
|
-
EnumerateUpTo<N, [...Acc, Acc['length']]> ;
|
|
715
|
+
/**
|
|
716
|
+
* An optional array of nested properties for array-type properties.
|
|
717
|
+
*/
|
|
718
|
+
readonly items?: Property;
|
|
718
719
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
720
|
+
/**
|
|
721
|
+
* The maximum number of items for array-type properties, if applicable.
|
|
722
|
+
*/
|
|
723
|
+
readonly maxItems?: number;
|
|
722
724
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
725
|
+
/**
|
|
726
|
+
* The minimum number of items for array-type properties, if applicable.
|
|
727
|
+
*/
|
|
728
|
+
readonly minItems?: number;
|
|
726
729
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
} [keyof T] ? true : false;
|
|
730
|
+
/**
|
|
731
|
+
* The maximum length for string-type properties, if applicable.
|
|
732
|
+
*/
|
|
733
|
+
readonly maxLength?: number;
|
|
732
734
|
|
|
733
|
-
|
|
735
|
+
/**
|
|
736
|
+
* The minimum length for string-type properties, if applicable.
|
|
737
|
+
*/
|
|
738
|
+
readonly minLength?: number;
|
|
734
739
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
[K in EnumerateFrom1To < T['version'] > ]: MigrationFunction<T> ;
|
|
740
|
-
};
|
|
740
|
+
/**
|
|
741
|
+
* An optional array of required fields for object-type properties.
|
|
742
|
+
*/
|
|
743
|
+
readonly required?: boolean;
|
|
741
744
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
};
|
|
745
|
+
/**
|
|
746
|
+
* An optional default value for the property.
|
|
747
|
+
*/
|
|
748
|
+
readonly default?: any;
|
|
747
749
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
{
|
|
752
|
-
|
|
753
|
-
}:
|
|
754
|
-
{
|
|
755
|
-
migrations?: never
|
|
750
|
+
/**
|
|
751
|
+
* An optional map of nested properties for object-type properties.
|
|
752
|
+
*/
|
|
753
|
+
readonly properties?: {
|
|
754
|
+
[name: string]: Property;
|
|
756
755
|
};
|
|
756
|
+
}
|
|
757
757
|
|
|
758
758
|
|
|
759
759
|
/**
|
|
@@ -871,6 +871,13 @@ interface InitOutput {
|
|
|
871
871
|
readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
|
|
872
872
|
readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
|
|
873
873
|
readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
|
|
874
|
+
readonly __wbg_database_free: (a: number) => void;
|
|
875
|
+
readonly database_start: (a: number) => number;
|
|
876
|
+
readonly database_close: (a: number) => number;
|
|
877
|
+
readonly database_started: (a: number) => number;
|
|
878
|
+
readonly database_authenticate: (a: number, b: number, c: number) => number;
|
|
879
|
+
readonly database_collections: (a: number, b: number) => void;
|
|
880
|
+
readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
|
|
874
881
|
readonly __wbg_operation_free: (a: number) => void;
|
|
875
882
|
readonly operation_collection: (a: number, b: number) => void;
|
|
876
883
|
readonly operation_opType: (a: number) => number;
|
|
@@ -879,20 +886,24 @@ interface InitOutput {
|
|
|
879
886
|
readonly operation_primaryKey: (a: number) => number;
|
|
880
887
|
readonly operation_primaryKeyIndex: (a: number, b: number) => void;
|
|
881
888
|
readonly __wbg_corestorage_free: (a: number) => void;
|
|
889
|
+
readonly __wbg_collection_free: (a: number) => void;
|
|
890
|
+
readonly collection_name: (a: number, b: number) => void;
|
|
891
|
+
readonly collection_schema: (a: number, b: number) => void;
|
|
892
|
+
readonly collection_find: (a: number, b: number, c: number) => number;
|
|
893
|
+
readonly collection_parse_query_options: (a: number, b: number, c: number) => void;
|
|
894
|
+
readonly collection_count: (a: number, b: number, c: number) => number;
|
|
895
|
+
readonly collection_findById: (a: number, b: number) => number;
|
|
896
|
+
readonly collection_update: (a: number, b: number) => number;
|
|
897
|
+
readonly collection_create: (a: number, b: number) => number;
|
|
898
|
+
readonly collection_delete: (a: number, b: number) => number;
|
|
899
|
+
readonly __wbg_basestorage_free: (a: number) => void;
|
|
900
|
+
readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
901
|
+
readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
|
|
902
|
+
readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
|
|
903
|
+
readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
|
|
904
|
+
readonly basestorage_core: (a: number, b: number) => void;
|
|
882
905
|
readonly main_js: () => void;
|
|
883
906
|
readonly is_debug_mode: () => number;
|
|
884
|
-
readonly __wbg_property_free: (a: number) => void;
|
|
885
|
-
readonly property_is_valid: (a: number, b: number) => void;
|
|
886
|
-
readonly property_type: (a: number) => number;
|
|
887
|
-
readonly property_items: (a: number, b: number) => void;
|
|
888
|
-
readonly property_maxItems: (a: number, b: number) => void;
|
|
889
|
-
readonly property_minItems: (a: number, b: number) => void;
|
|
890
|
-
readonly property_maxLength: (a: number, b: number) => void;
|
|
891
|
-
readonly property_minLength: (a: number, b: number) => void;
|
|
892
|
-
readonly property_properties: (a: number, b: number) => void;
|
|
893
|
-
readonly __wbgt_test_property_creation_0: (a: number) => void;
|
|
894
|
-
readonly __wbgt_test_property_validation_1: (a: number) => void;
|
|
895
|
-
readonly __wbgt_test_invalid_property_2: (a: number) => void;
|
|
896
907
|
readonly __wbg_query_free: (a: number) => void;
|
|
897
908
|
readonly query_new: (a: number, b: number, c: number) => void;
|
|
898
909
|
readonly query_query: (a: number, b: number) => void;
|
|
@@ -929,22 +940,19 @@ interface InitOutput {
|
|
|
929
940
|
readonly __wbgt_test_query_parse_eq_operator_wrong_type_32: (a: number) => void;
|
|
930
941
|
readonly __wbgt_test_query_parse_ne_operator_33: (a: number) => void;
|
|
931
942
|
readonly __wbgt_test_query_parse_ne_operator_wrong_type_34: (a: number) => void;
|
|
932
|
-
readonly
|
|
933
|
-
readonly
|
|
934
|
-
readonly
|
|
935
|
-
readonly
|
|
936
|
-
readonly
|
|
937
|
-
readonly
|
|
938
|
-
readonly
|
|
939
|
-
readonly
|
|
940
|
-
readonly
|
|
941
|
-
readonly
|
|
942
|
-
readonly
|
|
943
|
-
readonly
|
|
944
|
-
readonly
|
|
945
|
-
readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
|
|
946
|
-
readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
|
|
947
|
-
readonly basestorage_core: (a: number, b: number) => void;
|
|
943
|
+
readonly __wbg_schema_free: (a: number) => void;
|
|
944
|
+
readonly schema_validate: (a: number, b: number, c: number) => void;
|
|
945
|
+
readonly schema_is_valid: (a: number, b: number) => void;
|
|
946
|
+
readonly schema_create: (a: number, b: number) => void;
|
|
947
|
+
readonly schema_version: (a: number) => number;
|
|
948
|
+
readonly schema_primaryKey: (a: number, b: number) => void;
|
|
949
|
+
readonly schema_type: (a: number, b: number) => void;
|
|
950
|
+
readonly schema_indexes: (a: number, b: number) => void;
|
|
951
|
+
readonly schema_encrypted: (a: number, b: number) => void;
|
|
952
|
+
readonly schema_properties: (a: number, b: number) => void;
|
|
953
|
+
readonly __wbgt_test_schema_creation_3: (a: number) => void;
|
|
954
|
+
readonly __wbgt_test_schema_validation_4: (a: number) => void;
|
|
955
|
+
readonly __wbgt_test_invalid_schema_5: (a: number) => void;
|
|
948
956
|
readonly __wbg_baseplugin_free: (a: number) => void;
|
|
949
957
|
readonly baseplugin_new: (a: number, b: number, c: number) => void;
|
|
950
958
|
readonly baseplugin_name: (a: number) => number;
|
|
@@ -952,6 +960,14 @@ interface InitOutput {
|
|
|
952
960
|
readonly baseplugin_get_doc_recover_hook: (a: number) => number;
|
|
953
961
|
readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
|
|
954
962
|
readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
|
|
963
|
+
readonly __wbg_inmemory_free: (a: number) => void;
|
|
964
|
+
readonly inmemory_create: (a: number, b: number, c: number) => number;
|
|
965
|
+
readonly inmemory_write: (a: number, b: number) => number;
|
|
966
|
+
readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
967
|
+
readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
|
|
968
|
+
readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
969
|
+
readonly inmemory_close: (a: number) => number;
|
|
970
|
+
readonly inmemory_start: (a: number) => number;
|
|
955
971
|
readonly __wbg_ridberror_free: (a: number) => void;
|
|
956
972
|
readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
957
973
|
readonly ridberror_type: (a: number, b: number) => void;
|
|
@@ -974,37 +990,21 @@ interface InitOutput {
|
|
|
974
990
|
readonly indexdb_count: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
975
991
|
readonly indexdb_close: (a: number) => number;
|
|
976
992
|
readonly indexdb_start: (a: number) => number;
|
|
977
|
-
readonly __wbg_inmemory_free: (a: number) => void;
|
|
978
|
-
readonly inmemory_create: (a: number, b: number, c: number) => number;
|
|
979
|
-
readonly inmemory_write: (a: number, b: number) => number;
|
|
980
|
-
readonly inmemory_find: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
981
|
-
readonly inmemory_findDocumentById: (a: number, b: number, c: number, d: number) => number;
|
|
982
|
-
readonly inmemory_count: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
983
|
-
readonly inmemory_close: (a: number) => number;
|
|
984
|
-
readonly inmemory_start: (a: number) => number;
|
|
985
993
|
readonly __wbg_queryoptions_free: (a: number) => void;
|
|
986
994
|
readonly queryoptions_limit: (a: number, b: number) => void;
|
|
987
995
|
readonly queryoptions_offset: (a: number, b: number) => void;
|
|
988
|
-
readonly
|
|
989
|
-
readonly
|
|
990
|
-
readonly
|
|
991
|
-
readonly
|
|
992
|
-
readonly
|
|
993
|
-
readonly
|
|
994
|
-
readonly
|
|
995
|
-
readonly
|
|
996
|
-
readonly
|
|
997
|
-
readonly
|
|
998
|
-
readonly
|
|
999
|
-
readonly
|
|
1000
|
-
readonly __wbgt_test_invalid_schema_5: (a: number) => void;
|
|
1001
|
-
readonly __wbg_database_free: (a: number) => void;
|
|
1002
|
-
readonly database_start: (a: number) => number;
|
|
1003
|
-
readonly database_close: (a: number) => number;
|
|
1004
|
-
readonly database_started: (a: number) => number;
|
|
1005
|
-
readonly database_authenticate: (a: number, b: number, c: number) => number;
|
|
1006
|
-
readonly database_collections: (a: number, b: number) => void;
|
|
1007
|
-
readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
|
|
996
|
+
readonly __wbg_property_free: (a: number) => void;
|
|
997
|
+
readonly property_is_valid: (a: number, b: number) => void;
|
|
998
|
+
readonly property_type: (a: number) => number;
|
|
999
|
+
readonly property_items: (a: number, b: number) => void;
|
|
1000
|
+
readonly property_maxItems: (a: number, b: number) => void;
|
|
1001
|
+
readonly property_minItems: (a: number, b: number) => void;
|
|
1002
|
+
readonly property_maxLength: (a: number, b: number) => void;
|
|
1003
|
+
readonly property_minLength: (a: number, b: number) => void;
|
|
1004
|
+
readonly property_properties: (a: number, b: number) => void;
|
|
1005
|
+
readonly __wbgt_test_property_creation_0: (a: number) => void;
|
|
1006
|
+
readonly __wbgt_test_property_validation_1: (a: number) => void;
|
|
1007
|
+
readonly __wbgt_test_invalid_property_2: (a: number) => void;
|
|
1008
1008
|
readonly __wbg_wasmbindgentestcontext_free: (a: number) => void;
|
|
1009
1009
|
readonly wasmbindgentestcontext_new: () => number;
|
|
1010
1010
|
readonly wasmbindgentestcontext_args: (a: number, b: number, c: number) => void;
|
|
@@ -1017,16 +1017,16 @@ interface InitOutput {
|
|
|
1017
1017
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
1018
1018
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
1019
1019
|
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
1020
|
-
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h07337a613af73c1c: (a: number, b: number, c: number) => number;
|
|
1021
1020
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
1022
|
-
readonly
|
|
1023
|
-
readonly
|
|
1024
|
-
readonly
|
|
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__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hef4d0d64e714d731: (a: number, b: number, c: number) => number;
|
|
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;
|
|
1025
1025
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1026
1026
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
1027
|
-
readonly
|
|
1028
|
-
readonly
|
|
1029
|
-
readonly
|
|
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;
|
|
1030
1030
|
readonly __wbindgen_start: () => void;
|
|
1031
1031
|
}
|
|
1032
1032
|
|