@rawsql-ts/ztd-cli 0.16.0 → 0.19.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 (242) hide show
  1. package/README.md +532 -353
  2. package/package.json +35 -17
  3. package/templates/.editorconfig +16 -16
  4. package/templates/.prettierignore +2 -2
  5. package/templates/.prettierrc +24 -24
  6. package/templates/AGENTS.md +30 -325
  7. package/templates/CONTEXT.md +11 -0
  8. package/templates/CONTEXT.webapi.md +11 -0
  9. package/templates/DESIGN.md +17 -0
  10. package/templates/DEV_NOTES.md +14 -0
  11. package/templates/PROMPT_DOGFOOD.webapi.md +49 -0
  12. package/templates/README.md +46 -217
  13. package/templates/README.webapi.md +38 -0
  14. package/templates/scripts/local-source-guard.mjs +189 -0
  15. package/templates/src/AGENTS.md +26 -0
  16. package/templates/src/application/AGENTS.md +15 -0
  17. package/templates/src/application/README.md +6 -0
  18. package/templates/src/catalog/AGENTS.md +28 -0
  19. package/templates/src/catalog/runtime/AGENTS.md +28 -0
  20. package/templates/src/catalog/runtime/_coercions.local-source.ts +30 -0
  21. package/templates/src/catalog/runtime/_coercions.ts +30 -0
  22. package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
  23. package/templates/src/catalog/specs/AGENTS.md +41 -0
  24. package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
  25. package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
  26. package/templates/src/db/sql-client-adapters.ts +32 -0
  27. package/templates/src/db/sql-client.ts +24 -24
  28. package/templates/src/domain/AGENTS.md +15 -0
  29. package/templates/src/domain/README.md +6 -0
  30. package/templates/src/infrastructure/AGENTS.md +14 -0
  31. package/templates/src/infrastructure/README.md +6 -0
  32. package/templates/src/infrastructure/db/AGENTS.md +14 -0
  33. package/templates/src/infrastructure/db/sql-client-adapters.ts +34 -0
  34. package/templates/src/infrastructure/db/sql-client.ts +24 -0
  35. package/templates/src/infrastructure/persistence/AGENTS.md +18 -0
  36. package/templates/src/infrastructure/persistence/README.md +8 -0
  37. package/templates/src/infrastructure/persistence/repositories/AGENTS.md +17 -0
  38. package/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md +20 -0
  39. package/templates/src/infrastructure/persistence/repositories/tables/README.md +5 -0
  40. package/templates/src/infrastructure/persistence/repositories/views/AGENTS.md +16 -0
  41. package/templates/src/infrastructure/persistence/repositories/views/README.md +5 -0
  42. package/templates/src/infrastructure/telemetry/AGENTS.md +14 -0
  43. package/templates/src/infrastructure/telemetry/consoleRepositoryTelemetry.ts +66 -0
  44. package/templates/src/infrastructure/telemetry/repositoryTelemetry.ts +26 -0
  45. package/templates/src/infrastructure/telemetry/types.ts +48 -0
  46. package/templates/src/jobs/AGENTS.md +25 -0
  47. package/templates/src/jobs/README.md +3 -0
  48. package/templates/src/local/sql-contract.ts +1 -0
  49. package/templates/src/presentation/AGENTS.md +15 -0
  50. package/templates/src/presentation/http/AGENTS.md +15 -0
  51. package/templates/src/presentation/http/README.md +6 -0
  52. package/templates/src/repositories/AGENTS.md +30 -0
  53. package/templates/src/repositories/tables/AGENTS.md +29 -0
  54. package/templates/src/repositories/tables/README.md +5 -0
  55. package/templates/src/repositories/views/AGENTS.md +25 -0
  56. package/templates/src/repositories/views/README.md +5 -0
  57. package/templates/src/sql/AGENTS.md +30 -0
  58. package/templates/src/sql/README.md +6 -0
  59. package/templates/tests/AGENTS.md +29 -169
  60. package/templates/tests/generated/AGENTS.md +23 -0
  61. package/templates/tests/smoke.test.ts +25 -0
  62. package/templates/tests/smoke.validation.test.ts +34 -0
  63. package/templates/tests/support/AGENTS.md +24 -0
  64. package/templates/tests/support/global-setup.ts +15 -30
  65. package/templates/tests/support/testkit-client.ts +14 -742
  66. package/templates/tests/support/testkit-client.webapi.ts +14 -0
  67. package/templates/tests/ztd-layout.generated.ts +6 -6
  68. package/templates/tsconfig.json +15 -8
  69. package/templates/vitest.config.ts +13 -13
  70. package/templates/ztd/AGENTS.md +23 -74
  71. package/templates/ztd/README.md +6 -15
  72. package/templates/ztd/ddl/AGENTS.md +26 -0
  73. package/templates/ztd/ddl/demo.sql +74 -0
  74. package/LICENSE +0 -21
  75. package/dist/commands/ddl.d.ts +0 -7
  76. package/dist/commands/ddl.js +0 -118
  77. package/dist/commands/ddl.js.map +0 -1
  78. package/dist/commands/diff.d.ts +0 -10
  79. package/dist/commands/diff.js +0 -38
  80. package/dist/commands/diff.js.map +0 -1
  81. package/dist/commands/genEntities.d.ts +0 -6
  82. package/dist/commands/genEntities.js +0 -50
  83. package/dist/commands/genEntities.js.map +0 -1
  84. package/dist/commands/init.d.ts +0 -66
  85. package/dist/commands/init.js +0 -838
  86. package/dist/commands/init.js.map +0 -1
  87. package/dist/commands/lint.d.ts +0 -59
  88. package/dist/commands/lint.js +0 -338
  89. package/dist/commands/lint.js.map +0 -1
  90. package/dist/commands/options.d.ts +0 -9
  91. package/dist/commands/options.js +0 -48
  92. package/dist/commands/options.js.map +0 -1
  93. package/dist/commands/pull.d.ts +0 -10
  94. package/dist/commands/pull.js +0 -105
  95. package/dist/commands/pull.js.map +0 -1
  96. package/dist/commands/ztdConfig.d.ts +0 -23
  97. package/dist/commands/ztdConfig.js +0 -202
  98. package/dist/commands/ztdConfig.js.map +0 -1
  99. package/dist/commands/ztdConfigCommand.d.ts +0 -5
  100. package/dist/commands/ztdConfigCommand.js +0 -157
  101. package/dist/commands/ztdConfigCommand.js.map +0 -1
  102. package/dist/index.d.ts +0 -2
  103. package/dist/index.js +0 -22
  104. package/dist/index.js.map +0 -1
  105. package/dist/utils/agents.d.ts +0 -1
  106. package/dist/utils/agents.js +0 -48
  107. package/dist/utils/agents.js.map +0 -1
  108. package/dist/utils/collectSqlFiles.d.ts +0 -9
  109. package/dist/utils/collectSqlFiles.js +0 -58
  110. package/dist/utils/collectSqlFiles.js.map +0 -1
  111. package/dist/utils/connectionSummary.d.ts +0 -3
  112. package/dist/utils/connectionSummary.js +0 -29
  113. package/dist/utils/connectionSummary.js.map +0 -1
  114. package/dist/utils/dbConnection.d.ts +0 -29
  115. package/dist/utils/dbConnection.js +0 -210
  116. package/dist/utils/dbConnection.js.map +0 -1
  117. package/dist/utils/fs.d.ts +0 -1
  118. package/dist/utils/fs.js +0 -12
  119. package/dist/utils/fs.js.map +0 -1
  120. package/dist/utils/normalizePulledSchema.d.ts +0 -12
  121. package/dist/utils/normalizePulledSchema.js +0 -213
  122. package/dist/utils/normalizePulledSchema.js.map +0 -1
  123. package/dist/utils/pgDump.d.ts +0 -11
  124. package/dist/utils/pgDump.js +0 -55
  125. package/dist/utils/pgDump.js.map +0 -1
  126. package/dist/utils/sqlLintHelpers.d.ts +0 -18
  127. package/dist/utils/sqlLintHelpers.js +0 -270
  128. package/dist/utils/sqlLintHelpers.js.map +0 -1
  129. package/dist/utils/typeMapper.d.ts +0 -4
  130. package/dist/utils/typeMapper.js +0 -76
  131. package/dist/utils/typeMapper.js.map +0 -1
  132. package/dist/utils/ztdProjectConfig.d.ts +0 -40
  133. package/dist/utils/ztdProjectConfig.js +0 -167
  134. package/dist/utils/ztdProjectConfig.js.map +0 -1
  135. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +0 -38
  136. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +0 -117
  137. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +0 -1
  138. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +0 -4
  139. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +0 -71
  140. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +0 -1
  141. package/templates/dist/drivers/pg-testkit/src/index.d.ts +0 -5
  142. package/templates/dist/drivers/pg-testkit/src/index.js +0 -11
  143. package/templates/dist/drivers/pg-testkit/src/index.js.map +0 -1
  144. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +0 -3
  145. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +0 -79
  146. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +0 -1
  147. package/templates/dist/drivers/pg-testkit/src/types.d.ts +0 -69
  148. package/templates/dist/drivers/pg-testkit/src/types.js +0 -3
  149. package/templates/dist/drivers/pg-testkit/src/types.js.map +0 -1
  150. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +0 -15
  151. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +0 -34
  152. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +0 -1
  153. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +0 -12
  154. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +0 -53
  155. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +0 -1
  156. package/templates/dist/mapper-core/src/index.d.ts +0 -160
  157. package/templates/dist/mapper-core/src/index.js +0 -637
  158. package/templates/dist/mapper-core/src/index.js.map +0 -1
  159. package/templates/dist/testkit-core/src/errors/index.d.ts +0 -49
  160. package/templates/dist/testkit-core/src/errors/index.js +0 -111
  161. package/templates/dist/testkit-core/src/errors/index.js.map +0 -1
  162. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +0 -5
  163. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +0 -29
  164. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +0 -1
  165. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +0 -37
  166. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +0 -182
  167. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +0 -1
  168. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +0 -20
  169. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +0 -121
  170. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +0 -1
  171. package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +0 -51
  172. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +0 -199
  173. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +0 -1
  174. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +0 -10
  175. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +0 -28
  176. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +0 -1
  177. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +0 -18
  178. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +0 -80
  179. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +0 -1
  180. package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +0 -59
  181. package/templates/dist/testkit-core/src/fixtures/ddlLint.js +0 -489
  182. package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +0 -1
  183. package/templates/dist/testkit-core/src/fixtures/naming.d.ts +0 -1
  184. package/templates/dist/testkit-core/src/fixtures/naming.js +0 -6
  185. package/templates/dist/testkit-core/src/fixtures/naming.js.map +0 -1
  186. package/templates/dist/testkit-core/src/index.d.ts +0 -17
  187. package/templates/dist/testkit-core/src/index.js +0 -47
  188. package/templates/dist/testkit-core/src/index.js.map +0 -1
  189. package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +0 -8
  190. package/templates/dist/testkit-core/src/logger/NoopLogger.js +0 -16
  191. package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +0 -1
  192. package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +0 -57
  193. package/templates/dist/testkit-core/src/provider/TestkitProvider.js +0 -149
  194. package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +0 -1
  195. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +0 -43
  196. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +0 -473
  197. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +0 -1
  198. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +0 -9
  199. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +0 -38
  200. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +0 -1
  201. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +0 -42
  202. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +0 -298
  203. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +0 -1
  204. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +0 -12
  205. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +0 -63
  206. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +0 -1
  207. package/templates/dist/testkit-core/src/types/index.d.ts +0 -69
  208. package/templates/dist/testkit-core/src/types/index.js +0 -3
  209. package/templates/dist/testkit-core/src/types/index.js.map +0 -1
  210. package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +0 -28
  211. package/templates/dist/testkit-core/src/utils/queryHelpers.js +0 -81
  212. package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +0 -1
  213. package/templates/dist/writer-core/src/index.d.ts +0 -34
  214. package/templates/dist/writer-core/src/index.js +0 -115
  215. package/templates/dist/writer-core/src/index.js.map +0 -1
  216. package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +0 -20
  217. package/templates/dist/ztd-cli/templates/src/db/sql-client.js +0 -3
  218. package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +0 -1
  219. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +0 -36
  220. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +0 -85
  221. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +0 -1
  222. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +0 -20
  223. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +0 -33
  224. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +0 -1
  225. package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +0 -10
  226. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +0 -29
  227. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +0 -1
  228. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +0 -66
  229. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +0 -552
  230. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +0 -1
  231. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +0 -1
  232. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +0 -82
  233. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +0 -1
  234. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +0 -1
  235. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +0 -29
  236. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +0 -1
  237. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +0 -7
  238. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +0 -10
  239. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +0 -1
  240. package/templates/src/repositories/user-accounts.ts +0 -179
  241. package/templates/tests/user-profiles.test.ts +0 -161
  242. package/templates/tests/writer-constraints.test.ts +0 -32
package/package.json CHANGED
@@ -1,11 +1,19 @@
1
1
  {
2
2
  "name": "@rawsql-ts/ztd-cli",
3
- "version": "0.16.0",
3
+ "version": "0.19.0",
4
4
  "description": "DB-agnostic scaffolding and DDL helpers for Zero Table Dependency projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
7
  "ztd": "dist/index.js"
8
8
  },
9
+ "scripts": {
10
+ "prepack": "node -e \"const fs=require('fs');const cp=require('child_process');const npm=process.platform==='win32'?'npm.cmd':'npm';if(!fs.existsSync('dist/index.js')){process.exit(cp.spawnSync(npm,['run','build'],{stdio:'inherit'}).status??1)}\"",
11
+ "build": "pnpm --filter rawsql-ts run build && pnpm --filter @rawsql-ts/sql-grep-core run build && pnpm --filter @rawsql-ts/test-evidence-core run build && pnpm --filter @rawsql-ts/test-evidence-renderer-md run build && pnpm --filter @rawsql-ts/testkit-core run build && tsc -p tsconfig.json",
12
+ "test": "pnpm --filter @rawsql-ts/adapter-node-pg run build && vitest run --config vitest.config.ts",
13
+ "lint": "eslint src --ext .ts",
14
+ "release": "npm run lint && npm run test && npm run build && node -e \"require('fs').mkdirSync('../../tmp', { recursive: true })\" && pnpm pack --out ../../tmp/rawsql-ts-ztd-cli.tgz && pnpm publish --access public",
15
+ "test:consumer-validation": "vitest run --config vitest.config.ts tests/testEvidence.unit.test.ts tests/testEvidence.cli.test.ts tests/sqlCatalog.evidence.test.ts tests/testCaseCatalog.evidence.test.ts"
16
+ },
9
17
  "keywords": [
10
18
  "rawsql-ts",
11
19
  "ztd",
@@ -15,6 +23,11 @@
15
23
  ],
16
24
  "author": "msugiura",
17
25
  "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/mk3008/rawsql-ts.git",
29
+ "directory": "packages/ztd-cli"
30
+ },
18
31
  "publishConfig": {
19
32
  "access": "public"
20
33
  },
@@ -22,21 +35,33 @@
22
35
  "node": ">=20"
23
36
  },
24
37
  "dependencies": {
25
- "@testcontainers/postgresql": "^10.28.0",
38
+ "@rawsql-ts/test-evidence-core": "workspace:*",
39
+ "@rawsql-ts/test-evidence-renderer-md": "workspace:*",
26
40
  "chokidar": "^5.0.0",
27
41
  "commander": "^12.0.0",
28
42
  "diff": "^8.0.3",
29
43
  "fast-glob": "^3.3.3",
30
- "pg": "^8.11.1",
31
- "testcontainers": "^10.28.0",
32
- "@rawsql-ts/adapter-node-pg": "^0.15.1",
33
- "@rawsql-ts/testkit-postgres": "^0.15.1",
34
- "@rawsql-ts/testkit-core": "^0.15.1",
35
- "rawsql-ts": "^0.16.0"
44
+ "rawsql-ts": "workspace:^",
45
+ "yaml": "^2.8.2",
46
+ "@rawsql-ts/sql-grep-core": "workspace:*"
47
+ },
48
+ "peerDependencies": {
49
+ "@rawsql-ts/adapter-node-pg": "workspace:^"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "@rawsql-ts/adapter-node-pg": {
53
+ "optional": true
54
+ }
36
55
  },
37
56
  "devDependencies": {
57
+ "@rawsql-ts/adapter-node-pg": "workspace:^",
58
+ "@rawsql-ts/testkit-core": "workspace:^",
59
+ "@rawsql-ts/testkit-postgres": "workspace:^",
60
+ "@testcontainers/postgresql": "^10.28.0",
38
61
  "@types/diff": "^5.0.1",
39
62
  "@types/node": "^22.13.10",
63
+ "pg": "^8.11.1",
64
+ "testcontainers": "^10.28.0",
40
65
  "typescript": "^5.8.2",
41
66
  "vitest": "^4.0.7"
42
67
  },
@@ -45,12 +70,5 @@
45
70
  "templates",
46
71
  "AGENTS.md",
47
72
  "README.md"
48
- ],
49
- "scripts": {
50
- "prebuild": "pnpm --filter @rawsql-ts/testkit-core build && pnpm --filter @rawsql-ts/testkit-postgres build && pnpm --filter @rawsql-ts/adapter-node-pg build",
51
- "build": "tsc -p tsconfig.json",
52
- "test": "vitest run",
53
- "lint": "eslint src --ext .ts",
54
- "release": "npm run lint && npm run test && npm run build && npm pack --dry-run && npm publish --access public"
55
- }
56
- }
73
+ ]
74
+ }
@@ -1,16 +1,16 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- indent_style = space
7
- indent_size = 2
8
- tab_width = 2
9
- insert_final_newline = true
10
- trim_trailing_whitespace = true
11
-
12
- [*.md]
13
- trim_trailing_whitespace = false
14
-
15
- [*.sql]
16
- indent_size = 2
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_style = space
7
+ indent_size = 2
8
+ tab_width = 2
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
14
+
15
+ [*.sql]
16
+ indent_size = 2
@@ -1,2 +1,2 @@
1
- tests/generated/**
2
-
1
+ tests/generated/**
2
+
@@ -1,24 +1,24 @@
1
- {
2
- "semi": true,
3
- "singleQuote": true,
4
- "trailingComma": "all",
5
- "tabWidth": 2,
6
- "printWidth": 100,
7
- "bracketSpacing": true,
8
- "arrowParens": "always",
9
- "plugins": ["prettier-plugin-sql"],
10
- "overrides": [
11
- {
12
- "files": "*.sql",
13
- "options": {
14
- "parser": "sql"
15
- }
16
- },
17
- {
18
- "files": "*.md",
19
- "options": {
20
- "parser": "markdown"
21
- }
22
- }
23
- ]
24
- }
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "trailingComma": "all",
5
+ "tabWidth": 2,
6
+ "printWidth": 100,
7
+ "bracketSpacing": true,
8
+ "arrowParens": "always",
9
+ "plugins": ["prettier-plugin-sql"],
10
+ "overrides": [
11
+ {
12
+ "files": "*.sql",
13
+ "options": {
14
+ "parser": "sql"
15
+ }
16
+ },
17
+ {
18
+ "files": "*.md",
19
+ "options": {
20
+ "parser": "markdown"
21
+ }
22
+ }
23
+ ]
24
+ }
@@ -1,325 +1,30 @@
1
- # Appendix: Development Workflow Using Zero Table Dependency (ZTD)
2
-
3
- This application uses **Zero Table Dependency (ZTD)** as an internal development workflow for writing, testing, and maintaining SQL logic.
4
- ZTD is not part of the application's runtime behavior; rather, it provides a framework for:
5
-
6
- - Maintaining consistent SQL across the project
7
- - Keeping schema metadata and generated artifacts synchronized
8
- - Ensuring deterministic SQL unit tests
9
- - Enabling structured collaboration between humans and AI
10
-
11
- This section documents how ZTD is used inside this repository as a development methodology.
12
-
13
- ---
14
-
15
- ## Defaults (important)
16
-
17
- - This project adopts **ZTD as the default development and testing methodology**.
18
- - ZTD is assumed unless explicitly stated otherwise.
19
- - Detailed rules about test execution modes are defined in `templates/tests/AGENTS.md`.
20
-
21
- ---
22
-
23
- ## Generated files (important)
24
-
25
- - `tests/generated/` is auto-generated and must never be committed.
26
- - After cloning the repository (or in a clean environment), run `npx ztd ztd-config`.
27
- - If TypeScript reports missing modules or type errors because `tests/generated/` is missing, run `npx ztd ztd-config`.
28
-
29
- ---
30
-
31
- ## TypeScript validation (required)
32
-
33
- After any code change, TypeScript type checking **must** be performed and must pass.
34
-
35
- - Run the project-appropriate typecheck command (e.g. `pnpm typecheck`).
36
- - If generated files are involved, run generators first, then re-run typecheck.
37
- - If typecheck fails, fix errors by root cause, not only the first reported error.
38
- - A change is not considered complete unless typecheck is green.
39
- CI pipelines SHOULD run `npx ztd ztd-config` before typecheck and tests (recommended).
40
-
41
- Rationale:
42
- In ZTD-based development, many schema or SQL inconsistencies surface first as TypeScript errors via generated row maps and DTOs.
43
- Type checking is a primary correctness signal, not an optional step.
44
-
45
- ---
46
-
47
- ## ZTD Implementation Guide (src/)
48
-
49
- The `src/` directory should contain pure TypeScript logic that operates on the row interfaces generated by `tests/generated/ztd-row-map.generated.ts`. Tests should import the row map, repositories should import DTOs, and fixtures must stay under `tests/`. Keep production code decoupled from the generated row map to preserve the distinction between implementation and test scaffolding.
50
-
51
- ### Runtime dependency boundaries (important)
52
-
53
- - Code under `src/` MUST NOT import anything from `tests/` or `tests/generated/`.
54
- - Generated row-maps are test-only artifacts and MUST NEVER influence runtime behavior.
55
- - Mapper and writer runtime utilities MUST NOT depend on ZTD internals or generated helpers.
56
- - All schema compatibility checks (column existence, enum coverage, forbidden columns, etc.) MUST be enforced in tests, never in production code.
57
-
58
- ### Repository Classes: What to Care About
59
-
60
- #### Scope and Responsibility
61
- - Repository classes are responsible for executing SQL and returning query results.
62
- - Avoid embedding business logic, thresholds, or data reshaping inside repositories.
63
- - Treat repositories as thin adapters over SQL.
64
-
65
- #### Mandatory testing rule (important)
66
-
67
- Whenever a repository class is created or modified, corresponding tests **must** be created or updated.
68
-
69
- Rules:
70
- - Every public repository method must be covered by tests.
71
- - Tests must call repository methods, not raw SQL files or SQL strings.
72
- - ZTD fixtures are the only allowed source of database state in tests.
73
- - A repository change without tests is considered incomplete.
74
- - Every repository or test modification must be followed by `pnpm --filter <package> test` (replace `<package>` with the template package name).
75
- - `tests/support/global-setup.ts` already uses `@testcontainers/postgresql`, so the suite stands up a Postgres container automatically whenever `DATABASE_URL` is absent.
76
- - If the suite fails, fix the root cause and rerun the command until it passes before considering the repository change complete.
77
-
78
- Rationale:
79
- ZTD derives much of its value from deterministic, repository-level tests.
80
- Without tests, schema drift and SQL inconsistencies cannot be detected.
81
-
82
- #### SQL Management
83
- - Keep every SELECT statement in a dedicated `.sql` file under `src/sql/` (match the repository name, e.g. `src/sql/user-accounts.sql`).
84
- - Load the SQL via `fs.readFileSync` or similar helpers so the repository never embeds long SQL strings inline.
85
- - Inline SQL is forbidden unless a human explicitly requests an override; follow the `.sql` file convention by default.
86
- - Repository classes should reference those SQL files; the file name should match the repository class or the query method to keep the code/spec alignment clear.
87
-
88
- #### Specifications and Documentation
89
- - If a markdown file with the same base name as the repository or SQL exists, read it before implementation.
90
- - Such files may contain repository-local specifications (e.g. decision tables, thresholds, request/response notes).
91
- - Naming should be aligned (e.g. `FooRepository.ts`, `foo.sql`, `foo.md`).
92
-
93
- #### Request and Response Contracts
94
- - Be explicit about request parameters (types, nullability, constraints).
95
- - Be explicit about response shape (columns, ordering, cardinality).
96
- - Prefer documenting contracts in the repository-local markdown file rather than code comments when they are non-trivial.
97
-
98
- ### SqlClient lifecycle policy (important)
99
-
100
- - When using `src/db/sql-client.ts`, prefer a shared `SqlClient` per worker process (singleton).
101
- - Avoid creating a new database connection for every query or test case.
102
- - Do not share a live connection across parallel workers; each worker should own its own shared client or pool.
103
- - If you need strict isolation, create a dedicated client for that scope and close it explicitly.
104
-
105
- ### Repository SQL and DTO policy (important)
106
-
107
- - Repository SQL must return application-facing DTO shapes.
108
- - SQL SELECT statements should alias columns to camelCase and match the repository return types.
109
- - Do not introduce intermediate `*Row` types when SQL already returns DTO-compatible shapes.
110
- - Define separate Row types only when SQL intentionally returns database-shaped (snake_case) rows, and always convert them explicitly.
111
-
112
- ---
113
-
114
- ### Mapper + writer guardrails (template-specific)
115
-
116
- - In this project, `src/repositories/user-accounts.ts` is the authoritative mapper for the columns defined by the DDL; it MUST enumerate those columns explicitly so downstream logic never infers metadata at runtime.
117
- - Writer helpers in the same module MUST emit SQL for `public.user_account` only and MUST remain limited to the explicit insert/update/delete helpers shown there; DO NOT introduce ad-hoc schema discovery.
118
- - `tests/writer-constraints.test.ts` MUST consume `userAccountWriterColumnSets` together with `tests/generated/ztd-row-map.generated.ts` so CUD callers only reference columns that exist on `public.user_account`.
119
- - When the schema of `public.user_account` changes, update `src/repositories/user-accounts.ts` column metadata, keep `tests/writer-constraints.test.ts` expectations aligned, and re-run `npx ztd ztd-config` so the generated row map stays synchronized with the tests.
120
-
121
- #### Writer safety contract (important)
122
-
123
- - Allowed:
124
- - Insert, update, and delete helpers tied to a single table with explicitly enumerated column sets.
125
- - Explicit `RETURNING` clauses that list permitted columns.
126
- - Patch-style updates that only touch writable columns listed in `userAccountWriterColumnSets`.
127
- - Forbidden:
128
- - Generic writers that accept arbitrary table or column names.
129
- - Runtime schema or enum discovery (e.g., querying `information_schema`) to drive writer column lists.
130
- - Writers that embed joins or subqueries beyond simple `RETURNING` clauses.
131
- If these constraints are insufficient, write the SQL manually.
132
-
133
- #### Mapper strictness policy
134
-
135
- - Mapping is strict by default: SQL must return exactly the DTO-shaped results that `src/repositories/user-accounts.ts` exposes; missing or mismatched columns are bugs that tests MUST surface.
136
- - Non-strict behaviors (coercions, key transforms, etc.) MUST be enabled explicitly via named presets or configuration; relying on implicit or silent defaults is prohibited.
137
-
138
- ### Sequence / identity column policy (important)
139
-
140
- - Sequence / identity columns (auto-generated IDs) are infrastructure concerns.
141
- - Do not explicitly assign values to sequence / identity columns in `INSERT` statements unless explicitly instructed.
142
- - Repository method inputs should omit sequence / identity columns by default.
143
- - Only treat an ID as input data when it represents a business rule (e.g. natural keys, externally assigned IDs).
144
-
145
- ### No test-driven fallbacks in production code (important)
146
-
147
- - Do not add fallbacks in `src/` that exist only to accommodate ZTD/testkit/rewriter limitations.
148
- - If a query fails to be rewritten into ZTD form, do not change runtime behavior to compensate.
149
- - Report tooling issues with minimal reproduction and expected behavior.
150
-
151
- Rationale:
152
- Production code must not diverge from intended SQL semantics due to tooling constraints.
153
-
154
- ---
155
-
156
- ## ZTD Test Guide (tests/)
157
-
158
- Testing under ZTD follows dedicated, directory-scoped rules.
159
-
160
- - Test design, execution mode selection, and constraints are defined in:
161
- - `templates/tests/AGENTS.md`
162
- - Tests validate repository behavior and returned DTOs.
163
- - Raw SQL files or SQL strings must not be tested directly.
164
-
165
- ---
166
-
167
- # ZTD Directory Layout
168
-
169
- ```
170
- /ztd
171
- /ddl
172
- *.sql <- physical schema definitions
173
-
174
- README.md <- documentation for the layout
175
- AGENTS.md <- combined guidance for DDL
176
-
177
- /src <- application & repository logic
178
- /tests <- ZTD tests, fixtures, row-maps
179
- ```
180
-
181
- Only `ztd/ddl` is part of the template contract. Do not create or assume any other `ztd` subdirectories unless the project explicitly adds them.
182
-
183
- The file `tests/generated/ztd-layout.generated.ts` ensures ZTD CLI always points to the correct directories.
184
-
185
- ---
186
-
187
- # Protected directories and edit ownership (important)
188
-
189
- - DDL editing is human-led: `ztd/ddl/`
190
- - `ztd/ddl` is the sole human-owned directory inside `/ztd`; other directories must not be assumed or created without explicit instructions.
191
- - Application code is shared ownership: `src/`
192
- - Tests are shared ownership: `tests/`
193
- - Detailed test constraints live in `templates/tests/AGENTS.md`.
194
-
195
- Additionally:
196
- - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction.
197
- - When changes are required in human-led directories, prefer proposing a patch and explaining the impact before applying it.
198
-
199
- ---
200
-
201
- # Principles of ZTD in This Repository
202
-
203
- ### 1. Humans own the definitions
204
- - Physical schema (DDL)
205
- - Repository interfaces
206
-
207
- ### 2. AI assists with implementation
208
- - Generating repository SQL
209
- - Updating fixtures
210
- - Producing intermediate TypeScript structures
211
- - Ensuring SQL adheres to DDL
212
-
213
- ### 3. ZTD enforces consistency
214
- ZTD tests verify that:
215
- - SQL logic matches DDL shapes
216
-
217
- If anything diverges, ZTD failures surface immediately and deterministically.
218
-
219
- ---
220
-
221
- # Development Workflows
222
-
223
- Different types of changes start from different entry points. Use the workflow appropriate for your situation.
224
-
225
- ---
226
-
227
- # Workflow A - Starting From DDL Changes
228
- Modifying tables, columns, constraints, indexes.
229
-
230
- 1. Edit DDL files in `ztd/ddl/`.
231
- 2. Run `npx ztd ztd-config`.
232
- 3. Update repository SQL to match the new schema.
233
- 4. Update fixtures if result shapes changed.
234
- 5. Run tests.
235
-
236
- Flow: DDL to Repository SQL to Fixtures and Tests to Application
237
-
238
- ---
239
-
240
- # Workflow B - Starting From Repository Interface Changes
241
- Changing method signatures, adding new repository methods, etc.
242
-
243
- 1. Modify the repository interface or implementation in `/src`.
244
- 2. Use AI assistance to generate or update the SQL implementation.
245
- 3. If the generated SQL conflicts with DDL or other human-maintained references, update the authoritative source first.
246
- 4. Run ZTD tests.
247
- 5. Regenerate config if SQL output shape changed.
248
-
249
- Flow: Interface to SQL to Tests
250
-
251
- ---
252
-
253
- # Workflow C - Starting From Repository SQL Logic Changes
254
- Bug fixes, refactoring, rewriting queries.
255
-
256
- 1. Edit SQL inside the repository.
257
- 2. Run ZTD tests.
258
- 3. If intended behavior changes, coordinate any necessary DDL updates before adjusting dependent code.
259
- 4. Update fixtures as needed.
260
- 5. Regenerate config if result shape changed.
261
-
262
- Flow: SQL to Tests
263
-
264
- ---
265
-
266
- # Combined Real-World Examples
267
-
268
- - Adding a new contract state: DDL to SQL to config to tests
269
- - Adding a new table: DDL to SQL to fixtures/tests
270
- - Fixing business logic: SQL to tests
271
-
272
- ZTD ensures the development always converges into a consistent, validated workflow.
273
-
274
- ---
275
-
276
- # Human Responsibilities
277
-
278
- Humans maintain:
279
-
280
- - Schema definitions (`ztd/ddl`)
281
- - Repository interfaces and architectural decisions
282
- - Acceptance and review of AI-generated patches
283
-
284
- Humans decide what is correct.
285
-
286
- ---
287
-
288
- # AI Responsibilities
289
-
290
- AI must:
291
-
292
- - Use DDL as the physical structure constraint and never assume any additional `ztd` directories exist unless explicitly added.
293
- - Generate SQL consistent with DDL.
294
- - Update fixtures when needed.
295
- - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction.
296
-
297
- AI decides how to implement, but not what is correct.
298
-
299
- ---
300
-
301
- # ZTD CLI Responsibilities
302
-
303
- ZTD CLI:
304
-
305
- - Parses DDL to compute schema shapes
306
- - Rewrites SQL via CTE shadowing for testing
307
- - Generates `ztd-row-map.generated.ts`
308
- - Enables deterministic, parallel SQL unit tests
309
-
310
- ZTD is the verification engine that validates correctness beyond static typing.
311
-
312
- ---
313
-
314
- # Summary
315
-
316
- This appendix documents how ZTD is used strictly as an internal implementation and maintenance guide.
317
- It does not affect the runtime behavior of the application.
318
- Its purpose is ensuring:
319
-
320
- - Schema integrity
321
- - SQL correctness
322
- - Domain consistency
323
- - Reliable AI-assisted development
324
-
325
- With ZTD, humans define the meaning, AI writes the implementation, and tests guarantee correctness.
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates`.
3
+ - Defines repository-wide guardrails for generated project templates.
4
+ - Provides parent rules for runtime (`src`), tests (`tests`), and metadata (`ztd`) without forcing one application style on every subtree.
5
+
6
+ # Policy
7
+ ## REQUIRED
8
+ - The nearest nested `AGENTS.md` MUST be treated as highest-priority policy for edited files.
9
+ - Unknown facts during template work MUST be reported as `Not observed` with the next check.
10
+ - Generated artifacts MUST remain unedited unless explicit instruction exists.
11
+ - Preserve layer boundaries: transport, application, domain, and infrastructure concerns MUST remain explicit when those directories exist.
12
+ - Human-owned contract directories (`ztd/ddl`, `src/catalog/specs`, `src/sql`) MUST NOT be semantically changed without explicit instruction.
13
+ - Template output MUST include runnable test configuration at initialization.
14
+
15
+ ## ALLOWED
16
+ - AI-assisted implementation MAY occur in infrastructure adapters, catalog runtime, and tests excluding `tests/generated`.
17
+
18
+ ## PROHIBITED
19
+ - Manual edits under `tests/generated`.
20
+ - Treating ZTD-specific workflow rules as repository-global rules.
21
+
22
+ # Mandatory Workflow
23
+ - Template changes MUST preserve an executable `pnpm test` path for initialized projects.
24
+
25
+ # Hygiene
26
+ - Keep directory-local deltas in child `AGENTS.md`; avoid restating parent rules in child files.
27
+
28
+ # References
29
+ - Rationale: [DESIGN.md](./DESIGN.md)
30
+ - Operational notes: [DEV_NOTES.md](./DEV_NOTES.md)
@@ -0,0 +1,11 @@
1
+ # Agent Context
2
+
3
+ - Prefer `ztd --output json` in automation.
4
+ - Treat this file as a high-level index only; rely on subtree `AGENTS.md` files for path-specific rules.
5
+ - Prefer `ztd model-gen --probe-mode ztd` during the inner loop when local DDL is the source of truth.
6
+ - Use `--dry-run` before file-writing commands when you need a safe validation pass.
7
+ - Keep `ztd/ddl` as the human-owned schema source of truth.
8
+ - Regenerate `tests/generated/*` with `ztd ztd-config`; do not edit generated files manually.
9
+ - `ztd-cli` implicitly uses only `ZTD_TEST_DATABASE_URL`; it does not read `DATABASE_URL` automatically.
10
+ - Treat `ddl pull` and `ddl diff` as explicit target inspection commands. Pass `--url` or a complete `--db-*` flag set when using them.
11
+ - Keep transport, application, and domain work free from direct ZTD assumptions unless you are editing persistence infrastructure.
@@ -0,0 +1,11 @@
1
+ # Agent Context
2
+
3
+ - Treat this file as a top-level index for the layered WebAPI layout.
4
+ - Keep `src/domain`, `src/application`, and `src/presentation/http` free from direct ZTD assumptions.
5
+ - Apply ZTD-specific workflow rules only inside `src/infrastructure/persistence`, `src/sql`, `src/catalog`, and `ztd`.
6
+ - Prefer `ztd model-gen --probe-mode ztd` during the inner loop when local DDL is the source of truth.
7
+ - Use `--dry-run` before file-writing commands when you need a safe validation pass.
8
+ - Keep `ztd/ddl` as the human-owned schema source of truth.
9
+ - Regenerate `tests/generated/*` with `ztd ztd-config`; do not edit generated files manually.
10
+ - `ztd-cli` implicitly uses only `ZTD_TEST_DATABASE_URL`; runtime settings such as `DATABASE_URL` remain outside its ownership.
11
+ - Treat `ddl pull` and `ddl diff` as explicit target inspection commands. Pass `--url` or a complete `--db-*` flag set when using them.
@@ -0,0 +1,17 @@
1
+ # ZTD Template Design Notes
2
+
3
+ ## Role and Boundaries
4
+ - Defines template-level design intent for ownership and runtime/test split.
5
+ - Clarifies where human-owned contracts stop and implementation wiring begins.
6
+
7
+ ## Non-Goals
8
+ - Replacing directory-local AGENTS contracts.
9
+ - Embedding operational command playbooks.
10
+
11
+ ## Ownership Model
12
+ - Human-owned directories preserve domain contracts and SQL intent.
13
+ - AI-assisted directories implement runtime wiring and verification logic.
14
+
15
+ ## Runtime Split
16
+ - `src/` contains runtime assets.
17
+ - `tests/` and `ztd/` contain verification and generation inputs.
@@ -0,0 +1,14 @@
1
+ # ZTD Template Dev Notes
2
+
3
+ ## Commands
4
+ - `pnpm test` in initialized template projects.
5
+
6
+ ## Troubleshooting
7
+ - Template initialization must include runnable test configuration and at least one executable test.
8
+
9
+ ## Navigation
10
+ - `src/catalog/AGENTS.md`
11
+ - `src/repositories/AGENTS.md`
12
+ - `src/sql/AGENTS.md`
13
+ - `tests/AGENTS.md`
14
+ - `ztd/ddl/AGENTS.md`
@@ -0,0 +1,49 @@
1
+ # Prompt Dogfooding
2
+
3
+ Use this checklist when you want to confirm that generic WebAPI requests stay focused on transport, application, and domain layers unless persistence work is explicitly requested.
4
+
5
+ ## Prompt 1
6
+
7
+ Prompt:
8
+
9
+ ```text
10
+ Convert to WebAPI
11
+ ```
12
+
13
+ Expected focus:
14
+ - `src/presentation/http`
15
+ - `src/application`
16
+ - `src/domain`
17
+
18
+ Expected non-focus:
19
+ - `src/sql`
20
+ - `src/catalog`
21
+ - `ztd/ddl`
22
+ - `src/infrastructure/persistence`
23
+ - `src/infrastructure/telemetry`
24
+
25
+ ## Prompt 2
26
+
27
+ Prompt:
28
+
29
+ ```text
30
+ Add SQL and implement repository
31
+ ```
32
+
33
+ Expected focus:
34
+ - `src/infrastructure/persistence/repositories`
35
+ - `src/sql`
36
+ - `src/catalog/specs`
37
+ - `src/catalog/runtime`
38
+ - `ztd/ddl`
39
+
40
+ Expected non-focus:
41
+ - unrelated HTTP transport rewrites
42
+ - domain-wide refactors that are not required by the repository change
43
+
44
+ ## Record Template
45
+
46
+ | Prompt | Primary files mentioned | Unwanted ZTD leakage? | Notes |
47
+ | --- | --- | --- | --- |
48
+ | `Convert to WebAPI` | | | |
49
+ | `Add SQL and implement repository` | | | |