ddd-ts-kit 0.4.1 → 0.5.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 (214) hide show
  1. package/README.md +19 -9
  2. package/dist/check/catalogue/architecture-rules.d.ts.map +1 -1
  3. package/dist/check/catalogue/architecture-rules.js +2 -0
  4. package/dist/check/catalogue/architecture-rules.js.map +1 -1
  5. package/dist/check/configuration/config-inspection.d.ts +4 -0
  6. package/dist/check/configuration/config-inspection.d.ts.map +1 -1
  7. package/dist/check/configuration/config-inspection.js +10 -1
  8. package/dist/check/configuration/config-inspection.js.map +1 -1
  9. package/dist/check/explain/persistence-docs.d.ts +3 -0
  10. package/dist/check/explain/persistence-docs.d.ts.map +1 -0
  11. package/dist/check/explain/persistence-docs.js +14 -0
  12. package/dist/check/explain/persistence-docs.js.map +1 -0
  13. package/dist/check/explain/rule-docs.d.ts.map +1 -1
  14. package/dist/check/explain/rule-docs.js +2 -0
  15. package/dist/check/explain/rule-docs.js.map +1 -1
  16. package/dist/check/fixtures/fixtures.d.ts.map +1 -1
  17. package/dist/check/fixtures/fixtures.js +2 -0
  18. package/dist/check/fixtures/fixtures.js.map +1 -1
  19. package/dist/check/fixtures/persistence-fixtures.d.ts +3 -0
  20. package/dist/check/fixtures/persistence-fixtures.d.ts.map +1 -0
  21. package/dist/check/fixtures/persistence-fixtures.js +72 -0
  22. package/dist/check/fixtures/persistence-fixtures.js.map +1 -0
  23. package/dist/check/migrations/drizzle-history-findings.d.ts +9 -0
  24. package/dist/check/migrations/drizzle-history-findings.d.ts.map +1 -0
  25. package/dist/check/migrations/drizzle-history-findings.js +70 -0
  26. package/dist/check/migrations/drizzle-history-findings.js.map +1 -0
  27. package/dist/check/migrations/drizzle-migrations.d.ts +23 -0
  28. package/dist/check/migrations/drizzle-migrations.d.ts.map +1 -0
  29. package/dist/check/migrations/drizzle-migrations.js +2 -0
  30. package/dist/check/migrations/drizzle-migrations.js.map +1 -0
  31. package/dist/check/migrations/drizzle-out-folder.d.ts +3 -0
  32. package/dist/check/migrations/drizzle-out-folder.d.ts.map +1 -0
  33. package/dist/check/migrations/drizzle-out-folder.js +18 -0
  34. package/dist/check/migrations/drizzle-out-folder.js.map +1 -0
  35. package/dist/check/migrations/migration-folder.d.ts +13 -0
  36. package/dist/check/migrations/migration-folder.d.ts.map +1 -0
  37. package/dist/check/migrations/migration-folder.js +2 -0
  38. package/dist/check/migrations/migration-folder.js.map +1 -0
  39. package/dist/check/migrations/migration-name-findings.d.ts +9 -0
  40. package/dist/check/migrations/migration-name-findings.d.ts.map +1 -0
  41. package/dist/check/migrations/migration-name-findings.js +32 -0
  42. package/dist/check/migrations/migration-name-findings.js.map +1 -0
  43. package/dist/check/migrations/read-drizzle-migrations.d.ts +4 -0
  44. package/dist/check/migrations/read-drizzle-migrations.d.ts.map +1 -0
  45. package/dist/check/migrations/read-drizzle-migrations.js +67 -0
  46. package/dist/check/migrations/read-drizzle-migrations.js.map +1 -0
  47. package/dist/check/migrations/read-migration-folder.d.ts +5 -0
  48. package/dist/check/migrations/read-migration-folder.d.ts.map +1 -0
  49. package/dist/check/migrations/read-migration-folder.js +38 -0
  50. package/dist/check/migrations/read-migration-folder.js.map +1 -0
  51. package/dist/check/rules/config-valid.d.ts.map +1 -1
  52. package/dist/check/rules/config-valid.js +3 -1
  53. package/dist/check/rules/config-valid.js.map +1 -1
  54. package/dist/check/rules/persistence-migration-history.d.ts +3 -0
  55. package/dist/check/rules/persistence-migration-history.d.ts.map +1 -0
  56. package/dist/check/rules/persistence-migration-history.js +24 -0
  57. package/dist/check/rules/persistence-migration-history.js.map +1 -0
  58. package/dist/commands/init.d.ts.map +1 -1
  59. package/dist/commands/init.js +10 -1
  60. package/dist/commands/init.js.map +1 -1
  61. package/dist/commit/is-derived.d.ts.map +1 -1
  62. package/dist/commit/is-derived.js +5 -7
  63. package/dist/commit/is-derived.js.map +1 -1
  64. package/dist/config/ci-extra-problems.d.ts +4 -0
  65. package/dist/config/ci-extra-problems.d.ts.map +1 -0
  66. package/dist/config/ci-extra-problems.js +27 -0
  67. package/dist/config/ci-extra-problems.js.map +1 -0
  68. package/dist/config/ci-extras.d.ts +13 -0
  69. package/dist/config/ci-extras.d.ts.map +1 -0
  70. package/dist/config/ci-extras.js +13 -0
  71. package/dist/config/ci-extras.js.map +1 -0
  72. package/dist/config/config.d.ts +23 -0
  73. package/dist/config/config.d.ts.map +1 -1
  74. package/dist/config/index.d.ts +4 -1
  75. package/dist/config/index.d.ts.map +1 -1
  76. package/dist/config/index.js +3 -0
  77. package/dist/config/index.js.map +1 -1
  78. package/dist/config/open-api-problems.d.ts +4 -0
  79. package/dist/config/open-api-problems.d.ts.map +1 -0
  80. package/dist/config/open-api-problems.js +87 -0
  81. package/dist/config/open-api-problems.js.map +1 -0
  82. package/dist/config/openapi-formats.d.ts +3 -0
  83. package/dist/config/openapi-formats.d.ts.map +1 -0
  84. package/dist/config/openapi-formats.js +3 -0
  85. package/dist/config/openapi-formats.js.map +1 -0
  86. package/dist/config/parse-ci.d.ts +4 -0
  87. package/dist/config/parse-ci.d.ts.map +1 -0
  88. package/dist/config/parse-ci.js +7 -0
  89. package/dist/config/parse-ci.js.map +1 -0
  90. package/dist/config/parse-config.d.ts.map +1 -1
  91. package/dist/config/parse-config.js +4 -0
  92. package/dist/config/parse-config.js.map +1 -1
  93. package/dist/config/parse-open-api.d.ts +4 -0
  94. package/dist/config/parse-open-api.d.ts.map +1 -0
  95. package/dist/config/parse-open-api.js +20 -0
  96. package/dist/config/parse-open-api.js.map +1 -0
  97. package/dist/config/restack-config-text.d.ts +1 -1
  98. package/dist/config/restack-config-text.d.ts.map +1 -1
  99. package/dist/config/restack-config-text.js +9 -2
  100. package/dist/config/restack-config-text.js.map +1 -1
  101. package/dist/config/serialize-config.js +8 -0
  102. package/dist/config/serialize-config.js.map +1 -1
  103. package/dist/contracts/contract-format.d.ts +3 -0
  104. package/dist/contracts/contract-format.d.ts.map +1 -0
  105. package/dist/contracts/contract-format.js +11 -0
  106. package/dist/contracts/contract-format.js.map +1 -0
  107. package/dist/contracts/stringify-contract.d.ts +3 -0
  108. package/dist/contracts/stringify-contract.d.ts.map +1 -0
  109. package/dist/contracts/stringify-contract.js +6 -0
  110. package/dist/contracts/stringify-contract.js.map +1 -0
  111. package/dist/contracts.d.ts +9 -0
  112. package/dist/contracts.d.ts.map +1 -0
  113. package/dist/contracts.js +9 -0
  114. package/dist/contracts.js.map +1 -0
  115. package/dist/describe/describe-context.d.ts.map +1 -1
  116. package/dist/describe/describe-context.js +14 -3
  117. package/dist/describe/describe-context.js.map +1 -1
  118. package/dist/docs/open-api-documents-file.d.ts +4 -0
  119. package/dist/docs/open-api-documents-file.d.ts.map +1 -0
  120. package/dist/docs/open-api-documents-file.js +5 -0
  121. package/dist/docs/open-api-documents-file.js.map +1 -0
  122. package/dist/docs/render-open-api-documents.d.ts +13 -0
  123. package/dist/docs/render-open-api-documents.d.ts.map +1 -0
  124. package/dist/docs/render-open-api-documents.js +42 -0
  125. package/dist/docs/render-open-api-documents.js.map +1 -0
  126. package/dist/docs/write-docs.d.ts.map +1 -1
  127. package/dist/docs/write-docs.js +2 -0
  128. package/dist/docs/write-docs.js.map +1 -1
  129. package/dist/docs/write-open-api-documents.d.ts +9 -0
  130. package/dist/docs/write-open-api-documents.d.ts.map +1 -0
  131. package/dist/docs/write-open-api-documents.js +33 -0
  132. package/dist/docs/write-open-api-documents.js.map +1 -0
  133. package/dist/help/commands-guide-region.d.ts +3 -0
  134. package/dist/help/commands-guide-region.d.ts.map +1 -0
  135. package/dist/help/commands-guide-region.js +12 -0
  136. package/dist/help/commands-guide-region.js.map +1 -0
  137. package/dist/help/notes.d.ts +3 -0
  138. package/dist/help/notes.d.ts.map +1 -0
  139. package/dist/help/notes.js +24 -0
  140. package/dist/help/notes.js.map +1 -0
  141. package/dist/help/reference-text.d.ts +3 -0
  142. package/dist/help/reference-text.d.ts.map +1 -0
  143. package/dist/help/reference-text.js +14 -0
  144. package/dist/help/reference-text.js.map +1 -0
  145. package/dist/help/usage.d.ts +3 -0
  146. package/dist/help/usage.d.ts.map +1 -0
  147. package/dist/help/usage.js +37 -0
  148. package/dist/help/usage.js.map +1 -0
  149. package/dist/index.d.ts +1 -0
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +1 -0
  152. package/dist/index.js.map +1 -1
  153. package/dist/init/files/persistence-files.js +1 -1
  154. package/dist/init/files/persistence-files.js.map +1 -1
  155. package/dist/init/files/pipeline-files.d.ts.map +1 -1
  156. package/dist/init/files/pipeline-files.js +4 -2
  157. package/dist/init/files/pipeline-files.js.map +1 -1
  158. package/dist/init/manifest/database-scripts.d.ts.map +1 -1
  159. package/dist/init/manifest/database-scripts.js +5 -4
  160. package/dist/init/manifest/database-scripts.js.map +1 -1
  161. package/dist/init/manifest/versions.js +23 -23
  162. package/dist/init/run-init.d.ts.map +1 -1
  163. package/dist/init/run-init.js +3 -0
  164. package/dist/init/run-init.js.map +1 -1
  165. package/dist/init/stack/resolve-ci-extras.d.ts +8 -0
  166. package/dist/init/stack/resolve-ci-extras.d.ts.map +1 -0
  167. package/dist/init/stack/resolve-ci-extras.js +31 -0
  168. package/dist/init/stack/resolve-ci-extras.js.map +1 -0
  169. package/dist/init/stack/resolve-stack.d.ts.map +1 -1
  170. package/dist/init/stack/resolve-stack.js +3 -1
  171. package/dist/init/stack/resolve-stack.js.map +1 -1
  172. package/dist/init/stack/stack-options.d.ts +2 -0
  173. package/dist/init/stack/stack-options.d.ts.map +1 -1
  174. package/dist/init/template-vars.d.ts.map +1 -1
  175. package/dist/init/template-vars.js +14 -0
  176. package/dist/init/template-vars.js.map +1 -1
  177. package/dist/init/write-agent-settings.js +2 -2
  178. package/dist/init/write-agent-settings.js.map +1 -1
  179. package/dist/init/write-contracts.d.ts.map +1 -1
  180. package/dist/init/write-contracts.js +7 -3
  181. package/dist/init/write-contracts.js.map +1 -1
  182. package/dist/progress/format-progress.d.ts.map +1 -1
  183. package/dist/progress/format-progress.js +3 -1
  184. package/dist/progress/format-progress.js.map +1 -1
  185. package/dist/run.d.ts.map +1 -1
  186. package/dist/run.js +2 -63
  187. package/dist/run.js.map +1 -1
  188. package/dist/version.d.ts +1 -1
  189. package/dist/version.js +1 -1
  190. package/dist/yaml/to-yaml.d.ts +8 -0
  191. package/dist/yaml/to-yaml.d.ts.map +1 -0
  192. package/dist/yaml/to-yaml.js +132 -0
  193. package/dist/yaml/to-yaml.js.map +1 -0
  194. package/package.json +2 -2
  195. package/templates/docs/integration-readme.md.tpl +2 -2
  196. package/templates/init/CLAUDE.md.tpl +2 -1
  197. package/templates/init/README.md.tpl +37 -11
  198. package/templates/init/platform/database/data-source.typeorm.ts.tpl +1 -1
  199. package/templates/init/platform/database/drizzle.config.ts.tpl +2 -0
  200. package/templates/init/platform/database/knexfile.js.tpl +9 -3
  201. package/templates/init/platform/database/schema.drizzle.ts.tpl +1 -1
  202. package/templates/init/platform/database/schema.knex.ts.tpl +2 -2
  203. package/templates/init/platform/http/with-documentation.ts.tpl +13 -9
  204. package/templates/init/rules/presentation.md.tpl +1 -1
  205. package/templates/init/scripts/events.ts.tpl +16 -5
  206. package/templates/init/scripts/openapi.ts.tpl +49 -20
  207. package/templates/pipeline/github/branch-protection.md +8 -7
  208. package/templates/pipeline/github/workflows/{ci.yml → ci.yml.tpl} +3 -0
  209. package/templates/pipeline/gitlab/gitlab-ci.yml.tpl +11 -0
  210. package/templates/pipeline/gitlab/merge-request-settings.md +7 -6
  211. package/templates/pipeline/package-scripts.json +1 -1
  212. package/templates/repository/drizzle/table.tpl +2 -2
  213. package/templates/repository/prisma/model.tpl +1 -1
  214. package/templates/repository/typeorm/table.tpl +1 -1
@@ -13,9 +13,9 @@ export const AUDIT_SCHEMA = 'audit';
13
13
  {{/if}}
14
14
 
15
15
  /**
16
- * Every table of the application. The first migration (migrations/0001_initial.js) and the
16
+ * Every table of the application. The first migration (migrations/00000000000000_initial.js) and the
17
17
  * in-process database of the tests both call it; once a database is shared, a change of an
18
- * existing table goes into a migration of its own (`npm run db:generate <name>`).
18
+ * existing table goes into a migration of its own (`npm run db:generate <what-it-does>`).
19
19
  */
20
20
  export const createTables = async (knex: Knex): Promise<void> => {
21
21
  await createOutboxTables(knex, { schema: MESSAGING });
@@ -1,20 +1,24 @@
1
1
  import type { Route } from '@ddd-ts-kit/http';
2
- import { openApiDocsRoutes } from '@ddd-ts-kit/http/docs';
3
- import { generateOpenApi } from '@ddd-ts-kit/http/openapi';
2
+ import { openApiDocumentsRoutes } from '@ddd-ts-kit/http/docs';
3
+ import { generateOpenApi, routesByDocument } from '@ddd-ts-kit/http/openapi';
4
4
  import { securitySchemes } from '{{alias.platform}}/auth/security-schemes{{alias.ext}}';
5
5
  import type { AppConfig } from '{{alias.platform}}/config/app-config{{alias.ext}}';
6
+ import { OPENAPI_DOCUMENTS } from '{{alias.platform}}/http/openapi-documents{{alias.ext}}';
6
7
 
7
- /** Adds the contract and its interactive page next to the routes, unless documentation is switched off (API_DOCS, off in production by default). */
8
+ /** Adds the contract and its interactive page next to the routes, one per document of a split contract, unless documentation is switched off (API_DOCS, off in production by default). */
8
9
  export function withDocumentation(routes: readonly Route[], config: AppConfig): readonly Route[] {
9
10
  if (!config.docsEnabled) {
10
11
  return routes;
11
12
  }
12
13
 
13
- const document = generateOpenApi({
14
- info: { title: config.serviceName, version: config.serviceVersion },
15
- routes,
16
- securitySchemes,
17
- });
14
+ const documents = routesByDocument(routes, OPENAPI_DOCUMENTS).map(({ name, title, routes: selected }) => ({
15
+ name,
16
+ document: generateOpenApi({
17
+ info: { title: title ?? config.serviceName, version: config.serviceVersion },
18
+ routes: selected,
19
+ securitySchemes,
20
+ }),
21
+ }));
18
22
 
19
- return [...routes, ...openApiDocsRoutes(document, { ui: '{{docs.ui}}' })];
23
+ return [...routes, ...openApiDocumentsRoutes(documents, { ui: '{{docs.ui}}', title: config.serviceName })];
20
24
  }
@@ -28,5 +28,5 @@ paths:
28
28
  - 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.
29
29
  - Never put the message of an unexpected failure in a response or a log.
30
30
  - 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`).
31
- - After a change, `npm run docs:generate` regenerates `openapi/openapi.json`, committed with the route; CI fails on a difference. Never edit it by hand.
31
+ - 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.
32
32
  - 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.
@@ -1,18 +1,22 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createEventRegistry, generateEventCatalog, type AnyIntegrationEventDefinition } from '@ddd-ts-kit/events';
4
- import { generateAsyncApi, stringifyAsyncApi } from '@ddd-ts-kit/events/asyncapi';
4
+ import { generateAsyncApi } from '@ddd-ts-kit/events/asyncapi';
5
+ import { contractFormat, stringifyContract } from 'ddd-ts-kit/dist/contracts.js';
5
6
 
6
- // Generates docs/integration/asyncapi.json and docs/integration/event-catalog.md from the
7
- // declarations of every published language; with --check, fails when a committed file
8
- // differs. Both files are build products: never edit them by hand.
7
+ // Generates docs/integration/asyncapi.yaml (asyncapi.json under "openapi.format": "json" in
8
+ // ddd-ts-kit.config.json) and docs/integration/event-catalog.md from the declarations of every
9
+ // published language; with --check, fails when a committed file differs. Both files are build
10
+ // products: never edit them by hand.
9
11
  const contextsDirectory = '{{config.contextsDir}}';
10
12
  const target = path.resolve('docs/integration');
13
+ const format = contractFormat();
14
+ const other = format === 'yaml' ? 'asyncapi.json' : 'asyncapi.yaml';
11
15
 
12
16
  const registry = createEventRegistry(await declaredEvents());
13
17
 
14
18
  const generated: Readonly<Record<string, string>> = {
15
- 'asyncapi.json': stringifyAsyncApi(
19
+ [`asyncapi.${format}`]: stringifyContract(
16
20
  generateAsyncApi({
17
21
  info: {
18
22
  title: manifestField('name', '{{project.name}}'),
@@ -20,6 +24,7 @@ const generated: Readonly<Record<string, string>> = {
20
24
  },
21
25
  registry,
22
26
  }),
27
+ format,
23
28
  ),
24
29
  'event-catalog.md': generateEventCatalog(registry, { consumers: consumersByEventType() }),
25
30
  };
@@ -28,6 +33,7 @@ if (process.argv.includes('--check')) {
28
33
  reportStale();
29
34
  } else {
30
35
  fs.mkdirSync(target, { recursive: true });
36
+ fs.rmSync(path.join(target, other), { force: true });
31
37
 
32
38
  for (const [file, content] of Object.entries(generated)) {
33
39
  fs.writeFileSync(path.join(target, file), content);
@@ -43,6 +49,11 @@ function reportStale(): void {
43
49
  process.exitCode = 1;
44
50
  }
45
51
  }
52
+
53
+ if (fs.existsSync(path.join(target, other))) {
54
+ console.error('docs/integration/' + other + ' is in the other format: run the script `docs:generate`.');
55
+ process.exitCode = 1;
56
+ }
46
57
  }
47
58
 
48
59
  /** Every declaration exported by a published language. Read from the compiled modules next to this script, so that a new context needs no registration: a path completed at run time cannot be an import alias, which the build rewrites. */
@@ -1,47 +1,76 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { checkOpenApiDrift, generateOpenApi, stringifyOpenApi } from '@ddd-ts-kit/http/openapi';
3
+ import { generateOpenApi, routesByDocument } from '@ddd-ts-kit/http/openapi';
4
+ import { contractFormat, stringifyContract } from 'ddd-ts-kit/dist/contracts.js';
4
5
  import { offlineAuthenticator } from '{{alias.platform}}/auth/offline-authenticator{{alias.ext}}';
5
6
  import { securitySchemes } from '{{alias.platform}}/auth/security-schemes{{alias.ext}}';
6
7
  import { composeApplication } from '{{alias.platform}}/compose-application{{alias.ext}}';
7
8
  import { inertPersistence } from '{{alias.platform}}/database/inert-persistence{{alias.ext}}';
8
9
  import { inProcessEvents } from '{{alias.platform}}/events/in-process-events{{alias.ext}}';
10
+ import { OPENAPI_DOCUMENTS } from '{{alias.platform}}/http/openapi-documents{{alias.ext}}';
9
11
 
10
- // Generates openapi/openapi.json from the route definitions; with --check, fails when the
11
- // committed file differs. The file is a build product: never edit it by hand.
12
- const target = path.resolve('openapi/openapi.json');
12
+ // Generates the contract from the route definitions: openapi/openapi.yaml, or one file per
13
+ // document of "openapi.documents" in ddd-ts-kit.config.json, in the format of "openapi.format";
14
+ // with --check, fails when a committed file differs. Build products: never edit them by hand.
15
+ const directory = path.resolve('openapi');
16
+ const format = contractFormat();
13
17
 
14
18
  const application = composeApplication(inertPersistence(), {
15
19
  events: inProcessEvents(),
16
20
  authenticator: offlineAuthenticator,
17
21
  });
18
22
 
19
- const document = generateOpenApi({
20
- info: {
21
- title: manifestField('name', '{{project.name}}'),
22
- version: manifestField('version', '0.0.0'),
23
- },
24
- routes: application.routes,
25
- securitySchemes,
26
- errorMapper: application.boundary.errorMapper,
27
- });
23
+ const generated = new Map(
24
+ routesByDocument(application.routes, OPENAPI_DOCUMENTS).map(({ name, title, routes }) => [
25
+ `${name}.${format}`,
26
+ stringifyContract(
27
+ generateOpenApi({
28
+ info: { title: title ?? manifestField('name', '{{project.name}}'), version: manifestField('version', '0.0.0') },
29
+ routes,
30
+ securitySchemes,
31
+ errorMapper: application.boundary.errorMapper,
32
+ }),
33
+ format,
34
+ ),
35
+ ]),
36
+ );
28
37
 
29
38
  if (process.argv.includes('--check')) {
30
39
  reportDrift();
31
40
  } else {
32
- fs.mkdirSync(path.dirname(target), { recursive: true });
33
- fs.writeFileSync(target, stringifyOpenApi(document));
41
+ fs.mkdirSync(directory, { recursive: true });
42
+
43
+ for (const file of staleFiles()) {
44
+ fs.rmSync(path.join(directory, file));
45
+ }
46
+
47
+ for (const [file, content] of generated) {
48
+ fs.writeFileSync(path.join(directory, file), content);
49
+ }
34
50
  }
35
51
 
36
52
  function reportDrift(): void {
37
- const committed = fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : '';
53
+ for (const [file, content] of generated) {
54
+ const target = path.join(directory, file);
55
+ const committed = fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : '';
38
56
 
39
- if (!checkOpenApiDrift(document, committed).drift) {
40
- return;
57
+ if (committed.replaceAll('\r\n', '\n') !== content) {
58
+ console.error(`openapi/${file} is out of date: run the script \`docs:generate\` and commit it.`);
59
+ process.exitCode = 1;
60
+ }
41
61
  }
42
62
 
43
- console.error('openapi/openapi.json is out of date: run the script `docs:generate` and commit it.');
44
- process.exitCode = 1;
63
+ for (const file of staleFiles()) {
64
+ console.error(`openapi/${file} is no document of the contract any more: run the script \`docs:generate\`.`);
65
+ process.exitCode = 1;
66
+ }
67
+ }
68
+
69
+ /** The contracts left by another format or by a document that is gone. */
70
+ function staleFiles(): string[] {
71
+ const present = fs.existsSync(directory) ? fs.readdirSync(directory) : [];
72
+
73
+ return present.filter((file) => /\.(?:json|yaml)$/.test(file) && !generated.has(file));
45
74
  }
46
75
 
47
76
  function manifestField(name: string, fallback: string): string {
@@ -10,7 +10,7 @@ of `CI` on `main` (GitHub only offers a check as "required" once it has reported
10
10
  |---|---|---|
11
11
  | `gate` | `ci.yml` | Needs every other job of the workflow; a failed, cancelled or skipped job fails it. One required check, so adding a job never needs a settings change. |
12
12
  | `Conventional title` | `pr-title.yml` | The squash commit takes the pull request title. |
13
- | `Analyze` | `codeql.yml` | Optional: require it when code scanning is enabled on the repository. |
13
+ | `Analyze` | `codeql.yml` | Only with `init --ci-extras codeql`: require it when code scanning is enabled on the repository. |
14
14
 
15
15
  ## Protect `main`
16
16
 
@@ -66,12 +66,13 @@ Expected: `{"checks":["gate","Conventional title"],"strict":true,"admins":true}`
66
66
 
67
67
  ## Notes
68
68
 
69
- - Dependency review needs the dependency graph: free on public repositories, GitHub Advanced
70
- Security (or GitHub Code Security) on private ones. Without it the step fails with an explicit
71
- message; remove the step and keep `npm run ci:audit`.
72
- - CodeQL is free on public repositories and needs GitHub Code Security on private ones.
69
+ - Not installed by default, because they need a paid plan on a private repository:
70
+ dependency review (`--ci-extras dependency-review`: free on public repositories, GitHub Code
71
+ Security or GitHub Advanced Security on private ones) and CodeQL (`--ci-extras codeql`: free on
72
+ public repositories, GitHub Code Security on private ones). `npm run ci:audit` and gitleaks
73
+ hold dependencies and secrets on every plan.
73
74
  - Secret scanning in `ci.yml` runs the gitleaks container, which needs no licence. The
74
- `gitleaks/gitleaks-action` wrapper is not used because it requires a licence key for
75
- organization accounts.
75
+ `gitleaks/gitleaks-action` wrapper is not used: it asks organization accounts for a licence
76
+ key (free, by its README) and is no longer MIT.
76
77
  - Dependabot (`dependabot.yml`) is GitHub only. `renovate.json` works on both platforms; keep one
77
78
  of the two, not both.
@@ -173,11 +173,14 @@ jobs:
173
173
  - uses: ./.github/actions/setup
174
174
  - name: Production dependencies audit
175
175
  run: npm run ci:audit
176
+ {{#if extras.dependencyReview}}
177
+ # Opt-in (--ci-extras dependency-review): free on a public repository, GitHub Code Security on a private one.
176
178
  - name: Dependency review
177
179
  if: ${{ github.event_name == 'pull_request' && !cancelled() }}
178
180
  uses: actions/dependency-review-action@v5.0.0
179
181
  with:
180
182
  fail-on-severity: high
183
+ {{/if}}
181
184
  - name: Secrets
182
185
  if: ${{ !cancelled() }}
183
186
  run: docker run --rm --volume "$GITHUB_WORKSPACE:/repo" ghcr.io/gitleaks/gitleaks:v8.30.1 git /repo --redact --no-banner
@@ -7,13 +7,22 @@ workflow:
7
7
  # A pipeline schedule (Build > Pipeline schedules, every night on the default branch) runs everything.
8
8
  - if: $CI_PIPELINE_SOURCE == "schedule"
9
9
 
10
+ {{#if extras.gitlabSecurity}}
11
+ # Opt-in (--ci-extras): these run on every tier, but their findings reach a merge request on Ultimate only.
10
12
  include:
13
+ {{#if extras.gitlabSast}}
11
14
  - template: Jobs/SAST.gitlab-ci.yml
15
+ {{/if}}
16
+ {{#if extras.gitlabSecretDetection}}
12
17
  - template: Jobs/Secret-Detection.gitlab-ci.yml
18
+ {{/if}}
19
+ {{#if extras.gitlabDependencyScanning}}
13
20
  - template: Jobs/Dependency-Scanning.v2.gitlab-ci.yml
14
21
  rules:
15
22
  - if: $GITLAB_FEATURES =~ /\bdependency_scanning\b/
23
+ {{/if}}
16
24
 
25
+ {{/if}}
17
26
  stages:
18
27
  - install
19
28
  - test
@@ -21,7 +30,9 @@ stages:
21
30
  - gate
22
31
 
23
32
  variables:
33
+ {{#if extras.gitlabSecurity}}
24
34
  AST_ENABLE_MR_PIPELINES: 'true'
35
+ {{/if}}
25
36
  NODE_IMAGE: node:24-bookworm-slim
26
37
  # Behind the dependency proxy of a group, a registry that rate-limits is never asked twice:
27
38
  # POSTGRES_IMAGE: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/postgres:18
@@ -76,14 +76,15 @@ glab api "projects/:id/protected_branches/main" | jq '{name, allow_force_push, p
76
76
 
77
77
  | Piece | Free | Premium | Ultimate |
78
78
  |---|---|---|---|
79
- | SAST template (`Jobs/SAST.gitlab-ci.yml`, Semgrep rules for JavaScript and TypeScript) | job runs, report downloadable as an artifact | same | findings in the merge request, vulnerability management, Advanced SAST |
80
- | Secret Detection template (`Jobs/Secret-Detection.gitlab-ci.yml`) | job runs, report downloadable as an artifact | same | findings in the merge request and the security dashboard |
81
- | Dependency Scanning template (`Jobs/Dependency-Scanning.v2.gitlab-ci.yml`) | not available: the `include` is skipped | not available | available |
79
+ | SAST template (`Jobs/SAST.gitlab-ci.yml`, Semgrep rules for JavaScript and TypeScript), `--ci-extras gitlab-sast` | job runs, report downloadable as an artifact | same | findings in the merge request, vulnerability management, Advanced SAST |
80
+ | Secret Detection template (`Jobs/Secret-Detection.gitlab-ci.yml`), `--ci-extras gitlab-secret-detection` | job runs, report downloadable as an artifact | same | findings in the merge request and the security dashboard |
81
+ | Dependency Scanning template (`Jobs/Dependency-Scanning.v2.gitlab-ci.yml`), `--ci-extras gitlab-dependency-scanning` | not available: the `include` is skipped | not available | available |
82
82
  | Code Quality report (ESLint and architecture) | merge request widget | plus the pipeline report tab | plus inline in the changes view |
83
83
  | JUnit report, coverage percentage, Cobertura coverage in the diff | available | available | available |
84
84
  | Push rules | no | yes | yes |
85
85
  | Required approvals | no | yes | yes |
86
86
 
87
- The template jobs are `allow_failure: true` by design of GitLab: on Free and Premium they never
88
- block a merge. What blocks, on every tier, is the `audit` job (`npm audit`, production
89
- dependencies, high and above) and the `secrets` job (gitleaks).
87
+ The three templates are not in `.gitlab-ci.yml` unless `init --ci-extras` names them: on Free
88
+ and Premium their findings reach no merge request, and their jobs are `allow_failure: true` by
89
+ design of GitLab, so they never block a merge. What blocks, on every tier, is the `audit` job
90
+ (`npm audit`, production dependencies, high and above) and the `secrets` job (gitleaks).
@@ -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.4.1",
26
+ "@ddd-ts-kit/eslint-plugin": "^0.5.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",
@@ -13,7 +13,7 @@ export const {{aggregate.tableCamel}} = {{context.camel}}Schema.table(
13
13
  {
14
14
  id: text('id').primaryKey(),
15
15
  registeredAt: timestamp('registered_at', { withTimezone: true, mode: 'date' }).notNull(),
16
- // TODO(domain): add one column per field of {{aggregate.pascal}}State, with the type and the constraints the storage must enforce; then run `npm run db:generate`.
16
+ // TODO(domain): add one column per field of {{aggregate.pascal}}State, with the type and the constraints the storage must enforce; then run `npm run db:generate <what-it-does>`.
17
17
  version: integer('version').notNull(),
18
18
  ...tenantColumn(),
19
19
  ...auditColumns(),
@@ -25,7 +25,7 @@ export const {{aggregate.tableCamel}} = {{context.camel}}Schema.table(
25
25
  export const {{aggregate.tableCamel}} = {{context.camel}}Schema.table('{{aggregate.table}}', {
26
26
  id: text('id').primaryKey(),
27
27
  registeredAt: timestamp('registered_at', { withTimezone: true, mode: 'date' }).notNull(),
28
- // TODO(domain): add one column per field of {{aggregate.pascal}}State, with the type and the constraints the storage must enforce; then run `npm run db:generate`.
28
+ // TODO(domain): add one column per field of {{aggregate.pascal}}State, with the type and the constraints the storage must enforce; then run `npm run db:generate <what-it-does>`.
29
29
  version: integer('version').notNull(),
30
30
  ...auditColumns(),
31
31
  });
@@ -2,7 +2,7 @@
2
2
  model {{context.pascal}}{{aggregate.pascal}} {
3
3
  id String @id
4
4
  registeredAt DateTime @map("registered_at") @db.Timestamptz(3)
5
- // TODO(domain): add one field per field of {{aggregate.pascal}}State, with the type and the constraints the storage must enforce; then run `npm run db:client` and `npm run db:generate`.
5
+ // TODO(domain): add one field per field of {{aggregate.pascal}}State, with the type and the constraints the storage must enforce; then run `npm run db:client` and `npm run db:generate <what-it-does>`.
6
6
  version Int
7
7
  createdAt DateTime @map("created_at") @db.Timestamptz(3)
8
8
  createdBy String @map("created_by")
@@ -8,7 +8,7 @@ export const {{aggregate.tableCamel}} = new EntitySchema<{{aggregate.pascal}}Row
8
8
  columns: {
9
9
  id: { type: 'text', primary: true },
10
10
  registeredAt: { name: 'registered_at', type: 'timestamptz' },
11
- // TODO(domain): add one column per field of {{aggregate.pascal}}State (and to {{aggregate.pascal}}Columns of {{aggregate.kebab}}-row.schema.ts), with the type and the constraints the storage must enforce; then run `npm run db:generate`.
11
+ // TODO(domain): add one column per field of {{aggregate.pascal}}State (and to {{aggregate.pascal}}Columns of {{aggregate.kebab}}-row.schema.ts), with the type and the constraints the storage must enforce; then run `npm run build && npm run db:generate migrations/<what-it-does>`.
12
12
  version: { type: 'int' },
13
13
  ...auditColumns(),
14
14
  },