ddd-ts-kit 0.10.0 → 0.12.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 (299) hide show
  1. package/README.md +13 -7
  2. package/dist/check/canonical/roles.d.ts.map +1 -1
  3. package/dist/check/canonical/roles.js +18 -0
  4. package/dist/check/canonical/roles.js.map +1 -1
  5. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  6. package/dist/check/catalogue/architecture-rules.js +4 -0
  7. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  8. package/dist/check/catalogue/eslint-only-rules.d.ts.map +1 -1
  9. package/dist/check/catalogue/eslint-only-rules.js +4 -0
  10. package/dist/check/catalogue/eslint-only-rules.js.map +1 -1
  11. package/dist/check/domain-events/refused-before-commit.js +1 -1
  12. package/dist/check/domain-events/refused-before-commit.js.map +1 -1
  13. package/dist/check/errors/kit-error-codes.d.ts.map +1 -1
  14. package/dist/check/errors/kit-error-codes.js +2 -0
  15. package/dist/check/errors/kit-error-codes.js.map +1 -1
  16. package/dist/check/explain/errors-docs.js +1 -1
  17. package/dist/check/explain/errors-docs.js.map +1 -1
  18. package/dist/check/explain/events-docs.js +1 -1
  19. package/dist/check/explain/events-docs.js.map +1 -1
  20. package/dist/check/explain/lifecycle-docs.d.ts +3 -0
  21. package/dist/check/explain/lifecycle-docs.d.ts.map +1 -0
  22. package/dist/check/explain/lifecycle-docs.js +33 -0
  23. package/dist/check/explain/lifecycle-docs.js.map +1 -0
  24. package/dist/check/explain/rule-docs.d.ts.map +1 -1
  25. package/dist/check/explain/rule-docs.js +2 -0
  26. package/dist/check/explain/rule-docs.js.map +1 -1
  27. package/dist/check/fixtures/domain-events-fixtures.d.ts.map +1 -1
  28. package/dist/check/fixtures/domain-events-fixtures.js +18 -0
  29. package/dist/check/fixtures/domain-events-fixtures.js.map +1 -1
  30. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  31. package/dist/check/fixtures/fixtures.js +2 -0
  32. package/dist/check/fixtures/fixtures.js.map +1 -1
  33. package/dist/check/fixtures/lifecycle-fixtures.d.ts +3 -0
  34. package/dist/check/fixtures/lifecycle-fixtures.d.ts.map +1 -0
  35. package/dist/check/fixtures/lifecycle-fixtures.js +90 -0
  36. package/dist/check/fixtures/lifecycle-fixtures.js.map +1 -0
  37. package/dist/check/fixtures/standard-fixtures.d.ts.map +1 -1
  38. package/dist/check/fixtures/standard-fixtures.js +8 -0
  39. package/dist/check/fixtures/standard-fixtures.js.map +1 -1
  40. package/dist/check/lifecycle/is-aggregate-file.d.ts +4 -0
  41. package/dist/check/lifecycle/is-aggregate-file.d.ts.map +1 -0
  42. package/dist/check/lifecycle/is-aggregate-file.js +6 -0
  43. package/dist/check/lifecycle/is-aggregate-file.js.map +1 -0
  44. package/dist/check/lifecycle/machines-imported.d.ts +4 -0
  45. package/dist/check/lifecycle/machines-imported.d.ts.map +1 -0
  46. package/dist/check/lifecycle/machines-imported.js +11 -0
  47. package/dist/check/lifecycle/machines-imported.js.map +1 -0
  48. package/dist/check/lifecycle/shorthand-status-writes.d.ts +7 -0
  49. package/dist/check/lifecycle/shorthand-status-writes.d.ts.map +1 -0
  50. package/dist/check/lifecycle/shorthand-status-writes.js +34 -0
  51. package/dist/check/lifecycle/shorthand-status-writes.js.map +1 -0
  52. package/dist/check/lifecycle/status-writes.d.ts +14 -0
  53. package/dist/check/lifecycle/status-writes.d.ts.map +1 -0
  54. package/dist/check/lifecycle/status-writes.js +29 -0
  55. package/dist/check/lifecycle/status-writes.js.map +1 -0
  56. package/dist/check/rules/domain-events-transactional-before-commit.js +1 -1
  57. package/dist/check/rules/domain-events-transactional-before-commit.js.map +1 -1
  58. package/dist/check/rules/lifecycle-status-through-machine.d.ts +3 -0
  59. package/dist/check/rules/lifecycle-status-through-machine.d.ts.map +1 -0
  60. package/dist/check/rules/lifecycle-status-through-machine.js +55 -0
  61. package/dist/check/rules/lifecycle-status-through-machine.js.map +1 -0
  62. package/dist/check/rules/process-sends-commands-only.d.ts +3 -0
  63. package/dist/check/rules/process-sends-commands-only.d.ts.map +1 -0
  64. package/dist/check/rules/process-sends-commands-only.js +39 -0
  65. package/dist/check/rules/process-sends-commands-only.js.map +1 -0
  66. package/dist/check/standard/parallel-names.d.ts.map +1 -1
  67. package/dist/check/standard/parallel-names.js +6 -0
  68. package/dist/check/standard/parallel-names.js.map +1 -1
  69. package/dist/commands/generate.js +25 -19
  70. package/dist/commands/generate.js.map +1 -1
  71. package/dist/commands/init.d.ts.map +1 -1
  72. package/dist/commands/init.js +4 -0
  73. package/dist/commands/init.js.map +1 -1
  74. package/dist/config/index.d.ts +1 -1
  75. package/dist/config/index.d.ts.map +1 -1
  76. package/dist/config/index.js +1 -1
  77. package/dist/config/index.js.map +1 -1
  78. package/dist/config/parse-stack.d.ts.map +1 -1
  79. package/dist/config/parse-stack.js +3 -1
  80. package/dist/config/parse-stack.js.map +1 -1
  81. package/dist/config/stack.d.ts +17 -0
  82. package/dist/config/stack.d.ts.map +1 -1
  83. package/dist/config/stack.js +2 -0
  84. package/dist/config/stack.js.map +1 -1
  85. package/dist/declared/declared-role.d.ts.map +1 -1
  86. package/dist/declared/declared-role.js +1 -0
  87. package/dist/declared/declared-role.js.map +1 -1
  88. package/dist/describe/context-description.d.ts +6 -0
  89. package/dist/describe/context-description.d.ts.map +1 -1
  90. package/dist/describe/describe-context.d.ts.map +1 -1
  91. package/dist/describe/describe-context.js +3 -0
  92. package/dist/describe/describe-context.js.map +1 -1
  93. package/dist/describe/format-description.d.ts.map +1 -1
  94. package/dist/describe/format-description.js +13 -1
  95. package/dist/describe/format-description.js.map +1 -1
  96. package/dist/docs/background-job-facts.d.ts +7 -0
  97. package/dist/docs/background-job-facts.d.ts.map +1 -0
  98. package/dist/docs/background-job-facts.js +2 -0
  99. package/dist/docs/background-job-facts.js.map +1 -0
  100. package/dist/docs/context-facts.d.ts +9 -0
  101. package/dist/docs/context-facts.d.ts.map +1 -1
  102. package/dist/docs/object-properties.d.ts +11 -0
  103. package/dist/docs/object-properties.d.ts.map +1 -0
  104. package/dist/docs/object-properties.js +21 -0
  105. package/dist/docs/object-properties.js.map +1 -0
  106. package/dist/docs/process-facts.d.ts +8 -0
  107. package/dist/docs/process-facts.d.ts.map +1 -0
  108. package/dist/docs/process-facts.js +2 -0
  109. package/dist/docs/process-facts.js.map +1 -0
  110. package/dist/docs/read-background-jobs.d.ts +5 -0
  111. package/dist/docs/read-background-jobs.d.ts.map +1 -0
  112. package/dist/docs/read-background-jobs.js +16 -0
  113. package/dist/docs/read-background-jobs.js.map +1 -0
  114. package/dist/docs/read-context.d.ts.map +1 -1
  115. package/dist/docs/read-context.js +6 -0
  116. package/dist/docs/read-context.js.map +1 -1
  117. package/dist/docs/read-processes.d.ts +5 -0
  118. package/dist/docs/read-processes.d.ts.map +1 -0
  119. package/dist/docs/read-processes.js +22 -0
  120. package/dist/docs/read-processes.js.map +1 -0
  121. package/dist/docs/read-state-machines.d.ts +10 -0
  122. package/dist/docs/read-state-machines.d.ts.map +1 -0
  123. package/dist/docs/read-state-machines.js +81 -0
  124. package/dist/docs/read-state-machines.js.map +1 -0
  125. package/dist/docs/read-vocabularies.d.ts +4 -0
  126. package/dist/docs/read-vocabularies.d.ts.map +1 -0
  127. package/dist/docs/read-vocabularies.js +14 -0
  128. package/dist/docs/read-vocabularies.js.map +1 -0
  129. package/dist/docs/refresh-context-doc.d.ts +1 -1
  130. package/dist/docs/refresh-context-doc.d.ts.map +1 -1
  131. package/dist/docs/refresh-context-doc.js +32 -3
  132. package/dist/docs/refresh-context-doc.js.map +1 -1
  133. package/dist/docs/state-machine-facts.d.ts +18 -0
  134. package/dist/docs/state-machine-facts.d.ts.map +1 -0
  135. package/dist/docs/state-machine-facts.js +2 -0
  136. package/dist/docs/state-machine-facts.js.map +1 -0
  137. package/dist/docs/state-machine-lines.d.ts +8 -0
  138. package/dist/docs/state-machine-lines.d.ts.map +1 -0
  139. package/dist/docs/state-machine-lines.js +32 -0
  140. package/dist/docs/state-machine-lines.js.map +1 -0
  141. package/dist/generate/kind.d.ts +4 -0
  142. package/dist/generate/kind.d.ts.map +1 -1
  143. package/dist/generate/kinds/background/background-job-vars.d.ts +7 -0
  144. package/dist/generate/kinds/background/background-job-vars.d.ts.map +1 -0
  145. package/dist/generate/kinds/background/background-job-vars.js +29 -0
  146. package/dist/generate/kinds/background/background-job-vars.js.map +1 -0
  147. package/dist/generate/kinds/background/job-import.d.ts +8 -0
  148. package/dist/generate/kinds/background/job-import.d.ts.map +1 -0
  149. package/dist/generate/kinds/background/job-import.js +17 -0
  150. package/dist/generate/kinds/background/job-import.js.map +1 -0
  151. package/dist/generate/kinds/background/payload-field.d.ts +18 -0
  152. package/dist/generate/kinds/background/payload-field.d.ts.map +1 -0
  153. package/dist/generate/kinds/background/payload-field.js +52 -0
  154. package/dist/generate/kinds/background/payload-field.js.map +1 -0
  155. package/dist/generate/kinds/background/require-container.d.ts +7 -0
  156. package/dist/generate/kinds/background/require-container.d.ts.map +1 -0
  157. package/dist/generate/kinds/background/require-container.js +13 -0
  158. package/dist/generate/kinds/background/require-container.js.map +1 -0
  159. package/dist/generate/kinds/background-job-kind.d.ts +3 -0
  160. package/dist/generate/kinds/background-job-kind.d.ts.map +1 -0
  161. package/dist/generate/kinds/background-job-kind.js +49 -0
  162. package/dist/generate/kinds/background-job-kind.js.map +1 -0
  163. package/dist/generate/kinds/job/command-input.d.ts +11 -0
  164. package/dist/generate/kinds/job/command-input.d.ts.map +1 -0
  165. package/dist/generate/kinds/job/command-input.js +13 -0
  166. package/dist/generate/kinds/job/command-input.js.map +1 -0
  167. package/dist/generate/kinds/job/granted-in-spec.d.ts +6 -0
  168. package/dist/generate/kinds/job/granted-in-spec.d.ts.map +1 -0
  169. package/dist/generate/kinds/job/granted-in-spec.js +18 -0
  170. package/dist/generate/kinds/job/granted-in-spec.js.map +1 -0
  171. package/dist/generate/kinds/job/job-vars.d.ts.map +1 -1
  172. package/dist/generate/kinds/job/job-vars.js +1 -17
  173. package/dist/generate/kinds/job/job-vars.js.map +1 -1
  174. package/dist/generate/kinds/job/read-sent-command.d.ts +8 -2
  175. package/dist/generate/kinds/job/read-sent-command.d.ts.map +1 -1
  176. package/dist/generate/kinds/job/read-sent-command.js +18 -12
  177. package/dist/generate/kinds/job/read-sent-command.js.map +1 -1
  178. package/dist/generate/kinds/job/sent-command.d.ts +4 -1
  179. package/dist/generate/kinds/job/sent-command.d.ts.map +1 -1
  180. package/dist/generate/kinds/process-kind.d.ts +3 -0
  181. package/dist/generate/kinds/process-kind.d.ts.map +1 -0
  182. package/dist/generate/kinds/process-kind.js +39 -0
  183. package/dist/generate/kinds/process-kind.js.map +1 -0
  184. package/dist/generate/kinds/route/cache-policy-text.d.ts +8 -0
  185. package/dist/generate/kinds/route/cache-policy-text.d.ts.map +1 -0
  186. package/dist/generate/kinds/route/cache-policy-text.js +41 -0
  187. package/dist/generate/kinds/route/cache-policy-text.js.map +1 -0
  188. package/dist/generate/kinds/route/controller-plan.d.ts +2 -0
  189. package/dist/generate/kinds/route/controller-plan.d.ts.map +1 -1
  190. package/dist/generate/kinds/route/controller-vars.js +4 -1
  191. package/dist/generate/kinds/route/controller-vars.js.map +1 -1
  192. package/dist/generate/kinds/route/plan-controller.d.ts.map +1 -1
  193. package/dist/generate/kinds/route/plan-controller.js +4 -1
  194. package/dist/generate/kinds/route/plan-controller.js.map +1 -1
  195. package/dist/generate/kinds/route-kind.d.ts.map +1 -1
  196. package/dist/generate/kinds/route-kind.js +8 -1
  197. package/dist/generate/kinds/route-kind.js.map +1 -1
  198. package/dist/generate/kinds/state-machine/parse-transitions.d.ts +4 -0
  199. package/dist/generate/kinds/state-machine/parse-transitions.d.ts.map +1 -0
  200. package/dist/generate/kinds/state-machine/parse-transitions.js +24 -0
  201. package/dist/generate/kinds/state-machine/parse-transitions.js.map +1 -0
  202. package/dist/generate/kinds/state-machine/requested-transition.d.ts +9 -0
  203. package/dist/generate/kinds/state-machine/requested-transition.d.ts.map +1 -0
  204. package/dist/generate/kinds/state-machine/requested-transition.js +2 -0
  205. package/dist/generate/kinds/state-machine/requested-transition.js.map +1 -0
  206. package/dist/generate/kinds/state-machine/state-machine-vars.d.ts +12 -0
  207. package/dist/generate/kinds/state-machine/state-machine-vars.d.ts.map +1 -0
  208. package/dist/generate/kinds/state-machine/state-machine-vars.js +44 -0
  209. package/dist/generate/kinds/state-machine/state-machine-vars.js.map +1 -0
  210. package/dist/generate/kinds/state-machine/status-vocabulary.d.ts +9 -0
  211. package/dist/generate/kinds/state-machine/status-vocabulary.d.ts.map +1 -0
  212. package/dist/generate/kinds/state-machine/status-vocabulary.js +26 -0
  213. package/dist/generate/kinds/state-machine/status-vocabulary.js.map +1 -0
  214. package/dist/generate/kinds/state-machine-kind.d.ts +3 -0
  215. package/dist/generate/kinds/state-machine-kind.d.ts.map +1 -0
  216. package/dist/generate/kinds/state-machine-kind.js +33 -0
  217. package/dist/generate/kinds/state-machine-kind.js.map +1 -0
  218. package/dist/generate/kinds.d.ts.map +1 -1
  219. package/dist/generate/kinds.js +6 -0
  220. package/dist/generate/kinds.js.map +1 -1
  221. package/dist/generate/vocabulary/held-entries.d.ts +4 -0
  222. package/dist/generate/vocabulary/held-entries.d.ts.map +1 -0
  223. package/dist/generate/vocabulary/held-entries.js +6 -0
  224. package/dist/generate/vocabulary/held-entries.js.map +1 -0
  225. package/dist/generate/vocabulary/vocabulary-text.d.ts.map +1 -1
  226. package/dist/generate/vocabulary/vocabulary-text.js +2 -2
  227. package/dist/generate/vocabulary/vocabulary-text.js.map +1 -1
  228. package/dist/help/usage.d.ts +1 -1
  229. package/dist/help/usage.d.ts.map +1 -1
  230. package/dist/help/usage.js +3 -2
  231. package/dist/help/usage.js.map +1 -1
  232. package/dist/init/files/project-files.d.ts.map +1 -1
  233. package/dist/init/files/project-files.js +3 -1
  234. package/dist/init/files/project-files.js.map +1 -1
  235. package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
  236. package/dist/init/manifest/dependencies-for.js +2 -0
  237. package/dist/init/manifest/dependencies-for.js.map +1 -1
  238. package/dist/init/manifest/versions.js +24 -24
  239. package/dist/init/stack/resolve-queue.d.ts +13 -0
  240. package/dist/init/stack/resolve-queue.d.ts.map +1 -0
  241. package/dist/init/stack/resolve-queue.js +25 -0
  242. package/dist/init/stack/resolve-queue.js.map +1 -0
  243. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  244. package/dist/init/stack/resolve-stack.js +12 -1
  245. package/dist/init/stack/resolve-stack.js.map +1 -1
  246. package/dist/init/stack/stack-options.d.ts +4 -0
  247. package/dist/init/stack/stack-options.d.ts.map +1 -1
  248. package/dist/init/template-vars.js +4 -3
  249. package/dist/init/template-vars.js.map +1 -1
  250. package/dist/stack/stack-vars.d.ts.map +1 -1
  251. package/dist/stack/stack-vars.js +21 -1
  252. package/dist/stack/stack-vars.js.map +1 -1
  253. package/dist/version.d.ts +1 -1
  254. package/dist/version.js +1 -1
  255. package/package.json +2 -2
  256. package/templates/background-job/background-job.declared.ts.tpl +26 -0
  257. package/templates/background-job/background-job.spec.ts.tpl +63 -0
  258. package/templates/background-job/background-job.ts.tpl +24 -0
  259. package/templates/background-job/wiring.tsyringe.tpl +5 -0
  260. package/templates/context/CONTEXT.md.tpl +15 -0
  261. package/templates/controller/controller.class-validator.ts.tpl +3 -0
  262. package/templates/controller/controller.none.ts.tpl +3 -0
  263. package/templates/controller/controller.search.ts.tpl +3 -0
  264. package/templates/controller/controller.standard-schema.ts.tpl +3 -0
  265. package/templates/controller/controller.zod.ts.tpl +3 -0
  266. package/templates/docs/openapi.json.tpl +9 -0
  267. package/templates/init/docker/docker-compose.yml.tpl +20 -0
  268. package/templates/init/docker/env.example.tpl +10 -0
  269. package/templates/init/docker/varnish.vcl.tpl +74 -0
  270. package/templates/init/e2e/start-application.database.ts.tpl +28 -0
  271. package/templates/init/e2e/start-application.memory.ts.tpl +30 -0
  272. package/templates/init/e2e/test-environment.ts.tpl +5 -0
  273. package/templates/init/main.ts.tpl +13 -0
  274. package/templates/init/platform/auth/http-boundary.ts.tpl +29 -0
  275. package/templates/init/platform/compose-application.tsyringe.ts.tpl +13 -0
  276. package/templates/init/platform/config/app-config.ts.tpl +6 -0
  277. package/templates/init/platform/config/load-config.ts.tpl +12 -0
  278. package/templates/init/platform/create-platform.manual.ts.tpl +31 -0
  279. package/templates/init/platform/database/persistence-over.drizzle.ts.tpl +20 -1
  280. package/templates/init/platform/database/persistence-over.knex.ts.tpl +18 -1
  281. package/templates/init/platform/database/persistence.orm.ts.tpl +12 -1
  282. package/templates/init/platform/database/schema.drizzle.ts.tpl +12 -2
  283. package/templates/init/platform/database/schema.knex.ts.tpl +7 -1
  284. package/templates/init/platform/platform.manual.ts.tpl +7 -0
  285. package/templates/init/platform/platform.module.tsyringe.ts.tpl +43 -3
  286. package/templates/init/platform/redis/open-redis.ts.tpl +37 -1
  287. package/templates/init/rules/application.md.tpl +3 -2
  288. package/templates/init/rules/domain.md.tpl +1 -0
  289. package/templates/init/rules/presentation.md.tpl +2 -1
  290. package/templates/pipeline/package-scripts.json +1 -1
  291. package/templates/process/process.spec.ts.tpl +44 -0
  292. package/templates/process/process.ts.tpl +41 -0
  293. package/templates/process/timeout-job.declared.ts.tpl +18 -0
  294. package/templates/process/timeout-job.spec.ts.tpl +43 -0
  295. package/templates/process/timeout-job.ts.tpl +16 -0
  296. package/templates/process/timeout-job.wiring.tsyringe.tpl +5 -0
  297. package/templates/service/main.ts.tpl +13 -0
  298. package/templates/state-machine/state-machine.spec.ts.tpl +16 -0
  299. package/templates/state-machine/state-machine.ts.tpl +16 -0
@@ -1,7 +1,12 @@
1
1
  {{#if authz.rebac}}
2
2
  import type { RelationTuple } from '@ddd-ts-kit/auth/rebac';
3
3
  {{/if}}
4
+ {{#if httpCache.varnish}}
5
+ import { InMemoryCachePurger, PurgingPublisher, type IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
6
+ {{/if}}
7
+ {{#unless httpCache.varnish}}
4
8
  import type { IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
9
+ {{/unless}}
5
10
  import { createHttpClient, type HttpClient } from '@ddd-ts-kit/testing/e2e';
6
11
  {{#if authz.rebac}}
7
12
  import { relationTuples } from '{{alias.platform}}/auth/relation-tuples{{alias.ext}}';
@@ -45,6 +50,10 @@ export interface RunningApplication {
45
50
  readonly client: HttpClient;
46
51
  /** Subscribe here (`collectEvents`) to assert the integration events the application publishes. */
47
52
  readonly events: IntegrationEventSubscriber;
53
+ {{#if httpCache.varnish}}
54
+ /** What the relay purged from the shared cache once each command committed: `purges.purged` lists the tags. */
55
+ readonly purges: InMemoryCachePurger;
56
+ {{/if}}
48
57
 
49
58
  /** A client presenting the credential of `actor`; `client` itself presents none. */
50
59
  as(actor: TestActor): Promise<HttpClient>;
@@ -75,6 +84,9 @@ export async function startApplication(): Promise<RunningApplication> {
75
84
  return {
76
85
  client: started.client,
77
86
  events: started.events,
87
+ {{#if httpCache.varnish}}
88
+ purges: started.purges,
89
+ {{/if}}
78
90
  as: async (actor) => started.client.withHeaders(await credentials.headersOf(actor)),
79
91
  {{#if authz.rebac}}
80
92
  relate: (tuple) => relationTuples.write([tuple]),
@@ -87,6 +99,9 @@ export async function startApplication(): Promise<RunningApplication> {
87
99
  interface Started {
88
100
  readonly client: HttpClient;
89
101
  readonly events: IntegrationEventSubscriber;
102
+ {{#if httpCache.varnish}}
103
+ readonly purges: InMemoryCachePurger;
104
+ {{/if}}
90
105
 
91
106
  close(): Promise<void>;
92
107
  }
@@ -107,10 +122,20 @@ async function start(database: TestDatabase, config: AppConfig, credentials: Cre
107
122
 
108
123
  await application.start();
109
124
 
125
+ {{#if httpCache.varnish}}
126
+ const purges = new InMemoryCachePurger();
127
+
128
+ {{/if}}
110
129
  {{#if events.outbox}}
111
130
  const relay = startOutboxRelay({
112
131
  store: database.persistence.outbox,
132
+ {{#if httpCache.varnish}}
133
+ // The purge requests of the commands are recorded instead of sent to Varnish, every other event goes to the bus.
134
+ publisher: new PurgingPublisher(purges, application.eventBus),
135
+ {{/if}}
136
+ {{#unless httpCache.varnish}}
113
137
  publisher: application.eventBus,
138
+ {{/unless}}
114
139
  intervalMs: 20,
115
140
  logger: application.logger,
116
141
  });
@@ -121,6 +146,9 @@ async function start(database: TestDatabase, config: AppConfig, credentials: Cre
121
146
  return {
122
147
  client: createHttpClient('http://127.0.0.1:' + server.port),
123
148
  events: application.eventSubscriber,
149
+ {{#if httpCache.varnish}}
150
+ purges,
151
+ {{/if}}
124
152
  close: async () => {
125
153
  await server.close();
126
154
  {{#if events.outbox}}
@@ -1,7 +1,12 @@
1
1
  {{#if authz.rebac}}
2
2
  import type { RelationTuple } from '@ddd-ts-kit/auth/rebac';
3
3
  {{/if}}
4
+ {{#if httpCache.varnish}}
5
+ import { InMemoryCachePurger, PurgingPublisher, type IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
6
+ {{/if}}
7
+ {{#unless httpCache.varnish}}
4
8
  import type { IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
9
+ {{/unless}}
5
10
  import { createHttpClient, type HttpClient } from '@ddd-ts-kit/testing/e2e';
6
11
  {{#if authz.rebac}}
7
12
  import { relationTuples } from '{{alias.platform}}/auth/relation-tuples{{alias.ext}}';
@@ -48,6 +53,10 @@ export interface RunningApplication {
48
53
  readonly client: HttpClient;
49
54
  /** Subscribe here (`collectEvents`) to assert the integration events the application publishes. */
50
55
  readonly events: IntegrationEventSubscriber;
56
+ {{#if httpCache.varnish}}
57
+ /** What the relay purged from the shared cache once each command committed: `purges.purged` lists the tags. */
58
+ readonly purges: InMemoryCachePurger;
59
+ {{/if}}
51
60
 
52
61
  /** A client presenting the credential of `actor`; `client` itself presents none. */
53
62
  as(actor: TestActor): Promise<HttpClient>;
@@ -75,6 +84,11 @@ export async function startApplication(): Promise<RunningApplication> {
75
84
  get events() {
76
85
  return current.events;
77
86
  },
87
+ {{#if httpCache.varnish}}
88
+ get purges() {
89
+ return current.purges;
90
+ },
91
+ {{/if}}
78
92
  as: async (actor) => current.client.withHeaders(await credentials.headersOf(actor)),
79
93
  {{#if authz.rebac}}
80
94
  relate: (tuple) => relationTuples.write([tuple]),
@@ -90,6 +104,9 @@ export async function startApplication(): Promise<RunningApplication> {
90
104
  interface Started {
91
105
  readonly client: HttpClient;
92
106
  readonly events: IntegrationEventSubscriber;
107
+ {{#if httpCache.varnish}}
108
+ readonly purges: InMemoryCachePurger;
109
+ {{/if}}
93
110
 
94
111
  close(): Promise<void>;
95
112
  }
@@ -111,10 +128,20 @@ async function start(credentials: Credentials): Promise<Started> {
111
128
 
112
129
  await application.start();
113
130
 
131
+ {{#if httpCache.varnish}}
132
+ const purges = new InMemoryCachePurger();
133
+
134
+ {{/if}}
114
135
  {{#if events.outbox}}
115
136
  const relay = startOutboxRelay({
116
137
  store: persistence.outbox,
138
+ {{#if httpCache.varnish}}
139
+ // The purge requests of the commands are recorded instead of sent to Varnish, every other event goes to the bus.
140
+ publisher: new PurgingPublisher(purges, application.eventBus),
141
+ {{/if}}
142
+ {{#unless httpCache.varnish}}
117
143
  publisher: application.eventBus,
144
+ {{/unless}}
118
145
  intervalMs: 20,
119
146
  logger: application.logger,
120
147
  });
@@ -125,6 +152,9 @@ async function start(credentials: Credentials): Promise<Started> {
125
152
  return {
126
153
  client: createHttpClient('http://127.0.0.1:' + server.port),
127
154
  events: application.eventSubscriber,
155
+ {{#if httpCache.varnish}}
156
+ purges,
157
+ {{/if}}
128
158
  close: async () => {
129
159
  await server.close();
130
160
  {{#if events.outbox}}
@@ -25,6 +25,11 @@ export function testEnvironment(overrides: Variables = {}): Variables {
25
25
  {{#if redis.server}}
26
26
  REDIS_URL: (process.env['REDIS_URL'] ?? '') || noRedis,
27
27
  {{/if}}
28
+ {{#if httpCache.varnish}}
29
+ // The relay of the tests hands the purges to a recording purger, never to Varnish: the address only has to be one.
30
+ VARNISH_URL: (process.env['VARNISH_URL'] ?? '') || 'http://varnish.e2e.test',
31
+ VARNISH_PURGE_KEY: (process.env['VARNISH_PURGE_KEY'] ?? '') || 'e2e-purge-key',
32
+ {{/if}}
28
33
  {{#if cache.rateLimit}}
29
34
  RATE_LIMIT_MAX: process.env['RATE_LIMIT_MAX'] ?? '1000000',
30
35
  {{/if}}
@@ -4,6 +4,10 @@ import { tracing } from '{{alias.platform}}/tracing{{alias.ext}}';
4
4
  // Imported second on purpose: a failure while the rest of the application loads is already reported.
5
5
  import { errors } from '{{alias.platform}}/errors{{alias.ext}}';
6
6
  {{/if}}
7
+ {{#if httpCache.varnish}}
8
+ import { VarnishCachePurger } from '@ddd-ts-kit/http/purgers';
9
+ import { PurgingPublisher } from '@ddd-ts-kit/kernel';
10
+ {{/if}}
7
11
  {{#if http.any}}
8
12
  import { createAuthenticator } from '{{alias.platform}}/auth/create-authenticator{{alias.ext}}';
9
13
  {{/if}}
@@ -61,7 +65,16 @@ await application.start();
61
65
  {{#if events.outbox}}
62
66
  const relay = startOutboxRelay({
63
67
  store: persistence.outbox,
68
+ {{#if httpCache.varnish}}
69
+ // The purge requests the use cases wrote with their commands go to Varnish, every other event to the provider.
70
+ publisher: new PurgingPublisher(
71
+ new VarnishCachePurger({ url: config.varnishUrl, key: config.varnishPurgeKey }),
72
+ application.eventBus,
73
+ ),
74
+ {{/if}}
75
+ {{#unless httpCache.varnish}}
64
76
  publisher: application.eventBus,
77
+ {{/unless}}
65
78
  intervalMs: config.outboxRelayIntervalMs,
66
79
  logger: application.logger,
67
80
  {{#if errors.sentry}}
@@ -1,4 +1,12 @@
1
1
  import type { Authenticator } from '@ddd-ts-kit/auth';
2
+ {{#if httpCache.varnish}}
3
+ {{#unless httpCache.perTenant}}
4
+ import { CacheTagHeader } from '@ddd-ts-kit/http';
5
+ {{/unless}}
6
+ {{#if httpCache.perTenant}}
7
+ import { CacheTagHeader, tenantFromHeader, type TenantResolver } from '@ddd-ts-kit/http';
8
+ {{/if}}
9
+ {{/if}}
2
10
  {{#if errors.none}}
3
11
  import type { ErrorContext, ErrorMapper, {{#if audit.on}}GuardRefusal, {{/if}}RouteAround{{#if files.http}}, UploadReader{{/if}} } from '@ddd-ts-kit/http';
4
12
  import type { Clock, ExecutionScope, Logger, Session } from '@ddd-ts-kit/kernel';
@@ -49,6 +57,17 @@ export interface HttpBoundary {
49
57
  readonly onError: (error: unknown, context: ErrorContext) => void;
50
58
  /** The span of a request, named by its route template; probes and documentation routes make none. */
51
59
  readonly around: RouteAround;
60
+ {{#if httpCache.varnish}}
61
+ /** The header Varnish files a public answer under the tags of its resources from. */
62
+ readonly cacheTags: { readonly header: CacheTagHeader; readonly perTenant?: boolean };
63
+ {{/if}}
64
+ {{#if httpCache.perTenant}}
65
+ /**
66
+ * The tenant of a request that names one in `x-tenant-id`, an anonymous one on a public route included: its
67
+ * answers are then filed under that tenant, and vary on the header. Without it, the tenant of the caller.
68
+ */
69
+ readonly resolveTenant: TenantResolver;
70
+ {{/if}}
52
71
  {{#if files.http}}
53
72
  /** Reads the file of a controller that declares an upload, as it streams: its size and media types are checked on the way. */
54
73
  readonly uploads: UploadReader;
@@ -112,6 +131,16 @@ export function httpBoundary({
112
131
  errorMapper,
113
132
  clock,
114
133
  around: tracedRoutes(),
134
+ {{#if httpCache.varnish}}
135
+ {{#if httpCache.perTenant}}
136
+ // Filed under the tenant of the request, as the purges of the outbox are.
137
+ cacheTags: { header: CacheTagHeader.xkey, perTenant: true },
138
+ resolveTenant: tenantFromHeader(),
139
+ {{/if}}
140
+ {{#unless httpCache.perTenant}}
141
+ cacheTags: { header: CacheTagHeader.xkey },
142
+ {{/unless}}
143
+ {{/if}}
115
144
  {{#if files.http}}
116
145
  uploads: multipartUploads(),
117
146
  {{/if}}
@@ -54,6 +54,9 @@ import {
54
54
  {{/unless}}
55
55
  Logger,
56
56
  Metrics,
57
+ {{#if httpCache.perTenant}}
58
+ PublishedCacheInvalidation,
59
+ {{/if}}
57
60
  {{#if http.any}}
58
61
  QueryBus,
59
62
  {{/if}}
@@ -242,6 +245,16 @@ function kernel(foundations: Foundations, persistence: Persistence, options: App
242
245
  eventPublisher: scopedPublisher(bus, scope),
243
246
  {{/unless}}
244
247
  eventSubscriber: bus,
248
+ {{#if httpCache.perTenant}}
249
+ // The purges of the outbox filed under the tenant of the work, as the answers are tagged (`cacheTags.perTenant`).
250
+ cacheInvalidation: new PublishedCacheInvalidation({
251
+ publisher: scopedPublisher(new OutboxPublisher(persistence.outbox), scope),
252
+ ids,
253
+ clock,
254
+ scope,
255
+ perTenant: true,
256
+ }),
257
+ {{/if}}
245
258
  {{#if errors.sentry}}
246
259
  // The buses and the jobs report through it, and `container.stop()` flushes it; left out (the tools, the tests), nothing is reported.
247
260
  ...(options.errors === undefined ? {} : { errorReporter: options.errors }),
@@ -44,6 +44,12 @@ export interface AppConfig {
44
44
  {{#if redis.server}}
45
45
  readonly redisUrl: string;
46
46
  {{/if}}
47
+ {{#if httpCache.varnish}}
48
+ /** Varnish as the API reaches it (`VARNISH_URL`): where the relay of the outbox sends the purges of the tags. */
49
+ readonly varnishUrl: string;
50
+ /** The key Varnish lets a purge from another machine in with (`VARNISH_PURGE_KEY`): a secret in production. */
51
+ readonly varnishPurgeKey: string;
52
+ {{/if}}
47
53
  {{#if cache.rateLimit}}
48
54
  /** How many requests one caller address may send in a sliding window, before the HTTP layer answers 429. */
49
55
  readonly rateLimit: RateLimit;
@@ -62,6 +62,9 @@ export function loadConfig(env: Variables): AppConfig {
62
62
  {{#if redis.server}}
63
63
  redisUrl: readUrl(env, 'REDIS_URL', problems),
64
64
  {{/if}}
65
+ {{#if httpCache.varnish}}
66
+ ...readVarnish(env, problems),
67
+ {{/if}}
65
68
  {{#if cache.rateLimit}}
66
69
  rateLimit: readRateLimit(env, problems),
67
70
  {{/if}}
@@ -143,6 +146,15 @@ function readResilience(env: Variables, problems: string[]): AppConfig['resilien
143
146
  timeoutMs: readInteger(env, { name: 'OUTBOUND_TIMEOUT_MS', fallback: 2000, min: 1, max: 600000 }, problems),
144
147
  };
145
148
  }
149
+ {{#if httpCache.varnish}}
150
+
151
+ function readVarnish(env: Variables, problems: string[]): Pick<AppConfig, 'varnishUrl' | 'varnishPurgeKey'> {
152
+ return {
153
+ varnishUrl: readUrl(env, 'VARNISH_URL', problems),
154
+ varnishPurgeKey: readText(env, 'VARNISH_PURGE_KEY', problems),
155
+ };
156
+ }
157
+ {{/if}}
146
158
  {{#if cache.rateLimit}}
147
159
 
148
160
  function readRateLimit(env: Variables, problems: string[]): AppConfig['rateLimit'] {
@@ -17,6 +17,9 @@ import {
17
17
  InMemoryRateLimiter,
18
18
  {{/if}}
19
19
  NoopErrorReporter,
20
+ {{#if httpCache.varnish}}
21
+ PublishedCacheInvalidation,
22
+ {{/if}}
20
23
  ScopedActorContext,
21
24
  SystemClock,
22
25
  UuidGenerator,
@@ -143,7 +146,12 @@ export function createPlatform(persistence: Persistence, options: PlatformOption
143
146
 
144
147
  return {
145
148
  ...foundations,
149
+ {{#if httpCache.varnish}}
150
+ ...withCacheInvalidation(eventsOn(persistence, options, { scope, traced }), foundations),
151
+ {{/if}}
152
+ {{#unless httpCache.varnish}}
146
153
  ...eventsOn(persistence, options, { scope, traced }),
154
+ {{/unless}}
147
155
  // Around every use case, outermost first: {{#if errors.sentry}}the report of an unexpected failure, {{/if}}its log entry, its measure, the permission, its span; a command then {{#if files.any}}has the file it carries staged, out of any transaction, and {{/if}}runs in the unit of work.
148
156
  commands: chain(new InMemoryCommandBus(), [
149
157
  ...observed,
@@ -287,6 +295,29 @@ function eventsOn(
287
295
  };
288
296
  }
289
297
 
298
+ {{#if httpCache.varnish}}
299
+ /**
300
+ * The events, and the purges a change asks for, written to the outbox with it through the same publisher: a rollback
301
+ * takes them away, the relay sends them to Varnish once committed.{{#if httpCache.perTenant}} Filed under the tenant
302
+ * of the work, as the answers are tagged.{{/if}}
303
+ */
304
+ function withCacheInvalidation(events: Events, { ids, clock, scope }: Foundations): Events & CacheInvalidating {
305
+ const { publisher } = events;
306
+
307
+ {{#if httpCache.perTenant}}
308
+ return {
309
+ ...events,
310
+ cacheInvalidation: new PublishedCacheInvalidation({ publisher, ids, clock, scope, perTenant: true }),
311
+ };
312
+ {{/if}}
313
+ {{#unless httpCache.perTenant}}
314
+ return { ...events, cacheInvalidation: new PublishedCacheInvalidation({ publisher, ids, clock, scope }) };
315
+ {{/unless}}
316
+ }
317
+
318
+ type CacheInvalidating = Pick<Platform, 'cacheInvalidation'>;
319
+
320
+ {{/if}}
290
321
  interface Observation {
291
322
  readonly scope: Platform['scope'];
292
323
  readonly traced: TracedApplication;
@@ -1,7 +1,20 @@
1
1
  import type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
2
+ {{#if queue.processTable}}
3
+ import {
4
+ createDrizzleUnitOfWork,
5
+ {{#if queue.database}}
6
+ DrizzleJobStore,
7
+ {{/if}}
8
+ DrizzleOutboxStore,
9
+ DrizzleProcessedEventStore,
10
+ DrizzleProcessStore,
11
+ } from '@ddd-ts-kit/drizzle/postgres';
12
+ {{/if}}
13
+ {{#unless queue.processTable}}
2
14
  import { createDrizzleUnitOfWork, DrizzleOutboxStore, DrizzleProcessedEventStore } from '@ddd-ts-kit/drizzle/postgres';
15
+ {{/unless}}
3
16
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
4
- import { outbox, processedEvents } from '{{alias.platform}}/database/schema{{alias.ext}}';
17
+ import { {{#if queue.database}}jobs, {{/if}}outbox, processedEvents{{#if queue.processTable}}, processes{{/if}} } from '{{alias.platform}}/database/schema{{alias.ext}}';
5
18
 
6
19
  /** One object is the unit of work and what repositories query through; the stores write in its transaction. */
7
20
  export function persistenceOver(db: PgDatabase<PgQueryResultHKT>, close: () => Promise<void>): Persistence {
@@ -12,6 +25,12 @@ export function persistenceOver(db: PgDatabase<PgQueryResultHKT>, close: () => P
12
25
  database: unitOfWork,
13
26
  outbox: new DrizzleOutboxStore(unitOfWork, { table: outbox }),
14
27
  processedEvents: new DrizzleProcessedEventStore(unitOfWork, { table: processedEvents }),
28
+ {{#if queue.database}}
29
+ jobs: new DrizzleJobStore(unitOfWork, jobs),
30
+ {{/if}}
31
+ {{#if queue.processTable}}
32
+ processes: new DrizzleProcessStore(unitOfWork, processes),
33
+ {{/if}}
15
34
  close,
16
35
  };
17
36
  }
@@ -1,5 +1,16 @@
1
1
  import type { Knex } from 'knex';
2
- import { createKnexUnitOfWork, KnexOutboxStore, KnexProcessedEventStore } from '@ddd-ts-kit/knex';
2
+ {{#if queue.database}}
3
+ import {
4
+ createKnexUnitOfWork,
5
+ KnexJobStore,
6
+ KnexOutboxStore,
7
+ KnexProcessedEventStore,
8
+ KnexProcessStore,
9
+ } from '@ddd-ts-kit/knex';
10
+ {{/if}}
11
+ {{#unless queue.database}}
12
+ import { createKnexUnitOfWork, KnexOutboxStore, KnexProcessedEventStore{{#if queue.processTable}}, KnexProcessStore{{/if}} } from '@ddd-ts-kit/knex';
13
+ {{/unless}}
3
14
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
4
15
  import { MESSAGING } from '{{alias.platform}}/database/schema{{alias.ext}}';
5
16
 
@@ -17,6 +28,12 @@ export function persistenceOver(db: Knex, close: () => Promise<void>): Persisten
17
28
  outbox: new KnexOutboxStore(unitOfWork, { schema: MESSAGING }),
18
29
  {{/unless}}
19
30
  processedEvents: new KnexProcessedEventStore(unitOfWork, { schema: MESSAGING }),
31
+ {{#if queue.database}}
32
+ jobs: new KnexJobStore(unitOfWork, { schema: MESSAGING }),
33
+ {{/if}}
34
+ {{#if queue.processTable}}
35
+ processes: new KnexProcessStore(unitOfWork, { schema: MESSAGING }),
36
+ {{/if}}
20
37
  close,
21
38
  };
22
39
  }
@@ -1,5 +1,8 @@
1
1
  import type { OutboxStore } from '@ddd-ts-kit/events';
2
- import type { ProcessedEventStore, UnitOfWork } from '@ddd-ts-kit/kernel';
2
+ import type { ProcessedEventStore, {{#if queue.processTable}}ProcessStore, {{/if}}UnitOfWork } from '@ddd-ts-kit/kernel';
3
+ {{#if queue.database}}
4
+ import type { JobStore } from '@ddd-ts-kit/scheduling';
5
+ {{/if}}
3
6
  {{#if persistence.packagedToken}}
4
7
  import type { {{persistence.token}} } from '{{persistence.tokenPackage}}';
5
8
  {{/if}}
@@ -12,6 +15,14 @@ export interface Persistence {
12
15
  readonly unitOfWork: UnitOfWork;
13
16
  readonly outbox: OutboxStore;
14
17
  readonly processedEvents: ProcessedEventStore;
18
+ {{#if queue.database}}
19
+ /** The background jobs, enqueued in the transaction of the command that asks for them. */
20
+ readonly jobs: JobStore;
21
+ {{/if}}
22
+ {{#if queue.processTable}}
23
+ /** The instances of the process managers, saved in the transaction of each step. */
24
+ readonly processes: ProcessStore;
25
+ {{/if}}
15
26
  /** What repositories query through: the transaction of the current unit of work, or the database. */
16
27
  readonly database: {{persistence.token}};
17
28
 
@@ -2,17 +2,27 @@
2
2
  import { auditChainsTable, auditEntriesTable } from '@ddd-ts-kit/audit/drizzle';
3
3
  {{/if}}
4
4
  {{#if tenancy.any}}
5
- import { processedEventsTable, tenantOutboxTable } from '@ddd-ts-kit/drizzle/postgres';
5
+ import { {{#if queue.database}}jobsTable, {{/if}}processedEventsTable{{#if queue.processTable}}, processesTable{{/if}}, tenantOutboxTable } from '@ddd-ts-kit/drizzle/postgres';
6
6
 
7
7
  /** It keeps the tenant of each event, so that its consumers run in that tenant. */
8
8
  export const outbox = tenantOutboxTable('messaging');
9
9
  {{/if}}
10
10
  {{#unless tenancy.any}}
11
- import { outboxTable, processedEventsTable } from '@ddd-ts-kit/drizzle/postgres';
11
+ import { {{#if queue.database}}jobsTable, {{/if}}outboxTable, processedEventsTable{{#if queue.processTable}}, processesTable{{/if}} } from '@ddd-ts-kit/drizzle/postgres';
12
12
 
13
13
  export const outbox = outboxTable('messaging');
14
14
  {{/unless}}
15
15
  export const processedEvents = processedEventsTable('messaging');
16
+ {{#if queue.database}}
17
+
18
+ /** The background jobs, in the schema of the messaging of the application. */
19
+ export const jobs = jobsTable('messaging');
20
+ {{/if}}
21
+ {{#if queue.processTable}}
22
+
23
+ /** The instances of the process managers. */
24
+ export const processes = processesTable('messaging');
25
+ {{/if}}
16
26
  {{#if audit.on}}
17
27
 
18
28
  /** The schema of the audit trail. */
@@ -2,7 +2,7 @@ import type { Knex } from 'knex';
2
2
  {{#if audit.on}}
3
3
  import { createAuditTables } from '@ddd-ts-kit/audit/knex';
4
4
  {{/if}}
5
- import { createOutboxTables } from '@ddd-ts-kit/knex';
5
+ import { {{#if queue.database}}createJobTable, {{/if}}createOutboxTables{{#if queue.processTable}}, createProcessTable{{/if}} } from '@ddd-ts-kit/knex';
6
6
  // ddd-ts-kit:imports
7
7
  // /ddd-ts-kit:imports
8
8
 
@@ -25,6 +25,12 @@ export const createTables = async (knex: Knex): Promise<void> => {
25
25
  {{#unless tenancy.any}}
26
26
  await createOutboxTables(knex, { schema: MESSAGING });
27
27
  {{/unless}}
28
+ {{#if queue.database}}
29
+ await createJobTable(knex, { schema: MESSAGING });
30
+ {{/if}}
31
+ {{#if queue.processTable}}
32
+ await createProcessTable(knex, { schema: MESSAGING });
33
+ {{/if}}
28
34
  {{#if audit.on}}
29
35
  await createAuditTables(knex, { schema: AUDIT_SCHEMA });
30
36
  {{/if}}
@@ -3,6 +3,9 @@ import type { Access } from '@ddd-ts-kit/auth';
3
3
  import type {
4
4
  ActorContext,
5
5
  Cache,
6
+ {{#if httpCache.varnish}}
7
+ CacheInvalidation,
8
+ {{/if}}
6
9
  Clock,
7
10
  DomainEventDispatcher,
8
11
  {{#if errors.sentry}}
@@ -69,6 +72,10 @@ export interface Platform {
69
72
  readonly errors: ErrorReporter;
70
73
  {{/if}}
71
74
  readonly cache: Cache;
75
+ {{#if httpCache.varnish}}
76
+ /** What a before-commit handler asks to purge from Varnish: the purge runs after the commit, through the outbox. */
77
+ readonly cacheInvalidation: CacheInvalidation;
78
+ {{/if}}
72
79
  {{#if cache.rateLimit}}
73
80
  readonly rateLimiter: RateLimiter;
74
81
  {{/if}}
@@ -21,6 +21,9 @@ import {
21
21
  Lock,
22
22
  Metrics,
23
23
  ProcessedEventStore,
24
+ {{#if queue.processTable}}
25
+ ProcessStore,
26
+ {{/if}}
24
27
  RateLimiter,
25
28
  UnitOfWork,
26
29
  {{#if errors.sentry}}
@@ -35,19 +38,33 @@ import {
35
38
  Lock,
36
39
  Metrics,
37
40
  ProcessedEventStore,
41
+ {{#if queue.processTable}}
42
+ ProcessStore,
43
+ {{/if}}
38
44
  RateLimiter,
39
45
  UnitOfWork,
40
46
  type ErrorReporter,
41
47
  } from '@ddd-ts-kit/kernel';
42
48
  {{/if}}
43
49
  {{#unless errors.sentry}}
44
- import { Cache, Lock, Metrics, ProcessedEventStore, RateLimiter, UnitOfWork } from '@ddd-ts-kit/kernel';
50
+ import { Cache, Lock, Metrics, ProcessedEventStore, {{#if queue.processTable}}ProcessStore, {{/if}}RateLimiter, UnitOfWork } from '@ddd-ts-kit/kernel';
45
51
  {{/unless}}
46
52
  {{/unless}}
47
53
  {{/if}}
48
54
  {{#unless cache.redis}}
49
55
  import { {{#if broker.external}}EventSubscribers, {{/if}}ProcessedEventStore, UnitOfWork{{#if errors.sentry}}, type ErrorReporter{{/if}} } from '@ddd-ts-kit/kernel';
50
56
  {{/unless}}
57
+ {{#unless cache.redis}}
58
+ {{#if queue.processTable}}
59
+ import { ProcessStore } from '@ddd-ts-kit/kernel';
60
+ {{/if}}
61
+ {{/unless}}
62
+ {{#if queue.redis}}
63
+ import { Logger } from '@ddd-ts-kit/kernel';
64
+ {{/if}}
65
+ {{#if queue.stored}}
66
+ import { JobStore } from '@ddd-ts-kit/scheduling';
67
+ {{/if}}
51
68
  {{#if persistence.packagedToken}}
52
69
  import { {{persistence.token}} } from '{{persistence.tokenPackage}}';
53
70
  {{/if}}
@@ -88,7 +105,16 @@ export interface PlatformOptions {
88
105
  readonly errors?: ErrorReporter;
89
106
  {{/if}}
90
107
  {{#if cache.redis}}
108
+ {{#if queue.redis}}
109
+ /**
110
+ * The Redis protocol server, which `main.ts` and the worker always give; left out (the tools,
111
+ * the tests), the cache, the lock, the limiter and the background jobs stay in the memory of
112
+ * the process, whose jobs only this process runs.
113
+ */
114
+ {{/if}}
115
+ {{#unless queue.redis}}
91
116
  /** The Redis protocol server; left out, the cache, the lock and the limiter stay in the memory of the process. */
117
+ {{/unless}}
92
118
  readonly redis?: RedisServices;
93
119
  {{/if}}
94
120
  }
@@ -111,6 +137,12 @@ export function platformModule(persistence: Persistence, options: PlatformOption
111
137
  {{#if events.outbox}}
112
138
  builder.bind(OutboxStore).toValue(persistence.outbox);
113
139
  {{/if}}
140
+ {{#if queue.database}}
141
+ builder.rebind(JobStore).toValue(persistence.jobs);
142
+ {{/if}}
143
+ {{#if queue.processTable}}
144
+ builder.rebind(ProcessStore).toValue(persistence.processes);
145
+ {{/if}}
114
146
  {{#if broker.external}}
115
147
  builder.rebind(EventSubscribers).toValue({ forContext: (name) => options.events.forConsumer(name) });
116
148
  {{/if}}
@@ -122,7 +154,7 @@ export function platformModule(persistence: Persistence, options: PlatformOption
122
154
  {{#if cache.redis}}
123
155
 
124
156
  if (options.redis !== undefined) {
125
- bindRedis(builder, options.redis);
157
+ bindRedis(builder, options.redis{{#if queue.redis}}{{#if errors.sentry}}, options.errors{{/if}}{{/if}});
126
158
  }
127
159
  {{/if}}
128
160
  {{#if style.declared}}
@@ -137,10 +169,18 @@ export function platformModule(persistence: Persistence, options: PlatformOption
137
169
  }
138
170
  {{#if cache.redis}}
139
171
 
172
+ {{#if queue.redis}}
173
+ /** One server for the cache, the limiter in front of HTTP, the lock of the scheduled jobs and the background jobs. */
174
+ {{/if}}
175
+ {{#unless queue.redis}}
140
176
  /** One server for the cache, the limiter in front of HTTP and the lock that keeps a scheduled job to one instance. */
141
- function bindRedis(builder: ModuleBuilder, redis: RedisServices): void {
177
+ {{/unless}}
178
+ function bindRedis(builder: ModuleBuilder, redis: RedisServices{{#if queue.redis}}{{#if errors.sentry}}, errors?: ErrorReporter{{/if}}{{/if}}): void {
142
179
  builder.rebind(Cache).toFactory((resolve) => redis.cache(resolve(Metrics)));
143
180
  builder.rebind(RateLimiter).toValue(redis.rateLimiter);
144
181
  builder.rebind(Lock).toValue(redis.lock);
182
+ {{#if queue.redis}}
183
+ builder.rebind(JobStore).toFactory((resolve) => redis.jobs(resolve(Logger){{#if errors.sentry}}, errors{{/if}}));
184
+ {{/if}}
145
185
  }
146
186
  {{/if}}