@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage/storage.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/storage/storage.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,uBAAuB,EACvB,sBAAsB,GAEzB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAK9C,MAAM,OAAO,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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,CAAC,GAAW,EAAE,QAAgB,CAAC;QACpC,OAAO,IAAI,WAAW,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,WAAW,CAAC,KAAK,IAAI,EAAE;YAC9B,MAAM,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -13,7 +13,3 @@ export type IInitizable = {
|
|
|
13
13
|
};
|
|
14
14
|
export type Func<TArgs extends unknown[], TReturn> = (...args_: TArgs) => TReturn;
|
|
15
15
|
export type GetOrAddValue<TValue> = Awaited<TValue extends AnyFunction ? ReturnType<TValue> : TValue>;
|
|
16
|
-
export type GetOrAddResult<TValue> = {
|
|
17
|
-
value: TValue;
|
|
18
|
-
hasKey: boolean;
|
|
19
|
-
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Storage
|
|
3
3
|
*/
|
|
4
|
-
import type { GetOrAddResult } from "../../_shared/types";
|
|
5
4
|
/**
|
|
6
5
|
* @throws {StorageError} {@link StorageError}
|
|
7
6
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
@@ -9,64 +8,46 @@ import type { GetOrAddResult } from "../../_shared/types";
|
|
|
9
8
|
* @group Contracts
|
|
10
9
|
*/
|
|
11
10
|
export type IStorageAdapter<TType> = {
|
|
12
|
-
/**
|
|
13
|
-
* Returns true for the keys that are found otherwise false will be returned.
|
|
14
|
-
* @throws {StorageError} {@link StorageError}
|
|
15
|
-
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
16
|
-
*/
|
|
17
|
-
existsMany?<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
|
|
18
11
|
/**
|
|
19
12
|
* Returns the value for the keys that are found otherwise null will be returned.
|
|
20
13
|
* @throws {StorageError} {@link StorageError}
|
|
21
14
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
22
15
|
*/
|
|
23
|
-
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]):
|
|
16
|
+
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]): PromiseLike<Record<TKeys, TValues | null>>;
|
|
24
17
|
/**
|
|
25
18
|
* Adds the keys that doesn't exists. Returns true for the keys that doesn't exists otherwise false will be returned.
|
|
26
19
|
* @throws {StorageError} {@link StorageError}
|
|
27
20
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
28
21
|
*/
|
|
29
|
-
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>):
|
|
22
|
+
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): PromiseLike<Record<TKeys, boolean>>;
|
|
30
23
|
/**
|
|
31
24
|
* Updates the keys that exists. Returns true for the keys that exists otherwise false will be returned.
|
|
32
25
|
* @throws {StorageError} {@link StorageError}
|
|
33
26
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
34
27
|
*/
|
|
35
|
-
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>):
|
|
28
|
+
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): PromiseLike<Record<TKeys, boolean>>;
|
|
36
29
|
/**
|
|
37
30
|
* Replaces the keys that are found. Adds keys that are not found. Returns true for all the keys that are found otherwise false is returned.
|
|
38
31
|
* @throws {StorageError} {@link StorageError}
|
|
39
32
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
40
33
|
*/
|
|
41
|
-
putMany
|
|
34
|
+
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): PromiseLike<Record<TKeys, boolean>>;
|
|
42
35
|
/**
|
|
43
36
|
* Removes the keys that are found. Returns true for the keys that are found otherwise false is returned.
|
|
44
37
|
* @throws {StorageError} {@link StorageError}
|
|
45
38
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
46
39
|
*/
|
|
47
|
-
removeMany<TKeys extends string>(keys: TKeys[]):
|
|
48
|
-
/**
|
|
49
|
-
* If the key is found the value be returned and key will be removed otherwise null will be returned.
|
|
50
|
-
* @throws {StorageError} {@link StorageError}
|
|
51
|
-
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
52
|
-
*/
|
|
53
|
-
getAndRemove?<TValue extends TType>(key: string): Promise<TValue | null>;
|
|
54
|
-
/**
|
|
55
|
-
* If the key is found the value be returned otherwise valueToAdd will be added and returned.
|
|
56
|
-
* @throws {StorageError} {@link StorageError}
|
|
57
|
-
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
58
|
-
*/
|
|
59
|
-
getOrAdd?<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: TExtended): Promise<GetOrAddResult<TValue | TExtended>>;
|
|
40
|
+
removeMany<TKeys extends string>(keys: TKeys[]): PromiseLike<Record<TKeys, boolean>>;
|
|
60
41
|
/**
|
|
61
42
|
* Will increment the existing key with value if found otherwise nonthing occurs. Returns true if key exists otherwise false will be returned.
|
|
62
43
|
* @throws {StorageError} {@link StorageError}
|
|
63
44
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
64
45
|
* @throws {TypeStorageError} {@link TypeStorageError}
|
|
65
46
|
*/
|
|
66
|
-
increment
|
|
47
|
+
increment(key: string, value: number): PromiseLike<boolean>;
|
|
67
48
|
/**
|
|
68
49
|
* @throws {StorageError} {@link StorageError}
|
|
69
50
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
70
51
|
*/
|
|
71
|
-
clear(prefix: string):
|
|
52
|
+
clear(prefix: string): PromiseLike<void>;
|
|
72
53
|
};
|
|
@@ -16,133 +16,133 @@ export type IStorage<TType = unknown> = {
|
|
|
16
16
|
* @throws {StorageError} {@link StorageError}
|
|
17
17
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
18
18
|
*/
|
|
19
|
-
exists(key: string):
|
|
19
|
+
exists(key: string): PromiseLike<boolean>;
|
|
20
20
|
/**
|
|
21
21
|
* Returns true for the keys that are found otherwise false will be returned.
|
|
22
22
|
* @throws {StorageError} {@link StorageError}
|
|
23
23
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
24
24
|
*/
|
|
25
|
-
existsMany<TKeys extends string>(keys: TKeys[]):
|
|
25
|
+
existsMany<TKeys extends string>(keys: TKeys[]): PromiseLike<Record<TKeys, boolean>>;
|
|
26
26
|
/**
|
|
27
27
|
* Returns true when key is not found otherwise false will be returned.
|
|
28
28
|
* @throws {StorageError} {@link StorageError}
|
|
29
29
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
30
30
|
*/
|
|
31
|
-
missing(key: string):
|
|
31
|
+
missing(key: string): PromiseLike<boolean>;
|
|
32
32
|
/**
|
|
33
33
|
* Returns true for the keys that are not found otherwise false will be returned.
|
|
34
34
|
* @throws {StorageError} {@link StorageError}
|
|
35
35
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
36
36
|
*/
|
|
37
|
-
missingMany<TKeys extends string>(keys: TKeys[]):
|
|
37
|
+
missingMany<TKeys extends string>(keys: TKeys[]): PromiseLike<Record<TKeys, boolean>>;
|
|
38
38
|
/**
|
|
39
39
|
* Returns the value when key is found otherwise null will be returned.
|
|
40
40
|
* @throws {StorageError} {@link StorageError}
|
|
41
41
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
42
42
|
*/
|
|
43
|
-
get<TValue extends TType>(key: string):
|
|
43
|
+
get<TValue extends TType>(key: string): PromiseLike<TValue | null>;
|
|
44
44
|
/**
|
|
45
45
|
* Returns the value for the keys that are found otherwise null will be returned.
|
|
46
46
|
* @throws {StorageError} {@link StorageError}
|
|
47
47
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
48
48
|
*/
|
|
49
|
-
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]):
|
|
49
|
+
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]): PromiseLike<Record<TKeys, TValues | null>>;
|
|
50
50
|
/**
|
|
51
51
|
* Returns the value when key is found otherwise defaultValue will be returned.
|
|
52
52
|
* @throws {StorageError} {@link StorageError}
|
|
53
53
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
54
54
|
*/
|
|
55
|
-
getOr<TValue extends TType, TExtended extends TType>(key: string, defaultValue: AsyncLazyable<TExtended>):
|
|
55
|
+
getOr<TValue extends TType, TExtended extends TType>(key: string, defaultValue: AsyncLazyable<TExtended>): PromiseLike<TValue | TExtended>;
|
|
56
56
|
/**
|
|
57
57
|
* Returns the value for the keys that are found otherwise defaultValue will be returned.
|
|
58
58
|
* @throws {StorageError} {@link StorageError}
|
|
59
59
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
60
60
|
*/
|
|
61
|
-
getOrMany<TValues extends TType, TExtended extends TType, TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TExtended>>):
|
|
61
|
+
getOrMany<TValues extends TType, TExtended extends TType, TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TExtended>>): PromiseLike<Record<TKeys, TValues | TExtended>>;
|
|
62
62
|
/**
|
|
63
63
|
* Returns the value when key is found otherwise an error will be thrown.
|
|
64
64
|
* @throws {StorageError} {@link StorageError}
|
|
65
65
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
66
66
|
* @throws {KeyNotFoundStorageError} {@link KeyNotFoundStorageError}
|
|
67
67
|
*/
|
|
68
|
-
getOrFail<TValue extends TType>(key: string):
|
|
68
|
+
getOrFail<TValue extends TType>(key: string): PromiseLike<TValue>;
|
|
69
69
|
/**
|
|
70
70
|
* Adds a key when key doesn't exists. Returns true when key doesn't exists otherwise false will be returned.
|
|
71
71
|
* @throws {StorageError} {@link StorageError}
|
|
72
72
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
73
73
|
*/
|
|
74
|
-
add<TValue extends TType>(key: string, value: StorageValue<TValue>):
|
|
74
|
+
add<TValue extends TType>(key: string, value: StorageValue<TValue>): PromiseLike<boolean>;
|
|
75
75
|
/**
|
|
76
76
|
* Adds the keys that doesn't exists. Returns true for the keys that doesn't exists otherwise false will be returned.
|
|
77
77
|
* @throws {StorageError} {@link StorageError}
|
|
78
78
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
79
79
|
*/
|
|
80
|
-
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>):
|
|
80
|
+
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>): PromiseLike<Record<TKeys, boolean>>;
|
|
81
81
|
/**
|
|
82
82
|
* Updates a keys that exists. Returns true when key otherwise false will be returned.
|
|
83
83
|
* @throws {StorageError} {@link StorageError}
|
|
84
84
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
85
85
|
*/
|
|
86
|
-
update<TValue extends TType>(key: string, value: TValue):
|
|
86
|
+
update<TValue extends TType>(key: string, value: TValue): PromiseLike<boolean>;
|
|
87
87
|
/**
|
|
88
88
|
* Updates the keys that exists. Returns true for the keys that exists otherwise false will be returned.
|
|
89
89
|
* @throws {StorageError} {@link StorageError}
|
|
90
90
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
91
91
|
*/
|
|
92
|
-
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>):
|
|
92
|
+
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): PromiseLike<Record<TKeys, boolean>>;
|
|
93
93
|
/**
|
|
94
94
|
* If the key is found it will replaced. If the key is not found it will just be added. True is returned if the key is found otherwise false will be returned.
|
|
95
95
|
* @throws {StorageError} {@link StorageError}
|
|
96
96
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
97
97
|
*/
|
|
98
|
-
put<TValue extends TType>(key: string, value: StorageValue<TValue>):
|
|
98
|
+
put<TValue extends TType>(key: string, value: StorageValue<TValue>): PromiseLike<boolean>;
|
|
99
99
|
/**
|
|
100
100
|
* Replaces the keys that are found. Adds keys that are not found. Returns true for all the keys that are found otherwise false is returned.
|
|
101
101
|
* @throws {StorageError} {@link StorageError}
|
|
102
102
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
103
103
|
*/
|
|
104
|
-
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>):
|
|
104
|
+
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>): PromiseLike<Record<TKeys, boolean>>;
|
|
105
105
|
/**
|
|
106
106
|
* Removes the key when found. Returns true if the key is found otherwise false is returned.
|
|
107
107
|
* @throws {StorageError} {@link StorageError}
|
|
108
108
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
109
109
|
*/
|
|
110
|
-
remove(key: string):
|
|
110
|
+
remove(key: string): PromiseLike<boolean>;
|
|
111
111
|
/**
|
|
112
112
|
* Removes the keys that are found. Returns true for the keys that are found otherwise false is returned.
|
|
113
113
|
* @throws {StorageError} {@link StorageError}
|
|
114
114
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
115
115
|
*/
|
|
116
|
-
removeMany<TKeys extends string>(keys: TKeys[]):
|
|
116
|
+
removeMany<TKeys extends string>(keys: TKeys[]): PromiseLike<Record<TKeys, boolean>>;
|
|
117
117
|
/**
|
|
118
118
|
* If the key is found the value be returned and key will be removed otherwise null will be returned.
|
|
119
119
|
* @throws {StorageError} {@link StorageError}
|
|
120
120
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
121
121
|
*/
|
|
122
|
-
getAndRemove<TValue extends TType>(key: string):
|
|
122
|
+
getAndRemove<TValue extends TType>(key: string): PromiseLike<TValue | null>;
|
|
123
123
|
/**
|
|
124
124
|
* If the key is found the value be returned otherwise valueToAdd will be added and returned.
|
|
125
125
|
* @throws {StorageError} {@link StorageError}
|
|
126
126
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
127
127
|
*/
|
|
128
|
-
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: AsyncLazyable<StorageValue<GetOrAddValue<TExtended>>>):
|
|
128
|
+
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: AsyncLazyable<StorageValue<GetOrAddValue<TExtended>>>): PromiseLike<TValue | TExtended>;
|
|
129
129
|
/**
|
|
130
130
|
* Will increment the existing key with value if found otherwise nonthing will occur. Returns true if key exists otherwise false will be returned.
|
|
131
131
|
* @throws {StorageError} {@link StorageError}
|
|
132
132
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
133
133
|
* @throws {TypeStorageError} {@link TypeStorageError}
|
|
134
134
|
*/
|
|
135
|
-
increment(key: string, value?: number):
|
|
135
|
+
increment(key: string, value?: number): PromiseLike<boolean>;
|
|
136
136
|
/**
|
|
137
137
|
* Will decrement the existing key with value if found otherwise nonthing will occur. Returns true if key exists otherwise false will be returned.
|
|
138
138
|
* @throws {StorageError} {@link StorageError}
|
|
139
139
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
140
140
|
* @throws {TypeStorageError} {@link TypeStorageError}
|
|
141
141
|
*/
|
|
142
|
-
decrement(key: string, value?: number):
|
|
142
|
+
decrement(key: string, value?: number): PromiseLike<boolean>;
|
|
143
143
|
/**
|
|
144
144
|
* @throws {StorageError} {@link StorageError}
|
|
145
145
|
* @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
|
|
146
146
|
*/
|
|
147
|
-
clear():
|
|
147
|
+
clear(): PromiseLike<void>;
|
|
148
148
|
};
|
|
@@ -8,6 +8,8 @@ import { type IStorageAdapter } from "../../contracts/storage/storage-adapter.co
|
|
|
8
8
|
export declare class MemoryStorageAdapter<TType> implements IStorageAdapter<TType> {
|
|
9
9
|
private readonly map;
|
|
10
10
|
constructor(map?: Map<string, TType>);
|
|
11
|
+
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
12
|
+
increment(key: string, value: number): Promise<boolean>;
|
|
11
13
|
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, TValues | null>>;
|
|
12
14
|
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
13
15
|
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @module Storage
|
|
3
3
|
*/
|
|
4
4
|
import { type ISerializer } from "../../contracts/serializer/_module";
|
|
5
|
-
import type { GetOrAddResult } from "../../_shared/types";
|
|
6
5
|
import { type IInitizable } from "../../_shared/types";
|
|
7
6
|
import { type IStorageAdapter } from "../../contracts/storage/_module";
|
|
8
7
|
import { type Collection, ObjectId } from "mongodb";
|
|
@@ -39,8 +38,6 @@ export declare class MongodbStorageAdapter<TType> implements IStorageAdapter<TTy
|
|
|
39
38
|
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
40
39
|
private removeOne;
|
|
41
40
|
removeMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
|
|
42
|
-
getAndRemove<TValue extends TType>(key: string): Promise<TValue | null>;
|
|
43
|
-
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: TExtended): Promise<GetOrAddResult<TValue | TExtended>>;
|
|
44
41
|
increment(key: string, value: number): Promise<boolean>;
|
|
45
42
|
clear(prefix: string): Promise<void>;
|
|
46
43
|
}
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Storage
|
|
3
3
|
*/
|
|
4
|
-
import type { AsyncLazyable } from "../_shared/types";
|
|
5
4
|
import { type IStorageAdapter } from "../contracts/storage/_module";
|
|
6
|
-
import type { UsableStorageAdapter } from "../storage/usable-storage-adapter";
|
|
7
5
|
/**
|
|
8
6
|
* @internal
|
|
9
7
|
*/
|
|
10
8
|
export declare class NamespaceStorageAdapter<TType> implements Required<Omit<IStorageAdapter<TType>, "clear" | "getOrAdd">> {
|
|
11
|
-
private readonly
|
|
9
|
+
private readonly storageAdapter;
|
|
12
10
|
private readonly namespace;
|
|
13
|
-
constructor(
|
|
11
|
+
constructor(storageAdapter: IStorageAdapter<TType>, namespace: string);
|
|
14
12
|
private withNamespace;
|
|
15
13
|
private withNamespaceArray;
|
|
16
14
|
private withNamespaceObject;
|
|
17
15
|
private withoutNamespace;
|
|
18
16
|
private withoutNamespaceObject;
|
|
19
|
-
existsMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
|
|
20
17
|
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, TValues | null>>;
|
|
21
18
|
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
22
19
|
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
23
20
|
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
24
21
|
removeMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
|
|
25
|
-
getAndRemove<TValue extends TType>(key: string): Promise<TValue | null>;
|
|
26
|
-
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: AsyncLazyable<TExtended>): Promise<TValue | TExtended>;
|
|
27
22
|
increment(key: string, value: number): Promise<boolean>;
|
|
28
23
|
decrement(key: string, value: number): Promise<boolean>;
|
|
29
24
|
clear(): Promise<void>;
|
|
@@ -5,7 +5,6 @@ import { type ISerializer } from "../../contracts/serializer/_module";
|
|
|
5
5
|
import { type IStorageAdapter } from "../../contracts/storage/_module";
|
|
6
6
|
import type Redis from "ioredis";
|
|
7
7
|
import { type Result } from "ioredis";
|
|
8
|
-
import type { GetOrAddResult } from "../../_shared/types";
|
|
9
8
|
declare module "ioredis" {
|
|
10
9
|
interface RedisCommander<Context> {
|
|
11
10
|
daiso_storage_increment(key: string, number: string): Result<number, Context>;
|
|
@@ -34,8 +33,6 @@ export declare class RedisStorageAdapter<TType> implements IStorageAdapter<TType
|
|
|
34
33
|
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
35
34
|
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
36
35
|
removeMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
|
|
37
|
-
getAndRemove<TValue extends TType>(key: string): Promise<TValue | null>;
|
|
38
|
-
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: TExtended): Promise<GetOrAddResult<TValue | TExtended>>;
|
|
39
36
|
increment(key: string, value: number): Promise<boolean>;
|
|
40
37
|
clear(prefix: string): Promise<void>;
|
|
41
38
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { type IStorageAdapter } from "../../../contracts/storage/storage-adapter.contract";
|
|
5
5
|
import { type Generated, type Kysely } from "kysely";
|
|
6
6
|
import { type ISerializer } from "../../../contracts/serializer/_module";
|
|
7
|
-
import type { GetOrAddResult } from "../../../_shared/types";
|
|
8
7
|
import { type IInitizable } from "../../../_shared/types";
|
|
9
8
|
/**
|
|
10
9
|
* @internal
|
|
@@ -33,8 +32,6 @@ export declare class BaseSqliteStorageAdapter<TType> implements IStorageAdapter<
|
|
|
33
32
|
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
34
33
|
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
35
34
|
removeMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
|
|
36
|
-
getAndRemove<TValue extends TType>(key: string): Promise<TValue | null>;
|
|
37
|
-
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: TExtended): Promise<GetOrAddResult<TValue | TExtended>>;
|
|
38
35
|
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
|
|
39
36
|
increment(key: string, value: number): Promise<boolean>;
|
|
40
37
|
clear(prefix: string): Promise<void>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { type IStorageAdapter } from "../contracts/storage/_module";
|
|
5
5
|
import { type StorageValue, type IStorage } from "../contracts/storage/_module";
|
|
6
6
|
import { type AsyncLazyable, type GetOrAddValue } from "../_shared/types";
|
|
7
|
+
import { LazyPromise } from "../async/_module";
|
|
7
8
|
export type StorageSettings = {
|
|
8
9
|
namespace?: string;
|
|
9
10
|
};
|
|
@@ -11,28 +12,28 @@ export declare class Storage<TType = unknown> implements IStorage<TType> {
|
|
|
11
12
|
private readonly storageAdapter;
|
|
12
13
|
private readonly namespaceStorageAdapter;
|
|
13
14
|
private readonly settings;
|
|
14
|
-
constructor(storageAdapter: IStorageAdapter<TType>,
|
|
15
|
+
constructor(storageAdapter: IStorageAdapter<TType>, { namespace }?: StorageSettings);
|
|
15
16
|
namespace<TNamespaceType extends TType>(name: string): IStorage<TNamespaceType>;
|
|
16
|
-
exists(key: string):
|
|
17
|
-
existsMany<TKeys extends string>(keys: TKeys[]):
|
|
18
|
-
missing(key: string):
|
|
19
|
-
missingMany<TKeys extends string>(keys: TKeys[]):
|
|
20
|
-
get<TValue extends TType>(key: string):
|
|
21
|
-
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]):
|
|
22
|
-
getOr<TValue extends TType, TExtended extends TType>(key: string, defaultValue: AsyncLazyable<TExtended>):
|
|
23
|
-
getOrMany<TValues extends TType, TExtended extends TType, TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TExtended>>):
|
|
24
|
-
getOrFail<TValue extends TType>(key: string):
|
|
25
|
-
add<TValue extends TType>(key: string, value: StorageValue<TValue>):
|
|
26
|
-
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>):
|
|
27
|
-
update<TValue extends TType>(key: string, value: TValue):
|
|
28
|
-
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>):
|
|
29
|
-
put<TValue extends TType>(key: string, value: StorageValue<TValue>):
|
|
30
|
-
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>):
|
|
31
|
-
remove(key: string):
|
|
32
|
-
removeMany<TKeys extends string>(keys: TKeys[]):
|
|
33
|
-
getAndRemove<TValue extends TType>(key: string):
|
|
34
|
-
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: AsyncLazyable<StorageValue<GetOrAddValue<TExtended>>>):
|
|
35
|
-
increment(key: string, value?: number):
|
|
36
|
-
decrement(key: string, value?: number):
|
|
37
|
-
clear():
|
|
17
|
+
exists(key: string): LazyPromise<boolean>;
|
|
18
|
+
existsMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
|
|
19
|
+
missing(key: string): LazyPromise<boolean>;
|
|
20
|
+
missingMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
|
|
21
|
+
get<TValue extends TType>(key: string): LazyPromise<TValue | null>;
|
|
22
|
+
getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, TValues | null>>;
|
|
23
|
+
getOr<TValue extends TType, TExtended extends TType>(key: string, defaultValue: AsyncLazyable<TExtended>): LazyPromise<TValue | TExtended>;
|
|
24
|
+
getOrMany<TValues extends TType, TExtended extends TType, TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TExtended>>): LazyPromise<Record<TKeys, TValues | TExtended>>;
|
|
25
|
+
getOrFail<TValue extends TType>(key: string): LazyPromise<TValue>;
|
|
26
|
+
add<TValue extends TType>(key: string, value: StorageValue<TValue>): LazyPromise<boolean>;
|
|
27
|
+
addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>): LazyPromise<Record<TKeys, boolean>>;
|
|
28
|
+
update<TValue extends TType>(key: string, value: TValue): LazyPromise<boolean>;
|
|
29
|
+
updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): LazyPromise<Record<TKeys, boolean>>;
|
|
30
|
+
put<TValue extends TType>(key: string, value: StorageValue<TValue>): LazyPromise<boolean>;
|
|
31
|
+
putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>): LazyPromise<Record<TKeys, boolean>>;
|
|
32
|
+
remove(key: string): LazyPromise<boolean>;
|
|
33
|
+
removeMany<TKeys extends string>(keys: TKeys[]): LazyPromise<Record<TKeys, boolean>>;
|
|
34
|
+
getAndRemove<TValue extends TType>(key: string): LazyPromise<TValue | null>;
|
|
35
|
+
getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: AsyncLazyable<StorageValue<GetOrAddValue<TExtended>>>): LazyPromise<TValue | TExtended>;
|
|
36
|
+
increment(key: string, value?: number): LazyPromise<boolean>;
|
|
37
|
+
decrement(key: string, value?: number): LazyPromise<boolean>;
|
|
38
|
+
clear(): LazyPromise<void>;
|
|
38
39
|
}
|
package/package.json
CHANGED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UsableStorageAdapter = void 0;
|
|
4
|
-
const utilities_1 = require("../_shared/utilities");
|
|
5
|
-
const _module_1 = require("../contracts/storage/_module");
|
|
6
|
-
class UsableStorageAdapter {
|
|
7
|
-
storageAdapter;
|
|
8
|
-
constructor(storageAdapter) {
|
|
9
|
-
this.storageAdapter = storageAdapter;
|
|
10
|
-
}
|
|
11
|
-
async existsMany(keys) {
|
|
12
|
-
if (this.storageAdapter.existsMany !== undefined) {
|
|
13
|
-
return await this.storageAdapter.existsMany(keys);
|
|
14
|
-
}
|
|
15
|
-
const getResult = await this.getMany(keys);
|
|
16
|
-
const results = {};
|
|
17
|
-
for (const key in getResult) {
|
|
18
|
-
results[key] = getResult[key] !== null;
|
|
19
|
-
}
|
|
20
|
-
return results;
|
|
21
|
-
}
|
|
22
|
-
async getMany(keys) {
|
|
23
|
-
return await this.storageAdapter.getMany(keys);
|
|
24
|
-
}
|
|
25
|
-
async addMany(values) {
|
|
26
|
-
return await this.storageAdapter.addMany(values);
|
|
27
|
-
}
|
|
28
|
-
async updateMany(values) {
|
|
29
|
-
return await this.storageAdapter.updateMany(values);
|
|
30
|
-
}
|
|
31
|
-
async putMany(values) {
|
|
32
|
-
if (this.storageAdapter.putMany !== undefined) {
|
|
33
|
-
return await this.storageAdapter.putMany(values);
|
|
34
|
-
}
|
|
35
|
-
const removeResults = await this.removeMany(Object.keys(values));
|
|
36
|
-
await this.addMany(values);
|
|
37
|
-
return removeResults;
|
|
38
|
-
}
|
|
39
|
-
async removeMany(keys) {
|
|
40
|
-
return await this.storageAdapter.removeMany(keys);
|
|
41
|
-
}
|
|
42
|
-
async increment(key, value) {
|
|
43
|
-
if (this.storageAdapter.increment !== undefined) {
|
|
44
|
-
return await this.storageAdapter.increment(key, value);
|
|
45
|
-
}
|
|
46
|
-
const { [key]: previousValue } = await this.getMany([key]);
|
|
47
|
-
if (previousValue === undefined) {
|
|
48
|
-
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
49
|
-
}
|
|
50
|
-
if (previousValue === null) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
if (typeof previousValue !== "number") {
|
|
54
|
-
throw new _module_1.TypeStorageError(`Unable to increment or decrement none number type key "${key}"`);
|
|
55
|
-
}
|
|
56
|
-
const newValue = previousValue + value;
|
|
57
|
-
await this.updateMany({
|
|
58
|
-
[key]: newValue,
|
|
59
|
-
});
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
async getAndRemove(key) {
|
|
63
|
-
if (this.storageAdapter.getAndRemove !== undefined) {
|
|
64
|
-
return await this.storageAdapter.getAndRemove(key);
|
|
65
|
-
}
|
|
66
|
-
const { [key]: value } = await this.getMany([key]);
|
|
67
|
-
if (value === undefined) {
|
|
68
|
-
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
69
|
-
}
|
|
70
|
-
await this.removeMany([key]);
|
|
71
|
-
return value;
|
|
72
|
-
}
|
|
73
|
-
async getOrAdd(key, valueToAdd) {
|
|
74
|
-
if (typeof valueToAdd !== "function" &&
|
|
75
|
-
this.storageAdapter.getOrAdd !== undefined) {
|
|
76
|
-
return await this.storageAdapter.getOrAdd(key, valueToAdd);
|
|
77
|
-
}
|
|
78
|
-
const { [key]: value } = await this.getMany([key]);
|
|
79
|
-
if (value === undefined) {
|
|
80
|
-
throw new _module_1.UnexpectedStorageError(`Destructed field "key" is undefined`);
|
|
81
|
-
}
|
|
82
|
-
if (value === null) {
|
|
83
|
-
const valueToAddSimplified = await (0, utilities_1.simplifyAsyncLazyable)(valueToAdd);
|
|
84
|
-
await this.addMany({
|
|
85
|
-
[key]: valueToAddSimplified,
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
hasKey: false,
|
|
89
|
-
value: valueToAddSimplified,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
hasKey: true,
|
|
94
|
-
value,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
async clear(prefix) {
|
|
98
|
-
await this.storageAdapter.clear(prefix);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.UsableStorageAdapter = UsableStorageAdapter;
|
|
102
|
-
//# sourceMappingURL=usable-storage-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usable-storage-adapter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