ddd-ts-kit 0.108.0 → 0.109.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 +10 -0
- package/README.fr.md +3 -2
- package/README.md +2 -1
- package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
- package/dist/check/catalogue/architecture-rules.js +2 -0
- package/dist/check/catalogue/architecture-rules.js.map +1 -1
- package/dist/check/explain/persistence-docs.d.ts.map +1 -1
- package/dist/check/explain/persistence-docs.js +18 -0
- package/dist/check/explain/persistence-docs.js.map +1 -1
- package/dist/check/fixtures/files-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/files-fixtures.js +77 -0
- package/dist/check/fixtures/files-fixtures.js.map +1 -1
- package/dist/check/rules/search-store-from-platform.d.ts +3 -0
- package/dist/check/rules/search-store-from-platform.d.ts.map +1 -0
- package/dist/check/rules/search-store-from-platform.js +93 -0
- package/dist/check/rules/search-store-from-platform.js.map +1 -0
- 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/known-stack-keys.d.ts +1 -1
- package/dist/config/known-stack-keys.d.ts.map +1 -1
- package/dist/config/known-stack-keys.js +1 -0
- package/dist/config/known-stack-keys.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 +9 -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/help/usage.js +1 -1
- package/dist/init/files/platform-files.d.ts.map +1 -1
- package/dist/init/files/platform-files.js +11 -0
- package/dist/init/files/platform-files.js.map +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.d.ts.map +1 -1
- package/dist/init/manifest/versions.js +25 -24
- package/dist/init/manifest/versions.js.map +1 -1
- package/dist/init/stack/resolve-operations.d.ts +12 -0
- package/dist/init/stack/resolve-operations.d.ts.map +1 -0
- package/dist/init/stack/resolve-operations.js +23 -0
- package/dist/init/stack/resolve-operations.js.map +1 -0
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +2 -19
- 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/init/template-vars.d.ts.map +1 -1
- package/dist/init/template-vars.js +6 -4
- package/dist/init/template-vars.js.map +1 -1
- package/dist/stack/stack-vars.js +5 -3
- 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 +6 -5
- package/templates/init/README.md.tpl +20 -0
- package/templates/init/docker/docker-compose.yml.tpl +24 -0
- package/templates/init/docker/env.example.tpl +9 -0
- package/templates/init/e2e/test-environment.ts.tpl +4 -0
- package/templates/init/main.ts.tpl +3 -0
- package/templates/init/platform/composition/compose-application.container.ts.tpl +13 -0
- package/templates/init/platform/composition/compose-application.manual.ts.tpl +4 -0
- package/templates/init/platform/composition/lay-foundations.container.ts.tpl +30 -0
- package/templates/init/platform/composition/lay-foundations.manual.ts.tpl +11 -0
- package/templates/init/platform/composition/platform-options.manual.ts.tpl +7 -0
- package/templates/init/platform/composition/platform.manual.ts.tpl +7 -0
- package/templates/init/platform/config/app-config.ts.tpl +13 -0
- package/templates/init/platform/config/load-config.ts.tpl +38 -3
- package/templates/init/platform/search/open-search.ts.tpl +88 -0
- package/templates/init/platform/search/provisioned-indexes.ts.tpl +134 -0
- package/templates/init/platform/search/search-indexes.ts.tpl +23 -0
- package/templates/init/platform/search/search-name-taken-error.ts.tpl +10 -0
- package/templates/init/platform/search/search.module.container.ts.tpl +17 -0
- package/templates/init/platform/search/store-index.ts.tpl +49 -0
- package/templates/init/rules/infrastructure.md.tpl +3 -0
- package/templates/init/rules/platform.md.tpl +3 -0
- package/templates/init/scripts/privacy-erase.container.ts.tpl +9 -0
- package/templates/init/scripts/privacy-erase.manual.ts.tpl +9 -0
- package/templates/init/scripts/privacy-export.container.ts.tpl +9 -0
- package/templates/init/scripts/privacy-export.manual.ts.tpl +9 -0
- package/templates/init/scripts/privacy-purge.container.ts.tpl +9 -0
- package/templates/init/scripts/privacy-purge.manual.ts.tpl +9 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/service/main.ts.tpl +3 -0
- package/templates/worker/main.ts.tpl +3 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two stores built under one name with another definition or other fields: they would share the
|
|
3
|
+
* indices and aliases of that name. Each name starts with its context (`billing_invoices`).
|
|
4
|
+
*/
|
|
5
|
+
export class SearchNameTakenError extends Error {
|
|
6
|
+
constructor(readonly readModel: string) {
|
|
7
|
+
super(`the search read model "${readModel}" is already built with another definition or other fields`);
|
|
8
|
+
this.name = 'SearchNameTakenError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineContextModule, type ContextModule } from '@ddd-ts-kit/di';
|
|
2
|
+
import { SearchIndexes } from '{{alias.platform}}/search/search-indexes{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The read models of OpenSearch as a capability of the platform: `SearchIndexes`, which the
|
|
6
|
+
* adapter of a read model port names in its constructor, and the provisioning of the index of
|
|
7
|
+
* every store built by then, at the start.
|
|
8
|
+
*/
|
|
9
|
+
export function searchModule(search: SearchIndexes): ContextModule {
|
|
10
|
+
return defineContextModule({
|
|
11
|
+
name: 'search',
|
|
12
|
+
register(builder) {
|
|
13
|
+
builder.bind(SearchIndexes).toValue(search);
|
|
14
|
+
},
|
|
15
|
+
onStart: () => search.provision(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { OpenSearchReadModelStore } from '@ddd-ts-kit/opensearch';
|
|
2
|
+
|
|
3
|
+
/** What provisions the index of a store: the store itself, built on the transport of the platform. */
|
|
4
|
+
type Provisioned = Pick<OpenSearchReadModelStore<object>, 'ensureMapping' | 'provision'>;
|
|
5
|
+
|
|
6
|
+
/** The index of one store, provisioned once, or once per tenant: an attempt that failed is made again at the next request. */
|
|
7
|
+
export class StoreIndex {
|
|
8
|
+
private mapping: Promise<void> | undefined;
|
|
9
|
+
private readonly tenants = new Map<string, Promise<void>>();
|
|
10
|
+
|
|
11
|
+
constructor(private readonly store: Provisioned) {}
|
|
12
|
+
|
|
13
|
+
/** Whether the tenant was provisioned, or is being. */
|
|
14
|
+
has(tenant: string): boolean {
|
|
15
|
+
return this.tenants.has(tenant);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Without tenancy: the index and its alias. */
|
|
19
|
+
mapped(): Promise<void> {
|
|
20
|
+
this.mapping ??= this.store.ensureMapping().catch((error: unknown) => {
|
|
21
|
+
this.mapping = undefined;
|
|
22
|
+
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return this.mapping;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Under a tenant strategy: the index or the filtered alias of one tenant; its failure is its own. */
|
|
30
|
+
provisioned(tenant: string): Promise<void> {
|
|
31
|
+
const known = this.tenants.get(tenant);
|
|
32
|
+
|
|
33
|
+
if (known !== undefined) {
|
|
34
|
+
return known;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const provisioning = Promise.resolve()
|
|
38
|
+
.then(() => this.store.provision(tenant))
|
|
39
|
+
.catch((error: unknown) => {
|
|
40
|
+
this.tenants.delete(tenant);
|
|
41
|
+
|
|
42
|
+
throw error;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
this.tenants.set(tenant, provisioning);
|
|
46
|
+
|
|
47
|
+
return provisioning;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -34,6 +34,9 @@ paths:
|
|
|
34
34
|
{{#if eventSourcing.on}}
|
|
35
35
|
- The repository adapter of an event-sourced aggregate delegates to `EventSourcedRepository` of the kernel. Its stored events are declared in `persistence/<aggregate>-events.mapper.ts` with `defineStoredEvent` and a named type of their data; a change of that type is a new version with its upcaster, never an edit (`event-sourcing/upcaster-required`, against `stored-events.lock.json`, which `ddd-ts-kit docs --stored-events` writes once the shape of a version is final; `docs --check` fails while a version is unrecorded). Every named type the data reaches is declared in the codec file too.
|
|
36
36
|
{{/if}}
|
|
37
|
+
{{#if search.opensearch}}
|
|
38
|
+
- A read model kept in OpenSearch is written by hand, no generator yet: `class SearchInvoiceList extends OpenSearchReadModelStore<InvoiceRow> implements InvoiceList`, whose constructor takes `SearchIndexes` of the platform and calls `super(search.options('billing_invoices', invoiceCriteria))`; its name starts with the context, and nothing else of `@ddd-ts-kit/opensearch` is named here (`search/store-from-platform`). It is a copy for reading, written by its projection (`upsertIfNewer` with the stamp of the event, `delete` that keeps a tombstone) and rebuilt from the events: never read to decide an invariant or a right. It passes `readModelRowsContract` and `criteriaContract` of `@ddd-ts-kit/testing/contracts`, on a node the run names (`OPENSEARCH_URL`); the specs of the context bind its port to `InMemoryReadModelStore` of the kernel.
|
|
39
|
+
{{/if}}
|
|
37
40
|
- Infrastructure faults are plain errors (a 5xx, reported from outside); business refusals are `DomainError`s raised by the domain.
|
|
38
41
|
- Every adapter passes the contract suite of the fake of its port (`test/integration/*.contract.spec.ts`).
|
|
39
42
|
- Method: `/ddd-ts-kit:persistence`. Create with `npx ddd-ts-kit generate repository|adapter|gateway|acl ... --json`.
|
|
@@ -24,6 +24,9 @@ paths:
|
|
|
24
24
|
{{#if files.any}}
|
|
25
25
|
- Files: `files/open-files.ts` opens the connector of `stack.storage` from `config/read-files.ts`{{#if di.container}}, `files/files.module.ts` binds the ports and the hourly purge of staged files, `files/staging-uploads.ts` stages the file a command carries on the command bus, before the transaction{{/if}}{{#unless di.container}}, `files/create-files.ts` builds them, `composition/compose-application.ts` registers the hourly purge of staged files and `buses/create-command-bus.ts` stages the file a command carries on the command bus, before the transaction{{/unless}}; the tools and the tests keep files in memory. A scanner of your own (an antivirus) is bound here, never called from a use case.
|
|
26
26
|
{{/if}}
|
|
27
|
+
{{#if search.opensearch}}
|
|
28
|
+
- Search: `search/open-search.ts` builds `SearchIndexes` from `config.search`, with the transport and the tenancy of the project{{#if tenancy.any}} (`attribute`: one index, a filtered alias per tenant; `index` there gives each tenant its own){{/if}}{{#if di.container}}, `search/search.module.ts` binds it{{/if}}{{#unless di.container}}, `platform.search` hands it to each context{{/unless}}, and the index of every store built from it is provisioned before its first request. No context opens a transport or sets a tenancy of its own (`search/store-from-platform`). In production the security plugin stays on, with TLS and a user allowed on the indices and aliases of this project only.
|
|
29
|
+
{{/if}}
|
|
27
30
|
- `@ddd-ts-kit/tracing` and `@opentelemetry/*` are imported here and nowhere else (`tracing/platform-only`).
|
|
28
31
|
- Logs, spans and error reports carry identifiers and codes only: never arguments, payloads, error messages, nor anything personal beyond the id of the actor.
|
|
29
32
|
- Configuration is read here only, by `config/load-config.ts`: validated, fail fast, every problem named by its variable. A new variable joins `AppConfig` and `.env.example`. `RUN_JOBS` says whether a process runs the jobs, `jobs/job-settings.ts` what configuration changes of each.
|
|
@@ -13,6 +13,11 @@ import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
|
13
13
|
{{#if queue.redis}}
|
|
14
14
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
15
15
|
{{/if}}
|
|
16
|
+
{{#unless queue.redis}}
|
|
17
|
+
{{#if search.opensearch}}
|
|
18
|
+
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
19
|
+
{{/if}}
|
|
20
|
+
{{/unless}}
|
|
16
21
|
{{/unless}}
|
|
17
22
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
18
23
|
{{#if tenancy.any}}
|
|
@@ -86,6 +91,10 @@ const application = composeApplication(persistence, {
|
|
|
86
91
|
{{#if http.any}}
|
|
87
92
|
authenticator: offlineAuthenticator,
|
|
88
93
|
{{/if}}
|
|
94
|
+
{{#if search.opensearch}}
|
|
95
|
+
// The copies of a person in the read models of OpenSearch are reached on the node of the application.
|
|
96
|
+
search: loadConfig(process.env).search,
|
|
97
|
+
{{/if}}
|
|
89
98
|
{{#if queue.redis}}
|
|
90
99
|
redis,
|
|
91
100
|
{{/if}}
|
|
@@ -13,6 +13,11 @@ import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
|
13
13
|
{{#if queue.redis}}
|
|
14
14
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
15
15
|
{{/if}}
|
|
16
|
+
{{#unless queue.redis}}
|
|
17
|
+
{{#if search.opensearch}}
|
|
18
|
+
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
19
|
+
{{/if}}
|
|
20
|
+
{{/unless}}
|
|
16
21
|
{{/unless}}
|
|
17
22
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
18
23
|
{{#if tenancy.any}}
|
|
@@ -86,6 +91,10 @@ const application = composeApplication(persistence, {
|
|
|
86
91
|
{{#if http.any}}
|
|
87
92
|
authenticator: offlineAuthenticator,
|
|
88
93
|
{{/if}}
|
|
94
|
+
{{#if search.opensearch}}
|
|
95
|
+
// The copies of a person in the read models of OpenSearch are reached on the node of the application.
|
|
96
|
+
search: loadConfig(process.env).search,
|
|
97
|
+
{{/if}}
|
|
89
98
|
{{#if queue.redis}}
|
|
90
99
|
redis,
|
|
91
100
|
{{/if}}
|
|
@@ -8,6 +8,11 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
8
8
|
{{#if persistence.needsUrl}}
|
|
9
9
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
10
10
|
{{/if}}
|
|
11
|
+
{{#unless persistence.needsUrl}}
|
|
12
|
+
{{#if search.opensearch}}
|
|
13
|
+
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{/unless}}
|
|
11
16
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
12
17
|
{{#if tenancy.any}}
|
|
13
18
|
import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
|
|
@@ -57,6 +62,10 @@ const application = composeApplication(persistence, {
|
|
|
57
62
|
{{#if http.any}}
|
|
58
63
|
authenticator: offlineAuthenticator,
|
|
59
64
|
{{/if}}
|
|
65
|
+
{{#if search.opensearch}}
|
|
66
|
+
// The copies of a person in the read models of OpenSearch are reached on the node of the application.
|
|
67
|
+
search: loadConfig(process.env).search,
|
|
68
|
+
{{/if}}
|
|
60
69
|
});
|
|
61
70
|
|
|
62
71
|
{{#if tenancy.any}}
|
|
@@ -8,6 +8,11 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
8
8
|
{{#if persistence.needsUrl}}
|
|
9
9
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
10
10
|
{{/if}}
|
|
11
|
+
{{#unless persistence.needsUrl}}
|
|
12
|
+
{{#if search.opensearch}}
|
|
13
|
+
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{/unless}}
|
|
11
16
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
12
17
|
{{#if tenancy.any}}
|
|
13
18
|
import { tenantDirectory } from '{{alias.platform}}/composition/tenant-directory{{alias.ext}}';
|
|
@@ -57,6 +62,10 @@ const application = composeApplication(persistence, {
|
|
|
57
62
|
{{#if http.any}}
|
|
58
63
|
authenticator: offlineAuthenticator,
|
|
59
64
|
{{/if}}
|
|
65
|
+
{{#if search.opensearch}}
|
|
66
|
+
// The copies of a person in the read models of OpenSearch are reached on the node of the application.
|
|
67
|
+
search: loadConfig(process.env).search,
|
|
68
|
+
{{/if}}
|
|
60
69
|
});
|
|
61
70
|
|
|
62
71
|
{{#if tenancy.any}}
|
|
@@ -9,6 +9,11 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
9
9
|
{{#if persistence.needsUrl}}
|
|
10
10
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
11
11
|
{{/if}}
|
|
12
|
+
{{#unless persistence.needsUrl}}
|
|
13
|
+
{{#if search.opensearch}}
|
|
14
|
+
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
15
|
+
{{/if}}
|
|
16
|
+
{{/unless}}
|
|
12
17
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
13
18
|
import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
|
|
14
19
|
import { runPurge } from '{{alias.platform}}/privacy/run-purge{{alias.ext}}';
|
|
@@ -37,6 +42,10 @@ const application = composeApplication(persistence, {
|
|
|
37
42
|
{{#if http.any}}
|
|
38
43
|
authenticator: offlineAuthenticator,
|
|
39
44
|
{{/if}}
|
|
45
|
+
{{#if search.opensearch}}
|
|
46
|
+
// The copies of a person in the read models of OpenSearch are reached on the node of the application.
|
|
47
|
+
search: loadConfig(process.env).search,
|
|
48
|
+
{{/if}}
|
|
40
49
|
});
|
|
41
50
|
|
|
42
51
|
const actor: Actor = { id: values.operator, type: 'user', roles: [], attributes: {} };
|
|
@@ -9,6 +9,11 @@ import { composeApplication } from '{{alias.platform}}/composition/compose-appli
|
|
|
9
9
|
{{#if persistence.needsUrl}}
|
|
10
10
|
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
11
11
|
{{/if}}
|
|
12
|
+
{{#unless persistence.needsUrl}}
|
|
13
|
+
{{#if search.opensearch}}
|
|
14
|
+
import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
|
|
15
|
+
{{/if}}
|
|
16
|
+
{{/unless}}
|
|
12
17
|
import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
|
|
13
18
|
import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
|
|
14
19
|
import { runPurge } from '{{alias.platform}}/privacy/run-purge{{alias.ext}}';
|
|
@@ -37,6 +42,10 @@ const application = composeApplication(persistence, {
|
|
|
37
42
|
{{#if http.any}}
|
|
38
43
|
authenticator: offlineAuthenticator,
|
|
39
44
|
{{/if}}
|
|
45
|
+
{{#if search.opensearch}}
|
|
46
|
+
// The copies of a person in the read models of OpenSearch are reached on the node of the application.
|
|
47
|
+
search: loadConfig(process.env).search,
|
|
48
|
+
{{/if}}
|
|
40
49
|
});
|
|
41
50
|
|
|
42
51
|
const actor: Actor = { id: values.operator, type: 'user', roles: [], attributes: {} };
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@biomejs/biome": "2.6.3",
|
|
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.109.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",
|