@depup/supabase__supabase-js 2.99.2-depup.0
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 +25 -0
- package/changes.json +5 -0
- package/dist/cors.cjs +85 -0
- package/dist/cors.cjs.map +1 -0
- package/dist/cors.d.cts +56 -0
- package/dist/cors.d.cts.map +1 -0
- package/dist/cors.d.mts +56 -0
- package/dist/cors.d.mts.map +1 -0
- package/dist/cors.mjs +84 -0
- package/dist/cors.mjs.map +1 -0
- package/dist/index.cjs +622 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +564 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +564 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +575 -0
- package/dist/index.mjs.map +1 -0
- package/dist/umd/supabase.js +23 -0
- package/package.json +138 -0
- package/src/SupabaseClient.ts +589 -0
- package/src/cors.ts +75 -0
- package/src/index.ts +101 -0
- package/src/lib/SupabaseAuthClient.ts +8 -0
- package/src/lib/constants.ts +35 -0
- package/src/lib/fetch.ts +36 -0
- package/src/lib/helpers.ts +98 -0
- package/src/lib/rest/types/common/common.ts +66 -0
- package/src/lib/rest/types/common/rpc.ts +158 -0
- package/src/lib/types.ts +173 -0
- package/src/lib/version.ts +7 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import SupabaseClient from './SupabaseClient'
|
|
2
|
+
import type { SupabaseClientOptions } from './lib/types'
|
|
3
|
+
|
|
4
|
+
export * from '@supabase/auth-js'
|
|
5
|
+
export type { User as AuthUser, Session as AuthSession } from '@supabase/auth-js'
|
|
6
|
+
export type {
|
|
7
|
+
PostgrestResponse,
|
|
8
|
+
PostgrestSingleResponse,
|
|
9
|
+
PostgrestMaybeSingleResponse,
|
|
10
|
+
} from '@supabase/postgrest-js'
|
|
11
|
+
export { PostgrestError } from '@supabase/postgrest-js'
|
|
12
|
+
export type { FunctionInvokeOptions } from '@supabase/functions-js'
|
|
13
|
+
export {
|
|
14
|
+
FunctionsHttpError,
|
|
15
|
+
FunctionsFetchError,
|
|
16
|
+
FunctionsRelayError,
|
|
17
|
+
FunctionsError,
|
|
18
|
+
FunctionRegion,
|
|
19
|
+
} from '@supabase/functions-js'
|
|
20
|
+
export * from '@supabase/realtime-js'
|
|
21
|
+
export { default as SupabaseClient } from './SupabaseClient'
|
|
22
|
+
export type {
|
|
23
|
+
SupabaseClientOptions,
|
|
24
|
+
QueryResult,
|
|
25
|
+
QueryData,
|
|
26
|
+
QueryError,
|
|
27
|
+
DatabaseWithoutInternals,
|
|
28
|
+
} from './lib/types'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new Supabase Client.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
36
|
+
*
|
|
37
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
|
|
38
|
+
* const { data, error } = await supabase.from('profiles').select('*')
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const createClient = <
|
|
42
|
+
Database = any,
|
|
43
|
+
SchemaNameOrClientOptions extends
|
|
44
|
+
| (string & keyof Omit<Database, '__InternalSupabase'>)
|
|
45
|
+
| { PostgrestVersion: string } = 'public' extends keyof Omit<Database, '__InternalSupabase'>
|
|
46
|
+
? 'public'
|
|
47
|
+
: string & keyof Omit<Database, '__InternalSupabase'>,
|
|
48
|
+
SchemaName extends string &
|
|
49
|
+
keyof Omit<Database, '__InternalSupabase'> = SchemaNameOrClientOptions extends string &
|
|
50
|
+
keyof Omit<Database, '__InternalSupabase'>
|
|
51
|
+
? SchemaNameOrClientOptions
|
|
52
|
+
: 'public' extends keyof Omit<Database, '__InternalSupabase'>
|
|
53
|
+
? 'public'
|
|
54
|
+
: string & keyof Omit<Omit<Database, '__InternalSupabase'>, '__InternalSupabase'>,
|
|
55
|
+
>(
|
|
56
|
+
supabaseUrl: string,
|
|
57
|
+
supabaseKey: string,
|
|
58
|
+
options?: SupabaseClientOptions<SchemaName>
|
|
59
|
+
): SupabaseClient<Database, SchemaNameOrClientOptions, SchemaName> => {
|
|
60
|
+
return new SupabaseClient<Database, SchemaNameOrClientOptions, SchemaName>(
|
|
61
|
+
supabaseUrl,
|
|
62
|
+
supabaseKey,
|
|
63
|
+
options
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Check for Node.js <= 18 deprecation
|
|
68
|
+
function shouldShowDeprecationWarning(): boolean {
|
|
69
|
+
// Skip in browser environments
|
|
70
|
+
if (typeof window !== 'undefined') {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Skip if process is not available (e.g., Edge Runtime)
|
|
75
|
+
// Use dynamic property access to avoid Next.js Edge Runtime static analysis warnings
|
|
76
|
+
const _process = (globalThis as any)['process']
|
|
77
|
+
if (!_process) {
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const processVersion = _process['version']
|
|
82
|
+
if (processVersion === undefined || processVersion === null) {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const versionMatch = processVersion.match(/^v(\d+)\./)
|
|
87
|
+
if (!versionMatch) {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const majorVersion = parseInt(versionMatch[1], 10)
|
|
92
|
+
return majorVersion <= 18
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (shouldShowDeprecationWarning()) {
|
|
96
|
+
console.warn(
|
|
97
|
+
`⚠️ Node.js 18 and below are deprecated and will no longer be supported in future versions of @supabase/supabase-js. ` +
|
|
98
|
+
`Please upgrade to Node.js 20 or later. ` +
|
|
99
|
+
`For more information, visit: https://github.com/orgs/supabase/discussions/37217`
|
|
100
|
+
)
|
|
101
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// constants.ts
|
|
2
|
+
import { RealtimeClientOptions } from '@supabase/realtime-js'
|
|
3
|
+
import { SupabaseAuthClientOptions } from './types'
|
|
4
|
+
import { version } from './version'
|
|
5
|
+
|
|
6
|
+
let JS_ENV = ''
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
if (typeof Deno !== 'undefined') {
|
|
9
|
+
JS_ENV = 'deno'
|
|
10
|
+
} else if (typeof document !== 'undefined') {
|
|
11
|
+
JS_ENV = 'web'
|
|
12
|
+
} else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
13
|
+
JS_ENV = 'react-native'
|
|
14
|
+
} else {
|
|
15
|
+
JS_ENV = 'node'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js-${JS_ENV}/${version}` }
|
|
19
|
+
|
|
20
|
+
export const DEFAULT_GLOBAL_OPTIONS = {
|
|
21
|
+
headers: DEFAULT_HEADERS,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_DB_OPTIONS = {
|
|
25
|
+
schema: 'public',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
|
|
29
|
+
autoRefreshToken: true,
|
|
30
|
+
persistSession: true,
|
|
31
|
+
detectSessionInUrl: true,
|
|
32
|
+
flowType: 'implicit',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}
|
package/src/lib/fetch.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type Fetch = typeof fetch
|
|
2
|
+
|
|
3
|
+
export const resolveFetch = (customFetch?: Fetch): Fetch => {
|
|
4
|
+
if (customFetch) {
|
|
5
|
+
return (...args: Parameters<Fetch>) => customFetch(...args)
|
|
6
|
+
}
|
|
7
|
+
return (...args: Parameters<Fetch>) => fetch(...args)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const resolveHeadersConstructor = () => {
|
|
11
|
+
return Headers
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const fetchWithAuth = (
|
|
15
|
+
supabaseKey: string,
|
|
16
|
+
getAccessToken: () => Promise<string | null>,
|
|
17
|
+
customFetch?: Fetch
|
|
18
|
+
): Fetch => {
|
|
19
|
+
const fetch = resolveFetch(customFetch)
|
|
20
|
+
const HeadersConstructor = resolveHeadersConstructor()
|
|
21
|
+
|
|
22
|
+
return async (input, init) => {
|
|
23
|
+
const accessToken = (await getAccessToken()) ?? supabaseKey
|
|
24
|
+
let headers = new HeadersConstructor(init?.headers)
|
|
25
|
+
|
|
26
|
+
if (!headers.has('apikey')) {
|
|
27
|
+
headers.set('apikey', supabaseKey)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!headers.has('Authorization')) {
|
|
31
|
+
headers.set('Authorization', `Bearer ${accessToken}`)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return fetch(input, { ...init, headers })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// helpers.ts
|
|
2
|
+
import { SupabaseClientOptions } from './types'
|
|
3
|
+
|
|
4
|
+
export function uuid() {
|
|
5
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
6
|
+
var r = (Math.random() * 16) | 0,
|
|
7
|
+
v = c == 'x' ? r : (r & 0x3) | 0x8
|
|
8
|
+
return v.toString(16)
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ensureTrailingSlash(url: string): string {
|
|
13
|
+
return url.endsWith('/') ? url : url + '/'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const isBrowser = () => typeof window !== 'undefined'
|
|
17
|
+
|
|
18
|
+
export function applySettingDefaults<
|
|
19
|
+
Database = any,
|
|
20
|
+
SchemaName extends string & keyof Database = 'public' extends keyof Database
|
|
21
|
+
? 'public'
|
|
22
|
+
: string & keyof Database,
|
|
23
|
+
>(
|
|
24
|
+
options: SupabaseClientOptions<SchemaName>,
|
|
25
|
+
defaults: SupabaseClientOptions<any>
|
|
26
|
+
): Required<SupabaseClientOptions<SchemaName>> {
|
|
27
|
+
const {
|
|
28
|
+
db: dbOptions,
|
|
29
|
+
auth: authOptions,
|
|
30
|
+
realtime: realtimeOptions,
|
|
31
|
+
global: globalOptions,
|
|
32
|
+
} = options
|
|
33
|
+
const {
|
|
34
|
+
db: DEFAULT_DB_OPTIONS,
|
|
35
|
+
auth: DEFAULT_AUTH_OPTIONS,
|
|
36
|
+
realtime: DEFAULT_REALTIME_OPTIONS,
|
|
37
|
+
global: DEFAULT_GLOBAL_OPTIONS,
|
|
38
|
+
} = defaults
|
|
39
|
+
|
|
40
|
+
const result: Required<SupabaseClientOptions<SchemaName>> = {
|
|
41
|
+
db: {
|
|
42
|
+
...DEFAULT_DB_OPTIONS,
|
|
43
|
+
...dbOptions,
|
|
44
|
+
},
|
|
45
|
+
auth: {
|
|
46
|
+
...DEFAULT_AUTH_OPTIONS,
|
|
47
|
+
...authOptions,
|
|
48
|
+
},
|
|
49
|
+
realtime: {
|
|
50
|
+
...DEFAULT_REALTIME_OPTIONS,
|
|
51
|
+
...realtimeOptions,
|
|
52
|
+
},
|
|
53
|
+
storage: {},
|
|
54
|
+
global: {
|
|
55
|
+
...DEFAULT_GLOBAL_OPTIONS,
|
|
56
|
+
...globalOptions,
|
|
57
|
+
headers: {
|
|
58
|
+
...(DEFAULT_GLOBAL_OPTIONS?.headers ?? {}),
|
|
59
|
+
...(globalOptions?.headers ?? {}),
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
accessToken: async () => '',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.accessToken) {
|
|
66
|
+
result.accessToken = options.accessToken
|
|
67
|
+
} else {
|
|
68
|
+
// hack around Required<>
|
|
69
|
+
delete (result as any).accessToken
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Validates a Supabase client URL
|
|
77
|
+
*
|
|
78
|
+
* @param {string} supabaseUrl - The Supabase client URL string.
|
|
79
|
+
* @returns {URL} - The validated base URL.
|
|
80
|
+
* @throws {Error}
|
|
81
|
+
*/
|
|
82
|
+
export function validateSupabaseUrl(supabaseUrl: string): URL {
|
|
83
|
+
const trimmedUrl = supabaseUrl?.trim()
|
|
84
|
+
|
|
85
|
+
if (!trimmedUrl) {
|
|
86
|
+
throw new Error('supabaseUrl is required.')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!trimmedUrl.match(/^https?:\/\//i)) {
|
|
90
|
+
throw new Error('Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL.')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
return new URL(ensureTrailingSlash(trimmedUrl))
|
|
95
|
+
} catch {
|
|
96
|
+
throw Error('Invalid supabaseUrl: Provided URL is malformed.')
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE - DO NOT EDIT
|
|
3
|
+
*
|
|
4
|
+
* This file is automatically synchronized from @supabase/postgrest-js
|
|
5
|
+
* Source: packages/core/postgrest-js/src/types/common/
|
|
6
|
+
*
|
|
7
|
+
* To update this file, modify the source in postgrest-js and run:
|
|
8
|
+
* npm run codegen
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Types that are shared between supabase-js and postgrest-js
|
|
12
|
+
|
|
13
|
+
export type Fetch = typeof fetch
|
|
14
|
+
|
|
15
|
+
export type GenericRelationship = {
|
|
16
|
+
foreignKeyName: string
|
|
17
|
+
columns: string[]
|
|
18
|
+
isOneToOne?: boolean
|
|
19
|
+
referencedRelation: string
|
|
20
|
+
referencedColumns: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type GenericTable = {
|
|
24
|
+
Row: Record<string, unknown>
|
|
25
|
+
Insert: Record<string, unknown>
|
|
26
|
+
Update: Record<string, unknown>
|
|
27
|
+
Relationships: GenericRelationship[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type GenericUpdatableView = {
|
|
31
|
+
Row: Record<string, unknown>
|
|
32
|
+
Insert: Record<string, unknown>
|
|
33
|
+
Update: Record<string, unknown>
|
|
34
|
+
Relationships: GenericRelationship[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type GenericNonUpdatableView = {
|
|
38
|
+
Row: Record<string, unknown>
|
|
39
|
+
Relationships: GenericRelationship[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type GenericView = GenericUpdatableView | GenericNonUpdatableView
|
|
43
|
+
|
|
44
|
+
export type GenericSetofOption = {
|
|
45
|
+
isSetofReturn?: boolean | undefined
|
|
46
|
+
isOneToOne?: boolean | undefined
|
|
47
|
+
isNotNullable?: boolean | undefined
|
|
48
|
+
to: string
|
|
49
|
+
from: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type GenericFunction = {
|
|
53
|
+
Args: Record<string, unknown> | never
|
|
54
|
+
Returns: unknown
|
|
55
|
+
SetofOptions?: GenericSetofOption
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type GenericSchema = {
|
|
59
|
+
Tables: Record<string, GenericTable>
|
|
60
|
+
Views: Record<string, GenericView>
|
|
61
|
+
Functions: Record<string, GenericFunction>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type ClientServerOptions = {
|
|
65
|
+
PostgrestVersion?: string
|
|
66
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE - DO NOT EDIT
|
|
3
|
+
*
|
|
4
|
+
* This file is automatically synchronized from @supabase/postgrest-js
|
|
5
|
+
* Source: packages/core/postgrest-js/src/types/common/
|
|
6
|
+
*
|
|
7
|
+
* To update this file, modify the source in postgrest-js and run:
|
|
8
|
+
* npm run codegen
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { GenericFunction, GenericSchema, GenericSetofOption } from './common'
|
|
12
|
+
|
|
13
|
+
// Functions matching utils
|
|
14
|
+
type IsMatchingArgs<
|
|
15
|
+
FnArgs extends GenericFunction['Args'],
|
|
16
|
+
PassedArgs extends GenericFunction['Args'],
|
|
17
|
+
> = [FnArgs] extends [Record<PropertyKey, never>]
|
|
18
|
+
? PassedArgs extends Record<PropertyKey, never>
|
|
19
|
+
? true
|
|
20
|
+
: false
|
|
21
|
+
: keyof PassedArgs extends keyof FnArgs
|
|
22
|
+
? PassedArgs extends FnArgs
|
|
23
|
+
? true
|
|
24
|
+
: false
|
|
25
|
+
: false
|
|
26
|
+
|
|
27
|
+
type MatchingFunctionArgs<
|
|
28
|
+
Fn extends GenericFunction,
|
|
29
|
+
Args extends GenericFunction['Args'],
|
|
30
|
+
> = Fn extends { Args: infer A extends GenericFunction['Args'] }
|
|
31
|
+
? IsMatchingArgs<A, Args> extends true
|
|
32
|
+
? Fn
|
|
33
|
+
: never
|
|
34
|
+
: false
|
|
35
|
+
|
|
36
|
+
type FindMatchingFunctionByArgs<
|
|
37
|
+
FnUnion,
|
|
38
|
+
Args extends GenericFunction['Args'],
|
|
39
|
+
> = FnUnion extends infer Fn extends GenericFunction ? MatchingFunctionArgs<Fn, Args> : false
|
|
40
|
+
|
|
41
|
+
// Types for working with database schemas
|
|
42
|
+
type TablesAndViews<Schema extends GenericSchema> = Schema['Tables'] & Exclude<Schema['Views'], ''>
|
|
43
|
+
|
|
44
|
+
// Utility types for working with unions
|
|
45
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
|
|
46
|
+
? I
|
|
47
|
+
: never
|
|
48
|
+
|
|
49
|
+
type LastOf<T> =
|
|
50
|
+
UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never
|
|
51
|
+
|
|
52
|
+
type IsAny<T> = 0 extends 1 & T ? true : false
|
|
53
|
+
|
|
54
|
+
type ExactMatch<T, S> = [T] extends [S] ? ([S] extends [T] ? true : false) : false
|
|
55
|
+
|
|
56
|
+
type ExtractExactFunction<Fns, Args> = Fns extends infer F
|
|
57
|
+
? F extends GenericFunction
|
|
58
|
+
? ExactMatch<F['Args'], Args> extends true
|
|
59
|
+
? F
|
|
60
|
+
: never
|
|
61
|
+
: never
|
|
62
|
+
: never
|
|
63
|
+
|
|
64
|
+
type IsNever<T> = [T] extends [never] ? true : false
|
|
65
|
+
|
|
66
|
+
type RpcFunctionNotFound<FnName> = {
|
|
67
|
+
Row: any
|
|
68
|
+
Result: {
|
|
69
|
+
error: true
|
|
70
|
+
} & "Couldn't infer function definition matching provided arguments"
|
|
71
|
+
RelationName: FnName
|
|
72
|
+
Relationships: null
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type CrossSchemaError<TableRef extends string> = {
|
|
76
|
+
error: true
|
|
77
|
+
} & `Function returns SETOF from a different schema ('${TableRef}'). Use .overrideTypes<YourReturnType>() to specify the return type explicitly.`
|
|
78
|
+
|
|
79
|
+
export type GetRpcFunctionFilterBuilderByArgs<
|
|
80
|
+
Schema extends GenericSchema,
|
|
81
|
+
FnName extends string & keyof Schema['Functions'],
|
|
82
|
+
Args,
|
|
83
|
+
> = {
|
|
84
|
+
0: Schema['Functions'][FnName]
|
|
85
|
+
// If the Args is exactly never (function call without any params)
|
|
86
|
+
1: IsAny<Schema> extends true
|
|
87
|
+
? any
|
|
88
|
+
: IsNever<Args> extends true
|
|
89
|
+
? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
|
|
90
|
+
// we fallback to the last function definition matched by name
|
|
91
|
+
IsNever<ExtractExactFunction<Schema['Functions'][FnName], Args>> extends true
|
|
92
|
+
? LastOf<Schema['Functions'][FnName]>
|
|
93
|
+
: ExtractExactFunction<Schema['Functions'][FnName], Args>
|
|
94
|
+
: Args extends Record<PropertyKey, never>
|
|
95
|
+
? LastOf<Schema['Functions'][FnName]>
|
|
96
|
+
: // Otherwise, we attempt to match with one of the function definition in the union based
|
|
97
|
+
// on the function arguments provided
|
|
98
|
+
Args extends GenericFunction['Args']
|
|
99
|
+
? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
|
|
100
|
+
// we fallback to the last function definition matched by name
|
|
101
|
+
IsNever<
|
|
102
|
+
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
|
|
103
|
+
> extends true
|
|
104
|
+
? LastOf<Schema['Functions'][FnName]>
|
|
105
|
+
: // Otherwise, we use the arguments based function definition narrowing to get the right value
|
|
106
|
+
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
|
|
107
|
+
: // If we can't find a matching function by args, we try to find one by function name
|
|
108
|
+
ExtractExactFunction<Schema['Functions'][FnName], Args> extends GenericFunction
|
|
109
|
+
? ExtractExactFunction<Schema['Functions'][FnName], Args>
|
|
110
|
+
: any
|
|
111
|
+
}[1] extends infer Fn
|
|
112
|
+
? // If we are dealing with an non-typed client everything is any
|
|
113
|
+
IsAny<Fn> extends true
|
|
114
|
+
? { Row: any; Result: any; RelationName: FnName; Relationships: null }
|
|
115
|
+
: // Otherwise, we use the arguments based function definition narrowing to get the right value
|
|
116
|
+
Fn extends GenericFunction
|
|
117
|
+
? {
|
|
118
|
+
Row: Fn['SetofOptions'] extends GenericSetofOption
|
|
119
|
+
? Fn['SetofOptions']['to'] extends keyof TablesAndViews<Schema>
|
|
120
|
+
? TablesAndViews<Schema>[Fn['SetofOptions']['to']]['Row']
|
|
121
|
+
: // Cross-schema fallback: use Returns type when table is not in current schema
|
|
122
|
+
Fn['Returns'] extends any[]
|
|
123
|
+
? Fn['Returns'][number] extends Record<string, unknown>
|
|
124
|
+
? Fn['Returns'][number]
|
|
125
|
+
: CrossSchemaError<Fn['SetofOptions']['to'] & string>
|
|
126
|
+
: Fn['Returns'] extends Record<string, unknown>
|
|
127
|
+
? Fn['Returns']
|
|
128
|
+
: CrossSchemaError<Fn['SetofOptions']['to'] & string>
|
|
129
|
+
: Fn['Returns'] extends any[]
|
|
130
|
+
? Fn['Returns'][number] extends Record<string, unknown>
|
|
131
|
+
? Fn['Returns'][number]
|
|
132
|
+
: never
|
|
133
|
+
: Fn['Returns'] extends Record<string, unknown>
|
|
134
|
+
? Fn['Returns']
|
|
135
|
+
: never
|
|
136
|
+
Result: Fn['SetofOptions'] extends GenericSetofOption
|
|
137
|
+
? Fn['SetofOptions']['isSetofReturn'] extends true
|
|
138
|
+
? Fn['SetofOptions']['isOneToOne'] extends true
|
|
139
|
+
? Fn['Returns'][]
|
|
140
|
+
: Fn['Returns']
|
|
141
|
+
: Fn['Returns']
|
|
142
|
+
: Fn['Returns']
|
|
143
|
+
RelationName: Fn['SetofOptions'] extends GenericSetofOption
|
|
144
|
+
? Fn['SetofOptions']['to']
|
|
145
|
+
: FnName
|
|
146
|
+
Relationships: Fn['SetofOptions'] extends GenericSetofOption
|
|
147
|
+
? Fn['SetofOptions']['to'] extends keyof Schema['Tables']
|
|
148
|
+
? Schema['Tables'][Fn['SetofOptions']['to']]['Relationships']
|
|
149
|
+
: Fn['SetofOptions']['to'] extends keyof Schema['Views']
|
|
150
|
+
? Schema['Views'][Fn['SetofOptions']['to']]['Relationships']
|
|
151
|
+
: null
|
|
152
|
+
: null
|
|
153
|
+
}
|
|
154
|
+
: // If we failed to find the function by argument, we still pass with any but also add an overridable
|
|
155
|
+
Fn extends false
|
|
156
|
+
? RpcFunctionNotFound<FnName>
|
|
157
|
+
: RpcFunctionNotFound<FnName>
|
|
158
|
+
: RpcFunctionNotFound<FnName>
|
package/src/lib/types.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { GoTrueClientOptions } from '@supabase/auth-js'
|
|
2
|
+
import { RealtimeClientOptions } from '@supabase/realtime-js'
|
|
3
|
+
import { PostgrestError } from '@supabase/postgrest-js'
|
|
4
|
+
import type { StorageClientOptions } from '@supabase/storage-js'
|
|
5
|
+
import type {
|
|
6
|
+
GenericSchema,
|
|
7
|
+
GenericRelationship,
|
|
8
|
+
GenericTable,
|
|
9
|
+
GenericUpdatableView,
|
|
10
|
+
GenericNonUpdatableView,
|
|
11
|
+
GenericView,
|
|
12
|
+
GenericFunction,
|
|
13
|
+
} from './rest/types/common/common'
|
|
14
|
+
export type {
|
|
15
|
+
GenericSchema,
|
|
16
|
+
GenericRelationship,
|
|
17
|
+
GenericTable,
|
|
18
|
+
GenericUpdatableView,
|
|
19
|
+
GenericNonUpdatableView,
|
|
20
|
+
GenericView,
|
|
21
|
+
GenericFunction,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
|
|
25
|
+
|
|
26
|
+
export type Fetch = typeof fetch
|
|
27
|
+
|
|
28
|
+
export type SupabaseClientOptions<SchemaName> = {
|
|
29
|
+
/**
|
|
30
|
+
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to `public`.
|
|
31
|
+
*/
|
|
32
|
+
db?: {
|
|
33
|
+
schema?: SchemaName
|
|
34
|
+
/**
|
|
35
|
+
* Optional timeout in milliseconds for PostgREST requests.
|
|
36
|
+
* When set, requests will automatically abort after this duration to prevent indefinite hangs.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const supabase = createClient(url, key, {
|
|
41
|
+
* db: { timeout: 30000 } // 30 second timeout
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
timeout?: number
|
|
46
|
+
/**
|
|
47
|
+
* Maximum URL length in characters before warnings/errors are triggered.
|
|
48
|
+
* Defaults to 8000 characters. Used to provide helpful hints when URLs
|
|
49
|
+
* exceed server limits.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const supabase = createClient(url, key, {
|
|
54
|
+
* db: { urlLengthLimit: 10000 } // Custom limit
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
urlLengthLimit?: number
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
auth?: {
|
|
62
|
+
/**
|
|
63
|
+
* Automatically refreshes the token for logged-in users. Defaults to true.
|
|
64
|
+
*/
|
|
65
|
+
autoRefreshToken?: boolean
|
|
66
|
+
/**
|
|
67
|
+
* Optional key name used for storing tokens in local storage.
|
|
68
|
+
*/
|
|
69
|
+
storageKey?: string
|
|
70
|
+
/**
|
|
71
|
+
* Whether to persist a logged-in session to storage. Defaults to true.
|
|
72
|
+
*/
|
|
73
|
+
persistSession?: boolean
|
|
74
|
+
/**
|
|
75
|
+
* Detect a session from the URL. Used for OAuth login callbacks. Defaults to true.
|
|
76
|
+
*
|
|
77
|
+
* Can be set to a function to provide custom logic for determining if a URL contains
|
|
78
|
+
* a Supabase auth callback. The function receives the current URL and parsed parameters,
|
|
79
|
+
* and should return true if the URL should be processed as a Supabase auth callback.
|
|
80
|
+
*
|
|
81
|
+
* This is useful when your app uses other OAuth providers (e.g., Facebook Login) that
|
|
82
|
+
* also return access_token in the URL fragment, which would otherwise be incorrectly
|
|
83
|
+
* intercepted by Supabase Auth.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* detectSessionInUrl: (url, params) => {
|
|
88
|
+
* // Ignore Facebook OAuth redirects
|
|
89
|
+
* if (url.pathname === '/facebook/redirect') return false
|
|
90
|
+
* // Use default detection for other URLs
|
|
91
|
+
* return Boolean(params.access_token || params.error_description)
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
detectSessionInUrl?: boolean | ((url: URL, params: { [parameter: string]: string }) => boolean)
|
|
96
|
+
/**
|
|
97
|
+
* A storage provider. Used to store the logged-in session.
|
|
98
|
+
*/
|
|
99
|
+
storage?: SupabaseAuthClientOptions['storage']
|
|
100
|
+
/**
|
|
101
|
+
* A storage provider to store the user profile separately from the session.
|
|
102
|
+
* Useful when you need to store the session information in cookies,
|
|
103
|
+
* without bloating the data with the redundant user object.
|
|
104
|
+
*
|
|
105
|
+
* @experimental
|
|
106
|
+
*/
|
|
107
|
+
userStorage?: SupabaseAuthClientOptions['userStorage']
|
|
108
|
+
/**
|
|
109
|
+
* OAuth flow to use - defaults to implicit flow. PKCE is recommended for mobile and server-side applications.
|
|
110
|
+
*/
|
|
111
|
+
flowType?: SupabaseAuthClientOptions['flowType']
|
|
112
|
+
/**
|
|
113
|
+
* If debug messages for authentication client are emitted. Can be used to inspect the behavior of the library.
|
|
114
|
+
*/
|
|
115
|
+
debug?: SupabaseAuthClientOptions['debug']
|
|
116
|
+
/**
|
|
117
|
+
* Provide your own locking mechanism based on the environment. By default no locking is done at this time.
|
|
118
|
+
*
|
|
119
|
+
* @experimental
|
|
120
|
+
*/
|
|
121
|
+
lock?: SupabaseAuthClientOptions['lock']
|
|
122
|
+
/**
|
|
123
|
+
* If there is an error with the query, throwOnError will reject the promise by
|
|
124
|
+
* throwing the error instead of returning it as part of a successful response.
|
|
125
|
+
*/
|
|
126
|
+
throwOnError?: SupabaseAuthClientOptions['throwOnError']
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Options passed to the realtime-js instance
|
|
130
|
+
*/
|
|
131
|
+
realtime?: RealtimeClientOptions
|
|
132
|
+
storage?: StorageClientOptions
|
|
133
|
+
global?: {
|
|
134
|
+
/**
|
|
135
|
+
* A custom `fetch` implementation.
|
|
136
|
+
*/
|
|
137
|
+
fetch?: Fetch
|
|
138
|
+
/**
|
|
139
|
+
* Optional headers for initializing the client.
|
|
140
|
+
*/
|
|
141
|
+
headers?: Record<string, string>
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Optional function for using a third-party authentication system with
|
|
145
|
+
* Supabase. The function should return an access token or ID token (JWT) by
|
|
146
|
+
* obtaining it from the third-party auth SDK. Note that this
|
|
147
|
+
* function may be called concurrently and many times. Use memoization and
|
|
148
|
+
* locking techniques if this is not supported by the SDKs.
|
|
149
|
+
*
|
|
150
|
+
* When set, the `auth` namespace of the Supabase client cannot be used.
|
|
151
|
+
* Create another client if you wish to use Supabase Auth and third-party
|
|
152
|
+
* authentications concurrently in the same application.
|
|
153
|
+
*/
|
|
154
|
+
accessToken?: () => Promise<string | null>
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Helper types for query results.
|
|
159
|
+
*/
|
|
160
|
+
export type QueryResult<T> = T extends PromiseLike<infer U> ? U : never
|
|
161
|
+
export type QueryData<T> = T extends PromiseLike<{ data: infer U }> ? Exclude<U, null> : never
|
|
162
|
+
export type QueryError = PostgrestError
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Strips internal Supabase metadata from Database types.
|
|
166
|
+
* Useful for libraries defining generic constraints on Database types.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* type CleanDB = DatabaseWithoutInternals<Database>
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export type DatabaseWithoutInternals<DB> = Omit<DB, '__InternalSupabase'>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Generated automatically during releases by scripts/update-version-files.ts
|
|
2
|
+
// This file provides runtime access to the package version for:
|
|
3
|
+
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
|
4
|
+
// - Debugging and support (identifying which version is running)
|
|
5
|
+
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
|
+
// - Ensuring build artifacts match the published package version
|
|
7
|
+
export const version = '2.99.2'
|