@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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/infrastructure/db`.
|
|
3
|
+
- Defines SQL client seams and driver adapters for WebAPI-oriented scaffolds.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Driver adapters MUST fulfill the `SqlClient` contract without leaking driver-specific result objects.
|
|
8
|
+
- Connection lifecycle decisions MUST remain explicit.
|
|
9
|
+
|
|
10
|
+
## PROHIBITED
|
|
11
|
+
- Embedding repository business rules in DB adapter code.
|
|
12
|
+
|
|
13
|
+
# Mandatory Workflow
|
|
14
|
+
- DB adapter changes MUST run typecheck and adapter-focused tests.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SqlClient } from './sql-client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adapt a `pg`-style queryable (Client or Pool) into a SqlClient.
|
|
5
|
+
*
|
|
6
|
+
* pg's `query()` returns `QueryResult<T>` with a `.rows` property.
|
|
7
|
+
* This helper unwraps the result so it satisfies the `SqlClient` contract.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* // This runtime example uses DATABASE_URL for application code.
|
|
11
|
+
* // ztd-cli itself does not read DATABASE_URL implicitly.
|
|
12
|
+
* const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
13
|
+
* const client = fromPg(pool);
|
|
14
|
+
* const users = await client.query<{ id: number }>('SELECT id ...', []);
|
|
15
|
+
*/
|
|
16
|
+
export function fromPg(
|
|
17
|
+
queryable: {
|
|
18
|
+
query(text: string, values?: readonly unknown[]): Promise<{ rows: Record<string, unknown>[] }>;
|
|
19
|
+
}
|
|
20
|
+
): SqlClient {
|
|
21
|
+
return {
|
|
22
|
+
query<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
23
|
+
text: string,
|
|
24
|
+
values?: readonly unknown[] | Record<string, unknown>
|
|
25
|
+
): Promise<T[]> {
|
|
26
|
+
if (values != null && !Array.isArray(values)) {
|
|
27
|
+
throw new Error('fromPg adapter does not support named parameter objects; use positional parameter arrays');
|
|
28
|
+
}
|
|
29
|
+
return queryable
|
|
30
|
+
.query(text, values as readonly unknown[])
|
|
31
|
+
.then((result) => result.rows as T[]);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
export type SqlQueryRows<T> = Promise<T[]>;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Minimal SQL client interface required by the
|
|
10
|
+
* Minimal SQL client interface required by the persistence layer.
|
|
11
11
|
*
|
|
12
12
|
* - Production: adapt this interface to your preferred driver (pg, mysql2, etc.) and normalize the results to `T[]`.
|
|
13
13
|
* - Tests: replace the implementation with a mock, a fixture helper, or an adapter that follows this contract.
|
|
@@ -19,6 +19,6 @@ export type SqlQueryRows<T> = Promise<T[]>;
|
|
|
19
19
|
export type SqlClient = {
|
|
20
20
|
query<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
21
21
|
text: string,
|
|
22
|
-
values?: readonly unknown[]
|
|
22
|
+
values?: readonly unknown[] | Record<string, unknown>
|
|
23
23
|
): SqlQueryRows<T>;
|
|
24
|
-
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/infrastructure/persistence`.
|
|
3
|
+
- Defines persistence-layer rules for WebAPI-oriented scaffolds.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- ZTD-specific workflow rules apply here and in the related `src/sql`, `src/catalog`, and `ztd` assets.
|
|
8
|
+
- Persistence adapters MUST keep handwritten SQL, QuerySpecs, and DDL aligned.
|
|
9
|
+
- Repository code MUST rely on explicit contracts and generated/runtime helpers instead of hidden driver behavior.
|
|
10
|
+
- `ZTD_TEST_DATABASE_URL` is the only implicit database owned by `ztd-cli`.
|
|
11
|
+
- Non-ZTD database targets MUST be passed explicitly via `--url` or a complete `--db-*` flag set for inspection work.
|
|
12
|
+
- Migration SQL artifacts MAY be generated here, but applying them remains outside `ztd-cli` ownership.
|
|
13
|
+
|
|
14
|
+
## PROHIBITED
|
|
15
|
+
- Leaking persistence rules into domain, application, or presentation layers.
|
|
16
|
+
|
|
17
|
+
# Mandatory Workflow
|
|
18
|
+
- Persistence changes MUST run `ztd ztd-config`, relevant tests, and the persistence-focused verification flow.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/infrastructure/persistence/repositories`.
|
|
3
|
+
- Defines repository responsibilities for WebAPI-oriented persistence infrastructure.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Repositories MUST load SQL assets from `src/sql` through shared loader infrastructure.
|
|
8
|
+
- Repository CUD behavior MUST follow contract rules for `RETURNING`, rowCount handling, and explicit unsupported-driver failures.
|
|
9
|
+
- Repositories MUST reference SQL by stable logical keys.
|
|
10
|
+
- Constructors for repositories SHOULD accept an optional telemetry dependency from `src/infrastructure/telemetry/repositoryTelemetry.ts`.
|
|
11
|
+
- Tests MUST cover every public repository method.
|
|
12
|
+
|
|
13
|
+
## PROHIBITED
|
|
14
|
+
- Inline SQL strings or ad-hoc SQL file path resolution.
|
|
15
|
+
|
|
16
|
+
# Mandatory Workflow
|
|
17
|
+
- Repository changes MUST run tests covering mapping, rowCount behavior, and error surfaces.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/infrastructure/persistence/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
|
+
## PROHIBITED
|
|
15
|
+
- UPDATE/DELETE `RETURNING`-based success emulation.
|
|
16
|
+
- Follow-up SELECT workarounds for CUD verification.
|
|
17
|
+
- Ambiguous patch patterns that hide omitted-vs-null intent.
|
|
18
|
+
|
|
19
|
+
# Mandatory Workflow
|
|
20
|
+
- Table repository changes MUST run tests for affected-row handling and explicit failure surfaces.
|
|
@@ -0,0 +1,5 @@
|
|
|
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.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/infrastructure/persistence/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
|
+
## PROHIBITED
|
|
12
|
+
- INSERT/UPDATE/DELETE behavior in this subtree.
|
|
13
|
+
- Hidden write side effects in read-model query paths.
|
|
14
|
+
|
|
15
|
+
# Mandatory Workflow
|
|
16
|
+
- View repository changes MUST run tests for DTO validation and result ordering assumptions.
|
|
@@ -0,0 +1,5 @@
|
|
|
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.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/infrastructure/telemetry`.
|
|
3
|
+
- Defines repository telemetry seams and adapters.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Telemetry hooks MUST remain replaceable by application-owned wiring.
|
|
8
|
+
- Default telemetry behavior MUST stay conservative about query text emission.
|
|
9
|
+
|
|
10
|
+
## PROHIBITED
|
|
11
|
+
- Making telemetry mandatory for non-persistence layers.
|
|
12
|
+
|
|
13
|
+
# Mandatory Workflow
|
|
14
|
+
- Telemetry changes MUST run the focused scaffold verification tests.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RepositoryTelemetry,
|
|
3
|
+
RepositoryTelemetryConsoleOptions,
|
|
4
|
+
RepositoryTelemetryEvent,
|
|
5
|
+
} from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a conservative console-backed telemetry hook for repositories.
|
|
9
|
+
*
|
|
10
|
+
* The default policy keeps SQL text disabled so applications opt in before
|
|
11
|
+
* query text is emitted to logs or forwarded to another sink.
|
|
12
|
+
*/
|
|
13
|
+
export function createConsoleRepositoryTelemetry(
|
|
14
|
+
options: RepositoryTelemetryConsoleOptions = {},
|
|
15
|
+
): RepositoryTelemetry {
|
|
16
|
+
const logger = options.logger ?? console;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
emit(event: RepositoryTelemetryEvent): void {
|
|
20
|
+
const payload = serializeEvent(event, options.includeSqlText === true);
|
|
21
|
+
if (event.kind === 'query.execute.error') {
|
|
22
|
+
logger.error('[repository-telemetry]', payload);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
logger.info('[repository-telemetry]', payload);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function serializeEvent(
|
|
32
|
+
event: RepositoryTelemetryEvent,
|
|
33
|
+
includeSqlText: boolean,
|
|
34
|
+
): Record<string, unknown> {
|
|
35
|
+
const payload: Record<string, unknown> = {
|
|
36
|
+
kind: event.kind,
|
|
37
|
+
timestamp: event.timestamp,
|
|
38
|
+
repositoryName: event.repositoryName,
|
|
39
|
+
methodName: event.methodName,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (event.queryName) {
|
|
43
|
+
payload.queryName = event.queryName;
|
|
44
|
+
}
|
|
45
|
+
if (event.fallback !== undefined) {
|
|
46
|
+
payload.fallback = event.fallback;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Keep SQL text out of default logs so applications make that policy choice.
|
|
50
|
+
if (includeSqlText && event.sqlText) {
|
|
51
|
+
payload.sqlText = event.sqlText;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (event.kind !== 'query.execute.start') {
|
|
55
|
+
payload.durationMs = event.durationMs;
|
|
56
|
+
}
|
|
57
|
+
if (event.kind === 'query.execute.success' && event.rowCount !== undefined) {
|
|
58
|
+
payload.rowCount = event.rowCount;
|
|
59
|
+
}
|
|
60
|
+
if (event.kind === 'query.execute.error') {
|
|
61
|
+
payload.errorName = event.errorName;
|
|
62
|
+
payload.errorMessage = event.errorMessage;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return payload;
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createConsoleRepositoryTelemetry } from './consoleRepositoryTelemetry';
|
|
2
|
+
import type { RepositoryTelemetry } from './types';
|
|
3
|
+
|
|
4
|
+
export type {
|
|
5
|
+
RepositoryTelemetry,
|
|
6
|
+
RepositoryTelemetryConsoleOptions,
|
|
7
|
+
RepositoryTelemetryContext,
|
|
8
|
+
RepositoryTelemetryEvent,
|
|
9
|
+
RepositoryTelemetryEventKind,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
export { createConsoleRepositoryTelemetry } from './consoleRepositoryTelemetry';
|
|
13
|
+
|
|
14
|
+
export const defaultRepositoryTelemetry = createConsoleRepositoryTelemetry();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the repository telemetry hook that application code wants to use.
|
|
18
|
+
*
|
|
19
|
+
* Repository constructors can accept an optional telemetry dependency and call
|
|
20
|
+
* this helper so the default console hook works without extra setup.
|
|
21
|
+
*/
|
|
22
|
+
export function resolveRepositoryTelemetry(
|
|
23
|
+
telemetry?: RepositoryTelemetry,
|
|
24
|
+
): RepositoryTelemetry {
|
|
25
|
+
return telemetry ?? defaultRepositoryTelemetry;
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type RepositoryTelemetryEventKind =
|
|
2
|
+
| 'query.execute.start'
|
|
3
|
+
| 'query.execute.success'
|
|
4
|
+
| 'query.execute.error';
|
|
5
|
+
|
|
6
|
+
export interface RepositoryTelemetryContext {
|
|
7
|
+
repositoryName: string;
|
|
8
|
+
methodName: string;
|
|
9
|
+
queryName?: string;
|
|
10
|
+
sqlText?: string;
|
|
11
|
+
fallback?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface RepositoryTelemetryEventBase extends RepositoryTelemetryContext {
|
|
15
|
+
kind: RepositoryTelemetryEventKind;
|
|
16
|
+
timestamp: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface RepositoryQueryExecuteStartEvent extends RepositoryTelemetryEventBase {
|
|
20
|
+
kind: 'query.execute.start';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RepositoryQueryExecuteSuccessEvent extends RepositoryTelemetryEventBase {
|
|
24
|
+
kind: 'query.execute.success';
|
|
25
|
+
durationMs: number;
|
|
26
|
+
rowCount?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RepositoryQueryExecuteErrorEvent extends RepositoryTelemetryEventBase {
|
|
30
|
+
kind: 'query.execute.error';
|
|
31
|
+
durationMs: number;
|
|
32
|
+
errorName: string;
|
|
33
|
+
errorMessage: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type RepositoryTelemetryEvent =
|
|
37
|
+
| RepositoryQueryExecuteStartEvent
|
|
38
|
+
| RepositoryQueryExecuteSuccessEvent
|
|
39
|
+
| RepositoryQueryExecuteErrorEvent;
|
|
40
|
+
|
|
41
|
+
export interface RepositoryTelemetry {
|
|
42
|
+
emit(event: RepositoryTelemetryEvent): void | Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface RepositoryTelemetryConsoleOptions {
|
|
46
|
+
includeSqlText?: boolean;
|
|
47
|
+
logger?: Pick<Console, 'info' | 'error'>;
|
|
48
|
+
}
|
|
@@ -1,26 +1,25 @@
|
|
|
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
|
-
- If the job is heavy, test smaller units or use fixtures to limit scope.
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/jobs`.
|
|
3
|
+
- Defines contract rules for procedural and batch SQL job code.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Jobs MUST declare explicit transaction boundaries.
|
|
8
|
+
- Jobs MUST emit start/end operational events or logs.
|
|
9
|
+
- Job tests MUST validate observable outcomes.
|
|
10
|
+
|
|
11
|
+
## ALLOWED
|
|
12
|
+
- Jobs MAY execute multiple SQL statements, including temporary-table workflows.
|
|
13
|
+
- Heavy jobs MAY split verification across integration and focused fixture tests.
|
|
14
|
+
|
|
15
|
+
## PROHIBITED
|
|
16
|
+
- Coupling job logic to test-only helpers.
|
|
17
|
+
|
|
18
|
+
# Mandatory Workflow
|
|
19
|
+
- Job changes MUST run integration-style tests for affected job paths.
|
|
20
|
+
|
|
21
|
+
# Hygiene
|
|
22
|
+
- Job logic MUST remain idempotent for rerun safety.
|
|
23
|
+
|
|
24
|
+
# References
|
|
25
|
+
- Parent runtime policy: [../AGENTS.md](../AGENTS.md)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# Jobs
|
|
2
|
-
|
|
1
|
+
# Jobs
|
|
2
|
+
|
|
3
3
|
Job runners that orchestrate repository or SQL workflows.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/presentation`.
|
|
3
|
+
- Defines transport adapters for WebAPI-oriented scaffolds.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Presentation code MUST translate external input/output without embedding domain or persistence rules.
|
|
8
|
+
- Request/response contracts MUST remain explicit.
|
|
9
|
+
|
|
10
|
+
## PROHIBITED
|
|
11
|
+
- Direct SQL, DDL, or QuerySpec ownership.
|
|
12
|
+
- Hidden business rules in controllers or handlers.
|
|
13
|
+
|
|
14
|
+
# Mandatory Workflow
|
|
15
|
+
- Presentation changes MUST run tests for request parsing and response shaping.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/presentation/http`.
|
|
3
|
+
- Defines HTTP-specific transport behavior for WebAPI-oriented scaffolds.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- HTTP adapters MUST translate transport concerns into application-layer inputs and outputs.
|
|
8
|
+
- Handler code MUST keep status codes, headers, and serialization explicit.
|
|
9
|
+
|
|
10
|
+
## PROHIBITED
|
|
11
|
+
- Direct SQL execution.
|
|
12
|
+
- Embedding persistence-specific retries or ZTD workflow rules in handlers.
|
|
13
|
+
|
|
14
|
+
# Mandatory Workflow
|
|
15
|
+
- HTTP adapter changes MUST run transport-focused tests.
|
|
@@ -1,118 +1,30 @@
|
|
|
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
|
-
|
|
31
|
-
- Human-owned contracts live under "src/catalog/specs".
|
|
32
|
-
- Runtime normalization and validation live under "src/catalog/runtime".
|
|
33
|
-
- Repositories MUST NOT invent, infer, or modify contracts.
|
|
34
|
-
|
|
35
|
-
If a contract is insufficient, update the spec/runtime first.
|
|
36
|
-
|
|
37
|
-
## Mandatory runtime usage (required)
|
|
38
|
-
|
|
39
|
-
Repositories MUST use catalog runtime helpers:
|
|
40
|
-
- `ensure*Params` for all external inputs (`unknown -> typed`)
|
|
41
|
-
- `map*RowToDto` for row-to-DTO mapping and output validation
|
|
42
|
-
|
|
43
|
-
Repositories MUST NOT:
|
|
44
|
-
- call spec validators directly
|
|
45
|
-
- bypass runtime normalization
|
|
46
|
-
- return DTOs without runtime validation
|
|
47
|
-
- assume driver-specific runtime types (e.g. timestamps always `Date`)
|
|
48
|
-
|
|
49
|
-
## SQL rules
|
|
50
|
-
|
|
51
|
-
- SQL assets MUST remain DTO-independent.
|
|
52
|
-
- SQL files MUST use snake_case column names.
|
|
53
|
-
- Repositories MUST NOT push DTO aliasing into SQL.
|
|
54
|
-
- Inline SQL strings are forbidden.
|
|
55
|
-
- Repository SQL loading MUST be centralized in shared runtime/repository infrastructure.
|
|
56
|
-
- Repositories MUST reference SQL assets by stable logical key (example: `user/insert_user.sql`).
|
|
57
|
-
- Repository modules MUST NOT pass caller-relative paths (`./`, `../`) or absolute filesystem paths to SQL loaders.
|
|
58
|
-
- The shared loader MUST resolve logical keys against the `src/sql` root (or catalog SQL registry), never relative to the caller file location.
|
|
59
|
-
- Repository modules MUST NOT implement ad-hoc SQL file loading with `readFileSync`, `__dirname`, `import.meta.url`, or direct path resolution.
|
|
60
|
-
|
|
61
|
-
## CUD default policy (important)
|
|
62
|
-
|
|
63
|
-
Default policy for table-oriented CUD is:
|
|
64
|
-
- CREATE SQL MAY use `RETURNING` for identifier columns only.
|
|
65
|
-
- CREATE repository methods MUST return the generated identifier by default.
|
|
66
|
-
- CREATE repository methods MUST NOT perform a follow-up SELECT whose purpose is DTO return shaping.
|
|
67
|
-
- UPDATE/DELETE SQL MUST NOT use `RETURNING`.
|
|
68
|
-
- repositories do NOT perform follow-up SELECTs after UPDATE/DELETE.
|
|
69
|
-
- UPDATE/DELETE methods return `Promise<void>` by default.
|
|
70
|
-
|
|
71
|
-
If a CREATE method must return a DTO, that requirement MUST be explicitly declared in catalog specs by human instruction.
|
|
72
|
-
|
|
73
|
-
## CUD row count rules (non-negotiable)
|
|
74
|
-
|
|
75
|
-
- UPDATE and DELETE MUST rely on driver-reported affected row counts (`rowCount` or equivalent).
|
|
76
|
-
- Repositories MUST NOT use SQL `RETURNING` result presence/count as a substitute for affected row counts.
|
|
77
|
-
- Repositories MUST NOT emulate affected rows using:
|
|
78
|
-
- pre-check SELECT
|
|
79
|
-
- post-check SELECT
|
|
80
|
-
- retry loops
|
|
81
|
-
- shadow queries / CTE hacks
|
|
82
|
-
|
|
83
|
-
If `rowCount === 0`, repositories MUST throw an explicit error.
|
|
84
|
-
|
|
85
|
-
If the driver cannot report affected row counts:
|
|
86
|
-
- CUD verification is unsupported
|
|
87
|
-
- tests MUST fail fast
|
|
88
|
-
- do NOT add workaround logic in repositories
|
|
89
|
-
|
|
90
|
-
## Read (SELECT) rules
|
|
91
|
-
|
|
92
|
-
- SELECT methods may return:
|
|
93
|
-
- `T | null` for single-row queries
|
|
94
|
-
- `T[]` for multi-row queries
|
|
95
|
-
- Absence of rows is NOT an error unless specified by the contract.
|
|
96
|
-
|
|
97
|
-
## Error behavior
|
|
98
|
-
|
|
99
|
-
- Propagate validation errors as failures.
|
|
100
|
-
- Do not silently coerce invalid data.
|
|
101
|
-
- Error messages SHOULD include operation name and identifying parameters.
|
|
102
|
-
|
|
103
|
-
## Testing expectations
|
|
104
|
-
|
|
105
|
-
- Every public repository method MUST be covered by tests.
|
|
106
|
-
- Update/Delete tests MUST verify rowCount handling explicitly.
|
|
107
|
-
- Repository changes without tests are incomplete.
|
|
108
|
-
|
|
109
|
-
## Guiding principle
|
|
110
|
-
|
|
111
|
-
Repositories execute contracts.
|
|
112
|
-
They do not interpret intent.
|
|
113
|
-
|
|
114
|
-
If correctness depends on extra queries to "confirm" changes:
|
|
115
|
-
- the contract is wrong
|
|
116
|
-
- or the driver is unsupported
|
|
117
|
-
|
|
118
|
-
Fix the contract, not the repository.
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/src/repositories`.
|
|
3
|
+
- Defines runtime repository responsibilities for SQL execution orchestration.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- Repositories MUST load SQL assets from `src/sql` through shared loader infrastructure.
|
|
8
|
+
- Repositories MUST use catalog runtime helpers (`ensure*`, `map*`) for input/output validation.
|
|
9
|
+
- Repository CUD behavior MUST follow contract rules for `RETURNING`, rowCount handling, and explicit unsupported-driver failures.
|
|
10
|
+
- Repository modules MUST reference SQL by stable logical keys.
|
|
11
|
+
- Repository constructors SHOULD accept an optional telemetry dependency from `src/infrastructure/telemetry/repositoryTelemetry.ts`.
|
|
12
|
+
- Public repository methods MUST be covered by tests.
|
|
13
|
+
|
|
14
|
+
## ALLOWED
|
|
15
|
+
- SELECT methods MAY return `T | null` or `T[]` according to contract cardinality.
|
|
16
|
+
|
|
17
|
+
## PROHIBITED
|
|
18
|
+
- Embedding business rules or contract inference in repositories.
|
|
19
|
+
- Inline SQL strings or ad-hoc SQL file path resolution.
|
|
20
|
+
- Follow-up SELECT workarounds to emulate CUD success semantics.
|
|
21
|
+
|
|
22
|
+
# Mandatory Workflow
|
|
23
|
+
- Repository changes MUST run tests covering mapping, rowCount behavior, and error surfaces.
|
|
24
|
+
|
|
25
|
+
# Hygiene
|
|
26
|
+
- Error messages MUST include operation identifiers and relevant parameters.
|
|
27
|
+
|
|
28
|
+
# References
|
|
29
|
+
- Tables repository policy: [./tables/AGENTS.md](./tables/AGENTS.md)
|
|
30
|
+
- Views repository policy: [./views/AGENTS.md](./views/AGENTS.md)
|