@motherbase/client 1.2.4 → 1.2.5
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 +95 -42
- package/dist/auth.d.ts +0 -5
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +0 -15
- package/dist/auth.js.map +1 -1
- package/dist/database.d.ts +169 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +2 -0
- package/dist/database.js.map +1 -0
- package/dist/http.d.ts +11 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +10 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +49 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -2
- package/dist/index.js.map +1 -1
- package/dist/postgrest.d.ts +207 -32
- package/dist/postgrest.d.ts.map +1 -1
- package/dist/postgrest.js +349 -54
- package/dist/postgrest.js.map +1 -1
- package/dist/storage.d.ts +20 -14
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +56 -18
- package/dist/storage.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,15 +4,30 @@ import { StorageClient } from './storage.js';
|
|
|
4
4
|
import { FunctionsClient } from './functions.js';
|
|
5
5
|
import { RealtimeModule } from './realtime.js';
|
|
6
6
|
import { RealtimeChannel, type RealtimeChannelOptions } from './channel.js';
|
|
7
|
-
import {
|
|
7
|
+
import type { PostgrestCount, PostgrestResponse } from './postgrest.js';
|
|
8
8
|
import type { ClientOptions } from './types.js';
|
|
9
|
+
/** Options for `client.rpc(fn, args, options)`, mirroring supabase-js. */
|
|
10
|
+
export interface RpcOptions {
|
|
11
|
+
/** Send the request as HEAD: no rows, only the count. */
|
|
12
|
+
head?: boolean;
|
|
13
|
+
/** Use the read-only GET form, with the arguments as query parameters. */
|
|
14
|
+
get?: boolean;
|
|
15
|
+
count?: PostgrestCount;
|
|
16
|
+
}
|
|
17
|
+
import type { DefaultSchemaName, FunctionArgs, FunctionName, FunctionReturns, GenericDatabase, GenericSchema, InsertOf, RelationName, RowOf, SchemaOf, TypedQuery, UpdateOf } from './database.js';
|
|
9
18
|
/**
|
|
10
19
|
* Supabase-js-compatible client for a Motherbase backend.
|
|
11
20
|
*
|
|
12
21
|
* Drop-in shaped: `client.from(table).select()…`, `client.auth.signInWithPassword()`,
|
|
13
22
|
* `client.storage.from(bucket)`, `client.channel(name)`, `client.functions.invoke()`.
|
|
23
|
+
*
|
|
24
|
+
* Pass the type generated by `motherbase gen types typescript` to get real
|
|
25
|
+
* inference: `createClient<Database>(url, key)` then types every row, rejects
|
|
26
|
+
* unknown columns in `.select()`, checks `.insert()` payloads against the
|
|
27
|
+
* Insert shape and types `.rpc()` from `Functions`. Without it the client
|
|
28
|
+
* behaves exactly as it did before generics existed.
|
|
14
29
|
*/
|
|
15
|
-
export declare class MotherbaseClient {
|
|
30
|
+
export declare class MotherbaseClient<Database = GenericDatabase, SchemaName = DefaultSchemaName<Database>, Schema extends GenericSchema = SchemaOf<Database, SchemaName>> {
|
|
16
31
|
private readonly url;
|
|
17
32
|
/** Accepted for supabase-js signature parity; sent as an `apikey` header when set. */
|
|
18
33
|
readonly key?: string | undefined;
|
|
@@ -27,8 +42,29 @@ export declare class MotherbaseClient {
|
|
|
27
42
|
constructor(url: string,
|
|
28
43
|
/** Accepted for supabase-js signature parity; sent as an `apikey` header when set. */
|
|
29
44
|
key?: string | undefined, options?: ClientOptions);
|
|
30
|
-
/**
|
|
31
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Start a PostgREST-style query against a table or view.
|
|
47
|
+
*
|
|
48
|
+
* The first overload is the typed path: with a generated `Database` the
|
|
49
|
+
* relation name is checked and the row/insert/update types come from it.
|
|
50
|
+
* The second keeps the pre-generics form (`from<MyRow>('t')`) working; its
|
|
51
|
+
* `never` default makes the parameter unusable unless `Row` is passed
|
|
52
|
+
* explicitly, so a bare `from('typo')` still has to satisfy the first
|
|
53
|
+
* overload rather than silently falling through to an unchecked one.
|
|
54
|
+
*/
|
|
55
|
+
from<Name extends RelationName<Schema>>(table: Name): TypedQuery<RowOf<Schema, Name>, InsertOf<Schema, Name>, UpdateOf<Schema, Name>>;
|
|
56
|
+
from<Row extends object = never>(table: [Row] extends [never] ? never : string): TypedQuery<Row, Partial<Row>, Partial<Row>>;
|
|
57
|
+
/**
|
|
58
|
+
* Call a database function, typed from the generated `Functions` map.
|
|
59
|
+
*
|
|
60
|
+
* The transport is `POST /rest/v1/rpc/<fn>`, which the REST layer gains in
|
|
61
|
+
* Phase 2.8. The typing is independent of that work: it reads only the
|
|
62
|
+
* generated `Database`, so it is correct the moment the route exists.
|
|
63
|
+
*
|
|
64
|
+
* `get` and `head` switch to the read-only forms, which carry their arguments
|
|
65
|
+
* as query parameters rather than as a body, exactly as supabase-js does.
|
|
66
|
+
*/
|
|
67
|
+
rpc<Name extends FunctionName<Schema>>(fn: Name, args?: FunctionArgs<Schema, Name>, options?: RpcOptions): Promise<PostgrestResponse<FunctionReturns<Schema, Name>>>;
|
|
32
68
|
/** Create (or reuse) a realtime channel. */
|
|
33
69
|
channel(name: string, opts?: RealtimeChannelOptions): RealtimeChannel;
|
|
34
70
|
/** Unsubscribe and drop a channel. */
|
|
@@ -44,13 +80,20 @@ export declare class MotherbaseClient {
|
|
|
44
80
|
* @param url Backend API base URL.
|
|
45
81
|
* @param key Anon/publishable key (optional). Sent as an `apikey` header.
|
|
46
82
|
* @param options Session storage, fetch override, extra headers.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import type { Database } from './database.types'
|
|
87
|
+
* const client = createClient<Database>(url, anonKey)
|
|
88
|
+
* ```
|
|
47
89
|
*/
|
|
48
|
-
export declare function createClient(url: string, key?: string, options?: ClientOptions): MotherbaseClient
|
|
90
|
+
export declare function createClient<Database = GenericDatabase, SchemaName = DefaultSchemaName<Database>, Schema extends GenericSchema = SchemaOf<Database, SchemaName>>(url: string, key?: string, options?: ClientOptions): MotherbaseClient<Database, SchemaName, Schema>;
|
|
49
91
|
export { BackendError } from './http.js';
|
|
50
92
|
export { memoryStorage, localStorageStorage };
|
|
51
93
|
export { cookieStorage, serverCookieStorage } from './cookie.js';
|
|
52
94
|
export { PostgrestQueryBuilder } from './postgrest.js';
|
|
53
|
-
export type { PostgrestSingleBuilder } from './postgrest.js';
|
|
95
|
+
export type { PostgrestSingleBuilder, PostgrestTextBuilder, PostgrestExplainBuilder, PostgrestResponse, PostgrestPrimitive, PostgrestArrayOperand, PostgrestFilterOperator, PostgrestIsValue, PostgrestCount, TextSearchType, ReferencedTableOption, OrderOptions, SelectOptions, InsertOptions, UpsertOptions, MutateOptions, ExplainOptions, } from './postgrest.js';
|
|
96
|
+
export type { GenericDatabase, GenericSchema, GenericTable, GenericView, GenericFunction, DefaultSchemaName, SchemaOf, Relations, RelationName, RowOf, InsertOf, UpdateOf, FunctionName, FunctionArgs, FunctionReturns, TypedQuery, TypedSingleQuery, SelectResult, ValidateSelect, UnknownSelectColumns, EmbeddedSelectSeam, ColumnName, FilterValue, } from './database.js';
|
|
54
97
|
export { AuthClient } from './auth.js';
|
|
55
98
|
export type { SignUpCredentials, SignInWithPasswordCredentials, SignInWithOtpCredentials, VerifyOtpParams, SignInWithOAuthCredentials, UpdateUserAttributes, DeleteUserAttributes, Subscription, } from './auth.js';
|
|
56
99
|
export { StorageClient, StorageBucket } from './storage.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,aAAa,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,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AO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7E,YAAY,EACV,WAAW,EACX,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,sBAAsB,EACtB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,UAAU,GACX,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { HttpClient } from './http.js';
|
|
1
|
+
import { HttpClient, toError } from './http.js';
|
|
2
|
+
import { contractPath } from '@motherbase/contracts';
|
|
2
3
|
import { SessionStore, memoryStorage, localStorageStorage } from './session.js';
|
|
3
4
|
import { AuthClient } from './auth.js';
|
|
4
5
|
import { StorageClient } from './storage.js';
|
|
@@ -11,6 +12,12 @@ import { PostgrestQueryBuilder } from './postgrest.js';
|
|
|
11
12
|
*
|
|
12
13
|
* Drop-in shaped: `client.from(table).select()…`, `client.auth.signInWithPassword()`,
|
|
13
14
|
* `client.storage.from(bucket)`, `client.channel(name)`, `client.functions.invoke()`.
|
|
15
|
+
*
|
|
16
|
+
* Pass the type generated by `motherbase gen types typescript` to get real
|
|
17
|
+
* inference: `createClient<Database>(url, key)` then types every row, rejects
|
|
18
|
+
* unknown columns in `.select()`, checks `.insert()` payloads against the
|
|
19
|
+
* Insert shape and types `.rpc()` from `Functions`. Without it the client
|
|
20
|
+
* behaves exactly as it did before generics existed.
|
|
14
21
|
*/
|
|
15
22
|
export class MotherbaseClient {
|
|
16
23
|
constructor(url,
|
|
@@ -42,10 +49,47 @@ export class MotherbaseClient {
|
|
|
42
49
|
this.functions = new FunctionsClient(this.http);
|
|
43
50
|
this.realtime = new RealtimeModule(url, this.store, fetchImpl, options.realtimeIoFactory);
|
|
44
51
|
}
|
|
45
|
-
/** Start a PostgREST-style query against a table. */
|
|
46
52
|
from(table) {
|
|
47
53
|
return new PostgrestQueryBuilder(this.http, table);
|
|
48
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Call a database function, typed from the generated `Functions` map.
|
|
57
|
+
*
|
|
58
|
+
* The transport is `POST /rest/v1/rpc/<fn>`, which the REST layer gains in
|
|
59
|
+
* Phase 2.8. The typing is independent of that work: it reads only the
|
|
60
|
+
* generated `Database`, so it is correct the moment the route exists.
|
|
61
|
+
*
|
|
62
|
+
* `get` and `head` switch to the read-only forms, which carry their arguments
|
|
63
|
+
* as query parameters rather than as a body, exactly as supabase-js does.
|
|
64
|
+
*/
|
|
65
|
+
async rpc(fn, args, options = {}) {
|
|
66
|
+
try {
|
|
67
|
+
const method = options.head ? 'HEAD' : options.get ? 'GET' : 'POST';
|
|
68
|
+
const params = new URLSearchParams();
|
|
69
|
+
if (method !== 'POST') {
|
|
70
|
+
for (const [name, value] of Object.entries((args ?? {}))) {
|
|
71
|
+
if (value === undefined)
|
|
72
|
+
continue;
|
|
73
|
+
params.append(name, Array.isArray(value) ? `{${value.join(',')}}` : String(value));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const query = params.toString();
|
|
77
|
+
const path = `${contractPath.rest('rpc')}/${encodeURIComponent(fn)}${query ? `?${query}` : ''}`;
|
|
78
|
+
const headers = options.count ? { Prefer: `count=${options.count}` } : undefined;
|
|
79
|
+
const result = await this.http.requestWithHeaders(path, {
|
|
80
|
+
method,
|
|
81
|
+
body: method === 'POST' ? (args ?? {}) : undefined,
|
|
82
|
+
headers,
|
|
83
|
+
});
|
|
84
|
+
const range = result.headers.get('content-range');
|
|
85
|
+
const total = range?.split('/')[1];
|
|
86
|
+
const count = total && total !== '*' && Number.isFinite(Number(total)) ? Number(total) : null;
|
|
87
|
+
return { data: options.head ? null : result.data, error: null, count };
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
return { data: null, error: toError(err), count: null };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
49
93
|
/** Create (or reuse) a realtime channel. */
|
|
50
94
|
channel(name, opts = {}) {
|
|
51
95
|
const existing = this.channels.get(name);
|
|
@@ -78,6 +122,12 @@ export class MotherbaseClient {
|
|
|
78
122
|
* @param url Backend API base URL.
|
|
79
123
|
* @param key Anon/publishable key (optional). Sent as an `apikey` header.
|
|
80
124
|
* @param options Session storage, fetch override, extra headers.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import type { Database } from './database.types'
|
|
129
|
+
* const client = createClient<Database>(url, anonKey)
|
|
130
|
+
* ```
|
|
81
131
|
*/
|
|
82
132
|
export function createClient(url, key, options = {}) {
|
|
83
133
|
return new MotherbaseClient(url, key, options);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","s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C,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6EAA6E;IAC7E,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAI1B,GAAW,EAAE,GAAY,EAAE,UAAyB,EAAE;IACtD,OAAO,IAAI,gBAAgB,CAA+B,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AAC/E,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AA6CvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAWvC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/postgrest.d.ts
CHANGED
|
@@ -1,58 +1,233 @@
|
|
|
1
1
|
import { HttpClient } from './http.js';
|
|
2
2
|
import type { MotherbaseResponse } from './types.js';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* PostgREST query builder, supabase-js shaped.
|
|
5
|
+
*
|
|
6
|
+
* Everything in this file is about ONE thing: emitting the query string
|
|
7
|
+
* PostgREST (and the Motherbase REST dialect that mirrors it) reads. The
|
|
8
|
+
* builder is awaitable, resolves `{ data, error, count }` and never rejects for
|
|
9
|
+
* an expected API error. It has no runtime dependencies.
|
|
10
|
+
*
|
|
11
|
+
* Value encoding is the part that is easy to get wrong, so it lives in one
|
|
12
|
+
* place (`encodeLiteral` / `encodeArrayLiteral`) and every method routes
|
|
13
|
+
* through it:
|
|
14
|
+
*
|
|
15
|
+
* - A string value containing `,` `.` `:` `(` `)` `{` `}` `"` `\` or
|
|
16
|
+
* whitespace, or the empty string, is double quoted, with inner `"` and `\`
|
|
17
|
+
* backslash escaped. That is what makes `in.("a,b",c)` a two element list
|
|
18
|
+
* instead of three, and it is why a value containing a double quote is
|
|
19
|
+
* expressible at all.
|
|
20
|
+
* - Numbers and booleans are never quoted: their string form cannot contain a
|
|
21
|
+
* reserved character, and quoting them would make every `eq.3.14` read as a
|
|
22
|
+
* quoted literal for no gain.
|
|
23
|
+
* - `not()` and `filter()` take their value verbatim when it is a string.
|
|
24
|
+
* They are the escape hatches, so `not('id', 'in', '(1,2)')` has to reach
|
|
25
|
+
* the server as written, exactly as in supabase-js.
|
|
26
|
+
*/
|
|
27
|
+
export type PostgrestPrimitive = string | number | boolean | null;
|
|
28
|
+
/** Value accepted by the array/range operators (`cs`, `cd`, `ov`). */
|
|
29
|
+
export type PostgrestArrayOperand = string | readonly PostgrestPrimitive[] | Record<string, unknown>;
|
|
30
|
+
/** PostgREST's operator names. `filter()` also accepts modifier forms like `like(any)`. */
|
|
31
|
+
export type PostgrestFilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'match' | 'imatch' | 'in' | 'is' | 'isdistinct' | 'fts' | 'plfts' | 'phfts' | 'wfts' | 'cs' | 'cd' | 'ov' | 'sl' | 'sr' | 'nxr' | 'nxl' | 'adj';
|
|
32
|
+
/** `is` reaches SQL NULL and the three-valued booleans, and nothing else. */
|
|
33
|
+
export type PostgrestIsValue = null | boolean | 'null' | 'true' | 'false' | 'unknown';
|
|
34
|
+
export type PostgrestCount = 'exact' | 'planned' | 'estimated';
|
|
35
|
+
export type TextSearchType = 'plain' | 'phrase' | 'websearch';
|
|
36
|
+
export interface ReferencedTableOption {
|
|
37
|
+
/** Scope the modifier to an embedded resource: `comments.limit=5`. */
|
|
38
|
+
referencedTable?: string;
|
|
39
|
+
/** supabase-js's pre-2.x name for `referencedTable`. Accepted for parity. */
|
|
40
|
+
foreignTable?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface OrderOptions extends ReferencedTableOption {
|
|
43
|
+
ascending?: boolean;
|
|
44
|
+
nullsFirst?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface SelectOptions {
|
|
47
|
+
count?: PostgrestCount;
|
|
48
|
+
/** Send the request as HEAD: no rows come back, only the count. */
|
|
49
|
+
head?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface InsertOptions {
|
|
52
|
+
count?: PostgrestCount;
|
|
53
|
+
/**
|
|
54
|
+
* `false` sends `Prefer: missing=default`, so columns absent from a row take
|
|
55
|
+
* their column default instead of NULL.
|
|
56
|
+
*/
|
|
57
|
+
defaultToNull?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface UpsertOptions extends InsertOptions {
|
|
60
|
+
/** Conflict target, defaulting server side to the primary key. */
|
|
61
|
+
onConflict?: string;
|
|
62
|
+
/** `true` sends `Prefer: resolution=ignore-duplicates`. */
|
|
63
|
+
ignoreDuplicates?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface MutateOptions {
|
|
66
|
+
count?: PostgrestCount;
|
|
67
|
+
}
|
|
68
|
+
export interface ExplainOptions {
|
|
69
|
+
analyze?: boolean;
|
|
70
|
+
verbose?: boolean;
|
|
71
|
+
settings?: boolean;
|
|
72
|
+
buffers?: boolean;
|
|
73
|
+
wal?: boolean;
|
|
74
|
+
format?: 'text' | 'json';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The result a query resolves to. `count` is `null` unless `{ count }` was
|
|
78
|
+
* requested and the server answered with a `Content-Range` total.
|
|
79
|
+
*/
|
|
80
|
+
export interface PostgrestResponse<T> extends MotherbaseResponse<T> {
|
|
81
|
+
count: number | null;
|
|
82
|
+
}
|
|
83
|
+
/** One scalar value: quoted only when it has to be. */
|
|
84
|
+
export declare function encodeLiteral(value: PostgrestPrimitive): string;
|
|
4
85
|
/**
|
|
5
86
|
* PostgREST-style, chainable, thenable query builder mapping onto the backend's
|
|
6
|
-
* `/rest/v1/:model` query-param dialect. Awaiting it resolves to
|
|
7
|
-
* and never rejects for expected API errors (only for
|
|
87
|
+
* `/rest/v1/:model` query-param dialect. Awaiting it resolves to
|
|
88
|
+
* `{ data, error, count }` and never rejects for expected API errors (only for
|
|
89
|
+
* programmer misuse).
|
|
8
90
|
*/
|
|
9
|
-
export declare class PostgrestQueryBuilder<Row extends object = Record<string, unknown>> implements PromiseLike<
|
|
91
|
+
export declare class PostgrestQueryBuilder<Row extends object = Record<string, unknown>> implements PromiseLike<PostgrestResponse<Row[]>> {
|
|
10
92
|
private readonly http;
|
|
11
93
|
private readonly model;
|
|
12
94
|
private method;
|
|
13
95
|
private columns;
|
|
96
|
+
/**
|
|
97
|
+
* Repeated filters on one column must all survive: `?price=gt.10&price=lt.20`
|
|
98
|
+
* is two conditions ANDed together, which is why every filter is `append`ed
|
|
99
|
+
* and never `set`. Using `set` here (as this builder once did) silently
|
|
100
|
+
* dropped the first of the two.
|
|
101
|
+
*/
|
|
14
102
|
private readonly filters;
|
|
103
|
+
/** Reserved params that are replaced rather than repeated (`columns`, `on_conflict`). */
|
|
104
|
+
private readonly extras;
|
|
105
|
+
/** Keyed by referenced table (`''` for the base relation). */
|
|
15
106
|
private readonly orderParts;
|
|
16
|
-
private
|
|
17
|
-
private
|
|
107
|
+
private readonly limits;
|
|
108
|
+
private readonly offsets;
|
|
109
|
+
private readonly prefer;
|
|
110
|
+
private accept?;
|
|
111
|
+
private responseKind;
|
|
112
|
+
private countOption?;
|
|
113
|
+
private headOnly;
|
|
114
|
+
private signal?;
|
|
18
115
|
private body?;
|
|
19
116
|
private rowMode;
|
|
20
117
|
constructor(http: HttpClient, model: string);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Choose the columns, and optionally ask for a row count.
|
|
120
|
+
*
|
|
121
|
+
* After a write, `.select()` is the supabase-js way of asking for the rows
|
|
122
|
+
* back, so it also sends `Prefer: return=representation`.
|
|
123
|
+
*/
|
|
124
|
+
select(columns?: string, options?: SelectOptions): this;
|
|
125
|
+
insert(values: Partial<Row> | Array<Partial<Row>>, options?: InsertOptions): this;
|
|
126
|
+
/**
|
|
127
|
+
* `INSERT .. ON CONFLICT DO UPDATE`. The conflict target defaults to the
|
|
128
|
+
* primary key server side; `onConflict` names another unique constraint.
|
|
129
|
+
*/
|
|
130
|
+
upsert(values: Partial<Row> | Array<Partial<Row>>, options?: UpsertOptions): this;
|
|
131
|
+
update(values: Partial<Row>, options?: MutateOptions): this;
|
|
132
|
+
delete(options?: MutateOptions): this;
|
|
133
|
+
/**
|
|
134
|
+
* A bulk write states its column set explicitly, so a key missing from one
|
|
135
|
+
* row is still written (as NULL, or as the column default under
|
|
136
|
+
* `missing=default`) instead of being inferred from the first row alone.
|
|
137
|
+
*/
|
|
138
|
+
private applyColumns;
|
|
139
|
+
eq(column: string, value: PostgrestPrimitive): this;
|
|
140
|
+
neq(column: string, value: PostgrestPrimitive): this;
|
|
141
|
+
gt(column: string, value: PostgrestPrimitive): this;
|
|
142
|
+
gte(column: string, value: PostgrestPrimitive): this;
|
|
143
|
+
lt(column: string, value: PostgrestPrimitive): this;
|
|
144
|
+
lte(column: string, value: PostgrestPrimitive): this;
|
|
145
|
+
/** Case-sensitive LIKE. `*` is PostgREST's URL-friendly `%`. */
|
|
36
146
|
like(column: string, pattern: string): this;
|
|
37
147
|
ilike(column: string, pattern: string): this;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
148
|
+
likeAllOf(column: string, patterns: readonly string[]): this;
|
|
149
|
+
likeAnyOf(column: string, patterns: readonly string[]): this;
|
|
150
|
+
ilikeAllOf(column: string, patterns: readonly string[]): this;
|
|
151
|
+
ilikeAnyOf(column: string, patterns: readonly string[]): this;
|
|
152
|
+
in(column: string, values: readonly PostgrestPrimitive[]): this;
|
|
153
|
+
is(column: string, value: PostgrestIsValue): this;
|
|
154
|
+
/** Every key equal to its value, ANDed together. */
|
|
155
|
+
match(query: Record<string, PostgrestPrimitive>): this;
|
|
156
|
+
/**
|
|
157
|
+
* Negate any operator: `not('status', 'eq', 'live')` emits
|
|
158
|
+
* `status=not.eq.live`. The value is passed through verbatim for a string, so
|
|
159
|
+
* composite operands (`not('id', 'in', '(1,2)')`) reach the server as written.
|
|
160
|
+
*/
|
|
161
|
+
not(column: string, operator: PostgrestFilterOperator | (string & {}), value: PostgrestPrimitive | readonly PostgrestPrimitive[]): this;
|
|
162
|
+
/**
|
|
163
|
+
* The escape hatch: any operator, including the ones with no dedicated method
|
|
164
|
+
* (`match`, `imatch`, `isdistinct`) and the modifier forms (`like(any)`).
|
|
165
|
+
*/
|
|
166
|
+
filter(column: string, operator: PostgrestFilterOperator | (string & {}), value: PostgrestPrimitive | readonly PostgrestPrimitive[]): this;
|
|
167
|
+
/**
|
|
168
|
+
* A disjunction, written in PostgREST's own syntax and nestable:
|
|
169
|
+
* `or('status.eq.live,and(price.gt.10,price.lt.20)')`.
|
|
170
|
+
*/
|
|
171
|
+
or(filters: string, options?: ReferencedTableOption): this;
|
|
172
|
+
/** Full-text search. `type` picks the tsquery parser, `config` the dictionary. */
|
|
173
|
+
textSearch(column: string, query: string, options?: {
|
|
174
|
+
type?: TextSearchType;
|
|
175
|
+
config?: string;
|
|
42
176
|
}): this;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
177
|
+
/** `@>`: the column contains the operand (array, range or jsonb). */
|
|
178
|
+
contains(column: string, value: PostgrestArrayOperand): this;
|
|
179
|
+
/** `<@`: the column is contained by the operand. */
|
|
180
|
+
containedBy(column: string, value: PostgrestArrayOperand): this;
|
|
181
|
+
/** `&&`: the column and the operand have an element (or a point) in common. */
|
|
182
|
+
overlaps(column: string, value: PostgrestArrayOperand): this;
|
|
183
|
+
/** `>>`: strictly right of the range. */
|
|
184
|
+
rangeGt(column: string, range: string): this;
|
|
185
|
+
/** `&>`: does not extend to the left of the range. */
|
|
186
|
+
rangeGte(column: string, range: string): this;
|
|
187
|
+
/** `<<`: strictly left of the range. */
|
|
188
|
+
rangeLt(column: string, range: string): this;
|
|
189
|
+
/** `&<`: does not extend to the right of the range. */
|
|
190
|
+
rangeLte(column: string, range: string): this;
|
|
191
|
+
/** `-|-`: adjacent to the range. */
|
|
192
|
+
rangeAdjacent(column: string, range: string): this;
|
|
193
|
+
private push;
|
|
194
|
+
order(column: string, options?: OrderOptions): this;
|
|
195
|
+
limit(count: number, options?: ReferencedTableOption): this;
|
|
196
|
+
/** Inclusive range -> offset/limit. `range(0, 9)` fetches 10 rows from offset 0. */
|
|
197
|
+
range(from: number, to: number, options?: ReferencedTableOption): this;
|
|
198
|
+
/** Cancel the in-flight request when the signal aborts. */
|
|
199
|
+
abortSignal(signal: AbortSignal): this;
|
|
200
|
+
/**
|
|
201
|
+
* Re-type the rows. Purely a compile-time cast, for cases the generated
|
|
202
|
+
* `Database` cannot express (a computed column, an embedded shape).
|
|
203
|
+
*/
|
|
204
|
+
returns<T extends object>(): PostgrestQueryBuilder<T>;
|
|
205
|
+
/** Ask for `text/csv` instead of JSON. The result resolves to a string. */
|
|
206
|
+
csv(): PostgrestTextBuilder;
|
|
207
|
+
/** Ask the server for the query plan. Admin-only, and off by default. */
|
|
208
|
+
explain(options?: ExplainOptions): PostgrestExplainBuilder;
|
|
46
209
|
single(): PostgrestSingleBuilder<Row>;
|
|
47
210
|
maybeSingle(): PostgrestSingleBuilder<Row>;
|
|
48
211
|
/** The URL path (with query string) this builder targets. Exposed for tests. */
|
|
49
212
|
toPath(): string;
|
|
213
|
+
/** The headers this builder sends. Exposed for tests alongside `toPath()`. */
|
|
214
|
+
toHeaders(): Record<string, string>;
|
|
50
215
|
private execute;
|
|
51
|
-
then<TResult1 =
|
|
216
|
+
then<TResult1 = PostgrestResponse<Row[]>, TResult2 = never>(onfulfilled?: ((value: PostgrestResponse<Row[]>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
52
217
|
}
|
|
53
218
|
/** Same builder, typed to resolve a single row (from `.single()` / `.maybeSingle()`). */
|
|
54
|
-
export interface PostgrestSingleBuilder<Row extends object> extends Omit<PostgrestQueryBuilder<Row>, 'then' | 'single' | 'maybeSingle'>, PromiseLike<
|
|
55
|
-
|
|
219
|
+
export interface PostgrestSingleBuilder<Row extends object> extends Omit<PostgrestQueryBuilder<Row>, 'then' | 'single' | 'maybeSingle' | 'returns'>, PromiseLike<PostgrestResponse<Row>> {
|
|
220
|
+
returns<T extends object>(): PostgrestSingleBuilder<T>;
|
|
221
|
+
then<TResult1 = PostgrestResponse<Row>, TResult2 = never>(onfulfilled?: ((value: PostgrestResponse<Row>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
222
|
+
}
|
|
223
|
+
/** The builder after `.csv()`: the body is text, not rows. */
|
|
224
|
+
export interface PostgrestTextBuilder extends PromiseLike<PostgrestResponse<string>> {
|
|
225
|
+
toPath(): string;
|
|
226
|
+
toHeaders(): Record<string, string>;
|
|
227
|
+
}
|
|
228
|
+
/** The builder after `.explain()`: text, or the parsed plan for `format: 'json'`. */
|
|
229
|
+
export interface PostgrestExplainBuilder extends PromiseLike<PostgrestResponse<unknown>> {
|
|
230
|
+
toPath(): string;
|
|
231
|
+
toHeaders(): Record<string, string>;
|
|
56
232
|
}
|
|
57
|
-
export {};
|
|
58
233
|
//# sourceMappingURL=postgrest.d.ts.map
|
package/dist/postgrest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgrest.d.ts","sourceRoot":"","sources":["../src/postgrest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAmB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"postgrest.d.ts","sourceRoot":"","sources":["../src/postgrest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAmB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAElE,sEAAsE;AACtE,MAAM,MAAM,qBAAqB,GAC7B,MAAM,GACN,SAAS,kBAAkB,EAAE,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5B,2FAA2F;AAC3F,MAAM,MAAM,uBAAuB,GAC/B,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,KAAK,GACL,MAAM,GACN,OAAO,GACP,OAAO,GACP,QAAQ,GACR,IAAI,GACJ,IAAI,GACJ,YAAY,GACZ,KAAK,GACL,OAAO,GACP,OAAO,GACP,MAAM,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AAEV,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,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