@decaf-ts/core 0.5.0 → 0.5.2

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 (330) hide show
  1. package/LICENSE.md +21 -157
  2. package/README.md +652 -15
  3. package/dist/core.cjs +2638 -1085
  4. package/dist/core.esm.cjs +2636 -1070
  5. package/lib/esm/identity/decorators.d.ts +52 -14
  6. package/lib/esm/identity/decorators.js +54 -16
  7. package/lib/esm/identity/utils.d.ts +20 -1
  8. package/lib/esm/identity/utils.js +22 -2
  9. package/lib/esm/index.d.ts +11 -15
  10. package/lib/esm/index.js +17 -19
  11. package/lib/esm/interfaces/ErrorParser.d.ts +12 -0
  12. package/lib/esm/interfaces/ErrorParser.js +1 -1
  13. package/lib/esm/interfaces/Executor.d.ts +10 -13
  14. package/lib/esm/interfaces/Executor.js +1 -1
  15. package/lib/esm/interfaces/Observable.d.ts +20 -18
  16. package/lib/esm/interfaces/Observable.js +1 -1
  17. package/lib/esm/interfaces/Observer.d.ts +7 -8
  18. package/lib/esm/interfaces/Observer.js +1 -1
  19. package/lib/esm/interfaces/Paginatable.d.ts +18 -2
  20. package/lib/esm/interfaces/Paginatable.js +1 -1
  21. package/lib/esm/interfaces/Queriable.d.ts +44 -3
  22. package/lib/esm/interfaces/Queriable.js +1 -1
  23. package/lib/esm/interfaces/RawExecutor.d.ts +10 -13
  24. package/lib/esm/interfaces/RawExecutor.js +1 -1
  25. package/lib/esm/interfaces/SequenceOptions.d.ts +50 -5
  26. package/lib/esm/interfaces/SequenceOptions.js +19 -1
  27. package/lib/esm/interfaces/index.d.ts +0 -1
  28. package/lib/esm/interfaces/index.js +1 -2
  29. package/lib/esm/model/BaseModel.d.ts +31 -0
  30. package/lib/esm/model/BaseModel.js +24 -1
  31. package/lib/esm/model/construction.d.ts +442 -9
  32. package/lib/esm/model/construction.js +441 -2
  33. package/lib/esm/model/decorators.d.ts +166 -42
  34. package/lib/esm/model/decorators.js +161 -37
  35. package/lib/esm/model/index.js +1 -2
  36. package/lib/esm/model/types.d.ts +9 -0
  37. package/lib/esm/model/types.js +1 -1
  38. package/lib/esm/persistence/Adapter.d.ts +384 -40
  39. package/lib/esm/persistence/Adapter.js +415 -59
  40. package/lib/esm/persistence/Dispatch.d.ts +131 -0
  41. package/lib/esm/persistence/Dispatch.js +187 -0
  42. package/lib/esm/persistence/ObserverHandler.d.ts +109 -0
  43. package/lib/esm/persistence/ObserverHandler.js +137 -0
  44. package/lib/esm/persistence/Sequence.d.ts +89 -8
  45. package/lib/esm/persistence/Sequence.js +91 -1
  46. package/lib/esm/persistence/constants.d.ts +22 -5
  47. package/lib/esm/persistence/constants.js +23 -7
  48. package/lib/esm/persistence/decorators.d.ts +10 -0
  49. package/lib/esm/persistence/decorators.js +11 -1
  50. package/lib/esm/persistence/errors.d.ts +23 -3
  51. package/lib/esm/persistence/errors.js +25 -7
  52. package/lib/esm/persistence/index.d.ts +3 -0
  53. package/lib/esm/persistence/index.js +4 -1
  54. package/lib/esm/persistence/types.d.ts +21 -0
  55. package/lib/esm/persistence/types.js +2 -0
  56. package/lib/esm/query/Condition.d.ts +88 -44
  57. package/lib/esm/query/Condition.js +144 -62
  58. package/lib/esm/query/Paginator.d.ts +67 -10
  59. package/lib/esm/query/Paginator.js +64 -10
  60. package/lib/esm/query/Statement.d.ts +82 -47
  61. package/lib/esm/query/Statement.js +175 -122
  62. package/lib/esm/query/constants.d.ts +25 -64
  63. package/lib/esm/query/constants.js +26 -68
  64. package/lib/esm/query/errors.d.ts +14 -0
  65. package/lib/esm/query/errors.js +15 -1
  66. package/lib/esm/query/index.d.ts +0 -5
  67. package/lib/esm/query/index.js +1 -6
  68. package/lib/esm/query/options.d.ts +69 -178
  69. package/lib/esm/query/options.js +1 -1
  70. package/lib/esm/query/selectors.d.ts +20 -24
  71. package/lib/esm/query/selectors.js +1 -1
  72. package/lib/esm/ram/RamAdapter.d.ts +322 -20
  73. package/lib/esm/ram/RamAdapter.js +360 -140
  74. package/lib/esm/ram/RamContext.d.ts +16 -1
  75. package/lib/esm/ram/RamContext.js +18 -3
  76. package/lib/esm/ram/RamPaginator.d.ts +51 -6
  77. package/lib/esm/ram/RamPaginator.js +58 -6
  78. package/lib/esm/ram/RamSequence.d.ts +49 -24
  79. package/lib/esm/ram/RamSequence.js +52 -40
  80. package/lib/esm/ram/RamStatement.d.ts +84 -6
  81. package/lib/esm/ram/RamStatement.js +175 -6
  82. package/lib/esm/ram/constants.d.ts +9 -0
  83. package/lib/esm/ram/constants.js +10 -0
  84. package/lib/esm/ram/handlers.d.ts +25 -0
  85. package/lib/esm/ram/handlers.js +27 -0
  86. package/lib/esm/ram/index.d.ts +4 -4
  87. package/lib/esm/ram/index.js +9 -5
  88. package/lib/esm/ram/model/RamSequence.d.ts +21 -9
  89. package/lib/esm/ram/model/RamSequence.js +19 -1
  90. package/lib/esm/ram/types.d.ts +47 -5
  91. package/lib/esm/ram/types.js +1 -1
  92. package/lib/esm/repository/Repository.d.ts +381 -22
  93. package/lib/esm/repository/Repository.js +446 -43
  94. package/lib/esm/repository/constants.d.ts +23 -13
  95. package/lib/esm/repository/constants.js +24 -14
  96. package/lib/esm/repository/decorators.d.ts +27 -0
  97. package/lib/esm/repository/decorators.js +28 -1
  98. package/lib/esm/repository/errors.d.ts +12 -11
  99. package/lib/esm/repository/errors.js +13 -16
  100. package/lib/esm/repository/injectables.d.ts +18 -0
  101. package/lib/esm/repository/injectables.js +19 -1
  102. package/lib/esm/repository/types.d.ts +13 -1
  103. package/lib/esm/repository/types.js +1 -1
  104. package/lib/esm/repository/utils.d.ts +11 -0
  105. package/lib/esm/repository/utils.js +12 -1
  106. package/lib/esm/utils/decorators.d.ts +9 -0
  107. package/lib/esm/utils/decorators.js +19 -0
  108. package/lib/esm/utils/errors.d.ts +56 -0
  109. package/lib/esm/utils/errors.js +63 -0
  110. package/lib/esm/utils/index.d.ts +2 -0
  111. package/lib/esm/utils/index.js +3 -0
  112. package/lib/identity/decorators.cjs +54 -16
  113. package/lib/identity/decorators.d.ts +52 -14
  114. package/lib/identity/utils.cjs +22 -2
  115. package/lib/identity/utils.d.ts +20 -1
  116. package/lib/index.cjs +17 -19
  117. package/lib/index.d.ts +11 -15
  118. package/lib/interfaces/ErrorParser.cjs +1 -1
  119. package/lib/interfaces/ErrorParser.d.ts +12 -0
  120. package/lib/interfaces/Executor.cjs +1 -1
  121. package/lib/interfaces/Executor.d.ts +10 -13
  122. package/lib/interfaces/Observable.cjs +1 -1
  123. package/lib/interfaces/Observable.d.ts +20 -18
  124. package/lib/interfaces/Observer.cjs +1 -1
  125. package/lib/interfaces/Observer.d.ts +7 -8
  126. package/lib/interfaces/Paginatable.cjs +1 -1
  127. package/lib/interfaces/Paginatable.d.ts +18 -2
  128. package/lib/interfaces/Queriable.cjs +1 -1
  129. package/lib/interfaces/Queriable.d.ts +44 -3
  130. package/lib/interfaces/RawExecutor.cjs +1 -1
  131. package/lib/interfaces/RawExecutor.d.ts +10 -13
  132. package/lib/interfaces/SequenceOptions.cjs +19 -1
  133. package/lib/interfaces/SequenceOptions.d.ts +50 -5
  134. package/lib/interfaces/index.cjs +1 -2
  135. package/lib/interfaces/index.d.ts +0 -1
  136. package/lib/model/BaseModel.cjs +24 -1
  137. package/lib/model/BaseModel.d.ts +31 -0
  138. package/lib/model/construction.cjs +441 -2
  139. package/lib/model/construction.d.ts +442 -9
  140. package/lib/model/decorators.cjs +161 -37
  141. package/lib/model/decorators.d.ts +166 -42
  142. package/lib/model/index.cjs +1 -2
  143. package/lib/model/types.cjs +1 -1
  144. package/lib/model/types.d.ts +9 -0
  145. package/lib/persistence/Adapter.cjs +414 -58
  146. package/lib/persistence/Adapter.d.ts +384 -40
  147. package/lib/persistence/Dispatch.cjs +191 -0
  148. package/lib/persistence/Dispatch.d.ts +131 -0
  149. package/lib/persistence/ObserverHandler.cjs +141 -0
  150. package/lib/persistence/ObserverHandler.d.ts +109 -0
  151. package/lib/persistence/Sequence.cjs +91 -1
  152. package/lib/persistence/Sequence.d.ts +89 -8
  153. package/lib/persistence/constants.cjs +24 -8
  154. package/lib/persistence/constants.d.ts +22 -5
  155. package/lib/persistence/decorators.cjs +11 -1
  156. package/lib/persistence/decorators.d.ts +10 -0
  157. package/lib/persistence/errors.cjs +26 -9
  158. package/lib/persistence/errors.d.ts +23 -3
  159. package/lib/persistence/index.cjs +4 -1
  160. package/lib/persistence/index.d.ts +3 -0
  161. package/lib/persistence/types.cjs +3 -0
  162. package/lib/persistence/types.d.ts +21 -0
  163. package/lib/query/Condition.cjs +143 -61
  164. package/lib/query/Condition.d.ts +88 -44
  165. package/lib/query/Paginator.cjs +64 -10
  166. package/lib/query/Paginator.d.ts +67 -10
  167. package/lib/query/Statement.cjs +174 -121
  168. package/lib/query/Statement.d.ts +82 -47
  169. package/lib/query/constants.cjs +27 -69
  170. package/lib/query/constants.d.ts +25 -64
  171. package/lib/query/errors.cjs +15 -1
  172. package/lib/query/errors.d.ts +14 -0
  173. package/lib/query/index.cjs +1 -6
  174. package/lib/query/index.d.ts +0 -5
  175. package/lib/query/options.cjs +1 -1
  176. package/lib/query/options.d.ts +69 -178
  177. package/lib/query/selectors.cjs +1 -1
  178. package/lib/query/selectors.d.ts +20 -24
  179. package/lib/ram/RamAdapter.cjs +358 -172
  180. package/lib/ram/RamAdapter.d.ts +322 -20
  181. package/lib/ram/RamContext.cjs +18 -3
  182. package/lib/ram/RamContext.d.ts +16 -1
  183. package/lib/ram/RamPaginator.cjs +58 -6
  184. package/lib/ram/RamPaginator.d.ts +51 -6
  185. package/lib/ram/RamSequence.cjs +52 -41
  186. package/lib/ram/RamSequence.d.ts +49 -24
  187. package/lib/ram/RamStatement.cjs +175 -6
  188. package/lib/ram/RamStatement.d.ts +84 -6
  189. package/lib/ram/constants.cjs +13 -0
  190. package/lib/ram/constants.d.ts +9 -0
  191. package/lib/ram/handlers.cjs +30 -0
  192. package/lib/ram/handlers.d.ts +25 -0
  193. package/lib/ram/index.cjs +9 -5
  194. package/lib/ram/index.d.ts +4 -4
  195. package/lib/ram/model/RamSequence.cjs +19 -1
  196. package/lib/ram/model/RamSequence.d.ts +21 -9
  197. package/lib/ram/types.cjs +1 -1
  198. package/lib/ram/types.d.ts +47 -5
  199. package/lib/repository/Repository.cjs +445 -42
  200. package/lib/repository/Repository.d.ts +381 -22
  201. package/lib/repository/constants.cjs +24 -14
  202. package/lib/repository/constants.d.ts +23 -13
  203. package/lib/repository/decorators.cjs +28 -1
  204. package/lib/repository/decorators.d.ts +27 -0
  205. package/lib/repository/errors.cjs +14 -19
  206. package/lib/repository/errors.d.ts +12 -11
  207. package/lib/repository/injectables.cjs +19 -1
  208. package/lib/repository/injectables.d.ts +18 -0
  209. package/lib/repository/types.cjs +1 -1
  210. package/lib/repository/types.d.ts +13 -1
  211. package/lib/repository/utils.cjs +12 -1
  212. package/lib/repository/utils.d.ts +11 -0
  213. package/lib/utils/decorators.cjs +22 -0
  214. package/lib/utils/decorators.d.ts +9 -0
  215. package/lib/utils/errors.cjs +69 -0
  216. package/lib/utils/errors.d.ts +56 -0
  217. package/lib/{validators → utils}/index.cjs +2 -2
  218. package/lib/utils/index.d.ts +2 -0
  219. package/package.json +5 -5
  220. package/lib/esm/interfaces/Builder.d.ts +0 -16
  221. package/lib/esm/interfaces/Builder.js +0 -2
  222. package/lib/esm/model/IdentifiedBaseModel.d.ts +0 -7
  223. package/lib/esm/model/IdentifiedBaseModel.js +0 -25
  224. package/lib/esm/query/Clause.d.ts +0 -50
  225. package/lib/esm/query/Clause.js +0 -82
  226. package/lib/esm/query/ClauseFactory.d.ts +0 -71
  227. package/lib/esm/query/ClauseFactory.js +0 -6
  228. package/lib/esm/query/Query.d.ts +0 -43
  229. package/lib/esm/query/Query.js +0 -54
  230. package/lib/esm/query/clauses/FromClause.d.ts +0 -45
  231. package/lib/esm/query/clauses/FromClause.js +0 -59
  232. package/lib/esm/query/clauses/GroupByClause.d.ts +0 -21
  233. package/lib/esm/query/clauses/GroupByClause.js +0 -19
  234. package/lib/esm/query/clauses/InsertClause.d.ts +0 -37
  235. package/lib/esm/query/clauses/InsertClause.js +0 -55
  236. package/lib/esm/query/clauses/LimitClause.d.ts +0 -29
  237. package/lib/esm/query/clauses/LimitClause.js +0 -27
  238. package/lib/esm/query/clauses/OffsetClause.d.ts +0 -21
  239. package/lib/esm/query/clauses/OffsetClause.js +0 -19
  240. package/lib/esm/query/clauses/OrderByClause.d.ts +0 -37
  241. package/lib/esm/query/clauses/OrderByClause.js +0 -39
  242. package/lib/esm/query/clauses/SelectClause.d.ts +0 -47
  243. package/lib/esm/query/clauses/SelectClause.js +0 -62
  244. package/lib/esm/query/clauses/SelectorBasedClause.d.ts +0 -25
  245. package/lib/esm/query/clauses/SelectorBasedClause.js +0 -44
  246. package/lib/esm/query/clauses/ValuesClause.d.ts +0 -21
  247. package/lib/esm/query/clauses/ValuesClause.js +0 -36
  248. package/lib/esm/query/clauses/WhereClause.d.ts +0 -46
  249. package/lib/esm/query/clauses/WhereClause.js +0 -71
  250. package/lib/esm/query/clauses/index.d.ts +0 -10
  251. package/lib/esm/query/clauses/index.js +0 -11
  252. package/lib/esm/query/types.d.ts +0 -2
  253. package/lib/esm/query/types.js +0 -2
  254. package/lib/esm/ram/RamClauseFactory.d.ts +0 -17
  255. package/lib/esm/ram/RamClauseFactory.js +0 -92
  256. package/lib/esm/ram/clauses/FromClause.d.ts +0 -7
  257. package/lib/esm/ram/clauses/FromClause.js +0 -11
  258. package/lib/esm/ram/clauses/InsertClause.d.ts +0 -7
  259. package/lib/esm/ram/clauses/InsertClause.js +0 -13
  260. package/lib/esm/ram/clauses/OrderByClause.d.ts +0 -7
  261. package/lib/esm/ram/clauses/OrderByClause.js +0 -39
  262. package/lib/esm/ram/clauses/SelectClause.d.ts +0 -7
  263. package/lib/esm/ram/clauses/SelectClause.js +0 -16
  264. package/lib/esm/ram/clauses/ValuesClause.d.ts +0 -7
  265. package/lib/esm/ram/clauses/ValuesClause.js +0 -12
  266. package/lib/esm/ram/clauses/WhereClause.d.ts +0 -7
  267. package/lib/esm/ram/clauses/WhereClause.js +0 -11
  268. package/lib/esm/ram/clauses/index.d.ts +0 -6
  269. package/lib/esm/ram/clauses/index.js +0 -7
  270. package/lib/esm/validators/ClauseSequenceValidator.d.ts +0 -28
  271. package/lib/esm/validators/ClauseSequenceValidator.js +0 -95
  272. package/lib/esm/validators/decorators.d.ts +0 -10
  273. package/lib/esm/validators/decorators.js +0 -24
  274. package/lib/esm/validators/index.d.ts +0 -2
  275. package/lib/esm/validators/index.js +0 -3
  276. package/lib/interfaces/Builder.cjs +0 -3
  277. package/lib/interfaces/Builder.d.ts +0 -16
  278. package/lib/model/IdentifiedBaseModel.cjs +0 -29
  279. package/lib/model/IdentifiedBaseModel.d.ts +0 -7
  280. package/lib/query/Clause.cjs +0 -86
  281. package/lib/query/Clause.d.ts +0 -50
  282. package/lib/query/ClauseFactory.cjs +0 -10
  283. package/lib/query/ClauseFactory.d.ts +0 -71
  284. package/lib/query/Query.cjs +0 -58
  285. package/lib/query/Query.d.ts +0 -43
  286. package/lib/query/clauses/FromClause.cjs +0 -63
  287. package/lib/query/clauses/FromClause.d.ts +0 -45
  288. package/lib/query/clauses/GroupByClause.cjs +0 -23
  289. package/lib/query/clauses/GroupByClause.d.ts +0 -21
  290. package/lib/query/clauses/InsertClause.cjs +0 -59
  291. package/lib/query/clauses/InsertClause.d.ts +0 -37
  292. package/lib/query/clauses/LimitClause.cjs +0 -31
  293. package/lib/query/clauses/LimitClause.d.ts +0 -29
  294. package/lib/query/clauses/OffsetClause.cjs +0 -23
  295. package/lib/query/clauses/OffsetClause.d.ts +0 -21
  296. package/lib/query/clauses/OrderByClause.cjs +0 -43
  297. package/lib/query/clauses/OrderByClause.d.ts +0 -37
  298. package/lib/query/clauses/SelectClause.cjs +0 -66
  299. package/lib/query/clauses/SelectClause.d.ts +0 -47
  300. package/lib/query/clauses/SelectorBasedClause.cjs +0 -48
  301. package/lib/query/clauses/SelectorBasedClause.d.ts +0 -25
  302. package/lib/query/clauses/ValuesClause.cjs +0 -40
  303. package/lib/query/clauses/ValuesClause.d.ts +0 -21
  304. package/lib/query/clauses/WhereClause.cjs +0 -75
  305. package/lib/query/clauses/WhereClause.d.ts +0 -46
  306. package/lib/query/clauses/index.cjs +0 -27
  307. package/lib/query/clauses/index.d.ts +0 -10
  308. package/lib/query/types.cjs +0 -3
  309. package/lib/query/types.d.ts +0 -2
  310. package/lib/ram/RamClauseFactory.cjs +0 -96
  311. package/lib/ram/RamClauseFactory.d.ts +0 -17
  312. package/lib/ram/clauses/FromClause.cjs +0 -15
  313. package/lib/ram/clauses/FromClause.d.ts +0 -7
  314. package/lib/ram/clauses/InsertClause.cjs +0 -17
  315. package/lib/ram/clauses/InsertClause.d.ts +0 -7
  316. package/lib/ram/clauses/OrderByClause.cjs +0 -43
  317. package/lib/ram/clauses/OrderByClause.d.ts +0 -7
  318. package/lib/ram/clauses/SelectClause.cjs +0 -20
  319. package/lib/ram/clauses/SelectClause.d.ts +0 -7
  320. package/lib/ram/clauses/ValuesClause.cjs +0 -16
  321. package/lib/ram/clauses/ValuesClause.d.ts +0 -7
  322. package/lib/ram/clauses/WhereClause.cjs +0 -15
  323. package/lib/ram/clauses/WhereClause.d.ts +0 -7
  324. package/lib/ram/clauses/index.cjs +0 -23
  325. package/lib/ram/clauses/index.d.ts +0 -6
  326. package/lib/validators/ClauseSequenceValidator.cjs +0 -98
  327. package/lib/validators/ClauseSequenceValidator.d.ts +0 -28
  328. package/lib/validators/decorators.cjs +0 -27
  329. package/lib/validators/decorators.d.ts +0 -10
  330. package/lib/validators/index.d.ts +0 -2
@@ -1,41 +1,343 @@
1
- import { Context } from "@decaf-ts/db-decorators";
2
- import { RamFlags, RamQuery, RamStorage } from "./types";
1
+ import { RamFlags, RawRamQuery, RamStorage, RamRepository } from "./types";
3
2
  import { RamStatement } from "./RamStatement";
4
- import { RamClauseFactory } from "./RamClauseFactory";
5
3
  import { RamContext } from "./RamContext";
6
- import { Repo } from "../repository/Repository";
7
- import { RelationsMetadata } from "../model/types";
8
4
  import { Adapter, Sequence } from "../persistence";
9
- import { Paginator } from "../query/Paginator";
10
- import { ClauseFactory, Condition } from "../query";
11
5
  import { SequenceOptions } from "../interfaces";
12
6
  import { Constructor, Model } from "@decaf-ts/decorator-validation";
13
- import { BaseError } from "@decaf-ts/db-decorators";
14
- export declare function createdByOnRamCreateUpdate<M extends Model, R extends Repo<M, C, F>, V extends RelationsMetadata, F extends RamFlags, C extends Context<F>>(this: R, context: Context<F>, data: V, key: keyof M, model: M): Promise<void>;
15
- export declare class RamAdapter extends Adapter<RamStorage, RamQuery<any>, RamFlags, Context<RamFlags>> {
16
- protected factory?: RamClauseFactory;
17
- constructor(flavour?: string);
18
- context<M extends Model, C extends RamContext, F extends RamFlags>(operation: any, overrides: Partial<RamFlags>, model: Constructor<M>, ...args: any[]): Promise<C>;
7
+ import { BaseError, OperationKeys } from "@decaf-ts/db-decorators";
8
+ /**
9
+ * @description In-memory adapter for data persistence
10
+ * @summary The RamAdapter provides an in-memory implementation of the persistence layer.
11
+ * It stores data in JavaScript Maps and provides CRUD operations and query capabilities.
12
+ * This adapter is useful for testing, prototyping, and applications that don't require
13
+ * persistent storage across application restarts.
14
+ * @class RamAdapter
15
+ * @category Ram
16
+ * @example
17
+ * ```typescript
18
+ * // Create a new RAM adapter
19
+ * const adapter = new RamAdapter('myRamAdapter');
20
+ *
21
+ * // Create a repository for a model
22
+ * const userRepo = new (adapter.repository<User>())(User, adapter);
23
+ *
24
+ * // Perform CRUD operations
25
+ * const user = new User({ name: 'John', email: 'john@example.com' });
26
+ * await userRepo.create(user);
27
+ * const retrievedUser = await userRepo.findById(user.id);
28
+ * ```
29
+ * @mermaid
30
+ * sequenceDiagram
31
+ * participant Client
32
+ * participant Repository
33
+ * participant RamAdapter
34
+ * participant Storage as In-Memory Storage
35
+ *
36
+ * Client->>Repository: create(model)
37
+ * Repository->>RamAdapter: create(tableName, id, model)
38
+ * RamAdapter->>RamAdapter: lock.acquire()
39
+ * RamAdapter->>Storage: set(id, model)
40
+ * RamAdapter->>RamAdapter: lock.release()
41
+ * RamAdapter-->>Repository: model
42
+ * Repository-->>Client: model
43
+ *
44
+ * Client->>Repository: findById(id)
45
+ * Repository->>RamAdapter: read(tableName, id)
46
+ * RamAdapter->>Storage: get(id)
47
+ * Storage-->>RamAdapter: model
48
+ * RamAdapter-->>Repository: model
49
+ * Repository-->>Client: model
50
+ */
51
+ export declare class RamAdapter extends Adapter<RamStorage, RawRamQuery<any>, RamFlags, RamContext> {
52
+ constructor(alias?: string);
53
+ /**
54
+ * @description Gets the repository constructor for a model
55
+ * @summary Returns a constructor for creating repositories that work with the specified model type.
56
+ * This method overrides the base implementation to provide RAM-specific repository functionality.
57
+ * @template M - The model type for the repository
58
+ * @return {Constructor<RamRepository<M>>} A constructor for creating RAM repositories
59
+ */
60
+ repository<M extends Model>(): Constructor<RamRepository<M>>;
61
+ /**
62
+ * @description Creates operation flags with UUID
63
+ * @summary Extends the base flags with a UUID for user identification.
64
+ * This method ensures that all operations have a unique identifier for tracking purposes.
65
+ * @template M - The model type for the operation
66
+ * @param {OperationKeys} operation - The type of operation being performed
67
+ * @param {Constructor<M>} model - The model constructor
68
+ * @param {Partial<RamFlags>} flags - Partial flags to be extended
69
+ * @return {RamFlags} Complete flags with UUID
70
+ */
71
+ flags<M extends Model>(operation: OperationKeys, model: Constructor<M>, flags: Partial<RamFlags>): RamFlags;
72
+ Context: typeof RamContext;
19
73
  private indexes;
20
74
  private lock;
21
- private sequences;
75
+ /**
76
+ * @description Initializes the RAM adapter
77
+ * @summary A no-op initialization method for the RAM adapter.
78
+ * Since RAM adapter doesn't require any setup, this method simply resolves immediately.
79
+ * @param {...any[]} args - Initialization arguments (unused)
80
+ * @return {Promise<void>} A promise that resolves when initialization is complete
81
+ */
22
82
  initialize(...args: any[]): Promise<void>;
83
+ /**
84
+ * @description Indexes models in the RAM adapter
85
+ * @summary A no-op indexing method for the RAM adapter.
86
+ * Since RAM adapter doesn't require explicit indexing, this method simply resolves immediately.
87
+ * @param models - Models to be indexed (unused)
88
+ * @return {Promise<any>} A promise that resolves when indexing is complete
89
+ */
23
90
  index(...models: Record<string, any>[]): Promise<any>;
91
+ /**
92
+ * @description Prepares a model for storage
93
+ * @summary Converts a model instance to a format suitable for storage in the RAM adapter.
94
+ * This method extracts the primary key and creates a record without the primary key field.
95
+ * @template M - The model type being prepared
96
+ * @param {M} model - The model instance to prepare
97
+ * @param pk - The primary key property name
98
+ * @return Object containing the record and ID
99
+ */
24
100
  prepare<M extends Model>(model: M, pk: keyof M): {
25
101
  record: Record<string, any>;
26
102
  id: string;
27
103
  };
104
+ /**
105
+ * @description Converts a stored record back to a model instance
106
+ * @summary Reconstructs a model instance from a stored record by adding back the primary key.
107
+ * This method is the inverse of the prepare method.
108
+ * @template M - The model type to revert to
109
+ * @param {Record<string, any>} obj - The stored record
110
+ * @param {string | Constructor<M>} clazz - The model class or name
111
+ * @param pk - The primary key property name
112
+ * @param {string | number} id - The primary key value
113
+ * @return {M} The reconstructed model instance
114
+ */
28
115
  revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>, pk: keyof M, id: string | number): M;
116
+ /**
117
+ * @description Creates a new record in the in-memory storage
118
+ * @summary Stores a new record in the specified table with the given ID.
119
+ * This method acquires a lock to ensure thread safety, creates the table if it doesn't exist,
120
+ * checks for conflicts, and stores the model.
121
+ * @param {string} tableName - The name of the table to store the record in
122
+ * @param {string | number} id - The unique identifier for the record
123
+ * @param {Record<string, any>} model - The record data to store
124
+ * @return {Promise<Record<string, any>>} A promise that resolves to the stored record
125
+ * @mermaid
126
+ * sequenceDiagram
127
+ * participant Caller
128
+ * participant RamAdapter
129
+ * participant Storage as In-Memory Storage
130
+ *
131
+ * Caller->>RamAdapter: create(tableName, id, model)
132
+ * RamAdapter->>RamAdapter: lock.acquire()
133
+ * RamAdapter->>Storage: has(tableName)
134
+ * alt Table doesn't exist
135
+ * RamAdapter->>Storage: set(tableName, new Map())
136
+ * end
137
+ * RamAdapter->>Storage: has(id)
138
+ * alt Record exists
139
+ * RamAdapter-->>Caller: throw ConflictError
140
+ * end
141
+ * RamAdapter->>Storage: set(id, model)
142
+ * RamAdapter->>RamAdapter: lock.release()
143
+ * RamAdapter-->>Caller: model
144
+ */
29
145
  create(tableName: string, id: string | number, model: Record<string, any>): Promise<Record<string, any>>;
146
+ /**
147
+ * @description Retrieves a record from in-memory storage
148
+ * @summary Fetches a record with the specified ID from the given table.
149
+ * This method checks if the table and record exist and throws appropriate errors if not.
150
+ * @param {string} tableName - The name of the table to retrieve from
151
+ * @param {string | number} id - The unique identifier of the record to retrieve
152
+ * @return {Promise<Record<string, any>>} A promise that resolves to the retrieved record
153
+ * @mermaid
154
+ * sequenceDiagram
155
+ * participant Caller
156
+ * participant RamAdapter
157
+ * participant Storage as In-Memory Storage
158
+ *
159
+ * Caller->>RamAdapter: read(tableName, id)
160
+ * RamAdapter->>Storage: has(tableName)
161
+ * alt Table doesn't exist
162
+ * RamAdapter-->>Caller: throw NotFoundError
163
+ * end
164
+ * RamAdapter->>Storage: has(id)
165
+ * alt Record doesn't exist
166
+ * RamAdapter-->>Caller: throw NotFoundError
167
+ * end
168
+ * RamAdapter->>Storage: get(id)
169
+ * Storage-->>RamAdapter: record
170
+ * RamAdapter-->>Caller: record
171
+ */
30
172
  read(tableName: string, id: string | number): Promise<Record<string, any>>;
173
+ /**
174
+ * @description Updates an existing record in the in-memory storage
175
+ * @summary Updates a record with the specified ID in the given table.
176
+ * This method acquires a lock to ensure thread safety, checks if the table and record exist,
177
+ * and updates the record with the new data.
178
+ * @param {string} tableName - The name of the table containing the record
179
+ * @param {string | number} id - The unique identifier of the record to update
180
+ * @param {Record<string, any>} model - The new record data
181
+ * @return {Promise<Record<string, any>>} A promise that resolves to the updated record
182
+ * @mermaid
183
+ * sequenceDiagram
184
+ * participant Caller
185
+ * participant RamAdapter
186
+ * participant Storage as In-Memory Storage
187
+ *
188
+ * Caller->>RamAdapter: update(tableName, id, model)
189
+ * RamAdapter->>RamAdapter: lock.acquire()
190
+ * RamAdapter->>Storage: has(tableName)
191
+ * alt Table doesn't exist
192
+ * RamAdapter-->>Caller: throw NotFoundError
193
+ * end
194
+ * RamAdapter->>Storage: has(id)
195
+ * alt Record doesn't exist
196
+ * RamAdapter-->>Caller: throw NotFoundError
197
+ * end
198
+ * RamAdapter->>Storage: set(id, model)
199
+ * RamAdapter->>RamAdapter: lock.release()
200
+ * RamAdapter-->>Caller: model
201
+ */
31
202
  update(tableName: string, id: string | number, model: Record<string, any>): Promise<Record<string, any>>;
203
+ /**
204
+ * @description Deletes a record from the in-memory storage
205
+ * @summary Removes a record with the specified ID from the given table.
206
+ * This method acquires a lock to ensure thread safety, checks if the table and record exist,
207
+ * retrieves the record before deletion, and then removes it from storage.
208
+ * @param {string} tableName - The name of the table containing the record
209
+ * @param {string | number} id - The unique identifier of the record to delete
210
+ * @return {Promise<Record<string, any>>} A promise that resolves to the deleted record
211
+ * @mermaid
212
+ * sequenceDiagram
213
+ * participant Caller
214
+ * participant RamAdapter
215
+ * participant Storage as In-Memory Storage
216
+ *
217
+ * Caller->>RamAdapter: delete(tableName, id)
218
+ * RamAdapter->>RamAdapter: lock.acquire()
219
+ * RamAdapter->>Storage: has(tableName)
220
+ * alt Table doesn't exist
221
+ * RamAdapter-->>Caller: throw NotFoundError
222
+ * end
223
+ * RamAdapter->>Storage: has(id)
224
+ * alt Record doesn't exist
225
+ * RamAdapter-->>Caller: throw NotFoundError
226
+ * end
227
+ * RamAdapter->>Storage: get(id)
228
+ * Storage-->>RamAdapter: record
229
+ * RamAdapter->>Storage: delete(id)
230
+ * RamAdapter->>RamAdapter: lock.release()
231
+ * RamAdapter-->>Caller: record
232
+ */
32
233
  delete(tableName: string, id: string | number): Promise<Record<string, any>>;
33
- protected tableFor<M extends Model>(from: string | Constructor<M>): Record<string, any>;
34
- raw<Z>(rawInput: RamQuery<any>, process: boolean): Promise<Z>;
35
- paginate<Z>(rawInput: string): Promise<Paginator<Z, string>>;
234
+ /**
235
+ * @description Gets or creates a table in the in-memory storage
236
+ * @summary Retrieves the Map representing a table for a given model or table name.
237
+ * If the table doesn't exist, it creates a new one. This is a helper method used
238
+ * by other methods to access the correct storage location.
239
+ * @template M - The model type for the table
240
+ * @param {string | Constructor<M>} from - The model class or table name
241
+ * @return {Map<string | number, any> | undefined} The table Map or undefined
242
+ */
243
+ protected tableFor<M extends Model>(from: string | Constructor<M>): Map<string | number, any> | undefined;
244
+ /**
245
+ * @description Executes a raw query against the in-memory storage
246
+ * @summary Performs a query operation on the in-memory data store using the provided query specification.
247
+ * This method supports filtering, sorting, pagination, and field selection.
248
+ * @template R - The return type of the query
249
+ * @param {RawRamQuery<any>} rawInput - The query specification
250
+ * @return {Promise<R>} A promise that resolves to the query results
251
+ * @mermaid
252
+ * sequenceDiagram
253
+ * participant Caller
254
+ * participant RamAdapter
255
+ * participant Storage as In-Memory Storage
256
+ *
257
+ * Caller->>RamAdapter: raw(rawInput)
258
+ * RamAdapter->>RamAdapter: tableFor(from)
259
+ * alt Table doesn't exist
260
+ * RamAdapter-->>Caller: throw InternalError
261
+ * end
262
+ * RamAdapter->>RamAdapter: findPrimaryKey(new from())
263
+ * RamAdapter->>Storage: entries()
264
+ * Storage-->>RamAdapter: entries
265
+ * loop For each entry
266
+ * RamAdapter->>RamAdapter: revert(r, from, id, pk)
267
+ * end
268
+ * alt Where condition exists
269
+ * RamAdapter->>RamAdapter: result.filter(where)
270
+ * end
271
+ * alt Sort condition exists
272
+ * RamAdapter->>RamAdapter: result.sort(sort)
273
+ * end
274
+ * alt Skip specified
275
+ * RamAdapter->>RamAdapter: result.slice(skip)
276
+ * end
277
+ * alt Limit specified
278
+ * RamAdapter->>RamAdapter: result.slice(0, limit)
279
+ * end
280
+ * alt Select fields specified
281
+ * loop For each result
282
+ * RamAdapter->>RamAdapter: Filter to selected fields
283
+ * end
284
+ * end
285
+ * RamAdapter-->>Caller: result
286
+ */
287
+ raw<R>(rawInput: RawRamQuery<any>): Promise<R>;
288
+ /**
289
+ * @description Parses and converts errors to appropriate types
290
+ * @summary Ensures that errors are of the correct type for consistent error handling.
291
+ * If the error is already a BaseError, it's returned as is; otherwise, it's wrapped in an InternalError.
292
+ * @template V - The expected error type, extending BaseError
293
+ * @param {Error} err - The error to parse
294
+ * @return {V} The parsed error of the expected type
295
+ */
36
296
  parseError<V extends BaseError>(err: Error): V;
37
- get Clauses(): ClauseFactory<RamStorage, RamQuery<any>, typeof this>;
38
- get Statement(): RamStatement<any>;
297
+ /**
298
+ * @description Creates a new statement builder for queries
299
+ * @summary Factory method that creates a new RamStatement instance for building queries.
300
+ * This method allows for fluent query construction against the RAM adapter.
301
+ * @template M - The model type for the statement
302
+ * @return {RamStatement<M, any>} A new statement builder instance
303
+ */
304
+ Statement<M extends Model>(): RamStatement<M, any>;
305
+ /**
306
+ * @description Creates a new sequence for generating sequential IDs
307
+ * @summary Factory method that creates a new RamSequence instance for ID generation.
308
+ * This method provides a way to create auto-incrementing sequences for entity IDs.
309
+ * @param {SequenceOptions} options - Configuration options for the sequence
310
+ * @return {Promise<Sequence>} A promise that resolves to the new sequence instance
311
+ */
39
312
  Sequence(options: SequenceOptions): Promise<Sequence>;
40
- parseCondition(condition: Condition): RamQuery<any>;
313
+ /**
314
+ * @description Sets up RAM-specific decorations for model properties
315
+ * @summary Configures decorations for createdBy and updatedBy fields in the RAM adapter.
316
+ * This static method is called during initialization to set up handlers that automatically
317
+ * populate these fields with the current user's UUID during create and update operations.
318
+ * @return {void}
319
+ * @mermaid
320
+ * sequenceDiagram
321
+ * participant RamAdapter
322
+ * participant Decoration
323
+ * participant Repository
324
+ *
325
+ * RamAdapter->>Repository: key(PersistenceKeys.CREATED_BY)
326
+ * Repository-->>RamAdapter: createdByKey
327
+ * RamAdapter->>Repository: key(PersistenceKeys.UPDATED_BY)
328
+ * Repository-->>RamAdapter: updatedByKey
329
+ *
330
+ * RamAdapter->>Decoration: flavouredAs(RamFlavour)
331
+ * Decoration-->>RamAdapter: DecoratorBuilder
332
+ * RamAdapter->>Decoration: for(createdByKey)
333
+ * RamAdapter->>Decoration: define(onCreate, propMetadata)
334
+ * RamAdapter->>Decoration: apply()
335
+ *
336
+ * RamAdapter->>Decoration: flavouredAs(RamFlavour)
337
+ * Decoration-->>RamAdapter: DecoratorBuilder
338
+ * RamAdapter->>Decoration: for(updatedByKey)
339
+ * RamAdapter->>Decoration: define(onCreate, propMetadata)
340
+ * RamAdapter->>Decoration: apply()
341
+ */
342
+ static decoration(): void;
41
343
  }