ddd-ts-kit 0.11.0 → 0.12.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 +8 -6
- 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/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/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/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 +3 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/parse-stack.d.ts.map +1 -1
- package/dist/config/parse-stack.js +2 -1
- package/dist/config/parse-stack.js.map +1 -1
- package/dist/config/stack.d.ts +7 -0
- package/dist/config/stack.d.ts.map +1 -1
- package/dist/config/stack.js +1 -0
- package/dist/config/stack.js.map +1 -1
- package/dist/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-plan.d.ts +2 -0
- package/dist/generate/kinds/route/controller-plan.d.ts.map +1 -1
- package/dist/generate/kinds/route/controller-vars.js +4 -1
- package/dist/generate/kinds/route/controller-vars.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-kind.d.ts.map +1 -1
- package/dist/generate/kinds/route-kind.js +8 -1
- package/dist/generate/kinds/route-kind.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/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/versions.js +24 -24
- package/dist/init/stack/resolve-stack.d.ts.map +1 -1
- package/dist/init/stack/resolve-stack.js +10 -1
- package/dist/init/stack/resolve-stack.js.map +1 -1
- package/dist/init/stack/stack-options.d.ts +2 -0
- package/dist/init/stack/stack-options.d.ts.map +1 -1
- package/dist/init/template-vars.js +4 -3
- package/dist/init/template-vars.js.map +1 -1
- package/dist/stack/stack-vars.js +8 -1
- 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 +3 -0
- package/templates/controller/controller.none.ts.tpl +3 -0
- package/templates/controller/controller.search.ts.tpl +3 -0
- package/templates/controller/controller.standard-schema.ts.tpl +3 -0
- package/templates/controller/controller.zod.ts.tpl +3 -0
- 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/platform.manual.ts.tpl +7 -0
- package/templates/init/rules/presentation.md.tpl +2 -1
- package/templates/pipeline/package-scripts.json +1 -1
- package/templates/service/main.ts.tpl +13 -0
package/dist/stack/stack-vars.js
CHANGED
|
@@ -18,7 +18,7 @@ export function stackVars(config) {
|
|
|
18
18
|
style: one(style, ['declared', 'explicit']),
|
|
19
19
|
assembly: assemblyVars(config),
|
|
20
20
|
decorators: { legacy, standard: !legacy },
|
|
21
|
-
|
|
21
|
+
...edgeVars(config),
|
|
22
22
|
validation: one(validation, ['zod', 'class-validator', 'standard-schema', 'none']),
|
|
23
23
|
di: one(di, ['tsyringe', 'nest', 'manual']),
|
|
24
24
|
orm: { ...one(orm, ['drizzle', 'knex', 'prisma', 'typeorm', 'custom', 'none']), any: orm !== 'none' },
|
|
@@ -86,6 +86,13 @@ function assemblyVars(config) {
|
|
|
86
86
|
discovery: style === 'declared' && assembly === 'discovery',
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
+
/** The HTTP framework, and the shared cache in front of it. */
|
|
90
|
+
function edgeVars(config) {
|
|
91
|
+
const { httpCache, tenancy } = config.stack;
|
|
92
|
+
// A multi-tenant application files its tags under the tenant, on the answers and on the purges alike.
|
|
93
|
+
const perTenant = httpCache !== 'none' && tenancy !== 'none';
|
|
94
|
+
return { http: httpVars(config), httpCache: { ...one(httpCache, ['none', 'varnish']), perTenant } };
|
|
95
|
+
}
|
|
89
96
|
function httpVars(config) {
|
|
90
97
|
const { http } = config.stack;
|
|
91
98
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack-vars.js","sourceRoot":"","sources":["../../src/stack/stack-vars.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,6GAA6G;AAC7G,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC;IACnF,MAAM,MAAM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C,EAAE,SAAS,EAAE,EAAE,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC;AACtG,CAAC;AAED,SAAS,QAAQ,CAAC,MAAc;IAC9B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC;IAE9B,OAAO;QACL,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACpD,GAAG,EAAE,IAAI,KAAK,MAAM;QACpB,KAAK,EAAE,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;KAChD,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;KAChC,CAAC;AACJ,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.12.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.12.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ddd-ts-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Bootstrap, scaffold and verify DDD and Clean Architecture TypeScript projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"clean:packages": "node dist/bin.js check --clean-only ../kernel/src ../validation/src ../http/src ../tracing/src ../di/src ../events/src ../testing/src ../s3/src ../drizzle/src ../knex/src ../prisma/src ../typeorm/src ../aspects/src ../rabbitmq/src ../auth/src ../audit/src ../redis/src ../scheduling/src ../pino/src ../winston/src ../sentry/src ../kafka/src ../nats/src ../eslint-plugin/src"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@ddd-ts-kit/kernel": "^0.
|
|
32
|
+
"@ddd-ts-kit/kernel": "^0.12.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -44,6 +44,9 @@ const answer = classSchema({{name.pascal}}Answer, { validator: { forbidUnknownVa
|
|
|
44
44
|
{{/if}}
|
|
45
45
|
// 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`).
|
|
46
46
|
errors: [],
|
|
47
|
+
{{#if route.cached}}
|
|
48
|
+
cache: {{route.cache}},
|
|
49
|
+
{{/if}}
|
|
47
50
|
})
|
|
48
51
|
export class {{name.pascal}}Controller {
|
|
49
52
|
constructor({{route.constructorParams}}) {}
|
|
@@ -60,6 +60,9 @@ const answer = anyObject;
|
|
|
60
60
|
{{/if}}
|
|
61
61
|
// 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`).
|
|
62
62
|
errors: [],
|
|
63
|
+
{{#if route.cached}}
|
|
64
|
+
cache: {{route.cache}},
|
|
65
|
+
{{/if}}
|
|
63
66
|
})
|
|
64
67
|
export class {{name.pascal}}Controller {
|
|
65
68
|
constructor({{route.constructorParams}}) {}
|
|
@@ -65,6 +65,9 @@ const line = customSchema<{{name.pascal}}Line>(
|
|
|
65
65
|
response: { status: 200, description: 'One page of the search.', body: pageSchemaOf(line) },
|
|
66
66
|
// 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`).
|
|
67
67
|
errors: [],
|
|
68
|
+
{{#if route.cached}}
|
|
69
|
+
cache: {{route.cache}},
|
|
70
|
+
{{/if}}
|
|
68
71
|
})
|
|
69
72
|
export class {{name.pascal}}Controller {
|
|
70
73
|
constructor({{route.constructorParams}}) {}
|
|
@@ -72,6 +72,9 @@ const answer = standardSchema(anyObject, { type: 'object' });
|
|
|
72
72
|
{{/if}}
|
|
73
73
|
// 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`).
|
|
74
74
|
errors: [],
|
|
75
|
+
{{#if route.cached}}
|
|
76
|
+
cache: {{route.cache}},
|
|
77
|
+
{{/if}}
|
|
75
78
|
})
|
|
76
79
|
export class {{name.pascal}}Controller {
|
|
77
80
|
constructor({{route.constructorParams}}) {}
|
|
@@ -58,6 +58,9 @@ const answer = zodSchema(
|
|
|
58
58
|
{{/if}}
|
|
59
59
|
// 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`).
|
|
60
60
|
errors: [],
|
|
61
|
+
{{#if route.cached}}
|
|
62
|
+
cache: {{route.cache}},
|
|
63
|
+
{{/if}}
|
|
61
64
|
})
|
|
62
65
|
export class {{name.pascal}}Controller {
|
|
63
66
|
constructor({{route.constructorParams}}) {}
|
|
@@ -117,6 +117,15 @@
|
|
|
117
117
|
"responses": {
|
|
118
118
|
"200": {
|
|
119
119
|
"description": "A page of entries.",
|
|
120
|
+
"headers": {
|
|
121
|
+
"Cache-Control": {
|
|
122
|
+
"description": "How the caches on the way may keep this answer.",
|
|
123
|
+
"schema": {
|
|
124
|
+
"type": "string",
|
|
125
|
+
"const": "no-store"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
120
129
|
"content": {
|
|
121
130
|
"application/json": {
|
|
122
131
|
"schema": {
|
|
@@ -118,6 +118,26 @@ services:
|
|
|
118
118
|
timeout: 3s
|
|
119
119
|
retries: 30
|
|
120
120
|
|
|
121
|
+
{{/if}}
|
|
122
|
+
{{#if httpCache.varnish}}
|
|
123
|
+
# Varnish in front of the API (`npm run dev` on the port of .env), with the VCL of docker/varnish: it keeps the public
|
|
124
|
+
# answers, files them under the tags of their xkey header and lets the API purge them. Read the API through it at VARNISH_PORT.
|
|
125
|
+
varnish:
|
|
126
|
+
image: varnish:9.1.0
|
|
127
|
+
ulimits:
|
|
128
|
+
memlock: -1
|
|
129
|
+
tmpfs:
|
|
130
|
+
- /var/lib/varnish/varnishd:exec
|
|
131
|
+
extra_hosts:
|
|
132
|
+
- "host.docker.internal:host-gateway"
|
|
133
|
+
ports:
|
|
134
|
+
- "127.0.0.1:${VARNISH_PORT:-6081}:80"
|
|
135
|
+
environment:
|
|
136
|
+
# The purges of the API reach it through the published port, from another address: they send this key.
|
|
137
|
+
VARNISH_PURGE_KEY: ${VARNISH_PURGE_KEY:-}
|
|
138
|
+
volumes:
|
|
139
|
+
- ./docker/varnish/default.vcl:/etc/varnish/default.vcl:ro
|
|
140
|
+
|
|
121
141
|
{{/if}}
|
|
122
142
|
{{#if files.s3}}
|
|
123
143
|
# MinIO, an S3 server for local use (pgsty/minio builds it from the upstream sources, which no longer publish images).
|
|
@@ -90,6 +90,16 @@ AUTH_JWKS_URI=https://id.example.com/realms/app/protocol/openid-connect/certs
|
|
|
90
90
|
REDIS_PORT=6379
|
|
91
91
|
REDIS_URL=redis://localhost:6379
|
|
92
92
|
{{/if}}
|
|
93
|
+
{{#if httpCache.varnish}}
|
|
94
|
+
|
|
95
|
+
# Varnish in front of the API (docker-compose.yml): the port to read the API through, and where the outbox relay sends the purges.
|
|
96
|
+
# Its VCL (docker/varnish/default.vcl) reaches the API on host.docker.internal:3000: change both when PORT changes.
|
|
97
|
+
VARNISH_PORT=6081
|
|
98
|
+
VARNISH_URL=http://localhost:6081
|
|
99
|
+
# The key a purge sends: Varnish lets in a purge from another address than its own machine only with it.
|
|
100
|
+
# This one is for local development ONLY: production sets a secret of its own, on Varnish and on the API.
|
|
101
|
+
VARNISH_PURGE_KEY=local-purge-key
|
|
102
|
+
{{/if}}
|
|
93
103
|
{{#if cache.rateLimit}}
|
|
94
104
|
# Requests one caller address may send per window before the HTTP layer answers 429.
|
|
95
105
|
# RATE_LIMIT_MAX=120
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
vcl 4.1;
|
|
2
|
+
|
|
3
|
+
# Varnish in front of the API, for local development and CI. Written by `ddd-ts-kit init --http-cache varnish`.
|
|
4
|
+
# It keeps only what an answer allows by name (the Cache-Control of a route policy, with max-age or s-maxage), files
|
|
5
|
+
# it under its tags (the `xkey` header the API sends), and purges them when the API asks (VarnishCachePurger of
|
|
6
|
+
# @ddd-ts-kit/http/purgers). A request with Authorization or Cookie is passed to the API, never answered from the
|
|
7
|
+
# cache: the built-in rules. A purge is a PURGE request naming its tags in xkey-purge (or xkey-softpurge), or one
|
|
8
|
+
# tag in x-ban-tag for a ban.
|
|
9
|
+
|
|
10
|
+
import std;
|
|
11
|
+
import xkey;
|
|
12
|
+
|
|
13
|
+
backend api {
|
|
14
|
+
.host = "host.docker.internal";
|
|
15
|
+
.port = "3000";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
# Who may purge without the key: this machine only. Any other address sends the key Varnish was started with
|
|
19
|
+
# (VARNISH_PURGE_KEY of its environment) in x-purge-key; without one, it may not purge. In production, set a key of
|
|
20
|
+
# its own and keep the PURGE method away from the public side of the load balancer.
|
|
21
|
+
acl purgers {
|
|
22
|
+
"localhost";
|
|
23
|
+
"127.0.0.1";
|
|
24
|
+
"::1";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
sub vcl_recv {
|
|
28
|
+
if (req.method == "PURGE") {
|
|
29
|
+
if (client.ip !~ purgers && !(std.getenv("VARNISH_PURGE_KEY") != "" && req.http.x-purge-key == std.getenv("VARNISH_PURGE_KEY"))) {
|
|
30
|
+
return (synth(403, "Forbidden"));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (req.http.xkey-purge) {
|
|
34
|
+
set req.http.x-purged = xkey.purge(req.http.xkey-purge);
|
|
35
|
+
} elsif (req.http.xkey-softpurge) {
|
|
36
|
+
set req.http.x-purged = xkey.softpurge(req.http.xkey-softpurge);
|
|
37
|
+
} elsif (req.http.x-ban-tag) {
|
|
38
|
+
# A ban instead of a purge, applied lazily to the objects whose xkey header names the tag. The purger
|
|
39
|
+
# escapes the tag for the expression; a ban Varnish refuses is answered as a failure, and retried.
|
|
40
|
+
if (!std.ban("obj.http.xkey ~ (^|\s)" + req.http.x-ban-tag + "(\s|$)")) {
|
|
41
|
+
return (synth(500, "Ban refused: " + std.ban_error()));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
set req.http.x-purged = "a ban";
|
|
45
|
+
} else {
|
|
46
|
+
return (synth(400, "Name the tags in xkey-purge or xkey-softpurge, or one in x-ban-tag"));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (synth(200, "Purged " + req.http.x-purged));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
sub vcl_backend_response {
|
|
54
|
+
# An answer whose route declared no policy says nothing of its freshness: it is never kept, whatever the
|
|
55
|
+
# default TTL of Varnish would make of it (a public route without a policy, a problem, a probe). Varnish
|
|
56
|
+
# remembers for two minutes not to wait on it (hit-for-miss), and keeps the next answer that allows it.
|
|
57
|
+
if (beresp.http.cache-control !~ "(^|,)\s*(s-maxage|max-age)=") {
|
|
58
|
+
set beresp.uncacheable = true;
|
|
59
|
+
set beresp.ttl = 120s;
|
|
60
|
+
|
|
61
|
+
return (deliver);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
sub vcl_deliver {
|
|
66
|
+
# The tags are for this cache only; x-cache says whether the answer came from it.
|
|
67
|
+
unset resp.http.xkey;
|
|
68
|
+
|
|
69
|
+
if (obj.hits > 0) {
|
|
70
|
+
set resp.http.x-cache = "HIT";
|
|
71
|
+
} else {
|
|
72
|
+
set resp.http.x-cache = "MISS";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{{#if authz.rebac}}
|
|
2
2
|
import type { RelationTuple } from '@ddd-ts-kit/auth/rebac';
|
|
3
3
|
{{/if}}
|
|
4
|
+
{{#if httpCache.varnish}}
|
|
5
|
+
import { InMemoryCachePurger, PurgingPublisher, type IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#unless httpCache.varnish}}
|
|
4
8
|
import type { IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
|
|
9
|
+
{{/unless}}
|
|
5
10
|
import { createHttpClient, type HttpClient } from '@ddd-ts-kit/testing/e2e';
|
|
6
11
|
{{#if authz.rebac}}
|
|
7
12
|
import { relationTuples } from '{{alias.platform}}/auth/relation-tuples{{alias.ext}}';
|
|
@@ -45,6 +50,10 @@ export interface RunningApplication {
|
|
|
45
50
|
readonly client: HttpClient;
|
|
46
51
|
/** Subscribe here (`collectEvents`) to assert the integration events the application publishes. */
|
|
47
52
|
readonly events: IntegrationEventSubscriber;
|
|
53
|
+
{{#if httpCache.varnish}}
|
|
54
|
+
/** What the relay purged from the shared cache once each command committed: `purges.purged` lists the tags. */
|
|
55
|
+
readonly purges: InMemoryCachePurger;
|
|
56
|
+
{{/if}}
|
|
48
57
|
|
|
49
58
|
/** A client presenting the credential of `actor`; `client` itself presents none. */
|
|
50
59
|
as(actor: TestActor): Promise<HttpClient>;
|
|
@@ -75,6 +84,9 @@ export async function startApplication(): Promise<RunningApplication> {
|
|
|
75
84
|
return {
|
|
76
85
|
client: started.client,
|
|
77
86
|
events: started.events,
|
|
87
|
+
{{#if httpCache.varnish}}
|
|
88
|
+
purges: started.purges,
|
|
89
|
+
{{/if}}
|
|
78
90
|
as: async (actor) => started.client.withHeaders(await credentials.headersOf(actor)),
|
|
79
91
|
{{#if authz.rebac}}
|
|
80
92
|
relate: (tuple) => relationTuples.write([tuple]),
|
|
@@ -87,6 +99,9 @@ export async function startApplication(): Promise<RunningApplication> {
|
|
|
87
99
|
interface Started {
|
|
88
100
|
readonly client: HttpClient;
|
|
89
101
|
readonly events: IntegrationEventSubscriber;
|
|
102
|
+
{{#if httpCache.varnish}}
|
|
103
|
+
readonly purges: InMemoryCachePurger;
|
|
104
|
+
{{/if}}
|
|
90
105
|
|
|
91
106
|
close(): Promise<void>;
|
|
92
107
|
}
|
|
@@ -107,10 +122,20 @@ async function start(database: TestDatabase, config: AppConfig, credentials: Cre
|
|
|
107
122
|
|
|
108
123
|
await application.start();
|
|
109
124
|
|
|
125
|
+
{{#if httpCache.varnish}}
|
|
126
|
+
const purges = new InMemoryCachePurger();
|
|
127
|
+
|
|
128
|
+
{{/if}}
|
|
110
129
|
{{#if events.outbox}}
|
|
111
130
|
const relay = startOutboxRelay({
|
|
112
131
|
store: database.persistence.outbox,
|
|
132
|
+
{{#if httpCache.varnish}}
|
|
133
|
+
// The purge requests of the commands are recorded instead of sent to Varnish, every other event goes to the bus.
|
|
134
|
+
publisher: new PurgingPublisher(purges, application.eventBus),
|
|
135
|
+
{{/if}}
|
|
136
|
+
{{#unless httpCache.varnish}}
|
|
113
137
|
publisher: application.eventBus,
|
|
138
|
+
{{/unless}}
|
|
114
139
|
intervalMs: 20,
|
|
115
140
|
logger: application.logger,
|
|
116
141
|
});
|
|
@@ -121,6 +146,9 @@ async function start(database: TestDatabase, config: AppConfig, credentials: Cre
|
|
|
121
146
|
return {
|
|
122
147
|
client: createHttpClient('http://127.0.0.1:' + server.port),
|
|
123
148
|
events: application.eventSubscriber,
|
|
149
|
+
{{#if httpCache.varnish}}
|
|
150
|
+
purges,
|
|
151
|
+
{{/if}}
|
|
124
152
|
close: async () => {
|
|
125
153
|
await server.close();
|
|
126
154
|
{{#if events.outbox}}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{{#if authz.rebac}}
|
|
2
2
|
import type { RelationTuple } from '@ddd-ts-kit/auth/rebac';
|
|
3
3
|
{{/if}}
|
|
4
|
+
{{#if httpCache.varnish}}
|
|
5
|
+
import { InMemoryCachePurger, PurgingPublisher, type IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#unless httpCache.varnish}}
|
|
4
8
|
import type { IntegrationEventSubscriber } from '@ddd-ts-kit/kernel';
|
|
9
|
+
{{/unless}}
|
|
5
10
|
import { createHttpClient, type HttpClient } from '@ddd-ts-kit/testing/e2e';
|
|
6
11
|
{{#if authz.rebac}}
|
|
7
12
|
import { relationTuples } from '{{alias.platform}}/auth/relation-tuples{{alias.ext}}';
|
|
@@ -48,6 +53,10 @@ export interface RunningApplication {
|
|
|
48
53
|
readonly client: HttpClient;
|
|
49
54
|
/** Subscribe here (`collectEvents`) to assert the integration events the application publishes. */
|
|
50
55
|
readonly events: IntegrationEventSubscriber;
|
|
56
|
+
{{#if httpCache.varnish}}
|
|
57
|
+
/** What the relay purged from the shared cache once each command committed: `purges.purged` lists the tags. */
|
|
58
|
+
readonly purges: InMemoryCachePurger;
|
|
59
|
+
{{/if}}
|
|
51
60
|
|
|
52
61
|
/** A client presenting the credential of `actor`; `client` itself presents none. */
|
|
53
62
|
as(actor: TestActor): Promise<HttpClient>;
|
|
@@ -75,6 +84,11 @@ export async function startApplication(): Promise<RunningApplication> {
|
|
|
75
84
|
get events() {
|
|
76
85
|
return current.events;
|
|
77
86
|
},
|
|
87
|
+
{{#if httpCache.varnish}}
|
|
88
|
+
get purges() {
|
|
89
|
+
return current.purges;
|
|
90
|
+
},
|
|
91
|
+
{{/if}}
|
|
78
92
|
as: async (actor) => current.client.withHeaders(await credentials.headersOf(actor)),
|
|
79
93
|
{{#if authz.rebac}}
|
|
80
94
|
relate: (tuple) => relationTuples.write([tuple]),
|
|
@@ -90,6 +104,9 @@ export async function startApplication(): Promise<RunningApplication> {
|
|
|
90
104
|
interface Started {
|
|
91
105
|
readonly client: HttpClient;
|
|
92
106
|
readonly events: IntegrationEventSubscriber;
|
|
107
|
+
{{#if httpCache.varnish}}
|
|
108
|
+
readonly purges: InMemoryCachePurger;
|
|
109
|
+
{{/if}}
|
|
93
110
|
|
|
94
111
|
close(): Promise<void>;
|
|
95
112
|
}
|
|
@@ -111,10 +128,20 @@ async function start(credentials: Credentials): Promise<Started> {
|
|
|
111
128
|
|
|
112
129
|
await application.start();
|
|
113
130
|
|
|
131
|
+
{{#if httpCache.varnish}}
|
|
132
|
+
const purges = new InMemoryCachePurger();
|
|
133
|
+
|
|
134
|
+
{{/if}}
|
|
114
135
|
{{#if events.outbox}}
|
|
115
136
|
const relay = startOutboxRelay({
|
|
116
137
|
store: persistence.outbox,
|
|
138
|
+
{{#if httpCache.varnish}}
|
|
139
|
+
// The purge requests of the commands are recorded instead of sent to Varnish, every other event goes to the bus.
|
|
140
|
+
publisher: new PurgingPublisher(purges, application.eventBus),
|
|
141
|
+
{{/if}}
|
|
142
|
+
{{#unless httpCache.varnish}}
|
|
117
143
|
publisher: application.eventBus,
|
|
144
|
+
{{/unless}}
|
|
118
145
|
intervalMs: 20,
|
|
119
146
|
logger: application.logger,
|
|
120
147
|
});
|
|
@@ -125,6 +152,9 @@ async function start(credentials: Credentials): Promise<Started> {
|
|
|
125
152
|
return {
|
|
126
153
|
client: createHttpClient('http://127.0.0.1:' + server.port),
|
|
127
154
|
events: application.eventSubscriber,
|
|
155
|
+
{{#if httpCache.varnish}}
|
|
156
|
+
purges,
|
|
157
|
+
{{/if}}
|
|
128
158
|
close: async () => {
|
|
129
159
|
await server.close();
|
|
130
160
|
{{#if events.outbox}}
|
|
@@ -25,6 +25,11 @@ export function testEnvironment(overrides: Variables = {}): Variables {
|
|
|
25
25
|
{{#if redis.server}}
|
|
26
26
|
REDIS_URL: (process.env['REDIS_URL'] ?? '') || noRedis,
|
|
27
27
|
{{/if}}
|
|
28
|
+
{{#if httpCache.varnish}}
|
|
29
|
+
// The relay of the tests hands the purges to a recording purger, never to Varnish: the address only has to be one.
|
|
30
|
+
VARNISH_URL: (process.env['VARNISH_URL'] ?? '') || 'http://varnish.e2e.test',
|
|
31
|
+
VARNISH_PURGE_KEY: (process.env['VARNISH_PURGE_KEY'] ?? '') || 'e2e-purge-key',
|
|
32
|
+
{{/if}}
|
|
28
33
|
{{#if cache.rateLimit}}
|
|
29
34
|
RATE_LIMIT_MAX: process.env['RATE_LIMIT_MAX'] ?? '1000000',
|
|
30
35
|
{{/if}}
|
|
@@ -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}}
|
|
@@ -61,7 +65,16 @@ await application.start();
|
|
|
61
65
|
{{#if events.outbox}}
|
|
62
66
|
const relay = startOutboxRelay({
|
|
63
67
|
store: persistence.outbox,
|
|
68
|
+
{{#if httpCache.varnish}}
|
|
69
|
+
// The purge requests the use cases wrote with their commands go to Varnish, every other event to the provider.
|
|
70
|
+
publisher: new PurgingPublisher(
|
|
71
|
+
new VarnishCachePurger({ url: config.varnishUrl, key: config.varnishPurgeKey }),
|
|
72
|
+
application.eventBus,
|
|
73
|
+
),
|
|
74
|
+
{{/if}}
|
|
75
|
+
{{#unless httpCache.varnish}}
|
|
64
76
|
publisher: application.eventBus,
|
|
77
|
+
{{/unless}}
|
|
65
78
|
intervalMs: config.outboxRelayIntervalMs,
|
|
66
79
|
logger: application.logger,
|
|
67
80
|
{{#if errors.sentry}}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { Authenticator } from '@ddd-ts-kit/auth';
|
|
2
|
+
{{#if httpCache.varnish}}
|
|
3
|
+
{{#unless httpCache.perTenant}}
|
|
4
|
+
import { CacheTagHeader } from '@ddd-ts-kit/http';
|
|
5
|
+
{{/unless}}
|
|
6
|
+
{{#if httpCache.perTenant}}
|
|
7
|
+
import { CacheTagHeader, tenantFromHeader, type TenantResolver } from '@ddd-ts-kit/http';
|
|
8
|
+
{{/if}}
|
|
9
|
+
{{/if}}
|
|
2
10
|
{{#if errors.none}}
|
|
3
11
|
import type { ErrorContext, ErrorMapper, {{#if audit.on}}GuardRefusal, {{/if}}RouteAround{{#if files.http}}, UploadReader{{/if}} } from '@ddd-ts-kit/http';
|
|
4
12
|
import type { Clock, ExecutionScope, Logger, Session } from '@ddd-ts-kit/kernel';
|
|
@@ -49,6 +57,17 @@ export interface HttpBoundary {
|
|
|
49
57
|
readonly onError: (error: unknown, context: ErrorContext) => void;
|
|
50
58
|
/** The span of a request, named by its route template; probes and documentation routes make none. */
|
|
51
59
|
readonly around: RouteAround;
|
|
60
|
+
{{#if httpCache.varnish}}
|
|
61
|
+
/** The header Varnish files a public answer under the tags of its resources from. */
|
|
62
|
+
readonly cacheTags: { readonly header: CacheTagHeader; readonly perTenant?: boolean };
|
|
63
|
+
{{/if}}
|
|
64
|
+
{{#if httpCache.perTenant}}
|
|
65
|
+
/**
|
|
66
|
+
* The tenant of a request that names one in `x-tenant-id`, an anonymous one on a public route included: its
|
|
67
|
+
* answers are then filed under that tenant, and vary on the header. Without it, the tenant of the caller.
|
|
68
|
+
*/
|
|
69
|
+
readonly resolveTenant: TenantResolver;
|
|
70
|
+
{{/if}}
|
|
52
71
|
{{#if files.http}}
|
|
53
72
|
/** Reads the file of a controller that declares an upload, as it streams: its size and media types are checked on the way. */
|
|
54
73
|
readonly uploads: UploadReader;
|
|
@@ -112,6 +131,16 @@ export function httpBoundary({
|
|
|
112
131
|
errorMapper,
|
|
113
132
|
clock,
|
|
114
133
|
around: tracedRoutes(),
|
|
134
|
+
{{#if httpCache.varnish}}
|
|
135
|
+
{{#if httpCache.perTenant}}
|
|
136
|
+
// Filed under the tenant of the request, as the purges of the outbox are.
|
|
137
|
+
cacheTags: { header: CacheTagHeader.xkey, perTenant: true },
|
|
138
|
+
resolveTenant: tenantFromHeader(),
|
|
139
|
+
{{/if}}
|
|
140
|
+
{{#unless httpCache.perTenant}}
|
|
141
|
+
cacheTags: { header: CacheTagHeader.xkey },
|
|
142
|
+
{{/unless}}
|
|
143
|
+
{{/if}}
|
|
115
144
|
{{#if files.http}}
|
|
116
145
|
uploads: multipartUploads(),
|
|
117
146
|
{{/if}}
|
|
@@ -54,6 +54,9 @@ import {
|
|
|
54
54
|
{{/unless}}
|
|
55
55
|
Logger,
|
|
56
56
|
Metrics,
|
|
57
|
+
{{#if httpCache.perTenant}}
|
|
58
|
+
PublishedCacheInvalidation,
|
|
59
|
+
{{/if}}
|
|
57
60
|
{{#if http.any}}
|
|
58
61
|
QueryBus,
|
|
59
62
|
{{/if}}
|
|
@@ -242,6 +245,16 @@ function kernel(foundations: Foundations, persistence: Persistence, options: App
|
|
|
242
245
|
eventPublisher: scopedPublisher(bus, scope),
|
|
243
246
|
{{/unless}}
|
|
244
247
|
eventSubscriber: bus,
|
|
248
|
+
{{#if httpCache.perTenant}}
|
|
249
|
+
// The purges of the outbox filed under the tenant of the work, as the answers are tagged (`cacheTags.perTenant`).
|
|
250
|
+
cacheInvalidation: new PublishedCacheInvalidation({
|
|
251
|
+
publisher: scopedPublisher(new OutboxPublisher(persistence.outbox), scope),
|
|
252
|
+
ids,
|
|
253
|
+
clock,
|
|
254
|
+
scope,
|
|
255
|
+
perTenant: true,
|
|
256
|
+
}),
|
|
257
|
+
{{/if}}
|
|
245
258
|
{{#if errors.sentry}}
|
|
246
259
|
// The buses and the jobs report through it, and `container.stop()` flushes it; left out (the tools, the tests), nothing is reported.
|
|
247
260
|
...(options.errors === undefined ? {} : { errorReporter: options.errors }),
|
|
@@ -44,6 +44,12 @@ export interface AppConfig {
|
|
|
44
44
|
{{#if redis.server}}
|
|
45
45
|
readonly redisUrl: string;
|
|
46
46
|
{{/if}}
|
|
47
|
+
{{#if httpCache.varnish}}
|
|
48
|
+
/** Varnish as the API reaches it (`VARNISH_URL`): where the relay of the outbox sends the purges of the tags. */
|
|
49
|
+
readonly varnishUrl: string;
|
|
50
|
+
/** The key Varnish lets a purge from another machine in with (`VARNISH_PURGE_KEY`): a secret in production. */
|
|
51
|
+
readonly varnishPurgeKey: string;
|
|
52
|
+
{{/if}}
|
|
47
53
|
{{#if cache.rateLimit}}
|
|
48
54
|
/** How many requests one caller address may send in a sliding window, before the HTTP layer answers 429. */
|
|
49
55
|
readonly rateLimit: RateLimit;
|
|
@@ -62,6 +62,9 @@ export function loadConfig(env: Variables): AppConfig {
|
|
|
62
62
|
{{#if redis.server}}
|
|
63
63
|
redisUrl: readUrl(env, 'REDIS_URL', problems),
|
|
64
64
|
{{/if}}
|
|
65
|
+
{{#if httpCache.varnish}}
|
|
66
|
+
...readVarnish(env, problems),
|
|
67
|
+
{{/if}}
|
|
65
68
|
{{#if cache.rateLimit}}
|
|
66
69
|
rateLimit: readRateLimit(env, problems),
|
|
67
70
|
{{/if}}
|
|
@@ -143,6 +146,15 @@ function readResilience(env: Variables, problems: string[]): AppConfig['resilien
|
|
|
143
146
|
timeoutMs: readInteger(env, { name: 'OUTBOUND_TIMEOUT_MS', fallback: 2000, min: 1, max: 600000 }, problems),
|
|
144
147
|
};
|
|
145
148
|
}
|
|
149
|
+
{{#if httpCache.varnish}}
|
|
150
|
+
|
|
151
|
+
function readVarnish(env: Variables, problems: string[]): Pick<AppConfig, 'varnishUrl' | 'varnishPurgeKey'> {
|
|
152
|
+
return {
|
|
153
|
+
varnishUrl: readUrl(env, 'VARNISH_URL', problems),
|
|
154
|
+
varnishPurgeKey: readText(env, 'VARNISH_PURGE_KEY', problems),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
{{/if}}
|
|
146
158
|
{{#if cache.rateLimit}}
|
|
147
159
|
|
|
148
160
|
function readRateLimit(env: Variables, problems: string[]): AppConfig['rateLimit'] {
|
|
@@ -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;
|
|
@@ -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}}
|