@rebasepro/types 0.26.0 → 0.28.0

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.
@@ -264,6 +264,11 @@ export interface AuthAdapterCapabilities {
264
264
  anonymousLogin: boolean;
265
265
  /** List of enabled OAuth provider IDs (e.g. `["google", "github"]`). */
266
266
  enabledProviders: string[];
267
+ /**
268
+ * Public client ids, by provider id, for the providers whose sign-in a
269
+ * browser starts with one (Apple's Services ID). Absent when none does.
270
+ */
271
+ providerClientIds?: Record<string, string>;
267
272
  /**
268
273
  * For external auth (Clerk, Auth0, etc.): the URL where the user should
269
274
  * be redirected for login. The Rebase frontend will navigate here instead
@@ -354,6 +354,12 @@ export interface RealtimeProvider {
354
354
  * still look live, so it is reported rather than inferred.
355
355
  */
356
356
  health?(): RealtimeListenerHealth[];
357
+ /**
358
+ * This process's realtime counts, for `/metrics`. Read at each scrape, so
359
+ * it must be cheap. Absent on a provider with nothing to count, and the
360
+ * series are then not emitted rather than reported as zeros.
361
+ */
362
+ counts?(): RealtimeCounts;
357
363
  /**
358
364
  * Run the provider's own background reads — the refetches a change
359
365
  * schedules, whatever announced it (a write here, change capture, another
@@ -375,6 +381,21 @@ export interface RealtimeListenerHealth {
375
381
  /** When (epoch ms) it went down, while it is down. */
376
382
  downSince?: number;
377
383
  }
384
+ /**
385
+ * What one realtime process is carrying. Counts only: a channel's name is
386
+ * customer data and never leaves in a metric.
387
+ * @group Backend
388
+ */
389
+ export interface RealtimeCounts {
390
+ /** Open sockets on this process. */
391
+ sockets: number;
392
+ /** Channels with a member on this process. */
393
+ channels: number;
394
+ /** Frames this process published to the channel bus, by frame kind. */
395
+ busFramesPublished: Record<string, number>;
396
+ /** Broadcasts and presence changes not published because no other instance had members. */
397
+ busFramesSkipped: number;
398
+ }
378
399
  /**
379
400
  * Abstract collection registry interface.
380
401
  * Manages registration and lookup of entity collections.
@@ -569,6 +590,19 @@ export interface SQLAdmin {
569
590
  isolateSession?: boolean;
570
591
  maxResultBytes?: number;
571
592
  }): Promise<Record<string, unknown>[]>;
593
+ /**
594
+ * Ask the database whether it answers, on a connection of its own.
595
+ *
596
+ * For the health check. `executeSql("SELECT 1")` waits for a pooled
597
+ * connection, so a pool that is merely busy (every connection serving a
598
+ * slow request) failed a readiness probe that gives a few seconds — and an
599
+ * orchestrator took a working pod out of service, sending its load to the
600
+ * others or, with one pod, to nobody. Implementations open a connection
601
+ * outside the pool, run the cheapest round trip, and throw if that does not
602
+ * finish within `timeoutMs`. Optional: without it the health check asks
603
+ * through `executeSql` as before.
604
+ */
605
+ probe?(timeoutMs: number): Promise<void>;
572
606
  /**
573
607
  * Run a script a person wrote — the Studio SQL console — and describe what
574
608
  * it returned.
@@ -61,6 +61,23 @@ export type ChannelBusFrame =
61
61
  channel: string;
62
62
  joins: Record<string, Record<string, unknown>>;
63
63
  leaves: Record<string, Record<string, unknown>>;
64
+ }
65
+ /**
66
+ * Which channels an instance has members in, so the others can skip
67
+ * publishing to channels nobody else is listening on (see
68
+ * {@link ChannelBus.publishesOnDemand}). `add` is a channel's first local
69
+ * member. A full list comes as `list` parts, the last with `done`, and
70
+ * replaces what was known. `hello` asks everyone for theirs. `channel` is
71
+ * always `"__peers"`: a transport drops frames without one.
72
+ */
73
+ | {
74
+ kind: "channels";
75
+ sid: string;
76
+ channel: string;
77
+ add?: string[];
78
+ list?: string[];
79
+ done?: boolean;
80
+ hello?: boolean;
64
81
  };
65
82
  /** Receives frames published by *other* instances. */
66
83
  export type ChannelBusHandler = (frame: ChannelBusFrame) => void | Promise<void>;
@@ -98,6 +115,15 @@ export interface ChannelBus {
98
115
  * whether publishing is worth attempting at all.
99
116
  */
100
117
  readonly kind: string;
118
+ /**
119
+ * Publish only to channels another instance has members in.
120
+ *
121
+ * For a transport where each publish costs something (the Postgres bus: a
122
+ * query on the primary), the service gossips over the bus which channels each
123
+ * instance serves, and a frame nobody else is waiting for is not published
124
+ * at all. An instance alone publishes nothing. Unset: every frame is published.
125
+ */
126
+ readonly publishesOnDemand?: boolean;
101
127
  /**
102
128
  * Largest frame this transport will carry, in bytes of encoded JSON, or
103
129
  * `Infinity` when there is no meaningful ceiling.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Compile-time assertions about `PropertyConditions`.
3
+ *
4
+ * A plain module under `src`, imported by nothing, for the reason
5
+ * `packages/client/src/query-contract.types.ts` gives: `pnpm typecheck` reads
6
+ * `src`, and a type assertion in a jest test is checked by nothing.
7
+ *
8
+ * A dynamic bound is usually a constant. The evaluator returns a literal
9
+ * number as it is, and the docs write `min: 0` — which the type, a JSON Logic
10
+ * rule only, refused.
11
+ */
12
+ import type { PropertyConditions } from "./properties.js";
13
+ export declare const literalBounds: PropertyConditions;
14
+ export declare const ruleBounds: PropertyConditions;
@@ -93,7 +93,11 @@ export interface CronJobDefinition<DB = RegisteredDatabase> {
93
93
  export interface CronJobContext<DB = RegisteredDatabase> {
94
94
  /** The job's unique ID (derived from filename). */
95
95
  jobId: string;
96
- /** The current scheduled tick timestamp. */
96
+ /**
97
+ * The slot this run fires for. A catch-up run gets the slot it missed,
98
+ * not the time it started; a manual trigger, which has no slot, gets the
99
+ * moment the run started.
100
+ */
97
101
  scheduledAt: Date;
98
102
  /**
99
103
  * A simple logger scoped to this job run. Each line is written to the
@@ -326,8 +326,9 @@ export interface BaseProperty<CustomProps = unknown> {
326
326
  *
327
327
  * For secrets the server must store and read but no client should ever
328
328
  * receive — password hashes, verification tokens. The value is still
329
- * written and queryable server-side; it is stripped from every row the API
330
- * serves, for every caller, including admins and service keys, and it is
329
+ * written, and readable server-side through `rebase.sql()` only; it is
330
+ * stripped from every row the API serves, for every caller, including
331
+ * admins, service keys and `rebase.dataAsAdmin` reads, and it is
331
332
  * absent from every generated description of the surface: the SDK's `Row`,
332
333
  * `Insert` and `Update` types, and the OpenAPI schemas, filters and
333
334
  * parameters.
@@ -1501,14 +1502,14 @@ export interface PropertyConditions {
1501
1502
  requiredMessage?: string;
1502
1503
  /**
1503
1504
  * Dynamic minimum value for number/string length.
1504
- * Should evaluate to a number.
1505
+ * A number, or a rule that evaluates to one.
1505
1506
  */
1506
- min?: JsonLogicRule;
1507
+ min?: number | JsonLogicRule;
1507
1508
  /**
1508
1509
  * Dynamic maximum value for number/string length.
1509
- * Should evaluate to a number.
1510
+ * A number, or a rule that evaluates to one.
1510
1511
  */
1511
- max?: JsonLogicRule;
1512
+ max?: number | JsonLogicRule;
1512
1513
  /**
1513
1514
  * Dynamic default value for new entities.
1514
1515
  * Should evaluate to a value of the appropriate type for the field.
@@ -539,9 +539,43 @@ export interface JoinStep {
539
539
  *
540
540
  * When using arrays, both `from` and `to` must have the same length,
541
541
  * and columns are matched by position (index 0 with index 0, etc.).
542
+ *
543
+ * A list of conditions joins a row that meets **any one** of them. That is
544
+ * how a link stored in either of two columns is read: a friendship kept as
545
+ * one row with the smaller account first holds a person in `a` on some rows
546
+ * and in `b` on others, and both are their friends.
547
+ *
548
+ * ```typescript
549
+ * { table: "friendships", on: [{ from: "id", to: "a" }, { from: "id", to: "b" }] }
550
+ * ```
551
+ *
552
+ * A step with two or more alternatives is read-only, whatever its
553
+ * position in the chain: a new link could go in either column, and which
554
+ * one is the application's rule, not something to guess. A list of one is
555
+ * the bare condition, and is read and written the same.
542
556
  */
543
- on: {
544
- from: string | string[];
545
- to: string | string[];
546
- };
557
+ on: JoinCondition | JoinCondition[];
547
558
  }
559
+ /**
560
+ * One way a {@link JoinStep} can match: every `from` column equal to its `to`
561
+ * column.
562
+ * @group Models
563
+ */
564
+ export interface JoinCondition {
565
+ from: string | string[];
566
+ to: string | string[];
567
+ }
568
+ /**
569
+ * The conditions of a join step, as a list: one entry for a plain step, one
570
+ * per alternative for a step that joins on any of several.
571
+ * @group Models
572
+ */
573
+ export declare function joinConditions(step: Pick<JoinStep, "on">): JoinCondition[];
574
+ /**
575
+ * The one condition of a step that has no alternatives — for the write paths,
576
+ * which only run on a writable chain and a chain with alternatives never is.
577
+ * Throws rather than pick one of several: writing a link into the wrong column
578
+ * is the mistake read-only exists to prevent.
579
+ * @group Models
580
+ */
581
+ export declare function soleJoinCondition(step: Pick<JoinStep, "on" | "table">): JoinCondition;
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import { type DeclareOptions, type ResourceDeclaration, type ResourceHandle } from "./resources.js";
15
15
  import { type DataSourceDefinition } from "./data_source.js";
16
- import { type StorageSourceDefinition } from "./storage_source.js";
16
+ import { type OrphanSweepOptions, type StorageSourceDefinition } from "./storage_source.js";
17
17
  /** Options a database accepts beyond the common ones. */
18
18
  export interface DatabaseOptions extends DeclareOptions {
19
19
  /**
@@ -129,6 +129,16 @@ export interface BucketOptions extends DeclareOptions {
129
129
  * their shared account.
130
130
  */
131
131
  account?: string;
132
+ /**
133
+ * Delete, on a schedule, the files in this bucket that no row names:
134
+ * `true` for the defaults, or `{ olderThanHours, schedule }`. See
135
+ * {@link OrphanSweepOptions}.
136
+ *
137
+ * ```ts
138
+ * export const voice = bucket("voice", { engine: "gcs", orphanSweep: { olderThanHours: 72 } });
139
+ * ```
140
+ */
141
+ orphanSweep?: boolean | OrphanSweepOptions;
132
142
  }
133
143
  /** A bucket handle. Storage properties point at it via `storageSource`. */
134
144
  export type BucketHandle = ResourceHandle;
@@ -158,4 +158,57 @@ export interface SchemaEditingAdmin {
158
158
  */
159
159
  sourceOnly?: boolean;
160
160
  }): Promise<SchemaChangePlan>;
161
+ /**
162
+ * What it would take to bring the database's existing columns in line with
163
+ * the collections, beyond what boot does on its own.
164
+ *
165
+ * Boot is additive: it never relaxes a constraint and never drops a column,
166
+ * because nobody reads its plan. This is the reviewed counterpart. It
167
+ * plans `DROP NOT NULL` for every column the collections declare optional
168
+ * and the database still requires, lists every column no collection
169
+ * declares, and drops only the ones named in `drop`. Read-only; applying
170
+ * is `executeSql`, gated by the caller on the plan's `digest`.
171
+ *
172
+ * Optional so a driver that cannot answer stays a valid admin.
173
+ */
174
+ planSchemaReconcile?(collections: unknown[], options?: {
175
+ /** Undeclared columns to drop, as `<collection slug>.<column>`. */
176
+ drop?: string[];
177
+ }): Promise<SchemaReconcilePlan>;
178
+ }
179
+ /** A column that exists in a collection's table and that no property declares. */
180
+ export interface SchemaReconcileColumn {
181
+ /** The collection slug whose table holds it. */
182
+ collection: string;
183
+ /** `schema.table`. */
184
+ table: string;
185
+ column: string;
186
+ /** NOT NULL with no default: every insert through the API fails on it. */
187
+ blocksInserts: boolean;
188
+ /** Rows holding a value in it. Counted only for a column being dropped. */
189
+ rowsWithValue?: number;
190
+ }
191
+ /**
192
+ * The plan `planSchemaReconcile` returns.
193
+ *
194
+ * `digest` identifies exactly these statements. A caller applies a plan only
195
+ * when handed back the digest the person reviewed, so what runs is what was
196
+ * read, and a database that changed in between is planned and shown again.
197
+ */
198
+ export interface SchemaReconcilePlan {
199
+ /** Columns declared optional that the database still requires. */
200
+ relaxed: Array<{
201
+ collection: string;
202
+ table: string;
203
+ column: string;
204
+ }>;
205
+ /** Every column no collection declares, dropped or not. */
206
+ undeclared: SchemaReconcileColumn[];
207
+ /** The undeclared columns this plan drops: the ones `drop` named. */
208
+ dropped: SchemaReconcileColumn[];
209
+ /** In order: every `DROP NOT NULL`, then every `DROP COLUMN`. */
210
+ statements: string[];
211
+ /** Why a requested drop cannot be planned. A plan with problems is not applied. */
212
+ problems: string[];
213
+ digest: string;
161
214
  }
@@ -99,6 +99,40 @@ export interface StorageSourceDefinition {
99
99
  default?: boolean;
100
100
  /** Human-readable label for the UI (e.g. "Firebase Storage", "S3 Media"). */
101
101
  label?: string;
102
+ /**
103
+ * Delete, on a schedule, the files in this source that no row names.
104
+ *
105
+ * Absent, nothing is swept. See {@link OrphanSweepOptions}.
106
+ */
107
+ orphanSweep?: OrphanSweepOptions;
108
+ }
109
+ /**
110
+ * A scheduled sweep of a storage source's unreferenced files.
111
+ *
112
+ * Deleting a row leaves the files it named in the bucket, because a key is not
113
+ * owned by one row: another row, a version in row history, or app code holding
114
+ * the key in a plain string may still name it. So nothing is deleted with the
115
+ * row. The sweep is the same scan as `rebase storage orphans --delete`: every
116
+ * row of every collection and every history entry is read, a file still named
117
+ * anywhere is kept, a file newer than the grace period is kept, and each one is
118
+ * checked again right before it is deleted. A collection the scan cannot read
119
+ * keeps everything, that run.
120
+ *
121
+ * It runs as a cron job, `storage-orphan-sweep-<source>`, so it shows in the
122
+ * admin's cron list with its history, runs on one instance per slot, and can be
123
+ * triggered or paused like any other job.
124
+ *
125
+ * @group Models
126
+ */
127
+ export interface OrphanSweepOptions {
128
+ /**
129
+ * How old an unreferenced file must be before it is deleted, in hours. At
130
+ * least 24, because an upload is written before the row that names it is
131
+ * saved. Defaults to 168 (a week).
132
+ */
133
+ olderThanHours?: number;
134
+ /** When to run, as a cron expression in UTC. Defaults to daily at 04:17. */
135
+ schedule?: string;
102
136
  }
103
137
  /**
104
138
  * A resolved storage source: the single source of truth that the frontend
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/types",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "Rebase type definitions — shared interfaces and controller types",
5
5
  "keywords": [
6
6
  "rebase",