Skip to content

Commit da9d2ee

Browse files
committed
chore(repo): project references
1 parent 68ce107 commit da9d2ee

File tree

9 files changed

+295
-2
lines changed

9 files changed

+295
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"include": ["src"],
3+
"exclude": ["node_modules/**/*.ts"],
4+
"compilerOptions": {
5+
"declaration": true,
6+
"declarationMap": true,
7+
"module": "CommonJS",
8+
"outDir": "dist/main",
9+
"rootDir": "src",
10+
"sourceMap": true,
11+
"target": "ES2015",
12+
13+
"strict": true,
14+
15+
"esModuleInterop": true,
16+
"moduleResolution": "Node",
17+
"isolatedModules": true,
18+
19+
"forceConsistentCasingInFileNames": true,
20+
"stripInternal": true,
21+
"allowSyntheticDefaultImports": true
22+
},
23+
"typeRoots": ["./src/types"]
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"include": ["src"],
3+
"compilerOptions": {
4+
"declaration": true,
5+
"declarationMap": true,
6+
"module": "CommonJS",
7+
"outDir": "dist/cjs",
8+
"sourceMap": true,
9+
"target": "ES2017",
10+
11+
"strict": true,
12+
13+
"esModuleInterop": true,
14+
"moduleResolution": "Node",
15+
16+
"forceConsistentCasingInFileNames": true,
17+
"stripInternal": true
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"include": ["src"],
3+
"compilerOptions": {
4+
"declaration": true,
5+
"declarationMap": true,
6+
"module": "CommonJS",
7+
"outDir": "dist/main",
8+
"rootDir": "src",
9+
"sourceMap": true,
10+
"target": "ES2017",
11+
"strict": true,
12+
"esModuleInterop": true,
13+
"moduleResolution": "Node",
14+
"forceConsistentCasingInFileNames": true,
15+
"stripInternal": true
16+
}
17+
}

packages/core/storage-js/tsconfig.lib.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"sourceMap": true,
88
"target": "ES6",
99
"emitDeclarationOnly": false,
10+
"declaration": true,
11+
"declarationMap": true,
1012

1113
"stripInternal": true,
1214
"allowSyntheticDefaultImports": true,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"extends": "./tsconfig",
2+
"extends": "./tsconfig.lib.json",
33
"compilerOptions": {
44
"module": "ES2020",
5-
"outDir": "dist/module"
5+
"outDir": "./dist/module"
66
}
77
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Types that are shared between supabase-js and postgrest-js
2+
3+
export type Fetch = typeof fetch
4+
5+
export type GenericRelationship = {
6+
foreignKeyName: string
7+
columns: string[]
8+
isOneToOne?: boolean
9+
referencedRelation: string
10+
referencedColumns: string[]
11+
}
12+
13+
export type GenericTable = {
14+
Row: Record<string, unknown>
15+
Insert: Record<string, unknown>
16+
Update: Record<string, unknown>
17+
Relationships: GenericRelationship[]
18+
}
19+
20+
export type GenericUpdatableView = {
21+
Row: Record<string, unknown>
22+
Insert: Record<string, unknown>
23+
Update: Record<string, unknown>
24+
Relationships: GenericRelationship[]
25+
}
26+
27+
export type GenericNonUpdatableView = {
28+
Row: Record<string, unknown>
29+
Relationships: GenericRelationship[]
30+
}
31+
32+
export type GenericView = GenericUpdatableView | GenericNonUpdatableView
33+
34+
export type GenericSetofOption = {
35+
isSetofReturn?: boolean | undefined
36+
isOneToOne?: boolean | undefined
37+
isNotNullable?: boolean | undefined
38+
to: string
39+
from: string
40+
}
41+
42+
export type GenericFunction = {
43+
Args: Record<string, unknown> | never
44+
Returns: unknown
45+
SetofOptions?: GenericSetofOption
46+
}
47+
48+
export type GenericSchema = {
49+
Tables: Record<string, GenericTable>
50+
Views: Record<string, GenericView>
51+
Functions: Record<string, GenericFunction>
52+
}
53+
54+
export type ClientServerOptions = {
55+
PostgrestVersion?: string
56+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import type { GenericFunction, GenericSchema, GenericSetofOption } from './common'
2+
3+
// Functions matching utils
4+
type IsMatchingArgs<
5+
FnArgs extends GenericFunction['Args'],
6+
PassedArgs extends GenericFunction['Args'],
7+
> = [FnArgs] extends [Record<PropertyKey, never>]
8+
? PassedArgs extends Record<PropertyKey, never>
9+
? true
10+
: false
11+
: keyof PassedArgs extends keyof FnArgs
12+
? PassedArgs extends FnArgs
13+
? true
14+
: false
15+
: false
16+
17+
type MatchingFunctionArgs<
18+
Fn extends GenericFunction,
19+
Args extends GenericFunction['Args'],
20+
> = Fn extends { Args: infer A extends GenericFunction['Args'] }
21+
? IsMatchingArgs<A, Args> extends true
22+
? Fn
23+
: never
24+
: false
25+
26+
type FindMatchingFunctionByArgs<
27+
FnUnion,
28+
Args extends GenericFunction['Args'],
29+
> = FnUnion extends infer Fn extends GenericFunction ? MatchingFunctionArgs<Fn, Args> : false
30+
31+
// Types for working with database schemas
32+
type TablesAndViews<Schema extends GenericSchema> = Schema['Tables'] & Exclude<Schema['Views'], ''>
33+
34+
// Utility types for working with unions
35+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
36+
? I
37+
: never
38+
39+
type LastOf<T> =
40+
UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never
41+
42+
type IsAny<T> = 0 extends 1 & T ? true : false
43+
44+
type ExactMatch<T, S> = [T] extends [S] ? ([S] extends [T] ? true : false) : false
45+
46+
type ExtractExactFunction<Fns, Args> = Fns extends infer F
47+
? F extends GenericFunction
48+
? ExactMatch<F['Args'], Args> extends true
49+
? F
50+
: never
51+
: never
52+
: never
53+
54+
type IsNever<T> = [T] extends [never] ? true : false
55+
56+
type RpcFunctionNotFound<FnName> = {
57+
Row: any
58+
Result: {
59+
error: true
60+
} & "Couldn't infer function definition matching provided arguments"
61+
RelationName: FnName
62+
Relationships: null
63+
}
64+
65+
export type GetRpcFunctionFilterBuilderByArgs<
66+
Schema extends GenericSchema,
67+
FnName extends string & keyof Schema['Functions'],
68+
Args,
69+
> = {
70+
0: Schema['Functions'][FnName]
71+
// If the Args is exactly never (function call without any params)
72+
1: IsAny<Schema> extends true
73+
? any
74+
: IsNever<Args> extends true
75+
? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
76+
// we fallback to the last function definition matched by name
77+
IsNever<ExtractExactFunction<Schema['Functions'][FnName], Args>> extends true
78+
? LastOf<Schema['Functions'][FnName]>
79+
: ExtractExactFunction<Schema['Functions'][FnName], Args>
80+
: Args extends Record<PropertyKey, never>
81+
? LastOf<Schema['Functions'][FnName]>
82+
: // Otherwise, we attempt to match with one of the function definition in the union based
83+
// on the function arguments provided
84+
Args extends GenericFunction['Args']
85+
? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
86+
// we fallback to the last function definition matched by name
87+
IsNever<
88+
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
89+
> extends true
90+
? LastOf<Schema['Functions'][FnName]>
91+
: // Otherwise, we use the arguments based function definition narrowing to get the right value
92+
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
93+
: // If we can't find a matching function by args, we try to find one by function name
94+
ExtractExactFunction<Schema['Functions'][FnName], Args> extends GenericFunction
95+
? ExtractExactFunction<Schema['Functions'][FnName], Args>
96+
: any
97+
}[1] extends infer Fn
98+
? // If we are dealing with an non-typed client everything is any
99+
IsAny<Fn> extends true
100+
? { Row: any; Result: any; RelationName: FnName; Relationships: null }
101+
: // Otherwise, we use the arguments based function definition narrowing to get the rigt value
102+
Fn extends GenericFunction
103+
? {
104+
Row: Fn['SetofOptions'] extends GenericSetofOption
105+
? Fn['SetofOptions']['isSetofReturn'] extends true
106+
? TablesAndViews<Schema>[Fn['SetofOptions']['to']]['Row']
107+
: TablesAndViews<Schema>[Fn['SetofOptions']['to']]['Row']
108+
: Fn['Returns'] extends any[]
109+
? Fn['Returns'][number] extends Record<string, unknown>
110+
? Fn['Returns'][number]
111+
: never
112+
: Fn['Returns'] extends Record<string, unknown>
113+
? Fn['Returns']
114+
: never
115+
Result: Fn['SetofOptions'] extends GenericSetofOption
116+
? Fn['SetofOptions']['isSetofReturn'] extends true
117+
? Fn['SetofOptions']['isOneToOne'] extends true
118+
? Fn['Returns'][]
119+
: Fn['Returns']
120+
: Fn['Returns']
121+
: Fn['Returns']
122+
RelationName: Fn['SetofOptions'] extends GenericSetofOption
123+
? Fn['SetofOptions']['to']
124+
: FnName
125+
Relationships: Fn['SetofOptions'] extends GenericSetofOption
126+
? Fn['SetofOptions']['to'] extends keyof Schema['Tables']
127+
? Schema['Tables'][Fn['SetofOptions']['to']]['Relationships']
128+
: Schema['Views'][Fn['SetofOptions']['to']]['Relationships']
129+
: null
130+
}
131+
: // If we failed to find the function by argument, we still pass with any but also add an overridable
132+
Fn extends false
133+
? RpcFunctionNotFound<FnName>
134+
: RpcFunctionNotFound<FnName>
135+
: RpcFunctionNotFound<FnName>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"extends": "../../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "ES2020",
5+
"outDir": "./dist/main",
6+
"rootDir": "src",
7+
"sourceMap": true,
8+
"target": "ES2015",
9+
"emitDeclarationOnly": false,
10+
11+
"stripInternal": true,
12+
"allowSyntheticDefaultImports": true,
13+
"esModuleInterop": true
14+
},
15+
"include": ["src/**/*.ts"],
16+
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"],
17+
"references": [
18+
{
19+
"path": "../storage-js/tsconfig.lib.json"
20+
},
21+
{
22+
"path": "../realtime-js"
23+
},
24+
{
25+
"path": "../postgrest-js"
26+
},
27+
{
28+
"path": "../functions-js"
29+
},
30+
{
31+
"path": "../auth-js"
32+
}
33+
]
34+
}

packages/core/supabase-js/webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ module.exports = (env) => ({
2121
transpileOnly: true,
2222
},
2323
},
24+
{
25+
test: /\.m?js$/,
26+
resolve: {
27+
fullySpecified: false,
28+
},
29+
},
2430
],
2531
},
2632
resolve: {

0 commit comments

Comments
 (0)