@aztec/kv-store 0.0.0-test.1 → 0.0.1-commit.b655e406

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.
Files changed (130) hide show
  1. package/dest/config.d.ts +1 -1
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +5 -3
  4. package/dest/indexeddb/array.d.ts +2 -1
  5. package/dest/indexeddb/array.d.ts.map +1 -1
  6. package/dest/indexeddb/array.js +3 -0
  7. package/dest/indexeddb/index.js +1 -1
  8. package/dest/indexeddb/map.d.ts +11 -5
  9. package/dest/indexeddb/map.d.ts.map +1 -1
  10. package/dest/indexeddb/map.js +38 -60
  11. package/dest/indexeddb/multi_map.d.ts +12 -0
  12. package/dest/indexeddb/multi_map.d.ts.map +1 -0
  13. package/dest/indexeddb/multi_map.js +78 -0
  14. package/dest/indexeddb/singleton.d.ts +2 -1
  15. package/dest/indexeddb/singleton.d.ts.map +1 -1
  16. package/dest/indexeddb/singleton.js +3 -1
  17. package/dest/indexeddb/store.d.ts +12 -13
  18. package/dest/indexeddb/store.d.ts.map +1 -1
  19. package/dest/indexeddb/store.js +45 -42
  20. package/dest/interfaces/array.d.ts +4 -3
  21. package/dest/interfaces/array.d.ts.map +1 -1
  22. package/dest/interfaces/array.js +1 -3
  23. package/dest/interfaces/common.d.ts +10 -8
  24. package/dest/interfaces/common.d.ts.map +1 -1
  25. package/dest/interfaces/common.js +8 -3
  26. package/dest/interfaces/index.d.ts +3 -1
  27. package/dest/interfaces/index.d.ts.map +1 -1
  28. package/dest/interfaces/index.js +2 -0
  29. package/dest/interfaces/map.d.ts +20 -48
  30. package/dest/interfaces/map.d.ts.map +1 -1
  31. package/dest/interfaces/map.js +1 -1
  32. package/dest/interfaces/map_test_suite.d.ts.map +1 -1
  33. package/dest/interfaces/map_test_suite.js +135 -70
  34. package/dest/interfaces/multi_map.d.ts +35 -0
  35. package/dest/interfaces/multi_map.d.ts.map +1 -0
  36. package/dest/interfaces/multi_map.js +3 -0
  37. package/dest/interfaces/multi_map_test_suite.d.ts +3 -0
  38. package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -0
  39. package/dest/interfaces/multi_map_test_suite.js +245 -0
  40. package/dest/interfaces/store.d.ts +17 -42
  41. package/dest/interfaces/store.d.ts.map +1 -1
  42. package/dest/interfaces/utils.d.ts +1 -0
  43. package/dest/interfaces/utils.d.ts.map +1 -1
  44. package/dest/interfaces/utils.js +2 -1
  45. package/dest/lmdb/array.d.ts +2 -1
  46. package/dest/lmdb/array.d.ts.map +1 -1
  47. package/dest/lmdb/index.js +2 -2
  48. package/dest/lmdb/map.d.ts +10 -22
  49. package/dest/lmdb/map.d.ts.map +1 -1
  50. package/dest/lmdb/map.js +15 -81
  51. package/dest/lmdb/multi_map.d.ts +12 -0
  52. package/dest/lmdb/multi_map.d.ts.map +1 -0
  53. package/dest/lmdb/multi_map.js +29 -0
  54. package/dest/lmdb/store.d.ts +7 -22
  55. package/dest/lmdb/store.d.ts.map +1 -1
  56. package/dest/lmdb/store.js +11 -31
  57. package/dest/lmdb-v2/array.d.ts +2 -1
  58. package/dest/lmdb-v2/array.d.ts.map +1 -1
  59. package/dest/lmdb-v2/array.js +1 -0
  60. package/dest/lmdb-v2/factory.d.ts +1 -1
  61. package/dest/lmdb-v2/factory.d.ts.map +1 -1
  62. package/dest/lmdb-v2/factory.js +16 -6
  63. package/dest/lmdb-v2/map.d.ts +10 -43
  64. package/dest/lmdb-v2/map.d.ts.map +1 -1
  65. package/dest/lmdb-v2/map.js +17 -103
  66. package/dest/lmdb-v2/message.d.ts +23 -4
  67. package/dest/lmdb-v2/message.d.ts.map +1 -1
  68. package/dest/lmdb-v2/message.js +6 -4
  69. package/dest/lmdb-v2/multi_map.d.ts +51 -0
  70. package/dest/lmdb-v2/multi_map.d.ts.map +1 -0
  71. package/dest/lmdb-v2/multi_map.js +113 -0
  72. package/dest/lmdb-v2/read_transaction.d.ts +2 -0
  73. package/dest/lmdb-v2/read_transaction.d.ts.map +1 -1
  74. package/dest/lmdb-v2/read_transaction.js +34 -0
  75. package/dest/lmdb-v2/set.d.ts +15 -0
  76. package/dest/lmdb-v2/set.d.ts.map +1 -0
  77. package/dest/lmdb-v2/set.js +23 -0
  78. package/dest/lmdb-v2/singleton.d.ts.map +1 -1
  79. package/dest/lmdb-v2/singleton.js +1 -0
  80. package/dest/lmdb-v2/store.d.ts +9 -8
  81. package/dest/lmdb-v2/store.d.ts.map +1 -1
  82. package/dest/lmdb-v2/store.js +19 -7
  83. package/dest/lmdb-v2/utils.d.ts +2 -4
  84. package/dest/lmdb-v2/utils.d.ts.map +1 -1
  85. package/dest/lmdb-v2/write_transaction.d.ts +2 -4
  86. package/dest/lmdb-v2/write_transaction.d.ts.map +1 -1
  87. package/dest/stores/index.d.ts +1 -0
  88. package/dest/stores/index.d.ts.map +1 -1
  89. package/dest/stores/index.js +1 -0
  90. package/dest/stores/l2_tips_store.d.ts +2 -1
  91. package/dest/stores/l2_tips_store.d.ts.map +1 -1
  92. package/dest/stores/l2_tips_store.js +18 -9
  93. package/package.json +18 -14
  94. package/src/config.ts +6 -4
  95. package/src/indexeddb/array.ts +5 -1
  96. package/src/indexeddb/index.ts +2 -2
  97. package/src/indexeddb/map.ts +35 -53
  98. package/src/indexeddb/multi_map.ts +79 -0
  99. package/src/indexeddb/singleton.ts +4 -1
  100. package/src/indexeddb/store.ts +66 -56
  101. package/src/interfaces/array.ts +5 -3
  102. package/src/interfaces/common.ts +20 -9
  103. package/src/interfaces/index.ts +3 -1
  104. package/src/interfaces/map.ts +19 -53
  105. package/src/interfaces/map_test_suite.ts +73 -44
  106. package/src/interfaces/multi_map.ts +38 -0
  107. package/src/interfaces/multi_map_test_suite.ts +242 -0
  108. package/src/interfaces/store.ts +18 -53
  109. package/src/interfaces/utils.ts +1 -0
  110. package/src/lmdb/array.ts +2 -1
  111. package/src/lmdb/index.ts +3 -3
  112. package/src/lmdb/map.ts +23 -94
  113. package/src/lmdb/multi_map.ts +35 -0
  114. package/src/lmdb/store.ts +23 -47
  115. package/src/lmdb-v2/array.ts +7 -2
  116. package/src/lmdb-v2/factory.ts +17 -10
  117. package/src/lmdb-v2/map.ts +29 -126
  118. package/src/lmdb-v2/message.ts +23 -0
  119. package/src/lmdb-v2/multi_map.ts +141 -0
  120. package/src/lmdb-v2/read_transaction.ts +40 -0
  121. package/src/lmdb-v2/set.ts +33 -0
  122. package/src/lmdb-v2/singleton.ts +5 -1
  123. package/src/lmdb-v2/store.ts +22 -14
  124. package/src/lmdb-v2/write_transaction.ts +2 -2
  125. package/src/stores/index.ts +2 -0
  126. package/src/stores/l2_tips_store.ts +18 -9
  127. package/dest/interfaces/store_test_suite.d.ts +0 -3
  128. package/dest/interfaces/store_test_suite.d.ts.map +0 -1
  129. package/dest/interfaces/store_test_suite.js +0 -37
  130. package/src/interfaces/store_test_suite.ts +0 -56
@@ -1,22 +1,25 @@
1
+ import { SerialQueue } from '@aztec/foundation/queue';
1
2
  import { deleteDB, openDB } from 'idb';
2
3
  import { IndexedDBAztecArray } from './array.js';
3
4
  import { IndexedDBAztecMap } from './map.js';
5
+ import { IndexedDBAztecMultiMap } from './multi_map.js';
4
6
  import { IndexedDBAztecSet } from './set.js';
5
7
  import { IndexedDBAztecSingleton } from './singleton.js';
6
8
  /**
7
9
  * A key-value store backed by IndexedDB.
8
10
  */ export class AztecIndexedDBStore {
9
11
  isEphemeral;
10
- #log;
11
12
  #rootDB;
12
13
  #name;
14
+ #txQueue;
13
15
  #containers;
14
- constructor(rootDB, isEphemeral, log, name){
16
+ constructor(rootDB, isEphemeral, name){
15
17
  this.isEphemeral = isEphemeral;
16
18
  this.#containers = new Set();
17
19
  this.#rootDB = rootDB;
18
- this.#log = log;
19
20
  this.#name = name;
21
+ this.#txQueue = new SerialQueue();
22
+ this.#txQueue.start();
20
23
  }
21
24
  /**
22
25
  * Creates a new AztecKVStore backed by IndexedDB. The path to the database is optional. If not provided,
@@ -28,7 +31,7 @@ import { IndexedDBAztecSingleton } from './singleton.js';
28
31
  * @param log - A logger to use. Optional
29
32
  * @returns The store
30
33
  */ static async open(log, name, ephemeral = false) {
31
- name = name && !ephemeral ? name : self.crypto.getRandomValues(new Uint8Array(16)).join('');
34
+ name = name && !ephemeral ? name : globalThis.crypto.getRandomValues(new Uint8Array(16)).join('');
32
35
  log.debug(`Opening IndexedDB ${ephemeral ? 'temp ' : ''}database with name ${name}`);
33
36
  const rootDB = await openDB(name, 1, {
34
37
  upgrade (db) {
@@ -41,38 +44,30 @@ import { IndexedDBAztecSingleton } from './singleton.js';
41
44
  ], {
42
45
  unique: false
43
46
  });
47
+ // Keep count of the maximum number of keys ever inserted in the container
48
+ // This allows unique slots for repeated keys, which is useful for multi-maps
44
49
  objectStore.createIndex('keyCount', [
45
50
  'container',
46
51
  'key',
47
52
  'keyCount'
48
53
  ], {
49
- unique: false
54
+ unique: true
55
+ });
56
+ // Keep an index on the pair key-hash for a given container, allowing us to efficiently
57
+ // delete unique values from multi-maps
58
+ objectStore.createIndex('hash', [
59
+ 'container',
60
+ 'key',
61
+ 'hash'
62
+ ], {
63
+ unique: true
50
64
  });
51
65
  }
52
66
  });
53
- const kvStore = new AztecIndexedDBStore(rootDB, ephemeral, log, name);
67
+ const kvStore = new AztecIndexedDBStore(rootDB, ephemeral, name);
54
68
  return kvStore;
55
69
  }
56
70
  /**
57
- * Forks the current DB into a new DB by backing it up to a temporary location and opening a new indexedb.
58
- * @returns A new AztecIndexedDBStore.
59
- */ async fork() {
60
- const forkedStore = await AztecIndexedDBStore.open(this.#log, undefined, true);
61
- this.#log.verbose(`Forking store to ${forkedStore.#name}`);
62
- // Copy old data to new store
63
- const oldData = this.#rootDB.transaction('data').store;
64
- const dataToWrite = [];
65
- for await (const cursor of oldData.iterate()){
66
- dataToWrite.push(cursor.value);
67
- }
68
- const tx = forkedStore.#rootDB.transaction('data', 'readwrite').store;
69
- for (const data of dataToWrite){
70
- await tx.add(data);
71
- }
72
- this.#log.debug(`Forked store at ${forkedStore.#name} opened successfully`);
73
- return forkedStore;
74
- }
75
- /**
76
71
  * Creates a new AztecMap in the store.
77
72
  * @param name - Name of the map
78
73
  * @returns A new AztecMap
@@ -95,7 +90,7 @@ import { IndexedDBAztecSingleton } from './singleton.js';
95
90
  * @param name - Name of the map
96
91
  * @returns A new AztecMultiMap
97
92
  */ openMultiMap(name) {
98
- const multimap = new IndexedDBAztecMap(this.#rootDB, name);
93
+ const multimap = new IndexedDBAztecMultiMap(this.#rootDB, name);
99
94
  this.#containers.add(multimap);
100
95
  return multimap;
101
96
  }
@@ -124,22 +119,26 @@ import { IndexedDBAztecSingleton } from './singleton.js';
124
119
  * Runs a callback in a transaction.
125
120
  * @param callback - Function to execute in a transaction
126
121
  * @returns A promise that resolves to the return value of the callback
127
- */ async transactionAsync(callback) {
128
- const tx = this.#rootDB.transaction('data', 'readwrite');
129
- for (const container of this.#containers){
130
- container.db = tx.store;
131
- }
132
- // Avoid awaiting this promise so it doesn't get scheduled in the next microtask
133
- // By then, the tx would be closed
134
- const runningPromise = callback();
135
- // Wait for the transaction to finish
136
- await tx.done;
137
- for (const container of this.#containers){
138
- container.db = undefined;
139
- }
140
- // Return the result of the callback.
141
- // Tx is guaranteed to already be closed, so the await doesn't hurt anything here
142
- return await runningPromise;
122
+ */ transactionAsync(callback) {
123
+ // We can only have one transaction at a time for the same store
124
+ // So we need to wait for the current one to finish
125
+ return this.#txQueue.put(async ()=>{
126
+ const tx = this.#rootDB.transaction('data', 'readwrite');
127
+ for (const container of this.#containers){
128
+ container.db = tx.store;
129
+ }
130
+ // Avoid awaiting this promise so it doesn't get scheduled in the next microtask
131
+ // By then, the tx would be closed
132
+ const runningPromise = callback();
133
+ // Wait for the transaction to finish
134
+ await tx.done;
135
+ for (const container of this.#containers){
136
+ container.db = undefined;
137
+ }
138
+ // Return the result of the callback.
139
+ // Tx is guaranteed to already be closed, so the await doesn't hurt anything here
140
+ return await runningPromise;
141
+ });
143
142
  }
144
143
  /**
145
144
  * Clears all entries in the store & sub DBs.
@@ -154,6 +153,7 @@ import { IndexedDBAztecSingleton } from './singleton.js';
154
153
  estimateSize() {
155
154
  return Promise.resolve({
156
155
  mappingSize: 0,
156
+ physicalFileSize: 0,
157
157
  actualSize: 0,
158
158
  numItems: 0
159
159
  });
@@ -161,4 +161,7 @@ import { IndexedDBAztecSingleton } from './singleton.js';
161
161
  close() {
162
162
  return Promise.resolve();
163
163
  }
164
+ backupTo(_dstPath, _compact) {
165
+ throw new Error('Method not implemented.');
166
+ }
164
167
  }
@@ -1,7 +1,8 @@
1
+ import type { Value } from './common.js';
1
2
  /**
2
3
  * An array backed by a persistent store. Can not have any holes in it.
3
4
  */
4
- interface BaseAztecArray<T> {
5
+ interface BaseAztecArray<T extends Value> {
5
6
  /**
6
7
  * Pushes values to the end of the array
7
8
  * @param vals - The values to push to the end of the array
@@ -24,7 +25,7 @@ interface BaseAztecArray<T> {
24
25
  /**
25
26
  * An array backed by a persistent store. Can not have any holes in it.
26
27
  */
27
- export interface AztecAsyncArray<T> extends BaseAztecArray<T> {
28
+ export interface AztecAsyncArray<T extends Value> extends BaseAztecArray<T> {
28
29
  /**
29
30
  * The size of the array
30
31
  */
@@ -50,7 +51,7 @@ export interface AztecAsyncArray<T> extends BaseAztecArray<T> {
50
51
  */
51
52
  [Symbol.asyncIterator](): AsyncIterableIterator<T>;
52
53
  }
53
- export interface AztecArray<T> extends BaseAztecArray<T> {
54
+ export interface AztecArray<T extends Value> extends BaseAztecArray<T> {
54
55
  /**
55
56
  * The size of the array
56
57
  */
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/interfaces/array.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,UAAU,cAAc,CAAC,CAAC;IACxB;;;;OAIG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpC;;;OAGG;IACH,GAAG,IAAI,OAAO,CAAC,CAAC,GAAG,SAA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AI,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAC1C"}
@@ -1,3 +1 @@
1
- /**
2
- * An array backed by a persistent store. Can not have any holes in it.
3
- */ export { };
1
+ export { };
@@ -1,11 +1,8 @@
1
- /**
2
- * The key type for use with the kv-store
3
- */
4
- export type Key = string | number | Array<string | number>;
5
- /**
6
- * A range of keys to iterate over.
7
- */
8
- export type Range<K extends Key = Key> = {
1
+ /** The key type for use with the kv-store */
2
+ export type Key = string | number | Uint8Array | Array<string | number>;
3
+ export type Value = NonNullable<any>;
4
+ /** A range of keys of arbitrary type. */
5
+ export type CustomRange<K> = {
9
6
  /** The key of the first item to include */
10
7
  start?: K;
11
8
  /** The key of the last item to include */
@@ -15,8 +12,13 @@ export type Range<K extends Key = Key> = {
15
12
  /** The maximum number of items to iterate over */
16
13
  limit?: number;
17
14
  };
15
+ /** Maps a custom range into a range of valid key types to iterate over. */
16
+ export declare function mapRange<CK, K extends Key = Key>(range: CustomRange<CK>, mapFn: (key: CK) => K): Range<K>;
17
+ /** A range of keys to iterate over. */
18
+ export type Range<K extends Key = Key> = CustomRange<K>;
18
19
  export type StoreSize = {
19
20
  mappingSize: number;
21
+ physicalFileSize: number;
20
22
  actualSize: number;
21
23
  numItems: number;
22
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/interfaces/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI;IACvC,2CAA2C;IAC3C,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,0CAA0C;IAC1C,GAAG,CAAC,EAAE,CAAC,CAAC;IACR,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kDAAkD;IAClD,KAAK,CA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with the kv-store
3
- */ export { };
1
+ /** The key type for use with the kv-store */ /** Maps a custom range into a range of valid key types to iterate over. */ export function mapRange(range, mapFn) {
2
+ return {
3
+ start: range.start ? mapFn(range.start) : undefined,
4
+ end: range.end ? mapFn(range.end) : undefined,
5
+ reverse: range.reverse,
6
+ limit: range.limit
7
+ };
8
+ }
@@ -4,5 +4,7 @@ export * from './counter.js';
4
4
  export * from './singleton.js';
5
5
  export * from './store.js';
6
6
  export * from './set.js';
7
- export type { Range, StoreSize } from './common.js';
7
+ export * from './multi_map.js';
8
+ export { mapRange } from './common.js';
9
+ export type { CustomRange, Range, StoreSize } from './common.js';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -4,3 +4,5 @@ export * from './counter.js';
4
4
  export * from './singleton.js';
5
5
  export * from './store.js';
6
6
  export * from './set.js';
7
+ export * from './multi_map.js';
8
+ export { mapRange } from './common.js';
@@ -1,14 +1,22 @@
1
- import type { Key, Range } from './common.js';
1
+ import type { Key, Range, Value } from './common.js';
2
2
  /**
3
3
  * A map backed by a persistent store.
4
4
  */
5
- interface AztecBaseMap<K extends Key, V> {
5
+ interface AztecBaseMap<K extends Key, V extends Value> {
6
6
  /**
7
7
  * Sets the value at the given key.
8
8
  * @param key - The key to set the value at
9
9
  * @param val - The value to set
10
10
  */
11
11
  set(key: K, val: V): Promise<void>;
12
+ /**
13
+ * Sets the values at the given keys.
14
+ * @param entries - The entries to set
15
+ */
16
+ setMany(entries: {
17
+ key: K;
18
+ value: V;
19
+ }[]): Promise<void>;
12
20
  /**
13
21
  * Sets the value at the given key if it does not already exist.
14
22
  * @param key - The key to set the value at
@@ -21,12 +29,17 @@ interface AztecBaseMap<K extends Key, V> {
21
29
  */
22
30
  delete(key: K): Promise<void>;
23
31
  }
24
- export interface AztecMap<K extends Key, V> extends AztecBaseMap<K, V> {
32
+ export interface AztecMap<K extends Key, V extends Value> extends AztecBaseMap<K, V> {
25
33
  /**
26
34
  * Gets the value at the given key.
27
35
  * @param key - The key to get the value from
28
36
  */
29
37
  get(key: K): V | undefined;
38
+ /**
39
+ * Gets the current size of the map.
40
+ * @returns The size of the map
41
+ */
42
+ size(): number;
30
43
  /**
31
44
  * Checks if a key exists in the map.
32
45
  * @param key - The key to check
@@ -53,40 +66,10 @@ export interface AztecMap<K extends Key, V> extends AztecBaseMap<K, V> {
53
66
  */
54
67
  clear(): Promise<void>;
55
68
  }
56
- export interface AztecMapWithSize<K extends Key, V> extends AztecMap<K, V> {
57
- /**
58
- * Gets the size of the map.
59
- * @returns The size of the map
60
- */
61
- size(): number;
62
- }
63
- /**
64
- * A map backed by a persistent store that can have multiple values for a single key.
65
- */
66
- export interface AztecMultiMap<K extends Key, V> extends AztecMap<K, V> {
67
- /**
68
- * Gets all the values at the given key.
69
- * @param key - The key to get the values from
70
- */
71
- getValues(key: K): IterableIterator<V>;
72
- /**
73
- * Deletes a specific value at the given key.
74
- * @param key - The key to delete the value at
75
- * @param val - The value to delete
76
- */
77
- deleteValue(key: K, val: V): Promise<void>;
78
- }
79
- export interface AztecMultiMapWithSize<K extends Key, V> extends AztecMultiMap<K, V> {
80
- /**
81
- * Gets the size of the map.
82
- * @returns The size of the map
83
- */
84
- size(): number;
85
- }
86
69
  /**
87
70
  * A map backed by a persistent store.
88
71
  */
89
- export interface AztecAsyncMap<K extends Key, V> extends AztecBaseMap<K, V> {
72
+ export interface AztecAsyncMap<K extends Key, V extends Value> extends AztecBaseMap<K, V> {
90
73
  /**
91
74
  * Gets the value at the given key.
92
75
  * @param key - The key to get the value from
@@ -113,22 +96,11 @@ export interface AztecAsyncMap<K extends Key, V> extends AztecBaseMap<K, V> {
113
96
  * @param range - The range of keys to iterate over
114
97
  */
115
98
  keysAsync(range?: Range<K>): AsyncIterableIterator<K>;
116
- }
117
- /**
118
- * A map backed by a persistent store that can have multiple values for a single key.
119
- */
120
- export interface AztecAsyncMultiMap<K extends Key, V> extends AztecAsyncMap<K, V> {
121
99
  /**
122
- * Gets all the values at the given key.
123
- * @param key - The key to get the values from
124
- */
125
- getValuesAsync(key: K): AsyncIterableIterator<V>;
126
- /**
127
- * Deletes a specific value at the given key.
128
- * @param key - The key to delete the value at
129
- * @param val - The value to delete
100
+ * Gets the current size of the map.
101
+ * @returns The size of the map
130
102
  */
131
- deleteValue(key: K, val: V): Promise<void>;
103
+ sizeAsync(): Promise<number>;
132
104
  }
133
105
  export {};
134
106
  //# sourceMappingURL=map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/interfaces/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,UAAU,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC;IACrC;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAA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CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEpD;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAE9C;;;OAGG;IACH,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAE5C;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IACvF;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAEzC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnC;;;OAGG;IACH,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAE9D;;;OAGG;IACH,WAAW,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAExD;;;OAGG;IACH,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAEtD;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9B"}
@@ -1,3 +1,3 @@
1
1
  /**
2
- * A map backed by a persistent store that can have multiple values for a single key.
2
+ * A map backed by a persistent store.
3
3
  */ export { };
@@ -1 +1 @@
1
- {"version":3,"file":"map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/map_test_suite.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,EACzD,UAAU,GAAE,OAAe,QAkI5B"}
1
+ {"version":3,"file":"map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/map_test_suite.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,EACzD,UAAU,GAAE,OAAe,QA+J5B"}
@@ -7,7 +7,7 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
7
7
  let map;
8
8
  beforeEach(async ()=>{
9
9
  store = await getStore();
10
- map = store.openMultiMap('test');
10
+ map = store.openMap('test');
11
11
  });
12
12
  afterEach(async ()=>{
13
13
  await store.delete();
@@ -15,6 +15,9 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
15
15
  async function get(key, sut = map) {
16
16
  return isSyncStore(store) && !forceAsync ? sut.get(key) : await sut.getAsync(key);
17
17
  }
18
+ async function size(sut = map) {
19
+ return isSyncStore(store) && !forceAsync ? sut.size() : await sut.sizeAsync();
20
+ }
18
21
  async function entries() {
19
22
  return isSyncStore(store) && !forceAsync ? await toArray(map.entries()) : await toArray(map.entriesAsync());
20
23
  }
@@ -24,9 +27,6 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
24
27
  async function keys(range, sut = map) {
25
28
  return isSyncStore(store) && !forceAsync ? await toArray(sut.keys(range)) : await toArray(sut.keysAsync(range));
26
29
  }
27
- async function getValues(key) {
28
- return isSyncStore(store) && !forceAsync ? await toArray(map.getValues(key)) : await toArray(map.getValuesAsync(key));
29
- }
30
30
  it('should be able to set and get values', async ()=>{
31
31
  await map.set('foo', 'bar');
32
32
  await map.set('baz', 'qux');
@@ -34,6 +34,23 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
34
34
  expect(await get('baz')).to.equal('qux');
35
35
  expect(await get('quux')).to.equal(undefined);
36
36
  });
37
+ it('should be able to set many values', async ()=>{
38
+ const pairs = Array.from({
39
+ length: 100
40
+ }, (_, i)=>({
41
+ key: `key${i}`,
42
+ value: `value${i}`
43
+ }));
44
+ await map.setMany(pairs);
45
+ for (const { key, value } of pairs){
46
+ expect(await get(key)).to.equal(value);
47
+ }
48
+ });
49
+ it('should be able to overwrite values', async ()=>{
50
+ await map.set('foo', 'bar');
51
+ await map.set('foo', 'baz');
52
+ expect(await get('foo')).to.equal('baz');
53
+ });
37
54
  it('should be able to set values if they do not exist', async ()=>{
38
55
  expect(await map.setIfNotExists('foo', 'bar')).to.equal(true);
39
56
  expect(await map.setIfNotExists('foo', 'baz')).to.equal(false);
@@ -46,6 +63,14 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
46
63
  expect(await get('foo')).to.equal(undefined);
47
64
  expect(await get('baz')).to.equal('qux');
48
65
  });
66
+ it('should be able to return size of the map', async ()=>{
67
+ await map.set('foo', 'bar');
68
+ expect(await size()).to.equal(1);
69
+ await map.set('baz', 'qux');
70
+ expect(await size()).to.equal(2);
71
+ await map.delete('foo');
72
+ expect(await size()).to.equal(1);
73
+ });
49
74
  it('should be able to iterate over entries when there are no keys', async ()=>{
50
75
  expect(await entries()).to.deep.equal([]);
51
76
  });
@@ -79,73 +104,113 @@ export function describeAztecMap(testName, getStore, forceAsync = false) {
79
104
  'foo'
80
105
  ]);
81
106
  });
82
- it('should be able to get multiple values for a single key', async ()=>{
83
- await map.set('foo', 'bar');
84
- await map.set('foo', 'baz');
85
- expect(await getValues('foo')).to.deep.equal([
86
- 'bar',
87
- 'baz'
88
- ]);
89
- });
90
- it('should be able to delete individual values for a single key', async ()=>{
91
- await map.set('foo', 'bar');
92
- await map.set('foo', 'baz');
93
- await map.deleteValue('foo', 'bar');
94
- expect(await getValues('foo')).to.deep.equal([
95
- 'baz'
96
- ]);
97
- });
98
- it('supports range queries', async ()=>{
99
- await map.set('a', 'a');
100
- await map.set('b', 'b');
101
- await map.set('c', 'c');
102
- await map.set('d', 'd');
103
- expect(await keys({
104
- start: 'b',
105
- end: 'c'
106
- })).to.deep.equal([
107
- 'b'
108
- ]);
109
- expect(await keys({
110
- start: 'b'
111
- })).to.deep.equal([
112
- 'b',
113
- 'c',
114
- 'd'
115
- ]);
116
- expect(await keys({
117
- end: 'c'
118
- })).to.deep.equal([
119
- 'a',
120
- 'b'
121
- ]);
122
- expect(await keys({
123
- start: 'b',
124
- end: 'c',
125
- reverse: true
126
- })).to.deep.equal([
127
- 'c'
128
- ]);
129
- expect(await keys({
130
- start: 'b',
131
- limit: 1
132
- })).to.deep.equal([
133
- 'b'
134
- ]);
135
- expect(await keys({
136
- start: 'b',
137
- reverse: true
138
- })).to.deep.equal([
139
- 'd',
140
- 'c'
141
- ]);
142
- expect(await keys({
143
- end: 'b',
144
- reverse: true
145
- })).to.deep.equal([
146
- 'b',
147
- 'a'
107
+ it('should be able to iterate over string keys that represent numbers', async ()=>{
108
+ await map.set('0x22', 'bar');
109
+ await map.set('0x31', 'qux');
110
+ expect(await keys()).to.deep.equal([
111
+ '0x22',
112
+ '0x31'
148
113
  ]);
149
114
  });
115
+ for (const [name, data] of [
116
+ [
117
+ 'chars',
118
+ [
119
+ 'a',
120
+ 'b',
121
+ 'c',
122
+ 'd'
123
+ ]
124
+ ],
125
+ [
126
+ 'numbers',
127
+ [
128
+ 1,
129
+ 2,
130
+ 3,
131
+ 4
132
+ ]
133
+ ],
134
+ // disabled because indexeddb sorts lexigographically
135
+ // ['negative numbers', [-4, -3, -2, -1]],
136
+ [
137
+ 'strings',
138
+ [
139
+ 'aaa',
140
+ 'bbb',
141
+ 'ccc',
142
+ 'ddd'
143
+ ]
144
+ ],
145
+ [
146
+ 'zero-based numbers',
147
+ [
148
+ 0,
149
+ 1,
150
+ 2,
151
+ 3
152
+ ]
153
+ ]
154
+ ]){
155
+ it(`supports range queries over ${name} keys`, async ()=>{
156
+ const [a, b, c, d] = data;
157
+ await map.set(a, 'a');
158
+ await map.set(b, 'b');
159
+ await map.set(c, 'c');
160
+ await map.set(d, 'd');
161
+ expect(await keys()).to.deep.equal([
162
+ a,
163
+ b,
164
+ c,
165
+ d
166
+ ]);
167
+ expect(await keys({
168
+ start: b,
169
+ end: c
170
+ })).to.deep.equal([
171
+ b
172
+ ]);
173
+ expect(await keys({
174
+ start: b
175
+ })).to.deep.equal([
176
+ b,
177
+ c,
178
+ d
179
+ ]);
180
+ expect(await keys({
181
+ end: c
182
+ })).to.deep.equal([
183
+ a,
184
+ b
185
+ ]);
186
+ expect(await keys({
187
+ start: b,
188
+ end: c,
189
+ reverse: true
190
+ })).to.deep.equal([
191
+ c
192
+ ]);
193
+ expect(await keys({
194
+ start: b,
195
+ limit: 1
196
+ })).to.deep.equal([
197
+ b
198
+ ]);
199
+ expect(await keys({
200
+ start: b,
201
+ reverse: true
202
+ })).to.deep.equal([
203
+ d,
204
+ c
205
+ ]);
206
+ expect(await keys({
207
+ end: b,
208
+ reverse: true
209
+ })).to.deep.equal([
210
+ b,
211
+ a
212
+ ]);
213
+ });
214
+ }
150
215
  });
151
216
  }