ddd-ts-kit 0.92.0 → 0.94.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/CHANGELOG.md +90 -0
- package/README.fr.md +13 -8
- package/README.md +10 -6
- package/dist/acceptance/check-locked-files.d.ts +25 -0
- package/dist/acceptance/check-locked-files.d.ts.map +1 -0
- package/dist/acceptance/check-locked-files.js +84 -0
- package/dist/acceptance/check-locked-files.js.map +1 -0
- package/dist/acceptance/scenarios-in.d.ts +4 -0
- package/dist/acceptance/scenarios-in.d.ts.map +1 -1
- package/dist/acceptance/scenarios-in.js +2 -2
- package/dist/acceptance/scenarios-in.js.map +1 -1
- package/dist/check/authz/modelled-permissions.d.ts +32 -0
- package/dist/check/authz/modelled-permissions.d.ts.map +1 -0
- package/dist/check/authz/modelled-permissions.js +169 -0
- package/dist/check/authz/modelled-permissions.js.map +1 -0
- 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/authz-docs.d.ts.map +1 -1
- package/dist/check/explain/authz-docs.js +17 -0
- package/dist/check/explain/authz-docs.js.map +1 -1
- package/dist/check/explain/scheduling-docs.d.ts.map +1 -1
- package/dist/check/explain/scheduling-docs.js +7 -0
- package/dist/check/explain/scheduling-docs.js.map +1 -1
- package/dist/check/fixtures/authz-resource-modelled-fixtures.d.ts +3 -0
- package/dist/check/fixtures/authz-resource-modelled-fixtures.d.ts.map +1 -0
- package/dist/check/fixtures/authz-resource-modelled-fixtures.js +194 -0
- package/dist/check/fixtures/authz-resource-modelled-fixtures.js.map +1 -0
- 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/scheduling-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/scheduling-fixtures.js +69 -1
- package/dist/check/fixtures/scheduling-fixtures.js.map +1 -1
- package/dist/check/rules/authz-resource-modelled.d.ts +13 -0
- package/dist/check/rules/authz-resource-modelled.d.ts.map +1 -0
- package/dist/check/rules/authz-resource-modelled.js +128 -0
- package/dist/check/rules/authz-resource-modelled.js.map +1 -0
- package/dist/check/rules/scheduling-tenancy-declared.d.ts +3 -0
- package/dist/check/rules/scheduling-tenancy-declared.d.ts.map +1 -0
- package/dist/check/rules/scheduling-tenancy-declared.js +45 -0
- package/dist/check/rules/scheduling-tenancy-declared.js.map +1 -0
- package/dist/check/scheduling/job-names.d.ts +1 -1
- package/dist/check/scheduling/job-names.d.ts.map +1 -1
- package/dist/check/scheduling/job-names.js +3 -21
- package/dist/check/scheduling/job-names.js.map +1 -1
- package/dist/check/scheduling/jobs-declared.d.ts +11 -0
- package/dist/check/scheduling/jobs-declared.d.ts.map +1 -0
- package/dist/check/scheduling/jobs-declared.js +24 -0
- package/dist/check/scheduling/jobs-declared.js.map +1 -0
- package/dist/commands/acceptance.d.ts.map +1 -1
- package/dist/commands/acceptance.js +14 -0
- package/dist/commands/acceptance.js.map +1 -1
- package/dist/commands/generate.js +2 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/commit/run-git.d.ts +5 -1
- package/dist/commit/run-git.d.ts.map +1 -1
- package/dist/commit/run-git.js +19 -2
- package/dist/commit/run-git.js.map +1 -1
- package/dist/controllers/finish-migration.js +4 -2
- package/dist/controllers/finish-migration.js.map +1 -1
- package/dist/docs/behaviour-page.d.ts.map +1 -1
- package/dist/docs/behaviour-page.js +9 -1
- package/dist/docs/behaviour-page.js.map +1 -1
- package/dist/generate/access-vars.js +18 -0
- package/dist/generate/access-vars.js.map +1 -1
- package/dist/generate/kind.d.ts +2 -0
- package/dist/generate/kind.d.ts.map +1 -1
- package/dist/generate/kinds/job/grant-system-actor.js +2 -2
- package/dist/generate/kinds/job/grant-system-actor.js.map +1 -1
- package/dist/generate/kinds/job/job-vars.d.ts +4 -1
- package/dist/generate/kinds/job/job-vars.d.ts.map +1 -1
- package/dist/generate/kinds/job/job-vars.js +11 -1
- package/dist/generate/kinds/job/job-vars.js.map +1 -1
- package/dist/generate/kinds/job-kind.js +20 -3
- package/dist/generate/kinds/job-kind.js.map +1 -1
- package/dist/generate/kinds/service-kind.d.ts.map +1 -1
- package/dist/generate/kinds/service-kind.js +30 -3
- package/dist/generate/kinds/service-kind.js.map +1 -1
- package/dist/init/files/inert-persistence-file.d.ts +5 -0
- package/dist/init/files/inert-persistence-file.d.ts.map +1 -0
- package/dist/init/files/inert-persistence-file.js +16 -0
- package/dist/init/files/inert-persistence-file.js.map +1 -0
- package/dist/init/files/platform-files.js +7 -1
- package/dist/init/files/platform-files.js.map +1 -1
- package/dist/init/manifest/versions.js +24 -24
- package/dist/measures/branch-commits.d.ts +4 -2
- package/dist/measures/branch-commits.d.ts.map +1 -1
- package/dist/measures/branch-commits.js +32 -8
- package/dist/measures/branch-commits.js.map +1 -1
- package/dist/measures/timeline-of.d.ts +3 -2
- package/dist/measures/timeline-of.d.ts.map +1 -1
- package/dist/measures/timeline-of.js +37 -8
- package/dist/measures/timeline-of.js.map +1 -1
- package/dist/platform-layout/platform-layout.d.ts +3 -0
- package/dist/platform-layout/platform-layout.d.ts.map +1 -1
- package/dist/platform-layout/platform-layout.js +3 -0
- package/dist/platform-layout/platform-layout.js.map +1 -1
- package/dist/presets/apply-preset.d.ts.map +1 -1
- package/dist/presets/apply-preset.js +4 -0
- package/dist/presets/apply-preset.js.map +1 -1
- package/dist/presets/no-flags.d.ts.map +1 -1
- package/dist/presets/no-flags.js +1 -0
- package/dist/presets/no-flags.js.map +1 -1
- package/dist/presets/organisations-as-tenant-directory.d.ts +10 -0
- package/dist/presets/organisations-as-tenant-directory.d.ts.map +1 -0
- package/dist/presets/organisations-as-tenant-directory.js +16 -0
- package/dist/presets/organisations-as-tenant-directory.js.map +1 -0
- package/dist/progress/build-next-of.d.ts +9 -0
- package/dist/progress/build-next-of.d.ts.map +1 -0
- package/dist/progress/build-next-of.js +22 -0
- package/dist/progress/build-next-of.js.map +1 -0
- package/dist/progress/format-progress.d.ts.map +1 -1
- package/dist/progress/format-progress.js +3 -0
- package/dist/progress/format-progress.js.map +1 -1
- package/dist/progress/progress.d.ts +3 -1
- package/dist/progress/progress.d.ts.map +1 -1
- package/dist/progress/read-progress.d.ts.map +1 -1
- package/dist/progress/read-progress.js +7 -2
- package/dist/progress/read-progress.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/templates/architecture/extractable.declared.spec.ts.tpl +2 -2
- package/templates/architecture/extractable.manual.spec.ts.tpl +2 -2
- package/templates/architecture/extractable.tsyringe.spec.ts.tpl +2 -2
- package/templates/architecture/hosting.declared.spec.ts.tpl +69 -0
- package/templates/architecture/hosting.manual.spec.ts.tpl +57 -0
- package/templates/architecture/hosting.tsyringe.spec.ts.tpl +69 -0
- package/templates/command/command.ts.tpl +3 -0
- package/templates/file-upload/command.ts.tpl +3 -0
- package/templates/init/docker/env.example.tpl +9 -0
- package/templates/init/gitignore.tpl +3 -0
- package/templates/init/main.ts.tpl +27 -20
- package/templates/init/platform/audit/audit.module.tsyringe.ts.tpl +11 -3
- package/templates/init/platform/auth/relationships/relationship-schema.ts.tpl +24 -9
- package/templates/init/platform/composition/compose-application.manual.ts.tpl +25 -4
- package/templates/init/platform/composition/compose-application.tsyringe.ts.tpl +47 -65
- package/templates/init/platform/composition/context-selection.tsyringe.ts.tpl +17 -0
- package/templates/init/platform/composition/lay-foundations.manual.ts.tpl +13 -2
- package/templates/init/platform/composition/platform-options.manual.ts.tpl +9 -0
- package/templates/init/platform/composition/routes-of.tsyringe.ts.tpl +51 -0
- package/templates/init/platform/composition/tenant-directory.ts.tpl +14 -0
- package/templates/init/platform/config/app-config.ts.tpl +7 -0
- package/templates/init/platform/config/load-config.ts.tpl +25 -0
- package/templates/init/platform/files/files.module.tsyringe.ts.tpl +6 -2
- package/templates/init/platform/jobs/job-settings.ts.tpl +13 -3
- package/templates/init/platform/privacy/privacy.module.tsyringe.ts.tpl +9 -6
- package/templates/init/platform/redis/open-redis.ts.tpl +13 -8
- package/templates/init/scripts/privacy-erase.manual.ts.tpl +18 -8
- package/templates/init/scripts/privacy-erase.tsyringe.ts.tpl +18 -8
- package/templates/init/scripts/privacy-export.manual.ts.tpl +17 -7
- package/templates/init/scripts/privacy-export.tsyringe.ts.tpl +17 -7
- package/templates/job/job.declared.ts.tpl +1 -1
- package/templates/job/job.spec.buses.ts.tpl +3 -0
- package/templates/job/job.spec.tsyringe.ts.tpl +29 -1
- package/templates/job/wiring.manual.tpl +3 -0
- package/templates/job/wiring.tsyringe.tpl +1 -1
- package/templates/pipeline/biome.json.tpl +7 -0
- package/templates/pipeline/github/workflows/ci.yml.tpl +2 -0
- package/templates/pipeline/gitlab/gitlab-ci.yml.tpl +2 -0
- package/templates/pipeline/knip.json.tpl +1 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/presets/identity/context/infrastructure/persistence/drizzle-organisation-tenant-directory.reader.drizzle.ts.tpl +26 -0
- package/templates/presets/identity/context/infrastructure/persistence/knex-organisation-tenant-directory.reader.knex.ts.tpl +30 -0
- package/templates/presets/identity/context/infrastructure/persistence/prisma-organisation-tenant-directory.reader.prisma.ts.tpl +25 -0
- package/templates/presets/identity/context/test/integration/organisation-tenant-directory.spec.ts.tpl +107 -0
- package/templates/presets/identity/platform/tenant-directory.ts.tpl +13 -0
- package/templates/query/query.ts.tpl +3 -0
- package/templates/service/compose.tpl +1 -1
- package/templates/service/extracted-name.tpl +2 -0
- package/templates/service/extracted.declared.tpl +6 -0
- package/templates/service/extracted.manual.tpl +2 -0
- package/templates/service/extracted.tsyringe.tpl +6 -0
- package/templates/service/main.ts.tpl +5 -1
- package/templates/worker/main.ts.tpl +20 -13
|
@@ -31,6 +31,9 @@ import { logDecisions } from '{{alias.platform}}/auth/authorization/log-decision
|
|
|
31
31
|
import type { Platform } from '{{alias.platform}}/composition/platform{{alias.ext}}';
|
|
32
32
|
import type { PlatformOptions } from '{{alias.platform}}/composition/platform-options{{alias.ext}}';
|
|
33
33
|
import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
|
|
34
|
+
{{#if tenancy.any}}
|
|
35
|
+
import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
|
|
36
|
+
{{/if}}
|
|
34
37
|
{{#if eventSourcing.on}}
|
|
35
38
|
import { createEventSourcing } from '{{alias.platform}}/event-sourcing/create-event-sourcing{{alias.ext}}';
|
|
36
39
|
{{/if}}
|
|
@@ -79,6 +82,14 @@ export function layFoundations(persistence: Persistence, options: PlatformOption
|
|
|
79
82
|
const audit = createAudit(persistence, { scope, clock, ids });
|
|
80
83
|
{{/if}}
|
|
81
84
|
|
|
85
|
+
{{#if tenancy.any}}
|
|
86
|
+
// The tenants a job declared `per-tenant` runs for, asked at each occurrence.
|
|
87
|
+
const parts = { clock, lock, scope, ids, logger, metrics, tenants: tenantDirectory(persistence, options.tenants) };
|
|
88
|
+
{{/if}}
|
|
89
|
+
{{#unless tenancy.any}}
|
|
90
|
+
const parts = { clock, lock, scope, ids, logger, metrics };
|
|
91
|
+
{{/unless}}
|
|
92
|
+
|
|
82
93
|
return {
|
|
83
94
|
traced,
|
|
84
95
|
scope,
|
|
@@ -99,11 +110,11 @@ export function layFoundations(persistence: Persistence, options: PlatformOption
|
|
|
99
110
|
rateLimiter: options.redis?.rateLimiter ?? new InMemoryRateLimiter(clock),
|
|
100
111
|
{{/if}}
|
|
101
112
|
{{#if errors.none}}
|
|
102
|
-
jobs: schedulerOf(options, traced,
|
|
113
|
+
jobs: schedulerOf(options, traced, parts),
|
|
103
114
|
{{/if}}
|
|
104
115
|
{{#if errors.sentry}}
|
|
105
116
|
// A run that failed, a timeout included, is reported; a skipped or missed occurrence is not.
|
|
106
|
-
jobs: schedulerOf(options, traced, {
|
|
117
|
+
jobs: schedulerOf(options, traced, { ...parts, onRun: reportFailedRuns(errors) }),
|
|
107
118
|
{{/if}}
|
|
108
119
|
{{#if audit.on}}
|
|
109
120
|
audit,
|
|
@@ -43,6 +43,15 @@ export interface PlatformOptions {
|
|
|
43
43
|
readonly resilience?: ResilienceSettings;
|
|
44
44
|
/** Whether this process runs the scheduled jobs and consumes the background jobs, and the settings of the scheduled ones; left out (the tools, the tests), no job runs by time. */
|
|
45
45
|
readonly jobs?: JobsOptions;
|
|
46
|
+
/**
|
|
47
|
+
* Whether this composition registers the jobs of the platform itself. They belong to one process of a deployment, the
|
|
48
|
+
* whole application: a service passes `false`, or each of its containers would run them on the same database. Default: `true`.
|
|
49
|
+
*/
|
|
50
|
+
readonly platformJobs?: boolean;
|
|
51
|
+
{{#if tenancy.any}}
|
|
52
|
+
/** The ids of the tenants that exist (`TENANTS`): a job declared `per-tenant` runs once for each. Left out (the tools, the tests), none, and such a job runs for nobody. */
|
|
53
|
+
readonly tenants?: readonly string[];
|
|
54
|
+
{{/if}}
|
|
46
55
|
/** Concurrency per queue, polling interval and grace period of the worker of the background jobs; left out, one attempt at a time per queue. */
|
|
47
56
|
readonly queues?: Pick<QueueWorkerOptions, 'concurrency' | 'pollIntervalMs' | 'graceMs'>;
|
|
48
57
|
/** Whether a consumed event continues the trace of its publication (the default) or starts one linked to it. */
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{{#if routes.declaredControllers}}
|
|
2
|
+
import { DeclaredEdges, type Application as Container } from '@ddd-ts-kit/di';
|
|
3
|
+
{{/if}}
|
|
4
|
+
{{#unless routes.declaredControllers}}
|
|
5
|
+
import type { Application as Container } from '@ddd-ts-kit/di';
|
|
6
|
+
{{/unless}}
|
|
7
|
+
{{#if routes.mountsControllers}}
|
|
8
|
+
import { controllerRoutes, defineRoutes, type Route } from '@ddd-ts-kit/http';
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#unless routes.mountsControllers}}
|
|
11
|
+
import { defineRoutes, type Route } from '@ddd-ts-kit/http';
|
|
12
|
+
{{/unless}}
|
|
13
|
+
import { CommandBus, QueryBus } from '@ddd-ts-kit/kernel';
|
|
14
|
+
{{#if audit.functionRoute}}
|
|
15
|
+
import { searchAuditEntriesRoute } from '{{alias.platform}}/audit/search-audit-entries/search-audit-entries.route{{alias.ext}}';
|
|
16
|
+
{{/if}}
|
|
17
|
+
{{#if audit.controller}}
|
|
18
|
+
import { SearchAuditEntriesController } from '{{alias.platform}}/audit/search-audit-entries/search-audit-entries.controller{{alias.ext}}';
|
|
19
|
+
{{/if}}
|
|
20
|
+
{{#if routes.mountsControllers}}
|
|
21
|
+
import { securitySchemes } from '{{alias.platform}}/auth/authentication/security-schemes{{alias.ext}}';
|
|
22
|
+
{{/if}}
|
|
23
|
+
import type { ContextSelection } from '{{alias.platform}}/composition/context-selection{{alias.ext}}';
|
|
24
|
+
|
|
25
|
+
/** Every route of the hosted contexts, and the ones of the platform. */
|
|
26
|
+
export function routesOf(container: Container, contexts: ContextSelection): readonly Route[] {
|
|
27
|
+
const commands = container.resolve(CommandBus);
|
|
28
|
+
const queries = container.resolve(QueryBus);
|
|
29
|
+
|
|
30
|
+
{{#unless routes.mountsControllers}}
|
|
31
|
+
return defineRoutes(...(contexts.routes ?? []).map((routes) => routes(commands, queries)){{#if audit.route}}, [searchAuditEntriesRoute(queries)]{{/if}});
|
|
32
|
+
{{/unless}}
|
|
33
|
+
{{#if routes.mountsControllers}}
|
|
34
|
+
// Every route that is not public names these schemes in the contract.
|
|
35
|
+
const security = Object.keys(securitySchemes);
|
|
36
|
+
|
|
37
|
+
return defineRoutes(
|
|
38
|
+
...(contexts.routes ?? []).map((routes) => routes(commands, queries)),
|
|
39
|
+
{{#if routes.declaredControllers}}
|
|
40
|
+
// The controllers the hosted contexts declare, each built from its constructor.
|
|
41
|
+
controllerRoutes(container.resolve(DeclaredEdges).of('controller'), { resolve: container.resolve, security }),
|
|
42
|
+
{{/if}}
|
|
43
|
+
{{#if audit.functionRoute}}
|
|
44
|
+
[searchAuditEntriesRoute(queries)],
|
|
45
|
+
{{/if}}
|
|
46
|
+
{{#if audit.controller}}
|
|
47
|
+
controllerRoutes([new SearchAuditEntriesController(queries)], { security }),
|
|
48
|
+
{{/if}}
|
|
49
|
+
);
|
|
50
|
+
{{/if}}
|
|
51
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InMemoryTenantDirectory, type TenantDirectory } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The tenants a job declared `per-tenant` runs for, asked again at each occurrence.
|
|
6
|
+
*
|
|
7
|
+
* The project has no source of tenants yet, so this is the list of `TENANTS`, read once when the
|
|
8
|
+
* process starts: an organisation or a customer created later gets no run of such a job until the
|
|
9
|
+
* process restarts. Where the tenants live in the database, read them here instead (the identity
|
|
10
|
+
* preset writes this file that way: its organisations are the tenants).
|
|
11
|
+
*/
|
|
12
|
+
export function tenantDirectory(_persistence: Persistence, fixed: readonly string[] = []): TenantDirectory {
|
|
13
|
+
return new InMemoryTenantDirectory(fixed);
|
|
14
|
+
}
|
|
@@ -12,7 +12,10 @@ import type { TracingConfig } from '{{alias.platform}}/config/read-tracing{{alia
|
|
|
12
12
|
|
|
13
13
|
/** The validated configuration of the process: `loadConfig` is the only reader of the environment. */
|
|
14
14
|
export interface AppConfig {
|
|
15
|
+
/** What this process is called in traces and logs (`OTEL_SERVICE_NAME`): one per container, so it tells the processes of a deployment apart. */
|
|
15
16
|
readonly serviceName: string;
|
|
17
|
+
/** What the processes of one deployment share (`DEPLOYMENT_NAME`, the name of the project when left out): the namespace of the keys they exchange through the server, never `serviceName`. */
|
|
18
|
+
readonly deploymentName: string;
|
|
16
19
|
readonly serviceVersion: string;
|
|
17
20
|
readonly environment: 'development' | 'test' | 'production';
|
|
18
21
|
readonly port: number;
|
|
@@ -23,6 +26,10 @@ export interface AppConfig {
|
|
|
23
26
|
readonly resilience: ResilienceSettings;
|
|
24
27
|
/** Whether this process runs the scheduled jobs (`RUN_JOBS`): off for the API of a project that has a worker. */
|
|
25
28
|
readonly runJobs: boolean;
|
|
29
|
+
{{#if tenancy.any}}
|
|
30
|
+
/** The tenants that exist (`TENANTS`, comma separated): a job declared `per-tenant` runs once for each. Read once at the start: a tenant created later is missed. Once the tenants live in a table, make `composition/tenant-directory.ts` read it (the identity preset does). */
|
|
31
|
+
readonly tenants: readonly string[];
|
|
32
|
+
{{/if}}
|
|
26
33
|
{{#if persistence.needsUrl}}
|
|
27
34
|
readonly databaseUrl: string;
|
|
28
35
|
{{/if}}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
{{#if tenancy.any}}
|
|
2
|
+
import { LOG_LEVELS, isTenantId } from '@ddd-ts-kit/kernel';
|
|
3
|
+
{{/if}}
|
|
4
|
+
{{#unless tenancy.any}}
|
|
1
5
|
import { LOG_LEVELS } from '@ddd-ts-kit/kernel';
|
|
6
|
+
{{/unless}}
|
|
2
7
|
import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
|
|
3
8
|
import { Environment, type Variables } from '{{alias.platform}}/config/environment{{alias.ext}}';
|
|
4
9
|
{{#if files.any}}
|
|
@@ -28,6 +33,7 @@ export function loadConfig(variables: Variables): AppConfig {
|
|
|
28
33
|
|
|
29
34
|
const config: AppConfig = {
|
|
30
35
|
serviceName: env.optional('OTEL_SERVICE_NAME') ?? '{{project.name}}',
|
|
36
|
+
deploymentName: env.optional('DEPLOYMENT_NAME') ?? '{{project.name}}',
|
|
31
37
|
serviceVersion: env.optional('SERVICE_VERSION') ?? '0.0.0',
|
|
32
38
|
environment,
|
|
33
39
|
port: env.integer('PORT', { fallback: 3000, min: 0, max: 65535 }),
|
|
@@ -35,6 +41,9 @@ export function loadConfig(variables: Variables): AppConfig {
|
|
|
35
41
|
tracing: readTracing(env),
|
|
36
42
|
resilience: readResilience(env),
|
|
37
43
|
runJobs: env.flag('RUN_JOBS', runJobsByDefault),
|
|
44
|
+
{{#if tenancy.any}}
|
|
45
|
+
tenants: readTenants(env),
|
|
46
|
+
{{/if}}
|
|
38
47
|
{{#if persistence.needsUrl}}
|
|
39
48
|
databaseUrl: env.url('DATABASE_URL'),
|
|
40
49
|
{{/if}}
|
|
@@ -79,6 +88,22 @@ export function loadConfig(variables: Variables): AppConfig {
|
|
|
79
88
|
return config;
|
|
80
89
|
}
|
|
81
90
|
|
|
91
|
+
{{#if tenancy.any}}
|
|
92
|
+
/** `TENANTS=acme,globex`: each id in the grammar of a tenant id. */
|
|
93
|
+
function readTenants(env: Environment): readonly string[] {
|
|
94
|
+
const tenants = (env.optional('TENANTS') ?? '')
|
|
95
|
+
.split(',')
|
|
96
|
+
.map((tenant) => tenant.trim())
|
|
97
|
+
.filter((tenant) => tenant !== '');
|
|
98
|
+
|
|
99
|
+
if (!tenants.every(isTenantId)) {
|
|
100
|
+
env.problem('TENANTS must list tenant ids: letters, digits, _ and -, at most 63 characters each');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return tenants;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
{{/if}}
|
|
82
107
|
function readLog(env: Environment): AppConfig['log'] {
|
|
83
108
|
return {
|
|
84
109
|
level: env.oneOf('LOG_LEVEL', LOG_LEVELS, 'info'),
|
|
@@ -7,12 +7,16 @@ import { bindFiles } from '{{alias.platform}}/files/bind-files{{alias.ext}}';
|
|
|
7
7
|
* for the tools and the tests), its ports, and the hourly purge of what rolled-back commands left
|
|
8
8
|
* in `staging/`.
|
|
9
9
|
*/
|
|
10
|
-
export function filesModule(storage: FileStorage): ContextModule {
|
|
10
|
+
export function filesModule(storage: FileStorage, { jobs = true }: { readonly jobs?: boolean } = {}): ContextModule {
|
|
11
11
|
return defineContextModule({
|
|
12
12
|
name: 'files',
|
|
13
13
|
register(builder) {
|
|
14
14
|
bindFiles(builder, storage);
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
// Registered by the process that runs the jobs of the platform; a service of the deployment passes `jobs: false`.
|
|
17
|
+
if (jobs) {
|
|
18
|
+
builder.job('files.purge-staged', { every: '1h', tenancy: 'global' }).handledBy(PurgeStagedFiles, [FileStaging, Clock]);
|
|
19
|
+
}
|
|
16
20
|
},
|
|
17
21
|
});
|
|
18
22
|
}
|
|
@@ -2,12 +2,20 @@ import type { JobSettings } from '@ddd-ts-kit/kernel';
|
|
|
2
2
|
|
|
3
3
|
type Environment = Readonly<Record<string, string | undefined>>;
|
|
4
4
|
|
|
5
|
+
/** The contexts run as services of their own (`ddd-ts-kit generate service`): the whole application schedules none of their jobs. */
|
|
6
|
+
const extracted: readonly string[] = [
|
|
7
|
+
// ddd-ts-kit:extracted
|
|
8
|
+
// /ddd-ts-kit:extracted
|
|
9
|
+
];
|
|
10
|
+
|
|
5
11
|
/**
|
|
6
12
|
* What configuration changes of each scheduled job, by job name: a job is switched off in one
|
|
7
13
|
* environment with `JOB_<CONTEXT>_<JOB>_ENABLED=false`, never by a code change.
|
|
8
14
|
* `ddd-ts-kit generate job` adds a line; a schedule or a timeout read from the environment goes
|
|
9
|
-
* on the same line.
|
|
10
|
-
*
|
|
15
|
+
* on the same line. The wiring refuses the settings of a job no module declares (`UNKNOWN_JOB`), so each
|
|
16
|
+
* process is given those of the jobs it registers: a service that hosts one context is given a context
|
|
17
|
+
* and keeps its jobs only (the jobs of the platform run in the whole application); the whole application
|
|
18
|
+
* is given none, and leaves out the jobs of the contexts run as services of their own.
|
|
11
19
|
*/
|
|
12
20
|
export function jobSettings(environment: Environment, context?: string): Readonly<Record<string, JobSettings>> {
|
|
13
21
|
const settings: Readonly<Record<string, JobSettings>> = {
|
|
@@ -27,7 +35,9 @@ export function jobSettings(environment: Environment, context?: string): Readonl
|
|
|
27
35
|
};
|
|
28
36
|
|
|
29
37
|
if (context === undefined) {
|
|
30
|
-
return
|
|
38
|
+
return Object.fromEntries(
|
|
39
|
+
Object.entries(settings).filter(([name]) => !extracted.some((hosted) => name.startsWith(hosted + '.'))),
|
|
40
|
+
);
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
return Object.fromEntries(Object.entries(settings).filter(([name]) => name.startsWith(context + '.')));
|
|
@@ -6,15 +6,18 @@ import { runPurge } from '{{alias.platform}}/privacy/run-purge{{alias.ext}}';
|
|
|
6
6
|
* retention their declaration gives are purged (`privacy.purge-expired`, switched off in one
|
|
7
7
|
* environment with `JOB_PRIVACY_PURGE_EXPIRED_ENABLED=false`).
|
|
8
8
|
*/
|
|
9
|
-
export function privacyModule(): ContextModule {
|
|
9
|
+
export function privacyModule({ jobs = true }: { readonly jobs?: boolean } = {}): ContextModule {
|
|
10
10
|
return defineContextModule({
|
|
11
11
|
name: 'privacy',
|
|
12
12
|
register(builder) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
// Registered by the process that runs the jobs of the platform; a service of the deployment passes `jobs: false`.
|
|
14
|
+
if (jobs) {
|
|
15
|
+
builder.job('privacy.purge-expired', { cron: '0 3 * * *', tenancy: 'global' }).handledByFactory((resolve) => ({
|
|
16
|
+
run: async () => {
|
|
17
|
+
await runPurge(resolve);
|
|
18
|
+
},
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
18
21
|
},
|
|
19
22
|
});
|
|
20
23
|
}
|
|
@@ -67,25 +67,30 @@ export interface RedisServices {
|
|
|
67
67
|
|
|
68
68
|
interface RedisSettings {
|
|
69
69
|
readonly redisUrl: string;
|
|
70
|
-
/**
|
|
71
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Prefix of every key. The same for every process of one deployment (`DEPLOYMENT_NAME`), never
|
|
72
|
+
* the name of the container: the lock that keeps an occurrence of a job to one run, the cache
|
|
73
|
+
* a purge reaches and the jobs waiting in the store are shared by the API, the worker and the
|
|
74
|
+
* services, and each would otherwise find only its own keys.
|
|
75
|
+
*/
|
|
76
|
+
readonly deploymentName: string;
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
export function openRedis({ redisUrl,
|
|
79
|
+
export function openRedis({ redisUrl, deploymentName }: RedisSettings): RedisServices {
|
|
75
80
|
const connection = connectRedis(redisUrl);
|
|
76
81
|
{{#if cache.relaySignal}}
|
|
77
|
-
const relaySignal = new RedisRelaySignal(connection.client, { channel:
|
|
82
|
+
const relaySignal = new RedisRelaySignal(connection.client, { channel: deploymentName + ':outbox' });
|
|
78
83
|
{{/if}}
|
|
79
84
|
|
|
80
85
|
return {
|
|
81
|
-
cache: (metrics) => new RedisCache(connection.client, { namespace:
|
|
86
|
+
cache: (metrics) => new RedisCache(connection.client, { namespace: deploymentName, metrics }),
|
|
82
87
|
// While the server is away the API keeps serving, without a limit: a limiter must not take the application down.
|
|
83
|
-
rateLimiter: new RedisRateLimiter(connection.client, { namespace:
|
|
84
|
-
lock: new RedisLock(connection.client, { namespace:
|
|
88
|
+
rateLimiter: new RedisRateLimiter(connection.client, { namespace: deploymentName + ':rate', onError: 'allow' }),
|
|
89
|
+
lock: new RedisLock(connection.client, { namespace: deploymentName + ':lock' }),
|
|
85
90
|
{{#if queue.redis}}
|
|
86
91
|
jobs: (logger, errors) =>
|
|
87
92
|
new RedisJobStore(connection.client, {
|
|
88
|
-
namespace:
|
|
93
|
+
namespace: deploymentName + ':jobs',
|
|
89
94
|
onLostJob: reportLostJobs(logger, errors),
|
|
90
95
|
}),
|
|
91
96
|
{{/if}}
|
|
@@ -9,6 +9,9 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
9
9
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
10
10
|
{{/if}}
|
|
11
11
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
12
|
+
{{#if tenancy.any}}
|
|
13
|
+
import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
|
|
14
|
+
{{/if}}
|
|
12
15
|
import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
|
|
13
16
|
import { runErasure } from '{{alias.platform}}/privacy/run-erasure{{alias.ext}}';
|
|
14
17
|
|
|
@@ -17,11 +20,11 @@ import { runErasure } from '{{alias.platform}}/privacy/run-erasure{{alias.ext}}'
|
|
|
17
20
|
{{#if eventSourcing.on}}
|
|
18
21
|
// The key of the subject is destroyed first, so every personal value of its stored events reads as
|
|
19
22
|
// erased{{#if audit.on}}, and the erasure leaves a dated entry in the audit trail{{/if}}; then every copy a context declared in
|
|
20
|
-
// src/platform/privacy/data-subject-copies.ts is erased{{#if tenancy.any}}, in each tenant
|
|
23
|
+
// src/platform/privacy/data-subject-copies.ts is erased{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}.
|
|
21
24
|
{{/if}}
|
|
22
25
|
{{#unless eventSourcing.on}}
|
|
23
26
|
// Every copy a context declared in src/platform/privacy/data-subject-copies.ts is erased or
|
|
24
|
-
// pseudonymised where it lies{{#if tenancy.any}}, in each tenant
|
|
27
|
+
// pseudonymised where it lies{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}: the aggregates of
|
|
25
28
|
// this project are rows, so there is no key to destroy.
|
|
26
29
|
{{/unless}}
|
|
27
30
|
// The report says what was reached. Running it again completes an erasure that failed half way.
|
|
@@ -39,12 +42,8 @@ if (subject === undefined || positionals.length > 1) {
|
|
|
39
42
|
}
|
|
40
43
|
{{#if tenancy.any}}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (tenants.length === 0) {
|
|
45
|
-
console.error('TENANTS names the tenants the copies are erased in, comma separated: a write of tenant data is never widened.');
|
|
46
|
-
process.exit(2);
|
|
47
|
-
}
|
|
45
|
+
// The tenants of a project with no source of tenants (comma separated); the identity preset reads its organisations instead.
|
|
46
|
+
const fixedTenants = (process.env['TENANTS'] ?? '').split(',').map((tenant) => tenant.trim()).filter((tenant) => tenant !== '');
|
|
48
47
|
{{/if}}
|
|
49
48
|
|
|
50
49
|
{{#if persistence.needsUrl}}
|
|
@@ -61,6 +60,17 @@ const application = composeApplication(persistence, {
|
|
|
61
60
|
{{/if}}
|
|
62
61
|
});
|
|
63
62
|
|
|
63
|
+
{{#if tenancy.any}}
|
|
64
|
+
const tenants = await tenantDirectory(persistence, fixedTenants).tenants();
|
|
65
|
+
|
|
66
|
+
if (tenants.length === 0) {
|
|
67
|
+
console.error('The tenant directory lists no tenant: a write of tenant data is never widened. Name them in TENANTS, comma separated, or open an organisation first.');
|
|
68
|
+
await application.stop();
|
|
69
|
+
await persistence.close();
|
|
70
|
+
process.exit(2);
|
|
71
|
+
}
|
|
72
|
+
{{/if}}
|
|
73
|
+
|
|
64
74
|
try {
|
|
65
75
|
const report = await runErasure(subject, {
|
|
66
76
|
platform: application.platform,
|
|
@@ -9,6 +9,9 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
9
9
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
10
10
|
{{/if}}
|
|
11
11
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
12
|
+
{{#if tenancy.any}}
|
|
13
|
+
import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
|
|
14
|
+
{{/if}}
|
|
12
15
|
import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
|
|
13
16
|
import { runErasure } from '{{alias.platform}}/privacy/run-erasure{{alias.ext}}';
|
|
14
17
|
|
|
@@ -17,11 +20,11 @@ import { runErasure } from '{{alias.platform}}/privacy/run-erasure{{alias.ext}}'
|
|
|
17
20
|
{{#if eventSourcing.on}}
|
|
18
21
|
// The key of the subject is destroyed first, so every personal value of its stored events reads as
|
|
19
22
|
// erased{{#if audit.on}}, and the erasure leaves a dated entry in the audit trail{{/if}}; then every copy a context declared in
|
|
20
|
-
// src/platform/privacy/data-subject-copies.ts is erased{{#if tenancy.any}}, in each tenant
|
|
23
|
+
// src/platform/privacy/data-subject-copies.ts is erased{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}.
|
|
21
24
|
{{/if}}
|
|
22
25
|
{{#unless eventSourcing.on}}
|
|
23
26
|
// Every copy a context declared in src/platform/privacy/data-subject-copies.ts is erased or
|
|
24
|
-
// pseudonymised where it lies{{#if tenancy.any}}, in each tenant
|
|
27
|
+
// pseudonymised where it lies{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}: the aggregates of
|
|
25
28
|
// this project are rows, so there is no key to destroy.
|
|
26
29
|
{{/unless}}
|
|
27
30
|
// The report says what was reached. Running it again completes an erasure that failed half way.
|
|
@@ -39,12 +42,8 @@ if (subject === undefined || positionals.length > 1) {
|
|
|
39
42
|
}
|
|
40
43
|
{{#if tenancy.any}}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (tenants.length === 0) {
|
|
45
|
-
console.error('TENANTS names the tenants the copies are erased in, comma separated: a write of tenant data is never widened.');
|
|
46
|
-
process.exit(2);
|
|
47
|
-
}
|
|
45
|
+
// The tenants of a project with no source of tenants (comma separated); the identity preset reads its organisations instead.
|
|
46
|
+
const fixedTenants = (process.env['TENANTS'] ?? '').split(',').map((tenant) => tenant.trim()).filter((tenant) => tenant !== '');
|
|
48
47
|
{{/if}}
|
|
49
48
|
|
|
50
49
|
{{#if persistence.needsUrl}}
|
|
@@ -61,6 +60,17 @@ const application = composeApplication(persistence, {
|
|
|
61
60
|
{{/if}}
|
|
62
61
|
});
|
|
63
62
|
|
|
63
|
+
{{#if tenancy.any}}
|
|
64
|
+
const tenants = await tenantDirectory(persistence, fixedTenants).tenants();
|
|
65
|
+
|
|
66
|
+
if (tenants.length === 0) {
|
|
67
|
+
console.error('The tenant directory lists no tenant: a write of tenant data is never widened. Name them in TENANTS, comma separated, or open an organisation first.');
|
|
68
|
+
await application.stop();
|
|
69
|
+
await persistence.close();
|
|
70
|
+
process.exit(2);
|
|
71
|
+
}
|
|
72
|
+
{{/if}}
|
|
73
|
+
|
|
64
74
|
try {
|
|
65
75
|
const report = await runErasure(subject, {
|
|
66
76
|
container: application.container,
|
|
@@ -9,6 +9,9 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
9
9
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
10
10
|
{{/if}}
|
|
11
11
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
12
|
+
{{#if tenancy.any}}
|
|
13
|
+
import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
|
|
14
|
+
{{/if}}
|
|
12
15
|
import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
|
|
13
16
|
import { runExport } from '{{alias.platform}}/privacy/run-export{{alias.ext}}';
|
|
14
17
|
|
|
@@ -17,7 +20,7 @@ import { runExport } from '{{alias.platform}}/privacy/run-export{{alias.ext}}';
|
|
|
17
20
|
// npm run privacy:export -- <subject-id> [--operator <who-asks>] > export.json
|
|
18
21
|
// One JSON document on the standard output (`format`, `subject`, `exportedAt`, `records`): every
|
|
19
22
|
// record each context declared in src/platform/privacy/data-subject-exports.ts keeps of the
|
|
20
|
-
// person{{#if tenancy.any}}, in each tenant
|
|
23
|
+
// person{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}, as plain data. Hand it over to the person, then delete
|
|
21
24
|
// the file{{#if audit.on}}; the audit trail keeps the entry of each export, never the values. Every run is a
|
|
22
25
|
// handover and leaves its entry, a trial included: try it on a test subject, never on a real person{{/if}}.
|
|
23
26
|
{{#if eventSourcing.on}}
|
|
@@ -40,12 +43,8 @@ if (subject === undefined || positionals.length > 1) {
|
|
|
40
43
|
}
|
|
41
44
|
{{#if tenancy.any}}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (tenants.length === 0) {
|
|
46
|
-
console.error('TENANTS names the tenants the records are gathered in, comma separated.');
|
|
47
|
-
process.exit(2);
|
|
48
|
-
}
|
|
46
|
+
// The tenants of a project with no source of tenants (comma separated); the identity preset reads its organisations instead.
|
|
47
|
+
const fixedTenants = (process.env['TENANTS'] ?? '').split(',').map((tenant) => tenant.trim()).filter((tenant) => tenant !== '');
|
|
49
48
|
{{/if}}
|
|
50
49
|
|
|
51
50
|
{{#if persistence.needsUrl}}
|
|
@@ -62,6 +61,17 @@ const application = composeApplication(persistence, {
|
|
|
62
61
|
{{/if}}
|
|
63
62
|
});
|
|
64
63
|
|
|
64
|
+
{{#if tenancy.any}}
|
|
65
|
+
const tenants = await tenantDirectory(persistence, fixedTenants).tenants();
|
|
66
|
+
|
|
67
|
+
if (tenants.length === 0) {
|
|
68
|
+
console.error('The tenant directory lists no tenant to gather the records in. Name them in TENANTS, comma separated, or open an organisation first.');
|
|
69
|
+
await application.stop();
|
|
70
|
+
await persistence.close();
|
|
71
|
+
process.exit(2);
|
|
72
|
+
}
|
|
73
|
+
{{/if}}
|
|
74
|
+
|
|
65
75
|
try {
|
|
66
76
|
const document = await runExport(subject, {
|
|
67
77
|
platform: application.platform,
|
|
@@ -9,6 +9,9 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
9
9
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
10
10
|
{{/if}}
|
|
11
11
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
12
|
+
{{#if tenancy.any}}
|
|
13
|
+
import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
|
|
14
|
+
{{/if}}
|
|
12
15
|
import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
|
|
13
16
|
import { runExport } from '{{alias.platform}}/privacy/run-export{{alias.ext}}';
|
|
14
17
|
|
|
@@ -17,7 +20,7 @@ import { runExport } from '{{alias.platform}}/privacy/run-export{{alias.ext}}';
|
|
|
17
20
|
// npm run privacy:export -- <subject-id> [--operator <who-asks>] > export.json
|
|
18
21
|
// One JSON document on the standard output (`format`, `subject`, `exportedAt`, `records`): every
|
|
19
22
|
// record each context declared in src/platform/privacy/data-subject-exports.ts keeps of the
|
|
20
|
-
// person{{#if tenancy.any}}, in each tenant
|
|
23
|
+
// person{{#if tenancy.any}}, in each tenant the tenant directory lists (TENANTS, or the organisations of the identity context){{/if}}, as plain data. Hand it over to the person, then delete
|
|
21
24
|
// the file{{#if audit.on}}; the audit trail keeps the entry of each export, never the values. Every run is a
|
|
22
25
|
// handover and leaves its entry, a trial included: try it on a test subject, never on a real person{{/if}}.
|
|
23
26
|
{{#if eventSourcing.on}}
|
|
@@ -40,12 +43,8 @@ if (subject === undefined || positionals.length > 1) {
|
|
|
40
43
|
}
|
|
41
44
|
{{#if tenancy.any}}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (tenants.length === 0) {
|
|
46
|
-
console.error('TENANTS names the tenants the records are gathered in, comma separated.');
|
|
47
|
-
process.exit(2);
|
|
48
|
-
}
|
|
46
|
+
// The tenants of a project with no source of tenants (comma separated); the identity preset reads its organisations instead.
|
|
47
|
+
const fixedTenants = (process.env['TENANTS'] ?? '').split(',').map((tenant) => tenant.trim()).filter((tenant) => tenant !== '');
|
|
49
48
|
{{/if}}
|
|
50
49
|
|
|
51
50
|
{{#if persistence.needsUrl}}
|
|
@@ -62,6 +61,17 @@ const application = composeApplication(persistence, {
|
|
|
62
61
|
{{/if}}
|
|
63
62
|
});
|
|
64
63
|
|
|
64
|
+
{{#if tenancy.any}}
|
|
65
|
+
const tenants = await tenantDirectory(persistence, fixedTenants).tenants();
|
|
66
|
+
|
|
67
|
+
if (tenants.length === 0) {
|
|
68
|
+
console.error('The tenant directory lists no tenant to gather the records in. Name them in TENANTS, comma separated, or open an organisation first.');
|
|
69
|
+
await application.stop();
|
|
70
|
+
await persistence.close();
|
|
71
|
+
process.exit(2);
|
|
72
|
+
}
|
|
73
|
+
{{/if}}
|
|
74
|
+
|
|
65
75
|
try {
|
|
66
76
|
const document = await runExport(subject, {
|
|
67
77
|
container: application.container,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Scheduled, type JobExecution, type ScheduledJob } from '@ddd-ts-kit/kernel/declarations';
|
|
3
3
|
import { {{job.command}}Command } from '{{alias.context}}/application/commands/{{job.commandKebab}}/{{job.commandKebab}}.command{{alias.ext}}';
|
|
4
4
|
|
|
5
|
-
@Scheduled('{{job.name}}', {{job.
|
|
5
|
+
@Scheduled('{{job.name}}', {{job.scheduled}})
|
|
6
6
|
export class {{name.pascal}}Job implements ScheduledJob {
|
|
7
7
|
constructor(private readonly commands: CommandBus) {}
|
|
8
8
|
|
|
@@ -21,16 +21,35 @@ describe('{{name.title}}, when its time comes', () => {
|
|
|
21
21
|
|
|
22
22
|
await application.jobs.runNow('{{job.name}}');
|
|
23
23
|
|
|
24
|
+
{{#if job.perTenant}}
|
|
25
|
+
expect(sent).toHaveLength(2);
|
|
26
|
+
{{/if}}
|
|
27
|
+
{{#unless job.perTenant}}
|
|
24
28
|
expect(sent).toHaveLength(1);
|
|
29
|
+
{{/unless}}
|
|
25
30
|
expect(sent[0]).toBeInstanceOf({{job.command}}Command);
|
|
26
31
|
{{#if job.protected}}
|
|
27
32
|
expect(sent[0]).toMatchObject({ actor: { id: 'system:{{job.name}}', type: 'system' } });
|
|
28
33
|
{{/if}}
|
|
29
34
|
});
|
|
35
|
+
{{#if job.perTenant}}
|
|
36
|
+
|
|
37
|
+
it('runs once for each tenant, in the scope of that tenant', async () => {
|
|
38
|
+
const { application, tenants } = {{spec.await}}arrange();
|
|
39
|
+
|
|
40
|
+
await application.jobs.runNow('{{job.name}}');
|
|
41
|
+
|
|
42
|
+
expect(tenants).toEqual(['tenant-a', 'tenant-b']);
|
|
43
|
+
});
|
|
44
|
+
{{/if}}
|
|
30
45
|
|
|
31
46
|
// TODO(domain): replace each entry below by a test of what "{{name.words}}" asks of the use case: the period it names from `scheduledAt`, and that a second run of the same occurrence changes nothing.
|
|
32
47
|
it.todo('names the period of the occurrence, never the instant it really runs');
|
|
33
48
|
it.todo('has the same outcome when the same occurrence runs twice');
|
|
49
|
+
{{#if job.perTenant}}
|
|
50
|
+
// TODO(domain): once the handler reads a tenant-scoped repository, prove on the test database that each run reads its own tenant only: save a row for each tenant, run the job, and read both through the real repository inside the run (docs/concepts/scheduled-jobs.md, "A run reads its own tenant").
|
|
51
|
+
it.todo('reads and writes one tenant at a time');
|
|
52
|
+
{{/if}}
|
|
34
53
|
});
|
|
35
54
|
|
|
36
55
|
{{spec.async}}function arrange() {
|
|
@@ -40,13 +59,22 @@ describe('{{name.title}}, when its time comes', () => {
|
|
|
40
59
|
{{/if}}
|
|
41
60
|
const application = createTestApplication({
|
|
42
61
|
modules: [{{spec.modules}}],
|
|
62
|
+
{{#if job.perTenant}}
|
|
63
|
+
tenants: ['tenant-a', 'tenant-b'],
|
|
64
|
+
{{/if}}
|
|
43
65
|
});
|
|
44
66
|
|
|
45
67
|
const sent: Message[] = [];
|
|
68
|
+
{{#if job.perTenant}}
|
|
69
|
+
const tenants: (string | undefined)[] = [];
|
|
70
|
+
{{/if}}
|
|
46
71
|
|
|
47
72
|
application.commandBus.use(async (message) => {
|
|
48
73
|
sent.push(message);
|
|
74
|
+
{{#if job.perTenant}}
|
|
75
|
+
tenants.push(application.executionScope.require().tenantId);
|
|
76
|
+
{{/if}}
|
|
49
77
|
});
|
|
50
78
|
|
|
51
|
-
return { application, sent };
|
|
79
|
+
return { application, sent{{#if job.perTenant}}, tenants{{/if}} };
|
|
52
80
|
}
|
|
@@ -6,5 +6,8 @@ const {{name.camel}}Job = new {{name.pascal}}Job(platform.commands);
|
|
|
6
6
|
platform.jobs.register({
|
|
7
7
|
name: '{{job.name}}',
|
|
8
8
|
schedule: {{job.schedule}},
|
|
9
|
+
{{#if job.tenanted}}
|
|
10
|
+
tenancy: '{{job.tenancy}}',
|
|
11
|
+
{{/if}}
|
|
9
12
|
run: (execution) => {{name.camel}}Job.run(execution),
|
|
10
13
|
});
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
import { CommandBus } from '@ddd-ts-kit/kernel';
|
|
3
3
|
import { {{name.pascal}}Job } from '{{alias.context}}/application/scheduling/{{name.kebab}}.job{{alias.ext}}';
|
|
4
4
|
@@registrations
|
|
5
|
-
builder.job('{{job.name}}', {{job.
|
|
5
|
+
builder.job('{{job.name}}', {{job.scheduled}}).handledBy({{name.pascal}}Job, [CommandBus]);
|