@rawsql-ts/ztd-cli 0.17.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 -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.local-source.ts +30 -0
- 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/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 -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
package/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rawsql-ts/ztd-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "DB-agnostic scaffolding and DDL helpers for Zero Table Dependency projects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ztd": "dist/index.js"
|
|
8
8
|
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prepack": "node -e \"const fs=require('fs');const cp=require('child_process');const npm=process.platform==='win32'?'npm.cmd':'npm';if(!fs.existsSync('dist/index.js')){process.exit(cp.spawnSync(npm,['run','build'],{stdio:'inherit'}).status??1)}\"",
|
|
11
|
+
"build": "pnpm --filter rawsql-ts run build && pnpm --filter @rawsql-ts/sql-grep-core run build && pnpm --filter @rawsql-ts/test-evidence-core run build && pnpm --filter @rawsql-ts/test-evidence-renderer-md run build && pnpm --filter @rawsql-ts/testkit-core run build && tsc -p tsconfig.json",
|
|
12
|
+
"test": "pnpm --filter @rawsql-ts/adapter-node-pg run build && vitest run --config vitest.config.ts",
|
|
13
|
+
"lint": "eslint src --ext .ts",
|
|
14
|
+
"release": "npm run lint && npm run test && npm run build && node -e \"require('fs').mkdirSync('../../tmp', { recursive: true })\" && pnpm pack --out ../../tmp/rawsql-ts-ztd-cli.tgz && pnpm publish --access public",
|
|
15
|
+
"test:consumer-validation": "vitest run --config vitest.config.ts tests/testEvidence.unit.test.ts tests/testEvidence.cli.test.ts tests/sqlCatalog.evidence.test.ts tests/testCaseCatalog.evidence.test.ts"
|
|
16
|
+
},
|
|
9
17
|
"keywords": [
|
|
10
18
|
"rawsql-ts",
|
|
11
19
|
"ztd",
|
|
@@ -15,6 +23,11 @@
|
|
|
15
23
|
],
|
|
16
24
|
"author": "msugiura",
|
|
17
25
|
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/mk3008/rawsql-ts.git",
|
|
29
|
+
"directory": "packages/ztd-cli"
|
|
30
|
+
},
|
|
18
31
|
"publishConfig": {
|
|
19
32
|
"access": "public"
|
|
20
33
|
},
|
|
@@ -22,14 +35,18 @@
|
|
|
22
35
|
"node": ">=20"
|
|
23
36
|
},
|
|
24
37
|
"dependencies": {
|
|
38
|
+
"@rawsql-ts/test-evidence-core": "workspace:*",
|
|
39
|
+
"@rawsql-ts/test-evidence-renderer-md": "workspace:*",
|
|
25
40
|
"chokidar": "^5.0.0",
|
|
26
41
|
"commander": "^12.0.0",
|
|
27
42
|
"diff": "^8.0.3",
|
|
28
43
|
"fast-glob": "^3.3.3",
|
|
29
|
-
"rawsql-ts": "
|
|
44
|
+
"rawsql-ts": "workspace:^",
|
|
45
|
+
"yaml": "^2.8.2",
|
|
46
|
+
"@rawsql-ts/sql-grep-core": "workspace:*"
|
|
30
47
|
},
|
|
31
48
|
"peerDependencies": {
|
|
32
|
-
"@rawsql-ts/adapter-node-pg": "
|
|
49
|
+
"@rawsql-ts/adapter-node-pg": "workspace:^"
|
|
33
50
|
},
|
|
34
51
|
"peerDependenciesMeta": {
|
|
35
52
|
"@rawsql-ts/adapter-node-pg": {
|
|
@@ -37,27 +54,21 @@
|
|
|
37
54
|
}
|
|
38
55
|
},
|
|
39
56
|
"devDependencies": {
|
|
57
|
+
"@rawsql-ts/adapter-node-pg": "workspace:^",
|
|
58
|
+
"@rawsql-ts/testkit-core": "workspace:^",
|
|
59
|
+
"@rawsql-ts/testkit-postgres": "workspace:^",
|
|
40
60
|
"@testcontainers/postgresql": "^10.28.0",
|
|
41
61
|
"@types/diff": "^5.0.1",
|
|
42
62
|
"@types/node": "^22.13.10",
|
|
43
63
|
"pg": "^8.11.1",
|
|
44
64
|
"testcontainers": "^10.28.0",
|
|
45
65
|
"typescript": "^5.8.2",
|
|
46
|
-
"vitest": "^4.0.7"
|
|
47
|
-
"@rawsql-ts/adapter-node-pg": "^0.15.2",
|
|
48
|
-
"@rawsql-ts/testkit-core": "^0.15.1",
|
|
49
|
-
"@rawsql-ts/testkit-postgres": "^0.15.1"
|
|
66
|
+
"vitest": "^4.0.7"
|
|
50
67
|
},
|
|
51
68
|
"files": [
|
|
52
69
|
"dist",
|
|
53
70
|
"templates",
|
|
54
71
|
"AGENTS.md",
|
|
55
72
|
"README.md"
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
"build": "tsc -p tsconfig.json",
|
|
59
|
-
"test": "vitest run",
|
|
60
|
-
"lint": "eslint src --ext .ts",
|
|
61
|
-
"release": "npm run lint && npm run test && npm run build && npm pack --dry-run && npm publish --access public"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
73
|
+
]
|
|
74
|
+
}
|
package/templates/.editorconfig
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
charset = utf-8
|
|
5
|
-
end_of_line = lf
|
|
6
|
-
indent_style = space
|
|
7
|
-
indent_size = 2
|
|
8
|
-
tab_width = 2
|
|
9
|
-
insert_final_newline = true
|
|
10
|
-
trim_trailing_whitespace = true
|
|
11
|
-
|
|
12
|
-
[*.md]
|
|
13
|
-
trim_trailing_whitespace = false
|
|
14
|
-
|
|
15
|
-
[*.sql]
|
|
16
|
-
indent_size = 2
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
charset = utf-8
|
|
5
|
+
end_of_line = lf
|
|
6
|
+
indent_style = space
|
|
7
|
+
indent_size = 2
|
|
8
|
+
tab_width = 2
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
|
|
12
|
+
[*.md]
|
|
13
|
+
trim_trailing_whitespace = false
|
|
14
|
+
|
|
15
|
+
[*.sql]
|
|
16
|
+
indent_size = 2
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
tests/generated/**
|
|
2
|
-
|
|
1
|
+
tests/generated/**
|
|
2
|
+
|
package/templates/.prettierrc
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"semi": true,
|
|
3
|
-
"singleQuote": true,
|
|
4
|
-
"trailingComma": "all",
|
|
5
|
-
"tabWidth": 2,
|
|
6
|
-
"printWidth": 100,
|
|
7
|
-
"bracketSpacing": true,
|
|
8
|
-
"arrowParens": "always",
|
|
9
|
-
"plugins": ["prettier-plugin-sql"],
|
|
10
|
-
"overrides": [
|
|
11
|
-
{
|
|
12
|
-
"files": "*.sql",
|
|
13
|
-
"options": {
|
|
14
|
-
"parser": "sql"
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"files": "*.md",
|
|
19
|
-
"options": {
|
|
20
|
-
"parser": "markdown"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"singleQuote": true,
|
|
4
|
+
"trailingComma": "all",
|
|
5
|
+
"tabWidth": 2,
|
|
6
|
+
"printWidth": 100,
|
|
7
|
+
"bracketSpacing": true,
|
|
8
|
+
"arrowParens": "always",
|
|
9
|
+
"plugins": ["prettier-plugin-sql"],
|
|
10
|
+
"overrides": [
|
|
11
|
+
{
|
|
12
|
+
"files": "*.sql",
|
|
13
|
+
"options": {
|
|
14
|
+
"parser": "sql"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"files": "*.md",
|
|
19
|
+
"options": {
|
|
20
|
+
"parser": "markdown"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
package/templates/AGENTS.md
CHANGED
|
@@ -1,52 +1,30 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
- The
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- "src/repositories"
|
|
32
|
-
- "src/catalog/runtime"
|
|
33
|
-
- "tests" (except "tests/generated")
|
|
34
|
-
|
|
35
|
-
Never touch by hand:
|
|
36
|
-
- "tests/generated"
|
|
37
|
-
|
|
38
|
-
## Where to read next
|
|
39
|
-
|
|
40
|
-
- "src/catalog/AGENTS.md": catalog layout and contract boundaries
|
|
41
|
-
- "src/repositories/AGENTS.md": repository responsibilities and restrictions
|
|
42
|
-
- "src/sql/AGENTS.md": SQL asset rules
|
|
43
|
-
- "tests/AGENTS.md": ZTD testing rules
|
|
44
|
-
- "ztd/ddl/AGENTS.md": DDL authoring rules
|
|
45
|
-
|
|
46
|
-
## Test environment guarantee (important)
|
|
47
|
-
|
|
48
|
-
- This workspace MUST be test-runnable immediately after initialization.
|
|
49
|
-
- `pnpm test` (or equivalent) must not fail due to missing configuration.
|
|
50
|
-
- Test runner configuration (e.g. vitest.config.ts) is considered part of the template contract.
|
|
51
|
-
|
|
52
|
-
If tests fail due to missing config, this is a template defect, not a user error.
|
|
1
|
+
# Package Scope
|
|
2
|
+
- Applies to `packages/ztd-cli/templates`.
|
|
3
|
+
- Defines repository-wide guardrails for generated project templates.
|
|
4
|
+
- Provides parent rules for runtime (`src`), tests (`tests`), and metadata (`ztd`) without forcing one application style on every subtree.
|
|
5
|
+
|
|
6
|
+
# Policy
|
|
7
|
+
## REQUIRED
|
|
8
|
+
- The nearest nested `AGENTS.md` MUST be treated as highest-priority policy for edited files.
|
|
9
|
+
- Unknown facts during template work MUST be reported as `Not observed` with the next check.
|
|
10
|
+
- Generated artifacts MUST remain unedited unless explicit instruction exists.
|
|
11
|
+
- Preserve layer boundaries: transport, application, domain, and infrastructure concerns MUST remain explicit when those directories exist.
|
|
12
|
+
- Human-owned contract directories (`ztd/ddl`, `src/catalog/specs`, `src/sql`) MUST NOT be semantically changed without explicit instruction.
|
|
13
|
+
- Template output MUST include runnable test configuration at initialization.
|
|
14
|
+
|
|
15
|
+
## ALLOWED
|
|
16
|
+
- AI-assisted implementation MAY occur in infrastructure adapters, catalog runtime, and tests excluding `tests/generated`.
|
|
17
|
+
|
|
18
|
+
## PROHIBITED
|
|
19
|
+
- Manual edits under `tests/generated`.
|
|
20
|
+
- Treating ZTD-specific workflow rules as repository-global rules.
|
|
21
|
+
|
|
22
|
+
# Mandatory Workflow
|
|
23
|
+
- Template changes MUST preserve an executable `pnpm test` path for initialized projects.
|
|
24
|
+
|
|
25
|
+
# Hygiene
|
|
26
|
+
- Keep directory-local deltas in child `AGENTS.md`; avoid restating parent rules in child files.
|
|
27
|
+
|
|
28
|
+
# References
|
|
29
|
+
- Rationale: [DESIGN.md](./DESIGN.md)
|
|
30
|
+
- Operational notes: [DEV_NOTES.md](./DEV_NOTES.md)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Agent Context
|
|
2
|
+
|
|
3
|
+
- Prefer `ztd --output json` in automation.
|
|
4
|
+
- Treat this file as a high-level index only; rely on subtree `AGENTS.md` files for path-specific rules.
|
|
5
|
+
- Prefer `ztd model-gen --probe-mode ztd` during the inner loop when local DDL is the source of truth.
|
|
6
|
+
- Use `--dry-run` before file-writing commands when you need a safe validation pass.
|
|
7
|
+
- Keep `ztd/ddl` as the human-owned schema source of truth.
|
|
8
|
+
- Regenerate `tests/generated/*` with `ztd ztd-config`; do not edit generated files manually.
|
|
9
|
+
- `ztd-cli` implicitly uses only `ZTD_TEST_DATABASE_URL`; it does not read `DATABASE_URL` automatically.
|
|
10
|
+
- Treat `ddl pull` and `ddl diff` as explicit target inspection commands. Pass `--url` or a complete `--db-*` flag set when using them.
|
|
11
|
+
- Keep transport, application, and domain work free from direct ZTD assumptions unless you are editing persistence infrastructure.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Agent Context
|
|
2
|
+
|
|
3
|
+
- Treat this file as a top-level index for the layered WebAPI layout.
|
|
4
|
+
- Keep `src/domain`, `src/application`, and `src/presentation/http` free from direct ZTD assumptions.
|
|
5
|
+
- Apply ZTD-specific workflow rules only inside `src/infrastructure/persistence`, `src/sql`, `src/catalog`, and `ztd`.
|
|
6
|
+
- Prefer `ztd model-gen --probe-mode ztd` during the inner loop when local DDL is the source of truth.
|
|
7
|
+
- Use `--dry-run` before file-writing commands when you need a safe validation pass.
|
|
8
|
+
- Keep `ztd/ddl` as the human-owned schema source of truth.
|
|
9
|
+
- Regenerate `tests/generated/*` with `ztd ztd-config`; do not edit generated files manually.
|
|
10
|
+
- `ztd-cli` implicitly uses only `ZTD_TEST_DATABASE_URL`; runtime settings such as `DATABASE_URL` remain outside its ownership.
|
|
11
|
+
- Treat `ddl pull` and `ddl diff` as explicit target inspection commands. Pass `--url` or a complete `--db-*` flag set when using them.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# ZTD Template Design Notes
|
|
2
|
+
|
|
3
|
+
## Role and Boundaries
|
|
4
|
+
- Defines template-level design intent for ownership and runtime/test split.
|
|
5
|
+
- Clarifies where human-owned contracts stop and implementation wiring begins.
|
|
6
|
+
|
|
7
|
+
## Non-Goals
|
|
8
|
+
- Replacing directory-local AGENTS contracts.
|
|
9
|
+
- Embedding operational command playbooks.
|
|
10
|
+
|
|
11
|
+
## Ownership Model
|
|
12
|
+
- Human-owned directories preserve domain contracts and SQL intent.
|
|
13
|
+
- AI-assisted directories implement runtime wiring and verification logic.
|
|
14
|
+
|
|
15
|
+
## Runtime Split
|
|
16
|
+
- `src/` contains runtime assets.
|
|
17
|
+
- `tests/` and `ztd/` contain verification and generation inputs.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# ZTD Template Dev Notes
|
|
2
|
+
|
|
3
|
+
## Commands
|
|
4
|
+
- `pnpm test` in initialized template projects.
|
|
5
|
+
|
|
6
|
+
## Troubleshooting
|
|
7
|
+
- Template initialization must include runnable test configuration and at least one executable test.
|
|
8
|
+
|
|
9
|
+
## Navigation
|
|
10
|
+
- `src/catalog/AGENTS.md`
|
|
11
|
+
- `src/repositories/AGENTS.md`
|
|
12
|
+
- `src/sql/AGENTS.md`
|
|
13
|
+
- `tests/AGENTS.md`
|
|
14
|
+
- `ztd/ddl/AGENTS.md`
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Prompt Dogfooding
|
|
2
|
+
|
|
3
|
+
Use this checklist when you want to confirm that generic WebAPI requests stay focused on transport, application, and domain layers unless persistence work is explicitly requested.
|
|
4
|
+
|
|
5
|
+
## Prompt 1
|
|
6
|
+
|
|
7
|
+
Prompt:
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
Convert to WebAPI
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Expected focus:
|
|
14
|
+
- `src/presentation/http`
|
|
15
|
+
- `src/application`
|
|
16
|
+
- `src/domain`
|
|
17
|
+
|
|
18
|
+
Expected non-focus:
|
|
19
|
+
- `src/sql`
|
|
20
|
+
- `src/catalog`
|
|
21
|
+
- `ztd/ddl`
|
|
22
|
+
- `src/infrastructure/persistence`
|
|
23
|
+
- `src/infrastructure/telemetry`
|
|
24
|
+
|
|
25
|
+
## Prompt 2
|
|
26
|
+
|
|
27
|
+
Prompt:
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
Add SQL and implement repository
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Expected focus:
|
|
34
|
+
- `src/infrastructure/persistence/repositories`
|
|
35
|
+
- `src/sql`
|
|
36
|
+
- `src/catalog/specs`
|
|
37
|
+
- `src/catalog/runtime`
|
|
38
|
+
- `ztd/ddl`
|
|
39
|
+
|
|
40
|
+
Expected non-focus:
|
|
41
|
+
- unrelated HTTP transport rewrites
|
|
42
|
+
- domain-wide refactors that are not required by the repository change
|
|
43
|
+
|
|
44
|
+
## Record Template
|
|
45
|
+
|
|
46
|
+
| Prompt | Primary files mentioned | Unwanted ZTD leakage? | Notes |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| `Convert to WebAPI` | | | |
|
|
49
|
+
| `Add SQL and implement repository` | | | |
|
package/templates/README.md
CHANGED
|
@@ -1,14 +1,46 @@
|
|
|
1
|
-
# Zero Table Dependency Project
|
|
2
|
-
|
|
3
|
-
This project uses Zero Table Dependency (ZTD) to keep SQL, DDL, and tests aligned.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
- ztd
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
# Zero Table Dependency Project
|
|
2
|
+
|
|
3
|
+
This project uses Zero Table Dependency (ZTD) to keep SQL, DDL, and tests aligned.
|
|
4
|
+
|
|
5
|
+
Conceptual model:
|
|
6
|
+
- `ztd-cli` implicitly uses only `ZTD_TEST_DATABASE_URL`.
|
|
7
|
+
- `DATABASE_URL` and other runtime or deployment database settings are outside the ownership of `ztd-cli`.
|
|
8
|
+
- Any non-ZTD database target must be passed explicitly via `--url` or `--db-*`.
|
|
9
|
+
- `ztd-cli` may generate migration SQL artifacts, but it does not apply them.
|
|
10
|
+
|
|
11
|
+
Quick boundary table:
|
|
12
|
+
- `ZTD_TEST_DATABASE_URL`: owned by `ztd-cli` for ZTD tests and verification
|
|
13
|
+
- `DATABASE_URL`: runtime or deployment concern, not read automatically by `ztd-cli`
|
|
14
|
+
- `--url` / complete `--db-*`: explicit target inspection only
|
|
15
|
+
|
|
16
|
+
Key folders:
|
|
17
|
+
- ztd/ddl: schema files (source of truth)
|
|
18
|
+
- src: application SQL and repositories
|
|
19
|
+
- tests: ZTD tests and support
|
|
20
|
+
|
|
21
|
+
Next steps:
|
|
22
|
+
1. Update `ztd/ddl/<schema>.sql` if needed.
|
|
23
|
+
2. Run `pnpm exec ztd ztd-config` (or `npx ztd ztd-config` if you prefer npm-style invocation).
|
|
24
|
+
3. Run `pnpm exec ztd model-gen --probe-mode ztd <sql-file> --out <spec-file>` when you want a QuerySpec scaffold from the local DDL snapshot.
|
|
25
|
+
4. Wire repositories to `src/infrastructure/telemetry/repositoryTelemetry.ts` so application code can replace the default telemetry hook.
|
|
26
|
+
5. Provide a SqlClient implementation.
|
|
27
|
+
6. Run tests (`pnpm test` or `npx vitest run`).
|
|
28
|
+
7. Use `ZTD_TEST_DATABASE_URL` for ZTD-owned test and verification workflows.
|
|
29
|
+
8. Use `ztd model-gen --probe-mode live`, `ztd ddl pull`, or `ztd ddl diff` only for explicit target inspection by passing `--url` or a complete `--db-*` flag set.
|
|
30
|
+
9. If you generate migration SQL artifacts, apply them with your deployment tooling instead of `ztd-cli`.
|
|
31
|
+
|
|
32
|
+
If this project was scaffolded with `ztd init --local-source-root <monorepo-root>`, first run `pnpm install` (or `pnpm install --ignore-workspace` when nested under another `pnpm-workspace.yaml`), then `pnpm typecheck`, then `pnpm test`, then `pnpm ztd ztd-config`. For generated QuerySpecs, prefer `pnpm ztd model-gen --probe-mode ztd --import-style relative` so imports keep using the local shim.
|
|
33
|
+
|
|
34
|
+
For schema-change impact checks, `npx ztd query uses` defaults to the `impact` view. Table add / column add checks usually work with the default scan, while table rename / column rename / column type change checks often benefit from `--exclude-generated` so review-only specs under `src/catalog/specs/generated` do not add noise. The flag is optional and does not change the default scan set.
|
|
35
|
+
|
|
36
|
+
If you later switch this scaffold into a layered WebAPI shape, add a prompt-dogfooding guide similar to `PROMPT_DOGFOOD.md` so generic transport requests can be checked for accidental ZTD leakage.
|
|
37
|
+
|
|
38
|
+
Examples:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pnpm exec ztd query uses table public.sale_items --exclude-generated
|
|
42
|
+
pnpm exec ztd query uses table public.sale_lines --exclude-generated
|
|
43
|
+
pnpm exec ztd query uses column public.products.title --exclude-generated
|
|
44
|
+
pnpm exec ztd query uses column public.sale_items.quantity --exclude-generated
|
|
45
|
+
pnpm exec ztd query uses table public.sale_lines --view detail --exclude-generated
|
|
46
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Zero Table Dependency WebAPI Project
|
|
2
|
+
|
|
3
|
+
This scaffold separates WebAPI concerns into explicit layers so transport and use-case work do not accidentally inherit persistence-specific rules.
|
|
4
|
+
|
|
5
|
+
Conceptual model:
|
|
6
|
+
- `ztd-cli` implicitly uses only `ZTD_TEST_DATABASE_URL`.
|
|
7
|
+
- Projects often also have a runtime or deployment database setting such as `DATABASE_URL`, but `ztd-cli` does not read it automatically.
|
|
8
|
+
- Any non-ZTD database target must be passed explicitly via `--url` or `--db-*`.
|
|
9
|
+
- `ztd-cli` may generate migration SQL artifacts, but it does not apply them.
|
|
10
|
+
|
|
11
|
+
Quick boundary table:
|
|
12
|
+
- `ZTD_TEST_DATABASE_URL`: owned by `ztd-cli` for ZTD tests and verification
|
|
13
|
+
- `DATABASE_URL`: runtime or deployment concern, not read automatically by `ztd-cli`
|
|
14
|
+
- `--url` / complete `--db-*`: explicit target inspection only
|
|
15
|
+
|
|
16
|
+
Key folders:
|
|
17
|
+
- `src/domain`: domain types and business rules with no direct ZTD dependency
|
|
18
|
+
- `src/application`: use cases and orchestration over domain-facing ports
|
|
19
|
+
- `src/presentation/http`: HTTP handlers, request parsing, and response shaping
|
|
20
|
+
- `src/infrastructure/persistence`: repositories, SQL assets, and QuerySpec wiring
|
|
21
|
+
- `src/sql`, `src/catalog`, `ztd/ddl`: ZTD-owned persistence assets
|
|
22
|
+
- `tests`: smoke tests and test support
|
|
23
|
+
|
|
24
|
+
Prompt dogfooding:
|
|
25
|
+
- See `PROMPT_DOGFOOD.md` when you want to verify that generic WebAPI requests stay out of persistence-specific ZTD guidance unless repository or SQL work is explicitly requested.
|
|
26
|
+
|
|
27
|
+
Next steps:
|
|
28
|
+
1. Update `ztd/ddl/<schema>.sql` if needed.
|
|
29
|
+
2. Run `pnpm exec ztd ztd-config` (or `npx ztd ztd-config` if you prefer npm-style invocation).
|
|
30
|
+
3. Keep `src/domain`, `src/application`, and `src/presentation/http` free from direct SQL or DDL concerns.
|
|
31
|
+
4. Use `pnpm exec ztd model-gen --probe-mode ztd <sql-file> --out <spec-file>` when you want a QuerySpec scaffold from the local DDL snapshot.
|
|
32
|
+
5. Wire repositories to `src/infrastructure/telemetry/repositoryTelemetry.ts` only when you add SQL-backed repository classes.
|
|
33
|
+
6. Provide a SqlClient implementation in `src/infrastructure/db`.
|
|
34
|
+
7. Run tests (`pnpm test` or `npx vitest run`) with `ZTD_TEST_DATABASE_URL` when SQL-backed verification needs a managed test database.
|
|
35
|
+
8. Treat `ddl pull` and `ddl diff` as explicit target inspection commands that require `--url` or a complete `--db-*` flag set.
|
|
36
|
+
9. If you generate migration SQL artifacts, apply them outside `ztd-cli`.
|
|
37
|
+
|
|
38
|
+
If this project was scaffolded with `ztd init --local-source-root <monorepo-root>`, first run `pnpm install` (or `pnpm install --ignore-workspace` when nested under another `pnpm-workspace.yaml`), then `pnpm typecheck`, then `pnpm test`, then `pnpm ztd ztd-config`. For generated QuerySpecs, prefer `pnpm ztd model-gen --probe-mode ztd --import-style relative` so imports keep using the local shim.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
const projectRoot = process.cwd();
|
|
7
|
+
const command = process.argv[2];
|
|
8
|
+
|
|
9
|
+
if (command !== 'test' && command !== 'typecheck' && command !== 'ztd') {
|
|
10
|
+
console.error('local-source guard expects "test", "typecheck", or "ztd".');
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (command === 'ztd') {
|
|
15
|
+
const cliEntry = path.resolve(projectRoot, '__LOCAL_SOURCE_ZTD_CLI__');
|
|
16
|
+
const requestedSubcommand = process.argv.slice(3).join(' ').trim() || '(none)';
|
|
17
|
+
if (!existsSync(cliEntry)) {
|
|
18
|
+
console.error(
|
|
19
|
+
[
|
|
20
|
+
'[local-source guard] ztd cannot run against the local source checkout yet.',
|
|
21
|
+
'',
|
|
22
|
+
`What happened:`,
|
|
23
|
+
`- Requested subcommand: ${requestedSubcommand}`,
|
|
24
|
+
`- Project root: ${normalizePath(projectRoot)}`,
|
|
25
|
+
`- The local CLI entry was not found at ${normalizePath(cliEntry)}.`,
|
|
26
|
+
'',
|
|
27
|
+
'Next steps:',
|
|
28
|
+
'1. Build the local CLI package (for example: pnpm --filter @rawsql-ts/ztd-cli build)',
|
|
29
|
+
'2. Confirm this scaffold still points at the intended rawsql-ts monorepo root',
|
|
30
|
+
'3. Re-run pnpm ztd <subcommand>'
|
|
31
|
+
].join('\n')
|
|
32
|
+
);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cliArgs = process.argv.slice(3);
|
|
37
|
+
const result = spawnSync(process.execPath, [cliEntry, ...cliArgs], {
|
|
38
|
+
cwd: projectRoot,
|
|
39
|
+
stdio: 'inherit',
|
|
40
|
+
shell: false
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Surface execution failures explicitly so local-source dogfooding does not
|
|
44
|
+
// collapse permission, spawn, and signal problems into the same exit code.
|
|
45
|
+
if (result.error) {
|
|
46
|
+
console.error('[local-source guard] Failed to launch the local ztd CLI entry.');
|
|
47
|
+
console.error(`- Message: ${result.error.message}`);
|
|
48
|
+
if (result.error.stack) {
|
|
49
|
+
console.error(result.error.stack);
|
|
50
|
+
}
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (result.signal) {
|
|
55
|
+
console.error('[local-source guard] The local ztd CLI entry was terminated by signal.');
|
|
56
|
+
console.error(`- Signal: ${result.signal}`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
process.exit(result.status ?? 1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const workspaceRoot = findAncestorPnpmWorkspaceRoot(projectRoot);
|
|
64
|
+
const installCommand = workspaceRoot ? 'pnpm install --ignore-workspace' : 'pnpm install';
|
|
65
|
+
const rerunCommand = command === 'test' ? 'pnpm test' : 'pnpm typecheck';
|
|
66
|
+
const fallbackCommand = command === 'test' ? 'npx vitest run' : 'npx tsc --noEmit';
|
|
67
|
+
const binaryName = process.platform === 'win32'
|
|
68
|
+
? command === 'test'
|
|
69
|
+
? 'vitest.cmd'
|
|
70
|
+
: 'tsc.cmd'
|
|
71
|
+
: command === 'test'
|
|
72
|
+
? 'vitest'
|
|
73
|
+
: 'tsc';
|
|
74
|
+
const binaryArgs = command === 'test' ? ['run'] : ['--noEmit'];
|
|
75
|
+
const binaryPath = path.join(projectRoot, 'node_modules', '.bin', binaryName);
|
|
76
|
+
const packageChecks = command === 'test'
|
|
77
|
+
? ['vitest/package.json', 'zod/package.json', '@rawsql-ts/sql-contract/package.json']
|
|
78
|
+
: ['typescript/package.json', 'zod/package.json', '@rawsql-ts/sql-contract/package.json'];
|
|
79
|
+
|
|
80
|
+
const resolutionIssues = inspectResolution(packageChecks);
|
|
81
|
+
if (!existsSync(binaryPath) || resolutionIssues.length > 0) {
|
|
82
|
+
printGuidance({
|
|
83
|
+
command,
|
|
84
|
+
installCommand,
|
|
85
|
+
rerunCommand,
|
|
86
|
+
fallbackCommand,
|
|
87
|
+
workspaceRoot,
|
|
88
|
+
binaryPath,
|
|
89
|
+
resolutionIssues
|
|
90
|
+
});
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const result = spawnSync(binaryPath, binaryArgs, {
|
|
95
|
+
cwd: projectRoot,
|
|
96
|
+
stdio: 'inherit',
|
|
97
|
+
shell: process.platform === 'win32'
|
|
98
|
+
});
|
|
99
|
+
process.exit(result.status ?? 1);
|
|
100
|
+
|
|
101
|
+
function inspectResolution(specifiers) {
|
|
102
|
+
const projectRequire = createRequire(path.join(projectRoot, 'package.json'));
|
|
103
|
+
const issues = [];
|
|
104
|
+
|
|
105
|
+
for (const specifier of specifiers) {
|
|
106
|
+
try {
|
|
107
|
+
const resolvedPath = specifier.endsWith('/package.json')
|
|
108
|
+
? resolveInstalledPackageManifest(specifier)
|
|
109
|
+
: projectRequire.resolve(specifier);
|
|
110
|
+
if (!isInsideProject(resolvedPath)) {
|
|
111
|
+
issues.push(`${specifier} resolved outside this scaffold: ${normalizePath(resolvedPath)}`);
|
|
112
|
+
}
|
|
113
|
+
} catch {
|
|
114
|
+
issues.push(`${specifier} is not installed in this scaffold`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return issues;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function resolveInstalledPackageManifest(specifier) {
|
|
122
|
+
const manifestRelativePath = path.join('node_modules', ...specifier.split('/'));
|
|
123
|
+
const manifestPath = path.join(projectRoot, manifestRelativePath);
|
|
124
|
+
if (!existsSync(manifestPath)) {
|
|
125
|
+
throw new Error(`${specifier} manifest is missing`);
|
|
126
|
+
}
|
|
127
|
+
return manifestPath;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function isInsideProject(filePath) {
|
|
131
|
+
const relativePath = path.relative(projectRoot, filePath);
|
|
132
|
+
return relativePath.length === 0 || (!relativePath.startsWith('..') && !path.isAbsolute(relativePath));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function normalizePath(filePath) {
|
|
136
|
+
return filePath.replace(/\\/g, '/');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function findAncestorPnpmWorkspaceRoot(rootDir) {
|
|
140
|
+
let cursor = path.resolve(rootDir);
|
|
141
|
+
while (true) {
|
|
142
|
+
const parentDir = path.dirname(cursor);
|
|
143
|
+
if (parentDir === cursor) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
cursor = parentDir;
|
|
147
|
+
if (existsSync(path.join(cursor, 'pnpm-workspace.yaml'))) {
|
|
148
|
+
return cursor;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function printGuidance({
|
|
154
|
+
command,
|
|
155
|
+
installCommand,
|
|
156
|
+
rerunCommand,
|
|
157
|
+
fallbackCommand,
|
|
158
|
+
workspaceRoot,
|
|
159
|
+
binaryPath,
|
|
160
|
+
resolutionIssues
|
|
161
|
+
}) {
|
|
162
|
+
const commandLabel = command === 'test' ? 'pnpm test' : 'pnpm typecheck';
|
|
163
|
+
const lines = [
|
|
164
|
+
`[local-source guard] ${commandLabel} cannot run against this scaffold yet.`,
|
|
165
|
+
'',
|
|
166
|
+
'What happened:',
|
|
167
|
+
`- The local binary was not found at ${normalizePath(binaryPath)} or required packages resolved outside this project.`,
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
if (workspaceRoot) {
|
|
171
|
+
lines.push(`- This project sits under pnpm workspace ${normalizePath(workspaceRoot)}, so pnpm may still be using the parent workspace context.`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (resolutionIssues.length > 0) {
|
|
175
|
+
lines.push('- Resolution details:');
|
|
176
|
+
for (const issue of resolutionIssues) {
|
|
177
|
+
lines.push(` - ${issue}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
lines.push(
|
|
182
|
+
'',
|
|
183
|
+
'Next steps:',
|
|
184
|
+
`1. Run ${installCommand}`,
|
|
185
|
+
`2. Re-run ${rerunCommand}`,
|
|
186
|
+
`3. If pnpm still looks absorbed by the parent workspace, try ${fallbackCommand}`
|
|
187
|
+
);
|
|
188
|
+
console.error(lines.join('\n'));
|
|
189
|
+
}
|