@hypequery/clickhouse 0.0.0-canary-20260306132943

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.
Files changed (142) hide show
  1. package/LICENSE +201 -0
  2. package/README-CLI.md +123 -0
  3. package/README.md +316 -0
  4. package/dist/cli/bin.js +285 -0
  5. package/dist/cli/generate-types.d.ts +5 -0
  6. package/dist/cli/generate-types.js +218 -0
  7. package/dist/cli/index.d.ts +2 -0
  8. package/dist/cli/index.js +2 -0
  9. package/dist/core/cache/cache-manager.d.ts +4 -0
  10. package/dist/core/cache/cache-manager.d.ts.map +1 -0
  11. package/dist/core/cache/cache-manager.js +176 -0
  12. package/dist/core/cache/controller.d.ts +15 -0
  13. package/dist/core/cache/controller.d.ts.map +1 -0
  14. package/dist/core/cache/controller.js +58 -0
  15. package/dist/core/cache/key.d.ts +11 -0
  16. package/dist/core/cache/key.d.ts.map +1 -0
  17. package/dist/core/cache/key.js +26 -0
  18. package/dist/core/cache/providers/memory-lru.d.ts +31 -0
  19. package/dist/core/cache/providers/memory-lru.d.ts.map +1 -0
  20. package/dist/core/cache/providers/memory-lru.js +156 -0
  21. package/dist/core/cache/providers/noop.d.ts +7 -0
  22. package/dist/core/cache/providers/noop.d.ts.map +1 -0
  23. package/dist/core/cache/providers/noop.js +11 -0
  24. package/dist/core/cache/runtime-context.d.ts +30 -0
  25. package/dist/core/cache/runtime-context.d.ts.map +1 -0
  26. package/dist/core/cache/runtime-context.js +58 -0
  27. package/dist/core/cache/serialization.d.ts +6 -0
  28. package/dist/core/cache/serialization.d.ts.map +1 -0
  29. package/dist/core/cache/serialization.js +166 -0
  30. package/dist/core/cache/types.d.ts +52 -0
  31. package/dist/core/cache/types.d.ts.map +1 -0
  32. package/dist/core/cache/types.js +1 -0
  33. package/dist/core/cache/utils.d.ts +9 -0
  34. package/dist/core/cache/utils.d.ts.map +1 -0
  35. package/dist/core/cache/utils.js +30 -0
  36. package/dist/core/connection.d.ts +112 -0
  37. package/dist/core/connection.d.ts.map +1 -0
  38. package/dist/core/connection.js +150 -0
  39. package/dist/core/cross-filter.d.ts +73 -0
  40. package/dist/core/cross-filter.d.ts.map +1 -0
  41. package/dist/core/cross-filter.js +142 -0
  42. package/dist/core/env/auto-client.browser.d.ts +3 -0
  43. package/dist/core/env/auto-client.browser.d.ts.map +1 -0
  44. package/dist/core/env/auto-client.browser.js +3 -0
  45. package/dist/core/env/auto-client.d.ts +9 -0
  46. package/dist/core/env/auto-client.d.ts.map +1 -0
  47. package/dist/core/env/auto-client.js +21 -0
  48. package/dist/core/features/aggregations.d.ts +98 -0
  49. package/dist/core/features/aggregations.d.ts.map +1 -0
  50. package/dist/core/features/aggregations.js +36 -0
  51. package/dist/core/features/analytics.d.ts +81 -0
  52. package/dist/core/features/analytics.d.ts.map +1 -0
  53. package/dist/core/features/analytics.js +45 -0
  54. package/dist/core/features/cross-filtering.d.ts +11 -0
  55. package/dist/core/features/cross-filtering.d.ts.map +1 -0
  56. package/dist/core/features/cross-filtering.js +90 -0
  57. package/dist/core/features/executor.d.ts +21 -0
  58. package/dist/core/features/executor.d.ts.map +1 -0
  59. package/dist/core/features/executor.js +146 -0
  60. package/dist/core/features/filtering.d.ts +99 -0
  61. package/dist/core/features/filtering.d.ts.map +1 -0
  62. package/dist/core/features/filtering.js +118 -0
  63. package/dist/core/features/joins.d.ts +26 -0
  64. package/dist/core/features/joins.d.ts.map +1 -0
  65. package/dist/core/features/joins.js +17 -0
  66. package/dist/core/features/query-modifiers.d.ts +116 -0
  67. package/dist/core/features/query-modifiers.d.ts.map +1 -0
  68. package/dist/core/features/query-modifiers.js +51 -0
  69. package/dist/core/formatters/sql-formatter.d.ts +9 -0
  70. package/dist/core/formatters/sql-formatter.d.ts.map +1 -0
  71. package/dist/core/formatters/sql-formatter.js +131 -0
  72. package/dist/core/join-relationships.d.ts +51 -0
  73. package/dist/core/join-relationships.d.ts.map +1 -0
  74. package/dist/core/join-relationships.js +54 -0
  75. package/dist/core/query-builder.d.ts +236 -0
  76. package/dist/core/query-builder.d.ts.map +1 -0
  77. package/dist/core/query-builder.js +495 -0
  78. package/dist/core/tests/index.d.ts +2 -0
  79. package/dist/core/tests/index.d.ts.map +1 -0
  80. package/dist/core/tests/index.js +1 -0
  81. package/dist/core/tests/integration/setup.d.ts +48 -0
  82. package/dist/core/tests/integration/setup.d.ts.map +1 -0
  83. package/dist/core/tests/integration/setup.js +349 -0
  84. package/dist/core/tests/integration/test-config.d.ts +15 -0
  85. package/dist/core/tests/integration/test-config.d.ts.map +1 -0
  86. package/dist/core/tests/integration/test-config.js +14 -0
  87. package/dist/core/tests/integration/test-data.json +190 -0
  88. package/dist/core/tests/test-utils.d.ts +44 -0
  89. package/dist/core/tests/test-utils.d.ts.map +1 -0
  90. package/dist/core/tests/test-utils.js +65 -0
  91. package/dist/core/types/builder-state.d.ts +27 -0
  92. package/dist/core/types/builder-state.d.ts.map +1 -0
  93. package/dist/core/types/builder-state.js +1 -0
  94. package/dist/core/types/select-types.d.ts +33 -0
  95. package/dist/core/types/select-types.d.ts.map +1 -0
  96. package/dist/core/types/select-types.js +1 -0
  97. package/dist/core/types/type-helpers.d.ts +5 -0
  98. package/dist/core/types/type-helpers.d.ts.map +1 -0
  99. package/dist/core/types/type-helpers.js +1 -0
  100. package/dist/core/utils/logger.d.ts +43 -0
  101. package/dist/core/utils/logger.d.ts.map +1 -0
  102. package/dist/core/utils/logger.js +104 -0
  103. package/dist/core/utils/predicate-builder.d.ts +33 -0
  104. package/dist/core/utils/predicate-builder.d.ts.map +1 -0
  105. package/dist/core/utils/predicate-builder.js +95 -0
  106. package/dist/core/utils/sql-expressions.d.ts +77 -0
  107. package/dist/core/utils/sql-expressions.d.ts.map +1 -0
  108. package/dist/core/utils/sql-expressions.js +54 -0
  109. package/dist/core/utils/streaming-helpers.d.ts +2 -0
  110. package/dist/core/utils/streaming-helpers.d.ts.map +1 -0
  111. package/dist/core/utils/streaming-helpers.js +137 -0
  112. package/dist/core/utils.d.ts +3 -0
  113. package/dist/core/utils.d.ts.map +1 -0
  114. package/dist/core/utils.js +29 -0
  115. package/dist/core/validators/filter-validator.d.ts +9 -0
  116. package/dist/core/validators/filter-validator.d.ts.map +1 -0
  117. package/dist/core/validators/filter-validator.js +19 -0
  118. package/dist/core/validators/value-validator.d.ts +7 -0
  119. package/dist/core/validators/value-validator.d.ts.map +1 -0
  120. package/dist/core/validators/value-validator.js +47 -0
  121. package/dist/formatters/index.d.ts +2 -0
  122. package/dist/formatters/index.d.ts.map +1 -0
  123. package/dist/formatters/index.js +1 -0
  124. package/dist/index.d.ts +20 -0
  125. package/dist/index.d.ts.map +1 -0
  126. package/dist/index.js +21 -0
  127. package/dist/types/base.d.ts +50 -0
  128. package/dist/types/base.d.ts.map +1 -0
  129. package/dist/types/base.js +1 -0
  130. package/dist/types/clickhouse-types.d.ts +17 -0
  131. package/dist/types/clickhouse-types.d.ts.map +1 -0
  132. package/dist/types/clickhouse-types.js +1 -0
  133. package/dist/types/filters.d.ts +53 -0
  134. package/dist/types/filters.d.ts.map +1 -0
  135. package/dist/types/filters.js +1 -0
  136. package/dist/types/index.d.ts +5 -0
  137. package/dist/types/index.d.ts.map +1 -0
  138. package/dist/types/index.js +4 -0
  139. package/dist/types/schema.d.ts +19 -0
  140. package/dist/types/schema.d.ts.map +1 -0
  141. package/dist/types/schema.js +1 -0
  142. package/package.json +90 -0
@@ -0,0 +1,349 @@
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import { ClickHouseConnection } from '../../connection.js';
4
+ import { exec } from 'child_process';
5
+ import { promisify } from 'util';
6
+ import { logger as hypeQueryLogger } from '../../utils/logger.js';
7
+ // @ts-expect-error: raw JSON import for supplying fixture data
8
+ import rawTestData from './test-data.json';
9
+ // Disable the hypequery logger to prevent "logs after tests" errors
10
+ // This must be done early in the setup, before any queries run
11
+ hypeQueryLogger.configure({ enabled: false });
12
+ // Setup a logger that respects test environment
13
+ const logger = {
14
+ info: (message, ...args) => {
15
+ if (process.env.DEBUG === 'true') {
16
+ console.info(`[INFO] ${message}`, ...args);
17
+ }
18
+ },
19
+ error: (message, ...args) => {
20
+ if (process.env.DEBUG === 'true' || process.env.SUPPRESS_ERRORS !== 'true') {
21
+ console.error(`[ERROR] ${message}`, ...args);
22
+ }
23
+ },
24
+ warn: (message, ...args) => {
25
+ if (process.env.DEBUG === 'true') {
26
+ console.warn(`[WARN] ${message}`, ...args);
27
+ }
28
+ }
29
+ };
30
+ const execAsync = promisify(exec);
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;
44
+ // Initialize the ClickHouse connection
45
+ export const initializeTestConnection = async () => {
46
+ logger.info('Initializing ClickHouse connection with config:', config);
47
+ try {
48
+ // Make sure ClickHouse is initialized
49
+ ensureConnectionInitialized();
50
+ // Test connection by getting client and pinging
51
+ const client = ClickHouseConnection.getClient();
52
+ await client.ping();
53
+ logger.info('ClickHouse connection successful');
54
+ // Return the query builder from the index file
55
+ const { createQueryBuilder } = await import('../../../index.js');
56
+ return createQueryBuilder({
57
+ host: config.host,
58
+ username: config.user,
59
+ password: config.password,
60
+ database: config.database,
61
+ });
62
+ }
63
+ catch (error) {
64
+ logger.error('Failed to connect to ClickHouse:', error);
65
+ throw error;
66
+ }
67
+ };
68
+ // Helper function to ensure connection is initialized
69
+ export const ensureConnectionInitialized = () => {
70
+ // If connection hasn't been initialized yet, initialize it
71
+ try {
72
+ ClickHouseConnection.getClient();
73
+ }
74
+ catch (error) {
75
+ // If we get "not initialized" error, initialize the connection
76
+ logger.info('Initializing ClickHouse connection...');
77
+ ClickHouseConnection.initialize({
78
+ host: config.host,
79
+ username: config.user,
80
+ password: config.password,
81
+ database: config.database,
82
+ });
83
+ }
84
+ return ClickHouseConnection.getClient();
85
+ };
86
+ // 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
+ export const isContainerRunning = async (containerName) => {
115
+ try {
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
+ }
133
+ };
134
+ // Start the ClickHouse container
135
+ export const startClickHouseContainer = async () => {
136
+ const dockerAvailable = await isDockerAvailable();
137
+ if (!dockerAvailable) {
138
+ throw new Error('Docker is not available. Please install Docker to run integration tests.');
139
+ }
140
+ const composeAvailable = await isDockerComposeAvailable();
141
+ // Use Docker Compose if available
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
+ }
175
+ };
176
+ // Wait for ClickHouse to be ready
177
+ export const waitForClickHouse = async (maxAttempts = 30, retryInterval = 1000) => {
178
+ logger.info('Waiting for ClickHouse to be ready...');
179
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
180
+ if (await isClickHouseReady()) {
181
+ logger.info('ClickHouse is ready!');
182
+ return;
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`);
188
+ };
189
+ // Stop the ClickHouse container
190
+ export const stopClickHouseContainer = async () => {
191
+ const composeAvailable = await isDockerComposeAvailable();
192
+ if (composeAvailable) {
193
+ logger.info('Stopping ClickHouse container with Docker Compose...');
194
+ try {
195
+ // Fix the path to the docker-compose.test.yml file
196
+ const composePath = path.resolve(projectRoot, 'packages/clickhouse/docker-compose.test.yml');
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
+ }
206
+ }
207
+ else {
208
+ logger.info('Stopping ClickHouse container with Docker...');
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
+ }
216
+ }
217
+ };
218
+ function normalizeDateValue(value) {
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();
259
+ let hasSetupRun = false;
260
+ // Setup the test database
261
+ export const setupTestDatabase = async () => {
262
+ if (process.env.HYPEQUERY_SKIP_TEST_DB_SETUP === 'true') {
263
+ logger.info('Skipping test database setup because HYPEQUERY_SKIP_TEST_DB_SETUP is true.');
264
+ return;
265
+ }
266
+ if (hasSetupRun) {
267
+ return;
268
+ }
269
+ // Make sure connection is initialized before getting client
270
+ const client = ensureConnectionInitialized();
271
+ try {
272
+ // Create and use database if it doesn't exist
273
+ await client.exec({ query: `CREATE DATABASE IF NOT EXISTS ${config.database}` });
274
+ await client.exec({ query: `USE ${config.database}` });
275
+ // Drop tables if they exist
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
+ `
318
+ });
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
+ hasSetupRun = true;
342
+ logger.info('Test database setup complete');
343
+ }
344
+ catch (error) {
345
+ hasSetupRun = false;
346
+ logger.error('Failed to set up test database:', error);
347
+ throw error;
348
+ }
349
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Centralized configuration for integration tests
3
+ * Import this in all integration test files to ensure consistent behavior
4
+ */
5
+ /**
6
+ * Whether to skip integration tests:
7
+ * - Only skip when SKIP_INTEGRATION_TESTS is explicitly set to 'true'
8
+ * (used locally when ClickHouse is unavailable)
9
+ */
10
+ export declare const SKIP_INTEGRATION_TESTS: boolean;
11
+ /**
12
+ * Default timeout for test setup (in milliseconds)
13
+ */
14
+ export declare const SETUP_TIMEOUT = 30000;
15
+ //# sourceMappingURL=test-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-config.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/test-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,SAAgD,CAAC;AAEpF;;GAEG;AACH,eAAO,MAAM,aAAa,QAAQ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Centralized configuration for integration tests
3
+ * Import this in all integration test files to ensure consistent behavior
4
+ */
5
+ /**
6
+ * Whether to skip integration tests:
7
+ * - Only skip when SKIP_INTEGRATION_TESTS is explicitly set to 'true'
8
+ * (used locally when ClickHouse is unavailable)
9
+ */
10
+ export const SKIP_INTEGRATION_TESTS = process.env.SKIP_INTEGRATION_TESTS === 'true';
11
+ /**
12
+ * Default timeout for test setup (in milliseconds)
13
+ */
14
+ export const SETUP_TIMEOUT = 30000;
@@ -0,0 +1,190 @@
1
+ {
2
+ "test_table": [
3
+ {
4
+ "id": 1,
5
+ "name": "Product A",
6
+ "category": "A",
7
+ "price": 10.5,
8
+ "created_at": "2023-01-01 10:00:00",
9
+ "is_active": true,
10
+ "tags": [
11
+ "new",
12
+ "sale"
13
+ ],
14
+ "attributes": {
15
+ "color": "red",
16
+ "size": "M"
17
+ },
18
+ "optional_note": "Popular item",
19
+ "sku": "A-100",
20
+ "delivery_dates": [
21
+ "2023-01-05",
22
+ "2023-01-10"
23
+ ]
24
+ },
25
+ {
26
+ "id": 2,
27
+ "name": "Product B",
28
+ "category": "B",
29
+ "price": 20.75,
30
+ "created_at": "2023-01-02 12:30:00",
31
+ "is_active": true,
32
+ "tags": [
33
+ "featured"
34
+ ],
35
+ "attributes": {
36
+ "color": "blue",
37
+ "size": "L"
38
+ },
39
+ "optional_note": null,
40
+ "sku": "B-200",
41
+ "delivery_dates": [
42
+ "2023-01-06"
43
+ ]
44
+ },
45
+ {
46
+ "id": 3,
47
+ "name": "Product C",
48
+ "category": "A",
49
+ "price": 15.0,
50
+ "created_at": "2023-01-03 09:45:00",
51
+ "is_active": false,
52
+ "tags": [],
53
+ "attributes": {
54
+ "color": "green",
55
+ "size": "S"
56
+ },
57
+ "optional_note": "Backordered",
58
+ "sku": "C-300",
59
+ "delivery_dates": []
60
+ },
61
+ {
62
+ "id": 4,
63
+ "name": "Product D",
64
+ "category": "C",
65
+ "price": 8.25,
66
+ "created_at": "2023-01-04 15:15:00",
67
+ "is_active": true,
68
+ "tags": [
69
+ "clearance"
70
+ ],
71
+ "attributes": {
72
+ "color": "yellow",
73
+ "size": "XL"
74
+ },
75
+ "optional_note": null,
76
+ "sku": "D-400",
77
+ "delivery_dates": [
78
+ "2023-01-08"
79
+ ]
80
+ },
81
+ {
82
+ "id": 5,
83
+ "name": "Product E",
84
+ "category": "B",
85
+ "price": 30.0,
86
+ "created_at": "2023-01-05 11:20:00",
87
+ "is_active": true,
88
+ "tags": [
89
+ "premium",
90
+ "gift"
91
+ ],
92
+ "attributes": {
93
+ "color": "black",
94
+ "size": "M"
95
+ },
96
+ "optional_note": "Limited stock",
97
+ "sku": "E-500",
98
+ "delivery_dates": [
99
+ "2023-01-07",
100
+ "2023-01-09"
101
+ ]
102
+ },
103
+ {
104
+ "id": 6,
105
+ "name": "Product F",
106
+ "category": "D",
107
+ "price": 12.5,
108
+ "created_at": "2023-01-06 14:40:00",
109
+ "is_active": false,
110
+ "tags": [],
111
+ "attributes": {
112
+ "color": "white",
113
+ "size": "M"
114
+ },
115
+ "optional_note": null,
116
+ "sku": "F-600",
117
+ "delivery_dates": []
118
+ }
119
+ ],
120
+ "users": [
121
+ {
122
+ "id": 1,
123
+ "user_name": "john_doe",
124
+ "email": "john@example.com",
125
+ "status": "active",
126
+ "created_at": "2023-01-01"
127
+ },
128
+ {
129
+ "id": 2,
130
+ "user_name": "jane_smith",
131
+ "email": "jane@example.com",
132
+ "status": "active",
133
+ "created_at": "2023-01-02"
134
+ },
135
+ {
136
+ "id": 3,
137
+ "user_name": "bob_jones",
138
+ "email": "bob@example.com",
139
+ "status": "inactive",
140
+ "created_at": "2023-01-03"
141
+ }
142
+ ],
143
+ "orders": [
144
+ {
145
+ "id": 1,
146
+ "user_id": 1,
147
+ "product_id": 1,
148
+ "quantity": 2,
149
+ "total": 21.0,
150
+ "status": "completed",
151
+ "created_at": "2023-01-10"
152
+ },
153
+ {
154
+ "id": 2,
155
+ "user_id": 1,
156
+ "product_id": 3,
157
+ "quantity": 1,
158
+ "total": 15.0,
159
+ "status": "completed",
160
+ "created_at": "2023-01-11"
161
+ },
162
+ {
163
+ "id": 3,
164
+ "user_id": 2,
165
+ "product_id": 2,
166
+ "quantity": 3,
167
+ "total": 62.25,
168
+ "status": "pending",
169
+ "created_at": "2023-01-12"
170
+ },
171
+ {
172
+ "id": 4,
173
+ "user_id": 2,
174
+ "product_id": 5,
175
+ "quantity": 1,
176
+ "total": 30.0,
177
+ "status": "completed",
178
+ "created_at": "2023-01-13"
179
+ },
180
+ {
181
+ "id": 5,
182
+ "user_id": 3,
183
+ "product_id": 4,
184
+ "quantity": 2,
185
+ "total": 16.5,
186
+ "status": "cancelled",
187
+ "created_at": "2023-01-14"
188
+ }
189
+ ]
190
+ }
@@ -0,0 +1,44 @@
1
+ import { SelectQB } from '../query-builder.js';
2
+ import type { TableRecord } from '../../types/schema.js';
3
+ export type TestTableSchema = {
4
+ id: 'Int32';
5
+ name: 'String';
6
+ price: 'Float64';
7
+ created_at: 'Date';
8
+ category: 'String';
9
+ active: 'UInt8';
10
+ created_by: 'Int32';
11
+ updated_by: 'Int32';
12
+ status: 'String';
13
+ brand: 'String';
14
+ total: 'Int32';
15
+ priority: 'String';
16
+ is_premium: 'Bool';
17
+ metadata: 'Map(String, String)';
18
+ tags: 'Array(String)';
19
+ settings: 'Map(LowCardinality(String), String)';
20
+ optional_name: 'Nullable(String)';
21
+ categories: 'Array(LowCardinality(String))';
22
+ feature_flags: 'Array(Map(LowCardinality(String), String))';
23
+ optional_tags: 'Nullable(Array(String))';
24
+ permissions: 'Map(String, Array(String))';
25
+ created_timestamp: 'DateTime64(9)';
26
+ };
27
+ export type UsersSchema = {
28
+ id: 'Int32';
29
+ user_name: 'String';
30
+ email: 'String';
31
+ created_at: 'Date';
32
+ profile: 'Map(String, String)';
33
+ preferences: 'Nullable(Map(LowCardinality(String), String))';
34
+ roles: 'Array(LowCardinality(String))';
35
+ is_active: 'Bool';
36
+ };
37
+ export interface TestSchema {
38
+ test_table: TestTableSchema;
39
+ users: UsersSchema;
40
+ }
41
+ export declare const TEST_SCHEMAS: TestSchema;
42
+ export declare function setupUsersBuilder(): SelectQB<TestSchema, 'users', TableRecord<TestSchema['users']>, 'users'>;
43
+ export declare function setupTestBuilder(): SelectQB<TestSchema, 'test_table', TableRecord<TestSchema['test_table']>, 'test_table'>;
44
+ //# sourceMappingURL=test-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tests/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,QAAQ,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;IAEnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,qCAAqC,CAAC;IAChD,aAAa,EAAE,kBAAkB,CAAC;IAClC,UAAU,EAAE,+BAA+B,CAAC;IAC5C,aAAa,EAAE,4CAA4C,CAAC;IAC5D,aAAa,EAAE,yBAAyB,CAAC;IACzC,WAAW,EAAE,4BAA4B,CAAC;IAC1C,iBAAiB,EAAE,eAAe,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,QAAQ,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,WAAW,EAAE,+CAA+C,CAAC;IAC7D,KAAK,EAAE,+BAA+B,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,WAAW,CAAC;CACpB;AAED,eAAO,MAAM,YAAY,EAAE,UAmC1B,CAAC;AAoBF,wBAAgB,iBAAiB,IAAI,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAW5G;AAED,wBAAgB,gBAAgB,IAAI,QAAQ,CAAC,UAAU,EAAE,YAAY,EAAE,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,CAW1H"}
@@ -0,0 +1,65 @@
1
+ import { QueryBuilder } from '../query-builder.js';
2
+ import { buildRuntimeContext, resolveCacheConfig } from '../cache/runtime-context.js';
3
+ export const TEST_SCHEMAS = {
4
+ test_table: {
5
+ id: 'Int32',
6
+ name: 'String',
7
+ price: 'Float64',
8
+ created_at: 'Date',
9
+ category: 'String',
10
+ active: 'UInt8',
11
+ created_by: 'Int32',
12
+ updated_by: 'Int32',
13
+ status: 'String',
14
+ brand: 'String',
15
+ total: 'Int32',
16
+ priority: 'String',
17
+ is_premium: 'Bool',
18
+ metadata: 'Map(String, String)',
19
+ tags: 'Array(String)',
20
+ settings: 'Map(LowCardinality(String), String)',
21
+ optional_name: 'Nullable(String)',
22
+ categories: 'Array(LowCardinality(String))',
23
+ feature_flags: 'Array(Map(LowCardinality(String), String))',
24
+ optional_tags: 'Nullable(Array(String))',
25
+ permissions: 'Map(String, Array(String))',
26
+ created_timestamp: 'DateTime64(9)',
27
+ },
28
+ users: {
29
+ id: 'Int32',
30
+ user_name: 'String',
31
+ email: 'String',
32
+ created_at: 'Date',
33
+ profile: 'Map(String, String)',
34
+ preferences: 'Nullable(Map(LowCardinality(String), String))',
35
+ roles: 'Array(LowCardinality(String))',
36
+ is_active: 'Bool',
37
+ }
38
+ };
39
+ function createTestRuntime() {
40
+ return buildRuntimeContext(resolveCacheConfig(undefined, 'tests'));
41
+ }
42
+ export function setupUsersBuilder() {
43
+ const state = {
44
+ schema: TEST_SCHEMAS,
45
+ tables: 'users',
46
+ output: {},
47
+ baseTable: 'users',
48
+ base: TEST_SCHEMAS.users,
49
+ aliases: {},
50
+ scalars: {}
51
+ };
52
+ return new QueryBuilder('users', state, createTestRuntime());
53
+ }
54
+ export function setupTestBuilder() {
55
+ const state = {
56
+ schema: TEST_SCHEMAS,
57
+ tables: 'test_table',
58
+ output: {},
59
+ baseTable: 'test_table',
60
+ base: TEST_SCHEMAS.test_table,
61
+ aliases: {},
62
+ scalars: {}
63
+ };
64
+ return new QueryBuilder('test_table', state, createTestRuntime());
65
+ }