ddd-ts-kit 0.11.0 → 0.13.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/README.md +21 -8
- 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/domain-events/refused-before-commit.js +1 -1
- package/dist/check/domain-events/refused-before-commit.js.map +1 -1
- package/dist/check/errors/kit-error-codes.d.ts.map +1 -1
- package/dist/check/errors/kit-error-codes.js +2 -0
- package/dist/check/errors/kit-error-codes.js.map +1 -1
- package/dist/check/explain/errors-docs.js +1 -1
- package/dist/check/explain/errors-docs.js.map +1 -1
- package/dist/check/explain/events-docs.js +1 -1
- package/dist/check/explain/events-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/schema-docs.d.ts +3 -0
- package/dist/check/explain/schema-docs.d.ts.map +1 -0
- package/dist/check/explain/schema-docs.js +28 -0
- package/dist/check/explain/schema-docs.js.map +1 -0
- package/dist/check/fixtures/domain-events-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/domain-events-fixtures.js +18 -0
- package/dist/check/fixtures/domain-events-fixtures.js.map +1 -1
- package/dist/check/fixtures/fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/fixtures.js +2 -0
- package/dist/check/fixtures/fixtures.js.map +1 -1
- package/dist/check/fixtures/schema-fixtures.d.ts +3 -0
- package/dist/check/fixtures/schema-fixtures.d.ts.map +1 -0
- package/dist/check/fixtures/schema-fixtures.js +129 -0
- package/dist/check/fixtures/schema-fixtures.js.map +1 -0
- package/dist/check/fixtures/standard-fixtures.d.ts.map +1 -1
- package/dist/check/fixtures/standard-fixtures.js +8 -0
- package/dist/check/fixtures/standard-fixtures.js.map +1 -1
- package/dist/check/rules/domain-events-transactional-before-commit.js +1 -1
- package/dist/check/rules/domain-events-transactional-before-commit.js.map +1 -1
- package/dist/check/rules/schema-no-duplicate-shape.d.ts +3 -0
- package/dist/check/rules/schema-no-duplicate-shape.d.ts.map +1 -0
- package/dist/check/rules/schema-no-duplicate-shape.js +60 -0
- package/dist/check/rules/schema-no-duplicate-shape.js.map +1 -0
- package/dist/check/rules/schema-presentation-only.d.ts +3 -0
- package/dist/check/rules/schema-presentation-only.d.ts.map +1 -0
- package/dist/check/rules/schema-presentation-only.js +53 -0
- package/dist/check/rules/schema-presentation-only.js.map +1 -0
- package/dist/check/schemas/class-shapes.d.ts +9 -0
- package/dist/check/schemas/class-shapes.d.ts.map +1 -0
- package/dist/check/schemas/class-shapes.js +52 -0
- package/dist/check/schemas/class-shapes.js.map +1 -0
- package/dist/check/schemas/declared-shape.d.ts +9 -0
- package/dist/check/schemas/declared-shape.d.ts.map +1 -0
- package/dist/check/schemas/declared-shape.js +2 -0
- package/dist/check/schemas/declared-shape.js.map +1 -0
- package/dist/check/schemas/holds-schemas.d.ts +5 -0
- package/dist/check/schemas/holds-schemas.d.ts.map +1 -0
- package/dist/check/schemas/holds-schemas.js +12 -0
- package/dist/check/schemas/holds-schemas.js.map +1 -0
- package/dist/check/schemas/object-shapes.d.ts +8 -0
- package/dist/check/schemas/object-shapes.d.ts.map +1 -0
- package/dist/check/schemas/object-shapes.js +31 -0
- package/dist/check/schemas/object-shapes.js.map +1 -0
- package/dist/check/schemas/restored-code.d.ts +7 -0
- package/dist/check/schemas/restored-code.d.ts.map +1 -0
- package/dist/check/schemas/restored-code.js +17 -0
- package/dist/check/schemas/restored-code.js.map +1 -0
- package/dist/check/schemas/shared-presentation.d.ts +4 -0
- package/dist/check/schemas/shared-presentation.d.ts.map +1 -0
- package/dist/check/schemas/shared-presentation.js +5 -0
- package/dist/check/schemas/shared-presentation.js.map +1 -0
- package/dist/check/schemas/shares-schemas.d.ts +4 -0
- package/dist/check/schemas/shares-schemas.d.ts.map +1 -0
- package/dist/check/schemas/shares-schemas.js +5 -0
- package/dist/check/schemas/shares-schemas.js.map +1 -0
- package/dist/check/schemas/still-generated.d.ts +8 -0
- package/dist/check/schemas/still-generated.d.ts.map +1 -0
- package/dist/check/schemas/still-generated.js +11 -0
- package/dist/check/schemas/still-generated.js.map +1 -0
- package/dist/check/schemas/top-level-statements.d.ts +3 -0
- package/dist/check/schemas/top-level-statements.d.ts.map +1 -0
- package/dist/check/schemas/top-level-statements.js +21 -0
- package/dist/check/schemas/top-level-statements.js.map +1 -0
- package/dist/check/schemas/validation-packages.d.ts +3 -0
- package/dist/check/schemas/validation-packages.d.ts.map +1 -0
- package/dist/check/schemas/validation-packages.js +13 -0
- package/dist/check/schemas/validation-packages.js.map +1 -0
- package/dist/check/standard/parallel-names.d.ts.map +1 -1
- package/dist/check/standard/parallel-names.js +6 -0
- package/dist/check/standard/parallel-names.js.map +1 -1
- package/dist/commands/generate.js +23 -19
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +4 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/config/default-allowed-packages.d.ts.map +1 -1
- package/dist/config/default-allowed-packages.js +1 -0
- package/dist/config/default-allowed-packages.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/parse-stack.d.ts.map +1 -1
- package/dist/config/parse-stack.js +3 -1
- package/dist/config/parse-stack.js.map +1 -1
- package/dist/config/stack.d.ts +18 -2
- package/dist/config/stack.d.ts.map +1 -1
- package/dist/config/stack.js +4 -2
- package/dist/config/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/route/cache-policy-text.d.ts +8 -0
- package/dist/generate/kinds/route/cache-policy-text.d.ts.map +1 -0
- package/dist/generate/kinds/route/cache-policy-text.js +41 -0
- package/dist/generate/kinds/route/cache-policy-text.js.map +1 -0
- package/dist/generate/kinds/route/controller-imports.d.ts.map +1 -1
- package/dist/generate/kinds/route/controller-imports.js +2 -1
- package/dist/generate/kinds/route/controller-imports.js.map +1 -1
- package/dist/generate/kinds/route/controller-plan.d.ts +2 -0
- package/dist/generate/kinds/route/controller-plan.d.ts.map +1 -1
- package/dist/generate/kinds/route/controller-types.d.ts.map +1 -1
- package/dist/generate/kinds/route/controller-types.js +4 -2
- package/dist/generate/kinds/route/controller-types.js.map +1 -1
- package/dist/generate/kinds/route/controller-vars.d.ts.map +1 -1
- package/dist/generate/kinds/route/controller-vars.js +23 -8
- package/dist/generate/kinds/route/controller-vars.js.map +1 -1
- package/dist/generate/kinds/route/dto-classes.d.ts +5 -2
- package/dist/generate/kinds/route/dto-classes.d.ts.map +1 -1
- package/dist/generate/kinds/route/dto-classes.js +6 -3
- package/dist/generate/kinds/route/dto-classes.js.map +1 -1
- package/dist/generate/kinds/route/plan-controller.d.ts.map +1 -1
- package/dist/generate/kinds/route/plan-controller.js +4 -1
- package/dist/generate/kinds/route/plan-controller.js.map +1 -1
- package/dist/generate/kinds/route/route-vars.d.ts.map +1 -1
- package/dist/generate/kinds/route/route-vars.js +17 -4
- package/dist/generate/kinds/route/route-vars.js.map +1 -1
- package/dist/generate/kinds/route/search-line-libraries.d.ts +3 -0
- package/dist/generate/kinds/route/search-line-libraries.d.ts.map +1 -0
- package/dist/generate/kinds/route/search-line-libraries.js +3 -0
- package/dist/generate/kinds/route/search-line-libraries.js.map +1 -0
- package/dist/generate/kinds/route/shares-schemas.d.ts +4 -0
- package/dist/generate/kinds/route/shares-schemas.d.ts.map +1 -0
- package/dist/generate/kinds/route/shares-schemas.js +5 -0
- package/dist/generate/kinds/route/shares-schemas.js.map +1 -0
- package/dist/generate/kinds/route/write-controller.d.ts.map +1 -1
- package/dist/generate/kinds/route/write-controller.js +4 -2
- package/dist/generate/kinds/route/write-controller.js.map +1 -1
- package/dist/generate/kinds/route-kind.d.ts.map +1 -1
- package/dist/generate/kinds/route-kind.js +12 -3
- package/dist/generate/kinds/route-kind.js.map +1 -1
- package/dist/generate/kinds/schema-kind.d.ts +3 -0
- package/dist/generate/kinds/schema-kind.d.ts.map +1 -0
- package/dist/generate/kinds/schema-kind.js +36 -0
- package/dist/generate/kinds/schema-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/help/usage.d.ts +1 -1
- package/dist/help/usage.d.ts.map +1 -1
- package/dist/help/usage.js +5 -2
- package/dist/help/usage.js.map +1 -1
- package/dist/init/files/project-files.d.ts.map +1 -1
- package/dist/init/files/project-files.js +3 -1
- package/dist/init/files/project-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 +27 -24
- package/dist/init/manifest/versions.js.map +1 -1
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +13 -2
- package/dist/init/stack/resolve-stack.js.map +1 -1
- package/dist/init/stack/stack-options.d.ts +3 -0
- package/dist/init/stack/stack-options.d.ts.map +1 -1
- package/dist/init/template-vars.js +4 -3
- package/dist/init/template-vars.js.map +1 -1
- package/dist/init/validation-dependencies.d.ts.map +1 -1
- package/dist/init/validation-dependencies.js +1 -0
- package/dist/init/validation-dependencies.js.map +1 -1
- package/dist/stack/stack-vars.js +14 -6
- 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 +2 -2
- package/templates/controller/controller.class-validator.ts.tpl +5 -2
- package/templates/controller/controller.none.ts.tpl +5 -2
- package/templates/controller/controller.search.ts.tpl +17 -0
- package/templates/controller/controller.standard-schema.ts.tpl +5 -2
- package/templates/controller/controller.typebox.ts.tpl +98 -0
- package/templates/controller/controller.zod.ts.tpl +5 -2
- package/templates/docs/openapi.json.tpl +9 -0
- package/templates/init/docker/docker-compose.yml.tpl +20 -0
- package/templates/init/docker/env.example.tpl +10 -0
- package/templates/init/docker/varnish.vcl.tpl +74 -0
- package/templates/init/e2e/start-application.database.ts.tpl +28 -0
- package/templates/init/e2e/start-application.memory.ts.tpl +30 -0
- package/templates/init/e2e/test-environment.ts.tpl +5 -0
- package/templates/init/main.ts.tpl +13 -0
- package/templates/init/platform/auth/http-boundary.ts.tpl +29 -0
- package/templates/init/platform/compose-application.tsyringe.ts.tpl +13 -0
- package/templates/init/platform/config/app-config.ts.tpl +6 -0
- package/templates/init/platform/config/load-config.ts.tpl +12 -0
- package/templates/init/platform/create-platform.manual.ts.tpl +31 -0
- package/templates/init/platform/http/start-http-server.hono.ts.tpl +84 -0
- package/templates/init/platform/platform.manual.ts.tpl +7 -0
- package/templates/init/rules/presentation.md.tpl +5 -1
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/route/route.class-validator.ts.tpl +3 -3
- package/templates/route/route.none.ts.tpl +3 -3
- package/templates/route/route.search.ts.tpl +14 -0
- package/templates/route/route.standard-schema.ts.tpl +3 -3
- package/templates/route/route.typebox.ts.tpl +79 -0
- package/templates/route/route.zod.ts.tpl +3 -3
- package/templates/schema/schema.class-validator.ts.tpl +3 -0
- package/templates/schema/schema.custom.ts.tpl +14 -0
- package/templates/schema/schema.typebox.ts.tpl +8 -0
- package/templates/schema/schema.zod.ts.tpl +7 -0
- package/templates/service/main.ts.tpl +13 -0
|
@@ -17,6 +17,9 @@ import {
|
|
|
17
17
|
InMemoryRateLimiter,
|
|
18
18
|
{{/if}}
|
|
19
19
|
NoopErrorReporter,
|
|
20
|
+
{{#if httpCache.varnish}}
|
|
21
|
+
PublishedCacheInvalidation,
|
|
22
|
+
{{/if}}
|
|
20
23
|
ScopedActorContext,
|
|
21
24
|
SystemClock,
|
|
22
25
|
UuidGenerator,
|
|
@@ -143,7 +146,12 @@ export function createPlatform(persistence: Persistence, options: PlatformOption
|
|
|
143
146
|
|
|
144
147
|
return {
|
|
145
148
|
...foundations,
|
|
149
|
+
{{#if httpCache.varnish}}
|
|
150
|
+
...withCacheInvalidation(eventsOn(persistence, options, { scope, traced }), foundations),
|
|
151
|
+
{{/if}}
|
|
152
|
+
{{#unless httpCache.varnish}}
|
|
146
153
|
...eventsOn(persistence, options, { scope, traced }),
|
|
154
|
+
{{/unless}}
|
|
147
155
|
// Around every use case, outermost first: {{#if errors.sentry}}the report of an unexpected failure, {{/if}}its log entry, its measure, the permission, its span; a command then {{#if files.any}}has the file it carries staged, out of any transaction, and {{/if}}runs in the unit of work.
|
|
148
156
|
commands: chain(new InMemoryCommandBus(), [
|
|
149
157
|
...observed,
|
|
@@ -287,6 +295,29 @@ function eventsOn(
|
|
|
287
295
|
};
|
|
288
296
|
}
|
|
289
297
|
|
|
298
|
+
{{#if httpCache.varnish}}
|
|
299
|
+
/**
|
|
300
|
+
* The events, and the purges a change asks for, written to the outbox with it through the same publisher: a rollback
|
|
301
|
+
* takes them away, the relay sends them to Varnish once committed.{{#if httpCache.perTenant}} Filed under the tenant
|
|
302
|
+
* of the work, as the answers are tagged.{{/if}}
|
|
303
|
+
*/
|
|
304
|
+
function withCacheInvalidation(events: Events, { ids, clock, scope }: Foundations): Events & CacheInvalidating {
|
|
305
|
+
const { publisher } = events;
|
|
306
|
+
|
|
307
|
+
{{#if httpCache.perTenant}}
|
|
308
|
+
return {
|
|
309
|
+
...events,
|
|
310
|
+
cacheInvalidation: new PublishedCacheInvalidation({ publisher, ids, clock, scope, perTenant: true }),
|
|
311
|
+
};
|
|
312
|
+
{{/if}}
|
|
313
|
+
{{#unless httpCache.perTenant}}
|
|
314
|
+
return { ...events, cacheInvalidation: new PublishedCacheInvalidation({ publisher, ids, clock, scope }) };
|
|
315
|
+
{{/unless}}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
type CacheInvalidating = Pick<Platform, 'cacheInvalidation'>;
|
|
319
|
+
|
|
320
|
+
{{/if}}
|
|
290
321
|
interface Observation {
|
|
291
322
|
readonly scope: Platform['scope'];
|
|
292
323
|
readonly traced: TracedApplication;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { AddressInfo } from 'node:net';
|
|
2
|
+
import { serve, type ServerType } from '@hono/node-server';
|
|
3
|
+
{{#if cache.rateLimit}}
|
|
4
|
+
import { getConnInfo } from '@hono/node-server/conninfo';
|
|
5
|
+
{{/if}}
|
|
6
|
+
import { Hono } from 'hono';
|
|
7
|
+
import { mountHono } from '@ddd-ts-kit/http/hono';
|
|
8
|
+
import type { Application } from '{{alias.platform}}/compose-application{{alias.ext}}';
|
|
9
|
+
import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
|
|
10
|
+
{{#if cache.rateLimit}}
|
|
11
|
+
import { refusalFor } from '{{alias.platform}}/http/refusal-for{{alias.ext}}';
|
|
12
|
+
{{/if}}
|
|
13
|
+
{{#if docs.any}}
|
|
14
|
+
import { withDocumentation } from '{{alias.platform}}/http/with-documentation{{alias.ext}}';
|
|
15
|
+
{{/if}}
|
|
16
|
+
|
|
17
|
+
export interface HttpServer {
|
|
18
|
+
/** The port really bound: differs from the configured one when that was 0. */
|
|
19
|
+
readonly port: number;
|
|
20
|
+
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** What the server needs of the application: its routes and what stands at its edge. */
|
|
25
|
+
type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}>;
|
|
26
|
+
|
|
27
|
+
export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
|
|
28
|
+
const app = new Hono();
|
|
29
|
+
|
|
30
|
+
{{#if cache.rateLimit}}
|
|
31
|
+
guardTheDoor(app, served, config);
|
|
32
|
+
{{/if}}
|
|
33
|
+
{{#if docs.any}}
|
|
34
|
+
mountHono(app, withDocumentation(served.routes, config), served.boundary);
|
|
35
|
+
{{/if}}
|
|
36
|
+
{{#unless docs.any}}
|
|
37
|
+
mountHono(app, served.routes, served.boundary);
|
|
38
|
+
{{/unless}}
|
|
39
|
+
|
|
40
|
+
const server = await listen(app, config.port);
|
|
41
|
+
|
|
42
|
+
return { port: boundPort(server), close: () => close(server) };
|
|
43
|
+
}
|
|
44
|
+
{{#if cache.rateLimit}}
|
|
45
|
+
|
|
46
|
+
/** The readiness probe, then the limiter, before any route. */
|
|
47
|
+
function guardTheDoor(app: Hono, served: Served, config: AppConfig): void {
|
|
48
|
+
app.get('/health/ready', async (context) => {
|
|
49
|
+
const ready = await served.ready();
|
|
50
|
+
|
|
51
|
+
return context.json({ status: ready ? 'up' : 'down' }, ready ? 200 : 503);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
app.use(async (context, next) => {
|
|
55
|
+
const refusal = await refusalFor(served.rateLimiter, config.rateLimit, getConnInfo(context).remote.address);
|
|
56
|
+
|
|
57
|
+
if (refusal === undefined) {
|
|
58
|
+
await next();
|
|
59
|
+
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return new Response(JSON.stringify(refusal.problem), { status: refusal.problem.status, headers: refusal.headers });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
{{/if}}
|
|
67
|
+
|
|
68
|
+
function listen(app: Hono, port: number): Promise<ServerType> {
|
|
69
|
+
return new Promise<ServerType>((resolve) => {
|
|
70
|
+
const server = serve({ fetch: app.fetch, port }, () => resolve(server));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function boundPort(server: ServerType): number {
|
|
75
|
+
const address: AddressInfo | string | null = server.address();
|
|
76
|
+
|
|
77
|
+
return typeof address === 'object' && address !== null ? address.port : 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function close(server: ServerType): Promise<void> {
|
|
81
|
+
return new Promise<void>((resolve, reject) => {
|
|
82
|
+
server.close((error) => (error === undefined ? resolve() : reject(error)));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -3,6 +3,9 @@ import type { Access } from '@ddd-ts-kit/auth';
|
|
|
3
3
|
import type {
|
|
4
4
|
ActorContext,
|
|
5
5
|
Cache,
|
|
6
|
+
{{#if httpCache.varnish}}
|
|
7
|
+
CacheInvalidation,
|
|
8
|
+
{{/if}}
|
|
6
9
|
Clock,
|
|
7
10
|
DomainEventDispatcher,
|
|
8
11
|
{{#if errors.sentry}}
|
|
@@ -69,6 +72,10 @@ export interface Platform {
|
|
|
69
72
|
readonly errors: ErrorReporter;
|
|
70
73
|
{{/if}}
|
|
71
74
|
readonly cache: Cache;
|
|
75
|
+
{{#if httpCache.varnish}}
|
|
76
|
+
/** What a before-commit handler asks to purge from Varnish: the purge runs after the commit, through the outbox. */
|
|
77
|
+
readonly cacheInvalidation: CacheInvalidation;
|
|
78
|
+
{{/if}}
|
|
72
79
|
{{#if cache.rateLimit}}
|
|
73
80
|
readonly rateLimiter: RateLimiter;
|
|
74
81
|
{{/if}}
|
|
@@ -29,7 +29,11 @@ paths:
|
|
|
29
29
|
{{/if}}
|
|
30
30
|
- No role or ownership test in a controller or a route (`authz/in-application`): a guard of the group asks for a role at the edge, the bus asks for the permission, a policy decides on loaded state.
|
|
31
31
|
- Request and response types are presentation types, one class or schema per file next to the controller (`*.body.ts`, `*.params.ts`, `*.answer.ts`...; `*.dto.ts` for function routes and under `shared/`): never an aggregate, never a row.
|
|
32
|
+
{{#if schemas.shared}}
|
|
33
|
+
- A shape several routes use is declared once, in `presentation/http/shared/<name>.schema.ts` (`npx ddd-ts-kit generate schema <context> <Name>`), or in `presentation/` of the shared kernel when several contexts answer with it (`generate schema shared-kernel <Name>`), and shared: the contract documents it once and every route refers to it. A route takes the part it needs from it (pick, omit, partial, extend) instead of copying it, and answers an identifier with `acceptedSchema` of `@ddd-ts-kit/http` (`schema/no-duplicate-shape`). Only presentation layers import a schema (`schema/presentation-only`).
|
|
34
|
+
{{/if}}
|
|
35
|
+
- A read declares how caches may keep its answer in `cache` (its controller, its route group, or the spec of a function route): `private` for what a caller reads again, with `etag`; `public` only for what is the same for everybody, with `tags` naming the resources it shows. A route that knows its caller is `no-store` unless it says otherwise, and a `public` answer of such a route is refused unless `vary` names who calls (`Authorization`, `Cookie`) or the header its tenant is read from (`presentation/shared-cache-varies`, then the mount): never cache a decision of authorization across actors. A group policy reaches the reads of the group only. A write that must not overwrite a newer version declares `ifMatch` and hands `context.expectedVersion` to its command; the handler calls `expectVersion` (412). A change purges the answers it makes stale from a `before-commit` handler of its domain event, `CacheInvalidation.invalidate([cacheTag(...)])` (`platform.cacheInvalidation` on a platform wired by hand): the purge then runs after the commit, through the outbox. Every event that changes what a kept answer shows, its version included, purges it, not only the one the route is about.
|
|
32
36
|
- Never put the message of an unexpected failure in a response or a log.
|
|
33
37
|
- Files: the canonical tree of `presentation/http/` (`naming/suffix`, `tree/closed`): a folder per controller, `*.routes.ts` for the groups, `guards/`, `shared/`; function routes stay flat (`*.route.ts`, `*.dto.ts`).
|
|
34
38
|
- After a change, `npm run docs:generate` regenerates the contract, `openapi/openapi.yaml` (one file per document when `openapi.documents` of `ddd-ts-kit.config.json` splits it; JSON under `openapi.format: json`), committed with the route; CI fails on a difference. Never edit it by hand.{{#if sdk.on}} It regenerates the typed clients under `clients/` too (`npx ddd-ts-kit sdk`), committed with it.{{/if}}
|
|
35
|
-
- Contract with `/ddd-ts-kit:document`. Create with `npx ddd-ts-kit generate route <context> <UseCase> --method <M> --path <p> [--group <Name>] [--mapper] [--serializer] --json`, then `generate e2e <context> <UseCase>`; `generate route-group` and `generate guard` write a group and a guard.
|
|
39
|
+
- Contract with `/ddd-ts-kit:document`. Create with `npx ddd-ts-kit generate route <context> <UseCase> --method <M> --path <p> [--group <Name>] [--mapper] [--serializer] [--cache public|private|no-store] --json`, then `generate e2e <context> <UseCase>`; `generate route-group` and `generate guard` write a group and a guard.
|
|
@@ -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.13.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,7 +1,7 @@
|
|
|
1
1
|
{{#if route.protected}}
|
|
2
2
|
import { actorOf } from '@ddd-ts-kit/auth';
|
|
3
3
|
{{/if}}
|
|
4
|
-
import { defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
4
|
+
import { {{#if route.sharedAccepted}}acceptedSchema, {{/if}}defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
5
5
|
import type { {{route.busType}} } from '@ddd-ts-kit/kernel';
|
|
6
6
|
import { classSchema } from '@ddd-ts-kit/validation/class-validator';
|
|
7
7
|
{{route.useCaseImport}}
|
|
@@ -14,7 +14,7 @@ const params = classSchema({{name.pascal}}Params);
|
|
|
14
14
|
// TODO(domain): once {{name.pascal}}Body has its decorated fields, drop the second argument: it only lets a class without any decorated field through.
|
|
15
15
|
const body = classSchema({{name.pascal}}Body, { validator: { forbidUnknownValues: false } });
|
|
16
16
|
{{/if}}
|
|
17
|
-
{{#if route.
|
|
17
|
+
{{#if route.ownAccepted}}
|
|
18
18
|
const accepted = classSchema({{name.pascal}}Accepted);
|
|
19
19
|
{{/if}}
|
|
20
20
|
{{#if route.isQuery}}
|
|
@@ -34,7 +34,7 @@ export function {{name.camel}}Route({{route.bus}}: {{route.busType}}): Route {
|
|
|
34
34
|
request: { {{route.requestParts}} },
|
|
35
35
|
{{/if}}
|
|
36
36
|
{{#if route.returnsId}}
|
|
37
|
-
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body:
|
|
37
|
+
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body: {{route.acceptedBody}} } },
|
|
38
38
|
{{/if}}
|
|
39
39
|
{{#if route.returnsNothing}}
|
|
40
40
|
responses: { {{route.status}}: { description: 'Done.' } },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{{#if route.protected}}
|
|
2
2
|
import { actorOf } from '@ddd-ts-kit/auth';
|
|
3
3
|
{{/if}}
|
|
4
|
-
import { defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
4
|
+
import { {{#if route.sharedAccepted}}acceptedSchema, {{/if}}defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
5
5
|
{{#if route.usesSchema}}
|
|
6
6
|
import { err, ok, type {{route.busType}} } from '@ddd-ts-kit/kernel';
|
|
7
7
|
import { customSchema } from '@ddd-ts-kit/validation';
|
|
@@ -26,7 +26,7 @@ const anyObject = customSchema<Record<string, unknown>>(
|
|
|
26
26
|
const body = anyObject;
|
|
27
27
|
|
|
28
28
|
{{/if}}
|
|
29
|
-
{{#if route.
|
|
29
|
+
{{#if route.ownAccepted}}
|
|
30
30
|
const accepted = customSchema<{ readonly id: string }>(
|
|
31
31
|
(input) =>
|
|
32
32
|
typeof input === 'object' && input !== null && 'id' in input && typeof input.id === 'string'
|
|
@@ -53,7 +53,7 @@ export function {{name.camel}}Route({{route.bus}}: {{route.busType}}): Route {
|
|
|
53
53
|
request: { body },
|
|
54
54
|
{{/if}}
|
|
55
55
|
{{#if route.returnsId}}
|
|
56
|
-
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body:
|
|
56
|
+
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body: {{route.acceptedBody}} } },
|
|
57
57
|
{{/if}}
|
|
58
58
|
{{#if route.returnsNothing}}
|
|
59
59
|
responses: { {{route.status}}: { description: 'Done.' } },
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{{#if validation.zod}}
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
{{/if}}
|
|
4
|
+
{{#if validation.typebox}}
|
|
5
|
+
import Type from 'typebox';
|
|
6
|
+
{{/if}}
|
|
4
7
|
import { actorOf } from '@ddd-ts-kit/auth';
|
|
5
8
|
import { defineRoute, pageQuerySchema, pageResponse, pageSchemaOf, type Route } from '@ddd-ts-kit/http';
|
|
6
9
|
{{#if search.customSchema}}
|
|
@@ -16,6 +19,9 @@ import { zodSchema } from '@ddd-ts-kit/validation/zod';
|
|
|
16
19
|
{{#if validation.classValidator}}
|
|
17
20
|
import { classSchema } from '@ddd-ts-kit/validation/class-validator';
|
|
18
21
|
{{/if}}
|
|
22
|
+
{{#if validation.typebox}}
|
|
23
|
+
import { typeboxSchema } from '@ddd-ts-kit/validation/typebox';
|
|
24
|
+
{{/if}}
|
|
19
25
|
{{route.useCaseImport}}
|
|
20
26
|
{{#if validation.classValidator}}
|
|
21
27
|
import { {{name.pascal}}Line } from '{{alias.context}}/presentation/http/{{name.kebab}}-line.dto{{alias.ext}}';
|
|
@@ -36,6 +42,14 @@ const line = zodSchema(
|
|
|
36
42
|
{{#if validation.classValidator}}
|
|
37
43
|
const line = classSchema({{name.pascal}}Line);
|
|
38
44
|
{{/if}}
|
|
45
|
+
{{#if validation.typebox}}
|
|
46
|
+
const line = typeboxSchema(
|
|
47
|
+
Type.Object({
|
|
48
|
+
id: Type.String(),
|
|
49
|
+
// TODO(domain): declare the fields of {{name.pascal}}Item that are part of the public contract.
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
{{/if}}
|
|
39
53
|
{{#if search.customSchema}}
|
|
40
54
|
interface {{name.pascal}}Line {
|
|
41
55
|
readonly id: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{{#if route.protected}}
|
|
2
2
|
import { actorOf } from '@ddd-ts-kit/auth';
|
|
3
3
|
{{/if}}
|
|
4
|
-
import { defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
4
|
+
import { {{#if route.sharedAccepted}}acceptedSchema, {{/if}}defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
5
5
|
import type { {{route.busType}} } from '@ddd-ts-kit/kernel';
|
|
6
6
|
{{#if route.usesSchema}}
|
|
7
7
|
import { standardSchema, type StandardSchemaV1 } from '@ddd-ts-kit/validation/standard-schema';
|
|
@@ -26,7 +26,7 @@ const anyObject: StandardSchemaV1<unknown, Record<string, unknown>> = {
|
|
|
26
26
|
const body = standardSchema(anyObject, { type: 'object' });
|
|
27
27
|
|
|
28
28
|
{{/if}}
|
|
29
|
-
{{#if route.
|
|
29
|
+
{{#if route.ownAccepted}}
|
|
30
30
|
const acceptedShape: StandardSchemaV1<unknown, { readonly id: string }> = {
|
|
31
31
|
'~standard': {
|
|
32
32
|
version: 1,
|
|
@@ -62,7 +62,7 @@ export function {{name.camel}}Route({{route.bus}}: {{route.busType}}): Route {
|
|
|
62
62
|
request: { body },
|
|
63
63
|
{{/if}}
|
|
64
64
|
{{#if route.returnsId}}
|
|
65
|
-
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body:
|
|
65
|
+
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body: {{route.acceptedBody}} } },
|
|
66
66
|
{{/if}}
|
|
67
67
|
{{#if route.returnsNothing}}
|
|
68
68
|
responses: { {{route.status}}: { description: 'Done.' } },
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import Type from 'typebox';
|
|
2
|
+
{{#if route.protected}}
|
|
3
|
+
import { actorOf } from '@ddd-ts-kit/auth';
|
|
4
|
+
{{/if}}
|
|
5
|
+
import { {{#if route.sharedAccepted}}acceptedSchema, {{/if}}defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
6
|
+
import type { {{route.busType}} } from '@ddd-ts-kit/kernel';
|
|
7
|
+
import { typeboxSchema } from '@ddd-ts-kit/validation/typebox';
|
|
8
|
+
{{route.useCaseImport}}
|
|
9
|
+
|
|
10
|
+
{{#if route.hasParams}}
|
|
11
|
+
const params = typeboxSchema(Type.Object({ {{route.typeboxParams}} }));
|
|
12
|
+
|
|
13
|
+
{{/if}}
|
|
14
|
+
{{#if route.hasBody}}
|
|
15
|
+
const body = typeboxSchema(
|
|
16
|
+
Type.Object({
|
|
17
|
+
// TODO(domain): declare the fields the client sends for "{{name.words}}", with shape constraints only (types, formats, lengths); business rules stay in the domain.
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
{{/if}}
|
|
22
|
+
{{#if route.ownAccepted}}
|
|
23
|
+
const accepted = typeboxSchema(Type.Object({ id: Type.String() }));
|
|
24
|
+
|
|
25
|
+
{{/if}}
|
|
26
|
+
{{#if route.isQuery}}
|
|
27
|
+
const answer = typeboxSchema(
|
|
28
|
+
Type.Object({
|
|
29
|
+
// TODO(domain): declare the fields of {{name.pascal}}Result that are part of the public contract.
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
{{/if}}
|
|
34
|
+
export function {{name.camel}}Route({{route.bus}}: {{route.busType}}): Route {
|
|
35
|
+
return defineRoute(
|
|
36
|
+
{
|
|
37
|
+
method: '{{route.method}}',
|
|
38
|
+
path: '{{route.path}}',
|
|
39
|
+
operationId: '{{name.camel}}',
|
|
40
|
+
summary: '{{name.title}}',
|
|
41
|
+
tags: ['{{context.kebab}}'],
|
|
42
|
+
{{#if route.hasRequest}}
|
|
43
|
+
request: { {{route.requestParts}} },
|
|
44
|
+
{{/if}}
|
|
45
|
+
{{#if route.returnsId}}
|
|
46
|
+
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body: {{route.acceptedBody}} } },
|
|
47
|
+
{{/if}}
|
|
48
|
+
{{#if route.returnsNothing}}
|
|
49
|
+
responses: { {{route.status}}: { description: 'Done.' } },
|
|
50
|
+
{{/if}}
|
|
51
|
+
{{#if route.isQuery}}
|
|
52
|
+
responses: { {{route.status}}: { description: 'The answer.', body: answer } },
|
|
53
|
+
{{/if}}
|
|
54
|
+
// TODO(domain): list the codes of the refusals "{{name.words}}" can raise, as their factories set them, so that they appear in the contract with their status (`errors/known-code`).
|
|
55
|
+
errors: [{{route.errorCodes}}],
|
|
56
|
+
security: {{route.security}},
|
|
57
|
+
},
|
|
58
|
+
async (input) => {
|
|
59
|
+
{{#if route.isQuery}}
|
|
60
|
+
// TODO(domain): build the query from `input` (params, query string); the actor is already there and map its answer to the public fields.
|
|
61
|
+
await {{route.bus}}.execute(new {{route.input}}({{route.actor}}));
|
|
62
|
+
|
|
63
|
+
return { status: {{route.status}}, body: {} };
|
|
64
|
+
{{/if}}
|
|
65
|
+
{{#if route.returnsId}}
|
|
66
|
+
// TODO(domain): build the command from `input` (body, params); the actor is already there.
|
|
67
|
+
const id = await {{route.bus}}.execute(new {{route.input}}({{route.actor}}));
|
|
68
|
+
|
|
69
|
+
return { status: {{route.status}}, body: { id } };
|
|
70
|
+
{{/if}}
|
|
71
|
+
{{#if route.returnsNothing}}
|
|
72
|
+
// TODO(domain): build the command from `input` (body, params); the actor is already there.
|
|
73
|
+
await {{route.bus}}.execute(new {{route.input}}({{route.actor}}));
|
|
74
|
+
|
|
75
|
+
return { status: {{route.status}} };
|
|
76
|
+
{{/if}}
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
{{#if route.protected}}
|
|
3
3
|
import { actorOf } from '@ddd-ts-kit/auth';
|
|
4
4
|
{{/if}}
|
|
5
|
-
import { defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
5
|
+
import { {{#if route.sharedAccepted}}acceptedSchema, {{/if}}defineRoute, type Route } from '@ddd-ts-kit/http';
|
|
6
6
|
import type { {{route.busType}} } from '@ddd-ts-kit/kernel';
|
|
7
7
|
import { zodSchema } from '@ddd-ts-kit/validation/zod';
|
|
8
8
|
{{route.useCaseImport}}
|
|
@@ -19,7 +19,7 @@ const body = zodSchema(
|
|
|
19
19
|
);
|
|
20
20
|
|
|
21
21
|
{{/if}}
|
|
22
|
-
{{#if route.
|
|
22
|
+
{{#if route.ownAccepted}}
|
|
23
23
|
const accepted = zodSchema(z.object({ id: z.string() }), { io: 'output' });
|
|
24
24
|
|
|
25
25
|
{{/if}}
|
|
@@ -44,7 +44,7 @@ export function {{name.camel}}Route({{route.bus}}: {{route.busType}}): Route {
|
|
|
44
44
|
request: { {{route.requestParts}} },
|
|
45
45
|
{{/if}}
|
|
46
46
|
{{#if route.returnsId}}
|
|
47
|
-
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body:
|
|
47
|
+
responses: { {{route.status}}: { description: 'Done; the body carries the identifier.', body: {{route.acceptedBody}} } },
|
|
48
48
|
{{/if}}
|
|
49
49
|
{{#if route.returnsNothing}}
|
|
50
50
|
responses: { {{route.status}}: { description: 'Done.' } },
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export class {{name.pascal}} {
|
|
2
|
+
// TODO(domain): declare the fields of "{{name.words}}" as a client sees them, each with its class-validator decorators (shape constraints only). A route uses the class whole (`classSchema({{name.pascal}}, { shared: true })`), nested (`@ValidateNested()` and `@Type`) or in part (`class Body extends pickClass({{name.pascal}}, [...]) {}`, `omitClass`, `partialClass`); the contract documents it once, as {{name.pascal}}.
|
|
3
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { err, ok } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { customSchema, sharedSchema } from '@ddd-ts-kit/validation';
|
|
3
|
+
|
|
4
|
+
// TODO(domain): replace the object check by the schema of "{{name.words}}" written with the validation library of the project, wrapped as it is here, and describe its fields in the JSON Schema; the contract documents it once, as {{name.pascal}}.
|
|
5
|
+
export const {{name.camel}}Schema = sharedSchema(
|
|
6
|
+
'{{name.pascal}}',
|
|
7
|
+
customSchema<Record<string, unknown>>(
|
|
8
|
+
(input) =>
|
|
9
|
+
typeof input === 'object' && input !== null && !Array.isArray(input)
|
|
10
|
+
? ok({ ...input })
|
|
11
|
+
: err([{ path: '', code: 'invalid_type', message: 'An object is expected.' }]),
|
|
12
|
+
{ type: 'object' },
|
|
13
|
+
),
|
|
14
|
+
);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Type from 'typebox';
|
|
2
|
+
|
|
3
|
+
export const {{name.camel}}Schema = Type.Object(
|
|
4
|
+
{
|
|
5
|
+
// TODO(domain): declare the fields of "{{name.words}}" as a client sees them, with shape constraints only (types, formats, lengths). A route uses the schema whole (`typeboxSchema({{name.camel}}Schema)`), inside another one, in part (`Type.Pick`, `Type.Omit`, `Type.Partial`) or extended (`Type.Intersect([{{name.camel}}Schema, Type.Object({...})])` keeps the reference); the contract documents it once, as {{name.pascal}}.
|
|
6
|
+
},
|
|
7
|
+
{ $id: '{{name.pascal}}' },
|
|
8
|
+
);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const {{name.camel}}Schema = z
|
|
4
|
+
.object({
|
|
5
|
+
// TODO(domain): declare the fields of "{{name.words}}" as a client sees them, with shape constraints only (types, formats, lengths). A route uses the schema whole (`zodSchema({{name.camel}}Schema)`), inside another one, or in part (`.pick`, `.omit`, `.partial`, `.extend`); the contract documents it once, as {{name.pascal}}.
|
|
6
|
+
})
|
|
7
|
+
.meta({ id: '{{name.pascal}}' });
|
|
@@ -4,6 +4,10 @@ import { tracing } from '{{alias.platform}}/tracing{{alias.ext}}';
|
|
|
4
4
|
// Imported second on purpose: a failure while the rest of the application loads is already reported.
|
|
5
5
|
import { errors } from '{{alias.platform}}/errors{{alias.ext}}';
|
|
6
6
|
{{/if}}
|
|
7
|
+
{{#if httpCache.varnish}}
|
|
8
|
+
import { VarnishCachePurger } from '@ddd-ts-kit/http/purgers';
|
|
9
|
+
import { PurgingPublisher } from '@ddd-ts-kit/kernel';
|
|
10
|
+
{{/if}}
|
|
7
11
|
{{#if http.any}}
|
|
8
12
|
import { createAuthenticator } from '{{alias.platform}}/auth/create-authenticator{{alias.ext}}';
|
|
9
13
|
{{/if}}
|
|
@@ -67,7 +71,16 @@ await application.start();
|
|
|
67
71
|
{{#if events.outbox}}
|
|
68
72
|
const relay = startOutboxRelay({
|
|
69
73
|
store: persistence.outbox,
|
|
74
|
+
{{#if httpCache.varnish}}
|
|
75
|
+
// The purge requests the use cases of the context wrote with their commands go to Varnish, every other event to the provider.
|
|
76
|
+
publisher: new PurgingPublisher(
|
|
77
|
+
new VarnishCachePurger({ url: config.varnishUrl, key: config.varnishPurgeKey }),
|
|
78
|
+
application.eventBus,
|
|
79
|
+
),
|
|
80
|
+
{{/if}}
|
|
81
|
+
{{#unless httpCache.varnish}}
|
|
70
82
|
publisher: application.eventBus,
|
|
83
|
+
{{/unless}}
|
|
71
84
|
intervalMs: config.outboxRelayIntervalMs,
|
|
72
85
|
logger: application.logger,
|
|
73
86
|
{{#if errors.sentry}}
|