@query-graph/core 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -969
- package/definition.d.ts +11 -0
- package/definition.js +1 -2
- package/docs/authoring.md +161 -0
- package/docs/composition.md +100 -0
- package/docs/diagnostics.md +52 -0
- package/docs/sql.md +68 -0
- package/docs/type-system.md +86 -0
- package/dsl.d.ts +182 -1839
- package/dsl.js +57 -763
- package/index.d.ts +8 -100
- package/index.js +13 -568
- package/lib/authoring/definition.js +425 -0
- package/lib/authoring/primitives.js +433 -0
- package/lib/authoring/symbols.js +4 -0
- package/{composition.js → lib/composition.js} +9 -35
- package/lib/configuration.js +66 -0
- package/native.d.ts +98 -0
- package/native.js +714 -0
- package/package.json +16 -11
- package/types/authoring.d.ts +667 -0
- package/types/composition.d.ts +327 -0
- package/types/model.d.ts +425 -0
- package/types/result.d.ts +394 -0
- package/types/runtime.d.ts +168 -0
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AggregateExpression,
|
|
3
|
+
AllNullability,
|
|
4
|
+
AnyNullability,
|
|
5
|
+
BinaryExpression,
|
|
6
|
+
ConstraintDefinition,
|
|
7
|
+
DimensionDefinition,
|
|
8
|
+
ExistsExpression,
|
|
9
|
+
Expression,
|
|
10
|
+
ExpressionGroup,
|
|
11
|
+
ExpressionTypeMetadata,
|
|
12
|
+
FieldExpression,
|
|
13
|
+
FirstBySelection,
|
|
14
|
+
FunctionExpression,
|
|
15
|
+
GraphDefinition,
|
|
16
|
+
InExpression,
|
|
17
|
+
InParameterExpression,
|
|
18
|
+
JoinProjectionPath,
|
|
19
|
+
LikeExpression,
|
|
20
|
+
LiteralExpression,
|
|
21
|
+
MeasureDefinition,
|
|
22
|
+
NullsOrder,
|
|
23
|
+
OrderByDefinition,
|
|
24
|
+
OrderingDefinition,
|
|
25
|
+
ParameterDefinition,
|
|
26
|
+
ParameterExpression,
|
|
27
|
+
ProjectionFieldDefinition,
|
|
28
|
+
ProjectionObjectDefinition,
|
|
29
|
+
RelationCardinality,
|
|
30
|
+
RelationDefinition,
|
|
31
|
+
RelationSelection,
|
|
32
|
+
ScalarType,
|
|
33
|
+
SourceDefinition,
|
|
34
|
+
SourceFieldNullability,
|
|
35
|
+
SummaryFieldDefinition,
|
|
36
|
+
TypedDimensionDefinition,
|
|
37
|
+
TypedExpression,
|
|
38
|
+
TypedMeasureDefinition,
|
|
39
|
+
TypedProjectionField,
|
|
40
|
+
TypedProjectionObject,
|
|
41
|
+
UnaryExpression,
|
|
42
|
+
} from './model.js'
|
|
43
|
+
|
|
44
|
+
export interface FieldSpecDefinition<
|
|
45
|
+
Type extends ScalarType = ScalarType,
|
|
46
|
+
Nullable extends boolean = boolean,
|
|
47
|
+
Selectable extends boolean = boolean,
|
|
48
|
+
> {
|
|
49
|
+
scalarType: Type
|
|
50
|
+
nullable?: Nullable
|
|
51
|
+
selectable?: Selectable
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type FieldSpec = ScalarType | FieldSpecDefinition
|
|
55
|
+
export type FieldSpecMap = Record<string, FieldSpec>
|
|
56
|
+
|
|
57
|
+
export type FieldSpecScalarType<Specification extends FieldSpec> = Specification extends ScalarType
|
|
58
|
+
? Specification
|
|
59
|
+
: Specification extends FieldSpecDefinition<infer Type, infer _Nullable, infer _Selectable>
|
|
60
|
+
? Type
|
|
61
|
+
: never
|
|
62
|
+
|
|
63
|
+
export type FieldSpecIsNullable<Specification extends FieldSpec> = Specification extends ScalarType
|
|
64
|
+
? false
|
|
65
|
+
: Specification extends FieldSpecDefinition<infer _Type, infer Nullable, infer _Selectable>
|
|
66
|
+
? Nullable
|
|
67
|
+
: boolean
|
|
68
|
+
|
|
69
|
+
export type FieldSpecIsSelectable<Specification extends FieldSpec> = Specification extends ScalarType
|
|
70
|
+
? true
|
|
71
|
+
: Specification extends FieldSpecDefinition<infer _Type, infer _Nullable, infer Selectable>
|
|
72
|
+
? Selectable
|
|
73
|
+
: boolean
|
|
74
|
+
|
|
75
|
+
export interface SourceRef<Key extends string = string, Fields extends FieldSpecMap = FieldSpecMap>
|
|
76
|
+
extends SourceDefinition {
|
|
77
|
+
key: Key
|
|
78
|
+
field<Name extends Extract<keyof Fields, string>>(
|
|
79
|
+
name: Name,
|
|
80
|
+
): TypedExpression<
|
|
81
|
+
FieldExpression<Key, Name>,
|
|
82
|
+
FieldSpecScalarType<Fields[Name]>,
|
|
83
|
+
SourceFieldNullability<Key, FieldSpecIsNullable<Fields[Name]>>
|
|
84
|
+
>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface ScalarParameterRef<
|
|
88
|
+
Name extends string = string,
|
|
89
|
+
Type extends ScalarType = ScalarType,
|
|
90
|
+
Required extends boolean = boolean,
|
|
91
|
+
> extends ParameterDefinition {
|
|
92
|
+
name: Name
|
|
93
|
+
scalarType: Type
|
|
94
|
+
shape?: 'scalar'
|
|
95
|
+
required?: Required
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ListParameterRef<
|
|
99
|
+
Name extends string = string,
|
|
100
|
+
Type extends ScalarType = ScalarType,
|
|
101
|
+
Required extends boolean = boolean,
|
|
102
|
+
> extends ParameterDefinition {
|
|
103
|
+
name: Name
|
|
104
|
+
scalarType: Type
|
|
105
|
+
shape: 'list'
|
|
106
|
+
required?: Required
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type ParameterRef<
|
|
110
|
+
Name extends string = string,
|
|
111
|
+
Type extends ScalarType = ScalarType,
|
|
112
|
+
Required extends boolean = boolean,
|
|
113
|
+
> = ScalarParameterRef<Name, Type, Required> | ListParameterRef<Name, Type, Required>
|
|
114
|
+
|
|
115
|
+
export type RelationRef<
|
|
116
|
+
Name extends string = string,
|
|
117
|
+
From extends string = string,
|
|
118
|
+
To extends string = string,
|
|
119
|
+
Required extends boolean = boolean,
|
|
120
|
+
Cardinality extends RelationCardinality = RelationCardinality,
|
|
121
|
+
> = RelationDefinition<Name, From, To, Required, Cardinality>
|
|
122
|
+
|
|
123
|
+
export type LiteralInput = null | boolean | string | number
|
|
124
|
+
export type ExpressionInput = Expression | LiteralInput | SummaryFieldDefinition
|
|
125
|
+
|
|
126
|
+
type NumberLiteralScalarType<Value extends number> = number extends Value
|
|
127
|
+
? 'int64' | 'decimal'
|
|
128
|
+
: `${Value}` extends `${bigint}`
|
|
129
|
+
? 'int64'
|
|
130
|
+
: 'decimal'
|
|
131
|
+
|
|
132
|
+
type InputScalarType<Input extends ExpressionInput> =
|
|
133
|
+
Input extends ExpressionTypeMetadata<infer Type, infer _Nullability>
|
|
134
|
+
? Type
|
|
135
|
+
: Input extends ProjectionFieldDefinition<infer _Path, infer Type, infer _Nullability, infer _SelectedByDefault>
|
|
136
|
+
? Type
|
|
137
|
+
: Input extends null
|
|
138
|
+
? null
|
|
139
|
+
: Input extends boolean
|
|
140
|
+
? 'boolean'
|
|
141
|
+
: Input extends string
|
|
142
|
+
? 'string'
|
|
143
|
+
: Input extends number
|
|
144
|
+
? NumberLiteralScalarType<Input>
|
|
145
|
+
: ScalarType
|
|
146
|
+
|
|
147
|
+
type InputNullability<Input extends ExpressionInput> =
|
|
148
|
+
Input extends ExpressionTypeMetadata<infer _Type, infer Nullability>
|
|
149
|
+
? Nullability
|
|
150
|
+
: Input extends ProjectionFieldDefinition<infer _Path, infer _Type, infer Nullability, infer _SelectedByDefault>
|
|
151
|
+
? Nullability
|
|
152
|
+
: Input extends null
|
|
153
|
+
? true
|
|
154
|
+
: Input extends Expression
|
|
155
|
+
? boolean
|
|
156
|
+
: false
|
|
157
|
+
|
|
158
|
+
export type ExpressionScalarType<Input extends ExpressionInput> = InputScalarType<Input>
|
|
159
|
+
export type ExpressionNullability<Input extends ExpressionInput> = InputNullability<Input>
|
|
160
|
+
|
|
161
|
+
type PromoteScalarType<Type extends ScalarType | null> = 'float64' extends Type
|
|
162
|
+
? 'float64'
|
|
163
|
+
: 'decimal' extends Type
|
|
164
|
+
? 'decimal'
|
|
165
|
+
: 'int64' extends Type
|
|
166
|
+
? 'int64'
|
|
167
|
+
: 'int32' extends Type
|
|
168
|
+
? 'int32'
|
|
169
|
+
: 'dateTime' extends Type
|
|
170
|
+
? 'dateTime'
|
|
171
|
+
: Exclude<Type, null>
|
|
172
|
+
|
|
173
|
+
type AverageScalarType<Type extends ScalarType | null> = Type extends 'float64'
|
|
174
|
+
? 'float64'
|
|
175
|
+
: Type extends 'int32' | 'int64' | 'decimal'
|
|
176
|
+
? 'decimal'
|
|
177
|
+
: Exclude<Type, null>
|
|
178
|
+
|
|
179
|
+
type InputNullabilities<Inputs extends readonly ExpressionInput[]> = {
|
|
180
|
+
[Index in keyof Inputs]: InputNullability<Inputs[Index]>
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
type AnyInputNullability<Inputs extends readonly ExpressionInput[]> = AnyNullability<InputNullabilities<Inputs>>
|
|
184
|
+
type AllInputNullability<Inputs extends readonly ExpressionInput[]> = AllNullability<InputNullabilities<Inputs>>
|
|
185
|
+
|
|
186
|
+
export interface FieldTypeOptions {
|
|
187
|
+
nullable?: boolean
|
|
188
|
+
selectable?: boolean
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
type OptionNullable<Options extends FieldTypeOptions> = Options extends { nullable: true } ? true : false
|
|
192
|
+
type OptionSelectable<Options extends FieldTypeOptions> = Options extends { selectable: false } ? false : true
|
|
193
|
+
|
|
194
|
+
export function fieldType<const Type extends ScalarType, const Options extends FieldTypeOptions = Record<never, never>>(
|
|
195
|
+
scalarType: Type,
|
|
196
|
+
options?: Options,
|
|
197
|
+
): FieldSpecDefinition<Type, OptionNullable<Options>, OptionSelectable<Options>>
|
|
198
|
+
export function nullable<const Specification extends FieldSpec>(
|
|
199
|
+
specification: Specification,
|
|
200
|
+
): FieldSpecDefinition<FieldSpecScalarType<Specification>, true, FieldSpecIsSelectable<Specification>>
|
|
201
|
+
export function hidden<const Specification extends FieldSpec>(
|
|
202
|
+
specification: Specification,
|
|
203
|
+
): FieldSpecDefinition<FieldSpecScalarType<Specification>, FieldSpecIsNullable<Specification>, false>
|
|
204
|
+
|
|
205
|
+
export function source<const Key extends string, const Fields extends FieldSpecMap>(
|
|
206
|
+
key: Key,
|
|
207
|
+
fields: Fields,
|
|
208
|
+
): SourceRef<Key, Fields>
|
|
209
|
+
|
|
210
|
+
export function requiredParameter<const Name extends string, const Type extends ScalarType>(
|
|
211
|
+
name: Name,
|
|
212
|
+
scalarType: Type,
|
|
213
|
+
): ScalarParameterRef<Name, Type, true>
|
|
214
|
+
export function optionalParameter<const Name extends string, const Type extends ScalarType>(
|
|
215
|
+
name: Name,
|
|
216
|
+
scalarType: Type,
|
|
217
|
+
): ScalarParameterRef<Name, Type, false>
|
|
218
|
+
export function requiredListParameter<const Name extends string, const Type extends ScalarType>(
|
|
219
|
+
name: Name,
|
|
220
|
+
scalarType: Type,
|
|
221
|
+
): ListParameterRef<Name, Type, true>
|
|
222
|
+
export function optionalListParameter<const Name extends string, const Type extends ScalarType>(
|
|
223
|
+
name: Name,
|
|
224
|
+
scalarType: Type,
|
|
225
|
+
): ListParameterRef<Name, Type, false>
|
|
226
|
+
export function param<const Name extends string, const Type extends ScalarType>(
|
|
227
|
+
parameter: ScalarParameterRef<Name, Type>,
|
|
228
|
+
): TypedExpression<ParameterExpression<Name>, Type, false>
|
|
229
|
+
|
|
230
|
+
export function literal<const Value extends LiteralInput>(
|
|
231
|
+
value: Value,
|
|
232
|
+
): TypedExpression<LiteralExpression, InputScalarType<Value>, InputNullability<Value>>
|
|
233
|
+
export function integer(value: number): TypedExpression<LiteralExpression, 'int64', false>
|
|
234
|
+
export function decimal(value: string | number): TypedExpression<LiteralExpression, 'decimal', false>
|
|
235
|
+
|
|
236
|
+
type EqualityNullability<Left extends ExpressionInput, Right extends ExpressionInput> = null extends
|
|
237
|
+
| InputScalarType<Left>
|
|
238
|
+
| InputScalarType<Right>
|
|
239
|
+
? false
|
|
240
|
+
: AnyInputNullability<readonly [Left, Right]>
|
|
241
|
+
|
|
242
|
+
export function eq<const Left extends ExpressionInput, const Right extends ExpressionInput>(
|
|
243
|
+
left: Left,
|
|
244
|
+
right: Right,
|
|
245
|
+
): TypedExpression<BinaryExpression, 'boolean', EqualityNullability<Left, Right>>
|
|
246
|
+
export function neq<const Left extends ExpressionInput, const Right extends ExpressionInput>(
|
|
247
|
+
left: Left,
|
|
248
|
+
right: Right,
|
|
249
|
+
): TypedExpression<BinaryExpression, 'boolean', EqualityNullability<Left, Right>>
|
|
250
|
+
export function lt<const Left extends ExpressionInput, const Right extends ExpressionInput>(
|
|
251
|
+
left: Left,
|
|
252
|
+
right: Right,
|
|
253
|
+
): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
|
|
254
|
+
export function lte<const Left extends ExpressionInput, const Right extends ExpressionInput>(
|
|
255
|
+
left: Left,
|
|
256
|
+
right: Right,
|
|
257
|
+
): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
|
|
258
|
+
export function gt<const Left extends ExpressionInput, const Right extends ExpressionInput>(
|
|
259
|
+
left: Left,
|
|
260
|
+
right: Right,
|
|
261
|
+
): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
|
|
262
|
+
export function gte<const Left extends ExpressionInput, const Right extends ExpressionInput>(
|
|
263
|
+
left: Left,
|
|
264
|
+
right: Right,
|
|
265
|
+
): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
|
|
266
|
+
export function like<const Value extends ExpressionInput, const Pattern extends ExpressionInput>(
|
|
267
|
+
expression: Value,
|
|
268
|
+
pattern: Pattern,
|
|
269
|
+
): TypedExpression<LikeExpression, 'boolean', AnyInputNullability<readonly [Value, Pattern]>>
|
|
270
|
+
export function inList<const Value extends ExpressionInput, const Values extends readonly ExpressionInput[]>(
|
|
271
|
+
expression: Value,
|
|
272
|
+
values: Values,
|
|
273
|
+
): TypedExpression<InExpression, 'boolean', AnyInputNullability<readonly [Value, ...Values]>>
|
|
274
|
+
export function and<const Expressions extends readonly ExpressionInput[]>(
|
|
275
|
+
...expressions: Expressions
|
|
276
|
+
): TypedExpression<ExpressionGroup, 'boolean', AnyInputNullability<Expressions>>
|
|
277
|
+
export function inParameter<
|
|
278
|
+
const Value extends ExpressionInput,
|
|
279
|
+
const Name extends string,
|
|
280
|
+
const Type extends ScalarType,
|
|
281
|
+
>(
|
|
282
|
+
expression: Value,
|
|
283
|
+
parameter: ListParameterRef<Name, Type>,
|
|
284
|
+
): TypedExpression<InParameterExpression<Name>, 'boolean', InputNullability<Value>>
|
|
285
|
+
export function or<const Expressions extends readonly ExpressionInput[]>(
|
|
286
|
+
...expressions: Expressions
|
|
287
|
+
): TypedExpression<ExpressionGroup, 'boolean', AnyInputNullability<Expressions>>
|
|
288
|
+
export function not<const Value extends ExpressionInput>(
|
|
289
|
+
expression: Value,
|
|
290
|
+
): TypedExpression<UnaryExpression, 'boolean', InputNullability<Value>>
|
|
291
|
+
export function isNull(expression: ExpressionInput): TypedExpression<UnaryExpression, 'boolean', false>
|
|
292
|
+
export function isNotNull(expression: ExpressionInput): TypedExpression<UnaryExpression, 'boolean', false>
|
|
293
|
+
export function exists<const Source extends string>(
|
|
294
|
+
source: Source | SourceRef<Source>,
|
|
295
|
+
predicate?: ExpressionInput,
|
|
296
|
+
): TypedExpression<ExistsExpression<Source, never>, 'boolean', false>
|
|
297
|
+
export interface ExistsConfiguration<From extends string = string> {
|
|
298
|
+
from: From | SourceRef<From>
|
|
299
|
+
}
|
|
300
|
+
export function exists<const Source extends string, const From extends string>(
|
|
301
|
+
source: Source | SourceRef<Source>,
|
|
302
|
+
predicate: ExpressionInput | undefined,
|
|
303
|
+
configuration: ExistsConfiguration<From>,
|
|
304
|
+
): TypedExpression<ExistsExpression<Source, From>, 'boolean', false>
|
|
305
|
+
|
|
306
|
+
export function lower<const Value extends ExpressionInput>(
|
|
307
|
+
expression: Value,
|
|
308
|
+
): TypedExpression<FunctionExpression, 'string', InputNullability<Value>>
|
|
309
|
+
export function upper<const Value extends ExpressionInput>(
|
|
310
|
+
expression: Value,
|
|
311
|
+
): TypedExpression<FunctionExpression, 'string', InputNullability<Value>>
|
|
312
|
+
export function coalesce<
|
|
313
|
+
const First extends ExpressionInput,
|
|
314
|
+
const Second extends ExpressionInput,
|
|
315
|
+
const Rest extends readonly ExpressionInput[],
|
|
316
|
+
>(
|
|
317
|
+
first: First,
|
|
318
|
+
second: Second,
|
|
319
|
+
...rest: Rest
|
|
320
|
+
): TypedExpression<
|
|
321
|
+
FunctionExpression,
|
|
322
|
+
PromoteScalarType<InputScalarType<First | Second | Rest[number]>>,
|
|
323
|
+
AllInputNullability<readonly [First, Second, ...Rest]>
|
|
324
|
+
>
|
|
325
|
+
export function concat<const First extends ExpressionInput, const Rest extends readonly ExpressionInput[]>(
|
|
326
|
+
first: First,
|
|
327
|
+
...rest: Rest
|
|
328
|
+
): TypedExpression<FunctionExpression, 'string', AllInputNullability<readonly [First, ...Rest]>>
|
|
329
|
+
|
|
330
|
+
export function count(expression?: ExpressionInput): TypedExpression<AggregateExpression, 'int64', false>
|
|
331
|
+
export function countDistinct(expression: ExpressionInput): TypedExpression<AggregateExpression, 'int64', false>
|
|
332
|
+
export function sum<const Value extends ExpressionInput>(
|
|
333
|
+
expression: Value,
|
|
334
|
+
): TypedExpression<AggregateExpression, Exclude<InputScalarType<Value>, null>, true>
|
|
335
|
+
export function average<const Value extends ExpressionInput>(
|
|
336
|
+
expression: Value,
|
|
337
|
+
): TypedExpression<AggregateExpression, AverageScalarType<InputScalarType<Value>>, true>
|
|
338
|
+
export function minimum<const Value extends ExpressionInput>(
|
|
339
|
+
expression: Value,
|
|
340
|
+
): TypedExpression<AggregateExpression, Exclude<InputScalarType<Value>, null>, true>
|
|
341
|
+
export function maximum<const Value extends ExpressionInput>(
|
|
342
|
+
expression: Value,
|
|
343
|
+
): TypedExpression<AggregateExpression, Exclude<InputScalarType<Value>, null>, true>
|
|
344
|
+
|
|
345
|
+
export type SourceReferenceKey<Reference extends string | SourceRef> =
|
|
346
|
+
Reference extends SourceRef<infer Key, infer _Fields> ? Key : Reference extends string ? Reference : string
|
|
347
|
+
|
|
348
|
+
export interface RelationConfiguration<
|
|
349
|
+
Name extends string = string,
|
|
350
|
+
From extends string | SourceRef = string | SourceRef,
|
|
351
|
+
To extends string | SourceRef = string | SourceRef,
|
|
352
|
+
Required extends boolean = boolean,
|
|
353
|
+
Cardinality extends RelationCardinality = RelationCardinality,
|
|
354
|
+
> {
|
|
355
|
+
name: Name
|
|
356
|
+
from: From
|
|
357
|
+
to: To
|
|
358
|
+
on: Expression
|
|
359
|
+
required?: Required
|
|
360
|
+
cardinality?: Cardinality
|
|
361
|
+
selection?: RelationSelection
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export function relation<
|
|
365
|
+
const Name extends string,
|
|
366
|
+
const From extends string | SourceRef,
|
|
367
|
+
const To extends string | SourceRef,
|
|
368
|
+
const Required extends boolean = false,
|
|
369
|
+
const Cardinality extends RelationCardinality = 'one',
|
|
370
|
+
>(
|
|
371
|
+
configuration: RelationConfiguration<Name, From, To, Required, Cardinality>,
|
|
372
|
+
): RelationRef<Name, SourceReferenceKey<From>, SourceReferenceKey<To>, Required, Cardinality>
|
|
373
|
+
|
|
374
|
+
export interface ConstraintConfiguration {
|
|
375
|
+
predicate: Expression
|
|
376
|
+
when?: string | ParameterRef
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function constraint(configuration: ConstraintConfiguration): ConstraintDefinition
|
|
380
|
+
|
|
381
|
+
export interface ProjectionConfiguration<
|
|
382
|
+
Path extends string | readonly string[] = string | readonly string[],
|
|
383
|
+
Value extends ExpressionInput = ExpressionInput,
|
|
384
|
+
SelectedByDefault extends boolean = boolean,
|
|
385
|
+
> {
|
|
386
|
+
path: Path
|
|
387
|
+
expression: Value
|
|
388
|
+
default?: SelectedByDefault
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface ProjectionObjectConfiguration<
|
|
392
|
+
Path extends string | readonly string[] = string | readonly string[],
|
|
393
|
+
Value extends ExpressionInput = ExpressionInput,
|
|
394
|
+
> {
|
|
395
|
+
path: Path
|
|
396
|
+
presence: Value
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
type ConfigurationPath<Path extends string | readonly string[]> = Path extends string
|
|
400
|
+
? Path
|
|
401
|
+
: Path extends readonly string[]
|
|
402
|
+
? JoinProjectionPath<Path>
|
|
403
|
+
: never
|
|
404
|
+
|
|
405
|
+
export function project<
|
|
406
|
+
const Path extends string | readonly string[],
|
|
407
|
+
const Value extends ExpressionInput,
|
|
408
|
+
const SelectedByDefault extends boolean = false,
|
|
409
|
+
>(
|
|
410
|
+
configuration: ProjectionConfiguration<Path, Value, SelectedByDefault>,
|
|
411
|
+
): TypedProjectionField<
|
|
412
|
+
ConfigurationPath<Path>,
|
|
413
|
+
Extract<InputScalarType<Value>, ScalarType>,
|
|
414
|
+
InputNullability<Value>,
|
|
415
|
+
SelectedByDefault
|
|
416
|
+
>
|
|
417
|
+
|
|
418
|
+
export function projectObject<const Path extends string | readonly string[], const Value extends ExpressionInput>(
|
|
419
|
+
configuration: ProjectionObjectConfiguration<Path, Value>,
|
|
420
|
+
): TypedProjectionObject<ConfigurationPath<Path>, InputNullability<Value>>
|
|
421
|
+
|
|
422
|
+
export function dimension<
|
|
423
|
+
const Path extends string | readonly string[],
|
|
424
|
+
const Value extends ExpressionInput,
|
|
425
|
+
const SelectedByDefault extends boolean = false,
|
|
426
|
+
>(
|
|
427
|
+
configuration: ProjectionConfiguration<Path, Value, SelectedByDefault>,
|
|
428
|
+
): TypedDimensionDefinition<
|
|
429
|
+
ConfigurationPath<Path>,
|
|
430
|
+
Extract<InputScalarType<Value>, ScalarType>,
|
|
431
|
+
InputNullability<Value>,
|
|
432
|
+
SelectedByDefault
|
|
433
|
+
>
|
|
434
|
+
|
|
435
|
+
export function measure<
|
|
436
|
+
const Path extends string | readonly string[],
|
|
437
|
+
const Value extends ExpressionInput,
|
|
438
|
+
const SelectedByDefault extends boolean = false,
|
|
439
|
+
>(
|
|
440
|
+
configuration: ProjectionConfiguration<Path, Value, SelectedByDefault>,
|
|
441
|
+
): TypedMeasureDefinition<
|
|
442
|
+
ConfigurationPath<Path>,
|
|
443
|
+
Extract<InputScalarType<Value>, ScalarType>,
|
|
444
|
+
InputNullability<Value>,
|
|
445
|
+
SelectedByDefault
|
|
446
|
+
>
|
|
447
|
+
|
|
448
|
+
export interface OrderByOptions {
|
|
449
|
+
nulls?: NullsOrder
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export function asc(expression: ExpressionInput, options?: OrderByOptions): OrderByDefinition
|
|
453
|
+
export function desc(expression: ExpressionInput, options?: OrderByOptions): OrderByDefinition
|
|
454
|
+
|
|
455
|
+
export function firstBy(firstOrder: OrderByDefinition, ...rest: readonly OrderByDefinition[]): FirstBySelection
|
|
456
|
+
|
|
457
|
+
export interface OrderingConfiguration<Name extends string = string> {
|
|
458
|
+
name: Name
|
|
459
|
+
by: readonly [OrderByDefinition, ...OrderByDefinition[]]
|
|
460
|
+
default?: boolean
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export function ordering<const Name extends string>(
|
|
464
|
+
configuration: OrderingConfiguration<Name>,
|
|
465
|
+
): OrderingDefinition<Name>
|
|
466
|
+
|
|
467
|
+
export interface GraphModuleConfiguration {
|
|
468
|
+
name: string
|
|
469
|
+
modules?: readonly GraphModule[]
|
|
470
|
+
sources?: readonly SourceRef[]
|
|
471
|
+
parameters?: readonly ParameterDefinition[]
|
|
472
|
+
relations?: readonly RelationDefinition[]
|
|
473
|
+
constraints?: readonly ConstraintDefinition[]
|
|
474
|
+
projection?: readonly ProjectionFieldDefinition[]
|
|
475
|
+
objects?: readonly ProjectionObjectDefinition[]
|
|
476
|
+
orderings?: readonly OrderingDefinition[]
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
type ConfigurationElement<Configuration, Key extends PropertyKey> = Key extends keyof Configuration
|
|
480
|
+
? NonNullable<Configuration[Key]> extends readonly (infer Element)[]
|
|
481
|
+
? Element
|
|
482
|
+
: never
|
|
483
|
+
: never
|
|
484
|
+
|
|
485
|
+
type ModuleParameter<Module> =
|
|
486
|
+
Module extends GraphModule<
|
|
487
|
+
infer Parameter,
|
|
488
|
+
infer _ProjectionPath,
|
|
489
|
+
infer _OrderingName,
|
|
490
|
+
infer _ProjectionField,
|
|
491
|
+
infer _Relation
|
|
492
|
+
>
|
|
493
|
+
? Parameter
|
|
494
|
+
: never
|
|
495
|
+
|
|
496
|
+
type ModuleProjectionPath<Module> =
|
|
497
|
+
Module extends GraphModule<
|
|
498
|
+
infer _Parameter,
|
|
499
|
+
infer ProjectionPath,
|
|
500
|
+
infer _OrderingName,
|
|
501
|
+
infer _ProjectionField,
|
|
502
|
+
infer _Relation
|
|
503
|
+
>
|
|
504
|
+
? ProjectionPath
|
|
505
|
+
: never
|
|
506
|
+
|
|
507
|
+
type ModuleOrderingName<Module> =
|
|
508
|
+
Module extends GraphModule<
|
|
509
|
+
infer _Parameter,
|
|
510
|
+
infer _ProjectionPath,
|
|
511
|
+
infer OrderingName,
|
|
512
|
+
infer _ProjectionField,
|
|
513
|
+
infer _Relation
|
|
514
|
+
>
|
|
515
|
+
? OrderingName
|
|
516
|
+
: never
|
|
517
|
+
|
|
518
|
+
type ModuleProjectionField<Module> =
|
|
519
|
+
Module extends GraphModule<
|
|
520
|
+
infer _Parameter,
|
|
521
|
+
infer _ProjectionPath,
|
|
522
|
+
infer _OrderingName,
|
|
523
|
+
infer ProjectionField,
|
|
524
|
+
infer _Relation
|
|
525
|
+
>
|
|
526
|
+
? ProjectionField
|
|
527
|
+
: never
|
|
528
|
+
|
|
529
|
+
type ModuleRelation<Module> =
|
|
530
|
+
Module extends GraphModule<
|
|
531
|
+
infer _Parameter,
|
|
532
|
+
infer _ProjectionPath,
|
|
533
|
+
infer _OrderingName,
|
|
534
|
+
infer _ProjectionField,
|
|
535
|
+
infer Relation
|
|
536
|
+
>
|
|
537
|
+
? Relation
|
|
538
|
+
: never
|
|
539
|
+
|
|
540
|
+
type ModuleProjectionObject<Module> =
|
|
541
|
+
Module extends GraphModule<
|
|
542
|
+
infer _Parameter,
|
|
543
|
+
infer _ProjectionPath,
|
|
544
|
+
infer _OrderingName,
|
|
545
|
+
infer _ProjectionField,
|
|
546
|
+
infer _Relation,
|
|
547
|
+
infer ProjectionObject
|
|
548
|
+
>
|
|
549
|
+
? ProjectionObject
|
|
550
|
+
: never
|
|
551
|
+
|
|
552
|
+
type ProjectionPathOf<Field> = Field extends ProjectionFieldDefinition<infer Path> ? Path : never
|
|
553
|
+
|
|
554
|
+
type OrderingNameOf<Ordering> = Ordering extends OrderingDefinition<infer Name> ? Name : never
|
|
555
|
+
|
|
556
|
+
type ConfigurationParameter<Configuration> =
|
|
557
|
+
| Extract<ConfigurationElement<Configuration, 'parameters'>, ParameterDefinition>
|
|
558
|
+
| ModuleParameter<ConfigurationElement<Configuration, 'modules'>>
|
|
559
|
+
|
|
560
|
+
type ConfigurationProjectionPath<Configuration> =
|
|
561
|
+
| ProjectionPathOf<ConfigurationElement<Configuration, 'projection'>>
|
|
562
|
+
| ProjectionPathOf<ConfigurationElement<Configuration, 'dimensions'>>
|
|
563
|
+
| ProjectionPathOf<ConfigurationElement<Configuration, 'measures'>>
|
|
564
|
+
| ModuleProjectionPath<ConfigurationElement<Configuration, 'modules'>>
|
|
565
|
+
|
|
566
|
+
type ConfigurationProjectionField<Configuration> =
|
|
567
|
+
| Extract<ConfigurationElement<Configuration, 'projection'>, ProjectionFieldDefinition>
|
|
568
|
+
| Extract<ConfigurationElement<Configuration, 'dimensions'>, ProjectionFieldDefinition>
|
|
569
|
+
| Extract<ConfigurationElement<Configuration, 'measures'>, ProjectionFieldDefinition>
|
|
570
|
+
| ModuleProjectionField<ConfigurationElement<Configuration, 'modules'>>
|
|
571
|
+
|
|
572
|
+
type ConfigurationProjectionObject<Configuration> =
|
|
573
|
+
| Extract<ConfigurationElement<Configuration, 'objects'>, ProjectionObjectDefinition>
|
|
574
|
+
| ModuleProjectionObject<ConfigurationElement<Configuration, 'modules'>>
|
|
575
|
+
|
|
576
|
+
type ConfigurationOrderingName<Configuration> =
|
|
577
|
+
| OrderingNameOf<ConfigurationElement<Configuration, 'orderings'>>
|
|
578
|
+
| ModuleOrderingName<ConfigurationElement<Configuration, 'modules'>>
|
|
579
|
+
|
|
580
|
+
type ConfigurationRelation<Configuration> =
|
|
581
|
+
| Extract<ConfigurationElement<Configuration, 'relations'>, RelationDefinition>
|
|
582
|
+
| ModuleRelation<ConfigurationElement<Configuration, 'modules'>>
|
|
583
|
+
|
|
584
|
+
type ConfigurationRoot<Configuration> = Configuration extends {
|
|
585
|
+
root: infer Root extends string | SourceRef
|
|
586
|
+
}
|
|
587
|
+
? SourceReferenceKey<Root>
|
|
588
|
+
: string
|
|
589
|
+
|
|
590
|
+
export interface GraphModule<
|
|
591
|
+
Parameter extends ParameterDefinition = ParameterDefinition,
|
|
592
|
+
ProjectionPath extends string = string,
|
|
593
|
+
OrderingName extends string = string,
|
|
594
|
+
ProjectionField extends ProjectionFieldDefinition = ProjectionFieldDefinition<ProjectionPath>,
|
|
595
|
+
Relation extends RelationDefinition = RelationDefinition,
|
|
596
|
+
ProjectionObject extends ProjectionObjectDefinition = ProjectionObjectDefinition,
|
|
597
|
+
> {
|
|
598
|
+
readonly name: string
|
|
599
|
+
readonly sources: readonly SourceRef[]
|
|
600
|
+
readonly parameters: readonly Parameter[]
|
|
601
|
+
readonly relations: readonly Relation[]
|
|
602
|
+
readonly constraints: readonly ConstraintDefinition[]
|
|
603
|
+
readonly projection: readonly ProjectionField[]
|
|
604
|
+
readonly objects: readonly ProjectionObject[]
|
|
605
|
+
readonly orderings: readonly OrderingDefinition<OrderingName>[]
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export function defineGraphModule<const Configuration extends GraphModuleConfiguration>(
|
|
609
|
+
configuration: Configuration,
|
|
610
|
+
): GraphModule<
|
|
611
|
+
ConfigurationParameter<Configuration>,
|
|
612
|
+
ConfigurationProjectionPath<Configuration>,
|
|
613
|
+
ConfigurationOrderingName<Configuration>,
|
|
614
|
+
ConfigurationProjectionField<Configuration>,
|
|
615
|
+
ConfigurationRelation<Configuration>,
|
|
616
|
+
ConfigurationProjectionObject<Configuration>
|
|
617
|
+
>
|
|
618
|
+
|
|
619
|
+
export interface GraphConfiguration {
|
|
620
|
+
name: string
|
|
621
|
+
root: string | SourceRef
|
|
622
|
+
modules?: readonly GraphModule[]
|
|
623
|
+
sources?: readonly SourceRef[]
|
|
624
|
+
parameters?: readonly ParameterDefinition[]
|
|
625
|
+
relations?: readonly RelationDefinition[]
|
|
626
|
+
constraints?: readonly ConstraintDefinition[]
|
|
627
|
+
projection?: readonly ProjectionFieldDefinition[]
|
|
628
|
+
objects?: readonly ProjectionObjectDefinition[]
|
|
629
|
+
orderings?: readonly OrderingDefinition[]
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export function defineGraph<const Configuration extends GraphConfiguration>(
|
|
633
|
+
configuration: Configuration,
|
|
634
|
+
): GraphDefinition<
|
|
635
|
+
ConfigurationParameter<Configuration>,
|
|
636
|
+
ConfigurationProjectionPath<Configuration>,
|
|
637
|
+
ConfigurationOrderingName<Configuration>,
|
|
638
|
+
ConfigurationProjectionField<Configuration>,
|
|
639
|
+
ConfigurationRelation<Configuration>,
|
|
640
|
+
ConfigurationRoot<Configuration>,
|
|
641
|
+
ConfigurationProjectionObject<Configuration>
|
|
642
|
+
>
|
|
643
|
+
|
|
644
|
+
export interface SummaryGraphConfiguration {
|
|
645
|
+
name: string
|
|
646
|
+
root: string | SourceRef
|
|
647
|
+
modules?: readonly GraphModule[]
|
|
648
|
+
sources?: readonly SourceRef[]
|
|
649
|
+
parameters?: readonly ParameterDefinition[]
|
|
650
|
+
relations?: readonly RelationDefinition[]
|
|
651
|
+
constraints?: readonly ConstraintDefinition[]
|
|
652
|
+
dimensions?: readonly DimensionDefinition[]
|
|
653
|
+
measures?: readonly MeasureDefinition[]
|
|
654
|
+
orderings?: readonly OrderingDefinition[]
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export function defineSummaryGraph<const Configuration extends SummaryGraphConfiguration>(
|
|
658
|
+
configuration: Configuration,
|
|
659
|
+
): GraphDefinition<
|
|
660
|
+
ConfigurationParameter<Configuration>,
|
|
661
|
+
ConfigurationProjectionPath<Configuration>,
|
|
662
|
+
ConfigurationOrderingName<Configuration>,
|
|
663
|
+
ConfigurationProjectionField<Configuration>,
|
|
664
|
+
ConfigurationRelation<Configuration>,
|
|
665
|
+
ConfigurationRoot<Configuration>,
|
|
666
|
+
never
|
|
667
|
+
>
|