@rebasepro/client 0.30.0 → 0.31.0-canary.g59cd6fd
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 +10 -10
- package/dist/auth.d.ts +56 -0
- package/dist/client-contract.types.d.ts +25 -0
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +34 -29
- package/dist/index.es.js +227 -75
- package/dist/index.es.js.map +1 -1
- package/dist/{offline-B6J1YUWF.js → offline-D_wKJcO3.js} +102 -93
- package/dist/offline-D_wKJcO3.js.map +1 -0
- package/dist/offline-codec.d.ts +7 -1
- package/dist/offline-lazy.d.ts +5 -5
- package/dist/{offline-store-B7F5mimt.js → offline-store-DtmBwmKE.js} +52 -146
- package/dist/offline-store-DtmBwmKE.js.map +1 -0
- package/dist/offline-store.d.ts +11 -2
- package/dist/offline.d.ts +23 -23
- package/dist/query-contract.types.d.ts +4 -4
- package/dist/schema.d.ts +29 -0
- package/dist/sdk_query_builder.d.ts +7 -7
- package/dist/{collection.d.ts → table.d.ts} +13 -13
- package/dist/transport.d.ts +3 -4
- package/dist/websocket.d.ts +6 -12
- package/package.json +7 -5
- package/dist/offline-B6J1YUWF.js.map +0 -1
- package/dist/offline-store-B7F5mimt.js.map +0 -1
- package/dist/reviver.d.ts +0 -19
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* generated SDK — where `M` is a concrete row type — the documented call was a
|
|
24
24
|
* compile error. Nothing in this repo noticed; a downstream application did.
|
|
25
25
|
*/
|
|
26
|
-
import type { AggregateParams, FindParams, FindResult, LogicalCondition,
|
|
26
|
+
import type { AggregateParams, FindParams, FindResult, LogicalCondition, SDKTableClient, SDKQueryBuilderInterface, UpdateValues, WhereFilterOp } from "@rebasepro/types";
|
|
27
27
|
/**
|
|
28
28
|
* A row shaped the way a **generated** SDK shapes one: a type alias with a
|
|
29
29
|
* finite key set.
|
|
@@ -116,7 +116,7 @@ export declare const fluentIsNull: (qb: SDKQueryBuilderInterface<ContractRow>) =
|
|
|
116
116
|
* union of every branch rather than a `never`.
|
|
117
117
|
*/
|
|
118
118
|
export declare const fluentDynamicOp: (qb: SDKQueryBuilderInterface<ContractRow>, op: WhereFilterOp) => SDKQueryBuilderInterface<ContractRow, import("@rebasepro/types").IncludeSpec>;
|
|
119
|
-
/** Two conditions on one column:
|
|
119
|
+
/** Two conditions on one column: a shape a filter compiler once dropped. */
|
|
120
120
|
export declare const fluentRange: (qb: SDKQueryBuilderInterface<ContractRow>) => SDKQueryBuilderInterface<ContractRow, import("@rebasepro/types").IncludeSpec>;
|
|
121
121
|
/** The object form must accept exactly what the fluent form accepts. */
|
|
122
122
|
export declare const paramsArrayContains: FindParams<ContractRow>;
|
|
@@ -216,11 +216,11 @@ export declare const updateIncText: UpdateValues<Partial<ContractRow>>;
|
|
|
216
216
|
export declare const updateUntyped: UpdateValues<Partial<Record<string, unknown>>>;
|
|
217
217
|
/**
|
|
218
218
|
* A typed client is still a client: a helper written against the wide
|
|
219
|
-
* `
|
|
219
|
+
* `SDKTableClient` (an export, a paginator, a seeder) takes
|
|
220
220
|
* `rebase.data.posts`. The column checks above must narrow what a typed
|
|
221
221
|
* client's methods accept without making the typed client a different kind
|
|
222
222
|
* of thing — `NumericKeyOf` as a conditional over `keyof M` made tsc measure
|
|
223
223
|
* `AggregateParams` invariant, and this line stopped compiling.
|
|
224
224
|
*/
|
|
225
|
-
export declare const typedClientWidens: (posts:
|
|
225
|
+
export declare const typedClientWidens: (posts: SDKTableClient<ContractRow>) => SDKTableClient;
|
|
226
226
|
export {};
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type SchemaAPI } from "@rebasepro/types";
|
|
2
|
+
import type { Transport } from "./transport.js";
|
|
3
|
+
/**
|
|
4
|
+
* The code `client.schema.tables()` rejects with when the backend serves no
|
|
5
|
+
* tables: auth is not configured there (the route answers `404` with this
|
|
6
|
+
* code), or the server predates the route (a bare `404`).
|
|
7
|
+
*
|
|
8
|
+
* @group Schema
|
|
9
|
+
*/
|
|
10
|
+
export declare const SCHEMA_UNAVAILABLE = "SCHEMA_UNAVAILABLE";
|
|
11
|
+
/**
|
|
12
|
+
* Whether an error from `client.schema.tables()` says the backend serves no
|
|
13
|
+
* tables at all — as opposed to refusing this caller or failing.
|
|
14
|
+
*
|
|
15
|
+
* @group Schema
|
|
16
|
+
*/
|
|
17
|
+
export declare function isSchemaUnavailable(error: unknown): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* `client.schema`: the backend's tables as `GET /api/schema/tables` serves
|
|
20
|
+
* them to the signed-in caller.
|
|
21
|
+
*
|
|
22
|
+
* The answer is redacted per caller and the server tags it with an `ETag`;
|
|
23
|
+
* the last answer is kept with its tag and the next request sends the tag in
|
|
24
|
+
* `If-None-Match`, so an unchanged schema costs a `304` and no body. A `304`
|
|
25
|
+
* says the answer for *this* caller still has the tag that was sent, so the
|
|
26
|
+
* kept tables are exactly what the server would have sent — whoever is signed
|
|
27
|
+
* in now.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSchema(transport: Transport): SchemaAPI;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FindResult, LogicalCondition, PageWalkOptions, RelationAggregateSort,
|
|
1
|
+
import { FindResult, LogicalCondition, PageWalkOptions, RelationAggregateSort, SDKTableClient, SDKQueryBuilderInterface, WhereFilterOp, WhereValueFor, type AggregateParams, type AggregateResult, type ComputedSortField, type FieldPath, type IncludeSpec, type NonColumnFieldPath, type NullsPlacement } from "@rebasepro/types";
|
|
2
2
|
/**
|
|
3
3
|
* SDK Query Builder — returns flat rows (`FindResult<M>`) instead of
|
|
4
4
|
* Entity-wrapped results (`FindResponse<M>`).
|
|
@@ -13,9 +13,9 @@ import { FindResult, LogicalCondition, PageWalkOptions, RelationAggregateSort, S
|
|
|
13
13
|
* console.log(data[0].title); // flat access
|
|
14
14
|
*/
|
|
15
15
|
export declare class SDKQueryBuilder<M extends Record<string, unknown> = Record<string, unknown>> implements SDKQueryBuilderInterface<M> {
|
|
16
|
-
private
|
|
16
|
+
private table;
|
|
17
17
|
private params;
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(table: SDKTableClient<M>);
|
|
19
19
|
/**
|
|
20
20
|
* Add a filter condition to your query.
|
|
21
21
|
* @example
|
|
@@ -52,8 +52,8 @@ export declare class SDKQueryBuilder<M extends Record<string, unknown> = Record<
|
|
|
52
52
|
/**
|
|
53
53
|
* Set a free-text search string if supported by the backend.
|
|
54
54
|
*
|
|
55
|
-
* By default this is a substring match across the
|
|
56
|
-
* string
|
|
55
|
+
* By default this is a substring match across the table's top-level
|
|
56
|
+
* string columns. A Postgres table that declares a `search` block
|
|
57
57
|
* gets ranked full-text matching over the fields it named instead, and each
|
|
58
58
|
* row comes back with a `_score` you can sort on:
|
|
59
59
|
*
|
|
@@ -114,7 +114,7 @@ export declare class SDKQueryBuilder<M extends Record<string, unknown> = Record<
|
|
|
114
114
|
* ```
|
|
115
115
|
*
|
|
116
116
|
* Up to three hops deep, and `"*"` still loads every relation one hop
|
|
117
|
-
* deep. A name that is not a relation of the
|
|
117
|
+
* deep. A name that is not a relation of the table is a 400
|
|
118
118
|
* `UNKNOWN_RELATION` — it used to be ignored, which answers 200 with the
|
|
119
119
|
* field missing and reads exactly like a row that has no related row.
|
|
120
120
|
*
|
|
@@ -192,7 +192,7 @@ export declare class SDKQueryBuilder<M extends Record<string, unknown> = Record<
|
|
|
192
192
|
/**
|
|
193
193
|
* Listen to realtime updates matching this query.
|
|
194
194
|
*
|
|
195
|
-
* The guard that used to stand here — `if (!this.
|
|
195
|
+
* The guard that used to stand here — `if (!this.table.listen) throw`
|
|
196
196
|
* — has moved onto the client itself, which is where the same failure had
|
|
197
197
|
* to be diagnosed anyway: `client.data.posts.listen(…)`, one call short of
|
|
198
198
|
* this builder, answered `undefined is not a function`. The message is now
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { FindParams, Transport } from "./transport.js";
|
|
2
2
|
import type { RebaseWebSocketClient } from "./websocket.js";
|
|
3
|
-
import { FindResult,
|
|
3
|
+
import { FindResult, SDKTableClient, type ByIdReadOptions, type IncludeSpec, type RestoreOptions, type TrashClient, RebaseClientError } from "@rebasepro/types";
|
|
4
4
|
import { etagOf } from "@rebasepro/common";
|
|
5
5
|
/**
|
|
6
|
-
* The part of a {@link Transport} a
|
|
6
|
+
* The part of a {@link Transport} a table client uses: its requests, and
|
|
7
7
|
* the address they go to (to tell when a query is too long for a URL).
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
10
|
-
/** The part of the realtime client a
|
|
11
|
-
export type
|
|
9
|
+
export type TableTransport = Pick<Transport, "request" | "baseUrl" | "apiPath">;
|
|
10
|
+
/** The part of the realtime client a table client listens through. */
|
|
11
|
+
export type TableRealtime = Pick<RebaseWebSocketClient, "listenCollection" | "listenOne">;
|
|
12
12
|
/**
|
|
13
13
|
* A bulk call given something other than an array. A `RebaseClientError` with
|
|
14
14
|
* the code the server uses for the same mistake in a request body, so one
|
|
@@ -71,18 +71,18 @@ export interface ObserveByIdOptions<Inc = IncludeSpec> extends ObserveOptions, B
|
|
|
71
71
|
export type { RestoreOptions, TrashClient };
|
|
72
72
|
/**
|
|
73
73
|
* The concrete, HTTP-backed implementation of the public
|
|
74
|
-
* {@link
|
|
74
|
+
* {@link SDKTableClient} contract — flat rows (no Entity wrapper), plus
|
|
75
75
|
* fluent query-builder methods (`.where()`, `.orderBy()`, …).
|
|
76
76
|
*
|
|
77
|
-
* This is what `createRebaseClient().data.<
|
|
78
|
-
* separate API from {@link
|
|
77
|
+
* This is what `createRebaseClient().data.<table>` returns. It is not a
|
|
78
|
+
* separate API from {@link SDKTableClient}; it only widens it with
|
|
79
79
|
* `count()` and the reactive `observe()` pair. Program against
|
|
80
|
-
* {@link
|
|
80
|
+
* {@link SDKTableClient} when you want a transport-agnostic type.
|
|
81
81
|
*/
|
|
82
|
-
export interface
|
|
82
|
+
export interface TableClient<M extends Record<string, unknown> = Record<string, unknown>, I = Partial<M>, U = Partial<M>, Inc = IncludeSpec> extends SDKTableClient<M, I, U, Inc> {
|
|
83
83
|
count(params?: FindParams<M, Inc>): Promise<number>;
|
|
84
84
|
/**
|
|
85
|
-
* The
|
|
85
|
+
* The table's trash: list, count, restore and purge the rows a soft
|
|
86
86
|
* delete stamped. See {@link TrashClient}.
|
|
87
87
|
*/
|
|
88
88
|
trash: TrashClient<M, Inc>;
|
|
@@ -102,7 +102,7 @@ export interface CollectionClient<M extends Record<string, unknown> = Record<str
|
|
|
102
102
|
* @returns An unsubscribe function.
|
|
103
103
|
*/
|
|
104
104
|
observe(params: FindParams<M, Inc> | undefined, onResult: (result: LiveResult<M>) => void, onError?: (error: Error) => void, options?: ObserveOptions): () => void;
|
|
105
|
-
/** {@link
|
|
105
|
+
/** {@link TableClient.observe} for a single row. */
|
|
106
106
|
observeById(id: string | number, onResult: (row: M | undefined, meta: RowSnapshotMeta) => void, onError?: (error: Error) => void, options?: ObserveByIdOptions<Inc>): () => void;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
@@ -110,4 +110,4 @@ export interface CollectionClient<M extends Record<string, unknown> = Record<str
|
|
|
110
110
|
* nothing else, so `realtime` never travels as a query parameter.
|
|
111
111
|
*/
|
|
112
112
|
export declare function byIdRead<Inc>(options: ObserveByIdOptions<Inc> | undefined): ByIdReadOptions<Inc> | undefined;
|
|
113
|
-
export declare function
|
|
113
|
+
export declare function createTableClient<M extends Record<string, unknown> = Record<string, unknown>>(transport: TableTransport, slug: string, ws?: TableRealtime): TableClient<M>;
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AggregateParams, FindParams as TypesFindParams,
|
|
1
|
+
import { AggregateParams, FindParams as TypesFindParams, type IncludeSpec, type LogicalCondition } from "@rebasepro/types";
|
|
2
2
|
export { RebaseApiError } from "@rebasepro/types";
|
|
3
3
|
export type { RebaseErrorInit } from "@rebasepro/types";
|
|
4
4
|
/** Options for the realtime socket: `createRebaseClient({ realtime: { ... } })`. */
|
|
@@ -160,7 +160,6 @@ export declare const ANONYMOUS_SERVER_CLIENT_WARNING: string;
|
|
|
160
160
|
* definition, was where the typing was lost.
|
|
161
161
|
*/
|
|
162
162
|
export type FindParams<M extends Record<string, unknown> = Record<string, unknown>, Inc = IncludeSpec> = TypesFindParams<M, Inc>;
|
|
163
|
-
export type FindResponse<T> = TypesFindResponse<T extends Record<string, unknown> ? T : Record<string, unknown>>;
|
|
164
163
|
/**
|
|
165
164
|
* Refuse a filter whose *value* is missing.
|
|
166
165
|
*
|
|
@@ -190,7 +189,7 @@ export declare function assertNoUndefinedFilterValues(where: Record<string, unkn
|
|
|
190
189
|
export type SoftDeletedRows = "include" | "only";
|
|
191
190
|
export declare function buildQueryString(params?: FindParams, deleted?: SoftDeletedRows): string;
|
|
192
191
|
/**
|
|
193
|
-
* The body of `POST /data/<
|
|
192
|
+
* The body of `POST /data/<table>/query`: the parameters
|
|
194
193
|
* {@link buildQueryString} puts in the URL, spelled as the URL spells them —
|
|
195
194
|
* each value a string, and a parameter the URL repeats (a filter with two
|
|
196
195
|
* conditions on one field) a list of them. The server reads it back into the
|
|
@@ -212,7 +211,7 @@ export declare function writeFilterBody(query: {
|
|
|
212
211
|
logical?: string;
|
|
213
212
|
};
|
|
214
213
|
/**
|
|
215
|
-
* The query string for `GET /<
|
|
214
|
+
* The query string for `GET /<table>/aggregate`.
|
|
216
215
|
*
|
|
217
216
|
* `?select=sum(total),count()` is SQL's spelling, because whoever writes an
|
|
218
217
|
* aggregate is thinking in SQL and any other spelling has to be learned first —
|
package/dist/websocket.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeleteProps,
|
|
1
|
+
import { DeleteProps, FetchCollectionProps, ListenCollectionProps, FetchOneProps, SaveProps, CollectionUpdateMeta, ChannelMessage, TableMetadata, BranchInfo, RebaseApiError, type RealtimeConnectionState } from "@rebasepro/types";
|
|
2
2
|
import type { SqlScriptResult } from "@rebasepro/types";
|
|
3
3
|
/**
|
|
4
4
|
* A socket handler slot, declared with method syntax so its parameter is
|
|
@@ -402,7 +402,7 @@ export declare class RebaseWebSocketClient {
|
|
|
402
402
|
fetchAvailableRoles(): Promise<string[]>;
|
|
403
403
|
fetchApplicationRoles(): Promise<string[]>;
|
|
404
404
|
fetchCurrentDatabase(): Promise<string | undefined>;
|
|
405
|
-
checkUniqueField(path: string, name: string, value: unknown, id?: string
|
|
405
|
+
checkUniqueField(path: string, name: string, value: unknown, id?: string): Promise<boolean>;
|
|
406
406
|
count<M extends Record<string, unknown>>(props: FetchCollectionProps<M>): Promise<number>;
|
|
407
407
|
fetchUnmappedTables(mappedPaths?: string[]): Promise<string[]>;
|
|
408
408
|
fetchTableMetadata(tableName: string): Promise<TableMetadata>;
|
|
@@ -430,15 +430,9 @@ export declare class RebaseWebSocketClient {
|
|
|
430
430
|
/**
|
|
431
431
|
* Recursively compare two values a refetch can carry for structural
|
|
432
432
|
* equality: primitives, null, undefined, Date, RegExp, arrays and objects.
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* done by normalising each side into a copy first — two deep copies of
|
|
437
|
-
* every cached row on every frame, most of which then compared equal. It is
|
|
438
|
-
* done in place now, and an unchanged row costs no copy.
|
|
439
|
-
*
|
|
440
|
-
* `relationAware` is off for a relation's own fields: the copies never
|
|
441
|
-
* looked inside those either.
|
|
433
|
+
* In place — an unchanged row costs no copy. A row is wire values only, so
|
|
434
|
+
* a relation is its key, or the related row an `include` named, compared
|
|
435
|
+
* like any other value.
|
|
442
436
|
*/
|
|
443
437
|
private deepEqual;
|
|
444
438
|
/**
|
|
@@ -462,7 +456,7 @@ export declare class RebaseWebSocketClient {
|
|
|
462
456
|
*/
|
|
463
457
|
private mergeRows;
|
|
464
458
|
listenCollection<M extends Record<string, unknown>>(props: Omit<ListenCollectionProps<M>, "onUpdate" | "onError">, onUpdate: (rows: Record<string, unknown>[], meta?: CollectionUpdateMeta) => void, onError?: (error: Error) => void): () => void;
|
|
465
|
-
listenOne<M extends Record<string, unknown>>(props:
|
|
459
|
+
listenOne<M extends Record<string, unknown>>(props: FetchOneProps<M>, onUpdate: (row: Record<string, unknown> | null) => void, onError?: (error: Error) => void): () => void;
|
|
466
460
|
/**
|
|
467
461
|
* Send a `subscribe_collection` for an already-registered subscription and
|
|
468
462
|
* arm its watchdog.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0-canary.g59cd6fd",
|
|
4
4
|
"description": "HTTP SDK client for the Rebase custom backend",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rebase",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@rebasepro/common": "0.
|
|
45
|
-
"@rebasepro/
|
|
46
|
-
"@rebasepro/
|
|
44
|
+
"@rebasepro/common": "0.31.0-canary.g59cd6fd",
|
|
45
|
+
"@rebasepro/utils": "0.31.0-canary.g59cd6fd",
|
|
46
|
+
"@rebasepro/types": "0.31.0-canary.g59cd6fd"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@jest/globals": "^30.4.1",
|
|
@@ -82,11 +82,13 @@
|
|
|
82
82
|
"testEnvironment": "node",
|
|
83
83
|
"moduleNameMapper": {
|
|
84
84
|
"^@rebasepro/cms-types$": "<rootDir>/../cms-types/src/index.ts",
|
|
85
|
+
"^@rebasepro/common/migrate$": "<rootDir>/../common/src/migrate/index.ts",
|
|
85
86
|
"^@rebasepro/common$": "<rootDir>/../common/src/index.ts",
|
|
86
87
|
"^@rebasepro/types$": "<rootDir>/../types/src/index.ts",
|
|
87
88
|
"^@rebasepro/utils$": "<rootDir>/../utils/src/index.ts"
|
|
88
89
|
},
|
|
89
|
-
"testTimeout": 30000
|
|
90
|
+
"testTimeout": 30000,
|
|
91
|
+
"maxWorkers": 4
|
|
90
92
|
},
|
|
91
93
|
"scripts": {
|
|
92
94
|
"watch": "vite build --watch",
|