@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supabase/postgrest-js",
3
- "version": "2.117.3",
3
+ "version": "2.118.0-canary.1",
4
4
  "description": "Isomorphic PostgREST client",
5
5
  "keywords": [
6
6
  "postgrest",
@@ -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
- // For embeded function selection, the source of truth is the 'referencedRelation'
431
- // coming from the SetofOptions.to parameter
432
- Resolved['relation']['match'] extends 'func'
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
- ? [Schema['Functions'][FieldName]['Args']] extends [never]
690
- ? never
691
- : Schema['Functions'][FieldName] extends {
692
- Args: { '': TablesAndViews<Schema>[RelationName]['Row'] }
693
- Returns: any
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
- // Given a relation name (Table or View) extract all the "computed fields" based on the Row
700
- // object, and the schema functions definitions
701
- export type GetComputedFields<
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
@@ -76,10 +76,16 @@ export type GetRpcFunctionFilterBuilderByArgs<
76
76
  1: IsAny<Schema> extends true
77
77
  ? any
78
78
  : IsNever<Args> extends true
79
- ? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
80
- // we fallback to the last function definition matched by name
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
- ? LastOf<Schema['Functions'][FnName]>
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.117.3'
7
+ export const version = '2.118.0-canary.1'