@motherbase/client 2.2.0 → 2.2.3
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/COMPATIBILITY.md +157 -0
- package/LICENSE +21 -21
- package/README.md +53 -5
- package/dist/admin/auth-admin-client.d.ts +43 -0
- package/dist/admin/auth-admin-client.d.ts.map +1 -0
- package/dist/admin/auth-admin-client.js +62 -0
- package/dist/admin/auth-admin-client.js.map +1 -0
- package/dist/admin/auth-admin-mfa-client.d.ts +22 -0
- package/dist/admin/auth-admin-mfa-client.d.ts.map +1 -0
- package/dist/admin/auth-admin-mfa-client.js +17 -0
- package/dist/admin/auth-admin-mfa-client.js.map +1 -0
- package/dist/admin/types.d.ts +85 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +3 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/auth/constants.d.ts +21 -0
- package/dist/auth/constants.d.ts.map +1 -0
- package/dist/auth/constants.js +34 -0
- package/dist/auth/constants.js.map +1 -0
- package/dist/auth/index.d.ts +5 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +34 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/motherbase-plugin.d.ts +6 -0
- package/dist/auth/motherbase-plugin.d.ts.map +1 -0
- package/dist/auth/motherbase-plugin.js +80 -0
- package/dist/auth/motherbase-plugin.js.map +1 -0
- package/dist/auth/pkce.d.ts +19 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +89 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/session-utils.d.ts +29 -0
- package/dist/auth/session-utils.d.ts.map +1 -0
- package/dist/auth/session-utils.js +123 -0
- package/dist/auth/session-utils.js.map +1 -0
- package/dist/auth/session.d.ts +51 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +161 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/types.d.ts +341 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/utils.d.ts +28 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/auth/utils.js +70 -0
- package/dist/auth/utils.js.map +1 -0
- package/dist/auth.d.ts +3 -2
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +27 -11
- package/dist/auth.js.map +1 -1
- package/dist/channel.d.ts +11 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +26 -2
- package/dist/channel.js.map +1 -1
- package/dist/cookies/cookie-storage.d.ts +12 -0
- package/dist/cookies/cookie-storage.d.ts.map +1 -0
- package/dist/cookies/cookie-storage.js +35 -0
- package/dist/cookies/cookie-storage.js.map +1 -0
- package/dist/cookies/index.d.ts +5 -0
- package/dist/cookies/index.d.ts.map +1 -0
- package/dist/cookies/index.js +5 -0
- package/dist/cookies/index.js.map +1 -0
- package/dist/cookies/server-cookie-storage.d.ts +20 -0
- package/dist/cookies/server-cookie-storage.d.ts.map +1 -0
- package/dist/cookies/server-cookie-storage.js +60 -0
- package/dist/cookies/server-cookie-storage.js.map +1 -0
- package/dist/cookies/types.d.ts +33 -0
- package/dist/cookies/types.d.ts.map +1 -0
- package/dist/cookies/types.js +8 -0
- package/dist/cookies/types.js.map +1 -0
- package/dist/cookies/utils.d.ts +23 -0
- package/dist/cookies/utils.d.ts.map +1 -0
- package/dist/cookies/utils.js +67 -0
- package/dist/cookies/utils.js.map +1 -0
- package/dist/database/database.d.ts +197 -0
- package/dist/database/database.d.ts.map +1 -0
- package/dist/database/database.js +2 -0
- package/dist/database/database.js.map +1 -0
- package/dist/database/facade.d.ts +144 -0
- package/dist/database/facade.d.ts.map +1 -0
- package/dist/database/facade.js +147 -0
- package/dist/database/facade.js.map +1 -0
- package/dist/database/query.d.ts +97 -0
- package/dist/database/query.d.ts.map +1 -0
- package/dist/database/query.js +94 -0
- package/dist/database/query.js.map +1 -0
- package/dist/database/types.d.ts +314 -0
- package/dist/database/types.d.ts.map +1 -0
- package/dist/database/types.js +2 -0
- package/dist/database/types.js.map +1 -0
- package/dist/functions/errors.d.ts +28 -0
- package/dist/functions/errors.d.ts.map +1 -0
- package/dist/functions/errors.js +37 -0
- package/dist/functions/errors.js.map +1 -0
- package/dist/functions/index.d.ts +9 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +40 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/types.d.ts +25 -0
- package/dist/functions/types.d.ts.map +1 -0
- package/dist/functions/types.js +2 -0
- package/dist/functions/types.js.map +1 -0
- package/dist/http/backend-error.d.ts +17 -0
- package/dist/http/backend-error.d.ts.map +1 -0
- package/dist/http/backend-error.js +11 -0
- package/dist/http/backend-error.js.map +1 -0
- package/dist/http/index.d.ts +59 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +175 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/types.d.ts +45 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +2 -0
- package/dist/http/types.js.map +1 -0
- package/dist/http/utils.d.ts +14 -0
- package/dist/http/utils.d.ts.map +1 -0
- package/dist/http/utils.js +37 -0
- package/dist/http/utils.js.map +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +2 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +47 -77
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -73
- package/dist/index.js.map +1 -1
- package/dist/pkce.js +4 -4
- package/dist/postgrest/index.d.ts +4 -0
- package/dist/postgrest/index.d.ts.map +1 -0
- package/dist/postgrest/index.js +4 -0
- package/dist/postgrest/index.js.map +1 -0
- package/dist/postgrest/query-builder.d.ts +224 -0
- package/dist/postgrest/query-builder.d.ts.map +1 -0
- package/dist/postgrest/query-builder.js +544 -0
- package/dist/postgrest/query-builder.js.map +1 -0
- package/dist/postgrest/rpc.d.ts +12 -0
- package/dist/postgrest/rpc.d.ts.map +1 -0
- package/dist/postgrest/rpc.js +42 -0
- package/dist/postgrest/rpc.js.map +1 -0
- package/dist/postgrest/types.d.ts +88 -0
- package/dist/postgrest/types.d.ts.map +1 -0
- package/dist/postgrest/types.js +2 -0
- package/dist/postgrest/types.js.map +1 -0
- package/dist/postgrest/utils.d.ts +23 -0
- package/dist/postgrest/utils.d.ts.map +1 -0
- package/dist/postgrest/utils.js +87 -0
- package/dist/postgrest/utils.js.map +1 -0
- package/dist/postgrest.d.ts +5 -1
- package/dist/postgrest.d.ts.map +1 -1
- package/dist/postgrest.js +17 -10
- package/dist/postgrest.js.map +1 -1
- package/dist/realtime/channel.d.ts +83 -0
- package/dist/realtime/channel.d.ts.map +1 -0
- package/dist/realtime/channel.js +240 -0
- package/dist/realtime/channel.js.map +1 -0
- package/dist/realtime/index.d.ts +94 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +455 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/types.d.ts +120 -0
- package/dist/realtime/types.d.ts.map +1 -0
- package/dist/realtime/types.js +2 -0
- package/dist/realtime/types.js.map +1 -0
- package/dist/realtime.d.ts +1 -0
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +26 -1
- package/dist/realtime.js.map +1 -1
- package/dist/runtime.d.ts +13 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +15 -0
- package/dist/runtime.js.map +1 -0
- package/dist/session.d.ts +2 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +11 -2
- package/dist/session.js.map +1 -1
- package/dist/storage/bucket.d.ts +166 -0
- package/dist/storage/bucket.d.ts.map +1 -0
- package/dist/storage/bucket.js +294 -0
- package/dist/storage/bucket.js.map +1 -0
- package/dist/storage/index.d.ts +45 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +55 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/types.d.ts +131 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/storage/utils.d.ts +27 -0
- package/dist/storage/utils.d.ts.map +1 -0
- package/dist/storage/utils.js +43 -0
- package/dist/storage/utils.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +3 -0
- package/dist/test.js.map +1 -0
- package/dist/types.d.ts +14 -249
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compat.d.ts +40 -0
- package/dist/utils/compat.d.ts.map +1 -0
- package/dist/utils/compat.js +100 -0
- package/dist/utils/compat.js.map +1 -0
- package/dist/utils/runtime.d.ts +13 -0
- package/dist/utils/runtime.d.ts.map +1 -0
- package/dist/utils/runtime.js +15 -0
- package/dist/utils/runtime.js.map +1 -0
- package/dist/utils/testing.d.ts +38 -0
- package/dist/utils/testing.d.ts.map +1 -0
- package/dist/utils/testing.js +50 -0
- package/dist/utils/testing.js.map +1 -0
- package/dist/utils/warn.d.ts +2 -0
- package/dist/utils/warn.d.ts.map +1 -0
- package/dist/utils/warn.js +23 -0
- package/dist/utils/warn.js.map +1 -0
- package/package.json +13 -11
- package/dist/devices.d.ts +0 -13
- package/dist/devices.d.ts.map +0 -1
- package/dist/devices.js +0 -13
- package/dist/devices.js.map +0 -1
- package/dist/profile.d.ts +0 -16
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -26
- package/dist/profile.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Query / SWR glue: cache keys and fetchers for Motherbase queries.
|
|
3
|
+
*
|
|
4
|
+
* Every app that reaches for a data-fetching library writes the same two
|
|
5
|
+
* things, badly: a key convention, and a fetcher that remembers to throw on
|
|
6
|
+
* `{ error }` instead of caching it as data. The second one is the bug. A
|
|
7
|
+
* fetcher that returns `{ data: null, error }` resolves successfully as far as
|
|
8
|
+
* React Query is concerned, so the error is cached, `isError` stays false, and
|
|
9
|
+
* the UI renders an empty list forever.
|
|
10
|
+
*
|
|
11
|
+
* No dependency on React Query here, and none needed: the returned objects are
|
|
12
|
+
* plain `{ queryKey, queryFn }`, which is what `useQuery` takes. The same
|
|
13
|
+
* objects work with SWR by passing `queryKey` as the key and `queryFn` as the
|
|
14
|
+
* fetcher.
|
|
15
|
+
*/
|
|
16
|
+
import type { MotherbaseClient } from '../index.js';
|
|
17
|
+
import type { TypedQuery } from './types.js';
|
|
18
|
+
import type { PostgrestResponse } from '../postgrest/index.js';
|
|
19
|
+
/**
|
|
20
|
+
* The builder handed to a `build` callback: the same object `client.from()`
|
|
21
|
+
* returns, narrowed to the row type the helper was called with. Typed rather
|
|
22
|
+
* than `any`, so `.eq('athor', …)` is a compile error inside the callback and
|
|
23
|
+
* the editor completes the column names.
|
|
24
|
+
*/
|
|
25
|
+
export type QueryBuilderFor<Row extends object> = TypedQuery<Row, Partial<Row>, Partial<Row>>;
|
|
26
|
+
/**
|
|
27
|
+
* Any client, whatever `Database` it was created with.
|
|
28
|
+
*
|
|
29
|
+
* ponytail: the generic arguments are erased here because `from()`'s relation
|
|
30
|
+
* names are literal types that differ per `Database`, so no single parameter
|
|
31
|
+
* type accepts them all. The erasure stops at this boundary: everything the
|
|
32
|
+
* helpers hand back to the caller is typed through `Row`.
|
|
33
|
+
*/
|
|
34
|
+
type AnyClient = MotherbaseClient<any, any, any>;
|
|
35
|
+
/**
|
|
36
|
+
* Cache keys, hierarchical so invalidation can be coarse.
|
|
37
|
+
*
|
|
38
|
+
* `['motherbase', 'table', 'posts']` is a prefix of every key below it, so
|
|
39
|
+
* `invalidateQueries({ queryKey: keys.table('posts') })` reaches every list and
|
|
40
|
+
* every row of that table, which is what you want after a write. Anything
|
|
41
|
+
* narrower leaves a stale list on screen next to a fresh row.
|
|
42
|
+
*/
|
|
43
|
+
export declare const keys: {
|
|
44
|
+
all: readonly ["motherbase"];
|
|
45
|
+
table: (table: string) => readonly ["motherbase", "table", string];
|
|
46
|
+
list: (table: string, filters?: unknown) => readonly ["motherbase", "table", string, "list"] | readonly ["motherbase", "table", string, "list", {} | null];
|
|
47
|
+
row: (table: string, id: unknown) => readonly ["motherbase", "table", string, "row", unknown];
|
|
48
|
+
};
|
|
49
|
+
export interface QueryOptions<T> {
|
|
50
|
+
queryKey: readonly unknown[];
|
|
51
|
+
queryFn: () => Promise<T>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A list query.
|
|
55
|
+
*
|
|
56
|
+
* `build` receives the query builder so filters, ordering and column selection
|
|
57
|
+
* stay in the caller's hands; whatever it returns is awaited and unwrapped.
|
|
58
|
+
* Pass `filters` to make the key unique per filter set, or two different
|
|
59
|
+
* filtered lists of the same table will share one cache entry and overwrite
|
|
60
|
+
* each other.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* useQuery(listQuery(client, 'posts', {
|
|
64
|
+
* filters: { author },
|
|
65
|
+
* build: q => q.select('*').eq('author', author).order('created_at'),
|
|
66
|
+
* }))
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function listQuery<Row extends object = Record<string, unknown>>(client: AnyClient, table: string, options?: {
|
|
70
|
+
filters?: unknown;
|
|
71
|
+
build?: (query: QueryBuilderFor<Row>) => PromiseLike<PostgrestResponse<Row[]>>;
|
|
72
|
+
}): QueryOptions<Row[]>;
|
|
73
|
+
/**
|
|
74
|
+
* One row by primary key (or by any unique column, through `column`).
|
|
75
|
+
*
|
|
76
|
+
* Resolves `null` rather than throwing when the row is not there: "not found"
|
|
77
|
+
* is an answer, and a cache library that receives it as an error retries it.
|
|
78
|
+
*/
|
|
79
|
+
export declare function rowQuery<Row extends object = Record<string, unknown>>(client: AnyClient, table: string, id: unknown, options?: {
|
|
80
|
+
column?: keyof Row & string;
|
|
81
|
+
columns?: string;
|
|
82
|
+
}): QueryOptions<Row | null>;
|
|
83
|
+
/**
|
|
84
|
+
* Every row, walked through `stream()` rather than capped at the server's
|
|
85
|
+
* `api.rest.maxRows`.
|
|
86
|
+
*
|
|
87
|
+
* Separate from `listQuery` on purpose: this issues one request per page, so it
|
|
88
|
+
* belongs to lists that are known to be small enough to hold in memory and
|
|
89
|
+
* large enough to exceed the cap. Anything unbounded wants real pagination.
|
|
90
|
+
*/
|
|
91
|
+
export declare function allRowsQuery<Row extends object = Record<string, unknown>>(client: AnyClient, table: string, options?: {
|
|
92
|
+
filters?: unknown;
|
|
93
|
+
pageSize?: number;
|
|
94
|
+
build?: (query: QueryBuilderFor<Row>) => QueryBuilderFor<Row>;
|
|
95
|
+
}): QueryOptions<Row[]>;
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/database/query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CAAC,GAAG,SAAS,MAAM,IAAI,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9F;;;;;;;GAOG;AACH,KAAK,SAAS,GAAG,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAOjD;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI;;mBAEA,MAAM;kBACP,MAAM,YAAY,OAAO;iBAI1B,MAAM,MAAM,OAAO;CACjC,CAAC;AASF,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpE,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;CAC3E,GACL,YAAY,CAAC,GAAG,EAAE,CAAC,CASrB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnE,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,OAAO,EACX,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9D,YAAY,CAAC,GAAG,GAAG,IAAI,CAAC,CAc1B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvE,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,eAAe,CAAC,GAAG,CAAC,CAAC;CAC1D,GACL,YAAY,CAAC,GAAG,EAAE,CAAC,CAYrB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** `from()` on an erased client, re-typed to the row the caller asked for. */
|
|
2
|
+
function queryFor(client, table) {
|
|
3
|
+
return client.from(table);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Cache keys, hierarchical so invalidation can be coarse.
|
|
7
|
+
*
|
|
8
|
+
* `['motherbase', 'table', 'posts']` is a prefix of every key below it, so
|
|
9
|
+
* `invalidateQueries({ queryKey: keys.table('posts') })` reaches every list and
|
|
10
|
+
* every row of that table, which is what you want after a write. Anything
|
|
11
|
+
* narrower leaves a stale list on screen next to a fresh row.
|
|
12
|
+
*/
|
|
13
|
+
export const keys = {
|
|
14
|
+
all: ['motherbase'],
|
|
15
|
+
table: (table) => ['motherbase', 'table', table],
|
|
16
|
+
list: (table, filters) => (filters === undefined
|
|
17
|
+
? ['motherbase', 'table', table, 'list']
|
|
18
|
+
: ['motherbase', 'table', table, 'list', filters]),
|
|
19
|
+
row: (table, id) => ['motherbase', 'table', table, 'row', id],
|
|
20
|
+
};
|
|
21
|
+
/** Unwrap a `{ data, error }` result the way a cache library needs: throw on error. */
|
|
22
|
+
async function unwrap(result) {
|
|
23
|
+
const { data, error } = await result;
|
|
24
|
+
if (error)
|
|
25
|
+
throw Object.assign(new Error(error.message), error);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A list query.
|
|
30
|
+
*
|
|
31
|
+
* `build` receives the query builder so filters, ordering and column selection
|
|
32
|
+
* stay in the caller's hands; whatever it returns is awaited and unwrapped.
|
|
33
|
+
* Pass `filters` to make the key unique per filter set, or two different
|
|
34
|
+
* filtered lists of the same table will share one cache entry and overwrite
|
|
35
|
+
* each other.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* useQuery(listQuery(client, 'posts', {
|
|
39
|
+
* filters: { author },
|
|
40
|
+
* build: q => q.select('*').eq('author', author).order('created_at'),
|
|
41
|
+
* }))
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function listQuery(client, table, options = {}) {
|
|
45
|
+
const { filters, build } = options;
|
|
46
|
+
return {
|
|
47
|
+
queryKey: keys.list(table, filters),
|
|
48
|
+
queryFn: () => {
|
|
49
|
+
const base = queryFor(client, table);
|
|
50
|
+
return unwrap(build ? build(base) : base.select('*'));
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One row by primary key (or by any unique column, through `column`).
|
|
56
|
+
*
|
|
57
|
+
* Resolves `null` rather than throwing when the row is not there: "not found"
|
|
58
|
+
* is an answer, and a cache library that receives it as an error retries it.
|
|
59
|
+
*/
|
|
60
|
+
export function rowQuery(client, table, id, options = {}) {
|
|
61
|
+
const { column = 'id', columns = '*' } = options;
|
|
62
|
+
return {
|
|
63
|
+
queryKey: keys.row(table, id),
|
|
64
|
+
queryFn: () => unwrap(queryFor(client, table)
|
|
65
|
+
// `columns` is a runtime string, so it cannot be checked against the
|
|
66
|
+
// row the way a literal passed to `.select()` is.
|
|
67
|
+
.select(columns)
|
|
68
|
+
.eq(column, id)
|
|
69
|
+
.maybeSingle()),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Every row, walked through `stream()` rather than capped at the server's
|
|
74
|
+
* `api.rest.maxRows`.
|
|
75
|
+
*
|
|
76
|
+
* Separate from `listQuery` on purpose: this issues one request per page, so it
|
|
77
|
+
* belongs to lists that are known to be small enough to hold in memory and
|
|
78
|
+
* large enough to exceed the cap. Anything unbounded wants real pagination.
|
|
79
|
+
*/
|
|
80
|
+
export function allRowsQuery(client, table, options = {}) {
|
|
81
|
+
const { filters, pageSize, build } = options;
|
|
82
|
+
return {
|
|
83
|
+
queryKey: [...keys.list(table, filters), 'all'],
|
|
84
|
+
queryFn: async () => {
|
|
85
|
+
const base = queryFor(client, table);
|
|
86
|
+
const query = build ? build(base) : base.select('*');
|
|
87
|
+
const rows = [];
|
|
88
|
+
for await (const row of query.stream({ pageSize }))
|
|
89
|
+
rows.push(row);
|
|
90
|
+
return rows;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=query.js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AAK,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAA0B,CAAC;YAC/E,MAAM,IAAI,GAAU,EAAE,CAAC;YACvB,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,GAAU,CAAC,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level plumbing for `createClient<Database>(url, key)`.
|
|
3
|
+
*
|
|
4
|
+
* `Database` is the type generated by `motherbase gen types typescript`, which
|
|
5
|
+
* emits the exact shape supabase-js emits. Everything here reads that shape and
|
|
6
|
+
* nothing else, so a `database.types.ts` produced by Supabase's own generator
|
|
7
|
+
* works unchanged.
|
|
8
|
+
*
|
|
9
|
+
* This file is types only: it contains no runtime code. The query builder it
|
|
10
|
+
* describes is the existing `PostgrestQueryBuilder`; `MotherbaseClient.from()`
|
|
11
|
+
* hands back the same object viewed through this narrower interface.
|
|
12
|
+
*/
|
|
13
|
+
import type { ExplainOptions, InsertOptions, MutateOptions, OrderOptions, PaginateOptions, PostgrestArrayOperand, PostgrestExplainBuilder, PostgrestFilterOperator, PostgrestIsValue, PostgrestResponse, PostgrestTextBuilder, ReferencedTableOption, RpcOptions, SelectOptions, TextSearchType, UpsertOptions } from '../postgrest/index.js';
|
|
14
|
+
export interface GenericTable {
|
|
15
|
+
Row: Record<string, unknown>;
|
|
16
|
+
Insert: Record<string, unknown>;
|
|
17
|
+
Update: Record<string, unknown>;
|
|
18
|
+
Relationships?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface GenericView {
|
|
21
|
+
Row: Record<string, unknown>;
|
|
22
|
+
Relationships?: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface GenericFunction {
|
|
25
|
+
Args: Record<string, unknown>;
|
|
26
|
+
Returns: unknown;
|
|
27
|
+
}
|
|
28
|
+
export interface GenericSchema {
|
|
29
|
+
Tables: Record<string, GenericTable>;
|
|
30
|
+
Views: Record<string, GenericView>;
|
|
31
|
+
Functions: Record<string, GenericFunction>;
|
|
32
|
+
Enums?: Record<string, unknown>;
|
|
33
|
+
CompositeTypes?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The default when no `Database` is supplied. Every relation name is accepted
|
|
37
|
+
* and every row is `Record<string, unknown>`, which is exactly how the SDK
|
|
38
|
+
* behaved before generics existed. Passing a generated `Database` is opt-in.
|
|
39
|
+
*/
|
|
40
|
+
export type GenericDatabase = Record<string, GenericSchema>;
|
|
41
|
+
/**
|
|
42
|
+
* The schema a client reads by default. `public` when the database has one,
|
|
43
|
+
* otherwise whatever single schema was generated: `motherbase gen types
|
|
44
|
+
* typescript --schema shop` emits only `shop`, and requiring every call site to
|
|
45
|
+
* pass the name again would be pure friction.
|
|
46
|
+
*/
|
|
47
|
+
export type DefaultSchemaName<Database> = 'public' extends keyof Database ? 'public' : keyof Database;
|
|
48
|
+
export type SchemaOf<Database, Name> = Name extends keyof Database ? Database[Name] extends GenericSchema ? Database[Name] : GenericSchema : GenericSchema;
|
|
49
|
+
/** Tables and views together: both are selectable through `.from()`. */
|
|
50
|
+
export type Relations<Schema extends GenericSchema> = Schema['Tables'] & Schema['Views'];
|
|
51
|
+
export type RelationName<Schema extends GenericSchema> = string & keyof Relations<Schema>;
|
|
52
|
+
export type RowOf<Schema extends GenericSchema, Name extends RelationName<Schema>> = Relations<Schema>[Name] extends {
|
|
53
|
+
Row: infer R;
|
|
54
|
+
} ? R : never;
|
|
55
|
+
export type InsertOf<Schema extends GenericSchema, Name extends RelationName<Schema>> = Name extends keyof Schema['Tables'] ? Schema['Tables'][Name] extends {
|
|
56
|
+
Insert: infer I;
|
|
57
|
+
} ? I : never : never;
|
|
58
|
+
export type UpdateOf<Schema extends GenericSchema, Name extends RelationName<Schema>> = Name extends keyof Schema['Tables'] ? Schema['Tables'][Name] extends {
|
|
59
|
+
Update: infer U;
|
|
60
|
+
} ? U : never : never;
|
|
61
|
+
export type FunctionName<Schema extends GenericSchema> = string & keyof Schema['Functions'];
|
|
62
|
+
export type FunctionArgs<Schema extends GenericSchema, Name extends FunctionName<Schema>> = Schema['Functions'][Name] extends {
|
|
63
|
+
Args: infer A;
|
|
64
|
+
} ? A : never;
|
|
65
|
+
export type FunctionReturns<Schema extends GenericSchema, Name extends FunctionName<Schema>> = Schema['Functions'][Name] extends {
|
|
66
|
+
Returns: infer R;
|
|
67
|
+
} ? R : never;
|
|
68
|
+
type Trim<S extends string> = S extends ` ${infer Rest}` ? Trim<Rest> : S extends `${infer Rest} ` ? Trim<Rest> : S;
|
|
69
|
+
/** `'id, name'` -> `'id' | 'name'`. */
|
|
70
|
+
type SplitColumns<S extends string> = S extends `${infer Head},${infer Tail}` ? Trim<Head> | SplitColumns<Tail> : Trim<S>;
|
|
71
|
+
/** `'created_at::text'` -> `'created_at'`. Casts change the wire type, not the source column. */
|
|
72
|
+
type StripCast<S extends string> = S extends `${infer Column}::${string}` ? Column : S;
|
|
73
|
+
type AliasPart<S extends string> = S extends `${infer Alias}:${string}` ? Alias : S;
|
|
74
|
+
type ColumnPart<S extends string> = S extends `${string}:${infer Column}` ? Column : S;
|
|
75
|
+
/** `'writer:author_id'` -> `'writer'` (the key the row will carry). */
|
|
76
|
+
type OutputName<S extends string> = AliasPart<StripCast<S>>;
|
|
77
|
+
/** `'writer:author_id'` -> `'author_id'` (the column the type comes from). */
|
|
78
|
+
type SourceName<S extends string> = ColumnPart<StripCast<S>>;
|
|
79
|
+
/**
|
|
80
|
+
* SEAM: relational embedding (`select=*,author(*)`) is not implemented on the
|
|
81
|
+
* server yet, so a select string containing a parenthesised relation is not
|
|
82
|
+
* narrowed. It resolves to the base row plus an open index signature, which
|
|
83
|
+
* types the columns we do know and leaves the embedded keys accessible without
|
|
84
|
+
* pretending we know their shape.
|
|
85
|
+
*
|
|
86
|
+
* When embedding lands, replace this with a resolver that walks
|
|
87
|
+
* `Relationships` to decide object vs array and recurse into the target row.
|
|
88
|
+
*/
|
|
89
|
+
export type EmbeddedSelectSeam<Row> = Row & Record<string, unknown>;
|
|
90
|
+
type IsEmbeddedSelect<S extends string> = S extends `${string}(${string}` ? true : false;
|
|
91
|
+
/** Columns named in the select string that the relation does not have. */
|
|
92
|
+
export type UnknownSelectColumns<Row, S extends string> = Exclude<SourceName<SplitColumns<S>>, (keyof Row & string) | '*'>;
|
|
93
|
+
/**
|
|
94
|
+
* The `columns` argument type. Resolves to `unknown` (no extra constraint) when
|
|
95
|
+
* every named column exists, and to an error-message string literal otherwise,
|
|
96
|
+
* so a typo fails at the call site with the offending name in the message.
|
|
97
|
+
*/
|
|
98
|
+
export type ValidateSelect<Row, S extends string> = IsEmbeddedSelect<S> extends true ? unknown : [UnknownSelectColumns<Row, S>] extends [never] ? unknown : `Unknown column in select: ${UnknownSelectColumns<Row, S> & string}`;
|
|
99
|
+
/** The row shape a select resolves to. */
|
|
100
|
+
export type SelectResult<Row, S extends string> = IsEmbeddedSelect<S> extends true ? EmbeddedSelectSeam<Row> : '*' extends SplitColumns<S> ? Row : {
|
|
101
|
+
[K in SplitColumns<S> as OutputName<K>]: Row[SourceName<K> & keyof Row];
|
|
102
|
+
};
|
|
103
|
+
export type FilterValue = string | number | boolean | null;
|
|
104
|
+
/** A write without `.select()` stays `null` through re-typing and `.single()`. */
|
|
105
|
+
type RowsUnlessWrite<Data, Rows> = Data extends null ? null : Rows;
|
|
106
|
+
/** Columns that can be filtered or ordered on. Any string when untyped. */
|
|
107
|
+
export type ColumnName<Row> = keyof Row & string;
|
|
108
|
+
/**
|
|
109
|
+
* The `.from()` result. Structurally the existing `PostgrestQueryBuilder`, with
|
|
110
|
+
* the generated row/insert/update types threaded through. `Result` tracks what
|
|
111
|
+
* the current `select` narrowed the row to; it starts as the full row.
|
|
112
|
+
*
|
|
113
|
+
* `Data` is what awaiting resolves to. A write is sent with `return=minimal`
|
|
114
|
+
* and resolves `data: null` until `.select()` asks for the rows back, as in
|
|
115
|
+
* supabase-js; typing it as rows let `data.id` after a bare `insert()` compile
|
|
116
|
+
* and fail at runtime.
|
|
117
|
+
*/
|
|
118
|
+
export interface TypedQuery<Row, Insert, Update, Result = Row, Data = Result[]> extends PromiseLike<PostgrestResponse<Data>> {
|
|
119
|
+
/**
|
|
120
|
+
* Choose the columns to read, as a PostgREST select string. The result type
|
|
121
|
+
* narrows to those columns. After a write (`insert`, `update`, ...), asks for
|
|
122
|
+
* the written rows back: without it a write resolves `data: null`.
|
|
123
|
+
*
|
|
124
|
+
* @param columns Comma-separated columns, `*` for all. Supports aliases
|
|
125
|
+
* (`label:name`) and embedded relations (`author(name)`).
|
|
126
|
+
* @param options `count: 'exact' | 'planned' | 'estimated'` puts a total in
|
|
127
|
+
* `count`; `head: true` returns only that count, without rows.
|
|
128
|
+
* @example client.from('posts').select('id, title, author(name)')
|
|
129
|
+
*/
|
|
130
|
+
select<S extends string = '*'>(columns?: S & ValidateSelect<Row, S>, options?: SelectOptions): TypedQuery<Row, Insert, Update, SelectResult<Row, S>>;
|
|
131
|
+
/**
|
|
132
|
+
* Insert one row or several. Resolves `data: null` unless followed by
|
|
133
|
+
* `.select()`.
|
|
134
|
+
* @example client.from('posts').insert({ title }).select().single()
|
|
135
|
+
*/
|
|
136
|
+
insert(values: Insert | readonly Insert[], options?: InsertOptions): TypedQuery<Row, Insert, Update, Result, null>;
|
|
137
|
+
/**
|
|
138
|
+
* Insert, or update the row that already has the same primary key (or the
|
|
139
|
+
* same values in the `onConflict` columns). `ignoreDuplicates: true` skips
|
|
140
|
+
* that row instead of updating it.
|
|
141
|
+
*/
|
|
142
|
+
upsert(values: Insert | readonly Insert[], options?: UpsertOptions): TypedQuery<Row, Insert, Update, Result, null>;
|
|
143
|
+
/**
|
|
144
|
+
* Update the rows matched by the filters that follow. A filter is required:
|
|
145
|
+
* the server refuses an update of the whole table.
|
|
146
|
+
* @example client.from('posts').update({ title }).eq('id', id)
|
|
147
|
+
*/
|
|
148
|
+
update(values: Update, options?: MutateOptions): TypedQuery<Row, Insert, Update, Result, null>;
|
|
149
|
+
/**
|
|
150
|
+
* Delete the rows matched by the filters that follow. A filter is required:
|
|
151
|
+
* the server refuses a delete of the whole table.
|
|
152
|
+
* @example client.from('posts').delete().eq('id', id)
|
|
153
|
+
*/
|
|
154
|
+
delete(options?: MutateOptions): TypedQuery<Row, Insert, Update, Result, null>;
|
|
155
|
+
/** Rows where `column` equals `value`. Test NULL with `is(column, null)`. */
|
|
156
|
+
eq(column: ColumnName<Row>, value: FilterValue): this;
|
|
157
|
+
/** Rows where `column` differs from `value`. */
|
|
158
|
+
neq(column: ColumnName<Row>, value: FilterValue): this;
|
|
159
|
+
/** Rows where `column` is greater than `value`. */
|
|
160
|
+
gt(column: ColumnName<Row>, value: FilterValue): this;
|
|
161
|
+
/** Rows where `column` is greater than or equal to `value`. */
|
|
162
|
+
gte(column: ColumnName<Row>, value: FilterValue): this;
|
|
163
|
+
/** Rows where `column` is less than `value`. */
|
|
164
|
+
lt(column: ColumnName<Row>, value: FilterValue): this;
|
|
165
|
+
/** Rows where `column` is less than or equal to `value`. */
|
|
166
|
+
lte(column: ColumnName<Row>, value: FilterValue): this;
|
|
167
|
+
/** Case-sensitive pattern match. `%` (or `*`) matches any run of characters. */
|
|
168
|
+
like(column: ColumnName<Row>, pattern: string): this;
|
|
169
|
+
/** Case-insensitive pattern match. `%` (or `*`) matches any run of characters. */
|
|
170
|
+
ilike(column: ColumnName<Row>, pattern: string): this;
|
|
171
|
+
/** Rows where `column` matches every pattern (case-sensitive). */
|
|
172
|
+
likeAllOf(column: ColumnName<Row>, patterns: readonly string[]): this;
|
|
173
|
+
/** Rows where `column` matches at least one pattern (case-sensitive). */
|
|
174
|
+
likeAnyOf(column: ColumnName<Row>, patterns: readonly string[]): this;
|
|
175
|
+
/** Rows where `column` matches every pattern (case-insensitive). */
|
|
176
|
+
ilikeAllOf(column: ColumnName<Row>, patterns: readonly string[]): this;
|
|
177
|
+
/** Rows where `column` matches at least one pattern (case-insensitive). */
|
|
178
|
+
ilikeAnyOf(column: ColumnName<Row>, patterns: readonly string[]): this;
|
|
179
|
+
/** Rows where `column` is one of `values`. */
|
|
180
|
+
in(column: ColumnName<Row>, values: readonly FilterValue[]): this;
|
|
181
|
+
/** Rows where `column` IS `null`, `true`, `false` or `unknown`: the way to test NULL. */
|
|
182
|
+
is(column: ColumnName<Row>, value: PostgrestIsValue): this;
|
|
183
|
+
/** One `eq()` per key, ANDed: `match({ status: 'live', owner_id: id })`. */
|
|
184
|
+
match(query: Partial<Record<ColumnName<Row>, FilterValue>>): this;
|
|
185
|
+
/**
|
|
186
|
+
* Negate a filter: `not('status', 'eq', 'draft')`. The column is a free
|
|
187
|
+
* string, so json paths (`data->>k`) work.
|
|
188
|
+
*/
|
|
189
|
+
not(column: string, operator: PostgrestFilterOperator | (string & {}), value: FilterValue | readonly FilterValue[]): this;
|
|
190
|
+
/**
|
|
191
|
+
* Any PostgREST operator by name, for those without a dedicated method:
|
|
192
|
+
* `filter('price', 'isdistinct', null)`. The column is a free string, so json
|
|
193
|
+
* paths (`data->>k`) work.
|
|
194
|
+
*/
|
|
195
|
+
filter(column: string, operator: PostgrestFilterOperator | (string & {}), value: FilterValue | readonly FilterValue[]): this;
|
|
196
|
+
/**
|
|
197
|
+
* Rows matching at least one condition, in PostgREST syntax. Nests with
|
|
198
|
+
* `and(...)`: `or('status.eq.live,and(price.gt.10,stock.gt.0)')`.
|
|
199
|
+
*/
|
|
200
|
+
or(filters: string, options?: ReferencedTableOption): this;
|
|
201
|
+
/**
|
|
202
|
+
* Full-text search on a `tsvector` (or text) column.
|
|
203
|
+
* @param options `type`: `'plain'`, `'phrase'` or `'websearch'` (search-engine
|
|
204
|
+
* syntax); `config`: the text search language, e.g. `'english'`.
|
|
205
|
+
*/
|
|
206
|
+
textSearch(column: ColumnName<Row>, query: string, options?: {
|
|
207
|
+
type?: TextSearchType;
|
|
208
|
+
config?: string;
|
|
209
|
+
}): this;
|
|
210
|
+
/** Array, range or jsonb `column` contains every element of `value` (`@>`). */
|
|
211
|
+
contains(column: ColumnName<Row>, value: PostgrestArrayOperand): this;
|
|
212
|
+
/** Every element of array, range or jsonb `column` is in `value` (`<@`). */
|
|
213
|
+
containedBy(column: ColumnName<Row>, value: PostgrestArrayOperand): this;
|
|
214
|
+
/** Array or range `column` shares at least one element with `value` (`&&`). */
|
|
215
|
+
overlaps(column: ColumnName<Row>, value: PostgrestArrayOperand): this;
|
|
216
|
+
/** Range `column` is entirely after `range`. */
|
|
217
|
+
rangeGt(column: ColumnName<Row>, range: string): this;
|
|
218
|
+
/** Range `column` does not extend before `range`. */
|
|
219
|
+
rangeGte(column: ColumnName<Row>, range: string): this;
|
|
220
|
+
/** Range `column` is entirely before `range`. */
|
|
221
|
+
rangeLt(column: ColumnName<Row>, range: string): this;
|
|
222
|
+
/** Range `column` does not extend after `range`. */
|
|
223
|
+
rangeLte(column: ColumnName<Row>, range: string): this;
|
|
224
|
+
/** Range `column` touches `range` without overlapping it. */
|
|
225
|
+
rangeAdjacent(column: ColumnName<Row>, range: string): this;
|
|
226
|
+
/**
|
|
227
|
+
* Sort by `column`, ascending unless `ascending: false`. Call again for a
|
|
228
|
+
* secondary sort. `referencedTable` sorts the rows of an embedded relation.
|
|
229
|
+
*/
|
|
230
|
+
order(column: ColumnName<Row>, options?: OrderOptions): this;
|
|
231
|
+
/** Return at most `count` rows. */
|
|
232
|
+
limit(count: number, options?: ReferencedTableOption): this;
|
|
233
|
+
/**
|
|
234
|
+
* Return rows `from` to `to`, zero-based and both inclusive: `range(0, 9)` is
|
|
235
|
+
* the first 10. The way to paginate.
|
|
236
|
+
*/
|
|
237
|
+
range(from: number, to: number, options?: ReferencedTableOption): this;
|
|
238
|
+
/** Cancel the request when `signal` aborts. */
|
|
239
|
+
abortSignal(signal: AbortSignal): this;
|
|
240
|
+
/** Send one more header with this request only, e.g. `x-captcha-response`. */
|
|
241
|
+
setHeader(name: string, value: string): this;
|
|
242
|
+
/** Re-type the rows: for shapes the generated `Database` cannot express. */
|
|
243
|
+
returns<T>(): TypedQuery<Row, Insert, Update, T, RowsUnlessWrite<Data, T[]>>;
|
|
244
|
+
/** `returns<T>()` under supabase-js's newer name. */
|
|
245
|
+
overrideTypes<T>(): TypedQuery<Row, Insert, Update, T, RowsUnlessWrite<Data, T[]>>;
|
|
246
|
+
/** Reject instead of resolving `{ data: null, error }`, for try/catch code. */
|
|
247
|
+
throwOnError(): this;
|
|
248
|
+
/** Refuse the write if it would touch more than `count` rows: a net under a wrong filter. */
|
|
249
|
+
maxAffected(count: number): this;
|
|
250
|
+
/** Run the query, then roll the transaction back: a dry run of a write. */
|
|
251
|
+
rollback(): this;
|
|
252
|
+
/** Resolve the rows as one CSV string instead of objects. */
|
|
253
|
+
csv(): PostgrestTextBuilder;
|
|
254
|
+
/** Resolve the rows as a GeoJSON FeatureCollection, for PostGIS tables. */
|
|
255
|
+
geojson(): PostgrestExplainBuilder;
|
|
256
|
+
/** Resolve the Postgres query plan instead of the rows. Admin callers only. */
|
|
257
|
+
explain(options?: ExplainOptions): PostgrestExplainBuilder;
|
|
258
|
+
/**
|
|
259
|
+
* Walk every matching row instead of stopping at the server's row cap.
|
|
260
|
+
* Throws on error: a `for await` loop has nowhere to put an error value, and
|
|
261
|
+
* ending the iteration quietly looks exactly like reaching the last page.
|
|
262
|
+
* @example for await (const row of client.from('events').select('*').stream()) { ... }
|
|
263
|
+
*/
|
|
264
|
+
stream(options?: PaginateOptions): AsyncGenerator<Result, void, undefined>;
|
|
265
|
+
/**
|
|
266
|
+
* `stream()` a page at a time, with the total in `count` when the server
|
|
267
|
+
* reports one. Throws on error.
|
|
268
|
+
*/
|
|
269
|
+
paginate(options?: PaginateOptions): AsyncGenerator<{
|
|
270
|
+
rows: Result[];
|
|
271
|
+
from: number;
|
|
272
|
+
count: number | null;
|
|
273
|
+
}, void, undefined>;
|
|
274
|
+
/** Resolve one row instead of an array. Fails unless exactly one row matches. */
|
|
275
|
+
single(): TypedSingleQuery<RowsUnlessWrite<Data, Result>>;
|
|
276
|
+
/** Resolve one row, or `null` when none matches. Fails if several match. */
|
|
277
|
+
maybeSingle(): TypedSingleQuery<RowsUnlessWrite<Data, Result | null>>;
|
|
278
|
+
/** The URL path (with query string) this builder targets. Exposed for tests. */
|
|
279
|
+
toPath(): string;
|
|
280
|
+
/** The headers this builder sends (Prefer, Accept). Exposed for tests. */
|
|
281
|
+
toHeaders(): Record<string, string>;
|
|
282
|
+
}
|
|
283
|
+
/** A builder narrowed to one row by `.single()` / `.maybeSingle()`. */
|
|
284
|
+
export interface TypedSingleQuery<Result> extends PromiseLike<PostgrestResponse<Result>> {
|
|
285
|
+
toPath(): string;
|
|
286
|
+
toHeaders(): Record<string, string>;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* What the `client.transaction()` callback is handed.
|
|
290
|
+
*
|
|
291
|
+
* Typed loosely on purpose: the relation names come from the generated
|
|
292
|
+
* `Database` on `client.from()`, and reproducing that overload pair here for a
|
|
293
|
+
* callback that returns nothing buys inference no one reads at the cost of a
|
|
294
|
+
* signature nobody can follow.
|
|
295
|
+
*/
|
|
296
|
+
export interface TransactionContext {
|
|
297
|
+
from<Row extends object = Record<string, unknown>>(table: string): TypedQuery<Row, Partial<Row>, Partial<Row>>;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* What `client.schema(name)` returns for a schema other than `public`: its
|
|
301
|
+
* functions, called with the profile header PostgREST reads, so
|
|
302
|
+
* `client.schema('pgmq_public').rpc('send', { queue_name, message })` reaches
|
|
303
|
+
* Supabase Queues exactly as it does on Supabase.
|
|
304
|
+
*
|
|
305
|
+
* `from()` is here only to fail with the reason: the REST layer serves tables
|
|
306
|
+
* from `public` alone, and a ported call should say so rather than being
|
|
307
|
+
* "not a function".
|
|
308
|
+
*/
|
|
309
|
+
export interface SchemaClient<Schema extends GenericSchema = GenericSchema> {
|
|
310
|
+
rpc<Name extends FunctionName<Schema>>(fn: Name, args?: FunctionArgs<Schema, Name>, options?: RpcOptions): Promise<PostgrestResponse<FunctionReturns<Schema, Name>>>;
|
|
311
|
+
from(table: string): never;
|
|
312
|
+
}
|
|
313
|
+
export {};
|
|
314
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,UAAU,EACV,aAAa,EACb,cAAc,EACd,aAAa,EACd,MAAM,uBAAuB,CAAC;AAI/B,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACrC,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AM,IAAI,MAAM,CAAC;IACjB,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/C,KAAK,EAAE,MAAM,GACZ,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;CAChD;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa;IACxE,GAAG,CAAC,IAAI,SAAS,YAAY,CAAC,MAAM,CAAC,EACnC,EAAE,EAAE,IAAI,EACR,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,EACjC,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,iBAAiB,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error classes supabase-js throws from `functions.invoke`.
|
|
3
|
+
*
|
|
4
|
+
* Ported code branches on them (`if (error instanceof FunctionsHttpError)`), so
|
|
5
|
+
* they exist here and `invoke` puts the matching instance in `error`. It still
|
|
6
|
+
* resolves rather than throws: the `{ data, error }` envelope is the contract
|
|
7
|
+
* everywhere else in this SDK, and a method that sometimes throws and sometimes
|
|
8
|
+
* does not is worse than either.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FunctionsError extends Error {
|
|
11
|
+
readonly name_: string;
|
|
12
|
+
readonly context?: unknown | undefined;
|
|
13
|
+
constructor(message: string, name_?: string, context?: unknown | undefined);
|
|
14
|
+
}
|
|
15
|
+
/** The function ran and answered with a non-2xx status. */
|
|
16
|
+
export declare class FunctionsHttpError extends FunctionsError {
|
|
17
|
+
readonly status?: number;
|
|
18
|
+
constructor(message: string, status?: number, context?: unknown);
|
|
19
|
+
}
|
|
20
|
+
/** The function threw before producing a response. */
|
|
21
|
+
export declare class FunctionsRelayError extends FunctionsError {
|
|
22
|
+
constructor(message: string, context?: unknown);
|
|
23
|
+
}
|
|
24
|
+
/** The request never reached the function (network, abort, DNS). */
|
|
25
|
+
export declare class FunctionsFetchError extends FunctionsError {
|
|
26
|
+
constructor(message: string, context?: unknown);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/functions/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACR,QAAQ,CAAC,KAAK;IAAqB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO;gBAA9E,OAAO,EAAE,MAAM,EAAW,KAAK,SAAmB,EAAW,OAAO,CAAC,EAAE,OAAO,YAAA;CAI7F;AAED,2DAA2D;AAC3D,qBAAa,kBAAmB,SAAQ,cAAc;IAClD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAIlE;AAED,sDAAsD;AACtD,qBAAa,mBAAoB,SAAQ,cAAc;gBACvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAGjD;AAED,oEAAoE;AACpE,qBAAa,mBAAoB,SAAQ,cAAc;gBACvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAGjD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error classes supabase-js throws from `functions.invoke`.
|
|
3
|
+
*
|
|
4
|
+
* Ported code branches on them (`if (error instanceof FunctionsHttpError)`), so
|
|
5
|
+
* they exist here and `invoke` puts the matching instance in `error`. It still
|
|
6
|
+
* resolves rather than throws: the `{ data, error }` envelope is the contract
|
|
7
|
+
* everywhere else in this SDK, and a method that sometimes throws and sometimes
|
|
8
|
+
* does not is worse than either.
|
|
9
|
+
*/
|
|
10
|
+
export class FunctionsError extends Error {
|
|
11
|
+
constructor(message, name_ = 'FunctionsError', context) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name_ = name_;
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.name = name_;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** The function ran and answered with a non-2xx status. */
|
|
19
|
+
export class FunctionsHttpError extends FunctionsError {
|
|
20
|
+
constructor(message, status, context) {
|
|
21
|
+
super(message, 'FunctionsHttpError', context);
|
|
22
|
+
this.status = status;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** The function threw before producing a response. */
|
|
26
|
+
export class FunctionsRelayError extends FunctionsError {
|
|
27
|
+
constructor(message, context) {
|
|
28
|
+
super(message, 'FunctionsRelayError', context);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The request never reached the function (network, abort, DNS). */
|
|
32
|
+
export class FunctionsFetchError extends FunctionsError {
|
|
33
|
+
constructor(message, context) {
|
|
34
|
+
super(message, 'FunctionsFetchError', context);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/functions/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrC,YAAY,OAAe,EAAW,QAAQ,gBAAgB,EAAW,OAAiB;QACtF,KAAK,CAAC,OAAO,CAAC,CAAC;QADmB,UAAK,GAAL,KAAK,CAAmB;QAAW,YAAO,GAAP,OAAO,CAAU;QAEtF,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACtB,CAAC;CACJ;AAED,2DAA2D;AAC3D,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IAElD,YAAY,OAAe,EAAE,MAAe,EAAE,OAAiB;QAC3D,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAED,sDAAsD;AACtD,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACnD,YAAY,OAAe,EAAE,OAAiB;QAC1C,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACJ;AAED,oEAAoE;AACpE,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACnD,YAAY,OAAe,EAAE,OAAiB;QAC1C,KAAK,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;CACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HttpClient } from "../http/index.js";
|
|
2
|
+
import { FunctionInvokeOptions, MotherbaseResponse } from "../index.js";
|
|
3
|
+
/** Supabase-compatible edge functions client: `client.functions.invoke(name, { body })`. */
|
|
4
|
+
export declare class FunctionsClient {
|
|
5
|
+
private readonly http;
|
|
6
|
+
constructor(http: HttpClient);
|
|
7
|
+
invoke<Result = unknown, Body = Record<string, unknown>>(name: string, options?: FunctionInvokeOptions<Body>): Promise<MotherbaseResponse<Result>>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAgB,qBAAqB,EAA2C,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAI/H,4FAA4F;AAC5F,qBAAa,eAAe;IACZ,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAEvC,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAAqB,CAAC,IAAI,CAAM,GAC1C,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;CAgCzC"}
|