@rawsql-ts/ztd-cli 0.17.0 → 0.20.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 (240) hide show
  1. package/README.md +532 -366
  2. package/package.json +26 -15
  3. package/templates/.editorconfig +16 -16
  4. package/templates/.prettierignore +2 -2
  5. package/templates/.prettierrc +24 -24
  6. package/templates/AGENTS.md +30 -52
  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 -14
  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 -26
  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 -37
  19. package/templates/src/catalog/runtime/AGENTS.md +28 -75
  20. package/templates/src/catalog/runtime/_coercions.ts +30 -1
  21. package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -21
  22. package/templates/src/catalog/specs/AGENTS.md +41 -48
  23. package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -21
  24. package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -20
  25. package/templates/src/db/sql-client-adapters.ts +32 -0
  26. package/templates/src/db/sql-client.ts +24 -24
  27. package/templates/src/domain/AGENTS.md +15 -0
  28. package/templates/src/domain/README.md +6 -0
  29. package/templates/src/infrastructure/AGENTS.md +14 -0
  30. package/templates/src/infrastructure/README.md +6 -0
  31. package/templates/src/infrastructure/db/AGENTS.md +14 -0
  32. package/templates/src/infrastructure/db/sql-client-adapters.ts +34 -0
  33. package/templates/{dist/ztd-cli/templates/src → src/infrastructure}/db/sql-client.ts +3 -3
  34. package/templates/src/infrastructure/persistence/AGENTS.md +18 -0
  35. package/templates/src/infrastructure/persistence/README.md +8 -0
  36. package/templates/src/infrastructure/persistence/repositories/AGENTS.md +17 -0
  37. package/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md +20 -0
  38. package/templates/src/infrastructure/persistence/repositories/tables/README.md +5 -0
  39. package/templates/src/infrastructure/persistence/repositories/views/AGENTS.md +16 -0
  40. package/templates/src/infrastructure/persistence/repositories/views/README.md +5 -0
  41. package/templates/src/infrastructure/telemetry/AGENTS.md +14 -0
  42. package/templates/src/infrastructure/telemetry/consoleRepositoryTelemetry.ts +66 -0
  43. package/templates/src/infrastructure/telemetry/repositoryTelemetry.ts +26 -0
  44. package/templates/src/infrastructure/telemetry/types.ts +48 -0
  45. package/templates/src/jobs/AGENTS.md +25 -26
  46. package/templates/src/jobs/README.md +2 -2
  47. package/templates/src/presentation/AGENTS.md +15 -0
  48. package/templates/src/presentation/http/AGENTS.md +15 -0
  49. package/templates/src/presentation/http/README.md +6 -0
  50. package/templates/src/repositories/AGENTS.md +30 -118
  51. package/templates/src/repositories/tables/AGENTS.md +29 -94
  52. package/templates/src/repositories/tables/README.md +5 -3
  53. package/templates/src/repositories/views/AGENTS.md +25 -25
  54. package/templates/src/repositories/views/README.md +5 -3
  55. package/templates/src/sql/AGENTS.md +30 -77
  56. package/templates/src/sql/README.md +5 -5
  57. package/templates/tests/AGENTS.md +29 -62
  58. package/templates/tests/generated/AGENTS.md +23 -16
  59. package/templates/tests/smoke.test.ts +25 -5
  60. package/templates/tests/smoke.validation.test.ts +34 -34
  61. package/templates/tests/support/AGENTS.md +24 -26
  62. package/templates/tests/support/global-setup.ts +15 -15
  63. package/templates/tests/support/testkit-client.ts +14 -14
  64. package/templates/tests/support/testkit-client.webapi.ts +14 -0
  65. package/templates/tests/ztd-layout.generated.ts +6 -6
  66. package/templates/tsconfig.json +15 -15
  67. package/templates/vitest.config.ts +13 -13
  68. package/templates/ztd/AGENTS.md +23 -18
  69. package/templates/ztd/README.md +5 -5
  70. package/templates/ztd/ddl/AGENTS.md +26 -34
  71. package/templates/ztd/ddl/demo.sql +74 -74
  72. package/LICENSE +0 -21
  73. package/dist/commands/ddl.d.ts +0 -7
  74. package/dist/commands/ddl.js +0 -118
  75. package/dist/commands/ddl.js.map +0 -1
  76. package/dist/commands/diff.d.ts +0 -10
  77. package/dist/commands/diff.js +0 -38
  78. package/dist/commands/diff.js.map +0 -1
  79. package/dist/commands/genEntities.d.ts +0 -6
  80. package/dist/commands/genEntities.js +0 -50
  81. package/dist/commands/genEntities.js.map +0 -1
  82. package/dist/commands/init.d.ts +0 -79
  83. package/dist/commands/init.js +0 -1083
  84. package/dist/commands/init.js.map +0 -1
  85. package/dist/commands/lint.d.ts +0 -59
  86. package/dist/commands/lint.js +0 -358
  87. package/dist/commands/lint.js.map +0 -1
  88. package/dist/commands/options.d.ts +0 -9
  89. package/dist/commands/options.js +0 -48
  90. package/dist/commands/options.js.map +0 -1
  91. package/dist/commands/pull.d.ts +0 -10
  92. package/dist/commands/pull.js +0 -105
  93. package/dist/commands/pull.js.map +0 -1
  94. package/dist/commands/ztdConfig.d.ts +0 -23
  95. package/dist/commands/ztdConfig.js +0 -216
  96. package/dist/commands/ztdConfig.js.map +0 -1
  97. package/dist/commands/ztdConfigCommand.d.ts +0 -5
  98. package/dist/commands/ztdConfigCommand.js +0 -157
  99. package/dist/commands/ztdConfigCommand.js.map +0 -1
  100. package/dist/index.d.ts +0 -2
  101. package/dist/index.js +0 -22
  102. package/dist/index.js.map +0 -1
  103. package/dist/utils/agents.d.ts +0 -1
  104. package/dist/utils/agents.js +0 -48
  105. package/dist/utils/agents.js.map +0 -1
  106. package/dist/utils/collectSqlFiles.d.ts +0 -9
  107. package/dist/utils/collectSqlFiles.js +0 -58
  108. package/dist/utils/collectSqlFiles.js.map +0 -1
  109. package/dist/utils/connectionSummary.d.ts +0 -3
  110. package/dist/utils/connectionSummary.js +0 -29
  111. package/dist/utils/connectionSummary.js.map +0 -1
  112. package/dist/utils/dbConnection.d.ts +0 -29
  113. package/dist/utils/dbConnection.js +0 -210
  114. package/dist/utils/dbConnection.js.map +0 -1
  115. package/dist/utils/fs.d.ts +0 -1
  116. package/dist/utils/fs.js +0 -12
  117. package/dist/utils/fs.js.map +0 -1
  118. package/dist/utils/normalizePulledSchema.d.ts +0 -12
  119. package/dist/utils/normalizePulledSchema.js +0 -213
  120. package/dist/utils/normalizePulledSchema.js.map +0 -1
  121. package/dist/utils/optionalDependencies.d.ts +0 -35
  122. package/dist/utils/optionalDependencies.js +0 -96
  123. package/dist/utils/optionalDependencies.js.map +0 -1
  124. package/dist/utils/pgDump.d.ts +0 -11
  125. package/dist/utils/pgDump.js +0 -55
  126. package/dist/utils/pgDump.js.map +0 -1
  127. package/dist/utils/sqlLintHelpers.d.ts +0 -18
  128. package/dist/utils/sqlLintHelpers.js +0 -270
  129. package/dist/utils/sqlLintHelpers.js.map +0 -1
  130. package/dist/utils/typeMapper.d.ts +0 -4
  131. package/dist/utils/typeMapper.js +0 -76
  132. package/dist/utils/typeMapper.js.map +0 -1
  133. package/dist/utils/ztdProjectConfig.d.ts +0 -40
  134. package/dist/utils/ztdProjectConfig.js +0 -167
  135. package/dist/utils/ztdProjectConfig.js.map +0 -1
  136. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +0 -38
  137. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +0 -117
  138. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +0 -1
  139. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +0 -4
  140. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +0 -71
  141. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +0 -1
  142. package/templates/dist/drivers/pg-testkit/src/index.d.ts +0 -5
  143. package/templates/dist/drivers/pg-testkit/src/index.js +0 -11
  144. package/templates/dist/drivers/pg-testkit/src/index.js.map +0 -1
  145. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +0 -3
  146. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +0 -79
  147. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +0 -1
  148. package/templates/dist/drivers/pg-testkit/src/types.d.ts +0 -69
  149. package/templates/dist/drivers/pg-testkit/src/types.js +0 -3
  150. package/templates/dist/drivers/pg-testkit/src/types.js.map +0 -1
  151. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +0 -15
  152. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +0 -34
  153. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +0 -1
  154. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +0 -12
  155. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +0 -53
  156. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +0 -1
  157. package/templates/dist/mapper-core/src/index.d.ts +0 -160
  158. package/templates/dist/mapper-core/src/index.js +0 -637
  159. package/templates/dist/mapper-core/src/index.js.map +0 -1
  160. package/templates/dist/testkit-core/src/errors/index.d.ts +0 -49
  161. package/templates/dist/testkit-core/src/errors/index.js +0 -111
  162. package/templates/dist/testkit-core/src/errors/index.js.map +0 -1
  163. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +0 -5
  164. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +0 -29
  165. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +0 -1
  166. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +0 -37
  167. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +0 -182
  168. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +0 -1
  169. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +0 -20
  170. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +0 -121
  171. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +0 -1
  172. package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +0 -51
  173. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +0 -199
  174. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +0 -1
  175. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +0 -10
  176. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +0 -28
  177. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +0 -1
  178. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +0 -18
  179. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +0 -80
  180. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +0 -1
  181. package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +0 -59
  182. package/templates/dist/testkit-core/src/fixtures/ddlLint.js +0 -489
  183. package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +0 -1
  184. package/templates/dist/testkit-core/src/fixtures/naming.d.ts +0 -1
  185. package/templates/dist/testkit-core/src/fixtures/naming.js +0 -6
  186. package/templates/dist/testkit-core/src/fixtures/naming.js.map +0 -1
  187. package/templates/dist/testkit-core/src/index.d.ts +0 -17
  188. package/templates/dist/testkit-core/src/index.js +0 -47
  189. package/templates/dist/testkit-core/src/index.js.map +0 -1
  190. package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +0 -8
  191. package/templates/dist/testkit-core/src/logger/NoopLogger.js +0 -16
  192. package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +0 -1
  193. package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +0 -57
  194. package/templates/dist/testkit-core/src/provider/TestkitProvider.js +0 -149
  195. package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +0 -1
  196. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +0 -43
  197. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +0 -473
  198. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +0 -1
  199. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +0 -9
  200. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +0 -38
  201. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +0 -1
  202. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +0 -42
  203. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +0 -298
  204. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +0 -1
  205. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +0 -12
  206. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +0 -63
  207. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +0 -1
  208. package/templates/dist/testkit-core/src/types/index.d.ts +0 -69
  209. package/templates/dist/testkit-core/src/types/index.js +0 -3
  210. package/templates/dist/testkit-core/src/types/index.js.map +0 -1
  211. package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +0 -28
  212. package/templates/dist/testkit-core/src/utils/queryHelpers.js +0 -81
  213. package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +0 -1
  214. package/templates/dist/writer-core/src/index.d.ts +0 -34
  215. package/templates/dist/writer-core/src/index.js +0 -115
  216. package/templates/dist/writer-core/src/index.js.map +0 -1
  217. package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +0 -20
  218. package/templates/dist/ztd-cli/templates/src/db/sql-client.js +0 -3
  219. package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +0 -1
  220. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +0 -36
  221. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +0 -85
  222. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +0 -1
  223. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +0 -20
  224. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +0 -33
  225. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +0 -1
  226. package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +0 -10
  227. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +0 -29
  228. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +0 -1
  229. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +0 -66
  230. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +0 -552
  231. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +0 -1
  232. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +0 -1
  233. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +0 -82
  234. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +0 -1
  235. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +0 -1
  236. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +0 -29
  237. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +0 -1
  238. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +0 -7
  239. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +0 -10
  240. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +0 -1
@@ -1,94 +1,29 @@
1
- # src/repositories/tables AGENTS
2
-
3
- This directory contains simple CRUD-style repositories.
4
-
5
- ## Runtime classification
6
-
7
- - This is a runtime directory.
8
- - Code here executes SQL and returns application-facing results.
9
-
10
- ## Responsibilities
11
-
12
- - Execute SQL assets using defined contracts.
13
- - Perform explicit mapping from SQL rows to DTOs.
14
- - Enforce CUD semantics at the application boundary (including "0 rows" handling).
15
-
16
- ## Contract ownership (important)
17
-
18
- - Input parameter types and DTO shapes are defined in specs ("src/catalog/specs").
19
- - Repositories MUST NOT invent or modify contracts.
20
- - Repositories may adapt SQL results into DTOs, but must not redefine the contract.
21
-
22
- ## SQL usage rules (tables CRUD quality bar)
23
-
24
- - Repositories in this folder MUST treat SQL assets as human-maintained, idiomatic SQL.
25
- - Do not require SQL assets to implement driver-specific behaviors.
26
- - If a driver does not provide affected-row counts for UPDATE/DELETE, fail fast as unsupported.
27
-
28
- Examples:
29
- - Prefer a plain UPDATE statement in SQL.
30
- - Do not force SQL to return `affected_count` via CTE tricks.
31
-
32
- ## CUD behavior rules
33
-
34
- ### CREATE (INSERT)
35
-
36
- Default:
37
- - SQL MUST use `insert ... returning <primary_key>` when a generated key is needed.
38
- - Repository CREATE MUST return identifier only (scalar) per contract.
39
- - Repository CREATE MUST NOT perform a follow-up SELECT for DTO return shaping.
40
- - SQL MUST NOT return full rows or DTO-shaped payloads.
41
-
42
- Exception:
43
- - If a CREATE endpoint must return DTO, the spec MUST explicitly require it by human instruction.
44
- - Without that explicit contract, identifier-only return is mandatory.
45
-
46
- ### UPDATE
47
-
48
- Default:
49
- - SQL: plain UPDATE without RETURNING.
50
- - Repository: determine success by affected row count when available.
51
-
52
- Driver variability handling:
53
- - If affected row count is unavailable:
54
- - Treat UPDATE verification as unsupported for that driver/runtime.
55
- - Throw an explicit error.
56
- - Do not add fallback checks or workaround logic in repositories.
57
- - Do not push this variability down into SQL assets.
58
-
59
- 0-row rule (important):
60
- - Treat "0 rows updated" as a meaningful condition.
61
- - Default behavior is to surface it clearly (often an error), per spec.
62
-
63
- ### DELETE
64
-
65
- Default:
66
- - SQL: plain DELETE without RETURNING.
67
- - Repository: determine success by affected row count when available.
68
-
69
- Driver variability handling:
70
- - If affected row count is unavailable:
71
- - Treat DELETE verification as unsupported for that driver/runtime.
72
- - Throw an explicit error.
73
- - Do not add fallback checks or workaround logic in repositories.
74
-
75
- 0-row rule (important):
76
- - Treat "0 rows deleted" as a meaningful condition, per spec.
77
-
78
- ## Patch updates (important)
79
-
80
- - Avoid ambiguous patterns such as `coalesce(param, column)` by default.
81
- - Contracts should distinguish:
82
- - "not provided"
83
- - "explicitly set to null"
84
- - If patch semantics are needed, implement them explicitly via:
85
- - separate SQL variants, or
86
- - explicit contract types that preserve intent.
87
-
88
- ## Testing rule (required)
89
-
90
- - Every public repository method MUST be covered by tests.
91
- - Tests should verify:
92
- - correct mapping behavior
93
- - correct "0 rows" behavior for UPDATE/DELETE
94
- - correct error surfaces (do not silently succeed)
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/src/repositories/tables`.
3
+ - Defines table-oriented CRUD repository contract behavior.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - CREATE SQL MUST use identifier-focused `RETURNING` when generated keys are required.
8
+ - CREATE repository methods MUST return identifier-only results by default.
9
+ - UPDATE and DELETE MUST rely on affected-row counts where available.
10
+ - `rowCount === 0` conditions MUST surface explicitly according to contract behavior.
11
+ - Patch contracts MUST distinguish omitted fields from explicit null values.
12
+ - Public repository methods MUST be test-covered for mapping and CUD error behavior.
13
+
14
+ ## ALLOWED
15
+ - DTO-returning CREATE behavior MAY be implemented only when explicitly required by human-authored spec.
16
+
17
+ ## PROHIBITED
18
+ - UPDATE/DELETE `RETURNING`-based success emulation.
19
+ - Follow-up SELECT workarounds for CUD verification.
20
+ - Ambiguous patch patterns that hide omitted-vs-null intent.
21
+
22
+ # Mandatory Workflow
23
+ - Table repository changes MUST run tests for affected-row handling and explicit failure surfaces.
24
+
25
+ # Hygiene
26
+ - Keep SQL assets idiomatic and driver-neutral for table CRUD paths.
27
+
28
+ # References
29
+ - Parent repository policy: [../AGENTS.md](../AGENTS.md)
@@ -1,3 +1,5 @@
1
- # Table Repositories
2
-
3
- Write-focused repositories that execute CRUD SQL from `src/sql`.
1
+ # Table Repositories
2
+
3
+ Write-focused repositories that execute CRUD SQL from `src/sql`.
4
+
5
+ Accept an optional telemetry hook from `src/infrastructure/telemetry/repositoryTelemetry.ts` and default it through `resolveRepositoryTelemetry(...)` so applications can replace the sink without editing repository internals.
@@ -1,25 +1,25 @@
1
- # src/repositories/views AGENTS
2
-
3
- This folder is for complex read-only queries.
4
-
5
- ## Scope
6
-
7
- - Complex SELECT queries (joins, aggregations, window functions).
8
- - Read models that are not 1:1 with a single table.
9
-
10
- ## Allowed
11
-
12
- - Multi-table joins and aggregations.
13
- - Purpose-built DTOs for read models.
14
- - Validation at the boundary (catalog validator or repository-level validator).
15
-
16
- ## Forbidden
17
-
18
- - INSERT/UPDATE/DELETE in this folder by default.
19
- - Hidden write side-effects.
20
-
21
- ## Guidance
22
-
23
- - Keep query intent clear in naming.
24
- - Document cardinality assumptions (one, many, optional).
25
- - Prefer stable ordering if tests rely on order.
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/src/repositories/views`.
3
+ - Defines read-model repository behavior for complex SELECT-only queries.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Queries in this subtree MUST remain read-only.
8
+ - Read-model DTO validation MUST run at repository/catalog boundaries.
9
+ - Query naming MUST make cardinality assumptions explicit.
10
+
11
+ ## ALLOWED
12
+ - Multi-table joins, aggregations, and purpose-built read DTOs MAY be used.
13
+
14
+ ## PROHIBITED
15
+ - INSERT/UPDATE/DELETE behavior in this subtree.
16
+ - Hidden write side effects in read-model query paths.
17
+
18
+ # Mandatory Workflow
19
+ - View repository changes MUST run tests for DTO validation and result ordering assumptions.
20
+
21
+ # Hygiene
22
+ - Preserve explicit ordering whenever test behavior depends on row order.
23
+
24
+ # References
25
+ - Parent repository policy: [../AGENTS.md](../AGENTS.md)
@@ -1,3 +1,5 @@
1
- # View Repositories
2
-
3
- Read-only repositories backed by SELECT SQL in `src/sql`.
1
+ # View Repositories
2
+
3
+ Read-only repositories backed by SELECT SQL in `src/sql`.
4
+
5
+ Accept an optional telemetry hook from `src/infrastructure/telemetry/repositoryTelemetry.ts` and default it through `resolveRepositoryTelemetry(...)` so applications can bridge structured events into their own logging stack.
@@ -1,77 +1,30 @@
1
- # src/sql AGENTS
2
-
3
- This directory contains SQL assets executed at runtime.
4
-
5
- ## Runtime classification
6
-
7
- - This is a runtime directory.
8
- - SQL files are loaded and executed by repositories or catalog runtime.
9
-
10
- ## Ownership (important)
11
-
12
- - SQL expresses domain intent and is human-owned by default.
13
- - AI may propose changes, but MUST NOT alter semantics or intent without explicit human instruction.
14
- - If a human explicitly writes or edits SQL, the human decision always takes precedence.
15
-
16
- ## Parameter binding (required)
17
-
18
- - SQL assets MUST use named parameters (":name" form).
19
- - Positional parameters ("$1", "$2", ...) are forbidden in SQL assets.
20
- - Conversion from named to indexed parameters is a runtime responsibility.
21
-
22
- ## DTO independence (critical)
23
-
24
- - SQL MUST NOT depend on DTO shapes.
25
- - CamelCase aliases (e.g. `as "userId"`) are forbidden.
26
- - SQL should return database-oriented column names (typically snake_case).
27
- - Mapping to DTOs is the responsibility of repositories or catalog runtime.
28
-
29
- ## CRUD quality bar (tables) (important)
30
-
31
- For simple CRUD SQL under table-oriented areas:
32
- - Prefer the most direct and idiomatic SQL.
33
- - Do NOT encode driver limitations into SQL.
34
- - Avoid unnecessary CTEs or counting tricks.
35
-
36
- Examples of discouraged patterns for simple CRUD:
37
- - `with updated as (...) select count(*) ...`
38
- - returning values only to compute affected rows
39
-
40
- Affected-row handling belongs to repositories/runtime, not SQL.
41
-
42
- ## CUD and RETURNING policy
43
-
44
- - INSERT SQL MAY use `RETURNING` only for identifier columns (and optionally DB-generated columns required by contract).
45
- - INSERT SQL MUST NOT return full rows or DTO-shaped payloads.
46
- - UPDATE SQL MUST NOT use `RETURNING`.
47
- - DELETE SQL MUST NOT use `RETURNING`.
48
- - SQL MUST NOT use `RETURNING` to emulate affected-row detection.
49
- - If affected-row counts are unavailable from the driver/runtime, treat UPDATE/DELETE verification as unsupported at the driver boundary.
50
-
51
- ## Safety rules (critical)
52
-
53
- - UPDATE and DELETE MUST include a WHERE clause.
54
- - SQL MUST NOT rely on follow-up SELECTs in repositories to ensure correctness.
55
- - A missing or incorrect WHERE clause is a SQL bug and MUST surface via tests.
56
-
57
- ## Naming conventions (recommended)
58
-
59
- Prefer SQL-idiomatic verbs for CRUD assets:
60
- - insert_<entity>.sql
61
- - select_<entity>_by_<key>.sql
62
- - select_<entities>.sql
63
- - update_<entity>.sql
64
- - delete_<entity>.sql
65
-
66
- Avoid ambiguous verbs like "create" / "get" in SQL filenames by default.
67
-
68
- ## General SQL rules
69
-
70
- - Use explicit column lists.
71
- - Avoid `select *` unless explicitly justified.
72
- - Prefer stable ordering when result order matters.
73
-
74
- ## Boundaries
75
-
76
- - Do not place TypeScript code in this directory.
77
- - Query contracts live in "src/catalog/specs".
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/src/sql`.
3
+ - Defines SQL asset contract rules for runtime execution.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - SQL assets MUST use named parameters (`:name`).
8
+ - SQL assets MUST stay DTO-independent and use database-oriented column naming.
9
+ - UPDATE and DELETE statements MUST include WHERE clauses.
10
+ - SQL files MUST remain explicit enough for repository/runtime mapping contracts.
11
+ - CUD `RETURNING` behavior MUST follow repository contract rules.
12
+
13
+ ## ALLOWED
14
+ - INSERT SQL MAY use `RETURNING` for identifiers and required DB-generated contract columns.
15
+
16
+ ## PROHIBITED
17
+ - Positional placeholders in SQL asset files.
18
+ - DTO camelCase aliasing inside SQL assets.
19
+ - UPDATE/DELETE `RETURNING` usage.
20
+ - SQL-side emulation of affected-row verification behavior.
21
+
22
+ # Mandatory Workflow
23
+ - SQL asset changes MUST run tests that execute the changed SQL via catalog/repository paths.
24
+
25
+ # Hygiene
26
+ - Keep SQL filenames stable and unambiguous for CRUD intent.
27
+ - Avoid `select *` unless explicitly justified by contract behavior.
28
+
29
+ # References
30
+ - Parent runtime policy: [../AGENTS.md](../AGENTS.md)
@@ -1,6 +1,6 @@
1
- # SQL Files
2
-
3
- Store SQL statements by table or domain in subfolders.
4
-
5
- - Use named parameters (for example `:id`).
1
+ # SQL Files
2
+
3
+ Store SQL statements by table or domain in subfolders.
4
+
5
+ - Use named parameters (for example `:id`).
6
6
  - Keep SQL in files; repositories should load them.
@@ -1,62 +1,29 @@
1
- # tests AGENTS
2
-
3
- This directory contains verification code.
4
-
5
- ## Runtime classification
6
-
7
- - This is a non-runtime directory.
8
- - Code here is never part of application runtime.
9
-
10
- ## Core principles
11
-
12
- - This project uses ZTD (Zero Table Dependency).
13
- - DDL and fixtures define the test world.
14
- - Tests must be deterministic and parallel-safe.
15
-
16
- ## What to test (important)
17
-
18
- - Catalog specs are first-class test targets.
19
- - Tests should verify:
20
- - SQL executes under ZTD rewriting
21
- - mapping behavior
22
- - validation success and failure
23
- - DTO shape and semantics
24
-
25
- - Tests MUST NOT enforce repository behavior that contradicts repository contracts.
26
- - Tests MUST NOT require follow-up SELECTs after UPDATE or DELETE by default.
27
-
28
- ## CUD test policy (important)
29
-
30
- - UPDATE and DELETE success/failure MUST be verified via affected-row information
31
- (e.g. rowCount or equivalent).
32
- - Tests MUST NOT assume UPDATE/DELETE return DTOs.
33
- - If the driver cannot report affected rows, CUD verification is unsupported and
34
- tests MUST fail fast.
35
- - CREATE tests for table repositories MUST expect identifier-only returns by default.
36
- - Tests MUST NOT require repository follow-up SELECT after CREATE unless the catalog spec explicitly requires DTO return.
37
-
38
- ## Generated artifacts
39
-
40
- - "tests/generated/" is auto-generated.
41
- - Do not edit generated files by hand.
42
- - Regenerate before debugging type errors.
43
-
44
- ## Boundaries
45
-
46
- - Tests may import from "src/".
47
- - Runtime code under "src/" MUST NOT import from "tests/" or "tests/generated/".
48
-
49
- ## Test runner requirements (required)
50
-
51
- - A test runner configuration (e.g. vitest.config.ts) MUST exist.
52
- - Tests MUST be executable with a single command (e.g. `pnpm test`).
53
- - Missing test runner configuration is considered a setup error.
54
-
55
- Do not add tests that assume manual setup steps.
56
-
57
- ## Initialization invariant
58
-
59
- - The initial project state MUST include:
60
- - test runner configuration
61
- - at least one executable test file
62
- - The initial test run MUST pass or fail only due to user-written logic, not setup.
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/tests`.
3
+ - Defines verification contract for ZTD template-generated test code.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Tests MUST verify SQL execution under ZTD rewrite, mapping behavior, validation paths, and DTO shape semantics.
8
+ - CUD tests MUST verify UPDATE/DELETE via affected-row signals.
9
+ - CREATE tests for table repositories MUST expect identifier-only returns unless spec explicitly requires DTO return.
10
+ - Test runner configuration MUST exist and support single-command execution.
11
+ - Initial template state MUST include at least one executable test.
12
+
13
+ ## ALLOWED
14
+ - Tests MAY import runtime modules from `src/`.
15
+
16
+ ## PROHIBITED
17
+ - Runtime imports from `tests/` or `tests/generated/`.
18
+ - Tests that require repository follow-up SELECT behavior contradicting repository contracts.
19
+ - Manual edits to generated artifacts.
20
+
21
+ # Mandatory Workflow
22
+ - Test changes MUST run affected test suites and confirm test-runner configuration remains valid.
23
+
24
+ # Hygiene
25
+ - Regenerate `tests/generated` artifacts before diagnosing missing generated module errors.
26
+
27
+ # References
28
+ - Generated tests policy: [./generated/AGENTS.md](./generated/AGENTS.md)
29
+ - Shared support policy: [./support/AGENTS.md](./support/AGENTS.md)
@@ -1,16 +1,23 @@
1
- # tests/generated AGENTS
2
-
3
- This directory contains generated files.
4
-
5
- ## Non-negotiable
6
-
7
- - Do not edit any file in this directory by hand.
8
- - Do not commit generated artifacts unless the repository explicitly requires it.
9
-
10
- ## Regeneration
11
-
12
- If files are missing or stale, regenerate using the project command.
13
- Example:
14
- - "npx ztd ztd-config"
15
-
16
- If TypeScript reports missing modules referencing generated files, regenerate first.
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/tests/generated`.
3
+ - Governs generated test artifacts.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Missing or stale generated files MUST be regenerated using project generation commands.
8
+
9
+ ## ALLOWED
10
+ - Generated artifacts MAY be regenerated via `npx ztd ztd-config`.
11
+
12
+ ## PROHIBITED
13
+ - Manual edits to files in this directory.
14
+ - Committing generated artifacts when repository policy does not require them.
15
+
16
+ # Mandatory Workflow
17
+ - Run generation commands before diagnosing generated-module type errors.
18
+
19
+ # Hygiene
20
+ - Keep generated output reproducible from project tooling.
21
+
22
+ # References
23
+ - Parent tests policy: [../AGENTS.md](../AGENTS.md)
@@ -1,5 +1,25 @@
1
- import { expect, test } from 'vitest';
2
-
3
- test('smoke: template test runner is wired', () => {
4
- expect(true).toBe(true);
5
- });
1
+ import { expect, test } from 'vitest';
2
+
3
+ import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
4
+ import { createTestkitClient } from './support/testkit-client';
5
+
6
+ test('smoke: runtime contract wiring is usable before SQL-backed tests exist', () => {
7
+ const output = ensureSmokeOutput({
8
+ id: 1,
9
+ createdAt: '2025-01-01T00:00:00.000Z',
10
+ });
11
+
12
+ expect(output.id).toBe(1);
13
+ expect(output.createdAt).toBeInstanceOf(Date);
14
+ expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
15
+ });
16
+
17
+ test('smoke: SqlClient seam is either wired or fails with an actionable message', async () => {
18
+ try {
19
+ const client = await createTestkitClient();
20
+ expect(typeof client.query).toBe('function');
21
+ } catch (error) {
22
+ const message = error instanceof Error ? error.message : String(error);
23
+ expect(message).toContain('Provide a SqlClient implementation here');
24
+ }
25
+ });
@@ -1,34 +1,34 @@
1
- import { expect, test } from 'vitest';
2
-
3
- import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
4
-
5
- test('validator invariant smoke passes for valid runtime output', () => {
6
- const output = ensureSmokeOutput({
7
- id: 1,
8
- createdAt: new Date('2025-01-01T00:00:00.000Z')
9
- });
10
-
11
- expect(output).toEqual({
12
- id: 1,
13
- createdAt: new Date('2025-01-01T00:00:00.000Z')
14
- });
15
- });
16
-
17
- test('validator invariant smoke normalizes valid timestamp strings', () => {
18
- const output = ensureSmokeOutput({
19
- id: 1,
20
- createdAt: '2025-01-01T00:00:00.000Z'
21
- });
22
-
23
- expect(output.createdAt).toBeInstanceOf(Date);
24
- expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
25
- });
26
-
27
- test('validator invariant smoke fails for invalid runtime output', () => {
28
- expect(() =>
29
- ensureSmokeOutput({
30
- id: 1,
31
- createdAt: 'not-a-date'
32
- })
33
- ).toThrow(/Invalid timestamp string/);
34
- });
1
+ import { expect, test } from 'vitest';
2
+
3
+ import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
4
+
5
+ test('validator invariant smoke passes for valid runtime output', () => {
6
+ const output = ensureSmokeOutput({
7
+ id: 1,
8
+ createdAt: new Date('2025-01-01T00:00:00.000Z')
9
+ });
10
+
11
+ expect(output).toEqual({
12
+ id: 1,
13
+ createdAt: new Date('2025-01-01T00:00:00.000Z')
14
+ });
15
+ });
16
+
17
+ test('validator invariant smoke normalizes valid timestamp strings', () => {
18
+ const output = ensureSmokeOutput({
19
+ id: 1,
20
+ createdAt: '2025-01-01T00:00:00.000Z'
21
+ });
22
+
23
+ expect(output.createdAt).toBeInstanceOf(Date);
24
+ expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
25
+ });
26
+
27
+ test('validator invariant smoke fails for invalid runtime output', () => {
28
+ expect(() =>
29
+ ensureSmokeOutput({
30
+ id: 1,
31
+ createdAt: 'not-a-date'
32
+ })
33
+ ).toThrow(/Invalid timestamp string/);
34
+ });
@@ -1,26 +1,24 @@
1
- # tests/support AGENTS
2
-
3
- This folder contains shared test infrastructure.
4
-
5
- ## Scope
6
-
7
- - global setup and teardown
8
- - test clients and helpers for execution
9
- - environment/bootstrap logic
10
-
11
- ## Rules
12
-
13
- - Keep helpers minimal and explicit.
14
- - Prefer stable interfaces used across tests.
15
- - Do not place business rules here.
16
-
17
- ## Boundaries
18
-
19
- - Support code may import from "src/" as needed.
20
- - Runtime code under "src/" MUST NOT import from this folder.
21
-
22
- ## Changes
23
-
24
- When modifying global setup or shared clients:
25
- - Re-run a representative subset of tests and at least one full run when feasible.
26
- - Watch for parallelism and resource lifecycle issues.
1
+ # Package Scope
2
+ - Applies to `packages/ztd-cli/templates/tests/support`.
3
+ - Defines shared test infrastructure contracts.
4
+
5
+ # Policy
6
+ ## REQUIRED
7
+ - Shared support helpers MUST stay minimal and explicit.
8
+ - Shared support code MUST avoid business-rule ownership.
9
+ - Runtime code under `src/` MUST NOT import from this folder.
10
+
11
+ ## ALLOWED
12
+ - Support helpers MAY import from `src/`.
13
+
14
+ ## PROHIBITED
15
+ - Embedding domain business logic into support infrastructure.
16
+
17
+ # Mandatory Workflow
18
+ - Global setup/support changes MUST run representative subset tests and at least one full test run.
19
+
20
+ # Hygiene
21
+ - Validate resource lifecycle and parallelism behavior after support-layer changes.
22
+
23
+ # References
24
+ - Parent tests policy: [../AGENTS.md](../AGENTS.md)
@@ -1,15 +1,15 @@
1
- /**
2
- * Vitest global setup.
3
- *
4
- * This hook warns when DATABASE_URL is missing so the developer remembers to
5
- * install an adapter or provide a connection before running SQL-backed tests.
6
- */
7
- export default async function globalSetup() {
8
- const configuredUrl = process.env.DATABASE_URL?.trim();
9
- if (!configuredUrl) {
10
- console.warn(
11
- 'DATABASE_URL is not configured. Install a database adapter or set DATABASE_URL before running SQL-backed tests.',
12
- );
13
- }
14
- return () => undefined;
15
- }
1
+ /**
2
+ * Vitest global setup.
3
+ *
4
+ * This hook warns when ZTD_TEST_DATABASE_URL is missing so the developer remembers
5
+ * to provide the ZTD-owned test database connection before running SQL-backed tests.
6
+ */
7
+ export default async function globalSetup() {
8
+ const configuredUrl = process.env.ZTD_TEST_DATABASE_URL?.trim();
9
+ if (!configuredUrl) {
10
+ console.warn(
11
+ 'ZTD_TEST_DATABASE_URL is not configured. SQL-backed tests will need a driver plus a ZTD-owned test database connection before they can run.',
12
+ );
13
+ }
14
+ return () => undefined;
15
+ }