ddd-ts-kit 0.6.0 → 0.7.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 (253) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -5
  3. package/dist/check/canonical/roles.d.ts.map +1 -1
  4. package/dist/check/canonical/roles.js +1 -0
  5. package/dist/check/canonical/roles.js.map +1 -1
  6. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  7. package/dist/check/catalogue/architecture-rules.js +2 -0
  8. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  9. package/dist/check/catalogue/eslint-only-rules.d.ts.map +1 -1
  10. package/dist/check/catalogue/eslint-only-rules.js +4 -0
  11. package/dist/check/catalogue/eslint-only-rules.js.map +1 -1
  12. package/dist/check/declarations/option-of.d.ts +2 -0
  13. package/dist/check/declarations/option-of.d.ts.map +1 -1
  14. package/dist/check/declarations/option-of.js +7 -1
  15. package/dist/check/declarations/option-of.js.map +1 -1
  16. package/dist/check/events/domain-event-names.d.ts +4 -1
  17. package/dist/check/events/domain-event-names.d.ts.map +1 -1
  18. package/dist/check/events/domain-event-names.js +6 -3
  19. package/dist/check/events/domain-event-names.js.map +1 -1
  20. package/dist/check/explain/language-docs.d.ts.map +1 -1
  21. package/dist/check/explain/language-docs.js +10 -0
  22. package/dist/check/explain/language-docs.js.map +1 -1
  23. package/dist/check/fixtures/declarations-fixtures.d.ts.map +1 -1
  24. package/dist/check/fixtures/declarations-fixtures.js +31 -0
  25. package/dist/check/fixtures/declarations-fixtures.js.map +1 -1
  26. package/dist/check/fixtures/events-fixtures.d.ts.map +1 -1
  27. package/dist/check/fixtures/events-fixtures.js +8 -0
  28. package/dist/check/fixtures/events-fixtures.js.map +1 -1
  29. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  30. package/dist/check/fixtures/fixtures.js +2 -0
  31. package/dist/check/fixtures/fixtures.js.map +1 -1
  32. package/dist/check/fixtures/vocabulary-fixtures.d.ts +3 -0
  33. package/dist/check/fixtures/vocabulary-fixtures.d.ts.map +1 -0
  34. package/dist/check/fixtures/vocabulary-fixtures.js +121 -0
  35. package/dist/check/fixtures/vocabulary-fixtures.js.map +1 -0
  36. package/dist/check/language/declared-value.d.ts +14 -0
  37. package/dist/check/language/declared-value.d.ts.map +1 -0
  38. package/dist/check/language/declared-value.js +2 -0
  39. package/dist/check/language/declared-value.js.map +1 -0
  40. package/dist/check/language/declared-vocabularies.d.ts +11 -0
  41. package/dist/check/language/declared-vocabularies.d.ts.map +1 -0
  42. package/dist/check/language/declared-vocabularies.js +99 -0
  43. package/dist/check/language/declared-vocabularies.js.map +1 -0
  44. package/dist/check/rules/declarations-role-declared.d.ts.map +1 -1
  45. package/dist/check/rules/declarations-role-declared.js +16 -3
  46. package/dist/check/rules/declarations-role-declared.js.map +1 -1
  47. package/dist/check/rules/language-declared-vocabulary.d.ts +3 -0
  48. package/dist/check/rules/language-declared-vocabulary.d.ts.map +1 -0
  49. package/dist/check/rules/language-declared-vocabulary.js +58 -0
  50. package/dist/check/rules/language-declared-vocabulary.js.map +1 -0
  51. package/dist/commands/generate.js +2 -0
  52. package/dist/commands/generate.js.map +1 -1
  53. package/dist/commands/init.d.ts.map +1 -1
  54. package/dist/commands/init.js +4 -0
  55. package/dist/commands/init.js.map +1 -1
  56. package/dist/commands/value-objects.d.ts +4 -0
  57. package/dist/commands/value-objects.d.ts.map +1 -0
  58. package/dist/commands/value-objects.js +44 -0
  59. package/dist/commands/value-objects.js.map +1 -0
  60. package/dist/config/index.d.ts +1 -1
  61. package/dist/config/index.d.ts.map +1 -1
  62. package/dist/config/index.js +1 -1
  63. package/dist/config/index.js.map +1 -1
  64. package/dist/config/parse-stack.d.ts.map +1 -1
  65. package/dist/config/parse-stack.js +3 -1
  66. package/dist/config/parse-stack.js.map +1 -1
  67. package/dist/config/stack.d.ts +16 -0
  68. package/dist/config/stack.d.ts.map +1 -1
  69. package/dist/config/stack.js +2 -0
  70. package/dist/config/stack.js.map +1 -1
  71. package/dist/generate/kind.d.ts +2 -0
  72. package/dist/generate/kind.d.ts.map +1 -1
  73. package/dist/generate/kinds/event-name-reference.d.ts +9 -0
  74. package/dist/generate/kinds/event-name-reference.d.ts.map +1 -0
  75. package/dist/generate/kinds/event-name-reference.js +11 -0
  76. package/dist/generate/kinds/event-name-reference.js.map +1 -0
  77. package/dist/generate/kinds/event-vars.d.ts.map +1 -1
  78. package/dist/generate/kinds/event-vars.js +3 -1
  79. package/dist/generate/kinds/event-vars.js.map +1 -1
  80. package/dist/generate/kinds/integration-event-kind.d.ts.map +1 -1
  81. package/dist/generate/kinds/integration-event-kind.js +3 -1
  82. package/dist/generate/kinds/integration-event-kind.js.map +1 -1
  83. package/dist/generate/kinds/integration-handler-kind.js +13 -1
  84. package/dist/generate/kinds/integration-handler-kind.js.map +1 -1
  85. package/dist/generate/kinds/job/grant-system-actor.d.ts.map +1 -1
  86. package/dist/generate/kinds/job/grant-system-actor.js +21 -6
  87. package/dist/generate/kinds/job/grant-system-actor.js.map +1 -1
  88. package/dist/generate/kinds/job/permission-of.d.ts +9 -0
  89. package/dist/generate/kinds/job/permission-of.d.ts.map +1 -0
  90. package/dist/generate/kinds/job/permission-of.js +12 -0
  91. package/dist/generate/kinds/job/permission-of.js.map +1 -0
  92. package/dist/generate/kinds/route/group-vars.d.ts +5 -1
  93. package/dist/generate/kinds/route/group-vars.d.ts.map +1 -1
  94. package/dist/generate/kinds/route/group-vars.js +9 -5
  95. package/dist/generate/kinds/route/group-vars.js.map +1 -1
  96. package/dist/generate/kinds/route-group-kind.d.ts.map +1 -1
  97. package/dist/generate/kinds/route-group-kind.js +3 -2
  98. package/dist/generate/kinds/route-group-kind.js.map +1 -1
  99. package/dist/generate/kinds/vocabulary-kind.d.ts +3 -0
  100. package/dist/generate/kinds/vocabulary-kind.d.ts.map +1 -0
  101. package/dist/generate/kinds/vocabulary-kind.js +30 -0
  102. package/dist/generate/kinds/vocabulary-kind.js.map +1 -0
  103. package/dist/generate/kinds.d.ts.map +1 -1
  104. package/dist/generate/kinds.js +2 -0
  105. package/dist/generate/kinds.js.map +1 -1
  106. package/dist/generate/shared-writes.d.ts.map +1 -1
  107. package/dist/generate/shared-writes.js +5 -0
  108. package/dist/generate/shared-writes.js.map +1 -1
  109. package/dist/generate/vocabulary/declare-role.d.ts +13 -0
  110. package/dist/generate/vocabulary/declare-role.d.ts.map +1 -0
  111. package/dist/generate/vocabulary/declare-role.js +22 -0
  112. package/dist/generate/vocabulary/declare-role.js.map +1 -0
  113. package/dist/generate/vocabulary/entries-of.d.ts +4 -0
  114. package/dist/generate/vocabulary/entries-of.d.ts.map +1 -0
  115. package/dist/generate/vocabulary/entries-of.js +19 -0
  116. package/dist/generate/vocabulary/entries-of.js.map +1 -0
  117. package/dist/generate/vocabulary/vocabulary-entry.d.ts +6 -0
  118. package/dist/generate/vocabulary/vocabulary-entry.d.ts.map +1 -0
  119. package/dist/generate/vocabulary/vocabulary-entry.js +2 -0
  120. package/dist/generate/vocabulary/vocabulary-entry.js.map +1 -0
  121. package/dist/generate/vocabulary/vocabulary-text.d.ts +9 -0
  122. package/dist/generate/vocabulary/vocabulary-text.d.ts.map +1 -0
  123. package/dist/generate/vocabulary/vocabulary-text.js +28 -0
  124. package/dist/generate/vocabulary/vocabulary-text.js.map +1 -0
  125. package/dist/generate/with-import.d.ts +3 -0
  126. package/dist/generate/with-import.d.ts.map +1 -0
  127. package/dist/generate/with-import.js +12 -0
  128. package/dist/generate/with-import.js.map +1 -0
  129. package/dist/help/notes.d.ts +1 -1
  130. package/dist/help/notes.d.ts.map +1 -1
  131. package/dist/help/notes.js +3 -0
  132. package/dist/help/notes.js.map +1 -1
  133. package/dist/help/usage.d.ts +1 -1
  134. package/dist/help/usage.d.ts.map +1 -1
  135. package/dist/help/usage.js +2 -1
  136. package/dist/help/usage.js.map +1 -1
  137. package/dist/init/files/auth-files.js +2 -2
  138. package/dist/init/files/auth-files.js.map +1 -1
  139. package/dist/init/manifest/versions.js +23 -23
  140. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  141. package/dist/init/stack/resolve-stack.js +5 -1
  142. package/dist/init/stack/resolve-stack.js.map +1 -1
  143. package/dist/init/stack/stack-options.d.ts +2 -0
  144. package/dist/init/stack/stack-options.d.ts.map +1 -1
  145. package/dist/run.d.ts.map +1 -1
  146. package/dist/run.js +2 -0
  147. package/dist/run.js.map +1 -1
  148. package/dist/stack/stack-vars.d.ts.map +1 -1
  149. package/dist/stack/stack-vars.js +3 -1
  150. package/dist/stack/stack-vars.js.map +1 -1
  151. package/dist/value-objects/apply-edits.d.ts +4 -0
  152. package/dist/value-objects/apply-edits.d.ts.map +1 -0
  153. package/dist/value-objects/apply-edits.js +7 -0
  154. package/dist/value-objects/apply-edits.js.map +1 -0
  155. package/dist/value-objects/closing-angle.d.ts +6 -0
  156. package/dist/value-objects/closing-angle.d.ts.map +1 -0
  157. package/dist/value-objects/closing-angle.js +18 -0
  158. package/dist/value-objects/closing-angle.js.map +1 -0
  159. package/dist/value-objects/edit.d.ts +7 -0
  160. package/dist/value-objects/edit.d.ts.map +1 -0
  161. package/dist/value-objects/edit.js +2 -0
  162. package/dist/value-objects/edit.js.map +1 -0
  163. package/dist/value-objects/first-type-argument.d.ts +3 -0
  164. package/dist/value-objects/first-type-argument.d.ts.map +1 -0
  165. package/dist/value-objects/first-type-argument.js +21 -0
  166. package/dist/value-objects/first-type-argument.js.map +1 -0
  167. package/dist/value-objects/inline-results.d.ts +7 -0
  168. package/dist/value-objects/inline-results.d.ts.map +1 -0
  169. package/dist/value-objects/inline-results.js +56 -0
  170. package/dist/value-objects/inline-results.js.map +1 -0
  171. package/dist/value-objects/is-asserted-use.d.ts +14 -0
  172. package/dist/value-objects/is-asserted-use.d.ts.map +1 -0
  173. package/dist/value-objects/is-asserted-use.js +28 -0
  174. package/dist/value-objects/is-asserted-use.js.map +1 -0
  175. package/dist/value-objects/is-converted-call.d.ts +12 -0
  176. package/dist/value-objects/is-converted-call.d.ts.map +1 -0
  177. package/dist/value-objects/is-converted-call.js +46 -0
  178. package/dist/value-objects/is-converted-call.js.map +1 -0
  179. package/dist/value-objects/leftovers.d.ts +6 -0
  180. package/dist/value-objects/leftovers.d.ts.map +1 -0
  181. package/dist/value-objects/leftovers.js +16 -0
  182. package/dist/value-objects/leftovers.js.map +1 -0
  183. package/dist/value-objects/refusal-assertions.d.ts +8 -0
  184. package/dist/value-objects/refusal-assertions.d.ts.map +1 -0
  185. package/dist/value-objects/refusal-assertions.js +65 -0
  186. package/dist/value-objects/refusal-assertions.js.map +1 -0
  187. package/dist/value-objects/refusal-code.d.ts +7 -0
  188. package/dist/value-objects/refusal-code.d.ts.map +1 -0
  189. package/dist/value-objects/refusal-code.js +10 -0
  190. package/dist/value-objects/refusal-code.js.map +1 -0
  191. package/dist/value-objects/result-method-declarations.d.ts +19 -0
  192. package/dist/value-objects/result-method-declarations.d.ts.map +1 -0
  193. package/dist/value-objects/result-method-declarations.js +28 -0
  194. package/dist/value-objects/result-method-declarations.js.map +1 -0
  195. package/dist/value-objects/result-methods.d.ts +8 -0
  196. package/dist/value-objects/result-methods.d.ts.map +1 -0
  197. package/dist/value-objects/result-methods.js +2 -0
  198. package/dist/value-objects/result-methods.js.map +1 -0
  199. package/dist/value-objects/rewrite-usages.d.ts +10 -0
  200. package/dist/value-objects/rewrite-usages.d.ts.map +1 -0
  201. package/dist/value-objects/rewrite-usages.js +20 -0
  202. package/dist/value-objects/rewrite-usages.js.map +1 -0
  203. package/dist/value-objects/rewrite.d.ts +6 -0
  204. package/dist/value-objects/rewrite.d.ts.map +1 -0
  205. package/dist/value-objects/rewrite.js +2 -0
  206. package/dist/value-objects/rewrite.js.map +1 -0
  207. package/dist/value-objects/statement-end.d.ts +3 -0
  208. package/dist/value-objects/statement-end.d.ts.map +1 -0
  209. package/dist/value-objects/statement-end.js +19 -0
  210. package/dist/value-objects/statement-end.js.map +1 -0
  211. package/dist/value-objects/ternary-returns.d.ts +7 -0
  212. package/dist/value-objects/ternary-returns.d.ts.map +1 -0
  213. package/dist/value-objects/ternary-returns.js +59 -0
  214. package/dist/value-objects/ternary-returns.js.map +1 -0
  215. package/dist/value-objects/throwing-source.d.ts +17 -0
  216. package/dist/value-objects/throwing-source.d.ts.map +1 -0
  217. package/dist/value-objects/throwing-source.js +55 -0
  218. package/dist/value-objects/throwing-source.js.map +1 -0
  219. package/dist/value-objects/throwing-value-objects.d.ts +23 -0
  220. package/dist/value-objects/throwing-value-objects.d.ts.map +1 -0
  221. package/dist/value-objects/throwing-value-objects.js +68 -0
  222. package/dist/value-objects/throwing-value-objects.js.map +1 -0
  223. package/dist/value-objects/tidy-imports.d.ts +6 -0
  224. package/dist/value-objects/tidy-imports.d.ts.map +1 -0
  225. package/dist/value-objects/tidy-imports.js +54 -0
  226. package/dist/value-objects/tidy-imports.js.map +1 -0
  227. package/dist/value-objects/without-unwrap.d.ts +5 -0
  228. package/dist/value-objects/without-unwrap.d.ts.map +1 -0
  229. package/dist/value-objects/without-unwrap.js +32 -0
  230. package/dist/value-objects/without-unwrap.js.map +1 -0
  231. package/dist/version.d.ts +1 -1
  232. package/dist/version.js +1 -1
  233. package/package.json +2 -2
  234. package/templates/domain-event/domain-event.ts.tpl +3 -1
  235. package/templates/event-handler/event-handler.declared.ts.tpl +1 -1
  236. package/templates/event-handler/event-handler.spec.ts.tpl +1 -1
  237. package/templates/event-handler/wiring.manual.tpl +2 -2
  238. package/templates/event-handler/wiring.tsyringe.tpl +2 -2
  239. package/templates/init/platform/auth/attribute-policies.ts.tpl +2 -1
  240. package/templates/init/platform/auth/create-authorizer.rbac.ts.tpl +2 -1
  241. package/templates/init/platform/auth/role.ts.tpl +14 -0
  242. package/templates/init/platform/auth/roles.ts.tpl +4 -3
  243. package/templates/init/rules/application.md.tpl +3 -0
  244. package/templates/init/rules/domain.md.tpl +14 -4
  245. package/templates/init/scripts/events.ts.tpl +17 -4
  246. package/templates/integration-event/publisher.declared.ts.tpl +1 -1
  247. package/templates/integration-event/wiring.manual.tpl +1 -1
  248. package/templates/integration-event/wiring.tsyringe.tpl +1 -1
  249. package/templates/integration-handler/integration-handler.declared.ts.tpl +1 -1
  250. package/templates/integration-handler/integration-handler.ts.tpl +8 -1
  251. package/templates/pipeline/package-scripts.json +1 -1
  252. package/templates/value-object/value-object.spec.ts.tpl +16 -0
  253. package/templates/value-object/value-object.ts.tpl +22 -0
@@ -1,16 +1,17 @@
1
1
  import type { Grant } from '@ddd-ts-kit/auth';
2
+ import { Role } from '{{alias.platform}}/auth/role{{alias.ext}}';
2
3
 
3
4
  /**
4
5
  * What each role may do. A grant is a permission of a context (`billingPermissions['invoice.issue']`,
5
6
  * imported from the permissions file of the context), its id, `<context>:*` or `*`. The roles of an
6
7
  * actor come from its credential. Integration event handlers and scheduled jobs act as system
7
- * actors, which carry no role: the authorizer gives them `system`, and `generate job` adds there
8
+ * actors, which carry no role: the authorizer gives them `Role.System`, and `generate job` adds there
8
9
  * the permission of the command a job sends.
9
10
  */
10
11
  // TODO(platform): replace this starting point by the roles of the organisation.
11
12
  export const roles: Readonly<Record<string, readonly Grant[]>> = {
12
- admin: ['*'],
13
- system: [
13
+ [Role.Admin]: ['*'],
14
+ [Role.System]: [
14
15
  // ddd-ts-kit:system-grants
15
16
  // /ddd-ts-kit:system-grants
16
17
  ],
@@ -27,5 +27,8 @@ paths:
27
27
  - A job (`scheduling/*.job.ts`) and an integration event handler (`integration/handlers/`) only build one command and send it as a system actor; both are safe to repeat (`scheduling/job-triggers-use-case`, `events/consumer-idempotent`).
28
28
  - A query never saves, deletes or publishes (`application/command-query-separation`); it hands the access scope of the actor to its read port and never filters after loading.
29
29
  - A read that takes criteria, a scope or a page is a search, never a list (`naming/search-not-list`): `Search<Things>Query` in `queries/search-<things>/` (`generate query ... --search`), `search...` on the port, its adapters and its fakes; one element or none stays `findById` or `findBy...`.
30
+ {{#if literals.named}}
31
+ - A permission, a role or a status is read from its declaration, `billingPermissions['invoice.issue']`, `InvoiceStatus.Issued`, never written as a string (`language/declared-vocabulary`); a number has a name (`clean/no-magic-number`).
32
+ {{/if}}
30
33
  - Time through `Clock`, identifiers through `IdGenerator`, no `process.env` (`purity/*`). No logging, tracing, retry or audit call: they are applied from outside (`aspects/outside-in`, `tracing/platform-only`).
31
34
  - A whole feature with `/ddd-ts-kit:use-case`. Create with `npx ddd-ts-kit generate command|query|port|policy|job|event-handler|integration-handler ... --json`, then fill the `TODO(domain)` places.
@@ -10,20 +10,30 @@ paths:
10
10
  - Names come from the glossary of `CONTEXT.md`, written first (`language/glossary-term`); no `Manager`, `Helper`, `Data`, `Info`, `Model` (`language/no-technical-name`).
11
11
  - Aggregate: private constructor, `create` for birth, `rehydrate` for loading, state changed by methods named after the business intention, no setter, no public mutable property (`domain/aggregate-encapsulation`). One aggregate per transaction; another one is referenced by its id.
12
12
  - Value objects are immutable, validated in `create`, compared with `equals` (`domain/value-object-immutability`). An email, an amount, a period are types, not strings.
13
+ {{#if literals.named}}
14
+ - A closed list of values (a status, a kind, a role of the model) is a vocabulary, `npx ddd-ts-kit generate vocabulary <context> <Name> --value <value>...`: code reads `AppointmentStatus.NoShow`, never the string (`language/declared-vocabulary`).
15
+ - No number without a name: 0, 1, -1 and an index only; a duration, a limit or a rate is a constant of the module (`const MINUTES_PER_HOUR = 60;`) or a value object (`clean/no-magic-number`).
16
+ {{/if}}
13
17
  {{#if refusals.factories}}
14
18
  - A violated invariant throws a refusal built by a static factory of the error class of its concept, never `new` and never a bare `Error`: `throw InvoiceError.alreadyIssued(this.id)` (`errors/through-factory`, `domain/no-generic-error`). One class per concept of the glossary in `domain/errors/`, extending `ConceptError`, no constructor (`errors/constructor-not-public`); a factory is named after the refusal and its code says the same words (`errors/factory-name`), one code per refusal of the context (`errors/code-unique`).
15
- - A factory takes the facts of the refusal as typed parameters and gives them to `refusal(code, message, facts)`. Facts are private: one reaches a client only when the factory names it, `.exposing('<fact>')`, and never when it identifies a person. A value object returns its refusals in the `Result` of `create`: `err(PersonError.invalidEmail(raw))`.
19
+ - A factory takes the facts of the refusal as typed parameters and gives them to `refusal(code, message, facts)`. Facts are private: one reaches a client only when the factory names it, `.exposing('<fact>')`, and never when it identifies a person.
16
20
  {{/if}}
17
21
  {{#if refusals.classes}}
18
22
  - A violated invariant throws a `DomainError` of `domain/errors/` with a stable `code`, never a bare `Error` (`domain/no-generic-error`).
19
23
  {{/if}}
24
+ {{#if valueObjects.throwing}}
25
+ - A value object refuses in `create` as the rest of the domain does: it returns the value object or throws the refusal of the concept it describes{{#if refusals.factories}} (`throw PersonError.invalidEmail(raw)`){{/if}}. The caller takes the value as it is, with no `unwrap`; a spec asserts the refusal with `expectRefusal(() => Email.create(raw), 'INVALID_EMAIL')`.
26
+ {{/if}}
27
+ {{#if valueObjects.result}}
28
+ - A value object returns its refusals in the `Result` of `create`{{#if refusals.factories}}: `err(PersonError.invalidEmail(raw))`{{/if}}; the caller unwraps it with `unwrap(..)` of the kernel. `npx ddd-ts-kit value-objects` moves the project to factories that throw.
29
+ {{/if}}
20
30
  - Domain events are named in the past tense, `<context>.<aggregate>.<fact>` (`events/name-format`), and recorded by the aggregate (`this.record(...)`). They leave with the save: nothing here dispatches them.
21
31
  - A repository here is a port: an abstract class extending the kernel `Repository<Aggregate>`, abstract members only (`ports/abstract-class`). A domain service is stateless.
22
32
  - Time and identifiers come in as parameters (`purity/*`); nothing here knows the acting user or its rights (`authz/in-application`).
23
- - One concept per file, with the suffix of its role: `.aggregate.ts`, `.entity.ts`, `.vo.ts`, `.event.ts`, `.error.ts`, `.repository.ts`, `.service.ts` (`naming/suffix`, `naming/one-concept-per-file`).
33
+ - One concept per file, with the suffix of its role: `.aggregate.ts`, `.entity.ts`, `.vo.ts`, `.vocabulary.ts`, `.event.ts`, `.error.ts`, `.repository.ts`, `.service.ts` (`naming/suffix`, `naming/one-concept-per-file`).
24
34
  {{#if refusals.factories}}
25
- - The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|domain-event|domain-service|repository ... --json`, a refusal with `npx ddd-ts-kit generate error <context> <Concept> <refusal> --json` (it adds the factory to the class of the concept, and its case to the spec), and fill the `TODO(domain)` places it lists.
35
+ - The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|vocabulary|domain-event|domain-service|repository ... --json`, a refusal with `npx ddd-ts-kit generate error <context> <Concept> <refusal> --json` (it adds the factory to the class of the concept, and its case to the spec), and fill the `TODO(domain)` places it lists.
26
36
  {{/if}}
27
37
  {{#if refusals.classes}}
28
- - The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|domain-event|domain-error|domain-service|repository ... --json` and fill the `TODO(domain)` places it lists.
38
+ - The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|vocabulary|domain-event|domain-error|domain-service|repository ... --json` and fill the `TODO(domain)` places it lists.
29
39
  {{/if}}
@@ -13,6 +13,8 @@ const target = path.resolve('docs/integration');
13
13
  const format = contractFormat();
14
14
  const other = format === 'yaml' ? 'asyncapi.json' : 'asyncapi.yaml';
15
15
 
16
+ /** The type of each declaration by the name its published language exports it under, `invoiceIssuedV1`: what a handler reads with `invoiceIssuedV1.type`. */
17
+ const typesByName = new Map<string, string>();
16
18
  const registry = createEventRegistry(await declaredEvents());
17
19
 
18
20
  const generated: Readonly<Record<string, string>> = {
@@ -63,9 +65,16 @@ async function declaredEvents(): Promise<AnyIntegrationEventDefinition[]> {
63
65
  for (const context of contextNames()) {
64
66
  const index = new URL('../{{config.contextsDir}}/' + context + '/published-language/index.js', import.meta.url);
65
67
  const exported: unknown = await import(index.href);
66
- const values: unknown[] = typeof exported === 'object' && exported !== null ? Object.values(exported) : [];
67
68
 
68
- declarations.push(...values.filter(isDeclaration));
69
+ const entries: [string, unknown][] =
70
+ typeof exported === 'object' && exported !== null ? Object.entries(exported) : [];
71
+
72
+ for (const [name, value] of entries) {
73
+ if (isDeclaration(value)) {
74
+ declarations.push(value);
75
+ typesByName.set(name, value.type);
76
+ }
77
+ }
69
78
  }
70
79
 
71
80
  return declarations;
@@ -96,7 +105,7 @@ function isDeclaration(value: unknown): value is AnyIntegrationEventDefinition {
96
105
  );
97
106
  }
98
107
 
99
- /** Who consumes what, read from the sources: an integration event handler names the type it handles in `eventType`. */
108
+ /** Who consumes what, read from the sources: an integration event handler names the type it handles in `eventType`, read from the declaration (`invoiceIssuedV1.type`) or written out. */
100
109
  function consumersByEventType(): Record<string, string[]> {
101
110
  const consumers: Record<string, string[]> = {};
102
111
 
@@ -114,7 +123,11 @@ function consumedBy(context: string): string[] {
114
123
  const files = fs.existsSync(directory) ? fs.readdirSync(directory) : [];
115
124
 
116
125
  return files.flatMap((file) => {
117
- const type = /static readonly eventType = '([^']+)'/.exec(fs.readFileSync(path.join(directory, file), 'utf8'))?.[1];
126
+ const written = /static readonly eventType = (?:'([^']+)'|([A-Za-z_$][\w$]*)\.type\b)/.exec(
127
+ fs.readFileSync(path.join(directory, file), 'utf8'),
128
+ );
129
+
130
+ const type = written?.[1] ?? typesByName.get(written?.[2] ?? '');
118
131
 
119
132
  return type === undefined ? [] : [type];
120
133
  });
@@ -3,7 +3,7 @@ import { DomainEventHandler } from '@ddd-ts-kit/kernel/declarations';
3
3
  import { {{event.pascal}} } from '{{alias.context}}/domain/events/{{event.kebab}}.event{{alias.ext}}';
4
4
  import { {{event.camel}}V{{event.version}} } from '{{alias.context}}/published-language/{{event.kebab}}.v{{event.version}}.integration-event{{alias.ext}}';
5
5
 
6
- @DomainEventHandler({{event.pascal}}, { name: '{{event.name}}' })
6
+ @DomainEventHandler({{event.pascal}}, { name: {{event.reference}} })
7
7
  export class {{publisher.pascal}}Publisher implements DomainEventHandler<{{event.pascal}}> {
8
8
  constructor(
9
9
  private readonly publisher: IntegrationEventPublisher,
@@ -4,7 +4,7 @@ import { {{event.pascal}} } from '{{alias.context}}/domain/events/{{event.kebab}
4
4
  @@registrations
5
5
  const {{publisher.camel}}Publisher = platform.adapter(new {{publisher.pascal}}Publisher(platform.publisher, platform.ids), { kind: 'domain-event-handler', context: '{{context.kebab}}' });
6
6
 
7
- platform.domainEvents.on('{{event.name}}', async (event) => {
7
+ platform.domainEvents.on({{event.reference}}, async (event) => {
8
8
  if (event instanceof {{event.pascal}}) {
9
9
  await {{publisher.camel}}Publisher.handle(event);
10
10
  }
@@ -5,7 +5,7 @@ import { {{event.pascal}} } from '{{alias.context}}/domain/events/{{event.kebab}
5
5
  @@registrations
6
6
  builder.bind({{publisher.pascal}}Publisher).toClass({{publisher.pascal}}Publisher, [IntegrationEventPublisher, IdGenerator]).as('domain-event-handler');
7
7
  @@start
8
- resolve(DomainEventDispatcher).on('{{event.name}}', async (event) => {
8
+ resolve(DomainEventDispatcher).on({{event.reference}}, async (event) => {
9
9
  if (event instanceof {{event.pascal}}) {
10
10
  await resolve({{publisher.pascal}}Publisher).handle(event);
11
11
  }
@@ -4,7 +4,7 @@ import { {{upstream.definition}}, type {{upstream.eventType}} } from '{{alias.co
4
4
 
5
5
  @IntegrationEventHandler({{upstream.definition}}, { consumer: '{{context.kebab}}.{{name.kebab}}' })
6
6
  export class {{name.pascal}}IntegrationHandler {
7
- static readonly eventType = '{{upstream.eventName}}';
7
+ static readonly eventType = {{upstream.typeRead}};
8
8
 
9
9
  readonly actor = systemActor('{{context.kebab}}.{{name.kebab}}');
10
10
 
@@ -1,13 +1,20 @@
1
1
  {{#if upstream.known}}
2
2
  import { systemActor, type CommandBus } from '@ddd-ts-kit/kernel';
3
+ {{/if}}
4
+ {{#if upstream.readsType}}
5
+ import { {{upstream.definition}}, type {{upstream.eventType}} } from '{{alias.contexts}}/{{upstream.kebab}}/published-language/index{{alias.ext}}';
6
+ {{/if}}
7
+ {{#unless upstream.readsType}}
8
+ {{#if upstream.known}}
3
9
  import type { {{upstream.eventType}} } from '{{alias.contexts}}/{{upstream.kebab}}/published-language/index{{alias.ext}}';
4
10
  {{/if}}
11
+ {{/unless}}
5
12
  {{#unless upstream.known}}
6
13
  import { systemActor, type CommandBus, type IntegrationEvent } from '@ddd-ts-kit/kernel';
7
14
  {{/unless}}
8
15
 
9
16
  export class {{name.pascal}}IntegrationHandler {
10
- static readonly eventType = '{{upstream.eventName}}';
17
+ static readonly eventType = {{upstream.typeRead}};
11
18
 
12
19
  readonly actor = systemActor('{{context.kebab}}.{{name.kebab}}');
13
20
 
@@ -23,7 +23,7 @@
23
23
  "@biomejs/biome": "2.5.15",
24
24
  "@commitlint/cli": "^21.2.3",
25
25
  "@commitlint/config-conventional": "^21.2.3",
26
- "@ddd-ts-kit/eslint-plugin": "^0.6.0",
26
+ "@ddd-ts-kit/eslint-plugin": "^0.7.0",
27
27
  "@eslint/js": "^10.0.1",
28
28
  "@typescript/native": "npm:typescript@~7.0.2",
29
29
  "@vitest/coverage-v8": "5.0.3",
@@ -1,20 +1,36 @@
1
1
  import { describe, expect, it } from '{{tests.module}}';
2
+ {{#if valueObjects.throwing}}
3
+ import { expectRefusal } from '@ddd-ts-kit/testing';
4
+ {{/if}}
5
+ {{#if valueObjects.result}}
2
6
  import { unwrap } from '@ddd-ts-kit/kernel';
7
+ {{/if}}
3
8
  import { {{name.pascal}} } from '{{alias.context}}/domain/value-objects/{{name.kebab}}.vo{{alias.ext}}';
4
9
 
5
10
  describe('{{name.pascal}}', () => {
6
11
  it('is equal to another {{name.words}} with the same value', () => {
12
+ {{#if valueObjects.throwing}}
13
+ const first = {{name.pascal}}.create('sample');
14
+ const second = {{name.pascal}}.create('sample');
15
+ {{/if}}
16
+ {{#if valueObjects.result}}
7
17
  const first = unwrap({{name.pascal}}.create('sample'));
8
18
  const second = unwrap({{name.pascal}}.create('sample'));
19
+ {{/if}}
9
20
 
10
21
  expect(first.equals(second)).toBe(true);
11
22
  expect(first.value).toBe('sample');
12
23
  });
13
24
 
14
25
  it('refuses an empty value with a coded error', () => {
26
+ {{#if valueObjects.throwing}}
27
+ expectRefusal(() => {{name.pascal}}.create(' '), 'INVARIANT_VIOLATION');
28
+ {{/if}}
29
+ {{#if valueObjects.result}}
15
30
  const result = {{name.pascal}}.create(' ');
16
31
 
17
32
  expect(result.ok).toBe(false);
33
+ {{/if}}
18
34
  });
19
35
 
20
36
  // TODO(domain): replace each entry below by a test named after the validity rule it proves, with real examples from the domain.
@@ -1,4 +1,9 @@
1
+ {{#if valueObjects.throwing}}
2
+ import { InvariantViolation, ValueObject } from '@ddd-ts-kit/kernel';
3
+ {{/if}}
4
+ {{#if valueObjects.result}}
1
5
  import { InvariantViolation, ValueObject, err, ok, type Result } from '@ddd-ts-kit/kernel';
6
+ {{/if}}
2
7
 
3
8
  export type {{name.pascal}}Props = {
4
9
  readonly value: string;
@@ -9,6 +14,22 @@ export class {{name.pascal}} extends ValueObject<{{name.pascal}}Props> {
9
14
  super(props);
10
15
  }
11
16
 
17
+ {{#if valueObjects.throwing}}
18
+ static create(value: string): {{name.pascal}} {
19
+ {{#if refusals.factories}}
20
+ // TODO(domain): replace `value: string` by the real components of {{name.pascal}}, normalize them and check every validity rule; throw a refusal of the concept this value describes, for example `<Concept>Error.invalid{{name.pascal}}(value)` (`ddd-ts-kit generate error {{context.kebab}} <Concept> invalid{{name.pascal}}`), instead of InvariantViolation.
21
+ {{/if}}
22
+ {{#if refusals.classes}}
23
+ // TODO(domain): replace `value: string` by the real components of {{name.pascal}}, normalize them and check every validity rule; throw a dedicated error (`ddd-ts-kit generate domain-error {{context.kebab}} Invalid{{name.pascal}}`) instead of InvariantViolation.
24
+ {{/if}}
25
+ if (value.trim().length === 0) {
26
+ throw new InvariantViolation('{{name.title}} must not be empty.');
27
+ }
28
+
29
+ return new {{name.pascal}}({ value });
30
+ }
31
+ {{/if}}
32
+ {{#if valueObjects.result}}
12
33
  static create(value: string): Result<{{name.pascal}}, InvariantViolation> {
13
34
  {{#if refusals.factories}}
14
35
  // TODO(domain): replace `value: string` by the real components of {{name.pascal}}, normalize them and check every validity rule; return `err(...)` with a refusal of the concept this value describes, for example `<Concept>Error.invalid{{name.pascal}}(value)` (`ddd-ts-kit generate error {{context.kebab}} <Concept> invalid{{name.pascal}}`), instead of InvariantViolation.
@@ -22,6 +43,7 @@ export class {{name.pascal}} extends ValueObject<{{name.pascal}}Props> {
22
43
 
23
44
  return ok(new {{name.pascal}}({ value }));
24
45
  }
46
+ {{/if}}
25
47
 
26
48
  // TODO(domain): add the operations of {{name.pascal}} (add, isWithin, ...); each returns a new instance, never mutates.
27
49