@rawsql-ts/ztd-cli 0.15.0 → 0.16.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 +12 -12
- package/dist/commands/init.js +19 -10
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.d.ts +1 -1
- package/dist/commands/lint.js +3 -3
- package/dist/commands/lint.js.map +1 -1
- package/package.json +7 -6
- package/templates/AGENTS.md +58 -45
- package/templates/README.md +45 -67
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.d.ts +38 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js +117 -0
- package/templates/dist/drivers/pg-testkit/src/driver/PgTestkitClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.d.ts +4 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js +71 -0
- package/templates/dist/drivers/pg-testkit/src/driver/createPgTestkitPool.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/index.d.ts +5 -0
- package/templates/dist/drivers/pg-testkit/src/index.js +11 -0
- package/templates/dist/drivers/pg-testkit/src/index.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.d.ts +3 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js +79 -0
- package/templates/dist/drivers/pg-testkit/src/proxy/wrapPgClient.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/types.d.ts +69 -0
- package/templates/dist/drivers/pg-testkit/src/types.js +3 -0
- package/templates/dist/drivers/pg-testkit/src/types.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.d.ts +15 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js +34 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureState.js.map +1 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.d.ts +12 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js +53 -0
- package/templates/dist/drivers/pg-testkit/src/utils/fixtureValidation.js.map +1 -0
- package/templates/dist/mapper-core/src/index.d.ts +160 -0
- package/templates/dist/mapper-core/src/index.js +637 -0
- package/templates/dist/mapper-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/errors/index.d.ts +49 -0
- package/templates/dist/testkit-core/src/errors/index.js +111 -0
- package/templates/dist/testkit-core/src/errors/index.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.d.ts +5 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js +29 -0
- package/templates/dist/testkit-core/src/fixtures/ColumnAffinity.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.d.ts +37 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js +182 -0
- package/templates/dist/testkit-core/src/fixtures/DdlFixtureLoader.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.d.ts +20 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js +121 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.d.ts +51 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js +199 -0
- package/templates/dist/testkit-core/src/fixtures/FixtureStore.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.d.ts +10 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js +28 -0
- package/templates/dist/testkit-core/src/fixtures/TableDefinitionSchemaRegistry.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.d.ts +18 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js +80 -0
- package/templates/dist/testkit-core/src/fixtures/TableNameResolver.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.d.ts +59 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js +489 -0
- package/templates/dist/testkit-core/src/fixtures/ddlLint.js.map +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.d.ts +1 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js +6 -0
- package/templates/dist/testkit-core/src/fixtures/naming.js.map +1 -0
- package/templates/dist/testkit-core/src/index.d.ts +17 -0
- package/templates/dist/testkit-core/src/index.js +47 -0
- package/templates/dist/testkit-core/src/index.js.map +1 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.d.ts +8 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js +16 -0
- package/templates/dist/testkit-core/src/logger/NoopLogger.js.map +1 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.d.ts +57 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js +149 -0
- package/templates/dist/testkit-core/src/provider/TestkitProvider.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.d.ts +43 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js +473 -0
- package/templates/dist/testkit-core/src/rewriter/ResultSelectRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.d.ts +9 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js +38 -0
- package/templates/dist/testkit-core/src/rewriter/SelectAnalyzer.js.map +1 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.d.ts +42 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js +298 -0
- package/templates/dist/testkit-core/src/rewriter/SelectFixtureRewriter.js.map +1 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.d.ts +12 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js +63 -0
- package/templates/dist/testkit-core/src/sql/SqliteValuesBuilder.js.map +1 -0
- package/templates/dist/testkit-core/src/types/index.d.ts +69 -0
- package/templates/dist/testkit-core/src/types/index.js +3 -0
- package/templates/dist/testkit-core/src/types/index.js.map +1 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.d.ts +28 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js +81 -0
- package/templates/dist/testkit-core/src/utils/queryHelpers.js.map +1 -0
- package/templates/dist/writer-core/src/index.d.ts +34 -0
- package/templates/dist/writer-core/src/index.js +115 -0
- package/templates/dist/writer-core/src/index.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js +3 -0
- package/templates/dist/ztd-cli/templates/src/db/sql-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.d.ts +36 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js +85 -0
- package/templates/dist/ztd-cli/templates/src/repositories/user-accounts.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.d.ts +20 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js +33 -0
- package/templates/dist/ztd-cli/templates/tests/generated/ztd-row-map.generated.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.d.ts +10 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/support/global-setup.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.d.ts +66 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js +552 -0
- package/templates/dist/ztd-cli/templates/tests/support/testkit-client.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js +82 -0
- package/templates/dist/ztd-cli/templates/tests/user-profiles.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.d.ts +1 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js +29 -0
- package/templates/dist/ztd-cli/templates/tests/writer-constraints.test.js.map +1 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.d.ts +7 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js +10 -0
- package/templates/dist/ztd-cli/templates/tests/ztd-layout.generated.js.map +1 -0
- package/templates/src/db/sql-client.ts +1 -1
- package/templates/src/repositories/user-accounts.ts +179 -0
- package/templates/tests/AGENTS.md +23 -2
- package/templates/tests/support/global-setup.ts +1 -1
- package/templates/tests/support/testkit-client.ts +4 -4
- package/templates/tests/user-profiles.test.ts +161 -0
- package/templates/tests/writer-constraints.test.ts +32 -0
- package/templates/tests/ztd-layout.generated.ts +0 -2
- package/templates/tsconfig.json +1 -2
- package/templates/ztd/AGENTS.md +10 -85
- package/templates/ztd/README.md +10 -79
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPgTestkitPool.js","sourceRoot":"","sources":["../../../../../../../drivers/pg-testkit/src/driver/createPgTestkitPool.ts"],"names":[],"mappings":";;;AASA,2BAA8C;AAC9C,uDAA0D;AAQ1D,MAAM,sBAAsB,GAAG,gDAAgD,CAAC;AAEhF,MAAM,aAAa,GAAG,CAAC,KAAoD,EAAuC,EAAE;IAClH,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,IAAI,KAAK,IAAI,WAAW,IAAI,KAAK,IAAI,kBAAkB,IAAI,KAAK,CAAC,CACxE,CAAC;AACJ,CAAC,CAAC;AAEF,4GAA4G;AACrG,MAAM,mBAAmB,GAAG,CACjC,gBAAwB,EACxB,GAAG,iBAAuE,EACpE,EAAE;;IACR,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,GAAG,CAAC,IAAI,aAAa,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAClH,MAAM,WAAW,GAAG,UAAU;QAC5B,CAAC,CAAE,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAg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M,UAAU,GAAe,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IAC3E,OAAO,IAAI,SAAI,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC,CAAC;AA/FW,QAAA,mBAAmB,uBA+F9B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { CreatePgTestkitClientOptions, CreatePgTestkitPoolOptions, PgQueryInput, PgQueryable, WrapPgClientOptions, WrappedPgClient, } from './types';
|
|
2
|
+
export type { TableRowsFixture } from '@rawsql-ts/testkit-core';
|
|
3
|
+
export { createPgTestkitClient, PgTestkitClient } from './driver/PgTestkitClient';
|
|
4
|
+
export { createPgTestkitPool } from './driver/createPgTestkitPool';
|
|
5
|
+
export { wrapPgClient } from './proxy/wrapPgClient';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapPgClient = exports.createPgTestkitPool = exports.PgTestkitClient = exports.createPgTestkitClient = void 0;
|
|
4
|
+
var PgTestkitClient_1 = require("./driver/PgTestkitClient");
|
|
5
|
+
Object.defineProperty(exports, "createPgTestkitClient", { enumerable: true, get: function () { return PgTestkitClient_1.createPgTestkitClient; } });
|
|
6
|
+
Object.defineProperty(exports, "PgTestkitClient", { enumerable: true, get: function () { return PgTestkitClient_1.PgTestkitClient; } });
|
|
7
|
+
var createPgTestkitPool_1 = require("./driver/createPgTestkitPool");
|
|
8
|
+
Object.defineProperty(exports, "createPgTestkitPool", { enumerable: true, get: function () { return createPgTestkitPool_1.createPgTestkitPool; } });
|
|
9
|
+
var wrapPgClient_1 = require("./proxy/wrapPgClient");
|
|
10
|
+
Object.defineProperty(exports, "wrapPgClient", { enumerable: true, get: function () { return wrapPgClient_1.wrapPgClient; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../drivers/pg-testkit/src/index.ts"],"names":[],"mappings":";;;AASA,4DAAkF;AAAzE,wHAAA,qBAAqB,OAAA;AAAE,kHAAA,eAAe,OAAA;AAC/C,oEAAmE;AAA1D,0HAAA,mBAAmB,OAAA;AAC5B,qDAAoD;AAA3C,4GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PgQueryable, WrapPgClientOptions, WrappedPgClient } from '../types';
|
|
2
|
+
/** Wraps an existing Postgres client with fixture-aware query rewriting. */
|
|
3
|
+
export declare const wrapPgClient: <T extends PgQueryable>(client: T, options: WrapPgClientOptions) => WrappedPgClient<T>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapPgClient = void 0;
|
|
4
|
+
const testkit_core_1 = require("@rawsql-ts/testkit-core");
|
|
5
|
+
const fixtureValidation_1 = require("../utils/fixtureValidation");
|
|
6
|
+
const fixtureState_1 = require("../utils/fixtureState");
|
|
7
|
+
const buildEmptyResult = (command = 'NOOP') => ({
|
|
8
|
+
command,
|
|
9
|
+
rowCount: 0,
|
|
10
|
+
oid: 0,
|
|
11
|
+
rows: [],
|
|
12
|
+
fields: [],
|
|
13
|
+
});
|
|
14
|
+
/** Wraps an existing Postgres client with fixture-aware query rewriting. */
|
|
15
|
+
const wrapPgClient = (client, options) => {
|
|
16
|
+
var _a;
|
|
17
|
+
// Keep resolver configuration in sync with the pg-testkit options.
|
|
18
|
+
const tableNameResolver = new testkit_core_1.TableNameResolver({
|
|
19
|
+
defaultSchema: options.defaultSchema,
|
|
20
|
+
searchPath: options.searchPath,
|
|
21
|
+
});
|
|
22
|
+
// Align shared fixtures with the resolver so every consumer sees the same schema snapshot.
|
|
23
|
+
const fixtureState = (0, fixtureState_1.resolveFixtureState)({
|
|
24
|
+
ddl: options.ddl,
|
|
25
|
+
tableDefinitions: options.tableDefinitions,
|
|
26
|
+
tableRows: options.tableRows,
|
|
27
|
+
}, tableNameResolver);
|
|
28
|
+
// Ensure the provided fixtures align with the shared definitions before creating the fixture store.
|
|
29
|
+
(0, fixtureValidation_1.validateFixtureRowsAgainstTableDefinitions)(options.tableRows, fixtureState.tableDefinitions, 'wrap tableRows', tableNameResolver);
|
|
30
|
+
const fixtureStore = new testkit_core_1.DefaultFixtureProvider(fixtureState.tableDefinitions, fixtureState.tableRows, tableNameResolver);
|
|
31
|
+
const rewriter = new testkit_core_1.ResultSelectRewriter(fixtureStore, (_a = options.missingFixtureStrategy) !== null && _a !== void 0 ? _a : 'error', options.formatterOptions, tableNameResolver);
|
|
32
|
+
const buildProxy = (scopedFixtures) => {
|
|
33
|
+
return new Proxy(client, {
|
|
34
|
+
get(target, prop, receiver) {
|
|
35
|
+
if (prop === 'withFixtures') {
|
|
36
|
+
return (fixtures) => {
|
|
37
|
+
// Confirm each overlay matches the resolved definitions before reusing the proxy.
|
|
38
|
+
(0, fixtureValidation_1.validateFixtureRowsAgainstTableDefinitions)(fixtures, fixtureState.tableDefinitions, 'scoped fixtures', tableNameResolver);
|
|
39
|
+
return buildProxy(fixtures);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const value = Reflect.get(target, prop, receiver);
|
|
43
|
+
if (prop === 'query' && typeof value === 'function') {
|
|
44
|
+
return async (textOrConfig, values) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const sql = typeof textOrConfig === 'string' ? textOrConfig : textOrConfig.text;
|
|
47
|
+
if (!sql) {
|
|
48
|
+
return value.apply(target, [textOrConfig, values]);
|
|
49
|
+
}
|
|
50
|
+
// Inject fixture-backed CTEs into CRUD/SELECT statements and skip unsupported DDL.
|
|
51
|
+
const rewritten = rewriter.rewrite(sql, scopedFixtures);
|
|
52
|
+
if (!rewritten.sql) {
|
|
53
|
+
return buildEmptyResult();
|
|
54
|
+
}
|
|
55
|
+
// Align caller parameters with the rewritten SQL so placeholders stay contiguous.
|
|
56
|
+
const incomingParams = typeof textOrConfig === 'string'
|
|
57
|
+
? values
|
|
58
|
+
: (_a = values !== null && values !== void 0 ? values : textOrConfig.values) !== null && _a !== void 0 ? _a : textOrConfig.params;
|
|
59
|
+
const normalized = (0, testkit_core_1.alignRewrittenParameters)(rewritten.sql, incomingParams);
|
|
60
|
+
const payload = typeof textOrConfig === 'string'
|
|
61
|
+
? normalized.sql
|
|
62
|
+
: { ...textOrConfig, text: normalized.sql, values: normalized.params };
|
|
63
|
+
let result = typeof payload === 'string'
|
|
64
|
+
? await value.call(target, payload, normalized.params)
|
|
65
|
+
: await value.call(target, payload);
|
|
66
|
+
(_b = options.onExecute) === null || _b === void 0 ? void 0 : _b.call(options, normalized.sql, normalized.params, rewritten.fixturesApplied);
|
|
67
|
+
// Normalize rowCount/command only when the rewriter produced a count-wrapper SELECT.
|
|
68
|
+
result = (0, testkit_core_1.applyCountWrapper)(result, rewritten.sourceCommand, rewritten.isCountWrapper);
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
return buildProxy();
|
|
77
|
+
};
|
|
78
|
+
exports.wrapPgClient = wrapPgClient;
|
|
79
|
+
//# sourceMappingURL=wrapPgClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapPgClient.js","sourceRoot":"","sources":["../../../../../../../drivers/pg-testkit/src/proxy/wrapPgClient.ts"],"names":[],"mappings":";;;AACA,0DAMiC;AAQjC,kEAAwF;AACxF,wDAA4D;AAE5D,MAAM,gBAAgB,GAAG,CAA4C,OAAO,GAAG,MAAM,EAAkB,EAAE,CAAC,CAAC;IACzG,OAAO;IACP,QAAQ,EAAE,CAAC;IACX,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;CACX,CAAC,CAAC;AAEH,4EAA4E;AACrE,MAAM,Y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AAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC;4BACtD,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;wBAExC,MAAA,OAAO,CAAC,SAAS,wDAAG,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,CAAC;wBAElF,qFAAqF;wBACrF,MAAM,GAAG,IAAA,gCAAiB,EAAC,MAAM,EAAE,SAAS,CAAC,aAAa,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;wBAEtF,OAAO,MAAM,CAAC;oBAChB,CAAC,CAAC;gBACJ,CAAC;gBAED,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAClE,CAAC;SACF,CAAuB,CAAC;IAC3B,CAAC,CAAC;IAEF,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC,CAAC;AAvGW,QAAA,YAAY,gBAuGvB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { QueryConfig, QueryResult, QueryResultRow } from 'pg';
|
|
2
|
+
import type { FixtureTableDefinition, MissingFixtureStrategy, SqlFormatterOptions, TableDefinitionModel, TableDefinitionRegistry } from 'rawsql-ts';
|
|
3
|
+
export type { TableDefinitionModel } from 'rawsql-ts';
|
|
4
|
+
import type { TableRowsFixture } from '@rawsql-ts/testkit-core';
|
|
5
|
+
import type { DdlFixtureLoaderOptions } from '@rawsql-ts/testkit-core';
|
|
6
|
+
interface SchemaResolutionOptions {
|
|
7
|
+
defaultSchema?: string;
|
|
8
|
+
searchPath?: string[];
|
|
9
|
+
}
|
|
10
|
+
/** Rows-only fixtures authored by pg-testkit consumers. */
|
|
11
|
+
export type PgTableRowsFixture = TableRowsFixture;
|
|
12
|
+
/** Table definitions shared across testkits and derived from DDL. */
|
|
13
|
+
export type PgTableDefinition = TableDefinitionModel;
|
|
14
|
+
/** Snapshot returned after fixture resolution, containing the tables, resolver-generated registry, and the applied fixture names. */
|
|
15
|
+
export interface PgFixtureSnapshot {
|
|
16
|
+
fixtureTables: FixtureTableDefinition[];
|
|
17
|
+
tableDefinitions: TableDefinitionRegistry;
|
|
18
|
+
fixturesApplied: string[];
|
|
19
|
+
}
|
|
20
|
+
/** Resolves fixture overrides and exposes the most recently applied snapshot. */
|
|
21
|
+
export interface PgFixtureProvider {
|
|
22
|
+
resolve(overrides?: TableRowsFixture[]): PgFixtureSnapshot;
|
|
23
|
+
}
|
|
24
|
+
/** Input accepted by driver query helpers (raw SQL or pg `QueryConfig`). */
|
|
25
|
+
export type PgQueryInput = string | QueryConfig<unknown[]>;
|
|
26
|
+
/** Represents a Postgres client that can execute queries during testing. */
|
|
27
|
+
export interface PgQueryable {
|
|
28
|
+
query<T extends QueryResultRow = QueryResultRow>(queryTextOrConfig: PgQueryInput, values?: unknown[]): Promise<QueryResult<T>>;
|
|
29
|
+
end?(): Promise<void> | void;
|
|
30
|
+
release?(): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Options accepted when creating a PgTestkit client, including the
|
|
34
|
+
* connection factory and fixture resolution hooks.
|
|
35
|
+
*/
|
|
36
|
+
export interface CreatePgTestkitClientOptions extends SchemaResolutionOptions {
|
|
37
|
+
connectionFactory: () => PgQueryable | Promise<PgQueryable>;
|
|
38
|
+
tableDefinitions?: TableDefinitionModel[];
|
|
39
|
+
tableRows?: TableRowsFixture[];
|
|
40
|
+
formatterOptions?: SqlFormatterOptions;
|
|
41
|
+
missingFixtureStrategy?: MissingFixtureStrategy;
|
|
42
|
+
onExecute?(sql: string, params?: unknown[] | QueryConfig['values'], fixtures?: string[]): void;
|
|
43
|
+
/** Directories whose SQL files are converted into fixtures automatically. */
|
|
44
|
+
ddl?: DdlFixtureLoaderOptions;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Options accepted when wrapping an existing Postgres client, mirroring
|
|
48
|
+
* creation options but omitting the connection factory.
|
|
49
|
+
*/
|
|
50
|
+
export interface WrapPgClientOptions extends SchemaResolutionOptions {
|
|
51
|
+
tableDefinitions?: TableDefinitionModel[];
|
|
52
|
+
tableRows?: TableRowsFixture[];
|
|
53
|
+
formatterOptions?: SqlFormatterOptions;
|
|
54
|
+
missingFixtureStrategy?: MissingFixtureStrategy;
|
|
55
|
+
onExecute?(sql: string, params?: unknown[] | QueryConfig['values'], fixtures?: string[]): void;
|
|
56
|
+
/** Shared DDL directory configuration used to infer fixtures for wrapped clients. */
|
|
57
|
+
ddl?: DdlFixtureLoaderOptions;
|
|
58
|
+
}
|
|
59
|
+
/** Extends any Pg client instance with fixture-aware helper methods. */
|
|
60
|
+
export type WrappedPgClient<T> = T & {
|
|
61
|
+
withFixtures(fixtures: TableRowsFixture[]): WrappedPgClient<T>;
|
|
62
|
+
};
|
|
63
|
+
export interface CreatePgTestkitPoolOptions extends SchemaResolutionOptions {
|
|
64
|
+
tableDefinitions?: TableDefinitionModel[];
|
|
65
|
+
tableRows?: TableRowsFixture[];
|
|
66
|
+
/** DDL paths that should populate the base fixture set for the pool. */
|
|
67
|
+
ddl?: DdlFixtureLoaderOptions;
|
|
68
|
+
}
|
|
69
|
+
export type { TableRowsFixture } from '@rawsql-ts/testkit-core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../drivers/pg-testkit/src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DdlFixtureLoaderOptions, DdlProcessedFixture, TableRowsFixture } from '@rawsql-ts/testkit-core';
|
|
2
|
+
import type { TableDefinitionModel } from 'rawsql-ts';
|
|
3
|
+
import type { TableNameResolver } from '@rawsql-ts/testkit-core';
|
|
4
|
+
export interface FixtureResolutionOptions {
|
|
5
|
+
tableDefinitions?: TableDefinitionModel[];
|
|
6
|
+
tableRows?: TableRowsFixture[];
|
|
7
|
+
ddl?: DdlFixtureLoaderOptions;
|
|
8
|
+
}
|
|
9
|
+
export interface ResolvedFixtureState {
|
|
10
|
+
ddlFixtures: DdlProcessedFixture[];
|
|
11
|
+
tableDefinitions: TableDefinitionModel[];
|
|
12
|
+
tableRows: TableRowsFixture[];
|
|
13
|
+
}
|
|
14
|
+
/** Produces the merged fixture metadata for any pg-testkit entry point. */
|
|
15
|
+
export declare function resolveFixtureState(options: FixtureResolutionOptions, tableNameResolver: TableNameResolver): ResolvedFixtureState;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveFixtureState = resolveFixtureState;
|
|
4
|
+
const testkit_core_1 = require("@rawsql-ts/testkit-core");
|
|
5
|
+
/** Produces the merged fixture metadata for any pg-testkit entry point. */
|
|
6
|
+
function resolveFixtureState(options, tableNameResolver) {
|
|
7
|
+
var _a, _b, _c, _d, _e;
|
|
8
|
+
// Load DDL-derived fixtures when directories were supplied so every consumer shares the same resolver rules.
|
|
9
|
+
const loader = ((_b = (_a = options.ddl) === null || _a === void 0 ? void 0 : _a.directories) === null || _b === void 0 ? void 0 : _b.length)
|
|
10
|
+
? new testkit_core_1.DdlFixtureLoader({
|
|
11
|
+
...options.ddl,
|
|
12
|
+
tableNameResolver,
|
|
13
|
+
})
|
|
14
|
+
: undefined;
|
|
15
|
+
const ddlFixtures = (_c = loader === null || loader === void 0 ? void 0 : loader.getFixtures()) !== null && _c !== void 0 ? _c : [];
|
|
16
|
+
// Combine generated definitions with any explicit metadata the caller provided.
|
|
17
|
+
const tableDefinitions = [
|
|
18
|
+
...ddlFixtures.map((fixture) => fixture.tableDefinition),
|
|
19
|
+
...((_d = options.tableDefinitions) !== null && _d !== void 0 ? _d : []),
|
|
20
|
+
];
|
|
21
|
+
// Merge DDL-sourced rows ahead of caller-supplied fixtures so overrides take precedence.
|
|
22
|
+
const tableRows = [
|
|
23
|
+
...ddlFixtures.flatMap((fixture) => fixture.rows && fixture.rows.length
|
|
24
|
+
? [{ tableName: fixture.tableDefinition.name, rows: fixture.rows }]
|
|
25
|
+
: []),
|
|
26
|
+
...((_e = options.tableRows) !== null && _e !== void 0 ? _e : []),
|
|
27
|
+
];
|
|
28
|
+
return {
|
|
29
|
+
ddlFixtures,
|
|
30
|
+
tableDefinitions,
|
|
31
|
+
tableRows,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=fixtureState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtureState.js","sourceRoot":"","sources":["../../../../../../../drivers/pg-testkit/src/utils/fixtureState.ts"],"names":[],"mappings":";;AAkBA,kDAkCC;AAnDD,0DAA2D;AAgB3D,2EAA2E;AAC3E,SAAgB,mBAAmB,CACjC,OAAiC,EACjC,iBAAoC;;IAEpC,6GAA6G;IAC7G,MAAM,MAAM,GAAG,CAAA,MAAA,MAAA,OAAO,CAAC,GAAG,0CAAE,WAAW,0CAAE,MAAM;QAC7C,CAAC,CAAC,IAAI,+BAAgB,CAAC;YACnB,GAAG,OAAO,CAAC,GAAG;YACd,iBAAiB;SAClB,CAAC;QACJ,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,WAAW,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,EAAE,mCAAI,EAAE,CAAC;IAEhD,gFAAgF;IAChF,MAAM,gBAAgB,GAAG;QACvB,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,OAA4B,EAAE,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC;QAC7E,GAAG,CAAC,MAAA,OAAO,CAAC,gBAAgB,mCAAI,EAAE,CAAC;KACpC,CAAC;IAEF,yFAAyF;IACzF,MAAM,SAAS,GAAuB;QACpC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,OAA4B,EAAE,EAAE,CACtD,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM;YACjC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;YACnE,CAAC,CAAC,EAAE,CACP;QACD,GAAG,CAAC,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAC;KAC7B,CAAC;IAEF,OAAO;QACL,WAAW;QACX,gBAAgB;QAChB,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TableDefinitionModel, TableRowsFixture } from '../types';
|
|
2
|
+
import type { TableNameResolver } from '@rawsql-ts/testkit-core';
|
|
3
|
+
/**
|
|
4
|
+
* Validates fixture rows against table definitions, ensuring every referenced
|
|
5
|
+
* table and column exists in the configured DDL or explicit definitions.
|
|
6
|
+
*
|
|
7
|
+
* @param tableRows - Fixtures to validate; undefined or empty arrays are no-ops.
|
|
8
|
+
* @param tableDefinitions - Table metadata to validate against.
|
|
9
|
+
* @param contextLabel - Optional label prefixed to thrown error messages for clarity.
|
|
10
|
+
* @throws Error when a fixture references a missing table or column.
|
|
11
|
+
*/
|
|
12
|
+
export declare const validateFixtureRowsAgainstTableDefinitions: (tableRows: TableRowsFixture[] | undefined, tableDefinitions: TableDefinitionModel[], contextLabel?: string, tableNameResolver?: TableNameResolver) => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateFixtureRowsAgainstTableDefinitions = void 0;
|
|
4
|
+
const rawsql_ts_1 = require("rawsql-ts");
|
|
5
|
+
const normalizeColumnName = (value) => value.toLowerCase();
|
|
6
|
+
/**
|
|
7
|
+
* Validates fixture rows against table definitions, ensuring every referenced
|
|
8
|
+
* table and column exists in the configured DDL or explicit definitions.
|
|
9
|
+
*
|
|
10
|
+
* @param tableRows - Fixtures to validate; undefined or empty arrays are no-ops.
|
|
11
|
+
* @param tableDefinitions - Table metadata to validate against.
|
|
12
|
+
* @param contextLabel - Optional label prefixed to thrown error messages for clarity.
|
|
13
|
+
* @throws Error when a fixture references a missing table or column.
|
|
14
|
+
*/
|
|
15
|
+
const validateFixtureRowsAgainstTableDefinitions = (tableRows, tableDefinitions, contextLabel, tableNameResolver) => {
|
|
16
|
+
var _a;
|
|
17
|
+
if (!(tableRows === null || tableRows === void 0 ? void 0 : tableRows.length)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const prefix = contextLabel ? `${contextLabel}: ` : '';
|
|
21
|
+
// Build a lookup keyed by resolved table names so definitions can be resolved quickly.
|
|
22
|
+
const definitionLookup = new Map();
|
|
23
|
+
for (const definition of tableDefinitions) {
|
|
24
|
+
const key = (_a = tableNameResolver === null || tableNameResolver === void 0 ? void 0 : tableNameResolver.resolve(definition.name)) !== null && _a !== void 0 ? _a : (0, rawsql_ts_1.normalizeTableName)(definition.name);
|
|
25
|
+
definitionLookup.set(key, definition);
|
|
26
|
+
}
|
|
27
|
+
const columnCache = new Map();
|
|
28
|
+
for (const fixture of tableRows) {
|
|
29
|
+
const resolvedTableName = tableNameResolver
|
|
30
|
+
? tableNameResolver.resolve(fixture.tableName, (candidate) => definitionLookup.has(candidate))
|
|
31
|
+
: (0, rawsql_ts_1.normalizeTableName)(fixture.tableName);
|
|
32
|
+
const tableDefinition = definitionLookup.get(resolvedTableName);
|
|
33
|
+
if (!tableDefinition) {
|
|
34
|
+
throw new Error(`${prefix}Table '${fixture.tableName}' is not defined by the configured DDL or explicit table definitions.`);
|
|
35
|
+
}
|
|
36
|
+
// Memoize column metadata for each resolved table to avoid repeated work.
|
|
37
|
+
let columnNames = columnCache.get(resolvedTableName);
|
|
38
|
+
if (!columnNames) {
|
|
39
|
+
columnNames = new Set(tableDefinition.columns.map((column) => normalizeColumnName(column.name)));
|
|
40
|
+
columnCache.set(resolvedTableName, columnNames);
|
|
41
|
+
}
|
|
42
|
+
// Validate each row so mistyped columns surface immediately during setup.
|
|
43
|
+
for (const row of fixture.rows) {
|
|
44
|
+
for (const column of Object.keys(row)) {
|
|
45
|
+
if (!columnNames.has(normalizeColumnName(column))) {
|
|
46
|
+
throw new Error(`${prefix}Column '${column}' not found in table '${fixture.tableName}'. Please fix the fixture to match the DDL.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.validateFixtureRowsAgainstTableDefinitions = validateFixtureRowsAgainstTableDefinitions;
|
|
53
|
+
//# sourceMappingURL=fixtureValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtureValidation.js","sourceRoot":"","sources":["../../../../../../../drivers/pg-testkit/src/utils/fixtureValidation.ts"],"names":[],"mappings":";;;AAAA,yCAA+C;AAI/C,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;AAE3E;;;;;;;;GAQG;AACI,MAAM,0CAA0C,GAAG,CACxD,SAAyC,EACzC,gBAAwC,EACxC,YAAqB,EACrB,iBAAqC,EAC/B,EAAE;;IACR,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,MAAM,CAAA,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAEvD,uFAAuF;IACvF,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAgC,CAAC;IACjE,KAAK,MAAM,UAAU,IAAI,gBAAgB,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,MAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,mCAAI,IAAA,8BAAkB,EAAC,UA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CAAC,EAAE,CAAC;oBAClD,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,WAAW,MAAM,yBAAyB,OAAO,CAAC,SAAS,6CAA6C,CAClH,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAlDW,QAAA,0CAA0C,8CAkDrD"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single database row returned by a SQL driver.
|
|
3
|
+
* Row keys are SQL column names, which must be strings; symbol keys are not supported.
|
|
4
|
+
*/
|
|
5
|
+
export type Row = Record<string, unknown>;
|
|
6
|
+
/**
|
|
7
|
+
* Executes SQL and returns the resulting rows.
|
|
8
|
+
*
|
|
9
|
+
* The mapper keeps this layer DBMS/driver agnostic; callers inject the concrete
|
|
10
|
+
* executor that speaks to the desired database.
|
|
11
|
+
*/
|
|
12
|
+
export type QueryExecutor = (sql: string, params: unknown[]) => Promise<Row[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Defines how a column prefix, key, and optional overrides map to an entity.
|
|
15
|
+
*/
|
|
16
|
+
export interface EntityOptions<T, K extends Extract<keyof T, string>> {
|
|
17
|
+
name: string;
|
|
18
|
+
key: K;
|
|
19
|
+
prefix?: string;
|
|
20
|
+
columnMap?: Partial<Record<Extract<keyof T, string>, string>>;
|
|
21
|
+
coerce?: boolean;
|
|
22
|
+
coerceFn?: (value: unknown) => unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Describes how a child entity references a parent mapping.
|
|
26
|
+
*/
|
|
27
|
+
export interface BelongsToOptions {
|
|
28
|
+
optional?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Controls how raw column names are normalized for simple mapping.
|
|
32
|
+
*/
|
|
33
|
+
export type KeyTransform = 'snake_to_camel' | 'none' | ((column: string) => string);
|
|
34
|
+
/**
|
|
35
|
+
* Supported type hints for `mapSimpleRows`, controlling how primitive values are coerced before identifier normalization.
|
|
36
|
+
*/
|
|
37
|
+
export type SimpleMapTypeHint = 'string' | 'number' | 'boolean' | 'date' | 'bigint';
|
|
38
|
+
/**
|
|
39
|
+
* Options that influence simple (duck-typed) row mapping.
|
|
40
|
+
*/
|
|
41
|
+
export interface SimpleMapOptions {
|
|
42
|
+
keyTransform?: KeyTransform;
|
|
43
|
+
idKeysAsString?: boolean;
|
|
44
|
+
typeHints?: Record<string, SimpleMapTypeHint>;
|
|
45
|
+
coerceDates?: boolean;
|
|
46
|
+
coerceFn?: (args: {
|
|
47
|
+
key: string;
|
|
48
|
+
sourceKey: string;
|
|
49
|
+
value: unknown;
|
|
50
|
+
}) => unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Named presets for simple mapping that avoid implicit inference.
|
|
54
|
+
*/
|
|
55
|
+
export declare const simpleMapPresets: {
|
|
56
|
+
safe(): SimpleMapOptions;
|
|
57
|
+
pgLike(): SimpleMapOptions;
|
|
58
|
+
};
|
|
59
|
+
type ParentLink<T> = {
|
|
60
|
+
propertyName: string;
|
|
61
|
+
parent: EntityMapping<any>;
|
|
62
|
+
localKey: string;
|
|
63
|
+
optional: boolean;
|
|
64
|
+
};
|
|
65
|
+
type RowContext = {
|
|
66
|
+
row: Row;
|
|
67
|
+
normalizedColumns: Map<string, string>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Builds an entity mapping that can be consumed by {@link Mapper#query} or {@link mapRows}.
|
|
71
|
+
*/
|
|
72
|
+
export declare class EntityMapping<T, K extends Extract<keyof T, string> = Extract<keyof T, string>> {
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly key: K;
|
|
75
|
+
readonly prefix: string;
|
|
76
|
+
readonly parents: ParentLink<T>[];
|
|
77
|
+
private readonly columnMap;
|
|
78
|
+
private readonly overrideLookup;
|
|
79
|
+
private readonly prefixNormalized;
|
|
80
|
+
private readonly prefixLength;
|
|
81
|
+
private readonly shouldCoerce;
|
|
82
|
+
private readonly coerceFn;
|
|
83
|
+
constructor(options: EntityOptions<T, K>);
|
|
84
|
+
/**
|
|
85
|
+
* Registers a parent relationship that will be attached after the current row is mapped.
|
|
86
|
+
*/
|
|
87
|
+
belongsTo<P, PK extends Extract<keyof P, string>>(propertyName: Extract<keyof T, string>, parent: EntityMapping<P, PK>, localKey: Extract<keyof T, string>, options?: BelongsToOptions): this;
|
|
88
|
+
/**
|
|
89
|
+
* Registers a parent relationship with an explicit local key.
|
|
90
|
+
*/
|
|
91
|
+
belongsToWithLocalKey<P, PK extends Extract<keyof P, string>>(propertyName: Extract<keyof T, string>, parent: EntityMapping<P, PK>, localKey: Extract<keyof T, string>): this;
|
|
92
|
+
/**
|
|
93
|
+
* Registers an optional parent relationship with an explicit local key.
|
|
94
|
+
*/
|
|
95
|
+
belongsToOptional<P, PK extends Extract<keyof P, string>>(propertyName: Extract<keyof T, string>, parent: EntityMapping<P, PK>, localKey?: Extract<keyof T, string>): this;
|
|
96
|
+
matchColumn(columnName: string): string | undefined;
|
|
97
|
+
resolveColumnName(propertyName: string): string;
|
|
98
|
+
readKeyValue(ctx: RowContext): unknown;
|
|
99
|
+
assignFields(target: Record<string, unknown>, ctx: RowContext): void;
|
|
100
|
+
private normalizeColumnValue;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new entity mapping from the provided options.
|
|
104
|
+
*/
|
|
105
|
+
export declare function entity<T, K extends Extract<keyof T, string> = Extract<keyof T, string>>(options: EntityOptions<T, K>): EntityMapping<T, K>;
|
|
106
|
+
/**
|
|
107
|
+
* Builds a column map by prefixing each property with the provided prefix and
|
|
108
|
+
* converting property names to snake_case.
|
|
109
|
+
*/
|
|
110
|
+
export declare function columnMapFromPrefix<K extends string>(prefix: string, properties: readonly K[]): Record<K, string>;
|
|
111
|
+
/**
|
|
112
|
+
* Executes SQL via the provided executor and maps the rows using the supplied mapping.
|
|
113
|
+
*/
|
|
114
|
+
export declare class Mapper {
|
|
115
|
+
private readonly executor;
|
|
116
|
+
private readonly defaults;
|
|
117
|
+
constructor(executor: QueryExecutor, defaults?: SimpleMapOptions | undefined);
|
|
118
|
+
query<T>(sql: string, params: unknown[], mapping: EntityMapping<T>): Promise<T[]>;
|
|
119
|
+
query<T>(sql: string, params?: unknown[], options?: SimpleMapOptions): Promise<T[]>;
|
|
120
|
+
queryOne<T>(sql: string, params: unknown[], mapping: EntityMapping<T>): Promise<T | undefined>;
|
|
121
|
+
queryOne<T>(sql: string, params?: unknown[], options?: SimpleMapOptions): Promise<T | undefined>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* This package maps rows and does not manage DB drivers.
|
|
125
|
+
* Inject a query executor rather than wiring connections inside the mapper.
|
|
126
|
+
*/
|
|
127
|
+
export declare function createMapper(executor: QueryExecutor, defaults?: SimpleMapOptions): Mapper;
|
|
128
|
+
/**
|
|
129
|
+
* Creates a mapper using the supplied executor and user defaults.
|
|
130
|
+
* This helper is the recommended entry point when wiring an executor because
|
|
131
|
+
* it clearly signals where defaults are configured.
|
|
132
|
+
*/
|
|
133
|
+
export declare function createMapperFromExecutor(executor: QueryExecutor, defaults?: SimpleMapOptions): Mapper;
|
|
134
|
+
/**
|
|
135
|
+
* Normalizes an executor returning `{ rows }` so it can be consumed by the mapper.
|
|
136
|
+
*/
|
|
137
|
+
export declare function toRowsExecutor(executorOrTarget: ((sql: string, params: unknown[]) => Promise<{
|
|
138
|
+
rows: Row[];
|
|
139
|
+
} | {
|
|
140
|
+
rows: Row[];
|
|
141
|
+
rowCount?: number;
|
|
142
|
+
} | Row[]>) | {
|
|
143
|
+
[key: string]: (...args: unknown[]) => Promise<unknown>;
|
|
144
|
+
}, methodName?: string): QueryExecutor;
|
|
145
|
+
/**
|
|
146
|
+
* Maps a pre-fetched row array into typed objects defined by an entity mapping.
|
|
147
|
+
* Row values remain `unknown`, and the mapper only applies the general-purpose
|
|
148
|
+
* coercion rules declared in `coerceColumnValue`.
|
|
149
|
+
*/
|
|
150
|
+
export declare function mapRows<T>(rows: Row[], mapping: EntityMapping<T>): T[];
|
|
151
|
+
/**
|
|
152
|
+
* Maps pre-fetched rows into typed DTOs using the simple map preset, honoring key transforms, type hints, and optional coercion settings.
|
|
153
|
+
*
|
|
154
|
+
* @template T Target DTO shape.
|
|
155
|
+
* @param rows Rows produced by the SQL executor.
|
|
156
|
+
* @param options Optional overrides that control key normalization, coercion, and type hints.
|
|
157
|
+
* @returns An array of `T` instances synthesized from `rows`.
|
|
158
|
+
*/
|
|
159
|
+
export declare function mapSimpleRows<T>(rows: Row[], options?: SimpleMapOptions): T[];
|
|
160
|
+
export {};
|