@rebasepro/types 0.27.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.
- package/dist/controllers/client.d.ts +9 -3
- package/dist/index.es.js +42 -2
- package/dist/index.es.js.map +1 -1
- package/dist/types/properties.d.ts +3 -2
- package/dist/types/relations.d.ts +38 -4
- package/dist/types/resource_kinds.d.ts +11 -1
- package/dist/types/schema_editing.d.ts +53 -0
- package/dist/types/storage_source.d.ts +34 -0
- package/package.json +1 -1
|
@@ -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
|
|
330
|
-
* serves, for every caller, including
|
|
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.
|
|
@@ -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
|