@rebasepro/types 0.11.1-canary.gfd39654 → 0.12.1-canary.g181d0fe
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/dist/controllers/client.d.ts +34 -0
- package/dist/controllers/collection_registry.d.ts +1 -1
- package/dist/controllers/data.d.ts +148 -9
- package/dist/index.es.js +288 -98
- package/dist/index.es.js.map +1 -1
- package/dist/types/admin_block.d.ts +20 -0
- package/dist/types/api_keys.d.ts +60 -5
- package/dist/types/backend.d.ts +19 -0
- package/dist/types/collections.d.ts +56 -31
- package/dist/types/cron.d.ts +31 -0
- package/dist/types/data_source.d.ts +42 -1
- package/dist/types/database_adapter.d.ts +39 -8
- package/dist/types/entity_callbacks.d.ts +2 -2
- package/dist/types/history.d.ts +62 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/postgres_introspection.d.ts +95 -0
- package/dist/types/project_manifest.d.ts +146 -73
- package/dist/types/properties.d.ts +38 -49
- package/dist/types/storage_source.d.ts +60 -0
- package/dist/types/websockets.d.ts +0 -37
- package/package.json +4 -4
- package/src/controllers/client.ts +37 -0
- package/src/controllers/collection_registry.ts +1 -1
- package/src/controllers/data.ts +155 -9
- package/src/types/admin_block.ts +48 -0
- package/src/types/api_keys.ts +61 -5
- package/src/types/backend.ts +22 -0
- package/src/types/collections.ts +68 -39
- package/src/types/cron.ts +32 -0
- package/src/types/data_source.ts +60 -1
- package/src/types/database_adapter.ts +45 -8
- package/src/types/entity_callbacks.ts +2 -2
- package/src/types/history.ts +66 -0
- package/src/types/index.ts +2 -0
- package/src/types/postgres_introspection.ts +101 -0
- package/src/types/project_manifest.ts +149 -80
- package/src/types/properties.ts +43 -56
- package/src/types/storage_source.ts +130 -0
- package/src/types/websockets.ts +0 -42
|
@@ -83,6 +83,20 @@ export interface AuthClient {
|
|
|
83
83
|
* Manually refresh the session token
|
|
84
84
|
*/
|
|
85
85
|
refreshSession(): Promise<RebaseSession>;
|
|
86
|
+
/**
|
|
87
|
+
* Whether a session could exist that this client has not loaded yet.
|
|
88
|
+
*
|
|
89
|
+
* `false` means the only way this client can hold a session is an explicit
|
|
90
|
+
* sign-in during this page's lifetime: it neither persists sessions nor
|
|
91
|
+
* carries an httpOnly auth cookie, so there is nothing on disk or in the
|
|
92
|
+
* browser to restore from. A caller that would otherwise probe the server
|
|
93
|
+
* — `getUser()` on mount, say — can skip it, because the answer is already
|
|
94
|
+
* known and the request can only ever fail.
|
|
95
|
+
*
|
|
96
|
+
* Optional so that alternative {@link AuthClient} implementations need not
|
|
97
|
+
* supply it; treat a missing implementation as "unknown, go ahead and ask".
|
|
98
|
+
*/
|
|
99
|
+
canRestoreSession?: () => boolean;
|
|
86
100
|
}
|
|
87
101
|
/**
|
|
88
102
|
* User record as returned by the Admin API (`GET /admin/users`, etc.).
|
|
@@ -337,6 +351,16 @@ export interface RebaseClient<DB = unknown> {
|
|
|
337
351
|
apiKeys?: ApiKeysAPI;
|
|
338
352
|
/** Base HTTP URL of the backend server */
|
|
339
353
|
baseUrl?: string;
|
|
354
|
+
/**
|
|
355
|
+
* The path every API route is mounted under, appended to {@link baseUrl}.
|
|
356
|
+
*
|
|
357
|
+
* `"/api"` unless the backend was configured with a different `basePath`
|
|
358
|
+
* and the client told to match. Exposed because code that builds a URL by
|
|
359
|
+
* hand — rather than going through the client's own methods — otherwise has
|
|
360
|
+
* to guess, and guessing `/api` is wrong for exactly the projects that set
|
|
361
|
+
* the option.
|
|
362
|
+
*/
|
|
363
|
+
apiPath?: string;
|
|
340
364
|
/** WebSocket client for realtime subscriptions */
|
|
341
365
|
ws?: RebaseWebSocket;
|
|
342
366
|
/** Set the auth token for subsequent requests */
|
|
@@ -435,6 +459,16 @@ export interface RebaseBrowserClient<DB = unknown> {
|
|
|
435
459
|
apiKeys?: ApiKeysAPI;
|
|
436
460
|
/** Base HTTP URL of the backend server */
|
|
437
461
|
baseUrl?: string;
|
|
462
|
+
/**
|
|
463
|
+
* The path every API route is mounted under, appended to {@link baseUrl}.
|
|
464
|
+
*
|
|
465
|
+
* `"/api"` unless the backend was configured with a different `basePath`
|
|
466
|
+
* and the client told to match. Exposed because code that builds a URL by
|
|
467
|
+
* hand — rather than going through the client's own methods — otherwise has
|
|
468
|
+
* to guess, and guessing `/api` is wrong for exactly the projects that set
|
|
469
|
+
* the option.
|
|
470
|
+
*/
|
|
471
|
+
apiPath?: string;
|
|
438
472
|
/** WebSocket client for realtime subscriptions */
|
|
439
473
|
ws?: RebaseWebSocket;
|
|
440
474
|
/** Set the auth token for subsequent requests */
|
|
@@ -6,7 +6,7 @@ import type { EntityReference } from "../types/entities";
|
|
|
6
6
|
*/
|
|
7
7
|
export type CollectionRegistryController<DB = Record<string, unknown>, EC extends CollectionConfig = CollectionConfig> = {
|
|
8
8
|
/**
|
|
9
|
-
* List of the mapped collections in the
|
|
9
|
+
* List of the mapped collections in the admin.
|
|
10
10
|
* Each entry relates to a collection in the root database.
|
|
11
11
|
* Each of the navigation entries in this field
|
|
12
12
|
* generates an entry in the main menu.
|
|
@@ -108,12 +108,12 @@ export interface FindResponse<M extends Record<string, unknown> = Record<string,
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
-
* Fluent query builder for the **admin
|
|
111
|
+
* Fluent query builder for the **admin admin** — resolves to `FindResponse<M>`
|
|
112
112
|
* (Snapshot-wrapped rows).
|
|
113
113
|
*
|
|
114
114
|
* @internal App developers should use {@link SDKQueryBuilderInterface}
|
|
115
115
|
* (flat rows, returned by `client.data.*` / `context.data.*`). This
|
|
116
|
-
* Snapshot-flavored variant backs the admin
|
|
116
|
+
* Snapshot-flavored variant backs the admin admin internals only.
|
|
117
117
|
*
|
|
118
118
|
* @group Data
|
|
119
119
|
*/
|
|
@@ -129,13 +129,13 @@ export interface QueryBuilderInterface<M extends Record<string, unknown> = Recor
|
|
|
129
129
|
listen(onUpdate: (data: FindResponse<M>) => void, onError?: (error: Error) => void): () => void;
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
|
-
* A single collection's CRUD accessor for the **admin
|
|
132
|
+
* A single collection's CRUD accessor for the **admin admin** — every method
|
|
133
133
|
* resolves to `Snapshot`-wrapped rows (`FindResponse<M>` / `Snapshot<M>`).
|
|
134
134
|
*
|
|
135
135
|
* @internal App developers do **not** use this. The public, symmetric surface
|
|
136
136
|
* is {@link SDKCollectionClient} (flat rows), exposed as `client.data.products`
|
|
137
137
|
* in the SDK and `context.data.products` in framework callbacks. This
|
|
138
|
-
* Snapshot-flavored accessor backs the admin
|
|
138
|
+
* Snapshot-flavored accessor backs the admin admin view-model only.
|
|
139
139
|
*
|
|
140
140
|
* @group Data
|
|
141
141
|
*/
|
|
@@ -222,6 +222,86 @@ export interface FindResult<M extends Record<string, unknown> = Record<string, u
|
|
|
222
222
|
/** Pagination metadata */
|
|
223
223
|
meta: PaginationMeta;
|
|
224
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Which column an iteration seeks on, for keyset ("seek") pagination.
|
|
227
|
+
*
|
|
228
|
+
* Either the column name on its own — sorted ascending — or the column plus an
|
|
229
|
+
* explicit direction. The column must be **unique** and must be the column the
|
|
230
|
+
* query is ordered by; see {@link PageWalkOptions.cursor}.
|
|
231
|
+
*
|
|
232
|
+
* @group Data
|
|
233
|
+
*/
|
|
234
|
+
export type CursorSpec<M extends Record<string, unknown> = Record<string, unknown>> = (Extract<keyof M, string>) | {
|
|
235
|
+
field: Extract<keyof M, string>;
|
|
236
|
+
direction?: "asc" | "desc";
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* How {@link SDKCollectionClient.iterate} / {@link SDKCollectionClient.findAll}
|
|
240
|
+
* walk a collection, layered on top of the normal `find()` parameters.
|
|
241
|
+
*
|
|
242
|
+
* @group Data
|
|
243
|
+
*/
|
|
244
|
+
export interface PageWalkOptions<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
245
|
+
/**
|
|
246
|
+
* Rows fetched per request. Defaults to 200; values below 1 are clamped up.
|
|
247
|
+
* This is the request size, not a result cap — the iteration keeps going
|
|
248
|
+
* until the server says there is nothing left.
|
|
249
|
+
*/
|
|
250
|
+
pageSize?: number;
|
|
251
|
+
/**
|
|
252
|
+
* Paginate by **seeking on a column** instead of by offset.
|
|
253
|
+
*
|
|
254
|
+
* Offset paging — the default — re-counts rows on every request, so a row
|
|
255
|
+
* inserted or deleted *while the iteration runs* shifts the window and the
|
|
256
|
+
* walk silently skips or repeats rows. Seeking is immune to that: each page
|
|
257
|
+
* asks for rows strictly after the last one seen, so concurrent writes
|
|
258
|
+
* before the cursor cannot move it.
|
|
259
|
+
*
|
|
260
|
+
* Prefer this whenever the collection has a unique, sortable column
|
|
261
|
+
* (typically its primary key). The column must be unique — a repeated value
|
|
262
|
+
* at a page boundary either skips rows or stalls, and the iterator throws
|
|
263
|
+
* rather than looping — and the query is ordered by it, so a `cursor` and a
|
|
264
|
+
* conflicting `orderBy` is an error, not a silent override.
|
|
265
|
+
*
|
|
266
|
+
* Implemented with the parameters `find()` already takes (an `orderBy` plus
|
|
267
|
+
* a `>` / `<` filter on the cursor column), so it works on every transport
|
|
268
|
+
* and needs nothing new from the server.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* for await (const job of client.data.jobs.iterate({ cursor: "id" })) { … }
|
|
272
|
+
*/
|
|
273
|
+
cursor?: CursorSpec<M>;
|
|
274
|
+
/**
|
|
275
|
+
* Hard ceiling on the number of requests one walk may make, so a server
|
|
276
|
+
* that never stops saying `hasMore` cannot spin forever. Defaults to
|
|
277
|
+
* 10 000 pages; hitting it throws.
|
|
278
|
+
*/
|
|
279
|
+
maxPages?: number;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Parameters accepted by {@link SDKCollectionClient.iterate} — everything
|
|
283
|
+
* `find()` takes except the window itself (`limit`, `offset`, `page`), which
|
|
284
|
+
* the iterator owns, plus the walk options.
|
|
285
|
+
*
|
|
286
|
+
* @group Data
|
|
287
|
+
*/
|
|
288
|
+
export type IterateParams<M extends Record<string, unknown> = Record<string, unknown>> = Omit<FindParams<M>, "limit" | "offset" | "page"> & PageWalkOptions<M>;
|
|
289
|
+
/**
|
|
290
|
+
* Parameters accepted by {@link SDKCollectionClient.findAll}: the iteration
|
|
291
|
+
* parameters plus the ceiling that keeps a whole collection from being pulled
|
|
292
|
+
* into memory unnoticed.
|
|
293
|
+
*
|
|
294
|
+
* @group Data
|
|
295
|
+
*/
|
|
296
|
+
export type FindAllParams<M extends Record<string, unknown> = Record<string, unknown>> = IterateParams<M> & {
|
|
297
|
+
/**
|
|
298
|
+
* Most rows to materialise. Defaults to 10 000. Exceeding it **throws**
|
|
299
|
+
* — a truncated array returned as if it were the whole answer is the
|
|
300
|
+
* kind of quiet wrong that shows up months later in a report. Pass
|
|
301
|
+
* `Infinity` to opt out deliberately, or use `iterate()` to stream.
|
|
302
|
+
*/
|
|
303
|
+
maxRows?: number;
|
|
304
|
+
};
|
|
225
305
|
/**
|
|
226
306
|
* Fluent Query Builder Interface for the SDK client.
|
|
227
307
|
* Returns `FindResult<M>` (flat rows) instead of `FindResponse<M>` (Entity-wrapped).
|
|
@@ -244,7 +324,7 @@ export interface SDKQueryBuilderInterface<M extends Record<string, unknown> = Re
|
|
|
244
324
|
* SDK collection client — returns flat rows, no Entity wrapper.
|
|
245
325
|
*
|
|
246
326
|
* This is the public API surface for app developers using
|
|
247
|
-
* `createRebaseClient()`.
|
|
327
|
+
* `createRebaseClient()`. admin internals use `CollectionAccessor` instead.
|
|
248
328
|
*
|
|
249
329
|
* Type parameters:
|
|
250
330
|
* - `M` — the **Row** shape returned by reads (`find`, `findById`, `listen`).
|
|
@@ -290,6 +370,65 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
|
|
|
290
370
|
* Find multiple records with optional filtering, pagination, and sorting.
|
|
291
371
|
*/
|
|
292
372
|
find(params?: FindParams<M>): Promise<FindResult<M>>;
|
|
373
|
+
/**
|
|
374
|
+
* Walk every record matching a query, one row at a time, fetching pages as
|
|
375
|
+
* the consumer consumes them.
|
|
376
|
+
*
|
|
377
|
+
* This is the pagination primitive: `find()` returns one window, `iterate()`
|
|
378
|
+
* returns all of them without the caller hand-rolling the
|
|
379
|
+
* `limit` / `offset += ` / "am I done yet" loop. Nothing is buffered — rows
|
|
380
|
+
* are yielded as each page arrives, so a million-row walk costs one page of
|
|
381
|
+
* memory. `break` stops the walk and no further requests are made.
|
|
382
|
+
*
|
|
383
|
+
* Termination is driven by the server's `meta.hasMore`, never by comparing
|
|
384
|
+
* a page's length against the requested limit — a final page that happens
|
|
385
|
+
* to be exactly full is indistinguishable that way, and a walk that stops
|
|
386
|
+
* there drops rows. An empty page also ends the walk, and
|
|
387
|
+
* {@link PageWalkOptions.maxPages} bounds a server that never stops saying
|
|
388
|
+
* there is more.
|
|
389
|
+
*
|
|
390
|
+
* ## Consistency
|
|
391
|
+
*
|
|
392
|
+
* By default this pages by **offset**, which is only as stable as the table
|
|
393
|
+
* is still: a row inserted or deleted ahead of the cursor between two
|
|
394
|
+
* requests shifts every later window, so the walk can skip a row or hand
|
|
395
|
+
* back the same one twice. That is inherent to offset paging, not a bug
|
|
396
|
+
* here. On a collection with a unique sortable column, pass
|
|
397
|
+
* {@link PageWalkOptions.cursor} to seek on it instead — the walk then
|
|
398
|
+
* asks for rows strictly after the last one it saw, which concurrent writes
|
|
399
|
+
* cannot perturb.
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* for await (const job of client.data.jobs.iterate({
|
|
403
|
+
* where: { status: ["==", "queued"] },
|
|
404
|
+
* cursor: "id",
|
|
405
|
+
* pageSize: 500
|
|
406
|
+
* })) {
|
|
407
|
+
* await handle(job);
|
|
408
|
+
* }
|
|
409
|
+
*/
|
|
410
|
+
iterate(params?: IterateParams<M>): AsyncIterableIterator<M>;
|
|
411
|
+
/**
|
|
412
|
+
* {@link iterate}, collected into an array.
|
|
413
|
+
*
|
|
414
|
+
* Convenient when the result is known to be small and awkward to stream.
|
|
415
|
+
* Because "known to be small" is an assumption and not a fact, the result is
|
|
416
|
+
* capped — 10 000 rows by default — and going over the cap **throws**
|
|
417
|
+
* rather than returning a short array that reads like a complete one. Raise
|
|
418
|
+
* {@link FindAllParams.maxRows} when the data really is bigger, or switch to
|
|
419
|
+
* `iterate()` and stream it.
|
|
420
|
+
*
|
|
421
|
+
* The offset-drift caveat on {@link iterate} applies here too.
|
|
422
|
+
*
|
|
423
|
+
* @throws When more rows match than `maxRows` allows.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* const overdue = await client.data.invoices.findAll({
|
|
427
|
+
* where: { due_at: ["<", today] },
|
|
428
|
+
* cursor: "id"
|
|
429
|
+
* });
|
|
430
|
+
*/
|
|
431
|
+
findAll(params?: FindAllParams<M>): Promise<M[]>;
|
|
293
432
|
/**
|
|
294
433
|
* Find a single record by its ID.
|
|
295
434
|
*/
|
|
@@ -367,16 +506,16 @@ export interface SDKCollectionClient<M extends Record<string, unknown> = Record<
|
|
|
367
506
|
include(...relations: string[]): SDKQueryBuilderInterface<M>;
|
|
368
507
|
}
|
|
369
508
|
/**
|
|
370
|
-
* The unified data access object for the **admin
|
|
509
|
+
* The unified data access object for the **admin admin** (Entity-shaped).
|
|
371
510
|
*
|
|
372
511
|
* Access collections as dynamic properties: `data.products.find(...)`. Each
|
|
373
512
|
* accessor returns `Entity`-wrapped records (`{ id, path, values }`) — the
|
|
374
|
-
* view-model the
|
|
513
|
+
* view-model the admin renders. This is what `useData()` / the admin
|
|
375
514
|
* `RebaseContext.data` are backed by.
|
|
376
515
|
*
|
|
377
516
|
* @internal App developers do **not** use this — they use
|
|
378
517
|
* {@link RebaseSdkData} (flat rows), which is what the SDK client and backend
|
|
379
|
-
* `context.data` expose. This Entity-shaped map backs the admin
|
|
518
|
+
* `context.data` expose. This Entity-shaped map backs the admin admin only.
|
|
380
519
|
*
|
|
381
520
|
* @group Data
|
|
382
521
|
*/
|
|
@@ -415,7 +554,7 @@ export type RebaseData<DB = unknown> = {
|
|
|
415
554
|
*
|
|
416
555
|
* Every accessor returns flat rows (the table's columns) via
|
|
417
556
|
* {@link SDKCollectionClient} — access fields directly (`row.title`), never
|
|
418
|
-
* `row.values.title`. The admin
|
|
557
|
+
* `row.values.title`. The admin uses {@link RebaseData} (Entity) instead.
|
|
419
558
|
*
|
|
420
559
|
* @example
|
|
421
560
|
* // Frontend SDK
|