@rebasepro/types 0.29.0 → 0.29.1

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.
@@ -52,6 +52,38 @@ 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
+ defaultPolicies?: boolean;
84
+ inheritRoles?: string[];
85
+ identity?: "rebase" | "supabase";
86
+ sharedRole?: "warn" | "refuse" | "ignore";
55
87
  }
56
88
  /** A database handle. Collections point at it via `dataSource`. */
57
89
  export type DatabaseHandle = ResourceHandle;
@@ -84,6 +116,21 @@ export declare function database(key?: string, options?: DatabaseOptions): Datab
84
116
  * not opted in — so this reads as a refusal by default, on purpose.
85
117
  */
86
118
  export declare function declaredDatabaseExtensions(): readonly string[];
119
+ /** The `rls` options a database declaration gave, `{}` when it gave none or was never declared. */
120
+ export declare function declaredDatabaseRls(key?: string): DatabaseRlsOptions;
121
+ /**
122
+ * The policy settings every compile path must agree on — the boot's policy
123
+ * ensure, `rebase db generate`, the drift check — read from the one place all
124
+ * of them can see: the database declaration, with `REBASE_RLS_POLICY_TARGET` /
125
+ * `REBASE_RLS_DEFAULT_POLICIES` over it. Defaults are what Rebase compiled
126
+ * before these existed.
127
+ *
128
+ * Browser-safe: where there is no `process`, only the declaration counts.
129
+ */
130
+ export declare function declaredRlsPolicyShape(dataSource?: string): {
131
+ policyTarget: "public" | "requestRole";
132
+ defaultPolicies: boolean;
133
+ };
87
134
  /** Options a bucket accepts beyond the common ones. */
88
135
  export interface BucketOptions extends DeclareOptions {
89
136
  /**
@@ -54,6 +54,15 @@ 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()";
59
68
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebasepro/types",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "Rebase type definitions — shared interfaces and controller types",
5
5
  "keywords": [
6
6
  "rebase",