@rawsql-ts/ztd-cli 0.14.4 → 0.16.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 (130) hide show
  1. package/README.md +25 -11
  2. package/dist/commands/init.js +27 -10
  3. package/dist/commands/init.js.map +1 -1
  4. package/dist/commands/lint.d.ts +59 -0
  5. package/dist/commands/lint.js +338 -0
  6. package/dist/commands/lint.js.map +1 -0
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/utils/sqlLintHelpers.d.ts +18 -0
  10. package/dist/utils/sqlLintHelpers.js +270 -0
  11. package/dist/utils/sqlLintHelpers.js.map +1 -0
  12. package/package.json +11 -4
  13. package/templates/AGENTS.md +95 -53
  14. package/templates/README.md +45 -67
  15. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +38 -0
  16. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +117 -0
  17. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +1 -0
  18. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +4 -0
  19. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +71 -0
  20. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +1 -0
  21. package/templates/dist/drivers/pg-testkit/src/index.d.ts +5 -0
  22. package/templates/dist/drivers/pg-testkit/src/index.js +11 -0
  23. package/templates/dist/drivers/pg-testkit/src/index.js.map +1 -0
  24. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +3 -0
  25. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +79 -0
  26. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +1 -0
  27. package/templates/dist/drivers/pg-testkit/src/types.d.ts +69 -0
  28. package/templates/dist/drivers/pg-testkit/src/types.js +3 -0
  29. package/templates/dist/drivers/pg-testkit/src/types.js.map +1 -0
  30. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +15 -0
  31. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +34 -0
  32. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +1 -0
  33. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +12 -0
  34. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +53 -0
  35. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +1 -0
  36. package/templates/dist/mapper-core/src/index.d.ts +160 -0
  37. package/templates/dist/mapper-core/src/index.js +637 -0
  38. package/templates/dist/mapper-core/src/index.js.map +1 -0
  39. package/templates/dist/testkit-core/src/errors/index.d.ts +49 -0
  40. package/templates/dist/testkit-core/src/errors/index.js +111 -0
  41. package/templates/dist/testkit-core/src/errors/index.js.map +1 -0
  42. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +5 -0
  43. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +29 -0
  44. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +1 -0
  45. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +37 -0
  46. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +182 -0
  47. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +1 -0
  48. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +20 -0
  49. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +121 -0
  50. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +1 -0
  51. package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +51 -0
  52. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +199 -0
  53. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +1 -0
  54. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +10 -0
  55. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +28 -0
  56. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +1 -0
  57. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +18 -0
  58. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +80 -0
  59. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +1 -0
  60. package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +59 -0
  61. package/templates/dist/testkit-core/src/fixtures/ddlLint.js +489 -0
  62. package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +1 -0
  63. package/templates/dist/testkit-core/src/fixtures/naming.d.ts +1 -0
  64. package/templates/dist/testkit-core/src/fixtures/naming.js +6 -0
  65. package/templates/dist/testkit-core/src/fixtures/naming.js.map +1 -0
  66. package/templates/dist/testkit-core/src/index.d.ts +17 -0
  67. package/templates/dist/testkit-core/src/index.js +47 -0
  68. package/templates/dist/testkit-core/src/index.js.map +1 -0
  69. package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +8 -0
  70. package/templates/dist/testkit-core/src/logger/NoopLogger.js +16 -0
  71. package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +1 -0
  72. package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +57 -0
  73. package/templates/dist/testkit-core/src/provider/TestkitProvider.js +149 -0
  74. package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +1 -0
  75. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +43 -0
  76. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +473 -0
  77. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +1 -0
  78. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +9 -0
  79. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +38 -0
  80. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +1 -0
  81. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +42 -0
  82. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +298 -0
  83. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +1 -0
  84. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +12 -0
  85. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +63 -0
  86. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +1 -0
  87. package/templates/dist/testkit-core/src/types/index.d.ts +69 -0
  88. package/templates/dist/testkit-core/src/types/index.js +3 -0
  89. package/templates/dist/testkit-core/src/types/index.js.map +1 -0
  90. package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +28 -0
  91. package/templates/dist/testkit-core/src/utils/queryHelpers.js +81 -0
  92. package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +1 -0
  93. package/templates/dist/writer-core/src/index.d.ts +34 -0
  94. package/templates/dist/writer-core/src/index.js +115 -0
  95. package/templates/dist/writer-core/src/index.js.map +1 -0
  96. package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +20 -0
  97. package/templates/dist/ztd-cli/templates/src/db/sql-client.js +3 -0
  98. package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +1 -0
  99. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +36 -0
  100. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +85 -0
  101. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +1 -0
  102. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +20 -0
  103. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +33 -0
  104. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +1 -0
  105. package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +10 -0
  106. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +29 -0
  107. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +1 -0
  108. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +66 -0
  109. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +552 -0
  110. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +1 -0
  111. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +1 -0
  112. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +82 -0
  113. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +1 -0
  114. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +1 -0
  115. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +29 -0
  116. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +1 -0
  117. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +7 -0
  118. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +10 -0
  119. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +1 -0
  120. package/templates/src/db/sql-client.ts +1 -1
  121. package/templates/src/repositories/user-accounts.ts +179 -0
  122. package/templates/tests/AGENTS.md +59 -6
  123. package/templates/tests/support/global-setup.ts +1 -1
  124. package/templates/tests/support/testkit-client.ts +4 -4
  125. package/templates/tests/user-profiles.test.ts +161 -0
  126. package/templates/tests/writer-constraints.test.ts +32 -0
  127. package/templates/tests/ztd-layout.generated.ts +0 -2
  128. package/templates/tsconfig.json +1 -2
  129. package/templates/ztd/AGENTS.md +10 -85
  130. package/templates/ztd/README.md +10 -79
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlLintHelpers.js","sourceRoot":"","sources":["../../src/utils/sqlLintHelpers.ts"],"names":[],"mappings":";;;;;AAWA,0CA2BC;AAKD,8CA0BC;AAKD,kDAWC;AAKD,8CAqDC;AA/ID,qCAAgD;AAChD,0DAA6B;AAC7B,0DAA2B;AAC3B,iDAAyD;AACzD,uDAAoD;AAIpD;;GAEG;AACH,SAAgB,eAAe,CAAC,OAAe;IAC7C,MAAM,eAAe,GA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AG,KAAK,GAAG,CAAC,CAAC;IACpB,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,OAAO,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACzB,KAAK,IAAI,GAAG,CAAC;gBACb,GAAG,IAAI,CAAC,CAAC;gBACT,SAAS;YACX,CAAC;YACD,GAAG,IAAI,CAAC,CAAC;YACT,MAAM;QACR,CAAC;QACD,KAAK,IAAI,IAAI,CAAC;QACd,GAAG,IAAI,CAAC,CAAC;IACX,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,cAAc,CAAC,GAAW,EAAE,KAAa;IAChD,OAAO,KAAK,GAAG,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACnD,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rawsql-ts/ztd-cli",
3
- "version": "0.14.4",
3
+ "version": "0.16.0",
4
4
  "description": "DB-agnostic scaffolding and DDL helpers for Zero Table Dependency projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -22,11 +22,17 @@
22
22
  "node": ">=20"
23
23
  },
24
24
  "dependencies": {
25
+ "@testcontainers/postgresql": "^10.28.0",
25
26
  "chokidar": "^5.0.0",
26
27
  "commander": "^12.0.0",
27
- "diff": "^5.1.0",
28
- "@rawsql-ts/testkit-core": "0.14.4",
29
- "rawsql-ts": "0.14.4"
28
+ "diff": "^8.0.3",
29
+ "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"
30
36
  },
31
37
  "devDependencies": {
32
38
  "@types/diff": "^5.0.1",
@@ -41,6 +47,7 @@
41
47
  "README.md"
42
48
  ],
43
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",
44
51
  "build": "tsc -p tsconfig.json",
45
52
  "test": "vitest run",
46
53
  "lint": "eslint src --ext .ts",
@@ -4,7 +4,7 @@ This application uses **Zero Table Dependency (ZTD)** as an internal development
4
4
  ZTD is not part of the application's runtime behavior; rather, it provides a framework for:
5
5
 
6
6
  - Maintaining consistent SQL across the project
7
- - Keeping schema, domain specifications, and enums synchronized
7
+ - Keeping schema metadata and generated artifacts synchronized
8
8
  - Ensuring deterministic SQL unit tests
9
9
  - Enabling structured collaboration between humans and AI
10
10
 
@@ -26,10 +26,35 @@ This section documents how ZTD is used inside this repository as a development m
26
26
  - After cloning the repository (or in a clean environment), run `npx ztd ztd-config`.
27
27
  - If TypeScript reports missing modules or type errors because `tests/generated/` is missing, run `npx ztd ztd-config`.
28
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
+
29
47
  ## ZTD Implementation Guide (src/)
30
48
 
31
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.
32
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
+
33
58
  ### Repository Classes: What to Care About
34
59
 
35
60
  #### Scope and Responsibility
@@ -37,10 +62,28 @@ The `src/` directory should contain pure TypeScript logic that operates on the r
37
62
  - Avoid embedding business logic, thresholds, or data reshaping inside repositories.
38
63
  - Treat repositories as thin adapters over SQL.
39
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
+
40
82
  #### SQL Management
41
- - Prefer keeping SQL in separate `.sql` files.
42
- - If no explicit instruction is given, separate SQL into files by default.
43
- - Repository classes should reference SQL files by name, not inline long SQL strings.
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.
44
87
 
45
88
  #### Specifications and Documentation
46
89
  - If a markdown file with the same base name as the repository or SQL exists, read it before implementation.
@@ -66,6 +109,32 @@ The `src/` directory should contain pure TypeScript logic that operates on the r
66
109
  - Do not introduce intermediate `*Row` types when SQL already returns DTO-compatible shapes.
67
110
  - Define separate Row types only when SQL intentionally returns database-shaped (snake_case) rows, and always convert them explicitly.
68
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
+
69
138
  ### Sequence / identity column policy (important)
70
139
 
71
140
  - Sequence / identity columns (auto-generated IDs) are infrastructure concerns.
@@ -76,14 +145,11 @@ The `src/` directory should contain pure TypeScript logic that operates on the r
76
145
  ### No test-driven fallbacks in production code (important)
77
146
 
78
147
  - Do not add fallbacks in `src/` that exist only to accommodate ZTD/testkit/rewriter limitations.
79
- - If a query fails to be rewritten into ZTD form (e.g. rawsql-ts parsing/rewrite failure), do not paper over it by changing runtime behavior, adding `max(id)+1`, or introducing alternative logic paths.
80
- - Instead, stop and report the issue with evidence:
81
- - The exact SQL that fails
82
- - The error message / symptoms
83
- - A minimal reproduction (smallest query that triggers the failure)
84
- - The expected behavior (what ZTD/testkit should have produced)
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.
85
150
 
86
- Rationale: Production code must not diverge from the intended SQL semantics due to tooling constraints. Tooling issues should be fixed in the tooling layer (rawsql-ts / ztd / testkit), not by altering runtime logic.
151
+ Rationale:
152
+ Production code must not diverge from intended SQL semantics due to tooling constraints.
87
153
 
88
154
  ---
89
155
 
@@ -93,7 +159,8 @@ Testing under ZTD follows dedicated, directory-scoped rules.
93
159
 
94
160
  - Test design, execution mode selection, and constraints are defined in:
95
161
  - `templates/tests/AGENTS.md`
96
- - This file intentionally avoids duplicating test-specific operational rules to prevent divergence.
162
+ - Tests validate repository behavior and returned DTOs.
163
+ - Raw SQL files or SQL strings must not be tested directly.
97
164
 
98
165
  ---
99
166
 
@@ -104,19 +171,15 @@ Testing under ZTD follows dedicated, directory-scoped rules.
104
171
  /ddl
105
172
  *.sql <- physical schema definitions
106
173
 
107
- /domain-specs
108
- *.md <- one behavioral SELECT per file (one SQL block)
109
-
110
- /enums
111
- *.md <- one enum definition per file (one SQL block)
112
-
113
174
  README.md <- documentation for the layout
114
- AGENTS.md <- combined guidance for DDL, enums, and specs
175
+ AGENTS.md <- combined guidance for DDL
115
176
 
116
177
  /src <- application & repository logic
117
178
  /tests <- ZTD tests, fixtures, row-maps
118
179
  ```
119
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
+
120
183
  The file `tests/generated/ztd-layout.generated.ts` ensures ZTD CLI always points to the correct directories.
121
184
 
122
185
  ---
@@ -124,8 +187,7 @@ The file `tests/generated/ztd-layout.generated.ts` ensures ZTD CLI always points
124
187
  # Protected directories and edit ownership (important)
125
188
 
126
189
  - DDL editing is human-led: `ztd/ddl/`
127
- - Domain specs editing is human-led: `ztd/domain-specs/`
128
- - Enums editing is human-led: `ztd/enums/`
190
+ - `ztd/ddl` is the sole human-owned directory inside `/ztd`; other directories must not be assumed or created without explicit instructions.
129
191
  - Application code is shared ownership: `src/`
130
192
  - Tests are shared ownership: `tests/`
131
193
  - Detailed test constraints live in `templates/tests/AGENTS.md`.
@@ -140,21 +202,17 @@ Additionally:
140
202
 
141
203
  ### 1. Humans own the definitions
142
204
  - Physical schema (DDL)
143
- - Domain semantics (domain-specs)
144
- - Enumerations (enums)
145
205
  - Repository interfaces
146
206
 
147
207
  ### 2. AI assists with implementation
148
208
  - Generating repository SQL
149
209
  - Updating fixtures
150
210
  - Producing intermediate TypeScript structures
151
- - Ensuring SQL adheres to DDL, enums, and domain-specs
211
+ - Ensuring SQL adheres to DDL
152
212
 
153
213
  ### 3. ZTD enforces consistency
154
214
  ZTD tests verify that:
155
215
  - SQL logic matches DDL shapes
156
- - SQL semantics match domain-specs
157
- - SQL values match enumerations
158
216
 
159
217
  If anything diverges, ZTD failures surface immediately and deterministically.
160
218
 
@@ -184,11 +242,11 @@ Changing method signatures, adding new repository methods, etc.
184
242
 
185
243
  1. Modify the repository interface or implementation in `/src`.
186
244
  2. Use AI assistance to generate or update the SQL implementation.
187
- 3. If the generated SQL conflicts with domain-specs or enums, update definitions first.
245
+ 3. If the generated SQL conflicts with DDL or other human-maintained references, update the authoritative source first.
188
246
  4. Run ZTD tests.
189
247
  5. Regenerate config if SQL output shape changed.
190
248
 
191
- Flow: Interface to SQL to Specs (if needed) to Tests
249
+ Flow: Interface to SQL to Tests
192
250
 
193
251
  ---
194
252
 
@@ -197,31 +255,19 @@ Bug fixes, refactoring, rewriting queries.
197
255
 
198
256
  1. Edit SQL inside the repository.
199
257
  2. Run ZTD tests.
200
- 3. If intended behavior changes, update the appropriate file in `ztd/domain-specs/`.
258
+ 3. If intended behavior changes, coordinate any necessary DDL updates before adjusting dependent code.
201
259
  4. Update fixtures as needed.
202
260
  5. Regenerate config if result shape changed.
203
261
 
204
- Flow: SQL to Domain-specs to Tests
205
-
206
- ---
207
-
208
- # Workflow D - Starting From Enum or Domain Specification Changes
209
- Business rule changes or conceptual model updates.
210
-
211
- Flow: Specs or Enums to SQL to Tests to (DDL if required)
262
+ Flow: SQL to Tests
212
263
 
213
264
  ---
214
265
 
215
266
  # Combined Real-World Examples
216
267
 
217
- - Adding a new contract state:
218
- enums to domain-spec to SQL to config to tests
219
-
220
- - Adding a new table:
221
- DDL to config to SQL to fixtures to tests
222
-
223
- - Fixing business logic:
224
- SQL to domain-spec to tests
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
225
271
 
226
272
  ZTD ensures the development always converges into a consistent, validated workflow.
227
273
 
@@ -232,8 +278,6 @@ ZTD ensures the development always converges into a consistent, validated workfl
232
278
  Humans maintain:
233
279
 
234
280
  - Schema definitions (`ztd/ddl`)
235
- - Domain logic definitions (`ztd/domain-specs`)
236
- - Domain enumerations (`ztd/enums`)
237
281
  - Repository interfaces and architectural decisions
238
282
  - Acceptance and review of AI-generated patches
239
283
 
@@ -245,12 +289,10 @@ Humans decide what is correct.
245
289
 
246
290
  AI must:
247
291
 
248
- - Use domain-specs as the semantic source of truth
249
- - Use enums as the canonical vocabulary source
250
- - Use DDL as the physical structure constraint
251
- - Generate SQL consistent with all definitions
252
- - Update fixtures when needed
253
- - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction
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.
254
296
 
255
297
  AI decides how to implement, but not what is correct.
256
298
 
@@ -5,31 +5,28 @@ This project organizes all SQL‑related artifacts under the `ztd/` directory, s
5
5
  ```
6
6
  /ztd
7
7
  /ddl
8
- *.sql <- schema definitions
9
- /domain-specs
10
- *.md <- one behavior per file (one SQL block)
11
- /enums
12
- *.md <- one enum per file (one SQL block)
8
+ *.sql <- schema definitions (required)
13
9
  README.md <- documentation for the layout
14
- AGENTS.md <- combined guidance for people and agents
10
+ AGENTS.md <- combined guidance for DDL
15
11
 
16
12
  /src <- application & repository code
17
13
  /tests <- ZTD tests, fixtures, generated maps
18
14
  ```
19
15
 
16
+ Only `ztd/ddl` is part of the template contract. Do not create or assume other `ztd` subdirectories unless the project explicitly adds them.
17
+
20
18
  ## Generated files (important)
21
19
 
22
20
  `tests/generated/` is auto-generated and must never be committed to git.
23
-
24
- After cloning the repository (or in a clean environment), run:
21
+ After cloning the repository (or in a clean environment), run (strongly recommended):
25
22
 
26
23
  ```bash
27
24
  npx ztd ztd-config
28
25
  ```
29
26
 
30
- If TypeScript reports missing modules or type errors because `tests/generated/` is missing, run `npx ztd ztd-config`.
27
+ If TypeScript reports missing modules or type errors because `tests/generated/` is missing, rerun `npx ztd ztd-config`.
31
28
 
32
- `tests/generated/ztd-layout.generated.ts` declares the directories above so the CLI and your tests always point at the correct files.
29
+ `tests/generated/ztd-layout.generated.ts` declares the directories above so the CLI and your tests always point at the intended files. The authoritative directory remains `ztd/ddl/`; do not read or assume additional `ztd` subdirectories.
33
30
 
34
31
  ---
35
32
 
@@ -60,12 +57,21 @@ export function getSqlClient(): SqlClient {
60
57
 
61
58
  ---
62
59
 
60
+ # Mapper + writer sample
61
+
62
+ - This scaffold already exposes `src/repositories/user-accounts.ts`, which maps `public.user_account` rows together with optional `public.user_profile` data through `@rawsql-ts/sql-contract/mapper` and emits insert/update/remove helpers via `@rawsql-ts/sql-contract/writer`.
63
+ - The SQL used here is defined in `src/repositories/user-accounts.ts`; the template tests exercise that implementation and `ztd/ddl` is the authoritative source for every column and constraint.
64
+ - Two template tests demonstrate how to run the stitch:
65
+ - `tests/user-profiles.test.ts` seeds fixtures, executes the query through the mapper, and verifies the DTO shape.
66
+ - `tests/writer-constraints.test.ts` reads `userAccountWriterColumnSets` plus `tests/generated/ztd-row-map.generated.ts` so writer callers stay within the approved column set when referencing `public.user_account`.
67
+ - Regenerate `tests/generated/ztd-row-map.generated.ts` (`npx ztd ztd-config`) before running the example tests so the row map reflects any schema changes.
68
+ - The example tests require a real PostgreSQL connection via `DATABASE_URL`; they automatically skip when the variable is missing so local tooling stays fast.
69
+
63
70
  # Principles
64
71
 
65
72
  ### 1. Humans own the *definitions*
66
73
  - DDL (physical schema)
67
- - Domain specifications (business logic -> SQL semantics)
68
- - Enums (canonical domain values)
74
+ Only `ztd/ddl` is part of the template contract; other subdirectories should not be assumed.
69
75
 
70
76
  ### 2. AI owns the *implementation*
71
77
  - Repository SQL generation
@@ -75,9 +81,8 @@ export function getSqlClient(): SqlClient {
75
81
 
76
82
  ### 3. ZTD ensures these stay in sync
77
83
  ZTD acts as the consistency layer ensuring:
78
- - DDL SQL shape consistency
79
- - domain-specs query logic consistency
80
- - enums ↔ code‑level constants consistency
84
+ - DDL SQL shape consistency
85
+ - Do not rely on other directories unless the project explicitly adds them.
81
86
 
82
87
  If any part diverges, ZTD tests fail deterministically.
83
88
 
@@ -115,22 +120,22 @@ Different tasks start from different entry points. Choose the workflow that matc
115
120
 
116
121
  1. Modify the repository interface or class in `/src`.
117
122
  2. Allow AI to generate the SQL needed to satisfy the interface.
118
- 3. If the query contradicts domain-specs or enums, update specs first.
123
+ 3. If the query contradicts DDL, reconcile the authoritative definition before continuing.
119
124
  4. Run ZTD tests to confirm logic is consistent.
120
125
  5. Regenerate ZTD config if result shapes changed.
121
126
 
122
127
  **Flow:**
123
- **repository interface -> SQL -> (update specs if needed) -> tests**
128
+ **repository interface -> SQL -> tests**
124
129
 
125
130
  ---
126
131
 
127
- # Workflow C — Starting From *Repository SQL Logic Changes*
132
+ # Workflow C — Starting From Repository SQL Logic Changes
128
133
  (Fixing a bug, optimizing logic, rewriting a query)
129
134
 
130
135
  1. Edit SQL inside the repository.
131
- 2. Run existing ZTD tests.
132
- 3. If the intended behavior changes, update `ztd/domain-specs/`.
133
- 4. Update fixtures if necessary.
136
+ 2. Run ZTD tests.
137
+ 3. If the intended behavior changes, update the DDL before adjusting dependent logic and keep documentation aligned with the confirmed schema.
138
+ 4. Update fixtures as necessary.
134
139
  5. If SQL result shape changed, run:
135
140
 
136
141
  ```bash
@@ -138,62 +143,30 @@ Different tasks start from different entry points. Choose the workflow that matc
138
143
  ```
139
144
 
140
145
  **Flow:**
141
- **SQL -> domain-specs (if needed) -> fixtures/tests**
142
-
143
- ---
144
-
145
- # Workflow D — Starting From *Enums or Domain Spec Changes*
146
- (Business rules change, new status added, new definition created)
147
-
148
- ## For enums:
149
-
150
- 1. Update the relevant `.md` file under `ztd/enums/`.
151
- 2. Regenerate row-map:
152
-
153
- ```bash
154
- npx ztd ztd-config
155
- ```
156
-
157
- 3. Update SQL referencing enum values.
158
- 4. Update domain-specs or repository SQL if behaviors change.
159
- 5. Update fixtures and tests.
160
-
161
- ## For domain-specs:
162
-
163
- 1. Modify the `.md` spec in `ztd/domain-specs/`.
164
- 2. Update SQL in `/src` to follow the new semantics.
165
- 3. Update tests and fixtures.
166
- 4. Update DDL only if the new behavior requires schema changes.
167
-
168
- **Flow:**
169
- **spec/enums -> SQL -> tests -> (DDL if required)**
146
+ **SQL -> fixtures/tests**
170
147
 
171
148
  ---
172
149
 
173
150
  # Combined Real‑World Flow Examples
174
151
 
175
152
  - **Add a new contract status**
176
- enums -> domain-spec -> SQL -> config -> tests
153
+ DDL -> SQL -> config -> tests
177
154
 
178
155
  - **Add a new table**
179
156
  DDL -> config -> SQL -> fixtures -> tests
180
157
 
181
158
  - **Fix business logic**
182
- SQL -> domain-spec -> tests
183
-
184
- ZTD ensures all changes converge into the same consistency pipeline.
159
+ SQL -> tests
185
160
 
161
+ ZTD ensures all changes converge into a consistent, validated workflow.
186
162
  ---
187
163
 
188
164
  # Human Responsibilities
189
165
 
190
- Humans maintain:
191
-
192
- - Business logic definitions (`domain-specs`)
193
- - Physical schema (`ddl`)
194
- - Domain vocabularies (`enums`)
195
- - High‑level repository interfaces
196
- - Acceptance of AI-generated changes
166
+ - Humans maintain:
167
+ - Physical schema (`ddl`)
168
+ - High‑level repository interfaces
169
+ - Acceptance of AI-generated changes
197
170
 
198
171
  Humans decide “what is correct.”
199
172
 
@@ -203,12 +176,11 @@ Humans decide “what is correct.”
203
176
 
204
177
  AI must:
205
178
 
206
- - Use domain-specs as the **semantic source of truth**
207
- - Use enums as the **canonical vocabulary source**
208
- - Use DDL as the **physical shape constraint**
209
- - Generate repository SQL consistent with all three
210
- - Regenerate fixtures and tests as instructed
211
- - Never modify `ztd/AGENTS.md` or `ztd/README.md` unless explicitly asked
179
+ - Use DDL as the **physical shape constraint** and primary source of truth.
180
+ - Do not assume any additional `ztd` directories exist unless a human explicitly creates them.
181
+ - Generate repository SQL consistent with DDL and the documented behavior.
182
+ - Regenerate fixtures and tests as instructed.
183
+ - Never modify `ztd/AGENTS.md` or `ztd/README.md` unless explicitly asked.
212
184
 
213
185
  AI decides “how to implement” within those constraints.
214
186
 
@@ -237,3 +209,9 @@ ZTD is the verification engine guaranteeing correctness.
237
209
  ZTD enables a workflow where **humans define meaning**, **AI writes implementation**, and **tests guarantee correctness**.
238
210
 
239
211
  The project layout and workflows above ensure long-term maintainability, clarity, and full reproducibility of SQL logic independent of physical database state.
212
+
213
+ ## Recommended local verification
214
+
215
+ - `npx ztd ztd-config` (Recommended)
216
+ - `pnpm -C packages/ztd-cli test` (Recommended)
217
+ - `templates/tests/user-profiles.test.ts` runs only when `DATABASE_URL` is configured; otherwise it skips automatically.
@@ -0,0 +1,38 @@
1
+ import type { QueryResult, QueryResultRow } from 'pg';
2
+ import type { CreatePgTestkitClientOptions, PgQueryInput, PgQueryable, TableRowsFixture } from '../types';
3
+ /**
4
+ * Lightweight client that rewrites CRUD/SELECT statements into fixture-backed SELECTs
5
+ * and delegates execution to a real `pg` connection.
6
+ *
7
+ * Consumers can use this in place of `pg.Client` during tests; production code can stay
8
+ * unaware of pg-testkit as long as it relies on the standard `query` API.
9
+ */
10
+ export declare class PgTestkitClient {
11
+ private readonly options;
12
+ private readonly scopedRows?;
13
+ private connection?;
14
+ private readonly rewriter;
15
+ private readonly tableNameResolver;
16
+ constructor(options: CreatePgTestkitClientOptions, scopedRows?: TableRowsFixture[] | undefined, seedConnection?: PgQueryable);
17
+ /**
18
+ * Executes SQL after rewriting it to use fixture-backed CTEs. CRUD statements are converted
19
+ * to result-producing SELECTs; unsupported DDL is ignored.
20
+ *
21
+ * @param textOrConfig SQL text or pg QueryConfig
22
+ * @param values Optional positional parameters
23
+ * @returns pg-style QueryResult with rows simulated from fixtures
24
+ */
25
+ query<T extends QueryResultRow = QueryResultRow>(textOrConfig: PgQueryInput, values?: unknown[]): Promise<QueryResult<T>>;
26
+ /**
27
+ * Derives a scoped client that overlays additional fixtures while reusing the same connection.
28
+ */
29
+ withFixtures(fixtures: TableRowsFixture[]): PgTestkitClient;
30
+ /**
31
+ * Disposes the underlying connection or returns it to the pool if `release` is available.
32
+ */
33
+ close(): Promise<void>;
34
+ private getConnection;
35
+ private buildEmptyResult;
36
+ }
37
+ /** Factory that instantiates a `PgTestkitClient` with the provided fixture-driven options. */
38
+ export declare const createPgTestkitClient: (options: CreatePgTestkitClientOptions) => PgTestkitClient;