ddd-ts-kit 0.10.0 → 0.11.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.
- package/README.md +5 -1
- package/dist/check/canonical/roles.d.ts.map +1 -1
- package/dist/check/canonical/roles.js +18 -0
- package/dist/check/canonical/roles.js.map +1 -1
- package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
- package/dist/check/catalogue/architecture-rules.js +4 -0
- package/dist/check/catalogue/architecture-rules.js.map +1 -1
- package/dist/check/explain/lifecycle-docs.d.ts +3 -0
- package/dist/check/explain/lifecycle-docs.d.ts.map +1 -0
- package/dist/check/explain/lifecycle-docs.js +33 -0
- package/dist/check/explain/lifecycle-docs.js.map +1 -0
- package/dist/check/explain/rule-docs.d.ts.map +1 -1
- package/dist/check/explain/rule-docs.js +2 -0
- package/dist/check/explain/rule-docs.js.map +1 -1
- package/dist/check/fixtures/fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/fixtures.js +2 -0
- package/dist/check/fixtures/fixtures.js.map +1 -1
- package/dist/check/fixtures/lifecycle-fixtures.d.ts +3 -0
- package/dist/check/fixtures/lifecycle-fixtures.d.ts.map +1 -0
- package/dist/check/fixtures/lifecycle-fixtures.js +90 -0
- package/dist/check/fixtures/lifecycle-fixtures.js.map +1 -0
- package/dist/check/lifecycle/is-aggregate-file.d.ts +4 -0
- package/dist/check/lifecycle/is-aggregate-file.d.ts.map +1 -0
- package/dist/check/lifecycle/is-aggregate-file.js +6 -0
- package/dist/check/lifecycle/is-aggregate-file.js.map +1 -0
- package/dist/check/lifecycle/machines-imported.d.ts +4 -0
- package/dist/check/lifecycle/machines-imported.d.ts.map +1 -0
- package/dist/check/lifecycle/machines-imported.js +11 -0
- package/dist/check/lifecycle/machines-imported.js.map +1 -0
- package/dist/check/lifecycle/shorthand-status-writes.d.ts +7 -0
- package/dist/check/lifecycle/shorthand-status-writes.d.ts.map +1 -0
- package/dist/check/lifecycle/shorthand-status-writes.js +34 -0
- package/dist/check/lifecycle/shorthand-status-writes.js.map +1 -0
- package/dist/check/lifecycle/status-writes.d.ts +14 -0
- package/dist/check/lifecycle/status-writes.d.ts.map +1 -0
- package/dist/check/lifecycle/status-writes.js +29 -0
- package/dist/check/lifecycle/status-writes.js.map +1 -0
- package/dist/check/rules/lifecycle-status-through-machine.d.ts +3 -0
- package/dist/check/rules/lifecycle-status-through-machine.d.ts.map +1 -0
- package/dist/check/rules/lifecycle-status-through-machine.js +55 -0
- package/dist/check/rules/lifecycle-status-through-machine.js.map +1 -0
- package/dist/check/rules/process-sends-commands-only.d.ts +3 -0
- package/dist/check/rules/process-sends-commands-only.d.ts.map +1 -0
- package/dist/check/rules/process-sends-commands-only.js +39 -0
- package/dist/check/rules/process-sends-commands-only.js.map +1 -0
- package/dist/commands/generate.js +2 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +1 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/parse-stack.d.ts.map +1 -1
- package/dist/config/parse-stack.js +2 -1
- package/dist/config/parse-stack.js.map +1 -1
- package/dist/config/stack.d.ts +10 -0
- package/dist/config/stack.d.ts.map +1 -1
- package/dist/config/stack.js +1 -0
- package/dist/config/stack.js.map +1 -1
- package/dist/declared/declared-role.d.ts.map +1 -1
- package/dist/declared/declared-role.js +1 -0
- package/dist/declared/declared-role.js.map +1 -1
- package/dist/describe/context-description.d.ts +6 -0
- package/dist/describe/context-description.d.ts.map +1 -1
- package/dist/describe/describe-context.d.ts.map +1 -1
- package/dist/describe/describe-context.js +3 -0
- package/dist/describe/describe-context.js.map +1 -1
- package/dist/describe/format-description.d.ts.map +1 -1
- package/dist/describe/format-description.js +13 -1
- package/dist/describe/format-description.js.map +1 -1
- package/dist/docs/background-job-facts.d.ts +7 -0
- package/dist/docs/background-job-facts.d.ts.map +1 -0
- package/dist/docs/background-job-facts.js +2 -0
- package/dist/docs/background-job-facts.js.map +1 -0
- package/dist/docs/context-facts.d.ts +9 -0
- package/dist/docs/context-facts.d.ts.map +1 -1
- package/dist/docs/object-properties.d.ts +11 -0
- package/dist/docs/object-properties.d.ts.map +1 -0
- package/dist/docs/object-properties.js +21 -0
- package/dist/docs/object-properties.js.map +1 -0
- package/dist/docs/process-facts.d.ts +8 -0
- package/dist/docs/process-facts.d.ts.map +1 -0
- package/dist/docs/process-facts.js +2 -0
- package/dist/docs/process-facts.js.map +1 -0
- package/dist/docs/read-background-jobs.d.ts +5 -0
- package/dist/docs/read-background-jobs.d.ts.map +1 -0
- package/dist/docs/read-background-jobs.js +16 -0
- package/dist/docs/read-background-jobs.js.map +1 -0
- package/dist/docs/read-context.d.ts.map +1 -1
- package/dist/docs/read-context.js +6 -0
- package/dist/docs/read-context.js.map +1 -1
- package/dist/docs/read-processes.d.ts +5 -0
- package/dist/docs/read-processes.d.ts.map +1 -0
- package/dist/docs/read-processes.js +22 -0
- package/dist/docs/read-processes.js.map +1 -0
- package/dist/docs/read-state-machines.d.ts +10 -0
- package/dist/docs/read-state-machines.d.ts.map +1 -0
- package/dist/docs/read-state-machines.js +81 -0
- package/dist/docs/read-state-machines.js.map +1 -0
- package/dist/docs/read-vocabularies.d.ts +4 -0
- package/dist/docs/read-vocabularies.d.ts.map +1 -0
- package/dist/docs/read-vocabularies.js +14 -0
- package/dist/docs/read-vocabularies.js.map +1 -0
- package/dist/docs/refresh-context-doc.d.ts +1 -1
- package/dist/docs/refresh-context-doc.d.ts.map +1 -1
- package/dist/docs/refresh-context-doc.js +32 -3
- package/dist/docs/refresh-context-doc.js.map +1 -1
- package/dist/docs/state-machine-facts.d.ts +18 -0
- package/dist/docs/state-machine-facts.d.ts.map +1 -0
- package/dist/docs/state-machine-facts.js +2 -0
- package/dist/docs/state-machine-facts.js.map +1 -0
- package/dist/docs/state-machine-lines.d.ts +8 -0
- package/dist/docs/state-machine-lines.d.ts.map +1 -0
- package/dist/docs/state-machine-lines.js +32 -0
- package/dist/docs/state-machine-lines.js.map +1 -0
- package/dist/generate/kind.d.ts +2 -0
- package/dist/generate/kind.d.ts.map +1 -1
- package/dist/generate/kinds/background/background-job-vars.d.ts +7 -0
- package/dist/generate/kinds/background/background-job-vars.d.ts.map +1 -0
- package/dist/generate/kinds/background/background-job-vars.js +29 -0
- package/dist/generate/kinds/background/background-job-vars.js.map +1 -0
- package/dist/generate/kinds/background/job-import.d.ts +8 -0
- package/dist/generate/kinds/background/job-import.d.ts.map +1 -0
- package/dist/generate/kinds/background/job-import.js +17 -0
- package/dist/generate/kinds/background/job-import.js.map +1 -0
- package/dist/generate/kinds/background/payload-field.d.ts +18 -0
- package/dist/generate/kinds/background/payload-field.d.ts.map +1 -0
- package/dist/generate/kinds/background/payload-field.js +52 -0
- package/dist/generate/kinds/background/payload-field.js.map +1 -0
- package/dist/generate/kinds/background/require-container.d.ts +7 -0
- package/dist/generate/kinds/background/require-container.d.ts.map +1 -0
- package/dist/generate/kinds/background/require-container.js +13 -0
- package/dist/generate/kinds/background/require-container.js.map +1 -0
- package/dist/generate/kinds/background-job-kind.d.ts +3 -0
- package/dist/generate/kinds/background-job-kind.d.ts.map +1 -0
- package/dist/generate/kinds/background-job-kind.js +49 -0
- package/dist/generate/kinds/background-job-kind.js.map +1 -0
- package/dist/generate/kinds/job/command-input.d.ts +11 -0
- package/dist/generate/kinds/job/command-input.d.ts.map +1 -0
- package/dist/generate/kinds/job/command-input.js +13 -0
- package/dist/generate/kinds/job/command-input.js.map +1 -0
- package/dist/generate/kinds/job/granted-in-spec.d.ts +6 -0
- package/dist/generate/kinds/job/granted-in-spec.d.ts.map +1 -0
- package/dist/generate/kinds/job/granted-in-spec.js +18 -0
- package/dist/generate/kinds/job/granted-in-spec.js.map +1 -0
- package/dist/generate/kinds/job/job-vars.d.ts.map +1 -1
- package/dist/generate/kinds/job/job-vars.js +1 -17
- package/dist/generate/kinds/job/job-vars.js.map +1 -1
- package/dist/generate/kinds/job/read-sent-command.d.ts +8 -2
- package/dist/generate/kinds/job/read-sent-command.d.ts.map +1 -1
- package/dist/generate/kinds/job/read-sent-command.js +18 -12
- package/dist/generate/kinds/job/read-sent-command.js.map +1 -1
- package/dist/generate/kinds/job/sent-command.d.ts +4 -1
- package/dist/generate/kinds/job/sent-command.d.ts.map +1 -1
- package/dist/generate/kinds/process-kind.d.ts +3 -0
- package/dist/generate/kinds/process-kind.d.ts.map +1 -0
- package/dist/generate/kinds/process-kind.js +39 -0
- package/dist/generate/kinds/process-kind.js.map +1 -0
- package/dist/generate/kinds/state-machine/parse-transitions.d.ts +4 -0
- package/dist/generate/kinds/state-machine/parse-transitions.d.ts.map +1 -0
- package/dist/generate/kinds/state-machine/parse-transitions.js +24 -0
- package/dist/generate/kinds/state-machine/parse-transitions.js.map +1 -0
- package/dist/generate/kinds/state-machine/requested-transition.d.ts +9 -0
- package/dist/generate/kinds/state-machine/requested-transition.d.ts.map +1 -0
- package/dist/generate/kinds/state-machine/requested-transition.js +2 -0
- package/dist/generate/kinds/state-machine/requested-transition.js.map +1 -0
- package/dist/generate/kinds/state-machine/state-machine-vars.d.ts +12 -0
- package/dist/generate/kinds/state-machine/state-machine-vars.d.ts.map +1 -0
- package/dist/generate/kinds/state-machine/state-machine-vars.js +44 -0
- package/dist/generate/kinds/state-machine/state-machine-vars.js.map +1 -0
- package/dist/generate/kinds/state-machine/status-vocabulary.d.ts +9 -0
- package/dist/generate/kinds/state-machine/status-vocabulary.d.ts.map +1 -0
- package/dist/generate/kinds/state-machine/status-vocabulary.js +26 -0
- package/dist/generate/kinds/state-machine/status-vocabulary.js.map +1 -0
- package/dist/generate/kinds/state-machine-kind.d.ts +3 -0
- package/dist/generate/kinds/state-machine-kind.d.ts.map +1 -0
- package/dist/generate/kinds/state-machine-kind.js +33 -0
- package/dist/generate/kinds/state-machine-kind.js.map +1 -0
- package/dist/generate/kinds.d.ts.map +1 -1
- package/dist/generate/kinds.js +6 -0
- package/dist/generate/kinds.js.map +1 -1
- package/dist/generate/vocabulary/held-entries.d.ts +4 -0
- package/dist/generate/vocabulary/held-entries.d.ts.map +1 -0
- package/dist/generate/vocabulary/held-entries.js +6 -0
- package/dist/generate/vocabulary/held-entries.js.map +1 -0
- package/dist/generate/vocabulary/vocabulary-text.d.ts.map +1 -1
- package/dist/generate/vocabulary/vocabulary-text.js +2 -2
- package/dist/generate/vocabulary/vocabulary-text.js.map +1 -1
- package/dist/help/usage.d.ts +1 -1
- package/dist/help/usage.d.ts.map +1 -1
- package/dist/help/usage.js +1 -1
- package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
- package/dist/init/manifest/dependencies-for.js +2 -0
- package/dist/init/manifest/dependencies-for.js.map +1 -1
- package/dist/init/manifest/versions.js +24 -24
- package/dist/init/stack/resolve-queue.d.ts +13 -0
- package/dist/init/stack/resolve-queue.d.ts.map +1 -0
- package/dist/init/stack/resolve-queue.js +25 -0
- package/dist/init/stack/resolve-queue.js.map +1 -0
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +2 -0
- package/dist/init/stack/resolve-stack.js.map +1 -1
- package/dist/init/stack/stack-options.d.ts +2 -0
- package/dist/init/stack/stack-options.d.ts.map +1 -1
- package/dist/stack/stack-vars.d.ts.map +1 -1
- package/dist/stack/stack-vars.js +13 -0
- package/dist/stack/stack-vars.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/templates/background-job/background-job.declared.ts.tpl +26 -0
- package/templates/background-job/background-job.spec.ts.tpl +63 -0
- package/templates/background-job/background-job.ts.tpl +24 -0
- package/templates/background-job/wiring.tsyringe.tpl +5 -0
- package/templates/context/CONTEXT.md.tpl +15 -0
- package/templates/init/platform/database/persistence-over.drizzle.ts.tpl +20 -1
- package/templates/init/platform/database/persistence-over.knex.ts.tpl +18 -1
- package/templates/init/platform/database/persistence.orm.ts.tpl +12 -1
- package/templates/init/platform/database/schema.drizzle.ts.tpl +12 -2
- package/templates/init/platform/database/schema.knex.ts.tpl +7 -1
- package/templates/init/platform/platform.module.tsyringe.ts.tpl +43 -3
- package/templates/init/platform/redis/open-redis.ts.tpl +37 -1
- package/templates/init/rules/application.md.tpl +3 -2
- package/templates/init/rules/domain.md.tpl +1 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/process/process.spec.ts.tpl +44 -0
- package/templates/process/process.ts.tpl +41 -0
- package/templates/process/timeout-job.declared.ts.tpl +18 -0
- package/templates/process/timeout-job.spec.ts.tpl +43 -0
- package/templates/process/timeout-job.ts.tpl +16 -0
- package/templates/process/timeout-job.wiring.tsyringe.tpl +5 -0
- package/templates/state-machine/state-machine.spec.ts.tpl +16 -0
- package/templates/state-machine/state-machine.ts.tpl +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ddd-ts-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Bootstrap, scaffold and verify DDD and Clean Architecture TypeScript projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"clean:packages": "node dist/bin.js check --clean-only ../kernel/src ../validation/src ../http/src ../tracing/src ../di/src ../events/src ../testing/src ../s3/src ../drizzle/src ../knex/src ../prisma/src ../typeorm/src ../aspects/src ../rabbitmq/src ../auth/src ../audit/src ../redis/src ../scheduling/src ../pino/src ../winston/src ../sentry/src ../kafka/src ../nats/src ../eslint-plugin/src"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@ddd-ts-kit/kernel": "^0.
|
|
32
|
+
"@ddd-ts-kit/kernel": "^0.11.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BackgroundJob, BackgroundJobExecution, CommandBus } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { Background } from '@ddd-ts-kit/kernel/declarations';
|
|
3
|
+
import { {{job.command}}Command } from '{{alias.context}}/application/commands/{{job.commandKebab}}/{{job.commandKebab}}.command{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
{{#if job.hasPayload}}
|
|
6
|
+
/** What "{{name.words}}" works on, as plain JSON: a date travels as its ISO text. */
|
|
7
|
+
export interface {{name.pascal}}Payload {
|
|
8
|
+
{{job.payloadFields}}
|
|
9
|
+
}
|
|
10
|
+
{{/if}}
|
|
11
|
+
{{#unless job.hasPayload}}
|
|
12
|
+
// TODO(domain): declare what "{{name.words}}" works on (identifiers, a period, never an aggregate), as plain JSON: a date travels as its ISO text.
|
|
13
|
+
export type {{name.pascal}}Payload = Readonly<Record<string, never>>;
|
|
14
|
+
{{/unless}}
|
|
15
|
+
|
|
16
|
+
@Background()
|
|
17
|
+
export class {{name.pascal}}BackgroundJob implements BackgroundJob<{{name.pascal}}Payload> {
|
|
18
|
+
static readonly jobName = '{{job.name}}';
|
|
19
|
+
|
|
20
|
+
constructor(private readonly commands: CommandBus) {}
|
|
21
|
+
|
|
22
|
+
async run(payload: {{name.pascal}}Payload, execution: BackgroundJobExecution): Promise<void> {
|
|
23
|
+
// TODO(domain): {{job.todo}}
|
|
24
|
+
await this.commands.execute(new {{job.command}}Command({{job.arguments}}));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, expect, it } from '{{tests.module}}';
|
|
2
|
+
import { RoleBasedAuthorizer } from '@ddd-ts-kit/auth';
|
|
3
|
+
import { authorizationModule } from '@ddd-ts-kit/auth/di';
|
|
4
|
+
{{spec.diPlain}}
|
|
5
|
+
{{spec.contextImports}}
|
|
6
|
+
import type { Actor, Message } from '@ddd-ts-kit/kernel';
|
|
7
|
+
import { platformTestModule } from '{{alias.platform}}/platform-test.module{{alias.ext}}';
|
|
8
|
+
{{job.permissionsImport}}
|
|
9
|
+
import { {{job.command}}Command } from '{{alias.context}}/application/commands/{{job.commandKebab}}/{{job.commandKebab}}.command{{alias.ext}}';
|
|
10
|
+
{{job.specImport}}
|
|
11
|
+
|
|
12
|
+
const clerk: Actor = { id: 'clerk-1', type: 'user', roles: ['clerk'], attributes: {} };
|
|
13
|
+
|
|
14
|
+
const authorization = authorizationModule({
|
|
15
|
+
authorizer: new RoleBasedAuthorizer({ roles: { clerk: [{{job.granted}}] } }),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('{{name.title}}, once enqueued', () => {
|
|
19
|
+
it('sends {{job.commandWords}}{{job.asActor}}', async () => {
|
|
20
|
+
const { application, sent } = {{spec.await}}arrange();
|
|
21
|
+
|
|
22
|
+
{{#if job.hasPayload}}
|
|
23
|
+
const payload: {{name.pascal}}Payload = {
|
|
24
|
+
{{job.payloadSample}}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
await application.as(clerk, () => application.jobQueue.enqueue({{name.pascal}}BackgroundJob, payload));
|
|
28
|
+
{{/if}}
|
|
29
|
+
{{#unless job.hasPayload}}
|
|
30
|
+
await application.as(clerk, () => application.jobQueue.enqueue({{name.pascal}}BackgroundJob, {}));
|
|
31
|
+
{{/unless}}
|
|
32
|
+
|
|
33
|
+
expect(await application.backgroundJobs.runDue()).toMatchObject([{ job: '{{job.name}}', outcome: 'succeeded' }]);
|
|
34
|
+
|
|
35
|
+
expect(sent).toHaveLength(1);
|
|
36
|
+
expect(sent[0]).toBeInstanceOf({{job.command}}Command);
|
|
37
|
+
{{#if job.protected}}
|
|
38
|
+
expect(sent[0]).toMatchObject({ actor: { id: 'clerk-1' } });
|
|
39
|
+
{{/if}}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// TODO(domain): replace each entry below by a test of what "{{name.words}}" asks of the use case: a run may be a retry, and a long one resumes from its checkpoint.
|
|
43
|
+
it.todo('has the same outcome when the same job runs twice');
|
|
44
|
+
it.todo('resumes from its checkpoint after an interrupted attempt');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
{{spec.async}}function arrange() {
|
|
48
|
+
{{#if spec.assembles}}
|
|
49
|
+
const context = {{spec.context}};
|
|
50
|
+
|
|
51
|
+
{{/if}}
|
|
52
|
+
const application = createTestApplication({
|
|
53
|
+
modules: [{{spec.modules}}],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const sent: Message[] = [];
|
|
57
|
+
|
|
58
|
+
application.commandBus.use(async (message) => {
|
|
59
|
+
sent.push(message);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return { application, sent };
|
|
63
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BackgroundJob, BackgroundJobExecution, CommandBus } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { {{job.command}}Command } from '{{alias.context}}/application/commands/{{job.commandKebab}}/{{job.commandKebab}}.command{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
{{#if job.hasPayload}}
|
|
5
|
+
/** What "{{name.words}}" works on, as plain JSON: a date travels as its ISO text. */
|
|
6
|
+
export interface {{name.pascal}}Payload {
|
|
7
|
+
{{job.payloadFields}}
|
|
8
|
+
}
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#unless job.hasPayload}}
|
|
11
|
+
// TODO(domain): declare what "{{name.words}}" works on (identifiers, a period, never an aggregate), as plain JSON: a date travels as its ISO text.
|
|
12
|
+
export type {{name.pascal}}Payload = Readonly<Record<string, never>>;
|
|
13
|
+
{{/unless}}
|
|
14
|
+
|
|
15
|
+
export class {{name.pascal}}BackgroundJob implements BackgroundJob<{{name.pascal}}Payload> {
|
|
16
|
+
static readonly jobName = '{{job.name}}';
|
|
17
|
+
|
|
18
|
+
constructor(private readonly commands: CommandBus) {}
|
|
19
|
+
|
|
20
|
+
async run(payload: {{name.pascal}}Payload, execution: BackgroundJobExecution): Promise<void> {
|
|
21
|
+
// TODO(domain): {{job.todo}}
|
|
22
|
+
await this.commands.execute(new {{job.command}}Command({{job.arguments}}));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
@@imports
|
|
2
|
+
import { CommandBus } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { {{name.pascal}}BackgroundJob } from '{{alias.context}}/application/background/{{name.kebab}}.background-job{{alias.ext}}';
|
|
4
|
+
@@registrations
|
|
5
|
+
builder.backgroundJob({{name.pascal}}BackgroundJob.jobName).handledBy({{name.pascal}}BackgroundJob, [CommandBus]);
|
|
@@ -35,6 +35,21 @@ TODO(domain): say in one sentence why this context is {{doc.classification}}.
|
|
|
35
35
|
<!-- ddd-ts-kit:jobs -->
|
|
36
36
|
<!-- /ddd-ts-kit:jobs -->
|
|
37
37
|
|
|
38
|
+
## Background jobs
|
|
39
|
+
|
|
40
|
+
<!-- ddd-ts-kit:background-jobs -->
|
|
41
|
+
<!-- /ddd-ts-kit:background-jobs -->
|
|
42
|
+
|
|
43
|
+
## State machines
|
|
44
|
+
|
|
45
|
+
<!-- ddd-ts-kit:state-machines -->
|
|
46
|
+
<!-- /ddd-ts-kit:state-machines -->
|
|
47
|
+
|
|
48
|
+
## Process managers
|
|
49
|
+
|
|
50
|
+
<!-- ddd-ts-kit:processes -->
|
|
51
|
+
<!-- /ddd-ts-kit:processes -->
|
|
52
|
+
|
|
38
53
|
## Relationships
|
|
39
54
|
|
|
40
55
|
<!-- ddd-ts-kit:relationships -->
|
|
@@ -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
|
-
|
|
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}}
|
|
@@ -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
|
-
|
|
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}}
|
|
@@ -1,17 +1,39 @@
|
|
|
1
|
-
import type { Cache, Lock, Metrics, RateLimiter } from '@ddd-ts-kit/kernel';
|
|
1
|
+
import type { Cache, {{#if queue.redis}}ErrorReporter, {{/if}}Lock, {{#if queue.redis}}Logger, {{/if}}Metrics, RateLimiter } from '@ddd-ts-kit/kernel';
|
|
2
2
|
{{#if cache.relaySignal}}
|
|
3
3
|
import {
|
|
4
4
|
RedisCache,
|
|
5
|
+
{{#if queue.redis}}
|
|
6
|
+
RedisJobStore,
|
|
7
|
+
{{/if}}
|
|
5
8
|
RedisLock,
|
|
6
9
|
RedisRateLimiter,
|
|
7
10
|
RedisRelaySignal,
|
|
8
11
|
connectRedis,
|
|
9
12
|
redisHealth,
|
|
13
|
+
{{#if queue.redis}}
|
|
14
|
+
reportLostJobs,
|
|
15
|
+
{{/if}}
|
|
10
16
|
} from '@ddd-ts-kit/redis';
|
|
11
17
|
{{/if}}
|
|
12
18
|
{{#unless cache.relaySignal}}
|
|
19
|
+
{{#if queue.redis}}
|
|
20
|
+
import {
|
|
21
|
+
RedisCache,
|
|
22
|
+
RedisJobStore,
|
|
23
|
+
RedisLock,
|
|
24
|
+
RedisRateLimiter,
|
|
25
|
+
connectRedis,
|
|
26
|
+
redisHealth,
|
|
27
|
+
reportLostJobs,
|
|
28
|
+
} from '@ddd-ts-kit/redis';
|
|
29
|
+
{{/if}}
|
|
30
|
+
{{#unless queue.redis}}
|
|
13
31
|
import { RedisCache, RedisLock, RedisRateLimiter, connectRedis, redisHealth } from '@ddd-ts-kit/redis';
|
|
14
32
|
{{/unless}}
|
|
33
|
+
{{/unless}}
|
|
34
|
+
{{#if queue.redis}}
|
|
35
|
+
import type { JobStore } from '@ddd-ts-kit/scheduling';
|
|
36
|
+
{{/if}}
|
|
15
37
|
|
|
16
38
|
/**
|
|
17
39
|
* What the platform puts on one connection to a Redis protocol server. The adapters use a common
|
|
@@ -25,6 +47,13 @@ export interface RedisServices {
|
|
|
25
47
|
readonly rateLimiter: RateLimiter;
|
|
26
48
|
/** Excludes between processes: what keeps an occurrence of a scheduled job to one instance, best effort. */
|
|
27
49
|
readonly lock: Lock;
|
|
50
|
+
{{#if queue.redis}}
|
|
51
|
+
/**
|
|
52
|
+
* The background jobs: added once the command that enqueues them committed, claimed by every
|
|
53
|
+
* worker. A write lost after the commit (the server away) is logged and reported.
|
|
54
|
+
*/
|
|
55
|
+
jobs(logger: Logger, errors?: ErrorReporter): JobStore;
|
|
56
|
+
{{/if}}
|
|
28
57
|
{{#if cache.relaySignal}}
|
|
29
58
|
/** Wakes the outbox relay of every instance as soon as a command committed; the polling interval stays as the safety net. */
|
|
30
59
|
readonly relaySignal: RedisRelaySignal;
|
|
@@ -53,6 +82,13 @@ export function openRedis({ redisUrl, serviceName }: RedisSettings): RedisServic
|
|
|
53
82
|
// While the server is away the API keeps serving, without a limit: a limiter must not take the application down.
|
|
54
83
|
rateLimiter: new RedisRateLimiter(connection.client, { namespace: serviceName + ':rate', onError: 'allow' }),
|
|
55
84
|
lock: new RedisLock(connection.client, { namespace: serviceName + ':lock' }),
|
|
85
|
+
{{#if queue.redis}}
|
|
86
|
+
jobs: (logger, errors) =>
|
|
87
|
+
new RedisJobStore(connection.client, {
|
|
88
|
+
namespace: serviceName + ':jobs',
|
|
89
|
+
onLostJob: reportLostJobs(logger, errors),
|
|
90
|
+
}),
|
|
91
|
+
{{/if}}
|
|
56
92
|
{{#if cache.relaySignal}}
|
|
57
93
|
relaySignal,
|
|
58
94
|
{{/if}}
|
|
@@ -11,7 +11,7 @@ paths:
|
|
|
11
11
|
- Nothing here reads the event store: an event-sourced aggregate is loaded and saved through its repository port like any other (`event-sourcing/store-behind-repository`). A projection writes its read model and never a stream (`event-sourcing/projection-never-appends`); one fed by the store is declared `@Projection(name, { feed: 'event-store' })`.
|
|
12
12
|
{{#if style.declared}}
|
|
13
13
|
- Every command and query carries `@Requires(permission)` or `@Public()` (`authz/declared`), and the actor is in the message (`authz/actor-explicit`). Permissions live in `authorization/<context>.permissions.ts`, rules that need loaded state in `authorization/*.policy.ts`.
|
|
14
|
-
- The decorator is the registration (`declarations/role-declared`): `@CommandHandler(Message)`, `@QueryHandler(Message)`, `@DomainEventHandler(Event, { name })`, `@IntegrationEventHandler(definition, { consumer })`, `@Scheduled('<context>.<job>', schedule)`, `@Projection('<context>.<name>')`, `@Policy(permission, { name })`. Names are string literals.
|
|
14
|
+
- The decorator is the registration (`declarations/role-declared`): `@CommandHandler(Message)`, `@QueryHandler(Message)`, `@DomainEventHandler(Event, { name })`, `@IntegrationEventHandler(definition, { consumer })`, `@Scheduled('<context>.<job>', schedule)`, `@Background(options)` (the name is the static `jobName`), `@Projection('<context>.<name>')`, `@Policy(permission, { name })`. Names are string literals.
|
|
15
15
|
- The constructor is the one statement of what a class depends on (`declarations/constructor-injection`): each parameter is typed by one port class, with no `?`, default value, rest or destructuring, and no list repeats it in the decorator. To add a dependency, add the parameter: `npx ddd-ts-kit docs` reads the signature into the generated file of the context (`npm run dev` does it on every change), never edit that file.
|
|
16
16
|
{{/if}}
|
|
17
17
|
{{#if style.explicit}}
|
|
@@ -26,6 +26,7 @@ paths:
|
|
|
26
26
|
- A dependency list names port classes, imported as values, in the order of the constructor: never an adapter or a fake (`ports/value-import`, `ports/no-concrete-dependency`).
|
|
27
27
|
{{/if}}
|
|
28
28
|
- 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`).
|
|
29
|
+
- Work a use case hands to a worker is a background job (`background/*.background-job.ts`, `generate background-job ... --command <UseCase>`): enqueued through `JobQueue` in the unit of work of the command, run later as the actor that enqueued it, at least once, so it sends commands safe to repeat and a long one reports its progress and saves a checkpoint. A process that waits for events and has deadlines is a process manager (`processes/*.process.ts`, `generate process`): its steps decide from its state alone and answer commands and timeouts, never write an aggregate (`process/sends-commands-only`); an event handler runs each step through `ProcessRunner`.
|
|
29
30
|
{{#if files.any}}
|
|
30
31
|
- A file arrives in the command as a `FileUpload` of its area, which the bus stages before the transaction under a key of `FileKeys` (never a name or a path from the user) and scans; the handler records `upload.file`, its `StoredFile`, on the aggregate and calls `FileStaging.promoteOnCommit`, which moves it to its key with the commit. A direct upload is confirmed from the `PendingUpload` the aggregate kept, never from a key the client sends. The ports are named here, never a connector (`files/port-not-connector`); `npx ddd-ts-kit generate file-upload` writes the slice.
|
|
31
32
|
{{/if}}
|
|
@@ -35,4 +36,4 @@ paths:
|
|
|
35
36
|
- 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`).
|
|
36
37
|
{{/if}}
|
|
37
38
|
- 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`).
|
|
38
|
-
- 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.
|
|
39
|
+
- A whole feature with `/ddd-ts-kit:use-case`. Create with `npx ddd-ts-kit generate command|query|port|policy|job|background-job|process|event-handler|integration-handler ... --json`, then fill the `TODO(domain)` places.
|
|
@@ -9,6 +9,7 @@ paths:
|
|
|
9
9
|
- Imports only its own `domain/`, the shared kernel and `@ddd-ts-kit/kernel` (`layer/domain-purity`): no framework, no decorator, no validation library, no `node:` module.
|
|
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
|
+
- A status that moves through a lifecycle is declared once as a state machine, `state-machines/<aggregate>.state-machine.ts` (`generate state-machine <context> <Aggregate> --value .. --transition ..`): the aggregate writes its status only from `machine.next(..)` or `machine.start(..)` (`lifecycle/status-through-machine`), and a forbidden transition is refused by a static factory of its error class (`refused`).
|
|
12
13
|
- 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
14
|
{{#if literals.named}}
|
|
14
15
|
- 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`).
|
|
@@ -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.
|
|
26
|
+
"@ddd-ts-kit/eslint-plugin": "^0.11.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",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it } from '{{tests.module}}';
|
|
2
|
+
import { givenProcess } from '@ddd-ts-kit/testing';
|
|
3
|
+
import { {{name.pascal}}Process } from '{{alias.context}}/application/processes/{{name.kebab}}.process{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
const deadline = new Date('2026-03-01T12:00:00.000Z');
|
|
6
|
+
const process = new {{name.pascal}}Process();
|
|
7
|
+
const waiting = { id: '{{name.kebab}}-1', deadline: deadline.toISOString() };
|
|
8
|
+
|
|
9
|
+
describe('{{name.title}}', () => {
|
|
10
|
+
it('starts and waits until its deadline', () => {
|
|
11
|
+
givenProcess<typeof waiting>(undefined)
|
|
12
|
+
.when((current) => process.started('{{name.kebab}}-1', deadline, current))
|
|
13
|
+
.thenState(waiting)
|
|
14
|
+
.thenTimeouts([{ name: 'deadline', at: deadline }])
|
|
15
|
+
.thenCommands([]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('does not start twice', () => {
|
|
19
|
+
givenProcess(waiting)
|
|
20
|
+
.when((current) => process.started('{{name.kebab}}-1', deadline, current))
|
|
21
|
+
.thenIgnored();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('ends in time and disarms its deadline', () => {
|
|
25
|
+
givenProcess(waiting)
|
|
26
|
+
.when((current) => process.completed(current))
|
|
27
|
+
.thenCancelled(['deadline'])
|
|
28
|
+
.thenEnded();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('ends at its deadline', () => {
|
|
32
|
+
givenProcess(waiting)
|
|
33
|
+
.when((current) => (current === undefined ? undefined : process.timedOut('deadline', current)))
|
|
34
|
+
.thenEnded();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('recognises the state it saved', () => {
|
|
38
|
+
expect({{name.pascal}}Process.isState(waiting)).toBe(true);
|
|
39
|
+
expect({{name.pascal}}Process.isState({ id: 'unknown-1' })).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// TODO(domain): one case per step, and the commands a missed deadline sends.
|
|
43
|
+
it.todo('sends the command that answers a missed deadline');
|
|
44
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ProcessDecision, ProcessManager } from '@ddd-ts-kit/kernel';
|
|
2
|
+
|
|
3
|
+
export interface {{name.pascal}}State {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly deadline: string;
|
|
6
|
+
// TODO(domain): add what the next steps decide from, identifiers and values, never an aggregate.
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const DEADLINE = 'deadline';
|
|
10
|
+
|
|
11
|
+
export class {{name.pascal}}Process implements ProcessManager<{{name.pascal}}State> {
|
|
12
|
+
static readonly processName = '{{process.name}}';
|
|
13
|
+
|
|
14
|
+
static readonly timeoutJob = '{{process.timeoutJob}}';
|
|
15
|
+
|
|
16
|
+
static isState(value: unknown): value is {{name.pascal}}State {
|
|
17
|
+
return typeof value === 'object' && value !== null && 'id' in value && 'deadline' in value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// TODO(domain): take the event that starts the process (`ddd-ts-kit generate event-handler {{context.kebab}} <Aggregate> <Event>`, whose handler calls this step).
|
|
21
|
+
started(id: string, deadline: Date, current: {{name.pascal}}State | undefined): ProcessDecision<{{name.pascal}}State> | undefined {
|
|
22
|
+
if (current !== undefined) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { state: { id, deadline: deadline.toISOString() }, timeouts: [{ name: DEADLINE, at: deadline }] };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
completed(current: {{name.pascal}}State | undefined): ProcessDecision<{{name.pascal}}State> | undefined {
|
|
30
|
+
return current === undefined ? undefined : { state: current, cancel: [DEADLINE], ended: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
timedOut(name: string, current: {{name.pascal}}State): ProcessDecision<{{name.pascal}}State> | undefined {
|
|
34
|
+
if (name !== DEADLINE) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// TODO(domain): send the command that answers a missed deadline, as the process: `commands: [new <UseCase>Command(systemActor({{name.pascal}}Process.processName), ...)]`.
|
|
39
|
+
return { state: current, ended: true };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BackgroundJob, BackgroundJobExecution, ProcessRunner, ProcessTimeoutDue } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { Background } from '@ddd-ts-kit/kernel/declarations';
|
|
3
|
+
import { {{name.pascal}}Process } from '{{alias.context}}/application/processes/{{name.kebab}}.process{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
@Background()
|
|
6
|
+
export class {{name.pascal}}TimeoutBackgroundJob implements BackgroundJob<ProcessTimeoutDue> {
|
|
7
|
+
static readonly jobName = '{{process.timeoutJob}}';
|
|
8
|
+
|
|
9
|
+
private readonly process = new {{name.pascal}}Process();
|
|
10
|
+
|
|
11
|
+
constructor(private readonly processes: ProcessRunner) {}
|
|
12
|
+
|
|
13
|
+
async run(due: ProcessTimeoutDue, execution: BackgroundJobExecution): Promise<void> {
|
|
14
|
+
const delivered = { ...due, jobId: execution.jobId };
|
|
15
|
+
|
|
16
|
+
await this.processes.timeout({{name.pascal}}Process, delivered, (current) => this.process.timedOut(due.timeout, current));
|
|
17
|
+
}
|
|
18
|
+
}
|