@trust0/ridb-core 1.2.0 → 1.3.0-rc.1
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/package.json +1 -1
- package/pkg/ridb_core.d.ts +321 -306
- package/pkg/ridb_core.js +33 -33
- package/pkg/ridb_core_bg.wasm +0 -0
package/package.json
CHANGED
package/pkg/ridb_core.d.ts
CHANGED
|
@@ -63,18 +63,27 @@ export enum OpType {
|
|
|
63
63
|
COUNT = 4,
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export type Operators = {
|
|
66
|
+
export type Operators<T> = {
|
|
67
67
|
$gte?: number,
|
|
68
68
|
$gt?: number
|
|
69
69
|
$lt?: number,
|
|
70
|
-
$lte?: number
|
|
70
|
+
$lte?: number,
|
|
71
|
+
$eq?: T,
|
|
72
|
+
$ne?: T
|
|
71
73
|
};
|
|
74
|
+
|
|
72
75
|
export type InOperator<T> = { $in?: T[] };
|
|
73
|
-
export type
|
|
76
|
+
export type NInOperator<T> = { $nin?: T[] };
|
|
77
|
+
|
|
78
|
+
export type OperatorOrType<T> = T extends number ?
|
|
79
|
+
T | Operators<T> | InOperator<T> | NInOperator<T> :
|
|
80
|
+
T | InOperator<T> | NInOperator<T>;
|
|
81
|
+
|
|
74
82
|
export type LogicalOperators<T extends SchemaType> = {
|
|
75
83
|
$and?: Partial<QueryType<T>>[];
|
|
76
84
|
$or?: Partial<QueryType<T>>[];
|
|
77
85
|
};
|
|
86
|
+
|
|
78
87
|
export type QueryType<T extends SchemaType> = Partial<{
|
|
79
88
|
[K in keyof T['properties']]: OperatorOrType<
|
|
80
89
|
ExtractType<
|
|
@@ -82,167 +91,113 @@ export type QueryType<T extends SchemaType> = Partial<{
|
|
|
82
91
|
>
|
|
83
92
|
>
|
|
84
93
|
}> & LogicalOperators<T> | LogicalOperators<T>[];
|
|
94
|
+
|
|
85
95
|
export class Query<T extends SchemaType> {
|
|
86
96
|
constructor(query: QueryType<T>, schema:Schema<T>);
|
|
87
97
|
readonly query: QueryType<T>;
|
|
88
98
|
}
|
|
89
|
-
//test
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export type BaseStorageOptions = {
|
|
94
|
-
[name:string]:string | boolean | number
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
|
|
98
|
-
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
99
|
-
dbName: string,
|
|
100
|
-
schemas: SchemasCreate,
|
|
101
|
-
options?: BaseStorageOptions
|
|
102
|
-
): Promise<
|
|
103
|
-
BaseStorage<
|
|
104
|
-
SchemasCreate
|
|
105
|
-
>
|
|
106
|
-
>;
|
|
107
|
-
constructor(
|
|
108
|
-
dbName: string,
|
|
109
|
-
schemas: Schemas,
|
|
110
|
-
options?: BaseStorageOptions
|
|
111
|
-
);
|
|
112
|
-
readonly dbName: string;
|
|
113
|
-
readonly schemas: Record<keyof Schemas, Schema<Schemas[keyof Schemas]>>;
|
|
114
|
-
readonly options: BaseStorageOptions;
|
|
115
|
-
readonly core: CoreStorage;
|
|
116
|
-
start(): Promise<void>;
|
|
117
|
-
close(): Promise<void>;
|
|
118
|
-
count(colectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>): Promise<number>;
|
|
119
|
-
findDocumentById(collectionName: keyof Schemas, id: string): Promise<Doc<Schemas[keyof Schemas]> | null | undefined>;
|
|
120
|
-
find(collectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>[]>;
|
|
121
|
-
write(op: Operation<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>>;
|
|
122
|
-
getOption(name: string): string | boolean | number | undefined;
|
|
123
|
-
getSchema(name: string): Schema<any>;
|
|
124
|
-
//Call addIndexSchemas if you need extra indexing schemas for your database
|
|
125
|
-
addIndexSchemas(): null
|
|
126
|
-
}
|
|
127
99
|
|
|
128
100
|
|
|
129
101
|
|
|
130
102
|
/**
|
|
131
|
-
* Represents a
|
|
103
|
+
* Represents a database containing collections of documents.
|
|
104
|
+
* RIDB extends from this class and is used to expose collections.
|
|
105
|
+
*
|
|
106
|
+
* So if you specify:
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const db = new RIDB(
|
|
109
|
+
* {
|
|
110
|
+
* schemas: {
|
|
111
|
+
* demo: {
|
|
112
|
+
* version: 0,
|
|
113
|
+
* primaryKey: 'id',
|
|
114
|
+
* type: SchemaFieldType.object,
|
|
115
|
+
* properties: {
|
|
116
|
+
* id: {
|
|
117
|
+
* type: SchemaFieldType.string,
|
|
118
|
+
* maxLength: 60
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* } as const
|
|
123
|
+
* }
|
|
124
|
+
* )
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* 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.
|
|
128
|
+
*
|
|
129
|
+
* @template T - A record of schema types.
|
|
132
130
|
*/
|
|
133
|
-
export class
|
|
134
|
-
/**
|
|
135
|
-
* The type of the property.
|
|
136
|
-
*/
|
|
137
|
-
readonly type: string;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* The version of the property, if applicable.
|
|
141
|
-
*/
|
|
142
|
-
readonly version?: number;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* The primary key of the property, if applicable.
|
|
146
|
-
*/
|
|
147
|
-
readonly primaryKey?: string;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* An optional array of nested properties for array-type properties.
|
|
151
|
-
*/
|
|
152
|
-
readonly items?: Property;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* The maximum number of items for array-type properties, if applicable.
|
|
156
|
-
*/
|
|
157
|
-
readonly maxItems?: number;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* The minimum number of items for array-type properties, if applicable.
|
|
161
|
-
*/
|
|
162
|
-
readonly minItems?: number;
|
|
131
|
+
export class Database<T extends SchemaTypeRecord> {
|
|
163
132
|
|
|
164
133
|
/**
|
|
165
|
-
*
|
|
134
|
+
* Creates a new `Database` instance with the provided schemas and storage module.
|
|
135
|
+
*
|
|
136
|
+
* @template TS - A record of schema types.
|
|
137
|
+
* @param {TS} schemas - The schemas to use for the collections.
|
|
138
|
+
* @param migrations
|
|
139
|
+
* @param plugins
|
|
140
|
+
* @param options
|
|
141
|
+
* @param password
|
|
142
|
+
* @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
|
|
166
143
|
*/
|
|
167
|
-
|
|
144
|
+
static create<TS extends SchemaTypeRecord>(
|
|
145
|
+
db_name: string,
|
|
146
|
+
schemas: TS,
|
|
147
|
+
migrations: MigrationPathsForSchemas<TS> | MigrationPathsForSchema<TS[string]>,
|
|
148
|
+
plugins:Array<typeof BasePlugin>,
|
|
149
|
+
options: RIDBModule,
|
|
150
|
+
password?:string,
|
|
151
|
+
storage?: BaseStorage<TS>
|
|
152
|
+
): Promise<Database<TS>>;
|
|
168
153
|
|
|
169
154
|
/**
|
|
170
|
-
* The
|
|
155
|
+
* The collections in the database.
|
|
156
|
+
*
|
|
157
|
+
* This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
|
|
171
158
|
*/
|
|
172
|
-
readonly
|
|
159
|
+
readonly collections: {
|
|
160
|
+
[name in keyof T]: Collection<Schema<T[name]>>
|
|
161
|
+
}
|
|
173
162
|
|
|
174
|
-
|
|
175
|
-
* An optional array of required fields for object-type properties.
|
|
176
|
-
*/
|
|
177
|
-
readonly required?: boolean;
|
|
163
|
+
readonly started: boolean;
|
|
178
164
|
|
|
179
165
|
/**
|
|
180
|
-
*
|
|
166
|
+
* Starts the database.
|
|
167
|
+
*
|
|
168
|
+
* @returns {Promise<void>} A promise that resolves when the database is started.
|
|
181
169
|
*/
|
|
182
|
-
|
|
170
|
+
start(): Promise<void>;
|
|
183
171
|
|
|
184
172
|
/**
|
|
185
|
-
*
|
|
173
|
+
* Closes the database.
|
|
174
|
+
*
|
|
175
|
+
* @returns {Promise<void>} A promise that resolves when the database is closed.
|
|
186
176
|
*/
|
|
187
|
-
|
|
188
|
-
[name: string]: Property;
|
|
189
|
-
};
|
|
177
|
+
close(): Promise<void>;
|
|
190
178
|
}
|
|
191
179
|
|
|
192
|
-
|
|
193
|
-
|
|
194
180
|
/**
|
|
195
|
-
* Represents a
|
|
181
|
+
* Represents a function type for creating storage with the provided schema type records.
|
|
182
|
+
*
|
|
183
|
+
* @template T - The schema type record.
|
|
184
|
+
* @param {T} records - The schema type records.
|
|
185
|
+
* @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
|
|
196
186
|
*/
|
|
197
|
-
export type
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
export abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
|
|
202
|
-
constructor(
|
|
203
|
-
name: string,
|
|
204
|
-
schemas: Schemas
|
|
205
|
-
);
|
|
206
|
-
abstract start(): Promise<void>;
|
|
207
|
-
abstract close(): Promise<void>;
|
|
208
|
-
abstract count(
|
|
209
|
-
colectionName: keyof Schemas,
|
|
210
|
-
query: QueryType<Schemas[keyof Schemas]>
|
|
211
|
-
): Promise<number>;
|
|
212
|
-
abstract findDocumentById(
|
|
213
|
-
collectionName: keyof Schemas,
|
|
214
|
-
id: string
|
|
215
|
-
): Promise<Doc<Schemas[keyof Schemas]> | undefined | null>;
|
|
216
|
-
abstract find(
|
|
217
|
-
collectionName: keyof Schemas,
|
|
218
|
-
query: QueryType<Schemas[keyof Schemas]>
|
|
219
|
-
): Promise<Doc<Schemas[keyof Schemas]>[]>;
|
|
220
|
-
abstract write(
|
|
221
|
-
op: Operation<Schemas[keyof Schemas]>
|
|
222
|
-
): Promise<Doc<Schemas[keyof Schemas]>>;
|
|
223
|
-
}
|
|
224
|
-
|
|
187
|
+
export type CreateStorage = <T extends SchemaTypeRecord>(
|
|
188
|
+
records: T
|
|
189
|
+
) => Promise<BaseStorage<T>>;
|
|
225
190
|
|
|
226
191
|
/**
|
|
227
|
-
* Represents
|
|
228
|
-
*
|
|
229
|
-
* @template T - The schema type.
|
|
192
|
+
* Represents a storage module with a method for creating storage.
|
|
230
193
|
*/
|
|
231
|
-
export
|
|
194
|
+
export type RIDBModule = {
|
|
195
|
+
|
|
232
196
|
/**
|
|
233
|
-
*
|
|
197
|
+
* Plugin constructors array
|
|
234
198
|
*/
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
238
|
-
dbName: string,
|
|
239
|
-
schemas: SchemasCreate,
|
|
240
|
-
): Promise<
|
|
241
|
-
IndexDB<
|
|
242
|
-
SchemasCreate
|
|
243
|
-
>
|
|
244
|
-
>;
|
|
245
|
-
}
|
|
199
|
+
apply: (plugins:Array<typeof BasePlugin>) => Array<BasePlugin>;
|
|
200
|
+
};
|
|
246
201
|
|
|
247
202
|
|
|
248
203
|
|
|
@@ -354,29 +309,6 @@ export class Schema<T extends SchemaType> {
|
|
|
354
309
|
|
|
355
310
|
|
|
356
311
|
|
|
357
|
-
/**
|
|
358
|
-
* Represents an in-memory storage system extending the base storage functionality.
|
|
359
|
-
*
|
|
360
|
-
* @template T - The schema type.
|
|
361
|
-
*/
|
|
362
|
-
export class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
|
|
363
|
-
/**
|
|
364
|
-
* Frees the resources used by the in-memory storage.
|
|
365
|
-
*/
|
|
366
|
-
free(): void;
|
|
367
|
-
|
|
368
|
-
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
369
|
-
dbName: string,
|
|
370
|
-
schemas: SchemasCreate,
|
|
371
|
-
): Promise<
|
|
372
|
-
InMemory<
|
|
373
|
-
SchemasCreate
|
|
374
|
-
>
|
|
375
|
-
>;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
312
|
export type EnumerateUpTo<
|
|
381
313
|
N extends number,
|
|
382
314
|
Acc extends number[] = []
|
|
@@ -443,105 +375,153 @@ export class BasePlugin implements BasePluginOptions {
|
|
|
443
375
|
|
|
444
376
|
|
|
445
377
|
|
|
378
|
+
export class CoreStorage {
|
|
379
|
+
/**
|
|
380
|
+
* @param {any} document
|
|
381
|
+
* @param {Query} query
|
|
382
|
+
* @returns {boolean}
|
|
383
|
+
*/
|
|
384
|
+
matchesQuery(document: any, query: Query<any>): boolean;
|
|
385
|
+
getPrimaryKeyTyped(value: any): string | number;
|
|
386
|
+
getIndexes(schema: Schema<any>, op: Operation): string[];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
446
391
|
/**
|
|
447
|
-
* Represents
|
|
448
|
-
* RIDB extends from this class and is used to expose collections.
|
|
449
|
-
*
|
|
450
|
-
* So if you specify:
|
|
451
|
-
* ```typescript
|
|
452
|
-
* const db = new RIDB(
|
|
453
|
-
* {
|
|
454
|
-
* schemas: {
|
|
455
|
-
* demo: {
|
|
456
|
-
* version: 0,
|
|
457
|
-
* primaryKey: 'id',
|
|
458
|
-
* type: SchemaFieldType.object,
|
|
459
|
-
* properties: {
|
|
460
|
-
* id: {
|
|
461
|
-
* type: SchemaFieldType.string,
|
|
462
|
-
* maxLength: 60
|
|
463
|
-
* }
|
|
464
|
-
* }
|
|
465
|
-
* }
|
|
466
|
-
* } as const
|
|
467
|
-
* }
|
|
468
|
-
* )
|
|
469
|
-
* ```
|
|
470
|
-
*
|
|
471
|
-
* 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.
|
|
392
|
+
* Represents an operation to be performed on a collection.
|
|
472
393
|
*
|
|
473
|
-
* @template T -
|
|
394
|
+
* @template T - The schema type of the collection.
|
|
474
395
|
*/
|
|
475
|
-
export
|
|
396
|
+
export type Operation<T extends SchemaType> = {
|
|
397
|
+
/**
|
|
398
|
+
* The name of the collection on which the operation will be performed.
|
|
399
|
+
*/
|
|
400
|
+
collection: string,
|
|
476
401
|
|
|
477
402
|
/**
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* @template TS - A record of schema types.
|
|
481
|
-
* @param {TS} schemas - The schemas to use for the collections.
|
|
482
|
-
* @param migrations
|
|
483
|
-
* @param plugins
|
|
484
|
-
* @param options
|
|
485
|
-
* @param password
|
|
486
|
-
* @returns {Promise<Database<TS>>} A promise that resolves to the created `Database` instance.
|
|
403
|
+
* The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
|
|
487
404
|
*/
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
405
|
+
opType: OpType,
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* The data involved in the operation, conforming to the schema type.
|
|
409
|
+
*/
|
|
410
|
+
data: Doc<T>,
|
|
411
|
+
|
|
412
|
+
primaryKeyField?: string,
|
|
413
|
+
primaryKey?: string
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Represents a property within a schema, including various constraints and nested properties.
|
|
420
|
+
*/
|
|
421
|
+
export class Property {
|
|
422
|
+
/**
|
|
423
|
+
* The type of the property.
|
|
424
|
+
*/
|
|
425
|
+
readonly type: string;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The version of the property, if applicable.
|
|
429
|
+
*/
|
|
430
|
+
readonly version?: number;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* The primary key of the property, if applicable.
|
|
434
|
+
*/
|
|
435
|
+
readonly primaryKey?: string;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* An optional array of nested properties for array-type properties.
|
|
439
|
+
*/
|
|
440
|
+
readonly items?: Property;
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* The maximum number of items for array-type properties, if applicable.
|
|
444
|
+
*/
|
|
445
|
+
readonly maxItems?: number;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* The minimum number of items for array-type properties, if applicable.
|
|
449
|
+
*/
|
|
450
|
+
readonly minItems?: number;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* The maximum length for string-type properties, if applicable.
|
|
454
|
+
*/
|
|
455
|
+
readonly maxLength?: number;
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* The minimum length for string-type properties, if applicable.
|
|
459
|
+
*/
|
|
460
|
+
readonly minLength?: number;
|
|
497
461
|
|
|
498
462
|
/**
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
* This is a read-only property where the key is the name of the collection and the value is a `Collection` instance.
|
|
463
|
+
* An optional array of required fields for object-type properties.
|
|
502
464
|
*/
|
|
503
|
-
readonly
|
|
504
|
-
[name in keyof T]: Collection<Schema<T[name]>>
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
readonly started: boolean;
|
|
465
|
+
readonly required?: boolean;
|
|
508
466
|
|
|
509
467
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
* @returns {Promise<void>} A promise that resolves when the database is started.
|
|
468
|
+
* An optional default value for the property.
|
|
513
469
|
*/
|
|
514
|
-
|
|
470
|
+
readonly default?: any;
|
|
515
471
|
|
|
516
472
|
/**
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
* @returns {Promise<void>} A promise that resolves when the database is closed.
|
|
473
|
+
* An optional map of nested properties for object-type properties.
|
|
520
474
|
*/
|
|
521
|
-
|
|
475
|
+
readonly properties?: {
|
|
476
|
+
[name: string]: Property;
|
|
477
|
+
};
|
|
522
478
|
}
|
|
523
479
|
|
|
480
|
+
|
|
481
|
+
|
|
524
482
|
/**
|
|
525
|
-
* Represents
|
|
483
|
+
* Represents an IndexDB storage system extending the base storage functionality.
|
|
526
484
|
*
|
|
527
|
-
* @template T - The schema type
|
|
528
|
-
* @param {T} records - The schema type records.
|
|
529
|
-
* @returns {Promise<InternalsRecord>} A promise that resolves to the created internals record.
|
|
485
|
+
* @template T - The schema type.
|
|
530
486
|
*/
|
|
531
|
-
export
|
|
532
|
-
|
|
533
|
-
|
|
487
|
+
export class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
|
|
488
|
+
/**
|
|
489
|
+
* Frees the resources used by the in-memory storage.
|
|
490
|
+
*/
|
|
491
|
+
free(): void;
|
|
492
|
+
|
|
493
|
+
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
494
|
+
dbName: string,
|
|
495
|
+
schemas: SchemasCreate,
|
|
496
|
+
): Promise<
|
|
497
|
+
IndexDB<
|
|
498
|
+
SchemasCreate
|
|
499
|
+
>
|
|
500
|
+
>;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
|
|
534
504
|
|
|
535
505
|
/**
|
|
536
|
-
* Represents
|
|
506
|
+
* Represents an in-memory storage system extending the base storage functionality.
|
|
507
|
+
*
|
|
508
|
+
* @template T - The schema type.
|
|
537
509
|
*/
|
|
538
|
-
export
|
|
539
|
-
|
|
510
|
+
export class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
|
|
540
511
|
/**
|
|
541
|
-
*
|
|
512
|
+
* Frees the resources used by the in-memory storage.
|
|
542
513
|
*/
|
|
543
|
-
|
|
544
|
-
|
|
514
|
+
free(): void;
|
|
515
|
+
|
|
516
|
+
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
517
|
+
dbName: string,
|
|
518
|
+
schemas: SchemasCreate,
|
|
519
|
+
): Promise<
|
|
520
|
+
InMemory<
|
|
521
|
+
SchemasCreate
|
|
522
|
+
>
|
|
523
|
+
>;
|
|
524
|
+
}
|
|
545
525
|
|
|
546
526
|
|
|
547
527
|
|
|
@@ -639,45 +619,74 @@ export class Collection<T extends SchemaType> {
|
|
|
639
619
|
|
|
640
620
|
|
|
641
621
|
|
|
642
|
-
export
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
622
|
+
export type BaseStorageOptions = {
|
|
623
|
+
[name:string]:string | boolean | number
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageInternal<Schemas> {
|
|
627
|
+
static create<SchemasCreate extends SchemaTypeRecord>(
|
|
628
|
+
dbName: string,
|
|
629
|
+
schemas: SchemasCreate,
|
|
630
|
+
options?: BaseStorageOptions
|
|
631
|
+
): Promise<
|
|
632
|
+
BaseStorage<
|
|
633
|
+
SchemasCreate
|
|
634
|
+
>
|
|
635
|
+
>;
|
|
636
|
+
constructor(
|
|
637
|
+
dbName: string,
|
|
638
|
+
schemas: Schemas,
|
|
639
|
+
options?: BaseStorageOptions
|
|
640
|
+
);
|
|
641
|
+
readonly dbName: string;
|
|
642
|
+
readonly schemas: Record<keyof Schemas, Schema<Schemas[keyof Schemas]>>;
|
|
643
|
+
readonly options: BaseStorageOptions;
|
|
644
|
+
readonly core: CoreStorage;
|
|
645
|
+
start(): Promise<void>;
|
|
646
|
+
close(): Promise<void>;
|
|
647
|
+
count(colectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>): Promise<number>;
|
|
648
|
+
findDocumentById(collectionName: keyof Schemas, id: string): Promise<Doc<Schemas[keyof Schemas]> | null | undefined>;
|
|
649
|
+
find(collectionName: keyof Schemas, query: QueryType<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>[]>;
|
|
650
|
+
write(op: Operation<Schemas[keyof Schemas]>): Promise<Doc<Schemas[keyof Schemas]>>;
|
|
651
|
+
getOption(name: string): string | boolean | number | undefined;
|
|
652
|
+
getSchema(name: string): Schema<any>;
|
|
653
|
+
//Call addIndexSchemas if you need extra indexing schemas for your database
|
|
654
|
+
addIndexSchemas(): null
|
|
651
655
|
}
|
|
652
656
|
|
|
653
657
|
|
|
654
658
|
|
|
655
659
|
/**
|
|
656
|
-
* Represents
|
|
657
|
-
*
|
|
658
|
-
* @template T - The schema type of the collection.
|
|
660
|
+
* Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
|
|
659
661
|
*/
|
|
660
|
-
export type
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
*/
|
|
664
|
-
collection: string,
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
|
|
668
|
-
*/
|
|
669
|
-
opType: OpType,
|
|
670
|
-
|
|
671
|
-
/**
|
|
672
|
-
* The data involved in the operation, conforming to the schema type.
|
|
673
|
-
*/
|
|
674
|
-
data: Doc<T>,
|
|
662
|
+
export type SchemaTypeRecord = {
|
|
663
|
+
[name: string]: SchemaType
|
|
664
|
+
};
|
|
675
665
|
|
|
676
|
-
|
|
677
|
-
|
|
666
|
+
export abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
|
|
667
|
+
constructor(
|
|
668
|
+
name: string,
|
|
669
|
+
schemas: Schemas
|
|
670
|
+
);
|
|
671
|
+
abstract start(): Promise<void>;
|
|
672
|
+
abstract close(): Promise<void>;
|
|
673
|
+
abstract count(
|
|
674
|
+
colectionName: keyof Schemas,
|
|
675
|
+
query: QueryType<Schemas[keyof Schemas]>
|
|
676
|
+
): Promise<number>;
|
|
677
|
+
abstract findDocumentById(
|
|
678
|
+
collectionName: keyof Schemas,
|
|
679
|
+
id: string
|
|
680
|
+
): Promise<Doc<Schemas[keyof Schemas]> | undefined | null>;
|
|
681
|
+
abstract find(
|
|
682
|
+
collectionName: keyof Schemas,
|
|
683
|
+
query: QueryType<Schemas[keyof Schemas]>
|
|
684
|
+
): Promise<Doc<Schemas[keyof Schemas]>[]>;
|
|
685
|
+
abstract write(
|
|
686
|
+
op: Operation<Schemas[keyof Schemas]>
|
|
687
|
+
): Promise<Doc<Schemas[keyof Schemas]>>;
|
|
678
688
|
}
|
|
679
689
|
|
|
680
|
-
|
|
681
690
|
/**
|
|
682
691
|
* Runtime test harness support instantiated in JS.
|
|
683
692
|
*
|
|
@@ -750,12 +759,52 @@ export interface InitOutput {
|
|
|
750
759
|
readonly __wbgt_test_query_parse_multiple_operators_26: (a: number) => void;
|
|
751
760
|
readonly __wbgt_test_query_parse_invalid_in_operator_27: (a: number) => void;
|
|
752
761
|
readonly __wbgt_test_query_parse_empty_logical_operators_28: (a: number) => void;
|
|
753
|
-
readonly
|
|
754
|
-
readonly
|
|
755
|
-
readonly
|
|
756
|
-
readonly
|
|
757
|
-
readonly
|
|
758
|
-
readonly
|
|
762
|
+
readonly __wbgt_test_query_parse_nin_operator_29: (a: number) => void;
|
|
763
|
+
readonly __wbgt_test_query_parse_nin_operator_wrong_type_30: (a: number) => void;
|
|
764
|
+
readonly __wbgt_test_query_parse_eq_operator_31: (a: number) => void;
|
|
765
|
+
readonly __wbgt_test_query_parse_eq_operator_wrong_type_32: (a: number) => void;
|
|
766
|
+
readonly __wbgt_test_query_parse_ne_operator_33: (a: number) => void;
|
|
767
|
+
readonly __wbgt_test_query_parse_ne_operator_wrong_type_34: (a: number) => void;
|
|
768
|
+
readonly __wbg_database_free: (a: number) => void;
|
|
769
|
+
readonly database_start: (a: number) => number;
|
|
770
|
+
readonly database_close: (a: number) => number;
|
|
771
|
+
readonly database_started: (a: number) => number;
|
|
772
|
+
readonly database_collections: (a: number, b: number) => void;
|
|
773
|
+
readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
|
|
774
|
+
readonly __wbg_schema_free: (a: number) => void;
|
|
775
|
+
readonly schema_validate: (a: number, b: number, c: number) => void;
|
|
776
|
+
readonly schema_is_valid: (a: number, b: number) => void;
|
|
777
|
+
readonly schema_create: (a: number, b: number) => void;
|
|
778
|
+
readonly schema_version: (a: number) => number;
|
|
779
|
+
readonly schema_primaryKey: (a: number, b: number) => void;
|
|
780
|
+
readonly schema_type: (a: number, b: number) => void;
|
|
781
|
+
readonly schema_indexes: (a: number, b: number) => void;
|
|
782
|
+
readonly schema_encrypted: (a: number, b: number) => void;
|
|
783
|
+
readonly schema_properties: (a: number, b: number) => void;
|
|
784
|
+
readonly __wbgt_test_schema_creation_3: (a: number) => void;
|
|
785
|
+
readonly __wbgt_test_schema_validation_4: (a: number) => void;
|
|
786
|
+
readonly __wbgt_test_invalid_schema_5: (a: number) => void;
|
|
787
|
+
readonly __wbg_baseplugin_free: (a: number) => void;
|
|
788
|
+
readonly baseplugin_new: (a: number, b: number, c: number) => void;
|
|
789
|
+
readonly baseplugin_name: (a: number) => number;
|
|
790
|
+
readonly baseplugin_get_doc_create_hook: (a: number) => number;
|
|
791
|
+
readonly baseplugin_get_doc_recover_hook: (a: number) => number;
|
|
792
|
+
readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
|
|
793
|
+
readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
|
|
794
|
+
readonly corestorage_new: () => number;
|
|
795
|
+
readonly corestorage_getPrimaryKeyTyped: (a: number, b: number, c: number) => void;
|
|
796
|
+
readonly corestorage_getIndexes: (a: number, b: number, c: number, d: number) => void;
|
|
797
|
+
readonly corestorage_matchesQuery: (a: number, b: number, c: number, d: number) => void;
|
|
798
|
+
readonly __wbg_operation_free: (a: number) => void;
|
|
799
|
+
readonly operation_collection: (a: number, b: number) => void;
|
|
800
|
+
readonly operation_opType: (a: number) => number;
|
|
801
|
+
readonly operation_data: (a: number) => number;
|
|
802
|
+
readonly operation_primaryKeyField: (a: number) => number;
|
|
803
|
+
readonly operation_primaryKey: (a: number) => number;
|
|
804
|
+
readonly operation_primaryKeyIndex: (a: number, b: number) => void;
|
|
805
|
+
readonly main_js: () => void;
|
|
806
|
+
readonly is_debug_mode: () => number;
|
|
807
|
+
readonly __wbg_corestorage_free: (a: number) => void;
|
|
759
808
|
readonly __wbg_property_free: (a: number) => void;
|
|
760
809
|
readonly property_is_valid: (a: number, b: number) => void;
|
|
761
810
|
readonly property_type: (a: number) => number;
|
|
@@ -778,19 +827,6 @@ export interface InitOutput {
|
|
|
778
827
|
readonly indexdb_count: (a: number, b: number, c: number, d: number) => number;
|
|
779
828
|
readonly indexdb_close: (a: number) => number;
|
|
780
829
|
readonly indexdb_start: (a: number) => number;
|
|
781
|
-
readonly __wbg_schema_free: (a: number) => void;
|
|
782
|
-
readonly schema_validate: (a: number, b: number, c: number) => void;
|
|
783
|
-
readonly schema_is_valid: (a: number, b: number) => void;
|
|
784
|
-
readonly schema_create: (a: number, b: number) => void;
|
|
785
|
-
readonly schema_version: (a: number) => number;
|
|
786
|
-
readonly schema_primaryKey: (a: number, b: number) => void;
|
|
787
|
-
readonly schema_type: (a: number, b: number) => void;
|
|
788
|
-
readonly schema_indexes: (a: number, b: number) => void;
|
|
789
|
-
readonly schema_encrypted: (a: number, b: number) => void;
|
|
790
|
-
readonly schema_properties: (a: number, b: number) => void;
|
|
791
|
-
readonly __wbgt_test_schema_creation_3: (a: number) => void;
|
|
792
|
-
readonly __wbgt_test_schema_validation_4: (a: number) => void;
|
|
793
|
-
readonly __wbgt_test_invalid_schema_5: (a: number) => void;
|
|
794
830
|
readonly __wbg_inmemory_free: (a: number) => void;
|
|
795
831
|
readonly inmemory_create: (a: number, b: number, c: number) => number;
|
|
796
832
|
readonly inmemory_write: (a: number, b: number) => number;
|
|
@@ -799,19 +835,6 @@ export interface InitOutput {
|
|
|
799
835
|
readonly inmemory_count: (a: number, b: number, c: number, d: number) => number;
|
|
800
836
|
readonly inmemory_close: (a: number) => number;
|
|
801
837
|
readonly inmemory_start: (a: number) => number;
|
|
802
|
-
readonly __wbg_baseplugin_free: (a: number) => void;
|
|
803
|
-
readonly baseplugin_new: (a: number, b: number, c: number) => void;
|
|
804
|
-
readonly baseplugin_name: (a: number) => number;
|
|
805
|
-
readonly baseplugin_get_doc_create_hook: (a: number) => number;
|
|
806
|
-
readonly baseplugin_get_doc_recover_hook: (a: number) => number;
|
|
807
|
-
readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
|
|
808
|
-
readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
|
|
809
|
-
readonly __wbg_database_free: (a: number) => void;
|
|
810
|
-
readonly database_start: (a: number) => number;
|
|
811
|
-
readonly database_close: (a: number) => number;
|
|
812
|
-
readonly database_started: (a: number) => number;
|
|
813
|
-
readonly database_collections: (a: number, b: number) => void;
|
|
814
|
-
readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
|
|
815
838
|
readonly __wbg_collection_free: (a: number) => void;
|
|
816
839
|
readonly collection_name: (a: number, b: number) => void;
|
|
817
840
|
readonly collection_schema: (a: number, b: number) => void;
|
|
@@ -821,20 +844,12 @@ export interface InitOutput {
|
|
|
821
844
|
readonly collection_update: (a: number, b: number) => number;
|
|
822
845
|
readonly collection_create: (a: number, b: number) => number;
|
|
823
846
|
readonly collection_delete: (a: number, b: number) => number;
|
|
824
|
-
readonly
|
|
825
|
-
readonly
|
|
826
|
-
readonly
|
|
827
|
-
readonly
|
|
828
|
-
readonly
|
|
829
|
-
readonly
|
|
830
|
-
readonly operation_opType: (a: number) => number;
|
|
831
|
-
readonly operation_data: (a: number) => number;
|
|
832
|
-
readonly operation_primaryKeyField: (a: number) => number;
|
|
833
|
-
readonly operation_primaryKey: (a: number) => number;
|
|
834
|
-
readonly operation_primaryKeyIndex: (a: number, b: number) => void;
|
|
835
|
-
readonly __wbg_corestorage_free: (a: number) => void;
|
|
836
|
-
readonly main_js: () => void;
|
|
837
|
-
readonly is_debug_mode: () => number;
|
|
847
|
+
readonly __wbg_basestorage_free: (a: number) => void;
|
|
848
|
+
readonly basestorage_new: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
849
|
+
readonly basestorage_addIndexSchemas: (a: number, b: number) => void;
|
|
850
|
+
readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
|
|
851
|
+
readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
|
|
852
|
+
readonly basestorage_core: (a: number, b: number) => void;
|
|
838
853
|
readonly __wbg_wasmbindgentestcontext_free: (a: number) => void;
|
|
839
854
|
readonly wasmbindgentestcontext_new: () => number;
|
|
840
855
|
readonly wasmbindgentestcontext_args: (a: number, b: number, c: number) => void;
|
package/pkg/ridb_core.js
CHANGED
|
@@ -314,14 +314,6 @@ function addBorrowedObject(obj) {
|
|
|
314
314
|
return stack_pointer;
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
-
function handleError(f, args) {
|
|
318
|
-
try {
|
|
319
|
-
return f.apply(this, args);
|
|
320
|
-
} catch (e) {
|
|
321
|
-
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
317
|
function passArrayJsValueToWasm0(array, malloc) {
|
|
326
318
|
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
327
319
|
const mem = getUint32Memory0();
|
|
@@ -331,6 +323,14 @@ function passArrayJsValueToWasm0(array, malloc) {
|
|
|
331
323
|
WASM_VECTOR_LEN = array.length;
|
|
332
324
|
return ptr;
|
|
333
325
|
}
|
|
326
|
+
|
|
327
|
+
function handleError(f, args) {
|
|
328
|
+
try {
|
|
329
|
+
return f.apply(this, args);
|
|
330
|
+
} catch (e) {
|
|
331
|
+
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
334
|
/**
|
|
335
335
|
*/
|
|
336
336
|
export function main_js() {
|
|
@@ -2094,10 +2094,6 @@ function __wbg_get_imports() {
|
|
|
2094
2094
|
const ret = getObject(arg0).write(Operation.__wrap(arg1));
|
|
2095
2095
|
return addHeapObject(ret);
|
|
2096
2096
|
}, arguments) };
|
|
2097
|
-
imports.wbg.__wbg_collection_new = function(arg0) {
|
|
2098
|
-
const ret = Collection.__wrap(arg0);
|
|
2099
|
-
return addHeapObject(ret);
|
|
2100
|
-
};
|
|
2101
2097
|
imports.wbg.__wbindgen_is_array = function(arg0) {
|
|
2102
2098
|
const ret = Array.isArray(getObject(arg0));
|
|
2103
2099
|
return ret;
|
|
@@ -2115,18 +2111,27 @@ function __wbg_get_imports() {
|
|
|
2115
2111
|
const ret = !getObject(arg0);
|
|
2116
2112
|
return ret;
|
|
2117
2113
|
};
|
|
2118
|
-
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
2119
|
-
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
2120
|
-
return addHeapObject(ret);
|
|
2121
|
-
};
|
|
2122
2114
|
imports.wbg.__wbindgen_is_function = function(arg0) {
|
|
2123
2115
|
const ret = typeof(getObject(arg0)) === 'function';
|
|
2124
2116
|
return ret;
|
|
2125
2117
|
};
|
|
2118
|
+
imports.wbg.__wbg_collection_new = function(arg0) {
|
|
2119
|
+
const ret = Collection.__wrap(arg0);
|
|
2120
|
+
return addHeapObject(ret);
|
|
2121
|
+
};
|
|
2122
|
+
imports.wbg.__wbindgen_boolean_get = function(arg0) {
|
|
2123
|
+
const v = getObject(arg0);
|
|
2124
|
+
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
|
|
2125
|
+
return ret;
|
|
2126
|
+
};
|
|
2126
2127
|
imports.wbg.__wbindgen_is_bigint = function(arg0) {
|
|
2127
2128
|
const ret = typeof(getObject(arg0)) === 'bigint';
|
|
2128
2129
|
return ret;
|
|
2129
2130
|
};
|
|
2131
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
2132
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
2133
|
+
return addHeapObject(ret);
|
|
2134
|
+
};
|
|
2130
2135
|
imports.wbg.__wbindgen_cb_drop = function(arg0) {
|
|
2131
2136
|
const obj = takeObject(arg0).original;
|
|
2132
2137
|
if (obj.cnt-- == 1) {
|
|
@@ -2136,9 +2141,8 @@ function __wbg_get_imports() {
|
|
|
2136
2141
|
const ret = false;
|
|
2137
2142
|
return ret;
|
|
2138
2143
|
};
|
|
2139
|
-
imports.wbg.
|
|
2140
|
-
const
|
|
2141
|
-
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
|
|
2144
|
+
imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
|
|
2145
|
+
const ret = getObject(arg0) === getObject(arg1);
|
|
2142
2146
|
return ret;
|
|
2143
2147
|
};
|
|
2144
2148
|
imports.wbg.__wbindgen_in = function(arg0, arg1) {
|
|
@@ -2149,10 +2153,6 @@ function __wbg_get_imports() {
|
|
|
2149
2153
|
const ret = arg0;
|
|
2150
2154
|
return addHeapObject(ret);
|
|
2151
2155
|
};
|
|
2152
|
-
imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
|
|
2153
|
-
const ret = getObject(arg0) === getObject(arg1);
|
|
2154
|
-
return ret;
|
|
2155
|
-
};
|
|
2156
2156
|
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
2157
2157
|
const ret = BigInt.asUintN(64, arg0);
|
|
2158
2158
|
return addHeapObject(ret);
|
|
@@ -2736,24 +2736,24 @@ function __wbg_get_imports() {
|
|
|
2736
2736
|
const ret = wasm.memory;
|
|
2737
2737
|
return addHeapObject(ret);
|
|
2738
2738
|
};
|
|
2739
|
-
imports.wbg.
|
|
2740
|
-
const ret = makeClosure(arg0, arg1,
|
|
2739
|
+
imports.wbg.__wbindgen_closure_wrapper744 = function(arg0, arg1, arg2) {
|
|
2740
|
+
const ret = makeClosure(arg0, arg1, 270, __wbg_adapter_56);
|
|
2741
2741
|
return addHeapObject(ret);
|
|
2742
2742
|
};
|
|
2743
|
-
imports.wbg.
|
|
2744
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2743
|
+
imports.wbg.__wbindgen_closure_wrapper746 = function(arg0, arg1, arg2) {
|
|
2744
|
+
const ret = makeMutClosure(arg0, arg1, 270, __wbg_adapter_59);
|
|
2745
2745
|
return addHeapObject(ret);
|
|
2746
2746
|
};
|
|
2747
|
-
imports.wbg.
|
|
2748
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2747
|
+
imports.wbg.__wbindgen_closure_wrapper748 = function(arg0, arg1, arg2) {
|
|
2748
|
+
const ret = makeMutClosure(arg0, arg1, 270, __wbg_adapter_59);
|
|
2749
2749
|
return addHeapObject(ret);
|
|
2750
2750
|
};
|
|
2751
|
-
imports.wbg.
|
|
2752
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2751
|
+
imports.wbg.__wbindgen_closure_wrapper750 = function(arg0, arg1, arg2) {
|
|
2752
|
+
const ret = makeMutClosure(arg0, arg1, 270, __wbg_adapter_64);
|
|
2753
2753
|
return addHeapObject(ret);
|
|
2754
2754
|
};
|
|
2755
|
-
imports.wbg.
|
|
2756
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2755
|
+
imports.wbg.__wbindgen_closure_wrapper1548 = function(arg0, arg1, arg2) {
|
|
2756
|
+
const ret = makeMutClosure(arg0, arg1, 440, __wbg_adapter_67);
|
|
2757
2757
|
return addHeapObject(ret);
|
|
2758
2758
|
};
|
|
2759
2759
|
|
package/pkg/ridb_core_bg.wasm
CHANGED
|
Binary file
|