effect-app 4.0.0-beta.292 → 4.0.0-beta.294
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/CHANGELOG.md +12 -0
- package/dist/Model/query/dsl.d.ts +46 -38
- package/dist/Model/query/dsl.d.ts.map +1 -1
- package/dist/Model/query/dsl.js +1 -1
- package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -1
- package/dist/Model/query/new-kid-interpreter.js +20 -10
- package/package.json +1 -1
- package/src/Model/query/dsl.ts +170 -181
- package/src/Model/query/new-kid-interpreter.ts +21 -9
package/src/Model/query/dsl.ts
CHANGED
|
@@ -52,16 +52,29 @@ type ExtractTType<T> = T extends QueryTogether<any, any, any, any, any, any, inf
|
|
|
52
52
|
type ExtractExclusiveness<T> = T extends QueryTogether<any, any, infer Exclusive extends boolean, any, any, any, any>
|
|
53
53
|
? Exclusive
|
|
54
54
|
: never
|
|
55
|
+
type ExtractFieldValues<T> = T extends QueryTogether<infer TFieldValues, any, any, any, any, any, any> ? TFieldValues
|
|
56
|
+
: never
|
|
55
57
|
type ExtractFieldValuesRefined<T> = T extends QueryTogether<any, infer TFieldValuesRefined, any, any, any, any, any>
|
|
56
58
|
? TFieldValuesRefined
|
|
57
59
|
: never
|
|
60
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never
|
|
61
|
+
type LiteralValue<T> = T extends { readonly literal: infer L } ? L : T
|
|
62
|
+
type ExtractTagged<From, Tag> = From extends { readonly _tag: infer FromTag }
|
|
63
|
+
? [LiteralValue<FromTag>] extends [LiteralValue<Tag>] ? From : never
|
|
64
|
+
: never
|
|
65
|
+
type ProjectableSource<I, From> = I extends { readonly _tag: infer Tag } ? ExtractTagged<From, Tag>
|
|
66
|
+
: From
|
|
67
|
+
type ProjectableField<I, From, K extends PropertyKey> = K extends KeysOfUnion<From> ? I
|
|
68
|
+
: never
|
|
58
69
|
type ProjectableEncoded<I, From> = I extends FieldValues ? {
|
|
59
|
-
[K in keyof I]:
|
|
60
|
-
I
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
[K in keyof I]: ProjectableField<
|
|
71
|
+
I[K],
|
|
72
|
+
ProjectableSource<I, From>,
|
|
73
|
+
K
|
|
74
|
+
>
|
|
63
75
|
}
|
|
64
76
|
: never
|
|
77
|
+
type ProjectableGuard<I, From> = [I] extends [ProjectableEncoded<I, From>] ? unknown : never
|
|
65
78
|
|
|
66
79
|
export type RelationDirection = "some" | "every"
|
|
67
80
|
export type Relation = { relation: RelationDirection }
|
|
@@ -122,74 +135,87 @@ export type ComputedProjectionMathExpression =
|
|
|
122
135
|
readonly right: ComputedProjectionMathExpression
|
|
123
136
|
}
|
|
124
137
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
138
|
+
declare const ComputedProjectionExpressionTypeId: unique symbol
|
|
139
|
+
|
|
140
|
+
type ComputedProjectionOutput<A> = {
|
|
141
|
+
readonly [ComputedProjectionExpressionTypeId]?: Covariant<A>
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type ComputedProjectionExpression<A = unknown> =
|
|
145
|
+
& ComputedProjectionOutput<A>
|
|
146
|
+
& (
|
|
147
|
+
| {
|
|
148
|
+
readonly _tag: "relation-count"
|
|
149
|
+
readonly path: string
|
|
150
|
+
readonly operation?: ComputedProjectionOperation
|
|
151
|
+
}
|
|
152
|
+
| {
|
|
153
|
+
readonly _tag: "relation-any"
|
|
154
|
+
readonly path: string
|
|
155
|
+
readonly operation?: ComputedProjectionOperation
|
|
156
|
+
}
|
|
157
|
+
| {
|
|
158
|
+
readonly _tag: "relation-every"
|
|
159
|
+
readonly path: string
|
|
160
|
+
readonly operation: ComputedProjectionOperation
|
|
161
|
+
}
|
|
162
|
+
| {
|
|
163
|
+
readonly _tag: "relation-distinct-count"
|
|
164
|
+
readonly path: string
|
|
165
|
+
readonly field: string
|
|
166
|
+
readonly operation?: ComputedProjectionOperation
|
|
167
|
+
}
|
|
168
|
+
| {
|
|
169
|
+
readonly _tag: "relation-sum"
|
|
170
|
+
readonly path: string
|
|
171
|
+
readonly field: string
|
|
172
|
+
readonly operation?: ComputedProjectionOperation
|
|
173
|
+
}
|
|
174
|
+
| {
|
|
175
|
+
readonly _tag: "relation-sum-expr"
|
|
176
|
+
readonly path: string
|
|
177
|
+
readonly expression: ComputedProjectionMathExpression
|
|
178
|
+
readonly operation?: ComputedProjectionOperation
|
|
179
|
+
}
|
|
180
|
+
| {
|
|
181
|
+
readonly _tag: "relation-sum-expr-by"
|
|
182
|
+
readonly path: string
|
|
183
|
+
readonly expression: ComputedProjectionMathExpression
|
|
184
|
+
readonly unit: string
|
|
185
|
+
readonly operation?: ComputedProjectionOperation
|
|
186
|
+
}
|
|
187
|
+
| {
|
|
188
|
+
readonly _tag: "relation-sum-expr-normalized"
|
|
189
|
+
readonly path: string
|
|
190
|
+
readonly expression: ComputedProjectionMathExpression
|
|
191
|
+
readonly unit: string
|
|
192
|
+
readonly toBase: string
|
|
193
|
+
readonly factors: Readonly<Record<string, number>>
|
|
194
|
+
readonly operation?: ComputedProjectionOperation
|
|
195
|
+
}
|
|
196
|
+
| {
|
|
197
|
+
readonly _tag: "relation-collect"
|
|
198
|
+
readonly path: string
|
|
199
|
+
readonly field: string
|
|
200
|
+
readonly distinct: boolean
|
|
201
|
+
readonly operation?: ComputedProjectionOperation
|
|
202
|
+
}
|
|
203
|
+
| {
|
|
204
|
+
readonly _tag: "relation-collect-fields"
|
|
205
|
+
readonly path: string
|
|
206
|
+
readonly fields: readonly string[]
|
|
207
|
+
readonly distinct: boolean
|
|
208
|
+
readonly operation?: ComputedProjectionOperation
|
|
209
|
+
}
|
|
210
|
+
| {
|
|
211
|
+
readonly _tag: "relation-length"
|
|
212
|
+
readonly path: string
|
|
213
|
+
}
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
type NoExtraComputedKeys<M extends ComputedProjectionMap, I> = string extends keyof M ? unknown
|
|
217
|
+
: Exclude<keyof M, KeysOfUnion<I>> extends never ? unknown
|
|
218
|
+
: never
|
|
193
219
|
|
|
194
220
|
/**
|
|
195
221
|
* An expression that aggregates values across documents (for use with {@link aggregate}).
|
|
@@ -503,7 +529,7 @@ export const project: {
|
|
|
503
529
|
>(
|
|
504
530
|
schema:
|
|
505
531
|
& S.Codec<Option.Option<A>, I, R>
|
|
506
|
-
&
|
|
532
|
+
& ProjectableGuard<I, ExtractFieldValues<Q>>,
|
|
507
533
|
mode: "collect"
|
|
508
534
|
): (
|
|
509
535
|
current: Q
|
|
@@ -518,7 +544,7 @@ export const project: {
|
|
|
518
544
|
>(
|
|
519
545
|
schema:
|
|
520
546
|
& S.Codec<A, I, R>
|
|
521
|
-
&
|
|
547
|
+
& ProjectableGuard<I, ExtractFieldValues<Q>>,
|
|
522
548
|
mode: "project"
|
|
523
549
|
): (
|
|
524
550
|
current: Q
|
|
@@ -532,62 +558,7 @@ export const project: {
|
|
|
532
558
|
>(
|
|
533
559
|
schema:
|
|
534
560
|
& S.Codec<A, I, R>
|
|
535
|
-
&
|
|
536
|
-
): (
|
|
537
|
-
current: Q
|
|
538
|
-
) => QueryProjection<ExtractFieldValuesRefined<Q>, A, R, ExtractTType<Q>, E>
|
|
539
|
-
|
|
540
|
-
<
|
|
541
|
-
Q extends Query<any> | QueryWhere<any, any, any> | QueryEnd<any, "one" | "many", any>,
|
|
542
|
-
I,
|
|
543
|
-
A = ExtractFieldValuesRefined<Q>,
|
|
544
|
-
R = never,
|
|
545
|
-
E extends boolean = ExtractExclusiveness<Q>
|
|
546
|
-
>(
|
|
547
|
-
schema: S.Codec<
|
|
548
|
-
Option.Option<A>,
|
|
549
|
-
{
|
|
550
|
-
[K in keyof I]: K extends keyof ExtractFieldValuesRefined<Q> ? I[K] : never
|
|
551
|
-
},
|
|
552
|
-
R
|
|
553
|
-
>,
|
|
554
|
-
mode: "collect"
|
|
555
|
-
): (
|
|
556
|
-
current: Q
|
|
557
|
-
) => QueryProjection<ExtractFieldValuesRefined<Q>, A, R, ExtractTType<Q>, E>
|
|
558
|
-
|
|
559
|
-
<
|
|
560
|
-
Q extends Query<any> | QueryWhere<any, any, any> | QueryEnd<any, "one" | "many", any>,
|
|
561
|
-
I,
|
|
562
|
-
A = ExtractFieldValuesRefined<Q>,
|
|
563
|
-
R = never,
|
|
564
|
-
E extends boolean = ExtractExclusiveness<Q>
|
|
565
|
-
>(
|
|
566
|
-
schema: S.Codec<
|
|
567
|
-
A,
|
|
568
|
-
{
|
|
569
|
-
[K in keyof I]: K extends keyof ExtractFieldValuesRefined<Q> ? I[K] : never
|
|
570
|
-
},
|
|
571
|
-
R
|
|
572
|
-
>,
|
|
573
|
-
mode: "project"
|
|
574
|
-
): (
|
|
575
|
-
current: Q
|
|
576
|
-
) => QueryProjection<ExtractFieldValuesRefined<Q>, A, R, ExtractTType<Q>, E>
|
|
577
|
-
<
|
|
578
|
-
Q extends Query<any> | QueryWhere<any, any, any> | QueryEnd<any, "one" | "many", any>,
|
|
579
|
-
I,
|
|
580
|
-
A = ExtractFieldValuesRefined<Q>,
|
|
581
|
-
R = never,
|
|
582
|
-
E extends boolean = ExtractExclusiveness<Q>
|
|
583
|
-
>(
|
|
584
|
-
schema: S.Codec<
|
|
585
|
-
A,
|
|
586
|
-
{
|
|
587
|
-
[K in keyof I]: K extends keyof ExtractFieldValuesRefined<Q> ? I[K] : never
|
|
588
|
-
},
|
|
589
|
-
R
|
|
590
|
-
>
|
|
561
|
+
& ProjectableGuard<I, ExtractFieldValues<Q>>
|
|
591
562
|
): (
|
|
592
563
|
current: Q
|
|
593
564
|
) => QueryProjection<ExtractFieldValuesRefined<Q>, A, R, ExtractTType<Q>, E>
|
|
@@ -629,11 +600,11 @@ export const relation = <
|
|
|
629
600
|
right: ComputedProjectionMathExpression
|
|
630
601
|
): ComputedProjectionMathExpression => ({ _tag: "mul", left, right })
|
|
631
602
|
},
|
|
632
|
-
length: (): ComputedProjectionExpression => ({
|
|
603
|
+
length: (): ComputedProjectionExpression<number> => ({
|
|
633
604
|
_tag: "relation-length",
|
|
634
605
|
path: path as string
|
|
635
606
|
}),
|
|
636
|
-
count: (operation?: ComputedProjectionOperation): ComputedProjectionExpression =>
|
|
607
|
+
count: (operation?: ComputedProjectionOperation): ComputedProjectionExpression<number> =>
|
|
637
608
|
operation
|
|
638
609
|
? {
|
|
639
610
|
_tag: "relation-count",
|
|
@@ -644,7 +615,7 @@ export const relation = <
|
|
|
644
615
|
_tag: "relation-count",
|
|
645
616
|
path: path as string
|
|
646
617
|
},
|
|
647
|
-
any: (operation?: ComputedProjectionOperation): ComputedProjectionExpression =>
|
|
618
|
+
any: (operation?: ComputedProjectionOperation): ComputedProjectionExpression<boolean> =>
|
|
648
619
|
operation
|
|
649
620
|
? {
|
|
650
621
|
_tag: "relation-any",
|
|
@@ -655,15 +626,15 @@ export const relation = <
|
|
|
655
626
|
_tag: "relation-any",
|
|
656
627
|
path: path as string
|
|
657
628
|
},
|
|
658
|
-
every: (operation: ComputedProjectionOperation): ComputedProjectionExpression => ({
|
|
629
|
+
every: (operation: ComputedProjectionOperation): ComputedProjectionExpression<boolean> => ({
|
|
659
630
|
_tag: "relation-every",
|
|
660
631
|
path: path as string,
|
|
661
632
|
operation
|
|
662
633
|
}),
|
|
663
|
-
distinctCount: (
|
|
664
|
-
field:
|
|
634
|
+
distinctCount: <const F extends FieldPath<RelationElement<TFieldValues, P>>>(
|
|
635
|
+
field: F,
|
|
665
636
|
operation?: ComputedProjectionOperation
|
|
666
|
-
): ComputedProjectionExpression =>
|
|
637
|
+
): ComputedProjectionExpression<number> =>
|
|
667
638
|
operation
|
|
668
639
|
? {
|
|
669
640
|
_tag: "relation-distinct-count",
|
|
@@ -676,10 +647,10 @@ export const relation = <
|
|
|
676
647
|
path: path as string,
|
|
677
648
|
field: field as string
|
|
678
649
|
},
|
|
679
|
-
sum: (
|
|
680
|
-
field:
|
|
650
|
+
sum: <const F extends FieldPath<RelationElement<TFieldValues, P>>>(
|
|
651
|
+
field: F,
|
|
681
652
|
operation?: ComputedProjectionOperation
|
|
682
|
-
): ComputedProjectionExpression =>
|
|
653
|
+
): ComputedProjectionExpression<number> =>
|
|
683
654
|
operation
|
|
684
655
|
? {
|
|
685
656
|
_tag: "relation-sum",
|
|
@@ -695,7 +666,7 @@ export const relation = <
|
|
|
695
666
|
sumExpr: (
|
|
696
667
|
expression: ComputedProjectionMathExpression,
|
|
697
668
|
operation?: ComputedProjectionOperation
|
|
698
|
-
): ComputedProjectionExpression =>
|
|
669
|
+
): ComputedProjectionExpression<number> =>
|
|
699
670
|
operation
|
|
700
671
|
? {
|
|
701
672
|
_tag: "relation-sum-expr",
|
|
@@ -708,11 +679,13 @@ export const relation = <
|
|
|
708
679
|
path: path as string,
|
|
709
680
|
expression
|
|
710
681
|
},
|
|
711
|
-
sumExprBy: (
|
|
682
|
+
sumExprBy: <const F extends FieldPath<RelationElement<TFieldValues, P>>>(
|
|
712
683
|
expression: ComputedProjectionMathExpression,
|
|
713
|
-
options: { unit:
|
|
684
|
+
options: { unit: F },
|
|
714
685
|
operation?: ComputedProjectionOperation
|
|
715
|
-
): ComputedProjectionExpression
|
|
686
|
+
): ComputedProjectionExpression<
|
|
687
|
+
ReadonlyArray<{ readonly unit: FieldPathValue<RelationElement<TFieldValues, P>, F>; readonly total: number }>
|
|
688
|
+
> =>
|
|
716
689
|
operation
|
|
717
690
|
? {
|
|
718
691
|
_tag: "relation-sum-expr-by",
|
|
@@ -735,7 +708,7 @@ export const relation = <
|
|
|
735
708
|
factors: Readonly<Record<string, number>>
|
|
736
709
|
},
|
|
737
710
|
operation?: ComputedProjectionOperation
|
|
738
|
-
): ComputedProjectionExpression =>
|
|
711
|
+
): ComputedProjectionExpression<number> =>
|
|
739
712
|
operation
|
|
740
713
|
? {
|
|
741
714
|
_tag: "relation-sum-expr-normalized",
|
|
@@ -754,10 +727,10 @@ export const relation = <
|
|
|
754
727
|
toBase: options.toBase,
|
|
755
728
|
factors: options.factors
|
|
756
729
|
},
|
|
757
|
-
collect: (
|
|
758
|
-
field:
|
|
730
|
+
collect: <const F extends FieldPath<RelationElement<TFieldValues, P>>>(
|
|
731
|
+
field: F,
|
|
759
732
|
operation?: ComputedProjectionOperation
|
|
760
|
-
): ComputedProjectionExpression =>
|
|
733
|
+
): ComputedProjectionExpression<ReadonlyArray<FieldPathValue<RelationElement<TFieldValues, P>, F>>> =>
|
|
761
734
|
operation
|
|
762
735
|
? {
|
|
763
736
|
_tag: "relation-collect",
|
|
@@ -772,10 +745,10 @@ export const relation = <
|
|
|
772
745
|
field: field as string,
|
|
773
746
|
distinct: false
|
|
774
747
|
},
|
|
775
|
-
collectDistinct: (
|
|
776
|
-
field:
|
|
748
|
+
collectDistinct: <const F extends FieldPath<RelationElement<TFieldValues, P>>>(
|
|
749
|
+
field: F,
|
|
777
750
|
operation?: ComputedProjectionOperation
|
|
778
|
-
): ComputedProjectionExpression =>
|
|
751
|
+
): ComputedProjectionExpression<ReadonlyArray<FieldPathValue<RelationElement<TFieldValues, P>, F>>> =>
|
|
779
752
|
operation
|
|
780
753
|
? {
|
|
781
754
|
_tag: "relation-collect",
|
|
@@ -790,10 +763,12 @@ export const relation = <
|
|
|
790
763
|
field: field as string,
|
|
791
764
|
distinct: true
|
|
792
765
|
},
|
|
793
|
-
collectFields: (
|
|
794
|
-
fields:
|
|
766
|
+
collectFields: <const F extends readonly FieldPath<RelationElement<TFieldValues, P>>[]>(
|
|
767
|
+
fields: F,
|
|
795
768
|
operation?: ComputedProjectionOperation
|
|
796
|
-
): ComputedProjectionExpression
|
|
769
|
+
): ComputedProjectionExpression<
|
|
770
|
+
ReadonlyArray<FieldPathValue<RelationElement<TFieldValues, P>, F[number]>>
|
|
771
|
+
> =>
|
|
797
772
|
operation
|
|
798
773
|
? {
|
|
799
774
|
_tag: "relation-collect-fields",
|
|
@@ -808,10 +783,12 @@ export const relation = <
|
|
|
808
783
|
fields: fields as readonly string[],
|
|
809
784
|
distinct: false
|
|
810
785
|
},
|
|
811
|
-
collectDistinctFields: (
|
|
812
|
-
fields:
|
|
786
|
+
collectDistinctFields: <const F extends readonly FieldPath<RelationElement<TFieldValues, P>>[]>(
|
|
787
|
+
fields: F,
|
|
813
788
|
operation?: ComputedProjectionOperation
|
|
814
|
-
): ComputedProjectionExpression
|
|
789
|
+
): ComputedProjectionExpression<
|
|
790
|
+
ReadonlyArray<FieldPathValue<RelationElement<TFieldValues, P>, F[number]>>
|
|
791
|
+
> =>
|
|
815
792
|
operation
|
|
816
793
|
? {
|
|
817
794
|
_tag: "relation-collect-fields",
|
|
@@ -865,59 +842,71 @@ const makeComputedHelpers = <TFieldValues extends FieldValues>(): ComputedHelper
|
|
|
865
842
|
export const projectComputed: {
|
|
866
843
|
<
|
|
867
844
|
Q extends Query<any> | QueryWhere<any, any, any> | QueryEnd<any, "one" | "many", any>,
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
845
|
+
Schema extends S.Codec<any, FieldValues, any>,
|
|
846
|
+
M extends ComputedProjectionMap,
|
|
847
|
+
I extends FieldValues = S.Codec.Encoded<Schema>,
|
|
871
848
|
E extends boolean = ExtractExclusiveness<Q>
|
|
872
849
|
>(
|
|
873
|
-
schema:
|
|
874
|
-
build: (helpers: ComputedHelpers<
|
|
850
|
+
schema: Schema,
|
|
851
|
+
build: (helpers: ComputedHelpers<ExtractFieldValues<Q>>) => M & NoExtraComputedKeys<M, I>,
|
|
875
852
|
mode: "collect"
|
|
876
853
|
): (
|
|
877
854
|
current: Q
|
|
878
|
-
) => QueryProjection<
|
|
855
|
+
) => QueryProjection<
|
|
856
|
+
ExtractFieldValuesRefined<Q>,
|
|
857
|
+
S.Schema.Type<Schema> extends Option.Option<infer A> ? A : never,
|
|
858
|
+
never,
|
|
859
|
+
ExtractTType<Q>,
|
|
860
|
+
E
|
|
861
|
+
>
|
|
879
862
|
|
|
880
863
|
<
|
|
881
864
|
Q extends Query<any> | QueryWhere<any, any, any> | QueryEnd<any, "one" | "many", any>,
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
865
|
+
Schema extends S.Codec<any, FieldValues, any>,
|
|
866
|
+
M extends ComputedProjectionMap,
|
|
867
|
+
I extends FieldValues = S.Codec.Encoded<Schema>,
|
|
885
868
|
E extends boolean = ExtractExclusiveness<Q>
|
|
886
869
|
>(
|
|
887
|
-
schema:
|
|
888
|
-
build: (helpers: ComputedHelpers<
|
|
870
|
+
schema: Schema,
|
|
871
|
+
build: (helpers: ComputedHelpers<ExtractFieldValues<Q>>) => M & NoExtraComputedKeys<M, I>,
|
|
889
872
|
mode?: "project"
|
|
890
873
|
): (
|
|
891
874
|
current: Q
|
|
892
|
-
) => QueryProjection<ExtractFieldValuesRefined<Q>,
|
|
875
|
+
) => QueryProjection<ExtractFieldValuesRefined<Q>, S.Schema.Type<Schema>, never, ExtractTType<Q>, E>
|
|
893
876
|
|
|
894
877
|
<
|
|
895
878
|
Q extends Query<any> | QueryWhere<any, any, any> | QueryEnd<any, "one" | "many", any>,
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
879
|
+
Schema extends S.Codec<any, FieldValues, any>,
|
|
880
|
+
M extends ComputedProjectionMap,
|
|
881
|
+
I extends FieldValues = S.Codec.Encoded<Schema>,
|
|
899
882
|
E extends boolean = ExtractExclusiveness<Q>
|
|
900
883
|
>(
|
|
901
|
-
schema:
|
|
902
|
-
computedProjection:
|
|
884
|
+
schema: Schema,
|
|
885
|
+
computedProjection: M & NoExtraComputedKeys<M, I>,
|
|
903
886
|
mode: "collect"
|
|
904
887
|
): (
|
|
905
888
|
current: Q
|
|
906
|
-
) => QueryProjection<
|
|
889
|
+
) => QueryProjection<
|
|
890
|
+
ExtractFieldValuesRefined<Q>,
|
|
891
|
+
S.Schema.Type<Schema> extends Option.Option<infer A> ? A : never,
|
|
892
|
+
never,
|
|
893
|
+
ExtractTType<Q>,
|
|
894
|
+
E
|
|
895
|
+
>
|
|
907
896
|
|
|
908
897
|
<
|
|
909
898
|
Q extends Query<any> | QueryWhere<any, any, any> | QueryEnd<any, "one" | "many", any>,
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
899
|
+
Schema extends S.Codec<any, FieldValues, any>,
|
|
900
|
+
M extends ComputedProjectionMap,
|
|
901
|
+
I extends FieldValues = S.Codec.Encoded<Schema>,
|
|
913
902
|
E extends boolean = ExtractExclusiveness<Q>
|
|
914
903
|
>(
|
|
915
|
-
schema:
|
|
916
|
-
computedProjection:
|
|
904
|
+
schema: Schema,
|
|
905
|
+
computedProjection: M & NoExtraComputedKeys<M, I>,
|
|
917
906
|
mode?: "project"
|
|
918
907
|
): (
|
|
919
908
|
current: Q
|
|
920
|
-
) => QueryProjection<ExtractFieldValuesRefined<Q>,
|
|
909
|
+
) => QueryProjection<ExtractFieldValuesRefined<Q>, S.Schema.Type<Schema>, never, ExtractTType<Q>, E>
|
|
921
910
|
} = (
|
|
922
911
|
schema: any,
|
|
923
912
|
mapOrBuild:
|
|
@@ -357,6 +357,21 @@ const walkTransformation = (t: S.AST.AST): S.AST.AST => {
|
|
|
357
357
|
return t
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
const objectAsts = (ast: S.AST.AST): readonly S.AST.Objects[] => {
|
|
361
|
+
const t = walkTransformation(ast)
|
|
362
|
+
if (S.AST.isObjects(t)) {
|
|
363
|
+
return [t]
|
|
364
|
+
}
|
|
365
|
+
if (S.AST.isUnion(t)) {
|
|
366
|
+
return t.types.flatMap(objectAsts)
|
|
367
|
+
}
|
|
368
|
+
return []
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const objectKeys = (ast: S.AST.AST): readonly string[] => [
|
|
372
|
+
...new Set(objectAsts(ast).flatMap((object) => object.propertySignatures.map((_) => _.name as string)))
|
|
373
|
+
]
|
|
374
|
+
|
|
360
375
|
export const toFilter = <
|
|
361
376
|
TFieldValues extends FieldValues,
|
|
362
377
|
A,
|
|
@@ -399,9 +414,10 @@ export const toFilter = <
|
|
|
399
414
|
// TODO: support more complex (nested) schemas?
|
|
400
415
|
if (schema) {
|
|
401
416
|
const t = walkTransformation(SchemaAST.toEncoded(schema.ast))
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
417
|
+
const objects = [...objectAsts(t)]
|
|
418
|
+
if (Array.isArrayNonEmpty(objects)) {
|
|
419
|
+
select = [...objectKeys(t)]
|
|
420
|
+
for (const prop of objects.flatMap((_) => _.propertySignatures)) {
|
|
405
421
|
if (S.AST.isArrays(prop.type)) {
|
|
406
422
|
// make sure we only select when there are actually type literals in the tuple...
|
|
407
423
|
// otherwise we might be dealing with strings etc.
|
|
@@ -411,8 +427,7 @@ export const toFilter = <
|
|
|
411
427
|
subKeys: Array.flatMap(
|
|
412
428
|
prop.type.rest,
|
|
413
429
|
(x) => {
|
|
414
|
-
|
|
415
|
-
return S.AST.isObjects(t) ? t.propertySignatures.map((y) => y.name as string) : []
|
|
430
|
+
return objectKeys(x)
|
|
416
431
|
}
|
|
417
432
|
)
|
|
418
433
|
}
|
|
@@ -443,10 +458,7 @@ export const toFilter = <
|
|
|
443
458
|
return [] as string[]
|
|
444
459
|
}
|
|
445
460
|
const encoded = walkTransformation(SchemaAST.toEncoded(baseSchema.ast))
|
|
446
|
-
|
|
447
|
-
return [] as string[]
|
|
448
|
-
}
|
|
449
|
-
const encodedKeys = encoded.propertySignatures.map((_) => _.name as string)
|
|
461
|
+
const encodedKeys = objectKeys(encoded)
|
|
450
462
|
return schemaKeys.filter((key) => !encodedKeys.includes(key))
|
|
451
463
|
})()
|
|
452
464
|
const missingComputedKeys = nonEncodedSchemaKeys.filter((key) => !(computed && key in computed))
|