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