ddd-ts-kit 0.9.0 → 0.10.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 (197) hide show
  1. package/README.md +12 -2
  2. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  3. package/dist/check/catalogue/architecture-rules.js +10 -0
  4. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  5. package/dist/check/event-sourcing/declared-shape.d.ts +13 -0
  6. package/dist/check/event-sourcing/declared-shape.d.ts.map +1 -0
  7. package/dist/check/event-sourcing/declared-shape.js +100 -0
  8. package/dist/check/event-sourcing/declared-shape.js.map +1 -0
  9. package/dist/check/event-sourcing/event-sourced-classes.d.ts +5 -0
  10. package/dist/check/event-sourcing/event-sourced-classes.d.ts.map +1 -0
  11. package/dist/check/event-sourcing/event-sourced-classes.js +13 -0
  12. package/dist/check/event-sourcing/event-sourced-classes.js.map +1 -0
  13. package/dist/check/event-sourcing/fact-words.d.ts +6 -0
  14. package/dist/check/event-sourcing/fact-words.d.ts.map +1 -0
  15. package/dist/check/event-sourcing/fact-words.js +10 -0
  16. package/dist/check/event-sourcing/fact-words.js.map +1 -0
  17. package/dist/check/event-sourcing/is-apply-method.d.ts +3 -0
  18. package/dist/check/event-sourcing/is-apply-method.d.ts.map +1 -0
  19. package/dist/check/event-sourcing/is-apply-method.js +6 -0
  20. package/dist/check/event-sourcing/is-apply-method.js.map +1 -0
  21. package/dist/check/event-sourcing/kernel-names.d.ts +8 -0
  22. package/dist/check/event-sourcing/kernel-names.d.ts.map +1 -0
  23. package/dist/check/event-sourcing/kernel-names.js +7 -0
  24. package/dist/check/event-sourcing/kernel-names.js.map +1 -0
  25. package/dist/check/event-sourcing/read-stored-events-lock.d.ts +5 -0
  26. package/dist/check/event-sourcing/read-stored-events-lock.d.ts.map +1 -0
  27. package/dist/check/event-sourcing/read-stored-events-lock.js +25 -0
  28. package/dist/check/event-sourcing/read-stored-events-lock.js.map +1 -0
  29. package/dist/check/event-sourcing/read-stored-shape.d.ts +12 -0
  30. package/dist/check/event-sourcing/read-stored-shape.d.ts.map +1 -0
  31. package/dist/check/event-sourcing/read-stored-shape.js +46 -0
  32. package/dist/check/event-sourcing/read-stored-shape.js.map +1 -0
  33. package/dist/check/event-sourcing/state-writes.d.ts +3 -0
  34. package/dist/check/event-sourcing/state-writes.d.ts.map +1 -0
  35. package/dist/check/event-sourcing/state-writes.js +11 -0
  36. package/dist/check/event-sourcing/state-writes.js.map +1 -0
  37. package/dist/check/event-sourcing/stored-event-declaration.d.ts +18 -0
  38. package/dist/check/event-sourcing/stored-event-declaration.d.ts.map +1 -0
  39. package/dist/check/event-sourcing/stored-event-declaration.js +2 -0
  40. package/dist/check/event-sourcing/stored-event-declaration.js.map +1 -0
  41. package/dist/check/event-sourcing/stored-event-declarations.d.ts +9 -0
  42. package/dist/check/event-sourcing/stored-event-declarations.d.ts.map +1 -0
  43. package/dist/check/event-sourcing/stored-event-declarations.js +64 -0
  44. package/dist/check/event-sourcing/stored-event-declarations.js.map +1 -0
  45. package/dist/check/event-sourcing/stored-events-lock-file.d.ts +3 -0
  46. package/dist/check/event-sourcing/stored-events-lock-file.d.ts.map +1 -0
  47. package/dist/check/event-sourcing/stored-events-lock-file.js +3 -0
  48. package/dist/check/event-sourcing/stored-events-lock-file.js.map +1 -0
  49. package/dist/check/event-sourcing/stored-shape.d.ts +7 -0
  50. package/dist/check/event-sourcing/stored-shape.d.ts.map +1 -0
  51. package/dist/check/event-sourcing/stored-shape.js +2 -0
  52. package/dist/check/event-sourcing/stored-shape.js.map +1 -0
  53. package/dist/check/event-sourcing/words-of.d.ts +3 -0
  54. package/dist/check/event-sourcing/words-of.d.ts.map +1 -0
  55. package/dist/check/event-sourcing/words-of.js +9 -0
  56. package/dist/check/event-sourcing/words-of.js.map +1 -0
  57. package/dist/check/events/event-name-resolver.d.ts +6 -0
  58. package/dist/check/events/event-name-resolver.d.ts.map +1 -0
  59. package/dist/check/events/event-name-resolver.js +21 -0
  60. package/dist/check/events/event-name-resolver.js.map +1 -0
  61. package/dist/check/explain/event-sourcing-docs.d.ts +3 -0
  62. package/dist/check/explain/event-sourcing-docs.d.ts.map +1 -0
  63. package/dist/check/explain/event-sourcing-docs.js +62 -0
  64. package/dist/check/explain/event-sourcing-docs.js.map +1 -0
  65. package/dist/check/explain/rule-docs.d.ts.map +1 -1
  66. package/dist/check/explain/rule-docs.js +2 -0
  67. package/dist/check/explain/rule-docs.js.map +1 -1
  68. package/dist/check/fixtures/event-sourcing-fixtures.d.ts +3 -0
  69. package/dist/check/fixtures/event-sourcing-fixtures.d.ts.map +1 -0
  70. package/dist/check/fixtures/event-sourcing-fixtures.js +199 -0
  71. package/dist/check/fixtures/event-sourcing-fixtures.js.map +1 -0
  72. package/dist/check/fixtures/event-sourcing-projection-fixtures.d.ts +3 -0
  73. package/dist/check/fixtures/event-sourcing-projection-fixtures.d.ts.map +1 -0
  74. package/dist/check/fixtures/event-sourcing-projection-fixtures.js +48 -0
  75. package/dist/check/fixtures/event-sourcing-projection-fixtures.js.map +1 -0
  76. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  77. package/dist/check/fixtures/fixtures.js +2 -0
  78. package/dist/check/fixtures/fixtures.js.map +1 -1
  79. package/dist/check/rules/event-sourcing-past-tense.d.ts +3 -0
  80. package/dist/check/rules/event-sourcing-past-tense.d.ts.map +1 -0
  81. package/dist/check/rules/event-sourcing-past-tense.js +31 -0
  82. package/dist/check/rules/event-sourcing-past-tense.js.map +1 -0
  83. package/dist/check/rules/event-sourcing-projection-never-appends.d.ts +3 -0
  84. package/dist/check/rules/event-sourcing-projection-never-appends.d.ts.map +1 -0
  85. package/dist/check/rules/event-sourcing-projection-never-appends.js +54 -0
  86. package/dist/check/rules/event-sourcing-projection-never-appends.js.map +1 -0
  87. package/dist/check/rules/event-sourcing-state-in-apply.d.ts +3 -0
  88. package/dist/check/rules/event-sourcing-state-in-apply.d.ts.map +1 -0
  89. package/dist/check/rules/event-sourcing-state-in-apply.js +34 -0
  90. package/dist/check/rules/event-sourcing-state-in-apply.js.map +1 -0
  91. package/dist/check/rules/event-sourcing-store-behind-repository.d.ts +3 -0
  92. package/dist/check/rules/event-sourcing-store-behind-repository.d.ts.map +1 -0
  93. package/dist/check/rules/event-sourcing-store-behind-repository.js +34 -0
  94. package/dist/check/rules/event-sourcing-store-behind-repository.js.map +1 -0
  95. package/dist/check/rules/event-sourcing-upcaster-required.d.ts +3 -0
  96. package/dist/check/rules/event-sourcing-upcaster-required.d.ts.map +1 -0
  97. package/dist/check/rules/event-sourcing-upcaster-required.js +79 -0
  98. package/dist/check/rules/event-sourcing-upcaster-required.js.map +1 -0
  99. package/dist/commands/docs.d.ts.map +1 -1
  100. package/dist/commands/docs.js +44 -11
  101. package/dist/commands/docs.js.map +1 -1
  102. package/dist/commands/format-context.d.ts.map +1 -1
  103. package/dist/commands/format-context.js +1 -1
  104. package/dist/commands/format-context.js.map +1 -1
  105. package/dist/commands/generate.js +2 -0
  106. package/dist/commands/generate.js.map +1 -1
  107. package/dist/describe/context-description.d.ts +2 -0
  108. package/dist/describe/context-description.d.ts.map +1 -1
  109. package/dist/describe/describe-context.js +1 -0
  110. package/dist/describe/describe-context.js.map +1 -1
  111. package/dist/describe/format-description.d.ts.map +1 -1
  112. package/dist/describe/format-description.js +4 -1
  113. package/dist/describe/format-description.js.map +1 -1
  114. package/dist/docs/context-facts.d.ts +2 -0
  115. package/dist/docs/context-facts.d.ts.map +1 -1
  116. package/dist/docs/declared-stored-events.d.ts +9 -0
  117. package/dist/docs/declared-stored-events.d.ts.map +1 -0
  118. package/dist/docs/declared-stored-events.js +22 -0
  119. package/dist/docs/declared-stored-events.js.map +1 -0
  120. package/dist/docs/read-context.js +10 -0
  121. package/dist/docs/read-context.js.map +1 -1
  122. package/dist/docs/refresh-context-doc.js +1 -1
  123. package/dist/docs/refresh-context-doc.js.map +1 -1
  124. package/dist/docs/unrecorded-stored-events.d.ts +9 -0
  125. package/dist/docs/unrecorded-stored-events.d.ts.map +1 -0
  126. package/dist/docs/unrecorded-stored-events.js +17 -0
  127. package/dist/docs/unrecorded-stored-events.js.map +1 -0
  128. package/dist/docs/write-docs.d.ts +1 -2
  129. package/dist/docs/write-docs.d.ts.map +1 -1
  130. package/dist/docs/write-docs.js +1 -2
  131. package/dist/docs/write-docs.js.map +1 -1
  132. package/dist/docs/write-stored-events-lock.d.ts +12 -0
  133. package/dist/docs/write-stored-events-lock.d.ts.map +1 -0
  134. package/dist/docs/write-stored-events-lock.js +41 -0
  135. package/dist/docs/write-stored-events-lock.js.map +1 -0
  136. package/dist/generate/event-names.d.ts +2 -0
  137. package/dist/generate/event-names.d.ts.map +1 -1
  138. package/dist/generate/event-names.js +1 -0
  139. package/dist/generate/event-names.js.map +1 -1
  140. package/dist/generate/kind.d.ts +2 -0
  141. package/dist/generate/kind.d.ts.map +1 -1
  142. package/dist/generate/kinds/aggregate-kind.d.ts.map +1 -1
  143. package/dist/generate/kinds/aggregate-kind.js +8 -2
  144. package/dist/generate/kinds/aggregate-kind.js.map +1 -1
  145. package/dist/generate/kinds/domain-event-kind.d.ts.map +1 -1
  146. package/dist/generate/kinds/domain-event-kind.js +5 -2
  147. package/dist/generate/kinds/domain-event-kind.js.map +1 -1
  148. package/dist/generate/kinds/event-vars.d.ts.map +1 -1
  149. package/dist/generate/kinds/event-vars.js +6 -1
  150. package/dist/generate/kinds/event-vars.js.map +1 -1
  151. package/dist/generate/kinds/extend-event-sourced-aggregate.d.ts +9 -0
  152. package/dist/generate/kinds/extend-event-sourced-aggregate.d.ts.map +1 -0
  153. package/dist/generate/kinds/extend-event-sourced-aggregate.js +67 -0
  154. package/dist/generate/kinds/extend-event-sourced-aggregate.js.map +1 -0
  155. package/dist/generate/kinds/write-event-sourced-aggregate.d.ts +8 -0
  156. package/dist/generate/kinds/write-event-sourced-aggregate.d.ts.map +1 -0
  157. package/dist/generate/kinds/write-event-sourced-aggregate.js +24 -0
  158. package/dist/generate/kinds/write-event-sourced-aggregate.js.map +1 -0
  159. package/dist/help/notes.d.ts +1 -1
  160. package/dist/help/notes.d.ts.map +1 -1
  161. package/dist/help/notes.js +3 -0
  162. package/dist/help/notes.js.map +1 -1
  163. package/dist/help/usage.d.ts +1 -1
  164. package/dist/help/usage.d.ts.map +1 -1
  165. package/dist/help/usage.js +1 -1
  166. package/dist/init/manifest/versions.js +24 -24
  167. package/dist/init/manifest/versions.js.map +1 -1
  168. package/dist/naming/index.d.ts +2 -0
  169. package/dist/naming/index.d.ts.map +1 -1
  170. package/dist/naming/index.js +2 -0
  171. package/dist/naming/index.js.map +1 -1
  172. package/dist/naming/is-past-fact.d.ts +7 -0
  173. package/dist/naming/is-past-fact.d.ts.map +1 -0
  174. package/dist/naming/is-past-fact.js +18 -0
  175. package/dist/naming/is-past-fact.js.map +1 -0
  176. package/dist/naming/is-past-word.d.ts +3 -0
  177. package/dist/naming/is-past-word.d.ts.map +1 -0
  178. package/dist/naming/is-past-word.js +113 -0
  179. package/dist/naming/is-past-word.js.map +1 -0
  180. package/dist/naming/looks-like-past-fact.d.ts +1 -1
  181. package/dist/naming/looks-like-past-fact.d.ts.map +1 -1
  182. package/dist/naming/looks-like-past-fact.js +3 -66
  183. package/dist/naming/looks-like-past-fact.js.map +1 -1
  184. package/dist/version.d.ts +1 -1
  185. package/dist/version.d.ts.map +1 -1
  186. package/dist/version.js +1 -1
  187. package/dist/version.js.map +1 -1
  188. package/package.json +2 -2
  189. package/templates/aggregate/event-sourced.aggregate.spec.ts.tpl +26 -0
  190. package/templates/aggregate/event-sourced.aggregate.ts.tpl +61 -0
  191. package/templates/aggregate/event-sourced.events.mapper.ts.tpl +15 -0
  192. package/templates/builder/event-sourced.builder.ts.tpl +36 -0
  193. package/templates/init/CLAUDE.md.tpl +1 -1
  194. package/templates/init/rules/application.md.tpl +1 -0
  195. package/templates/init/rules/domain.md.tpl +1 -0
  196. package/templates/init/rules/infrastructure.md.tpl +1 -0
  197. package/templates/pipeline/package-scripts.json +1 -1
@@ -0,0 +1,3 @@
1
+ /** The lock of stored shapes, at the root of the project, committed: once a version is in it, its shape is the one stored. */
2
+ export const STORED_EVENTS_LOCK = 'stored-events.lock.json';
3
+ //# sourceMappingURL=stored-events-lock-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-events-lock-file.js","sourceRoot":"","sources":["../../../src/check/event-sourcing/stored-events-lock-file.ts"],"names":[],"mappings":"AAAA,8HAA8H;AAC9H,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** What `readStoredShape` reads of the data type of a stored event. */
2
+ export interface StoredShape {
3
+ readonly fingerprint: string;
4
+ /** The named types the shape reaches that the file does not declare, in the order met. */
5
+ readonly unresolved: readonly string[];
6
+ }
7
+ //# sourceMappingURL=stored-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-shape.d.ts","sourceRoot":"","sources":["../../../src/check/event-sourcing/stored-shape.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,0FAA0F;IAC1F,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=stored-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stored-shape.js","sourceRoot":"","sources":["../../../src/check/event-sourcing/stored-shape.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ /** The words of a PascalCase or kebab-case name, in lower case. */
2
+ export declare function wordsOf(name: string): string[];
3
+ //# sourceMappingURL=words-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"words-of.d.ts","sourceRoot":"","sources":["../../../src/check/event-sourcing/words-of.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAM9C"}
@@ -0,0 +1,9 @@
1
+ /** The words of a PascalCase or kebab-case name, in lower case. */
2
+ export function wordsOf(name) {
3
+ return name
4
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
5
+ .split(/[\s\-_.]+/)
6
+ .filter((word) => word !== '')
7
+ .map((word) => word.toLowerCase());
8
+ }
9
+ //# sourceMappingURL=words-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"words-of.js","sourceRoot":"","sources":["../../../src/check/event-sourcing/words-of.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI;SACR,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,KAAK,CAAC,WAAW,CAAC;SAClB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;SAC7B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { SourceFile } from '../model/source-file.js';
2
+ /** The name an event class declares, found by the name of the class. */
3
+ export type EventNameResolver = (eventClass: string) => string | undefined;
4
+ /** Reads `<Event>.eventName` among these files: the name the class `<Event>` declares once. */
5
+ export declare function eventNameResolver(files: readonly SourceFile[]): EventNameResolver;
6
+ //# sourceMappingURL=event-name-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-name-resolver.d.ts","sourceRoot":"","sources":["../../../src/check/events/event-name-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,wEAAwE;AACxE,MAAM,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE3E,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,iBAAiB,CAUjF"}
@@ -0,0 +1,21 @@
1
+ import { nameOfEventClass } from './name-of-event-class.js';
2
+ /** Reads `<Event>.eventName` among these files: the name the class `<Event>` declares once. */
3
+ export function eventNameResolver(files) {
4
+ const known = new Map();
5
+ return (eventClass) => {
6
+ if (!known.has(eventClass)) {
7
+ known.set(eventClass, firstName(files, eventClass));
8
+ }
9
+ return known.get(eventClass);
10
+ };
11
+ }
12
+ function firstName(files, eventClass) {
13
+ for (const file of files) {
14
+ const name = nameOfEventClass(file, eventClass);
15
+ if (name !== undefined) {
16
+ return name;
17
+ }
18
+ }
19
+ return undefined;
20
+ }
21
+ //# sourceMappingURL=event-name-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-name-resolver.js","sourceRoot":"","sources":["../../../src/check/events/event-name-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAK5D,+FAA+F;AAC/F,MAAM,UAAU,iBAAiB,CAAC,KAA4B;IAC5D,MAAM,KAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IAEpD,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3B,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,KAA4B,EAAE,UAAkB;IACjE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAEhD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuleDoc } from '../model/rule-doc.js';
2
+ export declare const EVENT_SOURCING_DOCS: Readonly<Record<string, RuleDoc>>;
3
+ //# sourceMappingURL=event-sourcing-docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-docs.d.ts","sourceRoot":"","sources":["../../../src/check/explain/event-sourcing-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4DjE,CAAC"}
@@ -0,0 +1,62 @@
1
+ export const EVENT_SOURCING_DOCS = {
2
+ 'event-sourcing/state-in-apply': {
3
+ why: 'An event-sourced aggregate is rebuilt by replaying its events through its apply methods, so the state a command leaves must be exactly what those methods make of the events it recorded. A command that also writes the state directly produces a state no replay will ever rebuild: the aggregate behaves one way just after the command and another way once loaded. Judged: every class of domain/aggregates/ that extends EventSourcedAggregate; outside the constructor, the static methods and the apply methods (a method named apply followed by an upper-case letter, and restore, which takes the state of a snapshot), an assignment, an increment or a mutating call (push, splice, set, add, delete...) on something of this is reported, and so is this.record(..) inside an apply method, which would record the event again at each replay.',
4
+ bad: `// domain/aggregates/attendance-record.aggregate.ts
5
+ noteNoShow(appointmentId: string, now: Date): void {
6
+ this.state = { noShows: this.state.noShows + 1 }; // written twice: here and by the replay
7
+ this.record(new NoShowNoted(this.id, now, appointmentId));
8
+ }`,
9
+ good: `// domain/aggregates/attendance-record.aggregate.ts
10
+ noteNoShow(appointmentId: string, now: Date): void {
11
+ this.record(new NoShowNoted(this.id, now, appointmentId));
12
+ }
13
+
14
+ private applyNoShowNoted(event: NoShowNoted): void {
15
+ this.state = { noShows: this.state.noShows + 1 };
16
+ }`,
17
+ },
18
+ 'event-sourcing/past-tense': {
19
+ why: 'A stored event is a fact that is kept and replayed for as long as the aggregate lives, read by people and by projections that were not written yet. A name in the present or the imperative (BookAppointment, Cancel) reads as a request that may still be refused; a name in the past tense says it happened. Judged: in a file of domain/aggregates/ holding a class that extends EventSourcedAggregate, every name imported from domain/events/. Its fact is judged, the words after the name of the aggregate when it starts with it (InvoiceIssued of Invoice: Issued), the whole name otherwise: one word of it must read as a past participle (ending in -ed, or a common irregular one such as paid, held, taken, withdrawn, sent, set, made, done, lost, won), and a participle spelled like its imperative (set, put, read, run, cut, found, left...) does not count at the head of the fact, where it reads as a command (SetPrice, ReadInvoice). The same words generate domain-event accepts.',
20
+ bad: `// domain/aggregates/attendance-record.aggregate.ts
21
+ import { NoteNoShow } from '@/contexts/scheduling/domain/events/note-no-show.event';`,
22
+ good: `// domain/aggregates/attendance-record.aggregate.ts
23
+ import { NoShowNoted } from '@/contexts/scheduling/domain/events/no-show-noted.event';`,
24
+ },
25
+ 'event-sourcing/store-behind-repository': {
26
+ why: "The domain and the use cases see an event-sourced aggregate exactly as they see any other: loaded by its repository port, changed by its methods, saved by the same port. A handler that reads a stream itself decides how events become state, which is the aggregate's job, and binds the use case to a storage technique the next aggregate may not use. Judged: production files of domain/ and application/ of a context; importing EventStore, SnapshotStore, CheckpointStore, EventSourcedRepository, EventSerializer, CatchUpSubscription or InMemoryEventStore from @ddd-ts-kit/kernel is reported. Infrastructure, the module file and the platform are left alone.",
27
+ bad: `// application/commands/note-no-show/note-no-show.handler.ts
28
+ constructor(private readonly store: EventStore) {}
29
+ const events = await this.store.readStream(\`scheduling.attendance-record-\${command.patientId}\`);`,
30
+ good: `// application/commands/note-no-show/note-no-show.handler.ts
31
+ constructor(private readonly records: AttendanceRecordRepository) {}
32
+ const record = await this.records.findById(command.patientId);`,
33
+ },
34
+ 'event-sourcing/projection-never-appends': {
35
+ why: "A projection turns facts into a read model; it is replayed from position zero whenever its read model is rebuilt. A projection that appends to a stream would append again at every rebuild, and makes the read side decide facts. Judged: production files of application/projections/ and any file declaring a class with @Projection; naming EventStore or EventSourcedRepository of @ddd-ts-kit/kernel is reported, and so is anything imported from domain/repositories/ in a projection declared @Projection(name, { feed: 'event-store' }). A projection fed by the dispatcher keeps the imports it had before event sourcing.",
36
+ bad: `// application/projections/attendance-history.projection.ts
37
+ @Projection('scheduling.attendance-history', { feed: 'event-store' })
38
+ export class AttendanceHistoryProjection {
39
+ constructor(private readonly history: AttendanceHistory, private readonly records: AttendanceRecordRepository) {}
40
+ }`,
41
+ good: `// application/projections/attendance-history.projection.ts
42
+ @Projection('scheduling.attendance-history', { feed: 'event-store' })
43
+ export class AttendanceHistoryProjection {
44
+ constructor(private readonly history: AttendanceHistory) {}
45
+ }`,
46
+ },
47
+ 'event-sourcing/upcaster-required': {
48
+ why: "Stored events are never rewritten: an event stored years ago is read by today's code. Changing the type of the data of an event that is already stored breaks every replay of it, silently when the fields keep their names. The checkable criterion: the data of a stored event is a named type declared in its codec file with every named type it reaches (the kit's own PersonalValue aside), `encode` answers it, and its fingerprint (its fields and their types, the types it reaches included, layout and order aside) is recorded per version in stored-events.lock.json by `ddd-ts-kit docs --stored-events`, which never rewrites a recorded version. `ddd-ts-kit docs --check`, in the pipeline, fails while a declared version is not recorded, so no version reaches the main branch unrecorded. Reported: an encode that names no type, a type not declared in the file, a type it reaches that the file does not declare, a version above 1 without an upcaster from each version below it, a version below the last one recorded, and a recorded version whose shape changed. The lock is committed; until a version is recorded, its shape is free to change.",
49
+ bad: `// infrastructure/persistence/attendance-record-events.mapper.ts
50
+ interface NoShowNotedData { readonly appointmentId: string; readonly reason: string } // a field added in place
51
+ [NoShowNoted.eventName]: defineStoredEvent(NoShowNoted, { version: 1, encode: (event): NoShowNotedData => ({ ... }), decode }),`,
52
+ good: `// infrastructure/persistence/attendance-record-events.mapper.ts
53
+ interface NoShowNotedData { readonly appointmentId: string; readonly reason: string }
54
+ [NoShowNoted.eventName]: defineStoredEvent(NoShowNoted, {
55
+ version: 2,
56
+ encode: (event): NoShowNotedData => ({ ... }),
57
+ decode,
58
+ upcasters: { 1: (data) => ({ ...data, reason: '' }) },
59
+ }),`,
60
+ },
61
+ };
62
+ //# sourceMappingURL=event-sourcing-docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-docs.js","sourceRoot":"","sources":["../../../src/check/explain/event-sourcing-docs.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAsC;IACpE,+BAA+B,EAAE;QAC/B,GAAG,EAAE,8zBAA8zB;QACn0B,GAAG,EAAE;;;;EAIP;QACE,IAAI,EAAE;;;;;;;EAOR;KACC;IACD,2BAA2B,EAAE;QAC3B,GAAG,EAAE,48BAA48B;QACj9B,GAAG,EAAE;qFAC4E;QACjF,IAAI,EAAE;uFAC6E;KACpF;IACD,wCAAwC,EAAE;QACxC,GAAG,EAAE,+oBAA+oB;QACppB,GAAG,EAAE;;oGAE2F;QAChG,IAAI,EAAE;;+DAEqD;KAC5D;IACD,yCAAyC,EAAE;QACzC,GAAG,EAAE,umBAAumB;QAC5mB,GAAG,EAAE;;;;EAIP;QACE,IAAI,EAAE;;;;EAIR;KACC;IACD,kCAAkC,EAAE;QAClC,GAAG,EAAE,inCAAinC;QACtnC,GAAG,EAAE;;gIAEuH;QAC5H,IAAI,EAAE;;;;;;;IAON;KACD;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rule-docs.d.ts","sourceRoot":"","sources":["../../../src/check/explain/rule-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAkBpD,oGAAoG;AACpG,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBvD,CAAC"}
1
+ {"version":3,"file":"rule-docs.d.ts","sourceRoot":"","sources":["../../../src/check/explain/rule-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAmBpD,oGAAoG;AACpG,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkBvD,CAAC"}
@@ -2,6 +2,7 @@ import { AUTHZ_DOCS } from './authz-docs.js';
2
2
  import { CLEAN_DOCS } from './clean-docs.js';
3
3
  import { CONTEXT_DOCS } from './context-docs.js';
4
4
  import { ERRORS_DOCS } from './errors-docs.js';
5
+ import { EVENT_SOURCING_DOCS } from './event-sourcing-docs.js';
5
6
  import { EVENTS_DOCS } from './events-docs.js';
6
7
  import { IMPORTS_DOCS } from './imports-docs.js';
7
8
  import { LANGUAGE_DOCS } from './language-docs.js';
@@ -20,6 +21,7 @@ export const RULE_DOCS = {
20
21
  ...CLEAN_DOCS,
21
22
  ...CONTEXT_DOCS,
22
23
  ...ERRORS_DOCS,
24
+ ...EVENT_SOURCING_DOCS,
23
25
  ...EVENTS_DOCS,
24
26
  ...IMPORTS_DOCS,
25
27
  ...LANGUAGE_DOCS,
@@ -1 +1 @@
1
- {"version":3,"file":"rule-docs.js","sourceRoot":"","sources":["../../../src/check/explain/rule-docs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,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C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,oGAAoG;AACpG,MAAM,CAAC,MAAM,SAAS,GAAsC;IAC1D,GAAG,UAAU;IACb,GAAG,UAAU;IACb,GAAG,YAAY;IACf,GAAG,WAAW;IACd,GAAG,mBAAmB;IACtB,GAAG,WAAW;IACd,GAAG,YAAY;IACf,GAAG,aAAa;IAChB,GAAG,UAAU;IACb,GAAG,WAAW;IACd,GAAG,gBAAgB;IACnB,GAAG,UAAU;IACb,GAAG,eAAe;IAClB,GAAG,aAAa;IAChB,GAAG,YAAY;IACf,GAAG,SAAS;IACZ,GAAG,WAAW;CACf,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Fixture } from './fixture.js';
2
+ export declare const EVENT_SOURCING_FIXTURES: readonly Fixture[];
3
+ //# sourceMappingURL=event-sourcing-fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-fixtures.d.ts","sourceRoot":"","sources":["../../../src/check/fixtures/event-sourcing-fixtures.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAqO5C,eAAO,MAAM,uBAAuB,EAAE,SAAS,OAAO,EAMrD,CAAC"}
@@ -0,0 +1,199 @@
1
+ import { readStoredShape } from '../event-sourcing/read-stored-shape.js';
2
+ import { STORED_EVENTS_LOCK } from '../event-sourcing/stored-events-lock-file.js';
3
+ import { scan } from '../scan/scan.js';
4
+ import { aggregate } from './aggregate.js';
5
+ import { contextDoc } from './context-doc.js';
6
+ import { EVENT_SOURCING_PROJECTION_FIXTURES } from './event-sourcing-projection-fixtures.js';
7
+ import { handler } from './handler.js';
8
+ import { PATHS } from './paths.js';
9
+ import { project } from './project.js';
10
+ import { SAMPLES } from './samples.js';
11
+ import { source } from './source.js';
12
+ const { AGGREGATE, BILLING, EVENT, HANDLER } = PATHS;
13
+ const STATE = 'event-sourcing/state-in-apply';
14
+ const PAST = 'event-sourcing/past-tense';
15
+ const STORE = 'event-sourcing/store-behind-repository';
16
+ const UPCASTER = 'event-sourcing/upcaster-required';
17
+ const KERNEL = "'@ddd-ts-kit/kernel'";
18
+ const ISSUED_EVENT = "import { InvoiceIssued } from '@/contexts/billing/domain/events/invoice-issued.event.js';";
19
+ const PRESENT_EVENT = `${BILLING}/domain/events/issue-invoice.event.ts`;
20
+ const CODEC = `${BILLING}/infrastructure/persistence/invoice-events.mapper.ts`;
21
+ const STORE_ADAPTER = `${BILLING}/infrastructure/persistence/event-store-invoice.repository.ts`;
22
+ const EVENTS = {
23
+ [EVENT]: source("export class InvoiceIssued {\n readonly name = 'billing.invoice.issued';\n\n constructor(\n readonly aggregateId: string,\n readonly amount: number,\n ) {}\n}"),
24
+ [PRESENT_EVENT]: source("export class IssueInvoice {\n readonly name = 'billing.invoice.issued';\n\n constructor(readonly aggregateId: string) {}\n}"),
25
+ };
26
+ const RECORDING = ['this.record(new InvoiceIssued(this.id, amount));'];
27
+ const APPLYING = ['this.amount = event.amount;'];
28
+ const STATE_IN_APPLY = [
29
+ {
30
+ ruleId: STATE,
31
+ name: 'a command that records, an apply method and a restore that write the state',
32
+ expect: 'pass',
33
+ files: project({ ...EVENTS, ...invoice(RECORDING, APPLYING) }),
34
+ },
35
+ {
36
+ ruleId: STATE,
37
+ name: 'a command that writes the state of an event-sourced aggregate itself',
38
+ expect: { file: AGGREGATE },
39
+ files: project({ ...EVENTS, ...invoice(['this.amount += amount;', ...RECORDING], APPLYING) }),
40
+ },
41
+ {
42
+ ruleId: STATE,
43
+ name: 'an apply method that records an event',
44
+ expect: { file: AGGREGATE },
45
+ files: project({ ...EVENTS, ...invoice(RECORDING, [...APPLYING, 'this.record(event);']) }),
46
+ },
47
+ ];
48
+ const PRICED_GLOSSARY = `${SAMPLES.GLOSSARY}\n| Price | What an invoice asks. |\n| Set | To give a value. |`;
49
+ const PAST_TENSE = [
50
+ {
51
+ ruleId: PAST,
52
+ name: 'an event-sourced aggregate recording a fact named in the past tense',
53
+ expect: 'pass',
54
+ files: project({ ...EVENTS, ...invoice(RECORDING, APPLYING) }),
55
+ },
56
+ {
57
+ ruleId: PAST,
58
+ name: 'an event-sourced aggregate recording an event named as a command',
59
+ expect: { file: AGGREGATE },
60
+ files: project({
61
+ ...EVENTS,
62
+ ...invoice(['this.record(new IssueInvoice(this.id));'], APPLYING, "import { IssueInvoice } from '@/contexts/billing/domain/events/issue-invoice.event.js';"),
63
+ }),
64
+ },
65
+ namedEvent('a command whose verb is spelled like its participle, at the head', 'SetPrice', { file: AGGREGATE }),
66
+ namedEvent('the same participle after the noun, a fact', 'InvoicePriceSet', 'pass'),
67
+ ];
68
+ /** An event-sourced invoice recording an event of this name, declared in `domain/events/`. */
69
+ function namedEvent(name, eventClass, expect) {
70
+ const file = eventClass.replace(/(?<=[a-z])(?=[A-Z])/g, '-').toLowerCase();
71
+ const imported = `import { ${eventClass} } from '@/contexts/billing/domain/events/${file}.event.js';`;
72
+ return {
73
+ ruleId: PAST,
74
+ name,
75
+ expect,
76
+ files: project({
77
+ [`${BILLING}/domain/events/${file}.event.ts`]: source(`export class ${eventClass} {\n readonly name = 'billing.invoice.price-set';\n\n constructor(readonly aggregateId: string) {}\n}`),
78
+ ...invoice([`this.record(new ${eventClass}(this.id));`], APPLYING, imported),
79
+ }, { [`${BILLING}/CONTEXT.md`]: contextDoc('core', undefined, PRICED_GLOSSARY) }),
80
+ };
81
+ }
82
+ const STORE_BEHIND_REPOSITORY = [
83
+ {
84
+ ruleId: STORE,
85
+ name: 'the event store held by the repository adapter, the handler given the repository',
86
+ expect: 'pass',
87
+ files: project({
88
+ ...handler(source("import { InvoiceRepository } from '@/contexts/billing/domain/repositories/invoice.repository.js';", '', 'export class IssueInvoiceHandler {', ' constructor(private readonly invoices: InvoiceRepository) {}', '}')),
89
+ [STORE_ADAPTER]: source(`import { EventStore } from ${KERNEL};`, '', 'export class EventStoreInvoiceRepository {', ' constructor(private readonly store: EventStore) {}', '}'),
90
+ }),
91
+ },
92
+ {
93
+ ruleId: STORE,
94
+ name: 'a command handler reading the stream of the aggregate',
95
+ expect: { file: HANDLER },
96
+ files: project(handler(source(`import { EventStore } from ${KERNEL};`, '', 'export class IssueInvoiceHandler {', ' constructor(private readonly store: EventStore) {}', '}'))),
97
+ },
98
+ ];
99
+ const AMOUNT = 'readonly amount: number;';
100
+ const ENCODE = 'encode: (event): InvoiceIssuedData => ({ amount: event.amount }),';
101
+ const UPCAST = 'upcasters: { 1: (data) => ({ amount: 0, ...data }) },';
102
+ const LINE = 'readonly line: InvoiceLineData;';
103
+ const LINE_DATA = 'interface InvoiceLineData {\n readonly cents: number;\n}';
104
+ const UPCASTER_REQUIRED = [
105
+ {
106
+ ruleId: UPCASTER,
107
+ name: 'version 2 read through the upcaster from version 1, its shape as recorded',
108
+ expect: 'pass',
109
+ files: project({
110
+ ...EVENTS,
111
+ [CODEC]: codec(AMOUNT, ['version: 2,', ENCODE, UPCAST]),
112
+ ...locked({ 1: fingerprintOf('readonly cents: number;'), 2: fingerprintOf(`\n ${AMOUNT} `) }),
113
+ }),
114
+ },
115
+ {
116
+ ruleId: UPCASTER,
117
+ name: 'version 2 without the upcaster from version 1',
118
+ expect: { file: CODEC },
119
+ files: project({ ...EVENTS, [CODEC]: codec(AMOUNT, ['version: 2,', ENCODE]) }),
120
+ },
121
+ {
122
+ ruleId: UPCASTER,
123
+ name: 'a field added to the shape of a recorded version',
124
+ expect: { file: CODEC },
125
+ files: project({
126
+ ...EVENTS,
127
+ [CODEC]: codec(`${AMOUNT}\n readonly currency: string;`, ['version: 1,', ENCODE]),
128
+ ...locked({ 1: fingerprintOf(AMOUNT) }),
129
+ }),
130
+ },
131
+ {
132
+ ruleId: UPCASTER,
133
+ name: 'a field added to the shape of a recorded version, the codec keyed by the name its event class declares',
134
+ expect: { file: CODEC },
135
+ files: project({
136
+ ...EVENTS,
137
+ [EVENT]: source("export class InvoiceIssued {\n static readonly eventName = 'billing.invoice.issued';\n\n readonly name = InvoiceIssued.eventName;\n\n constructor(\n readonly aggregateId: string,\n readonly amount: number,\n ) {}\n}"),
138
+ [CODEC]: codec(`${AMOUNT}\n readonly currency: string;`, ['version: 1,', ENCODE]).replace("'billing.invoice.issued': defineStoredEvent", '[InvoiceIssued.eventName]: defineStoredEvent'),
139
+ ...locked({ 1: fingerprintOf(AMOUNT) }),
140
+ }),
141
+ },
142
+ {
143
+ ruleId: UPCASTER,
144
+ name: 'an encode that names no stored type',
145
+ expect: { file: CODEC },
146
+ files: project({
147
+ ...EVENTS,
148
+ [CODEC]: codec(AMOUNT, ['version: 1,', 'encode: (event) => ({ amount: event.amount }),']),
149
+ }),
150
+ },
151
+ {
152
+ ruleId: UPCASTER,
153
+ name: 'a recorded shape that reaches a type of the file and a sealed value of the kit, both unchanged',
154
+ expect: 'pass',
155
+ files: project({
156
+ ...EVENTS,
157
+ [CODEC]: codec(`${LINE}\n readonly note: PersonalValue;`, ['version: 1,', ENCODE], LINE_DATA),
158
+ ...locked({ 1: fingerprintOf(`${LINE}\n readonly note: PersonalValue;`, LINE_DATA) }),
159
+ }),
160
+ },
161
+ {
162
+ ruleId: UPCASTER,
163
+ name: 'a field added to a type of the file that a recorded shape reaches',
164
+ expect: { file: CODEC },
165
+ files: project({
166
+ ...EVENTS,
167
+ [CODEC]: codec(LINE, ['version: 1,', ENCODE], LINE_DATA.replace(/}$/, ' readonly currency: string;\n}')),
168
+ ...locked({ 1: fingerprintOf(LINE, LINE_DATA) }),
169
+ }),
170
+ },
171
+ {
172
+ ruleId: UPCASTER,
173
+ name: 'a stored shape that reaches a type declared in another file',
174
+ expect: { file: CODEC },
175
+ files: project({ ...EVENTS, [CODEC]: codec('readonly line: InvoiceLine;', ['version: 1,', ENCODE]) }),
176
+ },
177
+ ];
178
+ export const EVENT_SOURCING_FIXTURES = [
179
+ ...STATE_IN_APPLY,
180
+ ...PAST_TENSE,
181
+ ...STORE_BEHIND_REPOSITORY,
182
+ ...EVENT_SOURCING_PROJECTION_FIXTURES,
183
+ ...UPCASTER_REQUIRED,
184
+ ];
185
+ /** An event-sourced invoice whose `issue` command and `applyIssued` method are the lines given. */
186
+ function invoice(command, apply, event = ISSUED_EVENT) {
187
+ return aggregate(source(`import { EventSourcedAggregate, type Appliers } from ${KERNEL};`, event, '', 'export class Invoice extends EventSourcedAggregate<InvoiceIssued> {', ' private amount = 0;', '', ' private constructor(id: string) {', ' super(id);', ' }', '', ' issue(amount: number): void {', ...command.map((line) => ` ${line}`), ' }', '', ' protected appliers(): Appliers<InvoiceIssued> {', " return { 'billing.invoice.issued': (event) => this.applyIssued(event) };", ' }', '', ' private applyIssued(event: InvoiceIssued): void {', ...apply.map((line) => ` ${line}`), ' }', '', ' private restore(amount: number): void {', ' this.amount = amount;', ' }', '}'));
188
+ }
189
+ /** The codec of the invoice: its data and the types it declares beside, then the entry of `billing.invoice.issued` with what the fixture declares. */
190
+ function codec(data, entry, beside = '') {
191
+ return source(`import { defineStoredEvent, type PersonalValue } from ${KERNEL};`, ISSUED_EVENT, '', `interface InvoiceIssuedData {\n ${data}\n}`, beside, '', 'export const invoiceEvents = {', " 'billing.invoice.issued': defineStoredEvent(InvoiceIssued, {", ...entry.map((line) => ` ${line}`), " decode: (data, { aggregateId }) => new InvoiceIssued(aggregateId, data.number('amount')),", ' }),', '};');
192
+ }
193
+ function fingerprintOf(data, beside = '') {
194
+ return readStoredShape(scan(codec(data, [], beside)), 'InvoiceIssuedData')?.fingerprint ?? '';
195
+ }
196
+ function locked(versions) {
197
+ return { [STORED_EVENTS_LOCK]: `${JSON.stringify({ 'billing.invoice.issued': versions }, null, 2)}\n` };
198
+ }
199
+ //# sourceMappingURL=event-sourcing-fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-fixtures.js","sourceRoot":"","sources":["../../../src/check/fixtures/event-sourcing-fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAC;AAG7F,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAErD,MAAM,KAAK,GAAG,+BAA+B,CAAC;AAC9C,MAAM,IAAI,GAAG,2BAA2B,CAAC;AACzC,MAAM,KAAK,GAAG,wCAAwC,CAAC;AACvD,MAAM,QAAQ,GAAG,kCAAkC,CAAC;AAEpD,MAAM,MAAM,GAAG,sBAAsB,CAAC;AACtC,MAAM,YAAY,GAAG,2FAA2F,CAAC;AACjH,MAAM,aAAa,GAAG,GAAG,OAAO,uCAAuC,CAAC;AACxE,MAAM,KAAK,GAAG,GAAG,OAAO,sDAAsD,CAAC;AAC/E,MAAM,aAAa,GAAG,GAAG,OAAO,+D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AC,SAAS,CAAC,EAAE,wBAAwB,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC1G,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Fixture } from './fixture.js';
2
+ export declare const EVENT_SOURCING_PROJECTION_FIXTURES: readonly Fixture[];
3
+ //# sourceMappingURL=event-sourcing-projection-fixtures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-projection-fixtures.d.ts","sourceRoot":"","sources":["../../../src/check/fixtures/event-sourcing-projection-fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAkB5C,eAAO,MAAM,kCAAkC,EAAE,SAAS,OAAO,EAiChE,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { PATHS } from './paths.js';
2
+ import { project } from './project.js';
3
+ import { source } from './source.js';
4
+ const { BILLING } = PATHS;
5
+ const PROJECTION_RULE = 'event-sourcing/projection-never-appends';
6
+ const STORE = 'event-sourcing/store-behind-repository';
7
+ const KERNEL = "'@ddd-ts-kit/kernel'";
8
+ const PROJECTION = `${BILLING}/application/projections/invoice-list.projection.ts`;
9
+ const LIST_PORT = "import { InvoiceList } from '@/contexts/billing/application/ports/invoice-list.port.js';";
10
+ const INVOICE_REPOSITORY = "import { InvoiceRepository } from '@/contexts/billing/domain/repositories/invoice.repository.js';";
11
+ export const EVENT_SOURCING_PROJECTION_FIXTURES = [
12
+ {
13
+ ruleId: PROJECTION_RULE,
14
+ name: 'a projection writing its read model only',
15
+ expect: 'pass',
16
+ files: project(projection([LIST_PORT], ['private readonly invoices: InvoiceList'])),
17
+ },
18
+ {
19
+ ruleId: PROJECTION_RULE,
20
+ name: 'a projection given the event store',
21
+ expect: { file: PROJECTION },
22
+ also: [STORE],
23
+ files: project(projection([LIST_PORT, `import { EventStore } from ${KERNEL};`], ['private readonly invoices: InvoiceList', 'private readonly store: EventStore'])),
24
+ },
25
+ {
26
+ ruleId: PROJECTION_RULE,
27
+ name: 'a projection fed by the dispatcher that names a repository, as before event sourcing',
28
+ expect: 'pass',
29
+ files: project(projection([INVOICE_REPOSITORY], ['private readonly invoices: InvoiceRepository'])),
30
+ },
31
+ {
32
+ ruleId: PROJECTION_RULE,
33
+ name: 'a projection fed by the event store given a repository',
34
+ expect: { file: PROJECTION },
35
+ files: project(projection([INVOICE_REPOSITORY], ['private readonly invoices: InvoiceRepository'], "{ feed: 'event-store' }")),
36
+ },
37
+ ];
38
+ /** A projection under `application/projections/`; declared with `@Projection` and these options when some are given. */
39
+ function projection(imports, parameters, options) {
40
+ const decorator = options === undefined ? [] : [`@Projection('billing.invoice-list', ${options})`];
41
+ const imported = options === undefined ? [] : ["import { Projection } from '@ddd-ts-kit/kernel/declarations';"];
42
+ return {
43
+ [PROJECTION]: source(...imports, ...imported, '', ...decorator, 'export class InvoiceListProjection {', ` constructor(${parameters.join(', ')}) {}`, '}'),
44
+ [`${BILLING}/test/unit/invoice-list.projection.spec.ts`]: source("import { it } from 'vitest';", '', "it.todo('lists');"),
45
+ [`${BILLING}/application/ports/invoice-list.port.ts`]: 'export abstract class InvoiceList {}\n',
46
+ };
47
+ }
48
+ //# sourceMappingURL=event-sourcing-projection-fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-projection-fixtures.js","sourceRoot":"","sources":["../../../src/check/fixtures/event-sourcing-projection-fixtures.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAE1B,MAAM,eAAe,GAAG,yCAAyC,CAAC;AAClE,MAAM,KAAK,GAAG,wCAAwC,CAAC;AACvD,MAAM,MAAM,GAAG,sBAAsB,CAAC;AACtC,MAAM,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CAAC,CAAC;IACnG,MAAM,QAAQ,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,+DAA+D,CAAC,CAAC;IAEhH,OAAO;QACL,CAAC,UAAU,CAAC,EAAE,MAAM,CAClB,GAAG,OAAO,EACV,GAAG,QAAQ,EACX,EAAE,EACF,GAAG,SAAS,EACZ,sCAAsC,EACtC,iBAAiB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAC5C,GAAG,CACJ;QACD,CAAC,GAAG,OAAO,4CAA4C,CAAC,EAAE,MAAM,CAC9D,8BAA8B,EAC9B,EAAE,EACF,mBAAmB,CACpB;QACD,CAAC,GAAG,OAAO,yCAAyC,CAAC,EAAE,wCAAwC;KAChG,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/check/fixtures/fixtures.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAmCtC,CAAC"}
1
+ {"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/check/fixtures/fixtures.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,OAAO,EAoCtC,CAAC"}
@@ -11,6 +11,7 @@ import { COVERAGE_FIXTURES } from './coverage-fixtures.js';
11
11
  import { DECLARATIONS_FIXTURES } from './declarations-fixtures.js';
12
12
  import { DOMAIN_EVENTS_FIXTURES } from './domain-events-fixtures.js';
13
13
  import { ERRORS_FIXTURES } from './errors-fixtures.js';
14
+ import { EVENT_SOURCING_FIXTURES } from './event-sourcing-fixtures.js';
14
15
  import { EVENTS_FIXTURES } from './events-fixtures.js';
15
16
  import { EXTENSION_FIXTURES } from './extension-fixtures.js';
16
17
  import { EXTRACTABLE_FIXTURES } from './extractable-fixtures.js';
@@ -51,6 +52,7 @@ export const FIXTURES = [
51
52
  ...DECLARATIONS_FIXTURES,
52
53
  ...DOMAIN_EVENTS_FIXTURES,
53
54
  ...ERRORS_FIXTURES,
55
+ ...EVENT_SOURCING_FIXTURES,
54
56
  ...EVENTS_FIXTURES,
55
57
  ...EXTENSION_FIXTURES,
56
58
  ...EXTRACTABLE_FIXTURES,
@@ -1 +1 @@
1
- {"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/check/fixtures/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B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,cAAc;IACjB,GAAG,cAAc;IACjB,GAAG,oBAAoB;IACvB,GAAG,eAAe;IAClB,GAAG,8BAA8B;IACjC,GAAG,iBAAiB;IACpB,GAAG,gBAAgB;IACnB,GAAG,iBAAiB;IACpB,GAAG,qBAAqB;IACxB,GAAG,sBAAsB;IACzB,GAAG,eAAe;IAClB,GAAG,uBAAuB;IAC1B,GAAG,eAAe;IAClB,GAAG,kBAAkB;IACrB,GAAG,oBAAoB;IACvB,GAAG,cAAc;IACjB,GAAG,mBAAmB;IACtB,GAAG,gBAAgB;IACnB,GAAG,iBAAiB;IACpB,GAAG,mBAAmB;IACtB,GAAG,cAAc;IACjB,GAAG,eAAe;IAClB,GAAG,eAAe;IAClB,GAAG,eAAe;IAClB,GAAG,oBAAoB;IACvB,GAAG,cAAc;IACjB,GAAG,eAAe;IAClB,GAAG,mBAAmB;IACtB,GAAG,iBAAiB;IACpB,GAAG,gBAAgB;IACnB,GAAG,aAAa;IAChB,GAAG,gBAAgB;IACnB,GAAG,aAAa;CACjB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '../model/rule.js';
2
+ export declare const eventSourcingPastTense: Rule;
3
+ //# sourceMappingURL=event-sourcing-past-tense.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-past-tense.d.ts","sourceRoot":"","sources":["../../../src/check/rules/event-sourcing-past-tense.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAQ7C,eAAO,MAAM,sBAAsB,EAAE,IAYpC,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { eventSourcedClasses } from '../event-sourcing/event-sourced-classes.js';
2
+ import { factWords } from '../event-sourcing/fact-words.js';
3
+ import { isPastFact } from '../../naming/index.js';
4
+ import { perFile } from '../support/per-file.js';
5
+ const FIX = 'Name the event after what happened, with a verb in the past tense: `InvoiceIssued`, `NoShowNoted`, `AmountWithdrawn`, `AppointmentMarkedNoShow`. A stored event is a fact that will be replayed for years; a name in the present or the imperative reads as a command.';
6
+ export const eventSourcingPastTense = {
7
+ id: 'event-sourcing/past-tense',
8
+ description: 'The events an event-sourced aggregate imports from domain/events/ are named in the past tense: one word of the fact, the name after the aggregate, is a past participle that does not read as a command at its head.',
9
+ scope: 'file',
10
+ run(project) {
11
+ return perFile(project, this.id, (file) => {
12
+ const aggregates = eventSourcedClasses(file).map(({ name }) => name);
13
+ return aggregates.length === 0 ? [] : misnamed(file, aggregates);
14
+ });
15
+ },
16
+ };
17
+ function misnamed(file, aggregates) {
18
+ return file.imports.flatMap(({ target, names, line }) => {
19
+ const fromEvents = target.kind === 'file' &&
20
+ target.location.area === 'context' &&
21
+ target.location.layer === 'domain' &&
22
+ target.location.inside[0] === 'events';
23
+ if (!fromEvents) {
24
+ return [];
25
+ }
26
+ return names
27
+ .filter((name) => !isPastFact(factWords(name, aggregates)))
28
+ .map((name) => ({ line, message: `The event ${name} is not named in the past tense.`, fix: FIX }));
29
+ });
30
+ }
31
+ //# sourceMappingURL=event-sourcing-past-tense.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-past-tense.js","sourceRoot":"","sources":["../../../src/check/rules/event-sourcing-past-tense.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAI5D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,MAAM,GAAG,GACP,wQAAwQ,CAAC;AAE3Q,MAAM,CAAC,MAAM,sBAAsB,GAAS;IAC1C,EAAE,EAAE,2BAA2B;IAC/B,WAAW,EACT,sNAAsN;IACxN,KAAK,EAAE,MAAM;IACb,GAAG,CAAC,OAAO;QACT,OAAO,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;YACxC,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;YAErE,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAEF,SAAS,QAAQ,CAAC,IAAgB,EAAE,UAA6B;IAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE;QACtD,MAAM,UAAU,GACd,MAAM,CAAC,IAAI,KAAK,MAAM;YACtB,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS;YAClC,MAAM,CAAC,QAAQ,CAAC,KAAK,KAAK,QAAQ;YAClC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;QAEzC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,KAAK;aACT,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;aAC1D,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,IAAI,kCAAkC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IACvG,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '../model/rule.js';
2
+ export declare const eventSourcingProjectionNeverAppends: Rule;
3
+ //# sourceMappingURL=event-sourcing-projection-never-appends.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-sourcing-projection-never-appends.d.ts","sourceRoot":"","sources":["../../../src/check/rules/event-sourcing-projection-never-appends.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAa7C,eAAO,MAAM,mCAAmC,EAAE,IAQjD,CAAC"}