@pazos-dev/contability-core 0.0.0-stage → 0.1.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 (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -2
  3. package/dist/adapters/memory/in-memory-accounting.d.ts +22 -0
  4. package/dist/adapters/memory/in-memory-accounting.js +28 -0
  5. package/dist/adapters/memory/in-memory-accounting.js.map +1 -0
  6. package/dist/adapters/memory/index.d.ts +3 -0
  7. package/dist/adapters/memory/index.js +3 -0
  8. package/dist/adapters/memory/index.js.map +1 -0
  9. package/dist/adapters/memory/repositories.d.ts +23 -0
  10. package/dist/adapters/memory/repositories.js +169 -0
  11. package/dist/adapters/memory/repositories.js.map +1 -0
  12. package/dist/adapters/memory/store.d.ts +61 -0
  13. package/dist/adapters/memory/store.js +59 -0
  14. package/dist/adapters/memory/store.js.map +1 -0
  15. package/dist/core/application/dto.d.ts +368 -0
  16. package/dist/core/application/dto.js +2 -0
  17. package/dist/core/application/dto.js.map +1 -0
  18. package/dist/core/application/errors.d.ts +45 -0
  19. package/dist/core/application/errors.js +120 -0
  20. package/dist/core/application/errors.js.map +1 -0
  21. package/dist/core/application/facade/accounting.d.ts +38 -0
  22. package/dist/core/application/facade/accounting.js +79 -0
  23. package/dist/core/application/facade/accounting.js.map +1 -0
  24. package/dist/core/application/index.d.ts +5 -0
  25. package/dist/core/application/index.js +7 -0
  26. package/dist/core/application/index.js.map +1 -0
  27. package/dist/core/application/ports.d.ts +134 -0
  28. package/dist/core/application/ports.js +2 -0
  29. package/dist/core/application/ports.js.map +1 -0
  30. package/dist/core/application/use-cases/accounts/accounts.d.ts +21 -0
  31. package/dist/core/application/use-cases/accounts/accounts.js +69 -0
  32. package/dist/core/application/use-cases/accounts/accounts.js.map +1 -0
  33. package/dist/core/application/use-cases/accounts/rules.d.ts +13 -0
  34. package/dist/core/application/use-cases/accounts/rules.js +31 -0
  35. package/dist/core/application/use-cases/accounts/rules.js.map +1 -0
  36. package/dist/core/application/use-cases/entries/entries.d.ts +70 -0
  37. package/dist/core/application/use-cases/entries/entries.js +237 -0
  38. package/dist/core/application/use-cases/entries/entries.js.map +1 -0
  39. package/dist/core/application/use-cases/entries/result.d.ts +54 -0
  40. package/dist/core/application/use-cases/entries/result.js +177 -0
  41. package/dist/core/application/use-cases/entries/result.js.map +1 -0
  42. package/dist/core/application/use-cases/entries/rules.d.ts +40 -0
  43. package/dist/core/application/use-cases/entries/rules.js +57 -0
  44. package/dist/core/application/use-cases/entries/rules.js.map +1 -0
  45. package/dist/core/application/use-cases/journals/journals.d.ts +14 -0
  46. package/dist/core/application/use-cases/journals/journals.js +50 -0
  47. package/dist/core/application/use-cases/journals/journals.js.map +1 -0
  48. package/dist/core/application/use-cases/journals/rules.d.ts +12 -0
  49. package/dist/core/application/use-cases/journals/rules.js +20 -0
  50. package/dist/core/application/use-cases/journals/rules.js.map +1 -0
  51. package/dist/core/application/use-cases/ledgers/ledgers.d.ts +25 -0
  52. package/dist/core/application/use-cases/ledgers/ledgers.js +76 -0
  53. package/dist/core/application/use-cases/ledgers/ledgers.js.map +1 -0
  54. package/dist/core/application/use-cases/ledgers/rules.d.ts +11 -0
  55. package/dist/core/application/use-cases/ledgers/rules.js +19 -0
  56. package/dist/core/application/use-cases/ledgers/rules.js.map +1 -0
  57. package/dist/core/application/use-cases/periods/periods.d.ts +20 -0
  58. package/dist/core/application/use-cases/periods/periods.js +67 -0
  59. package/dist/core/application/use-cases/periods/periods.js.map +1 -0
  60. package/dist/core/application/use-cases/periods/rules.d.ts +13 -0
  61. package/dist/core/application/use-cases/periods/rules.js +21 -0
  62. package/dist/core/application/use-cases/periods/rules.js.map +1 -0
  63. package/dist/core/application/use-cases/reports/aggregate.d.ts +51 -0
  64. package/dist/core/application/use-cases/reports/aggregate.js +125 -0
  65. package/dist/core/application/use-cases/reports/aggregate.js.map +1 -0
  66. package/dist/core/application/use-cases/reports/movements.d.ts +73 -0
  67. package/dist/core/application/use-cases/reports/movements.js +226 -0
  68. package/dist/core/application/use-cases/reports/movements.js.map +1 -0
  69. package/dist/core/application/use-cases/reports/reports.d.ts +49 -0
  70. package/dist/core/application/use-cases/reports/reports.js +110 -0
  71. package/dist/core/application/use-cases/reports/reports.js.map +1 -0
  72. package/dist/core/application/use-cases/reports/rules.d.ts +54 -0
  73. package/dist/core/application/use-cases/reports/rules.js +69 -0
  74. package/dist/core/application/use-cases/reports/rules.js.map +1 -0
  75. package/dist/core/application/use-cases/shared/idempotency.d.ts +42 -0
  76. package/dist/core/application/use-cases/shared/idempotency.js +78 -0
  77. package/dist/core/application/use-cases/shared/idempotency.js.map +1 -0
  78. package/dist/core/application/use-cases/shared/index.d.ts +1 -0
  79. package/dist/core/application/use-cases/shared/index.js +3 -0
  80. package/dist/core/application/use-cases/shared/index.js.map +1 -0
  81. package/dist/core/application/use-cases/shared/rules.d.ts +62 -0
  82. package/dist/core/application/use-cases/shared/rules.js +110 -0
  83. package/dist/core/application/use-cases/shared/rules.js.map +1 -0
  84. package/dist/core/domain/account/account.d.ts +29 -0
  85. package/dist/core/domain/account/account.js +134 -0
  86. package/dist/core/domain/account/account.js.map +1 -0
  87. package/dist/core/domain/account/dto/account-dto.d.ts +27 -0
  88. package/dist/core/domain/account/dto/account-dto.js +2 -0
  89. package/dist/core/domain/account/dto/account-dto.js.map +1 -0
  90. package/dist/core/domain/account/errors/account-errors.d.ts +10 -0
  91. package/dist/core/domain/account/errors/account-errors.js +20 -0
  92. package/dist/core/domain/account/errors/account-errors.js.map +1 -0
  93. package/dist/core/domain/account/index.d.ts +7 -0
  94. package/dist/core/domain/account/index.js +5 -0
  95. package/dist/core/domain/account/index.js.map +1 -0
  96. package/dist/core/domain/account/types/account-status.d.ts +1 -0
  97. package/dist/core/domain/account/types/account-status.js +2 -0
  98. package/dist/core/domain/account/types/account-status.js.map +1 -0
  99. package/dist/core/domain/account/types/account-type.d.ts +4 -0
  100. package/dist/core/domain/account/types/account-type.js +6 -0
  101. package/dist/core/domain/account/types/account-type.js.map +1 -0
  102. package/dist/core/domain/account/value-objects/account-code.d.ts +12 -0
  103. package/dist/core/domain/account/value-objects/account-code.js +35 -0
  104. package/dist/core/domain/account/value-objects/account-code.js.map +1 -0
  105. package/dist/core/domain/entries/dto/journal-entry-dto.d.ts +72 -0
  106. package/dist/core/domain/entries/dto/journal-entry-dto.js +2 -0
  107. package/dist/core/domain/entries/dto/journal-entry-dto.js.map +1 -0
  108. package/dist/core/domain/entries/dto/journal-entry-line-dto.d.ts +47 -0
  109. package/dist/core/domain/entries/dto/journal-entry-line-dto.js +2 -0
  110. package/dist/core/domain/entries/dto/journal-entry-line-dto.js.map +1 -0
  111. package/dist/core/domain/entries/entry-text.d.ts +11 -0
  112. package/dist/core/domain/entries/entry-text.js +22 -0
  113. package/dist/core/domain/entries/entry-text.js.map +1 -0
  114. package/dist/core/domain/entries/errors/entry-errors.d.ts +23 -0
  115. package/dist/core/domain/entries/errors/entry-errors.js +48 -0
  116. package/dist/core/domain/entries/errors/entry-errors.js.map +1 -0
  117. package/dist/core/domain/entries/index.d.ts +8 -0
  118. package/dist/core/domain/entries/index.js +4 -0
  119. package/dist/core/domain/entries/index.js.map +1 -0
  120. package/dist/core/domain/entries/journal-entry.d.ts +84 -0
  121. package/dist/core/domain/entries/journal-entry.js +413 -0
  122. package/dist/core/domain/entries/journal-entry.js.map +1 -0
  123. package/dist/core/domain/entries/types/entry-status.d.ts +5 -0
  124. package/dist/core/domain/entries/types/entry-status.js +2 -0
  125. package/dist/core/domain/entries/types/entry-status.js.map +1 -0
  126. package/dist/core/domain/entries/types/posting-side.d.ts +2 -0
  127. package/dist/core/domain/entries/types/posting-side.js +2 -0
  128. package/dist/core/domain/entries/types/posting-side.js.map +1 -0
  129. package/dist/core/domain/entries/value-objects/journal-entry-line.d.ts +66 -0
  130. package/dist/core/domain/entries/value-objects/journal-entry-line.js +197 -0
  131. package/dist/core/domain/entries/value-objects/journal-entry-line.js.map +1 -0
  132. package/dist/core/domain/journal/dto/journal-dto.d.ts +19 -0
  133. package/dist/core/domain/journal/dto/journal-dto.js +2 -0
  134. package/dist/core/domain/journal/dto/journal-dto.js.map +1 -0
  135. package/dist/core/domain/journal/errors/journal-errors.d.ts +8 -0
  136. package/dist/core/domain/journal/errors/journal-errors.js +13 -0
  137. package/dist/core/domain/journal/errors/journal-errors.js.map +1 -0
  138. package/dist/core/domain/journal/index.d.ts +5 -0
  139. package/dist/core/domain/journal/index.js +3 -0
  140. package/dist/core/domain/journal/index.js.map +1 -0
  141. package/dist/core/domain/journal/journal.d.ts +23 -0
  142. package/dist/core/domain/journal/journal.js +82 -0
  143. package/dist/core/domain/journal/journal.js.map +1 -0
  144. package/dist/core/domain/journal/types/journal-status.d.ts +1 -0
  145. package/dist/core/domain/journal/types/journal-status.js +2 -0
  146. package/dist/core/domain/journal/types/journal-status.js.map +1 -0
  147. package/dist/core/domain/ledger/dto/ledger-dto.d.ts +20 -0
  148. package/dist/core/domain/ledger/dto/ledger-dto.js +2 -0
  149. package/dist/core/domain/ledger/dto/ledger-dto.js.map +1 -0
  150. package/dist/core/domain/ledger/errors/ledger-errors.d.ts +8 -0
  151. package/dist/core/domain/ledger/errors/ledger-errors.js +13 -0
  152. package/dist/core/domain/ledger/errors/ledger-errors.js.map +1 -0
  153. package/dist/core/domain/ledger/index.d.ts +5 -0
  154. package/dist/core/domain/ledger/index.js +3 -0
  155. package/dist/core/domain/ledger/index.js.map +1 -0
  156. package/dist/core/domain/ledger/ledger.d.ts +37 -0
  157. package/dist/core/domain/ledger/ledger.js +110 -0
  158. package/dist/core/domain/ledger/ledger.js.map +1 -0
  159. package/dist/core/domain/ledger/types/ledger-status.d.ts +1 -0
  160. package/dist/core/domain/ledger/types/ledger-status.js +2 -0
  161. package/dist/core/domain/ledger/types/ledger-status.js.map +1 -0
  162. package/dist/core/domain/period/accounting-period.d.ts +24 -0
  163. package/dist/core/domain/period/accounting-period.js +95 -0
  164. package/dist/core/domain/period/accounting-period.js.map +1 -0
  165. package/dist/core/domain/period/dto/accounting-period-dto.d.ts +22 -0
  166. package/dist/core/domain/period/dto/accounting-period-dto.js +2 -0
  167. package/dist/core/domain/period/dto/accounting-period-dto.js.map +1 -0
  168. package/dist/core/domain/period/errors/period-errors.d.ts +10 -0
  169. package/dist/core/domain/period/errors/period-errors.js +19 -0
  170. package/dist/core/domain/period/errors/period-errors.js.map +1 -0
  171. package/dist/core/domain/period/index.d.ts +6 -0
  172. package/dist/core/domain/period/index.js +5 -0
  173. package/dist/core/domain/period/index.js.map +1 -0
  174. package/dist/core/domain/period/types/period-status.d.ts +4 -0
  175. package/dist/core/domain/period/types/period-status.js +6 -0
  176. package/dist/core/domain/period/types/period-status.js.map +1 -0
  177. package/dist/core/domain/period/value-objects/accounting-date.d.ts +19 -0
  178. package/dist/core/domain/period/value-objects/accounting-date.js +94 -0
  179. package/dist/core/domain/period/value-objects/accounting-date.js.map +1 -0
  180. package/dist/core/domain/shared/describe-value.d.ts +2 -0
  181. package/dist/core/domain/shared/describe-value.js +13 -0
  182. package/dist/core/domain/shared/describe-value.js.map +1 -0
  183. package/dist/core/domain/shared/money/currency-catalog.d.ts +15 -0
  184. package/dist/core/domain/shared/money/currency-catalog.js +211 -0
  185. package/dist/core/domain/shared/money/currency-catalog.js.map +1 -0
  186. package/dist/core/domain/shared/money/currency.d.ts +16 -0
  187. package/dist/core/domain/shared/money/currency.js +68 -0
  188. package/dist/core/domain/shared/money/currency.js.map +1 -0
  189. package/dist/core/domain/shared/money/dto/currency-dto.d.ts +5 -0
  190. package/dist/core/domain/shared/money/dto/currency-dto.js +2 -0
  191. package/dist/core/domain/shared/money/dto/currency-dto.js.map +1 -0
  192. package/dist/core/domain/shared/money/dto/money-dto.d.ts +6 -0
  193. package/dist/core/domain/shared/money/dto/money-dto.js +2 -0
  194. package/dist/core/domain/shared/money/dto/money-dto.js.map +1 -0
  195. package/dist/core/domain/shared/money/exchange-rate.d.ts +48 -0
  196. package/dist/core/domain/shared/money/exchange-rate.js +86 -0
  197. package/dist/core/domain/shared/money/exchange-rate.js.map +1 -0
  198. package/dist/core/domain/shared/money/factor.d.ts +23 -0
  199. package/dist/core/domain/shared/money/factor.js +57 -0
  200. package/dist/core/domain/shared/money/factor.js.map +1 -0
  201. package/dist/core/domain/shared/money/index.d.ts +13 -0
  202. package/dist/core/domain/shared/money/index.js +9 -0
  203. package/dist/core/domain/shared/money/index.js.map +1 -0
  204. package/dist/core/domain/shared/money/money-errors.d.ts +18 -0
  205. package/dist/core/domain/shared/money/money-errors.js +35 -0
  206. package/dist/core/domain/shared/money/money-errors.js.map +1 -0
  207. package/dist/core/domain/shared/money/money.d.ts +45 -0
  208. package/dist/core/domain/shared/money/money.js +232 -0
  209. package/dist/core/domain/shared/money/money.js.map +1 -0
  210. package/dist/core/domain/shared/money/rounding-mode.d.ts +4 -0
  211. package/dist/core/domain/shared/money/rounding-mode.js +3 -0
  212. package/dist/core/domain/shared/money/rounding-mode.js.map +1 -0
  213. package/dist/index.d.ts +8 -0
  214. package/dist/index.js +12 -0
  215. package/dist/index.js.map +1 -0
  216. package/package.json +32 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pazos-dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,33 @@
1
- # Temporary Holding Version
1
+ # @pazos-dev/contability-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Motor contable embebible en TypeScript. Dominio, casos de uso y puertos; **sin ORM, sin HTTP, sin base de datos y sin dependencias de runtime**. Los adaptadores durables se instalan aparte.
4
+
5
+ ```bash
6
+ pnpm add @pazos-dev/contability-core
7
+ ```
8
+
9
+ ## Punto de entrada
10
+
11
+ | Símbolo | Qué es |
12
+ | --- | --- |
13
+ | `Accounting` | La fachada pública: diecisiete operaciones, cada una entregando un DTO serializable. |
14
+ | `createInMemoryAccounting` | Adaptador volátil para pruebas y desarrollo. No persiste nada. |
15
+ | tipos de `ports` | `UnitOfWork` y los repositorios que implementa un adaptador durable. |
16
+
17
+ El paquete publica **una** fachada a propósito. No expone las diecisiete clases de caso de uso ni un símbolo por operación.
18
+
19
+ ## El importe nunca es flotante
20
+
21
+ `Money` guarda un `bigint` en unidades mínimas y una `Currency` con su escala. Un importe se construye con un parser decimal exacto o con `MoneyFactor`, nunca con un `number`. `Money.multiply`, `Money.divide` y `Money.allocate` reciben un factor exacto y un modo de redondeo explícito.
22
+
23
+ ## Sin entorno
24
+
25
+ El código compilado no importa ningún módulo de Node.js: no toca disco, red, procesos ni relojes. Corre igual en Node, Bun, Deno o un worker. La persistencia, la transacción y la concurrencia son obligaciones del adaptador, listadas en [docs/INTEGRATION.md](https://github.com/pazos-dev/contability-core/blob/main/docs/INTEGRATION.md).
26
+
27
+ ## Documentación
28
+
29
+ - Estado y alcance real: [docs/STATUS.md](https://github.com/pazos-dev/contability-core/blob/main/docs/STATUS.md)
30
+ - Contrato del adaptador del anfitrión: [docs/INTEGRATION.md](https://github.com/pazos-dev/contability-core/blob/main/docs/INTEGRATION.md)
31
+ - Especificaciones por área: [docs/specs](https://github.com/pazos-dev/contability-core/tree/main/docs/specs)
32
+
33
+ Este paquete es un motor, no un sistema contable terminado. Las cotizaciones, la diferencia de cambio y el cierre de ejercicio no están implementados.
@@ -0,0 +1,22 @@
1
+ import type { UnitOfWork, UnitOfWorkScope } from '../../core/application/ports.js';
2
+ import { type InMemorySnapshot } from './store.js';
3
+ /**
4
+ * In-memory adapter for development and tests.
5
+ *
6
+ * It is not durable and it has no isolation: two concurrent `run` calls can interleave, and no
7
+ * rollback survives the process. What it does model is the write discipline of the contract — a
8
+ * failing unit of work restores the previous state of every store — and the placement of reads and
9
+ * writes inside one transactional context.
10
+ */
11
+ export interface InMemoryAccountingOptions {
12
+ /**
13
+ * Testing seam: replaces any port of the default scope. Receives the scope that was just built so a
14
+ * caller can delegate to the real repositories and only change one operation.
15
+ */
16
+ readonly overrides?: (defaults: UnitOfWorkScope) => Partial<UnitOfWorkScope>;
17
+ }
18
+ export interface InMemoryAccounting {
19
+ readonly unitOfWork: UnitOfWork;
20
+ snapshot(): InMemorySnapshot;
21
+ }
22
+ export declare function createInMemoryAccounting(options?: InMemoryAccountingOptions): InMemoryAccounting;
@@ -0,0 +1,28 @@
1
+ import { createPorts } from './repositories.js';
2
+ import { copyMaps, emptyMaps, snapshotOf } from './store.js';
3
+ export function createInMemoryAccounting(options = {}) {
4
+ const store = { maps: emptyMaps() };
5
+ const ports = createPorts(store);
6
+ const defaults = ports;
7
+ const scope = { ...defaults, ...(options.overrides?.(defaults) ?? {}) };
8
+ const unitOfWork = {
9
+ async run(work) {
10
+ const backup = copyMaps(store.maps);
11
+ try {
12
+ return await work(scope);
13
+ }
14
+ catch (error) {
15
+ // A copy of the maps is a full backup: every stored value is an immutable domain object.
16
+ store.maps = backup;
17
+ throw error;
18
+ }
19
+ },
20
+ };
21
+ return {
22
+ unitOfWork,
23
+ snapshot() {
24
+ return snapshotOf(store.maps);
25
+ },
26
+ };
27
+ }
28
+ //# sourceMappingURL=in-memory-accounting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-accounting.js","sourceRoot":"","sources":["../../../src/adapters/memory/in-memory-accounting.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAyB,MAAM,YAAY,CAAC;AAwBpF,MAAM,UAAU,wBAAwB,CAAC,UAAqC,EAAE;IAC9E,MAAM,KAAK,GAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAEjC,MAAM,QAAQ,GAAoB,KAAK,CAAC;IACxC,MAAM,KAAK,GAAoB,EAAE,GAAG,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;IAEzF,MAAM,UAAU,GAAe;QAC7B,KAAK,CAAC,GAAG,CAAC,IAAI;YACZ,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,yFAAyF;gBACzF,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC;gBACpB,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;IAEF,OAAO;QACL,UAAU;QACV,QAAQ;YACN,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createInMemoryAccounting } from './in-memory-accounting.js';
2
+ export type { InMemoryAccounting, InMemoryAccountingOptions } from './in-memory-accounting.js';
3
+ export type { InMemoryIdempotencyRecord, InMemorySnapshot } from './store.js';
@@ -0,0 +1,3 @@
1
+ // Public surface of the in-memory adapter. Import from here, never from the internal files.
2
+ export { createInMemoryAccounting } from './in-memory-accounting.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/memory/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { AccountRepository, EntryNumberSequence, EntryRepository, IdempotencyRegistry, JournalRepository, LedgerRepository, PeriodRepository, PostedEntriesQuery, PostedMovementsQuery } from '../../core/application/ports.js';
2
+ import { type MemoryMaps } from './store.js';
3
+ /** The store holder exists so a failing unit of work can swap the whole set of maps at once. */
4
+ export interface StoreHolder {
5
+ maps: MemoryMaps;
6
+ }
7
+ /**
8
+ * Builds every port over the given store.
9
+ *
10
+ * Ledger scoping is done by the key, not by a filter: `journals.findById(ledger, id)` builds a key from
11
+ * both, so an id of another ledger simply does not exist here.
12
+ */
13
+ export declare function createPorts(store: StoreHolder): {
14
+ ledgers: LedgerRepository;
15
+ accounts: AccountRepository;
16
+ journals: JournalRepository;
17
+ periods: PeriodRepository;
18
+ entries: EntryRepository;
19
+ idempotency: IdempotencyRegistry;
20
+ entryNumbers: EntryNumberSequence;
21
+ postedMovements: PostedMovementsQuery;
22
+ postedEntries: PostedEntriesQuery;
23
+ };
@@ -0,0 +1,169 @@
1
+ import { copyResult, keyOf } from './store.js';
2
+ /**
3
+ * Builds every port over the given store.
4
+ *
5
+ * Ledger scoping is done by the key, not by a filter: `journals.findById(ledger, id)` builds a key from
6
+ * both, so an id of another ledger simply does not exist here.
7
+ */
8
+ export function createPorts(store) {
9
+ const ledgers = {
10
+ async findById(ledgerId) {
11
+ // Own keys only: a ledger id such as "constructor" must be unknown, not inherited.
12
+ return store.maps.ledgers.get(ledgerId);
13
+ },
14
+ async save(ledger) {
15
+ store.maps.ledgers.set(ledger.id, ledger);
16
+ },
17
+ };
18
+ const accounts = {
19
+ async findById(accountId) {
20
+ return store.maps.accounts.get(accountId);
21
+ },
22
+ async findByCode(chartOfAccountsId, code) {
23
+ for (const account of store.maps.accounts.values()) {
24
+ if (account.chartOfAccountsId === chartOfAccountsId && account.code.value === code)
25
+ return account;
26
+ }
27
+ return undefined;
28
+ },
29
+ async findByChart(chartOfAccountsId) {
30
+ const found = [];
31
+ for (const account of store.maps.accounts.values()) {
32
+ if (account.chartOfAccountsId === chartOfAccountsId)
33
+ found.push(account);
34
+ }
35
+ return found;
36
+ },
37
+ async save(account) {
38
+ store.maps.accounts.set(account.id, account);
39
+ },
40
+ };
41
+ const journals = {
42
+ async findById(ledgerId, journalId) {
43
+ return store.maps.journals.get(keyOf(ledgerId, journalId));
44
+ },
45
+ async findByCode(ledgerId, code) {
46
+ for (const journal of store.maps.journals.values()) {
47
+ if (journal.ledgerId === ledgerId && journal.code === code)
48
+ return journal;
49
+ }
50
+ return undefined;
51
+ },
52
+ async save(journal) {
53
+ store.maps.journals.set(keyOf(journal.ledgerId, journal.id), journal);
54
+ },
55
+ };
56
+ const periods = {
57
+ async findById(ledgerId, periodId) {
58
+ return store.maps.periods.get(keyOf(ledgerId, periodId));
59
+ },
60
+ async findOverlapping(ledgerId, startDate, endDate) {
61
+ return [...store.maps.periods.values()].filter((period) => period.ledgerId === ledgerId &&
62
+ period.startDate.compare(endDate) <= 0 &&
63
+ period.endDate.compare(startDate) >= 0);
64
+ },
65
+ async save(period) {
66
+ store.maps.periods.set(keyOf(period.ledgerId, period.id), period);
67
+ },
68
+ };
69
+ const entries = {
70
+ async findById(ledgerId, entryId) {
71
+ return store.maps.entries.get(keyOf(ledgerId, entryId));
72
+ },
73
+ async findReversalsOf(ledgerId, originalEntryId) {
74
+ const reversals = [];
75
+ for (const entry of store.maps.entries.values()) {
76
+ if (entry.ledgerId === ledgerId && entry.reversalOfEntryId === originalEntryId)
77
+ reversals.push(entry);
78
+ }
79
+ return reversals;
80
+ },
81
+ async save(entry) {
82
+ store.maps.entries.set(keyOf(entry.ledgerId, entry.id), entry);
83
+ },
84
+ };
85
+ const idempotency = {
86
+ async find(ledgerId, operation, key) {
87
+ const stored = store.maps.idempotency.get(keyOf(ledgerId, operation, key));
88
+ if (stored === undefined)
89
+ return undefined;
90
+ return { fingerprint: stored.fingerprint, result: copyResult(stored.result) };
91
+ },
92
+ async record(ledgerId, operation, key, entry) {
93
+ // The result is copied in, not referenced: the caller keeps the object it received and may mutate
94
+ // it, and a replay must still answer what the operation produced.
95
+ store.maps.idempotency.set(keyOf(ledgerId, operation, key), {
96
+ ledgerId,
97
+ operation,
98
+ key,
99
+ fingerprint: entry.fingerprint,
100
+ result: copyResult(entry.result),
101
+ });
102
+ },
103
+ };
104
+ /**
105
+ * Hands out the next number of a ledger: one more than the last one given. It is not "the highest number
106
+ * stored" on purpose — a stored entry cannot be read back here without walking the map, and a counter is
107
+ * what a host would keep. Gaps are allowed; repeats are not, and the durable adapter closes that with a
108
+ * unique constraint.
109
+ */
110
+ const entryNumbers = {
111
+ async nextNumber(ledgerId) {
112
+ const next = (store.maps.entryNumbers.get(ledgerId) ?? 0) + 1;
113
+ store.maps.entryNumbers.set(ledgerId, next);
114
+ return next;
115
+ },
116
+ };
117
+ const postedMovements = {
118
+ async hasPostedLines(accountId) {
119
+ for (const entry of store.maps.entries.values()) {
120
+ if (entry.status === 'POSTED' && entry.lines.some((line) => line.accountId === accountId))
121
+ return true;
122
+ }
123
+ return false;
124
+ },
125
+ };
126
+ /**
127
+ * Paged read over the entries map: it filters by ledger, status, inclusive dates and account, sorts so the
128
+ * pages partition the result, and returns the window the cursor points at. The cursor is an offset, which
129
+ * is opaque to the caller and only has to be stable while the same read is drained.
130
+ */
131
+ const postedEntries = {
132
+ async findPostedMovements(ledgerId, criteria, page) {
133
+ const matching = [];
134
+ for (const entry of store.maps.entries.values()) {
135
+ if (entry.ledgerId !== ledgerId || entry.status !== 'POSTED')
136
+ continue;
137
+ if (criteria.from !== undefined && entry.accountingDate.compare(criteria.from) < 0)
138
+ continue;
139
+ if (criteria.to !== undefined && entry.accountingDate.compare(criteria.to) > 0)
140
+ continue;
141
+ if (criteria.accountId !== undefined &&
142
+ !entry.lines.some((line) => line.accountId === criteria.accountId)) {
143
+ continue;
144
+ }
145
+ matching.push(entry);
146
+ }
147
+ // `entryId` is unique inside its ledger, so date plus id is a total order and the pages never overlap.
148
+ matching.sort((left, right) => left.accountingDate.compare(right.accountingDate) ||
149
+ (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
150
+ const offset = offsetOf(page.cursor);
151
+ const window = matching.slice(offset, offset + page.limit);
152
+ const next = offset + window.length;
153
+ return {
154
+ entries: window,
155
+ // An empty window proves nothing follows, whatever the limit: the drain cannot loop on the page alone.
156
+ nextCursor: window.length === 0 || next >= matching.length ? null : String(next),
157
+ };
158
+ },
159
+ };
160
+ return { ledgers, accounts, journals, periods, entries, idempotency, entryNumbers, postedMovements, postedEntries };
161
+ }
162
+ /** A cursor this adapter did not produce starts at the beginning instead of throwing at the caller. */
163
+ function offsetOf(cursor) {
164
+ if (cursor === undefined)
165
+ return 0;
166
+ const offset = Number(cursor);
167
+ return Number.isInteger(offset) && offset >= 0 ? offset : 0;
168
+ }
169
+ //# sourceMappingURL=repositories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repositories.js","sourceRoot":"","sources":["../../../src/adapters/memory/repositories.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AAOhE;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,MAAM,OAAO,GAAqB;QAChC,KAAK,CAAC,QAAQ,CAAC,QAAQ;YACrB,mFAAmF;YACnF,OAAO,KAAK,CAAC,IAAI,CAAC,OAA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C,MAAM,CAAC,CAAC;YACrC,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3D,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YAEpC,OAAO;gBACL,OAAO,EAAE,MAAM;gBACf,uGAAuG;gBACvG,UAAU,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;aACjF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,CAAC;AACtH,CAAC;AAED,uGAAuG;AACvG,SAAS,QAAQ,CAAC,MAA0B;IAC1C,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,61 @@
1
+ import type { Account } from '../../core/domain/account/index.js';
2
+ import type { JournalEntry } from '../../core/domain/entries/index.js';
3
+ import type { Journal } from '../../core/domain/journal/index.js';
4
+ import type { Ledger } from '../../core/domain/ledger/index.js';
5
+ import type { AccountingPeriod } from '../../core/domain/period/index.js';
6
+ import type { StoredOperation } from '../../core/application/dto.js';
7
+ /** Idempotency record as the snapshot exposes it: the fingerprint, never the stored result. */
8
+ export interface InMemoryIdempotencyRecord {
9
+ readonly ledgerId: string;
10
+ readonly operation: string;
11
+ readonly key: string;
12
+ readonly fingerprint: string;
13
+ }
14
+ /** Read-only view of what the adapter holds, for composition checks and tests. */
15
+ export interface InMemorySnapshot {
16
+ readonly ledgers: readonly Ledger[];
17
+ readonly accounts: readonly Account[];
18
+ readonly journals: readonly Journal[];
19
+ readonly periods: readonly AccountingPeriod[];
20
+ readonly entries: readonly JournalEntry[];
21
+ readonly idempotency: readonly InMemoryIdempotencyRecord[];
22
+ }
23
+ export interface StoredIdempotency extends StoredOperation {
24
+ readonly ledgerId: string;
25
+ readonly operation: string;
26
+ readonly key: string;
27
+ }
28
+ /** Every store of the adapter. Domain values are deeply frozen, so a copy of a map is a backup. */
29
+ export interface MemoryMaps {
30
+ readonly ledgers: Map<string, Ledger>;
31
+ readonly accounts: Map<string, Account>;
32
+ readonly journals: Map<string, Journal>;
33
+ readonly periods: Map<string, AccountingPeriod>;
34
+ readonly entries: Map<string, JournalEntry>;
35
+ readonly idempotency: Map<string, StoredIdempotency>;
36
+ /**
37
+ * Last entry number handed out per ledger (Q11). A counter is a value, not an entity, so it is copied
38
+ * with the maps and restored by a failed unit of work like any other write.
39
+ */
40
+ readonly entryNumbers: Map<string, number>;
41
+ }
42
+ /**
43
+ * Deep copy of an operation result.
44
+ *
45
+ * The parameter is always a serialized contract graph — plain objects, arrays and strings — never a domain
46
+ * instance, so a clone is enough and drops nothing the caller can observe.
47
+ *
48
+ * A copy of the maps is shallow because the values stored there are immutable domain objects. The result of
49
+ * an operation is not one: it is a plain object graph handed to the caller, who may mutate it at run time.
50
+ * The registry copies it in and out, so the only mutable graph a map holds was copied at the door and is
51
+ * never handed out again.
52
+ */
53
+ export declare function copyResult<T>(value: T): T;
54
+ /**
55
+ * Composite keys are built from a JSON array, not from a separator: any separator can appear inside an
56
+ * id, and then two different pairs would produce the same key and overwrite each other.
57
+ */
58
+ export declare function keyOf(...parts: readonly string[]): string;
59
+ export declare function emptyMaps(): MemoryMaps;
60
+ export declare function copyMaps(maps: MemoryMaps): MemoryMaps;
61
+ export declare function snapshotOf(maps: MemoryMaps): InMemorySnapshot;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Deep copy of an operation result.
3
+ *
4
+ * The parameter is always a serialized contract graph — plain objects, arrays and strings — never a domain
5
+ * instance, so a clone is enough and drops nothing the caller can observe.
6
+ *
7
+ * A copy of the maps is shallow because the values stored there are immutable domain objects. The result of
8
+ * an operation is not one: it is a plain object graph handed to the caller, who may mutate it at run time.
9
+ * The registry copies it in and out, so the only mutable graph a map holds was copied at the door and is
10
+ * never handed out again.
11
+ */
12
+ export function copyResult(value) {
13
+ return structuredClone(value);
14
+ }
15
+ /**
16
+ * Composite keys are built from a JSON array, not from a separator: any separator can appear inside an
17
+ * id, and then two different pairs would produce the same key and overwrite each other.
18
+ */
19
+ export function keyOf(...parts) {
20
+ return JSON.stringify(parts);
21
+ }
22
+ export function emptyMaps() {
23
+ return {
24
+ ledgers: new Map(),
25
+ accounts: new Map(),
26
+ journals: new Map(),
27
+ periods: new Map(),
28
+ entries: new Map(),
29
+ idempotency: new Map(),
30
+ entryNumbers: new Map(),
31
+ };
32
+ }
33
+ export function copyMaps(maps) {
34
+ return {
35
+ ledgers: new Map(maps.ledgers),
36
+ accounts: new Map(maps.accounts),
37
+ journals: new Map(maps.journals),
38
+ periods: new Map(maps.periods),
39
+ entries: new Map(maps.entries),
40
+ idempotency: new Map(maps.idempotency),
41
+ entryNumbers: new Map(maps.entryNumbers),
42
+ };
43
+ }
44
+ export function snapshotOf(maps) {
45
+ return {
46
+ ledgers: [...maps.ledgers.values()],
47
+ accounts: [...maps.accounts.values()],
48
+ journals: [...maps.journals.values()],
49
+ periods: [...maps.periods.values()],
50
+ entries: [...maps.entries.values()],
51
+ idempotency: [...maps.idempotency.values()].map(({ ledgerId, operation, key, fingerprint }) => ({
52
+ ledgerId,
53
+ operation,
54
+ key,
55
+ fingerprint,
56
+ })),
57
+ };
58
+ }
59
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../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