@supabase/postgrest-js 2.117.3 → 2.118.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -15
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +36 -15
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/select-query-parser/result.ts +5 -5
- package/src/select-query-parser/utils.ts +65 -11
- package/src/types/common/common.ts +8 -0
- package/src/types/common/rpc.ts +9 -3
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -383,6 +383,7 @@ export type ProcessEmbeddedResource<
|
|
|
383
383
|
}
|
|
384
384
|
: Resolved extends {
|
|
385
385
|
referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>
|
|
386
|
+
relationName: string
|
|
386
387
|
relation: GenericRelationship & { match: 'refrel' | 'col' | 'fkname' | 'func' }
|
|
387
388
|
direction: string
|
|
388
389
|
}
|
|
@@ -412,6 +413,7 @@ type ProcessEmbeddedResourceResult<
|
|
|
412
413
|
Schema extends GenericSchema,
|
|
413
414
|
Resolved extends {
|
|
414
415
|
referencedTable: Pick<GenericTable, 'Row' | 'Relationships'>
|
|
416
|
+
relationName: string
|
|
415
417
|
relation: GenericRelationship & {
|
|
416
418
|
match: 'refrel' | 'col' | 'fkname' | 'func'
|
|
417
419
|
isNotNullable?: boolean
|
|
@@ -427,11 +429,9 @@ type ProcessEmbeddedResourceResult<
|
|
|
427
429
|
ClientOptions,
|
|
428
430
|
Schema,
|
|
429
431
|
Resolved['referencedTable']['Row'],
|
|
430
|
-
//
|
|
431
|
-
//
|
|
432
|
-
Resolved['
|
|
433
|
-
? Resolved['relation']['referencedRelation']
|
|
434
|
-
: Field['name'],
|
|
432
|
+
// The embedded relation's own name, which differs from the field name when the embed
|
|
433
|
+
// goes through a column or foreign key name (`username(*)`) or an embedded function
|
|
434
|
+
Resolved['relationName'],
|
|
435
435
|
Resolved['referencedTable']['Relationships'],
|
|
436
436
|
Field['children'] extends undefined
|
|
437
437
|
? []
|
|
@@ -266,6 +266,7 @@ type ResolveReverseRelationship<
|
|
|
266
266
|
FoundRelation extends { hint: string } | { match: 'col' }
|
|
267
267
|
? {
|
|
268
268
|
referencedTable: TablesAndViews<Schema>[RelatedRelationName]
|
|
269
|
+
relationName: RelatedRelationName
|
|
269
270
|
relation: FoundRelation
|
|
270
271
|
direction: 'reverse'
|
|
271
272
|
from: CurrentTableOrView
|
|
@@ -275,6 +276,7 @@ type ResolveReverseRelationship<
|
|
|
275
276
|
? SelectQueryError<`Could not embed because more than one relationship was found for '${RelatedRelationName}' and '${CurrentTableOrView}' you need to hint the column with ${RelatedRelationName}!<columnName> ?`>
|
|
276
277
|
: {
|
|
277
278
|
referencedTable: TablesAndViews<Schema>[RelatedRelationName]
|
|
279
|
+
relationName: RelatedRelationName
|
|
278
280
|
relation: FoundRelation
|
|
279
281
|
direction: 'reverse'
|
|
280
282
|
from: CurrentTableOrView
|
|
@@ -428,6 +430,7 @@ export type ResolveForwardRelationship<
|
|
|
428
430
|
? FoundByName extends GenericRelationship
|
|
429
431
|
? {
|
|
430
432
|
referencedTable: TablesAndViews<Schema>[Field['name']]
|
|
433
|
+
relationName: Field['name']
|
|
431
434
|
relation: FoundByName
|
|
432
435
|
direction: 'forward'
|
|
433
436
|
from: Field['name']
|
|
@@ -443,6 +446,7 @@ export type ResolveForwardRelationship<
|
|
|
443
446
|
}
|
|
444
447
|
? {
|
|
445
448
|
referencedTable: TablesAndViews<Schema>[FoundByMatch['from']]
|
|
449
|
+
relationName: FoundByMatch['from'] & string
|
|
446
450
|
relation: FoundByMatch
|
|
447
451
|
direction: 'forward'
|
|
448
452
|
from: CurrentTableOrView
|
|
@@ -456,6 +460,7 @@ export type ResolveForwardRelationship<
|
|
|
456
460
|
? FoundByJoinTable extends GenericRelationship
|
|
457
461
|
? {
|
|
458
462
|
referencedTable: TablesAndViews<Schema>[FoundByJoinTable['referencedRelation']]
|
|
463
|
+
relationName: FoundByJoinTable['referencedRelation']
|
|
459
464
|
relation: FoundByJoinTable & { match: 'refrel' }
|
|
460
465
|
direction: 'forward'
|
|
461
466
|
from: CurrentTableOrView
|
|
@@ -491,6 +496,7 @@ export type ResolveForwardRelationship<
|
|
|
491
496
|
scalarType: FoundEmbededFunctionJoinTableRelation['Returns']
|
|
492
497
|
direction: 'forward'
|
|
493
498
|
from: CurrentTableOrView
|
|
499
|
+
relationName: ''
|
|
494
500
|
type: 'found-by-embeded-scalar-function'
|
|
495
501
|
}
|
|
496
502
|
: // Table-valued function: `to` names the target table/view.
|
|
@@ -515,6 +521,7 @@ export type ResolveForwardRelationship<
|
|
|
515
521
|
}
|
|
516
522
|
direction: 'forward'
|
|
517
523
|
from: CurrentTableOrView
|
|
524
|
+
relationName: FoundEmbededFunctionJoinTableRelation['SetofOptions']['to']
|
|
518
525
|
type: 'found-by-embeded-function'
|
|
519
526
|
}
|
|
520
527
|
: SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`>
|
|
@@ -681,26 +688,73 @@ type FindMatchingFunctionBySetofFrom<
|
|
|
681
688
|
? MatchingFunctionBySetofFrom<Fn, TableName>
|
|
682
689
|
: false
|
|
683
690
|
|
|
691
|
+
type IsUnion<T, U = T> = [T] extends [never]
|
|
692
|
+
? false
|
|
693
|
+
: T extends U
|
|
694
|
+
? [U] extends [T]
|
|
695
|
+
? false
|
|
696
|
+
: true
|
|
697
|
+
: never
|
|
698
|
+
|
|
699
|
+
type SameKeys<A, B> = [keyof A] extends [keyof B]
|
|
700
|
+
? [keyof B] extends [keyof A]
|
|
701
|
+
? true
|
|
702
|
+
: false
|
|
703
|
+
: false
|
|
704
|
+
|
|
705
|
+
// The type of a function's only argument when it has exactly one and it is required,
|
|
706
|
+
// whatever the argument is called. `Args: never` (a zero-argument function in older
|
|
707
|
+
// generated types), `Args: Record<PropertyKey, never>`, an optional argument and several
|
|
708
|
+
// arguments all resolve to `never`.
|
|
709
|
+
type SoleRequiredArgument<Args> = [Args] extends [never]
|
|
710
|
+
? never
|
|
711
|
+
: IsUnion<keyof Args> extends true
|
|
712
|
+
? never
|
|
713
|
+
: {} extends Args
|
|
714
|
+
? never
|
|
715
|
+
: Args[keyof Args]
|
|
716
|
+
|
|
717
|
+
// Whether one signature of a function (one member of an overload union, as `Fn` is a
|
|
718
|
+
// naked type parameter and distributes) is a computed field of a relation: PostgREST
|
|
719
|
+
// treats a function whose only argument is the relation's row type as one. The argument
|
|
720
|
+
// is matched on its keys rather than its exact type, so that a `Row` whose column types
|
|
721
|
+
// were overridden (`MergeDeep`) still matches the generated `Row` the argument references.
|
|
722
|
+
type IsComputedFieldFunction<Fn, Row> = Fn extends { Args: infer Args }
|
|
723
|
+
? [SoleRequiredArgument<Args>] extends [never]
|
|
724
|
+
? false
|
|
725
|
+
: SameKeys<SoleRequiredArgument<Args>, Row>
|
|
726
|
+
: false
|
|
727
|
+
|
|
684
728
|
type ComputedField<
|
|
685
729
|
Schema extends GenericSchema,
|
|
686
730
|
RelationName extends keyof TablesAndViews<Schema>,
|
|
687
731
|
FieldName extends keyof TablesAndViews<Schema>[RelationName]['Row'],
|
|
688
732
|
> = FieldName extends keyof Schema['Functions']
|
|
689
|
-
?
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
? FieldName
|
|
696
|
-
: never
|
|
733
|
+
? true extends IsComputedFieldFunction<
|
|
734
|
+
Schema['Functions'][FieldName],
|
|
735
|
+
TablesAndViews<Schema>[RelationName]['Row']
|
|
736
|
+
>
|
|
737
|
+
? FieldName
|
|
738
|
+
: never
|
|
697
739
|
: never
|
|
698
740
|
|
|
699
|
-
//
|
|
700
|
-
//
|
|
701
|
-
|
|
741
|
+
// Computed fields of a relation inferred from its `Row` keys and the schema functions, for
|
|
742
|
+
// types generated before the relation declared them in `ComputedFields`.
|
|
743
|
+
type InferredComputedFields<
|
|
702
744
|
Schema extends GenericSchema,
|
|
703
745
|
RelationName extends keyof TablesAndViews<Schema>,
|
|
704
746
|
> = {
|
|
705
747
|
[K in keyof TablesAndViews<Schema>[RelationName]['Row']]: ComputedField<Schema, RelationName, K>
|
|
706
748
|
}[keyof TablesAndViews<Schema>[RelationName]['Row']]
|
|
749
|
+
|
|
750
|
+
// Given a relation name (Table or View) extract all the "computed fields", which PostgREST
|
|
751
|
+
// leaves out of a `*` selection: the names the relation declares in `ComputedFields`, or
|
|
752
|
+
// otherwise the ones inferred from the schema functions definitions.
|
|
753
|
+
export type GetComputedFields<
|
|
754
|
+
Schema extends GenericSchema,
|
|
755
|
+
RelationName extends keyof TablesAndViews<Schema>,
|
|
756
|
+
> = 'ComputedFields' extends keyof TablesAndViews<Schema>[RelationName]
|
|
757
|
+
? TablesAndViews<Schema>[RelationName] extends { ComputedFields?: infer Fields extends string }
|
|
758
|
+
? Fields
|
|
759
|
+
: never
|
|
760
|
+
: InferredComputedFields<Schema, RelationName>
|
|
@@ -42,6 +42,12 @@ export type GenericTable = {
|
|
|
42
42
|
Insert: Record<string, unknown>
|
|
43
43
|
Update: Record<string, unknown>
|
|
44
44
|
Relationships: GenericRelationship[]
|
|
45
|
+
/**
|
|
46
|
+
* Names of the `Row` keys that are computed fields (functions taking the row), which
|
|
47
|
+
* PostgREST leaves out of `select('*')`. Generated types declare it; when absent, the
|
|
48
|
+
* computed fields are inferred from `Functions`.
|
|
49
|
+
*/
|
|
50
|
+
ComputedFields?: string
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
export type GenericUpdatableView = {
|
|
@@ -49,11 +55,13 @@ export type GenericUpdatableView = {
|
|
|
49
55
|
Insert: Record<string, unknown>
|
|
50
56
|
Update: Record<string, unknown>
|
|
51
57
|
Relationships: GenericRelationship[]
|
|
58
|
+
ComputedFields?: string
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
export type GenericNonUpdatableView = {
|
|
55
62
|
Row: Record<string, unknown>
|
|
56
63
|
Relationships: GenericRelationship[]
|
|
64
|
+
ComputedFields?: string
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
export type GenericView = GenericUpdatableView | GenericNonUpdatableView
|
package/src/types/common/rpc.ts
CHANGED
|
@@ -76,10 +76,16 @@ export type GetRpcFunctionFilterBuilderByArgs<
|
|
|
76
76
|
1: IsAny<Schema> extends true
|
|
77
77
|
? any
|
|
78
78
|
: IsNever<Args> extends true
|
|
79
|
-
? //
|
|
80
|
-
//
|
|
79
|
+
? // Generated types spell a zero-argument definition either `Args: never` or
|
|
80
|
+
// `Args: Record<PropertyKey, never>`, so both are matched before falling back to the last
|
|
81
|
+
// function definition matched by name, which is for retro compatibility with a single
|
|
82
|
+
// return and an union of Args
|
|
81
83
|
IsNever<ExtractExactFunction<Schema['Functions'][FnName], Args>> extends true
|
|
82
|
-
?
|
|
84
|
+
? IsNever<
|
|
85
|
+
ExtractExactFunction<Schema['Functions'][FnName], Record<PropertyKey, never>>
|
|
86
|
+
> extends true
|
|
87
|
+
? LastOf<Schema['Functions'][FnName]>
|
|
88
|
+
: ExtractExactFunction<Schema['Functions'][FnName], Record<PropertyKey, never>>
|
|
83
89
|
: ExtractExactFunction<Schema['Functions'][FnName], Args>
|
|
84
90
|
: Args extends Record<PropertyKey, never>
|
|
85
91
|
? LastOf<Schema['Functions'][FnName]>
|
package/src/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// - Debugging and support (identifying which version is running)
|
|
5
5
|
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
6
|
// - Ensuring build artifacts match the published package version
|
|
7
|
-
export const version = '2.
|
|
7
|
+
export const version = '2.118.0-canary.1'
|