ddd-ts-kit 0.110.0 → 0.111.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 +56 -0
- package/README.fr.md +7 -5
- package/README.md +6 -4
- package/dist/check/explain/tenancy-docs.d.ts.map +1 -1
- package/dist/check/explain/tenancy-docs.js +3 -1
- package/dist/check/explain/tenancy-docs.js.map +1 -1
- package/dist/check/fixtures/tenancy-advisory-lock-fixtures.d.ts +9 -0
- package/dist/check/fixtures/tenancy-advisory-lock-fixtures.d.ts.map +1 -0
- package/dist/check/fixtures/tenancy-advisory-lock-fixtures.js +45 -0
- package/dist/check/fixtures/tenancy-advisory-lock-fixtures.js.map +1 -0
- package/dist/check/fixtures/tenancy-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/tenancy-fixtures.js +2 -0
- package/dist/check/fixtures/tenancy-fixtures.js.map +1 -1
- package/dist/check/rules/privacy-declared-field.js +1 -1
- package/dist/check/rules/privacy-declared-field.js.map +1 -1
- package/dist/check/rules/tenancy-scoped-statement.d.ts.map +1 -1
- package/dist/check/rules/tenancy-scoped-statement.js +11 -3
- package/dist/check/rules/tenancy-scoped-statement.js.map +1 -1
- package/dist/commands/generate.js +2 -0
- package/dist/commands/generate.js.map +1 -1
- package/dist/context-layout/context-layout.d.ts.map +1 -1
- package/dist/context-layout/context-layout.js +6 -0
- package/dist/context-layout/context-layout.js.map +1 -1
- package/dist/context-layout/module-moves.d.ts +8 -0
- package/dist/context-layout/module-moves.d.ts.map +1 -1
- package/dist/context-layout/module-moves.js +14 -3
- package/dist/context-layout/module-moves.js.map +1 -1
- package/dist/context-layout/runner-configs-by-hand.d.ts.map +1 -1
- package/dist/context-layout/runner-configs-by-hand.js +12 -0
- package/dist/context-layout/runner-configs-by-hand.js.map +1 -1
- package/dist/context-layout/settle.d.ts +9 -0
- package/dist/context-layout/settle.d.ts.map +1 -1
- package/dist/context-layout/settle.js +25 -3
- package/dist/context-layout/settle.js.map +1 -1
- package/dist/describe/read-adapters.d.ts.map +1 -1
- package/dist/describe/read-adapters.js +5 -1
- package/dist/describe/read-adapters.js.map +1 -1
- package/dist/describe/read-ports.js +8 -1
- package/dist/describe/read-ports.js.map +1 -1
- package/dist/generate/generate-options.d.ts +7 -0
- package/dist/generate/generate-options.d.ts.map +1 -1
- package/dist/generate/generate-options.js +2 -0
- package/dist/generate/generate-options.js.map +1 -1
- package/dist/generate/kind.d.ts +4 -0
- package/dist/generate/kind.d.ts.map +1 -1
- package/dist/generate/kinds/adapter-kind.d.ts.map +1 -1
- package/dist/generate/kinds/adapter-kind.js +12 -0
- package/dist/generate/kinds/adapter-kind.js.map +1 -1
- package/dist/generate/kinds/declare-storage.d.ts.map +1 -1
- package/dist/generate/kinds/declare-storage.js +3 -57
- package/dist/generate/kinds/declare-storage.js.map +1 -1
- package/dist/generate/kinds/declare-table.d.ts +14 -0
- package/dist/generate/kinds/declare-table.d.ts.map +1 -0
- package/dist/generate/kinds/declare-table.js +72 -0
- package/dist/generate/kinds/declare-table.js.map +1 -0
- package/dist/generate/kinds/e2e/job-slug.d.ts +3 -0
- package/dist/generate/kinds/e2e/job-slug.d.ts.map +1 -0
- package/dist/generate/kinds/e2e/job-slug.js +8 -0
- package/dist/generate/kinds/e2e/job-slug.js.map +1 -0
- package/dist/generate/kinds/e2e/job-spec.d.ts +16 -0
- package/dist/generate/kinds/e2e/job-spec.d.ts.map +1 -0
- package/dist/generate/kinds/e2e/job-spec.js +54 -0
- package/dist/generate/kinds/e2e/job-spec.js.map +1 -0
- package/dist/generate/kinds/e2e/jobs-sending.d.ts +17 -5
- package/dist/generate/kinds/e2e/jobs-sending.d.ts.map +1 -1
- package/dist/generate/kinds/e2e/jobs-sending.js +15 -6
- package/dist/generate/kinds/e2e/jobs-sending.js.map +1 -1
- package/dist/generate/kinds/e2e/reaction-of.d.ts +5 -5
- package/dist/generate/kinds/e2e/reaction-of.d.ts.map +1 -1
- package/dist/generate/kinds/e2e/reaction-of.js +15 -8
- package/dist/generate/kinds/e2e/reaction-of.js.map +1 -1
- package/dist/generate/kinds/e2e/starting-jobs.d.ts +10 -0
- package/dist/generate/kinds/e2e/starting-jobs.d.ts.map +1 -0
- package/dist/generate/kinds/e2e/starting-jobs.js +33 -0
- package/dist/generate/kinds/e2e/starting-jobs.js.map +1 -0
- package/dist/generate/kinds/e2e-kind.d.ts.map +1 -1
- package/dist/generate/kinds/e2e-kind.js +47 -35
- package/dist/generate/kinds/e2e-kind.js.map +1 -1
- package/dist/generate/kinds/generate-repository.d.ts +8 -0
- package/dist/generate/kinds/generate-repository.d.ts.map +1 -1
- package/dist/generate/kinds/generate-repository.js +2 -13
- package/dist/generate/kinds/generate-repository.js.map +1 -1
- package/dist/generate/kinds/note-the-migration.d.ts +4 -0
- package/dist/generate/kinds/note-the-migration.d.ts.map +1 -0
- package/dist/generate/kinds/note-the-migration.js +13 -0
- package/dist/generate/kinds/note-the-migration.js.map +1 -0
- package/dist/generate/kinds/personal-data/columns-of-table.d.ts +18 -0
- package/dist/generate/kinds/personal-data/columns-of-table.d.ts.map +1 -0
- package/dist/generate/kinds/personal-data/columns-of-table.js +31 -0
- package/dist/generate/kinds/personal-data/columns-of-table.js.map +1 -0
- package/dist/generate/kinds/personal-data/declare-personal-data.d.ts.map +1 -1
- package/dist/generate/kinds/personal-data/declare-personal-data.js +7 -52
- package/dist/generate/kinds/personal-data/declare-personal-data.js.map +1 -1
- package/dist/generate/kinds/personal-data/declare-table-personal-fields.d.ts +11 -0
- package/dist/generate/kinds/personal-data/declare-table-personal-fields.d.ts.map +1 -0
- package/dist/generate/kinds/personal-data/declare-table-personal-fields.js +71 -0
- package/dist/generate/kinds/personal-data/declare-table-personal-fields.js.map +1 -0
- package/dist/generate/kinds/personal-data/personal-request-of-table.d.ts +11 -0
- package/dist/generate/kinds/personal-data/personal-request-of-table.d.ts.map +1 -0
- package/dist/generate/kinds/personal-data/personal-request-of-table.js +20 -0
- package/dist/generate/kinds/personal-data/personal-request-of-table.js.map +1 -0
- package/dist/generate/kinds/personal-data/personal-vars.d.ts +7 -0
- package/dist/generate/kinds/personal-data/personal-vars.d.ts.map +1 -1
- package/dist/generate/kinds/personal-data/personal-vars.js +14 -11
- package/dist/generate/kinds/personal-data/personal-vars.js.map +1 -1
- package/dist/generate/kinds/personal-data/schema-table.d.ts +13 -0
- package/dist/generate/kinds/personal-data/schema-table.d.ts.map +1 -0
- package/dist/generate/kinds/personal-data/schema-table.js +2 -0
- package/dist/generate/kinds/personal-data/schema-table.js.map +1 -0
- package/dist/generate/kinds/personal-data/schema-tables-of.d.ts +9 -0
- package/dist/generate/kinds/personal-data/schema-tables-of.d.ts.map +1 -0
- package/dist/generate/kinds/personal-data/schema-tables-of.js +78 -0
- package/dist/generate/kinds/personal-data/schema-tables-of.js.map +1 -0
- package/dist/generate/kinds/personal-data/table-of-schema.d.ts +15 -0
- package/dist/generate/kinds/personal-data/table-of-schema.d.ts.map +1 -0
- package/dist/generate/kinds/personal-data/table-of-schema.js +39 -0
- package/dist/generate/kinds/personal-data/table-of-schema.js.map +1 -0
- package/dist/generate/kinds/personal-data/write-personal-declaration.d.ts +20 -0
- package/dist/generate/kinds/personal-data/write-personal-declaration.d.ts.map +1 -0
- package/dist/generate/kinds/personal-data/write-personal-declaration.js +63 -0
- package/dist/generate/kinds/personal-data/write-personal-declaration.js.map +1 -0
- package/dist/generate/kinds/personal-fields-kind.d.ts +3 -0
- package/dist/generate/kinds/personal-fields-kind.d.ts.map +1 -0
- package/dist/generate/kinds/personal-fields-kind.js +15 -0
- package/dist/generate/kinds/personal-fields-kind.js.map +1 -0
- package/dist/generate/kinds/projection-kind.d.ts.map +1 -1
- package/dist/generate/kinds/projection-kind.js +2 -1
- package/dist/generate/kinds/projection-kind.js.map +1 -1
- package/dist/generate/kinds/read-model/field-lines.d.ts +11 -0
- package/dist/generate/kinds/read-model/field-lines.d.ts.map +1 -0
- package/dist/generate/kinds/read-model/field-lines.js +85 -0
- package/dist/generate/kinds/read-model/field-lines.js.map +1 -0
- package/dist/generate/kinds/read-model/live-rows-check.d.ts +22 -0
- package/dist/generate/kinds/read-model/live-rows-check.d.ts.map +1 -0
- package/dist/generate/kinds/read-model/live-rows-check.js +47 -0
- package/dist/generate/kinds/read-model/live-rows-check.js.map +1 -0
- package/dist/generate/kinds/read-model/read-model-fields.d.ts +19 -0
- package/dist/generate/kinds/read-model/read-model-fields.d.ts.map +1 -0
- package/dist/generate/kinds/read-model/read-model-fields.js +31 -0
- package/dist/generate/kinds/read-model/read-model-fields.js.map +1 -0
- package/dist/generate/kinds/read-model/read-model-store.d.ts +24 -0
- package/dist/generate/kinds/read-model/read-model-store.d.ts.map +1 -0
- package/dist/generate/kinds/read-model/read-model-store.js +39 -0
- package/dist/generate/kinds/read-model/read-model-store.js.map +1 -0
- package/dist/generate/kinds/read-model/read-model-table.d.ts +11 -0
- package/dist/generate/kinds/read-model/read-model-table.d.ts.map +1 -0
- package/dist/generate/kinds/read-model/read-model-table.js +2 -0
- package/dist/generate/kinds/read-model/read-model-table.js.map +1 -0
- package/dist/generate/kinds/read-model-kind.d.ts +3 -0
- package/dist/generate/kinds/read-model-kind.d.ts.map +1 -0
- package/dist/generate/kinds/read-model-kind.js +84 -0
- package/dist/generate/kinds/read-model-kind.js.map +1 -0
- package/dist/generate/kinds.d.ts.map +1 -1
- package/dist/generate/kinds.js +4 -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 +8 -0
- package/dist/generate/shared-writes.js.map +1 -1
- package/dist/help/tool-notes.d.ts.map +1 -1
- package/dist/help/tool-notes.js +2 -1
- package/dist/help/tool-notes.js.map +1 -1
- package/dist/init/files/persistence-files.d.ts.map +1 -1
- package/dist/init/files/persistence-files.js +2 -0
- package/dist/init/files/persistence-files.js.map +1 -1
- package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
- package/dist/init/manifest/dependencies-for.js +10 -7
- package/dist/init/manifest/dependencies-for.js.map +1 -1
- package/dist/init/manifest/versions.js +25 -25
- package/dist/layout/fit-block.js +4 -0
- package/dist/layout/fit-block.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/stack/end-to-end-vars.d.ts +9 -0
- package/dist/stack/end-to-end-vars.d.ts.map +1 -0
- package/dist/stack/end-to-end-vars.js +32 -0
- package/dist/stack/end-to-end-vars.js.map +1 -0
- package/dist/stack/stack-vars.d.ts.map +1 -1
- package/dist/stack/stack-vars.js +2 -0
- package/dist/stack/stack-vars.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker/briefing-of.js +2 -2
- package/dist/worker/briefing-of.js.map +1 -1
- package/package.json +6 -6
- package/templates/e2e/e2e-background-job-case.ts.tpl +12 -0
- package/templates/e2e/e2e-job.spec.ts.tpl +3 -3
- package/templates/init/README.md.tpl +1 -1
- package/templates/init/e2e/jest.e2e.config.js.tpl +24 -5
- package/templates/init/e2e/start-application.database.ts.tpl +40 -2
- package/templates/init/e2e/start-application.memory.ts.tpl +36 -0
- package/templates/init/e2e/vitest.e2e.config.ts.tpl +12 -3
- package/templates/init/platform/database/open-test-database.drizzle.ts.tpl +22 -4
- package/templates/init/platform/database/open-test-database.knex.ts.tpl +21 -3
- package/templates/init/platform/database/open-test-database.prisma.ts.tpl +22 -3
- package/templates/init/platform/database/open-test-database.typeorm.ts.tpl +22 -3
- package/templates/init/platform/database/test-database-clone.ts.tpl +184 -0
- package/templates/init/platform/jobs/background-jobs.ts.tpl +4 -0
- package/templates/init/platform/jobs/create-background-work.ts.tpl +1 -0
- package/templates/init/rules/infrastructure.md.tpl +1 -1
- package/templates/personal-data/declaration.drizzle.ts.tpl +6 -1
- package/templates/personal-data/declaration.knex.ts.tpl +14 -1
- package/templates/personal-data/declaration.prisma.ts.tpl +6 -1
- package/templates/personal-data/declaration.typeorm.ts.tpl +21 -1
- package/templates/personal-data/spec.table.ts.tpl +39 -0
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/projection/projection.manual.ts.tpl +2 -2
- package/templates/projection/projection.ts.tpl +2 -2
- package/templates/read-model/contract.spec.ts.tpl +95 -0
- package/templates/read-model/drizzle/schema.ts.tpl +8 -0
- package/templates/read-model/drizzle/store.ts.tpl +41 -0
- package/templates/read-model/drizzle/table.tpl +38 -0
- package/templates/read-model/fake.ts.tpl +8 -0
- package/templates/read-model/knex/store.ts.tpl +41 -0
- package/templates/read-model/knex/table.tpl +26 -0
- package/templates/read-model/none/store.ts.tpl +17 -0
- package/templates/read-model/port.ts.tpl +24 -0
- package/templates/read-model/prisma/model.tpl +25 -0
- package/templates/read-model/prisma/store.ts.tpl +43 -0
- package/templates/read-model/typeorm/schema-export.tpl +4 -0
- package/templates/read-model/typeorm/schema.ts.tpl +9 -0
- package/templates/read-model/typeorm/store.ts.tpl +30 -0
- package/templates/read-model/typeorm/table.tpl +54 -0
- package/templates/read-model/wiring.container.tpl +21 -0
- package/templates/repository/drizzle/table.tpl +1 -0
- package/templates/repository/typeorm/table.tpl +1 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{{#if adapter.needsDatabase}}
|
|
2
|
+
{{#if tenant.scoped}}
|
|
3
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '{{tests.module}}';
|
|
4
|
+
import { FixedExecutionScope, executionContext, type Actor, type ExecutionContext } from '@ddd-ts-kit/kernel';
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#unless tenant.scoped}}
|
|
7
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '{{tests.module}}';
|
|
8
|
+
{{/unless}}
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#unless adapter.needsDatabase}}
|
|
11
|
+
import { afterEach, beforeEach, describe, expect, it } from '{{tests.module}}';
|
|
12
|
+
{{/unless}}
|
|
13
|
+
import { readModelContract } from '@ddd-ts-kit/testing/contracts';
|
|
14
|
+
import type { {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
15
|
+
import { {{adapter.pascal}} } from '{{alias.context}}/infrastructure/persistence/{{adapter.kebab}}{{alias.ext}}';
|
|
16
|
+
{{#if adapter.needsDatabase}}
|
|
17
|
+
import { openTestDatabase, type TestDatabase } from '{{alias.platform}}/database/open-test-database{{alias.ext}}';
|
|
18
|
+
{{/if}}
|
|
19
|
+
import { Fake{{name.pascal}} } from '{{alias.context}}/test/fakes/{{name.kebab}}.fake{{alias.ext}}';
|
|
20
|
+
|
|
21
|
+
const runner = { describe, it, expect, beforeEach, afterEach };
|
|
22
|
+
|
|
23
|
+
const expectations = {
|
|
24
|
+
createRow: (key: string): {{name.pascal}}Row => ({
|
|
25
|
+
id: key,
|
|
26
|
+
{{#if fields.any}}
|
|
27
|
+
{{fields.sample}}
|
|
28
|
+
{{/if}}
|
|
29
|
+
}),
|
|
30
|
+
// TODO(domain): add `change: (row: {{name.pascal}}Row) => ({ ...row, <a field>: <another value> })`, so that the suite proves a later event replaces what the row holds; the case stays pending until then.
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
readModelContract<{{name.pascal}}Row>(runner, {
|
|
34
|
+
...expectations,
|
|
35
|
+
name: 'Fake{{name.pascal}}',
|
|
36
|
+
createStore: () => new Fake{{name.pascal}}(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
{{#if adapter.needsDatabase}}
|
|
40
|
+
let database: TestDatabase;
|
|
41
|
+
|
|
42
|
+
beforeAll(async () => {
|
|
43
|
+
database = await openTestDatabase();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
afterAll(async () => {
|
|
47
|
+
await database.close();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
readModelContract<{{name.pascal}}Row>(runner, {
|
|
51
|
+
...expectations,
|
|
52
|
+
name: '{{adapter.pascal}}',
|
|
53
|
+
createStore: async () => {
|
|
54
|
+
await database.reset();
|
|
55
|
+
|
|
56
|
+
{{#if tenant.scoped}}
|
|
57
|
+
return new {{adapter.pascal}}(database.persistence.database, new FixedExecutionScope(workOf('acme')));
|
|
58
|
+
{{/if}}
|
|
59
|
+
{{#unless tenant.scoped}}
|
|
60
|
+
return new {{adapter.pascal}}(database.persistence.database);
|
|
61
|
+
{{/unless}}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
{{#if tenant.scoped}}
|
|
65
|
+
|
|
66
|
+
describe('{{adapter.pascal}}, tenant by tenant', () => {
|
|
67
|
+
it('hides from a tenant what another tenant wrote', async () => {
|
|
68
|
+
await database.reset();
|
|
69
|
+
|
|
70
|
+
const scope = new FixedExecutionScope(workOf('acme'));
|
|
71
|
+
const store = new {{adapter.pascal}}(database.persistence.database, scope);
|
|
72
|
+
const stamp = { eventId: 'event-1', occurredAt: new Date('2026-01-01T00:00:00.000Z') };
|
|
73
|
+
|
|
74
|
+
await store.upsertIfNewer('row-1', stamp, () => expectations.createRow('row-1'));
|
|
75
|
+
|
|
76
|
+
scope.enter(workOf('globex'));
|
|
77
|
+
|
|
78
|
+
expect(await store.get('row-1')).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
function workOf(tenantId: string): ExecutionContext {
|
|
83
|
+
const actor: Actor = { id: 'member-of-' + tenantId, type: 'user', tenantId, roles: [], attributes: {} };
|
|
84
|
+
|
|
85
|
+
return executionContext({ correlationId: 'contract-spec', actor, origin: 'test' });
|
|
86
|
+
}
|
|
87
|
+
{{/if}}
|
|
88
|
+
{{/if}}
|
|
89
|
+
{{#unless adapter.needsDatabase}}
|
|
90
|
+
readModelContract<{{name.pascal}}Row>(runner, {
|
|
91
|
+
...expectations,
|
|
92
|
+
name: '{{adapter.pascal}}',
|
|
93
|
+
createStore: () => new {{adapter.pascal}}(),
|
|
94
|
+
});
|
|
95
|
+
{{/unless}}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PgQueryResultHKT } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { DrizzleReadModelStore } from '@ddd-ts-kit/drizzle/postgres';
|
|
3
|
+
{{#if tenant.scoped}}
|
|
4
|
+
import type { ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#if style.declared}}
|
|
7
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
8
|
+
import { {{name.pascal}}, {{name.camel}}Criteria, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#unless style.declared}}
|
|
11
|
+
import { {{name.camel}}Criteria, type {{name.pascal}}, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
12
|
+
{{/unless}}
|
|
13
|
+
{{storage.adapterImport}}
|
|
14
|
+
import { {{name.camel}} } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
15
|
+
|
|
16
|
+
{{#if style.declared}}
|
|
17
|
+
@Repository({{name.pascal}})
|
|
18
|
+
{{/if}}
|
|
19
|
+
export class {{adapter.pascal}} extends DrizzleReadModelStore<{{name.pascal}}Row, PgQueryResultHKT> implements {{name.pascal}} {
|
|
20
|
+
{{#if tenant.scoped}}
|
|
21
|
+
constructor(database: Database, scope: ExecutionScope) {
|
|
22
|
+
{{/if}}
|
|
23
|
+
{{#unless tenant.scoped}}
|
|
24
|
+
constructor(database: Database) {
|
|
25
|
+
{{/unless}}
|
|
26
|
+
super(database, {
|
|
27
|
+
table: {{name.camel}},
|
|
28
|
+
key: {{name.camel}}.id,
|
|
29
|
+
columns: {
|
|
30
|
+
id: {{name.camel}}.id,
|
|
31
|
+
{{#if fields.any}}
|
|
32
|
+
{{fields.drizzleColumns}}
|
|
33
|
+
{{/if}}
|
|
34
|
+
},
|
|
35
|
+
{{#if tenant.scoped}}
|
|
36
|
+
tenant: { scope, column: {{name.camel}}.tenantId },
|
|
37
|
+
{{/if}}
|
|
38
|
+
definition: {{name.camel}}Criteria,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
@@imports
|
|
2
|
+
{{#if fields.checked}}
|
|
3
|
+
import { sql } from 'drizzle-orm';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#if tenant.scoped}}
|
|
6
|
+
import { index, {{fields.drizzleImports}} } from 'drizzle-orm/pg-core';
|
|
7
|
+
import { readModelColumns, tenantColumn } from '@ddd-ts-kit/drizzle/postgres';
|
|
8
|
+
{{/if}}
|
|
9
|
+
{{#unless tenant.scoped}}
|
|
10
|
+
import { {{fields.drizzleImports}} } from 'drizzle-orm/pg-core';
|
|
11
|
+
import { readModelColumns } from '@ddd-ts-kit/drizzle/postgres';
|
|
12
|
+
{{/unless}}
|
|
13
|
+
@@tables
|
|
14
|
+
{{#if fields.drizzleWide}}
|
|
15
|
+
export const {{name.camel}} = {{context.camel}}Schema.table(
|
|
16
|
+
'{{table}}',
|
|
17
|
+
{
|
|
18
|
+
id: text('id').primaryKey(),
|
|
19
|
+
{{#if fields.any}}
|
|
20
|
+
{{fields.drizzleTable}}
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#if tenant.scoped}}
|
|
23
|
+
...tenantColumn(),
|
|
24
|
+
{{/if}}
|
|
25
|
+
...readModelColumns(),
|
|
26
|
+
},
|
|
27
|
+
{{fields.drizzleExtras}}
|
|
28
|
+
);
|
|
29
|
+
{{/if}}
|
|
30
|
+
{{#unless fields.drizzleWide}}
|
|
31
|
+
export const {{name.camel}} = {{context.camel}}Schema.table('{{table}}', {
|
|
32
|
+
id: text('id').primaryKey(),
|
|
33
|
+
{{#if fields.any}}
|
|
34
|
+
{{fields.drizzleTable}}
|
|
35
|
+
{{/if}}
|
|
36
|
+
...readModelColumns(),
|
|
37
|
+
});
|
|
38
|
+
{{/unless}}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InMemoryReadModelStore } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { {{name.camel}}Criteria, type {{name.pascal}}, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
3
|
+
|
|
4
|
+
export class Fake{{name.pascal}} extends InMemoryReadModelStore<{{name.pascal}}Row> implements {{name.pascal}} {
|
|
5
|
+
constructor() {
|
|
6
|
+
super({{name.camel}}Criteria);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{{#if tenant.scoped}}
|
|
2
|
+
import type { ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
3
|
+
{{/if}}
|
|
4
|
+
{{#if style.declared}}
|
|
5
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
6
|
+
{{/if}}
|
|
7
|
+
import { type KnexContext, KnexReadModelStore } from '@ddd-ts-kit/knex';
|
|
8
|
+
{{#if style.declared}}
|
|
9
|
+
import { {{name.pascal}}, {{name.camel}}Criteria, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
10
|
+
{{/if}}
|
|
11
|
+
{{#unless style.declared}}
|
|
12
|
+
import { {{name.camel}}Criteria, type {{name.pascal}}, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
13
|
+
{{/unless}}
|
|
14
|
+
import { {{context.constant}}_SCHEMA } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
15
|
+
|
|
16
|
+
{{#if style.declared}}
|
|
17
|
+
@Repository({{name.pascal}})
|
|
18
|
+
{{/if}}
|
|
19
|
+
export class {{adapter.pascal}} extends KnexReadModelStore<{{name.pascal}}Row> implements {{name.pascal}} {
|
|
20
|
+
{{#if tenant.scoped}}
|
|
21
|
+
constructor(database: KnexContext, scope: ExecutionScope) {
|
|
22
|
+
{{/if}}
|
|
23
|
+
{{#unless tenant.scoped}}
|
|
24
|
+
constructor(database: KnexContext) {
|
|
25
|
+
{{/unless}}
|
|
26
|
+
super(database, {
|
|
27
|
+
{{#if tenant.scoped}}
|
|
28
|
+
tenant: scope,
|
|
29
|
+
{{/if}}
|
|
30
|
+
schema: {{context.constant}}_SCHEMA,
|
|
31
|
+
table: '{{table}}',
|
|
32
|
+
columns: {
|
|
33
|
+
id: 'id',
|
|
34
|
+
{{#if fields.any}}
|
|
35
|
+
{{fields.names}}
|
|
36
|
+
{{/if}}
|
|
37
|
+
},
|
|
38
|
+
definition: {{name.camel}}Criteria,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
@@imports
|
|
2
|
+
{{#if tenant.scoped}}
|
|
3
|
+
import { readModelColumns, tenantColumn } from '@ddd-ts-kit/knex';
|
|
4
|
+
{{/if}}
|
|
5
|
+
{{#unless tenant.scoped}}
|
|
6
|
+
import { readModelColumns } from '@ddd-ts-kit/knex';
|
|
7
|
+
{{/unless}}
|
|
8
|
+
@@tables
|
|
9
|
+
await create{{name.pascal}}Table(knex);
|
|
10
|
+
@@definitions
|
|
11
|
+
function create{{name.pascal}}Table(knex: Knex): Promise<void> {
|
|
12
|
+
return knex.schema.withSchema({{context.constant}}_SCHEMA).createTable('{{table}}', (table) => {
|
|
13
|
+
table.text('id').primary();
|
|
14
|
+
{{#if fields.any}}
|
|
15
|
+
{{fields.knexTable}}
|
|
16
|
+
{{/if}}
|
|
17
|
+
{{#if tenant.scoped}}
|
|
18
|
+
tenantColumn(table);
|
|
19
|
+
table.index(['tenant_id', 'id'], '{{table}}_tenant_idx');
|
|
20
|
+
{{/if}}
|
|
21
|
+
readModelColumns(table);
|
|
22
|
+
{{#if fields.checked}}
|
|
23
|
+
{{fields.knexCheck}}
|
|
24
|
+
{{/if}}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InMemoryReadModelStore } from '@ddd-ts-kit/kernel';
|
|
2
|
+
{{#if style.declared}}
|
|
3
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
4
|
+
import { {{name.pascal}}, {{name.camel}}Criteria, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#unless style.declared}}
|
|
7
|
+
import { {{name.camel}}Criteria, type {{name.pascal}}, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
8
|
+
{{/unless}}
|
|
9
|
+
|
|
10
|
+
{{#if style.declared}}
|
|
11
|
+
@Repository({{name.pascal}})
|
|
12
|
+
{{/if}}
|
|
13
|
+
export class {{adapter.pascal}} extends InMemoryReadModelStore<{{name.pascal}}Row> implements {{name.pascal}} {
|
|
14
|
+
constructor() {
|
|
15
|
+
super({{name.camel}}Criteria);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReadModelStore, defineCriteria } from '@ddd-ts-kit/kernel';
|
|
2
|
+
|
|
3
|
+
export type {{name.pascal}}Row = {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
{{#if fields.any}}
|
|
6
|
+
{{fields.row}}
|
|
7
|
+
{{/if}}
|
|
8
|
+
{{#unless fields.any}}
|
|
9
|
+
// TODO(domain): add one field per thing a read of "{{name.words}}" shows or filters by, with its line in the criteria below, its column in the table and its entry in the columns of the store adapter (`--field <name>:<type>` writes the four).
|
|
10
|
+
{{/unless}}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const {{name.camel}}Criteria = defineCriteria<{{name.pascal}}Row>({
|
|
14
|
+
fields: {
|
|
15
|
+
// TODO(domain): open to the readers only what a screen needs: `filter: ['eq']` on a field it filters by, `sortable: true` on a field it sorts by, then a `defaultSort`.
|
|
16
|
+
id: { type: 'string' },
|
|
17
|
+
{{#if fields.any}}
|
|
18
|
+
{{fields.criteria}}
|
|
19
|
+
{{/if}}
|
|
20
|
+
},
|
|
21
|
+
tieBreaker: 'id',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export abstract class {{name.pascal}} extends ReadModelStore<{{name.pascal}}Row> {}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@@models
|
|
2
|
+
model {{context.pascal}}{{name.pascal}} {
|
|
3
|
+
id String @id
|
|
4
|
+
{{#if fields.any}}
|
|
5
|
+
{{fields.prismaModel}}
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#if fields.checked}}
|
|
8
|
+
// TODO(domain): the schema language has no check constraint. Add to the migration that creates this table, after its CREATE TABLE, what keeps the rows that are not removed whole: {{fields.prismaCheck}}
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#if tenant.scoped}}
|
|
11
|
+
tenantId String @map("tenant_id")
|
|
12
|
+
{{/if}}
|
|
13
|
+
/// The event that last changed the row: an older one changes nothing.
|
|
14
|
+
lastEventId String @map("last_event_id")
|
|
15
|
+
lastEventAt DateTime @map("last_event_at") @db.Timestamptz(3)
|
|
16
|
+
lastEventVersion BigInt? @map("last_event_version")
|
|
17
|
+
/// The trace of a removed row, so that a late event does not bring it back.
|
|
18
|
+
deleted Boolean @default(false)
|
|
19
|
+
|
|
20
|
+
{{#if tenant.scoped}}
|
|
21
|
+
@@index([tenantId, id], map: "{{table}}_tenant_idx")
|
|
22
|
+
{{/if}}
|
|
23
|
+
@@map("{{table}}")
|
|
24
|
+
@@schema("{{context.schema}}")
|
|
25
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{{#if tenant.scoped}}
|
|
2
|
+
import type { ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
3
|
+
{{/if}}
|
|
4
|
+
{{#if style.declared}}
|
|
5
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
6
|
+
{{/if}}
|
|
7
|
+
import { PrismaReadModelStore } from '@ddd-ts-kit/prisma';
|
|
8
|
+
{{#if style.declared}}
|
|
9
|
+
import { {{name.pascal}}, {{name.camel}}Criteria, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
10
|
+
{{/if}}
|
|
11
|
+
{{#unless style.declared}}
|
|
12
|
+
import { {{name.camel}}Criteria, type {{name.pascal}}, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
13
|
+
{{/unless}}
|
|
14
|
+
{{storage.adapterImport}}
|
|
15
|
+
import type { Prisma } from '{{alias.generated}}/prisma/client{{alias.ext}}';
|
|
16
|
+
|
|
17
|
+
{{#if style.declared}}
|
|
18
|
+
@Repository({{name.pascal}})
|
|
19
|
+
{{/if}}
|
|
20
|
+
export class {{adapter.pascal}} extends PrismaReadModelStore<{{name.pascal}}Row, Prisma.TransactionClient> implements {{name.pascal}} {
|
|
21
|
+
{{#if tenant.scoped}}
|
|
22
|
+
constructor(database: Database, scope: ExecutionScope) {
|
|
23
|
+
{{/if}}
|
|
24
|
+
{{#unless tenant.scoped}}
|
|
25
|
+
constructor(database: Database) {
|
|
26
|
+
{{/unless}}
|
|
27
|
+
super(database, {
|
|
28
|
+
delegate: (client) => client.{{context.camel}}{{name.pascal}},
|
|
29
|
+
schema: '{{context.schema}}',
|
|
30
|
+
table: '{{table}}',
|
|
31
|
+
columns: {
|
|
32
|
+
id: 'id',
|
|
33
|
+
{{#if fields.any}}
|
|
34
|
+
{{fields.names}}
|
|
35
|
+
{{/if}}
|
|
36
|
+
},
|
|
37
|
+
{{#if tenant.scoped}}
|
|
38
|
+
tenant: { scope },
|
|
39
|
+
{{/if}}
|
|
40
|
+
definition: {{name.camel}}Criteria,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// ddd-ts-kit:imports
|
|
2
|
+
import { EntitySchema } from 'typeorm';
|
|
3
|
+
import { schemaNameOf } from '@ddd-ts-kit/typeorm';
|
|
4
|
+
// /ddd-ts-kit:imports
|
|
5
|
+
|
|
6
|
+
const {{context.constant}}_SCHEMA = schemaNameOf('{{context.kebab}}');
|
|
7
|
+
|
|
8
|
+
// ddd-ts-kit:tables
|
|
9
|
+
// /ddd-ts-kit:tables
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{{#if tenant.scoped}}
|
|
2
|
+
import type { ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
3
|
+
{{/if}}
|
|
4
|
+
{{#if style.declared}}
|
|
5
|
+
import { Repository } from '@ddd-ts-kit/kernel/declarations';
|
|
6
|
+
{{/if}}
|
|
7
|
+
import { type TypeOrmContext, TypeOrmReadModelStore } from '@ddd-ts-kit/typeorm';
|
|
8
|
+
{{#if style.declared}}
|
|
9
|
+
import { {{name.pascal}}, {{name.camel}}Criteria, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
10
|
+
{{/if}}
|
|
11
|
+
{{#unless style.declared}}
|
|
12
|
+
import { {{name.camel}}Criteria, type {{name.pascal}}, type {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
13
|
+
{{/unless}}
|
|
14
|
+
import { {{name.camel}} } from '{{alias.context}}/infrastructure/persistence/{{context.kebab}}.schema{{alias.ext}}';
|
|
15
|
+
|
|
16
|
+
{{#if style.declared}}
|
|
17
|
+
@Repository({{name.pascal}})
|
|
18
|
+
{{/if}}
|
|
19
|
+
export class {{adapter.pascal}} extends TypeOrmReadModelStore<{{name.pascal}}Row> implements {{name.pascal}} {
|
|
20
|
+
{{#if tenant.scoped}}
|
|
21
|
+
constructor(database: TypeOrmContext, scope: ExecutionScope) {
|
|
22
|
+
super(database, { entity: {{name.camel}}, tenant: { scope }, definition: {{name.camel}}Criteria });
|
|
23
|
+
}
|
|
24
|
+
{{/if}}
|
|
25
|
+
{{#unless tenant.scoped}}
|
|
26
|
+
constructor(database: TypeOrmContext) {
|
|
27
|
+
super(database, { entity: {{name.camel}}, definition: {{name.camel}}Criteria });
|
|
28
|
+
}
|
|
29
|
+
{{/unless}}
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
@@imports
|
|
2
|
+
{{#if tenant.scoped}}
|
|
3
|
+
import type { TenantScoped } from '@ddd-ts-kit/kernel';
|
|
4
|
+
import { readModelColumns, tenantColumn, type ReadModelStamps } from '@ddd-ts-kit/typeorm';
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{#unless tenant.scoped}}
|
|
7
|
+
import { readModelColumns, type ReadModelStamps } from '@ddd-ts-kit/typeorm';
|
|
8
|
+
{{/unless}}
|
|
9
|
+
import type { {{name.pascal}}Row } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
10
|
+
@@tables
|
|
11
|
+
{{#if tenant.scoped}}
|
|
12
|
+
export const {{name.camel}} = new EntitySchema<{{name.pascal}}Row & TenantScoped & ReadModelStamps>({
|
|
13
|
+
name: '{{context.pascal}}{{name.pascal}}',
|
|
14
|
+
tableName: '{{table}}',
|
|
15
|
+
schema: {{context.constant}}_SCHEMA,
|
|
16
|
+
columns: {
|
|
17
|
+
id: { type: 'text', primary: true },
|
|
18
|
+
{{#if fields.any}}
|
|
19
|
+
{{fields.typeormTable}}
|
|
20
|
+
{{/if}}
|
|
21
|
+
tenantId: { ...tenantColumn().tenantId, select: false },
|
|
22
|
+
...readModelColumns(),
|
|
23
|
+
},
|
|
24
|
+
indices: [{ name: '{{table}}_tenant_idx', columns: ['tenantId', 'id'] }],
|
|
25
|
+
{{#if fields.checked}}
|
|
26
|
+
checks: [
|
|
27
|
+
{
|
|
28
|
+
{{fields.typeormCheck}}
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
{{/if}}
|
|
32
|
+
});
|
|
33
|
+
{{/if}}
|
|
34
|
+
{{#unless tenant.scoped}}
|
|
35
|
+
export const {{name.camel}} = new EntitySchema<{{name.pascal}}Row & ReadModelStamps>({
|
|
36
|
+
name: '{{context.pascal}}{{name.pascal}}',
|
|
37
|
+
tableName: '{{table}}',
|
|
38
|
+
schema: {{context.constant}}_SCHEMA,
|
|
39
|
+
columns: {
|
|
40
|
+
id: { type: 'text', primary: true },
|
|
41
|
+
{{#if fields.any}}
|
|
42
|
+
{{fields.typeormTable}}
|
|
43
|
+
{{/if}}
|
|
44
|
+
...readModelColumns(),
|
|
45
|
+
},
|
|
46
|
+
{{#if fields.checked}}
|
|
47
|
+
checks: [
|
|
48
|
+
{
|
|
49
|
+
{{fields.typeormCheck}}
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
{{/if}}
|
|
53
|
+
});
|
|
54
|
+
{{/unless}}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@@imports
|
|
2
|
+
{{#if adapter.needsDatabase}}
|
|
3
|
+
{{#if tenant.scoped}}
|
|
4
|
+
import { ExecutionScope } from '@ddd-ts-kit/kernel';
|
|
5
|
+
{{/if}}
|
|
6
|
+
{{storage.moduleImport}}
|
|
7
|
+
{{/if}}
|
|
8
|
+
import { {{name.pascal}} } from '{{alias.context}}/application/ports/{{name.kebab}}.port{{alias.ext}}';
|
|
9
|
+
import { {{adapter.pascal}} } from '{{alias.context}}/infrastructure/persistence/{{adapter.kebab}}{{alias.ext}}';
|
|
10
|
+
@@registrations
|
|
11
|
+
{{#if adapter.needsDatabase}}
|
|
12
|
+
{{#if tenant.scoped}}
|
|
13
|
+
builder.bind({{name.pascal}}).toClass({{adapter.pascal}}, [{{storage.token}}, ExecutionScope]).as('repository');
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{#unless tenant.scoped}}
|
|
16
|
+
builder.bind({{name.pascal}}).toClass({{adapter.pascal}}, [{{storage.token}}]).as('repository');
|
|
17
|
+
{{/unless}}
|
|
18
|
+
{{/if}}
|
|
19
|
+
{{#unless adapter.needsDatabase}}
|
|
20
|
+
builder.bind({{name.pascal}}).toClass({{adapter.pascal}}).as('repository');
|
|
21
|
+
{{/unless}}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
@@imports
|
|
2
2
|
import type { {{aggregate.pascal}}Row } from '{{alias.context}}/infrastructure/persistence/{{aggregate.kebab}}-row.schema{{alias.ext}}';
|
|
3
|
+
import { auditColumns } from '@ddd-ts-kit/typeorm';
|
|
3
4
|
{{#if tenant.scoped}}
|
|
4
5
|
import { tenantColumn } from '@ddd-ts-kit/typeorm';
|
|
5
6
|
{{/if}}
|