@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-profiles.test.js","sourceRoot":"","sources":["../../../../tests/user-profiles.test.ts"],"names":[],"mappings":";;AAAA,mCAAgD;AAEhD,6EAI2C;AAC3C,6DAA+D;AAC/D,qEAAqE;AAErE,SAAS,iBAAiB;IACxB,OAAO;QACL;YACE,eAAe,EAAE,CAAC;YAClB,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,mBAAmB;YAC1B,YAAY,EAAE,cAAc;YAC5B,UAAU,EAAE,sBAAsB;YAClC,UAAU,EAAE,sBAAsB;SACnC;QACD;YACE,eAAe,EAAE,CAAC;YAClB,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,mBAAmB;YAC1B,YAAY,EAAE,eAAe;YAC7B,UAAU,EAAE,sBAAsB;YAClC,UAAU,EAAE,sBAAsB;SACnC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO;QACL;YACE,UAAU,EAAE,GAAG;YACf,eAAe,EAAE,CAAC;YAClB,GAAG,EAAE,oCAAoC;YACzC,OAAO,EAAE,qBAAqB;YAC9B,QAAQ,EAAE,IAAI;SACf;KACF,CAAC;AACJ,CAAC;AAED,SAAS,aAAa;IACpB,OAAO;QACL,IAAA,oCAAY,EACV,qBAAqB,EACrB,iBAAiB,EAAE,EACnB,oCAAY,CAAC,qBAAqB,CAAC,CACpC;QACD,IAAA,oCAAY,EACV,qBAAqB,EACrB,iBAAiB,EAAE,EACnB,oCAAY,CAAC,qBAAqB,CAAC,C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|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const ztd_row_map_generated_1 = require("./generated/ztd-row-map.generated");
|
|
5
|
-
const user_accounts_1 = require("../src/repositories/user-accounts");
|
|
6
|
-
const userColumns = new Set(Object.keys(ztd_row_map_generated_1.tableSchemas['public.user_account'].columns));
|
|
7
|
-
(0, vitest_1.describe)('user_account writer columns', () => {
|
|
8
|
-
(0, vitest_1.test)('insert columns must exist on the canonical table', () => {
|
|
9
|
-
const { insertColumns } = user_accounts_1.userAccountWriterColumnSets;
|
|
10
|
-
const missing = insertColumns.filter((column) => !userColumns.has(column));
|
|
11
|
-
(0, vitest_1.expect)(missing).toEqual([]);
|
|
12
|
-
(0, vitest_1.expect)(insertColumns).toEqual(vitest_1.expect.arrayContaining(['username', 'email', 'display_name']));
|
|
13
|
-
});
|
|
14
|
-
(0, vitest_1.test)('update columns stay within allowed set and avoid immutable columns', () => {
|
|
15
|
-
const { updateColumns, immutableColumns } = user_accounts_1.userAccountWriterColumnSets;
|
|
16
|
-
const missing = updateColumns.filter((column) => !userColumns.has(column));
|
|
17
|
-
(0, vitest_1.expect)(missing).toEqual([]);
|
|
18
|
-
(0, vitest_1.expect)(updateColumns).not.toEqual(vitest_1.expect.arrayContaining([...immutableColumns]));
|
|
19
|
-
});
|
|
20
|
-
(0, vitest_1.test)('immutable columns reflect the DDL and are not targetted by updates', () => {
|
|
21
|
-
const { immutableColumns, updateColumns } = user_accounts_1.userAccountWriterColumnSets;
|
|
22
|
-
const missing = immutableColumns.filter((column) => !userColumns.has(column));
|
|
23
|
-
(0, vitest_1.expect)(missing).toEqual([]);
|
|
24
|
-
immutableColumns.forEach((column) => {
|
|
25
|
-
(0, vitest_1.expect)(updateColumns).not.toContain(column);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
//# sourceMappingURL=writer-constraints.test.js.map
|
|
@@ -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AAgB,CAAC,CAAC,CAC9C,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAA,aAAI,EAAC,oEAAoE,EAAE,GAAG,EAAE;QAC9E,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,GAAG,2CAA2B,CAAC;QACxE,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9E,IAAA,eAAM,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5B,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAClC,IAAA,eAAM,EAAC,aAAa,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// GENERATED FILE. DO NOT EDIT.
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.default = {
|
|
5
|
-
ztdRootDir: 'ztd',
|
|
6
|
-
ddlDir: 'ztd/ddl',
|
|
7
|
-
enumsDir: 'ztd/enums',
|
|
8
|
-
domainSpecsDir: 'ztd/domain-specs',
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=ztd-layout.generated.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ztd-layout.generated.js","sourceRoot":"","sources":["../../../../tests/ztd-layout.generated.ts"],"names":[],"mappings":";AAAA,+BAA+B;;AAE/B,kBAAe;IACb,UAAU,EAAE,KAAK;IACjB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,WAAW;IACrB,cAAc,EAAE,kBAAkB;CACnC,CAAC"}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import type { SqlClient } from '../db/sql-client';
|
|
2
|
-
import { createMapper, entity, toRowsExecutor } from '@rawsql-ts/mapper-core';
|
|
3
|
-
import { insert, Key, remove, update } from '@rawsql-ts/writer-core';
|
|
4
|
-
|
|
5
|
-
const userAccountTable = 'public.user_account';
|
|
6
|
-
|
|
7
|
-
type UserProfileRow = {
|
|
8
|
-
profileId: number;
|
|
9
|
-
userAccountId: number;
|
|
10
|
-
bio: string | null;
|
|
11
|
-
website: string | null;
|
|
12
|
-
verified: boolean;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* DTO that represents a user account with its optional profile information.
|
|
17
|
-
* @property {number} userAccountId The primary key for the user account.
|
|
18
|
-
* @property {string} username The canonical username.
|
|
19
|
-
* @property {string} email The account email address.
|
|
20
|
-
* @property {string} displayName The account display name.
|
|
21
|
-
* @property {Date} createdAt When the account was created.
|
|
22
|
-
* @property {Date} updatedAt When the account was last updated.
|
|
23
|
-
* @property {UserProfileRow} [profile] Optional profile payload joined from user_profile.
|
|
24
|
-
*/
|
|
25
|
-
export type UserAccountWithProfile = {
|
|
26
|
-
userAccountId: number;
|
|
27
|
-
username: string;
|
|
28
|
-
email: string;
|
|
29
|
-
displayName: string;
|
|
30
|
-
createdAt: Date;
|
|
31
|
-
updatedAt: Date;
|
|
32
|
-
profile?: UserProfileRow;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Map the joined profile columns so we can hydrate nested objects later.
|
|
36
|
-
const profileMapping = entity<UserProfileRow>({
|
|
37
|
-
name: 'userProfile',
|
|
38
|
-
key: 'profileId',
|
|
39
|
-
columnMap: {
|
|
40
|
-
profileId: 'profile_id',
|
|
41
|
-
userAccountId: 'profile_user_account_id',
|
|
42
|
-
bio: 'bio',
|
|
43
|
-
website: 'website',
|
|
44
|
-
verified: 'verified',
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const userAccountMapping = entity<UserAccountWithProfile>({
|
|
49
|
-
name: 'userAccount',
|
|
50
|
-
key: 'userAccountId',
|
|
51
|
-
columnMap: {
|
|
52
|
-
userAccountId: 'user_account_id',
|
|
53
|
-
username: 'username',
|
|
54
|
-
email: 'email',
|
|
55
|
-
displayName: 'display_name',
|
|
56
|
-
createdAt: 'created_at',
|
|
57
|
-
updatedAt: 'updated_at',
|
|
58
|
-
},
|
|
59
|
-
}).belongsTo('profile', profileMapping, 'userAccountId', { optional: true });
|
|
60
|
-
|
|
61
|
-
const userProfilesSql = `
|
|
62
|
-
SELECT
|
|
63
|
-
u.user_account_id,
|
|
64
|
-
u.username,
|
|
65
|
-
u.email,
|
|
66
|
-
u.display_name,
|
|
67
|
-
u.created_at,
|
|
68
|
-
u.updated_at,
|
|
69
|
-
p.profile_id,
|
|
70
|
-
p.user_account_id AS profile_user_account_id,
|
|
71
|
-
p.bio,
|
|
72
|
-
p.website,
|
|
73
|
-
p.verified
|
|
74
|
-
FROM public.user_account u
|
|
75
|
-
LEFT JOIN public.user_profile p ON p.user_account_id = u.user_account_id
|
|
76
|
-
ORDER BY u.user_account_id, p.profile_id;
|
|
77
|
-
`;
|
|
78
|
-
|
|
79
|
-
// Build a mapper that can translate snake_case columns into camelCase DTOs.
|
|
80
|
-
const createMapperForClient = (client: SqlClient) =>
|
|
81
|
-
createMapper(
|
|
82
|
-
toRowsExecutor((sql, params: unknown[] = []) =>
|
|
83
|
-
client.query<Record<string, unknown>>(sql, params),
|
|
84
|
-
),
|
|
85
|
-
{
|
|
86
|
-
// The explicit column maps enumerate the nested entity columns while keyTransform handles generic snake_to_camel conversions.
|
|
87
|
-
keyTransform: 'snake_to_camel',
|
|
88
|
-
coerceDates: true,
|
|
89
|
-
},
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Queries all user accounts together with their associated profiles.
|
|
94
|
-
* @param {SqlClient} client Client proxy that executes the mapper SQL.
|
|
95
|
-
* @returns {Promise<UserAccountWithProfile[]>} The joined account-with-profile rows.
|
|
96
|
-
*/
|
|
97
|
-
export async function listUserProfiles(
|
|
98
|
-
client: SqlClient,
|
|
99
|
-
): Promise<UserAccountWithProfile[]> {
|
|
100
|
-
const mapper = createMapperForClient(client);
|
|
101
|
-
return mapper.query(userProfilesSql, [], userAccountMapping);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Parameters required to insert a new user account.
|
|
106
|
-
* @property {string} username The requested username.
|
|
107
|
-
* @property {string} email The requested email address.
|
|
108
|
-
* @property {string} displayName The requested display name.
|
|
109
|
-
*/
|
|
110
|
-
export type NewUserAccount = {
|
|
111
|
-
username: string;
|
|
112
|
-
email: string;
|
|
113
|
-
displayName: string;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Payload describing the display name change for an existing account.
|
|
118
|
-
* @property {string} displayName The new display name to persist.
|
|
119
|
-
*/
|
|
120
|
-
export type DisplayNameUpdatePayload = {
|
|
121
|
-
displayName: string;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Builds an insert statement for the user_account writer.
|
|
126
|
-
* @param {NewUserAccount} input The normalized fields for the new account.
|
|
127
|
-
* @returns {ReturnType<typeof insert>} A well-formed insert statement for the user_account writer.
|
|
128
|
-
*/
|
|
129
|
-
export function buildInsertUserAccount(
|
|
130
|
-
input: NewUserAccount,
|
|
131
|
-
): ReturnType<typeof insert> {
|
|
132
|
-
return insert(userAccountTable, {
|
|
133
|
-
username: input.username,
|
|
134
|
-
email: input.email,
|
|
135
|
-
display_name: input.displayName,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Builds an update statement that refreshes the display name and timestamp.
|
|
141
|
-
* @param {Key} key The unique key identifying the row to update.
|
|
142
|
-
* @param {DisplayNameUpdatePayload} payload The new display name payload.
|
|
143
|
-
* @returns {ReturnType<typeof update>} A writer update statement that refreshes the display name and updated_at timestamp.
|
|
144
|
-
*/
|
|
145
|
-
export function buildUpdateDisplayName(
|
|
146
|
-
key: Key,
|
|
147
|
-
payload: DisplayNameUpdatePayload,
|
|
148
|
-
): ReturnType<typeof update> {
|
|
149
|
-
return update(
|
|
150
|
-
userAccountTable,
|
|
151
|
-
{
|
|
152
|
-
// Persist the new display name and bump the timestamp along with it.
|
|
153
|
-
display_name: payload.displayName,
|
|
154
|
-
updated_at: new Date(),
|
|
155
|
-
},
|
|
156
|
-
key,
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Builds a delete statement for the specified user account key.
|
|
162
|
-
* @param {Key} key Identifies the row to remove.
|
|
163
|
-
* @returns {ReturnType<typeof remove>} A writer delete statement for the matching user account.
|
|
164
|
-
*/
|
|
165
|
-
export function buildRemoveUserAccount(key: Key): ReturnType<typeof remove> {
|
|
166
|
-
return remove(userAccountTable, key);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Column sets that writer tests use to ensure only approved columns are touched.
|
|
171
|
-
* @property {readonly string[]} insertColumns Columns allowed for new account inserts.
|
|
172
|
-
* @property {readonly string[]} updateColumns Columns permitted during updates.
|
|
173
|
-
* @property {readonly string[]} immutableColumns Columns that must remain unchanged.
|
|
174
|
-
*/
|
|
175
|
-
export const userAccountWriterColumnSets = {
|
|
176
|
-
insertColumns: ['username', 'email', 'display_name'] as const,
|
|
177
|
-
updateColumns: ['display_name', 'updated_at'] as const,
|
|
178
|
-
immutableColumns: ['user_account_id', 'created_at'] as const,
|
|
179
|
-
};
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test, afterAll } from 'vitest';
|
|
2
|
-
import type { TableFixture, TestkitProvider } from '@rawsql-ts/testkit-core';
|
|
3
|
-
import { createTestkitProvider } from '@rawsql-ts/testkit-core';
|
|
4
|
-
import { createPgTestkitClient } from '@rawsql-ts/pg-testkit';
|
|
5
|
-
import { Pool } from 'pg';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import {
|
|
8
|
-
tableFixture,
|
|
9
|
-
tableSchemas,
|
|
10
|
-
TestRowMap,
|
|
11
|
-
} from './generated/ztd-row-map.generated';
|
|
12
|
-
import { listUserProfiles } from '../src/repositories/user-accounts';
|
|
13
|
-
|
|
14
|
-
const ddlDirectories = [path.resolve(__dirname, '../ztd/ddl')];
|
|
15
|
-
const skipReason = 'DATABASE_URL is not configured';
|
|
16
|
-
const configuredDatabaseUrl = process.env.DATABASE_URL?.trim();
|
|
17
|
-
const suiteTitle = configuredDatabaseUrl
|
|
18
|
-
? 'user profile mapper'
|
|
19
|
-
: `user profile mapper (skipped: ${skipReason})`;
|
|
20
|
-
const describeUserProfile = configuredDatabaseUrl
|
|
21
|
-
? describe
|
|
22
|
-
: (describe.skip as typeof describe);
|
|
23
|
-
let pool: Pool | undefined;
|
|
24
|
-
let providerPromise: Promise<TestkitProvider> | undefined;
|
|
25
|
-
|
|
26
|
-
// Lazily initialize the test provider so missing DATABASE_URL values do not trigger side effects.
|
|
27
|
-
function getProvider(): Promise<TestkitProvider> {
|
|
28
|
-
if (providerPromise) {
|
|
29
|
-
return providerPromise;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const databaseUrl = process.env.DATABASE_URL?.trim();
|
|
33
|
-
if (!databaseUrl) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
'Cannot initialize the repository testkit provider without DATABASE_URL.',
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
pool = new Pool({ connectionString: databaseUrl });
|
|
40
|
-
const activePool = pool;
|
|
41
|
-
providerPromise = createTestkitProvider({
|
|
42
|
-
connectionFactory: () => activePool.connect(),
|
|
43
|
-
resourceFactory: async (connection, fixtures) =>
|
|
44
|
-
createPgTestkitClient({
|
|
45
|
-
connectionFactory: () => connection,
|
|
46
|
-
tableRows: fixtures,
|
|
47
|
-
ddl: { directories: ddlDirectories },
|
|
48
|
-
}),
|
|
49
|
-
releaseResource: async (client) => {
|
|
50
|
-
await client.close();
|
|
51
|
-
},
|
|
52
|
-
disposeConnection: async (connection) => {
|
|
53
|
-
if (typeof connection.release === 'function') {
|
|
54
|
-
connection.release();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (typeof connection.end === 'function') {
|
|
58
|
-
await connection.end();
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return providerPromise;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
afterAll(async () => {
|
|
67
|
-
// Close resources only when initialization actually happened.
|
|
68
|
-
if (!providerPromise) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const provider = await providerPromise;
|
|
73
|
-
await provider.close();
|
|
74
|
-
if (pool) {
|
|
75
|
-
await pool.end();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
function buildUserAccounts(): TestRowMap['public.user_account'][] {
|
|
80
|
-
return [
|
|
81
|
-
{
|
|
82
|
-
user_account_id: 1,
|
|
83
|
-
username: 'alpha',
|
|
84
|
-
email: 'alpha@example.com',
|
|
85
|
-
display_name: 'Alpha Tester',
|
|
86
|
-
created_at: '2025-12-01T08:00:00Z',
|
|
87
|
-
updated_at: '2025-12-01T09:00:00Z',
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
user_account_id: 2,
|
|
91
|
-
username: 'bravo',
|
|
92
|
-
email: 'bravo@example.com',
|
|
93
|
-
display_name: 'Bravo Builder',
|
|
94
|
-
created_at: '2025-12-02T10:00:00Z',
|
|
95
|
-
updated_at: '2025-12-02T11:00:00Z',
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function buildUserProfiles(): TestRowMap['public.user_profile'][] {
|
|
101
|
-
return [
|
|
102
|
-
{
|
|
103
|
-
profile_id: 101,
|
|
104
|
-
user_account_id: 1,
|
|
105
|
-
bio: 'Lead engineer and mapper advocate.',
|
|
106
|
-
website: 'https://example.com',
|
|
107
|
-
verified: true,
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function buildFixtures(): TableFixture[] {
|
|
113
|
-
return [
|
|
114
|
-
tableFixture(
|
|
115
|
-
'public.user_account',
|
|
116
|
-
buildUserAccounts(),
|
|
117
|
-
tableSchemas['public.user_account'],
|
|
118
|
-
),
|
|
119
|
-
tableFixture(
|
|
120
|
-
'public.user_profile',
|
|
121
|
-
buildUserProfiles(),
|
|
122
|
-
tableSchemas['public.user_profile'],
|
|
123
|
-
),
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
describeUserProfile(suiteTitle, () => {
|
|
128
|
-
test('listUserProfiles hydrates optional profiles', async () => {
|
|
129
|
-
const fixtures = buildFixtures();
|
|
130
|
-
const provider = await getProvider();
|
|
131
|
-
await provider.withRepositoryFixture(fixtures, async (client) => {
|
|
132
|
-
const result = await listUserProfiles(client);
|
|
133
|
-
expect(result).toEqual([
|
|
134
|
-
{
|
|
135
|
-
userAccountId: 1,
|
|
136
|
-
username: 'alpha',
|
|
137
|
-
email: 'alpha@example.com',
|
|
138
|
-
displayName: 'Alpha Tester',
|
|
139
|
-
createdAt: new Date('2025-12-01T08:00:00Z'),
|
|
140
|
-
updatedAt: new Date('2025-12-01T09:00:00Z'),
|
|
141
|
-
profile: {
|
|
142
|
-
profileId: 101,
|
|
143
|
-
userAccountId: 1,
|
|
144
|
-
bio: 'Lead engineer and mapper advocate.',
|
|
145
|
-
website: 'https://example.com',
|
|
146
|
-
verified: true,
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
userAccountId: 2,
|
|
151
|
-
username: 'bravo',
|
|
152
|
-
email: 'bravo@example.com',
|
|
153
|
-
displayName: 'Bravo Builder',
|
|
154
|
-
createdAt: new Date('2025-12-02T10:00:00Z'),
|
|
155
|
-
updatedAt: new Date('2025-12-02T11:00:00Z'),
|
|
156
|
-
profile: undefined,
|
|
157
|
-
},
|
|
158
|
-
]);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { tableSchemas } from './generated/ztd-row-map.generated';
|
|
3
|
-
import { userAccountWriterColumnSets } from '../src/repositories/user-accounts';
|
|
4
|
-
|
|
5
|
-
const userColumns = new Set(
|
|
6
|
-
Object.keys(tableSchemas['public.user_account'].columns),
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
describe('user_account writer columns', () => {
|
|
10
|
-
test('insert columns must exist on the canonical table', () => {
|
|
11
|
-
const { insertColumns } = userAccountWriterColumnSets;
|
|
12
|
-
const missing = insertColumns.filter((column) => !userColumns.has(column));
|
|
13
|
-
expect(missing, `Missing columns: ${missing.join(', ')}`).toEqual([]);
|
|
14
|
-
expect(insertColumns).toEqual(
|
|
15
|
-
expect.arrayContaining(['username', 'email', 'display_name']),
|
|
16
|
-
);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('writer column sets align with the canonical table', () => {
|
|
20
|
-
const { updateColumns, immutableColumns } = userAccountWriterColumnSets;
|
|
21
|
-
const missingUpdates = updateColumns.filter((column) => !userColumns.has(column));
|
|
22
|
-
expect(missingUpdates, `Missing update columns: ${missingUpdates.join(', ')}`).toEqual([]);
|
|
23
|
-
const missingImmutables = immutableColumns.filter((column) => !userColumns.has(column));
|
|
24
|
-
expect(missingImmutables, `Missing immutable columns: ${missingImmutables.join(', ')}`).toEqual([]);
|
|
25
|
-
immutableColumns.forEach((column) => {
|
|
26
|
-
expect(
|
|
27
|
-
updateColumns,
|
|
28
|
-
`Immutable column "${column}" should never appear in updateColumns`,
|
|
29
|
-
).not.toContain(column);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|