@rawsql-ts/ztd-cli 0.15.0 → 0.17.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 (153) hide show
  1. package/README.md +38 -25
  2. package/dist/commands/init.d.ts +13 -0
  3. package/dist/commands/init.js +372 -118
  4. package/dist/commands/init.js.map +1 -1
  5. package/dist/commands/lint.d.ts +4 -4
  6. package/dist/commands/lint.js +60 -40
  7. package/dist/commands/lint.js.map +1 -1
  8. package/dist/commands/ztdConfig.d.ts +2 -2
  9. package/dist/commands/ztdConfig.js +26 -12
  10. package/dist/commands/ztdConfig.js.map +1 -1
  11. package/dist/utils/optionalDependencies.d.ts +35 -0
  12. package/dist/utils/optionalDependencies.js +96 -0
  13. package/dist/utils/optionalDependencies.js.map +1 -0
  14. package/package.json +18 -10
  15. package/templates/AGENTS.md +36 -296
  16. package/templates/README.md +12 -237
  17. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +38 -0
  18. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +117 -0
  19. package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +1 -0
  20. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +4 -0
  21. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +71 -0
  22. package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +1 -0
  23. package/templates/dist/drivers/pg-testkit/src/index.d.ts +5 -0
  24. package/templates/dist/drivers/pg-testkit/src/index.js +11 -0
  25. package/templates/dist/drivers/pg-testkit/src/index.js.map +1 -0
  26. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +3 -0
  27. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +79 -0
  28. package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +1 -0
  29. package/templates/dist/drivers/pg-testkit/src/types.d.ts +69 -0
  30. package/templates/dist/drivers/pg-testkit/src/types.js +3 -0
  31. package/templates/dist/drivers/pg-testkit/src/types.js.map +1 -0
  32. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +15 -0
  33. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +34 -0
  34. package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +1 -0
  35. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +12 -0
  36. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +53 -0
  37. package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +1 -0
  38. package/templates/dist/mapper-core/src/index.d.ts +160 -0
  39. package/templates/dist/mapper-core/src/index.js +637 -0
  40. package/templates/dist/mapper-core/src/index.js.map +1 -0
  41. package/templates/dist/testkit-core/src/errors/index.d.ts +49 -0
  42. package/templates/dist/testkit-core/src/errors/index.js +111 -0
  43. package/templates/dist/testkit-core/src/errors/index.js.map +1 -0
  44. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +5 -0
  45. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +29 -0
  46. package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +1 -0
  47. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +37 -0
  48. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +182 -0
  49. package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +1 -0
  50. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +20 -0
  51. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +121 -0
  52. package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +1 -0
  53. package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +51 -0
  54. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +199 -0
  55. package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +1 -0
  56. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +10 -0
  57. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +28 -0
  58. package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +1 -0
  59. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +18 -0
  60. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +80 -0
  61. package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +1 -0
  62. package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +59 -0
  63. package/templates/dist/testkit-core/src/fixtures/ddlLint.js +489 -0
  64. package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +1 -0
  65. package/templates/dist/testkit-core/src/fixtures/naming.d.ts +1 -0
  66. package/templates/dist/testkit-core/src/fixtures/naming.js +6 -0
  67. package/templates/dist/testkit-core/src/fixtures/naming.js.map +1 -0
  68. package/templates/dist/testkit-core/src/index.d.ts +17 -0
  69. package/templates/dist/testkit-core/src/index.js +47 -0
  70. package/templates/dist/testkit-core/src/index.js.map +1 -0
  71. package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +8 -0
  72. package/templates/dist/testkit-core/src/logger/NoopLogger.js +16 -0
  73. package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +1 -0
  74. package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +57 -0
  75. package/templates/dist/testkit-core/src/provider/TestkitProvider.js +149 -0
  76. package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +1 -0
  77. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +43 -0
  78. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +473 -0
  79. package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +1 -0
  80. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +9 -0
  81. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +38 -0
  82. package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +1 -0
  83. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +42 -0
  84. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +298 -0
  85. package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +1 -0
  86. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +12 -0
  87. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +63 -0
  88. package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +1 -0
  89. package/templates/dist/testkit-core/src/types/index.d.ts +69 -0
  90. package/templates/dist/testkit-core/src/types/index.js +3 -0
  91. package/templates/dist/testkit-core/src/types/index.js.map +1 -0
  92. package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +28 -0
  93. package/templates/dist/testkit-core/src/utils/queryHelpers.js +81 -0
  94. package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +1 -0
  95. package/templates/dist/writer-core/src/index.d.ts +34 -0
  96. package/templates/dist/writer-core/src/index.js +115 -0
  97. package/templates/dist/writer-core/src/index.js.map +1 -0
  98. package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +20 -0
  99. package/templates/dist/ztd-cli/templates/src/db/sql-client.js +3 -0
  100. package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +1 -0
  101. package/templates/dist/ztd-cli/templates/src/db/sql-client.ts +24 -0
  102. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +36 -0
  103. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +85 -0
  104. package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +1 -0
  105. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +20 -0
  106. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +33 -0
  107. package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +1 -0
  108. package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +10 -0
  109. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +29 -0
  110. package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +1 -0
  111. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +66 -0
  112. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +552 -0
  113. package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +1 -0
  114. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +1 -0
  115. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +82 -0
  116. package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +1 -0
  117. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +1 -0
  118. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +29 -0
  119. package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +1 -0
  120. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +7 -0
  121. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +10 -0
  122. package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +1 -0
  123. package/templates/src/AGENTS.md +26 -0
  124. package/templates/src/catalog/AGENTS.md +37 -0
  125. package/templates/src/catalog/runtime/AGENTS.md +75 -0
  126. package/templates/src/catalog/runtime/_coercions.ts +1 -0
  127. package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
  128. package/templates/src/catalog/specs/AGENTS.md +48 -0
  129. package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
  130. package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
  131. package/templates/src/db/sql-client.ts +5 -5
  132. package/templates/src/jobs/AGENTS.md +26 -0
  133. package/templates/src/jobs/README.md +3 -0
  134. package/templates/src/repositories/AGENTS.md +118 -0
  135. package/templates/src/repositories/tables/AGENTS.md +94 -0
  136. package/templates/src/repositories/tables/README.md +3 -0
  137. package/templates/src/repositories/views/AGENTS.md +25 -0
  138. package/templates/src/repositories/views/README.md +3 -0
  139. package/templates/src/sql/AGENTS.md +77 -0
  140. package/templates/src/sql/README.md +6 -0
  141. package/templates/tests/AGENTS.md +43 -129
  142. package/templates/tests/generated/AGENTS.md +16 -0
  143. package/templates/tests/smoke.test.ts +5 -0
  144. package/templates/tests/smoke.validation.test.ts +34 -0
  145. package/templates/tests/support/AGENTS.md +26 -0
  146. package/templates/tests/support/global-setup.ts +8 -23
  147. package/templates/tests/support/testkit-client.ts +13 -741
  148. package/templates/tests/ztd-layout.generated.ts +0 -2
  149. package/templates/tsconfig.json +9 -3
  150. package/templates/ztd/AGENTS.md +11 -142
  151. package/templates/ztd/README.md +4 -82
  152. package/templates/ztd/ddl/AGENTS.md +34 -0
  153. package/templates/ztd/ddl/demo.sql +74 -0
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.clearOptionalDependencyCache = clearOptionalDependencyCache;
40
+ exports.ensureTestkitCoreModule = ensureTestkitCoreModule;
41
+ exports.ensureAdapterNodePgModule = ensureAdapterNodePgModule;
42
+ exports.ensurePgModule = ensurePgModule;
43
+ exports.ensurePostgresContainerModule = ensurePostgresContainerModule;
44
+ const node_path_1 = __importDefault(require("node:path"));
45
+ const node_module_1 = require("node:module");
46
+ const node_url_1 = require("node:url");
47
+ const moduleCache = new Map();
48
+ async function loadOptionalModule(cacheKey, loader, description, installHint) {
49
+ if (moduleCache.has(cacheKey)) {
50
+ return moduleCache.get(cacheKey);
51
+ }
52
+ const moduleLoader = loader()
53
+ .catch((error) => {
54
+ moduleCache.delete(cacheKey);
55
+ const installNote = installHint ? ` Install it via \`${installHint}\`.` : '';
56
+ const original = error instanceof Error ? ` (${error.message})` : '';
57
+ throw new Error(`${description}${installNote}${original}`);
58
+ });
59
+ moduleCache.set(cacheKey, moduleLoader);
60
+ return moduleLoader;
61
+ }
62
+ function clearOptionalDependencyCache() {
63
+ moduleCache.clear();
64
+ }
65
+ function requireFromWorkspace(specifier) {
66
+ const require = (0, node_module_1.createRequire)(node_path_1.default.resolve(process.cwd(), 'package.json'));
67
+ return require(specifier);
68
+ }
69
+ async function loadAdapterNodePgModule() {
70
+ try {
71
+ return requireFromWorkspace('@rawsql-ts/adapter-node-pg');
72
+ }
73
+ catch (error) {
74
+ // Workspace tests can run before adapter build output exists, so use source entrypoint.
75
+ const workspaceAdapterSrc = node_path_1.default.resolve(process.cwd(), 'packages/adapters/adapter-node-pg/src/index.ts');
76
+ try {
77
+ return (await Promise.resolve(`${(0, node_url_1.pathToFileURL)(workspaceAdapterSrc).href}`).then(s => __importStar(require(s))));
78
+ }
79
+ catch {
80
+ throw error;
81
+ }
82
+ }
83
+ }
84
+ async function ensureTestkitCoreModule() {
85
+ return loadOptionalModule('@rawsql-ts/testkit-core', () => Promise.resolve().then(() => __importStar(require('@rawsql-ts/testkit-core'))), 'This command requires @rawsql-ts/testkit-core so fixtures and schema metadata are available.', 'pnpm add -D @rawsql-ts/testkit-core');
86
+ }
87
+ async function ensureAdapterNodePgModule() {
88
+ return loadOptionalModule('@rawsql-ts/adapter-node-pg', loadAdapterNodePgModule, 'A database adapter (for example @rawsql-ts/adapter-node-pg) is required to execute the rewritten SQL.', 'pnpm add -D @rawsql-ts/adapter-node-pg');
89
+ }
90
+ async function ensurePgModule() {
91
+ return loadOptionalModule('pg', () => Promise.resolve().then(() => __importStar(require('pg'))), 'The SQL lint command needs a PostgreSQL driver such as pg.', 'pnpm add -D pg');
92
+ }
93
+ async function ensurePostgresContainerModule() {
94
+ return loadOptionalModule('@testcontainers/postgresql', () => Promise.resolve().then(() => __importStar(require('@testcontainers/postgresql'))), 'ztd lint wants to spin up a disposable Postgres container via @testcontainers/postgresql.', 'pnpm add -D @testcontainers/postgresql');
95
+ }
96
+ //# sourceMappingURL=optionalDependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optionalDependencies.js","sourceRoot":"","sources":["../../src/utils/optionalDependencies.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,oEAEC;AAwBD,0DAOC;AAED,8DAOC;AAED,wCAOC;AAED,sEAOC;AA5HD,0DAA6B;AAC7B,6CAA4C;AAC5C,uCAAyC;AAEzC,MAAM,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;AAExD,KAAK,UAAU,kBAAkB,CAC/B,QAAgB,EAChB,MAAwB,EACxB,WAAmB,EACnB,WAAmB;IAEnB,IAAI,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAe,CAAC;IACjD,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,EAAE;SAC1B,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC7B,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,qBAAqB,WAAW,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7E,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEL,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACxC,OAAO,YAAY,CAAC;AACtB,CAAC;AAsCD,SAAgB,4BAA4B;IAC1C,WAAW,CAAC,KAAK,EAAE,CAAC;AACtB,CAAC;AAED,SAAS,oBAAoB,CAAI,SAAiB;IAChD,MAAM,OAAO,GAAG,IAAA,2BAAa,EAAC,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC;IAC3E,OAAO,OAAO,CAAC,SAAS,CAAM,CAAC;AACjC,CAAC;AAED,KAAK,UAAU,uBAAuB;IACpC,IAAI,CAAC;QACH,OAAO,oBAAoB,CAAsB,4BAA4B,CAAC,CAAC;IACjF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,wFAAwF;QACxF,MAAM,mBAAmB,GAAG,mBAAI,CAAC,OAAO,CACtC,OAAO,CAAC,GAAG,EAAE,EACb,gDAAgD,CACjD,CAAC;QACF,IAAI,CAAC;YACH,OAAO,CAAC,yBAAa,IAAA,wBAAa,EAAC,mBAAmB,CAAC,CAAC,IAAI,uCAAC,CAAwB,CAAC;QACxF,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC;AAEM,KAAK,UAAU,uBAAuB;IAC3C,OAAO,kBAAkB,CACvB,yBAAyB,EACzB,GAAG,EAAE,mDAAQ,yBAAyB,GAAC,EACvC,8FAA8F,EAC9F,qCAAqC,CACtC,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,yBAAyB;IAC7C,OAAO,kBAAkB,CACvB,4BAA4B,EAC5B,uBAAuB,EACvB,uGAAuG,EACvG,wCAAwC,CACzC,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,cAAc;IAClC,OAAO,kBAAkB,CACvB,IAAI,EACJ,GAAG,EAAE,mDAAQ,IAAI,GAAC,EAClB,4DAA4D,EAC5D,gBAAgB,CACjB,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,6BAA6B;IACjD,OAAO,kBAAkB,CACvB,4BAA4B,EAC5B,GAAG,EAAE,mDAAQ,4BAA4B,GAAC,EAC1C,2FAA2F,EAC3F,wCAAwC,CACzC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rawsql-ts/ztd-cli",
3
- "version": "0.15.0",
3
+ "version": "0.17.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,22 +22,31 @@
22
22
  "node": ">=20"
23
23
  },
24
24
  "dependencies": {
25
- "@testcontainers/postgresql": "^10.28.0",
26
25
  "chokidar": "^5.0.0",
27
26
  "commander": "^12.0.0",
28
- "diff": "^5.1.0",
27
+ "diff": "^8.0.3",
29
28
  "fast-glob": "^3.3.3",
30
- "pg": "^8.11.1",
31
- "testcontainers": "^10.28.0",
32
- "@rawsql-ts/pg-testkit": "0.15.0",
33
- "rawsql-ts": "0.15.0",
34
- "@rawsql-ts/testkit-core": "0.15.0"
29
+ "rawsql-ts": "^0.16.0"
30
+ },
31
+ "peerDependencies": {
32
+ "@rawsql-ts/adapter-node-pg": "^0.15.2"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@rawsql-ts/adapter-node-pg": {
36
+ "optional": true
37
+ }
35
38
  },
36
39
  "devDependencies": {
40
+ "@testcontainers/postgresql": "^10.28.0",
37
41
  "@types/diff": "^5.0.1",
38
42
  "@types/node": "^22.13.10",
43
+ "pg": "^8.11.1",
44
+ "testcontainers": "^10.28.0",
39
45
  "typescript": "^5.8.2",
40
- "vitest": "^4.0.7"
46
+ "vitest": "^4.0.7",
47
+ "@rawsql-ts/adapter-node-pg": "^0.15.2",
48
+ "@rawsql-ts/testkit-core": "^0.15.1",
49
+ "@rawsql-ts/testkit-postgres": "^0.15.1"
41
50
  },
42
51
  "files": [
43
52
  "dist",
@@ -46,7 +55,6 @@
46
55
  "README.md"
47
56
  ],
48
57
  "scripts": {
49
- "prebuild": "pnpm --filter @rawsql-ts/testkit-core build && pnpm --filter @rawsql-ts/pg-testkit build",
50
58
  "build": "tsc -p tsconfig.json",
51
59
  "test": "vitest run",
52
60
  "lint": "eslint src --ext .ts",
@@ -1,312 +1,52 @@
1
- # Appendix: Development Workflow Using Zero Table Dependency (ZTD)
1
+ # Workspace AGENTS
2
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:
3
+ This repository uses directory-scoped AGENTS.
4
+ Rules live close to where the work happens.
5
5
 
6
- - Maintaining consistent SQL across the project
7
- - Keeping schema, domain specifications, and enums synchronized
8
- - Ensuring deterministic SQL unit tests
9
- - Enabling structured collaboration between humans and AI
6
+ ## Rule precedence
10
7
 
11
- This section documents how ZTD is used inside this repository as a development methodology.
8
+ - The closest "AGENTS.md" to the file being edited has the highest priority.
9
+ - Parent directories provide shared rules.
10
+ - Child directories should only describe deltas.
12
11
 
13
- ---
12
+ ## Global non-negotiables
14
13
 
15
- ## Defaults (important)
14
+ - Do not guess. If something is unknown, state "Not observed" and propose the next check.
15
+ - Do not edit generated artifacts unless explicitly instructed.
16
+ - Respect ownership boundaries: human-owned contracts must not be changed without explicit instruction.
16
17
 
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`.
18
+ ## Runtime vs non-runtime
20
19
 
21
- ---
20
+ - Runtime assets live under "src/": executed/loaded by the application.
21
+ - Non-runtime assets live under "ztd/" and parts of "tests/": used for verification and generation.
22
22
 
23
- ## Generated files (important)
23
+ ## Human-owned vs AI-assisted (important)
24
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`.
25
+ Human-owned (do not change without explicit instruction):
26
+ - "ztd/ddl" (physical schema / DDL)
27
+ - "src/catalog/specs" (query contracts: params + DTO + semantics)
28
+ - "src/sql" (SQL assets; AI may propose patches, but do not rewrite intent)
28
29
 
29
- ---
30
+ AI-assisted (implementation and verification):
31
+ - "src/repositories"
32
+ - "src/catalog/runtime"
33
+ - "tests" (except "tests/generated")
30
34
 
31
- ## TypeScript validation (required)
35
+ Never touch by hand:
36
+ - "tests/generated"
32
37
 
33
- After any code change, TypeScript type checking **must** be performed and must pass.
38
+ ## Where to read next
34
39
 
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.
40
+ - "src/catalog/AGENTS.md": catalog layout and contract boundaries
41
+ - "src/repositories/AGENTS.md": repository responsibilities and restrictions
42
+ - "src/sql/AGENTS.md": SQL asset rules
43
+ - "tests/AGENTS.md": ZTD testing rules
44
+ - "ztd/ddl/AGENTS.md": DDL authoring rules
39
45
 
40
- Rationale:
41
- In ZTD-based development, many schema or SQL inconsistencies surface first as TypeScript errors via generated row maps and DTOs.
42
- Type checking is a primary correctness signal, not an optional step.
46
+ ## Test environment guarantee (important)
43
47
 
44
- ---
48
+ - This workspace MUST be test-runnable immediately after initialization.
49
+ - `pnpm test` (or equivalent) must not fail due to missing configuration.
50
+ - Test runner configuration (e.g. vitest.config.ts) is considered part of the template contract.
45
51
 
46
- ## ZTD Implementation Guide (src/)
47
-
48
- 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.
49
-
50
- ### Repository Classes: What to Care About
51
-
52
- #### Scope and Responsibility
53
- - Repository classes are responsible for executing SQL and returning query results.
54
- - Avoid embedding business logic, thresholds, or data reshaping inside repositories.
55
- - Treat repositories as thin adapters over SQL.
56
-
57
- #### Mandatory testing rule (important)
58
-
59
- Whenever a repository class is created or modified, corresponding tests **must** be created or updated.
60
-
61
- Rules:
62
- - Every public repository method must be covered by tests.
63
- - Tests must call repository methods, not raw SQL files or SQL strings.
64
- - ZTD fixtures are the only allowed source of database state in tests.
65
- - A repository change without tests is considered incomplete.
66
-
67
- Rationale:
68
- ZTD derives much of its value from deterministic, repository-level tests.
69
- Without tests, schema drift and SQL inconsistencies cannot be detected.
70
-
71
- #### SQL Management
72
- - Prefer keeping SQL in separate `.sql` files.
73
- - If no explicit instruction is given, separate SQL into files by default.
74
- - Repository classes should reference SQL files by name, not inline long SQL strings.
75
-
76
- #### Specifications and Documentation
77
- - If a markdown file with the same base name as the repository or SQL exists, read it before implementation.
78
- - Such files may contain repository-local specifications (e.g. decision tables, thresholds, request/response notes).
79
- - Naming should be aligned (e.g. `FooRepository.ts`, `foo.sql`, `foo.md`).
80
-
81
- #### Request and Response Contracts
82
- - Be explicit about request parameters (types, nullability, constraints).
83
- - Be explicit about response shape (columns, ordering, cardinality).
84
- - Prefer documenting contracts in the repository-local markdown file rather than code comments when they are non-trivial.
85
-
86
- ### SqlClient lifecycle policy (important)
87
-
88
- - When using `src/db/sql-client.ts`, prefer a shared `SqlClient` per worker process (singleton).
89
- - Avoid creating a new database connection for every query or test case.
90
- - Do not share a live connection across parallel workers; each worker should own its own shared client or pool.
91
- - If you need strict isolation, create a dedicated client for that scope and close it explicitly.
92
-
93
- ### Repository SQL and DTO policy (important)
94
-
95
- - Repository SQL must return application-facing DTO shapes.
96
- - SQL SELECT statements should alias columns to camelCase and match the repository return types.
97
- - Do not introduce intermediate `*Row` types when SQL already returns DTO-compatible shapes.
98
- - Define separate Row types only when SQL intentionally returns database-shaped (snake_case) rows, and always convert them explicitly.
99
-
100
- ### Sequence / identity column policy (important)
101
-
102
- - Sequence / identity columns (auto-generated IDs) are infrastructure concerns.
103
- - Do not explicitly assign values to sequence / identity columns in `INSERT` statements unless explicitly instructed.
104
- - Repository method inputs should omit sequence / identity columns by default.
105
- - Only treat an ID as input data when it represents a business rule (e.g. natural keys, externally assigned IDs).
106
-
107
- ### No test-driven fallbacks in production code (important)
108
-
109
- - Do not add fallbacks in `src/` that exist only to accommodate ZTD/testkit/rewriter limitations.
110
- - If a query fails to be rewritten into ZTD form, do not change runtime behavior to compensate.
111
- - Report tooling issues with minimal reproduction and expected behavior.
112
-
113
- Rationale:
114
- Production code must not diverge from intended SQL semantics due to tooling constraints.
115
-
116
- ---
117
-
118
- ## ZTD Test Guide (tests/)
119
-
120
- Testing under ZTD follows dedicated, directory-scoped rules.
121
-
122
- - Test design, execution mode selection, and constraints are defined in:
123
- - `templates/tests/AGENTS.md`
124
- - Tests validate repository behavior and returned DTOs.
125
- - Raw SQL files or SQL strings must not be tested directly.
126
-
127
- ---
128
-
129
- # ZTD Directory Layout
130
-
131
- ```
132
- /ztd
133
- /ddl
134
- *.sql <- physical schema definitions
135
-
136
- /domain-specs
137
- *.md <- one behavioral SELECT per file (one SQL block)
138
-
139
- /enums
140
- *.md <- one enum definition per file (one SQL block)
141
-
142
- README.md <- documentation for the layout
143
- AGENTS.md <- combined guidance for DDL, enums, and specs
144
-
145
- /src <- application & repository logic
146
- /tests <- ZTD tests, fixtures, row-maps
147
- ```
148
-
149
- The file `tests/generated/ztd-layout.generated.ts` ensures ZTD CLI always points to the correct directories.
150
-
151
- ---
152
-
153
- # Protected directories and edit ownership (important)
154
-
155
- - DDL editing is human-led: `ztd/ddl/`
156
- - Domain specs editing is human-led: `ztd/domain-specs/`
157
- - Enums editing is human-led: `ztd/enums/`
158
- - Application code is shared ownership: `src/`
159
- - Tests are shared ownership: `tests/`
160
- - Detailed test constraints live in `templates/tests/AGENTS.md`.
161
-
162
- Additionally:
163
- - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction.
164
- - When changes are required in human-led directories, prefer proposing a patch and explaining the impact before applying it.
165
-
166
- ---
167
-
168
- # Principles of ZTD in This Repository
169
-
170
- ### 1. Humans own the definitions
171
- - Physical schema (DDL)
172
- - Domain semantics (domain-specs)
173
- - Enumerations (enums)
174
- - Repository interfaces
175
-
176
- ### 2. AI assists with implementation
177
- - Generating repository SQL
178
- - Updating fixtures
179
- - Producing intermediate TypeScript structures
180
- - Ensuring SQL adheres to DDL, enums, and domain-specs
181
-
182
- ### 3. ZTD enforces consistency
183
- ZTD tests verify that:
184
- - SQL logic matches DDL shapes
185
- - SQL semantics match domain-specs
186
- - SQL values match enumerations
187
-
188
- If anything diverges, ZTD failures surface immediately and deterministically.
189
-
190
- ---
191
-
192
- # Development Workflows
193
-
194
- Different types of changes start from different entry points. Use the workflow appropriate for your situation.
195
-
196
- ---
197
-
198
- # Workflow A - Starting From DDL Changes
199
- Modifying tables, columns, constraints, indexes.
200
-
201
- 1. Edit DDL files in `ztd/ddl/`.
202
- 2. Run `npx ztd ztd-config`.
203
- 3. Update repository SQL to match the new schema.
204
- 4. Update fixtures if result shapes changed.
205
- 5. Run tests.
206
-
207
- Flow: DDL to Repository SQL to Fixtures and Tests to Application
208
-
209
- ---
210
-
211
- # Workflow B - Starting From Repository Interface Changes
212
- Changing method signatures, adding new repository methods, etc.
213
-
214
- 1. Modify the repository interface or implementation in `/src`.
215
- 2. Use AI assistance to generate or update the SQL implementation.
216
- 3. If the generated SQL conflicts with domain-specs or enums, update definitions first.
217
- 4. Run ZTD tests.
218
- 5. Regenerate config if SQL output shape changed.
219
-
220
- Flow: Interface to SQL to Specs (if needed) to Tests
221
-
222
- ---
223
-
224
- # Workflow C - Starting From Repository SQL Logic Changes
225
- Bug fixes, refactoring, rewriting queries.
226
-
227
- 1. Edit SQL inside the repository.
228
- 2. Run ZTD tests.
229
- 3. If intended behavior changes, update the appropriate file in `ztd/domain-specs/`.
230
- 4. Update fixtures as needed.
231
- 5. Regenerate config if result shape changed.
232
-
233
- Flow: SQL to Domain-specs to Tests
234
-
235
- ---
236
-
237
- # Workflow D - Starting From Enum or Domain Specification Changes
238
- Business rule changes or conceptual model updates.
239
-
240
- Flow: Specs or Enums to SQL to Tests to (DDL if required)
241
-
242
- ---
243
-
244
- # Combined Real-World Examples
245
-
246
- - Adding a new contract state:
247
- enums to domain-spec to SQL to config to tests
248
-
249
- - Adding a new table:
250
- DDL to config to SQL to fixtures to tests
251
-
252
- - Fixing business logic:
253
- SQL to domain-spec to tests
254
-
255
- ZTD ensures the development always converges into a consistent, validated workflow.
256
-
257
- ---
258
-
259
- # Human Responsibilities
260
-
261
- Humans maintain:
262
-
263
- - Schema definitions (`ztd/ddl`)
264
- - Domain logic definitions (`ztd/domain-specs`)
265
- - Domain enumerations (`ztd/enums`)
266
- - Repository interfaces and architectural decisions
267
- - Acceptance and review of AI-generated patches
268
-
269
- Humans decide what is correct.
270
-
271
- ---
272
-
273
- # AI Responsibilities
274
-
275
- AI must:
276
-
277
- - Use domain-specs as the semantic source of truth
278
- - Use enums as the canonical vocabulary source
279
- - Use DDL as the physical structure constraint
280
- - Generate SQL consistent with all definitions
281
- - Update fixtures when needed
282
- - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction
283
-
284
- AI decides how to implement, but not what is correct.
285
-
286
- ---
287
-
288
- # ZTD CLI Responsibilities
289
-
290
- ZTD CLI:
291
-
292
- - Parses DDL to compute schema shapes
293
- - Rewrites SQL via CTE shadowing for testing
294
- - Generates `ztd-row-map.generated.ts`
295
- - Enables deterministic, parallel SQL unit tests
296
-
297
- ZTD is the verification engine that validates correctness beyond static typing.
298
-
299
- ---
300
-
301
- # Summary
302
-
303
- This appendix documents how ZTD is used strictly as an internal implementation and maintenance guide.
304
- It does not affect the runtime behavior of the application.
305
- Its purpose is ensuring:
306
-
307
- - Schema integrity
308
- - SQL correctness
309
- - Domain consistency
310
- - Reliable AI-assisted development
311
-
312
- With ZTD, humans define the meaning, AI writes the implementation, and tests guarantee correctness.
52
+ If tests fail due to missing config, this is a template defect, not a user error.