@rawsql-ts/ztd-cli 0.13.2 → 0.14.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 +163 -2
- package/dist/commands/init.d.ts +11 -0
- package/dist/commands/init.js +282 -16
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/ztdConfig.d.ts +2 -1
- package/dist/commands/ztdConfig.js +12 -0
- package/dist/commands/ztdConfig.js.map +1 -1
- package/dist/commands/ztdConfigCommand.js +17 -6
- package/dist/commands/ztdConfigCommand.js.map +1 -1
- package/dist/utils/agents.js +19 -2
- package/dist/utils/agents.js.map +1 -1
- package/dist/utils/normalizePulledSchema.js +12 -0
- package/dist/utils/normalizePulledSchema.js.map +1 -1
- package/dist/utils/ztdProjectConfig.d.ts +3 -0
- package/dist/utils/ztdProjectConfig.js +7 -1
- package/dist/utils/ztdProjectConfig.js.map +1 -1
- package/package.json +7 -3
- package/templates/.editorconfig +16 -0
- package/templates/.prettierignore +2 -0
- package/templates/.prettierrc +24 -0
- package/templates/AGENTS.md +326 -0
- package/templates/README.md +239 -0
- package/templates/src/db/sql-client.ts +24 -0
- package/templates/tests/support/global-setup.ts +30 -0
- package/templates/tests/support/testkit-client.ts +742 -0
- package/templates/tests/ztd-layout.generated.ts +8 -0
- package/templates/tsconfig.json +9 -0
- package/templates/vitest.config.ts +13 -0
- package/templates/ztd/AGENTS.md +103 -0
- package/templates/ztd/README.md +84 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
include: ['tests/**/*.test.ts'],
|
|
6
|
+
environment: 'node',
|
|
7
|
+
globals: true,
|
|
8
|
+
globalSetup: ['tests/support/global-setup.ts'],
|
|
9
|
+
// Starting a Postgres testcontainer can exceed the default 5s timeout on some machines.
|
|
10
|
+
testTimeout: 60_000,
|
|
11
|
+
hookTimeout: 60_000,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# AGENTS: Zero Table Dependency Definitions
|
|
2
|
+
|
|
3
|
+
## Generated files (important)
|
|
4
|
+
|
|
5
|
+
- `tests/generated/` is auto-generated and must never be committed.
|
|
6
|
+
- After cloning the repository (or in a clean environment), run `npx ztd ztd-config`.
|
|
7
|
+
- If TypeScript reports missing modules or type errors because `tests/generated/` is missing, run `npx ztd ztd-config`.
|
|
8
|
+
|
|
9
|
+
## DDL Specifications
|
|
10
|
+
|
|
11
|
+
You are an AI assistant responsible for reading and respecting the contents of this /ztd/ddl directory.
|
|
12
|
+
|
|
13
|
+
### Purpose
|
|
14
|
+
|
|
15
|
+
This directory contains all canonical definitions of database structure, including CREATE TABLE, ALTER TABLE, constraints, and indexes. It is considered the **single source of truth** for database schema as interpreted by the ztd-cli.
|
|
16
|
+
|
|
17
|
+
### Behavior Rules
|
|
18
|
+
|
|
19
|
+
- **Never modify files in this folder unless explicitly instructed by a human.**
|
|
20
|
+
- You may propose edits, reviews, or new DDL structures when asked, but you must preserve all human-authored structure, naming, and intent.
|
|
21
|
+
- All DDL statements **must be semicolon-terminated** and valid PostgreSQL syntax.
|
|
22
|
+
- You must not reorder statements arbitrarily; semantic meaning and dependency order must be preserved.
|
|
23
|
+
- Respect formatting conventions, identifier styles, and comments written by humans.
|
|
24
|
+
- When generating new tables or columns, infer types and constraints based on other schema examples or enums (if available).
|
|
25
|
+
- Maintain consistency in column ordering, naming style, and constraint patterns.
|
|
26
|
+
- When adding to existing definitions, do not remove human-authored comments unless told to.
|
|
27
|
+
- Do not introduce structural changes that conflict with domain-specs or enums.
|
|
28
|
+
|
|
29
|
+
### Interaction with Other Sources
|
|
30
|
+
|
|
31
|
+
- Refer to /ztd/domain-specs for domain logic and behavioral definitions. These dictate *what* should exist in the schema.
|
|
32
|
+
- Refer to /ztd/enums for allowable value sets when defining enum-like columns or constraints.
|
|
33
|
+
- Always use those definitions as context when writing or editing this schema.
|
|
34
|
+
|
|
35
|
+
If uncertain, defer to human authorship and request clarification.
|
|
36
|
+
|
|
37
|
+
## Domain Specifications
|
|
38
|
+
|
|
39
|
+
You are an AI agent reading this directory to interpret domain logic.
|
|
40
|
+
|
|
41
|
+
### Instructions
|
|
42
|
+
|
|
43
|
+
- Treat each Markdown file as defining **one domain behavior**.
|
|
44
|
+
- Use the embedded SQL block (`sql ... `) as the **reference SELECT**.
|
|
45
|
+
- Only the first top-level SELECT block should be considered executable logic.
|
|
46
|
+
- Parameters may be written in :named format (e.g., :as_of). You must bind them as positional placeholders (e.g., $1, $2, ?) in generated code.
|
|
47
|
+
- Do not generate or modify files in this directory unless explicitly asked.
|
|
48
|
+
|
|
49
|
+
### Assumptions
|
|
50
|
+
|
|
51
|
+
- `ztd-config` parses only DDL (`ztd/ddl/**/*.sql`) to generate row shapes.
|
|
52
|
+
- These specifications are for **humans and AI consumption** (documentation + reference SQL).
|
|
53
|
+
- Comments and descriptions exist to help you interpret logic correctly.
|
|
54
|
+
|
|
55
|
+
### Rules
|
|
56
|
+
|
|
57
|
+
- Never ignore the human-written description above the SQL block.
|
|
58
|
+
- Keep exactly one executable SQL block per file (one file = one behavior).
|
|
59
|
+
- Do not reorder or optimize the SQL unless explicitly instructed.
|
|
60
|
+
- Preserve the semantic meaning as given in the specification.
|
|
61
|
+
- This folder defines **what** logic means. Your job is to reproduce that logic elsewhere (e.g., in src/ or tests).
|
|
62
|
+
|
|
63
|
+
If in doubt, ask for clarification or defer to human judgment.
|
|
64
|
+
|
|
65
|
+
## Domain Enums
|
|
66
|
+
|
|
67
|
+
You are an AI assistant responsible for reading domain enum definitions from this folder.
|
|
68
|
+
|
|
69
|
+
### Purpose
|
|
70
|
+
|
|
71
|
+
This directory defines canonical value sets (enums) such as status codes and plan tiers. These definitions inform your code generation logic, constraint enforcement, and vocabulary use.
|
|
72
|
+
|
|
73
|
+
### Behavior Guidelines
|
|
74
|
+
|
|
75
|
+
- Read from the Markdown file containing SQL select ... from (values ...) blocks.
|
|
76
|
+
- Never invent magic numbers or enum values. Always use those explicitly defined here.
|
|
77
|
+
- Do not modify or append new enums unless explicitly instructed by a human.
|
|
78
|
+
|
|
79
|
+
### SQL Rules
|
|
80
|
+
|
|
81
|
+
- Each SQL block defines an enum set.
|
|
82
|
+
- Keep exactly one executable SQL block per file (one file = one enum set).
|
|
83
|
+
- All blocks follow the form:
|
|
84
|
+
|
|
85
|
+
`sql
|
|
86
|
+
select v.*
|
|
87
|
+
from (
|
|
88
|
+
values
|
|
89
|
+
(1, 'some_code', 'some_label')
|
|
90
|
+
) v(key, value, display_name);
|
|
91
|
+
`
|
|
92
|
+
|
|
93
|
+
- You must extract key and value pairs as the authoritative mapping.
|
|
94
|
+
- display_name,
|
|
95
|
+
ranking, or other metadata may be used where helpful (e.g., UI rendering or sorting).
|
|
96
|
+
|
|
97
|
+
### Use in Code Generation
|
|
98
|
+
|
|
99
|
+
- Use these enums when generating SQL WHERE clauses, conditionals, or constants.
|
|
100
|
+
- When translating logic from /ztd/domain-specs, map references like :status__established to corresponding values here.
|
|
101
|
+
- Maintain full consistency with enum names and intent.
|
|
102
|
+
|
|
103
|
+
If a required enum is missing, raise an error or ask for human clarification.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# ZTD Definitions
|
|
2
|
+
|
|
3
|
+
This directory hosts the schema, domain-spec, and enum definitions that feed native ZTD workflows.
|
|
4
|
+
|
|
5
|
+
## DDL Definitions
|
|
6
|
+
|
|
7
|
+
The ztd/ddl/ directory stores **Data Definition Language (DDL)** files that describe the database schema. These files include CREATE TABLE, ALTER TABLE, index declarations, and constraint definitions. ZTD treats the SQL files here as the single source of truth for schemas, so both humans and AI must reference this directory when evolving the structure.
|
|
8
|
+
|
|
9
|
+
### Allowed Content and Structure
|
|
10
|
+
|
|
11
|
+
- **Schema Definition Files:** Core table structures live in ztd/ddl/ using CREATE TABLE statements, but you may also add related DDL such as ALTER TABLE commands or explicit index declarations that contribute to the schema contract.
|
|
12
|
+
- **Semantic Flexibility:** The directory supports multiple ways to describe schema changes (e.g., altering tables inline or via subsequent ALTER TABLE statements). The key is clarity and correctness so the CLI tooling can interpret the intended shape.
|
|
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.
|