@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
package/types/model.d.ts
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
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
|
+
type BooleanOr<Value extends boolean> = true extends Value ? true : false
|
|
36
|
+
|
|
37
|
+
export interface SourceFieldNullability<Source extends string = string, FieldNullable extends boolean = boolean> {
|
|
38
|
+
kind: 'sourceField'
|
|
39
|
+
source: Source
|
|
40
|
+
fieldNullable: FieldNullable
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AnyNullability<Values = unknown> {
|
|
44
|
+
kind: 'any'
|
|
45
|
+
values: Values
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AllNullability<Values = unknown> {
|
|
49
|
+
kind: 'all'
|
|
50
|
+
values: Values
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type NullabilityExpression = boolean | SourceFieldNullability | AnyNullability | AllNullability
|
|
54
|
+
|
|
55
|
+
declare const expressionTypeMetadata: unique symbol
|
|
56
|
+
|
|
57
|
+
export interface ExpressionTypeMetadata<
|
|
58
|
+
Type extends ScalarType | null = ScalarType,
|
|
59
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
60
|
+
> {
|
|
61
|
+
readonly [expressionTypeMetadata]: {
|
|
62
|
+
scalarType: Type
|
|
63
|
+
nullability: Nullability
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type TypedExpression<
|
|
68
|
+
Definition extends Expression = Expression,
|
|
69
|
+
Type extends ScalarType | null = ScalarType,
|
|
70
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
71
|
+
> = Definition & ExpressionTypeMetadata<Type, Nullability>
|
|
72
|
+
|
|
73
|
+
export interface FieldDefinition {
|
|
74
|
+
name: string
|
|
75
|
+
scalarType: ScalarType
|
|
76
|
+
nullable?: boolean
|
|
77
|
+
selectable?: boolean
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface SourceDefinition {
|
|
81
|
+
key: string
|
|
82
|
+
fields: FieldDefinition[]
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ParameterDefinition {
|
|
86
|
+
name: string
|
|
87
|
+
scalarType: ScalarType
|
|
88
|
+
shape?: ParameterShape
|
|
89
|
+
required?: boolean
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface FieldExpression<Source extends string = string, Field extends string = string> {
|
|
93
|
+
kind: 'field'
|
|
94
|
+
source: Source
|
|
95
|
+
field: Field
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ParameterExpression<Name extends string = string> {
|
|
99
|
+
kind: 'parameter'
|
|
100
|
+
name: Name
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export type LiteralValue =
|
|
104
|
+
| { kind: 'null' }
|
|
105
|
+
| { kind: 'boolean'; value: boolean }
|
|
106
|
+
| { kind: 'integer'; value: number }
|
|
107
|
+
| { kind: 'decimal'; value: string }
|
|
108
|
+
| { kind: 'string'; value: string }
|
|
109
|
+
|
|
110
|
+
export interface LiteralExpression {
|
|
111
|
+
kind: 'literal'
|
|
112
|
+
value: LiteralValue
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type BinaryExpressionKind =
|
|
116
|
+
| 'eq'
|
|
117
|
+
| 'notEq'
|
|
118
|
+
| 'lessThan'
|
|
119
|
+
| 'lessThanOrEqual'
|
|
120
|
+
| 'greaterThan'
|
|
121
|
+
| 'greaterThanOrEqual'
|
|
122
|
+
|
|
123
|
+
export interface BinaryExpression {
|
|
124
|
+
kind: BinaryExpressionKind
|
|
125
|
+
left: Expression
|
|
126
|
+
right: Expression
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface LikeExpression {
|
|
130
|
+
kind: 'like'
|
|
131
|
+
expression: Expression
|
|
132
|
+
pattern: Expression
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface InExpression {
|
|
136
|
+
kind: 'in'
|
|
137
|
+
expression: Expression
|
|
138
|
+
values: Expression[]
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface InParameterExpression<Name extends string = string> {
|
|
142
|
+
kind: 'inParameter'
|
|
143
|
+
expression: Expression
|
|
144
|
+
parameter: Name
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface ExpressionGroup {
|
|
148
|
+
kind: 'and' | 'or'
|
|
149
|
+
expressions: Expression[]
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface UnaryExpression {
|
|
153
|
+
kind: 'not' | 'isNull' | 'isNotNull'
|
|
154
|
+
expression: Expression
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface ExistsExpression<Source extends string = string, From extends string = string> {
|
|
158
|
+
kind: 'exists'
|
|
159
|
+
source: Source
|
|
160
|
+
from?: From
|
|
161
|
+
predicate?: Expression
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface FunctionExpression {
|
|
165
|
+
kind: 'function'
|
|
166
|
+
name: SemanticFunctionName
|
|
167
|
+
arguments: Expression[]
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface AggregateExpression {
|
|
171
|
+
kind: 'aggregate'
|
|
172
|
+
function: AggregateFunctionName
|
|
173
|
+
expression?: Expression
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export type Expression =
|
|
177
|
+
| FieldExpression
|
|
178
|
+
| ParameterExpression
|
|
179
|
+
| LiteralExpression
|
|
180
|
+
| BinaryExpression
|
|
181
|
+
| LikeExpression
|
|
182
|
+
| InExpression
|
|
183
|
+
| InParameterExpression
|
|
184
|
+
| ExpressionGroup
|
|
185
|
+
| UnaryExpression
|
|
186
|
+
| ExistsExpression
|
|
187
|
+
| FunctionExpression
|
|
188
|
+
| AggregateExpression
|
|
189
|
+
|
|
190
|
+
export interface RelationDefinition<
|
|
191
|
+
Name extends string = string,
|
|
192
|
+
From extends string = string,
|
|
193
|
+
To extends string = string,
|
|
194
|
+
Required extends boolean = boolean,
|
|
195
|
+
Cardinality extends RelationCardinality = RelationCardinality,
|
|
196
|
+
> {
|
|
197
|
+
name: Name
|
|
198
|
+
from: From
|
|
199
|
+
to: To
|
|
200
|
+
cardinality?: Cardinality
|
|
201
|
+
required?: Required
|
|
202
|
+
selection?: RelationSelection
|
|
203
|
+
on: Expression
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export type ConstraintCondition = { kind: 'always' } | { kind: 'parameterPresent'; parameter: string }
|
|
207
|
+
|
|
208
|
+
export interface ConstraintDefinition {
|
|
209
|
+
when?: ConstraintCondition
|
|
210
|
+
predicate: Expression
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export type JoinProjectionPath<Segments extends readonly string[]> = number extends Segments['length']
|
|
214
|
+
? string
|
|
215
|
+
: Segments extends readonly []
|
|
216
|
+
? ''
|
|
217
|
+
: Segments extends readonly [infer Only extends string]
|
|
218
|
+
? Only
|
|
219
|
+
: Segments extends readonly [infer Head extends string, ...infer Tail extends readonly string[]]
|
|
220
|
+
? `${Head}.${JoinProjectionPath<Tail>}`
|
|
221
|
+
: string
|
|
222
|
+
|
|
223
|
+
declare const projectionPathType: unique symbol
|
|
224
|
+
declare const projectionScalarType: unique symbol
|
|
225
|
+
declare const projectionNullabilityType: unique symbol
|
|
226
|
+
declare const projectionDefaultType: unique symbol
|
|
227
|
+
declare const projectionObjectPathType: unique symbol
|
|
228
|
+
declare const projectionObjectNullabilityType: unique symbol
|
|
229
|
+
declare const summaryFieldType: unique symbol
|
|
230
|
+
declare const typedProjectionPathType: unique symbol
|
|
231
|
+
declare const typedProjectionScalarType: unique symbol
|
|
232
|
+
declare const typedProjectionNullabilityType: unique symbol
|
|
233
|
+
declare const typedProjectionDefaultType: unique symbol
|
|
234
|
+
declare const typedProjectionObjectPathType: unique symbol
|
|
235
|
+
declare const typedProjectionObjectNullabilityType: unique symbol
|
|
236
|
+
|
|
237
|
+
export interface ProjectionTypeMetadata<
|
|
238
|
+
Path extends string = string,
|
|
239
|
+
Type extends ScalarType = ScalarType,
|
|
240
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
241
|
+
SelectedByDefault extends boolean = boolean,
|
|
242
|
+
> {
|
|
243
|
+
readonly [typedProjectionPathType]: Path
|
|
244
|
+
readonly [typedProjectionScalarType]: Type
|
|
245
|
+
readonly [typedProjectionNullabilityType]: Nullability
|
|
246
|
+
readonly [typedProjectionDefaultType]: SelectedByDefault
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface ProjectionObjectTypeMetadata<
|
|
250
|
+
Path extends string = string,
|
|
251
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
252
|
+
> {
|
|
253
|
+
readonly [typedProjectionObjectPathType]: Path
|
|
254
|
+
readonly [typedProjectionObjectNullabilityType]: Nullability
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export type TypedProjectionObject<
|
|
258
|
+
Path extends string = string,
|
|
259
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
260
|
+
> = ProjectionObjectDefinition<Path, Nullability> & ProjectionObjectTypeMetadata<Path, Nullability>
|
|
261
|
+
|
|
262
|
+
export type TypedProjectionField<
|
|
263
|
+
Path extends string = string,
|
|
264
|
+
Type extends ScalarType = ScalarType,
|
|
265
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
266
|
+
SelectedByDefault extends boolean = boolean,
|
|
267
|
+
> = ProjectionFieldDefinition<Path, Type, Nullability, SelectedByDefault> &
|
|
268
|
+
ProjectionTypeMetadata<Path, Type, Nullability, SelectedByDefault>
|
|
269
|
+
|
|
270
|
+
export type TypedDimensionDefinition<
|
|
271
|
+
Path extends string = string,
|
|
272
|
+
Type extends ScalarType = ScalarType,
|
|
273
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
274
|
+
SelectedByDefault extends boolean = boolean,
|
|
275
|
+
> = DimensionDefinition<Path, Type, Nullability, SelectedByDefault> &
|
|
276
|
+
ProjectionTypeMetadata<Path, Type, Nullability, SelectedByDefault>
|
|
277
|
+
|
|
278
|
+
export type TypedMeasureDefinition<
|
|
279
|
+
Path extends string = string,
|
|
280
|
+
Type extends ScalarType = ScalarType,
|
|
281
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
282
|
+
SelectedByDefault extends boolean = boolean,
|
|
283
|
+
> = MeasureDefinition<Path, Type, Nullability, SelectedByDefault> &
|
|
284
|
+
ProjectionTypeMetadata<Path, Type, Nullability, SelectedByDefault>
|
|
285
|
+
|
|
286
|
+
export interface ProjectionFieldDefinition<
|
|
287
|
+
Path extends string = string,
|
|
288
|
+
Type extends ScalarType = ScalarType,
|
|
289
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
290
|
+
SelectedByDefault extends boolean = boolean,
|
|
291
|
+
> {
|
|
292
|
+
path: string[]
|
|
293
|
+
readonly [projectionPathType]?: Path
|
|
294
|
+
readonly [projectionScalarType]?: Type
|
|
295
|
+
readonly [projectionNullabilityType]?: Nullability
|
|
296
|
+
readonly [projectionDefaultType]?: SelectedByDefault
|
|
297
|
+
expression: Expression
|
|
298
|
+
role?: ProjectionFieldRole
|
|
299
|
+
selectedByDefault?: boolean
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface ProjectionObjectDefinition<
|
|
303
|
+
Path extends string = string,
|
|
304
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
305
|
+
> {
|
|
306
|
+
path: string[]
|
|
307
|
+
readonly [projectionObjectPathType]?: Path
|
|
308
|
+
readonly [projectionObjectNullabilityType]?: Nullability
|
|
309
|
+
presence: Expression
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface DimensionDefinition<
|
|
313
|
+
Path extends string = string,
|
|
314
|
+
Type extends ScalarType = ScalarType,
|
|
315
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
316
|
+
SelectedByDefault extends boolean = boolean,
|
|
317
|
+
> extends ProjectionFieldDefinition<Path, Type, Nullability, SelectedByDefault> {
|
|
318
|
+
readonly [summaryFieldType]: 'dimension'
|
|
319
|
+
role: 'dimension'
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface MeasureDefinition<
|
|
323
|
+
Path extends string = string,
|
|
324
|
+
Type extends ScalarType = ScalarType,
|
|
325
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
326
|
+
SelectedByDefault extends boolean = boolean,
|
|
327
|
+
> extends ProjectionFieldDefinition<Path, Type, Nullability, SelectedByDefault> {
|
|
328
|
+
readonly [summaryFieldType]: 'measure'
|
|
329
|
+
role: 'measure'
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export type SummaryFieldDefinition<
|
|
333
|
+
Path extends string = string,
|
|
334
|
+
Type extends ScalarType = ScalarType,
|
|
335
|
+
Nullability extends NullabilityExpression = NullabilityExpression,
|
|
336
|
+
SelectedByDefault extends boolean = boolean,
|
|
337
|
+
> =
|
|
338
|
+
| DimensionDefinition<Path, Type, Nullability, SelectedByDefault>
|
|
339
|
+
| MeasureDefinition<Path, Type, Nullability, SelectedByDefault>
|
|
340
|
+
|
|
341
|
+
export interface ProjectionDefinition<
|
|
342
|
+
Path extends string = string,
|
|
343
|
+
Field extends ProjectionFieldDefinition = ProjectionFieldDefinition<Path>,
|
|
344
|
+
Object extends ProjectionObjectDefinition = ProjectionObjectDefinition,
|
|
345
|
+
> {
|
|
346
|
+
fields: Field[]
|
|
347
|
+
objects: Object[]
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface ProjectionDefinitionInput<
|
|
351
|
+
Path extends string = string,
|
|
352
|
+
Field extends ProjectionFieldDefinition = ProjectionFieldDefinition<Path>,
|
|
353
|
+
Object extends ProjectionObjectDefinition = ProjectionObjectDefinition,
|
|
354
|
+
> {
|
|
355
|
+
fields?: Field[]
|
|
356
|
+
objects?: Object[]
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface OrderByDefinition {
|
|
360
|
+
expression: Expression
|
|
361
|
+
direction: OrderDirection
|
|
362
|
+
nulls?: NullsOrder
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export interface OrderingDefinition<Name extends string = string> {
|
|
366
|
+
name: Name
|
|
367
|
+
orderBy: OrderByDefinition[]
|
|
368
|
+
default?: boolean
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface FirstBySelection {
|
|
372
|
+
kind: 'firstBy'
|
|
373
|
+
orderBy: OrderByDefinition[]
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export type RelationSelection = FirstBySelection
|
|
377
|
+
|
|
378
|
+
export interface GraphDefinitionInput {
|
|
379
|
+
schemaVersion: 10
|
|
380
|
+
name: string
|
|
381
|
+
root: string
|
|
382
|
+
sources: SourceDefinition[]
|
|
383
|
+
parameters?: ParameterDefinition[]
|
|
384
|
+
relations?: RelationDefinition[]
|
|
385
|
+
constraints?: ConstraintDefinition[]
|
|
386
|
+
projection?: ProjectionDefinitionInput
|
|
387
|
+
orderings?: OrderingDefinition[]
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export interface GraphDefinition<
|
|
391
|
+
Parameter extends ParameterDefinition = ParameterDefinition,
|
|
392
|
+
ProjectionPath extends string = string,
|
|
393
|
+
OrderingName extends string = string,
|
|
394
|
+
ProjectionField extends ProjectionFieldDefinition = ProjectionFieldDefinition<ProjectionPath>,
|
|
395
|
+
Relation extends RelationDefinition = RelationDefinition,
|
|
396
|
+
Root extends string = string,
|
|
397
|
+
ProjectionObject extends ProjectionObjectDefinition = ProjectionObjectDefinition,
|
|
398
|
+
> extends GraphDefinitionInput {
|
|
399
|
+
root: Root
|
|
400
|
+
parameters: Parameter[]
|
|
401
|
+
relations: Relation[]
|
|
402
|
+
constraints: ConstraintDefinition[]
|
|
403
|
+
projection: ProjectionDefinition<ProjectionPath, ProjectionField, ProjectionObject>
|
|
404
|
+
orderings: OrderingDefinition<OrderingName>[]
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export type ExactGraphDefinitionInput<Definition extends GraphDefinitionInput> = Definition &
|
|
408
|
+
Record<Exclude<keyof Definition, keyof GraphDefinitionInput>, never>
|
|
409
|
+
|
|
410
|
+
export type TableName =
|
|
411
|
+
| string
|
|
412
|
+
| {
|
|
413
|
+
catalog?: string
|
|
414
|
+
schema?: string
|
|
415
|
+
name: string
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export interface SourceMapping {
|
|
419
|
+
table: TableName
|
|
420
|
+
columns?: Record<string, string>
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface RelationalMapping {
|
|
424
|
+
sources: Record<string, SourceMapping>
|
|
425
|
+
}
|