@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.
- package/README.md +25 -11
- package/dist/commands/init.js +27 -10
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.d.ts +59 -0
- package/dist/commands/lint.js +338 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/sqlLintHelpers.d.ts +18 -0
- package/dist/utils/sqlLintHelpers.js +270 -0
- package/dist/utils/sqlLintHelpers.js.map +1 -0
- package/package.json +11 -4
- package/templates/AGENTS.md +95 -53
- package/templates/README.md +45 -67
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +38 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +117 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +4 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +71 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/index.d.ts +5 -0
- package/templates/dist/drivers/pg-testkit/src/index.js +11 -0
- package/templates/dist/drivers/pg-testkit/src/index.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +3 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +79 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/types.d.ts +69 -0
- package/templates/dist/drivers/pg-testkit/src/types.js +3 -0
- package/templates/dist/drivers/pg-testkit/src/types.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +15 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +34 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +12 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +53 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +1 -0
- package/templates/dist/mapper-core/src/index.d.ts +160 -0
- package/templates/dist/mapper-core/src/index.js +637 -0
- package/templates/dist/mapper-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/errors/index.d.ts +49 -0
- package/templates/dist/testkit-core/src/errors/index.js +111 -0
- package/templates/dist/testkit-core/src/errors/index.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +5 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +29 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +37 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +182 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +20 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +121 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +51 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +199 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +10 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +28 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +18 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +80 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +59 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js +489 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.d.ts +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js +6 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js.map +1 -0
- package/templates/dist/testkit-core/src/index.d.ts +17 -0
- package/templates/dist/testkit-core/src/index.js +47 -0
- package/templates/dist/testkit-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +8 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js +16 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +1 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +57 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js +149 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +43 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +473 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +9 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +38 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +42 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +298 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +12 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +63 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +1 -0
- package/templates/dist/testkit-core/src/types/index.d.ts +69 -0
- package/templates/dist/testkit-core/src/types/index.js +3 -0
- package/templates/dist/testkit-core/src/types/index.js.map +1 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +28 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js +81 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +1 -0
- package/templates/dist/writer-core/src/index.d.ts +34 -0
- package/templates/dist/writer-core/src/index.js +115 -0
- package/templates/dist/writer-core/src/index.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js +3 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +36 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +85 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +33 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +10 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +66 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +552 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +82 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +7 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +10 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +1 -0
- package/templates/src/db/sql-client.ts +1 -1
- package/templates/src/repositories/user-accounts.ts +179 -0
- package/templates/tests/AGENTS.md +59 -6
- package/templates/tests/support/global-setup.ts +1 -1
- package/templates/tests/support/testkit-client.ts +4 -4
- package/templates/tests/user-profiles.test.ts +161 -0
- package/templates/tests/writer-constraints.test.ts +32 -0
- package/templates/tests/ztd-layout.generated.ts +0 -2
- package/templates/tsconfig.json +1 -2
- package/templates/ztd/AGENTS.md +10 -85
- package/templates/ztd/README.md +10 -79
package/templates/ztd/AGENTS.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# AGENTS: Zero Table Dependency Definitions
|
|
2
2
|
|
|
3
3
|
This file defines **protected, human-led domains** under the `ztd/` directory.
|
|
4
4
|
AI must treat these directories as authoritative sources of truth and must not modify them without explicit instruction.
|
|
5
|
+
These rules govern the `ztd/` contents after project initialization and apply regardless of mapper, writer, or runtime architecture decisions.
|
|
5
6
|
|
|
6
7
|
---
|
|
7
8
|
|
|
@@ -10,6 +11,7 @@ AI must treat these directories as authoritative sources of truth and must not m
|
|
|
10
11
|
- `tests/generated/` is auto-generated and must never be committed.
|
|
11
12
|
- After cloning the repository (or in a clean environment), run `npx ztd ztd-config`.
|
|
12
13
|
- If TypeScript reports missing modules or type errors because `tests/generated/` is missing, run `npx ztd ztd-config`.
|
|
14
|
+
- Generated artifacts exist solely to support validation and testing and MUST NEVER influence definitions under `ztd/`.
|
|
13
15
|
|
|
14
16
|
---
|
|
15
17
|
|
|
@@ -45,105 +47,28 @@ It is the **single source of truth** for the physical database schema as interpr
|
|
|
45
47
|
- When asked to extend existing definitions:
|
|
46
48
|
- Do not remove or rewrite existing columns or comments unless explicitly told.
|
|
47
49
|
- Maintain column order and constraint style.
|
|
48
|
-
- Do not introduce schema changes that conflict with
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
- Do not introduce schema changes that conflict with existing constraints or indexes.
|
|
51
|
+
- The `public.user_account` and `public.user_profile` tables exist to support the mapper/writer sample; any modification to those tables is a maintenance obligation that requires concurrent updates to `src/repositories/user-accounts.ts` and `tests/writer-constraints.test.ts` so the workflow keeps functioning.
|
|
52
|
+
- DDL defines physical truth only and MUST NEVER be reshaped to accommodate mapper, writer, or test tooling.
|
|
53
|
+
- Runtime convenience is never a valid reason to alter DDL.
|
|
51
54
|
|
|
52
55
|
If there is uncertainty, stop and request clarification instead of guessing.
|
|
53
56
|
|
|
54
57
|
---
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
You are an AI agent that **reads** domain specifications to understand business semantics.
|
|
59
|
-
|
|
60
|
-
### Purpose
|
|
61
|
-
|
|
62
|
-
Each file in this directory defines **one domain behavior**.
|
|
63
|
-
These files explain *what the data means*, not how the application is implemented.
|
|
64
|
-
|
|
65
|
-
### Instructions
|
|
66
|
-
|
|
67
|
-
- Treat each Markdown file as defining exactly **one behavior**.
|
|
68
|
-
- Use the embedded SQL block as the **reference SELECT**.
|
|
69
|
-
- Only the first top-level SQL block is executable logic.
|
|
70
|
-
- Parameters may be written as `:named` placeholders.
|
|
71
|
-
- When generating executable SQL, bind them as positional placeholders (`$1`, `$2`, `?`).
|
|
72
|
-
- **Never modify files in this directory unless explicitly instructed.**
|
|
73
|
-
|
|
74
|
-
### Rules (strict)
|
|
75
|
-
|
|
76
|
-
- Never ignore the human-written explanation above the SQL block.
|
|
77
|
-
- Keep exactly one executable SQL block per file.
|
|
78
|
-
- Do not reorder, optimize, or “simplify” SQL unless explicitly instructed.
|
|
79
|
-
- Preserve the exact semantics described by humans.
|
|
80
|
-
- This directory defines **what is correct behavior**.
|
|
81
|
-
- Your role is to reproduce that behavior elsewhere (`src/`, `tests/`), not reinterpret it.
|
|
82
|
-
|
|
83
|
-
If meaning is ambiguous, defer to human judgment and ask.
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Domain Enums (`ztd/enums/`)
|
|
88
|
-
|
|
89
|
-
You are an AI assistant responsible for **reading and using** domain enum definitions.
|
|
90
|
-
|
|
91
|
-
### Purpose
|
|
92
|
-
|
|
93
|
-
This directory defines canonical value sets such as:
|
|
94
|
-
|
|
95
|
-
- Status codes
|
|
96
|
-
- Category types
|
|
97
|
-
- Plan tiers
|
|
98
|
-
|
|
99
|
-
These enums are the **only allowed vocabulary** for such concepts.
|
|
100
|
-
|
|
101
|
-
### Behavior Guidelines (strict)
|
|
102
|
-
|
|
103
|
-
- Never invent enum values.
|
|
104
|
-
- Never hardcode magic numbers or strings.
|
|
105
|
-
- Never modify or add enum definitions unless explicitly instructed by a human.
|
|
106
|
-
|
|
107
|
-
### SQL Rules
|
|
108
|
-
|
|
109
|
-
- Each file contains exactly one executable SQL block.
|
|
110
|
-
- Enum definitions follow this canonical pattern:
|
|
111
|
-
|
|
112
|
-
```sql
|
|
113
|
-
select v.*
|
|
114
|
-
from (
|
|
115
|
-
values
|
|
116
|
-
(1, 'some_code', 'some_label')
|
|
117
|
-
) v(key, value, display_name);
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
- `key` and `value` are authoritative.
|
|
121
|
-
- Additional columns (e.g. `display_name`, `ranking`) may be used for:
|
|
122
|
-
- UI display
|
|
123
|
-
- Sorting
|
|
124
|
-
- Documentation
|
|
125
|
-
|
|
126
|
-
### Use in Code Generation
|
|
127
|
-
|
|
128
|
-
- Always reference enums when generating:
|
|
129
|
-
- SQL WHERE conditions
|
|
130
|
-
- Constants
|
|
131
|
-
- Conditional logic
|
|
132
|
-
- When translating logic from `ztd/domain-specs`, resolve enum references through this directory.
|
|
133
|
-
- Maintain full consistency with naming and intent.
|
|
134
|
-
|
|
135
|
-
If a required enum does not exist, stop and ask for human clarification.
|
|
59
|
+
- Only `ztd/ddl` is part of the canonical `ztd` contract; do not create or assume additional subdirectories without explicit human direction.
|
|
136
60
|
|
|
137
61
|
---
|
|
138
62
|
|
|
139
63
|
## Absolute Restrictions (important)
|
|
140
64
|
|
|
141
65
|
- AI must not modify anything under `ztd/` by default.
|
|
142
|
-
- DDL
|
|
66
|
+
- DDL is the only **human-led artifact** in this directory.
|
|
143
67
|
- AI may assist by:
|
|
144
68
|
- Reading
|
|
145
69
|
- Explaining
|
|
146
70
|
- Proposing diffs
|
|
147
71
|
- AI may apply changes **only** with explicit instruction.
|
|
72
|
+
- No tooling limitation, test strategy, or runtime design justifies modifying `ztd/` artifacts.
|
|
148
73
|
|
|
149
74
|
Violation of these rules leads to silent corruption of domain meaning and is unacceptable.
|
package/templates/ztd/README.md
CHANGED
|
@@ -1,84 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
# ZTD Definitions
|
|
2
2
|
|
|
3
|
-
This directory hosts the schema
|
|
3
|
+
This directory hosts the schema definitions under `ztd/ddl/`. Every DDL file in that folder is the single source of truth for database objects; parser tools and tests read these files to learn table structures, columns, indexes, and constraints.
|
|
4
4
|
|
|
5
|
-
## DDL
|
|
5
|
+
## DDL Guidelines
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Place every schema definition under `ztd/ddl/` with valid PostgreSQL and semicolon-terminated statements.
|
|
8
|
+
- Keep the files deterministic: avoid generated output, enforce column ordering, and document any non-obvious constraints with comments.
|
|
9
|
+
- When you rename or drop a column, update the corresponding DDL file rather than trying to patch test artifacts manually.
|
|
10
|
+
- Treat `ztd/ddl/` as a human-maintained catalog; AI may assist but must not invent or diverge from the files stored there.
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
## Workflow expectations
|
|
10
13
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
### File Format and Execution
|
|
15
|
-
|
|
16
|
-
- **Executable SQL Scripts:** Every file should be valid PostgreSQL with semicolon-terminated statements and a consistent dependency ordering.
|
|
17
|
-
- **Integration with ZTD CLI:** The CLI parses these files to understand schema shapes. Treat this directory as authoritative: every schema change should be captured here as if it were applied to a clean database.
|
|
18
|
-
|
|
19
|
-
### Maintenance Guidelines
|
|
20
|
-
|
|
21
|
-
- **Human-Maintained Schema:** Developers own the schema structure; AI tooling may only assist with targeted edits.
|
|
22
|
-
- **Conventions:** Follow the established naming, formatting, and typing patterns. Include comments to explain non-obvious schema choices.
|
|
23
|
-
|
|
24
|
-
### Relationships
|
|
25
|
-
|
|
26
|
-
- /ztd/domain-specs: Translates schema structures into behavioral expectations.
|
|
27
|
-
- /ztd/enums: Provides the enum sets referenced by constraints or column defaults.
|
|
28
|
-
|
|
29
|
-
## Domain Specifications
|
|
30
|
-
|
|
31
|
-
The ztd/domain-specs/ directory documents key domain behaviors as human-readable specifications.
|
|
32
|
-
|
|
33
|
-
### Purpose
|
|
34
|
-
|
|
35
|
-
Each Markdown file describes one business concept, explains it in natural language, and pairs it with an example SELECT query inside a fenced SQL block. These specifications help AI agents understand **what** the domain logic should do without prescribing implementation details.
|
|
36
|
-
|
|
37
|
-
### Format and Best Practices
|
|
38
|
-
|
|
39
|
-
- One file per concept with a prose explanation followed by an example SELECT.
|
|
40
|
-
- Keep exactly one executable SQL block per file (one file = one behavior).
|
|
41
|
-
- Named parameters (e.g., :as_of) signal intent; you may translate them into positional placeholders when generating code.
|
|
42
|
-
- Focus on semantics—use Markdown structuring (tables, bullets, etc.) to clarify the behavior.
|
|
43
|
-
- Always update the description before touching the SQL when the behavior evolves.
|
|
44
|
-
|
|
45
|
-
### Relationships
|
|
46
|
-
|
|
47
|
-
- /ztd/ddl: Supplies the physical schema that backs the behavior.
|
|
48
|
-
- /ztd/enums: Provides the vocabularies referenced in the domain logic.
|
|
49
|
-
|
|
50
|
-
## Domain Enums
|
|
51
|
-
|
|
52
|
-
The ztd/enums/ directory contains enumerated value sets such as statuses, tiers, or lifecycle states.
|
|
53
|
-
|
|
54
|
-
### Purpose
|
|
55
|
-
|
|
56
|
-
These enums are human-maintained and support:
|
|
57
|
-
|
|
58
|
-
- AI-assisted SQL/code generation
|
|
59
|
-
- TypeScript constant generation
|
|
60
|
-
- Schema enforcement (e.g., CHECK constraints)
|
|
61
|
-
- Frontend label rendering via display names
|
|
62
|
-
|
|
63
|
-
### Format and Structure
|
|
64
|
-
|
|
65
|
-
- The folder uses Markdown to keep the definitions readable.
|
|
66
|
-
- Each enum is documented in a single file using SELECT ... FROM (VALUES ...) blocks with explicit column aliases.
|
|
67
|
-
|
|
68
|
-
### Required Structure
|
|
69
|
-
|
|
70
|
-
- Each row must include at least key and value columns.
|
|
71
|
-
- Optional metadata like display_name,
|
|
72
|
-
ranking, or sort_order may be added for UI/logic purposes.
|
|
73
|
-
|
|
74
|
-
### Guidelines
|
|
75
|
-
|
|
76
|
-
- Keep naming conventions consistent and avoid duplicate value identifiers across unrelated enums.
|
|
77
|
-
- Ensure compatibility with /ztd/domain-specs and /ztd/ddl when expanding enums.
|
|
78
|
-
- Preserve human-readable display_name values as needed for front-end contexts.
|
|
79
|
-
|
|
80
|
-
### Relationships
|
|
81
|
-
|
|
82
|
-
- /ztd/ddl: Referenced by constraints or lookup tables.
|
|
83
|
-
- /ztd/domain-specs: Provides the vocabulary for behavioral rules.
|
|
84
|
-
- src/: Maps enums to generated constants or query logic.
|
|
14
|
+
- Regenerate `tests/generated/ztd-row-map.generated.ts` via `npx ztd ztd-config` whenever the DDL changes.
|
|
15
|
+
- Do not assume any other subdirectories under `/ztd` exist unless a human has explicitly created them for a specific purpose.
|