@rebasepro/types 0.25.1 → 0.27.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/call_context.d.ts +18 -0
- package/dist/controllers/client.d.ts +78 -2
- package/dist/controllers/data_driver.d.ts +22 -0
- package/dist/controllers/storage.d.ts +112 -0
- package/dist/index.es.js +122 -1
- package/dist/index.es.js.map +1 -1
- package/dist/types/api_keys.d.ts +20 -0
- package/dist/types/auth_adapter.d.ts +88 -0
- package/dist/types/backend.d.ts +309 -1
- package/dist/types/channel_bus.d.ts +26 -0
- package/dist/types/conditions-contract.types.d.ts +14 -0
- package/dist/types/cron.d.ts +5 -1
- package/dist/types/properties.d.ts +7 -7
- package/dist/types/relations.d.ts +17 -6
- package/dist/types/scopes.d.ts +14 -0
- package/dist/users/user.d.ts +8 -0
- package/package.json +1 -4
package/dist/types/api_keys.d.ts
CHANGED
|
@@ -24,6 +24,26 @@ import type { ScopeSummary } from "./scopes.js";
|
|
|
24
24
|
* @group Models
|
|
25
25
|
*/
|
|
26
26
|
export type ApiKeyKind = "service" | "personal";
|
|
27
|
+
/**
|
|
28
|
+
* The API key a request authenticated with, as server-side code sees it:
|
|
29
|
+
* `context.credential` in a collection callback, and `credential` on the
|
|
30
|
+
* identity the request's driver is scoped to.
|
|
31
|
+
*
|
|
32
|
+
* It tells a write made with a key from the same person's own session. A
|
|
33
|
+
* personal key acts as its owner, so `context.user` is the owner either way;
|
|
34
|
+
* this is what says "the CI token did it" rather than "Ada did it". Never the
|
|
35
|
+
* secret: only what the key list shows.
|
|
36
|
+
*
|
|
37
|
+
* @group Models
|
|
38
|
+
*/
|
|
39
|
+
export interface CallerCredential {
|
|
40
|
+
/** `"personal"` acts as its owner (`context.user`); `"service"` as the key itself. */
|
|
41
|
+
kind: ApiKeyKind;
|
|
42
|
+
/** The key's id, as `GET /api/auth/keys` lists it. */
|
|
43
|
+
id: string;
|
|
44
|
+
/** The name the key was given when it was created. */
|
|
45
|
+
name: string;
|
|
46
|
+
}
|
|
27
47
|
/**
|
|
28
48
|
* An API key with the secret masked — what list / get / update return.
|
|
29
49
|
* @group Models
|
|
@@ -65,6 +65,89 @@ export interface MountableRouter {
|
|
|
65
65
|
* @group Auth
|
|
66
66
|
*/
|
|
67
67
|
export declare const IMPERSONATE_HEADER = "x-rebase-impersonate";
|
|
68
|
+
/**
|
|
69
|
+
* The request header that asks for a data-plane request to run as a role —
|
|
70
|
+
* the RLS simulator's "view as". Alone it runs as a signed-in holder of that
|
|
71
|
+
* role who owns no rows; with {@link SIMULATE_USER_ID_HEADER} it runs as that
|
|
72
|
+
* uid holding that role, whether or not such an account exists.
|
|
73
|
+
*
|
|
74
|
+
* `anon` (or `anonymous`) runs as a caller with no session at all.
|
|
75
|
+
*
|
|
76
|
+
* Like {@link IMPERSONATE_HEADER}, only a signed-in administrator's own session
|
|
77
|
+
* may send it; anyone else is refused with 403, never answered as themselves.
|
|
78
|
+
*
|
|
79
|
+
* @group Auth
|
|
80
|
+
*/
|
|
81
|
+
export declare const SIMULATE_ROLE_HEADER = "x-rebase-simulate-role";
|
|
82
|
+
/**
|
|
83
|
+
* The uid a simulated request runs as. With {@link SIMULATE_ROLE_HEADER} it is
|
|
84
|
+
* a hypothetical — "u_1 holding customer" — and need not name an account;
|
|
85
|
+
* without it, the uid must be an active user and runs with their roles now.
|
|
86
|
+
*
|
|
87
|
+
* @group Auth
|
|
88
|
+
*/
|
|
89
|
+
export declare const SIMULATE_USER_ID_HEADER = "x-rebase-simulate-user-id";
|
|
90
|
+
/**
|
|
91
|
+
* The id of a service API key a simulated request runs as: the key's identity,
|
|
92
|
+
* its RLS roles and its scopes, exactly as a request presenting the key would.
|
|
93
|
+
* Excludes the other two simulation headers.
|
|
94
|
+
*
|
|
95
|
+
* @group Auth
|
|
96
|
+
*/
|
|
97
|
+
export declare const SIMULATE_API_KEY_ID_HEADER = "x-rebase-simulate-api-key-id";
|
|
98
|
+
/**
|
|
99
|
+
* The response header naming what a simulated request ran as:
|
|
100
|
+
* `role=<role>;sub=<uid>;masked_columns=<a,b>`, plus `api_key=<id>` and
|
|
101
|
+
* `collection=<slug>` when they apply. Every value is URI-encoded. Read it
|
|
102
|
+
* with {@link parseSimulatedContext}.
|
|
103
|
+
*
|
|
104
|
+
* @group Auth
|
|
105
|
+
*/
|
|
106
|
+
export declare const SIMULATED_CONTEXT_HEADER = "x-rebase-simulated-context";
|
|
107
|
+
/**
|
|
108
|
+
* What an administrator asks a request to run as. Exactly one of these
|
|
109
|
+
* shapes is honoured: a role (optionally with a uid), a uid alone (an existing
|
|
110
|
+
* user, with their roles), or an API key id alone.
|
|
111
|
+
*
|
|
112
|
+
* @group Auth
|
|
113
|
+
*/
|
|
114
|
+
export interface AccessSimulation {
|
|
115
|
+
role?: string;
|
|
116
|
+
userId?: string;
|
|
117
|
+
apiKeyId?: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The request headers for an {@link AccessSimulation}. Empty when it asks for
|
|
121
|
+
* nothing, so spreading it into a header set is always safe.
|
|
122
|
+
*
|
|
123
|
+
* @group Auth
|
|
124
|
+
*/
|
|
125
|
+
export declare function simulationHeaders(simulation: AccessSimulation | null | undefined): Record<string, string>;
|
|
126
|
+
/**
|
|
127
|
+
* What {@link SIMULATED_CONTEXT_HEADER} says a request ran as.
|
|
128
|
+
*
|
|
129
|
+
* @group Auth
|
|
130
|
+
*/
|
|
131
|
+
export interface SimulatedContext {
|
|
132
|
+
role: string;
|
|
133
|
+
sub: string;
|
|
134
|
+
maskedColumns: string[];
|
|
135
|
+
apiKeyId?: string;
|
|
136
|
+
collection?: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Write a {@link SimulatedContext} as the header value.
|
|
140
|
+
*
|
|
141
|
+
* @group Auth
|
|
142
|
+
*/
|
|
143
|
+
export declare function formatSimulatedContext(context: SimulatedContext): string;
|
|
144
|
+
/**
|
|
145
|
+
* Read {@link SIMULATED_CONTEXT_HEADER}. `undefined` for an absent header or one
|
|
146
|
+
* missing `role` or `sub`.
|
|
147
|
+
*
|
|
148
|
+
* @group Auth
|
|
149
|
+
*/
|
|
150
|
+
export declare function parseSimulatedContext(value: string | null | undefined): SimulatedContext | undefined;
|
|
68
151
|
/**
|
|
69
152
|
* The normalized user object returned by `AuthAdapter.verifyRequest()`.
|
|
70
153
|
*
|
|
@@ -181,6 +264,11 @@ export interface AuthAdapterCapabilities {
|
|
|
181
264
|
anonymousLogin: boolean;
|
|
182
265
|
/** List of enabled OAuth provider IDs (e.g. `["google", "github"]`). */
|
|
183
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>;
|
|
184
272
|
/**
|
|
185
273
|
* For external auth (Clerk, Auth0, etc.): the URL where the user should
|
|
186
274
|
* be redirected for login. The Rebase frontend will navigate here instead
|
package/dist/types/backend.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { HistoryConfig } from "../controllers/client.js";
|
|
|
7
7
|
import type { ChannelBusSetting } from "./channel_bus.js";
|
|
8
8
|
import type { SchemaEditingAdmin } from "./schema_editing.js";
|
|
9
9
|
import type { AccessModel } from "./scopes.js";
|
|
10
|
+
import type { ApiKeyKind } from "./api_keys.js";
|
|
10
11
|
/**
|
|
11
12
|
* Abstract database connection interface.
|
|
12
13
|
* Represents a connection to any database system.
|
|
@@ -353,6 +354,20 @@ export interface RealtimeProvider {
|
|
|
353
354
|
* still look live, so it is reported rather than inferred.
|
|
354
355
|
*/
|
|
355
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;
|
|
363
|
+
/**
|
|
364
|
+
* Run the provider's own background reads — the refetches a change
|
|
365
|
+
* schedules, whatever announced it (a write here, change capture, another
|
|
366
|
+
* instance) — through `run`. The server passes one that enters the backend
|
|
367
|
+
* owning this provider, so a hook such a read reaches sees that backend as
|
|
368
|
+
* `rebase`. Without it they run in the context of whatever scheduled them.
|
|
369
|
+
*/
|
|
370
|
+
setScopeRunner?(run: <T>(fn: () => T) => T): void;
|
|
356
371
|
}
|
|
357
372
|
/**
|
|
358
373
|
* One long-lived realtime connection, as `/health` reports it.
|
|
@@ -366,6 +381,21 @@ export interface RealtimeListenerHealth {
|
|
|
366
381
|
/** When (epoch ms) it went down, while it is down. */
|
|
367
382
|
downSince?: number;
|
|
368
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
|
+
}
|
|
369
399
|
/**
|
|
370
400
|
* Abstract collection registry interface.
|
|
371
401
|
* Manages registration and lookup of entity collections.
|
|
@@ -560,6 +590,19 @@ export interface SQLAdmin {
|
|
|
560
590
|
isolateSession?: boolean;
|
|
561
591
|
maxResultBytes?: number;
|
|
562
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>;
|
|
563
606
|
/**
|
|
564
607
|
* Run a script a person wrote — the Studio SQL console — and describe what
|
|
565
608
|
* it returned.
|
|
@@ -697,6 +740,13 @@ export interface BranchInfo {
|
|
|
697
740
|
createdAt: Date;
|
|
698
741
|
/** Size in bytes, if available from the server. */
|
|
699
742
|
sizeBytes?: number;
|
|
743
|
+
/**
|
|
744
|
+
* The transaction that created the branch database, recorded when it was
|
|
745
|
+
* made: the fork point a branch diff tells the two sides' writes apart by.
|
|
746
|
+
* Absent for a branch made before it was recorded, or by a server that
|
|
747
|
+
* does not record it.
|
|
748
|
+
*/
|
|
749
|
+
forkXid?: string;
|
|
700
750
|
}
|
|
701
751
|
/**
|
|
702
752
|
* Administrative operations for database branching.
|
|
@@ -715,6 +765,250 @@ export interface BranchAdmin {
|
|
|
715
765
|
listBranches(): Promise<BranchInfo[]>;
|
|
716
766
|
/** Get info about a specific branch. */
|
|
717
767
|
getBranchInfo(name: string): Promise<BranchInfo | undefined>;
|
|
768
|
+
/**
|
|
769
|
+
* What the branch changed, against the database it was made from: its
|
|
770
|
+
* tables, columns, constraints, indexes, triggers, row-level-security
|
|
771
|
+
* policies, enum types, views and functions, and per table the rows it
|
|
772
|
+
* inserted, updated and deleted. Reads only.
|
|
773
|
+
*/
|
|
774
|
+
diffBranch?(name: string, options?: BranchDiffOptions): Promise<BranchDiff>;
|
|
775
|
+
/**
|
|
776
|
+
* Apply the rows the branch changed to the database it was made from. See
|
|
777
|
+
* {@link BranchMergeOptions} for what wins, and when nothing is written.
|
|
778
|
+
*/
|
|
779
|
+
mergeBranch?(name: string, options: BranchMergeOptions): Promise<BranchMergeResult>;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* What {@link BranchAdmin.diffBranch} compares.
|
|
783
|
+
* @group Admin
|
|
784
|
+
*/
|
|
785
|
+
export interface BranchDiffOptions {
|
|
786
|
+
/** Rows shown per table, across every kind of change. Default 100, at most 1,000. */
|
|
787
|
+
sampleLimit?: number;
|
|
788
|
+
/** Schemas to compare. Default: every schema but the system's, without Rebase's own tables. */
|
|
789
|
+
schemas?: string[];
|
|
790
|
+
/**
|
|
791
|
+
* Rows a table may hold, on either side, for its rows to be matched one by
|
|
792
|
+
* one. A larger table that differs is reported with its row counts only,
|
|
793
|
+
* and cannot be merged. Default 100,000.
|
|
794
|
+
*/
|
|
795
|
+
maxRowsPerTable?: number;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* One change to the schema: a table, a column, a policy, a table's row-level
|
|
799
|
+
* security, a constraint (unique, foreign key, check, exclusion), an index, a
|
|
800
|
+
* trigger — or, outside any table, an enum type, a view or a function.
|
|
801
|
+
* @group Admin
|
|
802
|
+
*/
|
|
803
|
+
export interface BranchSchemaChange {
|
|
804
|
+
object: "table" | "column" | "policy" | "rls" | "constraint" | "index" | "trigger" | "enum" | "view" | "function";
|
|
805
|
+
change: "added" | "dropped" | "altered";
|
|
806
|
+
schema: string;
|
|
807
|
+
/**
|
|
808
|
+
* The table the change is on — or, for an enum, a view or a function, the
|
|
809
|
+
* object's own name (a function's with its argument types).
|
|
810
|
+
*/
|
|
811
|
+
table: string;
|
|
812
|
+
/** The column's, policy's, constraint's, index's or trigger's name. */
|
|
813
|
+
name?: string;
|
|
814
|
+
/** The definition on the target, as SQL. Absent for an addition. */
|
|
815
|
+
before?: string;
|
|
816
|
+
/** The definition on the branch, as SQL. Absent for a drop. */
|
|
817
|
+
after?: string;
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Why the changed rows of a table cannot be merged.
|
|
821
|
+
* @group Admin
|
|
822
|
+
*/
|
|
823
|
+
export interface BranchMergeBlock {
|
|
824
|
+
/**
|
|
825
|
+
* `TABLE_REWRITTEN`: one side wrote every row anew since the branch was
|
|
826
|
+
* made (a column type change, a volatile default, `VACUUM FULL`), so which
|
|
827
|
+
* side changed which row can no longer be told.
|
|
828
|
+
*/
|
|
829
|
+
code: "TABLE_ADDED" | "TABLE_DROPPED" | "COLUMNS_DIFFER" | "PRIMARY_KEY_DIFFERS" | "NO_PRIMARY_KEY" | "TOO_LARGE" | "TABLE_REWRITTEN";
|
|
830
|
+
message: string;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* One row the branch changed, or one both sides changed.
|
|
834
|
+
*
|
|
835
|
+
* Values are the text the database writes for them, `null` for SQL NULL, so a
|
|
836
|
+
* `bigint` or a `numeric` reads exactly as it is stored — except a column named
|
|
837
|
+
* like a credential (`password_hash`, `*_token`, `*secret*`, `*_hash`), whose
|
|
838
|
+
* value reads `"[redacted]"`. It is still listed in {@link changedColumns}.
|
|
839
|
+
*
|
|
840
|
+
* A `"conflict"` with no {@link after} is a row the branch deleted that rows
|
|
841
|
+
* the target wrote since the branch was made still reference — see
|
|
842
|
+
* {@link BranchTableDataDiff.referencedBy}.
|
|
843
|
+
* @group Admin
|
|
844
|
+
*/
|
|
845
|
+
export interface BranchRowChange {
|
|
846
|
+
change: "inserted" | "updated" | "deleted" | "conflict";
|
|
847
|
+
/** The primary key, as a JSON array of its columns' values. */
|
|
848
|
+
key: string;
|
|
849
|
+
/** The row on the target. Absent for an insert. */
|
|
850
|
+
before?: Record<string, string | null>;
|
|
851
|
+
/** The row on the branch. Absent for a delete. */
|
|
852
|
+
after?: Record<string, string | null>;
|
|
853
|
+
/** The columns whose values differ, for an update or a conflict. */
|
|
854
|
+
changedColumns?: string[];
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* The rows of one table that differ between the branch and its target.
|
|
858
|
+
* @group Admin
|
|
859
|
+
*/
|
|
860
|
+
export interface BranchTableDataDiff {
|
|
861
|
+
schema: string;
|
|
862
|
+
table: string;
|
|
863
|
+
/** The collection whose table this is, when the server knows one. */
|
|
864
|
+
collection?: string;
|
|
865
|
+
primaryKey: string[];
|
|
866
|
+
/** Rows the branch inserted. */
|
|
867
|
+
inserted: number;
|
|
868
|
+
/** Rows the branch updated. */
|
|
869
|
+
updated: number;
|
|
870
|
+
/** Rows the branch deleted. */
|
|
871
|
+
deleted: number;
|
|
872
|
+
/**
|
|
873
|
+
* Rows both sides changed since the branch was made, differently — and
|
|
874
|
+
* rows the branch deleted that rows the target wrote since still
|
|
875
|
+
* reference through a foreign key ({@link referencedBy}). Deleting one of
|
|
876
|
+
* those on the target would cascade into, or rewrite, the target's own
|
|
877
|
+
* rows, so it is a conflict {@link BranchMergeOptions.onConflict} decides.
|
|
878
|
+
*/
|
|
879
|
+
conflicts: number;
|
|
880
|
+
/**
|
|
881
|
+
* Rows the target changed since the branch was made, and the branch did
|
|
882
|
+
* not. A merge leaves them as they are.
|
|
883
|
+
*/
|
|
884
|
+
targetChanges: number;
|
|
885
|
+
/** Up to {@link BranchDiffOptions.sampleLimit} of the rows counted above, but not of {@link targetChanges}. */
|
|
886
|
+
samples: BranchRowChange[];
|
|
887
|
+
/** Present when this table's rows cannot be merged. A merge refuses it unless told to skip it. */
|
|
888
|
+
blocked?: BranchMergeBlock;
|
|
889
|
+
/**
|
|
890
|
+
* Rows on each side, for a table whose rows were not matched one by one.
|
|
891
|
+
* Its inserted, updated, deleted and conflict counts are then 0 because
|
|
892
|
+
* they are unknown, not because nothing changed.
|
|
893
|
+
*/
|
|
894
|
+
rowCounts?: {
|
|
895
|
+
target: number;
|
|
896
|
+
branch: number;
|
|
897
|
+
};
|
|
898
|
+
/**
|
|
899
|
+
* The foreign keys through which rows the target wrote since the branch
|
|
900
|
+
* was made reference rows of this table the branch deleted. Each such
|
|
901
|
+
* delete is counted in {@link conflicts}.
|
|
902
|
+
*/
|
|
903
|
+
referencedBy?: BranchReferencingRows[];
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Rows of one table, written on the target since the branch was made, that
|
|
907
|
+
* reference rows the branch deleted.
|
|
908
|
+
* @group Admin
|
|
909
|
+
*/
|
|
910
|
+
export interface BranchReferencingRows {
|
|
911
|
+
schema: string;
|
|
912
|
+
table: string;
|
|
913
|
+
/** The foreign key's name. */
|
|
914
|
+
constraint: string;
|
|
915
|
+
/** What deleting the referenced row does to them on the target. */
|
|
916
|
+
onDelete: "cascade" | "set null" | "set default" | "restrict" | "no action";
|
|
917
|
+
/** How many of them there are. */
|
|
918
|
+
rows: number;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* What {@link BranchAdmin.diffBranch} returns.
|
|
922
|
+
* @group Admin
|
|
923
|
+
*/
|
|
924
|
+
export interface BranchDiff {
|
|
925
|
+
branch: string;
|
|
926
|
+
/** The branch's database. */
|
|
927
|
+
branchDatabase: string;
|
|
928
|
+
/** The database the branch was made from, which a merge writes to. */
|
|
929
|
+
targetDatabase: string;
|
|
930
|
+
/** The schemas compared. */
|
|
931
|
+
schemas: string[];
|
|
932
|
+
/**
|
|
933
|
+
* Whether rows could be told apart by which side changed them since the
|
|
934
|
+
* branch was made. When `false`, every row that differs is counted as the
|
|
935
|
+
* branch's change, and a merge would undo what the target changed.
|
|
936
|
+
*/
|
|
937
|
+
forkPointKnown: boolean;
|
|
938
|
+
/** Pass to {@link BranchAdmin.mergeBranch}: what this diff saw, on both sides. */
|
|
939
|
+
fingerprint: string;
|
|
940
|
+
schema: BranchSchemaChange[];
|
|
941
|
+
/** Only the tables with rows that differ. */
|
|
942
|
+
data: BranchTableDataDiff[];
|
|
943
|
+
sampleLimit: number;
|
|
944
|
+
computedAt: string;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* How {@link BranchAdmin.mergeBranch} applies a branch.
|
|
948
|
+
*
|
|
949
|
+
* A merge writes the rows the branch inserted, updated and deleted to the
|
|
950
|
+
* target, in one statement: all of them, or none. Rows the target changed
|
|
951
|
+
* since the branch was made are kept. Schema and policy changes are never
|
|
952
|
+
* merged — they belong to the collections and their migrations.
|
|
953
|
+
*
|
|
954
|
+
* Nothing is written when either side changed since the diff that produced
|
|
955
|
+
* {@link expectedFingerprint}, when a table with changed rows cannot be merged
|
|
956
|
+
* (unless {@link skipBlocked}), or when a row was changed on both sides and
|
|
957
|
+
* {@link onConflict} is `"abort"`.
|
|
958
|
+
* @group Admin
|
|
959
|
+
*/
|
|
960
|
+
export interface BranchMergeOptions {
|
|
961
|
+
/** {@link BranchDiff.fingerprint} of the diff that was reviewed. */
|
|
962
|
+
expectedFingerprint: string;
|
|
963
|
+
/**
|
|
964
|
+
* A row both sides changed: `"abort"` (the default) writes nothing,
|
|
965
|
+
* `"branch"` writes the branch's row over the target's, `"target"` keeps
|
|
966
|
+
* the target's.
|
|
967
|
+
*
|
|
968
|
+
* A row the branch deleted that the target's newer rows reference
|
|
969
|
+
* ({@link BranchTableDataDiff.referencedBy}) is a conflict too: `"target"`
|
|
970
|
+
* keeps it, and with it the rows that reference it; `"branch"` deletes it,
|
|
971
|
+
* and the foreign key's `ON DELETE` reaches those rows — the result's
|
|
972
|
+
* `warnings` say which.
|
|
973
|
+
*/
|
|
974
|
+
onConflict?: "abort" | "branch" | "target";
|
|
975
|
+
/** Merge the other tables when some cannot be merged, instead of writing nothing. */
|
|
976
|
+
skipBlocked?: boolean;
|
|
977
|
+
/** The schemas the reviewed diff compared, when it was not the default. */
|
|
978
|
+
schemas?: string[];
|
|
979
|
+
/** The row limit the reviewed diff used, when it was not the default. */
|
|
980
|
+
maxRowsPerTable?: number;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* What {@link BranchAdmin.mergeBranch} wrote.
|
|
984
|
+
* @group Admin
|
|
985
|
+
*/
|
|
986
|
+
export interface BranchMergeResult {
|
|
987
|
+
branch: string;
|
|
988
|
+
targetDatabase: string;
|
|
989
|
+
tables: {
|
|
990
|
+
schema: string;
|
|
991
|
+
table: string;
|
|
992
|
+
inserted: number;
|
|
993
|
+
updated: number;
|
|
994
|
+
deleted: number;
|
|
995
|
+
}[];
|
|
996
|
+
/** Tables left unmerged because they could not be, with `skipBlocked`. */
|
|
997
|
+
skipped: {
|
|
998
|
+
schema: string;
|
|
999
|
+
table: string;
|
|
1000
|
+
reason: BranchMergeBlock;
|
|
1001
|
+
}[];
|
|
1002
|
+
/** Rows both sides changed that kept the target's version, with `onConflict: "target"`. */
|
|
1003
|
+
conflictsKept: number;
|
|
1004
|
+
/** Schema and policy changes on the branch, none of which a merge applies. */
|
|
1005
|
+
schemaChangesNotMerged: number;
|
|
1006
|
+
/**
|
|
1007
|
+
* What the merge did beyond the rows it counts, or what went wrong after
|
|
1008
|
+
* they were written: a delete whose foreign keys reached the target's own
|
|
1009
|
+
* rows (with `onConflict: "branch"`), a sequence left behind them.
|
|
1010
|
+
*/
|
|
1011
|
+
warnings: string[];
|
|
718
1012
|
}
|
|
719
1013
|
/**
|
|
720
1014
|
* Union type for all admin capabilities.
|
|
@@ -890,10 +1184,16 @@ export interface RealtimeSocketOptions {
|
|
|
890
1184
|
uid: string;
|
|
891
1185
|
roles: string[];
|
|
892
1186
|
scopes: string[];
|
|
893
|
-
/**
|
|
1187
|
+
/**
|
|
1188
|
+
* The key itself: its id and `rate_limit` decide which rate-limit
|
|
1189
|
+
* bucket its frames count in. With `name` and `kind`, collection
|
|
1190
|
+
* callbacks on its write frames read it as `context.credential`.
|
|
1191
|
+
*/
|
|
894
1192
|
apiKey?: {
|
|
895
1193
|
id: string;
|
|
896
1194
|
rate_limit: number | null;
|
|
1195
|
+
name?: string;
|
|
1196
|
+
kind?: ApiKeyKind;
|
|
897
1197
|
};
|
|
898
1198
|
} | {
|
|
899
1199
|
message: string;
|
|
@@ -960,6 +1260,14 @@ export interface RealtimeSocketOptions {
|
|
|
960
1260
|
* answered `404` and closed, so the client is not left hanging.
|
|
961
1261
|
*/
|
|
962
1262
|
path?: string;
|
|
1263
|
+
/**
|
|
1264
|
+
* Run `fn` on behalf of the backend that owns this socket: each connection
|
|
1265
|
+
* and each frame is handled inside it, so a hook a frame reaches sees that
|
|
1266
|
+
* backend as `rebase`, as it does over REST. The server passes its own.
|
|
1267
|
+
* Absent, frames run in the context the HTTP connection was accepted in —
|
|
1268
|
+
* the process default's.
|
|
1269
|
+
*/
|
|
1270
|
+
runInScope?: <T>(fn: () => T) => T;
|
|
963
1271
|
}
|
|
964
1272
|
/**
|
|
965
1273
|
* A `BackendBootstrapper` encapsulates all driver-specific initialization logic.
|
|
@@ -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;
|
package/dist/types/cron.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
|
@@ -392,9 +392,9 @@ export interface BaseProperty<CustomProps = unknown> {
|
|
|
392
392
|
* Give the expression, in the template form `isId` takes
|
|
393
393
|
* (``databaseDefault: "sql`gen_random_uuid()`"``), and the schema planner
|
|
394
394
|
* writes it as the column's `DEFAULT`, so `rebase db push` keeps it. `true`
|
|
395
|
-
* declares a DEFAULT someone else wrote
|
|
396
|
-
* one
|
|
397
|
-
* `rebase schema introspect` set the expression they read.
|
|
395
|
+
* declares a DEFAULT someone else wrote: the planner writes none, and
|
|
396
|
+
* `rebase db push` leaves the one the database holds as it is. "Import
|
|
397
|
+
* from table" and `rebase schema introspect` set the expression they read.
|
|
398
398
|
*/
|
|
399
399
|
databaseDefault?: boolean | SqlExpression;
|
|
400
400
|
/**
|
|
@@ -1501,14 +1501,14 @@ export interface PropertyConditions {
|
|
|
1501
1501
|
requiredMessage?: string;
|
|
1502
1502
|
/**
|
|
1503
1503
|
* Dynamic minimum value for number/string length.
|
|
1504
|
-
*
|
|
1504
|
+
* A number, or a rule that evaluates to one.
|
|
1505
1505
|
*/
|
|
1506
|
-
min?: JsonLogicRule;
|
|
1506
|
+
min?: number | JsonLogicRule;
|
|
1507
1507
|
/**
|
|
1508
1508
|
* Dynamic maximum value for number/string length.
|
|
1509
|
-
*
|
|
1509
|
+
* A number, or a rule that evaluates to one.
|
|
1510
1510
|
*/
|
|
1511
|
-
max?: JsonLogicRule;
|
|
1511
|
+
max?: number | JsonLogicRule;
|
|
1512
1512
|
/**
|
|
1513
1513
|
* Dynamic default value for new entities.
|
|
1514
1514
|
* Should evaluate to a value of the appropriate type for the field.
|
|
@@ -314,9 +314,11 @@ export interface ViaRelation extends RelationBase {
|
|
|
314
314
|
* The joins, in order, from this collection's table to the target's.
|
|
315
315
|
*
|
|
316
316
|
* Each step names a table and the columns to join it on; the last step's
|
|
317
|
-
* table is the target.
|
|
318
|
-
*
|
|
319
|
-
*
|
|
317
|
+
* table is the target. A single-hop chain is writable through a create or
|
|
318
|
+
* update — to-one in one step (the target holds the key), to-many through
|
|
319
|
+
* one junction table — and a longer one is read-only, because Rebase will
|
|
320
|
+
* not work out how to write through an arbitrary chain, and guessing is
|
|
321
|
+
* what this kind exists to stop.
|
|
320
322
|
*/
|
|
321
323
|
joinPath: JoinStep[];
|
|
322
324
|
}
|
|
@@ -379,8 +381,12 @@ export interface ResolvedRelationBase {
|
|
|
379
381
|
*/
|
|
380
382
|
cardinality: "one" | "many";
|
|
381
383
|
/**
|
|
382
|
-
* Whether Rebase
|
|
383
|
-
* {@link ResolvedVia}
|
|
384
|
+
* Whether Rebase writes this link through a create or update. True for
|
|
385
|
+
* every kind but a multi-hop {@link ResolvedVia}: a `via` is writable when
|
|
386
|
+
* it has a single link to set — a to-one chain of one step (the target
|
|
387
|
+
* holds the key) or a to-many chain through one junction table — and
|
|
388
|
+
* read-only otherwise, since Rebase will not invent a write for a longer
|
|
389
|
+
* chain.
|
|
384
390
|
*/
|
|
385
391
|
writable: boolean;
|
|
386
392
|
/**
|
|
@@ -463,7 +469,12 @@ export interface ResolvedManyToMany extends ResolvedRelationBase {
|
|
|
463
469
|
/** @group Models */
|
|
464
470
|
export interface ResolvedVia extends ResolvedRelationBase {
|
|
465
471
|
kind: "via";
|
|
466
|
-
|
|
472
|
+
/**
|
|
473
|
+
* True for a single-hop chain — to-one through one step, or to-many through
|
|
474
|
+
* one junction table — and false for anything longer. See
|
|
475
|
+
* {@link ResolvedRelationBase.writable}.
|
|
476
|
+
*/
|
|
477
|
+
writable: boolean;
|
|
467
478
|
/** The chain as authored — see {@link ViaRelation.joinPath}. Nothing to default. */
|
|
468
479
|
joinPath: JoinStep[];
|
|
469
480
|
}
|
package/dist/types/scopes.d.ts
CHANGED
|
@@ -164,6 +164,20 @@ export declare function isDataPlaneScope(scope: string): scope is DataPlaneScope
|
|
|
164
164
|
export declare function isAdminScope(scope: string): scope is AdminScope;
|
|
165
165
|
/** Does this list of roles include the built-in `admin` role? @group Auth */
|
|
166
166
|
export declare function hasAdminRole(roles: readonly string[] | null | undefined): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Why `name` cannot be written as a role, or `undefined` when it can.
|
|
169
|
+
*
|
|
170
|
+
* No naming pattern is imposed — an app may call its roles anything. What is
|
|
171
|
+
* refused is a name that would be read back as *other* roles: a role travels as
|
|
172
|
+
* one element of a Postgres `text[]` and as one entry of the comma-joined
|
|
173
|
+
* `app.user_roles` setting that RLS policies split with
|
|
174
|
+
* `string_to_array(…, ',')`. Written as `"support,admin"`, a role comes back as
|
|
175
|
+
* `admin`; braces, quotes and backslashes are array-literal syntax, so they are
|
|
176
|
+
* refused too, as are empty names and control characters.
|
|
177
|
+
*
|
|
178
|
+
* @group Auth
|
|
179
|
+
*/
|
|
180
|
+
export declare function roleNameProblem(name: unknown): string | undefined;
|
|
167
181
|
/**
|
|
168
182
|
* Does a set of held scopes grant `scope`, optionally on one `target`?
|
|
169
183
|
*
|
package/dist/users/user.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CallerCredential } from "../types/api_keys.js";
|
|
1
2
|
/**
|
|
2
3
|
* The canonical representation of an authenticated user in the Rebase ecosystem.
|
|
3
4
|
*
|
|
@@ -86,5 +87,12 @@ export type User = {
|
|
|
86
87
|
* anonymous request.
|
|
87
88
|
*/
|
|
88
89
|
readonly claims?: Record<string, unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* The API key this request authenticated with, when it was one. Set
|
|
92
|
+
* server-side on the identity a request's driver is scoped to, and read by
|
|
93
|
+
* collection callbacks as `context.credential`. Absent for a session, a
|
|
94
|
+
* service-key request and in the browser.
|
|
95
|
+
*/
|
|
96
|
+
readonly credential?: CallerCredential;
|
|
89
97
|
getIdToken?: (forceRefresh?: boolean) => Promise<string>;
|
|
90
98
|
};
|