@hypequery/clickhouse 1.4.0 → 1.6.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/LICENSE +201 -0
- package/README.md +1 -1
- package/dist/cli/generate-types.js +1 -1
- package/dist/core/cache/types.d.ts +2 -2
- package/dist/core/features/analytics.d.ts +19 -0
- package/dist/core/features/analytics.d.ts.map +1 -1
- package/dist/core/features/analytics.js +9 -0
- package/dist/core/query-builder.d.ts +5 -15
- package/dist/core/query-builder.d.ts.map +1 -1
- package/dist/core/query-builder.js +31 -22
- package/dist/core/tests/integration/setup.d.ts +1 -0
- package/dist/core/tests/integration/setup.d.ts.map +1 -1
- package/dist/core/tests/integration/setup.js +2 -1
- package/dist/core/tests/test-utils.d.ts.map +1 -1
- package/dist/core/tests/test-utils.js +4 -2
- package/dist/core/types/builder-state.d.ts +7 -5
- package/dist/core/types/builder-state.d.ts.map +1 -1
- package/dist/core/types/select-types.d.ts +3 -2
- package/dist/core/types/select-types.d.ts.map +1 -1
- package/dist/core/utils/predicate-builder.d.ts +4 -0
- package/dist/core/utils/predicate-builder.d.ts.map +1 -1
- package/dist/core/utils/predicate-builder.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/base.d.ts +0 -22
- package/dist/types/base.d.ts.map +1 -1
- package/dist/types/clickhouse-types.d.ts +1 -1
- package/dist/types/clickhouse-types.d.ts.map +1 -1
- package/package.json +26 -30
- package/dist/core/features/pagination.d.ts +0 -21
- package/dist/core/features/pagination.d.ts.map +0 -1
- package/dist/core/features/pagination.js +0 -165
- package/dist/core/tests/integration/pagination-test-tbc.d.ts +0 -2
- package/dist/core/tests/integration/pagination-test-tbc.d.ts.map +0 -1
- package/dist/core/tests/integration/pagination-test-tbc.js +0 -190
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are advised to review the applicable
|
|
150
|
+
documentation for the specific language governing permissions and
|
|
151
|
+
limitations under each license.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 hypequery
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -263,7 +263,7 @@ Run the fast feedback loop with:
|
|
|
263
263
|
npm run test
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
-
This command runs type checks + unit tests only. To exercise the ClickHouse-backed integration suite,
|
|
266
|
+
This command runs type checks + unit tests only. To exercise the ClickHouse-backed integration suite, copy `.env.test.example` to `.env.test`, point it at a ClickHouse instance, and run:
|
|
267
267
|
|
|
268
268
|
```bash
|
|
269
269
|
npm run test:integration
|
|
@@ -193,7 +193,7 @@ export interface IntrospectedSchema {`;
|
|
|
193
193
|
*
|
|
194
194
|
* // Now you have full type safety and autocomplete
|
|
195
195
|
* const results = await db
|
|
196
|
-
* .
|
|
196
|
+
* .table('${tables.length > 0 ? tables[0].name : 'table_name'}')
|
|
197
197
|
* .select(['column1', 'column2'])
|
|
198
198
|
* .where('column1', 'eq', 'value')
|
|
199
199
|
* .execute();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type hypequeryCacheMode = 'no-store' | 'cache-first' | 'network-first' | 'stale-while-revalidate';
|
|
2
2
|
export interface CacheSerializationResult {
|
|
3
3
|
payload: string | Uint8Array;
|
|
4
4
|
byteSize: number;
|
|
@@ -7,7 +7,7 @@ export type CacheSerializeFn = (value: unknown) => CacheSerializationResult | Pr
|
|
|
7
7
|
export type CacheDeserializeFn<T = unknown> = (raw: string | Uint8Array) => T | Promise<T>;
|
|
8
8
|
export type CacheStatus = 'hit' | 'miss' | 'stale-hit' | 'revalidate' | 'bypass';
|
|
9
9
|
export interface CacheOptions {
|
|
10
|
-
mode?:
|
|
10
|
+
mode?: hypequeryCacheMode;
|
|
11
11
|
ttlMs?: number;
|
|
12
12
|
staleTtlMs?: number;
|
|
13
13
|
cacheTimeMs?: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ClickHouseSettings } from '@clickhouse/client-common';
|
|
2
2
|
import type { AnyBuilderState, BuilderState, SchemaDefinition } from '../types/builder-state.js';
|
|
3
3
|
import { QueryBuilder } from '../query-builder.js';
|
|
4
|
+
import type { PredicateExpression } from '../utils/predicate-builder.js';
|
|
4
5
|
export declare class AnalyticsFeature<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>> {
|
|
5
6
|
private builder;
|
|
6
7
|
constructor(builder: QueryBuilder<Schema, State>);
|
|
@@ -22,6 +23,24 @@ export declare class AnalyticsFeature<Schema extends SchemaDefinition<Schema>, S
|
|
|
22
23
|
unionQueries?: string[];
|
|
23
24
|
settings?: string;
|
|
24
25
|
};
|
|
26
|
+
addScalar(alias: string, expression: PredicateExpression): {
|
|
27
|
+
ctes: string[];
|
|
28
|
+
select?: (string | keyof State["output"])[] | undefined;
|
|
29
|
+
where?: import("../../types/base.js").WhereCondition[];
|
|
30
|
+
groupBy?: string[];
|
|
31
|
+
having?: string[];
|
|
32
|
+
limit?: number;
|
|
33
|
+
offset?: number;
|
|
34
|
+
distinct?: boolean;
|
|
35
|
+
orderBy?: {
|
|
36
|
+
column: keyof State["output"] | import("../../index.js").TableColumn<Schema>;
|
|
37
|
+
direction: import("../../index.js").OrderDirection;
|
|
38
|
+
}[] | undefined;
|
|
39
|
+
joins?: import("../../types/base.js").JoinClause[];
|
|
40
|
+
parameters?: any[];
|
|
41
|
+
unionQueries?: string[];
|
|
42
|
+
settings?: string;
|
|
43
|
+
};
|
|
25
44
|
addTimeInterval(column: string, interval: string, method: 'toStartOfInterval' | 'toStartOfMinute' | 'toStartOfHour' | 'toStartOfDay' | 'toStartOfWeek' | 'toStartOfMonth' | 'toStartOfQuarter' | 'toStartOfYear'): {
|
|
26
45
|
groupBy: string[];
|
|
27
46
|
select?: (string | keyof State["output"])[] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../src/core/features/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../../src/core/features/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAGzE,qBAAa,gBAAgB,CAC3B,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACvC,KAAK,SAAS,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAExD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,CAAC,GAAG,EAAE,eAAe,CAAC,GAAG,MAAM;;;;;;;;;;;;;;;;;;IAS3E,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;IASxD,eAAe,CACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,mBAAmB,GAAG,iBAAiB,GAAG,eAAe,GAAG,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,eAAe;;;;;;;;;;;;;;;;;;IAiBhK,WAAW,CAAC,IAAI,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;CAQrC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { substituteParameters } from '../utils.js';
|
|
1
2
|
export class AnalyticsFeature {
|
|
2
3
|
builder;
|
|
3
4
|
constructor(builder) {
|
|
@@ -11,6 +12,14 @@ export class AnalyticsFeature {
|
|
|
11
12
|
ctes: [...(config.ctes || []), `${alias} AS (${cte})`]
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
addScalar(alias, expression) {
|
|
16
|
+
const config = this.builder.getConfig();
|
|
17
|
+
const scalarExpression = substituteParameters(expression.sql, expression.parameters);
|
|
18
|
+
return {
|
|
19
|
+
...config,
|
|
20
|
+
ctes: [...(config.ctes || []), `${scalarExpression} AS ${alias}`]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
14
23
|
addTimeInterval(column, interval, method) {
|
|
15
24
|
const config = this.builder.getConfig();
|
|
16
25
|
const groupBy = config.groupBy || [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CrossFilter } from './cross-filter.js';
|
|
2
|
-
import { FilterOperator, OperatorValueMap, OrderDirection,
|
|
2
|
+
import { FilterOperator, OperatorValueMap, OrderDirection, QueryConfig } from '../types/index.js';
|
|
3
3
|
import { AnySchema } from '../types/schema.js';
|
|
4
4
|
import { SQLFormatter } from './formatters/sql-formatter.js';
|
|
5
5
|
import { ExecutorFeature } from './features/executor.js';
|
|
@@ -10,11 +10,12 @@ import type { ClickHouseClient as NodeClickHouseClient } from '@clickhouse/clien
|
|
|
10
10
|
import type { ClickHouseClient as WebClickHouseClient } from '@clickhouse/client-web';
|
|
11
11
|
import type { CacheOptions, CacheConfig } from './cache/types.js';
|
|
12
12
|
import type { QueryRuntimeContext } from './cache/runtime-context.js';
|
|
13
|
-
import type { BuilderState, AnyBuilderState, SchemaDefinition, InitialState, UpdateOutput, WidenTables, AppendToOutput, BaseRow, AddAlias } from './types/builder-state.js';
|
|
13
|
+
import type { BuilderState, AnyBuilderState, SchemaDefinition, InitialState, UpdateOutput, WidenTables, AppendToOutput, BaseRow, AddAlias, AddScalar } from './types/builder-state.js';
|
|
14
14
|
import { SelectableItem, SelectableColumn, SelectionResult, ColumnSelectionValue } from './types/select-types.js';
|
|
15
15
|
type WhereColumn<State extends AnyBuilderState> = SelectableColumn<State>;
|
|
16
16
|
type ColumnOperatorValue<Schema extends SchemaDefinition<Schema>, State extends BuilderState<Schema, string, any, keyof Schema, Partial<Record<string, keyof Schema>>>, Column extends WhereColumn<State>, Op extends keyof OperatorValueMap<any, Schema>> = OperatorValueMap<ColumnSelectionValue<State, Column>, Schema>[Op];
|
|
17
17
|
type ClickHouseClient = NodeClickHouseClient | WebClickHouseClient;
|
|
18
|
+
type ScalarAlias<Alias extends string> = Alias extends `${string} ${string}` ? never : Alias;
|
|
18
19
|
export interface ExecuteOptions {
|
|
19
20
|
queryId?: string;
|
|
20
21
|
cache?: CacheOptions | false;
|
|
@@ -51,7 +52,6 @@ export declare class QueryBuilder<Schema extends SchemaDefinition<Schema>, State
|
|
|
51
52
|
private analytics;
|
|
52
53
|
private executor;
|
|
53
54
|
private modifiers;
|
|
54
|
-
private pagination;
|
|
55
55
|
private crossFiltering;
|
|
56
56
|
private runtime;
|
|
57
57
|
private cacheOptions?;
|
|
@@ -60,6 +60,7 @@ export declare class QueryBuilder<Schema extends SchemaDefinition<Schema>, State
|
|
|
60
60
|
debug(): this;
|
|
61
61
|
cache(options: CacheOptions | false): this;
|
|
62
62
|
withCTE(alias: string, subquery: QueryBuilder<any, AnyBuilderState> | string): this;
|
|
63
|
+
withScalar<Alias extends string, TValue>(alias: ScalarAlias<Alias>, expressionBuilder: (expr: PredicateBuilder<State>) => PredicateExpression<TValue>): QueryBuilder<Schema, AddScalar<State, Alias, TValue>>;
|
|
63
64
|
/**
|
|
64
65
|
* Groups results by a time interval using a specified ClickHouse function.
|
|
65
66
|
*
|
|
@@ -216,18 +217,6 @@ export declare class QueryBuilder<Schema extends SchemaDefinition<Schema>, State
|
|
|
216
217
|
fullJoin<TableName extends Extract<keyof Schema, string>, Alias extends string | undefined = undefined>(table: TableName, leftColumn: keyof BaseRow<State>, rightColumn: `${TableName & string}.${keyof Schema[TableName] & string}`, alias?: Alias): QueryBuilder<Schema, Alias extends string ? AddAlias<WidenTables<State, TableName>, Alias, TableName> : WidenTables<State, TableName>>;
|
|
217
218
|
private applyJoin;
|
|
218
219
|
getConfig(): QueryConfig<State["output"], Schema>;
|
|
219
|
-
/**
|
|
220
|
-
* Paginates the query results using cursor-based pagination
|
|
221
|
-
*/
|
|
222
|
-
paginate(options: PaginationOptions<State['output']>): Promise<PaginatedResult<State['output']>>;
|
|
223
|
-
/**
|
|
224
|
-
* Gets the first page of results
|
|
225
|
-
*/
|
|
226
|
-
firstPage(pageSize: number): Promise<PaginatedResult<State['output']>>;
|
|
227
|
-
/**
|
|
228
|
-
* Returns an async iterator that yields all pages
|
|
229
|
-
*/
|
|
230
|
-
iteratePages(pageSize: number): AsyncGenerator<PaginatedResult<State['output']>>;
|
|
231
220
|
static setJoinRelationships<S extends SchemaDefinition<S>>(relationships: JoinRelationships<S>): void;
|
|
232
221
|
/**
|
|
233
222
|
* Apply a predefined join relationship
|
|
@@ -240,6 +229,7 @@ export type CreateQueryBuilderConfig = ClickHouseConfig & {
|
|
|
240
229
|
};
|
|
241
230
|
export declare function createQueryBuilder<Schema extends SchemaDefinition<Schema>>(config: CreateQueryBuilderConfig): {
|
|
242
231
|
cache: import("./cache/controller.js").CacheController;
|
|
232
|
+
rawQuery<TResult = any>(sql: string, params?: unknown[]): Promise<TResult[][]>;
|
|
243
233
|
table<TableName extends Extract<keyof Schema, string>>(tableName: TableName): SelectQB<Schema, TableName, InitialState<Schema, TableName>["output"], TableName>;
|
|
244
234
|
};
|
|
245
235
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/core/query-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/core/query-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,WAAW,EAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAc,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAK7D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAiB,MAAM,yBAAyB,CAAC;AAE5F,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EAEpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAAiC,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,KAAK,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAItE,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,cAAc,EACd,OAAO,EACP,QAAQ,EACR,SAA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SAAS,MAAM,EACrB,MAAM,EACN,SAAS,SAAS,MAAM,MAAM,IAC5B,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;AAE9E,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IACxD,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAYF,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EACxE,MAAM,EAAE,wBAAwB;;aAUf,OAAO,aAAa,MAAM,WAAU,OAAO,EAAE;UAStD,SAAS,SAAS,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,SAAS,GAAG,QAAQ,CACpF,MAAM,EACN,SAAS,EACT,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,EACzC,SAAS,CACV;EAcJ"}
|
|
@@ -7,10 +7,10 @@ import { AnalyticsFeature } from './features/analytics.js';
|
|
|
7
7
|
import { ExecutorFeature } from './features/executor.js';
|
|
8
8
|
import { QueryModifiersFeature } from './features/query-modifiers.js';
|
|
9
9
|
import { FilterValidator } from './validators/filter-validator.js';
|
|
10
|
-
import { PaginationFeature } from './features/pagination.js';
|
|
11
10
|
import { createPredicateBuilder, } from './utils/predicate-builder.js';
|
|
12
11
|
import { CrossFilteringFeature } from './features/cross-filtering.js';
|
|
13
12
|
import { executeWithCache } from './cache/cache-manager.js';
|
|
13
|
+
import { substituteParameters } from './utils.js';
|
|
14
14
|
import { mergeCacheOptionsPartial, initializeCacheRuntime } from './cache/utils.js';
|
|
15
15
|
/**
|
|
16
16
|
* Type guard to check if a config is a client-based configuration.
|
|
@@ -34,7 +34,6 @@ export class QueryBuilder {
|
|
|
34
34
|
analytics;
|
|
35
35
|
executor;
|
|
36
36
|
modifiers;
|
|
37
|
-
pagination;
|
|
38
37
|
crossFiltering;
|
|
39
38
|
runtime;
|
|
40
39
|
cacheOptions;
|
|
@@ -48,7 +47,6 @@ export class QueryBuilder {
|
|
|
48
47
|
this.analytics = new AnalyticsFeature(this);
|
|
49
48
|
this.executor = new ExecutorFeature(this);
|
|
50
49
|
this.modifiers = new QueryModifiersFeature(this);
|
|
51
|
-
this.pagination = new PaginationFeature(this);
|
|
52
50
|
this.crossFiltering = new CrossFilteringFeature(this);
|
|
53
51
|
}
|
|
54
52
|
fork(state, config) {
|
|
@@ -77,6 +75,25 @@ export class QueryBuilder {
|
|
|
77
75
|
this.config = this.analytics.addCTE(alias, subquery);
|
|
78
76
|
return this;
|
|
79
77
|
}
|
|
78
|
+
// --- Analytics Helper: Add a scalar WITH alias.
|
|
79
|
+
withScalar(alias, expressionBuilder) {
|
|
80
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(alias)) {
|
|
81
|
+
throw new Error(`Invalid scalar alias "${alias}". Use an unquoted SQL identifier (letters, numbers, underscore; cannot start with a number).`);
|
|
82
|
+
}
|
|
83
|
+
const expression = expressionBuilder(createPredicateBuilder());
|
|
84
|
+
const nextConfig = this.analytics.addScalar(alias, expression);
|
|
85
|
+
const nextState = {
|
|
86
|
+
...this.state,
|
|
87
|
+
scalars: {
|
|
88
|
+
...this.state.scalars,
|
|
89
|
+
[alias]: undefined,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
const builder = new QueryBuilder(this.tableName, nextState, this.runtime);
|
|
93
|
+
builder.config = { ...nextConfig };
|
|
94
|
+
builder.cacheOptions = this.cacheOptions;
|
|
95
|
+
return builder;
|
|
96
|
+
}
|
|
80
97
|
/**
|
|
81
98
|
* Groups results by a time interval using a specified ClickHouse function.
|
|
82
99
|
*
|
|
@@ -406,24 +423,6 @@ export class QueryBuilder {
|
|
|
406
423
|
getConfig() {
|
|
407
424
|
return this.config;
|
|
408
425
|
}
|
|
409
|
-
/**
|
|
410
|
-
* Paginates the query results using cursor-based pagination
|
|
411
|
-
*/
|
|
412
|
-
async paginate(options) {
|
|
413
|
-
return this.pagination.paginate(options);
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Gets the first page of results
|
|
417
|
-
*/
|
|
418
|
-
async firstPage(pageSize) {
|
|
419
|
-
return this.pagination.firstPage(pageSize);
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Returns an async iterator that yields all pages
|
|
423
|
-
*/
|
|
424
|
-
iteratePages(pageSize) {
|
|
425
|
-
return this.pagination.iteratePages(pageSize);
|
|
426
|
-
}
|
|
427
426
|
static setJoinRelationships(relationships) {
|
|
428
427
|
this.relationships = relationships;
|
|
429
428
|
}
|
|
@@ -471,6 +470,15 @@ export function createQueryBuilder(config) {
|
|
|
471
470
|
const { runtime, cacheController } = initializeCacheRuntime(cacheConfig, namespace);
|
|
472
471
|
return {
|
|
473
472
|
cache: cacheController,
|
|
473
|
+
async rawQuery(sql, params = []) {
|
|
474
|
+
const client = ClickHouseConnection.getClient();
|
|
475
|
+
const finalSQL = substituteParameters(sql, params);
|
|
476
|
+
const result = await client.query({
|
|
477
|
+
query: finalSQL,
|
|
478
|
+
format: 'JSONEachRow'
|
|
479
|
+
});
|
|
480
|
+
return result.json();
|
|
481
|
+
},
|
|
474
482
|
table(tableName) {
|
|
475
483
|
const state = {
|
|
476
484
|
schema: {},
|
|
@@ -478,7 +486,8 @@ export function createQueryBuilder(config) {
|
|
|
478
486
|
output: {},
|
|
479
487
|
baseTable: tableName,
|
|
480
488
|
base: {},
|
|
481
|
-
aliases: {}
|
|
489
|
+
aliases: {},
|
|
490
|
+
scalars: {}
|
|
482
491
|
};
|
|
483
492
|
return new QueryBuilder(tableName, state, runtime);
|
|
484
493
|
}
|
|
@@ -6,6 +6,7 @@ export declare const TEST_CONNECTION_CONFIG: {
|
|
|
6
6
|
};
|
|
7
7
|
export declare const initializeTestConnection: () => Promise<{
|
|
8
8
|
cache: import("../../cache/controller.js").CacheController;
|
|
9
|
+
rawQuery<TResult = any>(sql: string, params?: unknown[]): Promise<TResult[][]>;
|
|
9
10
|
table<TableName extends never>(tableName: TableName): import("../../query-builder.js").SelectQB<import("../../types/builder-state.js").SchemaDefinition<unknown>, TableName, import("../../../index.js").TableRecord<import("../../types/builder-state.js").SchemaDefinition<unknown>[TableName]>, TableName>;
|
|
10
11
|
}>;
|
|
11
12
|
export declare const ensureConnectionInitialized: () => import("@clickhouse/client").ClickHouseClient | import("@clickhouse/client-web").ClickHouseClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/setup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../../src/core/tests/integration/setup.ts"],"names":[],"mappings":"AAgDA,eAAO,MAAM,sBAAsB;;;;;CAAS,CAAC;AAG7C,eAAO,MAAM,wBAAwB;;;;EAyBpC,CAAC;AAGF,eAAO,MAAM,2BAA2B,yGAevC,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,OAAO,CAOzD,CAAC;AAGF,eAAO,MAAM,wBAAwB,QAAa,OAAO,CAAC,OAAO,CAahE,CAAC;AAGF,eAAO,MAAM,kBAAkB,GAAU,eAAe,MAAM,KAAG,OAAO,CAAC,OAAO,CAO/E,CAAC;AAGF,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,OAAO,CAQzD,CAAC;AAGF,eAAO,MAAM,wBAAwB,QAAa,OAAO,CAAC,IAAI,CAwC7D,CAAC;AAGF,eAAO,MAAM,iBAAiB,GAC5B,oBAAgB,EAChB,sBAAoB,KACnB,OAAO,CAAC,IAAI,CAad,CAAC;AAGF,eAAO,MAAM,uBAAuB,QAAa,OAAO,CAAC,IAAI,CA0B5D,CAAC;AAGF,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,KAAK,CAAC;QAChB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC,CAAC;IACH,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;IACH,MAAM,EAAE,KAAK,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ;AAkDD,eAAO,MAAM,SAAS,EAAE,cAAoC,CAAC;AAK7D,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,IAAI,CAkGtD,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { ClickHouseConnection } from '../../connection.js';
|
|
|
4
4
|
import { exec } from 'child_process';
|
|
5
5
|
import { promisify } from 'util';
|
|
6
6
|
import { logger as hypeQueryLogger } from '../../utils/logger.js';
|
|
7
|
-
|
|
7
|
+
// @ts-expect-error: raw JSON import for supplying fixture data
|
|
8
8
|
import rawTestData from './test-data.json';
|
|
9
9
|
// Disable the hypequery logger to prevent "logs after tests" errors
|
|
10
10
|
// This must be done early in the setup, before any queries run
|
|
@@ -13,6 +13,7 @@ hypeQueryLogger.configure({ enabled: false });
|
|
|
13
13
|
const logger = {
|
|
14
14
|
info: (message, ...args) => {
|
|
15
15
|
if (process.env.DEBUG === 'true') {
|
|
16
|
+
console.info(`[INFO] ${message}`, ...args);
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
19
|
error: (message, ...args) => {
|
|
@@ -1 +1 @@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AG;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"}
|
|
@@ -46,7 +46,8 @@ export function setupUsersBuilder() {
|
|
|
46
46
|
output: {},
|
|
47
47
|
baseTable: 'users',
|
|
48
48
|
base: TEST_SCHEMAS.users,
|
|
49
|
-
aliases: {}
|
|
49
|
+
aliases: {},
|
|
50
|
+
scalars: {}
|
|
50
51
|
};
|
|
51
52
|
return new QueryBuilder('users', state, createTestRuntime());
|
|
52
53
|
}
|
|
@@ -57,7 +58,8 @@ export function setupTestBuilder() {
|
|
|
57
58
|
output: {},
|
|
58
59
|
baseTable: 'test_table',
|
|
59
60
|
base: TEST_SCHEMAS.test_table,
|
|
60
|
-
aliases: {}
|
|
61
|
+
aliases: {},
|
|
62
|
+
scalars: {}
|
|
61
63
|
};
|
|
62
64
|
return new QueryBuilder('test_table', state, createTestRuntime());
|
|
63
65
|
}
|
|
@@ -3,23 +3,25 @@ import type { Simplify } from './type-helpers.js';
|
|
|
3
3
|
export type SchemaDefinition<Schema extends Record<string, any> = Record<string, any>> = {
|
|
4
4
|
[K in keyof Schema]: Record<string, ColumnType>;
|
|
5
5
|
};
|
|
6
|
-
export type BuilderState<Schema extends SchemaDefinition<Schema>, VisibleTables extends string, OutputRow, BaseTable extends keyof Schema, Aliases extends Partial<Record<string, keyof Schema>> = {}> = {
|
|
6
|
+
export type BuilderState<Schema extends SchemaDefinition<Schema>, VisibleTables extends string, OutputRow, BaseTable extends keyof Schema, Aliases extends Partial<Record<string, keyof Schema>> = {}, Scalars extends Record<string, unknown> = {}> = {
|
|
7
7
|
schema: Schema;
|
|
8
8
|
tables: VisibleTables;
|
|
9
9
|
output: OutputRow;
|
|
10
10
|
baseTable: BaseTable;
|
|
11
11
|
base: Schema[BaseTable];
|
|
12
12
|
aliases: Aliases;
|
|
13
|
+
scalars: Scalars;
|
|
13
14
|
};
|
|
14
15
|
export type AnyBuilderState = BuilderState<any, any, any, any, any>;
|
|
15
16
|
export type BaseRow<State extends AnyBuilderState> = Simplify<{
|
|
16
17
|
[K in keyof State['base']]: State['base'][K] extends ColumnType ? InferColumnType<State['base'][K]> : never;
|
|
17
18
|
}>;
|
|
18
|
-
export type WidenTables<State extends AnyBuilderState, Table extends keyof State['schema']> = BuilderState<State['schema'], State['tables'] | (Table & string), State['output'], State['baseTable'], State['aliases']>;
|
|
19
|
-
export type UpdateOutput<State extends AnyBuilderState, Output> = BuilderState<State['schema'], State['tables'], Output, State['baseTable'], State['aliases']>;
|
|
20
|
-
export type InitialState<Schema extends SchemaDefinition<Schema>, Table extends keyof Schema> = BuilderState<Schema, Table & string, TableRecord<Schema[Table]>, Table, {}>;
|
|
19
|
+
export type WidenTables<State extends AnyBuilderState, Table extends keyof State['schema']> = BuilderState<State['schema'], State['tables'] | (Table & string), State['output'], State['baseTable'], State['aliases'], State['scalars']>;
|
|
20
|
+
export type UpdateOutput<State extends AnyBuilderState, Output> = BuilderState<State['schema'], State['tables'], Output, State['baseTable'], State['aliases'], State['scalars']>;
|
|
21
|
+
export type InitialState<Schema extends SchemaDefinition<Schema>, Table extends keyof Schema> = BuilderState<Schema, Table & string, TableRecord<Schema[Table]>, Table, {}, {}>;
|
|
21
22
|
export type ExplicitSelectionState<State extends AnyBuilderState> = BaseRow<State> extends State['output'] ? State['output'] extends BaseRow<State> ? false : true : true;
|
|
22
23
|
export type AppendToOutput<State extends AnyBuilderState, Added> = UpdateOutput<State, ExplicitSelectionState<State> extends true ? Simplify<State['output'] & Added> : Simplify<Added>>;
|
|
23
|
-
export type AddAlias<State extends AnyBuilderState, Alias extends string, Table extends keyof State['schema']> = BuilderState<State['schema'], State['tables'] | Alias, State['output'], State['baseTable'], State['aliases'] & Record<Alias, Table
|
|
24
|
+
export type AddAlias<State extends AnyBuilderState, Alias extends string, Table extends keyof State['schema']> = BuilderState<State['schema'], State['tables'] | Alias, State['output'], State['baseTable'], State['aliases'] & Record<Alias, Table>, State['scalars']>;
|
|
25
|
+
export type AddScalar<State extends AnyBuilderState, Alias extends string, Value> = BuilderState<State['schema'], State['tables'], State['output'], State['baseTable'], State['aliases'], State['scalars'] & Record<Alias, Value>>;
|
|
24
26
|
export type ResolveTableSchema<State extends AnyBuilderState, Table extends string> = Table extends keyof State['schema'] ? State['schema'][Table] : Table extends keyof State['aliases'] ? State['schema'][State['aliases'][Table]] : never;
|
|
25
27
|
//# sourceMappingURL=builder-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder-state.d.ts","sourceRoot":"","sources":["../../../src/core/types/builder-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAA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