@trust0/ridb-core 1.4.3 → 1.5.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 CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "1.4.3",
8
+ "version": "1.5.0-rc.1",
9
9
  "main": "./pkg/ridb_core.js",
10
10
  "types": "./pkg/ridb_core.d.ts",
11
11
  "sideEffects": [
@@ -186,70 +186,6 @@ export class BaseStorage<Schemas extends SchemaTypeRecord> extends StorageIntern
186
186
 
187
187
 
188
188
 
189
- /**
190
- * Represents an in-memory storage system extending the base storage functionality.
191
- *
192
- * @template T - The schema type.
193
- */
194
- export class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
195
- /**
196
- * Frees the resources used by the in-memory storage.
197
- */
198
- free(): void;
199
-
200
- static create<SchemasCreate extends SchemaTypeRecord>(
201
- dbName: string,
202
- schemas: SchemasCreate,
203
- ): Promise<
204
- InMemory<
205
- SchemasCreate
206
- >
207
- >;
208
- }
209
-
210
-
211
-
212
- /**
213
- * Represents an IndexDB storage system extending the base storage functionality.
214
- *
215
- * @template T - The schema type.
216
- */
217
- export class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
218
- /**
219
- * Frees the resources used by the in-memory storage.
220
- */
221
- free(): void;
222
-
223
- static create<SchemasCreate extends SchemaTypeRecord>(
224
- dbName: string,
225
- schemas: SchemasCreate,
226
- ): Promise<
227
- IndexDB<
228
- SchemasCreate
229
- >
230
- >;
231
- }
232
-
233
-
234
-
235
- type Hook = (
236
- schema: Schema<SchemaType>,
237
- migration: MigrationPathsForSchema<SchemaType>,
238
- doc: Doc<SchemaType>
239
- ) => Doc<SchemaType>
240
-
241
- type BasePluginOptions = {
242
- docCreateHook?: Hook,
243
- docRecoverHook?: Hook
244
- }
245
-
246
- export class BasePlugin implements BasePluginOptions {
247
- docCreateHook?:Hook;
248
- docRecoverHook?:Hook;
249
- }
250
-
251
-
252
-
253
189
  /**
254
190
  * Represents a database containing collections of documents.
255
191
  * RIDB extends from this class and is used to expose collections.
@@ -302,6 +238,8 @@ export class Database<T extends SchemaTypeRecord> {
302
238
  storage?: BaseStorage<TS>
303
239
  ): Promise<Database<TS>>;
304
240
 
241
+ authenticate(password: string): Promise<boolean>;
242
+
305
243
  /**
306
244
  * The collections in the database.
307
245
  *
@@ -353,38 +291,68 @@ export type RIDBModule = {
353
291
 
354
292
 
355
293
  /**
356
- * Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
294
+ * Represents an in-memory storage system extending the base storage functionality.
295
+ *
296
+ * @template T - The schema type.
357
297
  */
358
- export type SchemaTypeRecord = {
359
- [name: string]: SchemaType
360
- };
298
+ export class InMemory<T extends SchemaTypeRecord> extends BaseStorage<T> {
299
+ /**
300
+ * Frees the resources used by the in-memory storage.
301
+ */
302
+ free(): void;
361
303
 
362
- export abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
363
- constructor(
364
- name: string,
365
- schemas: Schemas
366
- );
367
- abstract start(): Promise<void>;
368
- abstract close(): Promise<void>;
369
- abstract count(
370
- colectionName: keyof Schemas,
371
- query: QueryType<Schemas[keyof Schemas]>,
372
- options?: QueryOptions
373
- ): Promise<number>;
374
- abstract findDocumentById(
375
- collectionName: keyof Schemas,
376
- id: string
377
- ): Promise<Doc<Schemas[keyof Schemas]> | null>;
378
- abstract find(
379
- collectionName: keyof Schemas,
380
- query: QueryType<Schemas[keyof Schemas]>,
381
- options?: QueryOptions
382
- ): Promise<Doc<Schemas[keyof Schemas]>[]>;
383
- abstract write(
384
- op: Operation<Schemas[keyof Schemas]>
385
- ): Promise<Doc<Schemas[keyof Schemas]>>;
304
+ static create<SchemasCreate extends SchemaTypeRecord>(
305
+ dbName: string,
306
+ schemas: SchemasCreate,
307
+ ): Promise<
308
+ InMemory<
309
+ SchemasCreate
310
+ >
311
+ >;
312
+ }
313
+
314
+
315
+
316
+ /**
317
+ * Represents an IndexDB storage system extending the base storage functionality.
318
+ *
319
+ * @template T - The schema type.
320
+ */
321
+ export class IndexDB<T extends SchemaTypeRecord> extends BaseStorage<T> {
322
+ /**
323
+ * Frees the resources used by the in-memory storage.
324
+ */
325
+ free(): void;
326
+
327
+ static create<SchemasCreate extends SchemaTypeRecord>(
328
+ dbName: string,
329
+ schemas: SchemasCreate,
330
+ ): Promise<
331
+ IndexDB<
332
+ SchemasCreate
333
+ >
334
+ >;
335
+ }
336
+
337
+
338
+
339
+ type Hook = (
340
+ schema: Schema<SchemaType>,
341
+ migration: MigrationPathsForSchema<SchemaType>,
342
+ doc: Doc<SchemaType>
343
+ ) => Doc<SchemaType>
344
+
345
+ type BasePluginOptions = {
346
+ docCreateHook?: Hook,
347
+ docRecoverHook?: Hook
386
348
  }
387
349
 
350
+ export class BasePlugin implements BasePluginOptions {
351
+ docCreateHook?:Hook;
352
+ docRecoverHook?:Hook;
353
+ }
354
+
355
+
388
356
 
389
357
  /**
390
358
  * Represents the type definition for a schema.
@@ -704,11 +672,59 @@ export class Property {
704
672
  }
705
673
 
706
674
 
675
+
676
+ /**
677
+ * Represents a record of schema types, where each key is a string and the value is a `SchemaType`.
678
+ */
679
+ export type SchemaTypeRecord = {
680
+ [name: string]: SchemaType
681
+ };
682
+
683
+ export abstract class StorageInternal<Schemas extends SchemaTypeRecord> {
684
+ constructor(
685
+ name: string,
686
+ schemas: Schemas
687
+ );
688
+ abstract start(): Promise<void>;
689
+ abstract close(): Promise<void>;
690
+ abstract count(
691
+ colectionName: keyof Schemas,
692
+ query: QueryType<Schemas[keyof Schemas]>,
693
+ options?: QueryOptions
694
+ ): Promise<number>;
695
+ abstract findDocumentById(
696
+ collectionName: keyof Schemas,
697
+ id: string
698
+ ): Promise<Doc<Schemas[keyof Schemas]> | null>;
699
+ abstract find(
700
+ collectionName: keyof Schemas,
701
+ query: QueryType<Schemas[keyof Schemas]>,
702
+ options?: QueryOptions
703
+ ): Promise<Doc<Schemas[keyof Schemas]>[]>;
704
+ abstract write(
705
+ op: Operation<Schemas[keyof Schemas]>
706
+ ): Promise<Doc<Schemas[keyof Schemas]>>;
707
+ }
708
+
707
709
  /**
708
710
  */
709
711
  export class RIDBError {
712
+ /**
713
+ ** Return copy of self without private attributes.
714
+ */
715
+ toJSON(): Object;
716
+ /**
717
+ * Return stringified version of self.
718
+ */
719
+ toString(): string;
710
720
  free(): void;
711
721
  /**
722
+ * @param {string} err_type
723
+ * @param {string} message
724
+ * @param {number} code
725
+ */
726
+ constructor(err_type: string, message: string, code: number);
727
+ /**
712
728
  * @param {any} err
713
729
  * @returns {RIDBError}
714
730
  */
@@ -857,6 +873,28 @@ export interface InitOutput {
857
873
  readonly basestorage_getOption: (a: number, b: number, c: number, d: number) => void;
858
874
  readonly basestorage_getSchema: (a: number, b: number, c: number, d: number) => void;
859
875
  readonly basestorage_core: (a: number, b: number) => void;
876
+ readonly __wbg_ridberror_free: (a: number) => void;
877
+ readonly ridberror_new: (a: number, b: number, c: number, d: number, e: number) => number;
878
+ readonly ridberror_type: (a: number, b: number) => void;
879
+ readonly ridberror_code: (a: number) => number;
880
+ readonly ridberror_message: (a: number, b: number) => void;
881
+ readonly ridberror_from: (a: number) => number;
882
+ readonly ridberror_error: (a: number, b: number, c: number) => number;
883
+ readonly ridberror_query: (a: number, b: number, c: number) => number;
884
+ readonly ridberror_authentication: (a: number, b: number, c: number) => number;
885
+ readonly ridberror_serialisation: (a: number, b: number, c: number) => number;
886
+ readonly ridberror_validation: (a: number, b: number, c: number) => number;
887
+ readonly ridberror_hook: (a: number, b: number, c: number) => number;
888
+ readonly __wbg_database_free: (a: number) => void;
889
+ readonly database_start: (a: number) => number;
890
+ readonly database_close: (a: number) => number;
891
+ readonly database_started: (a: number) => number;
892
+ readonly database_authenticate: (a: number, b: number, c: number) => number;
893
+ readonly database_collections: (a: number, b: number) => void;
894
+ readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
895
+ readonly __wbg_queryoptions_free: (a: number) => void;
896
+ readonly queryoptions_limit: (a: number, b: number) => void;
897
+ readonly queryoptions_offset: (a: number, b: number) => void;
860
898
  readonly __wbg_inmemory_free: (a: number) => void;
861
899
  readonly inmemory_create: (a: number, b: number, c: number) => number;
862
900
  readonly inmemory_write: (a: number, b: number) => number;
@@ -882,26 +920,6 @@ export interface InitOutput {
882
920
  readonly baseplugin_get_doc_recover_hook: (a: number) => number;
883
921
  readonly baseplugin_set_doc_create_hook: (a: number, b: number) => void;
884
922
  readonly baseplugin_set_doc_recover_hook: (a: number, b: number) => void;
885
- readonly __wbg_ridberror_free: (a: number) => void;
886
- readonly ridberror_type: (a: number, b: number) => void;
887
- readonly ridberror_code: (a: number) => number;
888
- readonly ridberror_message: (a: number, b: number) => void;
889
- readonly ridberror_from: (a: number) => number;
890
- readonly ridberror_error: (a: number, b: number, c: number) => number;
891
- readonly ridberror_query: (a: number, b: number, c: number) => number;
892
- readonly ridberror_authentication: (a: number, b: number, c: number) => number;
893
- readonly ridberror_serialisation: (a: number, b: number, c: number) => number;
894
- readonly ridberror_validation: (a: number, b: number, c: number) => number;
895
- readonly ridberror_hook: (a: number, b: number, c: number) => number;
896
- readonly __wbg_database_free: (a: number) => void;
897
- readonly database_start: (a: number) => number;
898
- readonly database_close: (a: number) => number;
899
- readonly database_started: (a: number) => number;
900
- readonly database_collections: (a: number, b: number) => void;
901
- readonly database_create: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => number;
902
- readonly __wbg_queryoptions_free: (a: number) => void;
903
- readonly queryoptions_limit: (a: number, b: number) => void;
904
- readonly queryoptions_offset: (a: number, b: number) => void;
905
923
  readonly __wbg_schema_free: (a: number) => void;
906
924
  readonly schema_validate: (a: number, b: number, c: number) => void;
907
925
  readonly schema_is_valid: (a: number, b: number) => void;
package/pkg/ridb_core.js CHANGED
@@ -409,15 +409,15 @@ export function __wbgtest_console_error(args) {
409
409
  }
410
410
  }
411
411
 
412
- function __wbg_adapter_294(arg0, arg1) {
412
+ function __wbg_adapter_296(arg0, arg1) {
413
413
  wasm.wasm_bindgen__convert__closures__invoke0_mut__hf4bced6426ca6f31(arg0, arg1);
414
414
  }
415
415
 
416
- function __wbg_adapter_337(arg0, arg1, arg2, arg3, arg4) {
416
+ function __wbg_adapter_339(arg0, arg1, arg2, arg3, arg4) {
417
417
  wasm.wasm_bindgen__convert__closures__invoke3_mut__h425269a7185d1f5b(arg0, arg1, addHeapObject(arg2), arg3, addHeapObject(arg4));
418
418
  }
419
419
 
420
- function __wbg_adapter_388(arg0, arg1, arg2, arg3) {
420
+ function __wbg_adapter_390(arg0, arg1, arg2, arg3) {
421
421
  wasm.wasm_bindgen__convert__closures__invoke2_mut__h1b9fff078715ef14(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
422
422
  }
423
423
 
@@ -977,6 +977,16 @@ export class Database {
977
977
  return ret !== 0;
978
978
  }
979
979
  /**
980
+ * @param {string} password
981
+ * @returns {Promise<boolean>}
982
+ */
983
+ authenticate(password) {
984
+ const ptr0 = passStringToWasm0(password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
985
+ const len0 = WASM_VECTOR_LEN;
986
+ const ret = wasm.database_authenticate(this.__wbg_ptr, ptr0, len0);
987
+ return takeObject(ret);
988
+ }
989
+ /**
980
990
  * Retrieves the collections in the database.
981
991
  *
982
992
  * This function returns an `Object` containing the collections.
@@ -1808,6 +1818,18 @@ export class RIDBError {
1808
1818
  return obj;
1809
1819
  }
1810
1820
 
1821
+ toJSON() {
1822
+ return {
1823
+ type: this.type,
1824
+ code: this.code,
1825
+ message: this.message,
1826
+ };
1827
+ }
1828
+
1829
+ toString() {
1830
+ return JSON.stringify(this);
1831
+ }
1832
+
1811
1833
  __destroy_into_raw() {
1812
1834
  const ptr = this.__wbg_ptr;
1813
1835
  this.__wbg_ptr = 0;
@@ -1820,6 +1842,20 @@ export class RIDBError {
1820
1842
  wasm.__wbg_ridberror_free(ptr);
1821
1843
  }
1822
1844
  /**
1845
+ * @param {string} err_type
1846
+ * @param {string} message
1847
+ * @param {number} code
1848
+ */
1849
+ constructor(err_type, message, code) {
1850
+ const ptr0 = passStringToWasm0(err_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1851
+ const len0 = WASM_VECTOR_LEN;
1852
+ const ptr1 = passStringToWasm0(message, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1853
+ const len1 = WASM_VECTOR_LEN;
1854
+ const ret = wasm.ridberror_new(ptr0, len0, ptr1, len1, code);
1855
+ this.__wbg_ptr = ret >>> 0;
1856
+ return this;
1857
+ }
1858
+ /**
1823
1859
  * @returns {string}
1824
1860
  */
1825
1861
  get type() {
@@ -2677,7 +2713,7 @@ function __wbg_get_imports() {
2677
2713
  const a = state0.a;
2678
2714
  state0.a = 0;
2679
2715
  try {
2680
- return __wbg_adapter_294(a, state0.b, );
2716
+ return __wbg_adapter_296(a, state0.b, );
2681
2717
  } finally {
2682
2718
  state0.a = a;
2683
2719
  }
@@ -2842,7 +2878,7 @@ function __wbg_get_imports() {
2842
2878
  const a = state0.a;
2843
2879
  state0.a = 0;
2844
2880
  try {
2845
- return __wbg_adapter_337(a, state0.b, arg0, arg1, arg2);
2881
+ return __wbg_adapter_339(a, state0.b, arg0, arg1, arg2);
2846
2882
  } finally {
2847
2883
  state0.a = a;
2848
2884
  }
@@ -2921,7 +2957,7 @@ function __wbg_get_imports() {
2921
2957
  const a = state0.a;
2922
2958
  state0.a = 0;
2923
2959
  try {
2924
- return __wbg_adapter_388(a, state0.b, arg0, arg1);
2960
+ return __wbg_adapter_390(a, state0.b, arg0, arg1);
2925
2961
  } finally {
2926
2962
  state0.a = a;
2927
2963
  }
@@ -3021,20 +3057,20 @@ function __wbg_get_imports() {
3021
3057
  const ret = wasm.memory;
3022
3058
  return addHeapObject(ret);
3023
3059
  };
3024
- imports.wbg.__wbindgen_closure_wrapper495 = function(arg0, arg1, arg2) {
3025
- const ret = makeMutClosure(arg0, arg1, 177, __wbg_adapter_56);
3060
+ imports.wbg.__wbindgen_closure_wrapper499 = function(arg0, arg1, arg2) {
3061
+ const ret = makeMutClosure(arg0, arg1, 181, __wbg_adapter_56);
3026
3062
  return addHeapObject(ret);
3027
3063
  };
3028
- imports.wbg.__wbindgen_closure_wrapper497 = function(arg0, arg1, arg2) {
3029
- const ret = makeClosure(arg0, arg1, 177, __wbg_adapter_59);
3064
+ imports.wbg.__wbindgen_closure_wrapper501 = function(arg0, arg1, arg2) {
3065
+ const ret = makeClosure(arg0, arg1, 181, __wbg_adapter_59);
3030
3066
  return addHeapObject(ret);
3031
3067
  };
3032
- imports.wbg.__wbindgen_closure_wrapper499 = function(arg0, arg1, arg2) {
3033
- const ret = makeMutClosure(arg0, arg1, 177, __wbg_adapter_62);
3068
+ imports.wbg.__wbindgen_closure_wrapper503 = function(arg0, arg1, arg2) {
3069
+ const ret = makeMutClosure(arg0, arg1, 181, __wbg_adapter_62);
3034
3070
  return addHeapObject(ret);
3035
3071
  };
3036
- imports.wbg.__wbindgen_closure_wrapper1617 = function(arg0, arg1, arg2) {
3037
- const ret = makeMutClosure(arg0, arg1, 449, __wbg_adapter_65);
3072
+ imports.wbg.__wbindgen_closure_wrapper1625 = function(arg0, arg1, arg2) {
3073
+ const ret = makeMutClosure(arg0, arg1, 453, __wbg_adapter_65);
3038
3074
  return addHeapObject(ret);
3039
3075
  };
3040
3076
 
Binary file