@rawsql-ts/ztd-cli 0.14.4 → 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 +25 -11
- package/dist/commands/init.js +27 -10
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.d.ts +59 -0
- package/dist/commands/lint.js +338 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/sqlLintHelpers.d.ts +18 -0
- package/dist/utils/sqlLintHelpers.js +270 -0
- package/dist/utils/sqlLintHelpers.js.map +1 -0
- package/package.json +11 -4
- package/templates/AGENTS.md +95 -53
- 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 +59 -6
- 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,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remove = exports.update = exports.insert = void 0;
|
|
4
|
+
const identifierPattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
5
|
+
const identifierControlPattern = /[\u0000-\u001F\u007F]/;
|
|
6
|
+
const assertIdentifierBasics = (identifier, kind) => {
|
|
7
|
+
if (identifier.length === 0) {
|
|
8
|
+
throw new Error(`${kind} identifier must not be empty`);
|
|
9
|
+
}
|
|
10
|
+
if (identifierControlPattern.test(identifier)) {
|
|
11
|
+
throw new Error(`identifier "${identifier}" must not contain control characters`);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const assertColumnIdentifier = (identifier, allowUnsafe) => {
|
|
15
|
+
assertIdentifierBasics(identifier, 'column');
|
|
16
|
+
if (!allowUnsafe && !identifierPattern.test(identifier)) {
|
|
17
|
+
throw new Error(`column identifier "${identifier}" must match ${identifierPattern}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const assertTableIdentifier = (identifier, allowUnsafe) => {
|
|
21
|
+
assertIdentifierBasics(identifier, 'table');
|
|
22
|
+
if (!allowUnsafe && !identifierPattern.test(identifier)) {
|
|
23
|
+
throw new Error(`table identifier "${identifier}" must match ${identifierPattern}`);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const hasParamValueEntry = (entry) => entry[1] !== undefined;
|
|
27
|
+
const ensureEntries = (entries, kind) => {
|
|
28
|
+
if (entries.length === 0) {
|
|
29
|
+
throw new Error(kind === 'insert' ? 'insert values must not be empty' : 'update values must not be empty');
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const formatPlaceholder = (index) => `$${index}`;
|
|
33
|
+
const buildPlaceholders = (count, startIndex = 1) => Array.from({ length: count }, (_, index) => formatPlaceholder(startIndex + index));
|
|
34
|
+
const buildWhereClause = (key, startIndex, options) => {
|
|
35
|
+
const entries = Object.entries(key);
|
|
36
|
+
if (entries.length === 0) {
|
|
37
|
+
throw new Error('where must not be empty');
|
|
38
|
+
}
|
|
39
|
+
const params = [];
|
|
40
|
+
const clauses = entries.map(([column, value], index) => {
|
|
41
|
+
assertColumnIdentifier(column, options === null || options === void 0 ? void 0 : options.allowUnsafeIdentifiers);
|
|
42
|
+
if (value === undefined) {
|
|
43
|
+
throw new Error('key values must not be undefined');
|
|
44
|
+
}
|
|
45
|
+
params.push(value);
|
|
46
|
+
return `${column} = ${formatPlaceholder(startIndex + index)}`;
|
|
47
|
+
});
|
|
48
|
+
// Build a flat AND list of equality checks with placeholders offset by the caller.
|
|
49
|
+
return {
|
|
50
|
+
clause: `WHERE ${clauses.join(' AND ')}`,
|
|
51
|
+
params,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Build an INSERT statement that keeps SQL visible and drops undefined fields.
|
|
56
|
+
* @param options – Pass `allowUnsafeIdentifiers` when you knowingly use Unicode names.
|
|
57
|
+
*/
|
|
58
|
+
const insert = (table, values, options) => {
|
|
59
|
+
const allowUnsafe = (options === null || options === void 0 ? void 0 : options.allowUnsafeIdentifiers) === true;
|
|
60
|
+
assertTableIdentifier(table, allowUnsafe);
|
|
61
|
+
const entries = Object.entries(values).filter(hasParamValueEntry);
|
|
62
|
+
ensureEntries(entries, 'insert');
|
|
63
|
+
const columns = [];
|
|
64
|
+
const params = [];
|
|
65
|
+
for (const [column, value] of entries) {
|
|
66
|
+
assertColumnIdentifier(column, allowUnsafe);
|
|
67
|
+
columns.push(column);
|
|
68
|
+
params.push(value);
|
|
69
|
+
}
|
|
70
|
+
const columnsList = columns.join(', ');
|
|
71
|
+
const placeholders = buildPlaceholders(params.length).join(', ');
|
|
72
|
+
return {
|
|
73
|
+
sql: `INSERT INTO ${table} (${columnsList}) VALUES (${placeholders})`,
|
|
74
|
+
params,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.insert = insert;
|
|
78
|
+
/**
|
|
79
|
+
* Build an UPDATE statement that reuses parameterized placeholders and guards empty sets.
|
|
80
|
+
* @param options – Pass `allowUnsafeIdentifiers` when you knowingly use Unicode names.
|
|
81
|
+
*/
|
|
82
|
+
const update = (table, values, where, options) => {
|
|
83
|
+
const allowUnsafe = (options === null || options === void 0 ? void 0 : options.allowUnsafeIdentifiers) === true;
|
|
84
|
+
assertTableIdentifier(table, allowUnsafe);
|
|
85
|
+
const entries = Object.entries(values).filter(hasParamValueEntry);
|
|
86
|
+
ensureEntries(entries, 'update');
|
|
87
|
+
const params = [];
|
|
88
|
+
const clauses = entries.map(([column, value]) => {
|
|
89
|
+
assertColumnIdentifier(column, allowUnsafe);
|
|
90
|
+
params.push(value);
|
|
91
|
+
return `${column} = ${formatPlaceholder(params.length)}`;
|
|
92
|
+
});
|
|
93
|
+
// Offset WHERE placeholders so they follow the SET parameters.
|
|
94
|
+
const whereClause = buildWhereClause(where, params.length + 1, options);
|
|
95
|
+
return {
|
|
96
|
+
sql: `UPDATE ${table} SET ${clauses.join(', ')} ${whereClause.clause}`,
|
|
97
|
+
params: [...params, ...whereClause.params],
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
exports.update = update;
|
|
101
|
+
/**
|
|
102
|
+
* Build a DELETE statement that only emits equality-only WHERE clauses.
|
|
103
|
+
* @param options – Pass `allowUnsafeIdentifiers` when you knowingly use Unicode names.
|
|
104
|
+
*/
|
|
105
|
+
const remove = (table, where, options) => {
|
|
106
|
+
const allowUnsafe = (options === null || options === void 0 ? void 0 : options.allowUnsafeIdentifiers) === true;
|
|
107
|
+
assertTableIdentifier(table, allowUnsafe);
|
|
108
|
+
const whereClause = buildWhereClause(where, 1, options);
|
|
109
|
+
return {
|
|
110
|
+
sql: `DELETE FROM ${table} ${whereClause.clause}`,
|
|
111
|
+
params: [...whereClause.params],
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
exports.remove = remove;
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../writer-core/src/index.ts"],"names":[],"mappings":";;;AAeA,MAAM,iBAAiB,GAAG,0BAA0B,CAAA;AACpD,MAAM,wBAAwB,GAAG,uBAAuB,CAAA;AAOxD,MAAM,sBAAsB,GAAG,CAAC,UAAkB,EAAE,IAAwB,EAAE,EAAE;IAC9E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,+BAA+B,CAAC,CAAA;IACzD,CAAC;IAED,IAAI,wBAAwB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,uCAAuC,CAAC,CAAA;IACnF,CAAC;AACH,CAAC,CAAA;AAED,MAAM,sBAAsB,GAAG,CAAC,UAAkB,EAAE,WAAqB,EAAE,EAAE;IAC3E,sBAAsB,CAAC,UAAU,EAA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K,CAAC,CAAA;QAClB,OAAO,GAAG,MAAM,MAAM,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAA;IAC1D,CAAC,CAAC,CAAA;IACF,+DAA+D;IAC/D,MAAM,WAAW,GAAG,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,OAAO,CAAC,CAAA;IAEvE,OAAO;QACL,GAAG,EAAE,UAAU,KAAK,QAAQ,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE;QACtE,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC;KAC3C,CAAA;AACH,CAAC,CAAA;AAxBY,QAAA,MAAM,UAwBlB;AAED;;;GAGG;AACI,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,KAAU,EAAE,OAA2B,EAAE,EAAE;IAC/E,MAAM,WAAW,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,sBAAsB,MAAK,IAAI,CAAA;IAC5D,qBAAqB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IACzC,MAAM,WAAW,GAAG,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,CAAA;IAEvD,OAAO;QACL,GAAG,EAAE,eAAe,KAAK,IAAI,WAAW,CAAC,MAAM,EAAE;QACjD,MAAM,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC;KAChC,CAAA;AACH,CAAC,CAAA;AATY,QAAA,MAAM,UASlB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promise that resolves to the array of rows produced by an SQL query.
|
|
3
|
+
* @template T Shape of each row yielded by the SQL client.
|
|
4
|
+
* @example
|
|
5
|
+
* const rows: SqlQueryRows<{ id: number; name: string }> = client.query('SELECT id, name FROM users');
|
|
6
|
+
*/
|
|
7
|
+
export type SqlQueryRows<T> = Promise<T[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Minimal SQL client interface required by the repository layer.
|
|
10
|
+
*
|
|
11
|
+
* - Production: adapt `pg` (or other drivers) to normalize results into `T[]`
|
|
12
|
+
* - Tests: compatible with `pg-testkit` clients returned by `createTestkitClient()`
|
|
13
|
+
*
|
|
14
|
+
* Connection strategy note:
|
|
15
|
+
* - Prefer a shared client per worker process for performance.
|
|
16
|
+
* - Do not share a live client across parallel workers.
|
|
17
|
+
*/
|
|
18
|
+
export type SqlClient = {
|
|
19
|
+
query<T extends Record<string, unknown> = Record<string, unknown>>(text: string, values?: readonly unknown[]): SqlQueryRows<T>;
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-client.js","sourceRoot":"","sources":["../../../../../src/db/sql-client.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SqlClient } from '../db/sql-client';
|
|
2
|
+
import { insert, Key, remove, update } from '@rawsql-ts/writer-core';
|
|
3
|
+
type UserProfileRow = {
|
|
4
|
+
profileId: number;
|
|
5
|
+
userAccountId: number;
|
|
6
|
+
bio: string | null;
|
|
7
|
+
website: string | null;
|
|
8
|
+
verified: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type UserAccountWithProfile = {
|
|
11
|
+
userAccountId: number;
|
|
12
|
+
username: string;
|
|
13
|
+
email: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
updatedAt: Date;
|
|
17
|
+
profile?: UserProfileRow;
|
|
18
|
+
};
|
|
19
|
+
export declare function listUserProfiles(client: SqlClient): Promise<UserAccountWithProfile[]>;
|
|
20
|
+
export type NewUserAccount = {
|
|
21
|
+
username: string;
|
|
22
|
+
email: string;
|
|
23
|
+
displayName: string;
|
|
24
|
+
};
|
|
25
|
+
export type DisplayNameUpdatePayload = {
|
|
26
|
+
displayName: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function buildInsertUserAccount(input: NewUserAccount): ReturnType<typeof insert>;
|
|
29
|
+
export declare function buildUpdateDisplayName(key: Key, payload: DisplayNameUpdatePayload): ReturnType<typeof update>;
|
|
30
|
+
export declare function buildRemoveUserAccount(key: Key): ReturnType<typeof remove>;
|
|
31
|
+
export declare const userAccountWriterColumnSets: {
|
|
32
|
+
insertColumns: readonly ["username", "email", "display_name"];
|
|
33
|
+
updateColumns: readonly ["display_name", "updated_at"];
|
|
34
|
+
immutableColumns: readonly ["user_account_id", "created_at"];
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.userAccountWriterColumnSets = void 0;
|
|
4
|
+
exports.listUserProfiles = listUserProfiles;
|
|
5
|
+
exports.buildInsertUserAccount = buildInsertUserAccount;
|
|
6
|
+
exports.buildUpdateDisplayName = buildUpdateDisplayName;
|
|
7
|
+
exports.buildRemoveUserAccount = buildRemoveUserAccount;
|
|
8
|
+
const mapper_core_1 = require("@rawsql-ts/mapper-core");
|
|
9
|
+
const writer_core_1 = require("@rawsql-ts/writer-core");
|
|
10
|
+
const userAccountTable = 'public.user_account';
|
|
11
|
+
// Map the joined profile columns so we can hydrate nested objects later.
|
|
12
|
+
const profileMapping = (0, mapper_core_1.entity)({
|
|
13
|
+
name: 'userProfile',
|
|
14
|
+
key: 'profileId',
|
|
15
|
+
columnMap: {
|
|
16
|
+
profileId: 'profile_id',
|
|
17
|
+
userAccountId: 'profile_user_account_id',
|
|
18
|
+
bio: 'bio',
|
|
19
|
+
website: 'website',
|
|
20
|
+
verified: 'verified',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
const userAccountMapping = (0, mapper_core_1.entity)({
|
|
24
|
+
name: 'userAccount',
|
|
25
|
+
key: 'userAccountId',
|
|
26
|
+
columnMap: {
|
|
27
|
+
userAccountId: 'user_account_id',
|
|
28
|
+
username: 'username',
|
|
29
|
+
email: 'email',
|
|
30
|
+
displayName: 'display_name',
|
|
31
|
+
createdAt: 'created_at',
|
|
32
|
+
updatedAt: 'updated_at',
|
|
33
|
+
},
|
|
34
|
+
}).belongsTo('profile', profileMapping, 'userAccountId', { optional: true });
|
|
35
|
+
const userProfilesSql = `
|
|
36
|
+
SELECT
|
|
37
|
+
u.user_account_id,
|
|
38
|
+
u.username,
|
|
39
|
+
u.email,
|
|
40
|
+
u.display_name,
|
|
41
|
+
u.created_at,
|
|
42
|
+
u.updated_at,
|
|
43
|
+
p.profile_id,
|
|
44
|
+
p.user_account_id AS profile_user_account_id,
|
|
45
|
+
p.bio,
|
|
46
|
+
p.website,
|
|
47
|
+
p.verified
|
|
48
|
+
FROM public.user_account u
|
|
49
|
+
LEFT JOIN public.user_profile p ON p.user_account_id = u.user_account_id
|
|
50
|
+
ORDER BY u.user_account_id, p.profile_id;
|
|
51
|
+
`;
|
|
52
|
+
// Build a mapper that can translate snake_case columns into camelCase DTOs.
|
|
53
|
+
const createMapperForClient = (client) => (0, mapper_core_1.createMapper)((0, mapper_core_1.toRowsExecutor)((sql, params = []) => client.query(sql, params)), {
|
|
54
|
+
keyTransform: 'snake_to_camel',
|
|
55
|
+
coerceDates: true,
|
|
56
|
+
});
|
|
57
|
+
async function listUserProfiles(client) {
|
|
58
|
+
const mapper = createMapperForClient(client);
|
|
59
|
+
return mapper.query(userProfilesSql, [], userAccountMapping);
|
|
60
|
+
}
|
|
61
|
+
// Writer helpers keep SQL+params visible and enforce the minimal CUD surface.
|
|
62
|
+
function buildInsertUserAccount(input) {
|
|
63
|
+
return (0, writer_core_1.insert)(userAccountTable, {
|
|
64
|
+
username: input.username,
|
|
65
|
+
email: input.email,
|
|
66
|
+
display_name: input.displayName,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function buildUpdateDisplayName(key, payload) {
|
|
70
|
+
return (0, writer_core_1.update)(userAccountTable, {
|
|
71
|
+
// Persist the new display name and bump the timestamp along with it.
|
|
72
|
+
display_name: payload.displayName,
|
|
73
|
+
updated_at: new Date(),
|
|
74
|
+
}, key);
|
|
75
|
+
}
|
|
76
|
+
function buildRemoveUserAccount(key) {
|
|
77
|
+
return (0, writer_core_1.remove)(userAccountTable, key);
|
|
78
|
+
}
|
|
79
|
+
// Tests consume these lists to verify writer callers stay within the approved columns.
|
|
80
|
+
exports.userAccountWriterColumnSets = {
|
|
81
|
+
insertColumns: ['username', 'email', 'display_name'],
|
|
82
|
+
updateColumns: ['display_name', 'updated_at'],
|
|
83
|
+
immutableColumns: ['user_account_id', 'created_at'],
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=user-accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-accounts.js","sourceRoot":"","sources":["../../../../../src/repositories/user-accounts.ts"],"names":[],"mappings":";;;AAgFA,4CAKC;AAaD,wDAQC;AAED,wDAaC;AAED,wDAEC;AA5HD,wDAA8E;AAC9E,wDAAqE;AAErE,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAoB/C,yEAAyE;AACzE,MAAM,cAAc,GAAG,IAAA,oBAAM,EAAiB;IAC5C,IAAI,EAAE,aAAa;IACnB,GAAG,EAAE,WAAW;IAChB,SAAS,EAAE;QACT,SAAS,EAAE,YAAY;QACvB,aAAa,EAAE,yBAAyB;QACxC,GAAG,EAAE,KAAK;QACV,OAAO,EAAE,SAAS;QAClB,QAAQ,EAAE,UAAU;KACrB;CACF,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,IAAA,oBAAM,EAAyB;IACxD,IAAI,EAAE,aAAa;IACnB,GAAG,EAAE,eAAe;IACpB,SAAS,EAAE;QACT,aAAa,EAAE,iBAAiB;QAChC,QAAQ,EAAE,UAAU;QACpB,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,cAAc;QAC3B,SAAS,EAAE,YAAY;QACvB,SAAS,EAAE,YAAY;KACxB;CACF,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,cAA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,UAAU,EAAE,OAAO,EAAE,cAAc,CAAU;IAC7D,aAAa,EAAE,CAAC,cAAc,EAAE,YAAY,CAAU;IACtD,gBAAgB,EAAE,CAAC,iBAAiB,EAAE,YAAY,CAAU;CAC7D,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TableFixture, TableSchemaDefinition } from '@rawsql-ts/testkit-core';
|
|
2
|
+
export type TestRowMap = {
|
|
3
|
+
'public.user_account': {
|
|
4
|
+
user_account_id: number;
|
|
5
|
+
username: string;
|
|
6
|
+
email: string;
|
|
7
|
+
display_name: string;
|
|
8
|
+
created_at: string;
|
|
9
|
+
updated_at: string;
|
|
10
|
+
};
|
|
11
|
+
'public.user_profile': {
|
|
12
|
+
profile_id: number;
|
|
13
|
+
user_account_id: number;
|
|
14
|
+
bio: string | null;
|
|
15
|
+
website: string | null;
|
|
16
|
+
verified: boolean;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const tableSchemas: Record<keyof TestRowMap, TableSchemaDefinition>;
|
|
20
|
+
export declare function tableFixture<TableName extends keyof TestRowMap>(tableName: TableName, rows: TestRowMap[TableName][], schema: TableSchemaDefinition): TableFixture;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableSchemas = void 0;
|
|
4
|
+
exports.tableFixture = tableFixture;
|
|
5
|
+
exports.tableSchemas = {
|
|
6
|
+
'public.user_account': {
|
|
7
|
+
columns: {
|
|
8
|
+
user_account_id: 'int',
|
|
9
|
+
username: 'text',
|
|
10
|
+
email: 'text',
|
|
11
|
+
display_name: 'text',
|
|
12
|
+
created_at: 'timestamp',
|
|
13
|
+
updated_at: 'timestamp',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
'public.user_profile': {
|
|
17
|
+
columns: {
|
|
18
|
+
profile_id: 'int',
|
|
19
|
+
user_account_id: 'int',
|
|
20
|
+
bio: 'text',
|
|
21
|
+
website: 'text',
|
|
22
|
+
verified: 'boolean',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
function tableFixture(tableName, rows, schema) {
|
|
27
|
+
return {
|
|
28
|
+
tableName,
|
|
29
|
+
rows,
|
|
30
|
+
schema,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ztd-row-map.generated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ztd-row-map.generated.js","sourceRoot":"","sources":["../../../../../tests/generated/ztd-row-map.generated.ts"],"names":[],"mappings":";;;AA0CA,oCAUC;AAhCY,QAAA,YAAY,GAAoD;IAC3E,qBAAqB,EAAE;QACrB,OAAO,EAAE;YACP,eAAe,EAAE,KAAK;YACtB,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,MAAM;YACb,YAAY,EAAE,MAAM;YACpB,UAAU,EAAE,WAAW;YACvB,UAAU,EAAE,WAAW;SACxB;KACF;IACD,qBAAqB,EAAE;QACrB,OAAO,EAAE;YACP,UAAU,EAAE,KAAK;YACjB,eAAe,EAAE,KAAK;YACtB,GAAG,EAAE,MAAM;YACX,OAAO,EAAE,MAAM;YACf,QAAQ,EAAE,SAAS;SACpB;KACF;CACF,CAAC;AAEF,SAAgB,YAAY,CAC1B,SAAoB,EACpB,IAA6B,EAC7B,MAA6B;IAE7B,OAAO;QACL,SAAS;QACT,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest global setup.
|
|
3
|
+
*
|
|
4
|
+
* ZTD tests are safe to run in parallel against a single Postgres instance because pg-testkit
|
|
5
|
+
* rewrites CRUD into fixture-backed SELECT queries (no physical tables are created/mutated).
|
|
6
|
+
*
|
|
7
|
+
* This setup starts exactly one disposable Postgres container when DATABASE_URL is not provided,
|
|
8
|
+
* and shares the resulting DATABASE_URL with all Vitest workers.
|
|
9
|
+
*/
|
|
10
|
+
export default function globalSetup(): Promise<(() => undefined) | (() => Promise<void>)>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = globalSetup;
|
|
4
|
+
const postgresql_1 = require("@testcontainers/postgresql");
|
|
5
|
+
/**
|
|
6
|
+
* Vitest global setup.
|
|
7
|
+
*
|
|
8
|
+
* ZTD tests are safe to run in parallel against a single Postgres instance because pg-testkit
|
|
9
|
+
* rewrites CRUD into fixture-backed SELECT queries (no physical tables are created/mutated).
|
|
10
|
+
*
|
|
11
|
+
* This setup starts exactly one disposable Postgres container when DATABASE_URL is not provided,
|
|
12
|
+
* and shares the resulting DATABASE_URL with all Vitest workers.
|
|
13
|
+
*/
|
|
14
|
+
async function globalSetup() {
|
|
15
|
+
const configuredUrl = process.env.DATABASE_URL;
|
|
16
|
+
if (configuredUrl && configuredUrl.length > 0) {
|
|
17
|
+
return () => undefined;
|
|
18
|
+
}
|
|
19
|
+
const container = new postgresql_1.PostgreSqlContainer('postgres:18-alpine')
|
|
20
|
+
.withDatabase('ztd_playground')
|
|
21
|
+
.withUsername('postgres')
|
|
22
|
+
.withPassword('postgres');
|
|
23
|
+
const started = await container.start();
|
|
24
|
+
process.env.DATABASE_URL = started.getConnectionUri();
|
|
25
|
+
return async () => {
|
|
26
|
+
await started.stop();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=global-setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-setup.js","sourceRoot":"","sources":["../../../../../tests/support/global-setup.ts"],"names":[],"mappings":";;AAWA,8BAiBC;AA5BD,2DAAiE;AAEjE;;;;;;;;GAQG;AACY,KAAK,UAAU,WAAW;IACvC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IAC/C,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC;IACzB,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,gCAAmB,CAAC,oBAAoB,CAAC;SAC5D,YAAY,CAAC,gBAAgB,CAAC;SAC9B,YAAY,CAAC,UAAU,CAAC;SACxB,YAAY,CAAC,UAAU,CAAC,CAAC;IAE5B,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAEtD,OAAO,KAAK,IAAI,EAAE;QAChB,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { QueryResultRow } from 'pg';
|
|
2
|
+
import type { TableFixture } from '@rawsql-ts/testkit-core';
|
|
3
|
+
type ZtdSqlLogPhase = 'original' | 'rewritten';
|
|
4
|
+
type ZtdSqlLogEvent = {
|
|
5
|
+
kind: 'ztd-sql';
|
|
6
|
+
phase: ZtdSqlLogPhase;
|
|
7
|
+
queryId: number;
|
|
8
|
+
sql: string;
|
|
9
|
+
params?: unknown[];
|
|
10
|
+
fixturesApplied?: string[];
|
|
11
|
+
timestamp: string;
|
|
12
|
+
};
|
|
13
|
+
export type ZtdExecutionMode = 'ztd' | 'traditional';
|
|
14
|
+
export type TraditionalIsolationMode = 'schema' | 'none';
|
|
15
|
+
export type TraditionalCleanupStrategy = 'drop_schema' | 'custom_sql' | 'none';
|
|
16
|
+
export interface TraditionalExecutionConfig {
|
|
17
|
+
isolation?: TraditionalIsolationMode;
|
|
18
|
+
setupSql?: string[];
|
|
19
|
+
cleanup?: TraditionalCleanupStrategy;
|
|
20
|
+
cleanupSql?: string[];
|
|
21
|
+
schemaName?: string;
|
|
22
|
+
}
|
|
23
|
+
export type ZtdSqlLogOptions = {
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
includeParams?: boolean;
|
|
26
|
+
logger?: (event: ZtdSqlLogEvent) => void;
|
|
27
|
+
profile?: ZtdProfileOptions;
|
|
28
|
+
mode?: ZtdExecutionMode;
|
|
29
|
+
traditional?: TraditionalExecutionConfig;
|
|
30
|
+
};
|
|
31
|
+
type ZtdProfilePhase = 'connection' | 'setup' | 'query' | 'teardown';
|
|
32
|
+
type ZtdProfileEvent = {
|
|
33
|
+
kind: 'ztd-profile';
|
|
34
|
+
phase: ZtdProfilePhase;
|
|
35
|
+
testName?: string;
|
|
36
|
+
workerId?: string;
|
|
37
|
+
processId: number;
|
|
38
|
+
executionMode?: 'serial' | 'parallel' | 'unknown';
|
|
39
|
+
connectionReused?: boolean;
|
|
40
|
+
queryId?: number;
|
|
41
|
+
queryCount?: number;
|
|
42
|
+
durationMs?: number;
|
|
43
|
+
totalQueryMs?: number;
|
|
44
|
+
sql?: string;
|
|
45
|
+
params?: unknown[];
|
|
46
|
+
fixturesApplied?: string[];
|
|
47
|
+
sampleSql?: string[];
|
|
48
|
+
timestamp: string;
|
|
49
|
+
};
|
|
50
|
+
export type ZtdProfileOptions = {
|
|
51
|
+
enabled?: boolean;
|
|
52
|
+
perQuery?: boolean;
|
|
53
|
+
includeParams?: boolean;
|
|
54
|
+
includeSql?: boolean;
|
|
55
|
+
sampleLimit?: number;
|
|
56
|
+
testName?: string;
|
|
57
|
+
executionMode?: 'serial' | 'parallel' | 'unknown';
|
|
58
|
+
logger?: (event: ZtdProfileEvent) => void;
|
|
59
|
+
};
|
|
60
|
+
export type ZtdPlaygroundQueryResult<T extends QueryResultRow = QueryResultRow> = Promise<T[]>;
|
|
61
|
+
export type ZtdPlaygroundClient = {
|
|
62
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[]): ZtdPlaygroundQueryResult<T>;
|
|
63
|
+
close(): Promise<void>;
|
|
64
|
+
};
|
|
65
|
+
export declare function createTestkitClient(fixtures: TableFixture[], options?: ZtdSqlLogOptions): Promise<ZtdPlaygroundClient>;
|
|
66
|
+
export {};
|