Skip to content

Commit ce9dad8

Browse files
committed
docs(repo): more description and examples
1 parent dc13ad7 commit ce9dad8

File tree

7 files changed

+93
-0
lines changed

7 files changed

+93
-0
lines changed

packages/core/auth-js/src/lib/locks.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ export class ProcessLockAcquireTimeoutError extends LockAcquireTimeoutError {}
8686
* will time out after so many milliseconds. An error is
8787
* a timeout if it has `isAcquireTimeout` set to true.
8888
* @param fn The operation to run once the lock is acquired.
89+
* @example
90+
* ```ts
91+
* await navigatorLock('sync-user', 1000, async () => {
92+
* await refreshSession()
93+
* })
94+
* ```
8995
*/
9096
export async function navigatorLock<R>(
9197
name: string,
@@ -198,6 +204,12 @@ const PROCESS_LOCKS: { [name: string]: Promise<any> } = {}
198204
* will time out after so many milliseconds. An error is
199205
* a timeout if it has `isAcquireTimeout` set to true.
200206
* @param fn The operation to run once the lock is acquired.
207+
* @example
208+
* ```ts
209+
* await processLock('migrate', 5000, async () => {
210+
* await runMigration()
211+
* })
212+
* ```
201213
*/
202214
export async function processLock<R>(
203215
name: string,

packages/core/functions-js/src/FunctionsClient.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,28 @@ import {
99
FunctionsResponse,
1010
} from './types'
1111

12+
/**
13+
* Client for invoking Supabase Edge Functions.
14+
*/
1215
export class FunctionsClient {
1316
protected url: string
1417
protected headers: Record<string, string>
1518
protected region: FunctionRegion
1619
protected fetch: Fetch
1720

21+
/**
22+
* Creates a new Functions client bound to an Edge Functions URL.
23+
*
24+
* @example
25+
* ```ts
26+
* import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'
27+
*
28+
* const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
29+
* headers: { apikey: 'public-anon-key' },
30+
* region: FunctionRegion.UsEast1,
31+
* })
32+
* ```
33+
*/
1834
constructor(
1935
url: string,
2036
{
@@ -36,6 +52,10 @@ export class FunctionsClient {
3652
/**
3753
* Updates the authorization header
3854
* @param token - the new jwt token sent in the authorisation header
55+
* @example
56+
* ```ts
57+
* functions.setAuth(session.access_token)
58+
* ```
3959
*/
4060
setAuth(token: string) {
4161
this.headers.Authorization = `Bearer ${token}`
@@ -45,6 +65,12 @@ export class FunctionsClient {
4565
* Invokes a function
4666
* @param functionName - The name of the Function to invoke.
4767
* @param options - Options for invoking the Function.
68+
* @example
69+
* ```ts
70+
* const { data, error } = await functions.invoke('hello-world', {
71+
* body: { name: 'Ada' },
72+
* })
73+
* ```
4874
*/
4975
async invoke<T = any>(
5076
functionName: string,

packages/core/postgrest-js/src/PostgrestBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default abstract class PostgrestBuilder<
2929
protected isMaybeSingle: boolean
3030

3131
/**
32+
* Creates a builder configured for a specific PostgREST request.
33+
*
3234
* @example
3335
* ```ts
3436
* import PostgrestQueryBuilder from '@supabase/postgrest-js'

packages/core/postgrest-js/src/PostgrestQueryBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export default class PostgrestQueryBuilder<
2222
fetch?: Fetch
2323

2424
/**
25+
* Creates a query builder scoped to a Postgres table or view.
26+
*
2527
* @example
2628
* ```ts
2729
* import PostgrestQueryBuilder from '@supabase/postgrest-js'

packages/core/realtime-js/src/lib/websocket-factory.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export interface WebSocketEnvironment {
3232
workaround?: string
3333
}
3434

35+
/**
36+
* Utilities for creating WebSocket instances across runtimes.
37+
*/
3538
export class WebSocketFactory {
3639
private static detectEnvironment(): WebSocketEnvironment {
3740
if (typeof WebSocket !== 'undefined') {
@@ -115,6 +118,15 @@ export class WebSocketFactory {
115118
}
116119
}
117120

121+
/**
122+
* Returns the best available WebSocket constructor for the current runtime.
123+
*
124+
* @example
125+
* ```ts
126+
* const WS = WebSocketFactory.getWebSocketConstructor()
127+
* const socket = new WS('wss://realtime.supabase.co/socket')
128+
* ```
129+
*/
118130
public static getWebSocketConstructor(): typeof WebSocket {
119131
const env = this.detectEnvironment()
120132
if (env.constructor) {
@@ -127,11 +139,29 @@ export class WebSocketFactory {
127139
throw new Error(errorMessage)
128140
}
129141

142+
/**
143+
* Creates a WebSocket using the detected constructor.
144+
*
145+
* @example
146+
* ```ts
147+
* const socket = WebSocketFactory.createWebSocket('wss://realtime.supabase.co/socket')
148+
* ```
149+
*/
130150
public static createWebSocket(url: string | URL, protocols?: string | string[]): WebSocketLike {
131151
const WS = this.getWebSocketConstructor()
132152
return new WS(url, protocols)
133153
}
134154

155+
/**
156+
* Detects whether the runtime can establish WebSocket connections.
157+
*
158+
* @example
159+
* ```ts
160+
* if (!WebSocketFactory.isWebSocketSupported()) {
161+
* console.warn('Falling back to long polling')
162+
* }
163+
* ```
164+
*/
135165
public static isWebSocketSupported(): boolean {
136166
try {
137167
const env = this.detectEnvironment()

packages/core/storage-js/src/StorageClient.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ export interface StorageClientOptions {
99
}
1010

1111
export class StorageClient extends StorageBucketApi {
12+
/**
13+
* Creates a client for Storage buckets, files, analytics, and vectors.
14+
*
15+
* @example
16+
* ```ts
17+
* import { StorageClient } from '@supabase/storage-js'
18+
*
19+
* const storage = new StorageClient('https://xyzcompany.supabase.co/storage/v1', {
20+
* apikey: 'public-anon-key',
21+
* })
22+
* const avatars = storage.from('avatars')
23+
* ```
24+
*/
1225
constructor(
1326
url: string,
1427
headers: { [key: string]: string } = {},

packages/core/supabase-js/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export type { SupabaseClientOptions, QueryResult, QueryData, QueryError } from '
2323

2424
/**
2525
* Creates a new Supabase Client.
26+
*
27+
* @example
28+
* ```ts
29+
* import { createClient } from '@supabase/supabase-js'
30+
*
31+
* const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
32+
* const { data, error } = await supabase.from('profiles').select('*')
33+
* ```
2634
*/
2735
export const createClient = <
2836
Database = any,

0 commit comments

Comments
 (0)