@rebasepro/client 0.23.0 → 0.24.1-canary.g19596ef
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -10
- package/dist/admin-contract.types.d.ts +21 -0
- package/dist/admin.d.ts +11 -5
- package/dist/api-keys.d.ts +29 -11
- package/dist/auth.d.ts +65 -11
- package/dist/backups.d.ts +14 -7
- package/dist/collection.d.ts +40 -19
- package/dist/cron.d.ts +13 -8
- package/dist/exports-contract.types.d.ts +39 -0
- package/dist/functions.d.ts +2 -12
- package/dist/index.d.ts +70 -19
- package/dist/index.es.js +1631 -4004
- package/dist/index.es.js.map +1 -1
- package/dist/offline-QNQgsPOq.js +3307 -0
- package/dist/offline-QNQgsPOq.js.map +1 -0
- package/dist/offline-codec.d.ts +12 -0
- package/dist/offline-connectivity.d.ts +6 -0
- package/dist/offline-errors.d.ts +9 -0
- package/dist/offline-lazy.d.ts +58 -0
- package/dist/offline-store-Cm5sAX81.js +1837 -0
- package/dist/offline-store-Cm5sAX81.js.map +1 -0
- package/dist/offline-store.d.ts +45 -0
- package/dist/offline.d.ts +315 -19
- package/dist/query-contract.types.d.ts +76 -24
- package/dist/realtime-channel.d.ts +30 -0
- package/dist/reviver.d.ts +18 -0
- package/dist/sdk_query_builder.d.ts +2 -2
- package/dist/sql-script.d.ts +10 -0
- package/dist/storage-resumable-VO-cMpse.js +2 -0
- package/dist/storage-resumable.d.ts +1 -0
- package/dist/transport.d.ts +100 -7
- package/dist/websocket.d.ts +199 -23
- package/package.json +4 -4
- package/dist/query_builder.d.ts +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,41 +3,43 @@ import { createAuth, CreateAuthOptions } from "./auth.js";
|
|
|
3
3
|
import { createAdmin, CreateAdminOptions } from "./admin.js";
|
|
4
4
|
import { createCron, CreateCronOptions } from "./cron.js";
|
|
5
5
|
import { createBackups } from "./backups.js";
|
|
6
|
-
import { createApiKeys, CreateApiKeysOptions } from "./api-keys.js";
|
|
6
|
+
import { createApiKeys, CreateApiKeysOptions, createPersonalKeys, CreatePersonalKeysOptions } from "./api-keys.js";
|
|
7
7
|
import { CollectionClient } from "./collection.js";
|
|
8
8
|
import { createFunctionsClient } from "./functions.js";
|
|
9
9
|
import { RebaseWebSocketClient } from "./websocket.js";
|
|
10
10
|
import { RebaseRealtimeChannel, type ChannelOptions } from "./realtime-channel.js";
|
|
11
|
-
import {
|
|
12
|
-
import { type BatchOperation, type BatchResult, InsertOf, RebaseClient, RebaseSdkData, RowOf, StorageSource, StorageSourceDefinition, StorageSourceRegistry, UpdateOf, type WriteOptions } from "@rebasepro/types";
|
|
11
|
+
import type { OfflineApi, OfflineConfig } from "./offline.js";
|
|
12
|
+
import { type BatchOperation, type BatchResult, type IncludeOf, InsertOf, RebaseClient, RebaseSdkData, RowOf, StorageSource, StorageSourceDefinition, StorageSourceRegistry, UpdateOf, type WriteOptions } from "@rebasepro/types";
|
|
13
13
|
export { RebaseApiError } from "./transport.js";
|
|
14
14
|
export { RebaseClientError } from "./errors.js";
|
|
15
15
|
export type { RebaseErrorCode } from "@rebasepro/types";
|
|
16
16
|
export type { RebaseClientConfig, FindParams, FindResponse } from "./transport.js";
|
|
17
|
-
export type { CollectionClient } from "./collection.js";
|
|
17
|
+
export type { CollectionClient, RestoreOptions, TrashClient } from "./collection.js";
|
|
18
18
|
export type { FindResult, SDKCollectionClient, SDKQueryBuilderInterface, PaginationMeta } from "@rebasepro/types";
|
|
19
19
|
export type { IterateParams, FindAllParams, PageWalkOptions, CursorSpec } from "@rebasepro/types";
|
|
20
20
|
export { RebasePaginationError } from "@rebasepro/common";
|
|
21
21
|
export type { PaginationErrorCode } from "@rebasepro/common";
|
|
22
|
-
export {
|
|
22
|
+
export { or, and, not, cond } from "@rebasepro/common";
|
|
23
|
+
export { resolveStorageReferences, storageReference, parseStorageReference, isStorageReference, STORAGE_REFERENCE_SCHEME, storageTargetOfDownloadUrl, storageReferencesForDownloadUrls, storageTargetsInText } from "@rebasepro/types";
|
|
24
|
+
export type { StorageReferenceTarget, StorageReferenceResolver } from "@rebasepro/types";
|
|
23
25
|
export { createCookieStorage, createMemoryStorage } from "./auth.js";
|
|
24
|
-
export type { AuthConfig, AuthStorage, CookieStorageOptions, CreateAuthOptions } from "./auth.js";
|
|
26
|
+
export type { AuthConfig, AuthStorage, CookieStorageOptions, CreateAuthOptions, SessionRestoreOutcome } from "./auth.js";
|
|
25
27
|
export type { User, RebaseSession, AuthTokens, AuthChangeEvent, DeviceSession } from "@rebasepro/types";
|
|
26
28
|
export type { CreateAdminOptions, ListUsersOptions } from "./admin.js";
|
|
27
29
|
export type { AdminUser } from "./admin.js";
|
|
28
30
|
export type { CreateCronOptions } from "./cron.js";
|
|
29
|
-
export {
|
|
30
|
-
export type {
|
|
31
|
-
export type { ApiKeyMasked, ApiKeyPermission, ApiKeyWithSecret, CreateApiKeyRequest, CreateApiKeysOptions, UpdateApiKeyRequest } from "./api-keys.js";
|
|
31
|
+
export type { BackupStream } from "./backups.js";
|
|
32
|
+
export type { ApiKeyKind, ApiKeyMasked, ApiKeyWithSecret, CreateApiKeyRequest, CreateApiKeysOptions, CreatePersonalKeyRequest, CreatePersonalKeysOptions, UpdateApiKeyRequest } from "./api-keys.js";
|
|
32
33
|
export type { FunctionInvokeOptions, FunctionsClient } from "./functions.js";
|
|
33
34
|
export { RebaseWebSocketClient } from "./websocket.js";
|
|
34
35
|
export { RebaseRealtimeChannel } from "./realtime-channel.js";
|
|
35
36
|
export type { PresenceState, PresenceDiff, BroadcastEvent, ChannelTransport, ChannelOptions, ChannelHistoryEntry, ChannelHistoryResult } from "./realtime-channel.js";
|
|
36
|
-
export type { OfflineApi, OfflineConfig, OfflineStatus } from "./offline.js";
|
|
37
|
-
export { isOfflineError } from "./offline.js";
|
|
38
|
-
export type { LiveResult, ObserveOptions, RowSnapshotMeta } from "./collection.js";
|
|
37
|
+
export type { ConflictResolution, OfflineApi, OfflineConfig, OfflineQueueOptions, OfflineStatus } from "./offline.js";
|
|
38
|
+
export { isOfflineError } from "./offline-errors.js";
|
|
39
|
+
export type { LiveResult, ObserveByIdOptions, ObserveOptions, RowSnapshotMeta } from "./collection.js";
|
|
39
40
|
export { etagOf } from "./collection.js";
|
|
40
41
|
export type { BatchOperation, BatchRef, BatchResult, FieldOperation, UpdateValues, UpsertOptions } from "@rebasepro/types";
|
|
42
|
+
export type { WriteOptions, WhereFilterOp, WhereFor, WhereConditionFor, WhereValueFor, FilterValues, FieldPath, OrderBySpec, LogicalCondition, LogicalConditionFor, FilterCondition, FilterConditionFor, AggregateParams, AggregateSelect, AggregateRow, AggregateResult, AggregateMeta, IncludeSpec, IncludeOptions, QueryComputedFields, RowOf, InsertOf, UpdateOf, StorageSource } from "@rebasepro/types";
|
|
41
43
|
export type { OfflineStore, OfflineCacheEntry, OfflineCacheRecord, PendingMutation, MutationRollback } from "./offline-store.js";
|
|
42
44
|
export { MemoryOfflineStore } from "./offline-store.js";
|
|
43
45
|
export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
@@ -45,6 +47,7 @@ export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
|
45
47
|
admin?: CreateAdminOptions;
|
|
46
48
|
cron?: CreateCronOptions;
|
|
47
49
|
apiKeys?: CreateApiKeysOptions;
|
|
50
|
+
personalKeys?: CreatePersonalKeysOptions;
|
|
48
51
|
/**
|
|
49
52
|
* Declared storage sources for multi-backend support. Server-transport
|
|
50
53
|
* entries are auto-wired into `client.storageRegistry`; `direct` sources
|
|
@@ -77,12 +80,20 @@ export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
|
77
80
|
offline?: boolean | OfflineConfig;
|
|
78
81
|
}
|
|
79
82
|
type KebabToCamelCase<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamelCase<U>>}` : S;
|
|
80
|
-
|
|
83
|
+
/** The accessor whose generated entry declares `Slug: S`, or `never`. */
|
|
84
|
+
type AccessorOfSlug<DB, S extends string> = {
|
|
85
|
+
[K in keyof DB]: DB[K] extends {
|
|
86
|
+
Slug: S;
|
|
87
|
+
} ? K : never;
|
|
88
|
+
}[keyof DB];
|
|
89
|
+
type DBEntry<DB, S extends string> = [
|
|
90
|
+
AccessorOfSlug<DB, S>
|
|
91
|
+
] extends [never] ? (KebabToCamelCase<S> extends keyof DB ? DB[KebabToCamelCase<S>] : unknown) : DB[AccessorOfSlug<DB, S>];
|
|
81
92
|
type TypedDataLayer<DB> = {
|
|
82
|
-
collection<S extends string>(slug: S): CollectionClient<RowOf<DBEntry<DB, S>>, InsertOf<DBEntry<DB, S>>, UpdateOf<DBEntry<DB, S
|
|
93
|
+
collection<S extends string>(slug: S): CollectionClient<RowOf<DBEntry<DB, S>>, InsertOf<DBEntry<DB, S>>, UpdateOf<DBEntry<DB, S>>, IncludeOf<DBEntry<DB, S>, DB>>;
|
|
83
94
|
} & {
|
|
84
|
-
[K in keyof DB]: CollectionClient<RowOf<DB[K]>, InsertOf<DB[K]>, UpdateOf<DB[K]>>;
|
|
85
|
-
} & RebaseSdkData;
|
|
95
|
+
[K in keyof DB]: CollectionClient<RowOf<DB[K]>, InsertOf<DB[K]>, UpdateOf<DB[K]>, IncludeOf<DB[K], DB>>;
|
|
96
|
+
} & (string extends keyof DB ? RebaseSdkData : Pick<RebaseSdkData, "collection">);
|
|
86
97
|
/**
|
|
87
98
|
* The return type of `createRebaseClient<DB>()`.
|
|
88
99
|
*
|
|
@@ -91,15 +102,42 @@ type TypedDataLayer<DB> = {
|
|
|
91
102
|
* typed collection accessors when a `DB` schema generic is supplied.
|
|
92
103
|
*/
|
|
93
104
|
export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<RebaseClient<DB>, "data" | "email"> & {
|
|
105
|
+
/**
|
|
106
|
+
* Send this token from now on, over HTTP and on the realtime socket. An
|
|
107
|
+
* open socket is rebuilt to authenticate with it. A token getter, when one
|
|
108
|
+
* is installed, still comes first.
|
|
109
|
+
*/
|
|
94
110
|
setToken: (token: string | null) => void;
|
|
111
|
+
/**
|
|
112
|
+
* Ask `getter` for the token each time one is needed — every HTTP request
|
|
113
|
+
* and every time the realtime socket authenticates. This is how a host
|
|
114
|
+
* that signs users in with its own provider (Clerk, Firebase Auth, a
|
|
115
|
+
* session of its own) authenticates the client:
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* client.setAuthTokenGetter(() => clerk.session?.getToken() ?? Promise.resolve(null));
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* It comes before the client's own session and the `token` option, which
|
|
122
|
+
* are used when it answers `null` or throws. An open socket is rebuilt to
|
|
123
|
+
* authenticate through it.
|
|
124
|
+
*/
|
|
95
125
|
setAuthTokenGetter: (getter: () => Promise<string | null>) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Answer a refused credential — a 401 over HTTP, an auth error on the
|
|
128
|
+
* socket — with `handler`; resolve `true` to have the request or
|
|
129
|
+
* subscription retried with the token resolved again. Replaces the
|
|
130
|
+
* client's own session refresh.
|
|
131
|
+
*/
|
|
96
132
|
setOnUnauthorized: (handler: () => Promise<boolean>) => void;
|
|
133
|
+
/** The token the next request would carry, resolved as it would be. */
|
|
97
134
|
resolveToken: () => Promise<string | null>;
|
|
98
135
|
auth: ReturnType<typeof createAuth>;
|
|
99
136
|
admin: ReturnType<typeof createAdmin>;
|
|
100
137
|
cron: ReturnType<typeof createCron>;
|
|
101
138
|
backups: ReturnType<typeof createBackups>;
|
|
102
139
|
apiKeys: ReturnType<typeof createApiKeys>;
|
|
140
|
+
personalKeys: ReturnType<typeof createPersonalKeys>;
|
|
103
141
|
functions: ReturnType<typeof createFunctionsClient>;
|
|
104
142
|
ws?: RebaseWebSocketClient;
|
|
105
143
|
/**
|
|
@@ -147,7 +185,15 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
147
185
|
* Neither reaches into the response for a `data` key.
|
|
148
186
|
*/
|
|
149
187
|
call: <T = unknown>(endpoint: string, payload?: unknown) => Promise<T>;
|
|
150
|
-
|
|
188
|
+
/**
|
|
189
|
+
* A collection by slug — the same client `data.collection(slug)` returns,
|
|
190
|
+
* typed from the generated `Database` when the slug is one of its
|
|
191
|
+
* collections, or by the row type passed explicitly.
|
|
192
|
+
*/
|
|
193
|
+
collection: {
|
|
194
|
+
<S extends string>(slug: S): CollectionClient<RowOf<DBEntry<DB, S>>, InsertOf<DBEntry<DB, S>>, UpdateOf<DBEntry<DB, S>>, IncludeOf<DBEntry<DB, S>, DB>>;
|
|
195
|
+
<M extends Record<string, unknown> = Record<string, unknown>>(slug: string): CollectionClient<M>;
|
|
196
|
+
};
|
|
151
197
|
/**
|
|
152
198
|
* Write across collections in one transaction.
|
|
153
199
|
*
|
|
@@ -170,12 +216,17 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
170
216
|
* `data` is aligned to `operations`: the written row for a create, upsert
|
|
171
217
|
* or update, and `null` for a delete.
|
|
172
218
|
*
|
|
219
|
+
* `collection` is the accessor `client.data.<accessor>` takes — `orderItems`
|
|
220
|
+
* for the slug `order_items` — and is sent as the slug through the
|
|
221
|
+
* `collections` dictionary. A name that is not an accessor goes out as
|
|
222
|
+
* written, so an untyped client can still pass the slug.
|
|
223
|
+
*
|
|
173
224
|
* @example
|
|
174
225
|
* ```ts
|
|
175
226
|
* await client.batch([
|
|
176
227
|
* { op: "create", collection: "orders", values: { total: 40 }, ref: "order" },
|
|
177
|
-
* { op: "create", collection: "
|
|
178
|
-
* values: {
|
|
228
|
+
* { op: "create", collection: "orderItems",
|
|
229
|
+
* values: { orderId: { $ref: "order.id" }, sku: "A-1" } },
|
|
179
230
|
* { op: "update", collection: "stock", id: "A-1", values: { count: { $inc: -1 } } }
|
|
180
231
|
* ]);
|
|
181
232
|
* ```
|