@rawsql-ts/ztd-cli 0.16.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.
- package/README.md +33 -20
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.js +372 -127
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.d.ts +4 -4
- package/dist/commands/lint.js +60 -40
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/ztdConfig.d.ts +2 -2
- package/dist/commands/ztdConfig.js +26 -12
- package/dist/commands/ztdConfig.js.map +1 -1
- package/dist/utils/optionalDependencies.d.ts +35 -0
- package/dist/utils/optionalDependencies.js +96 -0
- package/dist/utils/optionalDependencies.js.map +1 -0
- package/package.json +16 -9
- package/templates/AGENTS.md +36 -309
- package/templates/README.md +12 -215
- package/templates/dist/ztd-cli/templates/src/db/sql-client.ts +24 -0
- package/templates/src/AGENTS.md +26 -0
- package/templates/src/catalog/AGENTS.md +37 -0
- package/templates/src/catalog/runtime/AGENTS.md +75 -0
- package/templates/src/catalog/runtime/_coercions.ts +1 -0
- package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
- package/templates/src/catalog/specs/AGENTS.md +48 -0
- package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
- package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
- package/templates/src/db/sql-client.ts +5 -5
- package/templates/src/jobs/AGENTS.md +26 -0
- package/templates/src/jobs/README.md +3 -0
- package/templates/src/repositories/AGENTS.md +118 -0
- package/templates/src/repositories/tables/AGENTS.md +94 -0
- package/templates/src/repositories/tables/README.md +3 -0
- package/templates/src/repositories/views/AGENTS.md +25 -0
- package/templates/src/repositories/views/README.md +3 -0
- package/templates/src/sql/AGENTS.md +77 -0
- package/templates/src/sql/README.md +6 -0
- package/templates/tests/AGENTS.md +43 -150
- package/templates/tests/generated/AGENTS.md +16 -0
- package/templates/tests/smoke.test.ts +5 -0
- package/templates/tests/smoke.validation.test.ts +34 -0
- package/templates/tests/support/AGENTS.md +26 -0
- package/templates/tests/support/global-setup.ts +8 -23
- package/templates/tests/support/testkit-client.ts +13 -741
- package/templates/tsconfig.json +8 -1
- package/templates/ztd/AGENTS.md +11 -67
- package/templates/ztd/README.md +4 -13
- package/templates/ztd/ddl/AGENTS.md +34 -0
- package/templates/ztd/ddl/demo.sql +74 -0
- package/templates/src/repositories/user-accounts.ts +0 -179
- package/templates/tests/user-profiles.test.ts +0 -161
- package/templates/tests/writer-constraints.test.ts +0 -32
package/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Scaffold **Zero Table Dependency (ZTD)** projects and keep DDL-derived test types in sync.
|
|
4
4
|
|
|
5
|
-
`@rawsql-ts/ztd-cli` does **not** execute SQL
|
|
5
|
+
`@rawsql-ts/ztd-cli` does **not** execute SQL by itself. It provides an adapter-neutral core that scaffolds a ZTD-ready development environment.
|
|
6
|
+
To actually run ZTD tests, you plug in a database adapter (driver-specific) and a DBMS-specific testkit (for example, `@rawsql-ts/adapter-node-pg` plus `@rawsql-ts/testkit-postgres` for Postgres).
|
|
6
7
|
|
|
7
8
|
## Install
|
|
8
9
|
|
|
@@ -10,13 +11,16 @@ Scaffold **Zero Table Dependency (ZTD)** projects and keep DDL-derived test type
|
|
|
10
11
|
pnpm add -D @rawsql-ts/ztd-cli
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
To run ZTD-style tests, install:
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```
|
|
16
|
+
* a **database adapter** (driver-specific) to execute SQL, and
|
|
17
|
+
* a **DBMS-specific testkit** to handle fixture resolution, query rewriting, and result validation.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
For Postgres, the typical ZTD setup is:
|
|
20
|
+
`@rawsql-ts/adapter-node-pg` (driver adapter) +
|
|
21
|
+
`@rawsql-ts/testkit-postgres` (Postgres-specific testkit).
|
|
22
|
+
|
|
23
|
+
If you run `npx ztd init`, the CLI will install the Postgres driver/testkit stack plus `@rawsql-ts/sql-contract`, and it will always prompt you to select a validator backend (Zod or ArkType). The wizard keeps the required workflow documented in the recipes under `docs/recipes/` (e.g., `docs/recipes/sql-contract.md`, `docs/recipes/validation-zod.md`, and `docs/recipes/validation-arktype.md`), so the implementation path stays centralized and version-controlled.
|
|
20
24
|
|
|
21
25
|
Then use the CLI through `npx ztd` or the installed `ztd` bin.
|
|
22
26
|
|
|
@@ -43,6 +47,12 @@ Then use the CLI through `npx ztd` or the installed `ztd` bin.
|
|
|
43
47
|
|
|
44
48
|
Use `--with-app-interface` to append the application interface guidance block to `AGENTS.md` without generating the ZTD layout or touching other files.
|
|
45
49
|
|
|
50
|
+
```bash
|
|
51
|
+
npx ztd init --yes
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Use `--yes` to overwrite existing scaffold files without prompting (useful for non-interactive runs).
|
|
55
|
+
|
|
46
56
|
2. Put your schema into `ztd/ddl/`:
|
|
47
57
|
|
|
48
58
|
- Edit the starter file (default): `ztd/ddl/public.sql`, or
|
|
@@ -82,7 +92,10 @@ You can introduce ZTD incrementally; existing tests and ORMs can remain untouche
|
|
|
82
92
|
- `AGENTS.md` (copied from the package template unless the project already has one; `--with-app-interface` adds the application interface guidance block at the end)
|
|
83
93
|
- `ztd/AGENTS.md` and `ztd/README.md` (folder-specific instructions that describe the new schema/domain layout)
|
|
84
94
|
- `src/db/sql-client.ts` (optional; generated only with `--with-sqlclient`)
|
|
85
|
-
-
|
|
95
|
+
- `src/sql/views/README.md` + `src/sql/jobs/README.md` (SQL file structure)
|
|
96
|
+
- `src/repositories/views/README.md` + `src/repositories/tables/README.md` (repository structure)
|
|
97
|
+
- `src/jobs/README.md` (job runner structure)
|
|
98
|
+
- Example view SQL/repository and job SQL/runner files for the sample schema
|
|
86
99
|
|
|
87
100
|
The resulting project follows the "DDL -> ztd-config -> tests" flow so you can regenerate everything from SQL-first artifacts.
|
|
88
101
|
|
|
@@ -169,27 +182,27 @@ npx ztd lint path/to/query.sql
|
|
|
169
182
|
```
|
|
170
183
|
|
|
171
184
|
- Accepts a single `.sql` file, glob pattern, or directory (directories expand to `**/*.sql`).
|
|
172
|
-
-
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
-
|
|
185
|
+
- Resolves `ZTD_LINT_DATABASE_URL` or `DATABASE_URL` for the database connection. When no URL is configured, it loads `@testcontainers/postgresql` (if installed) to spin up a temporary Postgres container.
|
|
186
|
+
- Dynamically loads the registered adapter (for example `@rawsql-ts/adapter-node-pg` plus `@rawsql-ts/testkit-postgres`) so the rewritten statement is inspected through the fixture pipeline before it runs.
|
|
187
|
+
- Executes each rewritten query using `PREPARE ... AS ...` (falling back to `EXPLAIN`) so Postgres (or your adapter) performs the same parsing/type resolution used in tests.
|
|
188
|
+
- Reports the file path, location, error code/message/detail/hint, and a caret-marked excerpt to make fixes actionable before running tests.
|
|
189
|
+
- Override the database image with `ZTD_LINT_DB_IMAGE` (default `postgres:16-alpine`), or supply a URL to reuse an existing server instead of a container.
|
|
190
|
+
- If the adapter is missing, the command stops early with an error that points you at the adapter package to install or instructs you to set `DATABASE_URL`.
|
|
176
191
|
|
|
177
192
|
## ZTD Testing
|
|
178
193
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
The driver sits downstream of `testkit-core` and applies the rewrite + fixture pipeline before running any database interaction. Install the driver, configure it in your tests, and point it at the row map from `tests/generated/ztd-row-map.generated.ts`.
|
|
194
|
+
The generated `tests/support/testkit-client.ts` is a stub. Replace `createTestkitClient` with a factory that returns an object conforming to `SqlClient` (defined in `src/db/sql-client.ts`). Use it to wire your preferred adapter (for example a Postgres adapter, a mock data source, or a fixture helper) before running the repository tests.
|
|
182
195
|
|
|
183
|
-
|
|
196
|
+
ZTD rewrites every statement into a fixture-friendly shape and expects your adapter to execute the rewritten SQL using the metadata under `tests/generated/ztd-row-map.generated.ts`. The CLI avoids bundling a driver so you can choose whatever stack fits your project; install the necessary adapter package and point it at the generated row map before executing DB-backed suites.
|
|
184
197
|
|
|
185
|
-
|
|
198
|
+
### SQL rewrite logging
|
|
186
199
|
|
|
187
|
-
|
|
200
|
+
If you need to inspect the rewritten SQL, add logging inside your adapter or within `tests/support/testkit-client.ts`. There is no built-in logger in the template, but you can guard logging with environment variables such as:
|
|
188
201
|
|
|
189
|
-
- `ZTD_SQL_LOG=1`
|
|
190
|
-
- `ZTD_SQL_LOG_PARAMS=1`
|
|
202
|
+
- `ZTD_SQL_LOG=1` or `true`: log the raw SQL plus the rewritten statement.
|
|
203
|
+
- `ZTD_SQL_LOG_PARAMS=1` or `true`: include query parameters in the emitted logs.
|
|
191
204
|
|
|
192
|
-
|
|
205
|
+
Add any adapter-specific options or helpers to control logging per call (for example, guard logging with your own `ZtdSqlLogOptions` type) so the test outputs remain deterministic when logging is disabled.
|
|
193
206
|
|
|
194
207
|
## Benchmark summary
|
|
195
208
|
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ type PackageInstallKind = 'devDependencies' | 'install';
|
|
|
9
9
|
export interface Prompter {
|
|
10
10
|
selectChoice(question: string, choices: string[]): Promise<number>;
|
|
11
11
|
promptInput(question: string, example?: string): Promise<string>;
|
|
12
|
+
promptInputWithDefault(question: string, defaultValue: string, example?: string): Promise<string>;
|
|
12
13
|
confirm(question: string): Promise<boolean>;
|
|
13
14
|
close(): void;
|
|
14
15
|
}
|
|
@@ -57,10 +58,22 @@ export interface InitCommandOptions {
|
|
|
57
58
|
dependencies?: Partial<ZtdConfigWriterDependencies>;
|
|
58
59
|
withSqlClient?: boolean;
|
|
59
60
|
withAppInterface?: boolean;
|
|
61
|
+
forceOverwrite?: boolean;
|
|
62
|
+
nonInteractive?: boolean;
|
|
60
63
|
}
|
|
61
64
|
/**
|
|
62
65
|
* Run the interactive `ztd init` workflow and return the resulting summary.
|
|
63
66
|
*/
|
|
64
67
|
export declare function runInitCommand(prompter: Prompter, options?: InitCommandOptions): Promise<InitResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Normalizes a schema identifier into the canonical lowercase form used by ztd-cli file naming.
|
|
70
|
+
* Empty input falls back to the configured default schema.
|
|
71
|
+
*/
|
|
72
|
+
export declare function normalizeSchemaName(value: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Sanitizes a normalized schema identifier so it can be used as a filesystem-safe file stem.
|
|
75
|
+
* Returns `schema` when all characters are stripped by sanitization.
|
|
76
|
+
*/
|
|
77
|
+
export declare function sanitizeSchemaFileName(schemaName: string): string;
|
|
65
78
|
export declare function registerInitCommand(program: Command): void;
|
|
66
79
|
export {};
|