@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
package/dist/utils/pgDump.js
DELETED
|
@@ -1,55 +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.runPgDump = runPgDump;
|
|
7
|
-
const node_child_process_1 = require("node:child_process");
|
|
8
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
9
|
-
const connectionSummary_1 = require("./connectionSummary");
|
|
10
|
-
/**
|
|
11
|
-
* Wraps `pg_dump` in schema-only mode for the given connection URL and returns the captured DDL output.
|
|
12
|
-
*/
|
|
13
|
-
function runPgDump(options) {
|
|
14
|
-
var _a, _b, _c, _d, _e, _f;
|
|
15
|
-
const executable = (_b = (_a = options.pgDumpPath) !== null && _a !== void 0 ? _a : process.env.PG_DUMP_PATH) !== null && _b !== void 0 ? _b : 'pg_dump';
|
|
16
|
-
const args = [
|
|
17
|
-
'--schema-only',
|
|
18
|
-
'--no-owner',
|
|
19
|
-
'--no-privileges',
|
|
20
|
-
...((_c = options.extraArgs) !== null && _c !== void 0 ? _c : []),
|
|
21
|
-
'--dbname',
|
|
22
|
-
options.url
|
|
23
|
-
];
|
|
24
|
-
const result = (0, node_child_process_1.spawnSync)(executable, args, {
|
|
25
|
-
encoding: 'utf8',
|
|
26
|
-
stdio: ['ignore', 'pipe', 'pipe']
|
|
27
|
-
});
|
|
28
|
-
const connectionNote = (0, connectionSummary_1.describeConnectionContext)(options.connectionContext);
|
|
29
|
-
const extraArgsNote = ((_d = options.extraArgs) === null || _d === void 0 ? void 0 : _d.length) ? ` (extra args: ${options.extraArgs.join(' ')})` : '';
|
|
30
|
-
if (result.error) {
|
|
31
|
-
const windowsHint = node_os_1.default.platform() === 'win32'
|
|
32
|
-
? ' On Windows, ensure "C:\\Program Files\\PostgreSQL\\<version>\\bin" is on PATH or use a shell where pg_dump is available.'
|
|
33
|
-
: '';
|
|
34
|
-
if (isExecutableMissing(result.error, (_e = result.stderr) === null || _e === void 0 ? void 0 : _e.toString())) {
|
|
35
|
-
throw new Error(`pg_dump executable not found (${executable}). Install PostgreSQL or pass --pg-dump-path to point at the binary.${windowsHint}`);
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`Failed to launch pg_dump (${executable})${connectionNote}: ${(_f = result.error.message) !== null && _f !== void 0 ? _f : 'Unknown error'}${extraArgsNote}`);
|
|
38
|
-
}
|
|
39
|
-
if (result.status !== 0 || !result.stdout) {
|
|
40
|
-
const stderr = result.stderr ? result.stderr.toString().trim() : 'Unknown error';
|
|
41
|
-
throw new Error(`pg_dump reported an error${connectionNote}: ${stderr}${extraArgsNote}`);
|
|
42
|
-
}
|
|
43
|
-
return result.stdout;
|
|
44
|
-
}
|
|
45
|
-
function isExecutableMissing(error, stderr) {
|
|
46
|
-
if (error.code === 'ENOENT') {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
if (!stderr) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
const normalized = stderr.toLowerCase();
|
|
53
|
-
return normalized.includes('not recognized') || normalized.includes('command not found');
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=pgDump.js.map
|
package/dist/utils/pgDump.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pgDump.js","sourceRoot":"","sources":["../../src/utils/pgDump.ts"],"names":[],"mappings":";;;;;AAeA,8BA0CC;AAzDD,2DAA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KAAK,CAAC,OAAO,mCAAI,eAAe,GAAG,aAAa,EAAE,CACxH,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,KAAK,MAAM,GAAG,aAAa,EAAE,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED,SAAS,mBAAmB,CAAC,KAA4B,EAAE,MAAe;IACxE,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACxC,OAAO,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AAC3F,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { TableDefinitionModel } from 'rawsql-ts';
|
|
2
|
-
import type { FixtureRow } from '@rawsql-ts/testkit-core';
|
|
3
|
-
/**
|
|
4
|
-
* Resolve a CLI argument into an absolute list of `.sql` files.
|
|
5
|
-
*/
|
|
6
|
-
export declare function resolveSqlFiles(pattern: string): string[];
|
|
7
|
-
/**
|
|
8
|
-
* Scan the configured DDL directories for CREATE TYPE ... AS ENUM definitions.
|
|
9
|
-
*/
|
|
10
|
-
export declare function extractEnumLabels(directories: string[], extensions?: string[]): Map<string, string[]>;
|
|
11
|
-
/**
|
|
12
|
-
* Build a fixture row for linting using minimal values derived from the column types.
|
|
13
|
-
*/
|
|
14
|
-
export declare function buildLintFixtureRow(definition: TableDefinitionModel, enumLabels: Map<string, string[]>): FixtureRow;
|
|
15
|
-
/**
|
|
16
|
-
* Infer a default value for a required column to keep Postgres happy.
|
|
17
|
-
*/
|
|
18
|
-
export declare function inferDefaultValue(typeName: string | undefined, enumLabels: Map<string, string[]>): unknown;
|
|
@@ -1,270 +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.resolveSqlFiles = resolveSqlFiles;
|
|
7
|
-
exports.extractEnumLabels = extractEnumLabels;
|
|
8
|
-
exports.buildLintFixtureRow = buildLintFixtureRow;
|
|
9
|
-
exports.inferDefaultValue = inferDefaultValue;
|
|
10
|
-
const node_fs_1 = require("node:fs");
|
|
11
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
13
|
-
const options_1 = require("../commands/options");
|
|
14
|
-
const collectSqlFiles_1 = require("./collectSqlFiles");
|
|
15
|
-
/**
|
|
16
|
-
* Resolve a CLI argument into an absolute list of `.sql` files.
|
|
17
|
-
*/
|
|
18
|
-
function resolveSqlFiles(pattern) {
|
|
19
|
-
const absolutePattern = node_path_1.default.resolve(pattern);
|
|
20
|
-
if ((0, node_fs_1.existsSync)(absolutePattern)) {
|
|
21
|
-
const stats = (0, node_fs_1.lstatSync)(absolutePattern);
|
|
22
|
-
if (stats.isFile()) {
|
|
23
|
-
return [toPosixPattern(absolutePattern)];
|
|
24
|
-
}
|
|
25
|
-
if (stats.isDirectory()) {
|
|
26
|
-
const matches = fast_glob_1.default.sync(toPosixPattern(node_path_1.default.join(absolutePattern, '**', '*.sql')), {
|
|
27
|
-
absolute: true,
|
|
28
|
-
onlyFiles: true
|
|
29
|
-
});
|
|
30
|
-
if (matches.length === 0) {
|
|
31
|
-
throw new Error(`No SQL files were found under ${absolutePattern}`);
|
|
32
|
-
}
|
|
33
|
-
return matches.map(toPosixPattern).sort();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const globMatches = fast_glob_1.default.sync(toPosixPattern(pattern), {
|
|
37
|
-
absolute: true,
|
|
38
|
-
onlyFiles: true
|
|
39
|
-
});
|
|
40
|
-
if (globMatches.length === 0) {
|
|
41
|
-
throw new Error(`No SQL files matched ${pattern}`);
|
|
42
|
-
}
|
|
43
|
-
return globMatches.map(toPosixPattern).sort();
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Scan the configured DDL directories for CREATE TYPE ... AS ENUM definitions.
|
|
47
|
-
*/
|
|
48
|
-
function extractEnumLabels(directories, extensions = options_1.DEFAULT_EXTENSIONS) {
|
|
49
|
-
const enums = new Map();
|
|
50
|
-
for (const directory of directories) {
|
|
51
|
-
if (!(0, node_fs_1.existsSync)(directory)) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const files = (0, collectSqlFiles_1.collectSqlFiles)([directory], extensions);
|
|
55
|
-
for (const { sql } of files) {
|
|
56
|
-
for (const { name, labels } of parseEnumDefinitions(sql)) {
|
|
57
|
-
if (!labels.length) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const normalized = normalizeQualifiedName(name);
|
|
61
|
-
if (!normalized) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (!enums.has(normalized)) {
|
|
65
|
-
enums.set(normalized, labels);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return enums;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Build a fixture row for linting using minimal values derived from the column types.
|
|
74
|
-
*/
|
|
75
|
-
function buildLintFixtureRow(definition, enumLabels) {
|
|
76
|
-
const row = {};
|
|
77
|
-
for (const column of definition.columns) {
|
|
78
|
-
row[column.name] = column.required
|
|
79
|
-
? inferDefaultValue(column.typeName, enumLabels)
|
|
80
|
-
: null;
|
|
81
|
-
}
|
|
82
|
-
return row;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Infer a default value for a required column to keep Postgres happy.
|
|
86
|
-
*/
|
|
87
|
-
function inferDefaultValue(typeName, enumLabels) {
|
|
88
|
-
if (!typeName) {
|
|
89
|
-
return '';
|
|
90
|
-
}
|
|
91
|
-
const normalized = normalizeTypeName(typeName);
|
|
92
|
-
const enumMatch = enumLabels.get(normalized.key);
|
|
93
|
-
if (enumMatch && enumMatch.length > 0) {
|
|
94
|
-
return enumMatch[0];
|
|
95
|
-
}
|
|
96
|
-
if (normalized.isArray) {
|
|
97
|
-
return '{}';
|
|
98
|
-
}
|
|
99
|
-
if (normalized.base.startsWith('int') ||
|
|
100
|
-
normalized.base.includes('serial') ||
|
|
101
|
-
normalized.base === 'numeric' ||
|
|
102
|
-
normalized.base === 'decimal' ||
|
|
103
|
-
normalized.base === 'real' ||
|
|
104
|
-
normalized.base === 'double precision') {
|
|
105
|
-
return 0;
|
|
106
|
-
}
|
|
107
|
-
if (normalized.base === 'boolean' || normalized.base === 'bool') {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
if (normalized.base === 'uuid') {
|
|
111
|
-
return '00000000-0000-0000-0000-000000000000';
|
|
112
|
-
}
|
|
113
|
-
if (normalized.base.startsWith('character') ||
|
|
114
|
-
normalized.base.startsWith('varchar') ||
|
|
115
|
-
normalized.base === 'text' ||
|
|
116
|
-
normalized.base === 'citext' ||
|
|
117
|
-
normalized.base === 'name') {
|
|
118
|
-
return '';
|
|
119
|
-
}
|
|
120
|
-
if (normalized.base === 'date') {
|
|
121
|
-
return '1970-01-01';
|
|
122
|
-
}
|
|
123
|
-
if (normalized.base.startsWith('timestamp')) {
|
|
124
|
-
return '1970-01-01 00:00:00';
|
|
125
|
-
}
|
|
126
|
-
if (normalized.base.startsWith('time')) {
|
|
127
|
-
return '00:00:00';
|
|
128
|
-
}
|
|
129
|
-
if (normalized.base === 'json' || normalized.base === 'jsonb') {
|
|
130
|
-
return '{}';
|
|
131
|
-
}
|
|
132
|
-
return '';
|
|
133
|
-
}
|
|
134
|
-
function normalizeTypeName(typeName) {
|
|
135
|
-
const segments = splitQualifiedName(typeName);
|
|
136
|
-
if (segments.length === 0) {
|
|
137
|
-
return { base: '', key: '', isArray: false };
|
|
138
|
-
}
|
|
139
|
-
const cleaned = segments.map((token) => compactIdentifier(token).toLowerCase());
|
|
140
|
-
let isArray = false;
|
|
141
|
-
let lastSegment = cleaned[cleaned.length - 1];
|
|
142
|
-
if (lastSegment.endsWith('[]')) {
|
|
143
|
-
isArray = true;
|
|
144
|
-
lastSegment = lastSegment.slice(0, -2).trim();
|
|
145
|
-
}
|
|
146
|
-
const base = lastSegment.replace(/\(.*\)$/, '').trim();
|
|
147
|
-
cleaned[cleaned.length - 1] = base;
|
|
148
|
-
return {
|
|
149
|
-
base,
|
|
150
|
-
key: cleaned.join('.'),
|
|
151
|
-
isArray
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function normalizeQualifiedName(value) {
|
|
155
|
-
const segments = splitQualifiedName(value);
|
|
156
|
-
if (segments.length === 0) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
const cleaned = segments.map((segment) => compactIdentifier(segment).toLowerCase());
|
|
160
|
-
return cleaned.join('.');
|
|
161
|
-
}
|
|
162
|
-
function splitQualifiedName(value) {
|
|
163
|
-
const parts = [];
|
|
164
|
-
let buffer = '';
|
|
165
|
-
let inQuotes = false;
|
|
166
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
167
|
-
const char = value[i];
|
|
168
|
-
if (char === '"') {
|
|
169
|
-
buffer += char;
|
|
170
|
-
if (inQuotes && value[i + 1] === '"') {
|
|
171
|
-
buffer += '"';
|
|
172
|
-
i += 1;
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
inQuotes = !inQuotes;
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if (char === '.' && !inQuotes) {
|
|
179
|
-
if (buffer.length > 0) {
|
|
180
|
-
parts.push(buffer);
|
|
181
|
-
}
|
|
182
|
-
buffer = '';
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
buffer += char;
|
|
186
|
-
}
|
|
187
|
-
if (buffer.length > 0) {
|
|
188
|
-
parts.push(buffer);
|
|
189
|
-
}
|
|
190
|
-
return parts
|
|
191
|
-
.map((segment) => segment.trim())
|
|
192
|
-
.filter(Boolean);
|
|
193
|
-
}
|
|
194
|
-
function compactIdentifier(value) {
|
|
195
|
-
const trimmed = value.trim();
|
|
196
|
-
if (trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
197
|
-
return trimmed
|
|
198
|
-
.slice(1, -1)
|
|
199
|
-
.replace(/""/g, '"');
|
|
200
|
-
}
|
|
201
|
-
return trimmed.replace(/\s+/g, ' ');
|
|
202
|
-
}
|
|
203
|
-
function parseEnumDefinitions(sql) {
|
|
204
|
-
const results = [];
|
|
205
|
-
const regex = /create\s+type\s+(.+?)\s+as\s+enum\s*\(/gsi;
|
|
206
|
-
let match;
|
|
207
|
-
while ((match = regex.exec(sql))) {
|
|
208
|
-
const rawName = match[1].trim();
|
|
209
|
-
const openParenIndex = regex.lastIndex - 1;
|
|
210
|
-
if (openParenIndex < 0 || sql[openParenIndex] !== '(') {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
const { labels, end } = parseEnumLabelList(sql, openParenIndex);
|
|
214
|
-
results.push({ name: rawName, labels });
|
|
215
|
-
regex.lastIndex = end;
|
|
216
|
-
}
|
|
217
|
-
return results;
|
|
218
|
-
}
|
|
219
|
-
function parseEnumLabelList(sql, startIndex) {
|
|
220
|
-
const labels = [];
|
|
221
|
-
let idx = startIndex + 1;
|
|
222
|
-
while (idx < sql.length) {
|
|
223
|
-
idx = skipWhitespace(sql, idx);
|
|
224
|
-
if (sql[idx] === ')') {
|
|
225
|
-
idx += 1;
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
if (sql[idx] === ',') {
|
|
229
|
-
idx += 1;
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
if (sql[idx] !== "'") {
|
|
233
|
-
idx += 1;
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
const { value, newIndex } = parseStringLiteral(sql, idx);
|
|
237
|
-
labels.push(value);
|
|
238
|
-
idx = newIndex;
|
|
239
|
-
}
|
|
240
|
-
return { labels, end: idx };
|
|
241
|
-
}
|
|
242
|
-
function parseStringLiteral(sql, index) {
|
|
243
|
-
let idx = index + 1;
|
|
244
|
-
let value = '';
|
|
245
|
-
while (idx < sql.length) {
|
|
246
|
-
const char = sql[idx];
|
|
247
|
-
if (char === "'") {
|
|
248
|
-
if (sql[idx + 1] === "'") {
|
|
249
|
-
value += "'";
|
|
250
|
-
idx += 2;
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
idx += 1;
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
value += char;
|
|
257
|
-
idx += 1;
|
|
258
|
-
}
|
|
259
|
-
return { value, newIndex: idx };
|
|
260
|
-
}
|
|
261
|
-
function skipWhitespace(sql, index) {
|
|
262
|
-
while (index < sql.length && /\s/.test(sql[index])) {
|
|
263
|
-
index += 1;
|
|
264
|
-
}
|
|
265
|
-
return index;
|
|
266
|
-
}
|
|
267
|
-
function toPosixPattern(value) {
|
|
268
|
-
return value.replace(/\\/g, '/');
|
|
269
|
-
}
|
|
270
|
-
//# sourceMappingURL=sqlLintHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlLintHelpers.js","sourceRoot":"","sources":["../../src/utils/sqlLintHelpers.ts"],"names":[],"mappings":";;;;;AAWA,0CA2BC;AAKD,8CA0BC;AAKD,kDAWC;AAKD,8C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;IACjB,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,kBAAkB,CACzB,GAAW,EACX,KAAa;IAEb,IAAI,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC;IACpB,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,OAAO,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACzB,KAAK,IAAI,GAAG,CAAC;gBACb,GAAG,IAAI,CAAC,CAAC;gBACT,SAAS;YACX,CAAC;YACD,GAAG,IAAI,CAAC,CAAC;YACT,MAAM;QACR,CAAC;QACD,KAAK,IAAI,IAAI,CAAC;QACd,GAAG,IAAI,CAAC,CAAC;IACX,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,cAAc,CAAC,GAAW,EAAE,KAAa;IAChD,OAAO,KAAK,GAAG,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACnD,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/utils/typeMapper.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapSqlTypeToTs = mapSqlTypeToTs;
|
|
4
|
-
const numericTypes = new Set([
|
|
5
|
-
'int',
|
|
6
|
-
'integer',
|
|
7
|
-
'smallint',
|
|
8
|
-
'bigint',
|
|
9
|
-
'real',
|
|
10
|
-
'double precision',
|
|
11
|
-
'float',
|
|
12
|
-
'serial',
|
|
13
|
-
'bigserial',
|
|
14
|
-
'smallserial'
|
|
15
|
-
]);
|
|
16
|
-
const arbitraryPrecisionTypes = new Set(['decimal', 'numeric']);
|
|
17
|
-
const stringTypes = new Set(['text', 'varchar', 'char', 'character varying', 'character', 'uuid', 'citext']);
|
|
18
|
-
const dateTypes = new Set(['date', 'timestamp', 'timestamp without time zone', 'timestamp with time zone', 'time', 'time without time zone', 'time with time zone', 'timestamptz']);
|
|
19
|
-
const shouldLogUnknownSqlTypes = process.env.RAWSQL_DDL_SILENT !== '1';
|
|
20
|
-
function warnUnknownSqlType(typeName, context) {
|
|
21
|
-
// Do nothing when logging is explicitly silenced in CI or tooling.
|
|
22
|
-
if (!shouldLogUnknownSqlTypes) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
// Keep developers aware when the generator sees an unmapped SQL type.
|
|
26
|
-
const subject = context !== null && context !== void 0 ? context : 'column';
|
|
27
|
-
console.warn(`[ztd ddl] Unknown SQL type for ${subject}: ${typeName !== null && typeName !== void 0 ? typeName : 'undefined'}. Defaulting to unknown.`);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Maps PostgreSQL data types (basic numeric, string, temporal, JSON/binary types) to serializable TypeScript types, falling back to `unknown` when unmatched.
|
|
31
|
-
*/
|
|
32
|
-
function mapSqlTypeToTs(typeName, context) {
|
|
33
|
-
// Log when the AST omitted a type so callers can track down why type inference failed.
|
|
34
|
-
if (!typeName) {
|
|
35
|
-
warnUnknownSqlType(typeName, context);
|
|
36
|
-
return 'unknown';
|
|
37
|
-
}
|
|
38
|
-
// Drop trailing precision/length metadata (varchar(255), numeric(10,2), etc.) because TS cannot capture it.
|
|
39
|
-
const normalized = typeName.split('(')[0].trim().toLowerCase();
|
|
40
|
-
if (numericTypes.has(normalized)) {
|
|
41
|
-
return 'number';
|
|
42
|
-
}
|
|
43
|
-
if (arbitraryPrecisionTypes.has(normalized)) {
|
|
44
|
-
// Postgres decimal/numeric are arbitrary precision, so string preserves exactness when floating-point would lose it.
|
|
45
|
-
return 'string';
|
|
46
|
-
}
|
|
47
|
-
// Treat all date/time families as strings to keep the generated rows serializable.
|
|
48
|
-
if (normalized.includes('time') || dateTypes.has(normalized)) {
|
|
49
|
-
return 'string';
|
|
50
|
-
}
|
|
51
|
-
if (stringTypes.has(normalized) || normalized.includes('text')) {
|
|
52
|
-
return 'string';
|
|
53
|
-
}
|
|
54
|
-
if (normalized === 'boolean' || normalized === 'bool') {
|
|
55
|
-
return 'boolean';
|
|
56
|
-
}
|
|
57
|
-
if (normalized === 'json' || normalized === 'jsonb') {
|
|
58
|
-
// Use any so generated APIs stay friendly for JSON-heavy applications; narrowing can still be applied later.
|
|
59
|
-
return 'any';
|
|
60
|
-
}
|
|
61
|
-
if (normalized === 'bytea') {
|
|
62
|
-
// Prefer Uint8Array to avoid Node.js-only Buffer while still representing binary payloads.
|
|
63
|
-
return 'Uint8Array';
|
|
64
|
-
}
|
|
65
|
-
if (normalized === 'inet' || normalized === 'cidr' || normalized === 'macaddr') {
|
|
66
|
-
return 'string';
|
|
67
|
-
}
|
|
68
|
-
if (normalized.startsWith('interval')) {
|
|
69
|
-
// Interval strings cover day/hour/second variants, so keep them as text.
|
|
70
|
-
return 'string';
|
|
71
|
-
}
|
|
72
|
-
// Alert when an unfamiliar SQL type flows through so we can extend the mapper later.
|
|
73
|
-
warnUnknownSqlType(typeName, context);
|
|
74
|
-
return 'unknown';
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=typeMapper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typeMapper.js","sourceRoot":"","sources":["../../src/utils/typeMapper.ts"],"names":[],"mappings":";;AAqCA,wCAsDC;AA3FD,MAAM,YAAY,GAAG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
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { DdlLintMode } from '@rawsql-ts/testkit-core';
|
|
2
|
-
export interface ZtdConnectionConfig {
|
|
3
|
-
url?: string;
|
|
4
|
-
host?: string;
|
|
5
|
-
port?: number;
|
|
6
|
-
user?: string;
|
|
7
|
-
password?: string;
|
|
8
|
-
database?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface ZtdProjectConfig {
|
|
11
|
-
dialect: string;
|
|
12
|
-
ddlDir: string;
|
|
13
|
-
testsDir: string;
|
|
14
|
-
ddl: {
|
|
15
|
-
defaultSchema: string;
|
|
16
|
-
searchPath: string[];
|
|
17
|
-
};
|
|
18
|
-
/** Controls DDL integrity validation during config generation and tests. */
|
|
19
|
-
ddlLint: DdlLintMode;
|
|
20
|
-
connection?: ZtdConnectionConfig;
|
|
21
|
-
}
|
|
22
|
-
export declare const DEFAULT_ZTD_CONFIG: ZtdProjectConfig;
|
|
23
|
-
/**
|
|
24
|
-
* Resolves the path to the project's ztd.config.json from a provided root.
|
|
25
|
-
* @param rootDir - Directory to start searching from (defaults to current working directory).
|
|
26
|
-
* @returns Absolute path to ztd.config.json.
|
|
27
|
-
*/
|
|
28
|
-
export declare function resolveZtdConfigPath(rootDir?: string): string;
|
|
29
|
-
/**
|
|
30
|
-
* Loads the project configuration, merging against defaults when the file is missing or partially provided.
|
|
31
|
-
* @param rootDir - Directory containing the ztd.config.json file.
|
|
32
|
-
* @returns A fully-resolved ZtdProjectConfig instance.
|
|
33
|
-
*/
|
|
34
|
-
export declare function loadZtdProjectConfig(rootDir?: string): ZtdProjectConfig;
|
|
35
|
-
/**
|
|
36
|
-
* Persists the provided overrides on top of the existing project configuration.
|
|
37
|
-
* @param rootDir - Directory that hosts ztd.config.json.
|
|
38
|
-
* @param overrides - Partial configuration values to merge.
|
|
39
|
-
*/
|
|
40
|
-
export declare function writeZtdProjectConfig(rootDir: string, overrides?: Partial<ZtdProjectConfig>): void;
|
|
@@ -1,167 +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_ZTD_CONFIG = void 0;
|
|
7
|
-
exports.resolveZtdConfigPath = resolveZtdConfigPath;
|
|
8
|
-
exports.loadZtdProjectConfig = loadZtdProjectConfig;
|
|
9
|
-
exports.writeZtdProjectConfig = writeZtdProjectConfig;
|
|
10
|
-
const node_fs_1 = require("node:fs");
|
|
11
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
-
const CONFIG_NAME = 'ztd.config.json';
|
|
13
|
-
const DEFAULT_DDL_PROPERTIES = {
|
|
14
|
-
defaultSchema: 'public',
|
|
15
|
-
searchPath: ['public']
|
|
16
|
-
};
|
|
17
|
-
exports.DEFAULT_ZTD_CONFIG = {
|
|
18
|
-
dialect: 'postgres',
|
|
19
|
-
ddlDir: 'ztd/ddl',
|
|
20
|
-
testsDir: 'tests',
|
|
21
|
-
ddl: { ...DEFAULT_DDL_PROPERTIES },
|
|
22
|
-
ddlLint: 'strict'
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Resolves the path to the project's ztd.config.json from a provided root.
|
|
26
|
-
* @param rootDir - Directory to start searching from (defaults to current working directory).
|
|
27
|
-
* @returns Absolute path to ztd.config.json.
|
|
28
|
-
*/
|
|
29
|
-
function resolveZtdConfigPath(rootDir = process.cwd()) {
|
|
30
|
-
return node_path_1.default.join(rootDir, CONFIG_NAME);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Loads the project configuration, merging against defaults when the file is missing or partially provided.
|
|
34
|
-
* @param rootDir - Directory containing the ztd.config.json file.
|
|
35
|
-
* @returns A fully-resolved ZtdProjectConfig instance.
|
|
36
|
-
*/
|
|
37
|
-
function loadZtdProjectConfig(rootDir = process.cwd()) {
|
|
38
|
-
const filePath = resolveZtdConfigPath(rootDir);
|
|
39
|
-
if (!(0, node_fs_1.existsSync)(filePath)) {
|
|
40
|
-
return exports.DEFAULT_ZTD_CONFIG;
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
// Merge on top of defaults so partial configs remain valid.
|
|
44
|
-
const raw = JSON.parse((0, node_fs_1.readFileSync)(filePath, 'utf8'));
|
|
45
|
-
const rawDdl = typeof raw.ddl === 'object' && raw.ddl !== null ? raw.ddl : undefined;
|
|
46
|
-
const rawConnection = typeof raw.connection === 'object' && raw.connection !== null ? raw.connection : undefined;
|
|
47
|
-
const rawLintMode = typeof raw.ddlLint === 'string' ? raw.ddlLint.trim().toLowerCase() : undefined;
|
|
48
|
-
// Treat only non-empty ddl.searchPath arrays as explicit overrides.
|
|
49
|
-
const rawSearchPath = Array.isArray(rawDdl === null || rawDdl === void 0 ? void 0 : rawDdl.searchPath) ? rawDdl.searchPath : undefined;
|
|
50
|
-
// Detect override intent only when a non-empty searchPath array is provided.
|
|
51
|
-
let hasSearchPathOverrides = false;
|
|
52
|
-
if (rawSearchPath && rawSearchPath.length > 0) {
|
|
53
|
-
hasSearchPathOverrides = true;
|
|
54
|
-
}
|
|
55
|
-
let resolvedSearchPath = [...exports.DEFAULT_ZTD_CONFIG.ddl.searchPath];
|
|
56
|
-
if (hasSearchPathOverrides && rawSearchPath) {
|
|
57
|
-
resolvedSearchPath = rawSearchPath.filter((schema) => typeof schema === 'string' && schema.length > 0);
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
dialect: typeof raw.dialect === 'string' ? raw.dialect : exports.DEFAULT_ZTD_CONFIG.dialect,
|
|
61
|
-
ddlDir: typeof raw.ddlDir === 'string' && raw.ddlDir.length ? raw.ddlDir : exports.DEFAULT_ZTD_CONFIG.ddlDir,
|
|
62
|
-
testsDir: typeof raw.testsDir === 'string' && raw.testsDir.length ? raw.testsDir : exports.DEFAULT_ZTD_CONFIG.testsDir,
|
|
63
|
-
ddl: {
|
|
64
|
-
defaultSchema: typeof (rawDdl === null || rawDdl === void 0 ? void 0 : rawDdl.defaultSchema) === 'string' && rawDdl.defaultSchema.length
|
|
65
|
-
? rawDdl.defaultSchema
|
|
66
|
-
: exports.DEFAULT_ZTD_CONFIG.ddl.defaultSchema,
|
|
67
|
-
searchPath: resolvedSearchPath
|
|
68
|
-
},
|
|
69
|
-
ddlLint: isDdlLintMode(rawLintMode) ? rawLintMode : exports.DEFAULT_ZTD_CONFIG.ddlLint,
|
|
70
|
-
connection: normalizeConnectionConfig(rawConnection)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
throw new Error(`${CONFIG_NAME} is malformed: ${error instanceof Error ? error.message : String(error)}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function isDdlLintMode(value) {
|
|
78
|
-
return value === 'strict' || value === 'warn' || value === 'off';
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Persists the provided overrides on top of the existing project configuration.
|
|
82
|
-
* @param rootDir - Directory that hosts ztd.config.json.
|
|
83
|
-
* @param overrides - Partial configuration values to merge.
|
|
84
|
-
*/
|
|
85
|
-
function writeZtdProjectConfig(rootDir, overrides = {}) {
|
|
86
|
-
var _a;
|
|
87
|
-
const baseConfig = loadZtdProjectConfig(rootDir);
|
|
88
|
-
const finalConfig = {
|
|
89
|
-
...baseConfig,
|
|
90
|
-
...overrides,
|
|
91
|
-
ddl: {
|
|
92
|
-
...baseConfig.ddl,
|
|
93
|
-
...((_a = overrides.ddl) !== null && _a !== void 0 ? _a : {})
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const resolvedConnection = mergeConnectionConfig(baseConfig.connection, overrides.connection);
|
|
97
|
-
if (resolvedConnection) {
|
|
98
|
-
finalConfig.connection = resolvedConnection;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
delete finalConfig.connection;
|
|
102
|
-
}
|
|
103
|
-
const serialized = `${JSON.stringify(finalConfig, null, 2)}\n`;
|
|
104
|
-
(0, node_fs_1.writeFileSync)(resolveZtdConfigPath(rootDir), serialized, 'utf8');
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Normalizes a raw connection object into the typed connection configuration.
|
|
108
|
-
* @param rawConnection - Value read from ztd.config.json that may describe a connection.
|
|
109
|
-
* @returns A typed connection config or undefined when the input is invalid.
|
|
110
|
-
*/
|
|
111
|
-
function normalizeConnectionConfig(rawConnection) {
|
|
112
|
-
if (typeof rawConnection !== 'object' || rawConnection === null) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
const rawRecord = rawConnection;
|
|
116
|
-
const connection = {};
|
|
117
|
-
const url = typeof rawRecord.url === 'string' ? rawRecord.url.trim() : undefined;
|
|
118
|
-
if (url) {
|
|
119
|
-
connection.url = url;
|
|
120
|
-
}
|
|
121
|
-
const host = typeof rawRecord.host === 'string' ? rawRecord.host.trim() : undefined;
|
|
122
|
-
if (host) {
|
|
123
|
-
connection.host = host;
|
|
124
|
-
}
|
|
125
|
-
const user = typeof rawRecord.user === 'string' ? rawRecord.user.trim() : undefined;
|
|
126
|
-
if (user) {
|
|
127
|
-
connection.user = user;
|
|
128
|
-
}
|
|
129
|
-
const password = typeof rawRecord.password === 'string' && rawRecord.password.length > 0 ? rawRecord.password : undefined;
|
|
130
|
-
if (password) {
|
|
131
|
-
connection.password = password;
|
|
132
|
-
}
|
|
133
|
-
const database = typeof rawRecord.database === 'string' ? rawRecord.database.trim() : undefined;
|
|
134
|
-
if (database) {
|
|
135
|
-
connection.database = database;
|
|
136
|
-
}
|
|
137
|
-
const portValue = rawRecord.port;
|
|
138
|
-
const port = typeof portValue === 'number'
|
|
139
|
-
? portValue
|
|
140
|
-
: typeof portValue === 'string'
|
|
141
|
-
? Number(portValue)
|
|
142
|
-
: undefined;
|
|
143
|
-
if (port && Number.isInteger(port) && port > 0) {
|
|
144
|
-
connection.port = port;
|
|
145
|
-
}
|
|
146
|
-
if (Object.keys(connection).length === 0) {
|
|
147
|
-
return undefined;
|
|
148
|
-
}
|
|
149
|
-
return connection;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Merges two connection config objects, preferring values from the overrides.
|
|
153
|
-
* @param base - Existing connection configuration.
|
|
154
|
-
* @param overrides - Incoming override values from CLI or other sources.
|
|
155
|
-
* @returns Combined configuration or undefined when nothing is specified.
|
|
156
|
-
*/
|
|
157
|
-
function mergeConnectionConfig(base, overrides) {
|
|
158
|
-
const merged = {
|
|
159
|
-
...(base !== null && base !== void 0 ? base : {}),
|
|
160
|
-
...(overrides !== null && overrides !== void 0 ? overrides : {})
|
|
161
|
-
};
|
|
162
|
-
if (Object.keys(merged).length === 0) {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
return merged;
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=ztdProjectConfig.js.map
|