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

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 (150) hide show
  1. package/dest/config.d.ts +2 -2
  2. package/dest/config.d.ts.map +1 -1
  3. package/dest/config.js +5 -3
  4. package/dest/indexeddb/array.d.ts +3 -2
  5. package/dest/indexeddb/array.d.ts.map +1 -1
  6. package/dest/indexeddb/array.js +3 -0
  7. package/dest/indexeddb/index.d.ts +1 -1
  8. package/dest/indexeddb/index.js +1 -1
  9. package/dest/indexeddb/map.d.ts +12 -6
  10. package/dest/indexeddb/map.d.ts.map +1 -1
  11. package/dest/indexeddb/map.js +38 -60
  12. package/dest/indexeddb/multi_map.d.ts +13 -0
  13. package/dest/indexeddb/multi_map.d.ts.map +1 -0
  14. package/dest/indexeddb/multi_map.js +92 -0
  15. package/dest/indexeddb/set.d.ts +1 -1
  16. package/dest/indexeddb/set.d.ts.map +1 -1
  17. package/dest/indexeddb/singleton.d.ts +3 -2
  18. package/dest/indexeddb/singleton.d.ts.map +1 -1
  19. package/dest/indexeddb/singleton.js +3 -1
  20. package/dest/indexeddb/store.d.ts +13 -14
  21. package/dest/indexeddb/store.d.ts.map +1 -1
  22. package/dest/indexeddb/store.js +45 -42
  23. package/dest/interfaces/array.d.ts +5 -4
  24. package/dest/interfaces/array.d.ts.map +1 -1
  25. package/dest/interfaces/array.js +1 -3
  26. package/dest/interfaces/array_test_suite.d.ts +1 -1
  27. package/dest/interfaces/common.d.ts +11 -9
  28. package/dest/interfaces/common.d.ts.map +1 -1
  29. package/dest/interfaces/common.js +8 -3
  30. package/dest/interfaces/counter.d.ts +1 -1
  31. package/dest/interfaces/index.d.ts +4 -2
  32. package/dest/interfaces/index.d.ts.map +1 -1
  33. package/dest/interfaces/index.js +2 -0
  34. package/dest/interfaces/map.d.ts +21 -49
  35. package/dest/interfaces/map.d.ts.map +1 -1
  36. package/dest/interfaces/map.js +1 -1
  37. package/dest/interfaces/map_test_suite.d.ts +1 -1
  38. package/dest/interfaces/map_test_suite.d.ts.map +1 -1
  39. package/dest/interfaces/map_test_suite.js +135 -70
  40. package/dest/interfaces/multi_map.d.ts +41 -0
  41. package/dest/interfaces/multi_map.d.ts.map +1 -0
  42. package/dest/interfaces/multi_map.js +3 -0
  43. package/dest/interfaces/multi_map_test_suite.d.ts +3 -0
  44. package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -0
  45. package/dest/interfaces/multi_map_test_suite.js +339 -0
  46. package/dest/interfaces/set.d.ts +1 -1
  47. package/dest/interfaces/set_test_suite.d.ts +1 -1
  48. package/dest/interfaces/singleton.d.ts +1 -1
  49. package/dest/interfaces/singleton_test_suite.d.ts +1 -1
  50. package/dest/interfaces/store.d.ts +18 -43
  51. package/dest/interfaces/store.d.ts.map +1 -1
  52. package/dest/interfaces/utils.d.ts +2 -1
  53. package/dest/interfaces/utils.d.ts.map +1 -1
  54. package/dest/interfaces/utils.js +2 -1
  55. package/dest/lmdb/array.d.ts +3 -2
  56. package/dest/lmdb/array.d.ts.map +1 -1
  57. package/dest/lmdb/counter.d.ts +1 -1
  58. package/dest/lmdb/counter.d.ts.map +1 -1
  59. package/dest/lmdb/index.d.ts +1 -1
  60. package/dest/lmdb/index.js +2 -2
  61. package/dest/lmdb/map.d.ts +11 -23
  62. package/dest/lmdb/map.d.ts.map +1 -1
  63. package/dest/lmdb/map.js +15 -81
  64. package/dest/lmdb/multi_map.d.ts +13 -0
  65. package/dest/lmdb/multi_map.d.ts.map +1 -0
  66. package/dest/lmdb/multi_map.js +44 -0
  67. package/dest/lmdb/set.d.ts +1 -1
  68. package/dest/lmdb/set.d.ts.map +1 -1
  69. package/dest/lmdb/singleton.d.ts +1 -1
  70. package/dest/lmdb/singleton.d.ts.map +1 -1
  71. package/dest/lmdb/store.d.ts +9 -25
  72. package/dest/lmdb/store.d.ts.map +1 -1
  73. package/dest/lmdb/store.js +11 -31
  74. package/dest/lmdb-v2/array.d.ts +3 -2
  75. package/dest/lmdb-v2/array.d.ts.map +1 -1
  76. package/dest/lmdb-v2/array.js +1 -0
  77. package/dest/lmdb-v2/factory.d.ts +4 -7
  78. package/dest/lmdb-v2/factory.d.ts.map +1 -1
  79. package/dest/lmdb-v2/factory.js +16 -6
  80. package/dest/lmdb-v2/index.d.ts +1 -1
  81. package/dest/lmdb-v2/map.d.ts +11 -44
  82. package/dest/lmdb-v2/map.d.ts.map +1 -1
  83. package/dest/lmdb-v2/map.js +17 -103
  84. package/dest/lmdb-v2/message.d.ts +24 -5
  85. package/dest/lmdb-v2/message.d.ts.map +1 -1
  86. package/dest/lmdb-v2/message.js +6 -4
  87. package/dest/lmdb-v2/multi_map.d.ts +52 -0
  88. package/dest/lmdb-v2/multi_map.d.ts.map +1 -0
  89. package/dest/lmdb-v2/multi_map.js +124 -0
  90. package/dest/lmdb-v2/read_transaction.d.ts +3 -1
  91. package/dest/lmdb-v2/read_transaction.d.ts.map +1 -1
  92. package/dest/lmdb-v2/read_transaction.js +34 -0
  93. package/dest/lmdb-v2/set.d.ts +15 -0
  94. package/dest/lmdb-v2/set.d.ts.map +1 -0
  95. package/dest/lmdb-v2/set.js +23 -0
  96. package/dest/lmdb-v2/singleton.d.ts +1 -1
  97. package/dest/lmdb-v2/singleton.d.ts.map +1 -1
  98. package/dest/lmdb-v2/singleton.js +1 -0
  99. package/dest/lmdb-v2/store.d.ts +10 -9
  100. package/dest/lmdb-v2/store.d.ts.map +1 -1
  101. package/dest/lmdb-v2/store.js +19 -7
  102. package/dest/lmdb-v2/utils.d.ts +3 -5
  103. package/dest/lmdb-v2/utils.d.ts.map +1 -1
  104. package/dest/lmdb-v2/write_transaction.d.ts +3 -5
  105. package/dest/lmdb-v2/write_transaction.d.ts.map +1 -1
  106. package/dest/stores/index.d.ts +2 -1
  107. package/dest/stores/index.d.ts.map +1 -1
  108. package/dest/stores/index.js +1 -0
  109. package/dest/stores/l2_tips_store.d.ts +3 -2
  110. package/dest/stores/l2_tips_store.d.ts.map +1 -1
  111. package/dest/stores/l2_tips_store.js +18 -9
  112. package/dest/utils.d.ts +1 -1
  113. package/package.json +21 -16
  114. package/src/config.ts +6 -4
  115. package/src/indexeddb/array.ts +5 -1
  116. package/src/indexeddb/index.ts +2 -2
  117. package/src/indexeddb/map.ts +35 -53
  118. package/src/indexeddb/multi_map.ts +91 -0
  119. package/src/indexeddb/singleton.ts +4 -1
  120. package/src/indexeddb/store.ts +66 -56
  121. package/src/interfaces/array.ts +5 -3
  122. package/src/interfaces/common.ts +20 -9
  123. package/src/interfaces/index.ts +3 -1
  124. package/src/interfaces/map.ts +19 -53
  125. package/src/interfaces/map_test_suite.ts +73 -44
  126. package/src/interfaces/multi_map.ts +45 -0
  127. package/src/interfaces/multi_map_test_suite.ts +342 -0
  128. package/src/interfaces/store.ts +18 -53
  129. package/src/interfaces/utils.ts +1 -0
  130. package/src/lmdb/array.ts +2 -1
  131. package/src/lmdb/index.ts +3 -3
  132. package/src/lmdb/map.ts +23 -94
  133. package/src/lmdb/multi_map.ts +51 -0
  134. package/src/lmdb/store.ts +23 -47
  135. package/src/lmdb-v2/array.ts +7 -2
  136. package/src/lmdb-v2/factory.ts +17 -10
  137. package/src/lmdb-v2/map.ts +29 -126
  138. package/src/lmdb-v2/message.ts +23 -0
  139. package/src/lmdb-v2/multi_map.ts +150 -0
  140. package/src/lmdb-v2/read_transaction.ts +40 -0
  141. package/src/lmdb-v2/set.ts +33 -0
  142. package/src/lmdb-v2/singleton.ts +5 -1
  143. package/src/lmdb-v2/store.ts +22 -14
  144. package/src/lmdb-v2/write_transaction.ts +2 -2
  145. package/src/stores/index.ts +2 -0
  146. package/src/stores/l2_tips_store.ts +18 -9
  147. package/dest/interfaces/store_test_suite.d.ts +0 -3
  148. package/dest/interfaces/store_test_suite.d.ts.map +0 -1
  149. package/dest/interfaces/store_test_suite.js +0 -37
  150. package/src/interfaces/store_test_suite.ts +0 -56
@@ -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
  }
@@ -0,0 +1,41 @@
1
+ import type { Key, Value } from './common.js';
2
+ import type { AztecAsyncMap, AztecMap } from './map.js';
3
+ /**
4
+ * A map backed by a persistent store that can have multiple values for a single key.
5
+ */
6
+ export interface AztecMultiMap<K extends Key, V extends Value> extends AztecMap<K, V> {
7
+ /**
8
+ * Gets all the values at the given key.
9
+ * @param key - The key to get the values from
10
+ */
11
+ getValues(key: K): IterableIterator<V>;
12
+ /**
13
+ * Deletes a specific value at the given key.
14
+ * @param key - The key to delete the value at
15
+ * @param val - The value to delete
16
+ */
17
+ deleteValue(key: K, val: V): Promise<void>;
18
+ }
19
+ /**
20
+ * A map backed by a persistent store that can have multiple values for a single key.
21
+ */
22
+ export interface AztecAsyncMultiMap<K extends Key, V extends Value> extends AztecAsyncMap<K, V> {
23
+ /**
24
+ * Gets all the values at the given key.
25
+ * @param key - The key to get the values from
26
+ */
27
+ getValuesAsync(key: K): AsyncIterableIterator<V>;
28
+ /**
29
+ * Gets the number of values at the given key.
30
+ * @param key - The key to get the number of values from
31
+ * @returns The number of values at the given key
32
+ */
33
+ getValueCountAsync(key: K): Promise<number>;
34
+ /**
35
+ * Deletes a specific value at the given key.
36
+ * @param key - The key to delete the value at
37
+ * @param val - The value to delete
38
+ */
39
+ deleteValue(key: K, val: V): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXVsdGlfbWFwLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW50ZXJmYWNlcy9tdWx0aV9tYXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsR0FBRyxFQUFFLEtBQUssRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUM5QyxPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsUUFBUSxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBRXhEOztHQUVHO0FBQ0gsTUFBTSxXQUFXLGFBQWEsQ0FBQyxDQUFDLFNBQVMsR0FBRyxFQUFFLENBQUMsU0FBUyxLQUFLLENBQUUsU0FBUSxRQUFRLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FBQztJQUNuRjs7O09BR0c7SUFDSCxTQUFTLENBQUMsR0FBRyxFQUFFLENBQUMsR0FBRyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUV2Qzs7OztPQUlHO0lBQ0gsV0FBVyxDQUFDLEdBQUcsRUFBRSxDQUFDLEVBQUUsR0FBRyxFQUFFLENBQUMsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDNUM7QUFFRDs7R0FFRztBQUNILE1BQU0sV0FBVyxrQkFBa0IsQ0FBQyxDQUFDLFNBQVMsR0FBRyxFQUFFLENBQUMsU0FBUyxLQUFLLENBQUUsU0FBUSxhQUFhLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FBQztJQUM3Rjs7O09BR0c7SUFDSCxjQUFjLENBQUMsR0FBRyxFQUFFLENBQUMsR0FBRyxxQkFBcUIsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUVqRDs7OztPQUlHO0lBQ0gsa0JBQWtCLENBQUMsR0FBRyxFQUFFLENBQUMsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7SUFFNUM7Ozs7T0FJRztJQUNILFdBQVcsQ0FBQyxHQUFHLEVBQUUsQ0FBQyxFQUFFLEdBQUcsRUFBRSxDQUFDLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDO0NBQzVDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi_map.d.ts","sourceRoot":"","sources":["../../src/interfaces/multi_map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAAE,SAAQ,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACnF;;;OAGG;IACH,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEvC;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,KAAK,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7F;;;OAGG;IACH,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAEjD;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE5C;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,3 @@
1
+ /**
2
+ * A map backed by a persistent store that can have multiple values for a single key.
3
+ */ export { };
@@ -0,0 +1,3 @@
1
+ import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
2
+ export declare function describeAztecMultiMap(testName: string, getStore: () => AztecKVStore | Promise<AztecAsyncKVStore>, forceAsync?: boolean): void;
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXVsdGlfbWFwX3Rlc3Rfc3VpdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbnRlcmZhY2VzL211bHRpX21hcF90ZXN0X3N1aXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLFlBQVksRUFBRSxNQUFNLFlBQVksQ0FBQztBQUdsRSx3QkFBZ0IscUJBQXFCLENBQ25DLFFBQVEsRUFBRSxNQUFNLEVBQ2hCLFFBQVEsRUFBRSxNQUFNLFlBQVksR0FBRyxPQUFPLENBQUMsaUJBQWlCLENBQUMsRUFDekQsVUFBVSxHQUFFLE9BQWUsUUF5VTVCIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi_map_test_suite.d.ts","sourceRoot":"","sources":["../../src/interfaces/multi_map_test_suite.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGlE,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,EACzD,UAAU,GAAE,OAAe,QAyU5B"}
@@ -0,0 +1,339 @@
1
+ import { toArray } from '@aztec/foundation/iterable';
2
+ import { expect } from 'chai';
3
+ import { isSyncStore } from './utils.js';
4
+ export function describeAztecMultiMap(testName, getStore, forceAsync = false) {
5
+ describe(testName, ()=>{
6
+ let store;
7
+ let multiMap;
8
+ beforeEach(async ()=>{
9
+ store = await getStore();
10
+ multiMap = store.openMultiMap('test');
11
+ });
12
+ afterEach(async ()=>{
13
+ await store.delete();
14
+ });
15
+ async function get(key, sut = multiMap) {
16
+ return isSyncStore(store) && !forceAsync ? sut.get(key) : await sut.getAsync(key);
17
+ }
18
+ async function size(sut = multiMap) {
19
+ return isSyncStore(store) && !forceAsync ? sut.size() : await sut.sizeAsync();
20
+ }
21
+ async function entries() {
22
+ return isSyncStore(store) && !forceAsync ? await toArray(multiMap.entries()) : await toArray(multiMap.entriesAsync());
23
+ }
24
+ async function values() {
25
+ return isSyncStore(store) && !forceAsync ? await toArray(multiMap.values()) : await toArray(multiMap.valuesAsync());
26
+ }
27
+ async function keys(range, sut = multiMap) {
28
+ return isSyncStore(store) && !forceAsync ? await toArray(sut.keys(range)) : await toArray(sut.keysAsync(range));
29
+ }
30
+ async function getValues(key) {
31
+ return isSyncStore(store) && !forceAsync ? await toArray(multiMap.getValues(key)) : await toArray(multiMap.getValuesAsync(key));
32
+ }
33
+ async function getValueCount(key, sut = multiMap) {
34
+ return await sut.getValueCountAsync(key);
35
+ }
36
+ it('should be able to set and get values', async ()=>{
37
+ await multiMap.set('foo', 'bar');
38
+ await multiMap.set('baz', 'qux');
39
+ expect(await get('foo')).to.equal('bar');
40
+ expect(await get('baz')).to.equal('qux');
41
+ expect(await get('quux')).to.equal(undefined);
42
+ });
43
+ it('should be able to set values if they do not exist', async ()=>{
44
+ expect(await multiMap.setIfNotExists('foo', 'bar')).to.equal(true);
45
+ expect(await multiMap.setIfNotExists('foo', 'baz')).to.equal(false);
46
+ expect(await get('foo')).to.equal('bar');
47
+ });
48
+ it('should be able to delete values', async ()=>{
49
+ await multiMap.set('foo', 'bar');
50
+ await multiMap.set('baz', 'qux');
51
+ await multiMap.delete('foo');
52
+ expect(await get('foo')).to.equal(undefined);
53
+ expect(await get('baz')).to.equal('qux');
54
+ });
55
+ it('should be able to get size of the map', async ()=>{
56
+ await multiMap.set('foo', 'bar');
57
+ expect(await size()).to.equal(1);
58
+ await multiMap.set('baz', 'qux');
59
+ expect(await size()).to.equal(2);
60
+ await multiMap.delete('foo');
61
+ expect(await size()).to.equal(1);
62
+ });
63
+ it('should be able to iterate over entries when there are no keys', async ()=>{
64
+ expect(await entries()).to.deep.equal([]);
65
+ });
66
+ it('should be able to iterate over entries', async ()=>{
67
+ await multiMap.set('foo', 'bar');
68
+ await multiMap.set('baz', 'qux');
69
+ expect(await entries()).to.deep.equal([
70
+ [
71
+ 'baz',
72
+ 'qux'
73
+ ],
74
+ [
75
+ 'foo',
76
+ 'bar'
77
+ ]
78
+ ]);
79
+ });
80
+ it('should be able to iterate over values', async ()=>{
81
+ await multiMap.set('foo', 'bar');
82
+ await multiMap.set('baz', 'quux');
83
+ expect(await values()).to.deep.equal([
84
+ 'quux',
85
+ 'bar'
86
+ ]);
87
+ });
88
+ it('should be able to iterate over keys', async ()=>{
89
+ await multiMap.set('foo', 'bar');
90
+ await multiMap.set('baz', 'qux');
91
+ expect(await keys()).to.deep.equal([
92
+ 'baz',
93
+ 'foo'
94
+ ]);
95
+ });
96
+ it('should be able to get multiple values for a single key', async ()=>{
97
+ await multiMap.set('foo', 'bar');
98
+ await multiMap.set('foo', 'baz');
99
+ expect(await getValues('foo')).to.deep.equal([
100
+ 'bar',
101
+ 'baz'
102
+ ]);
103
+ });
104
+ it('should ignore multiple identical values', async ()=>{
105
+ await multiMap.set('foo', 'bar');
106
+ await multiMap.set('foo', 'bar');
107
+ expect(await getValues('foo')).to.deep.equal([
108
+ 'bar'
109
+ ]);
110
+ });
111
+ it('should be able to delete individual values for a single key', async ()=>{
112
+ await multiMap.set('foo', '1');
113
+ await multiMap.set('foo', '2');
114
+ await multiMap.set('foo', '3');
115
+ await multiMap.deleteValue('foo', '2');
116
+ expect(await getValues('foo')).to.deep.equal([
117
+ '1',
118
+ '3'
119
+ ]);
120
+ });
121
+ it('should be able to get size of the map with duplicate keys', async ()=>{
122
+ await multiMap.set('foo', '1');
123
+ await multiMap.set('foo', '2');
124
+ await multiMap.set('foo', '3');
125
+ expect(await size()).to.equal(3);
126
+ await multiMap.set('bar', '1');
127
+ await multiMap.set('bar', '2');
128
+ await multiMap.set('bar', '3');
129
+ expect(await size()).to.equal(6);
130
+ await multiMap.deleteValue('foo', '2');
131
+ expect(await size()).to.equal(5);
132
+ });
133
+ it('should be able to delete the last and first values for a key', async ()=>{
134
+ await multiMap.set('foo', '1');
135
+ await multiMap.set('foo', '2');
136
+ await multiMap.set('foo', '3');
137
+ await multiMap.deleteValue('foo', '1');
138
+ expect(await getValues('foo')).to.deep.equal([
139
+ '2',
140
+ '3'
141
+ ]);
142
+ await multiMap.deleteValue('foo', '3');
143
+ expect(await getValues('foo')).to.deep.equal([
144
+ '2'
145
+ ]);
146
+ });
147
+ it('should be able to fully clear a key', async ()=>{
148
+ await multiMap.set('foo', '1');
149
+ await multiMap.set('foo', '2');
150
+ await multiMap.set('foo', '3');
151
+ await multiMap.deleteValue('foo', '1');
152
+ await multiMap.deleteValue('foo', '3');
153
+ await multiMap.deleteValue('foo', '2');
154
+ expect(await getValues('foo')).to.deep.equal([]);
155
+ });
156
+ it('should be able to insert after deletion', async ()=>{
157
+ await multiMap.set('foo', '1');
158
+ await multiMap.set('foo', '2');
159
+ await multiMap.set('foo', '3');
160
+ await multiMap.deleteValue('foo', '2');
161
+ await multiMap.set('foo', 'bar');
162
+ expect(await getValues('foo')).to.deep.equal([
163
+ '1',
164
+ '3',
165
+ 'bar'
166
+ ]);
167
+ // Delete the just-added entry
168
+ await multiMap.deleteValue('foo', 'bar');
169
+ expect(await getValues('foo')).to.deep.equal([
170
+ '1',
171
+ '3'
172
+ ]);
173
+ // Reinsert the initially deleted key
174
+ await multiMap.set('foo', '2');
175
+ // LMDB and IndexedDB behave differently here, the former ordering by value and the latter by insertion. This is
176
+ // fine because there is no expectation for values in a multimap to be ordered.
177
+ const values = (await getValues('foo')).sort((a, b)=>a.localeCompare(b));
178
+ expect(values).to.deep.equal([
179
+ '1',
180
+ '2',
181
+ '3'
182
+ ]);
183
+ // Fully clear the key
184
+ await multiMap.deleteValue('foo', '1');
185
+ await multiMap.deleteValue('foo', '3');
186
+ await multiMap.deleteValue('foo', '2');
187
+ // Insert some more
188
+ await multiMap.set('foo', 'baz');
189
+ await multiMap.set('foo', 'qux');
190
+ expect(await getValues('foo')).to.deep.equal([
191
+ 'baz',
192
+ 'qux'
193
+ ]);
194
+ });
195
+ it('supports range queries', async ()=>{
196
+ await multiMap.set('a', 'a');
197
+ await multiMap.set('b', 'b');
198
+ await multiMap.set('c', 'c');
199
+ await multiMap.set('d', 'd');
200
+ expect(await keys({
201
+ start: 'b',
202
+ end: 'c'
203
+ })).to.deep.equal([
204
+ 'b'
205
+ ]);
206
+ expect(await keys({
207
+ start: 'b'
208
+ })).to.deep.equal([
209
+ 'b',
210
+ 'c',
211
+ 'd'
212
+ ]);
213
+ expect(await keys({
214
+ end: 'c'
215
+ })).to.deep.equal([
216
+ 'a',
217
+ 'b'
218
+ ]);
219
+ expect(await keys({
220
+ start: 'b',
221
+ end: 'c',
222
+ reverse: true
223
+ })).to.deep.equal([
224
+ 'c'
225
+ ]);
226
+ expect(await keys({
227
+ start: 'b',
228
+ limit: 1
229
+ })).to.deep.equal([
230
+ 'b'
231
+ ]);
232
+ expect(await keys({
233
+ start: 'b',
234
+ reverse: true
235
+ })).to.deep.equal([
236
+ 'd',
237
+ 'c'
238
+ ]);
239
+ expect(await keys({
240
+ end: 'b',
241
+ reverse: true
242
+ })).to.deep.equal([
243
+ 'b',
244
+ 'a'
245
+ ]);
246
+ });
247
+ it('returns 0 for missing key', async ()=>{
248
+ expect(await getValueCount('missing')).to.equal(0);
249
+ });
250
+ it('counts a single value', async ()=>{
251
+ await multiMap.set('foo', 'bar');
252
+ expect(await getValueCount('foo')).to.equal(1);
253
+ });
254
+ it('counts multiple distinct values for same key', async ()=>{
255
+ await multiMap.set('foo', 'bar');
256
+ await multiMap.set('foo', 'baz');
257
+ await multiMap.set('foo', 'qux');
258
+ expect(await getValueCount('foo')).to.equal(3);
259
+ });
260
+ it('does not increase count for duplicate inserts', async ()=>{
261
+ await multiMap.set('foo', 'bar');
262
+ await multiMap.set('foo', 'bar');
263
+ await multiMap.set('foo', 'baz');
264
+ await multiMap.set('foo', 'baz');
265
+ expect(await getValueCount('foo')).to.equal(2);
266
+ expect(await getValues('foo')).to.have.members([
267
+ 'bar',
268
+ 'baz'
269
+ ]);
270
+ });
271
+ it('decrements when deleting a single value', async ()=>{
272
+ await multiMap.set('foo', '1');
273
+ await multiMap.set('foo', '2');
274
+ await multiMap.set('foo', '3');
275
+ expect(await getValueCount('foo')).to.equal(3);
276
+ await multiMap.deleteValue('foo', '2');
277
+ expect(await getValueCount('foo')).to.equal(2);
278
+ expect(await getValues('foo')).to.have.members([
279
+ '1',
280
+ '3'
281
+ ]);
282
+ });
283
+ it('does not change count when deleting a non-existent value', async ()=>{
284
+ await multiMap.set('foo', '1');
285
+ await multiMap.set('foo', '3');
286
+ expect(await getValueCount('foo')).to.equal(2);
287
+ await multiMap.deleteValue('foo', '2');
288
+ expect(await getValueCount('foo')).to.equal(2);
289
+ });
290
+ it('clears all values when deleting a key', async ()=>{
291
+ await multiMap.set('foo', 'bar');
292
+ await multiMap.set('foo', 'baz');
293
+ expect(await getValueCount('foo')).to.equal(2);
294
+ await multiMap.delete('foo');
295
+ expect(await getValueCount('foo')).to.equal(0);
296
+ expect(await getValues('foo')).to.deep.equal([]);
297
+ });
298
+ it('count equals enumerated values length', async ()=>{
299
+ await multiMap.set('foo', '1');
300
+ await multiMap.set('foo', '2');
301
+ const vals = await getValues('foo');
302
+ expect(await getValueCount('foo')).to.equal(vals.length);
303
+ });
304
+ it('sum of per-key counts equals total size', async ()=>{
305
+ await multiMap.set('foo', '1');
306
+ await multiMap.set('foo', '2');
307
+ await multiMap.set('bar', '3');
308
+ await multiMap.set('bar', '4');
309
+ await multiMap.set('baz', '5');
310
+ const allKeys = await keys();
311
+ const uniqueKeys = Array.from(new Set(allKeys));
312
+ const counts = await Promise.all(uniqueKeys.map((k)=>getValueCount(k)));
313
+ const sum = counts.reduce((s, n)=>s + n, 0);
314
+ expect(sum).to.equal(await size());
315
+ });
316
+ it('supports sparse slots: delete middle, reinsert new, count remains correct', async ()=>{
317
+ await multiMap.set('foo', '1');
318
+ await multiMap.set('foo', '2');
319
+ await multiMap.set('foo', '3');
320
+ expect(await getValueCount('foo')).to.equal(3);
321
+ await multiMap.deleteValue('foo', '2');
322
+ expect(await getValueCount('foo')).to.equal(2);
323
+ await multiMap.set('foo', '4');
324
+ expect(await getValueCount('foo')).to.equal(3);
325
+ expect(await getValues('foo')).to.have.members([
326
+ '1',
327
+ '3',
328
+ '4'
329
+ ]);
330
+ });
331
+ it('multiple keys are independent', async ()=>{
332
+ await multiMap.set('foo', '1');
333
+ await multiMap.set('foo', '2');
334
+ await multiMap.set('bar', '3');
335
+ expect(await getValueCount('foo')).to.equal(2);
336
+ expect(await getValueCount('bar')).to.equal(1);
337
+ });
338
+ });
339
+ }
@@ -41,4 +41,4 @@ export interface AztecAsyncSet<K extends Key> extends AztecBaseSet<K> {
41
41
  entriesAsync(range?: Range<K>): AsyncIterableIterator<K>;
42
42
  }
43
43
  export {};
44
- //# sourceMappingURL=set.d.ts.map
44
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW50ZXJmYWNlcy9zZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsR0FBRyxFQUFFLEtBQUssRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUU5Qzs7R0FFRztBQUNILFVBQVUsWUFBWSxDQUFDLENBQUMsU0FBUyxHQUFHO0lBQ2xDOzs7T0FHRztJQUNILEdBQUcsQ0FBQyxHQUFHLEVBQUUsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQztJQUUzQjs7O09BR0c7SUFDSCxNQUFNLENBQUMsR0FBRyxFQUFFLENBQUMsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDL0I7QUFFRCxNQUFNLFdBQVcsUUFBUSxDQUFDLENBQUMsU0FBUyxHQUFHLENBQUUsU0FBUSxZQUFZLENBQUMsQ0FBQyxDQUFDO0lBQzlEOzs7O09BSUc7SUFDSCxHQUFHLENBQUMsR0FBRyxFQUFFLENBQUMsR0FBRyxPQUFPLENBQUM7SUFFckI7OztPQUdHO0lBQ0gsT0FBTyxDQUFDLEtBQUssQ0FBQyxFQUFFLEtBQUssQ0FBQyxDQUFDLENBQUMsR0FBRyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUMsQ0FBQztDQUNoRDtBQUVELE1BQU0sV0FBVyxhQUFhLENBQUMsQ0FBQyxTQUFTLEdBQUcsQ0FBRSxTQUFRLFlBQVksQ0FBQyxDQUFDLENBQUM7SUFDbkU7Ozs7T0FJRztJQUNILFFBQVEsQ0FBQyxHQUFHLEVBQUUsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUVuQzs7O09BR0c7SUFDSCxZQUFZLENBQUMsS0FBSyxDQUFDLEVBQUUsS0FBSyxDQUFDLENBQUMsQ0FBQyxHQUFHLHFCQUFxQixDQUFDLENBQUMsQ0FBQyxDQUFDO0NBQzFEIn0=
@@ -1,3 +1,3 @@
1
1
  import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
2
2
  export declare function describeAztecSet(testName: string, getStore: () => AztecKVStore | Promise<AztecAsyncKVStore>, forceAsync?: boolean): void;
3
- //# sourceMappingURL=set_test_suite.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0X3Rlc3Rfc3VpdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbnRlcmZhY2VzL3NldF90ZXN0X3N1aXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLFlBQVksRUFBRSxNQUFNLFlBQVksQ0FBQztBQUdsRSx3QkFBZ0IsZ0JBQWdCLENBQzlCLFFBQVEsRUFBRSxNQUFNLEVBQ2hCLFFBQVEsRUFBRSxNQUFNLFlBQVksR0FBRyxPQUFPLENBQUMsaUJBQWlCLENBQUMsRUFDekQsVUFBVSxHQUFFLE9BQWUsUUFvRTVCIn0=
@@ -26,4 +26,4 @@ export interface AztecAsyncSingleton<T> extends AztecBaseSingleton<T> {
26
26
  getAsync(): Promise<T | undefined>;
27
27
  }
28
28
  export {};
29
- //# sourceMappingURL=singleton.d.ts.map
29
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2luZ2xldG9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW50ZXJmYWNlcy9zaW5nbGV0b24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7OztHQUdHO0FBQ0gsVUFBVSxrQkFBa0IsQ0FBQyxDQUFDO0lBQzVCOzs7T0FHRztJQUNILEdBQUcsQ0FBQyxHQUFHLEVBQUUsQ0FBQyxHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUU5Qjs7T0FFRztJQUNILE1BQU0sSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7Q0FDNUI7QUFDRCxNQUFNLFdBQVcsY0FBYyxDQUFDLENBQUMsQ0FBRSxTQUFRLGtCQUFrQixDQUFDLENBQUMsQ0FBQztJQUM5RDs7T0FFRztJQUNILEdBQUcsSUFBSSxDQUFDLEdBQUcsU0FBUyxDQUFDO0NBQ3RCO0FBRUQsTUFBTSxXQUFXLG1CQUFtQixDQUFDLENBQUMsQ0FBRSxTQUFRLGtCQUFrQixDQUFDLENBQUMsQ0FBQztJQUNuRTs7T0FFRztJQUNILFFBQVEsSUFBSSxPQUFPLENBQUMsQ0FBQyxHQUFHLFNBQVMsQ0FBQyxDQUFDO0NBQ3BDIn0=
@@ -1,3 +1,3 @@
1
1
  import type { AztecAsyncKVStore, AztecKVStore } from './store.js';
2
2
  export declare function describeAztecSingleton(testName: string, getStore: () => AztecKVStore | Promise<AztecAsyncKVStore>, forceAsync?: boolean): void;
3
- //# sourceMappingURL=singleton_test_suite.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2luZ2xldG9uX3Rlc3Rfc3VpdGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pbnRlcmZhY2VzL3NpbmdsZXRvbl90ZXN0X3N1aXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLFlBQVksRUFBRSxNQUFNLFlBQVksQ0FBQztBQUdsRSx3QkFBZ0Isc0JBQXNCLENBQ3BDLFFBQVEsRUFBRSxNQUFNLEVBQ2hCLFFBQVEsRUFBRSxNQUFNLFlBQVksR0FBRyxPQUFPLENBQUMsaUJBQWlCLENBQUMsRUFDekQsVUFBVSxHQUFFLE9BQWUsUUFvQzVCIn0=