@rebasepro/types 0.29.0 → 0.29.2
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/aggregates.d.ts +7 -1
- package/dist/controllers/client.d.ts +31 -3
- package/dist/controllers/data.d.ts +164 -29
- package/dist/controllers/data_driver.d.ts +93 -3
- package/dist/controllers/storage-references.d.ts +4 -3
- package/dist/controllers/storage.d.ts +3 -2
- package/dist/index.es.js +126 -14
- package/dist/index.es.js.map +1 -1
- package/dist/types/auth_adapter.d.ts +1 -1
- package/dist/types/filter-operators.d.ts +23 -2
- package/dist/types/properties.d.ts +19 -3
- package/dist/types/resource_kinds.d.ts +50 -0
- package/dist/types/rls-functions.d.ts +45 -0
- package/package.json +1 -1
|
@@ -717,7 +717,7 @@ export interface AuthAdapter {
|
|
|
717
717
|
* refuse — for one that would leave the project without an administrator,
|
|
718
718
|
* among others.
|
|
719
719
|
*
|
|
720
|
-
* If not implemented, the rows are deleted
|
|
720
|
+
* If not implemented, the rows are deleted like any other.
|
|
721
721
|
*/
|
|
722
722
|
prepareUserDeletions?(uids: readonly string[]): Promise<void>;
|
|
723
723
|
/**
|
|
@@ -219,7 +219,8 @@ export type WhereFilterOp = "<" | "<=" | "==" | "!=" | ">=" | ">" | "array-conta
|
|
|
219
219
|
* { name: ["ilike", "%john%"] }
|
|
220
220
|
* { slug: ["like", "post-%"] }
|
|
221
221
|
*
|
|
222
|
-
* // Null checks (the value is ignored; `null` is conventional
|
|
222
|
+
* // Null checks (the value is ignored; `null` is conventional, and an
|
|
223
|
+
* // untyped caller may leave it out: `["is-null"]`)
|
|
223
224
|
* { deleted_at: ["is-null", null] }
|
|
224
225
|
* { published_at: ["is-not-null", null] }
|
|
225
226
|
*
|
|
@@ -279,7 +280,27 @@ export type FieldPath<M extends Record<string, unknown> = Record<string, unknown
|
|
|
279
280
|
*
|
|
280
281
|
* @group Models
|
|
281
282
|
*/
|
|
282
|
-
export type NonColumnFieldPath = `${string}.${string}` | `${string}->>${string}
|
|
283
|
+
export type NonColumnFieldPath = `${string}.${string}` | `${string}->>${string}` | CaseFoldedFieldPath;
|
|
284
|
+
/**
|
|
285
|
+
* A text column compared in one case: `lower(artist)` or `upper(code)`. Every
|
|
286
|
+
* operator applies to the folded value, so the values written beside it are
|
|
287
|
+
* written in that case — `{ "lower(artist)": ["in", ["abba", "queen"]] }`
|
|
288
|
+
* matches "ABBA" and "Queen". Compiled to `lower(artist)`, which an index on
|
|
289
|
+
* that expression serves. The same spelling an aggregate's `groupBy` uses.
|
|
290
|
+
*
|
|
291
|
+
* @group Models
|
|
292
|
+
*/
|
|
293
|
+
export type CaseFoldedFieldPath = `lower(${string})` | `upper(${string})`;
|
|
294
|
+
/**
|
|
295
|
+
* Read a {@link CaseFoldedFieldPath}: the function and the field it folds, or
|
|
296
|
+
* `undefined` for any other key.
|
|
297
|
+
*
|
|
298
|
+
* @group Models
|
|
299
|
+
*/
|
|
300
|
+
export declare function parseCaseFoldedFieldPath(key: string): {
|
|
301
|
+
fn: "lower" | "upper";
|
|
302
|
+
field: string;
|
|
303
|
+
} | undefined;
|
|
283
304
|
/**
|
|
284
305
|
* Relaxed filter type that also accepts pre-serialized PostgREST strings.
|
|
285
306
|
* **Internal only** — used at the wire-format boundary
|
|
@@ -771,6 +771,14 @@ export interface DateProperty extends BaseProperty {
|
|
|
771
771
|
* `updated_on` fields
|
|
772
772
|
*/
|
|
773
773
|
autoValue?: "on_create" | "on_update";
|
|
774
|
+
/**
|
|
775
|
+
* Makes this field (part of) the primary key — a calendar day in a key such
|
|
776
|
+
* as `(day, player)`. Only on `columnType: "date"`, whose value is a day and
|
|
777
|
+
* not an instant: it travels as `YYYY-MM-DD` in rows and in addresses
|
|
778
|
+
* (`2026-11-09:::p1`), never through a `Date`, so no time zone moves it.
|
|
779
|
+
* The day is the caller's (`"manual"`); the database assigns none.
|
|
780
|
+
*/
|
|
781
|
+
isId?: "manual" | true;
|
|
774
782
|
}
|
|
775
783
|
/**
|
|
776
784
|
* @group Entity properties
|
|
@@ -1017,6 +1025,8 @@ export type PropertyBuilderProps<M extends Record<string, unknown> = Record<stri
|
|
|
1017
1025
|
path: string;
|
|
1018
1026
|
/** The record's id, or `undefined` while it is being created. */
|
|
1019
1027
|
id?: string | number;
|
|
1028
|
+
/** @deprecated Use `id` instead. */
|
|
1029
|
+
entityId?: string | number;
|
|
1020
1030
|
/** Who is editing — the signed-in user and their roles. */
|
|
1021
1031
|
authController: AuthState;
|
|
1022
1032
|
};
|
|
@@ -1341,6 +1351,10 @@ export interface UploadedFileContext {
|
|
|
1341
1351
|
* The record's id; absent for one being created.
|
|
1342
1352
|
*/
|
|
1343
1353
|
id?: string | number;
|
|
1354
|
+
/**
|
|
1355
|
+
* @deprecated Use `id` instead.
|
|
1356
|
+
*/
|
|
1357
|
+
entityId?: string | number;
|
|
1344
1358
|
/**
|
|
1345
1359
|
* Entity path. E.g. `products/PID/locales`
|
|
1346
1360
|
*/
|
|
@@ -1494,8 +1508,10 @@ export interface PropertyConditions {
|
|
|
1494
1508
|
/**
|
|
1495
1509
|
* Make the field required when this condition evaluates to true.
|
|
1496
1510
|
* Overrides the static `validation.required` setting.
|
|
1511
|
+
*
|
|
1512
|
+
* A literal `true` makes it required unconditionally.
|
|
1497
1513
|
*/
|
|
1498
|
-
required?:
|
|
1514
|
+
required?: ConditionRule;
|
|
1499
1515
|
/**
|
|
1500
1516
|
* Custom message when conditional required validation fails.
|
|
1501
1517
|
*/
|
|
@@ -1566,9 +1582,9 @@ export interface PropertyConditions {
|
|
|
1566
1582
|
acceptedFiles?: JsonLogicRule;
|
|
1567
1583
|
/**
|
|
1568
1584
|
* Dynamic maximum file size in bytes.
|
|
1569
|
-
*
|
|
1585
|
+
* A number, or a rule that evaluates to one.
|
|
1570
1586
|
*/
|
|
1571
|
-
maxFileSize?: JsonLogicRule;
|
|
1587
|
+
maxFileSize?: number | JsonLogicRule;
|
|
1572
1588
|
}
|
|
1573
1589
|
/**
|
|
1574
1590
|
* Context available during JSON Logic condition evaluation.
|
|
@@ -52,6 +52,39 @@ export interface DatabaseOptions extends DeclareOptions {
|
|
|
52
52
|
* a stock `postgres:18` does not carry.
|
|
53
53
|
*/
|
|
54
54
|
extensions?: string[];
|
|
55
|
+
/**
|
|
56
|
+
* How row-level security runs on this database — the request role and
|
|
57
|
+
* everything around it. Every default is what Rebase did before the option
|
|
58
|
+
* existed. Declared here rather than only on the driver because the policy
|
|
59
|
+
* settings shape the SQL `rebase db generate` writes, and the CLI reads
|
|
60
|
+
* this declaration as the server does. The `REBASE_RLS_*` variables win.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* export const main = database({ rls: { requestRole: "acme_user" } });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* See `PostgresRlsConfig` in `@rebasepro/server-postgres` for each setting,
|
|
67
|
+
* and the forms only code can give (a function for the role or identity).
|
|
68
|
+
*/
|
|
69
|
+
rls?: DatabaseRlsOptions;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The data-only `rls` settings a database declaration takes. The driver's own
|
|
73
|
+
* `rls` block (`PostgresRlsConfig`) accepts these and the function forms.
|
|
74
|
+
*/
|
|
75
|
+
export interface DatabaseRlsOptions {
|
|
76
|
+
requestRole?: string | {
|
|
77
|
+
anonymous: string;
|
|
78
|
+
signedIn: string;
|
|
79
|
+
};
|
|
80
|
+
provisionRole?: "auto" | "never";
|
|
81
|
+
grants?: "schema" | "managed" | "none";
|
|
82
|
+
policyTarget?: "public" | "requestRole";
|
|
83
|
+
adminPolicies?: "adminRole" | "public";
|
|
84
|
+
defaultPolicies?: boolean;
|
|
85
|
+
inheritRoles?: string[];
|
|
86
|
+
identity?: "rebase" | "supabase";
|
|
87
|
+
sharedRole?: "warn" | "refuse" | "ignore";
|
|
55
88
|
}
|
|
56
89
|
/** A database handle. Collections point at it via `dataSource`. */
|
|
57
90
|
export type DatabaseHandle = ResourceHandle;
|
|
@@ -84,6 +117,23 @@ export declare function database(key?: string, options?: DatabaseOptions): Datab
|
|
|
84
117
|
* not opted in — so this reads as a refusal by default, on purpose.
|
|
85
118
|
*/
|
|
86
119
|
export declare function declaredDatabaseExtensions(): readonly string[];
|
|
120
|
+
/** The `rls` options a database declaration gave, `{}` when it gave none or was never declared. */
|
|
121
|
+
export declare function declaredDatabaseRls(key?: string): DatabaseRlsOptions;
|
|
122
|
+
/**
|
|
123
|
+
* The policy settings every compile path must agree on — the boot's policy
|
|
124
|
+
* ensure, `rebase db generate`, the drift check — read from the one place all
|
|
125
|
+
* of them can see: the database declaration, with `REBASE_RLS_POLICY_TARGET` /
|
|
126
|
+
* `REBASE_RLS_ADMIN_POLICIES` / `REBASE_RLS_DEFAULT_POLICIES` over it. Defaults
|
|
127
|
+
* are what Rebase compiled before these existed, except `adminPolicies`, whose
|
|
128
|
+
* default (`"adminRole"`) changed what the server-or-admin policies are `TO`.
|
|
129
|
+
*
|
|
130
|
+
* Browser-safe: where there is no `process`, only the declaration counts.
|
|
131
|
+
*/
|
|
132
|
+
export declare function declaredRlsPolicyShape(dataSource?: string): {
|
|
133
|
+
policyTarget: "public" | "requestRole";
|
|
134
|
+
adminPolicies: "adminRole" | "public";
|
|
135
|
+
defaultPolicies: boolean;
|
|
136
|
+
};
|
|
87
137
|
/** Options a bucket accepts beyond the common ones. */
|
|
88
138
|
export interface BucketOptions extends DeclareOptions {
|
|
89
139
|
/**
|
|
@@ -54,8 +54,53 @@ export declare const REBASE_SCHEMA = "rebase";
|
|
|
54
54
|
* the trusted server plane and `IS NOT NULL` a tautology.
|
|
55
55
|
*/
|
|
56
56
|
export declare const RLS_UID_SQL = "rebase.uid()";
|
|
57
|
+
/**
|
|
58
|
+
* Is the caller one of this database's request roles? What a permissive
|
|
59
|
+
* policy is ANDed with under `rls.policyTarget: "requestRole"`, so another
|
|
60
|
+
* application's role holding a grant on the table gets nothing from it.
|
|
61
|
+
* `current_user` is passed in — inside the function, which reads the recorded
|
|
62
|
+
* roles with its owner's rights, `current_user` would be the owner — and the
|
|
63
|
+
* sub-select makes it one evaluation per statement, not one per row.
|
|
64
|
+
*/
|
|
65
|
+
export declare const RLS_IS_REQUEST_ROLE_SQL = "(SELECT rebase.is_request_role(current_user::text))";
|
|
57
66
|
/** The request's roles as a comma-separated string, for `string_to_array`. */
|
|
58
67
|
export declare const RLS_ROLES_SQL = "rebase.roles()";
|
|
68
|
+
/**
|
|
69
|
+
* The Postgres role that policies granting only the server context or admins
|
|
70
|
+
* are written `TO`: the injected `<table>_default_admin_*` baseline, and any
|
|
71
|
+
* permissive rule whose every clause requires one of the two (`roles: ["admin"]`).
|
|
72
|
+
*
|
|
73
|
+
* Postgres ORs the permissive policies that apply to the current role. Written
|
|
74
|
+
* `TO public`, the baseline applied to every signed-in user too, as
|
|
75
|
+
* `(InitPlan) OR owner_id = (InitPlan)` — and an OR with a per-statement
|
|
76
|
+
* constant arm cannot use the owner index, so a user's owner-scoped list or
|
|
77
|
+
* count scanned the whole table (78 ms against 2.8 ms at 1M rows). Written `TO`
|
|
78
|
+
* this role, the policy is not in a user's plan at all.
|
|
79
|
+
*
|
|
80
|
+
* It holds no privilege and cannot log in: being in it only decides which
|
|
81
|
+
* policies apply, and those still test `rebase.uid() IS NULL` or the `admin`
|
|
82
|
+
* role. Admin requests switch to a request role that inherits it
|
|
83
|
+
* ({@link adminRequestRoleFor}); a connection that is itself subject to RLS
|
|
84
|
+
* inherits it for the server context. One fixed name, so the policy text is the
|
|
85
|
+
* same in every deployment and every generated migration. FROZEN.
|
|
86
|
+
*/
|
|
87
|
+
export declare const REBASE_ADMIN_ROLE = "rebase_admin";
|
|
88
|
+
/**
|
|
89
|
+
* The role an admin request runs as, for a signed-in request role: it inherits
|
|
90
|
+
* that role (its grants and every policy written for it) and
|
|
91
|
+
* {@link REBASE_ADMIN_ROLE}. One per request role rather than the shared
|
|
92
|
+
* `rebase_admin` itself, because roles belong to the cluster: a project with a
|
|
93
|
+
* request role of its own (`rls.requestRole`) would otherwise share its admin
|
|
94
|
+
* access with every other project on the cluster. FROZEN derivation.
|
|
95
|
+
*/
|
|
96
|
+
export declare function adminRequestRoleFor(requestRole: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Whether a request with these roles passes `rolesOverlap(["admin"])` — the
|
|
99
|
+
* test `string_to_array(rebase.roles(), ',') && ARRAY['admin']` makes of the
|
|
100
|
+
* comma-joined `app.user_roles`, so a role name with a comma in it is split
|
|
101
|
+
* exactly as Postgres splits it.
|
|
102
|
+
*/
|
|
103
|
+
export declare function holdsAdminRole(roles: readonly string[]): boolean;
|
|
59
104
|
/**
|
|
60
105
|
* Whether the caller is a GUEST — signed in through anonymous sign-in rather
|
|
61
106
|
* than with an account.
|