@rawsql-ts/ztd-cli 0.17.0 → 0.20.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 +532 -366
- package/package.json +26 -15
- package/templates/.editorconfig +16 -16
- package/templates/.prettierignore +2 -2
- package/templates/.prettierrc +24 -24
- package/templates/AGENTS.md +30 -52
- package/templates/CONTEXT.md +11 -0
- package/templates/CONTEXT.webapi.md +11 -0
- package/templates/DESIGN.md +17 -0
- package/templates/DEV_NOTES.md +14 -0
- package/templates/PROMPT_DOGFOOD.webapi.md +49 -0
- package/templates/README.md +46 -14
- package/templates/README.webapi.md +38 -0
- package/templates/scripts/local-source-guard.mjs +189 -0
- package/templates/src/AGENTS.md +26 -26
- package/templates/src/application/AGENTS.md +15 -0
- package/templates/src/application/README.md +6 -0
- package/templates/src/catalog/AGENTS.md +28 -37
- package/templates/src/catalog/runtime/AGENTS.md +28 -75
- package/templates/src/catalog/runtime/_coercions.ts +30 -1
- package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -21
- package/templates/src/catalog/specs/AGENTS.md +41 -48
- package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -21
- package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -20
- package/templates/src/db/sql-client-adapters.ts +32 -0
- package/templates/src/db/sql-client.ts +24 -24
- package/templates/src/domain/AGENTS.md +15 -0
- package/templates/src/domain/README.md +6 -0
- package/templates/src/infrastructure/AGENTS.md +14 -0
- package/templates/src/infrastructure/README.md +6 -0
- package/templates/src/infrastructure/db/AGENTS.md +14 -0
- package/templates/src/infrastructure/db/sql-client-adapters.ts +34 -0
- package/templates/{dist/ztd-cli/templates/src → src/infrastructure}/db/sql-client.ts +3 -3
- package/templates/src/infrastructure/persistence/AGENTS.md +18 -0
- package/templates/src/infrastructure/persistence/README.md +8 -0
- package/templates/src/infrastructure/persistence/repositories/AGENTS.md +17 -0
- package/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md +20 -0
- package/templates/src/infrastructure/persistence/repositories/tables/README.md +5 -0
- package/templates/src/infrastructure/persistence/repositories/views/AGENTS.md +16 -0
- package/templates/src/infrastructure/persistence/repositories/views/README.md +5 -0
- package/templates/src/infrastructure/telemetry/AGENTS.md +14 -0
- package/templates/src/infrastructure/telemetry/consoleRepositoryTelemetry.ts +66 -0
- package/templates/src/infrastructure/telemetry/repositoryTelemetry.ts +26 -0
- package/templates/src/infrastructure/telemetry/types.ts +48 -0
- package/templates/src/jobs/AGENTS.md +25 -26
- package/templates/src/jobs/README.md +2 -2
- package/templates/src/presentation/AGENTS.md +15 -0
- package/templates/src/presentation/http/AGENTS.md +15 -0
- package/templates/src/presentation/http/README.md +6 -0
- package/templates/src/repositories/AGENTS.md +30 -118
- package/templates/src/repositories/tables/AGENTS.md +29 -94
- package/templates/src/repositories/tables/README.md +5 -3
- package/templates/src/repositories/views/AGENTS.md +25 -25
- package/templates/src/repositories/views/README.md +5 -3
- package/templates/src/sql/AGENTS.md +30 -77
- package/templates/src/sql/README.md +5 -5
- package/templates/tests/AGENTS.md +29 -62
- package/templates/tests/generated/AGENTS.md +23 -16
- package/templates/tests/smoke.test.ts +25 -5
- package/templates/tests/smoke.validation.test.ts +34 -34
- package/templates/tests/support/AGENTS.md +24 -26
- package/templates/tests/support/global-setup.ts +15 -15
- package/templates/tests/support/testkit-client.ts +14 -14
- package/templates/tests/support/testkit-client.webapi.ts +14 -0
- package/templates/tests/ztd-layout.generated.ts +6 -6
- package/templates/tsconfig.json +15 -15
- package/templates/vitest.config.ts +13 -13
- package/templates/ztd/AGENTS.md +23 -18
- package/templates/ztd/README.md +5 -5
- package/templates/ztd/ddl/AGENTS.md +26 -34
- package/templates/ztd/ddl/demo.sql +74 -74
- package/LICENSE +0 -21
- package/dist/commands/ddl.d.ts +0 -7
- package/dist/commands/ddl.js +0 -118
- package/dist/commands/ddl.js.map +0 -1
- package/dist/commands/diff.d.ts +0 -10
- package/dist/commands/diff.js +0 -38
- package/dist/commands/diff.js.map +0 -1
- package/dist/commands/genEntities.d.ts +0 -6
- package/dist/commands/genEntities.js +0 -50
- package/dist/commands/genEntities.js.map +0 -1
- package/dist/commands/init.d.ts +0 -79
- package/dist/commands/init.js +0 -1083
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/lint.d.ts +0 -59
- package/dist/commands/lint.js +0 -358
- package/dist/commands/lint.js.map +0 -1
- package/dist/commands/options.d.ts +0 -9
- package/dist/commands/options.js +0 -48
- package/dist/commands/options.js.map +0 -1
- package/dist/commands/pull.d.ts +0 -10
- package/dist/commands/pull.js +0 -105
- package/dist/commands/pull.js.map +0 -1
- package/dist/commands/ztdConfig.d.ts +0 -23
- package/dist/commands/ztdConfig.js +0 -216
- package/dist/commands/ztdConfig.js.map +0 -1
- package/dist/commands/ztdConfigCommand.d.ts +0 -5
- package/dist/commands/ztdConfigCommand.js +0 -157
- package/dist/commands/ztdConfigCommand.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/utils/agents.d.ts +0 -1
- package/dist/utils/agents.js +0 -48
- package/dist/utils/agents.js.map +0 -1
- package/dist/utils/collectSqlFiles.d.ts +0 -9
- package/dist/utils/collectSqlFiles.js +0 -58
- package/dist/utils/collectSqlFiles.js.map +0 -1
- package/dist/utils/connectionSummary.d.ts +0 -3
- package/dist/utils/connectionSummary.js +0 -29
- package/dist/utils/connectionSummary.js.map +0 -1
- package/dist/utils/dbConnection.d.ts +0 -29
- package/dist/utils/dbConnection.js +0 -210
- package/dist/utils/dbConnection.js.map +0 -1
- package/dist/utils/fs.d.ts +0 -1
- package/dist/utils/fs.js +0 -12
- package/dist/utils/fs.js.map +0 -1
- package/dist/utils/normalizePulledSchema.d.ts +0 -12
- package/dist/utils/normalizePulledSchema.js +0 -213
- package/dist/utils/normalizePulledSchema.js.map +0 -1
- package/dist/utils/optionalDependencies.d.ts +0 -35
- package/dist/utils/optionalDependencies.js +0 -96
- package/dist/utils/optionalDependencies.js.map +0 -1
- package/dist/utils/pgDump.d.ts +0 -11
- package/dist/utils/pgDump.js +0 -55
- package/dist/utils/pgDump.js.map +0 -1
- package/dist/utils/sqlLintHelpers.d.ts +0 -18
- package/dist/utils/sqlLintHelpers.js +0 -270
- package/dist/utils/sqlLintHelpers.js.map +0 -1
- package/dist/utils/typeMapper.d.ts +0 -4
- package/dist/utils/typeMapper.js +0 -76
- package/dist/utils/typeMapper.js.map +0 -1
- package/dist/utils/ztdProjectConfig.d.ts +0 -40
- package/dist/utils/ztdProjectConfig.js +0 -167
- package/dist/utils/ztdProjectConfig.js.map +0 -1
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +0 -38
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +0 -117
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +0 -1
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +0 -4
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +0 -71
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +0 -1
- package/templates/dist/drivers/pg-testkit/src/index.d.ts +0 -5
- package/templates/dist/drivers/pg-testkit/src/index.js +0 -11
- package/templates/dist/drivers/pg-testkit/src/index.js.map +0 -1
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +0 -3
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +0 -79
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +0 -1
- package/templates/dist/drivers/pg-testkit/src/types.d.ts +0 -69
- package/templates/dist/drivers/pg-testkit/src/types.js +0 -3
- package/templates/dist/drivers/pg-testkit/src/types.js.map +0 -1
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +0 -15
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +0 -34
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +0 -1
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +0 -12
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +0 -53
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +0 -1
- package/templates/dist/mapper-core/src/index.d.ts +0 -160
- package/templates/dist/mapper-core/src/index.js +0 -637
- package/templates/dist/mapper-core/src/index.js.map +0 -1
- package/templates/dist/testkit-core/src/errors/index.d.ts +0 -49
- package/templates/dist/testkit-core/src/errors/index.js +0 -111
- package/templates/dist/testkit-core/src/errors/index.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +0 -5
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +0 -29
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +0 -37
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +0 -182
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +0 -20
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +0 -121
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +0 -51
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +0 -199
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +0 -10
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +0 -28
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +0 -18
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +0 -80
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +0 -59
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js +0 -489
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +0 -1
- package/templates/dist/testkit-core/src/fixtures/naming.d.ts +0 -1
- package/templates/dist/testkit-core/src/fixtures/naming.js +0 -6
- package/templates/dist/testkit-core/src/fixtures/naming.js.map +0 -1
- package/templates/dist/testkit-core/src/index.d.ts +0 -17
- package/templates/dist/testkit-core/src/index.js +0 -47
- package/templates/dist/testkit-core/src/index.js.map +0 -1
- package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +0 -8
- package/templates/dist/testkit-core/src/logger/NoopLogger.js +0 -16
- package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +0 -1
- package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +0 -57
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js +0 -149
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +0 -1
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +0 -43
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +0 -473
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +0 -1
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +0 -9
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +0 -38
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +0 -1
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +0 -42
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +0 -298
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +0 -1
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +0 -12
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +0 -63
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +0 -1
- package/templates/dist/testkit-core/src/types/index.d.ts +0 -69
- package/templates/dist/testkit-core/src/types/index.js +0 -3
- package/templates/dist/testkit-core/src/types/index.js.map +0 -1
- package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +0 -28
- package/templates/dist/testkit-core/src/utils/queryHelpers.js +0 -81
- package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +0 -1
- package/templates/dist/writer-core/src/index.d.ts +0 -34
- package/templates/dist/writer-core/src/index.js +0 -115
- package/templates/dist/writer-core/src/index.js.map +0 -1
- package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +0 -20
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js +0 -3
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +0 -1
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +0 -36
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +0 -85
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +0 -1
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +0 -20
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +0 -33
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +0 -1
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +0 -10
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +0 -29
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +0 -1
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +0 -66
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +0 -552
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +0 -1
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +0 -1
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +0 -82
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +0 -1
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +0 -1
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +0 -29
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +0 -1
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +0 -7
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +0 -10
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +0 -1
|
@@ -1,94 +1,29 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
- Do not force SQL to return `affected_count` via CTE tricks.
|
|
31
|
-
|
|
32
|
-
## CUD behavior rules
|
|
33
|
-
|
|
34
|
-
### CREATE (INSERT)
|
|
35
|
-
|
|
36
|
-
Default:
|
|
37
|
-
- SQL MUST use `insert ... returning <primary_key>` when a generated key is needed.
|
|
38
|
-
- Repository CREATE MUST return identifier only (scalar) per contract.
|
|
39
|
-
- Repository CREATE MUST NOT perform a follow-up SELECT for DTO return shaping.
|
|
40
|
-
- SQL MUST NOT return full rows or DTO-shaped payloads.
|
|
41
|
-
|
|
42
|
-
Exception:
|
|
43
|
-
- If a CREATE endpoint must return DTO, the spec MUST explicitly require it by human instruction.
|
|
44
|
-
- Without that explicit contract, identifier-only return is mandatory.
|
|
45
|
-
|
|
46
|
-
### UPDATE
|
|
47
|
-
|
|
48
|
-
Default:
|
|
49
|
-
- SQL: plain UPDATE without RETURNING.
|
|
50
|
-
- Repository: determine success by affected row count when available.
|
|
51
|
-
|
|
52
|
-
Driver variability handling:
|
|
53
|
-
- If affected row count is unavailable:
|
|
54
|
-
- Treat UPDATE verification as unsupported for that driver/runtime.
|
|
55
|
-
- Throw an explicit error.
|
|
56
|
-
- Do not add fallback checks or workaround logic in repositories.
|
|
57
|
-
- Do not push this variability down into SQL assets.
|
|
58
|
-
|
|
59
|
-
0-row rule (important):
|
|
60
|
-
- Treat "0 rows updated" as a meaningful condition.
|
|
61
|
-
- Default behavior is to surface it clearly (often an error), per spec.
|
|
62
|
-
|
|
63
|
-
### DELETE
|
|
64
|
-
|
|
65
|
-
Default:
|
|
66
|
-
- SQL: plain DELETE without RETURNING.
|
|
67
|
-
- Repository: determine success by affected row count when available.
|
|
68
|
-
|
|
69
|
-
Driver variability handling:
|
|
70
|
-
- If affected row count is unavailable:
|
|
71
|
-
- Treat DELETE verification as unsupported for that driver/runtime.
|
|
72
|
-
- Throw an explicit error.
|
|
73
|
-
- Do not add fallback checks or workaround logic in repositories.
|
|
74
|
-
|
|
75
|
-
0-row rule (important):
|
|
76
|
-
- Treat "0 rows deleted" as a meaningful condition, per spec.
|
|
77
|
-
|
|
78
|
-
## Patch updates (important)
|
|
79
|
-
|
|
80
|
-
- Avoid ambiguous patterns such as `coalesce(param, column)` by default.
|
|
81
|
-
- Contracts should distinguish:
|
|
82
|
-
- "not provided"
|
|
83
|
-
- "explicitly set to null"
|
|
84
|
-
- If patch semantics are needed, implement them explicitly via:
|
|
85
|
-
- separate SQL variants, or
|
|
86
|
-
- explicit contract types that preserve intent.
|
|
87
|
-
|
|
88
|
-
## Testing rule (required)
|
|
89
|
-
|
|
90
|
-
- Every public repository method MUST be covered by tests.
|
|
91
|
-
- Tests should verify:
|
|
92
|
-
- correct mapping behavior
|
|
93
|
-
- correct "0 rows" behavior for UPDATE/DELETE
|
|
94
|
-
- correct error surfaces (do not silently succeed)
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/repositories/tables`.
|
|
3
|
+
- Defines table-oriented CRUD repository contract behavior.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- CREATE SQL MUST use identifier-focused `RETURNING` when generated keys are required.
|
|
8
|
+
- CREATE repository methods MUST return identifier-only results by default.
|
|
9
|
+
- UPDATE and DELETE MUST rely on affected-row counts where available.
|
|
10
|
+
- `rowCount === 0` conditions MUST surface explicitly according to contract behavior.
|
|
11
|
+
- Patch contracts MUST distinguish omitted fields from explicit null values.
|
|
12
|
+
- Public repository methods MUST be test-covered for mapping and CUD error behavior.
|
|
13
|
+
|
|
14
|
+
## ALLOWED
|
|
15
|
+
- DTO-returning CREATE behavior MAY be implemented only when explicitly required by human-authored spec.
|
|
16
|
+
|
|
17
|
+
## PROHIBITED
|
|
18
|
+
- UPDATE/DELETE `RETURNING`-based success emulation.
|
|
19
|
+
- Follow-up SELECT workarounds for CUD verification.
|
|
20
|
+
- Ambiguous patch patterns that hide omitted-vs-null intent.
|
|
21
|
+
|
|
22
|
+
# Mandatory Workflow
|
|
23
|
+
- Table repository changes MUST run tests for affected-row handling and explicit failure surfaces.
|
|
24
|
+
|
|
25
|
+
# Hygiene
|
|
26
|
+
- Keep SQL assets idiomatic and driver-neutral for table CRUD paths.
|
|
27
|
+
|
|
28
|
+
# References
|
|
29
|
+
- Parent repository policy: [../AGENTS.md](../AGENTS.md)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
# Table Repositories
|
|
2
|
-
|
|
3
|
-
Write-focused repositories that execute CRUD SQL from `src/sql`.
|
|
1
|
+
# Table Repositories
|
|
2
|
+
|
|
3
|
+
Write-focused repositories that execute CRUD SQL from `src/sql`.
|
|
4
|
+
|
|
5
|
+
Accept an optional telemetry hook from `src/infrastructure/telemetry/repositoryTelemetry.ts` and default it through `resolveRepositoryTelemetry(...)` so applications can replace the sink without editing repository internals.
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
- Read
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- Multi-table joins and
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/repositories/views`.
|
|
3
|
+
- Defines read-model repository behavior for complex SELECT-only queries.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Queries in this subtree MUST remain read-only.
|
|
8
|
+
- Read-model DTO validation MUST run at repository/catalog boundaries.
|
|
9
|
+
- Query naming MUST make cardinality assumptions explicit.
|
|
10
|
+
|
|
11
|
+
## ALLOWED
|
|
12
|
+
- Multi-table joins, aggregations, and purpose-built read DTOs MAY be used.
|
|
13
|
+
|
|
14
|
+
## PROHIBITED
|
|
15
|
+
- INSERT/UPDATE/DELETE behavior in this subtree.
|
|
16
|
+
- Hidden write side effects in read-model query paths.
|
|
17
|
+
|
|
18
|
+
# Mandatory Workflow
|
|
19
|
+
- View repository changes MUST run tests for DTO validation and result ordering assumptions.
|
|
20
|
+
|
|
21
|
+
# Hygiene
|
|
22
|
+
- Preserve explicit ordering whenever test behavior depends on row order.
|
|
23
|
+
|
|
24
|
+
# References
|
|
25
|
+
- Parent repository policy: [../AGENTS.md](../AGENTS.md)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
# View Repositories
|
|
2
|
-
|
|
3
|
-
Read-only repositories backed by SELECT SQL in `src/sql`.
|
|
1
|
+
# View Repositories
|
|
2
|
+
|
|
3
|
+
Read-only repositories backed by SELECT SQL in `src/sql`.
|
|
4
|
+
|
|
5
|
+
Accept an optional telemetry hook from `src/infrastructure/telemetry/repositoryTelemetry.ts` and default it through `resolveRepositoryTelemetry(...)` so applications can bridge structured events into their own logging stack.
|
|
@@ -1,77 +1,30 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
- SQL
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- SQL
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
For simple CRUD SQL under table-oriented areas:
|
|
32
|
-
- Prefer the most direct and idiomatic SQL.
|
|
33
|
-
- Do NOT encode driver limitations into SQL.
|
|
34
|
-
- Avoid unnecessary CTEs or counting tricks.
|
|
35
|
-
|
|
36
|
-
Examples of discouraged patterns for simple CRUD:
|
|
37
|
-
- `with updated as (...) select count(*) ...`
|
|
38
|
-
- returning values only to compute affected rows
|
|
39
|
-
|
|
40
|
-
Affected-row handling belongs to repositories/runtime, not SQL.
|
|
41
|
-
|
|
42
|
-
## CUD and RETURNING policy
|
|
43
|
-
|
|
44
|
-
- INSERT SQL MAY use `RETURNING` only for identifier columns (and optionally DB-generated columns required by contract).
|
|
45
|
-
- INSERT SQL MUST NOT return full rows or DTO-shaped payloads.
|
|
46
|
-
- UPDATE SQL MUST NOT use `RETURNING`.
|
|
47
|
-
- DELETE SQL MUST NOT use `RETURNING`.
|
|
48
|
-
- SQL MUST NOT use `RETURNING` to emulate affected-row detection.
|
|
49
|
-
- If affected-row counts are unavailable from the driver/runtime, treat UPDATE/DELETE verification as unsupported at the driver boundary.
|
|
50
|
-
|
|
51
|
-
## Safety rules (critical)
|
|
52
|
-
|
|
53
|
-
- UPDATE and DELETE MUST include a WHERE clause.
|
|
54
|
-
- SQL MUST NOT rely on follow-up SELECTs in repositories to ensure correctness.
|
|
55
|
-
- A missing or incorrect WHERE clause is a SQL bug and MUST surface via tests.
|
|
56
|
-
|
|
57
|
-
## Naming conventions (recommended)
|
|
58
|
-
|
|
59
|
-
Prefer SQL-idiomatic verbs for CRUD assets:
|
|
60
|
-
- insert_<entity>.sql
|
|
61
|
-
- select_<entity>_by_<key>.sql
|
|
62
|
-
- select_<entities>.sql
|
|
63
|
-
- update_<entity>.sql
|
|
64
|
-
- delete_<entity>.sql
|
|
65
|
-
|
|
66
|
-
Avoid ambiguous verbs like "create" / "get" in SQL filenames by default.
|
|
67
|
-
|
|
68
|
-
## General SQL rules
|
|
69
|
-
|
|
70
|
-
- Use explicit column lists.
|
|
71
|
-
- Avoid `select *` unless explicitly justified.
|
|
72
|
-
- Prefer stable ordering when result order matters.
|
|
73
|
-
|
|
74
|
-
## Boundaries
|
|
75
|
-
|
|
76
|
-
- Do not place TypeScript code in this directory.
|
|
77
|
-
- Query contracts live in "src/catalog/specs".
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/sql`.
|
|
3
|
+
- Defines SQL asset contract rules for runtime execution.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- SQL assets MUST use named parameters (`:name`).
|
|
8
|
+
- SQL assets MUST stay DTO-independent and use database-oriented column naming.
|
|
9
|
+
- UPDATE and DELETE statements MUST include WHERE clauses.
|
|
10
|
+
- SQL files MUST remain explicit enough for repository/runtime mapping contracts.
|
|
11
|
+
- CUD `RETURNING` behavior MUST follow repository contract rules.
|
|
12
|
+
|
|
13
|
+
## ALLOWED
|
|
14
|
+
- INSERT SQL MAY use `RETURNING` for identifiers and required DB-generated contract columns.
|
|
15
|
+
|
|
16
|
+
## PROHIBITED
|
|
17
|
+
- Positional placeholders in SQL asset files.
|
|
18
|
+
- DTO camelCase aliasing inside SQL assets.
|
|
19
|
+
- UPDATE/DELETE `RETURNING` usage.
|
|
20
|
+
- SQL-side emulation of affected-row verification behavior.
|
|
21
|
+
|
|
22
|
+
# Mandatory Workflow
|
|
23
|
+
- SQL asset changes MUST run tests that execute the changed SQL via catalog/repository paths.
|
|
24
|
+
|
|
25
|
+
# Hygiene
|
|
26
|
+
- Keep SQL filenames stable and unambiguous for CRUD intent.
|
|
27
|
+
- Avoid `select *` unless explicitly justified by contract behavior.
|
|
28
|
+
|
|
29
|
+
# References
|
|
30
|
+
- Parent runtime policy: [../AGENTS.md](../AGENTS.md)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# SQL Files
|
|
2
|
-
|
|
3
|
-
Store SQL statements by table or domain in subfolders.
|
|
4
|
-
|
|
5
|
-
- Use named parameters (for example `:id`).
|
|
1
|
+
# SQL Files
|
|
2
|
+
|
|
3
|
+
Store SQL statements by table or domain in subfolders.
|
|
4
|
+
|
|
5
|
+
- Use named parameters (for example `:id`).
|
|
6
6
|
- Keep SQL in files; repositories should load them.
|
|
@@ -1,62 +1,29 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- Tests
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- UPDATE and DELETE success/failure MUST be verified via affected-row information
|
|
31
|
-
(e.g. rowCount or equivalent).
|
|
32
|
-
- Tests MUST NOT assume UPDATE/DELETE return DTOs.
|
|
33
|
-
- If the driver cannot report affected rows, CUD verification is unsupported and
|
|
34
|
-
tests MUST fail fast.
|
|
35
|
-
- CREATE tests for table repositories MUST expect identifier-only returns by default.
|
|
36
|
-
- Tests MUST NOT require repository follow-up SELECT after CREATE unless the catalog spec explicitly requires DTO return.
|
|
37
|
-
|
|
38
|
-
## Generated artifacts
|
|
39
|
-
|
|
40
|
-
- "tests/generated/" is auto-generated.
|
|
41
|
-
- Do not edit generated files by hand.
|
|
42
|
-
- Regenerate before debugging type errors.
|
|
43
|
-
|
|
44
|
-
## Boundaries
|
|
45
|
-
|
|
46
|
-
- Tests may import from "src/".
|
|
47
|
-
- Runtime code under "src/" MUST NOT import from "tests/" or "tests/generated/".
|
|
48
|
-
|
|
49
|
-
## Test runner requirements (required)
|
|
50
|
-
|
|
51
|
-
- A test runner configuration (e.g. vitest.config.ts) MUST exist.
|
|
52
|
-
- Tests MUST be executable with a single command (e.g. `pnpm test`).
|
|
53
|
-
- Missing test runner configuration is considered a setup error.
|
|
54
|
-
|
|
55
|
-
Do not add tests that assume manual setup steps.
|
|
56
|
-
|
|
57
|
-
## Initialization invariant
|
|
58
|
-
|
|
59
|
-
- The initial project state MUST include:
|
|
60
|
-
- test runner configuration
|
|
61
|
-
- at least one executable test file
|
|
62
|
-
- The initial test run MUST pass or fail only due to user-written logic, not setup.
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/tests`.
|
|
3
|
+
- Defines verification contract for ZTD template-generated test code.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Tests MUST verify SQL execution under ZTD rewrite, mapping behavior, validation paths, and DTO shape semantics.
|
|
8
|
+
- CUD tests MUST verify UPDATE/DELETE via affected-row signals.
|
|
9
|
+
- CREATE tests for table repositories MUST expect identifier-only returns unless spec explicitly requires DTO return.
|
|
10
|
+
- Test runner configuration MUST exist and support single-command execution.
|
|
11
|
+
- Initial template state MUST include at least one executable test.
|
|
12
|
+
|
|
13
|
+
## ALLOWED
|
|
14
|
+
- Tests MAY import runtime modules from `src/`.
|
|
15
|
+
|
|
16
|
+
## PROHIBITED
|
|
17
|
+
- Runtime imports from `tests/` or `tests/generated/`.
|
|
18
|
+
- Tests that require repository follow-up SELECT behavior contradicting repository contracts.
|
|
19
|
+
- Manual edits to generated artifacts.
|
|
20
|
+
|
|
21
|
+
# Mandatory Workflow
|
|
22
|
+
- Test changes MUST run affected test suites and confirm test-runner configuration remains valid.
|
|
23
|
+
|
|
24
|
+
# Hygiene
|
|
25
|
+
- Regenerate `tests/generated` artifacts before diagnosing missing generated module errors.
|
|
26
|
+
|
|
27
|
+
# References
|
|
28
|
+
- Generated tests policy: [./generated/AGENTS.md](./generated/AGENTS.md)
|
|
29
|
+
- Shared support policy: [./support/AGENTS.md](./support/AGENTS.md)
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/tests/generated`.
|
|
3
|
+
- Governs generated test artifacts.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Missing or stale generated files MUST be regenerated using project generation commands.
|
|
8
|
+
|
|
9
|
+
## ALLOWED
|
|
10
|
+
- Generated artifacts MAY be regenerated via `npx ztd ztd-config`.
|
|
11
|
+
|
|
12
|
+
## PROHIBITED
|
|
13
|
+
- Manual edits to files in this directory.
|
|
14
|
+
- Committing generated artifacts when repository policy does not require them.
|
|
15
|
+
|
|
16
|
+
# Mandatory Workflow
|
|
17
|
+
- Run generation commands before diagnosing generated-module type errors.
|
|
18
|
+
|
|
19
|
+
# Hygiene
|
|
20
|
+
- Keep generated output reproducible from project tooling.
|
|
21
|
+
|
|
22
|
+
# References
|
|
23
|
+
- Parent tests policy: [../AGENTS.md](../AGENTS.md)
|
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
|
|
4
|
+
import { createTestkitClient } from './support/testkit-client';
|
|
5
|
+
|
|
6
|
+
test('smoke: runtime contract wiring is usable before SQL-backed tests exist', () => {
|
|
7
|
+
const output = ensureSmokeOutput({
|
|
8
|
+
id: 1,
|
|
9
|
+
createdAt: '2025-01-01T00:00:00.000Z',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
expect(output.id).toBe(1);
|
|
13
|
+
expect(output.createdAt).toBeInstanceOf(Date);
|
|
14
|
+
expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('smoke: SqlClient seam is either wired or fails with an actionable message', async () => {
|
|
18
|
+
try {
|
|
19
|
+
const client = await createTestkitClient();
|
|
20
|
+
expect(typeof client.query).toBe('function');
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
23
|
+
expect(message).toContain('Provide a SqlClient implementation here');
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
|
|
4
|
-
|
|
5
|
-
test('validator invariant smoke passes for valid runtime output', () => {
|
|
6
|
-
const output = ensureSmokeOutput({
|
|
7
|
-
id: 1,
|
|
8
|
-
createdAt: new Date('2025-01-01T00:00:00.000Z')
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
expect(output).toEqual({
|
|
12
|
-
id: 1,
|
|
13
|
-
createdAt: new Date('2025-01-01T00:00:00.000Z')
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('validator invariant smoke normalizes valid timestamp strings', () => {
|
|
18
|
-
const output = ensureSmokeOutput({
|
|
19
|
-
id: 1,
|
|
20
|
-
createdAt: '2025-01-01T00:00:00.000Z'
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(output.createdAt).toBeInstanceOf(Date);
|
|
24
|
-
expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('validator invariant smoke fails for invalid runtime output', () => {
|
|
28
|
-
expect(() =>
|
|
29
|
-
ensureSmokeOutput({
|
|
30
|
-
id: 1,
|
|
31
|
-
createdAt: 'not-a-date'
|
|
32
|
-
})
|
|
33
|
-
).toThrow(/Invalid timestamp string/);
|
|
34
|
-
});
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { ensureSmokeOutput } from '../src/catalog/runtime/_smoke.runtime';
|
|
4
|
+
|
|
5
|
+
test('validator invariant smoke passes for valid runtime output', () => {
|
|
6
|
+
const output = ensureSmokeOutput({
|
|
7
|
+
id: 1,
|
|
8
|
+
createdAt: new Date('2025-01-01T00:00:00.000Z')
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
expect(output).toEqual({
|
|
12
|
+
id: 1,
|
|
13
|
+
createdAt: new Date('2025-01-01T00:00:00.000Z')
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('validator invariant smoke normalizes valid timestamp strings', () => {
|
|
18
|
+
const output = ensureSmokeOutput({
|
|
19
|
+
id: 1,
|
|
20
|
+
createdAt: '2025-01-01T00:00:00.000Z'
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(output.createdAt).toBeInstanceOf(Date);
|
|
24
|
+
expect(output.createdAt.toISOString()).toBe('2025-01-01T00:00:00.000Z');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('validator invariant smoke fails for invalid runtime output', () => {
|
|
28
|
+
expect(() =>
|
|
29
|
+
ensureSmokeOutput({
|
|
30
|
+
id: 1,
|
|
31
|
+
createdAt: 'not-a-date'
|
|
32
|
+
})
|
|
33
|
+
).toThrow(/Invalid timestamp string/);
|
|
34
|
+
});
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- Re-run a representative subset of tests and at least one full run when feasible.
|
|
26
|
-
- Watch for parallelism and resource lifecycle issues.
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/tests/support`.
|
|
3
|
+
- Defines shared test infrastructure contracts.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Shared support helpers MUST stay minimal and explicit.
|
|
8
|
+
- Shared support code MUST avoid business-rule ownership.
|
|
9
|
+
- Runtime code under `src/` MUST NOT import from this folder.
|
|
10
|
+
|
|
11
|
+
## ALLOWED
|
|
12
|
+
- Support helpers MAY import from `src/`.
|
|
13
|
+
|
|
14
|
+
## PROHIBITED
|
|
15
|
+
- Embedding domain business logic into support infrastructure.
|
|
16
|
+
|
|
17
|
+
# Mandatory Workflow
|
|
18
|
+
- Global setup/support changes MUST run representative subset tests and at least one full test run.
|
|
19
|
+
|
|
20
|
+
# Hygiene
|
|
21
|
+
- Validate resource lifecycle and parallelism behavior after support-layer changes.
|
|
22
|
+
|
|
23
|
+
# References
|
|
24
|
+
- Parent tests policy: [../AGENTS.md](../AGENTS.md)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vitest global setup.
|
|
3
|
-
*
|
|
4
|
-
* This hook warns when
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
export default async function globalSetup() {
|
|
8
|
-
const configuredUrl = process.env.
|
|
9
|
-
if (!configuredUrl) {
|
|
10
|
-
console.warn(
|
|
11
|
-
'
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
return () => undefined;
|
|
15
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Vitest global setup.
|
|
3
|
+
*
|
|
4
|
+
* This hook warns when ZTD_TEST_DATABASE_URL is missing so the developer remembers
|
|
5
|
+
* to provide the ZTD-owned test database connection before running SQL-backed tests.
|
|
6
|
+
*/
|
|
7
|
+
export default async function globalSetup() {
|
|
8
|
+
const configuredUrl = process.env.ZTD_TEST_DATABASE_URL?.trim();
|
|
9
|
+
if (!configuredUrl) {
|
|
10
|
+
console.warn(
|
|
11
|
+
'ZTD_TEST_DATABASE_URL is not configured. SQL-backed tests will need a driver plus a ZTD-owned test database connection before they can run.',
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return () => undefined;
|
|
15
|
+
}
|