@query-graph/core 1.1.4 → 1.1.6

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.
@@ -0,0 +1,702 @@
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
+ declare const parameterRefBrand: unique symbol
88
+
89
+ export interface ScalarParameterRef<
90
+ Name extends string = string,
91
+ Type extends ScalarType = ScalarType,
92
+ Required extends boolean = boolean,
93
+ > extends ParameterDefinition {
94
+ readonly [parameterRefBrand]: true
95
+ name: Name
96
+ scalarType: Type
97
+ shape?: 'scalar'
98
+ required?: Required
99
+ }
100
+
101
+ export interface ListParameterRef<
102
+ Name extends string = string,
103
+ Type extends ScalarType = ScalarType,
104
+ Required extends boolean = boolean,
105
+ > extends ParameterDefinition {
106
+ readonly [parameterRefBrand]: true
107
+ name: Name
108
+ scalarType: Type
109
+ shape: 'list'
110
+ required?: Required
111
+ }
112
+
113
+ export type ParameterRef<
114
+ Name extends string = string,
115
+ Type extends ScalarType = ScalarType,
116
+ Required extends boolean = boolean,
117
+ > = ScalarParameterRef<Name, Type, Required> | ListParameterRef<Name, Type, Required>
118
+
119
+ export type RelationRef<
120
+ Name extends string = string,
121
+ From extends string = string,
122
+ To extends string = string,
123
+ Required extends boolean = boolean,
124
+ Cardinality extends RelationCardinality = RelationCardinality,
125
+ > = RelationDefinition<Name, From, To, Required, Cardinality>
126
+
127
+ export type LiteralInput = null | boolean | string | number
128
+ export type ExpressionInput = Expression | LiteralInput | ScalarParameterRef | SummaryFieldDefinition
129
+
130
+ type NumberLiteralScalarType<Value extends number> = number extends Value
131
+ ? 'int64' | 'decimal'
132
+ : `${Value}` extends `${bigint}`
133
+ ? 'int64'
134
+ : 'decimal'
135
+
136
+ type InputScalarType<Input extends ExpressionInput> =
137
+ Input extends ExpressionTypeMetadata<infer Type, infer _Nullability>
138
+ ? Type
139
+ : Input extends ProjectionFieldDefinition<infer _Path, infer Type, infer _Nullability, infer _SelectedByDefault>
140
+ ? Type
141
+ : Input extends ScalarParameterRef<infer _Name, infer Type, infer _Required>
142
+ ? Type
143
+ : Input extends null
144
+ ? null
145
+ : Input extends boolean
146
+ ? 'boolean'
147
+ : Input extends string
148
+ ? 'string'
149
+ : Input extends number
150
+ ? NumberLiteralScalarType<Input>
151
+ : ScalarType
152
+
153
+ type InputNullability<Input extends ExpressionInput> =
154
+ Input extends ExpressionTypeMetadata<infer _Type, infer Nullability>
155
+ ? Nullability
156
+ : Input extends ProjectionFieldDefinition<infer _Path, infer _Type, infer Nullability, infer _SelectedByDefault>
157
+ ? Nullability
158
+ : Input extends ScalarParameterRef
159
+ ? false
160
+ : Input extends null
161
+ ? true
162
+ : Input extends Expression
163
+ ? boolean
164
+ : false
165
+
166
+ export type ExpressionScalarType<Input extends ExpressionInput> = InputScalarType<Input>
167
+ export type ExpressionNullability<Input extends ExpressionInput> = InputNullability<Input>
168
+
169
+ type PromoteScalarType<Type extends ScalarType | null> = 'float64' extends Type
170
+ ? 'float64'
171
+ : 'decimal' extends Type
172
+ ? 'decimal'
173
+ : 'int64' extends Type
174
+ ? 'int64'
175
+ : 'int32' extends Type
176
+ ? 'int32'
177
+ : 'dateTime' extends Type
178
+ ? 'dateTime'
179
+ : Exclude<Type, null>
180
+
181
+ type AverageScalarType<Type extends ScalarType | null> = Type extends 'float64'
182
+ ? 'float64'
183
+ : Type extends 'int32' | 'int64' | 'decimal'
184
+ ? 'decimal'
185
+ : Exclude<Type, null>
186
+
187
+ type DivideScalarType<Type extends ScalarType | null> = 'float64' extends Type ? 'float64' : 'decimal'
188
+
189
+ type InputNullabilities<Inputs extends readonly ExpressionInput[]> = {
190
+ [Index in keyof Inputs]: InputNullability<Inputs[Index]>
191
+ }
192
+
193
+ type AnyInputNullability<Inputs extends readonly ExpressionInput[]> = AnyNullability<InputNullabilities<Inputs>>
194
+ type AllInputNullability<Inputs extends readonly ExpressionInput[]> = AllNullability<InputNullabilities<Inputs>>
195
+
196
+ export interface FieldTypeOptions {
197
+ nullable?: boolean
198
+ selectable?: boolean
199
+ }
200
+
201
+ type OptionNullable<Options extends FieldTypeOptions> = Options extends { nullable: true } ? true : false
202
+ type OptionSelectable<Options extends FieldTypeOptions> = Options extends { selectable: false } ? false : true
203
+
204
+ export function fieldType<const Type extends ScalarType, const Options extends FieldTypeOptions = Record<never, never>>(
205
+ scalarType: Type,
206
+ options?: Options,
207
+ ): FieldSpecDefinition<Type, OptionNullable<Options>, OptionSelectable<Options>>
208
+ export function nullable<const Specification extends FieldSpec>(
209
+ specification: Specification,
210
+ ): FieldSpecDefinition<FieldSpecScalarType<Specification>, true, FieldSpecIsSelectable<Specification>>
211
+ export function hidden<const Specification extends FieldSpec>(
212
+ specification: Specification,
213
+ ): FieldSpecDefinition<FieldSpecScalarType<Specification>, FieldSpecIsNullable<Specification>, false>
214
+
215
+ export function source<const Key extends string, const Fields extends FieldSpecMap>(
216
+ key: Key,
217
+ fields: Fields,
218
+ ): SourceRef<Key, Fields>
219
+
220
+ export function requiredParameter<const Name extends string, const Type extends ScalarType>(
221
+ name: Name,
222
+ scalarType: Type,
223
+ ): ScalarParameterRef<Name, Type, true>
224
+ export const requiredParam: typeof requiredParameter
225
+ export function optionalParameter<const Name extends string, const Type extends ScalarType>(
226
+ name: Name,
227
+ scalarType: Type,
228
+ ): ScalarParameterRef<Name, Type, false>
229
+ export const optionalParam: typeof optionalParameter
230
+ export function requiredListParameter<const Name extends string, const Type extends ScalarType>(
231
+ name: Name,
232
+ scalarType: Type,
233
+ ): ListParameterRef<Name, Type, true>
234
+ export const requiredListParam: typeof requiredListParameter
235
+ export function optionalListParameter<const Name extends string, const Type extends ScalarType>(
236
+ name: Name,
237
+ scalarType: Type,
238
+ ): ListParameterRef<Name, Type, false>
239
+ export const optionalListParam: typeof optionalListParameter
240
+ /** @deprecated Pass a scalar parameter reference directly to an expression factory. */
241
+ export function param<const Name extends string, const Type extends ScalarType>(
242
+ parameter: ScalarParameterRef<Name, Type>,
243
+ ): TypedExpression<ParameterExpression<Name>, Type, false>
244
+
245
+ export function literal<const Value extends LiteralInput>(
246
+ value: Value,
247
+ ): TypedExpression<LiteralExpression, InputScalarType<Value>, InputNullability<Value>>
248
+ export function integer(value: number): TypedExpression<LiteralExpression, 'int64', false>
249
+ export function decimal(value: string | number): TypedExpression<LiteralExpression, 'decimal', false>
250
+
251
+ type EqualityNullability<Left extends ExpressionInput, Right extends ExpressionInput> = null extends
252
+ | InputScalarType<Left>
253
+ | InputScalarType<Right>
254
+ ? false
255
+ : AnyInputNullability<readonly [Left, Right]>
256
+
257
+ export function eq<const Left extends ExpressionInput, const Right extends ExpressionInput>(
258
+ left: Left,
259
+ right: Right,
260
+ ): TypedExpression<BinaryExpression, 'boolean', EqualityNullability<Left, Right>>
261
+ export function neq<const Left extends ExpressionInput, const Right extends ExpressionInput>(
262
+ left: Left,
263
+ right: Right,
264
+ ): TypedExpression<BinaryExpression, 'boolean', EqualityNullability<Left, Right>>
265
+ export function lt<const Left extends ExpressionInput, const Right extends ExpressionInput>(
266
+ left: Left,
267
+ right: Right,
268
+ ): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
269
+ export function lte<const Left extends ExpressionInput, const Right extends ExpressionInput>(
270
+ left: Left,
271
+ right: Right,
272
+ ): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
273
+ export function gt<const Left extends ExpressionInput, const Right extends ExpressionInput>(
274
+ left: Left,
275
+ right: Right,
276
+ ): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
277
+ export function gte<const Left extends ExpressionInput, const Right extends ExpressionInput>(
278
+ left: Left,
279
+ right: Right,
280
+ ): TypedExpression<BinaryExpression, 'boolean', AnyInputNullability<readonly [Left, Right]>>
281
+ export function like<const Value extends ExpressionInput, const Pattern extends ExpressionInput>(
282
+ expression: Value,
283
+ pattern: Pattern,
284
+ ): TypedExpression<LikeExpression, 'boolean', AnyInputNullability<readonly [Value, Pattern]>>
285
+ export function inList<const Value extends ExpressionInput, const Values extends readonly ExpressionInput[]>(
286
+ expression: Value,
287
+ values: Values,
288
+ ): TypedExpression<InExpression, 'boolean', AnyInputNullability<readonly [Value, ...Values]>>
289
+ export function and<const Expressions extends readonly ExpressionInput[]>(
290
+ ...expressions: Expressions
291
+ ): TypedExpression<ExpressionGroup, 'boolean', AnyInputNullability<Expressions>>
292
+ export function inParameter<
293
+ const Value extends ExpressionInput,
294
+ const Name extends string,
295
+ const Type extends ScalarType,
296
+ >(
297
+ expression: Value,
298
+ parameter: ListParameterRef<Name, Type>,
299
+ ): TypedExpression<InParameterExpression<Name>, 'boolean', InputNullability<Value>>
300
+ export const inParam: typeof inParameter
301
+ export function or<const Expressions extends readonly ExpressionInput[]>(
302
+ ...expressions: Expressions
303
+ ): TypedExpression<ExpressionGroup, 'boolean', AnyInputNullability<Expressions>>
304
+ export function not<const Value extends ExpressionInput>(
305
+ expression: Value,
306
+ ): TypedExpression<UnaryExpression, 'boolean', InputNullability<Value>>
307
+ export function isNull(expression: ExpressionInput): TypedExpression<UnaryExpression, 'boolean', false>
308
+ export function isNotNull(expression: ExpressionInput): TypedExpression<UnaryExpression, 'boolean', false>
309
+ export function exists<const Source extends string>(
310
+ source: Source | SourceRef<Source>,
311
+ predicate?: ExpressionInput,
312
+ ): TypedExpression<ExistsExpression<Source, never>, 'boolean', false>
313
+ export interface ExistsConfiguration<From extends string = string> {
314
+ from: From | SourceRef<From>
315
+ }
316
+ export function exists<const Source extends string, const From extends string>(
317
+ source: Source | SourceRef<Source>,
318
+ predicate: ExpressionInput | undefined,
319
+ configuration: ExistsConfiguration<From>,
320
+ ): TypedExpression<ExistsExpression<Source, From>, 'boolean', false>
321
+
322
+ export function lower<const Value extends ExpressionInput>(
323
+ expression: Value,
324
+ ): TypedExpression<FunctionExpression, 'string', InputNullability<Value>>
325
+ export function upper<const Value extends ExpressionInput>(
326
+ expression: Value,
327
+ ): TypedExpression<FunctionExpression, 'string', InputNullability<Value>>
328
+ export function coalesce<
329
+ const First extends ExpressionInput,
330
+ const Second extends ExpressionInput,
331
+ const Rest extends readonly ExpressionInput[],
332
+ >(
333
+ first: First,
334
+ second: Second,
335
+ ...rest: Rest
336
+ ): TypedExpression<
337
+ FunctionExpression,
338
+ PromoteScalarType<InputScalarType<First | Second | Rest[number]>>,
339
+ AllInputNullability<readonly [First, Second, ...Rest]>
340
+ >
341
+ export function concat<const First extends ExpressionInput, const Rest extends readonly ExpressionInput[]>(
342
+ first: First,
343
+ ...rest: Rest
344
+ ): TypedExpression<FunctionExpression, 'string', AllInputNullability<readonly [First, ...Rest]>>
345
+ export function divide<const Left extends ExpressionInput, const Right extends ExpressionInput>(
346
+ left: Left,
347
+ right: Right,
348
+ ): TypedExpression<
349
+ FunctionExpression,
350
+ DivideScalarType<InputScalarType<Left | Right>>,
351
+ AnyInputNullability<readonly [Left, Right]>
352
+ >
353
+ export function truncate<const Value extends ExpressionInput>(
354
+ expression: Value,
355
+ ): TypedExpression<FunctionExpression, Exclude<InputScalarType<Value>, null>, InputNullability<Value>>
356
+ export function modulo<const Left extends ExpressionInput, const Right extends ExpressionInput>(
357
+ left: Left,
358
+ right: Right,
359
+ ): TypedExpression<
360
+ FunctionExpression,
361
+ PromoteScalarType<InputScalarType<Left | Right>>,
362
+ AnyInputNullability<readonly [Left, Right]>
363
+ >
364
+
365
+ export function count(expression?: ExpressionInput): TypedExpression<AggregateExpression, 'int64', false>
366
+ export function countDistinct(expression: ExpressionInput): TypedExpression<AggregateExpression, 'int64', false>
367
+ export function sum<const Value extends ExpressionInput>(
368
+ expression: Value,
369
+ ): TypedExpression<AggregateExpression, Exclude<InputScalarType<Value>, null>, true>
370
+ export function average<const Value extends ExpressionInput>(
371
+ expression: Value,
372
+ ): TypedExpression<AggregateExpression, AverageScalarType<InputScalarType<Value>>, true>
373
+ export function minimum<const Value extends ExpressionInput>(
374
+ expression: Value,
375
+ ): TypedExpression<AggregateExpression, Exclude<InputScalarType<Value>, null>, true>
376
+ export function maximum<const Value extends ExpressionInput>(
377
+ expression: Value,
378
+ ): TypedExpression<AggregateExpression, Exclude<InputScalarType<Value>, null>, true>
379
+
380
+ export type SourceReferenceKey<Reference extends string | SourceRef> =
381
+ Reference extends SourceRef<infer Key, infer _Fields> ? Key : Reference extends string ? Reference : string
382
+
383
+ export interface RelationConfiguration<
384
+ Name extends string = string,
385
+ From extends string | SourceRef = string | SourceRef,
386
+ To extends string | SourceRef = string | SourceRef,
387
+ Required extends boolean = boolean,
388
+ Cardinality extends RelationCardinality = RelationCardinality,
389
+ > {
390
+ name: Name
391
+ from: From
392
+ to: To
393
+ on: Expression
394
+ required?: Required
395
+ cardinality?: Cardinality
396
+ selection?: RelationSelection
397
+ }
398
+
399
+ export function relation<
400
+ const Name extends string,
401
+ const From extends string | SourceRef,
402
+ const To extends string | SourceRef,
403
+ const Required extends boolean = false,
404
+ const Cardinality extends RelationCardinality = 'one',
405
+ >(
406
+ configuration: RelationConfiguration<Name, From, To, Required, Cardinality>,
407
+ ): RelationRef<Name, SourceReferenceKey<From>, SourceReferenceKey<To>, Required, Cardinality>
408
+
409
+ export interface ConstraintConfiguration {
410
+ predicate: Expression
411
+ when?: string | ParameterRef
412
+ }
413
+
414
+ export function constraint(configuration: ConstraintConfiguration): ConstraintDefinition
415
+
416
+ export interface ProjectionConfiguration<
417
+ Path extends string | readonly string[] = string | readonly string[],
418
+ Value extends ExpressionInput = ExpressionInput,
419
+ SelectedByDefault extends boolean = boolean,
420
+ > {
421
+ path: Path
422
+ expression: Value
423
+ default?: SelectedByDefault
424
+ }
425
+
426
+ export interface ProjectionObjectConfiguration<
427
+ Path extends string | readonly string[] = string | readonly string[],
428
+ Value extends ExpressionInput = ExpressionInput,
429
+ > {
430
+ path: Path
431
+ presence: Value
432
+ }
433
+
434
+ type ConfigurationPath<Path extends string | readonly string[]> = Path extends string
435
+ ? Path
436
+ : Path extends readonly string[]
437
+ ? JoinProjectionPath<Path>
438
+ : never
439
+
440
+ export function project<
441
+ const Path extends string | readonly string[],
442
+ const Value extends ExpressionInput,
443
+ const SelectedByDefault extends boolean = false,
444
+ >(
445
+ configuration: ProjectionConfiguration<Path, Value, SelectedByDefault>,
446
+ ): TypedProjectionField<
447
+ ConfigurationPath<Path>,
448
+ Extract<InputScalarType<Value>, ScalarType>,
449
+ InputNullability<Value>,
450
+ SelectedByDefault
451
+ >
452
+
453
+ export function projectObject<const Path extends string | readonly string[], const Value extends ExpressionInput>(
454
+ configuration: ProjectionObjectConfiguration<Path, Value>,
455
+ ): TypedProjectionObject<ConfigurationPath<Path>, InputNullability<Value>>
456
+
457
+ export function dimension<
458
+ const Path extends string | readonly string[],
459
+ const Value extends ExpressionInput,
460
+ const SelectedByDefault extends boolean = false,
461
+ >(
462
+ configuration: ProjectionConfiguration<Path, Value, SelectedByDefault>,
463
+ ): TypedDimensionDefinition<
464
+ ConfigurationPath<Path>,
465
+ Extract<InputScalarType<Value>, ScalarType>,
466
+ InputNullability<Value>,
467
+ SelectedByDefault
468
+ >
469
+
470
+ export function measure<
471
+ const Path extends string | readonly string[],
472
+ const Value extends ExpressionInput,
473
+ const SelectedByDefault extends boolean = false,
474
+ >(
475
+ configuration: ProjectionConfiguration<Path, Value, SelectedByDefault>,
476
+ ): TypedMeasureDefinition<
477
+ ConfigurationPath<Path>,
478
+ Extract<InputScalarType<Value>, ScalarType>,
479
+ InputNullability<Value>,
480
+ SelectedByDefault
481
+ >
482
+
483
+ export interface OrderByOptions {
484
+ nulls?: NullsOrder
485
+ }
486
+
487
+ export function asc(expression: ExpressionInput, options?: OrderByOptions): OrderByDefinition
488
+ export function desc(expression: ExpressionInput, options?: OrderByOptions): OrderByDefinition
489
+
490
+ export function firstBy(firstOrder: OrderByDefinition, ...rest: readonly OrderByDefinition[]): FirstBySelection
491
+
492
+ export interface OrderingConfiguration<Name extends string = string> {
493
+ name: Name
494
+ by: readonly [OrderByDefinition, ...OrderByDefinition[]]
495
+ default?: boolean
496
+ }
497
+
498
+ export function ordering<const Name extends string>(
499
+ configuration: OrderingConfiguration<Name>,
500
+ ): OrderingDefinition<Name>
501
+
502
+ export interface GraphModuleConfiguration {
503
+ name: string
504
+ modules?: readonly GraphModule[]
505
+ sources?: readonly SourceRef[]
506
+ parameters?: readonly ParameterDefinition[]
507
+ relations?: readonly RelationDefinition[]
508
+ constraints?: readonly ConstraintDefinition[]
509
+ projection?: readonly ProjectionFieldDefinition[]
510
+ objects?: readonly ProjectionObjectDefinition[]
511
+ orderings?: readonly OrderingDefinition[]
512
+ }
513
+
514
+ type ConfigurationElement<Configuration, Key extends PropertyKey> = Key extends keyof Configuration
515
+ ? NonNullable<Configuration[Key]> extends readonly (infer Element)[]
516
+ ? Element
517
+ : never
518
+ : never
519
+
520
+ type ModuleParameter<Module> =
521
+ Module extends GraphModule<
522
+ infer Parameter,
523
+ infer _ProjectionPath,
524
+ infer _OrderingName,
525
+ infer _ProjectionField,
526
+ infer _Relation
527
+ >
528
+ ? Parameter
529
+ : never
530
+
531
+ type ModuleProjectionPath<Module> =
532
+ Module extends GraphModule<
533
+ infer _Parameter,
534
+ infer ProjectionPath,
535
+ infer _OrderingName,
536
+ infer _ProjectionField,
537
+ infer _Relation
538
+ >
539
+ ? ProjectionPath
540
+ : never
541
+
542
+ type ModuleOrderingName<Module> =
543
+ Module extends GraphModule<
544
+ infer _Parameter,
545
+ infer _ProjectionPath,
546
+ infer OrderingName,
547
+ infer _ProjectionField,
548
+ infer _Relation
549
+ >
550
+ ? OrderingName
551
+ : never
552
+
553
+ type ModuleProjectionField<Module> =
554
+ Module extends GraphModule<
555
+ infer _Parameter,
556
+ infer _ProjectionPath,
557
+ infer _OrderingName,
558
+ infer ProjectionField,
559
+ infer _Relation
560
+ >
561
+ ? ProjectionField
562
+ : never
563
+
564
+ type ModuleRelation<Module> =
565
+ Module extends GraphModule<
566
+ infer _Parameter,
567
+ infer _ProjectionPath,
568
+ infer _OrderingName,
569
+ infer _ProjectionField,
570
+ infer Relation
571
+ >
572
+ ? Relation
573
+ : never
574
+
575
+ type ModuleProjectionObject<Module> =
576
+ Module extends GraphModule<
577
+ infer _Parameter,
578
+ infer _ProjectionPath,
579
+ infer _OrderingName,
580
+ infer _ProjectionField,
581
+ infer _Relation,
582
+ infer ProjectionObject
583
+ >
584
+ ? ProjectionObject
585
+ : never
586
+
587
+ type ProjectionPathOf<Field> = Field extends ProjectionFieldDefinition<infer Path> ? Path : never
588
+
589
+ type OrderingNameOf<Ordering> = Ordering extends OrderingDefinition<infer Name> ? Name : never
590
+
591
+ type ConfigurationParameter<Configuration> =
592
+ | Extract<ConfigurationElement<Configuration, 'parameters'>, ParameterDefinition>
593
+ | ModuleParameter<ConfigurationElement<Configuration, 'modules'>>
594
+
595
+ type ConfigurationProjectionPath<Configuration> =
596
+ | ProjectionPathOf<ConfigurationElement<Configuration, 'projection'>>
597
+ | ProjectionPathOf<ConfigurationElement<Configuration, 'dimensions'>>
598
+ | ProjectionPathOf<ConfigurationElement<Configuration, 'measures'>>
599
+ | ModuleProjectionPath<ConfigurationElement<Configuration, 'modules'>>
600
+
601
+ type ConfigurationProjectionField<Configuration> =
602
+ | Extract<ConfigurationElement<Configuration, 'projection'>, ProjectionFieldDefinition>
603
+ | Extract<ConfigurationElement<Configuration, 'dimensions'>, ProjectionFieldDefinition>
604
+ | Extract<ConfigurationElement<Configuration, 'measures'>, ProjectionFieldDefinition>
605
+ | ModuleProjectionField<ConfigurationElement<Configuration, 'modules'>>
606
+
607
+ type ConfigurationProjectionObject<Configuration> =
608
+ | Extract<ConfigurationElement<Configuration, 'objects'>, ProjectionObjectDefinition>
609
+ | ModuleProjectionObject<ConfigurationElement<Configuration, 'modules'>>
610
+
611
+ type ConfigurationOrderingName<Configuration> =
612
+ | OrderingNameOf<ConfigurationElement<Configuration, 'orderings'>>
613
+ | ModuleOrderingName<ConfigurationElement<Configuration, 'modules'>>
614
+
615
+ type ConfigurationRelation<Configuration> =
616
+ | Extract<ConfigurationElement<Configuration, 'relations'>, RelationDefinition>
617
+ | ModuleRelation<ConfigurationElement<Configuration, 'modules'>>
618
+
619
+ type ConfigurationRoot<Configuration> = Configuration extends {
620
+ root: infer Root extends string | SourceRef
621
+ }
622
+ ? SourceReferenceKey<Root>
623
+ : string
624
+
625
+ export interface GraphModule<
626
+ Parameter extends ParameterDefinition = ParameterDefinition,
627
+ ProjectionPath extends string = string,
628
+ OrderingName extends string = string,
629
+ ProjectionField extends ProjectionFieldDefinition = ProjectionFieldDefinition<ProjectionPath>,
630
+ Relation extends RelationDefinition = RelationDefinition,
631
+ ProjectionObject extends ProjectionObjectDefinition = ProjectionObjectDefinition,
632
+ > {
633
+ readonly name: string
634
+ readonly sources: readonly SourceRef[]
635
+ readonly parameters: readonly Parameter[]
636
+ readonly relations: readonly Relation[]
637
+ readonly constraints: readonly ConstraintDefinition[]
638
+ readonly projection: readonly ProjectionField[]
639
+ readonly objects: readonly ProjectionObject[]
640
+ readonly orderings: readonly OrderingDefinition<OrderingName>[]
641
+ }
642
+
643
+ export function defineGraphModule<const Configuration extends GraphModuleConfiguration>(
644
+ configuration: Configuration,
645
+ ): GraphModule<
646
+ ConfigurationParameter<Configuration>,
647
+ ConfigurationProjectionPath<Configuration>,
648
+ ConfigurationOrderingName<Configuration>,
649
+ ConfigurationProjectionField<Configuration>,
650
+ ConfigurationRelation<Configuration>,
651
+ ConfigurationProjectionObject<Configuration>
652
+ >
653
+
654
+ export interface GraphConfiguration {
655
+ name: string
656
+ root: string | SourceRef
657
+ modules?: readonly GraphModule[]
658
+ sources?: readonly SourceRef[]
659
+ parameters?: readonly ParameterDefinition[]
660
+ relations?: readonly RelationDefinition[]
661
+ constraints?: readonly ConstraintDefinition[]
662
+ projection?: readonly ProjectionFieldDefinition[]
663
+ objects?: readonly ProjectionObjectDefinition[]
664
+ orderings?: readonly OrderingDefinition[]
665
+ }
666
+
667
+ export function defineGraph<const Configuration extends GraphConfiguration>(
668
+ configuration: Configuration,
669
+ ): GraphDefinition<
670
+ ConfigurationParameter<Configuration>,
671
+ ConfigurationProjectionPath<Configuration>,
672
+ ConfigurationOrderingName<Configuration>,
673
+ ConfigurationProjectionField<Configuration>,
674
+ ConfigurationRelation<Configuration>,
675
+ ConfigurationRoot<Configuration>,
676
+ ConfigurationProjectionObject<Configuration>
677
+ >
678
+
679
+ export interface SummaryGraphConfiguration {
680
+ name: string
681
+ root: string | SourceRef
682
+ modules?: readonly GraphModule[]
683
+ sources?: readonly SourceRef[]
684
+ parameters?: readonly ParameterDefinition[]
685
+ relations?: readonly RelationDefinition[]
686
+ constraints?: readonly ConstraintDefinition[]
687
+ dimensions?: readonly DimensionDefinition[]
688
+ measures?: readonly MeasureDefinition[]
689
+ orderings?: readonly OrderingDefinition[]
690
+ }
691
+
692
+ export function defineSummaryGraph<const Configuration extends SummaryGraphConfiguration>(
693
+ configuration: Configuration,
694
+ ): GraphDefinition<
695
+ ConfigurationParameter<Configuration>,
696
+ ConfigurationProjectionPath<Configuration>,
697
+ ConfigurationOrderingName<Configuration>,
698
+ ConfigurationProjectionField<Configuration>,
699
+ ConfigurationRelation<Configuration>,
700
+ ConfigurationRoot<Configuration>,
701
+ never
702
+ >