@daiso-tech/core 0.2.0 → 0.3.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.
Files changed (260) hide show
  1. package/dist/cjs/_module.js +3 -1
  2. package/dist/cjs/_module.js.map +1 -1
  3. package/dist/cjs/_shared/kysely/_module.js +18 -0
  4. package/dist/cjs/_shared/kysely/_module.js.map +1 -0
  5. package/dist/cjs/_shared/kysely/kysely-table-name-transformer-plugin.js +45 -0
  6. package/dist/cjs/_shared/kysely/kysely-table-name-transformer-plugin.js.map +1 -0
  7. package/dist/cjs/_shared/redis/_module.js +20 -0
  8. package/dist/cjs/_shared/redis/_module.js.map +1 -0
  9. package/dist/cjs/_shared/redis/clear-iterable.js +25 -0
  10. package/dist/cjs/_shared/redis/clear-iterable.js.map +1 -0
  11. package/dist/cjs/_shared/redis/escape-redis-chars.js +41 -0
  12. package/dist/cjs/_shared/redis/escape-redis-chars.js.map +1 -0
  13. package/dist/cjs/_shared/redis/is-redis-type-error.js +9 -0
  14. package/dist/cjs/_shared/redis/is-redis-type-error.js.map +1 -0
  15. package/dist/cjs/_shared/utilities.js.map +1 -1
  16. package/dist/cjs/collection/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
  17. package/dist/cjs/collection/async-iterable-collection/async-iterable-collection.js.map +1 -1
  18. package/dist/cjs/collection/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
  19. package/dist/cjs/contracts/_module.js +2 -0
  20. package/dist/cjs/contracts/_module.js.map +1 -1
  21. package/dist/cjs/contracts/collection/_module.js.map +1 -1
  22. package/dist/cjs/contracts/serializer/_module.js +18 -0
  23. package/dist/cjs/contracts/serializer/_module.js.map +1 -0
  24. package/dist/cjs/contracts/serializer/serializer.contract.js +25 -0
  25. package/dist/cjs/contracts/serializer/serializer.contract.js.map +1 -0
  26. package/dist/cjs/contracts/storage/_module.js +20 -0
  27. package/dist/cjs/contracts/storage/_module.js.map +1 -0
  28. package/dist/cjs/contracts/storage/_shared.js +32 -0
  29. package/dist/cjs/contracts/storage/_shared.js.map +1 -0
  30. package/dist/cjs/contracts/storage/storage-adapter.contract.js +3 -0
  31. package/dist/cjs/contracts/storage/storage-adapter.contract.js.map +1 -0
  32. package/dist/cjs/contracts/storage/storage.contract.js +3 -0
  33. package/dist/cjs/contracts/storage/storage.contract.js.map +1 -0
  34. package/dist/cjs/serializer/_module.js +22 -0
  35. package/dist/cjs/serializer/_module.js.map +1 -0
  36. package/dist/cjs/serializer/_shared/test-utilities/_module.js +18 -0
  37. package/dist/cjs/serializer/_shared/test-utilities/_module.js.map +1 -0
  38. package/dist/cjs/serializer/_shared/test-utilities/serializer.test-suite.js +361 -0
  39. package/dist/cjs/serializer/_shared/test-utilities/serializer.test-suite.js.map +1 -0
  40. package/dist/cjs/serializer/mongodb-serializer/_module.js +18 -0
  41. package/dist/cjs/serializer/mongodb-serializer/_module.js.map +1 -0
  42. package/dist/cjs/serializer/mongodb-serializer/mongodb-serializer.js +36 -0
  43. package/dist/cjs/serializer/mongodb-serializer/mongodb-serializer.js.map +1 -0
  44. package/dist/cjs/serializer/redis-serializer/_module.js +18 -0
  45. package/dist/cjs/serializer/redis-serializer/_module.js.map +1 -0
  46. package/dist/cjs/serializer/redis-serializer/redis-serializer.js +37 -0
  47. package/dist/cjs/serializer/redis-serializer/redis-serializer.js.map +1 -0
  48. package/dist/cjs/serializer/sql-serializer/_module.js +18 -0
  49. package/dist/cjs/serializer/sql-serializer/_module.js.map +1 -0
  50. package/dist/cjs/serializer/sql-serializer/sql-serializer.js +37 -0
  51. package/dist/cjs/serializer/sql-serializer/sql-serializer.js.map +1 -0
  52. package/dist/cjs/serializer/super-json-serializer/_module.js +18 -0
  53. package/dist/cjs/serializer/super-json-serializer/_module.js.map +1 -0
  54. package/dist/cjs/serializer/super-json-serializer/super-json-serializer.js +304 -0
  55. package/dist/cjs/serializer/super-json-serializer/super-json-serializer.js.map +1 -0
  56. package/dist/cjs/storage/_module.js +23 -0
  57. package/dist/cjs/storage/_module.js.map +1 -0
  58. package/dist/cjs/storage/_shared/test-utilities/_module.js +18 -0
  59. package/dist/cjs/storage/_shared/test-utilities/_module.js.map +1 -0
  60. package/dist/cjs/storage/_shared/test-utilities/storage-api.test-suite.js +572 -0
  61. package/dist/cjs/storage/_shared/test-utilities/storage-api.test-suite.js.map +1 -0
  62. package/dist/cjs/storage/_shared/test-utilities/storage-namespace.test-suite.js +241 -0
  63. package/dist/cjs/storage/_shared/test-utilities/storage-namespace.test-suite.js.map +1 -0
  64. package/dist/cjs/storage/_shared/test-utilities/storage-value.test-suite.js +4172 -0
  65. package/dist/cjs/storage/_shared/test-utilities/storage-value.test-suite.js.map +1 -0
  66. package/dist/cjs/storage/_shared/test-utilities/storage.test-suite.js +12 -0
  67. package/dist/cjs/storage/_shared/test-utilities/storage.test-suite.js.map +1 -0
  68. package/dist/cjs/storage/memory-storage-adapter/_module.js +18 -0
  69. package/dist/cjs/storage/memory-storage-adapter/_module.js.map +1 -0
  70. package/dist/cjs/storage/memory-storage-adapter/memory-storage-adapter.js +62 -0
  71. package/dist/cjs/storage/memory-storage-adapter/memory-storage-adapter.js.map +1 -0
  72. package/dist/cjs/storage/mongodb-storage-adapter/_module.js +6 -0
  73. package/dist/cjs/storage/mongodb-storage-adapter/_module.js.map +1 -0
  74. package/dist/cjs/storage/mongodb-storage-adapter/mongodb-storage-adapter.js +273 -0
  75. package/dist/cjs/storage/mongodb-storage-adapter/mongodb-storage-adapter.js.map +1 -0
  76. package/dist/cjs/storage/namespace-storage-adapter.js +66 -0
  77. package/dist/cjs/storage/namespace-storage-adapter.js.map +1 -0
  78. package/dist/cjs/storage/redis-storage-adapter/_module.js +18 -0
  79. package/dist/cjs/storage/redis-storage-adapter/_module.js.map +1 -0
  80. package/dist/cjs/storage/redis-storage-adapter/redis-storage-adapter.js +248 -0
  81. package/dist/cjs/storage/redis-storage-adapter/redis-storage-adapter.js.map +1 -0
  82. package/dist/cjs/storage/sqlite/_module.js +19 -0
  83. package/dist/cjs/storage/sqlite/_module.js.map +1 -0
  84. package/dist/cjs/storage/sqlite/_shared/_module.js +18 -0
  85. package/dist/cjs/storage/sqlite/_shared/_module.js.map +1 -0
  86. package/dist/cjs/storage/sqlite/_shared/base-sqlite-storage-adapter.js +224 -0
  87. package/dist/cjs/storage/sqlite/_shared/base-sqlite-storage-adapter.js.map +1 -0
  88. package/dist/cjs/storage/sqlite/libsql-storage-adapter/_module.js +18 -0
  89. package/dist/cjs/storage/sqlite/libsql-storage-adapter/_module.js.map +1 -0
  90. package/dist/cjs/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js +53 -0
  91. package/dist/cjs/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js.map +1 -0
  92. package/dist/cjs/storage/sqlite/sqlite-storage-adapter/_module.js +18 -0
  93. package/dist/cjs/storage/sqlite/sqlite-storage-adapter/_module.js.map +1 -0
  94. package/dist/cjs/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js +52 -0
  95. package/dist/cjs/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js.map +1 -0
  96. package/dist/cjs/storage/storage.js +291 -0
  97. package/dist/cjs/storage/storage.js.map +1 -0
  98. package/dist/cjs/storage/usable-storage-adapter.js +102 -0
  99. package/dist/cjs/storage/usable-storage-adapter.js.map +1 -0
  100. package/dist/esm/_module.js +3 -1
  101. package/dist/esm/_module.js.map +1 -1
  102. package/dist/esm/_shared/kysely/_module.js +2 -0
  103. package/dist/esm/_shared/kysely/_module.js.map +1 -0
  104. package/dist/esm/_shared/kysely/kysely-table-name-transformer-plugin.js +41 -0
  105. package/dist/esm/_shared/kysely/kysely-table-name-transformer-plugin.js.map +1 -0
  106. package/dist/esm/_shared/redis/_module.js +4 -0
  107. package/dist/esm/_shared/redis/_module.js.map +1 -0
  108. package/dist/esm/_shared/redis/clear-iterable.js +21 -0
  109. package/dist/esm/_shared/redis/clear-iterable.js.map +1 -0
  110. package/dist/esm/_shared/redis/escape-redis-chars.js +38 -0
  111. package/dist/esm/_shared/redis/escape-redis-chars.js.map +1 -0
  112. package/dist/esm/_shared/redis/is-redis-type-error.js +6 -0
  113. package/dist/esm/_shared/redis/is-redis-type-error.js.map +1 -0
  114. package/dist/esm/_shared/utilities.js.map +1 -1
  115. package/dist/esm/collection/async-iterable-collection/_shared/async-cross-join-iterable.js.map +1 -1
  116. package/dist/esm/collection/async-iterable-collection/async-iterable-collection.js.map +1 -1
  117. package/dist/esm/collection/iterable-collection/_shared/cross-join-iterable.js.map +1 -1
  118. package/dist/esm/contracts/_module.js +2 -0
  119. package/dist/esm/contracts/_module.js.map +1 -1
  120. package/dist/esm/contracts/collection/_module.js.map +1 -1
  121. package/dist/esm/contracts/serializer/_module.js +2 -0
  122. package/dist/esm/contracts/serializer/_module.js.map +1 -0
  123. package/dist/esm/contracts/serializer/serializer.contract.js +19 -0
  124. package/dist/esm/contracts/serializer/serializer.contract.js.map +1 -0
  125. package/dist/esm/contracts/storage/_module.js +4 -0
  126. package/dist/esm/contracts/storage/_module.js.map +1 -0
  127. package/dist/esm/contracts/storage/_shared.js +25 -0
  128. package/dist/esm/contracts/storage/_shared.js.map +1 -0
  129. package/dist/esm/contracts/storage/storage-adapter.contract.js +1 -0
  130. package/dist/esm/contracts/storage/storage-adapter.contract.js.map +1 -0
  131. package/dist/esm/contracts/storage/storage.contract.js +1 -0
  132. package/dist/esm/contracts/storage/storage.contract.js.map +1 -0
  133. package/dist/esm/serializer/_module.js +6 -0
  134. package/dist/esm/serializer/_module.js.map +1 -0
  135. package/dist/esm/serializer/_shared/test-utilities/_module.js +2 -0
  136. package/dist/esm/serializer/_shared/test-utilities/_module.js.map +1 -0
  137. package/dist/esm/serializer/_shared/test-utilities/serializer.test-suite.js +358 -0
  138. package/dist/esm/serializer/_shared/test-utilities/serializer.test-suite.js.map +1 -0
  139. package/dist/esm/serializer/mongodb-serializer/_module.js +2 -0
  140. package/dist/esm/serializer/mongodb-serializer/_module.js.map +1 -0
  141. package/dist/esm/serializer/mongodb-serializer/mongodb-serializer.js +32 -0
  142. package/dist/esm/serializer/mongodb-serializer/mongodb-serializer.js.map +1 -0
  143. package/dist/esm/serializer/redis-serializer/_module.js +2 -0
  144. package/dist/esm/serializer/redis-serializer/_module.js.map +1 -0
  145. package/dist/esm/serializer/redis-serializer/redis-serializer.js +33 -0
  146. package/dist/esm/serializer/redis-serializer/redis-serializer.js.map +1 -0
  147. package/dist/esm/serializer/sql-serializer/_module.js +2 -0
  148. package/dist/esm/serializer/sql-serializer/_module.js.map +1 -0
  149. package/dist/esm/serializer/sql-serializer/sql-serializer.js +33 -0
  150. package/dist/esm/serializer/sql-serializer/sql-serializer.js.map +1 -0
  151. package/dist/esm/serializer/super-json-serializer/_module.js +2 -0
  152. package/dist/esm/serializer/super-json-serializer/_module.js.map +1 -0
  153. package/dist/esm/serializer/super-json-serializer/super-json-serializer.js +277 -0
  154. package/dist/esm/serializer/super-json-serializer/super-json-serializer.js.map +1 -0
  155. package/dist/esm/storage/_module.js +7 -0
  156. package/dist/esm/storage/_module.js.map +1 -0
  157. package/dist/esm/storage/_shared/test-utilities/_module.js +2 -0
  158. package/dist/esm/storage/_shared/test-utilities/_module.js.map +1 -0
  159. package/dist/esm/storage/_shared/test-utilities/storage-api.test-suite.js +569 -0
  160. package/dist/esm/storage/_shared/test-utilities/storage-api.test-suite.js.map +1 -0
  161. package/dist/esm/storage/_shared/test-utilities/storage-namespace.test-suite.js +238 -0
  162. package/dist/esm/storage/_shared/test-utilities/storage-namespace.test-suite.js.map +1 -0
  163. package/dist/esm/storage/_shared/test-utilities/storage-value.test-suite.js +4169 -0
  164. package/dist/esm/storage/_shared/test-utilities/storage-value.test-suite.js.map +1 -0
  165. package/dist/esm/storage/_shared/test-utilities/storage.test-suite.js +9 -0
  166. package/dist/esm/storage/_shared/test-utilities/storage.test-suite.js.map +1 -0
  167. package/dist/esm/storage/memory-storage-adapter/_module.js +2 -0
  168. package/dist/esm/storage/memory-storage-adapter/_module.js.map +1 -0
  169. package/dist/esm/storage/memory-storage-adapter/memory-storage-adapter.js +58 -0
  170. package/dist/esm/storage/memory-storage-adapter/memory-storage-adapter.js.map +1 -0
  171. package/dist/esm/storage/mongodb-storage-adapter/_module.js +2 -0
  172. package/dist/esm/storage/mongodb-storage-adapter/_module.js.map +1 -0
  173. package/dist/esm/storage/mongodb-storage-adapter/mongodb-storage-adapter.js +266 -0
  174. package/dist/esm/storage/mongodb-storage-adapter/mongodb-storage-adapter.js.map +1 -0
  175. package/dist/esm/storage/namespace-storage-adapter.js +62 -0
  176. package/dist/esm/storage/namespace-storage-adapter.js.map +1 -0
  177. package/dist/esm/storage/redis-storage-adapter/_module.js +2 -0
  178. package/dist/esm/storage/redis-storage-adapter/_module.js.map +1 -0
  179. package/dist/esm/storage/redis-storage-adapter/redis-storage-adapter.js +244 -0
  180. package/dist/esm/storage/redis-storage-adapter/redis-storage-adapter.js.map +1 -0
  181. package/dist/esm/storage/sqlite/_module.js +3 -0
  182. package/dist/esm/storage/sqlite/_module.js.map +1 -0
  183. package/dist/esm/storage/sqlite/_shared/_module.js +2 -0
  184. package/dist/esm/storage/sqlite/_shared/_module.js.map +1 -0
  185. package/dist/esm/storage/sqlite/_shared/base-sqlite-storage-adapter.js +220 -0
  186. package/dist/esm/storage/sqlite/_shared/base-sqlite-storage-adapter.js.map +1 -0
  187. package/dist/esm/storage/sqlite/libsql-storage-adapter/_module.js +2 -0
  188. package/dist/esm/storage/sqlite/libsql-storage-adapter/_module.js.map +1 -0
  189. package/dist/esm/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js +49 -0
  190. package/dist/esm/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.js.map +1 -0
  191. package/dist/esm/storage/sqlite/sqlite-storage-adapter/_module.js +2 -0
  192. package/dist/esm/storage/sqlite/sqlite-storage-adapter/_module.js.map +1 -0
  193. package/dist/esm/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js +48 -0
  194. package/dist/esm/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.js.map +1 -0
  195. package/dist/esm/storage/storage.js +287 -0
  196. package/dist/esm/storage/storage.js.map +1 -0
  197. package/dist/esm/storage/usable-storage-adapter.js +98 -0
  198. package/dist/esm/storage/usable-storage-adapter.js.map +1 -0
  199. package/dist/types/_module.d.ts +3 -1
  200. package/dist/types/_shared/kysely/_module.d.ts +1 -0
  201. package/dist/types/_shared/kysely/kysely-table-name-transformer-plugin.d.ts +13 -0
  202. package/dist/types/_shared/redis/_module.d.ts +3 -0
  203. package/dist/types/_shared/redis/clear-iterable.d.ts +13 -0
  204. package/dist/types/_shared/redis/escape-redis-chars.d.ts +7 -0
  205. package/dist/types/_shared/redis/is-redis-type-error.d.ts +7 -0
  206. package/dist/types/_shared/types.d.ts +15 -2
  207. package/dist/types/_shared/utilities.d.ts +11 -1
  208. package/dist/types/collection/_shared.d.ts +1 -1
  209. package/dist/types/collection/async-iterable-collection/_shared/async-cross-join-iterable.d.ts +2 -1
  210. package/dist/types/collection/async-iterable-collection/_shared/async-group-by-iterable.d.ts +1 -1
  211. package/dist/types/collection/async-iterable-collection/async-iterable-collection.d.ts +2 -2
  212. package/dist/types/collection/iterable-collection/_shared/cross-join-iterable.d.ts +1 -1
  213. package/dist/types/collection/iterable-collection/_shared/group-by-iterable.d.ts +1 -1
  214. package/dist/types/collection/iterable-collection/iterable-collection.d.ts +1 -1
  215. package/dist/types/collection/list-collection/list-collection.d.ts +1 -1
  216. package/dist/types/contracts/_module.d.ts +2 -0
  217. package/dist/types/contracts/collection/_module.d.ts +0 -3
  218. package/dist/types/contracts/collection/_shared.d.ts +1 -1
  219. package/dist/types/contracts/collection/async-collection.contract.d.ts +3 -3
  220. package/dist/types/contracts/collection/collection.contract.d.ts +3 -3
  221. package/dist/types/contracts/serializer/_module.d.ts +1 -0
  222. package/dist/types/contracts/serializer/serializer.contract.d.ts +37 -0
  223. package/dist/types/contracts/storage/_module.d.ts +3 -0
  224. package/dist/types/contracts/storage/_shared.d.ts +27 -0
  225. package/dist/types/contracts/storage/storage-adapter.contract.d.ts +72 -0
  226. package/dist/types/contracts/storage/storage.contract.d.ts +147 -0
  227. package/dist/types/serializer/_module.d.ts +5 -0
  228. package/dist/types/serializer/_shared/test-utilities/_module.d.ts +1 -0
  229. package/dist/types/serializer/_shared/test-utilities/serializer.test-suite.d.ts +18 -0
  230. package/dist/types/serializer/mongodb-serializer/_module.d.ts +1 -0
  231. package/dist/types/serializer/mongodb-serializer/mongodb-serializer.d.ts +13 -0
  232. package/dist/types/serializer/redis-serializer/_module.d.ts +1 -0
  233. package/dist/types/serializer/redis-serializer/redis-serializer.d.ts +13 -0
  234. package/dist/types/serializer/sql-serializer/_module.d.ts +1 -0
  235. package/dist/types/serializer/sql-serializer/sql-serializer.d.ts +13 -0
  236. package/dist/types/serializer/super-json-serializer/_module.d.ts +1 -0
  237. package/dist/types/serializer/super-json-serializer/super-json-serializer.d.ts +37 -0
  238. package/dist/types/storage/_module.d.ts +6 -0
  239. package/dist/types/storage/_shared/test-utilities/_module.d.ts +1 -0
  240. package/dist/types/storage/_shared/test-utilities/storage-api.test-suite.d.ts +20 -0
  241. package/dist/types/storage/_shared/test-utilities/storage-namespace.test-suite.d.ts +20 -0
  242. package/dist/types/storage/_shared/test-utilities/storage-value.test-suite.d.ts +20 -0
  243. package/dist/types/storage/_shared/test-utilities/storage.test-suite.d.ts +20 -0
  244. package/dist/types/storage/memory-storage-adapter/_module.d.ts +1 -0
  245. package/dist/types/storage/memory-storage-adapter/memory-storage-adapter.d.ts +16 -0
  246. package/dist/types/storage/mongodb-storage-adapter/_module.d.ts +1 -0
  247. package/dist/types/storage/mongodb-storage-adapter/mongodb-storage-adapter.d.ts +46 -0
  248. package/dist/types/storage/namespace-storage-adapter.d.ts +30 -0
  249. package/dist/types/storage/redis-storage-adapter/_module.d.ts +1 -0
  250. package/dist/types/storage/redis-storage-adapter/redis-storage-adapter.d.ts +41 -0
  251. package/dist/types/storage/sqlite/_module.d.ts +2 -0
  252. package/dist/types/storage/sqlite/_shared/_module.d.ts +1 -0
  253. package/dist/types/storage/sqlite/_shared/base-sqlite-storage-adapter.d.ts +42 -0
  254. package/dist/types/storage/sqlite/libsql-storage-adapter/_module.d.ts +1 -0
  255. package/dist/types/storage/sqlite/libsql-storage-adapter/libsql-storage-adapter.d.ts +30 -0
  256. package/dist/types/storage/sqlite/sqlite-storage-adapter/_module.d.ts +1 -0
  257. package/dist/types/storage/sqlite/sqlite-storage-adapter/sqlite-storage-adapter.d.ts +30 -0
  258. package/dist/types/storage/storage.d.ts +36 -0
  259. package/dist/types/storage/usable-storage-adapter.d.ts +22 -0
  260. package/package.json +41 -6
@@ -0,0 +1,98 @@
1
+ import { simplifyAsyncLazyable } from "../_shared/utilities";
2
+ import { TypeStorageError, UnexpectedStorageError, } from "../contracts/storage/_module";
3
+ export class UsableStorageAdapter {
4
+ storageAdapter;
5
+ constructor(storageAdapter) {
6
+ this.storageAdapter = storageAdapter;
7
+ }
8
+ async existsMany(keys) {
9
+ if (this.storageAdapter.existsMany !== undefined) {
10
+ return await this.storageAdapter.existsMany(keys);
11
+ }
12
+ const getResult = await this.getMany(keys);
13
+ const results = {};
14
+ for (const key in getResult) {
15
+ results[key] = getResult[key] !== null;
16
+ }
17
+ return results;
18
+ }
19
+ async getMany(keys) {
20
+ return await this.storageAdapter.getMany(keys);
21
+ }
22
+ async addMany(values) {
23
+ return await this.storageAdapter.addMany(values);
24
+ }
25
+ async updateMany(values) {
26
+ return await this.storageAdapter.updateMany(values);
27
+ }
28
+ async putMany(values) {
29
+ if (this.storageAdapter.putMany !== undefined) {
30
+ return await this.storageAdapter.putMany(values);
31
+ }
32
+ const removeResults = await this.removeMany(Object.keys(values));
33
+ await this.addMany(values);
34
+ return removeResults;
35
+ }
36
+ async removeMany(keys) {
37
+ return await this.storageAdapter.removeMany(keys);
38
+ }
39
+ async increment(key, value) {
40
+ if (this.storageAdapter.increment !== undefined) {
41
+ return await this.storageAdapter.increment(key, value);
42
+ }
43
+ const { [key]: previousValue } = await this.getMany([key]);
44
+ if (previousValue === undefined) {
45
+ throw new UnexpectedStorageError(`Destructed field "key" is undefined`);
46
+ }
47
+ if (previousValue === null) {
48
+ return false;
49
+ }
50
+ if (typeof previousValue !== "number") {
51
+ throw new TypeStorageError(`Unable to increment or decrement none number type key "${key}"`);
52
+ }
53
+ const newValue = previousValue + value;
54
+ await this.updateMany({
55
+ [key]: newValue,
56
+ });
57
+ return true;
58
+ }
59
+ async getAndRemove(key) {
60
+ if (this.storageAdapter.getAndRemove !== undefined) {
61
+ return await this.storageAdapter.getAndRemove(key);
62
+ }
63
+ const { [key]: value } = await this.getMany([key]);
64
+ if (value === undefined) {
65
+ throw new UnexpectedStorageError(`Destructed field "key" is undefined`);
66
+ }
67
+ await this.removeMany([key]);
68
+ return value;
69
+ }
70
+ async getOrAdd(key, valueToAdd) {
71
+ if (typeof valueToAdd !== "function" &&
72
+ this.storageAdapter.getOrAdd !== undefined) {
73
+ return await this.storageAdapter.getOrAdd(key, valueToAdd);
74
+ }
75
+ const { [key]: value } = await this.getMany([key]);
76
+ if (value === undefined) {
77
+ throw new UnexpectedStorageError(`Destructed field "key" is undefined`);
78
+ }
79
+ if (value === null) {
80
+ const valueToAddSimplified = await simplifyAsyncLazyable(valueToAdd);
81
+ await this.addMany({
82
+ [key]: valueToAddSimplified,
83
+ });
84
+ return {
85
+ hasKey: false,
86
+ value: valueToAddSimplified,
87
+ };
88
+ }
89
+ return {
90
+ hasKey: true,
91
+ value,
92
+ };
93
+ }
94
+ async clear(prefix) {
95
+ await this.storageAdapter.clear(prefix);
96
+ }
97
+ }
98
+ //# sourceMappingURL=usable-storage-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usable-storage-adapter.js","sourceRoot":"","sources":["../../../src/storage/usable-storage-adapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAEH,gBAAgB,EACh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CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACJ"}
@@ -1,2 +1,4 @@
1
- export * from "./collection/_module";
2
1
  export * from "./contracts/_module";
2
+ export * from "./collection/_module";
3
+ export * from "./serializer/_module";
4
+ export * from "./storage/_module";
@@ -0,0 +1 @@
1
+ export * from "../../_shared/kysely/kysely-table-name-transformer-plugin";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module Shared
3
+ */
4
+ import type { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, RootOperationNode, UnknownRow } from "kysely";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare class KyselyTableNameTransformerPlugin implements KyselyPlugin {
9
+ private readonly transformer;
10
+ constructor(tableNameMap: Record<string, string>);
11
+ transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
12
+ transformResult(args: PluginTransformResultArgs): Promise<QueryResult<UnknownRow>>;
13
+ }
@@ -0,0 +1,3 @@
1
+ export * from "../../_shared/redis/escape-redis-chars";
2
+ export * from "../../_shared/redis/clear-iterable";
3
+ export * from "../../_shared/redis/is-redis-type-error";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module Shared
3
+ */
4
+ import type Redis from "ioredis";
5
+ /**
6
+ * @internal
7
+ */
8
+ export declare class ClearIterable implements AsyncIterable<void> {
9
+ private readonly client;
10
+ private readonly pattern;
11
+ constructor(client: Redis, pattern: string);
12
+ [Symbol.asyncIterator](): AsyncIterator<void>;
13
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module Shared
3
+ */
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare function escapeRedisChars(value: string): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module Shared
3
+ */
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare function isRedisTypeError(value: any): boolean;
@@ -1,6 +1,19 @@
1
+ /**
2
+ * @module Shared
3
+ */
1
4
  export type EnsureType<TValue, TType> = Exclude<TValue, TType> extends never ? TValue : never;
2
5
  export type RecordItem<TKey, TValue> = [key: TKey, value: TValue];
3
6
  export type Lazyable<TValue> = TValue | (() => TValue);
4
- export type AsyncLazyable_<TValue> = TValue | (() => Promise<TValue>);
5
- export type AsyncLazyable<TValue> = AsyncLazyable_<TValue> | Lazyable<TValue>;
7
+ export type Promisable<TValue> = TValue | Promise<TValue>;
8
+ export type AsyncLazyable<TValue> = TValue | (() => Promisable<TValue>);
6
9
  export type AsyncIterableValue<TInput> = Iterable<TInput> | AsyncIterable<TInput>;
10
+ export type AnyFunction = (...parameters: unknown[]) => unknown;
11
+ export type IInitizable = {
12
+ init(): Promise<void>;
13
+ };
14
+ export type Func<TArgs extends unknown[], TReturn> = (...args_: TArgs) => TReturn;
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,3 +1,13 @@
1
- import { AsyncLazyable, Lazyable } from "../_shared/types";
1
+ /**
2
+ * @module Shared
3
+ */
4
+ import type { Lazyable } from "../_shared/types";
5
+ import { type AsyncLazyable } from "../_shared/types";
6
+ /**
7
+ * @internal
8
+ */
2
9
  export declare function simplifyLazyable<TValue>(lazyable: Lazyable<TValue>): TValue;
10
+ /**
11
+ * @internal
12
+ */
3
13
  export declare function simplifyAsyncLazyable<TValue>(lazyable: AsyncLazyable<TValue>): Promise<TValue>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @module Collections
2
+ * @module Collection
3
3
  */
4
4
  /**
5
5
  * The <i>range</i> function return a <i>{@link Iterable}</i> of numbers, starting from <i>from</i>,increments by 1 and stops at <i>to</i>.
@@ -1,4 +1,5 @@
1
- import { CrossJoinResult, type IAsyncCollection } from "../../../contracts/collection/_module";
1
+ import type { CrossJoinResult } from "../../../contracts/collection/_module";
2
+ import { type IAsyncCollection } from "../../../contracts/collection/_module";
2
3
  import { type AsyncIterableValue } from "../../../_shared/types";
3
4
  /**
4
5
  * @internal
@@ -7,6 +7,6 @@ export declare class AsyncGroupByIterable<TInput, TOutput = TInput> implements A
7
7
  private collection;
8
8
  private selectFn;
9
9
  private makeCollection;
10
- constructor(collection: IAsyncCollection<TInput>, selectFn: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput>, makeCollection: <TInput>(iterable: AsyncIterableValue<TInput>) => IAsyncCollection<TInput>);
10
+ constructor(collection: IAsyncCollection<TInput>, selectFn: AsyncMap<TInput, IAsyncCollection<TInput>, TOutput> | undefined, makeCollection: <TInput>(iterable: AsyncIterableValue<TInput>) => IAsyncCollection<TInput>);
11
11
  [Symbol.asyncIterator](): AsyncIterator<RecordItem<TOutput, IAsyncCollection<TInput>>>;
12
12
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @module Collections
2
+ * @module Collection
3
3
  */
4
4
  import { type AsyncCollapse, type AsyncPredicate, type AsyncForEach, type AsyncMap, type AsyncModifier, type AsyncTap, type AsyncTransform, type Comparator, type IAsyncCollection, type ChangendItem, type AsyncReduce, type CrossJoinResult } from "../../contracts/collection/_module";
5
5
  import { type AsyncIterableValue, type AsyncLazyable, type EnsureType } from "../../_shared/types";
@@ -72,7 +72,7 @@ export declare class AsyncIterableCollection<TInput> implements IAsyncCollection
72
72
  insertAfter<TExtended = TInput>(predicateFn: AsyncPredicate<TInput, IAsyncCollection<TInput>>, iterable: AsyncIterableValue<TInput | TExtended>): IAsyncCollection<TInput | TExtended>;
73
73
  crossJoin<TExtended>(iterable: AsyncIterableValue<TExtended>): IAsyncCollection<CrossJoinResult<TInput, TExtended>>;
74
74
  zip<TExtended>(iterable: AsyncIterableValue<TExtended>): IAsyncCollection<RecordItem<TInput, TExtended>>;
75
- sort(comparator?: Comparator<TInput> | undefined): IAsyncCollection<TInput>;
75
+ sort(comparator?: Comparator<TInput>): IAsyncCollection<TInput>;
76
76
  reverse(chunkSize?: number): IAsyncCollection<TInput>;
77
77
  shuffle(mathRandom?: () => number): IAsyncCollection<TInput>;
78
78
  first<TOutput extends TInput>(predicateFn?: AsyncPredicate<TInput, IAsyncCollection<TInput>, TOutput>): Promise<TOutput | null>;
@@ -1,4 +1,4 @@
1
- import { CrossJoinResult, ICollection } from "../../../contracts/collection/_module";
1
+ import type { CrossJoinResult, ICollection } from "../../../contracts/collection/_module";
2
2
  export declare class CrossJoinIterable<TInput, TExtended = TInput> implements Iterable<CrossJoinResult<TInput, TExtended>> {
3
3
  private collection;
4
4
  private iterable;
@@ -7,6 +7,6 @@ export declare class GroupByIterable<TInput, TOutput = TInput> implements Iterab
7
7
  private collection;
8
8
  private selectFn;
9
9
  private makeCollection;
10
- constructor(collection: ICollection<TInput>, selectFn: Map<TInput, ICollection<TInput>, TOutput>, makeCollection: <TInput>(iterable: Iterable<TInput>) => ICollection<TInput>);
10
+ constructor(collection: ICollection<TInput>, selectFn: Map<TInput, ICollection<TInput>, TOutput> | undefined, makeCollection: <TInput>(iterable: Iterable<TInput>) => ICollection<TInput>);
11
11
  [Symbol.iterator](): Iterator<RecordItem<TOutput, ICollection<TInput>>>;
12
12
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @module Collections
2
+ * @module Collection
3
3
  */
4
4
  import { type Collapse, type Comparator, type Predicate, type ForEach, type ICollection, type Map, type Modifier, type Tap, type Transform, type ChangendItem, type Reduce, type CrossJoinResult } from "../../contracts/collection/_module";
5
5
  import { type Lazyable, type EnsureType } from "../../_shared/types";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @module Collections
2
+ * @module Collection
3
3
  */
4
4
  import { type Collapse, type Comparator, type Predicate, type ICollection, type Map, type Modifier, type Tap, type Transform, type ChangendItem, type Reduce, type ForEach, type CrossJoinResult } from "../../contracts/collection/_module";
5
5
  import { type EnsureType, type Lazyable } from "../../_shared/types";
@@ -1 +1,3 @@
1
1
  export * from "../contracts/collection/_module";
2
+ export * from "../contracts/serializer/_module";
3
+ export * from "../contracts/storage/_module";
@@ -1,6 +1,3 @@
1
- /**
2
- * @module Collections
3
- */
4
1
  export * from "../../contracts/collection/_shared";
5
2
  export * from "../../contracts/collection/collection.contract";
6
3
  export * from "../../contracts/collection/async-collection.contract";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @module Collections
2
+ * @module Collection
3
3
  */
4
4
  /**
5
5
  * @group Errors
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @module Collections
2
+ * @module Collection
3
3
  */
4
- import { type AsyncPredicate, type AsyncForEach, type AsyncMap, type AsyncModifier, type AsyncTap, type AsyncTransform, type Comparator, type ChangendItem, AsyncReduce, CrossJoinResult } from "../../contracts/collection/_shared";
5
- import { type RecordItem, type AsyncLazyable, type EnsureType, type AsyncIterableValue } from "../../_shared/types";
4
+ import type { AsyncReduce, CrossJoinResult, AsyncPredicate, AsyncForEach, AsyncMap, AsyncModifier, AsyncTap, AsyncTransform, Comparator, ChangendItem } from "../../contracts/collection/_shared";
5
+ import type { RecordItem, AsyncLazyable, EnsureType, AsyncIterableValue } from "../../_shared/types";
6
6
  export type AsyncCollapse<TValue> = TValue extends Array<infer TItem> | Iterable<infer TItem> | IAsyncCollection<infer TItem> ? TItem : TValue;
7
7
  /**
8
8
  * <i>IAsyncCollection</i> is immutable. The <i>throwOnIndexOverflow</i> parameter in the <i>IAsyncCollection</i> methods is used for preventing the index to overflow by throwing an error.
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @module Collections
2
+ * @module Collection
3
3
  */
4
- import { type Comparator, type Predicate, type ForEach, type Map, type Modifier, type Tap, type Transform, type ChangendItem, type Reduce, type CrossJoinResult } from "../../contracts/collection/_shared";
5
- import { type Lazyable, type RecordItem, type EnsureType } from "../../_shared/types";
4
+ import type { Comparator, Predicate, ForEach, Map, Modifier, Tap, Transform, ChangendItem, Reduce, CrossJoinResult } from "../../contracts/collection/_shared";
5
+ import type { Lazyable, RecordItem, EnsureType } from "../../_shared/types";
6
6
  export type Collapse<TValue> = TValue extends Array<infer TItem> | Iterable<infer TItem> | ICollection<infer TItem> ? TItem : TValue;
7
7
  /**
8
8
  * <i>ICollection</i> is immutable.
@@ -0,0 +1 @@
1
+ export * from "../../contracts/serializer/serializer.contract";
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @module Serializer
3
+ */
4
+ /**
5
+ * @group Errors
6
+ */
7
+ export declare class SerializerError extends Error {
8
+ constructor(message: string, cause?: unknown);
9
+ }
10
+ /**
11
+ * @group Errors
12
+ */
13
+ export declare class SerializationError extends SerializerError {
14
+ constructor(message: string, cause?: unknown);
15
+ }
16
+ /**
17
+ * @group Errors
18
+ */
19
+ export declare class DeserializationError extends SerializerError {
20
+ constructor(message: string, cause?: unknown);
21
+ }
22
+ /**
23
+ * @group Contracts
24
+ * @throws {SerializerError} {@link SerializerError}
25
+ * @throws {SerializationError} {@link SerializationError}
26
+ * @throws {DeserializationError} {@link DeserializationError}
27
+ */
28
+ export type ISerializer<TSerialized = unknown> = {
29
+ /**
30
+ * @throws {SerializationError} {@link SerializationError}
31
+ */
32
+ serialize<TValue>(value: TValue): Promise<TSerialized>;
33
+ /**
34
+ * @throws {DeserializationError} {@link DeserializationError}
35
+ */
36
+ deserialize<TValue>(value: TSerialized): Promise<TValue>;
37
+ };
@@ -0,0 +1,3 @@
1
+ export * from "../../contracts/storage/_shared";
2
+ export * from "../../contracts/storage/storage.contract";
3
+ export * from "../../contracts/storage/storage-adapter.contract";
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @module Storage
3
+ */
4
+ /**
5
+ * @group Errors
6
+ */
7
+ export declare class StorageError extends Error {
8
+ constructor(message: string, cause?: unknown);
9
+ }
10
+ /**
11
+ * @group Errors
12
+ */
13
+ export declare class UnexpectedStorageError extends StorageError {
14
+ constructor(message: string, cause?: unknown);
15
+ }
16
+ /**
17
+ * @group Errors
18
+ */
19
+ export declare class TypeStorageError extends StorageError {
20
+ constructor(message: string, cause?: unknown);
21
+ }
22
+ /**
23
+ * @group Errors
24
+ */
25
+ export declare class KeyNotFoundStorageError extends StorageError {
26
+ constructor(message: string, cause?: unknown);
27
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @module Storage
3
+ */
4
+ import type { GetOrAddResult } from "../../_shared/types";
5
+ /**
6
+ * @throws {StorageError} {@link StorageError}
7
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
8
+ * @throws {TypeStorageError} {@link TypeStorageError}
9
+ * @group Contracts
10
+ */
11
+ 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
+ /**
19
+ * Returns the value for the keys that are found otherwise null will be returned.
20
+ * @throws {StorageError} {@link StorageError}
21
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
22
+ */
23
+ getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, TValues | null>>;
24
+ /**
25
+ * Adds the keys that doesn't exists. Returns true for the keys that doesn't exists otherwise false will be returned.
26
+ * @throws {StorageError} {@link StorageError}
27
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
28
+ */
29
+ addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
30
+ /**
31
+ * Updates the keys that exists. Returns true for the keys that exists otherwise false will be returned.
32
+ * @throws {StorageError} {@link StorageError}
33
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
34
+ */
35
+ updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
36
+ /**
37
+ * 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
+ * @throws {StorageError} {@link StorageError}
39
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
40
+ */
41
+ putMany?<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
42
+ /**
43
+ * Removes the keys that are found. Returns true for the keys that are found otherwise false is returned.
44
+ * @throws {StorageError} {@link StorageError}
45
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
46
+ */
47
+ removeMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
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>>;
60
+ /**
61
+ * Will increment the existing key with value if found otherwise nonthing occurs. Returns true if key exists otherwise false will be returned.
62
+ * @throws {StorageError} {@link StorageError}
63
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
64
+ * @throws {TypeStorageError} {@link TypeStorageError}
65
+ */
66
+ increment?(key: string, value: number): Promise<boolean>;
67
+ /**
68
+ * @throws {StorageError} {@link StorageError}
69
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
70
+ */
71
+ clear(prefix: string): Promise<void>;
72
+ };
@@ -0,0 +1,147 @@
1
+ /**
2
+ * @module Storage
3
+ */
4
+ import { type AnyFunction, type AsyncLazyable, type GetOrAddValue } from "../../_shared/types";
5
+ export type StorageValue<T> = Exclude<T, AnyFunction | undefined | null>;
6
+ /**
7
+ * @throws {StorageError} {@link StorageError}
8
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
9
+ * @throws {TypeStorageError} {@link TypeStorageError}
10
+ * @group Contracts
11
+ */
12
+ export type IStorage<TType = unknown> = AsyncDisposable & {
13
+ /**
14
+ * Returns true when key is found otherwise false will be returned.
15
+ * @throws {StorageError} {@link StorageError}
16
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
17
+ */
18
+ exists(key: string): Promise<boolean>;
19
+ /**
20
+ * Returns true for the keys that are found otherwise false will be returned.
21
+ * @throws {StorageError} {@link StorageError}
22
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
23
+ */
24
+ existsMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
25
+ /**
26
+ * Returns true when key is not found otherwise false will be returned.
27
+ * @throws {StorageError} {@link StorageError}
28
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
29
+ */
30
+ missing(key: string): Promise<boolean>;
31
+ /**
32
+ * Returns true for the keys that are not found otherwise false will be returned.
33
+ * @throws {StorageError} {@link StorageError}
34
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
35
+ */
36
+ missingMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
37
+ /**
38
+ * Returns the value when key is found otherwise null will be returned.
39
+ * @throws {StorageError} {@link StorageError}
40
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
41
+ */
42
+ get<TValue extends TType>(key: string): Promise<TValue | null>;
43
+ /**
44
+ * Returns the value for the keys that are found otherwise null will be returned.
45
+ * @throws {StorageError} {@link StorageError}
46
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
47
+ */
48
+ getMany<TValues extends TType, TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, TValues | null>>;
49
+ /**
50
+ * Returns the value when key is found otherwise defaultValue will be returned.
51
+ * @throws {StorageError} {@link StorageError}
52
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
53
+ */
54
+ getOr<TValue extends TType, TExtended extends TType>(key: string, defaultValue: AsyncLazyable<TExtended>): Promise<TValue | TExtended>;
55
+ /**
56
+ * Returns the value for the keys that are found otherwise defaultValue will be returned.
57
+ * @throws {StorageError} {@link StorageError}
58
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
59
+ */
60
+ getOrMany<TValues extends TType, TExtended extends TType, TKeys extends string>(keysWithDefaults: Record<TKeys, AsyncLazyable<TExtended>>): Promise<Record<TKeys, TValues | TExtended>>;
61
+ /**
62
+ * Returns the value when key is found otherwise an error will be thrown.
63
+ * @throws {StorageError} {@link StorageError}
64
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
65
+ * @throws {KeyNotFoundStorageError} {@link KeyNotFoundStorageError}
66
+ */
67
+ getOrFail<TValue extends TType>(key: string): Promise<TValue>;
68
+ /**
69
+ * Adds a key when key doesn't exists. Returns true when key doesn't exists otherwise false will be returned.
70
+ * @throws {StorageError} {@link StorageError}
71
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
72
+ */
73
+ add<TValue extends TType>(key: string, value: StorageValue<TValue>): Promise<boolean>;
74
+ /**
75
+ * Adds the keys that doesn't exists. Returns true for the keys that doesn't exists otherwise false will be returned.
76
+ * @throws {StorageError} {@link StorageError}
77
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
78
+ */
79
+ addMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>): Promise<Record<TKeys, boolean>>;
80
+ /**
81
+ * Updates a keys that exists. Returns true when key otherwise false will be returned.
82
+ * @throws {StorageError} {@link StorageError}
83
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
84
+ */
85
+ update<TValue extends TType>(key: string, value: TValue): Promise<boolean>;
86
+ /**
87
+ * Updates the keys that exists. Returns true for the keys that exists otherwise false will be returned.
88
+ * @throws {StorageError} {@link StorageError}
89
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
90
+ */
91
+ updateMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, TValues>): Promise<Record<TKeys, boolean>>;
92
+ /**
93
+ * 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.
94
+ * @throws {StorageError} {@link StorageError}
95
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
96
+ */
97
+ put<TValue extends TType>(key: string, value: StorageValue<TValue>): Promise<boolean>;
98
+ /**
99
+ * 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.
100
+ * @throws {StorageError} {@link StorageError}
101
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
102
+ */
103
+ putMany<TValues extends TType, TKeys extends string>(values: Record<TKeys, StorageValue<TValues>>): Promise<Record<TKeys, boolean>>;
104
+ /**
105
+ * Removes the key when found. Returns true if the key is found otherwise false is returned.
106
+ * @throws {StorageError} {@link StorageError}
107
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
108
+ */
109
+ remove(key: string): Promise<boolean>;
110
+ /**
111
+ * Removes the keys that are found. Returns true for the keys that are found otherwise false is returned.
112
+ * @throws {StorageError} {@link StorageError}
113
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
114
+ */
115
+ removeMany<TKeys extends string>(keys: TKeys[]): Promise<Record<TKeys, boolean>>;
116
+ /**
117
+ * If the key is found the value be returned and key will be removed otherwise null will be returned.
118
+ * @throws {StorageError} {@link StorageError}
119
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
120
+ */
121
+ getAndRemove<TValue extends TType>(key: string): Promise<TValue | null>;
122
+ /**
123
+ * If the key is found the value be returned otherwise valueToAdd will be added and returned.
124
+ * @throws {StorageError} {@link StorageError}
125
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
126
+ */
127
+ getOrAdd<TValue extends TType, TExtended extends TType>(key: string, valueToAdd: AsyncLazyable<StorageValue<GetOrAddValue<TExtended>>>): Promise<TValue | TExtended>;
128
+ /**
129
+ * Will increment the existing key with value if found otherwise nonthing will occur. Returns true if key exists otherwise false will be returned.
130
+ * @throws {StorageError} {@link StorageError}
131
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
132
+ * @throws {TypeStorageError} {@link TypeStorageError}
133
+ */
134
+ increment(key: string, value?: number): Promise<boolean>;
135
+ /**
136
+ * Will decrement the existing key with value if found otherwise nonthing will occur. Returns true if key exists otherwise false will be returned.
137
+ * @throws {StorageError} {@link StorageError}
138
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
139
+ * @throws {TypeStorageError} {@link TypeStorageError}
140
+ */
141
+ decrement(key: string, value?: number): Promise<boolean>;
142
+ /**
143
+ * @throws {StorageError} {@link StorageError}
144
+ * @throws {UnexpectedStorageError} {@link UnexpectedStorageError}
145
+ */
146
+ clear(): Promise<void>;
147
+ };
@@ -0,0 +1,5 @@
1
+ export * from "../serializer/_shared/test-utilities/_module";
2
+ export * from "../serializer/mongodb-serializer/_module";
3
+ export * from "../serializer/redis-serializer/_module";
4
+ export * from "../serializer/sql-serializer/_module";
5
+ export * from "../serializer/super-json-serializer/_module";
@@ -0,0 +1 @@
1
+ export * from "../../../serializer/_shared/test-utilities/serializer.test-suite";