@rebasepro/types 0.34.2 → 0.35.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 +23 -1
- package/dist/index.es.js +594 -5
- package/dist/index.es.js.map +1 -1
- package/dist/schema/column_options.d.ts +6 -0
- package/dist/schema/columns.d.ts +12 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/rpc.d.ts +148 -0
- package/dist/types/backend.d.ts +86 -0
- package/dist/types/database_adapter.d.ts +7 -1
- package/dist/types/project_manifest.d.ts +198 -0
- package/dist/types/storage_authorize.d.ts +54 -0
- package/dist/users/import.d.ts +123 -0
- package/dist/users/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -49,6 +49,10 @@ export interface ColumnStamp {
|
|
|
49
49
|
* - `identity` — `GENERATED BY DEFAULT AS IDENTITY`.
|
|
50
50
|
* - `database` — the database holds a default Rebase does not state and must
|
|
51
51
|
* not drop; a create may omit the column.
|
|
52
|
+
* - `server` — the table's server code (a `beforeSave` hook, the column's
|
|
53
|
+
* `.transform()`) fills the column when a create leaves it out. No DDL
|
|
54
|
+
* default is written; a create may omit the column, and the panel's form
|
|
55
|
+
* lets a record be created without it.
|
|
52
56
|
*
|
|
53
57
|
* @group Schema
|
|
54
58
|
*/
|
|
@@ -64,6 +68,8 @@ export type ColumnDefault = {
|
|
|
64
68
|
kind: "identity";
|
|
65
69
|
} | {
|
|
66
70
|
kind: "database";
|
|
71
|
+
} | {
|
|
72
|
+
kind: "server";
|
|
67
73
|
};
|
|
68
74
|
/** What every `.validate()` accepts. */
|
|
69
75
|
export interface BaseValidation {
|
package/dist/schema/columns.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare const DRIZZLE_REFUSALS: {
|
|
|
41
41
|
/** `.references(() => …)`: a foreign key is a `rel.belongsTo`. */
|
|
42
42
|
readonly references: "A foreign key is a relation in Rebase: write `relations: { author: rel.belongsTo(() => users, { localKey: \"author_id\", onDelete: \"cascade\" }) }`. The relation's key is what `include` names.";
|
|
43
43
|
/** `.$defaultFn()` / `.$default()`: a run-time default function. */
|
|
44
|
-
readonly defaultFn: "Rebase's schema is data, not code: a default is `.default(value)` or `.default(sql`…`)`; the time is `.defaultNow()` or `.onCreateNow()`, the caller `.onCreateUser()`; anything else belongs in `hooks.beforeSave`.";
|
|
44
|
+
readonly defaultFn: "Rebase's schema is data, not code: a default is `.default(value)` or `.default(sql`…`)`; the time is `.defaultNow()` or `.onCreateNow()`, the caller `.onCreateUser()`; anything else belongs in `hooks.beforeSave`, with `.serverDefault()` on the column it fills.";
|
|
45
45
|
/** `.$onUpdate()` / `.$onUpdateFn()`: a run-time update function. */
|
|
46
46
|
readonly onUpdateFn: "Rebase's schema is data, not code: write `.onUpdateNow()` for the time, `.onUpdateUser()` for the caller; anything else belongs in `hooks.beforeSave`.";
|
|
47
47
|
/** `.unique(name, { nulls })`: a named or NULLS NOT DISTINCT constraint. */
|
|
@@ -270,6 +270,17 @@ export declare class ColumnBuilder<TData, TKind extends BuilderKind = BuilderKin
|
|
|
270
270
|
* alone.
|
|
271
271
|
*/
|
|
272
272
|
dbDefault(): ColumnBuilder<TData, TKind, WithDefault<F>>;
|
|
273
|
+
/**
|
|
274
|
+
* The table's own server code fills this column when a create leaves it
|
|
275
|
+
* out: a `hooks.beforeSave` that derives it (a slug from the title), or
|
|
276
|
+
* the column's `.transform()`. A hook is code and cannot be read, so this
|
|
277
|
+
* says what it does: a create may omit the column (the SDK's insert type
|
|
278
|
+
* makes it optional), the panel's form lets a record be created without
|
|
279
|
+
* it, and the descriptor carries `default: { kind: "server" }`. No DDL
|
|
280
|
+
* default is written. A `NOT NULL` column the hook does not fill still
|
|
281
|
+
* fails on the database.
|
|
282
|
+
*/
|
|
283
|
+
serverDefault(): ColumnBuilder<TData, TKind, WithDefault<F>>;
|
|
273
284
|
/**
|
|
274
285
|
* `GENERATED ALWAYS AS (<expression>) STORED`, as Drizzle writes it:
|
|
275
286
|
* `.generatedAlwaysAs(sql\`lower(email)\`)`. Nobody writes the column.
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { COLUMN_BRAND, ColumnBuilder, col, isColumnBuilder, isSqlTemplate, pgEnu
|
|
|
7
7
|
export * from "./relations.js";
|
|
8
8
|
export * from "./table_options.js";
|
|
9
9
|
export * from "./table.js";
|
|
10
|
+
export * from "./rpc.js";
|
|
10
11
|
export * from "./descriptor.js";
|
|
11
12
|
export * from "./infer.js";
|
|
12
13
|
export * from "./table_patch.js";
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { AnyJsonField, JsonObjectOf } from "./json.js";
|
|
2
|
+
/** The brand of a `defineRpc` result. */
|
|
3
|
+
export declare const RPC_BRAND = "rebase.rpc";
|
|
4
|
+
/**
|
|
5
|
+
* Who may call an RPC.
|
|
6
|
+
*
|
|
7
|
+
* - `"public"`: anyone, signed in or not. An anonymous caller runs as the
|
|
8
|
+
* anonymous identity, so the function's own privileges and the tables'
|
|
9
|
+
* row-level security decide what it reaches. Always rate-limited.
|
|
10
|
+
* - `"authenticated"`: any caller with an identity (a session, a guest
|
|
11
|
+
* session, an API key or the service key). Anonymous callers get `401`.
|
|
12
|
+
*
|
|
13
|
+
* @group Schema
|
|
14
|
+
*/
|
|
15
|
+
export type RpcAccess = "public" | "authenticated";
|
|
16
|
+
/**
|
|
17
|
+
* The named arguments an RPC takes: each a `json.*` field, as in a JSON
|
|
18
|
+
* column's shape. A key is the SQL function's parameter name.
|
|
19
|
+
*
|
|
20
|
+
* @group Schema
|
|
21
|
+
*/
|
|
22
|
+
export type RpcArgsShape = Record<string, AnyJsonField>;
|
|
23
|
+
/**
|
|
24
|
+
* A per-caller limit on one RPC: `limit` calls per `windowMs`, counted where
|
|
25
|
+
* the backend counts its function rate limits (`rateLimit` in
|
|
26
|
+
* `@rebasepro/server/functions`).
|
|
27
|
+
*
|
|
28
|
+
* @group Schema
|
|
29
|
+
*/
|
|
30
|
+
export interface RpcRateLimit {
|
|
31
|
+
/** Calls allowed per window, per caller. */
|
|
32
|
+
limit: number;
|
|
33
|
+
/** The sliding window, in milliseconds. */
|
|
34
|
+
windowMs: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The limit a `public` RPC is held to when it declares none: 120 calls a
|
|
38
|
+
* minute per caller.
|
|
39
|
+
*
|
|
40
|
+
* @group Schema
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_PUBLIC_RPC_RATE_LIMIT: RpcRateLimit;
|
|
43
|
+
/**
|
|
44
|
+
* What `defineRpc` takes besides the name.
|
|
45
|
+
*
|
|
46
|
+
* @group Schema
|
|
47
|
+
*/
|
|
48
|
+
export interface RpcConfig<A extends RpcArgsShape = RpcArgsShape> {
|
|
49
|
+
/** Who may call it. See {@link RpcAccess}. */
|
|
50
|
+
access: RpcAccess;
|
|
51
|
+
/**
|
|
52
|
+
* The named arguments, validated before the function runs: a key that is
|
|
53
|
+
* not declared, a `.required()` one that is missing, or a value of the
|
|
54
|
+
* wrong kind is refused with `400`, naming the field. Absent: the
|
|
55
|
+
* function takes no arguments.
|
|
56
|
+
*/
|
|
57
|
+
args?: A;
|
|
58
|
+
/** The Postgres schema the function lives in. Default `"public"`. */
|
|
59
|
+
schema?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Run the call in a read-write transaction. Off by default: the function
|
|
62
|
+
* runs read-only (and may be served by a read replica), so one that
|
|
63
|
+
* inserts, updates or deletes fails until this is set.
|
|
64
|
+
*/
|
|
65
|
+
write?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* A per-caller limit for this function. A `public` RPC is always limited:
|
|
68
|
+
* {@link DEFAULT_PUBLIC_RPC_RATE_LIMIT} when this is absent. An
|
|
69
|
+
* `authenticated` one is limited only when this is set.
|
|
70
|
+
*/
|
|
71
|
+
rateLimit?: RpcRateLimit;
|
|
72
|
+
/** What the function does, for whoever reads the declarations. */
|
|
73
|
+
description?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A SQL function exposed at `POST /api/rpc/<name>`: what `defineRpc` returns.
|
|
77
|
+
* Export it from `backend/schema/index.ts` to serve it.
|
|
78
|
+
*
|
|
79
|
+
* @group Schema
|
|
80
|
+
*/
|
|
81
|
+
export interface RpcDef<N extends string = string, A extends RpcArgsShape = RpcArgsShape> {
|
|
82
|
+
readonly brand: typeof RPC_BRAND;
|
|
83
|
+
/** The SQL function's name, which is also its URL segment. */
|
|
84
|
+
readonly name: N;
|
|
85
|
+
/** What it was defined with, as written. */
|
|
86
|
+
readonly config: RpcConfig<A>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Any RPC, whatever its arguments.
|
|
90
|
+
*
|
|
91
|
+
* @group Schema
|
|
92
|
+
*/
|
|
93
|
+
export interface AnyRpcDef {
|
|
94
|
+
readonly brand: typeof RPC_BRAND;
|
|
95
|
+
readonly name: string;
|
|
96
|
+
readonly config: RpcConfig<RpcArgsShape>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The arguments object an RPC takes, from its type:
|
|
100
|
+
* `RpcArgs<typeof getPublicProposal>`. `.required()` keys are required, the
|
|
101
|
+
* rest optional. Reads the definition structurally, so `import type` is
|
|
102
|
+
* enough.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* import type { getPublicProposal } from "../../backend/schema";
|
|
106
|
+
* const args: RpcArgs<typeof getPublicProposal> = { token };
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @group Schema
|
|
110
|
+
*/
|
|
111
|
+
export type RpcArgs<D> = D extends {
|
|
112
|
+
readonly config: {
|
|
113
|
+
readonly args?: infer A;
|
|
114
|
+
};
|
|
115
|
+
} ? [NonNullable<A>] extends [RpcArgsShape] ? JsonObjectOf<NonNullable<A>> : Record<never, never> : Record<string, unknown>;
|
|
116
|
+
/**
|
|
117
|
+
* Expose a SQL function as `POST /api/rpc/<name>`, with a JSON body of named
|
|
118
|
+
* arguments.
|
|
119
|
+
*
|
|
120
|
+
* Only declared functions are callable. Each call runs as the caller, like
|
|
121
|
+
* `getSql(c)`: an anonymous caller as the anonymous identity, a signed-in one
|
|
122
|
+
* as themselves under the tables' row-level security. A `SECURITY DEFINER`
|
|
123
|
+
* function runs as its owner, as it does anywhere. The answer is the
|
|
124
|
+
* function's result: an array of rows (or values) for a set-returning
|
|
125
|
+
* function, the row or the value for any other.
|
|
126
|
+
*
|
|
127
|
+
* Export the result from `backend/schema/index.ts`, beside the tables.
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* // backend/schema/rpc.ts
|
|
131
|
+
* import { defineRpc, json } from "@rebasepro/server/schema";
|
|
132
|
+
*
|
|
133
|
+
* export const getPublicProposal = defineRpc("get_public_proposal", {
|
|
134
|
+
* access: "public",
|
|
135
|
+
* args: { token: json.string().required() }
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @group Schema
|
|
140
|
+
*/
|
|
141
|
+
export declare function defineRpc<const N extends string, A extends RpcArgsShape = Record<never, never>>(name: N, config: RpcConfig<A>): RpcDef<N, A>;
|
|
142
|
+
/**
|
|
143
|
+
* Whether a value is the result of `defineRpc`, from this copy of the package
|
|
144
|
+
* or another.
|
|
145
|
+
*
|
|
146
|
+
* @group Schema
|
|
147
|
+
*/
|
|
148
|
+
export declare function isRpcDef(value: unknown): value is AnyRpcDef;
|
package/dist/types/backend.d.ts
CHANGED
|
@@ -428,6 +428,23 @@ export interface RealtimeSocketTotals {
|
|
|
428
428
|
*/
|
|
429
429
|
refused: Record<string, number>;
|
|
430
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Passive post-mutation observer attached by framework services (such as
|
|
433
|
+
* zero-code webhooks) without wrapping or replacing the project's declared
|
|
434
|
+
* `globalHooks`.
|
|
435
|
+
*
|
|
436
|
+
* @group Backend
|
|
437
|
+
*/
|
|
438
|
+
export interface TableMutationListener {
|
|
439
|
+
afterSave?: TableHooks["afterSave"];
|
|
440
|
+
afterDelete?: TableHooks["afterDelete"];
|
|
441
|
+
/**
|
|
442
|
+
* Whether this listener wants the writes of the table `slug` at all.
|
|
443
|
+
* Asked per write, so a table nobody listens to keeps the driver's fast
|
|
444
|
+
* paths (batched inserts, the single-statement delete). Absent: every table.
|
|
445
|
+
*/
|
|
446
|
+
watches?(slug: string): boolean;
|
|
447
|
+
}
|
|
431
448
|
/**
|
|
432
449
|
* The table registry a data driver builds for itself and returns on
|
|
433
450
|
* `InitializedDriver.tableRegistry`: the compiled tables it serves, by
|
|
@@ -448,6 +465,11 @@ export interface TableRegistryInterface {
|
|
|
448
465
|
* it is refused at boot.
|
|
449
466
|
*/
|
|
450
467
|
setGlobalHooks?(hooks: TableHooks): void;
|
|
468
|
+
/**
|
|
469
|
+
* Register a passive post-mutation listener (e.g. zero-code webhooks)
|
|
470
|
+
* that runs alongside global/table hooks without altering `globalHooks`.
|
|
471
|
+
*/
|
|
472
|
+
addMutationListener?(listener: TableMutationListener): void;
|
|
451
473
|
/**
|
|
452
474
|
* Replace one table's own hooks after boot (`backend.setTableHooks`).
|
|
453
475
|
* Returns whether this registry serves the table.
|
|
@@ -634,6 +656,15 @@ export interface SQLAdmin {
|
|
|
634
656
|
isolateSession?: boolean;
|
|
635
657
|
maxResultBytes?: number;
|
|
636
658
|
}): Promise<Record<string, unknown>[]>;
|
|
659
|
+
/**
|
|
660
|
+
* Run a sequence of SQL statements inside a single database transaction on
|
|
661
|
+
* one dedicated connection, rolling back atomically if any statement fails.
|
|
662
|
+
*
|
|
663
|
+
* Calling `executeSql("BEGIN")` / `executeSql(stmt)` / `executeSql("COMMIT")`
|
|
664
|
+
* separately checks out a different pooled connection per call on `pg.Pool`;
|
|
665
|
+
* multi-statement DDL transactions must use this method instead.
|
|
666
|
+
*/
|
|
667
|
+
executeSqlTransaction?(statements: readonly string[]): Promise<void>;
|
|
637
668
|
/**
|
|
638
669
|
* Ask the database whether it answers, on a connection of its own.
|
|
639
670
|
*
|
|
@@ -1450,6 +1481,23 @@ export interface BackendBootstrapper {
|
|
|
1450
1481
|
ensureTablePolicies?(tables: readonly CompiledTable[], driverResult?: InitializedDriver, log?: (message: string) => void): Promise<{
|
|
1451
1482
|
applied: number;
|
|
1452
1483
|
}>;
|
|
1484
|
+
/**
|
|
1485
|
+
* Apply the project's own SQL — `backend/sql/*.sql`, the functions,
|
|
1486
|
+
* triggers and CHECKs a table declaration cannot say — as `rebase db push`
|
|
1487
|
+
* does: in file-name order, each new or changed file once, in its own
|
|
1488
|
+
* transaction, recorded by hash. This is how a deploy applies them.
|
|
1489
|
+
*
|
|
1490
|
+
* `dir` is the directory the boot found (a bundle carries it); without one
|
|
1491
|
+
* the adapter falls back to the directory it was constructed with, and
|
|
1492
|
+
* with neither there is nothing to do. Runs after auth initialization and
|
|
1493
|
+
* before {@link ensureTablePolicies}, on the default source only, so a file
|
|
1494
|
+
* may call `rebase.uid()` and a policy may call a function a file defines.
|
|
1495
|
+
*
|
|
1496
|
+
* MUST be safe for several instances booting at once (each file applied
|
|
1497
|
+
* once), and MUST throw, naming the file, when one fails: the boot fails
|
|
1498
|
+
* rather than serve a half-applied schema.
|
|
1499
|
+
*/
|
|
1500
|
+
ensureSqlFiles?(dir: string | undefined, driverResult?: InitializedDriver, log?: (message: string) => void): Promise<SqlFilesOutcome>;
|
|
1453
1501
|
/**
|
|
1454
1502
|
* Create the RLS helper functions on this source's database. See
|
|
1455
1503
|
* `DatabaseAdapter.ensureRlsRuntime`; needed on every source that is not
|
|
@@ -1560,6 +1608,16 @@ export interface InitializedDriver {
|
|
|
1560
1608
|
* Rejecting leaves the driver serving the tables it served before.
|
|
1561
1609
|
*/
|
|
1562
1610
|
refreshTables?(tables: readonly CompiledTable[]): Promise<TableRefreshOutcome>;
|
|
1611
|
+
/**
|
|
1612
|
+
* Re-introspect the live database schema and swap it in without a restart.
|
|
1613
|
+
*
|
|
1614
|
+
* Used in zero-code / database-first BaaS mode whenever DDL runs (through
|
|
1615
|
+
* `/api/admin/db/*`, Studio's SQL console, `POST /api/admin/schema/reload`,
|
|
1616
|
+
* or a PostgreSQL `NOTIFY rebase_schema_changed` event): newly created or
|
|
1617
|
+
* altered tables become reachable on REST, Realtime, OpenAPI, MCP and
|
|
1618
|
+
* `GET /api/schema/tables` immediately.
|
|
1619
|
+
*/
|
|
1620
|
+
reintrospectTables?(): Promise<ReintrospectOutcome>;
|
|
1563
1621
|
/** The underlying database connection (for lifecycle management). */
|
|
1564
1622
|
connection?: DatabaseConnection;
|
|
1565
1623
|
/**
|
|
@@ -1585,6 +1643,23 @@ export type TableRefreshOutcome = {
|
|
|
1585
1643
|
status: "restart";
|
|
1586
1644
|
reason: string;
|
|
1587
1645
|
};
|
|
1646
|
+
/**
|
|
1647
|
+
* Outcome of {@link InitializedDriver.reintrospectTables}.
|
|
1648
|
+
*
|
|
1649
|
+
* @group Backend
|
|
1650
|
+
*/
|
|
1651
|
+
export type ReintrospectOutcome = {
|
|
1652
|
+
status: "served";
|
|
1653
|
+
tables: CompiledTable[];
|
|
1654
|
+
descriptors: import("../schema/descriptor.js").TableDescriptor[];
|
|
1655
|
+
unprotectedTables: {
|
|
1656
|
+
schema: string;
|
|
1657
|
+
table: string;
|
|
1658
|
+
}[];
|
|
1659
|
+
} | {
|
|
1660
|
+
status: "unsupported";
|
|
1661
|
+
reason: string;
|
|
1662
|
+
};
|
|
1588
1663
|
/**
|
|
1589
1664
|
* Result of `BackendBootstrapper.initializeAuth()`.
|
|
1590
1665
|
* @group Backend
|
|
@@ -1620,3 +1695,14 @@ export interface AuthSchemaHealth {
|
|
|
1620
1695
|
/** Auth schema version this runtime expects. */
|
|
1621
1696
|
runtimeVersion?: number;
|
|
1622
1697
|
}
|
|
1698
|
+
/** What {@link BackendBootstrapper.ensureSqlFiles} did with `backend/sql`. */
|
|
1699
|
+
export interface SqlFilesOutcome {
|
|
1700
|
+
/** The directory read, or `undefined` when there was none to read. */
|
|
1701
|
+
dir?: string;
|
|
1702
|
+
/** Files run by this call, in order. */
|
|
1703
|
+
applied: string[];
|
|
1704
|
+
/** Files already applied at their current content (by an earlier boot, a push, or another instance). */
|
|
1705
|
+
unchanged: string[];
|
|
1706
|
+
/** Recorded as applied but no longer present. Nothing they did is undone. */
|
|
1707
|
+
removed: string[];
|
|
1708
|
+
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import type { DataDriver } from "../controllers/data_driver.js";
|
|
23
23
|
import type { CompiledTable } from "../schema/compiled.js";
|
|
24
|
-
import type { DatabaseAdmin, InitializedDriver, RealtimeProvider, RealtimeSocketOptions, BootstrappedAuth } from "./backend.js";
|
|
24
|
+
import type { DatabaseAdmin, InitializedDriver, RealtimeProvider, RealtimeSocketOptions, BootstrappedAuth, SqlFilesOutcome } from "./backend.js";
|
|
25
25
|
import type { HistoryConfig } from "../controllers/client.js";
|
|
26
26
|
/**
|
|
27
27
|
* A `DatabaseAdapter` provides data persistence for Rebase.
|
|
@@ -123,6 +123,12 @@ export interface DatabaseAdapter {
|
|
|
123
123
|
ensureTablePolicies?(tables: readonly CompiledTable[], driverResult?: InitializedDriver, log?: (message: string) => void): Promise<{
|
|
124
124
|
applied: number;
|
|
125
125
|
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Apply `backend/sql/*.sql` — see `BackendBootstrapper.ensureSqlFiles`.
|
|
128
|
+
* Same forwarding requirement as `ensureTableSchema`: a wrapper that drops
|
|
129
|
+
* it deploys a project whose functions and triggers never arrive.
|
|
130
|
+
*/
|
|
131
|
+
ensureSqlFiles?(dir: string | undefined, driverResult?: InitializedDriver, log?: (message: string) => void): Promise<SqlFilesOutcome>;
|
|
126
132
|
/**
|
|
127
133
|
* Create the helper functions the generated policies call (`rebase.uid()`,
|
|
128
134
|
* `rebase.roles()` and their siblings) on THIS source's database.
|
|
@@ -239,6 +239,83 @@ export interface RebaseStaticAppConfig {
|
|
|
239
239
|
* that carry no policy of their own.
|
|
240
240
|
*/
|
|
241
241
|
frameAncestors?: string[];
|
|
242
|
+
/**
|
|
243
|
+
* Requests this app answers with a redirect instead of a file: moved
|
|
244
|
+
* pages, a renamed section, a whole hostname sent to another.
|
|
245
|
+
*
|
|
246
|
+
* `from` is a path on this app's address, absolute and inside its `path`,
|
|
247
|
+
* where `:name` matches one segment and `:name*` (last only) matches the
|
|
248
|
+
* rest of the path, none included. `to` is a path on the same address or
|
|
249
|
+
* an absolute `http(s)://` URL, and every parameter it names is replaced by
|
|
250
|
+
* what `from` captured: `{ "from": "/blog/:slug", "to": "/posts/:slug" }`.
|
|
251
|
+
* `host` and `query` narrow a redirect to one hostname or to a query
|
|
252
|
+
* string holding exact values, and `notHost` to every hostname but one.
|
|
253
|
+
* `status` is 301, 302, 307 or 308, default 308.
|
|
254
|
+
*
|
|
255
|
+
* Checked in declaration order, before the build's files, and the first
|
|
256
|
+
* match answers. The request's query string is kept unless `to` has one
|
|
257
|
+
* of its own. A request {@link RebaseStaticAppConfig.routes} sends to a
|
|
258
|
+
* function is the function's, and is not redirected.
|
|
259
|
+
*
|
|
260
|
+
* An app whose only job is a redirect still declares a directory to
|
|
261
|
+
* serve: `{ "from": "/:path*", "to": "https://www.example.com/:path*" }`
|
|
262
|
+
* on an app at `https://example.com` sends the bare domain to `www`.
|
|
263
|
+
*
|
|
264
|
+
* @see validateStaticRedirect for every rule a redirect is held to.
|
|
265
|
+
*/
|
|
266
|
+
redirects?: RebaseStaticRedirect[];
|
|
267
|
+
/**
|
|
268
|
+
* Serve `x.html` at `/x`, and answer `/x.html` with a 308 to `/x`.
|
|
269
|
+
*
|
|
270
|
+
* For a static site whose pages are files: `/privacidad` serves
|
|
271
|
+
* `privacidad.html`, `/legal/terms` serves `legal/terms.html`. A file or
|
|
272
|
+
* directory of the request's exact name is served first. `index.html`
|
|
273
|
+
* keeps the directory's address: `/docs/index.html` answers 308 to
|
|
274
|
+
* `/docs/`. The query string is kept. Default `false`.
|
|
275
|
+
*/
|
|
276
|
+
cleanUrls?: boolean;
|
|
277
|
+
}
|
|
278
|
+
/** The statuses a static app's redirect may answer with. */
|
|
279
|
+
export declare const STATIC_REDIRECT_STATUSES: readonly [301, 302, 307, 308];
|
|
280
|
+
/** One of {@link STATIC_REDIRECT_STATUSES}. */
|
|
281
|
+
export type RebaseStaticRedirectStatus = typeof STATIC_REDIRECT_STATUSES[number];
|
|
282
|
+
/** The status a redirect answers with when it names none: permanent, method kept. */
|
|
283
|
+
export declare const DEFAULT_STATIC_REDIRECT_STATUS: RebaseStaticRedirectStatus;
|
|
284
|
+
/** Whether `value` is one of {@link STATIC_REDIRECT_STATUSES}. */
|
|
285
|
+
export declare function isStaticRedirectStatus(value: unknown): value is RebaseStaticRedirectStatus;
|
|
286
|
+
/**
|
|
287
|
+
* A request a static app answers with a redirect. See
|
|
288
|
+
* {@link RebaseStaticAppConfig.redirects}.
|
|
289
|
+
*/
|
|
290
|
+
export interface RebaseStaticRedirect {
|
|
291
|
+
/**
|
|
292
|
+
* The path it matches, absolute and inside the app's `path`: literal
|
|
293
|
+
* segments, `:name` for one segment, and `:name*` as the last segment for
|
|
294
|
+
* the rest of the path, none included. A trailing slash on the request is
|
|
295
|
+
* ignored. Matched case-sensitively.
|
|
296
|
+
*/
|
|
297
|
+
from: string;
|
|
298
|
+
/**
|
|
299
|
+
* Where it sends the request: a path on the same address, or an absolute
|
|
300
|
+
* `http://` or `https://` URL. `:name` and `:name*` are replaced by what
|
|
301
|
+
* `from` captured, in its path and query.
|
|
302
|
+
*/
|
|
303
|
+
to: string;
|
|
304
|
+
/** 301, 302, 307 or 308. Default 308. */
|
|
305
|
+
status?: RebaseStaticRedirectStatus;
|
|
306
|
+
/** Only for requests to this hostname, lowercase, e.g. `example.com`. */
|
|
307
|
+
host?: string;
|
|
308
|
+
/**
|
|
309
|
+
* Only for requests to any hostname but this one, lowercase: what
|
|
310
|
+
* `vercel.json` writes as `missing` with `"type": "host"`. Not with
|
|
311
|
+
* `host`, which already names the only hostname it answers on.
|
|
312
|
+
*/
|
|
313
|
+
notHost?: string;
|
|
314
|
+
/**
|
|
315
|
+
* Only for requests whose query string holds each of these parameters
|
|
316
|
+
* with exactly this value. `""` matches `?k` and `?k=`.
|
|
317
|
+
*/
|
|
318
|
+
query?: Record<string, string>;
|
|
242
319
|
}
|
|
243
320
|
/**
|
|
244
321
|
* A path on a static app's address answered by a custom function instead of
|
|
@@ -359,6 +436,78 @@ export declare function matchStaticRoute(route: RebaseStaticRoute, requestPath:
|
|
|
359
436
|
* order breaks ties, which only equal wildcards can have.
|
|
360
437
|
*/
|
|
361
438
|
export declare function compareStaticRoutes(a: RebaseStaticRoute, b: RebaseStaticRoute): number;
|
|
439
|
+
/** A request a static app's redirects are matched against. */
|
|
440
|
+
export interface StaticRedirectRequest {
|
|
441
|
+
/**
|
|
442
|
+
* The request's hostname, lowercase, with no port and no trailing dot —
|
|
443
|
+
* as the runtime normalises the `Host` header.
|
|
444
|
+
*/
|
|
445
|
+
host: string;
|
|
446
|
+
/** The request path, percent-encoded as it arrived (a `URL`'s `pathname`). */
|
|
447
|
+
path: string;
|
|
448
|
+
/** The query string with its `?`, or `""` (a `URL`'s `search`). */
|
|
449
|
+
search: string;
|
|
450
|
+
}
|
|
451
|
+
/** What a matched redirect answers with. */
|
|
452
|
+
export interface StaticRedirectMatch {
|
|
453
|
+
status: RebaseStaticRedirectStatus;
|
|
454
|
+
/** The `Location` header: a path on the same address, or an absolute URL. */
|
|
455
|
+
location: string;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Compile a static app's redirects into the one function that answers a
|
|
459
|
+
* request with the first that matches, in declaration order — `undefined`
|
|
460
|
+
* when none does. Each must have passed {@link validateStaticRedirect}.
|
|
461
|
+
*
|
|
462
|
+
* Shared so every server of a static app answers the same request the same
|
|
463
|
+
* way: `rebase dev`, `rebase start` and `rebase-server` through `serveSPA`,
|
|
464
|
+
* and any other host that serves a built app.
|
|
465
|
+
*/
|
|
466
|
+
export declare function compileStaticRedirects(redirects: readonly RebaseStaticRedirect[]): (request: StaticRedirectRequest) => StaticRedirectMatch | undefined;
|
|
467
|
+
export type StaticRedirectResult = {
|
|
468
|
+
ok: true;
|
|
469
|
+
redirect: RebaseStaticRedirect;
|
|
470
|
+
} | {
|
|
471
|
+
ok: false;
|
|
472
|
+
field?: "from" | "to" | "status" | "host" | "notHost" | "query";
|
|
473
|
+
reason: string;
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Validate one of a static app's redirects against the app's address (its
|
|
477
|
+
* hostname, when its `path` names one, and the path part).
|
|
478
|
+
*
|
|
479
|
+
* Shared for the reason {@link validateStaticRoute} is: the CLI checks a
|
|
480
|
+
* redirect while `rebase.json` is edited, and the runtime checks it again
|
|
481
|
+
* when it loads a bundle. The rules:
|
|
482
|
+
*
|
|
483
|
+
* - `from` is an absolute path with no empty segment, no trailing slash and
|
|
484
|
+
* no segment starting with a dot. A segment is literal text or a parameter
|
|
485
|
+
* — `:name`, or `:name*` as the last segment — and a literal holds no
|
|
486
|
+
* space, `?`, `#`, `\`, `*` or `:`. Its leading literal segments are inside
|
|
487
|
+
* the app's path and not under a prefix the backend owns, since the app is
|
|
488
|
+
* what answers there.
|
|
489
|
+
* - `to` is a path (`/…`, never `//…`) or an absolute `http://` or `https://`
|
|
490
|
+
* URL, with no space or backslash. It names only parameters `from`
|
|
491
|
+
* declares, and none in an absolute URL's scheme, host or port.
|
|
492
|
+
* - `status` is 301, 302, 307 or 308.
|
|
493
|
+
* - `host` is a public hostname, lowercase, and is the app's own when the
|
|
494
|
+
* app has one — on any other the redirect could never match.
|
|
495
|
+
* - `notHost` is a public hostname, lowercase, never with `host`, and never
|
|
496
|
+
* the app's own hostname, on which the redirect could never match.
|
|
497
|
+
* - `query` maps parameter names to the exact string each must hold.
|
|
498
|
+
* - A redirect to a path on the same address that its own `from` matches
|
|
499
|
+
* again is refused: every request it answers would be sent round forever.
|
|
500
|
+
*/
|
|
501
|
+
export declare function validateStaticRedirect(value: unknown, app: AppAddress): StaticRedirectResult;
|
|
502
|
+
/**
|
|
503
|
+
* Where a `cleanUrls` app sends a request for an HTML file by name: `/x.html`
|
|
504
|
+
* to `/x`, and an `index.html` to its directory, `/docs/index.html` to
|
|
505
|
+
* `/docs/`. `undefined` for a path that names no `.html` file.
|
|
506
|
+
*
|
|
507
|
+
* The path is compared as it arrives, percent-encoded; the caller keeps the
|
|
508
|
+
* query string and redirects only when the file exists.
|
|
509
|
+
*/
|
|
510
|
+
export declare function cleanUrlFor(requestPath: string): string | undefined;
|
|
362
511
|
export type FrameAncestorResult = {
|
|
363
512
|
ok: true;
|
|
364
513
|
origin: string;
|
|
@@ -608,6 +757,17 @@ export interface RebaseBundleEntrypoints {
|
|
|
608
757
|
* (the server then knows only the preferences it stores).
|
|
609
758
|
*/
|
|
610
759
|
uiConfig?: string;
|
|
760
|
+
/**
|
|
761
|
+
* The project's `backend/sql` — the functions, triggers and CHECKs a table
|
|
762
|
+
* declaration cannot say — copied as is (drafts, `_`-prefixed, left out).
|
|
763
|
+
* The runtime applies it at boot, after auth and before the policies, as
|
|
764
|
+
* `rebase db push` does: each new or changed file once, in name order,
|
|
765
|
+
* recorded by hash in `rebase.sql_files`.
|
|
766
|
+
*
|
|
767
|
+
* Optional and additive within format 3: absent when the project has no
|
|
768
|
+
* such files, and on bundles built before it existed.
|
|
769
|
+
*/
|
|
770
|
+
sql?: string;
|
|
611
771
|
/**
|
|
612
772
|
* Built static apps to serve from this process, in declaration order.
|
|
613
773
|
*
|
|
@@ -677,6 +837,20 @@ export interface RebaseBundleStatic {
|
|
|
677
837
|
* that predates this field serves `frame-ancestors 'self'`.
|
|
678
838
|
*/
|
|
679
839
|
frameAncestors?: string[];
|
|
840
|
+
/**
|
|
841
|
+
* Requests answered with a redirect before the build's files, copied from
|
|
842
|
+
* the app's declaration — see {@link RebaseStaticAppConfig.redirects}.
|
|
843
|
+
* Each has passed {@link validateStaticRedirect}, and the runtime checks
|
|
844
|
+
* it again. A runtime that predates this field serves the build at those
|
|
845
|
+
* paths instead.
|
|
846
|
+
*/
|
|
847
|
+
redirects?: RebaseStaticRedirect[];
|
|
848
|
+
/**
|
|
849
|
+
* Serve `x.html` at `/x` — see {@link RebaseStaticAppConfig.cleanUrls}.
|
|
850
|
+
* Present only when `true`. A runtime that predates this field answers
|
|
851
|
+
* `/x` as it would without it.
|
|
852
|
+
*/
|
|
853
|
+
cleanUrls?: boolean;
|
|
680
854
|
}
|
|
681
855
|
/**
|
|
682
856
|
* A native module found in the dependency closure.
|
|
@@ -784,6 +958,16 @@ export interface RebaseBundleManifest {
|
|
|
784
958
|
* consumer must treat it as optional rather than as an empty list.
|
|
785
959
|
*/
|
|
786
960
|
functions?: RebaseBundleFunction[];
|
|
961
|
+
/**
|
|
962
|
+
* The files in `entry.sql`, in the order they are applied, with the
|
|
963
|
+
* SHA-256 of each — what `rebase.sql_files` records once a boot has
|
|
964
|
+
* applied it. For inspection: a host can tell which files a deploy will
|
|
965
|
+
* run without opening the bundle. Absent when the bundle carries none.
|
|
966
|
+
*/
|
|
967
|
+
sqlFiles?: {
|
|
968
|
+
name: string;
|
|
969
|
+
hash: string;
|
|
970
|
+
}[];
|
|
787
971
|
hooks: {
|
|
788
972
|
/**
|
|
789
973
|
* Whether the dependency closure contains native code.
|
|
@@ -884,6 +1068,20 @@ export interface RebaseBundleManifest {
|
|
|
884
1068
|
/** ISO-8601. */
|
|
885
1069
|
createdAt: string;
|
|
886
1070
|
};
|
|
1071
|
+
/**
|
|
1072
|
+
* Set only on the platform's stock bundle: what a new Rebase Cloud project
|
|
1073
|
+
* runs before anybody deploys code to it — an introspected backend (no
|
|
1074
|
+
* `entry.tables`) and the admin panel. `version` is the `@rebasepro`
|
|
1075
|
+
* release it was built from.
|
|
1076
|
+
*
|
|
1077
|
+
* Written by `tooling/scripts/build-stock-bundle.mts` and by nothing a
|
|
1078
|
+
* project builds, so a host can tell "this project serves no code of its
|
|
1079
|
+
* own yet" from "this project's code declares no tables". The runtime does
|
|
1080
|
+
* not read it: a stock bundle boots like any other.
|
|
1081
|
+
*/
|
|
1082
|
+
stock?: {
|
|
1083
|
+
version: string;
|
|
1084
|
+
};
|
|
887
1085
|
}
|
|
888
1086
|
/** The contract a running backend serves at `GET /api/meta/contract`. */
|
|
889
1087
|
export interface RebaseProjectContract {
|
|
@@ -14,6 +14,7 @@ export interface StorageAuthorizeUser {
|
|
|
14
14
|
uid: string;
|
|
15
15
|
email?: string;
|
|
16
16
|
roles?: string[];
|
|
17
|
+
claims?: Record<string, unknown>;
|
|
17
18
|
}
|
|
18
19
|
export interface StorageAuthorizeContext {
|
|
19
20
|
/** Object key, bucket prefix stripped and traversal already sanitized. */
|
|
@@ -81,3 +82,56 @@ export interface StorageAuthorizeData {
|
|
|
81
82
|
* Return false (or throw) to deny. Denials surface as 403.
|
|
82
83
|
*/
|
|
83
84
|
export type StorageAuthorize = (ctx: StorageAuthorizeContext) => boolean | Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Who a {@link StorageRule} grants to — data only, so it can live in an
|
|
87
|
+
* environment variable and be edited in a console:
|
|
88
|
+
*
|
|
89
|
+
* - `"public"` — anyone, signed in or not
|
|
90
|
+
* - `"authenticated"` — any signed-in caller
|
|
91
|
+
* - `"owner"` — the signed-in caller whose uid is the key's `:uid` segment
|
|
92
|
+
* (the rule's `path` must capture one)
|
|
93
|
+
* - `{ roles: [...] }` — a signed-in caller holding any of these roles
|
|
94
|
+
*
|
|
95
|
+
* @group Storage
|
|
96
|
+
*/
|
|
97
|
+
export type StorageRuleAllow = "public" | "authenticated" | "owner" | {
|
|
98
|
+
roles: string[];
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* One storage access rule, as data: the form `STORAGE_POLICIES` takes (a JSON
|
|
102
|
+
* array of these), for a deployment that runs no code of its own — the managed
|
|
103
|
+
* runtime, Rebase Cloud's console. The same deny-by-default list as
|
|
104
|
+
* `storagePolicies`: a key no rule matches is refused, and a rule that matched
|
|
105
|
+
* and did not grant is a denial.
|
|
106
|
+
*
|
|
107
|
+
* ```json
|
|
108
|
+
* [
|
|
109
|
+
* { "path": "public/**", "operations": ["read"], "allow": "public" },
|
|
110
|
+
* { "path": "users/:uid/**", "allow": "owner" },
|
|
111
|
+
* { "path": "**", "allow": { "roles": ["admin"] } }
|
|
112
|
+
* ]
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @group Storage
|
|
116
|
+
*/
|
|
117
|
+
export interface StorageRule {
|
|
118
|
+
/**
|
|
119
|
+
* A key pattern, matched segment by segment: a literal matches itself,
|
|
120
|
+
* `*` one segment, `:name` one segment and captures it, `**` the rest
|
|
121
|
+
* (final segment only).
|
|
122
|
+
*/
|
|
123
|
+
path: string;
|
|
124
|
+
/** Which operations it grants. Every one of them when omitted. */
|
|
125
|
+
operations?: StorageOperation[];
|
|
126
|
+
allow: StorageRuleAllow;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Where a project with no storage rules of its own starts — what Rebase
|
|
130
|
+
* Cloud gives a new project and what its console offers as "recommended":
|
|
131
|
+
* a `public/` folder anyone may read, a `users/<uid>/` folder only its user
|
|
132
|
+
* may touch, and every key to admins. Rules are deny-by-default, so this is
|
|
133
|
+
* also everything a caller may do.
|
|
134
|
+
*
|
|
135
|
+
* @group Storage
|
|
136
|
+
*/
|
|
137
|
+
export declare const RECOMMENDED_STORAGE_RULES: readonly StorageRule[];
|