ddd-ts-kit 0.6.0 → 0.8.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/LICENSE +21 -0
- package/README.md +33 -9
- package/dist/check/canonical/roles.d.ts.map +1 -1
- package/dist/check/canonical/roles.js +1 -0
- package/dist/check/canonical/roles.js.map +1 -1
- package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
- package/dist/check/catalogue/architecture-rules.js +4 -0
- package/dist/check/catalogue/architecture-rules.js.map +1 -1
- package/dist/check/catalogue/eslint-only-rules.d.ts.map +1 -1
- package/dist/check/catalogue/eslint-only-rules.js +4 -0
- package/dist/check/catalogue/eslint-only-rules.js.map +1 -1
- package/dist/check/declarations/option-of.d.ts +2 -0
- package/dist/check/declarations/option-of.d.ts.map +1 -1
- package/dist/check/declarations/option-of.js +7 -1
- package/dist/check/declarations/option-of.js.map +1 -1
- package/dist/check/events/domain-event-names.d.ts +4 -1
- package/dist/check/events/domain-event-names.d.ts.map +1 -1
- package/dist/check/events/domain-event-names.js +6 -3
- package/dist/check/events/domain-event-names.js.map +1 -1
- package/dist/check/explain/language-docs.d.ts.map +1 -1
- package/dist/check/explain/language-docs.js +10 -0
- package/dist/check/explain/language-docs.js.map +1 -1
- package/dist/check/explain/rule-docs.d.ts.map +1 -1
- package/dist/check/explain/rule-docs.js +2 -0
- package/dist/check/explain/rule-docs.js.map +1 -1
- package/dist/check/explain/tenancy-docs.d.ts +3 -0
- package/dist/check/explain/tenancy-docs.d.ts.map +1 -0
- package/dist/check/explain/tenancy-docs.js +15 -0
- package/dist/check/explain/tenancy-docs.js.map +1 -0
- package/dist/check/fixtures/declarations-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/declarations-fixtures.js +31 -0
- package/dist/check/fixtures/declarations-fixtures.js.map +1 -1
- package/dist/check/fixtures/events-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/events-fixtures.js +8 -0
- package/dist/check/fixtures/events-fixtures.js.map +1 -1
- package/dist/check/fixtures/fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/fixtures.js +4 -0
- package/dist/check/fixtures/fixtures.js.map +1 -1
- package/dist/check/fixtures/tenancy-fixtures.d.ts +3 -0
- package/dist/check/fixtures/tenancy-fixtures.d.ts.map +1 -0
- package/dist/check/fixtures/tenancy-fixtures.js +136 -0
- package/dist/check/fixtures/tenancy-fixtures.js.map +1 -0
- package/dist/check/fixtures/vocabulary-fixtures.d.ts +3 -0
- package/dist/check/fixtures/vocabulary-fixtures.d.ts.map +1 -0
- package/dist/check/fixtures/vocabulary-fixtures.js +121 -0
- package/dist/check/fixtures/vocabulary-fixtures.js.map +1 -0
- package/dist/check/language/declared-value.d.ts +14 -0
- package/dist/check/language/declared-value.d.ts.map +1 -0
- package/dist/check/language/declared-value.js +2 -0
- package/dist/check/language/declared-value.js.map +1 -0
- package/dist/check/language/declared-vocabularies.d.ts +11 -0
- package/dist/check/language/declared-vocabularies.d.ts.map +1 -0
- package/dist/check/language/declared-vocabularies.js +99 -0
- package/dist/check/language/declared-vocabularies.js.map +1 -0
- package/dist/check/rules/declarations-role-declared.d.ts.map +1 -1
- package/dist/check/rules/declarations-role-declared.js +16 -3
- package/dist/check/rules/declarations-role-declared.js.map +1 -1
- package/dist/check/rules/language-declared-vocabulary.d.ts +3 -0
- package/dist/check/rules/language-declared-vocabulary.d.ts.map +1 -0
- package/dist/check/rules/language-declared-vocabulary.js +58 -0
- package/dist/check/rules/language-declared-vocabulary.js.map +1 -0
- package/dist/check/rules/tenancy-scoped-statement.d.ts +3 -0
- package/dist/check/rules/tenancy-scoped-statement.d.ts.map +1 -0
- package/dist/check/rules/tenancy-scoped-statement.js +37 -0
- package/dist/check/rules/tenancy-scoped-statement.js.map +1 -0
- package/dist/check/tenancy/balanced-arguments.d.ts +3 -0
- package/dist/check/tenancy/balanced-arguments.d.ts.map +1 -0
- package/dist/check/tenancy/balanced-arguments.js +13 -0
- package/dist/check/tenancy/balanced-arguments.js.map +1 -0
- package/dist/check/tenancy/declared-with.d.ts +11 -0
- package/dist/check/tenancy/declared-with.d.ts.map +1 -0
- package/dist/check/tenancy/declared-with.js +13 -0
- package/dist/check/tenancy/declared-with.js.map +1 -0
- package/dist/check/tenancy/drizzle-unscoped.d.ts +7 -0
- package/dist/check/tenancy/drizzle-unscoped.d.ts.map +1 -0
- package/dist/check/tenancy/drizzle-unscoped.js +35 -0
- package/dist/check/tenancy/drizzle-unscoped.js.map +1 -0
- package/dist/check/tenancy/executor-uses.d.ts +11 -0
- package/dist/check/tenancy/executor-uses.d.ts.map +1 -0
- package/dist/check/tenancy/executor-uses.js +14 -0
- package/dist/check/tenancy/executor-uses.js.map +1 -0
- package/dist/check/tenancy/knex-unscoped.d.ts +7 -0
- package/dist/check/tenancy/knex-unscoped.d.ts.map +1 -0
- package/dist/check/tenancy/knex-unscoped.js +19 -0
- package/dist/check/tenancy/knex-unscoped.js.map +1 -0
- package/dist/check/tenancy/unscoped-read-models.d.ts +4 -0
- package/dist/check/tenancy/unscoped-read-models.d.ts.map +1 -0
- package/dist/check/tenancy/unscoped-read-models.js +15 -0
- package/dist/check/tenancy/unscoped-read-models.js.map +1 -0
- package/dist/commands/generate.js +2 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +5 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/value-objects.d.ts +4 -0
- package/dist/commands/value-objects.d.ts.map +1 -0
- package/dist/commands/value-objects.js +44 -0
- package/dist/commands/value-objects.js.map +1 -0
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/parse-stack.d.ts.map +1 -1
- package/dist/config/parse-stack.js +4 -1
- package/dist/config/parse-stack.js.map +1 -1
- package/dist/config/stack.d.ts +26 -0
- package/dist/config/stack.d.ts.map +1 -1
- package/dist/config/stack.js +9 -0
- package/dist/config/stack.js.map +1 -1
- package/dist/config/written-stack.d.ts.map +1 -1
- package/dist/config/written-stack.js +6 -2
- package/dist/config/written-stack.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/event-name-reference.d.ts +9 -0
- package/dist/generate/kinds/event-name-reference.d.ts.map +1 -0
- package/dist/generate/kinds/event-name-reference.js +11 -0
- package/dist/generate/kinds/event-name-reference.js.map +1 -0
- package/dist/generate/kinds/event-vars.d.ts.map +1 -1
- package/dist/generate/kinds/event-vars.js +3 -1
- package/dist/generate/kinds/event-vars.js.map +1 -1
- package/dist/generate/kinds/generate-repository.js +5 -4
- package/dist/generate/kinds/generate-repository.js.map +1 -1
- package/dist/generate/kinds/integration-event-kind.d.ts.map +1 -1
- package/dist/generate/kinds/integration-event-kind.js +3 -1
- package/dist/generate/kinds/integration-event-kind.js.map +1 -1
- package/dist/generate/kinds/integration-handler-kind.js +13 -1
- package/dist/generate/kinds/integration-handler-kind.js.map +1 -1
- package/dist/generate/kinds/job/grant-system-actor.d.ts.map +1 -1
- package/dist/generate/kinds/job/grant-system-actor.js +21 -6
- package/dist/generate/kinds/job/grant-system-actor.js.map +1 -1
- package/dist/generate/kinds/job/permission-of.d.ts +9 -0
- package/dist/generate/kinds/job/permission-of.d.ts.map +1 -0
- package/dist/generate/kinds/job/permission-of.js +12 -0
- package/dist/generate/kinds/job/permission-of.js.map +1 -0
- package/dist/generate/kinds/route/group-vars.d.ts +5 -1
- package/dist/generate/kinds/route/group-vars.d.ts.map +1 -1
- package/dist/generate/kinds/route/group-vars.js +9 -5
- package/dist/generate/kinds/route/group-vars.js.map +1 -1
- package/dist/generate/kinds/route-group-kind.d.ts.map +1 -1
- package/dist/generate/kinds/route-group-kind.js +3 -2
- package/dist/generate/kinds/route-group-kind.js.map +1 -1
- package/dist/generate/kinds/vocabulary-kind.d.ts +3 -0
- package/dist/generate/kinds/vocabulary-kind.d.ts.map +1 -0
- package/dist/generate/kinds/vocabulary-kind.js +30 -0
- package/dist/generate/kinds/vocabulary-kind.js.map +1 -0
- package/dist/generate/kinds.d.ts.map +1 -1
- package/dist/generate/kinds.js +2 -0
- package/dist/generate/kinds.js.map +1 -1
- package/dist/generate/shared-writes.d.ts.map +1 -1
- package/dist/generate/shared-writes.js +5 -0
- package/dist/generate/shared-writes.js.map +1 -1
- package/dist/generate/vocabulary/declare-role.d.ts +13 -0
- package/dist/generate/vocabulary/declare-role.d.ts.map +1 -0
- package/dist/generate/vocabulary/declare-role.js +22 -0
- package/dist/generate/vocabulary/declare-role.js.map +1 -0
- package/dist/generate/vocabulary/entries-of.d.ts +4 -0
- package/dist/generate/vocabulary/entries-of.d.ts.map +1 -0
- package/dist/generate/vocabulary/entries-of.js +19 -0
- package/dist/generate/vocabulary/entries-of.js.map +1 -0
- package/dist/generate/vocabulary/vocabulary-entry.d.ts +6 -0
- package/dist/generate/vocabulary/vocabulary-entry.d.ts.map +1 -0
- package/dist/generate/vocabulary/vocabulary-entry.js +2 -0
- package/dist/generate/vocabulary/vocabulary-entry.js.map +1 -0
- package/dist/generate/vocabulary/vocabulary-text.d.ts +9 -0
- package/dist/generate/vocabulary/vocabulary-text.d.ts.map +1 -0
- package/dist/generate/vocabulary/vocabulary-text.js +28 -0
- package/dist/generate/vocabulary/vocabulary-text.js.map +1 -0
- package/dist/generate/with-import.d.ts +3 -0
- package/dist/generate/with-import.d.ts.map +1 -0
- package/dist/generate/with-import.js +12 -0
- package/dist/generate/with-import.js.map +1 -0
- package/dist/help/notes.d.ts +1 -1
- package/dist/help/notes.d.ts.map +1 -1
- package/dist/help/notes.js +3 -0
- package/dist/help/notes.js.map +1 -1
- package/dist/help/usage.d.ts +1 -1
- package/dist/help/usage.d.ts.map +1 -1
- package/dist/help/usage.js +2 -1
- package/dist/help/usage.js.map +1 -1
- package/dist/init/files/auth-files.js +2 -2
- package/dist/init/files/auth-files.js.map +1 -1
- package/dist/init/manifest/versions.js +23 -23
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +7 -1
- package/dist/init/stack/resolve-stack.js.map +1 -1
- package/dist/init/stack/resolve-tenancy.d.ts +8 -0
- package/dist/init/stack/resolve-tenancy.d.ts.map +1 -0
- package/dist/init/stack/resolve-tenancy.js +31 -0
- package/dist/init/stack/resolve-tenancy.js.map +1 -0
- package/dist/init/stack/stack-options.d.ts +3 -0
- package/dist/init/stack/stack-options.d.ts.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +2 -0
- package/dist/run.js.map +1 -1
- package/dist/stack/stack-vars.d.ts.map +1 -1
- package/dist/stack/stack-vars.js +4 -1
- package/dist/stack/stack-vars.js.map +1 -1
- package/dist/value-objects/apply-edits.d.ts +4 -0
- package/dist/value-objects/apply-edits.d.ts.map +1 -0
- package/dist/value-objects/apply-edits.js +7 -0
- package/dist/value-objects/apply-edits.js.map +1 -0
- package/dist/value-objects/closing-angle.d.ts +6 -0
- package/dist/value-objects/closing-angle.d.ts.map +1 -0
- package/dist/value-objects/closing-angle.js +18 -0
- package/dist/value-objects/closing-angle.js.map +1 -0
- package/dist/value-objects/edit.d.ts +7 -0
- package/dist/value-objects/edit.d.ts.map +1 -0
- package/dist/value-objects/edit.js +2 -0
- package/dist/value-objects/edit.js.map +1 -0
- package/dist/value-objects/first-type-argument.d.ts +3 -0
- package/dist/value-objects/first-type-argument.d.ts.map +1 -0
- package/dist/value-objects/first-type-argument.js +21 -0
- package/dist/value-objects/first-type-argument.js.map +1 -0
- package/dist/value-objects/inline-results.d.ts +7 -0
- package/dist/value-objects/inline-results.d.ts.map +1 -0
- package/dist/value-objects/inline-results.js +56 -0
- package/dist/value-objects/inline-results.js.map +1 -0
- package/dist/value-objects/is-asserted-use.d.ts +14 -0
- package/dist/value-objects/is-asserted-use.d.ts.map +1 -0
- package/dist/value-objects/is-asserted-use.js +28 -0
- package/dist/value-objects/is-asserted-use.js.map +1 -0
- package/dist/value-objects/is-converted-call.d.ts +12 -0
- package/dist/value-objects/is-converted-call.d.ts.map +1 -0
- package/dist/value-objects/is-converted-call.js +46 -0
- package/dist/value-objects/is-converted-call.js.map +1 -0
- package/dist/value-objects/leftovers.d.ts +6 -0
- package/dist/value-objects/leftovers.d.ts.map +1 -0
- package/dist/value-objects/leftovers.js +16 -0
- package/dist/value-objects/leftovers.js.map +1 -0
- package/dist/value-objects/refusal-assertions.d.ts +8 -0
- package/dist/value-objects/refusal-assertions.d.ts.map +1 -0
- package/dist/value-objects/refusal-assertions.js +65 -0
- package/dist/value-objects/refusal-assertions.js.map +1 -0
- package/dist/value-objects/refusal-code.d.ts +7 -0
- package/dist/value-objects/refusal-code.d.ts.map +1 -0
- package/dist/value-objects/refusal-code.js +10 -0
- package/dist/value-objects/refusal-code.js.map +1 -0
- package/dist/value-objects/result-method-declarations.d.ts +19 -0
- package/dist/value-objects/result-method-declarations.d.ts.map +1 -0
- package/dist/value-objects/result-method-declarations.js +28 -0
- package/dist/value-objects/result-method-declarations.js.map +1 -0
- package/dist/value-objects/result-methods.d.ts +8 -0
- package/dist/value-objects/result-methods.d.ts.map +1 -0
- package/dist/value-objects/result-methods.js +2 -0
- package/dist/value-objects/result-methods.js.map +1 -0
- package/dist/value-objects/rewrite-usages.d.ts +10 -0
- package/dist/value-objects/rewrite-usages.d.ts.map +1 -0
- package/dist/value-objects/rewrite-usages.js +20 -0
- package/dist/value-objects/rewrite-usages.js.map +1 -0
- package/dist/value-objects/rewrite.d.ts +6 -0
- package/dist/value-objects/rewrite.d.ts.map +1 -0
- package/dist/value-objects/rewrite.js +2 -0
- package/dist/value-objects/rewrite.js.map +1 -0
- package/dist/value-objects/statement-end.d.ts +3 -0
- package/dist/value-objects/statement-end.d.ts.map +1 -0
- package/dist/value-objects/statement-end.js +19 -0
- package/dist/value-objects/statement-end.js.map +1 -0
- package/dist/value-objects/ternary-returns.d.ts +7 -0
- package/dist/value-objects/ternary-returns.d.ts.map +1 -0
- package/dist/value-objects/ternary-returns.js +59 -0
- package/dist/value-objects/ternary-returns.js.map +1 -0
- package/dist/value-objects/throwing-source.d.ts +17 -0
- package/dist/value-objects/throwing-source.d.ts.map +1 -0
- package/dist/value-objects/throwing-source.js +55 -0
- package/dist/value-objects/throwing-source.js.map +1 -0
- package/dist/value-objects/throwing-value-objects.d.ts +23 -0
- package/dist/value-objects/throwing-value-objects.d.ts.map +1 -0
- package/dist/value-objects/throwing-value-objects.js +68 -0
- package/dist/value-objects/throwing-value-objects.js.map +1 -0
- package/dist/value-objects/tidy-imports.d.ts +6 -0
- package/dist/value-objects/tidy-imports.d.ts.map +1 -0
- package/dist/value-objects/tidy-imports.js +54 -0
- package/dist/value-objects/tidy-imports.js.map +1 -0
- package/dist/value-objects/without-unwrap.d.ts +5 -0
- package/dist/value-objects/without-unwrap.d.ts.map +1 -0
- package/dist/value-objects/without-unwrap.js +32 -0
- package/dist/value-objects/without-unwrap.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/templates/domain-event/domain-event.ts.tpl +3 -1
- package/templates/event-handler/event-handler.declared.ts.tpl +1 -1
- package/templates/event-handler/event-handler.spec.ts.tpl +1 -1
- package/templates/event-handler/wiring.manual.tpl +2 -2
- package/templates/event-handler/wiring.tsyringe.tpl +2 -2
- package/templates/init/platform/audit/audit.module.manual.ts.tpl +5 -0
- package/templates/init/platform/audit/audit.module.tsyringe.ts.tpl +5 -0
- package/templates/init/platform/audit/create-audit.ts.tpl +24 -0
- package/templates/init/platform/audit/search-audit-entries.handler.ts.tpl +13 -0
- package/templates/init/platform/audit/search-audit-entries.query.ts.tpl +5 -0
- package/templates/init/platform/auth/attribute-policies.ts.tpl +2 -1
- package/templates/init/platform/auth/create-authorizer.rbac.ts.tpl +2 -1
- package/templates/init/platform/auth/http-boundary.ts.tpl +38 -1
- package/templates/init/platform/auth/role.ts.tpl +14 -0
- package/templates/init/platform/auth/roles.ts.tpl +4 -3
- package/templates/init/platform/compose-application.manual.ts.tpl +3 -0
- package/templates/init/platform/compose-application.tsyringe.ts.tpl +14 -0
- package/templates/init/platform/database/persistence-over.knex.ts.tpl +5 -0
- package/templates/init/platform/database/schema.drizzle.ts.tpl +8 -0
- package/templates/init/platform/database/schema.knex.ts.tpl +6 -0
- package/templates/init/rules/application.md.tpl +3 -0
- package/templates/init/rules/domain.md.tpl +14 -4
- package/templates/init/rules/infrastructure.md.tpl +3 -0
- package/templates/init/scripts/events.ts.tpl +17 -4
- package/templates/integration-event/publisher.declared.ts.tpl +1 -1
- package/templates/integration-event/wiring.manual.tpl +1 -1
- package/templates/integration-event/wiring.tsyringe.tpl +1 -1
- package/templates/integration-handler/integration-handler.declared.ts.tpl +1 -1
- package/templates/integration-handler/integration-handler.ts.tpl +8 -1
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/repository/drizzle/repository.ts.tpl +7 -8
- package/templates/repository/knex/repository.ts.tpl +32 -12
- package/templates/value-object/value-object.spec.ts.tpl +16 -0
- package/templates/value-object/value-object.ts.tpl +22 -0
|
@@ -6,7 +6,7 @@ const {{event.camel}}EventHandler = platform.adapter(new {{event.pascal}}EventHa
|
|
|
6
6
|
|
|
7
7
|
{{#if handler.afterCommit}}
|
|
8
8
|
platform.domainEvents.on(
|
|
9
|
-
|
|
9
|
+
{{event.reference}},
|
|
10
10
|
async (event) => {
|
|
11
11
|
if (event instanceof {{event.pascal}}) {
|
|
12
12
|
await {{event.camel}}EventHandler.handle(event);
|
|
@@ -16,7 +16,7 @@ platform.domainEvents.on(
|
|
|
16
16
|
);
|
|
17
17
|
{{/if}}
|
|
18
18
|
{{#unless handler.afterCommit}}
|
|
19
|
-
platform.domainEvents.on(
|
|
19
|
+
platform.domainEvents.on({{event.reference}}, async (event) => {
|
|
20
20
|
if (event instanceof {{event.pascal}}) {
|
|
21
21
|
await {{event.camel}}EventHandler.handle(event);
|
|
22
22
|
}
|
|
@@ -7,7 +7,7 @@ builder.bind({{event.pascal}}EventHandler).toClass({{event.pascal}}EventHandler)
|
|
|
7
7
|
@@start
|
|
8
8
|
{{#if handler.afterCommit}}
|
|
9
9
|
resolve(DomainEventDispatcher).on(
|
|
10
|
-
|
|
10
|
+
{{event.reference}},
|
|
11
11
|
async (event) => {
|
|
12
12
|
if (event instanceof {{event.pascal}}) {
|
|
13
13
|
await resolve({{event.pascal}}EventHandler).handle(event);
|
|
@@ -17,7 +17,7 @@ resolve(DomainEventDispatcher).on(
|
|
|
17
17
|
);
|
|
18
18
|
{{/if}}
|
|
19
19
|
{{#unless handler.afterCommit}}
|
|
20
|
-
resolve(DomainEventDispatcher).on(
|
|
20
|
+
resolve(DomainEventDispatcher).on({{event.reference}}, async (event) => {
|
|
21
21
|
if (event instanceof {{event.pascal}}) {
|
|
22
22
|
await resolve({{event.pascal}}EventHandler).handle(event);
|
|
23
23
|
}
|
|
@@ -29,7 +29,12 @@ interface AuditWiring {
|
|
|
29
29
|
* use case so that reading the trail is authorized and recorded.
|
|
30
30
|
*/
|
|
31
31
|
export function auditModule(platform: Platform): AuditWiring {
|
|
32
|
+
{{#if tenancy.any}}
|
|
33
|
+
platform.queries.register(SearchAuditEntriesQuery, new SearchAuditEntriesHandler(platform.audit.reader), {
|
|
34
|
+
{{/if}}
|
|
35
|
+
{{#unless tenancy.any}}
|
|
32
36
|
platform.queries.register(SearchAuditEntriesQuery, new SearchAuditEntriesHandler(platform.audit.trail), {
|
|
37
|
+
{{/unless}}
|
|
33
38
|
context: 'audit',
|
|
34
39
|
});
|
|
35
40
|
|
|
@@ -22,7 +22,12 @@ export function auditModule(audit: Audit): ContextModule {
|
|
|
22
22
|
name: 'audit',
|
|
23
23
|
register(builder) {
|
|
24
24
|
builder.bind(AuditTrail).toValue(audit.trail);
|
|
25
|
+
{{#if tenancy.any}}
|
|
26
|
+
builder.bind(AuditReader).toValue(audit.reader);
|
|
27
|
+
{{/if}}
|
|
28
|
+
{{#unless tenancy.any}}
|
|
25
29
|
builder.bind(AuditReader).toValue(audit.trail);
|
|
30
|
+
{{/unless}}
|
|
26
31
|
{{#if audit.route}}
|
|
27
32
|
{{#if authz.rebac}}
|
|
28
33
|
|
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
{{#if audit.sql}}
|
|
2
2
|
import {
|
|
3
|
+
{{#if tenancy.any}}
|
|
4
|
+
TenantAuditReader,
|
|
5
|
+
{{/if}}
|
|
3
6
|
auditDecisions,
|
|
7
|
+
auditGuardRefusals,
|
|
4
8
|
auditIntegrationEvents,
|
|
5
9
|
auditMiddleware,
|
|
6
10
|
type AuditReader,
|
|
7
11
|
type AuditSource,
|
|
8
12
|
type AuditTrail,
|
|
13
|
+
type GuardRefusalOfARoute,
|
|
9
14
|
} from '@ddd-ts-kit/audit';
|
|
10
15
|
{{/if}}
|
|
11
16
|
{{#if audit.memory}}
|
|
12
17
|
import {
|
|
13
18
|
InMemoryAuditTrail,
|
|
19
|
+
{{#if tenancy.any}}
|
|
20
|
+
TenantAuditReader,
|
|
21
|
+
{{/if}}
|
|
14
22
|
auditDecisions,
|
|
23
|
+
auditGuardRefusals,
|
|
15
24
|
auditIntegrationEvents,
|
|
16
25
|
auditMiddleware,
|
|
17
26
|
type AuditReader,
|
|
18
27
|
type AuditSource,
|
|
19
28
|
type AuditTrail,
|
|
29
|
+
type GuardRefusalOfARoute,
|
|
20
30
|
} from '@ddd-ts-kit/audit';
|
|
21
31
|
{{/if}}
|
|
22
32
|
{{#if audit.knex}}
|
|
@@ -50,8 +60,18 @@ const consumer = 'audit';
|
|
|
50
60
|
*/
|
|
51
61
|
export interface Audit {
|
|
52
62
|
readonly trail: AuditTrail & AuditReader;
|
|
63
|
+
{{#if tenancy.any}}
|
|
64
|
+
/**
|
|
65
|
+
* The trail as the read side searches it: confined to the tenant of the work in progress,
|
|
66
|
+
* whatever the filter or the actor says. Platform staff read across tenants only inside
|
|
67
|
+
* `acrossTenants`, which records the elevation first; work in no tenant is refused.
|
|
68
|
+
*/
|
|
69
|
+
readonly reader: AuditReader;
|
|
70
|
+
{{/if}}
|
|
53
71
|
/** The `onDecision` hook of the authorization: who was allowed or refused what. */
|
|
54
72
|
readonly decisions: OnDecision;
|
|
73
|
+
/** The `onGuardRefusal` hook of the HTTP pipeline: who a guard refused at the edge, before any use case. */
|
|
74
|
+
readonly refusals: (refusal: GuardRefusalOfARoute) => Promise<void>;
|
|
55
75
|
/** On the command bus, before the unit of work: which command ran and how it ended. */
|
|
56
76
|
readonly commands: BusMiddleware;
|
|
57
77
|
/** On the query bus: whoever reads the trail leaves an entry in it. */
|
|
@@ -68,6 +88,10 @@ export function createAudit(persistence: Persistence, source: AuditSource): Audi
|
|
|
68
88
|
|
|
69
89
|
return {
|
|
70
90
|
trail,
|
|
91
|
+
{{#if tenancy.any}}
|
|
92
|
+
reader: new TenantAuditReader(trail, source.scope),
|
|
93
|
+
{{/if}}
|
|
94
|
+
refusals: auditGuardRefusals(trail, source),
|
|
71
95
|
{{#if audit.route}}
|
|
72
96
|
decisions: auditDecisions(trail, { ...source, sensitivePermissions: [auditPermissions['trail.read'].id] }),
|
|
73
97
|
// TODO(platform): declare what may go into `changes` with `fields: [auditedFields(SomeCommand, ['status'])]`; by default an entry carries identifiers and codes only.
|
|
@@ -5,6 +5,18 @@ import type { SearchAuditEntriesQuery } from '{{alias.platform}}/audit/search-au
|
|
|
5
5
|
export class SearchAuditEntriesHandler implements QueryHandler<SearchAuditEntriesQuery> {
|
|
6
6
|
constructor(private readonly reader: AuditReader) {}
|
|
7
7
|
|
|
8
|
+
{{#if tenancy.any}}
|
|
9
|
+
/**
|
|
10
|
+
* The permission was decided by the guard of the bus. The reader is the tenant audit reader
|
|
11
|
+
* of the platform: it bounds the read to the tenant of the work in progress, in the statement
|
|
12
|
+
* and never in memory, whatever the filter says. Platform staff read across tenants only
|
|
13
|
+
* through `acrossTenants`, never because their actor names no tenant.
|
|
14
|
+
*/
|
|
15
|
+
async execute(query: SearchAuditEntriesQuery): Promise<Page<AuditEntry>> {
|
|
16
|
+
return this.reader.search(query.filter, query.page);
|
|
17
|
+
}
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{#unless tenancy.any}}
|
|
8
20
|
/**
|
|
9
21
|
* The permission was decided by the guard of the bus. The tenant of the actor then bounds the
|
|
10
22
|
* read itself, in the statement and never in memory: a tenant lists its own chain, and only an
|
|
@@ -15,4 +27,5 @@ export class SearchAuditEntriesHandler implements QueryHandler<SearchAuditEntrie
|
|
|
15
27
|
|
|
16
28
|
return this.reader.search({ ...query.filter, ...(tenantId === undefined ? {} : { tenantId }) }, query.page);
|
|
17
29
|
}
|
|
30
|
+
{{/unless}}
|
|
18
31
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { AuditEntry, AuditFilter, AuditSortField } from '@ddd-ts-kit/audit';
|
|
2
2
|
import { AuthorizedQuery, type Actor, type Page, type PageRequest } from '@ddd-ts-kit/kernel';
|
|
3
3
|
|
|
4
|
+
{{#if tenancy.any}}
|
|
5
|
+
/** What a reader of the trail may narrow the search by. The tenant is the one of the work, never a filter. */
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#unless tenancy.any}}
|
|
4
8
|
/** What a reader of the trail may narrow the search by. The tenant is not among them: it is the one of the actor. */
|
|
9
|
+
{{/unless}}
|
|
5
10
|
export type AuditEntriesFilter = Pick<AuditFilter, 'actorId' | 'action' | 'outcome' | 'correlationId'>;
|
|
6
11
|
|
|
7
12
|
/** A page of the audit trail, for whoever holds `audit:trail.read`. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { permit, type AttributePolicy, type Condition } from '@ddd-ts-kit/auth';
|
|
2
|
+
import { Role } from '{{alias.platform}}/auth/role{{alias.ext}}';
|
|
2
3
|
|
|
3
|
-
const isAdministrator: Condition = ({ actor }) => actor.roles.includes(
|
|
4
|
+
const isAdministrator: Condition = ({ actor }) => actor.roles.includes(Role.Admin);
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The rules, over `{ actor, permission, resource, attributes, context, now }`. A matching `forbid`
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RoleBasedAuthorizer, type Authorizer } from '@ddd-ts-kit/auth';
|
|
2
|
+
import { Role } from '{{alias.platform}}/auth/role{{alias.ext}}';
|
|
2
3
|
import { roles } from '{{alias.platform}}/auth/roles{{alias.ext}}';
|
|
3
4
|
|
|
4
5
|
/** Roles: does one of the actor's roles grant this action? Another model is another adapter of the same port. */
|
|
5
6
|
export function createAuthorizer(): Authorizer {
|
|
6
|
-
return new RoleBasedAuthorizer({ roles, systemRole:
|
|
7
|
+
return new RoleBasedAuthorizer({ roles, systemRole: Role.System });
|
|
7
8
|
}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import type { Authenticator } from '@ddd-ts-kit/auth';
|
|
2
2
|
{{#if errors.none}}
|
|
3
|
-
import type { ErrorContext, ErrorMapper, RouteAround } from '@ddd-ts-kit/http';
|
|
3
|
+
import type { ErrorContext, ErrorMapper, {{#if audit.on}}GuardRefusal, {{/if}}RouteAround } from '@ddd-ts-kit/http';
|
|
4
4
|
import type { Clock, ExecutionScope, Logger, Session } from '@ddd-ts-kit/kernel';
|
|
5
5
|
{{/if}}
|
|
6
6
|
{{#if errors.sentry}}
|
|
7
|
+
{{#unless audit.on}}
|
|
7
8
|
import { reportHttpErrors, type ErrorContext, type ErrorMapper, type RouteAround } from '@ddd-ts-kit/http';
|
|
9
|
+
{{/unless}}
|
|
10
|
+
{{#if audit.on}}
|
|
11
|
+
import {
|
|
12
|
+
reportHttpErrors,
|
|
13
|
+
type ErrorContext,
|
|
14
|
+
type ErrorMapper,
|
|
15
|
+
type GuardRefusal,
|
|
16
|
+
type RouteAround,
|
|
17
|
+
} from '@ddd-ts-kit/http';
|
|
18
|
+
{{/if}}
|
|
8
19
|
import type { Clock, ErrorReporter, ExecutionScope, Logger, Session } from '@ddd-ts-kit/kernel';
|
|
9
20
|
{{/if}}
|
|
10
21
|
import { tracedRoutes } from '@ddd-ts-kit/tracing';
|
|
@@ -21,6 +32,10 @@ export interface HttpBoundary {
|
|
|
21
32
|
readonly onError: (error: unknown, context: ErrorContext) => void;
|
|
22
33
|
/** The span of a request, named by its route template; probes and documentation routes make none. */
|
|
23
34
|
readonly around: RouteAround;
|
|
35
|
+
{{#if audit.on}}
|
|
36
|
+
/** A request a guard refused at the edge, written to the audit trail as a denied decision. */
|
|
37
|
+
readonly onGuardRefusal: (refusal: GuardRefusal) => Promise<void>;
|
|
38
|
+
{{/if}}
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
interface Edge {
|
|
@@ -29,6 +44,10 @@ interface Edge {
|
|
|
29
44
|
readonly errorMapper: ErrorMapper;
|
|
30
45
|
readonly clock: Clock;
|
|
31
46
|
readonly logger: Logger;
|
|
47
|
+
{{#if audit.on}}
|
|
48
|
+
/** Where a refusal at the edge is recorded: the audit trail. */
|
|
49
|
+
readonly refusals: (refusal: GuardRefusal) => Promise<void>;
|
|
50
|
+
{{/if}}
|
|
32
51
|
{{#if errors.sentry}}
|
|
33
52
|
/** Where a request answered 5xx is reported, unless a bus already reported its failure. */
|
|
34
53
|
readonly errors: ErrorReporter;
|
|
@@ -37,7 +56,19 @@ interface Edge {
|
|
|
37
56
|
|
|
38
57
|
/** A request is authenticated once, then handled inside the execution scope, so infrastructure sees who acts and under which correlation. */
|
|
39
58
|
{{#if errors.none}}
|
|
59
|
+
{{#unless audit.on}}
|
|
40
60
|
export function httpBoundary({ authenticator, executionScope, errorMapper, clock, logger }: Edge): HttpBoundary {
|
|
61
|
+
{{/unless}}
|
|
62
|
+
{{#if audit.on}}
|
|
63
|
+
export function httpBoundary({
|
|
64
|
+
authenticator,
|
|
65
|
+
executionScope,
|
|
66
|
+
errorMapper,
|
|
67
|
+
clock,
|
|
68
|
+
logger,
|
|
69
|
+
refusals,
|
|
70
|
+
}: Edge): HttpBoundary {
|
|
71
|
+
{{/if}}
|
|
41
72
|
{{/if}}
|
|
42
73
|
{{#if errors.sentry}}
|
|
43
74
|
export function httpBoundary({
|
|
@@ -46,6 +77,9 @@ export function httpBoundary({
|
|
|
46
77
|
errorMapper,
|
|
47
78
|
clock,
|
|
48
79
|
logger,
|
|
80
|
+
{{#if audit.on}}
|
|
81
|
+
refusals,
|
|
82
|
+
{{/if}}
|
|
49
83
|
errors,
|
|
50
84
|
}: Edge): HttpBoundary {
|
|
51
85
|
const report = reportHttpErrors(errors);
|
|
@@ -57,6 +91,9 @@ export function httpBoundary({
|
|
|
57
91
|
errorMapper,
|
|
58
92
|
clock,
|
|
59
93
|
around: tracedRoutes(),
|
|
94
|
+
{{#if audit.on}}
|
|
95
|
+
onGuardRefusal: refusals,
|
|
96
|
+
{{/if}}
|
|
60
97
|
// The message of the error may quote data: only the code and the route are logged.
|
|
61
98
|
{{#if errors.none}}
|
|
62
99
|
onError: (_error, context) => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The roles a credential carries, each written once: a grant, a policy or a guard names one as
|
|
3
|
+
* `Role.Admin`, never as a string, and `generate route-group --role <role>` adds the role it
|
|
4
|
+
* requires.
|
|
5
|
+
*/
|
|
6
|
+
// TODO(platform): replace this starting point by the roles of the organisation.
|
|
7
|
+
export const Role = {
|
|
8
|
+
Admin: 'admin',
|
|
9
|
+
{{#if authz.rbac}}
|
|
10
|
+
System: 'system',
|
|
11
|
+
{{/if}}
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export type Role = (typeof Role)[keyof typeof Role];
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { Grant } from '@ddd-ts-kit/auth';
|
|
2
|
+
import { Role } from '{{alias.platform}}/auth/role{{alias.ext}}';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* What each role may do. A grant is a permission of a context (`billingPermissions['invoice.issue']`,
|
|
5
6
|
* imported from the permissions file of the context), its id, `<context>:*` or `*`. The roles of an
|
|
6
7
|
* actor come from its credential. Integration event handlers and scheduled jobs act as system
|
|
7
|
-
* actors, which carry no role: the authorizer gives them `
|
|
8
|
+
* actors, which carry no role: the authorizer gives them `Role.System`, and `generate job` adds there
|
|
8
9
|
* the permission of the command a job sends.
|
|
9
10
|
*/
|
|
10
11
|
// TODO(platform): replace this starting point by the roles of the organisation.
|
|
11
12
|
export const roles: Readonly<Record<string, readonly Grant[]>> = {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
[Role.Admin]: ['*'],
|
|
14
|
+
[Role.System]: [
|
|
14
15
|
// ddd-ts-kit:system-grants
|
|
15
16
|
// /ddd-ts-kit:system-grants
|
|
16
17
|
],
|
|
@@ -38,6 +38,11 @@ import {
|
|
|
38
38
|
{{#if http.any}}
|
|
39
39
|
ExecutionScope,
|
|
40
40
|
{{/if}}
|
|
41
|
+
{{#if audit.on}}
|
|
42
|
+
{{#if http.any}}
|
|
43
|
+
IdGenerator,
|
|
44
|
+
{{/if}}
|
|
45
|
+
{{/if}}
|
|
41
46
|
{{#unless broker.external}}
|
|
42
47
|
IntegrationEventSubscriber,
|
|
43
48
|
{{/unless}}
|
|
@@ -57,6 +62,9 @@ import {
|
|
|
57
62
|
} from '@ddd-ts-kit/kernel';
|
|
58
63
|
import { tracedPublisher } from '@ddd-ts-kit/tracing';
|
|
59
64
|
{{#if audit.on}}
|
|
65
|
+
{{#if http.any}}
|
|
66
|
+
import { AuditTrail, auditGuardRefusals } from '@ddd-ts-kit/audit';
|
|
67
|
+
{{/if}}
|
|
60
68
|
import { auditModule } from '{{alias.platform}}/audit/audit.module{{alias.ext}}';
|
|
61
69
|
{{/if}}
|
|
62
70
|
{{#if audit.functionRoute}}
|
|
@@ -232,6 +240,12 @@ function running(container: Container, options: ApplicationOptions, contexts: Co
|
|
|
232
240
|
errorMapper: container.resolve(ErrorMapper),
|
|
233
241
|
clock: container.resolve(Clock),
|
|
234
242
|
logger,
|
|
243
|
+
{{#if audit.on}}
|
|
244
|
+
refusals: auditGuardRefusals(container.resolve(AuditTrail), {
|
|
245
|
+
clock: container.resolve(Clock),
|
|
246
|
+
ids: container.resolve(IdGenerator),
|
|
247
|
+
}),
|
|
248
|
+
{{/if}}
|
|
235
249
|
{{#if errors.sentry}}
|
|
236
250
|
errors: container.resolve(ErrorReporter),
|
|
237
251
|
{{/if}}
|
|
@@ -10,7 +10,12 @@ export function persistenceOver(db: Knex, close: () => Promise<void>): Persisten
|
|
|
10
10
|
return {
|
|
11
11
|
unitOfWork,
|
|
12
12
|
database: unitOfWork,
|
|
13
|
+
{{#if tenancy.any}}
|
|
14
|
+
outbox: new KnexOutboxStore(unitOfWork, { schema: MESSAGING, tenant: true }),
|
|
15
|
+
{{/if}}
|
|
16
|
+
{{#unless tenancy.any}}
|
|
13
17
|
outbox: new KnexOutboxStore(unitOfWork, { schema: MESSAGING }),
|
|
18
|
+
{{/unless}}
|
|
14
19
|
processedEvents: new KnexProcessedEventStore(unitOfWork, { schema: MESSAGING }),
|
|
15
20
|
close,
|
|
16
21
|
};
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{{#if audit.on}}
|
|
2
2
|
import { auditChainsTable, auditEntriesTable } from '@ddd-ts-kit/audit/drizzle';
|
|
3
3
|
{{/if}}
|
|
4
|
+
{{#if tenancy.any}}
|
|
5
|
+
import { processedEventsTable, tenantOutboxTable } from '@ddd-ts-kit/drizzle/postgres';
|
|
6
|
+
|
|
7
|
+
/** It keeps the tenant of each event, so that its consumers run in that tenant. */
|
|
8
|
+
export const outbox = tenantOutboxTable('messaging');
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#unless tenancy.any}}
|
|
4
11
|
import { outboxTable, processedEventsTable } from '@ddd-ts-kit/drizzle/postgres';
|
|
5
12
|
|
|
6
13
|
export const outbox = outboxTable('messaging');
|
|
14
|
+
{{/unless}}
|
|
7
15
|
export const processedEvents = processedEventsTable('messaging');
|
|
8
16
|
{{#if audit.on}}
|
|
9
17
|
|
|
@@ -18,7 +18,13 @@ export const AUDIT_SCHEMA = 'audit';
|
|
|
18
18
|
* existing table goes into a migration of its own (`npm run db:generate <what-it-does>`).
|
|
19
19
|
*/
|
|
20
20
|
export const createTables = async (knex: Knex): Promise<void> => {
|
|
21
|
+
{{#if tenancy.any}}
|
|
22
|
+
// The tenant of each event, so that its consumers run in that tenant.
|
|
23
|
+
await createOutboxTables(knex, { schema: MESSAGING, tenant: true });
|
|
24
|
+
{{/if}}
|
|
25
|
+
{{#unless tenancy.any}}
|
|
21
26
|
await createOutboxTables(knex, { schema: MESSAGING });
|
|
27
|
+
{{/unless}}
|
|
22
28
|
{{#if audit.on}}
|
|
23
29
|
await createAuditTables(knex, { schema: AUDIT_SCHEMA });
|
|
24
30
|
{{/if}}
|
|
@@ -27,5 +27,8 @@ paths:
|
|
|
27
27
|
- A job (`scheduling/*.job.ts`) and an integration event handler (`integration/handlers/`) only build one command and send it as a system actor; both are safe to repeat (`scheduling/job-triggers-use-case`, `events/consumer-idempotent`).
|
|
28
28
|
- A query never saves, deletes or publishes (`application/command-query-separation`); it hands the access scope of the actor to its read port and never filters after loading.
|
|
29
29
|
- A read that takes criteria, a scope or a page is a search, never a list (`naming/search-not-list`): `Search<Things>Query` in `queries/search-<things>/` (`generate query ... --search`), `search...` on the port, its adapters and its fakes; one element or none stays `findById` or `findBy...`.
|
|
30
|
+
{{#if literals.named}}
|
|
31
|
+
- A permission, a role or a status is read from its declaration, `billingPermissions['invoice.issue']`, `InvoiceStatus.Issued`, never written as a string (`language/declared-vocabulary`); a number has a name (`clean/no-magic-number`).
|
|
32
|
+
{{/if}}
|
|
30
33
|
- Time through `Clock`, identifiers through `IdGenerator`, no `process.env` (`purity/*`). No logging, tracing, retry or audit call: they are applied from outside (`aspects/outside-in`, `tracing/platform-only`).
|
|
31
34
|
- A whole feature with `/ddd-ts-kit:use-case`. Create with `npx ddd-ts-kit generate command|query|port|policy|job|event-handler|integration-handler ... --json`, then fill the `TODO(domain)` places.
|
|
@@ -10,20 +10,30 @@ paths:
|
|
|
10
10
|
- Names come from the glossary of `CONTEXT.md`, written first (`language/glossary-term`); no `Manager`, `Helper`, `Data`, `Info`, `Model` (`language/no-technical-name`).
|
|
11
11
|
- Aggregate: private constructor, `create` for birth, `rehydrate` for loading, state changed by methods named after the business intention, no setter, no public mutable property (`domain/aggregate-encapsulation`). One aggregate per transaction; another one is referenced by its id.
|
|
12
12
|
- Value objects are immutable, validated in `create`, compared with `equals` (`domain/value-object-immutability`). An email, an amount, a period are types, not strings.
|
|
13
|
+
{{#if literals.named}}
|
|
14
|
+
- A closed list of values (a status, a kind, a role of the model) is a vocabulary, `npx ddd-ts-kit generate vocabulary <context> <Name> --value <value>...`: code reads `AppointmentStatus.NoShow`, never the string (`language/declared-vocabulary`).
|
|
15
|
+
- No number without a name: 0, 1, -1 and an index only; a duration, a limit or a rate is a constant of the module (`const MINUTES_PER_HOUR = 60;`) or a value object (`clean/no-magic-number`).
|
|
16
|
+
{{/if}}
|
|
13
17
|
{{#if refusals.factories}}
|
|
14
18
|
- A violated invariant throws a refusal built by a static factory of the error class of its concept, never `new` and never a bare `Error`: `throw InvoiceError.alreadyIssued(this.id)` (`errors/through-factory`, `domain/no-generic-error`). One class per concept of the glossary in `domain/errors/`, extending `ConceptError`, no constructor (`errors/constructor-not-public`); a factory is named after the refusal and its code says the same words (`errors/factory-name`), one code per refusal of the context (`errors/code-unique`).
|
|
15
|
-
- A factory takes the facts of the refusal as typed parameters and gives them to `refusal(code, message, facts)`. Facts are private: one reaches a client only when the factory names it, `.exposing('<fact>')`, and never when it identifies a person.
|
|
19
|
+
- A factory takes the facts of the refusal as typed parameters and gives them to `refusal(code, message, facts)`. Facts are private: one reaches a client only when the factory names it, `.exposing('<fact>')`, and never when it identifies a person.
|
|
16
20
|
{{/if}}
|
|
17
21
|
{{#if refusals.classes}}
|
|
18
22
|
- A violated invariant throws a `DomainError` of `domain/errors/` with a stable `code`, never a bare `Error` (`domain/no-generic-error`).
|
|
19
23
|
{{/if}}
|
|
24
|
+
{{#if valueObjects.throwing}}
|
|
25
|
+
- A value object refuses in `create` as the rest of the domain does: it returns the value object or throws the refusal of the concept it describes{{#if refusals.factories}} (`throw PersonError.invalidEmail(raw)`){{/if}}. The caller takes the value as it is, with no `unwrap`; a spec asserts the refusal with `expectRefusal(() => Email.create(raw), 'INVALID_EMAIL')`.
|
|
26
|
+
{{/if}}
|
|
27
|
+
{{#if valueObjects.result}}
|
|
28
|
+
- A value object returns its refusals in the `Result` of `create`{{#if refusals.factories}}: `err(PersonError.invalidEmail(raw))`{{/if}}; the caller unwraps it with `unwrap(..)` of the kernel. `npx ddd-ts-kit value-objects` moves the project to factories that throw.
|
|
29
|
+
{{/if}}
|
|
20
30
|
- Domain events are named in the past tense, `<context>.<aggregate>.<fact>` (`events/name-format`), and recorded by the aggregate (`this.record(...)`). They leave with the save: nothing here dispatches them.
|
|
21
31
|
- A repository here is a port: an abstract class extending the kernel `Repository<Aggregate>`, abstract members only (`ports/abstract-class`). A domain service is stateless.
|
|
22
32
|
- Time and identifiers come in as parameters (`purity/*`); nothing here knows the acting user or its rights (`authz/in-application`).
|
|
23
|
-
- One concept per file, with the suffix of its role: `.aggregate.ts`, `.entity.ts`, `.vo.ts`, `.event.ts`, `.error.ts`, `.repository.ts`, `.service.ts` (`naming/suffix`, `naming/one-concept-per-file`).
|
|
33
|
+
- One concept per file, with the suffix of its role: `.aggregate.ts`, `.entity.ts`, `.vo.ts`, `.vocabulary.ts`, `.event.ts`, `.error.ts`, `.repository.ts`, `.service.ts` (`naming/suffix`, `naming/one-concept-per-file`).
|
|
24
34
|
{{#if refusals.factories}}
|
|
25
|
-
- The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|domain-event|domain-service|repository ... --json`, a refusal with `npx ddd-ts-kit generate error <context> <Concept> <refusal> --json` (it adds the factory to the class of the concept, and its case to the spec), and fill the `TODO(domain)` places it lists.
|
|
35
|
+
- The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|vocabulary|domain-event|domain-service|repository ... --json`, a refusal with `npx ddd-ts-kit generate error <context> <Concept> <refusal> --json` (it adds the factory to the class of the concept, and its case to the spec), and fill the `TODO(domain)` places it lists.
|
|
26
36
|
{{/if}}
|
|
27
37
|
{{#if refusals.classes}}
|
|
28
|
-
- The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|domain-event|domain-error|domain-service|repository ... --json` and fill the `TODO(domain)` places it lists.
|
|
38
|
+
- The language first, with `/ddd-ts-kit:glossary`. Then create with `npx ddd-ts-kit generate aggregate|entity|value-object|vocabulary|domain-event|domain-error|domain-service|repository ... --json` and fill the `TODO(domain)` places it lists.
|
|
29
39
|
{{/if}}
|
|
@@ -10,6 +10,9 @@ paths:
|
|
|
10
10
|
- Rows never leave `persistence/`: a mapper translates to and from the aggregate, and is the only place for a type assertion (`clean/no-escape-hatch`).
|
|
11
11
|
- Own tables, in the schema of the context: no join, foreign key or transaction across contexts (`context/extractable`).
|
|
12
12
|
- Audit columns and the tenant column are stamped from the execution scope with the kernel helpers (`stampCreation`, `stampUpdate`, `tenantScopeOf`), never handed over by a use case.
|
|
13
|
+
{{#if tenancy.any}}
|
|
14
|
+
- Tenant data is reached through the helpers of the ORM package, never straight from the executor: {{#if orm.knex}}`tenantTable` to read, `ownTenantTable` to update or delete{{/if}}{{#if orm.drizzle}}`tenantCondition` in the condition of a read, `ownTenantCondition` in that of an update or a delete{{/if}}, the tenant named on every insert (`tenancy/scoped-statement`). A table of no tenant is a recorded deviation. See `docs/concepts/multitenancy.md` of the kit.
|
|
15
|
+
{{/if}}
|
|
13
16
|
{{#if style.declared}}
|
|
14
17
|
- An adapter declares itself on its class, one per file (`declarations/role-declared`): `@Repository(InvoiceRepository)`, `@Gateway(Port)` or `@Adapter(Port, { kind })`. What it is given is what its constructor takes, each parameter typed by one class (`{{persistence.tokenOrNone}}`, `ExecutionScope`, `Clock`, a port, an abstract class the platform binds to a value) and nothing listed in the decorator (`declarations/constructor-injection`); an adapter that extends a class of a package writes its own constructor.
|
|
15
18
|
- Retry, timeout and cache go on the declaration (`aspects: [ownPolicy(retry(...), timeout(...))]`) or, when the policy is part of what the adapter is, as decorators of `@ddd-ts-kit/aspects/decorators` (`aspects/outside-in`). Kinds `external` and `gateway` get the default policy of the platform otherwise. `ownPolicy` is the helper of `{{alias.platform}}/resilience/own-policy{{alias.ext}}`, which `generate adapter` writes when the platform does not have it yet.
|
|
@@ -13,6 +13,8 @@ const target = path.resolve('docs/integration');
|
|
|
13
13
|
const format = contractFormat();
|
|
14
14
|
const other = format === 'yaml' ? 'asyncapi.json' : 'asyncapi.yaml';
|
|
15
15
|
|
|
16
|
+
/** The type of each declaration by the name its published language exports it under, `invoiceIssuedV1`: what a handler reads with `invoiceIssuedV1.type`. */
|
|
17
|
+
const typesByName = new Map<string, string>();
|
|
16
18
|
const registry = createEventRegistry(await declaredEvents());
|
|
17
19
|
|
|
18
20
|
const generated: Readonly<Record<string, string>> = {
|
|
@@ -63,9 +65,16 @@ async function declaredEvents(): Promise<AnyIntegrationEventDefinition[]> {
|
|
|
63
65
|
for (const context of contextNames()) {
|
|
64
66
|
const index = new URL('../{{config.contextsDir}}/' + context + '/published-language/index.js', import.meta.url);
|
|
65
67
|
const exported: unknown = await import(index.href);
|
|
66
|
-
const values: unknown[] = typeof exported === 'object' && exported !== null ? Object.values(exported) : [];
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
const entries: [string, unknown][] =
|
|
70
|
+
typeof exported === 'object' && exported !== null ? Object.entries(exported) : [];
|
|
71
|
+
|
|
72
|
+
for (const [name, value] of entries) {
|
|
73
|
+
if (isDeclaration(value)) {
|
|
74
|
+
declarations.push(value);
|
|
75
|
+
typesByName.set(name, value.type);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
return declarations;
|
|
@@ -96,7 +105,7 @@ function isDeclaration(value: unknown): value is AnyIntegrationEventDefinition {
|
|
|
96
105
|
);
|
|
97
106
|
}
|
|
98
107
|
|
|
99
|
-
/** Who consumes what, read from the sources: an integration event handler names the type it handles in `eventType
|
|
108
|
+
/** Who consumes what, read from the sources: an integration event handler names the type it handles in `eventType`, read from the declaration (`invoiceIssuedV1.type`) or written out. */
|
|
100
109
|
function consumersByEventType(): Record<string, string[]> {
|
|
101
110
|
const consumers: Record<string, string[]> = {};
|
|
102
111
|
|
|
@@ -114,7 +123,11 @@ function consumedBy(context: string): string[] {
|
|
|
114
123
|
const files = fs.existsSync(directory) ? fs.readdirSync(directory) : [];
|
|
115
124
|
|
|
116
125
|
return files.flatMap((file) => {
|
|
117
|
-
const
|
|
126
|
+
const written = /static readonly eventType = (?:'([^']+)'|([A-Za-z_$][\w$]*)\.type\b)/.exec(
|
|
127
|
+
fs.readFileSync(path.join(directory, file), 'utf8'),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const type = written?.[1] ?? typesByName.get(written?.[2] ?? '');
|
|
118
131
|
|
|
119
132
|
return type === undefined ? [] : [type];
|
|
120
133
|
});
|
|
@@ -3,7 +3,7 @@ import { DomainEventHandler } from '@ddd-ts-kit/kernel/declarations';
|
|
|
3
3
|
import { {{event.pascal}} } from '{{alias.context}}/domain/events/{{event.kebab}}.event{{alias.ext}}';
|
|
4
4
|
import { {{event.camel}}V{{event.version}} } from '{{alias.context}}/published-language/{{event.kebab}}.v{{event.version}}.integration-event{{alias.ext}}';
|
|
5
5
|
|
|
6
|
-
@DomainEventHandler({{event.pascal}}, { name:
|
|
6
|
+
@DomainEventHandler({{event.pascal}}, { name: {{event.reference}} })
|
|
7
7
|
export class {{publisher.pascal}}Publisher implements DomainEventHandler<{{event.pascal}}> {
|
|
8
8
|
constructor(
|
|
9
9
|
private readonly publisher: IntegrationEventPublisher,
|
|
@@ -4,7 +4,7 @@ import { {{event.pascal}} } from '{{alias.context}}/domain/events/{{event.kebab}
|
|
|
4
4
|
@@registrations
|
|
5
5
|
const {{publisher.camel}}Publisher = platform.adapter(new {{publisher.pascal}}Publisher(platform.publisher, platform.ids), { kind: 'domain-event-handler', context: '{{context.kebab}}' });
|
|
6
6
|
|
|
7
|
-
platform.domainEvents.on(
|
|
7
|
+
platform.domainEvents.on({{event.reference}}, async (event) => {
|
|
8
8
|
if (event instanceof {{event.pascal}}) {
|
|
9
9
|
await {{publisher.camel}}Publisher.handle(event);
|
|
10
10
|
}
|
|
@@ -5,7 +5,7 @@ import { {{event.pascal}} } from '{{alias.context}}/domain/events/{{event.kebab}
|
|
|
5
5
|
@@registrations
|
|
6
6
|
builder.bind({{publisher.pascal}}Publisher).toClass({{publisher.pascal}}Publisher, [IntegrationEventPublisher, IdGenerator]).as('domain-event-handler');
|
|
7
7
|
@@start
|
|
8
|
-
resolve(DomainEventDispatcher).on(
|
|
8
|
+
resolve(DomainEventDispatcher).on({{event.reference}}, async (event) => {
|
|
9
9
|
if (event instanceof {{event.pascal}}) {
|
|
10
10
|
await resolve({{publisher.pascal}}Publisher).handle(event);
|
|
11
11
|
}
|
|
@@ -4,7 +4,7 @@ import { {{upstream.definition}}, type {{upstream.eventType}} } from '{{alias.co
|
|
|
4
4
|
|
|
5
5
|
@IntegrationEventHandler({{upstream.definition}}, { consumer: '{{context.kebab}}.{{name.kebab}}' })
|
|
6
6
|
export class {{name.pascal}}IntegrationHandler {
|
|
7
|
-
static readonly eventType =
|
|
7
|
+
static readonly eventType = {{upstream.typeRead}};
|
|
8
8
|
|
|
9
9
|
readonly actor = systemActor('{{context.kebab}}.{{name.kebab}}');
|
|
10
10
|
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
{{#if upstream.known}}
|
|
2
2
|
import { systemActor, type CommandBus } from '@ddd-ts-kit/kernel';
|
|
3
|
+
{{/if}}
|
|
4
|
+
{{#if upstream.readsType}}
|
|
5
|
+
import { {{upstream.definition}}, type {{upstream.eventType}} } from '{{alias.contexts}}/{{upstream.kebab}}/published-language/index{{alias.ext}}';
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#unless upstream.readsType}}
|
|
8
|
+
{{#if upstream.known}}
|
|
3
9
|
import type { {{upstream.eventType}} } from '{{alias.contexts}}/{{upstream.kebab}}/published-language/index{{alias.ext}}';
|
|
4
10
|
{{/if}}
|
|
11
|
+
{{/unless}}
|
|
5
12
|
{{#unless upstream.known}}
|
|
6
13
|
import { systemActor, type CommandBus, type IntegrationEvent } from '@ddd-ts-kit/kernel';
|
|
7
14
|
{{/unless}}
|
|
8
15
|
|
|
9
16
|
export class {{name.pascal}}IntegrationHandler {
|
|
10
|
-
static readonly eventType =
|
|
17
|
+
static readonly eventType = {{upstream.typeRead}};
|
|
11
18
|
|
|
12
19
|
readonly actor = systemActor('{{context.kebab}}.{{name.kebab}}');
|
|
13
20
|
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@biomejs/biome": "2.5.15",
|
|
24
24
|
"@commitlint/cli": "^21.2.3",
|
|
25
25
|
"@commitlint/config-conventional": "^21.2.3",
|
|
26
|
-
"@ddd-ts-kit/eslint-plugin": "^0.
|
|
26
|
+
"@ddd-ts-kit/eslint-plugin": "^0.8.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",
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { and, eq } from 'drizzle-orm';
|
|
2
|
+
{{#if tenant.scoped}}
|
|
3
|
+
import { optimisticUpdate, ownTenantCondition, tenantCondition } from '@ddd-ts-kit/drizzle/postgres';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#unless tenant.scoped}}
|
|
2
6
|
import { optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';
|
|
7
|
+
{{/unless}}
|
|
3
8
|
{{#if tenant.scoped}}
|
|
4
9
|
import { stampCreation, stampUpdate, tenantScopeOf, type Clock, type ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
5
10
|
{{/if}}
|
|
@@ -34,7 +39,7 @@ export class Drizzle{{aggregate.pascal}}Repository implements {{aggregate.pascal
|
|
|
34
39
|
|
|
35
40
|
async findById(id: string): Promise<{{aggregate.pascal}} | undefined> {
|
|
36
41
|
{{#if tenant.scoped}}
|
|
37
|
-
const mine = and(eq({{aggregate.tableCamel}}.id, id), this.
|
|
42
|
+
const mine = and(eq({{aggregate.tableCamel}}.id, id), tenantCondition({{aggregate.tableCamel}}.tenantId, this.scope));
|
|
38
43
|
const [row] = await this.database.executor().select().from({{aggregate.tableCamel}}).where(mine);
|
|
39
44
|
{{/if}}
|
|
40
45
|
{{#unless tenant.scoped}}
|
|
@@ -70,13 +75,7 @@ export class Drizzle{{aggregate.pascal}}Repository implements {{aggregate.pascal
|
|
|
70
75
|
.executor()
|
|
71
76
|
.update({{aggregate.tableCamel}})
|
|
72
77
|
.set({ ...state, ...stampUpdate(this.scope, this.clock) })
|
|
73
|
-
.where(and(sameId, sameVersion{{#if tenant.scoped}}, this.
|
|
78
|
+
.where(and(sameId, sameVersion{{#if tenant.scoped}}, ownTenantCondition({{aggregate.tableCamel}}.tenantId, this.scope){{/if}}))
|
|
74
79
|
.returning({ id: {{aggregate.tableCamel}}.id });
|
|
75
80
|
}
|
|
76
|
-
{{#if tenant.scoped}}
|
|
77
|
-
|
|
78
|
-
private ownTenant() {
|
|
79
|
-
return eq({{aggregate.tableCamel}}.tenantId, tenantScopeOf(this.scope).tenantId);
|
|
80
|
-
}
|
|
81
|
-
{{/if}}
|
|
82
81
|
}
|