@procedures/collections 0.4.0 → 0.5.0
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/CHANGELOG.md +16 -0
- package/README.md +28 -10
- package/dist/.tsbuildinfo +1 -1
- package/dist/storage/interface.d.ts +25 -4
- package/dist/storage/interface.d.ts.map +1 -1
- package/dist/storage/interface.js.map +1 -1
- package/dist/storage/memory.d.ts +38 -7
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +79 -25
- package/dist/storage/memory.js.map +1 -1
- package/dist/testing/check.d.ts +0 -2
- package/dist/testing/check.d.ts.map +1 -1
- package/dist/testing/check.js +0 -4
- package/dist/testing/check.js.map +1 -1
- package/dist/testing/storage-contract.d.ts +11 -15
- package/dist/testing/storage-contract.d.ts.map +1 -1
- package/dist/testing/storage-contract.js +167 -45
- package/dist/testing/storage-contract.js.map +1 -1
- package/package.json +1 -1
- package/src/storage/interface.ts +26 -4
- package/src/storage/memory.ts +95 -26
- package/src/testing/check.ts +0 -5
- package/src/testing/storage-contract.ts +174 -60
package/dist/storage/memory.d.ts
CHANGED
|
@@ -13,6 +13,16 @@ export interface InMemoryStorageOptions {
|
|
|
13
13
|
* @default 10000
|
|
14
14
|
*/
|
|
15
15
|
maxTombstones?: number;
|
|
16
|
+
/**
|
|
17
|
+
* True: the storage keeps a copy of each value that a write takes, and each read gives a new
|
|
18
|
+
* copy (`structuredClone`). Then a change of a written or a read value does not change the
|
|
19
|
+
* stored item, as in each other storage.
|
|
20
|
+
*
|
|
21
|
+
* False: the storage keeps the values themselves, and the reads give them. This is faster.
|
|
22
|
+
* Give it only when no caller changes a value after a write or a read.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
copies?: boolean;
|
|
16
26
|
}
|
|
17
27
|
/**
|
|
18
28
|
* In-memory storage backed by JavaScript Map.
|
|
@@ -24,6 +34,10 @@ export interface InMemoryStorageOptions {
|
|
|
24
34
|
* - Returns Promises for API consistency with remote storage
|
|
25
35
|
* - Each error is a rejected promise: an error of a `find` predicate does not throw at once
|
|
26
36
|
* - A change log: `getChangesSince(version)` gives the changes after a version (roadmap R28)
|
|
37
|
+
* - Copies: a change of a written or a read value does not change the stored item (the option
|
|
38
|
+
* `copies: false` turns this off)
|
|
39
|
+
* - `getIds()` gives the ids without a copy of the values
|
|
40
|
+
* - After `close()`, each operation rejects, and a second `close()` does nothing
|
|
27
41
|
*
|
|
28
42
|
* @example
|
|
29
43
|
* ```typescript
|
|
@@ -34,33 +48,44 @@ export interface InMemoryStorageOptions {
|
|
|
34
48
|
*/
|
|
35
49
|
export declare class InMemoryStorage<T> implements CollectionStorage<T> {
|
|
36
50
|
private data;
|
|
37
|
-
private epoch;
|
|
51
|
+
private readonly epoch;
|
|
38
52
|
private seq;
|
|
39
|
-
/** The number of the last write of each id that has an item */
|
|
53
|
+
/** The number of the last write of each id that has an item, the oldest first */
|
|
40
54
|
private readonly changedAt;
|
|
41
55
|
/** The number of the delete of each id that has no item, the oldest first (the tombstones) */
|
|
42
56
|
private readonly deletedAt;
|
|
43
57
|
/** The log does not know the deletes at or below this number: they were dropped */
|
|
44
58
|
private floor;
|
|
45
59
|
private readonly maxTombstones;
|
|
60
|
+
private readonly copy;
|
|
61
|
+
private closed;
|
|
46
62
|
constructor(options?: InMemoryStorageOptions);
|
|
47
63
|
get(id: string): Promise<T | undefined>;
|
|
48
64
|
getAll(): Promise<T[]>;
|
|
49
65
|
getEntries(): Promise<Array<[string, T]>>;
|
|
66
|
+
/** The ids of the items, in the order of the entries. This method copies no value. */
|
|
67
|
+
getIds(): Promise<string[]>;
|
|
50
68
|
/**
|
|
51
|
-
* The changes after a version (roadmap R28). A version of another storage,
|
|
52
|
-
*
|
|
69
|
+
* The changes after a version (roadmap R28). A version of another storage, or older than the
|
|
70
|
+
* dropped deletes, gives all items (`full: true`) in the order of the entries. A delta gives
|
|
71
|
+
* the changed items and the deleted ids in the order of the last change of each id.
|
|
53
72
|
*/
|
|
54
73
|
getChangesSince(since?: string): Promise<StorageChanges<T>>;
|
|
74
|
+
/** The items for which the predicate gives true. The predicate gets a copy of each item. */
|
|
55
75
|
find(predicate: (item: T) => boolean): Promise<T[]>;
|
|
56
76
|
has(id: string): Promise<boolean>;
|
|
57
77
|
size(): Promise<number>;
|
|
58
78
|
set(id: string, value: T): Promise<void>;
|
|
59
79
|
delete(id: string): Promise<boolean>;
|
|
60
80
|
clear(): Promise<void>;
|
|
81
|
+
/** This method sets several items. When one value has no copy, nothing changes. */
|
|
61
82
|
setBatch(items: Array<[string, T]>): Promise<void>;
|
|
62
83
|
deleteBatch(ids: string[]): Promise<number>;
|
|
63
84
|
getBatch(ids: string[]): Promise<Map<string, T>>;
|
|
85
|
+
/**
|
|
86
|
+
* This method closes the storage and drops its items. After it, each operation rejects (and
|
|
87
|
+
* each method of the `Map` interface throws). A second `close()` does nothing.
|
|
88
|
+
*/
|
|
64
89
|
close(): Promise<void>;
|
|
65
90
|
getMetadata(): Promise<StorageMetadata>;
|
|
66
91
|
/**
|
|
@@ -70,19 +95,20 @@ export declare class InMemoryStorage<T> implements CollectionStorage<T> {
|
|
|
70
95
|
*/
|
|
71
96
|
keys(): IterableIterator<string>;
|
|
72
97
|
/**
|
|
73
|
-
*
|
|
98
|
+
* The values in storage: copies, unless the option `copies` is false.
|
|
74
99
|
*
|
|
75
100
|
* @returns Iterator of values
|
|
76
101
|
*/
|
|
77
102
|
values(): IterableIterator<T>;
|
|
78
103
|
/**
|
|
79
|
-
*
|
|
104
|
+
* The entries in storage: copies of the values, unless the option `copies` is false.
|
|
80
105
|
*
|
|
81
106
|
* @returns Iterator of [id, value] tuples
|
|
82
107
|
*/
|
|
83
108
|
entries(): IterableIterator<[string, T]>;
|
|
84
109
|
/**
|
|
85
|
-
* Iterate over storage entries.
|
|
110
|
+
* Iterate over storage entries. The callback gets a copy of each value, and a `Map` of the
|
|
111
|
+
* copies, unless the option `copies` is false.
|
|
86
112
|
*
|
|
87
113
|
* @param callback - Function to call for each entry
|
|
88
114
|
*/
|
|
@@ -91,6 +117,11 @@ export declare class InMemoryStorage<T> implements CollectionStorage<T> {
|
|
|
91
117
|
* Make storage iterable.
|
|
92
118
|
*/
|
|
93
119
|
[Symbol.iterator](): IterableIterator<[string, T]>;
|
|
120
|
+
/** This method throws after `close()`. In an async method, the throw rejects the promise. */
|
|
121
|
+
private checkOpen;
|
|
122
|
+
/** The entries with copies of the values. */
|
|
123
|
+
private copiedEntries;
|
|
124
|
+
/** A set moves the id to the end of the order of the log: the order of the last change. */
|
|
94
125
|
private noteSet;
|
|
95
126
|
private noteDelete;
|
|
96
127
|
/** The number of a version of this storage, or undefined for another or an unknown version. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEzF,uCAAuC;AACvC,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEzF,uCAAuC;AACvC,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAYD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,YAAW,iBAAiB,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,IAAI,CAAwB;IAIpC,OAAO,CAAC,QAAQ,CAAC,KAA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.
|
|
5
5
|
* All operations return Promises for interface consistency.
|
|
6
6
|
*/
|
|
7
|
-
/** A new epoch: a version of another storage
|
|
7
|
+
/** A new epoch: a version of another storage does not match it. */
|
|
8
8
|
function newEpoch() {
|
|
9
9
|
return Math.random().toString(36).slice(2, 10);
|
|
10
10
|
}
|
|
11
|
+
const same = (value) => value;
|
|
12
|
+
const clone = (value) => structuredClone(value);
|
|
11
13
|
/**
|
|
12
14
|
* In-memory storage backed by JavaScript Map.
|
|
13
15
|
*
|
|
@@ -18,6 +20,10 @@ function newEpoch() {
|
|
|
18
20
|
* - Returns Promises for API consistency with remote storage
|
|
19
21
|
* - Each error is a rejected promise: an error of a `find` predicate does not throw at once
|
|
20
22
|
* - A change log: `getChangesSince(version)` gives the changes after a version (roadmap R28)
|
|
23
|
+
* - Copies: a change of a written or a read value does not change the stored item (the option
|
|
24
|
+
* `copies: false` turns this off)
|
|
25
|
+
* - `getIds()` gives the ids without a copy of the values
|
|
26
|
+
* - After `close()`, each operation rejects, and a second `close()` does nothing
|
|
21
27
|
*
|
|
22
28
|
* @example
|
|
23
29
|
* ```typescript
|
|
@@ -32,42 +38,55 @@ export class InMemoryStorage {
|
|
|
32
38
|
// `<epoch>:<seq>`.
|
|
33
39
|
epoch = newEpoch();
|
|
34
40
|
seq = 0;
|
|
35
|
-
/** The number of the last write of each id that has an item */
|
|
41
|
+
/** The number of the last write of each id that has an item, the oldest first */
|
|
36
42
|
changedAt = new Map();
|
|
37
43
|
/** The number of the delete of each id that has no item, the oldest first (the tombstones) */
|
|
38
44
|
deletedAt = new Map();
|
|
39
45
|
/** The log does not know the deletes at or below this number: they were dropped */
|
|
40
46
|
floor = 0;
|
|
41
47
|
maxTombstones;
|
|
48
|
+
copy;
|
|
49
|
+
closed = false;
|
|
42
50
|
constructor(options = {}) {
|
|
43
51
|
this.maxTombstones = Math.max(0, options.maxTombstones ?? 10_000);
|
|
52
|
+
this.copy = options.copies === false ? same : clone;
|
|
44
53
|
}
|
|
45
54
|
//
|
|
46
55
|
// ═══ Read Operations ═══
|
|
47
56
|
//
|
|
48
57
|
async get(id) {
|
|
49
|
-
|
|
58
|
+
this.checkOpen();
|
|
59
|
+
return this.copy(this.data.get(id));
|
|
50
60
|
}
|
|
51
61
|
async getAll() {
|
|
52
|
-
|
|
62
|
+
this.checkOpen();
|
|
63
|
+
return Array.from(this.data.values(), this.copy);
|
|
53
64
|
}
|
|
54
65
|
async getEntries() {
|
|
55
|
-
|
|
66
|
+
this.checkOpen();
|
|
67
|
+
return this.copiedEntries();
|
|
68
|
+
}
|
|
69
|
+
/** The ids of the items, in the order of the entries. This method copies no value. */
|
|
70
|
+
async getIds() {
|
|
71
|
+
this.checkOpen();
|
|
72
|
+
return Array.from(this.data.keys());
|
|
56
73
|
}
|
|
57
74
|
/**
|
|
58
|
-
* The changes after a version (roadmap R28). A version of another storage,
|
|
59
|
-
*
|
|
75
|
+
* The changes after a version (roadmap R28). A version of another storage, or older than the
|
|
76
|
+
* dropped deletes, gives all items (`full: true`) in the order of the entries. A delta gives
|
|
77
|
+
* the changed items and the deleted ids in the order of the last change of each id.
|
|
60
78
|
*/
|
|
61
79
|
async getChangesSince(since) {
|
|
80
|
+
this.checkOpen();
|
|
62
81
|
const version = `${this.epoch}:${this.seq}`;
|
|
63
82
|
const from = this.parseVersion(since);
|
|
64
83
|
if (from === undefined || from < this.floor) {
|
|
65
|
-
return { version, full: true, changed:
|
|
84
|
+
return { version, full: true, changed: this.copiedEntries(), deleted: [] };
|
|
66
85
|
}
|
|
67
86
|
const changed = [];
|
|
68
87
|
for (const [id, at] of this.changedAt) {
|
|
69
88
|
if (at > from)
|
|
70
|
-
changed.push([id, this.data.get(id)]);
|
|
89
|
+
changed.push([id, this.copy(this.data.get(id))]);
|
|
71
90
|
}
|
|
72
91
|
const deleted = [];
|
|
73
92
|
for (const [id, at] of this.deletedAt) {
|
|
@@ -76,9 +95,12 @@ export class InMemoryStorage {
|
|
|
76
95
|
}
|
|
77
96
|
return { version, full: false, changed, deleted };
|
|
78
97
|
}
|
|
98
|
+
/** The items for which the predicate gives true. The predicate gets a copy of each item. */
|
|
79
99
|
async find(predicate) {
|
|
100
|
+
this.checkOpen();
|
|
80
101
|
const results = [];
|
|
81
|
-
for (const
|
|
102
|
+
for (const stored of this.data.values()) {
|
|
103
|
+
const item = this.copy(stored);
|
|
82
104
|
if (predicate(item)) {
|
|
83
105
|
results.push(item);
|
|
84
106
|
}
|
|
@@ -86,25 +108,30 @@ export class InMemoryStorage {
|
|
|
86
108
|
return results;
|
|
87
109
|
}
|
|
88
110
|
async has(id) {
|
|
111
|
+
this.checkOpen();
|
|
89
112
|
return this.data.has(id);
|
|
90
113
|
}
|
|
91
114
|
async size() {
|
|
115
|
+
this.checkOpen();
|
|
92
116
|
return this.data.size;
|
|
93
117
|
}
|
|
94
118
|
//
|
|
95
119
|
// ═══ Write Operations ═══
|
|
96
120
|
//
|
|
97
121
|
async set(id, value) {
|
|
98
|
-
this.
|
|
122
|
+
this.checkOpen();
|
|
123
|
+
this.data.set(id, this.copy(value));
|
|
99
124
|
this.noteSet(id);
|
|
100
125
|
}
|
|
101
126
|
async delete(id) {
|
|
127
|
+
this.checkOpen();
|
|
102
128
|
const existed = this.data.delete(id);
|
|
103
129
|
if (existed)
|
|
104
130
|
this.noteDelete(id);
|
|
105
131
|
return existed;
|
|
106
132
|
}
|
|
107
133
|
async clear() {
|
|
134
|
+
this.checkOpen();
|
|
108
135
|
for (const id of this.data.keys())
|
|
109
136
|
this.noteDelete(id);
|
|
110
137
|
this.data.clear();
|
|
@@ -112,13 +139,17 @@ export class InMemoryStorage {
|
|
|
112
139
|
//
|
|
113
140
|
// ═══ Bulk Operations ═══
|
|
114
141
|
//
|
|
142
|
+
/** This method sets several items. When one value has no copy, nothing changes. */
|
|
115
143
|
async setBatch(items) {
|
|
116
|
-
|
|
144
|
+
this.checkOpen();
|
|
145
|
+
const copies = items.map(([id, value]) => [id, this.copy(value)]);
|
|
146
|
+
for (const [id, value] of copies) {
|
|
117
147
|
this.data.set(id, value);
|
|
118
148
|
this.noteSet(id);
|
|
119
149
|
}
|
|
120
150
|
}
|
|
121
151
|
async deleteBatch(ids) {
|
|
152
|
+
this.checkOpen();
|
|
122
153
|
let deleted = 0;
|
|
123
154
|
for (const id of ids) {
|
|
124
155
|
if (this.data.delete(id)) {
|
|
@@ -129,11 +160,12 @@ export class InMemoryStorage {
|
|
|
129
160
|
return deleted;
|
|
130
161
|
}
|
|
131
162
|
async getBatch(ids) {
|
|
163
|
+
this.checkOpen();
|
|
132
164
|
const result = new Map();
|
|
133
165
|
for (const id of ids) {
|
|
134
166
|
const value = this.data.get(id);
|
|
135
167
|
if (value !== undefined) {
|
|
136
|
-
result.set(id, value);
|
|
168
|
+
result.set(id, this.copy(value));
|
|
137
169
|
}
|
|
138
170
|
}
|
|
139
171
|
return result;
|
|
@@ -141,17 +173,20 @@ export class InMemoryStorage {
|
|
|
141
173
|
//
|
|
142
174
|
// ═══ Lifecycle & Metadata ═══
|
|
143
175
|
//
|
|
176
|
+
/**
|
|
177
|
+
* This method closes the storage and drops its items. After it, each operation rejects (and
|
|
178
|
+
* each method of the `Map` interface throws). A second `close()` does nothing.
|
|
179
|
+
*/
|
|
144
180
|
async close() {
|
|
145
|
-
|
|
181
|
+
if (this.closed)
|
|
182
|
+
return;
|
|
183
|
+
this.closed = true;
|
|
146
184
|
this.data.clear();
|
|
147
|
-
// A new epoch: a version of the closed storage gives all items
|
|
148
185
|
this.changedAt.clear();
|
|
149
186
|
this.deletedAt.clear();
|
|
150
|
-
this.epoch = newEpoch();
|
|
151
|
-
this.seq = 0;
|
|
152
|
-
this.floor = 0;
|
|
153
187
|
}
|
|
154
188
|
async getMetadata() {
|
|
189
|
+
this.checkOpen();
|
|
155
190
|
// Rough memory estimation:
|
|
156
191
|
// Each entry has ~overhead of 100 bytes (key string + Map entry overhead)
|
|
157
192
|
const estimatedEntrySize = 100;
|
|
@@ -173,42 +208,61 @@ export class InMemoryStorage {
|
|
|
173
208
|
* @returns Iterator of keys
|
|
174
209
|
*/
|
|
175
210
|
keys() {
|
|
211
|
+
this.checkOpen();
|
|
176
212
|
return this.data.keys();
|
|
177
213
|
}
|
|
178
214
|
/**
|
|
179
|
-
*
|
|
215
|
+
* The values in storage: copies, unless the option `copies` is false.
|
|
180
216
|
*
|
|
181
217
|
* @returns Iterator of values
|
|
182
218
|
*/
|
|
183
219
|
values() {
|
|
184
|
-
|
|
220
|
+
this.checkOpen();
|
|
221
|
+
return this.copiedEntries().map(([, value]) => value)[Symbol.iterator]();
|
|
185
222
|
}
|
|
186
223
|
/**
|
|
187
|
-
*
|
|
224
|
+
* The entries in storage: copies of the values, unless the option `copies` is false.
|
|
188
225
|
*
|
|
189
226
|
* @returns Iterator of [id, value] tuples
|
|
190
227
|
*/
|
|
191
228
|
entries() {
|
|
192
|
-
|
|
229
|
+
this.checkOpen();
|
|
230
|
+
return this.copiedEntries()[Symbol.iterator]();
|
|
193
231
|
}
|
|
194
232
|
/**
|
|
195
|
-
* Iterate over storage entries.
|
|
233
|
+
* Iterate over storage entries. The callback gets a copy of each value, and a `Map` of the
|
|
234
|
+
* copies, unless the option `copies` is false.
|
|
196
235
|
*
|
|
197
236
|
* @param callback - Function to call for each entry
|
|
198
237
|
*/
|
|
199
238
|
forEach(callback) {
|
|
200
|
-
this.
|
|
239
|
+
this.checkOpen();
|
|
240
|
+
new Map(this.copiedEntries()).forEach(callback);
|
|
201
241
|
}
|
|
202
242
|
/**
|
|
203
243
|
* Make storage iterable.
|
|
204
244
|
*/
|
|
205
245
|
[Symbol.iterator]() {
|
|
206
|
-
return this.
|
|
246
|
+
return this.entries();
|
|
247
|
+
}
|
|
248
|
+
//
|
|
249
|
+
// ═══ Internal Helpers ═══
|
|
250
|
+
//
|
|
251
|
+
/** This method throws after `close()`. In an async method, the throw rejects the promise. */
|
|
252
|
+
checkOpen() {
|
|
253
|
+
if (this.closed)
|
|
254
|
+
throw new Error("The InMemoryStorage is closed");
|
|
255
|
+
}
|
|
256
|
+
/** The entries with copies of the values. */
|
|
257
|
+
copiedEntries() {
|
|
258
|
+
return Array.from(this.data, ([id, value]) => [id, this.copy(value)]);
|
|
207
259
|
}
|
|
208
260
|
//
|
|
209
261
|
// ═══ The change log ═══
|
|
210
262
|
//
|
|
263
|
+
/** A set moves the id to the end of the order of the log: the order of the last change. */
|
|
211
264
|
noteSet(id) {
|
|
265
|
+
this.changedAt.delete(id);
|
|
212
266
|
this.changedAt.set(id, ++this.seq);
|
|
213
267
|
this.deletedAt.delete(id);
|
|
214
268
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH,mEAAmE;AACnE,SAAS,QAAQ;IACf,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACjD,CAAC;AAID,MAAM,IAAI,GAAS,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;AACpC,MAAM,KAAK,GAAS,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,eAAe;IAClB,IAAI,GAAG,IAAI,GAAG,EAAa,CAAC;IAEpC,uFAAuF;IACvF,mBAAmB;IACF,KAAK,GAAG,QAAQ,EAAE,CAAC;IAC5B,GAAG,GAAG,CAAC,CAAC;IAChB,iFAAiF;IAChE,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvD,8FAA8F;IAC7E,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvD,mFAAmF;IAC3E,KAAK,GAAG,CAAC,CAAC;IACD,aA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AAC,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAyB,CAAC;YAC/E,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,+FAA+F;IACvF,YAAY,CAAC,KAAyB;QAC5C,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,SAAS,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAChF,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5E,CAAC;CACF"}
|
package/dist/testing/check.d.ts
CHANGED
|
@@ -22,6 +22,4 @@ export declare function holds(condition: boolean, what: string): void;
|
|
|
22
22
|
* A synchronous throw breaks the contract too: each method of a storage gives a promise.
|
|
23
23
|
*/
|
|
24
24
|
export declare function rejects(start: () => Promise<unknown>, what: string): Promise<unknown>;
|
|
25
|
-
/** The entries sorted by id, for a comparison where the order is not part of the contract. */
|
|
26
|
-
export declare function byId<T>(entries: ReadonlyArray<readonly [string, T]>): Array<[string, T]>;
|
|
27
25
|
//# sourceMappingURL=check.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/testing/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yDAAyD;AACzD,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,SAAkB,IAAI,uBAAuB;CAC9C;AAED,gGAAgG;AAChG,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAO3C;AAQD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAkBrE;AAED,yFAAyF;AACzF,wBAAgB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAI3E;AAED,4EAA4E;AAC5E,wBAAgB,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAc3F
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/testing/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yDAAyD;AACzD,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,SAAkB,IAAI,uBAAuB;CAC9C;AAED,gGAAgG;AAChG,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAO3C;AAQD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAkBrE;AAED,yFAAyF;AACzF,wBAAgB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAI3E;AAED,4EAA4E;AAC5E,wBAAgB,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAc3F"}
|
package/dist/testing/check.js
CHANGED
|
@@ -82,8 +82,4 @@ export async function rejects(start, what) {
|
|
|
82
82
|
}
|
|
83
83
|
throw new ContractViolation(`${what}: the promise did not reject`);
|
|
84
84
|
}
|
|
85
|
-
/** The entries sorted by id, for a comparison where the order is not part of the contract. */
|
|
86
|
-
export function byId(entries) {
|
|
87
|
-
return [...entries].map(([id, value]) => [id, value]).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
88
|
-
}
|
|
89
85
|
//# sourceMappingURL=check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/testing/check.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yDAAyD;AACzD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACxB,IAAI,GAAG,mBAAmB,CAAC;CAC9C;AAED,gGAAgG;AAChG,MAAM,UAAU,IAAI,CAAC,KAAc;IACjC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAC5C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAa,EAAE,EAAE,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1J,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,C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KAAK,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,iBAAiB,CAAC,GAAG,IAAI,8BAA8B,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
*
|
|
16
16
|
* describeCollectionStorageContract("MyStorage", { create: () => new MyStorage() }, { describe, it });
|
|
17
17
|
* ```
|
|
18
|
+
*
|
|
19
|
+
* The suite has no option that hides a difference of a storage. Each storage keeps copies, keeps
|
|
20
|
+
* a stored `null`, gives a delta in the order of the last change of each id, and rejects each
|
|
21
|
+
* operation after `close()`.
|
|
18
22
|
*/
|
|
19
23
|
import type { CollectionStorage } from "../storage/interface.js";
|
|
20
24
|
/** The item of the suite. Its `id` is its key, so a `HybridStorage` can sync it. */
|
|
@@ -25,26 +29,18 @@ export interface ContractItem {
|
|
|
25
29
|
}
|
|
26
30
|
/** A storage of the suite. */
|
|
27
31
|
export type ContractStorage = CollectionStorage<ContractItem>;
|
|
28
|
-
/** The options of the suite: the
|
|
32
|
+
/** The options of the suite: the factories of the storage. */
|
|
29
33
|
export interface CollectionStorageContractOptions {
|
|
30
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* This function makes a new, empty storage for each case. The case closes it at its end, also
|
|
36
|
+
* when the case closed it already.
|
|
37
|
+
*/
|
|
31
38
|
create(): ContractStorage | Promise<ContractStorage>;
|
|
32
39
|
/**
|
|
33
40
|
* This function makes a new, empty storage whose change log keeps at most `max` deletes. With it,
|
|
34
41
|
* the suite tests the drop of the old deletes. A storage without such a limit does not give it.
|
|
35
42
|
*/
|
|
36
43
|
createWithMaxTombstones?: ((max: number) => ContractStorage | Promise<ContractStorage>) | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* True when the storage keeps a copy of each value: a change of a value after `set`, or of a read
|
|
39
|
-
* value, does not change the stored item. The interface does not ask for copies, so the default
|
|
40
|
-
* is false, and the suite then does not test them.
|
|
41
|
-
*/
|
|
42
|
-
copies?: boolean | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* False when a stored `null` reads back as `undefined`. A remote storage can lose the difference
|
|
45
|
-
* on the wire. The default is true.
|
|
46
|
-
*/
|
|
47
|
-
nullValues?: boolean | undefined;
|
|
48
44
|
}
|
|
49
45
|
/** The context that a test framework gives to a case. Vitest gives `skip`. */
|
|
50
46
|
export interface ContractTestContext {
|
|
@@ -62,8 +58,8 @@ export interface ContractTestApi {
|
|
|
62
58
|
}
|
|
63
59
|
/**
|
|
64
60
|
* This function gives the cases of the contract for a storage. Each case makes its own storage
|
|
65
|
-
* with `options.create`. A case for an optional method (`getEntries`, `
|
|
66
|
-
* `getMetadata`) skips a storage without the method.
|
|
61
|
+
* with `options.create`. A case for an optional method (`getEntries`, `getIds`, `getChangesSince`,
|
|
62
|
+
* `flush`, `getMetadata`) skips a storage without the method.
|
|
67
63
|
*/
|
|
68
64
|
export declare function collectionStorageContract(options: CollectionStorageContractOptions): ContractCase[];
|
|
69
65
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-contract.d.ts","sourceRoot":"","sources":["../../src/testing/storage-contract.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"storage-contract.d.ts","sourceRoot":"","sources":["../../src/testing/storage-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,yBAAyB,CAAC;AAGjF,oFAAoF;AACpF,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,8BAA8B;AAC9B,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;AAE9D,8DAA8D;AAC9D,MAAM,WAAW,gCAAgC;IAC/C;;;OAGG;IACH,MAAM,IAAI,eAAe,GAAG,OAAO,CAAC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