@hypequery/clickhouse 1.6.2 → 2.0.1
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-CLI.md +43 -88
- package/README.md +84 -253
- package/dist/cli/bin.js +16 -8
- package/dist/core/adapters/clickhouse-adapter.d.ts.map +1 -1
- package/dist/core/adapters/clickhouse-adapter.js +3 -2
- package/dist/core/cache/cache-manager.d.ts.map +1 -1
- package/dist/core/cache/cache-manager.js +5 -3
- package/dist/core/connection.d.ts +6 -6
- package/dist/core/connection.js +9 -9
- package/dist/core/cross-filter.js +1 -1
- package/dist/core/dialects/clickhouse-dialect.d.ts +2 -2
- package/dist/core/dialects/clickhouse-dialect.d.ts.map +1 -1
- package/dist/core/dialects/clickhouse-dialect.js +39 -22
- package/dist/core/dialects/sql-dialect.d.ts +2 -2
- package/dist/core/dialects/sql-dialect.d.ts.map +1 -1
- package/dist/core/env/auto-client.d.ts.map +1 -1
- package/dist/core/env/auto-client.js +1 -1
- package/dist/core/features/aggregations.d.ts +27 -84
- package/dist/core/features/aggregations.d.ts.map +1 -1
- package/dist/core/features/aggregations.js +59 -7
- package/dist/core/features/analytics.d.ts +5 -870
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/features/analytics.js +15 -13
- package/dist/core/features/cross-filtering.d.ts +1 -1
- package/dist/core/features/cross-filtering.d.ts.map +1 -1
- package/dist/core/features/cross-filtering.js +28 -73
- package/dist/core/features/executor.d.ts +1 -1
- package/dist/core/features/executor.d.ts.map +1 -1
- package/dist/core/features/executor.js +9 -11
- package/dist/core/features/filtering.d.ts +5 -91
- package/dist/core/features/filtering.d.ts.map +1 -1
- package/dist/core/features/filtering.js +63 -77
- package/dist/core/features/joins.d.ts +2 -19
- package/dist/core/features/joins.d.ts.map +1 -1
- package/dist/core/features/joins.js +16 -5
- package/dist/core/features/query-modifiers.d.ts +10 -109
- package/dist/core/features/query-modifiers.d.ts.map +1 -1
- package/dist/core/features/query-modifiers.js +64 -18
- package/dist/core/formatters/sql-formatter.d.ts +16 -5
- package/dist/core/formatters/sql-formatter.d.ts.map +1 -1
- package/dist/core/formatters/sql-formatter.js +197 -93
- package/dist/core/join-relationships.d.ts +22 -5
- package/dist/core/join-relationships.d.ts.map +1 -1
- package/dist/core/join-relationships.js +1 -1
- package/dist/core/query-builder.d.ts +64 -12
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +213 -153
- package/dist/core/query-node.d.ts +7 -0
- package/dist/core/query-node.d.ts.map +1 -0
- package/dist/core/query-node.js +80 -0
- package/dist/core/tests/integration/setup.d.ts +3 -10
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/core/tests/integration/setup.js +30 -249
- package/dist/core/types/select-types.d.ts +3 -0
- package/dist/core/types/select-types.d.ts.map +1 -1
- package/dist/core/utils/connection-endpoint.d.ts +3 -0
- package/dist/core/utils/connection-endpoint.d.ts.map +1 -0
- package/dist/core/utils/connection-endpoint.js +9 -0
- package/dist/core/utils/filter-application.d.ts +15 -0
- package/dist/core/utils/filter-application.d.ts.map +1 -0
- package/dist/core/utils/filter-application.js +32 -0
- package/dist/core/utils/query-config-compat.d.ts +48 -0
- package/dist/core/utils/query-config-compat.d.ts.map +1 -0
- package/dist/core/utils/query-config-compat.js +137 -0
- package/dist/core/utils/relation-application.d.ts +9 -0
- package/dist/core/utils/relation-application.d.ts.map +1 -0
- package/dist/core/utils/relation-application.js +19 -0
- package/dist/core/utils/relation-validation.d.ts +6 -0
- package/dist/core/utils/relation-validation.d.ts.map +1 -0
- package/dist/core/utils/relation-validation.js +29 -0
- package/dist/core/utils/sql-expressions.d.ts +14 -0
- package/dist/core/utils/sql-expressions.d.ts.map +1 -1
- package/dist/core/utils/sql-expressions.js +40 -0
- package/dist/core/utils/tuple-filter-validation.d.ts +3 -0
- package/dist/core/utils/tuple-filter-validation.d.ts.map +1 -0
- package/dist/core/utils/tuple-filter-validation.js +16 -0
- package/dist/index.d.ts +2 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -8
- package/dist/types/base.d.ts +89 -22
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/filters.d.ts +9 -5
- package/dist/types/filters.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/core/tests/integration/test-data.json +0 -190
- package/dist/migrations/config/index.d.ts +0 -3
- package/dist/migrations/config/index.d.ts.map +0 -1
- package/dist/migrations/config/index.js +0 -1
- package/dist/migrations/config/types.d.ts +0 -45
- package/dist/migrations/config/types.d.ts.map +0 -1
- package/dist/migrations/config/types.js +0 -28
- package/dist/migrations/diff/diff.d.ts +0 -11
- package/dist/migrations/diff/diff.d.ts.map +0 -1
- package/dist/migrations/diff/diff.js +0 -240
- package/dist/migrations/diff/index.d.ts +0 -3
- package/dist/migrations/diff/index.d.ts.map +0 -1
- package/dist/migrations/diff/index.js +0 -1
- package/dist/migrations/diff/types.d.ts +0 -74
- package/dist/migrations/diff/types.d.ts.map +0 -1
- package/dist/migrations/diff/types.js +0 -1
- package/dist/migrations/plan/index.d.ts +0 -3
- package/dist/migrations/plan/index.d.ts.map +0 -1
- package/dist/migrations/plan/index.js +0 -1
- package/dist/migrations/plan/plan.d.ts +0 -12
- package/dist/migrations/plan/plan.d.ts.map +0 -1
- package/dist/migrations/plan/plan.js +0 -416
- package/dist/migrations/plan/types.d.ts +0 -93
- package/dist/migrations/plan/types.d.ts.map +0 -1
- package/dist/migrations/plan/types.js +0 -1
- package/dist/migrations/schema/column.d.ts +0 -71
- package/dist/migrations/schema/column.d.ts.map +0 -1
- package/dist/migrations/schema/column.js +0 -123
- package/dist/migrations/schema/define.d.ts +0 -24
- package/dist/migrations/schema/define.d.ts.map +0 -1
- package/dist/migrations/schema/define.js +0 -47
- package/dist/migrations/schema/index.d.ts +0 -4
- package/dist/migrations/schema/index.d.ts.map +0 -1
- package/dist/migrations/schema/index.js +0 -2
- package/dist/migrations/schema/types.d.ts +0 -74
- package/dist/migrations/schema/types.d.ts.map +0 -1
- package/dist/migrations/schema/types.js +0 -1
- package/dist/migrations/snapshot/index.d.ts +0 -3
- package/dist/migrations/snapshot/index.d.ts.map +0 -1
- package/dist/migrations/snapshot/index.js +0 -1
- package/dist/migrations/snapshot/serialize.d.ts +0 -21
- package/dist/migrations/snapshot/serialize.d.ts.map +0 -1
- package/dist/migrations/snapshot/serialize.js +0 -127
- package/dist/migrations/snapshot/types.d.ts +0 -47
- package/dist/migrations/snapshot/types.d.ts.map +0 -1
- package/dist/migrations/snapshot/types.js +0 -1
- package/dist/migrations/sql/index.d.ts +0 -4
- package/dist/migrations/sql/index.d.ts.map +0 -1
- package/dist/migrations/sql/index.js +0 -2
- package/dist/migrations/sql/render.d.ts +0 -10
- package/dist/migrations/sql/render.d.ts.map +0 -1
- package/dist/migrations/sql/render.js +0 -347
- package/dist/migrations/sql/types.d.ts +0 -53
- package/dist/migrations/sql/types.d.ts.map +0 -1
- package/dist/migrations/sql/types.js +0 -1
- package/dist/migrations/sql/write.d.ts +0 -10
- package/dist/migrations/sql/write.d.ts.map +0 -1
- package/dist/migrations/sql/write.js +0 -35
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
1
|
import { ClickHouseConnection } from '../../connection.js';
|
|
4
|
-
import { exec } from 'child_process';
|
|
5
|
-
import { promisify } from 'util';
|
|
6
2
|
import { logger as hypeQueryLogger } from '../../utils/logger.js';
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { CLICKHOUSE_CONTAINER_NAME, TEST_CONNECTION_CONFIG, TEST_DATA, detectComposeCommand, ensureDockerDaemon, isContainerRunning as sharedIsContainerRunning, seedClickHouseDatabase, startClickHouseContainer as sharedStartClickHouseContainer, stopClickHouseContainer as sharedStopClickHouseContainer, waitForClickHouse as sharedWaitForClickHouse,
|
|
4
|
+
// @ts-expect-error: shared test harness is plain JS
|
|
5
|
+
} from '../../../../../../testing/clickhouse/harness.mjs';
|
|
9
6
|
// Disable the hypequery logger to prevent "logs after tests" errors
|
|
10
7
|
// This must be done early in the setup, before any queries run
|
|
11
8
|
hypeQueryLogger.configure({ enabled: false });
|
|
@@ -27,20 +24,7 @@ const logger = {
|
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
};
|
|
30
|
-
const
|
|
31
|
-
// Create a path to the project root
|
|
32
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
33
|
-
const __dirname = path.dirname(__filename);
|
|
34
|
-
const projectRoot = path.resolve(__dirname, '../../../../../');
|
|
35
|
-
// Connection configuration (with defaults that can be overridden by env variables)
|
|
36
|
-
const CLICKHOUSE_TEST_PORT = process.env.CLICKHOUSE_TEST_PORT || '8123';
|
|
37
|
-
const config = {
|
|
38
|
-
host: process.env.CLICKHOUSE_TEST_HOST || `http://localhost:${CLICKHOUSE_TEST_PORT}`,
|
|
39
|
-
user: process.env.CLICKHOUSE_TEST_USER || 'default',
|
|
40
|
-
password: process.env.CLICKHOUSE_TEST_PASSWORD || 'hypequery_test',
|
|
41
|
-
database: process.env.CLICKHOUSE_TEST_DB || 'test_db',
|
|
42
|
-
};
|
|
43
|
-
export const TEST_CONNECTION_CONFIG = config;
|
|
27
|
+
const config = TEST_CONNECTION_CONFIG;
|
|
44
28
|
// Initialize the ClickHouse connection
|
|
45
29
|
export const initializeTestConnection = async () => {
|
|
46
30
|
logger.info('Initializing ClickHouse connection with config:', config);
|
|
@@ -84,178 +68,41 @@ export const ensureConnectionInitialized = () => {
|
|
|
84
68
|
return ClickHouseConnection.getClient();
|
|
85
69
|
};
|
|
86
70
|
// Check if Docker is installed
|
|
87
|
-
export const isDockerAvailable = async () => {
|
|
88
|
-
try {
|
|
89
|
-
await execAsync('docker --version');
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
// Check if Docker Compose is installed
|
|
97
|
-
export const isDockerComposeAvailable = async () => {
|
|
98
|
-
try {
|
|
99
|
-
await execAsync('docker compose version');
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
try {
|
|
104
|
-
// Try the hyphenated version for older installations
|
|
105
|
-
await execAsync('docker-compose --version');
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
// Check if a docker container is running
|
|
114
71
|
export const isContainerRunning = async (containerName) => {
|
|
115
|
-
|
|
116
|
-
const { stdout } = await execAsync(`docker ps --filter "name=${containerName}" --format "{{.Names}}"`);
|
|
117
|
-
return stdout.trim() === containerName;
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
// Check if ClickHouse is ready
|
|
124
|
-
export const isClickHouseReady = async () => {
|
|
125
|
-
try {
|
|
126
|
-
const client = ClickHouseConnection.getClient();
|
|
127
|
-
await client.ping();
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
72
|
+
return sharedIsContainerRunning(containerName);
|
|
133
73
|
};
|
|
134
74
|
// Start the ClickHouse container
|
|
135
75
|
export const startClickHouseContainer = async () => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (composeAvailable) {
|
|
143
|
-
logger.info('Starting ClickHouse container with Docker Compose...');
|
|
144
|
-
try {
|
|
145
|
-
// Fix the path to the docker-compose.test.yml file
|
|
146
|
-
const composePath = path.resolve(projectRoot, 'packages/clickhouse/docker-compose.test.yml');
|
|
147
|
-
logger.info(`Using Docker Compose file at: ${composePath}`);
|
|
148
|
-
// Make sure we're executing the command from the correct directory
|
|
149
|
-
await execAsync(`docker compose -f "${composePath}" up -d`);
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
logger.error('Failed to start ClickHouse container with Docker Compose:', error);
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
// Fallback to Docker run
|
|
158
|
-
logger.info('Starting ClickHouse container with Docker...');
|
|
159
|
-
try {
|
|
160
|
-
await execAsync(`
|
|
161
|
-
docker run -d --name hypequery-test-clickhouse
|
|
162
|
-
-p 8123:8123 -p 9000:9000
|
|
163
|
-
-e CLICKHOUSE_USER=${config.user}
|
|
164
|
-
-e CLICKHOUSE_PASSWORD=${config.password}
|
|
165
|
-
-e CLICKHOUSE_DB=${config.database}
|
|
166
|
-
--ulimit nofile=262144:262144
|
|
167
|
-
clickhouse/clickhouse-server:latest
|
|
168
|
-
`);
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
logger.error('Failed to start ClickHouse container with Docker:', error);
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
76
|
+
await ensureDockerDaemon();
|
|
77
|
+
const compose = await detectComposeCommand();
|
|
78
|
+
await sharedStartClickHouseContainer({
|
|
79
|
+
compose,
|
|
80
|
+
logger: (message) => logger.info(message),
|
|
81
|
+
});
|
|
175
82
|
};
|
|
176
83
|
// Wait for ClickHouse to be ready
|
|
177
84
|
export const waitForClickHouse = async (maxAttempts = 30, retryInterval = 1000) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
logger.info(`Waiting for ClickHouse... Attempt ${attempt}/${maxAttempts}`);
|
|
185
|
-
await new Promise(resolve => setTimeout(resolve, retryInterval));
|
|
186
|
-
}
|
|
187
|
-
throw new Error(`ClickHouse failed to start after ${maxAttempts} attempts`);
|
|
85
|
+
await sharedWaitForClickHouse({
|
|
86
|
+
config,
|
|
87
|
+
maxAttempts,
|
|
88
|
+
retryDelayMs: retryInterval,
|
|
89
|
+
logger: (message) => logger.info(message),
|
|
90
|
+
});
|
|
188
91
|
};
|
|
189
92
|
// Stop the ClickHouse container
|
|
190
93
|
export const stopClickHouseContainer = async () => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
logger.info(`Using Docker Compose file at: ${composePath}`);
|
|
198
|
-
// Make sure we're executing the command from the correct directory
|
|
199
|
-
await execAsync(`docker compose -f "${composePath}" down -v`);
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
logger.error('Failed to stop ClickHouse container with Docker Compose:', error);
|
|
203
|
-
// Log the error but don't throw, so the tests can complete
|
|
204
|
-
// This allows for manual cleanup if needed
|
|
205
|
-
}
|
|
94
|
+
try {
|
|
95
|
+
const compose = await detectComposeCommand();
|
|
96
|
+
await sharedStopClickHouseContainer({
|
|
97
|
+
compose,
|
|
98
|
+
logger: (message) => logger.info(message),
|
|
99
|
+
});
|
|
206
100
|
}
|
|
207
|
-
|
|
208
|
-
logger.
|
|
209
|
-
try {
|
|
210
|
-
await execAsync('docker stop hypequery-test-clickhouse && docker rm hypequery-test-clickhouse');
|
|
211
|
-
}
|
|
212
|
-
catch (error) {
|
|
213
|
-
logger.error('Failed to stop ClickHouse container with Docker:', error);
|
|
214
|
-
// Log the error but don't throw, so the tests can complete
|
|
215
|
-
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
logger.error('Failed to stop ClickHouse container:', error);
|
|
216
103
|
}
|
|
217
104
|
};
|
|
218
|
-
|
|
219
|
-
if (!value) {
|
|
220
|
-
return value;
|
|
221
|
-
}
|
|
222
|
-
if (value.includes('T')) {
|
|
223
|
-
return value.split('T')[0];
|
|
224
|
-
}
|
|
225
|
-
if (value.includes(' ')) {
|
|
226
|
-
return value.split(' ')[0];
|
|
227
|
-
}
|
|
228
|
-
return value;
|
|
229
|
-
}
|
|
230
|
-
function normalizeTestData() {
|
|
231
|
-
const testTable = (rawTestData.test_table ?? []).map(row => ({
|
|
232
|
-
id: row.id,
|
|
233
|
-
name: row.name,
|
|
234
|
-
category: row.category,
|
|
235
|
-
price: row.price,
|
|
236
|
-
created_at: normalizeDateValue(row.created_at),
|
|
237
|
-
is_active: row.is_active
|
|
238
|
-
}));
|
|
239
|
-
const users = (rawTestData.users ?? []).map(row => ({
|
|
240
|
-
id: row.id,
|
|
241
|
-
user_name: row.user_name,
|
|
242
|
-
email: row.email,
|
|
243
|
-
status: row.status,
|
|
244
|
-
created_at: normalizeDateValue(row.created_at)
|
|
245
|
-
}));
|
|
246
|
-
const orders = (rawTestData.orders ?? []).map(row => ({
|
|
247
|
-
id: row.id,
|
|
248
|
-
user_id: row.user_id,
|
|
249
|
-
product_id: row.product_id,
|
|
250
|
-
quantity: row.quantity,
|
|
251
|
-
total: row.total,
|
|
252
|
-
status: row.status,
|
|
253
|
-
created_at: normalizeDateValue(row.created_at)
|
|
254
|
-
}));
|
|
255
|
-
return { test_table: testTable, users, orders };
|
|
256
|
-
}
|
|
257
|
-
// Test data
|
|
258
|
-
export const TEST_DATA = normalizeTestData();
|
|
105
|
+
export { CLICKHOUSE_CONTAINER_NAME, TEST_CONNECTION_CONFIG, TEST_DATA };
|
|
259
106
|
let hasSetupRun = false;
|
|
260
107
|
// Setup the test database
|
|
261
108
|
export const setupTestDatabase = async () => {
|
|
@@ -266,78 +113,12 @@ export const setupTestDatabase = async () => {
|
|
|
266
113
|
if (hasSetupRun) {
|
|
267
114
|
return;
|
|
268
115
|
}
|
|
269
|
-
// Make sure connection is initialized before getting client
|
|
270
|
-
const client = ensureConnectionInitialized();
|
|
271
116
|
try {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
await client.exec({ query: 'DROP TABLE IF EXISTS test_table' });
|
|
277
|
-
await client.exec({ query: 'DROP TABLE IF EXISTS users' });
|
|
278
|
-
await client.exec({ query: 'DROP TABLE IF EXISTS orders' });
|
|
279
|
-
// Create tables
|
|
280
|
-
await client.exec({
|
|
281
|
-
query: `
|
|
282
|
-
CREATE TABLE test_table (
|
|
283
|
-
id UInt32,
|
|
284
|
-
name String,
|
|
285
|
-
category String,
|
|
286
|
-
price Float64,
|
|
287
|
-
created_at Date,
|
|
288
|
-
is_active Boolean
|
|
289
|
-
) ENGINE = MergeTree()
|
|
290
|
-
ORDER BY id
|
|
291
|
-
`
|
|
292
|
-
});
|
|
293
|
-
await client.exec({
|
|
294
|
-
query: `
|
|
295
|
-
CREATE TABLE users (
|
|
296
|
-
id UInt32,
|
|
297
|
-
user_name String,
|
|
298
|
-
email String,
|
|
299
|
-
status String,
|
|
300
|
-
created_at Date
|
|
301
|
-
) ENGINE = MergeTree()
|
|
302
|
-
ORDER BY id
|
|
303
|
-
`
|
|
304
|
-
});
|
|
305
|
-
await client.exec({
|
|
306
|
-
query: `
|
|
307
|
-
CREATE TABLE orders (
|
|
308
|
-
id UInt32,
|
|
309
|
-
user_id UInt32,
|
|
310
|
-
product_id UInt32,
|
|
311
|
-
quantity UInt32,
|
|
312
|
-
total Float64,
|
|
313
|
-
status String,
|
|
314
|
-
created_at Date
|
|
315
|
-
) ENGINE = MergeTree()
|
|
316
|
-
ORDER BY id
|
|
317
|
-
`
|
|
117
|
+
await seedClickHouseDatabase({
|
|
118
|
+
config,
|
|
119
|
+
data: TEST_DATA,
|
|
120
|
+
logger: (message) => logger.info(message),
|
|
318
121
|
});
|
|
319
|
-
// Insert test data
|
|
320
|
-
for (const row of TEST_DATA.test_table) {
|
|
321
|
-
await client.insert({
|
|
322
|
-
table: 'test_table',
|
|
323
|
-
values: [row],
|
|
324
|
-
format: 'JSONEachRow'
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
for (const row of TEST_DATA.users) {
|
|
328
|
-
await client.insert({
|
|
329
|
-
table: 'users',
|
|
330
|
-
values: [row],
|
|
331
|
-
format: 'JSONEachRow'
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
for (const row of TEST_DATA.orders) {
|
|
335
|
-
await client.insert({
|
|
336
|
-
table: 'orders',
|
|
337
|
-
values: [row],
|
|
338
|
-
format: 'JSONEachRow'
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
122
|
hasSetupRun = true;
|
|
342
123
|
logger.info('Test database setup complete');
|
|
343
124
|
}
|
|
@@ -18,6 +18,9 @@ export type SelectableItem<State extends AnyBuilderState> = SelectableColumn<Sta
|
|
|
18
18
|
export type ColumnSelectionKey<P> = P extends `${string}.${infer C}` ? C : P;
|
|
19
19
|
type QualifiedColumnValue<State extends AnyBuilderState, P> = P extends `${infer Table}.${infer Column}` ? ResolveTableSchema<State, Table> extends Record<string, ColumnType> ? Column extends keyof ResolveTableSchema<State, Table> ? ResolveTableSchema<State, Table>[Column] extends ColumnType ? InferColumnType<ResolveTableSchema<State, Table>[Column]> : never : never : never : never;
|
|
20
20
|
export type ColumnSelectionValue<State extends AnyBuilderState, P> = P extends OutputColumnKeys<State> ? State['output'][P] : P extends ScalarColumnKeys<State> ? State['scalars'][P] : P extends BaseColumnKeys<State> ? BaseRow<State>[P] : QualifiedColumnValue<State, P>;
|
|
21
|
+
export type ArraySelectableColumn<State extends AnyBuilderState> = {
|
|
22
|
+
[P in SelectableColumn<State>]: ColumnSelectionValue<State, P> extends readonly unknown[] | null ? P : never;
|
|
23
|
+
}[SelectableColumn<State>];
|
|
21
24
|
export type ColumnSelectionRecord<State extends AnyBuilderState, K> = {
|
|
22
25
|
[P in Extract<K, SelectableColumn<State>> as ColumnSelectionKey<P>]: ColumnSelectionValue<State, P>;
|
|
23
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-types.d.ts","sourceRoot":"","sources":["../../../src/core/types/select-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,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IAAI,MAAM,OAAO,IAAI,MAAM,KAAK,EAAE,GAC/D,SAAS,CAAC,OAAO,CAAC,SAAS,IAAI,GAC7B,MAAM,SAAS,sBAAsB,CAAC,KAAK,CAAC,GAC1C;KAAG,CAAC,IAAI,KAAK,GAAG,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC;CAAE,GACrD,EAAE,GACJ,EAAE,GACJ,EAAE,CAAC;AAEP,KAAK,4BAA4B,CAC/B,KAAK,SAAS,eAAe,EAC7B,CAAC,IACC,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACpC,EAAE,GACF,mBAAmB,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI,mBAAmB,CAC5D,CAAC,SAAS,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC;CAAE,GAAG,EAAE,CACrE,CAAC;AAEF,MAAM,MAAM,eAAe,CACzB,KAAK,SAAS,eAAe,EAC7B,CAAC,IACC,QAAQ,CACV,qBAAqB,CAAC,KAAK,EAAE,CAAC,CAAC,GAC7B,yBAAyB,CAAC,CAAC,CAAC,GAC5B,4BAA4B,CAAC,KAAK,EAAE,CAAC,CAAC,CACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-endpoint.d.ts","sourceRoot":"","sources":["../../../src/core/utils/connection-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAQlF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FilterOperator } from '../../types/index.js';
|
|
2
|
+
import type { PredicateBuilder, PredicateExpression } from './predicate-builder.js';
|
|
3
|
+
export interface FilterExpressionApplication<TExpression> {
|
|
4
|
+
kind: 'expression';
|
|
5
|
+
expression: TExpression;
|
|
6
|
+
}
|
|
7
|
+
export interface FilterConditionApplication {
|
|
8
|
+
kind: 'condition';
|
|
9
|
+
column: string | string[];
|
|
10
|
+
validationTarget: string | string[];
|
|
11
|
+
operator: FilterOperator;
|
|
12
|
+
value: unknown;
|
|
13
|
+
}
|
|
14
|
+
export declare function normalizeFilterApplication<TExpression>(clause: 'where' | 'prewhere', conjunction: 'AND' | 'OR', columnOrColumns: string | string[] | ((expr: PredicateBuilder<any>) => PredicateExpression), operator: FilterOperator | undefined, value: unknown, buildExpression: (builder: (expr: PredicateBuilder<any>) => PredicateExpression) => TExpression): FilterExpressionApplication<TExpression> | FilterConditionApplication;
|
|
15
|
+
//# sourceMappingURL=filter-application.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-application.d.ts","sourceRoot":"","sources":["../../../src/core/utils/filter-application.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGpF,MAAM,WAAW,2BAA2B,CAAC,WAAW;IACtD,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,WAAW,CAAC;CACzB;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACpC,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,0BAA0B,CAAC,WAAW,EACpD,MAAM,EAAE,OAAO,GAAG,UAAU,EAC5B,WAAW,EAAE,KAAK,GAAG,IAAI,EACzB,eAAe,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,mBAAmB,CAAC,EAC3F,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,KAAK,mBAAmB,KAAK,WAAW,GAC9F,2BAA2B,CAAC,WAAW,CAAC,GAAG,0BAA0B,CAkCvE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { validateTupleFilterValue } from './tuple-filter-validation.js';
|
|
2
|
+
export function normalizeFilterApplication(clause, conjunction, columnOrColumns, operator, value, buildExpression) {
|
|
3
|
+
if (typeof columnOrColumns === 'function') {
|
|
4
|
+
return {
|
|
5
|
+
kind: 'expression',
|
|
6
|
+
expression: buildExpression(columnOrColumns),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
if (operator === undefined) {
|
|
10
|
+
throw new Error(`Operator is required when specifying a column for ${conjunction === 'AND' ? clause : `or${clause[0].toUpperCase()}${clause.slice(1)}`}()`);
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(columnOrColumns) && (operator === 'inTuple' || operator === 'globalInTuple')) {
|
|
13
|
+
const columns = columnOrColumns.map(String);
|
|
14
|
+
validateTupleFilterValue(operator, value, columns.length);
|
|
15
|
+
return {
|
|
16
|
+
kind: 'condition',
|
|
17
|
+
column: columns,
|
|
18
|
+
validationTarget: columns,
|
|
19
|
+
operator,
|
|
20
|
+
value,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
validateTupleFilterValue(operator, value, 1);
|
|
24
|
+
const column = Array.isArray(columnOrColumns) ? String(columnOrColumns[0]) : String(columnOrColumns);
|
|
25
|
+
return {
|
|
26
|
+
kind: 'condition',
|
|
27
|
+
column,
|
|
28
|
+
validationTarget: Array.isArray(columnOrColumns) ? columnOrColumns.map(String) : column,
|
|
29
|
+
operator,
|
|
30
|
+
value,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ClickHouseSettings } from '@clickhouse/client-common';
|
|
2
|
+
import type { FilterOperator, JoinType, OrderDirection, SelectQueryNode } from '../../types/index.js';
|
|
3
|
+
export type LegacyStandardWhereCondition = {
|
|
4
|
+
column: string;
|
|
5
|
+
operator: FilterOperator;
|
|
6
|
+
value: any;
|
|
7
|
+
conjunction: 'AND' | 'OR';
|
|
8
|
+
type?: 'condition' | 'group-start' | 'group-end';
|
|
9
|
+
};
|
|
10
|
+
export type LegacyExpressionWhereCondition = {
|
|
11
|
+
type: 'expression';
|
|
12
|
+
expression: string;
|
|
13
|
+
parameters: any[];
|
|
14
|
+
conjunction: 'AND' | 'OR';
|
|
15
|
+
};
|
|
16
|
+
export type LegacyWhereCondition = LegacyStandardWhereCondition | LegacyExpressionWhereCondition;
|
|
17
|
+
export type LegacyQueryConfig<T> = {
|
|
18
|
+
select?: Array<keyof T | string>;
|
|
19
|
+
from?: {
|
|
20
|
+
kind: 'table';
|
|
21
|
+
name: string;
|
|
22
|
+
final?: boolean;
|
|
23
|
+
};
|
|
24
|
+
where?: LegacyWhereCondition[];
|
|
25
|
+
prewhere?: LegacyWhereCondition[];
|
|
26
|
+
groupBy?: string[];
|
|
27
|
+
having?: string[];
|
|
28
|
+
limit?: number;
|
|
29
|
+
offset?: number;
|
|
30
|
+
distinct?: boolean;
|
|
31
|
+
orderBy?: Array<{
|
|
32
|
+
column: keyof T | string;
|
|
33
|
+
direction: OrderDirection;
|
|
34
|
+
}>;
|
|
35
|
+
joins?: Array<{
|
|
36
|
+
type: JoinType;
|
|
37
|
+
table: string;
|
|
38
|
+
leftColumn: string;
|
|
39
|
+
rightColumn: string;
|
|
40
|
+
alias?: string;
|
|
41
|
+
}>;
|
|
42
|
+
parameters?: any[];
|
|
43
|
+
ctes?: string[];
|
|
44
|
+
unionQueries?: string[];
|
|
45
|
+
settings?: ClickHouseSettings;
|
|
46
|
+
};
|
|
47
|
+
export declare function toLegacyQueryConfig<T, Schema>(queryNode: SelectQueryNode<T, Schema>): LegacyQueryConfig<T>;
|
|
48
|
+
//# sourceMappingURL=query-config-compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-config-compat.d.ts","sourceRoot":"","sources":["../../../src/core/utils/query-config-compat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAGV,cAAc,EACd,QAAQ,EACR,cAAc,EACd,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,4BAA4B,GAAG;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,GAAG,CAAC;IACX,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,WAAW,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,4BAA4B,GAAG,8BAA8B,CAAC;AAEjG,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;QACzB,SAAS,EAAE,cAAc,CAAC;KAC3B,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B,CAAC;AA+HF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAC3C,SAAS,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,GACpC,iBAAiB,CAAC,CAAC,CAAC,CA+BtB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
function unwrapValueNode(value) {
|
|
2
|
+
return value.value;
|
|
3
|
+
}
|
|
4
|
+
function unwrapConditionValue(value) {
|
|
5
|
+
if (typeof value === 'string') {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
return value.map(item => Array.isArray(item) ? item.map(unwrapValueNode) : unwrapValueNode(item));
|
|
10
|
+
}
|
|
11
|
+
return unwrapValueNode(value);
|
|
12
|
+
}
|
|
13
|
+
function collectExprParameters(expr) {
|
|
14
|
+
if (!expr)
|
|
15
|
+
return [];
|
|
16
|
+
switch (expr.kind) {
|
|
17
|
+
case 'condition': {
|
|
18
|
+
const value = unwrapConditionValue(expr.value);
|
|
19
|
+
if (expr.operator === 'between') {
|
|
20
|
+
return Array.isArray(value) ? value : [];
|
|
21
|
+
}
|
|
22
|
+
if (expr.operator === 'in' ||
|
|
23
|
+
expr.operator === 'notIn' ||
|
|
24
|
+
expr.operator === 'globalIn' ||
|
|
25
|
+
expr.operator === 'globalNotIn') {
|
|
26
|
+
return Array.isArray(value) ? value : [];
|
|
27
|
+
}
|
|
28
|
+
if (expr.operator === 'inTuple' || expr.operator === 'globalInTuple') {
|
|
29
|
+
return Array.isArray(value) ? value.flat() : [];
|
|
30
|
+
}
|
|
31
|
+
if (expr.operator === 'inSubquery' ||
|
|
32
|
+
expr.operator === 'globalInSubquery' ||
|
|
33
|
+
expr.operator === 'inTable' ||
|
|
34
|
+
expr.operator === 'globalInTable' ||
|
|
35
|
+
expr.operator === 'isNull' ||
|
|
36
|
+
expr.operator === 'isNotNull') {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return [value];
|
|
40
|
+
}
|
|
41
|
+
case 'raw':
|
|
42
|
+
return expr.parameters.map(unwrapValueNode);
|
|
43
|
+
case 'group':
|
|
44
|
+
return collectExprParameters(expr.expression);
|
|
45
|
+
case 'logical':
|
|
46
|
+
return expr.conditions.flatMap(condition => collectExprParameters(condition));
|
|
47
|
+
case 'sequence':
|
|
48
|
+
return expr.items.flatMap(item => collectExprParameters(item.expression));
|
|
49
|
+
default:
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function flattenExprToLegacyConditions(expr, firstConjunction = 'AND') {
|
|
54
|
+
if (!expr)
|
|
55
|
+
return [];
|
|
56
|
+
switch (expr.kind) {
|
|
57
|
+
case 'condition':
|
|
58
|
+
return [{
|
|
59
|
+
column: expr.column,
|
|
60
|
+
operator: expr.operator,
|
|
61
|
+
value: unwrapConditionValue(expr.value),
|
|
62
|
+
conjunction: firstConjunction,
|
|
63
|
+
}];
|
|
64
|
+
case 'raw':
|
|
65
|
+
return [{
|
|
66
|
+
type: 'expression',
|
|
67
|
+
expression: expr.expression,
|
|
68
|
+
parameters: expr.parameters.map(unwrapValueNode),
|
|
69
|
+
conjunction: firstConjunction,
|
|
70
|
+
}];
|
|
71
|
+
case 'group': {
|
|
72
|
+
if (!expr.expression)
|
|
73
|
+
return [];
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
column: '',
|
|
77
|
+
operator: 'eq',
|
|
78
|
+
value: null,
|
|
79
|
+
conjunction: firstConjunction,
|
|
80
|
+
type: 'group-start',
|
|
81
|
+
},
|
|
82
|
+
...flattenExprToLegacyConditions(expr.expression, 'AND'),
|
|
83
|
+
{
|
|
84
|
+
column: '',
|
|
85
|
+
operator: 'eq',
|
|
86
|
+
value: null,
|
|
87
|
+
conjunction: 'AND',
|
|
88
|
+
type: 'group-end',
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
case 'sequence':
|
|
93
|
+
return expr.items.flatMap((item, index) => flattenExprToLegacyConditions(item.expression, index === 0 ? firstConjunction : (item.conjunction || 'AND')));
|
|
94
|
+
case 'logical':
|
|
95
|
+
return flattenExprToLegacyConditions({
|
|
96
|
+
kind: 'sequence',
|
|
97
|
+
items: expr.conditions.map((condition, index) => ({
|
|
98
|
+
conjunction: index === 0 ? undefined : expr.operator,
|
|
99
|
+
expression: condition,
|
|
100
|
+
})),
|
|
101
|
+
}, firstConjunction);
|
|
102
|
+
default:
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function toLegacyQueryConfig(queryNode) {
|
|
107
|
+
return {
|
|
108
|
+
select: queryNode.select?.map(item => item.selection),
|
|
109
|
+
from: queryNode.from ? { ...queryNode.from } : undefined,
|
|
110
|
+
where: flattenExprToLegacyConditions(queryNode.where),
|
|
111
|
+
prewhere: flattenExprToLegacyConditions(queryNode.prewhere),
|
|
112
|
+
groupBy: queryNode.groupBy?.map(item => item.expression),
|
|
113
|
+
having: queryNode.having?.map(item => item.expression),
|
|
114
|
+
limit: queryNode.limit,
|
|
115
|
+
offset: queryNode.offset,
|
|
116
|
+
distinct: queryNode.distinct,
|
|
117
|
+
orderBy: queryNode.orderBy?.map(item => ({
|
|
118
|
+
column: item.column,
|
|
119
|
+
direction: item.direction,
|
|
120
|
+
})),
|
|
121
|
+
joins: queryNode.joins?.map(join => ({
|
|
122
|
+
type: join.type,
|
|
123
|
+
table: join.table,
|
|
124
|
+
leftColumn: join.leftColumn,
|
|
125
|
+
rightColumn: join.rightColumn,
|
|
126
|
+
alias: join.alias,
|
|
127
|
+
})),
|
|
128
|
+
parameters: [
|
|
129
|
+
...collectExprParameters(queryNode.prewhere),
|
|
130
|
+
...collectExprParameters(queryNode.where),
|
|
131
|
+
...(queryNode.having?.flatMap(item => item.parameters?.map(unwrapValueNode) || []) || []),
|
|
132
|
+
],
|
|
133
|
+
ctes: queryNode.ctes?.map(item => item.expression),
|
|
134
|
+
unionQueries: queryNode.unionQueries ? [...queryNode.unionQueries] : undefined,
|
|
135
|
+
settings: queryNode.settings ? { ...queryNode.settings } : undefined,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SelectQueryNode } from '../../types/index.js';
|
|
2
|
+
import type { SchemaDefinition } from '../types/builder-state.js';
|
|
3
|
+
import type { JoinPath, JoinPathOptions, JoinRelationships } from '../join-relationships.js';
|
|
4
|
+
export declare function resolveRelationPath<Schema extends SchemaDefinition<Schema>>(nameOrPath: string | JoinPath<Schema, string> | readonly JoinPath<Schema, string>[], relationships: JoinRelationships<Schema> | undefined): {
|
|
5
|
+
path: JoinPath<Schema, string> | readonly JoinPath<Schema, string>[];
|
|
6
|
+
label?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function applyRelationPath<Schema extends SchemaDefinition<Schema>>(query: SelectQueryNode<any, Schema>, path: JoinPath<Schema, string> | readonly JoinPath<Schema, string>[], options: JoinPathOptions | undefined, appendJoin: (currentQuery: SelectQueryNode<any, Schema>, joinPath: JoinPath<Schema, string>, options: JoinPathOptions | undefined) => SelectQueryNode<any, Schema>, label?: string): SelectQueryNode<any, Schema>;
|
|
9
|
+
//# sourceMappingURL=relation-application.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation-application.d.ts","sourceRoot":"","sources":["../../../src/core/utils/relation-application.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACzE,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACnF,aAAa,EAAE,iBAAiB,CAAC,MAAM,CAAC,GAAG,SAAS,GACnD;IAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAe1F;AAED,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACvE,KAAK,EAAE,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,EACnC,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACpE,OAAO,EAAE,eAAe,GAAG,SAAS,EACpC,UAAU,EAAE,CACV,YAAY,EAAE,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,EAC1C,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,OAAO,EAAE,eAAe,GAAG,SAAS,KACjC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,EACjC,KAAK,CAAC,EAAE,MAAM,GACb,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAQ9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { validateRelationAliasOverride, validateRelationPathOrigin } from './relation-validation.js';
|
|
2
|
+
export function resolveRelationPath(nameOrPath, relationships) {
|
|
3
|
+
if (typeof nameOrPath !== 'string') {
|
|
4
|
+
return { path: nameOrPath };
|
|
5
|
+
}
|
|
6
|
+
if (!relationships) {
|
|
7
|
+
throw new Error('Join relationships have not been initialized. Call QueryBuilder.setJoinRelationships first.');
|
|
8
|
+
}
|
|
9
|
+
const path = relationships.get(nameOrPath);
|
|
10
|
+
if (!path) {
|
|
11
|
+
throw new Error(`Join relationship '${nameOrPath}' not found`);
|
|
12
|
+
}
|
|
13
|
+
return { path, label: nameOrPath };
|
|
14
|
+
}
|
|
15
|
+
export function applyRelationPath(query, path, options, appendJoin, label) {
|
|
16
|
+
validateRelationAliasOverride(path, options?.alias, label);
|
|
17
|
+
validateRelationPathOrigin(query, path, label);
|
|
18
|
+
return (Array.isArray(path) ? path : [path]).reduce((currentQuery, joinPath) => appendJoin(currentQuery, joinPath, options), query);
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SelectQueryNode } from '../../types/index.js';
|
|
2
|
+
import type { SchemaDefinition } from '../types/builder-state.js';
|
|
3
|
+
import type { JoinPath } from '../join-relationships.js';
|
|
4
|
+
export declare function validateRelationPathOrigin<Schema extends SchemaDefinition<Schema>>(query: SelectQueryNode<any, Schema>, path: JoinPath<Schema, string> | readonly JoinPath<Schema, string>[], label?: string): void;
|
|
5
|
+
export declare function validateRelationAliasOverride(path: JoinPath<any, string> | readonly JoinPath<any, string>[], alias: string | undefined, label?: string): void;
|
|
6
|
+
//# sourceMappingURL=relation-validation.d.ts.map
|