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
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://biomejs.dev/schemas/2.6.2/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
3
8
|
"files": {
|
|
4
9
|
"includes": [
|
|
5
10
|
"**/*.ts",
|
|
@@ -14,6 +19,8 @@
|
|
|
14
19
|
"!**/coverage",
|
|
15
20
|
"!**/reports",
|
|
16
21
|
"!.worktrees",
|
|
22
|
+
"!**/.claude",
|
|
23
|
+
"!.mcp.json",
|
|
17
24
|
"!**/.ddd-ts-kit",
|
|
18
25
|
"!**/generated",
|
|
19
26
|
"!**/package-lock.json",
|
|
@@ -256,6 +256,8 @@ jobs:
|
|
|
256
256
|
run: |
|
|
257
257
|
run=$(gh run list --workflow "${{ github.workflow }}" --event schedule --branch "${{ github.event.repository.default_branch }}" --status success --limit 1 --json databaseId --jq '.[0].databaseId')
|
|
258
258
|
if [ -n "$run" ]; then gh run download "$run" --name mutation --dir reports/mutation || echo "The last night kept no report: a full run."; fi
|
|
259
|
+
# The night runs without a base and writes no incremental file: its json report is the same object, which Stryker reads back.
|
|
260
|
+
if [ -f reports/mutation/mutation.json ]; then cp reports/mutation/mutation.json reports/mutation/incremental.json; fi
|
|
259
261
|
- name: Stryker on what the change touches, then the survivors of its files
|
|
260
262
|
run: |
|
|
261
263
|
mkdir -p reports/mutation
|
|
@@ -261,6 +261,8 @@ mutation_changed:
|
|
|
261
261
|
GIT_DEPTH: 0
|
|
262
262
|
script:
|
|
263
263
|
- 'curl --silent --fail --location --output night.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/artifacts/$CI_DEFAULT_BRANCH/download?job=mutation" && unzip -q -o night.zip && rm night.zip || echo "The last night kept no report: a full run."'
|
|
264
|
+
# The night runs without a base and writes no incremental file: its json report is the same object, which Stryker reads back.
|
|
265
|
+
- if [ -f reports/mutation/mutation.json ]; then cp reports/mutation/mutation.json reports/mutation/incremental.json; fi
|
|
264
266
|
- git fetch --quiet origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
|
|
265
267
|
- base=$(git merge-base "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" HEAD)
|
|
266
268
|
- DDD_TS_KIT_MUTATION_SINCE="$base" npm run test:mutation
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@biomejs/biome": "2.6.2",
|
|
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.94.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,26 @@
|
|
|
1
|
+
import type { TenantDirectory } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { Database } from '{{alias.platform}}/database/database{{alias.ext}}';
|
|
3
|
+
import { organisations } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The tenants are the organisations of the application, read from the database each time a job
|
|
7
|
+
* declared `per-tenant` has its occurrence: an organisation opened after the boot gets its run
|
|
8
|
+
* at the next one, where a fixed list (`TENANTS`) would miss it.
|
|
9
|
+
*/
|
|
10
|
+
export class DrizzleOrganisationTenantDirectory implements TenantDirectory {
|
|
11
|
+
constructor(private readonly database: Database) {}
|
|
12
|
+
|
|
13
|
+
async tenants(): Promise<readonly string[]> {
|
|
14
|
+
const rows = await executorOf(this.database).select({ id: organisations.id }).from(organisations).orderBy(organisations.id);
|
|
15
|
+
|
|
16
|
+
return rows.map((row) => row.id);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The executor of the unit of work, which every statement of this file goes through. */
|
|
21
|
+
function executorOf(database: Database): ReturnType<Database['executor']> {
|
|
22
|
+
{{#if tenancy.any}}
|
|
23
|
+
// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- {{preset.adr}}: the {{context.kebab}} context is the control plane of the tenants, and its rows belong to none of them.
|
|
24
|
+
{{/if}}
|
|
25
|
+
return database.executor();
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { TenantDirectory } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import type { KnexContext } from '@ddd-ts-kit/knex';
|
|
4
|
+
import { {{context.constant}}_SCHEMA } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
5
|
+
import type { OrganisationRow } from '{{alias.context}}/infrastructure/persistence/organisation-row.schema{{alias.ext}}';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The tenants are the organisations of the application, read from the database each time a job
|
|
9
|
+
* declared `per-tenant` has its occurrence: an organisation opened after the boot gets its run
|
|
10
|
+
* at the next one, where a fixed list (`TENANTS`) would miss it.
|
|
11
|
+
*/
|
|
12
|
+
export class KnexOrganisationTenantDirectory implements TenantDirectory {
|
|
13
|
+
constructor(private readonly database: KnexContext) {}
|
|
14
|
+
|
|
15
|
+
async tenants(): Promise<readonly string[]> {
|
|
16
|
+
const rows = await tableOf(this.database).select('id').orderBy('id');
|
|
17
|
+
|
|
18
|
+
return rows.map((row) => row.id);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A function and not a method: a query builder is thenable, and a method that answers one is read as asynchronous by whatever wraps the adapter (tracing), which then answers a promise. */
|
|
23
|
+
function tableOf(database: KnexContext): Knex.QueryBuilder<OrganisationRow, OrganisationRow[]> {
|
|
24
|
+
{{#if tenancy.any}}
|
|
25
|
+
// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- {{preset.adr}}: the {{context.kebab}} context is the control plane of the tenants, and its rows belong to none of them.
|
|
26
|
+
{{/if}}
|
|
27
|
+
const table = database.executor()<OrganisationRow, OrganisationRow[]>('organisations');
|
|
28
|
+
|
|
29
|
+
return table.withSchema({{context.constant}}_SCHEMA);
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { TenantDirectory } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { Database } from '{{alias.platform}}/database/database{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The tenants are the organisations of the application, read from the database each time a job
|
|
6
|
+
* declared `per-tenant` has its occurrence: an organisation opened after the boot gets its run
|
|
7
|
+
* at the next one, where a fixed list (`TENANTS`) would miss it.
|
|
8
|
+
*/
|
|
9
|
+
export class PrismaOrganisationTenantDirectory implements TenantDirectory {
|
|
10
|
+
constructor(private readonly database: Database) {}
|
|
11
|
+
|
|
12
|
+
async tenants(): Promise<readonly string[]> {
|
|
13
|
+
const rows = await organisationsOf(this.database).findMany({ select: { id: true }, orderBy: { id: 'asc' } });
|
|
14
|
+
|
|
15
|
+
return rows.map((row) => row.id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The organisations on the client of the unit of work, which every statement of this file goes through. */
|
|
20
|
+
function organisationsOf(database: Database): ReturnType<Database['client']>['{{context.camel}}Organisation'] {
|
|
21
|
+
{{#if tenancy.any}}
|
|
22
|
+
// ddd-ts-kit-disable-next-line tenancy/scoped-statement -- {{preset.adr}}: the {{context.kebab}} context is the control plane of the tenants, and its rows belong to none of them.
|
|
23
|
+
{{/if}}
|
|
24
|
+
return database.client().{{context.camel}}Organisation;
|
|
25
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '{{tests.module}}';
|
|
2
|
+
{{#if di.tsyringe}}
|
|
3
|
+
import { contextModule, createApplication, kernelModule } from '@ddd-ts-kit/di';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if di.tsyringe}}
|
|
6
|
+
import {
|
|
7
|
+
FixedClock,
|
|
8
|
+
FixedExecutionScope,
|
|
9
|
+
executionContext,
|
|
10
|
+
JobScheduler,
|
|
11
|
+
type Actor,
|
|
12
|
+
type JobExecution,
|
|
13
|
+
type ScheduledJob,
|
|
14
|
+
} from '@ddd-ts-kit/kernel';
|
|
15
|
+
{{/if}}
|
|
16
|
+
{{#unless di.tsyringe}}
|
|
17
|
+
import { FixedClock, FixedExecutionScope, executionContext, type Actor } from '@ddd-ts-kit/kernel';
|
|
18
|
+
{{/unless}}
|
|
19
|
+
{{#if di.tsyringe}}
|
|
20
|
+
import { Scheduled } from '@ddd-ts-kit/kernel/declarations';
|
|
21
|
+
{{/if}}
|
|
22
|
+
import { {{preset.adapter.pascal}}OrganisationRepository } from '{{alias.context}}/infrastructure/persistence/{{preset.adapter.kebab}}-organisation.repository{{alias.ext}}';
|
|
23
|
+
import { {{preset.adapter.pascal}}OrganisationTenantDirectory } from '{{alias.context}}/infrastructure/persistence/{{preset.adapter.kebab}}-organisation-tenant-directory.reader{{alias.ext}}';
|
|
24
|
+
import { openTestDatabase, type TestDatabase } from '{{alias.platform}}/database/open-test-database{{alias.ext}}';
|
|
25
|
+
import { anOrganisation } from '{{alias.context}}/test/builders/organisation.builder{{alias.ext}}';
|
|
26
|
+
|
|
27
|
+
const clock = new FixedClock(new Date('2026-01-01T00:00:00.000Z'));
|
|
28
|
+
const actor: Actor = { id: 'subject-ada', type: 'user', roles: [], attributes: {} };
|
|
29
|
+
const scope = new FixedExecutionScope(executionContext({ correlationId: 'tenant-directory-spec', actor, origin: 'test' }));
|
|
30
|
+
|
|
31
|
+
let database: TestDatabase;
|
|
32
|
+
|
|
33
|
+
beforeAll(async () => {
|
|
34
|
+
database = await openTestDatabase();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
beforeEach(async () => {
|
|
38
|
+
await database.reset();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
await database.close();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('{{preset.adapter.pascal}}OrganisationTenantDirectory', () => {
|
|
46
|
+
it('lists no tenant while no organisation was opened', async () => {
|
|
47
|
+
const { directory } = arrange();
|
|
48
|
+
|
|
49
|
+
expect(await directory.tenants()).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('lists the organisations of the application as its tenants, by their id', async () => {
|
|
53
|
+
const { organisations, directory } = arrange();
|
|
54
|
+
|
|
55
|
+
await organisations.save(anOrganisation().identifiedBy('globex').build());
|
|
56
|
+
await organisations.save(anOrganisation().identifiedBy('acme').build());
|
|
57
|
+
|
|
58
|
+
expect(await directory.tenants()).toEqual(['acme', 'globex']);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('lists an organisation opened after the first read, on the same directory', async () => {
|
|
62
|
+
const { organisations, directory } = arrange();
|
|
63
|
+
|
|
64
|
+
await organisations.save(anOrganisation().identifiedBy('acme').build());
|
|
65
|
+
expect(await directory.tenants()).toEqual(['acme']);
|
|
66
|
+
|
|
67
|
+
await organisations.save(anOrganisation().identifiedBy('globex').build());
|
|
68
|
+
expect(await directory.tenants()).toEqual(['acme', 'globex']);
|
|
69
|
+
});
|
|
70
|
+
{{#if di.tsyringe}}
|
|
71
|
+
|
|
72
|
+
it('gives an organisation opened after the boot its run of a per-tenant job', async () => {
|
|
73
|
+
const { organisations, directory } = arrange();
|
|
74
|
+
const ran: (string | undefined)[] = [];
|
|
75
|
+
|
|
76
|
+
class CloseTheDay implements ScheduledJob {
|
|
77
|
+
async run(execution: JobExecution): Promise<void> {
|
|
78
|
+
ran.push(execution.tenantId);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Scheduled('tenant-directory-spec.close-the-day', { every: '1d', tenancy: 'per-tenant' }, [])(CloseTheDay);
|
|
83
|
+
|
|
84
|
+
await organisations.save(anOrganisation().identifiedBy('acme').build());
|
|
85
|
+
|
|
86
|
+
const application = createApplication({
|
|
87
|
+
modules: [kernelModule({ tenants: directory }), contextModule('tenant-directory-spec', [CloseTheDay])],
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await application.resolve(JobScheduler).runNow('tenant-directory-spec.close-the-day');
|
|
91
|
+
expect(ran).toEqual(['acme']);
|
|
92
|
+
|
|
93
|
+
await organisations.save(anOrganisation().identifiedBy('globex').build());
|
|
94
|
+
ran.length = 0;
|
|
95
|
+
|
|
96
|
+
await application.resolve(JobScheduler).runNow('tenant-directory-spec.close-the-day');
|
|
97
|
+
expect(ran).toEqual(['acme', 'globex']);
|
|
98
|
+
});
|
|
99
|
+
{{/if}}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
function arrange() {
|
|
103
|
+
const organisations = new {{preset.adapter.pascal}}OrganisationRepository(database.persistence.database, scope, clock);
|
|
104
|
+
const directory = new {{preset.adapter.pascal}}OrganisationTenantDirectory(database.persistence.database);
|
|
105
|
+
|
|
106
|
+
return { organisations, directory };
|
|
107
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TenantDirectory } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
|
|
3
|
+
import { {{preset.adapter.pascal}}OrganisationTenantDirectory } from '{{alias.context}}/infrastructure/persistence/{{preset.adapter.kebab}}-organisation-tenant-directory.reader{{alias.ext}}';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The tenants a job declared `per-tenant` runs for, asked again at each occurrence: the
|
|
7
|
+
* organisations of the {{context.kebab}} context, read from the database. An organisation opened
|
|
8
|
+
* after the process started gets its run at the next occurrence, with no restart. `TENANTS` is
|
|
9
|
+
* not read here: it is the list of a project with no source of tenants.
|
|
10
|
+
*/
|
|
11
|
+
export function tenantDirectory(persistence: Persistence, _fixed: readonly string[] = []): TenantDirectory {
|
|
12
|
+
return new {{preset.adapter.pascal}}OrganisationTenantDirectory(persistence.database);
|
|
13
|
+
}
|
|
@@ -9,5 +9,8 @@ import type { {{name.pascal}}Result } from '{{alias.context}}/application/querie
|
|
|
9
9
|
@{{access.decoration}}
|
|
10
10
|
{{/if}}
|
|
11
11
|
export class {{name.pascal}}Query extends {{access.queryBase}}<{{name.pascal}}Result> {
|
|
12
|
+
{{#if access.resourceUnnamed}}
|
|
13
|
+
// {{access.resourceTodo}}
|
|
14
|
+
{{/if}}
|
|
12
15
|
// TODO(domain): declare the criteria of "{{name.words}}" as a constructor with readonly primitives (filters, page), for example `{{access.constructorSample}}`.
|
|
13
16
|
}
|
|
@@ -54,8 +54,12 @@ const application = composeApplication(
|
|
|
54
54
|
log: { ...config.log, service: config.serviceName, environment: config.environment },
|
|
55
55
|
traceConsumers: config.tracing.consumers,
|
|
56
56
|
resilience: config.resilience,
|
|
57
|
-
// A context run alone takes its jobs with it, and only its own.
|
|
57
|
+
// A context run alone takes its jobs with it, and only its own: the jobs of the platform stay with the whole application.
|
|
58
58
|
jobs: { start: config.runJobs, settings: jobSettings(process.env, '{{context.kebab}}') },
|
|
59
|
+
platformJobs: false,
|
|
60
|
+
{{#if tenancy.any}}
|
|
61
|
+
tenants: config.tenants,
|
|
62
|
+
{{/if}}
|
|
59
63
|
{{#if cache.redis}}
|
|
60
64
|
redis,
|
|
61
65
|
{{/if}}
|
|
@@ -7,7 +7,7 @@ import { errors } from '{{alias.platform}}/observability/errors{{alias.ext}}';
|
|
|
7
7
|
{{#if http.any}}
|
|
8
8
|
import { createAuthenticator } from '{{alias.platform}}/auth/authentication/create-authenticator{{alias.ext}}';
|
|
9
9
|
{{/if}}
|
|
10
|
-
import { composeApplication } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
|
|
10
|
+
import { composeApplication, hostedContexts } from '{{alias.platform}}/composition/compose-application{{alias.ext}}';
|
|
11
11
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
12
12
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
13
13
|
import { {{events.providerName}} } from '{{alias.platform}}/events/{{events.providerFile}}{{alias.ext}}';
|
|
@@ -31,26 +31,33 @@ const persistence = openPersistence();
|
|
|
31
31
|
const redis = openRedis(config);
|
|
32
32
|
{{/if}}
|
|
33
33
|
|
|
34
|
-
const application = composeApplication(
|
|
35
|
-
|
|
34
|
+
const application = composeApplication(
|
|
35
|
+
persistence,
|
|
36
|
+
{
|
|
37
|
+
events: {{events.provider}},
|
|
36
38
|
{{#if errors.sentry}}
|
|
37
|
-
|
|
39
|
+
errors,
|
|
38
40
|
{{/if}}
|
|
39
41
|
{{#if http.any}}
|
|
40
|
-
|
|
42
|
+
authenticator: createAuthenticator(config),
|
|
43
|
+
{{/if}}
|
|
44
|
+
log: { ...config.log, service: config.serviceName, environment: config.environment },
|
|
45
|
+
traceConsumers: config.tracing.consumers,
|
|
46
|
+
resilience: config.resilience,
|
|
47
|
+
// This process is the one that runs the jobs, whatever `RUN_JOBS` says to the others.
|
|
48
|
+
jobs: { start: true, settings: jobSettings(process.env) },
|
|
49
|
+
{{#if tenancy.any}}
|
|
50
|
+
tenants: config.tenants,
|
|
41
51
|
{{/if}}
|
|
42
|
-
log: { ...config.log, service: config.serviceName, environment: config.environment },
|
|
43
|
-
traceConsumers: config.tracing.consumers,
|
|
44
|
-
resilience: config.resilience,
|
|
45
|
-
// This process is the one that runs the jobs, whatever `RUN_JOBS` says to the others.
|
|
46
|
-
jobs: { start: true, settings: jobSettings(process.env) },
|
|
47
52
|
{{#if cache.redis}}
|
|
48
|
-
|
|
53
|
+
redis,
|
|
49
54
|
{{/if}}
|
|
50
55
|
{{#if files.any}}
|
|
51
|
-
|
|
56
|
+
files: openFiles(config.files),
|
|
52
57
|
{{/if}}
|
|
53
|
-
}
|
|
58
|
+
},
|
|
59
|
+
hostedContexts,
|
|
60
|
+
);
|
|
54
61
|
|
|
55
62
|
await application.start();
|
|
56
63
|
application.logger.info('started', { process: 'worker' });
|