@daiso-tech/core 0.5.0 → 0.6.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/dist/cjs/storage/memory-storage-adapter/memory-storage-adapter.js +23 -0
- package/dist/cjs/storage/memory-storage-adapter/memory-storage-adapter.js.map +1 -1
- package/dist/cjs/storage/mongodb-storage-adapter/mongodb-storage-adapter.js +0 -70
- package/dist/cjs/storage/mongodb-storage-adapter/mongodb-storage-adapter.js.map +1 -1
- package/dist/cjs/storage/namespace-storage-adapter.js +11 -21
- package/dist/cjs/storage/namespace-storage-adapter.js.map +1 -1
- package/dist/cjs/storage/redis-storage-adapter/redis-storage-adapter.js +0 -20
- package/dist/cjs/storage/redis-storage-adapter/redis-storage-adapter.js.map +1 -1
- package/dist/cjs/storage/sqlite/_shared/base-sqlite-storage-adapter.js +0 -34
- package/dist/cjs/storage/sqlite/_shared/base-sqlite-storage-adapter.js.map +1 -1
- package/dist/cjs/storage/storage.js +104 -188
- package/dist/cjs/storage/storage.js.map +1 -1
- package/dist/esm/storage/memory-storage-adapter/memory-storage-adapter.js +23 -0
- package/dist/esm/storage/memory-storage-adapter/memory-storage-adapter.js.map +1 -1
- package/dist/esm/storage/mongodb-storage-adapter/mongodb-storage-adapter.js +0 -70
- package/dist/esm/storage/mongodb-storage-adapter/mongodb-storage-adapter.js.map +1 -1
- package/dist/esm/storage/namespace-storage-adapter.js +11 -21
- package/dist/esm/storage/namespace-storage-adapter.js.map +1 -1
- package/dist/esm/storage/redis-storage-adapter/redis-storage-adapter.js +0 -20
- package/dist/esm/storage/redis-storage-adapter/redis-storage-adapter.js.map +1 -1
- package/dist/esm/storage/sqlite/_shared/base-sqlite-storage-adapter.js +0 -34
- package/dist/esm/storage/sqlite/_shared/base-sqlite-storage-adapter.js.map +1 -1
- package/dist/esm/storage/storage.js +105 -189
- package/dist/esm/storage/storage.js.map +1 -1
- package/dist/types/_shared/types.d.ts +0 -4
- package/dist/types/contracts/storage/storage-adapter.contract.d.ts +7 -26
- package/dist/types/contracts/storage/storage.contract.d.ts +22 -22
- package/dist/types/storage/memory-storage-adapter/memory-storage-adapter.d.ts +2 -0
- package/dist/types/storage/mongodb-storage-adapter/mongodb-storage-adapter.d.ts +0 -3
- package/dist/types/storage/namespace-storage-adapter.d.ts +2 -7
- package/dist/types/storage/redis-storage-adapter/redis-storage-adapter.d.ts +0 -3
- package/dist/types/storage/sqlite/_shared/base-sqlite-storage-adapter.d.ts +0 -3
- package/dist/types/storage/storage.d.ts +24 -23
- package/package.json +1 -1
- package/dist/cjs/storage/usable-storage-adapter.js +0 -102
- package/dist/cjs/storage/usable-storage-adapter.js.map +0 -1
- package/dist/esm/storage/usable-storage-adapter.js +0 -98
- package/dist/esm/storage/usable-storage-adapter.js.map +0 -1
- package/dist/types/storage/usable-storage-adapter.d.ts +0 -22
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Storage = void 0;
|
|
4
4
|
const _module_1 = require("../contracts/storage/_module");
|
|
5
|
-
const usable_storage_adapter_1 = require("../storage/usable-storage-adapter");
|
|
6
5
|
const namespace_storage_adapter_1 = require("../storage/namespace-storage-adapter");
|
|
7
6
|
const utilities_1 = require("../_shared/utilities");
|
|
7
|
+
const _module_2 = require("../async/_module");
|
|
8
8
|
class Storage {
|
|
9
9
|
storageAdapter;
|
|
10
10
|
namespaceStorageAdapter;
|
|
11
11
|
settings;
|
|
12
|
-
constructor(storageAdapter,
|
|
12
|
+
constructor(storageAdapter, { namespace = "" } = {}) {
|
|
13
13
|
this.storageAdapter = storageAdapter;
|
|
14
14
|
this.settings = {
|
|
15
|
-
namespace
|
|
16
|
-
...settings,
|
|
15
|
+
namespace,
|
|
17
16
|
};
|
|
18
|
-
this.namespaceStorageAdapter = new namespace_storage_adapter_1.NamespaceStorageAdapter(
|
|
17
|
+
this.namespaceStorageAdapter = new namespace_storage_adapter_1.NamespaceStorageAdapter(this.storageAdapter, this.settings.namespace);
|
|
19
18
|
}
|
|
20
19
|
namespace(name) {
|
|
21
20
|
return new Storage(this.storageAdapter, {
|
|
@@ -23,73 +22,55 @@ class Storage {
|
|
|
23
22
|
namespace: `${this.settings.namespace}${name}`,
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
exists(key) {
|
|
26
|
+
return new _module_2.LazyPromise(async () => {
|
|
28
27
|
const { [key]: hasKey } = await this.existsMany([key]);
|
|
29
28
|
if (hasKey === undefined) {
|
|
30
29
|
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
31
30
|
}
|
|
32
31
|
return hasKey;
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
if (error instanceof _module_1.StorageError) {
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
39
|
-
}
|
|
32
|
+
});
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw error;
|
|
34
|
+
existsMany(keys) {
|
|
35
|
+
return new _module_2.LazyPromise(async () => {
|
|
36
|
+
const getResult = await this.getMany(keys);
|
|
37
|
+
const results = {};
|
|
38
|
+
for (const key in getResult) {
|
|
39
|
+
results[key] = getResult[key] !== null;
|
|
48
40
|
}
|
|
49
|
-
|
|
50
|
-
}
|
|
41
|
+
return results;
|
|
42
|
+
});
|
|
51
43
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
missing(key) {
|
|
45
|
+
return new _module_2.LazyPromise(async () => {
|
|
46
|
+
const { [key]: hasKey } = await this.missingMany([key]);
|
|
47
|
+
if (hasKey === undefined) {
|
|
48
|
+
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
49
|
+
}
|
|
50
|
+
return hasKey;
|
|
51
|
+
});
|
|
58
52
|
}
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
key,
|
|
62
|
-
|
|
63
|
-
]));
|
|
53
|
+
missingMany(keys) {
|
|
54
|
+
return new _module_2.LazyPromise(async () => {
|
|
55
|
+
return Object.fromEntries(Object.entries(await this.existsMany(keys)).map(([key, hasKey]) => [key, !hasKey]));
|
|
56
|
+
});
|
|
64
57
|
}
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
get(key) {
|
|
59
|
+
return new _module_2.LazyPromise(async () => {
|
|
67
60
|
const { [key]: value } = await this.getMany([key]);
|
|
68
61
|
if (value === undefined) {
|
|
69
62
|
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
70
63
|
}
|
|
71
64
|
return value;
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
if (error instanceof _module_1.StorageError) {
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
78
|
-
}
|
|
65
|
+
});
|
|
79
66
|
}
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
getMany(keys) {
|
|
68
|
+
return new _module_2.LazyPromise(async () => {
|
|
82
69
|
return await this.namespaceStorageAdapter.getMany(keys);
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
if (error instanceof _module_1.StorageError) {
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
89
|
-
}
|
|
70
|
+
});
|
|
90
71
|
}
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
getOr(key, defaultValue) {
|
|
73
|
+
return new _module_2.LazyPromise(async () => {
|
|
93
74
|
const { [key]: value } = await this.getOrMany({
|
|
94
75
|
[key]: defaultValue,
|
|
95
76
|
});
|
|
@@ -97,16 +78,10 @@ class Storage {
|
|
|
97
78
|
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
98
79
|
}
|
|
99
80
|
return value;
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
if (error instanceof _module_1.StorageError) {
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
106
|
-
}
|
|
81
|
+
});
|
|
107
82
|
}
|
|
108
|
-
|
|
109
|
-
|
|
83
|
+
getOrMany(keysWithDefaults) {
|
|
84
|
+
return new _module_2.LazyPromise(async () => {
|
|
110
85
|
const getManyResult = await this.getMany(Object.keys(keysWithDefaults));
|
|
111
86
|
const result = {};
|
|
112
87
|
for (const key in getManyResult) {
|
|
@@ -123,31 +98,19 @@ class Storage {
|
|
|
123
98
|
}
|
|
124
99
|
}
|
|
125
100
|
return result;
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
if (error instanceof _module_1.StorageError) {
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
132
|
-
}
|
|
101
|
+
});
|
|
133
102
|
}
|
|
134
|
-
|
|
135
|
-
|
|
103
|
+
getOrFail(key) {
|
|
104
|
+
return new _module_2.LazyPromise(async () => {
|
|
136
105
|
const value = await this.get(key);
|
|
137
106
|
if (value === null) {
|
|
138
107
|
throw new _module_1.KeyNotFoundStorageError(`Key "${key}" is not found`);
|
|
139
108
|
}
|
|
140
109
|
return value;
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
if (error instanceof _module_1.StorageError) {
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
147
|
-
}
|
|
110
|
+
});
|
|
148
111
|
}
|
|
149
|
-
|
|
150
|
-
|
|
112
|
+
add(key, value) {
|
|
113
|
+
return new _module_2.LazyPromise(async () => {
|
|
151
114
|
const { [key]: hasAdded } = await this.addMany({
|
|
152
115
|
[key]: value,
|
|
153
116
|
});
|
|
@@ -155,39 +118,31 @@ class Storage {
|
|
|
155
118
|
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
156
119
|
}
|
|
157
120
|
return hasAdded;
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
if (error instanceof _module_1.StorageError) {
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
164
|
-
}
|
|
121
|
+
});
|
|
165
122
|
}
|
|
166
|
-
|
|
167
|
-
|
|
123
|
+
addMany(values) {
|
|
124
|
+
return new _module_2.LazyPromise(async () => {
|
|
168
125
|
return await this.namespaceStorageAdapter.addMany(values);
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
if (error instanceof _module_1.StorageError) {
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
174
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
175
|
-
}
|
|
126
|
+
});
|
|
176
127
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
[key]:
|
|
128
|
+
update(key, value) {
|
|
129
|
+
return new _module_2.LazyPromise(async () => {
|
|
130
|
+
const { [key]: hasKey } = await this.updateMany({
|
|
131
|
+
[key]: value,
|
|
132
|
+
});
|
|
133
|
+
if (hasKey === undefined) {
|
|
134
|
+
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
135
|
+
}
|
|
136
|
+
return hasKey;
|
|
180
137
|
});
|
|
181
|
-
if (hasKey === undefined) {
|
|
182
|
-
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
183
|
-
}
|
|
184
|
-
return hasKey;
|
|
185
138
|
}
|
|
186
|
-
|
|
187
|
-
return
|
|
139
|
+
updateMany(values) {
|
|
140
|
+
return new _module_2.LazyPromise(async () => {
|
|
141
|
+
return await this.namespaceStorageAdapter.updateMany(values);
|
|
142
|
+
});
|
|
188
143
|
}
|
|
189
|
-
|
|
190
|
-
|
|
144
|
+
put(key, value) {
|
|
145
|
+
return new _module_2.LazyPromise(async () => {
|
|
191
146
|
const { [key]: hasAdded } = await this.putMany({
|
|
192
147
|
[key]: value,
|
|
193
148
|
});
|
|
@@ -195,106 +150,67 @@ class Storage {
|
|
|
195
150
|
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
196
151
|
}
|
|
197
152
|
return hasAdded;
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
if (error instanceof _module_1.StorageError) {
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
203
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
204
|
-
}
|
|
153
|
+
});
|
|
205
154
|
}
|
|
206
|
-
|
|
207
|
-
|
|
155
|
+
putMany(values) {
|
|
156
|
+
return new _module_2.LazyPromise(async () => {
|
|
208
157
|
return await this.namespaceStorageAdapter.putMany(values);
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
if (error instanceof _module_1.StorageError) {
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
214
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
215
|
-
}
|
|
158
|
+
});
|
|
216
159
|
}
|
|
217
|
-
|
|
218
|
-
|
|
160
|
+
remove(key) {
|
|
161
|
+
return new _module_2.LazyPromise(async () => {
|
|
219
162
|
const { [key]: hasAdded } = await this.removeMany([key]);
|
|
220
163
|
if (hasAdded === undefined) {
|
|
221
164
|
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
222
165
|
}
|
|
223
166
|
return hasAdded;
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
if (error instanceof _module_1.StorageError) {
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
230
|
-
}
|
|
167
|
+
});
|
|
231
168
|
}
|
|
232
|
-
|
|
233
|
-
|
|
169
|
+
removeMany(keys) {
|
|
170
|
+
return new _module_2.LazyPromise(async () => {
|
|
234
171
|
return await this.namespaceStorageAdapter.removeMany(keys);
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
if (error instanceof _module_1.StorageError) {
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
241
|
-
}
|
|
172
|
+
});
|
|
242
173
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (error instanceof _module_1.StorageError) {
|
|
249
|
-
throw error;
|
|
174
|
+
getAndRemove(key) {
|
|
175
|
+
return new _module_2.LazyPromise(async () => {
|
|
176
|
+
const { [key]: value } = await this.getMany([key]);
|
|
177
|
+
if (value === undefined) {
|
|
178
|
+
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
250
179
|
}
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
async getOrAdd(key, valueToAdd) {
|
|
255
|
-
try {
|
|
256
|
-
const value = await this.namespaceStorageAdapter.getOrAdd(key, valueToAdd);
|
|
180
|
+
await this.namespaceStorageAdapter.removeMany([key]);
|
|
257
181
|
return value;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
getOrAdd(key, valueToAdd) {
|
|
185
|
+
return new _module_2.LazyPromise(async () => {
|
|
186
|
+
const { [key]: value } = await this.getMany([key]);
|
|
187
|
+
if (value === undefined) {
|
|
188
|
+
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
262
189
|
}
|
|
263
|
-
|
|
264
|
-
|
|
190
|
+
if (value === null) {
|
|
191
|
+
const valueToAddSimplified = (await (0, utilities_1.simplifyAsyncLazyable)(valueToAdd));
|
|
192
|
+
await this.namespaceStorageAdapter.addMany({
|
|
193
|
+
[key]: valueToAddSimplified,
|
|
194
|
+
});
|
|
195
|
+
return valueToAddSimplified;
|
|
196
|
+
}
|
|
197
|
+
return value;
|
|
198
|
+
});
|
|
265
199
|
}
|
|
266
|
-
|
|
267
|
-
|
|
200
|
+
increment(key, value = 1) {
|
|
201
|
+
return new _module_2.LazyPromise(async () => {
|
|
268
202
|
return await this.namespaceStorageAdapter.increment(key, value);
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
if (error instanceof _module_1.StorageError) {
|
|
272
|
-
throw error;
|
|
273
|
-
}
|
|
274
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
275
|
-
}
|
|
203
|
+
});
|
|
276
204
|
}
|
|
277
|
-
|
|
278
|
-
|
|
205
|
+
decrement(key, value = 1) {
|
|
206
|
+
return new _module_2.LazyPromise(async () => {
|
|
279
207
|
return await this.namespaceStorageAdapter.increment(key, -value);
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
if (error instanceof _module_1.StorageError) {
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
286
|
-
}
|
|
208
|
+
});
|
|
287
209
|
}
|
|
288
|
-
|
|
289
|
-
|
|
210
|
+
clear() {
|
|
211
|
+
return new _module_2.LazyPromise(async () => {
|
|
290
212
|
await this.namespaceStorageAdapter.clear();
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
if (error instanceof _module_1.StorageError) {
|
|
294
|
-
throw error;
|
|
295
|
-
}
|
|
296
|
-
throw new _module_1.UnexpectedStorageError(`Unexpected error "${String(error)}" occured`, error);
|
|
297
|
-
}
|
|
213
|
+
});
|
|
298
214
|
}
|
|
299
215
|
}
|
|
300
216
|
exports.Storage = Storage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage/storage.ts"],"names":[],"mappings":";;;AAIA,
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage/storage.ts"],"names":[],"mappings":";;;AAIA,yDAIqC;AAErC,mFAA8E;AAC9E,mDAA4D;AAE5D,6CAA8C;AAK9C,MAAa,OAAO;IAKK;IAJJ,uBAAuB,CAAiC;IACxD,QAAQ,CAA4B;IAErD,YACqB,cAAsC,EACvD,EAAE,SAAS,GAAG,EAAE,KAAsB,EAAE;QADvB,mBAAc,GAAd,cAAc,CAAwB;QAGvD,IAAI,CAAC,QAAQ,GAAG;YACZ,SAAS;SACZ,CAAC;QACF,IAAI,CAAC,uBAAuB,GAAG,IAAI,mDAAuB,CACtD,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,QAAQ,CAAC,SAAS,CAC1B,CAAC;IACN,CAAC;IAED,SAAS,CACL,IAAY;QAEZ,OAAO,IAAI,OAAO,CAAiB,IAAI,CAAC,cAAc,EAAE;YACpD,GAAG,IAAI,CAAC,QAAQ;YAChB,SAAS,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,GAAG,IAAI,EAAE;SACjD,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,GAAW;QACd,OAAO,IAAI,qBAAW,CAAC,KAAK,IAAI,EAAE;YAC9B,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACvD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,IAAI,gCAAsB,CAC5B,qCAAqC,CACxC,CAAC;YACN,CAAC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ACT,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACtB,MAAM,IAAI,gCAAsB,CAC5B,qCAAqC,CACxC,CAAC;YACN,CAAC;YACD,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACjB,MAAM,oBAAoB,GAAG,CAAC,MAAM,IAAA,iCAAqB,EACrD,UAAU,CACb,CAAc,CAAC;gBAChB,MAAM,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC;oBACvC,CAAC,GAAG,CAAC,EAAE,oBAAoB;iBAC9B,CAAC,CAAC;gBACH,OAAO,oBAAoB,CAAC;YAChC,CAAC;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,QAAgB,CAAC;QACpC,OAAO,IAAI,qBAAW,CAAC,KAAK,IAAI,EAAE;YAC9B,OAAO,MAAM,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,QAAgB,CAAC;QACpC,OAAO,IAAI,qBAAW,CAAC,KAAK,IAAI,EAAE;YAC9B,OAAO,MAAM,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK;QACD,OAAO,IAAI,qBAAW,CAAC,KAAK,IAAI,EAAE;YAC9B,MAAM,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAxTD,0BAwTC"}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
|
+
import { TypeStorageError, UnexpectedStorageError, } from "../../contracts/storage/_shared";
|
|
1
2
|
export class MemoryStorageAdapter {
|
|
2
3
|
map;
|
|
3
4
|
constructor(map = new Map()) {
|
|
4
5
|
this.map = map;
|
|
5
6
|
}
|
|
7
|
+
async putMany(values) {
|
|
8
|
+
const removeResults = await this.removeMany(Object.keys(values));
|
|
9
|
+
await this.addMany(values);
|
|
10
|
+
return removeResults;
|
|
11
|
+
}
|
|
12
|
+
async increment(key, value) {
|
|
13
|
+
const { [key]: previousValue } = await this.getMany([key]);
|
|
14
|
+
if (previousValue === undefined) {
|
|
15
|
+
throw new UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
16
|
+
}
|
|
17
|
+
if (previousValue === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (typeof previousValue !== "number") {
|
|
21
|
+
throw new TypeStorageError(`Unable to increment or decrement none number type key "${key}"`);
|
|
22
|
+
}
|
|
23
|
+
const newValue = previousValue + value;
|
|
24
|
+
await this.updateMany({
|
|
25
|
+
[key]: newValue,
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
6
29
|
getMany(keys) {
|
|
7
30
|
const values = {};
|
|
8
31
|
for (const key of keys) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-storage-adapter.js","sourceRoot":"","sources":["../../../../src/storage/memory-storage-adapter/memory-storage-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory-storage-adapter.js","sourceRoot":"","sources":["../../../../src/storage/memory-storage-adapter/memory-storage-adapter.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,gBAAgB,EAChB,sBAAsB,GACzB,MAAM,6BAA6B,CAAC;AAMrC,MAAM,OAAO,oBAAoB;IACA;IAA7B,YAA6B,MAA0B,IAAI,GAAG,EAAE;QAAnC,QAAG,GAAH,GAAG,CAAgC;IAAG,CAAC;IAEpE,KAAK,CAAC,OAAO,CACT,MAA8B;QAE9B,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QACjE,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAA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AAI,GAAa,EAAE,CAAC;QAC1B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YAChC,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC;QACL,CAAC;QACD,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACJ"}
|
|
@@ -157,76 +157,6 @@ export class MongodbStorageAdapter {
|
|
|
157
157
|
}
|
|
158
158
|
return results;
|
|
159
159
|
}
|
|
160
|
-
async getAndRemove(key) {
|
|
161
|
-
const document = (await this.collection.findOneAndDelete({
|
|
162
|
-
key,
|
|
163
|
-
}, {
|
|
164
|
-
projection: {
|
|
165
|
-
_id: 0,
|
|
166
|
-
value: 1,
|
|
167
|
-
},
|
|
168
|
-
}));
|
|
169
|
-
if (document === null) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
return await this.serializer.deserialize(document.value);
|
|
173
|
-
}
|
|
174
|
-
async getOrAdd(key, valueToAdd) {
|
|
175
|
-
const document = (await this.collection.findOneAndUpdate({
|
|
176
|
-
key,
|
|
177
|
-
}, [
|
|
178
|
-
{
|
|
179
|
-
$addFields: {
|
|
180
|
-
array: {
|
|
181
|
-
$objectToArray: "$$ROOT",
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
$addFields: {
|
|
187
|
-
size: {
|
|
188
|
-
$size: "$array",
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
$unset: "array",
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
$set: {
|
|
197
|
-
value: {
|
|
198
|
-
$cond: {
|
|
199
|
-
if: {
|
|
200
|
-
$eq: ["$size", 1],
|
|
201
|
-
},
|
|
202
|
-
then: await this.serializer.serialize(valueToAdd),
|
|
203
|
-
else: "$value",
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
$unset: "size",
|
|
210
|
-
},
|
|
211
|
-
], {
|
|
212
|
-
upsert: true,
|
|
213
|
-
projection: {
|
|
214
|
-
_id: 0,
|
|
215
|
-
value: 1,
|
|
216
|
-
},
|
|
217
|
-
}));
|
|
218
|
-
if (document === null) {
|
|
219
|
-
return {
|
|
220
|
-
hasKey: false,
|
|
221
|
-
value: valueToAdd,
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
const { value } = document;
|
|
225
|
-
return {
|
|
226
|
-
hasKey: true,
|
|
227
|
-
value: await this.serializer.deserialize(value),
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
160
|
async increment(key, value) {
|
|
231
161
|
try {
|
|
232
162
|
const mongodbResult = await this.collection.updateOne({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb-storage-adapter.js","sourceRoot":"","sources":["../../../../src/storage/mongodb-storage-adapter/mongodb-storage-adapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"mongodb-storage-adapter.js","sourceRoot":"","sources":["../../../../src/storage/mongodb-storage-adapter/mongodb-storage-adapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,OAAO,EACH,gBAAgB,EAChB,sBAAsB,GAEzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAmB,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAmBtE,MAAM,OAAO,qBAAqB;IA8BT;IA3Bb,MAAM,CAAC,uBAAuB,CAClC,KAAc;QAEd,OAAO,CACH,KA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