@query-graph/core 1.0.0-next.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/LICENSE +21 -0
- package/README.md +620 -0
- package/definition.d.ts +87 -0
- package/definition.js +112 -0
- package/dsl.d.ts +687 -0
- package/dsl.js +742 -0
- package/index.d.ts +60 -0
- package/index.js +562 -0
- package/package.json +143 -0
package/dsl.d.ts
ADDED
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
export type ScalarType =
|
|
2
|
+
| 'boolean'
|
|
3
|
+
| 'int32'
|
|
4
|
+
| 'int64'
|
|
5
|
+
| 'float64'
|
|
6
|
+
| 'decimal'
|
|
7
|
+
| 'string'
|
|
8
|
+
| 'date'
|
|
9
|
+
| 'dateTime'
|
|
10
|
+
| 'binary'
|
|
11
|
+
| 'json'
|
|
12
|
+
|
|
13
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | { readonly [key: string]: JsonValue }
|
|
14
|
+
|
|
15
|
+
export type ScalarParameterValue<Type extends ScalarType> = Type extends 'boolean'
|
|
16
|
+
? boolean
|
|
17
|
+
: Type extends 'int32' | 'float64'
|
|
18
|
+
? number
|
|
19
|
+
: Type extends 'int64' | 'decimal'
|
|
20
|
+
? number | string
|
|
21
|
+
: Type extends 'string' | 'date' | 'dateTime' | 'binary'
|
|
22
|
+
? string
|
|
23
|
+
: Type extends 'json'
|
|
24
|
+
? JsonValue
|
|
25
|
+
: never
|
|
26
|
+
|
|
27
|
+
export type ParameterShape = 'scalar' | 'list'
|
|
28
|
+
export type RelationCardinality = 'one' | 'many'
|
|
29
|
+
export type OrderDirection = 'asc' | 'desc'
|
|
30
|
+
export type NullsOrder = 'first' | 'last'
|
|
31
|
+
export type SemanticFunctionName = 'lower' | 'upper' | 'coalesce' | 'concat'
|
|
32
|
+
export type AggregateFunctionName = 'count' | 'countDistinct' | 'sum' | 'average' | 'minimum' | 'maximum'
|
|
33
|
+
export type ProjectionFieldRole = 'value' | 'dimension' | 'measure'
|
|
34
|
+
|
|
35
|
+
export interface FieldDefinition {
|
|
36
|
+
name: string
|
|
37
|
+
scalarType: ScalarType
|
|
38
|
+
nullable?: boolean
|
|
39
|
+
selectable?: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SourceDefinition {
|
|
43
|
+
key: string
|
|
44
|
+
fields: FieldDefinition[]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ParameterDefinition {
|
|
48
|
+
name: string
|
|
49
|
+
scalarType: ScalarType
|
|
50
|
+
shape?: ParameterShape
|
|
51
|
+
required?: boolean
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface FieldExpression<Source extends string = string, Field extends string = string> {
|
|
55
|
+
kind: 'field'
|
|
56
|
+
source: Source
|
|
57
|
+
field: Field
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ParameterExpression<Name extends string = string> {
|
|
61
|
+
kind: 'parameter'
|
|
62
|
+
name: Name
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type LiteralValue =
|
|
66
|
+
| { kind: 'null' }
|
|
67
|
+
| { kind: 'boolean'; value: boolean }
|
|
68
|
+
| { kind: 'integer'; value: number }
|
|
69
|
+
| { kind: 'decimal'; value: string }
|
|
70
|
+
| { kind: 'string'; value: string }
|
|
71
|
+
|
|
72
|
+
export interface LiteralExpression {
|
|
73
|
+
kind: 'literal'
|
|
74
|
+
value: LiteralValue
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type BinaryExpressionKind =
|
|
78
|
+
| 'eq'
|
|
79
|
+
| 'notEq'
|
|
80
|
+
| 'lessThan'
|
|
81
|
+
| 'lessThanOrEqual'
|
|
82
|
+
| 'greaterThan'
|
|
83
|
+
| 'greaterThanOrEqual'
|
|
84
|
+
|
|
85
|
+
export interface BinaryExpression {
|
|
86
|
+
kind: BinaryExpressionKind
|
|
87
|
+
left: Expression
|
|
88
|
+
right: Expression
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface LikeExpression {
|
|
92
|
+
kind: 'like'
|
|
93
|
+
expression: Expression
|
|
94
|
+
pattern: Expression
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface InExpression {
|
|
98
|
+
kind: 'in'
|
|
99
|
+
expression: Expression
|
|
100
|
+
values: Expression[]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface InParameterExpression<Name extends string = string> {
|
|
104
|
+
kind: 'inParameter'
|
|
105
|
+
expression: Expression
|
|
106
|
+
parameter: Name
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ExpressionGroup {
|
|
110
|
+
kind: 'and' | 'or'
|
|
111
|
+
expressions: Expression[]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface UnaryExpression {
|
|
115
|
+
kind: 'not' | 'isNull' | 'isNotNull'
|
|
116
|
+
expression: Expression
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ExistsExpression<Source extends string = string, From extends string = string> {
|
|
120
|
+
kind: 'exists'
|
|
121
|
+
source: Source
|
|
122
|
+
from?: From
|
|
123
|
+
predicate?: Expression
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface FunctionExpression {
|
|
127
|
+
kind: 'function'
|
|
128
|
+
name: SemanticFunctionName
|
|
129
|
+
arguments: Expression[]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface AggregateExpression {
|
|
133
|
+
kind: 'aggregate'
|
|
134
|
+
function: AggregateFunctionName
|
|
135
|
+
expression?: Expression
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type Expression =
|
|
139
|
+
| FieldExpression
|
|
140
|
+
| ParameterExpression
|
|
141
|
+
| LiteralExpression
|
|
142
|
+
| BinaryExpression
|
|
143
|
+
| LikeExpression
|
|
144
|
+
| InExpression
|
|
145
|
+
| InParameterExpression
|
|
146
|
+
| ExpressionGroup
|
|
147
|
+
| UnaryExpression
|
|
148
|
+
| ExistsExpression
|
|
149
|
+
| FunctionExpression
|
|
150
|
+
| AggregateExpression
|
|
151
|
+
|
|
152
|
+
export interface RelationDefinition {
|
|
153
|
+
name: string
|
|
154
|
+
from: string
|
|
155
|
+
to: string
|
|
156
|
+
cardinality?: RelationCardinality
|
|
157
|
+
required?: boolean
|
|
158
|
+
selection?: RelationSelection
|
|
159
|
+
on: Expression
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type ConstraintCondition = { kind: 'always' } | { kind: 'parameterPresent'; parameter: string }
|
|
163
|
+
|
|
164
|
+
export interface ConstraintDefinition {
|
|
165
|
+
when?: ConstraintCondition
|
|
166
|
+
predicate: Expression
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export type JoinProjectionPath<Segments extends readonly string[]> = number extends Segments['length']
|
|
170
|
+
? string
|
|
171
|
+
: Segments extends readonly []
|
|
172
|
+
? ''
|
|
173
|
+
: Segments extends readonly [infer Only extends string]
|
|
174
|
+
? Only
|
|
175
|
+
: Segments extends readonly [infer Head extends string, ...infer Tail extends readonly string[]]
|
|
176
|
+
? `${Head}.${JoinProjectionPath<Tail>}`
|
|
177
|
+
: string
|
|
178
|
+
|
|
179
|
+
declare const projectionPathType: unique symbol
|
|
180
|
+
declare const summaryFieldType: unique symbol
|
|
181
|
+
|
|
182
|
+
export interface ProjectionFieldDefinition<Path extends string = string> {
|
|
183
|
+
path: string[]
|
|
184
|
+
readonly [projectionPathType]?: Path
|
|
185
|
+
expression: Expression
|
|
186
|
+
role?: ProjectionFieldRole
|
|
187
|
+
selectedByDefault?: boolean
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface DimensionDefinition<Path extends string = string> extends ProjectionFieldDefinition<Path> {
|
|
191
|
+
readonly [summaryFieldType]: 'dimension'
|
|
192
|
+
role: 'dimension'
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface MeasureDefinition<Path extends string = string> extends ProjectionFieldDefinition<Path> {
|
|
196
|
+
readonly [summaryFieldType]: 'measure'
|
|
197
|
+
role: 'measure'
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type SummaryFieldDefinition<Path extends string = string> = DimensionDefinition<Path> | MeasureDefinition<Path>
|
|
201
|
+
|
|
202
|
+
export interface ProjectionDefinition<Path extends string = string> {
|
|
203
|
+
fields: ProjectionFieldDefinition<Path>[]
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface ProjectionDefinitionInput<Path extends string = string> {
|
|
207
|
+
fields?: ProjectionFieldDefinition<Path>[]
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface OrderByDefinition {
|
|
211
|
+
expression: Expression
|
|
212
|
+
direction: OrderDirection
|
|
213
|
+
nulls?: NullsOrder
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface OrderingDefinition<Name extends string = string> {
|
|
217
|
+
name: Name
|
|
218
|
+
orderBy: OrderByDefinition[]
|
|
219
|
+
default?: boolean
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface FirstBySelection {
|
|
223
|
+
kind: 'firstBy'
|
|
224
|
+
orderBy: OrderByDefinition[]
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export type RelationSelection = FirstBySelection
|
|
228
|
+
|
|
229
|
+
export interface GraphDefinitionInput {
|
|
230
|
+
schemaVersion: 9
|
|
231
|
+
name: string
|
|
232
|
+
root: string
|
|
233
|
+
sources: SourceDefinition[]
|
|
234
|
+
parameters?: ParameterDefinition[]
|
|
235
|
+
relations?: RelationDefinition[]
|
|
236
|
+
constraints?: ConstraintDefinition[]
|
|
237
|
+
projection?: ProjectionDefinitionInput
|
|
238
|
+
orderings?: OrderingDefinition[]
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface GraphDefinition<
|
|
242
|
+
Parameter extends ParameterDefinition = ParameterDefinition,
|
|
243
|
+
ProjectionPath extends string = string,
|
|
244
|
+
OrderingName extends string = string,
|
|
245
|
+
> extends GraphDefinitionInput {
|
|
246
|
+
parameters: Parameter[]
|
|
247
|
+
relations: RelationDefinition[]
|
|
248
|
+
constraints: ConstraintDefinition[]
|
|
249
|
+
projection: ProjectionDefinition<ProjectionPath>
|
|
250
|
+
orderings: OrderingDefinition<OrderingName>[]
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export type ExactGraphDefinitionInput<Definition extends GraphDefinitionInput> = Definition &
|
|
254
|
+
Record<Exclude<keyof Definition, keyof GraphDefinitionInput>, never>
|
|
255
|
+
|
|
256
|
+
export type TableName =
|
|
257
|
+
| string
|
|
258
|
+
| {
|
|
259
|
+
catalog?: string
|
|
260
|
+
schema?: string
|
|
261
|
+
name: string
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface SourceMapping {
|
|
265
|
+
table: TableName
|
|
266
|
+
columns?: Record<string, string>
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface RelationalMapping {
|
|
270
|
+
sources: Record<string, SourceMapping>
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface QueryOperationBase<SelectPath extends string = string, OrderingName extends string = string> {
|
|
274
|
+
select?: readonly SelectPath[]
|
|
275
|
+
ordering?: OrderingName
|
|
276
|
+
offset?: number
|
|
277
|
+
limit?: number
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export type DefinitionParameter<Definition extends GraphDefinitionInput> =
|
|
281
|
+
Definition extends GraphDefinition<infer Parameter, infer _ProjectionPath, infer _OrderingName>
|
|
282
|
+
? Parameter
|
|
283
|
+
: NonNullable<Definition['parameters']>[number]
|
|
284
|
+
|
|
285
|
+
export type DefinitionProjectionPath<Definition extends GraphDefinitionInput> =
|
|
286
|
+
Definition extends GraphDefinition<infer _Parameter, infer ProjectionPath, infer _OrderingName>
|
|
287
|
+
? ProjectionPath
|
|
288
|
+
: Definition['projection'] extends ProjectionDefinitionInput<infer ProjectionPath>
|
|
289
|
+
? ProjectionPath
|
|
290
|
+
: string
|
|
291
|
+
|
|
292
|
+
export type DefinitionOrderingName<Definition extends GraphDefinitionInput> =
|
|
293
|
+
Definition extends GraphDefinition<infer _Parameter, infer _ProjectionPath, infer OrderingName>
|
|
294
|
+
? OrderingName
|
|
295
|
+
: NonNullable<Definition['orderings']>[number] extends OrderingDefinition<infer OrderingName>
|
|
296
|
+
? OrderingName
|
|
297
|
+
: never
|
|
298
|
+
|
|
299
|
+
export type ParameterValue<Parameter extends ParameterDefinition> = Parameter extends { shape: 'list' }
|
|
300
|
+
? readonly ScalarParameterValue<Parameter['scalarType']>[]
|
|
301
|
+
: ScalarParameterValue<Parameter['scalarType']>
|
|
302
|
+
|
|
303
|
+
type RequiredParameter<Parameter extends ParameterDefinition> = Parameter extends unknown
|
|
304
|
+
? Parameter extends { required?: true }
|
|
305
|
+
? Parameter
|
|
306
|
+
: never
|
|
307
|
+
: never
|
|
308
|
+
|
|
309
|
+
type OptionalParameter<Parameter extends ParameterDefinition> = Parameter extends unknown
|
|
310
|
+
? Parameter extends { required?: true }
|
|
311
|
+
? never
|
|
312
|
+
: Parameter
|
|
313
|
+
: never
|
|
314
|
+
|
|
315
|
+
export type OperationParameters<Definition extends GraphDefinitionInput> = {
|
|
316
|
+
[Parameter in RequiredParameter<DefinitionParameter<Definition>> as Parameter['name']]-?: ParameterValue<Parameter>
|
|
317
|
+
} & {
|
|
318
|
+
[Parameter in OptionalParameter<DefinitionParameter<Definition>> as Parameter['name']]?: ParameterValue<Parameter>
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
type OperationParameterInput<Definition extends GraphDefinitionInput> = [DefinitionParameter<Definition>] extends [
|
|
322
|
+
never,
|
|
323
|
+
]
|
|
324
|
+
? { parameters?: never }
|
|
325
|
+
: [RequiredParameter<DefinitionParameter<Definition>>] extends [never]
|
|
326
|
+
? { parameters?: OperationParameters<Definition> }
|
|
327
|
+
: { parameters: OperationParameters<Definition> }
|
|
328
|
+
|
|
329
|
+
export type QueryOperation<Definition extends GraphDefinitionInput = GraphDefinitionInput> = QueryOperationBase<
|
|
330
|
+
DefinitionProjectionPath<Definition>,
|
|
331
|
+
DefinitionOrderingName<Definition>
|
|
332
|
+
> &
|
|
333
|
+
OperationParameterInput<Definition>
|
|
334
|
+
|
|
335
|
+
export interface QueryGraph<Definition extends GraphDefinitionInput = GraphDefinitionInput> {
|
|
336
|
+
readonly name: string
|
|
337
|
+
readonly root: string
|
|
338
|
+
readonly sourceCount: number
|
|
339
|
+
readonly relationCount: number
|
|
340
|
+
hasSource(source: string): boolean
|
|
341
|
+
hasField(source: string, field: string): boolean
|
|
342
|
+
hasParameter(parameter: string): boolean
|
|
343
|
+
hasRelation(relation: string): boolean
|
|
344
|
+
selectableFields(): Array<DefinitionProjectionPath<Definition>>
|
|
345
|
+
withRelationalMapping(mapping: RelationalMapping): RelationalQueryGraph<Definition>
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export interface RelationalQueryGraph<Definition extends GraphDefinitionInput = GraphDefinitionInput> {
|
|
349
|
+
readonly name: string
|
|
350
|
+
compileSqlServer(
|
|
351
|
+
operation: QueryOperation<Definition>,
|
|
352
|
+
options?: SqlServerCompileOptions,
|
|
353
|
+
): import('./index.js').CompiledSqlStatement
|
|
354
|
+
compileOracle(
|
|
355
|
+
operation: QueryOperation<Definition>,
|
|
356
|
+
options?: OracleCompileOptions,
|
|
357
|
+
): import('./index.js').CompiledSqlStatement
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export type SqlServerVersion = '2008' | '2012' | '2016' | '2019' | '2022'
|
|
361
|
+
export type OracleVersion = '11g' | '12c' | '19c' | '21c' | '23ai'
|
|
362
|
+
|
|
363
|
+
export interface SqlServerCompileOptions {
|
|
364
|
+
version?: SqlServerVersion
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface OracleCompileOptions {
|
|
368
|
+
version?: OracleVersion
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export type QueryGraphErrorPhase = 'definition' | 'mapping' | 'operation' | 'sql'
|
|
372
|
+
|
|
373
|
+
export interface QueryGraphDiagnostic {
|
|
374
|
+
code: string
|
|
375
|
+
location: string
|
|
376
|
+
message: string
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface QueryGraphError extends Error {
|
|
380
|
+
readonly name: 'QueryGraphError'
|
|
381
|
+
readonly code: string
|
|
382
|
+
readonly phase: QueryGraphErrorPhase
|
|
383
|
+
readonly issues: readonly QueryGraphDiagnostic[]
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface FieldSpecDefinition {
|
|
387
|
+
scalarType: ScalarType
|
|
388
|
+
nullable?: boolean
|
|
389
|
+
selectable?: boolean
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export type FieldSpec = ScalarType | FieldSpecDefinition
|
|
393
|
+
export type FieldSpecMap = Record<string, FieldSpec>
|
|
394
|
+
|
|
395
|
+
export interface SourceRef<Key extends string = string, Fields extends FieldSpecMap = FieldSpecMap>
|
|
396
|
+
extends SourceDefinition {
|
|
397
|
+
key: Key
|
|
398
|
+
field<Name extends Extract<keyof Fields, string>>(name: Name): FieldExpression<Key, Name>
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export interface ScalarParameterRef<
|
|
402
|
+
Name extends string = string,
|
|
403
|
+
Type extends ScalarType = ScalarType,
|
|
404
|
+
Required extends boolean = boolean,
|
|
405
|
+
> extends ParameterDefinition {
|
|
406
|
+
name: Name
|
|
407
|
+
scalarType: Type
|
|
408
|
+
shape?: 'scalar'
|
|
409
|
+
required?: Required
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export interface ListParameterRef<
|
|
413
|
+
Name extends string = string,
|
|
414
|
+
Type extends ScalarType = ScalarType,
|
|
415
|
+
Required extends boolean = boolean,
|
|
416
|
+
> extends ParameterDefinition {
|
|
417
|
+
name: Name
|
|
418
|
+
scalarType: Type
|
|
419
|
+
shape: 'list'
|
|
420
|
+
required?: Required
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export type ParameterRef<
|
|
424
|
+
Name extends string = string,
|
|
425
|
+
Type extends ScalarType = ScalarType,
|
|
426
|
+
Required extends boolean = boolean,
|
|
427
|
+
> = ScalarParameterRef<Name, Type, Required> | ListParameterRef<Name, Type, Required>
|
|
428
|
+
|
|
429
|
+
export interface RelationRef<Name extends string = string> extends RelationDefinition {
|
|
430
|
+
name: Name
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export type LiteralInput = null | boolean | string | number
|
|
434
|
+
export type ExpressionInput = Expression | LiteralInput | SummaryFieldDefinition
|
|
435
|
+
|
|
436
|
+
export interface FieldTypeOptions {
|
|
437
|
+
nullable?: boolean
|
|
438
|
+
selectable?: boolean
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function fieldType(scalarType: ScalarType, options?: FieldTypeOptions): FieldSpecDefinition
|
|
442
|
+
export function nullable(specification: FieldSpec): FieldSpecDefinition
|
|
443
|
+
export function hidden(specification: FieldSpec): FieldSpecDefinition
|
|
444
|
+
|
|
445
|
+
export function source<const Key extends string, const Fields extends FieldSpecMap>(
|
|
446
|
+
key: Key,
|
|
447
|
+
fields: Fields,
|
|
448
|
+
): SourceRef<Key, Fields>
|
|
449
|
+
|
|
450
|
+
export function requiredParameter<const Name extends string, const Type extends ScalarType>(
|
|
451
|
+
name: Name,
|
|
452
|
+
scalarType: Type,
|
|
453
|
+
): ScalarParameterRef<Name, Type, true>
|
|
454
|
+
export function optionalParameter<const Name extends string, const Type extends ScalarType>(
|
|
455
|
+
name: Name,
|
|
456
|
+
scalarType: Type,
|
|
457
|
+
): ScalarParameterRef<Name, Type, false>
|
|
458
|
+
export function requiredListParameter<const Name extends string, const Type extends ScalarType>(
|
|
459
|
+
name: Name,
|
|
460
|
+
scalarType: Type,
|
|
461
|
+
): ListParameterRef<Name, Type, true>
|
|
462
|
+
export function optionalListParameter<const Name extends string, const Type extends ScalarType>(
|
|
463
|
+
name: Name,
|
|
464
|
+
scalarType: Type,
|
|
465
|
+
): ListParameterRef<Name, Type, false>
|
|
466
|
+
export function param<const Name extends string, const Type extends ScalarType>(
|
|
467
|
+
parameter: ScalarParameterRef<Name, Type>,
|
|
468
|
+
): ParameterExpression<Name>
|
|
469
|
+
|
|
470
|
+
export function literal(value: LiteralInput): LiteralExpression
|
|
471
|
+
export function integer(value: number): LiteralExpression
|
|
472
|
+
export function decimal(value: string | number): LiteralExpression
|
|
473
|
+
|
|
474
|
+
export function eq(left: ExpressionInput, right: ExpressionInput): BinaryExpression
|
|
475
|
+
export function neq(left: ExpressionInput, right: ExpressionInput): BinaryExpression
|
|
476
|
+
export function lt(left: ExpressionInput, right: ExpressionInput): BinaryExpression
|
|
477
|
+
export function lte(left: ExpressionInput, right: ExpressionInput): BinaryExpression
|
|
478
|
+
export function gt(left: ExpressionInput, right: ExpressionInput): BinaryExpression
|
|
479
|
+
export function gte(left: ExpressionInput, right: ExpressionInput): BinaryExpression
|
|
480
|
+
export function like(expression: ExpressionInput, pattern: ExpressionInput): LikeExpression
|
|
481
|
+
export function inList(expression: ExpressionInput, values: readonly ExpressionInput[]): InExpression
|
|
482
|
+
export function and(...expressions: readonly ExpressionInput[]): ExpressionGroup
|
|
483
|
+
export function inParameter<const Name extends string, const Type extends ScalarType>(
|
|
484
|
+
expression: ExpressionInput,
|
|
485
|
+
parameter: ListParameterRef<Name, Type>,
|
|
486
|
+
): InParameterExpression<Name>
|
|
487
|
+
export function or(...expressions: readonly ExpressionInput[]): ExpressionGroup
|
|
488
|
+
export function not(expression: ExpressionInput): UnaryExpression
|
|
489
|
+
export function isNull(expression: ExpressionInput): UnaryExpression
|
|
490
|
+
export function isNotNull(expression: ExpressionInput): UnaryExpression
|
|
491
|
+
export function exists<const Source extends string>(
|
|
492
|
+
source: Source | SourceRef<Source>,
|
|
493
|
+
predicate?: ExpressionInput,
|
|
494
|
+
): ExistsExpression<Source, never>
|
|
495
|
+
export interface ExistsConfiguration<From extends string = string> {
|
|
496
|
+
from: From | SourceRef<From>
|
|
497
|
+
}
|
|
498
|
+
export function exists<const Source extends string, const From extends string>(
|
|
499
|
+
source: Source | SourceRef<Source>,
|
|
500
|
+
predicate: ExpressionInput | undefined,
|
|
501
|
+
configuration: ExistsConfiguration<From>,
|
|
502
|
+
): ExistsExpression<Source, From>
|
|
503
|
+
|
|
504
|
+
export function lower(expression: ExpressionInput): FunctionExpression
|
|
505
|
+
export function upper(expression: ExpressionInput): FunctionExpression
|
|
506
|
+
export function coalesce(
|
|
507
|
+
first: ExpressionInput,
|
|
508
|
+
second: ExpressionInput,
|
|
509
|
+
...rest: readonly ExpressionInput[]
|
|
510
|
+
): FunctionExpression
|
|
511
|
+
export function concat(first: ExpressionInput, ...rest: readonly ExpressionInput[]): FunctionExpression
|
|
512
|
+
|
|
513
|
+
export function count(expression?: ExpressionInput): AggregateExpression
|
|
514
|
+
export function countDistinct(expression: ExpressionInput): AggregateExpression
|
|
515
|
+
export function sum(expression: ExpressionInput): AggregateExpression
|
|
516
|
+
export function average(expression: ExpressionInput): AggregateExpression
|
|
517
|
+
export function minimum(expression: ExpressionInput): AggregateExpression
|
|
518
|
+
export function maximum(expression: ExpressionInput): AggregateExpression
|
|
519
|
+
|
|
520
|
+
export interface RelationConfiguration<Name extends string = string> {
|
|
521
|
+
name: Name
|
|
522
|
+
from: string | SourceRef
|
|
523
|
+
to: string | SourceRef
|
|
524
|
+
on: Expression
|
|
525
|
+
required?: boolean
|
|
526
|
+
cardinality?: RelationCardinality
|
|
527
|
+
selection?: RelationSelection
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function relation<const Name extends string>(configuration: RelationConfiguration<Name>): RelationRef<Name>
|
|
531
|
+
|
|
532
|
+
export interface ConstraintConfiguration {
|
|
533
|
+
predicate: Expression
|
|
534
|
+
when?: string | ParameterRef
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export function constraint(configuration: ConstraintConfiguration): ConstraintDefinition
|
|
538
|
+
|
|
539
|
+
export interface ProjectionConfiguration<Path extends string | readonly string[] = string | readonly string[]> {
|
|
540
|
+
path: Path
|
|
541
|
+
expression: ExpressionInput
|
|
542
|
+
default?: boolean
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
type ConfigurationPath<Path extends string | readonly string[]> = Path extends string
|
|
546
|
+
? Path
|
|
547
|
+
: Path extends readonly string[]
|
|
548
|
+
? JoinProjectionPath<Path>
|
|
549
|
+
: never
|
|
550
|
+
|
|
551
|
+
export function project<const Path extends string | readonly string[]>(
|
|
552
|
+
configuration: ProjectionConfiguration<Path>,
|
|
553
|
+
): ProjectionFieldDefinition<ConfigurationPath<Path>>
|
|
554
|
+
|
|
555
|
+
export function dimension<const Path extends string | readonly string[]>(
|
|
556
|
+
configuration: ProjectionConfiguration<Path>,
|
|
557
|
+
): DimensionDefinition<ConfigurationPath<Path>>
|
|
558
|
+
|
|
559
|
+
export function measure<const Path extends string | readonly string[]>(
|
|
560
|
+
configuration: ProjectionConfiguration<Path>,
|
|
561
|
+
): MeasureDefinition<ConfigurationPath<Path>>
|
|
562
|
+
|
|
563
|
+
export interface OrderByOptions {
|
|
564
|
+
nulls?: NullsOrder
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export function asc(expression: ExpressionInput, options?: OrderByOptions): OrderByDefinition
|
|
568
|
+
export function desc(expression: ExpressionInput, options?: OrderByOptions): OrderByDefinition
|
|
569
|
+
|
|
570
|
+
export function firstBy(firstOrder: OrderByDefinition, ...rest: readonly OrderByDefinition[]): FirstBySelection
|
|
571
|
+
|
|
572
|
+
export interface OrderingConfiguration<Name extends string = string> {
|
|
573
|
+
name: Name
|
|
574
|
+
by: readonly [OrderByDefinition, ...OrderByDefinition[]]
|
|
575
|
+
default?: boolean
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export function ordering<const Name extends string>(
|
|
579
|
+
configuration: OrderingConfiguration<Name>,
|
|
580
|
+
): OrderingDefinition<Name>
|
|
581
|
+
|
|
582
|
+
export interface GraphModuleConfiguration {
|
|
583
|
+
name: string
|
|
584
|
+
modules?: readonly GraphModule[]
|
|
585
|
+
sources?: readonly SourceRef[]
|
|
586
|
+
parameters?: readonly ParameterDefinition[]
|
|
587
|
+
relations?: readonly RelationDefinition[]
|
|
588
|
+
constraints?: readonly ConstraintDefinition[]
|
|
589
|
+
projection?: readonly ProjectionFieldDefinition[]
|
|
590
|
+
orderings?: readonly OrderingDefinition[]
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
type ConfigurationElement<Configuration, Key extends PropertyKey> = Key extends keyof Configuration
|
|
594
|
+
? NonNullable<Configuration[Key]> extends readonly (infer Element)[]
|
|
595
|
+
? Element
|
|
596
|
+
: never
|
|
597
|
+
: never
|
|
598
|
+
|
|
599
|
+
type ModuleParameter<Module> =
|
|
600
|
+
Module extends GraphModule<infer Parameter, infer _ProjectionPath, infer _OrderingName> ? Parameter : never
|
|
601
|
+
|
|
602
|
+
type ModuleProjectionPath<Module> =
|
|
603
|
+
Module extends GraphModule<infer _Parameter, infer ProjectionPath, infer _OrderingName> ? ProjectionPath : never
|
|
604
|
+
|
|
605
|
+
type ModuleOrderingName<Module> =
|
|
606
|
+
Module extends GraphModule<infer _Parameter, infer _ProjectionPath, infer OrderingName> ? OrderingName : never
|
|
607
|
+
|
|
608
|
+
type ProjectionPathOf<Field> = Field extends ProjectionFieldDefinition<infer Path> ? Path : never
|
|
609
|
+
|
|
610
|
+
type OrderingNameOf<Ordering> = Ordering extends OrderingDefinition<infer Name> ? Name : never
|
|
611
|
+
|
|
612
|
+
type ConfigurationParameter<Configuration> =
|
|
613
|
+
| Extract<ConfigurationElement<Configuration, 'parameters'>, ParameterDefinition>
|
|
614
|
+
| ModuleParameter<ConfigurationElement<Configuration, 'modules'>>
|
|
615
|
+
|
|
616
|
+
type ConfigurationProjectionPath<Configuration> =
|
|
617
|
+
| ProjectionPathOf<ConfigurationElement<Configuration, 'projection'>>
|
|
618
|
+
| ProjectionPathOf<ConfigurationElement<Configuration, 'dimensions'>>
|
|
619
|
+
| ProjectionPathOf<ConfigurationElement<Configuration, 'measures'>>
|
|
620
|
+
| ModuleProjectionPath<ConfigurationElement<Configuration, 'modules'>>
|
|
621
|
+
|
|
622
|
+
type ConfigurationOrderingName<Configuration> =
|
|
623
|
+
| OrderingNameOf<ConfigurationElement<Configuration, 'orderings'>>
|
|
624
|
+
| ModuleOrderingName<ConfigurationElement<Configuration, 'modules'>>
|
|
625
|
+
|
|
626
|
+
export interface GraphModule<
|
|
627
|
+
Parameter extends ParameterDefinition = ParameterDefinition,
|
|
628
|
+
ProjectionPath extends string = string,
|
|
629
|
+
OrderingName extends string = string,
|
|
630
|
+
> {
|
|
631
|
+
readonly name: string
|
|
632
|
+
readonly sources: readonly SourceRef[]
|
|
633
|
+
readonly parameters: readonly Parameter[]
|
|
634
|
+
readonly relations: readonly RelationDefinition[]
|
|
635
|
+
readonly constraints: readonly ConstraintDefinition[]
|
|
636
|
+
readonly projection: readonly ProjectionFieldDefinition<ProjectionPath>[]
|
|
637
|
+
readonly orderings: readonly OrderingDefinition<OrderingName>[]
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
export function defineGraphModule<const Configuration extends GraphModuleConfiguration>(
|
|
641
|
+
configuration: Configuration,
|
|
642
|
+
): GraphModule<
|
|
643
|
+
ConfigurationParameter<Configuration>,
|
|
644
|
+
ConfigurationProjectionPath<Configuration>,
|
|
645
|
+
ConfigurationOrderingName<Configuration>
|
|
646
|
+
>
|
|
647
|
+
|
|
648
|
+
export interface GraphConfiguration {
|
|
649
|
+
name: string
|
|
650
|
+
root: string | SourceRef
|
|
651
|
+
modules?: readonly GraphModule[]
|
|
652
|
+
sources?: readonly SourceRef[]
|
|
653
|
+
parameters?: readonly ParameterDefinition[]
|
|
654
|
+
relations?: readonly RelationDefinition[]
|
|
655
|
+
constraints?: readonly ConstraintDefinition[]
|
|
656
|
+
projection?: readonly ProjectionFieldDefinition[]
|
|
657
|
+
orderings?: readonly OrderingDefinition[]
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export function defineGraph<const Configuration extends GraphConfiguration>(
|
|
661
|
+
configuration: Configuration,
|
|
662
|
+
): GraphDefinition<
|
|
663
|
+
ConfigurationParameter<Configuration>,
|
|
664
|
+
ConfigurationProjectionPath<Configuration>,
|
|
665
|
+
ConfigurationOrderingName<Configuration>
|
|
666
|
+
>
|
|
667
|
+
|
|
668
|
+
export interface SummaryGraphConfiguration {
|
|
669
|
+
name: string
|
|
670
|
+
root: string | SourceRef
|
|
671
|
+
modules?: readonly GraphModule[]
|
|
672
|
+
sources?: readonly SourceRef[]
|
|
673
|
+
parameters?: readonly ParameterDefinition[]
|
|
674
|
+
relations?: readonly RelationDefinition[]
|
|
675
|
+
constraints?: readonly ConstraintDefinition[]
|
|
676
|
+
dimensions?: readonly DimensionDefinition[]
|
|
677
|
+
measures?: readonly MeasureDefinition[]
|
|
678
|
+
orderings?: readonly OrderingDefinition[]
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export function defineSummaryGraph<const Configuration extends SummaryGraphConfiguration>(
|
|
682
|
+
configuration: Configuration,
|
|
683
|
+
): GraphDefinition<
|
|
684
|
+
ConfigurationParameter<Configuration>,
|
|
685
|
+
ConfigurationProjectionPath<Configuration>,
|
|
686
|
+
ConfigurationOrderingName<Configuration>
|
|
687
|
+
>
|