@rawsql-ts/ztd-cli 0.16.0 → 0.19.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 -353
- package/package.json +35 -17
- package/templates/.editorconfig +16 -16
- package/templates/.prettierignore +2 -2
- package/templates/.prettierrc +24 -24
- package/templates/AGENTS.md +30 -325
- 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 -217
- package/templates/README.webapi.md +38 -0
- package/templates/scripts/local-source-guard.mjs +189 -0
- package/templates/src/AGENTS.md +26 -0
- package/templates/src/application/AGENTS.md +15 -0
- package/templates/src/application/README.md +6 -0
- package/templates/src/catalog/AGENTS.md +28 -0
- package/templates/src/catalog/runtime/AGENTS.md +28 -0
- package/templates/src/catalog/runtime/_coercions.local-source.ts +30 -0
- package/templates/src/catalog/runtime/_coercions.ts +30 -0
- package/templates/src/catalog/runtime/_smoke.runtime.ts +21 -0
- package/templates/src/catalog/specs/AGENTS.md +41 -0
- package/templates/src/catalog/specs/_smoke.spec.arktype.ts +21 -0
- package/templates/src/catalog/specs/_smoke.spec.zod.ts +20 -0
- package/templates/src/db/sql-client-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/src/infrastructure/db/sql-client.ts +24 -0
- 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 -0
- package/templates/src/jobs/README.md +3 -0
- package/templates/src/local/sql-contract.ts +1 -0
- 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 -0
- package/templates/src/repositories/tables/AGENTS.md +29 -0
- package/templates/src/repositories/tables/README.md +5 -0
- package/templates/src/repositories/views/AGENTS.md +25 -0
- package/templates/src/repositories/views/README.md +5 -0
- package/templates/src/sql/AGENTS.md +30 -0
- package/templates/src/sql/README.md +6 -0
- package/templates/tests/AGENTS.md +29 -169
- package/templates/tests/generated/AGENTS.md +23 -0
- package/templates/tests/smoke.test.ts +25 -0
- package/templates/tests/smoke.validation.test.ts +34 -0
- package/templates/tests/support/AGENTS.md +24 -0
- package/templates/tests/support/global-setup.ts +15 -30
- package/templates/tests/support/testkit-client.ts +14 -742
- package/templates/tests/support/testkit-client.webapi.ts +14 -0
- package/templates/tests/ztd-layout.generated.ts +6 -6
- package/templates/tsconfig.json +15 -8
- package/templates/vitest.config.ts +13 -13
- package/templates/ztd/AGENTS.md +23 -74
- package/templates/ztd/README.md +6 -15
- package/templates/ztd/ddl/AGENTS.md +26 -0
- package/templates/ztd/ddl/demo.sql +74 -0
- 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 -66
- package/dist/commands/init.js +0 -838
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/lint.d.ts +0 -59
- package/dist/commands/lint.js +0 -338
- 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 -202
- 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/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
- package/templates/src/repositories/user-accounts.ts +0 -179
- package/templates/tests/user-profiles.test.ts +0 -161
- package/templates/tests/writer-constraints.test.ts +0 -32
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SqlClient } from '../../src/infrastructure/db/sql-client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Placeholder for wiring an SQL client that tests can reuse.
|
|
5
|
+
*
|
|
6
|
+
* Replace this implementation with your chosen adapter (pg, mysql2, etc.) or a
|
|
7
|
+
* fixture-based helper that fulfills the `SqlClient` contract. Avoid committing
|
|
8
|
+
* production credentials inside this file.
|
|
9
|
+
*/
|
|
10
|
+
export async function createTestkitClient(): Promise<SqlClient> {
|
|
11
|
+
throw new Error(
|
|
12
|
+
'Provide a SqlClient implementation here (for example by adapting pg via src/infrastructure/db/sql-client-adapters.ts, or by importing @rawsql-ts/adapter-node-pg for ZTD-backed tests).',
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// GENERATED FILE. DO NOT EDIT.
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
ztdRootDir: 'ztd',
|
|
5
|
-
ddlDir: 'ztd/ddl',
|
|
6
|
-
};
|
|
1
|
+
// GENERATED FILE. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
ztdRootDir: 'ztd',
|
|
5
|
+
ddlDir: 'ztd/ddl',
|
|
6
|
+
};
|
package/templates/tsconfig.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022"],
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"outDir": "dist",
|
|
12
|
+
"tsBuildInfoFile": "dist/.tsbuildinfo"
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts", "tests/**/*.ts"]
|
|
15
|
+
}
|
|
@@ -1,13 +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
|
-
});
|
|
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
|
+
});
|
package/templates/ztd/AGENTS.md
CHANGED
|
@@ -1,74 +1,23 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
This directory contains all canonical definitions of database structure, including:
|
|
25
|
-
|
|
26
|
-
- CREATE TABLE
|
|
27
|
-
- ALTER TABLE
|
|
28
|
-
- Constraints
|
|
29
|
-
- Indexes
|
|
30
|
-
|
|
31
|
-
It is the **single source of truth** for the physical database schema as interpreted by ztd-cli.
|
|
32
|
-
|
|
33
|
-
### Behavior Rules (strict)
|
|
34
|
-
|
|
35
|
-
- **Never modify files in this directory unless explicitly instructed by a human.**
|
|
36
|
-
- Do not apply “helpful” refactors, cleanups, or formatting changes on your own.
|
|
37
|
-
- You may propose edits or review changes when asked, but you must not apply them without approval.
|
|
38
|
-
- All DDL statements must be:
|
|
39
|
-
- Valid PostgreSQL syntax
|
|
40
|
-
- Explicitly semicolon-terminated
|
|
41
|
-
- Do not reorder statements; dependency and execution order matters.
|
|
42
|
-
- Preserve all human-authored:
|
|
43
|
-
- Naming
|
|
44
|
-
- Formatting
|
|
45
|
-
- Comments
|
|
46
|
-
- Structural intent
|
|
47
|
-
- When asked to extend existing definitions:
|
|
48
|
-
- Do not remove or rewrite existing columns or comments unless explicitly told.
|
|
49
|
-
- Maintain column order and constraint style.
|
|
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.
|
|
54
|
-
|
|
55
|
-
If there is uncertainty, stop and request clarification instead of guessing.
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
- Only `ztd/ddl` is part of the canonical `ztd` contract; do not create or assume additional subdirectories without explicit human direction.
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
## Absolute Restrictions (important)
|
|
64
|
-
|
|
65
|
-
- AI must not modify anything under `ztd/` by default.
|
|
66
|
-
- DDL is the only **human-led artifact** in this directory.
|
|
67
|
-
- AI may assist by:
|
|
68
|
-
- Reading
|
|
69
|
-
- Explaining
|
|
70
|
-
- Proposing diffs
|
|
71
|
-
- AI may apply changes **only** with explicit instruction.
|
|
72
|
-
- No tooling limitation, test strategy, or runtime design justifies modifying `ztd/` artifacts.
|
|
73
|
-
|
|
74
|
-
Violation of these rules leads to silent corruption of domain meaning and is unacceptable.
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/ztd`.
|
|
3
|
+
- Governs ZTD inputs and related metadata used for generation.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- `ztd/ddl` MUST remain the human-owned source of truth inside `ztd`.
|
|
8
|
+
|
|
9
|
+
## ALLOWED
|
|
10
|
+
- Tests MAY reference ZTD DDL and generated outputs through ZTD tooling.
|
|
11
|
+
|
|
12
|
+
## PROHIBITED
|
|
13
|
+
- Creating new `ztd` subdirectories without explicit instruction.
|
|
14
|
+
- Modifying `ztd/README.md` without explicit instruction.
|
|
15
|
+
|
|
16
|
+
# Mandatory Workflow
|
|
17
|
+
- DDL-related rule updates MUST be made in `ztd/ddl/AGENTS.md`.
|
|
18
|
+
|
|
19
|
+
# Hygiene
|
|
20
|
+
- Keep runtime code independent from `ztd` subtree dependencies.
|
|
21
|
+
|
|
22
|
+
# References
|
|
23
|
+
- DDL policy: [./ddl/AGENTS.md](./ddl/AGENTS.md)
|
package/templates/ztd/README.md
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
This directory
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.
|
|
11
|
-
|
|
12
|
-
## Workflow expectations
|
|
13
|
-
|
|
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.
|
|
1
|
+
# ztd/
|
|
2
|
+
|
|
3
|
+
This directory stores ZTD schema artifacts.
|
|
4
|
+
|
|
5
|
+
- `ztd/ddl/<schema>.sql` is the source of truth for schema.
|
|
6
|
+
- Run `npx ztd ztd-config` to regenerate `tests/generated` outputs.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates/ztd/ddl`.
|
|
3
|
+
- Defines contract rules for human-owned physical schema definitions.
|
|
4
|
+
|
|
5
|
+
# Policy
|
|
6
|
+
## REQUIRED
|
|
7
|
+
- DDL semantics MUST remain human-owned.
|
|
8
|
+
- Table and column comments MUST be included for important schema elements.
|
|
9
|
+
- DDL naming and file organization MUST stay consistent within the selected strategy.
|
|
10
|
+
|
|
11
|
+
## ALLOWED
|
|
12
|
+
- AI MAY assist with mechanical DDL edits when explicitly requested.
|
|
13
|
+
- Foreign keys MAY be used when intentional and documented.
|
|
14
|
+
|
|
15
|
+
## PROHIBITED
|
|
16
|
+
- Inventing domain rules without explicit instruction.
|
|
17
|
+
- Inconsistent schema splitting strategy within this subtree.
|
|
18
|
+
|
|
19
|
+
# Mandatory Workflow
|
|
20
|
+
- DDL changes MUST preserve comment statements and naming conventions.
|
|
21
|
+
|
|
22
|
+
# Hygiene
|
|
23
|
+
- Maintain explicit NOT NULL and unique constraints where contract semantics require them.
|
|
24
|
+
|
|
25
|
+
# References
|
|
26
|
+
- Parent ZTD policy: [../AGENTS.md](../AGENTS.md)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
create table "user" (
|
|
2
|
+
user_id serial8 primary key,
|
|
3
|
+
user_name text not null,
|
|
4
|
+
email text not null,
|
|
5
|
+
created_at timestamptz not null default current_timestamp
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
comment on table "user" is
|
|
9
|
+
'User master. Referenced by task_assignment.';
|
|
10
|
+
|
|
11
|
+
comment on column "user".user_id is
|
|
12
|
+
'Primary key of user.';
|
|
13
|
+
comment on column "user".user_name is
|
|
14
|
+
'Display name of the user.';
|
|
15
|
+
comment on column "user".email is
|
|
16
|
+
'Email address of the user.';
|
|
17
|
+
comment on column "user".created_at is
|
|
18
|
+
'Timestamp when the user was created.';
|
|
19
|
+
|
|
20
|
+
create table task (
|
|
21
|
+
task_id serial8 primary key,
|
|
22
|
+
title text not null,
|
|
23
|
+
status text not null,
|
|
24
|
+
priority integer not null,
|
|
25
|
+
due_date date,
|
|
26
|
+
created_at timestamptz not null default current_timestamp
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
comment on table task is
|
|
30
|
+
'Task entity. Current assignee is derived from task_assignment history.';
|
|
31
|
+
|
|
32
|
+
comment on column task.task_id is
|
|
33
|
+
'Primary key of task.';
|
|
34
|
+
comment on column task.title is
|
|
35
|
+
'Short description of the task.';
|
|
36
|
+
comment on column task.status is
|
|
37
|
+
'Task status. Example: open, in_progress, done.';
|
|
38
|
+
comment on column task.priority is
|
|
39
|
+
'Priority of the task. Higher value means higher priority.';
|
|
40
|
+
comment on column task.due_date is
|
|
41
|
+
'Optional due date of the task.';
|
|
42
|
+
comment on column task.created_at is
|
|
43
|
+
'Timestamp when the task was created.';
|
|
44
|
+
|
|
45
|
+
create table task_assignment (
|
|
46
|
+
task_assignment_id serial8 primary key,
|
|
47
|
+
task_id bigint not null,
|
|
48
|
+
user_id bigint not null,
|
|
49
|
+
assigned_at timestamptz not null default current_timestamp
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
comment on table task_assignment is
|
|
53
|
+
'Assignment history of tasks. Latest assigned_at defines current assignee.';
|
|
54
|
+
|
|
55
|
+
comment on column task_assignment.task_assignment_id is
|
|
56
|
+
'Primary key of task_assignment.';
|
|
57
|
+
comment on column task_assignment.task_id is
|
|
58
|
+
'Referenced task identifier.';
|
|
59
|
+
comment on column task_assignment.user_id is
|
|
60
|
+
'Referenced user identifier.';
|
|
61
|
+
comment on column task_assignment.assigned_at is
|
|
62
|
+
'Timestamp when the task was assigned to the user.';
|
|
63
|
+
|
|
64
|
+
create index idx_task_assignment_task
|
|
65
|
+
on task_assignment(task_id);
|
|
66
|
+
|
|
67
|
+
create index idx_task_assignment_task_time
|
|
68
|
+
on task_assignment(task_id, assigned_at desc);
|
|
69
|
+
|
|
70
|
+
comment on index idx_task_assignment_task is
|
|
71
|
+
'Index for joining task_assignment by task_id.';
|
|
72
|
+
|
|
73
|
+
comment on index idx_task_assignment_task_time is
|
|
74
|
+
'Index for resolving latest assignment per task.';
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 MSugiura
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/commands/ddl.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
/**
|
|
3
|
-
* Registers all DDL-related commands (`pull`, `gen-entities`, `diff`) on the top-level CLI program.
|
|
4
|
-
* @param program - The Commander program instance to extend.
|
|
5
|
-
*/
|
|
6
|
-
export declare function registerDdlCommands(program: Command): void;
|
|
7
|
-
export { collectDirectories, parseExtensions, DEFAULT_EXTENSIONS, DEFAULT_DDL_DIRECTORY } from './options';
|
package/dist/commands/ddl.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DEFAULT_DDL_DIRECTORY = exports.DEFAULT_EXTENSIONS = exports.parseExtensions = exports.collectDirectories = void 0;
|
|
7
|
-
exports.registerDdlCommands = registerDdlCommands;
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const diff_1 = require("./diff");
|
|
10
|
-
const genEntities_1 = require("./genEntities");
|
|
11
|
-
const pull_1 = require("./pull");
|
|
12
|
-
const ztdProjectConfig_1 = require("../utils/ztdProjectConfig");
|
|
13
|
-
const dbConnection_1 = require("../utils/dbConnection");
|
|
14
|
-
const options_1 = require("./options");
|
|
15
|
-
/**
|
|
16
|
-
* Registers all DDL-related commands (`pull`, `gen-entities`, `diff`) on the top-level CLI program.
|
|
17
|
-
* @param program - The Commander program instance to extend.
|
|
18
|
-
*/
|
|
19
|
-
function registerDdlCommands(program) {
|
|
20
|
-
const ddl = program.command('ddl').description('DDL-focused workflows');
|
|
21
|
-
ddl
|
|
22
|
-
.command('pull')
|
|
23
|
-
.description('Retrieve the current schema DDL from a PostgreSQL database')
|
|
24
|
-
.option('--url <databaseUrl>', 'Connection string to use for pg_dump (optional; fallback to env/config)')
|
|
25
|
-
.option('--out <directory>', 'Destination directory for the pulled DDL', options_1.DEFAULT_DDL_DIRECTORY)
|
|
26
|
-
.option('--db-host <host>', 'Database host to use instead of DATABASE_URL')
|
|
27
|
-
.option('--db-port <port>', 'Database port (defaults to 5432)')
|
|
28
|
-
.option('--db-user <user>', 'Database user to connect as')
|
|
29
|
-
.option('--db-password <password>', 'Database password')
|
|
30
|
-
.option('--db-name <name>', 'Database name to connect to')
|
|
31
|
-
.option('--pg-dump-path <path>', 'Custom pg_dump executable path')
|
|
32
|
-
.option('--schema <schema>', 'Schema name to include (repeatable)', options_1.collectValues, [])
|
|
33
|
-
.option('--table <table>', 'Table spec (schema.table) to include (repeatable)', options_1.collectValues, [])
|
|
34
|
-
.action(async (options) => {
|
|
35
|
-
var _a, _b, _c;
|
|
36
|
-
const connection = resolveCliConnection(options);
|
|
37
|
-
await (0, pull_1.runPullSchema)({
|
|
38
|
-
url: connection.url,
|
|
39
|
-
out: (_a = options.out) !== null && _a !== void 0 ? _a : options_1.DEFAULT_DDL_DIRECTORY,
|
|
40
|
-
pgDumpPath: options.pgDumpPath,
|
|
41
|
-
schemas: (_b = options.schema) !== null && _b !== void 0 ? _b : [],
|
|
42
|
-
tables: (_c = options.table) !== null && _c !== void 0 ? _c : [],
|
|
43
|
-
connectionContext: connection.context
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
ddl
|
|
47
|
-
.command('gen-entities')
|
|
48
|
-
.description('Generate optional entities.ts helpers from the DDL snapshot')
|
|
49
|
-
.option('--ddl-dir <directory>', 'DDL directory to scan (repeatable)', options_1.collectDirectories, [])
|
|
50
|
-
.option('--extensions <list>', 'Comma-separated extensions to include', options_1.parseExtensions, options_1.DEFAULT_EXTENSIONS)
|
|
51
|
-
.option('--out <file>', 'Destination TypeScript file', node_path_1.default.join('src', 'entities.ts'))
|
|
52
|
-
.action(async (options) => {
|
|
53
|
-
var _a;
|
|
54
|
-
const directories = (0, options_1.normalizeDirectoryList)(options.ddlDir, options_1.DEFAULT_DDL_DIRECTORY);
|
|
55
|
-
const extensions = (0, options_1.resolveExtensions)(options.extensions, options_1.DEFAULT_EXTENSIONS);
|
|
56
|
-
await (0, genEntities_1.runGenerateEntities)({
|
|
57
|
-
directories,
|
|
58
|
-
extensions,
|
|
59
|
-
out: (_a = options.out) !== null && _a !== void 0 ? _a : node_path_1.default.join('src', 'entities.ts')
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
ddl
|
|
63
|
-
.command('diff')
|
|
64
|
-
.description('Compare local DDL against a live PostgreSQL database and emit a plan')
|
|
65
|
-
.option('--ddl-dir <directory>', 'DDL directory to scan (repeatable)', options_1.collectDirectories, [])
|
|
66
|
-
.option('--extensions <list>', 'Comma-separated extensions to include', options_1.parseExtensions, options_1.DEFAULT_EXTENSIONS)
|
|
67
|
-
.option('--url <databaseUrl>', 'Connection string to use for pg_dump (optional; fallback to env/config)')
|
|
68
|
-
.requiredOption('--out <file>', 'Output path for the generated plan file')
|
|
69
|
-
.option('--db-host <host>', 'Database host to use instead of DATABASE_URL')
|
|
70
|
-
.option('--db-port <port>', 'Database port (defaults to 5432)')
|
|
71
|
-
.option('--db-user <user>', 'Database user to connect as')
|
|
72
|
-
.option('--db-password <password>', 'Database password')
|
|
73
|
-
.option('--db-name <name>', 'Database name to connect to')
|
|
74
|
-
.option('--pg-dump-path <path>', 'Custom pg_dump executable path')
|
|
75
|
-
.action(async (options) => {
|
|
76
|
-
var _a;
|
|
77
|
-
const directories = (0, options_1.normalizeDirectoryList)((_a = options.ddlDir) !== null && _a !== void 0 ? _a : [], options_1.DEFAULT_DDL_DIRECTORY);
|
|
78
|
-
const extensions = (0, options_1.resolveExtensions)(options.extensions, options_1.DEFAULT_EXTENSIONS);
|
|
79
|
-
const connection = resolveCliConnection(options);
|
|
80
|
-
await (0, diff_1.runDiffSchema)({
|
|
81
|
-
directories,
|
|
82
|
-
extensions,
|
|
83
|
-
url: connection.url,
|
|
84
|
-
out: options.out,
|
|
85
|
-
pgDumpPath: options.pgDumpPath,
|
|
86
|
-
connectionContext: connection.context
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Resolves connection metadata for CLI commands using flags, environment, and project config.
|
|
92
|
-
* @param options - CLI options containing optional overrides.
|
|
93
|
-
* @returns The resolved connection and context.
|
|
94
|
-
*/
|
|
95
|
-
function resolveCliConnection(options) {
|
|
96
|
-
// Gather configuration once per command so overrides and defaults stay synchronized.
|
|
97
|
-
return (0, dbConnection_1.resolveDatabaseConnection)(buildFlagSet(options), (0, ztdProjectConfig_1.loadZtdProjectConfig)(), options.url);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Normalizes the incoming CLI flag values into the shared DbConnectionFlags shape.
|
|
101
|
-
* @param options - CLI options exposing partial connection pieces.
|
|
102
|
-
* @returns Flag object consumed by the `resolveDatabaseConnection` helper.
|
|
103
|
-
*/
|
|
104
|
-
function buildFlagSet(options) {
|
|
105
|
-
return {
|
|
106
|
-
host: options.dbHost,
|
|
107
|
-
port: options.dbPort,
|
|
108
|
-
user: options.dbUser,
|
|
109
|
-
password: options.dbPassword,
|
|
110
|
-
database: options.dbName
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
var options_2 = require("./options");
|
|
114
|
-
Object.defineProperty(exports, "collectDirectories", { enumerable: true, get: function () { return options_2.collectDirectories; } });
|
|
115
|
-
Object.defineProperty(exports, "parseExtensions", { enumerable: true, get: function () { return options_2.parseExtensions; } });
|
|
116
|
-
Object.defineProperty(exports, "DEFAULT_EXTENSIONS", { enumerable: true, get: function () { return options_2.DEFAULT_EXTENSIONS; } });
|
|
117
|
-
Object.defineProperty(exports, "DEFAULT_DDL_DIRECTORY", { enumerable: true, get: function () { return options_2.DEFAULT_DDL_DIRECTORY; } });
|
|
118
|
-
//# sourceMappingURL=ddl.js.map
|
package/dist/commands/ddl.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ddl.js","sourceRoot":"","sources":["../../src/commands/ddl.ts"],"names":[],"mappings":";;;;;;AA4CA,kDAsEC;AAlHD,0DAA6B;AAE7B,iCAAuC;AACvC,+CAAoD;AACpD,iCAAuC;AACvC,gEAAiE;AACjE,wDAAkE;AAElE,uCAQmB;AAwBnB;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,OAAgB;IAClD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC;IAExE,GAAG;SACA,OAAO,CAAC,MAAM,CAAC;SACb,WAAW,CAAC,4DAA4D,CAAC;SACzE,MAAM,CAAC,qBAAqB,EAAE,yEAAyE,CAAC;SACxG,MAAM,CAAC,mBAAmB,EAAE,0CAA0C,EAAE,+BAAqB,CAAC;SAC9F,MAAM,CAAC,kBAAkB,EAAE,8CAA8C,CAAC;SAC1E,MAAM,CAAC,kBAAkB,EAAE,kCAAkC,CAAC;SAC9D,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC;SACzD,MAAM,CAAC,0BAA0B,EAAE,mBAAmB,CAAC;SACvD,MAAM,CAAC,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ACjB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,iBAAiB,EAAE,UAAU,CAAC,OAAO;SACtC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACT,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,OAA6B;IACzD,qFAAqF;IACrF,OAAO,IAAA,wCAAyB,EAAC,YAAY,CAAC,OAAO,CAAC,EAAE,IAAA,uCAAoB,GAAE,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;AAC/F,CAAC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,OAA6B;IACjD,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,MAAM;QACpB,IAAI,EAAE,OAAO,CAAC,MAAM;QACpB,IAAI,EAAE,OAAO,CAAC,MAAM;QACpB,QAAQ,EAAE,OAAO,CAAC,UAAU;QAC5B,QAAQ,EAAE,OAAO,CAAC,MAAM;KACzB,CAAC;AACJ,CAAC;AAED,qCAA2G;AAAlG,6GAAA,kBAAkB,OAAA;AAAE,0GAAA,eAAe,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,gHAAA,qBAAqB,OAAA"}
|
package/dist/commands/diff.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { DbConnectionContext } from '../utils/dbConnection';
|
|
2
|
-
export interface DiffSchemaOptions {
|
|
3
|
-
directories: string[];
|
|
4
|
-
extensions: string[];
|
|
5
|
-
url: string;
|
|
6
|
-
out: string;
|
|
7
|
-
pgDumpPath?: string;
|
|
8
|
-
connectionContext?: DbConnectionContext;
|
|
9
|
-
}
|
|
10
|
-
export declare function runDiffSchema(options: DiffSchemaOptions): void;
|
package/dist/commands/diff.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.runDiffSchema = runDiffSchema;
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const diff_1 = require("diff");
|
|
10
|
-
const collectSqlFiles_1 = require("../utils/collectSqlFiles");
|
|
11
|
-
const fs_1 = require("../utils/fs");
|
|
12
|
-
const pgDump_1 = require("../utils/pgDump");
|
|
13
|
-
const connectionSummary_1 = require("../utils/connectionSummary");
|
|
14
|
-
function runDiffSchema(options) {
|
|
15
|
-
const localSources = (0, collectSqlFiles_1.collectSqlFiles)(options.directories, options.extensions);
|
|
16
|
-
if (localSources.length === 0) {
|
|
17
|
-
throw new Error(`No SQL files were discovered under ${options.directories.join(', ')}`);
|
|
18
|
-
}
|
|
19
|
-
// Concatenate the local DDL files in a stable order for deterministic diff outputs.
|
|
20
|
-
const localSql = localSources.map((source) => source.sql).join('\n\n');
|
|
21
|
-
const remoteSql = (0, pgDump_1.runPgDump)({
|
|
22
|
-
url: options.url,
|
|
23
|
-
pgDumpPath: options.pgDumpPath,
|
|
24
|
-
connectionContext: options.connectionContext
|
|
25
|
-
});
|
|
26
|
-
const hasChanges = localSql !== remoteSql;
|
|
27
|
-
// Create a unified diff patch only when there are material differences to report.
|
|
28
|
-
const patch = hasChanges
|
|
29
|
-
? (0, diff_1.createTwoFilesPatch)('local', 'database', localSql, remoteSql, '', '', { context: 3 })
|
|
30
|
-
: '-- No schema differences detected.';
|
|
31
|
-
const databaseTarget = (0, connectionSummary_1.formatConnectionTarget)(options.connectionContext) || 'target: unknown';
|
|
32
|
-
const header = `-- ztd ddl diff plan\n-- Local DDL: ${options.directories.join(', ')}\n-- Database: ${databaseTarget}\n-- Generated: ${new Date().toISOString()}\n\n`;
|
|
33
|
-
// Guarantee the target path exists before emitting the plan file.
|
|
34
|
-
(0, fs_1.ensureDirectory)(node_path_1.default.dirname(options.out));
|
|
35
|
-
(0, node_fs_1.writeFileSync)(options.out, `${header}${patch}\n`, 'utf8');
|
|
36
|
-
console.log(`DDL diff plan written to ${options.out}`);
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=diff.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/commands/diff.ts"],"names":[],"mappings":";;;;;AAkBA,sCA2BC;AA7CD,qCAAwC;AACxC,0DAA6B;AAC7B,+BAA2C;AAC3C,8DAA2D;AAC3D,oCAA8C;AAC9C,4CAA4C;AAC5C,kEAAoE;AAYpE,SAAgB,aAAa,CAAC,OAA0B;IACtD,MAAM,YAAY,GAAG,IAAA,iCAAe,EAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9E,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,sCAAsC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,oFAAoF;IACpF,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvE,MAAM,SAAS,GAAG,IAAA,kBAAS,EAAC;QAC1B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;KAC7C,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,QAAQ,KAAK,SAAS,CAAC;IAC1C,kFAAkF;IAClF,MAAM,KAAK,GAAG,UAAU;QACtB,CAAC,CAAC,IAAA,0BAAmB,EAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QACvF,CAAC,CAAC,oCAAoC,CAAC;IAEzC,MAAM,cAAc,GAAG,IAAA,0CAAsB,EAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAC9F,MAAM,MAAM,GAAG,uCAAuC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,cAAc,mBAAmB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC;IAEtK,kEAAkE;IAClE,IAAA,oBAAe,EAAC,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,IAAA,uBAAa,EAAC,OAAO,CAAC,GAAG,EAAE,GAAG,MAAM,GAAG,KAAK,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,4BAA4B,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.runGenerateEntities = runGenerateEntities;
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const collectSqlFiles_1 = require("../utils/collectSqlFiles");
|
|
10
|
-
const fs_1 = require("../utils/fs");
|
|
11
|
-
const typeMapper_1 = require("../utils/typeMapper");
|
|
12
|
-
const ztdConfig_1 = require("./ztdConfig");
|
|
13
|
-
function runGenerateEntities(options) {
|
|
14
|
-
const sources = (0, collectSqlFiles_1.collectSqlFiles)(options.directories, options.extensions);
|
|
15
|
-
if (sources.length === 0) {
|
|
16
|
-
throw new Error(`No SQL files were discovered under ${options.directories.join(', ')}`);
|
|
17
|
-
}
|
|
18
|
-
const tables = (0, ztdConfig_1.snapshotTableMetadata)(sources);
|
|
19
|
-
if (tables.length === 0) {
|
|
20
|
-
throw new Error('The provided DDL sources did not contain any CREATE TABLE statements.');
|
|
21
|
-
}
|
|
22
|
-
const output = renderEntitiesFile(tables);
|
|
23
|
-
(0, fs_1.ensureDirectory)(node_path_1.default.dirname(options.out));
|
|
24
|
-
(0, node_fs_1.writeFileSync)(options.out, output, 'utf8');
|
|
25
|
-
console.log(`Generated ${tables.length} schema helpers at ${options.out}`);
|
|
26
|
-
}
|
|
27
|
-
function renderEntitiesFile(tables) {
|
|
28
|
-
// The header reminds maintainers that this file is a secondary reference next to tests/generated/ztd-row-map.generated.ts.
|
|
29
|
-
const header = [
|
|
30
|
-
'// ENTITY HELPERS - AUTO GENERATED',
|
|
31
|
-
'// Complementary reference for tooling. TestRowMap in tests/generated/ztd-row-map.generated.ts remains authoritative.',
|
|
32
|
-
''
|
|
33
|
-
].join('\n');
|
|
34
|
-
// Emit an interface per table to keep column metadata available for optional helpers.
|
|
35
|
-
const definitions = tables
|
|
36
|
-
.map((table) => {
|
|
37
|
-
const entityName = table.testRowInterfaceName.replace(/TestRow$/, 'Entity');
|
|
38
|
-
const fields = table.columns
|
|
39
|
-
.map((column) => {
|
|
40
|
-
const baseType = (0, typeMapper_1.mapSqlTypeToTs)(column.typeName, `${table.name}.${column.name}`);
|
|
41
|
-
const tsType = column.isNullable ? `${baseType} | null` : baseType;
|
|
42
|
-
return ` ${column.name}: ${tsType};`;
|
|
43
|
-
})
|
|
44
|
-
.join('\n');
|
|
45
|
-
return `export interface ${entityName} {\n${fields}\n}`;
|
|
46
|
-
})
|
|
47
|
-
.join('\n\n');
|
|
48
|
-
return `${header}${definitions}\n`;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=genEntities.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"genEntities.js","sourceRoot":"","sources":["../../src/commands/genEntities.ts"],"names":[],"mappings":";;;;;AAaA,kDAeC;AA5BD,qCAAwC;AACxC,0D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AM,MAAM,GAAG,KAAK,CAAC,OAAO;aACzB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACd,MAAM,QAAQ,GAAG,IAAA,2BAAc,EAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACjF,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;YACnE,OAAO,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,GAAG,CAAC;QACxC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,oBAAoB,UAAU,OAAO,MAAM,KAAK,CAAC;IAC1D,CAAC,CAAC;SACD,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhB,OAAO,GAAG,MAAM,GAAG,WAAW,IAAI,CAAC;AACrC,CAAC"}
|
package/dist/commands/init.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { type ZtdConfigGenerationOptions } from './ztdConfig';
|
|
3
|
-
import { type PullSchemaOptions } from './pull';
|
|
4
|
-
type PackageManager = 'pnpm' | 'npm' | 'yarn';
|
|
5
|
-
type PackageInstallKind = 'devDependencies' | 'install';
|
|
6
|
-
/**
|
|
7
|
-
* Prompt interface for interactive input during `ztd init`.
|
|
8
|
-
*/
|
|
9
|
-
export interface Prompter {
|
|
10
|
-
selectChoice(question: string, choices: string[]): Promise<number>;
|
|
11
|
-
promptInput(question: string, example?: string): Promise<string>;
|
|
12
|
-
confirm(question: string): Promise<boolean>;
|
|
13
|
-
close(): void;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Create a readline-backed prompter that reads from stdin/stdout.
|
|
17
|
-
*/
|
|
18
|
-
export declare function createConsolePrompter(): Prompter;
|
|
19
|
-
/**
|
|
20
|
-
* Summarizes how an individual file was created during initialization.
|
|
21
|
-
*/
|
|
22
|
-
export interface FileSummary {
|
|
23
|
-
relativePath: string;
|
|
24
|
-
outcome: 'created' | 'overwritten' | 'unchanged';
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Result payload for `ztd init` describing outputs and next steps.
|
|
28
|
-
*/
|
|
29
|
-
export interface InitResult {
|
|
30
|
-
summary: string;
|
|
31
|
-
files: FileSummary[];
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Dependency overrides used to orchestrate the init flow and IO side effects.
|
|
35
|
-
*/
|
|
36
|
-
export interface ZtdConfigWriterDependencies {
|
|
37
|
-
ensureDirectory: (directory: string) => void;
|
|
38
|
-
writeFile: (filePath: string, contents: string) => void;
|
|
39
|
-
fileExists: (filePath: string) => boolean;
|
|
40
|
-
runPullSchema: (options: PullSchemaOptions) => Promise<void> | void;
|
|
41
|
-
runGenerateZtdConfig: (options: ZtdConfigGenerationOptions) => Promise<void> | void;
|
|
42
|
-
checkPgDump: () => boolean;
|
|
43
|
-
log: (message: string) => void;
|
|
44
|
-
copyAgentsTemplate: (rootDir: string) => string | null;
|
|
45
|
-
installPackages: (options: {
|
|
46
|
-
rootDir: string;
|
|
47
|
-
kind: PackageInstallKind;
|
|
48
|
-
packages: string[];
|
|
49
|
-
packageManager: PackageManager;
|
|
50
|
-
}) => Promise<void> | void;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Options for configuring the `ztd init` command execution.
|
|
54
|
-
*/
|
|
55
|
-
export interface InitCommandOptions {
|
|
56
|
-
rootDir?: string;
|
|
57
|
-
dependencies?: Partial<ZtdConfigWriterDependencies>;
|
|
58
|
-
withSqlClient?: boolean;
|
|
59
|
-
withAppInterface?: boolean;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Run the interactive `ztd init` workflow and return the resulting summary.
|
|
63
|
-
*/
|
|
64
|
-
export declare function runInitCommand(prompter: Prompter, options?: InitCommandOptions): Promise<InitResult>;
|
|
65
|
-
export declare function registerInitCommand(program: Command): void;
|
|
66
|
-
export {};
|