ddd-ts-kit 0.8.0 → 0.9.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.
Files changed (137) hide show
  1. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  2. package/dist/check/catalogue/architecture-rules.js +4 -0
  3. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  4. package/dist/check/errors/kit-error-codes.d.ts.map +1 -1
  5. package/dist/check/errors/kit-error-codes.js +5 -0
  6. package/dist/check/errors/kit-error-codes.js.map +1 -1
  7. package/dist/check/explain/errors-docs.js +1 -1
  8. package/dist/check/explain/errors-docs.js.map +1 -1
  9. package/dist/check/explain/persistence-docs.d.ts.map +1 -1
  10. package/dist/check/explain/persistence-docs.js +26 -0
  11. package/dist/check/explain/persistence-docs.js.map +1 -1
  12. package/dist/check/files/file-content-findings.d.ts +4 -0
  13. package/dist/check/files/file-content-findings.d.ts.map +1 -0
  14. package/dist/check/files/file-content-findings.js +29 -0
  15. package/dist/check/files/file-content-findings.js.map +1 -0
  16. package/dist/check/files/file-content-pattern.d.ts +7 -0
  17. package/dist/check/files/file-content-pattern.d.ts.map +1 -0
  18. package/dist/check/files/file-content-pattern.js +17 -0
  19. package/dist/check/files/file-content-pattern.js.map +1 -0
  20. package/dist/check/files/schema-sources.d.ts +13 -0
  21. package/dist/check/files/schema-sources.d.ts.map +1 -0
  22. package/dist/check/files/schema-sources.js +37 -0
  23. package/dist/check/files/schema-sources.js.map +1 -0
  24. package/dist/check/fixtures/files-fixtures.d.ts +3 -0
  25. package/dist/check/fixtures/files-fixtures.d.ts.map +1 -0
  26. package/dist/check/fixtures/files-fixtures.js +92 -0
  27. package/dist/check/fixtures/files-fixtures.js.map +1 -0
  28. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  29. package/dist/check/fixtures/fixtures.js +2 -0
  30. package/dist/check/fixtures/fixtures.js.map +1 -1
  31. package/dist/check/layers/outside-concern.d.ts.map +1 -1
  32. package/dist/check/layers/outside-concern.js +4 -0
  33. package/dist/check/layers/outside-concern.js.map +1 -1
  34. package/dist/check/rules/files-port-not-connector.d.ts +3 -0
  35. package/dist/check/rules/files-port-not-connector.d.ts.map +1 -0
  36. package/dist/check/rules/files-port-not-connector.js +28 -0
  37. package/dist/check/rules/files-port-not-connector.js.map +1 -0
  38. package/dist/check/rules/persistence-no-file-content.d.ts +3 -0
  39. package/dist/check/rules/persistence-no-file-content.d.ts.map +1 -0
  40. package/dist/check/rules/persistence-no-file-content.js +14 -0
  41. package/dist/check/rules/persistence-no-file-content.js.map +1 -0
  42. package/dist/commands/init.d.ts.map +1 -1
  43. package/dist/commands/init.js +1 -0
  44. package/dist/commands/init.js.map +1 -1
  45. package/dist/config/index.d.ts +1 -1
  46. package/dist/config/index.d.ts.map +1 -1
  47. package/dist/config/index.js +1 -1
  48. package/dist/config/index.js.map +1 -1
  49. package/dist/config/parse-stack.d.ts.map +1 -1
  50. package/dist/config/parse-stack.js +2 -1
  51. package/dist/config/parse-stack.js.map +1 -1
  52. package/dist/config/stack.d.ts +8 -0
  53. package/dist/config/stack.d.ts.map +1 -1
  54. package/dist/config/stack.js +1 -0
  55. package/dist/config/stack.js.map +1 -1
  56. package/dist/generate/kinds/file-upload/write-upload-controller.d.ts +5 -0
  57. package/dist/generate/kinds/file-upload/write-upload-controller.d.ts.map +1 -0
  58. package/dist/generate/kinds/file-upload/write-upload-controller.js +42 -0
  59. package/dist/generate/kinds/file-upload/write-upload-controller.js.map +1 -0
  60. package/dist/generate/kinds/file-upload-kind.d.ts +3 -0
  61. package/dist/generate/kinds/file-upload-kind.d.ts.map +1 -0
  62. package/dist/generate/kinds/file-upload-kind.js +55 -0
  63. package/dist/generate/kinds/file-upload-kind.js.map +1 -0
  64. package/dist/generate/kinds.d.ts.map +1 -1
  65. package/dist/generate/kinds.js +2 -0
  66. package/dist/generate/kinds.js.map +1 -1
  67. package/dist/help/usage.d.ts +1 -1
  68. package/dist/help/usage.d.ts.map +1 -1
  69. package/dist/help/usage.js +2 -1
  70. package/dist/help/usage.js.map +1 -1
  71. package/dist/init/files/platform-files.d.ts.map +1 -1
  72. package/dist/init/files/platform-files.js +22 -0
  73. package/dist/init/files/platform-files.js.map +1 -1
  74. package/dist/init/manifest/dependencies-for.d.ts.map +1 -1
  75. package/dist/init/manifest/dependencies-for.js +7 -1
  76. package/dist/init/manifest/dependencies-for.js.map +1 -1
  77. package/dist/init/manifest/versions.d.ts.map +1 -1
  78. package/dist/init/manifest/versions.js +28 -23
  79. package/dist/init/manifest/versions.js.map +1 -1
  80. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  81. package/dist/init/stack/resolve-stack.js +11 -2
  82. package/dist/init/stack/resolve-stack.js.map +1 -1
  83. package/dist/init/stack/stack-options.d.ts +1 -0
  84. package/dist/init/stack/stack-options.d.ts.map +1 -1
  85. package/dist/init/template-vars.d.ts.map +1 -1
  86. package/dist/init/template-vars.js +3 -2
  87. package/dist/init/template-vars.js.map +1 -1
  88. package/dist/stack/files-vars.d.ts +5 -0
  89. package/dist/stack/files-vars.d.ts.map +1 -0
  90. package/dist/stack/files-vars.js +11 -0
  91. package/dist/stack/files-vars.js.map +1 -0
  92. package/dist/stack/stack-vars.d.ts.map +1 -1
  93. package/dist/stack/stack-vars.js +13 -4
  94. package/dist/stack/stack-vars.js.map +1 -1
  95. package/dist/version.d.ts +1 -1
  96. package/dist/version.js +1 -1
  97. package/package.json +3 -3
  98. package/templates/file-upload/command.ts.tpl +41 -0
  99. package/templates/file-upload/controller.spec.ts.tpl +46 -0
  100. package/templates/file-upload/controller.ts.tpl +23 -0
  101. package/templates/file-upload/handler.declared.ts.tpl +18 -0
  102. package/templates/file-upload/handler.spec.ts.tpl +79 -0
  103. package/templates/file-upload/handler.ts.tpl +16 -0
  104. package/templates/file-upload/wiring.manual.tpl +9 -0
  105. package/templates/file-upload/wiring.tsyringe.tpl +7 -0
  106. package/templates/init/README.md.tpl +22 -0
  107. package/templates/init/docker/docker-compose.yml.tpl +25 -0
  108. package/templates/init/docker/env.example.tpl +21 -0
  109. package/templates/init/gitignore.tpl +3 -0
  110. package/templates/init/main.ts.tpl +6 -0
  111. package/templates/init/platform/auth/http-boundary.ts.tpl +25 -1
  112. package/templates/init/platform/buses/create-command-bus.ts.tpl +7 -1
  113. package/templates/init/platform/compose-application.manual.ts.tpl +25 -0
  114. package/templates/init/platform/compose-application.tsyringe.ts.tpl +31 -0
  115. package/templates/init/platform/config/app-config.ts.tpl +7 -0
  116. package/templates/init/platform/config/load-config.ts.tpl +9 -0
  117. package/templates/init/platform/config/read-files.local.ts.tpl +39 -0
  118. package/templates/init/platform/config/read-files.s3.ts.tpl +42 -0
  119. package/templates/init/platform/create-platform.manual.ts.tpl +38 -1
  120. package/templates/init/platform/files/bind-files.tsyringe.ts.tpl +32 -0
  121. package/templates/init/platform/files/create-files.ts.tpl +34 -0
  122. package/templates/init/platform/files/file-routes.ts.tpl +10 -0
  123. package/templates/init/platform/files/files.module.tsyringe.ts.tpl +18 -0
  124. package/templates/init/platform/files/open-files.local.ts.tpl +13 -0
  125. package/templates/init/platform/files/open-files.s3.ts.tpl +10 -0
  126. package/templates/init/platform/files/staging-uploads.tsyringe.ts.tpl +11 -0
  127. package/templates/init/platform/http/start-http-server.express.ts.tpl +5 -1
  128. package/templates/init/platform/http/start-http-server.fastify.ts.tpl +4 -1
  129. package/templates/init/platform/http/start-http-server.nest.ts.tpl +12 -1
  130. package/templates/init/platform/platform-test.module.tsyringe.ts.tpl +11 -0
  131. package/templates/init/platform/platform.manual.ts.tpl +7 -0
  132. package/templates/init/rules/application.md.tpl +3 -0
  133. package/templates/init/rules/infrastructure.md.tpl +1 -0
  134. package/templates/init/rules/platform.md.tpl +3 -0
  135. package/templates/pipeline/package-scripts.json +1 -1
  136. package/templates/service/main.ts.tpl +6 -0
  137. package/templates/worker/main.ts.tpl +6 -0
@@ -19,7 +19,7 @@ export interface HttpServer {
19
19
  }
20
20
 
21
21
  /** What the server needs of the application: its routes and what stands at its edge. */
22
- type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}>;
22
+ type Served = Pick<Application, 'routes' | 'boundary'{{#if cache.rateLimit}} | 'rateLimiter' | 'ready'{{/if}}{{#if files.http}} | 'fileRoutes'{{/if}}>;
23
23
  {{#if cache.rateLimit}}
24
24
 
25
25
  /** The part of the incoming request and of its response the limiter and the probe need, whatever Nest runs on. */
@@ -36,6 +36,16 @@ interface Outgoing {
36
36
  {{/if}}
37
37
 
38
38
  export async function startHttpServer(served: Served, config: AppConfig): Promise<HttpServer> {
39
+ {{#if files.http}}
40
+ {{#if docs.any}}
41
+ const routes = [...withDocumentation(served.routes, config), ...served.fileRoutes];
42
+ {{/if}}
43
+ {{#unless docs.any}}
44
+ const routes = [...served.routes, ...served.fileRoutes];
45
+ {{/unless}}
46
+ const app = await NestFactory.create(createAppModule(routes, served.boundary), { logger: ['error', 'warn'] });
47
+ {{/if}}
48
+ {{#unless files.http}}
39
49
  {{#if docs.any}}
40
50
  const app = await NestFactory.create(createAppModule(withDocumentation(served.routes, config), served.boundary), {
41
51
  logger: ['error', 'warn'],
@@ -44,6 +54,7 @@ export async function startHttpServer(served: Served, config: AppConfig): Promis
44
54
  {{#unless docs.any}}
45
55
  const app = await NestFactory.create(createAppModule(served.routes, served.boundary), { logger: ['error', 'warn'] });
46
56
  {{/unless}}
57
+ {{/unless}}
47
58
 
48
59
  {{#if cache.rateLimit}}
49
60
  app.use(
@@ -1,10 +1,16 @@
1
1
  import { defineContextModule } from '@ddd-ts-kit/di';
2
+ {{#if files.any}}
3
+ import { InMemoryFileStorage } from '@ddd-ts-kit/kernel';
4
+ {{/if}}
2
5
  {{#if persistence.packagedToken}}
3
6
  import { {{persistence.token}} } from '{{persistence.tokenPackage}}';
4
7
  {{/if}}
5
8
  {{#if persistence.ownDatabase}}
6
9
  import { Database } from '{{alias.platform}}/database/database{{alias.ext}}';
7
10
  {{/if}}
11
+ {{#if files.any}}
12
+ import { bindFiles } from '{{alias.platform}}/files/bind-files{{alias.ext}}';
13
+ {{/if}}
8
14
  // ddd-ts-kit:imports
9
15
  // /ddd-ts-kit:imports
10
16
 
@@ -17,6 +23,11 @@ export const platformTestModule = defineContextModule({
17
23
  throw new Error('A handler spec has no database: give a fake for the repository it uses.');
18
24
  });
19
25
 
26
+ {{/if}}
27
+ {{#if files.any}}
28
+ // The files a handler spec stores stay in the memory of the test.
29
+ bindFiles(builder, new InMemoryFileStorage());
30
+
20
31
  {{/if}}
21
32
  // ddd-ts-kit:test-bindings
22
33
  // /ddd-ts-kit:test-bindings
@@ -26,6 +26,9 @@ import type { Audit } from '{{alias.platform}}/audit/create-audit{{alias.ext}}';
26
26
  {{/if}}
27
27
  import type { UseCaseProtection } from '{{alias.platform}}/auth/use-case-protection{{alias.ext}}';
28
28
  import type { Persistence } from '{{alias.platform}}/database/persistence{{alias.ext}}';
29
+ {{#if files.any}}
30
+ import type { Files } from '{{alias.platform}}/files/create-files{{alias.ext}}';
31
+ {{/if}}
29
32
 
30
33
  /** Wraps an adapter from outside: a span for its kind and, for what leaves the process, the default policy unless it states its own. */
31
34
  type Adapt = <T extends object>(instance: T, info: AspectInfo) => T;
@@ -78,4 +81,8 @@ export interface Platform {
78
81
  {{#if audit.on}}
79
82
  readonly audit: Audit;
80
83
  {{/if}}
84
+ {{#if files.any}}
85
+ /** Where files live, the keys they are stored under and the staging that keeps them consistent with the database: never their content in a table. */
86
+ readonly files: Files;
87
+ {{/if}}
81
88
  }
@@ -25,6 +25,9 @@ paths:
25
25
  - A dependency list names port classes, imported as values, in the order of the constructor: never an adapter or a fake (`ports/value-import`, `ports/no-concrete-dependency`).
26
26
  {{/if}}
27
27
  - A job (`scheduling/*.job.ts`) and an integration event handler (`integration/handlers/`) only build one command and send it as a system actor; both are safe to repeat (`scheduling/job-triggers-use-case`, `events/consumer-idempotent`).
28
+ {{#if files.any}}
29
+ - A file arrives in the command as a `FileUpload` of its area, which the bus stages before the transaction under a key of `FileKeys` (never a name or a path from the user) and scans; the handler records `upload.file`, its `StoredFile`, on the aggregate and calls `FileStaging.promoteOnCommit`, which moves it to its key with the commit. A direct upload is confirmed from the `PendingUpload` the aggregate kept, never from a key the client sends. The ports are named here, never a connector (`files/port-not-connector`); `npx ddd-ts-kit generate file-upload` writes the slice.
30
+ {{/if}}
28
31
  - A query never saves, deletes or publishes (`application/command-query-separation`); it hands the access scope of the actor to its read port and never filters after loading.
29
32
  - A read that takes criteria, a scope or a page is a search, never a list (`naming/search-not-list`): `Search<Things>Query` in `queries/search-<things>/` (`generate query ... --search`), `search...` on the port, its adapters and its fakes; one element or none stays `findById` or `findBy...`.
30
33
  {{#if literals.named}}
@@ -8,6 +8,7 @@ paths:
8
8
  - An adapter `implements` a port of `application/ports/` or a repository port of `domain/repositories/`, and never `extends` it (`ports/implements-never-extends`). It never imports `presentation/` (`layer/infrastructure-no-presentation`).
9
9
  - `persistence/` holds repository adapters, mappers and rows, `external/` the adapters of outside systems, `anti-corruption/` the translators of another model.
10
10
  - Rows never leave `persistence/`: a mapper translates to and from the aggregate, and is the only place for a type assertion (`clean/no-escape-hatch`).
11
+ - The content of a file never goes in a table: no binary or base64 column (`persistence/no-file-content`). The file lives in the `FileStorage` port; a row keeps the key, size, media type and checksum of its `StoredFile`.
11
12
  - Own tables, in the schema of the context: no join, foreign key or transaction across contexts (`context/extractable`).
12
13
  - Audit columns and the tenant column are stamped from the execution scope with the kernel helpers (`stampCreation`, `stampUpdate`, `tenantScopeOf`), never handed over by a use case.
13
14
  {{#if tenancy.any}}
@@ -20,6 +20,9 @@ paths:
20
20
  - One `Platform` is built in `create-platform.ts` and handed to each context; a port or a value is typed by an abstract class. No token helper, no injection constant; one exported class, interface or function per file.
21
21
  - Cross-cutting behaviour lives here: spans through the members of `traceApplication()` (`create-platform.ts`), `around: tracedRoutes()` at the HTTP boundary and `tracedPublisher` for the outbox relay; logs, measures, permissions and audit as bus middlewares; the policy of outbound adapters in `resilience/`.
22
22
  {{/unless}}
23
+ {{#if files.any}}
24
+ - Files: `files/open-files.ts` opens the connector of `stack.storage` from `config/read-files.ts`{{#if di.tsyringe}}, `files/files.module.ts` binds the ports and the hourly purge of staged files, `files/staging-uploads.ts` stages the file a command carries on the command bus, before the transaction{{/if}}{{#unless di.tsyringe}}, `files/create-files.ts` builds them, `compose-application.ts` registers the hourly purge of staged files and `create-platform.ts` stages the file a command carries on the command bus, before the transaction{{/unless}}; the tools and the tests keep files in memory. A scanner of your own (an antivirus) is bound here, never called from a use case.
25
+ {{/if}}
23
26
  - `@ddd-ts-kit/tracing` and `@opentelemetry/*` are imported here and nowhere else (`tracing/platform-only`).
24
27
  - Logs, spans and error reports carry identifiers and codes only: never arguments, payloads, error messages, nor anything personal beyond the id of the actor.
25
28
  - Configuration is read here only, by `config/load-config.ts`: validated, fail fast, every problem named by its variable. A new variable joins `AppConfig` and `.env.example`. `RUN_JOBS` says whether a process runs the jobs, `job-settings.ts` what configuration changes of each.
@@ -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.8.0",
26
+ "@ddd-ts-kit/eslint-plugin": "^0.9.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",
@@ -14,6 +14,9 @@ import { {{events.providerName}} } from '{{alias.platform}}/events/{{events.prov
14
14
  {{#if events.outbox}}
15
15
  import { startOutboxRelay } from '{{alias.platform}}/events/start-outbox-relay{{alias.ext}}';
16
16
  {{/if}}
17
+ {{#if files.any}}
18
+ import { openFiles } from '{{alias.platform}}/files/open-files{{alias.ext}}';
19
+ {{/if}}
17
20
  {{#if http.any}}
18
21
  import { startHttpServer } from '{{alias.platform}}/http/start-http-server{{alias.ext}}';
19
22
  {{/if}}
@@ -52,6 +55,9 @@ const application = composeApplication(
52
55
  {{#if cache.redis}}
53
56
  redis,
54
57
  {{/if}}
58
+ {{#if files.any}}
59
+ files: openFiles(config.files),
60
+ {{/if}}
55
61
  },
56
62
  {{service.selection}}
57
63
  );
@@ -11,6 +11,9 @@ import { composeApplication } from '{{alias.platform}}/compose-application{{alia
11
11
  import { loadConfig } from '{{alias.platform}}/config/load-config{{alias.ext}}';
12
12
  import { openPersistence } from '{{alias.platform}}/database/open-persistence{{alias.ext}}';
13
13
  import { {{events.providerName}} } from '{{alias.platform}}/events/{{events.providerFile}}{{alias.ext}}';
14
+ {{#if files.any}}
15
+ import { openFiles } from '{{alias.platform}}/files/open-files{{alias.ext}}';
16
+ {{/if}}
14
17
  import { jobSettings } from '{{alias.platform}}/job-settings{{alias.ext}}';
15
18
  {{#if cache.redis}}
16
19
  import { openRedis } from '{{alias.platform}}/redis/open-redis{{alias.ext}}';
@@ -44,6 +47,9 @@ const application = composeApplication(persistence, {
44
47
  {{#if cache.redis}}
45
48
  redis,
46
49
  {{/if}}
50
+ {{#if files.any}}
51
+ files: openFiles(config.files),
52
+ {{/if}}
47
53
  });
48
54
 
49
55
  await application.start();