@rebasepro/types 0.7.0 → 0.9.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.
Files changed (88) hide show
  1. package/README.md +10 -10
  2. package/dist/controllers/auth.d.ts +1 -1
  3. package/dist/controllers/client.d.ts +237 -7
  4. package/dist/controllers/collection_registry.d.ts +3 -3
  5. package/dist/controllers/customization_controller.d.ts +1 -1
  6. package/dist/controllers/data.d.ts +285 -81
  7. package/dist/controllers/data_driver.d.ts +50 -37
  8. package/dist/controllers/index.d.ts +1 -1
  9. package/dist/controllers/local_config_persistence.d.ts +4 -4
  10. package/dist/controllers/navigation.d.ts +2 -2
  11. package/dist/controllers/registry.d.ts +17 -6
  12. package/dist/controllers/{side_entity_controller.d.ts → side_panel_controller.d.ts} +7 -7
  13. package/dist/controllers/storage.d.ts +39 -0
  14. package/dist/errors.d.ts +64 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.es.js +290 -16
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +305 -18
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/rebase_context.d.ts +8 -4
  21. package/dist/types/auth_adapter.d.ts +9 -6
  22. package/dist/types/backend.d.ts +30 -26
  23. package/dist/types/builders.d.ts +2 -2
  24. package/dist/types/collections.d.ts +211 -136
  25. package/dist/types/component_overrides.d.ts +61 -3
  26. package/dist/types/cron.d.ts +10 -1
  27. package/dist/types/data_source.d.ts +18 -5
  28. package/dist/types/database_adapter.d.ts +4 -3
  29. package/dist/types/entities.d.ts +7 -7
  30. package/dist/types/entity_actions.d.ts +7 -7
  31. package/dist/types/entity_callbacks.d.ts +55 -43
  32. package/dist/types/entity_views.d.ts +3 -3
  33. package/dist/types/filter-operators.d.ts +153 -0
  34. package/dist/types/index.d.ts +3 -2
  35. package/dist/types/modify_collections.d.ts +2 -2
  36. package/dist/types/plugins.d.ts +9 -9
  37. package/dist/types/policy.d.ts +191 -0
  38. package/dist/types/properties.d.ts +153 -43
  39. package/dist/types/property_config.d.ts +1 -1
  40. package/dist/types/relations.d.ts +3 -3
  41. package/dist/types/slots.d.ts +14 -14
  42. package/dist/types/storage_source.d.ts +83 -0
  43. package/dist/types/websockets.d.ts +12 -13
  44. package/dist/users/user.d.ts +21 -9
  45. package/package.json +1 -1
  46. package/src/controllers/auth.tsx +1 -1
  47. package/src/controllers/client.ts +275 -7
  48. package/src/controllers/collection_registry.ts +3 -3
  49. package/src/controllers/customization_controller.tsx +1 -1
  50. package/src/controllers/data.ts +309 -97
  51. package/src/controllers/data_driver.ts +49 -40
  52. package/src/controllers/index.ts +1 -1
  53. package/src/controllers/local_config_persistence.tsx +4 -4
  54. package/src/controllers/navigation.ts +2 -2
  55. package/src/controllers/registry.ts +18 -6
  56. package/src/controllers/{side_entity_controller.tsx → side_panel_controller.tsx} +7 -7
  57. package/src/controllers/storage.ts +60 -1
  58. package/src/errors.ts +80 -0
  59. package/src/index.ts +1 -0
  60. package/src/rebase_context.tsx +8 -4
  61. package/src/types/auth_adapter.ts +9 -6
  62. package/src/types/backend.ts +41 -36
  63. package/src/types/builders.ts +2 -2
  64. package/src/types/collections.ts +256 -172
  65. package/src/types/component_overrides.ts +72 -5
  66. package/src/types/cron.ts +10 -1
  67. package/src/types/data_source.ts +29 -7
  68. package/src/types/database_adapter.ts +4 -3
  69. package/src/types/entities.ts +7 -7
  70. package/src/types/entity_actions.tsx +7 -7
  71. package/src/types/entity_callbacks.ts +58 -47
  72. package/src/types/entity_views.tsx +3 -3
  73. package/src/types/filter-operators.ts +240 -0
  74. package/src/types/index.ts +3 -2
  75. package/src/types/modify_collections.tsx +2 -2
  76. package/src/types/plugins.tsx +9 -9
  77. package/src/types/policy.ts +229 -0
  78. package/src/types/properties.ts +164 -44
  79. package/src/types/property_config.tsx +0 -1
  80. package/src/types/relations.ts +3 -3
  81. package/src/types/slots.tsx +14 -14
  82. package/src/types/storage_source.ts +90 -0
  83. package/src/types/websockets.ts +12 -14
  84. package/src/users/user.ts +22 -9
  85. package/dist/types/backend_hooks.d.ts +0 -109
  86. package/dist/types/entity_overrides.d.ts +0 -10
  87. package/src/types/backend_hooks.ts +0 -114
  88. package/src/types/entity_overrides.tsx +0 -11
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Canonical filter operators and REST wire-format mappings.
3
+ *
4
+ * `WhereFilterOp` is THE operator type used at every layer — from React
5
+ * components through the SDK, server, and down to the database driver.
6
+ *
7
+ * PostgREST short-codes (`eq`, `gt`, `cs`, …) exist **only** at the
8
+ * HTTP wire boundary, handled by `serializeFilter` / `deserializeFilter`
9
+ * in `@rebasepro/common`.
10
+ *
11
+ * ┌──────────────────────┬───────────────┬──────────────────────────────┐
12
+ * │ Canonical │ REST short │ Meaning │
13
+ * ├──────────────────────┼───────────────┼──────────────────────────────┤
14
+ * │ "==" │ "eq" │ Equal │
15
+ * │ "!=" │ "neq" │ Not equal │
16
+ * │ ">" │ "gt" │ Greater than │
17
+ * │ ">=" │ "gte" │ Greater than or equal │
18
+ * │ "<" │ "lt" │ Less than │
19
+ * │ "<=" │ "lte" │ Less than or equal │
20
+ * │ "in" │ "in" │ Value in list │
21
+ * │ "not-in" │ "nin" │ Value not in list │
22
+ * │ "array-contains" │ "cs" │ Array contains element │
23
+ * │ "array-contains-any" │ "csa" │ Array contains any of │
24
+ * │ "like" │ "like" │ SQL LIKE (case-sensitive) │
25
+ * │ "ilike" │ "ilike" │ SQL ILIKE (case-insensitive) │
26
+ * │ "not-like" │ "nlike" │ NOT LIKE (case-sensitive) │
27
+ * │ "not-ilike" │ "nilike" │ NOT ILIKE (case-insensitive) │
28
+ * │ "is-null" │ "isnull" │ Field IS NULL │
29
+ * │ "is-not-null" │ "notnull" │ Field IS NOT NULL │
30
+ * └──────────────────────┴───────────────┴──────────────────────────────┘
31
+ *
32
+ * Pattern matching (`like`/`ilike`) uses SQL wildcard syntax: `%` matches any
33
+ * sequence of characters, `_` matches a single character. On MongoDB these are
34
+ * translated to anchored regular expressions; Firestore has no native pattern
35
+ * matching and rejects these operators (use `searchString` instead).
36
+ *
37
+ * @module
38
+ */
39
+ /**
40
+ * Canonical sort representation: `[fieldName, direction]`.
41
+ *
42
+ * Used in `FindParams.orderBy`, `collection.sort`, and `FilterPreset.sort`.
43
+ * The colon-string form (`"field:direction"`) exists only at the HTTP wire
44
+ * boundary, handled by `serializeOrderBy` / `deserializeOrderBy` in
45
+ * `@rebasepro/common`.
46
+ *
47
+ * Design note: the natural extension for multi-column sort is
48
+ * `OrderByTuple[]` — not implemented yet (server consumes only the first).
49
+ *
50
+ * @group Models
51
+ */
52
+ export type OrderByTuple<Key extends string = string> = [Key, "asc" | "desc"];
53
+ /**
54
+ * Canonical filter operators supported across all database backends.
55
+ * Each DB driver translates these to its native query format.
56
+ *
57
+ * @group Models
58
+ */
59
+ export type WhereFilterOp = "<" | "<=" | "==" | "!=" | ">=" | ">" | "array-contains" | "in" | "not-in" | "array-contains-any" | "like" | "ilike" | "not-like" | "not-ilike" | "is-null" | "is-not-null";
60
+ /**
61
+ * Used to define filters applied in collections.
62
+ *
63
+ * A single condition is a tuple `[operator, value]`.
64
+ * Multiple conditions on the same field use an array of tuples.
65
+ *
66
+ * @example
67
+ * // Single condition per field
68
+ * { status: ["==", "active"], price: [">=", 9.99] }
69
+ *
70
+ * // Multiple conditions on one field
71
+ * { age: [[">=", 18], ["<", 65]] }
72
+ *
73
+ * // Array operators
74
+ * { role: ["in", ["admin", "editor"]] }
75
+ * { tags: ["array-contains", "featured"] }
76
+ *
77
+ * // Pattern matching (SQL wildcards: % and _)
78
+ * { name: ["ilike", "%john%"] }
79
+ * { slug: ["like", "post-%"] }
80
+ *
81
+ * // Null checks (the value is ignored; `null` is conventional)
82
+ * { deleted_at: ["is-null", null] }
83
+ * { published_at: ["is-not-null", null] }
84
+ *
85
+ * @group Models
86
+ */
87
+ export type FilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp, unknown] | [WhereFilterOp, unknown][]>>;
88
+ /**
89
+ * Relaxed filter type that also accepts pre-serialized PostgREST strings.
90
+ * **Internal only** — used at the wire-format boundary
91
+ * (`serializeFilter` / `deserializeFilter` in `@rebasepro/common`).
92
+ *
93
+ * Application code, UI components, and SDK consumers should use
94
+ * {@link FilterValues} instead.
95
+ *
96
+ * @internal
97
+ */
98
+ export type WireFilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp, unknown] | [WhereFilterOp, unknown][] | string>>;
99
+ /**
100
+ * A pre-defined filter preset for quick access in the collection toolbar.
101
+ * Users can select a preset to instantly apply a set of filters and
102
+ * optionally a sort order.
103
+ *
104
+ * @group Models
105
+ */
106
+ export interface FilterPreset<Key extends string = string> {
107
+ /**
108
+ * Display label shown in the preset menu.
109
+ * If omitted, a summary is auto-generated from the filter keys.
110
+ */
111
+ label?: string;
112
+ /**
113
+ * The filter values to apply when this preset is selected.
114
+ */
115
+ filterValues: FilterValues<Key>;
116
+ /**
117
+ * Optional sort override to apply alongside the filter values.
118
+ */
119
+ sort?: OrderByTuple<Key>;
120
+ }
121
+ /**
122
+ * PostgREST short-code operators. Wire format only — these never appear
123
+ * in application code. Used by `serializeFilter`/`deserializeFilter`
124
+ * in `@rebasepro/common`.
125
+ */
126
+ export type RestFilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "nin" | "cs" | "csa" | "like" | "ilike" | "nlike" | "nilike" | "isnull" | "notnull";
127
+ /** Maps canonical operators to their REST short-code equivalents. */
128
+ export declare const CANONICAL_TO_REST: Readonly<Record<WhereFilterOp, RestFilterOp>>;
129
+ /** Maps REST short-code operators to their canonical equivalents. */
130
+ export declare const REST_TO_CANONICAL: Readonly<Record<RestFilterOp, WhereFilterOp>>;
131
+ /**
132
+ * Operators that test for null/not-null and therefore ignore their value.
133
+ * Codecs normalize the value of these conditions to `null`.
134
+ */
135
+ export declare const NULL_OPS: ReadonlySet<WhereFilterOp>;
136
+ /**
137
+ * Every canonical operator, in a stable order. Useful for engine capability
138
+ * declarations ({@link DataSourceCapabilities.filterOperators}) and for
139
+ * building operator subsets.
140
+ * @group Models
141
+ */
142
+ export declare const ALL_WHERE_FILTER_OPS: readonly WhereFilterOp[];
143
+ /**
144
+ * Resolve any operator string (canonical or REST short-code) to its
145
+ * canonical `WhereFilterOp` form. Returns `undefined` for unknown operators.
146
+ *
147
+ * @example
148
+ * toCanonicalOp("==") // "=="
149
+ * toCanonicalOp("eq") // "=="
150
+ * toCanonicalOp("cs") // "array-contains"
151
+ * toCanonicalOp("xyz") // undefined
152
+ */
153
+ export declare function toCanonicalOp(op: string): WhereFilterOp | undefined;
@@ -1,13 +1,14 @@
1
1
  export * from "./entities";
2
+ export * from "./filter-operators";
2
3
  export * from "./chips";
3
4
  export * from "./properties";
4
5
  export * from "./collections";
5
6
  export * from "./relations";
7
+ export * from "./policy";
6
8
  export * from "./locales";
7
9
  export * from "./entity_link_builder";
8
10
  export * from "./user_management_delegate";
9
11
  export * from "./entity_callbacks";
10
- export * from "./entity_overrides";
11
12
  export * from "./export_import";
12
13
  export * from "./modify_collections";
13
14
  export * from "./formex";
@@ -21,8 +22,8 @@ export * from "./entity_actions";
21
22
  export * from "./property_config";
22
23
  export * from "./entity_views";
23
24
  export * from "./data_source";
25
+ export * from "./storage_source";
24
26
  export * from "./cron";
25
- export * from "./backend_hooks";
26
27
  export * from "./component_ref";
27
28
  export * from "./auth_adapter";
28
29
  export * from "./database_adapter";
@@ -1,5 +1,5 @@
1
- import { EntityCollection } from "./collections";
1
+ import { CollectionConfig } from "./collections";
2
2
  export type ModifyCollectionProps = {
3
- collection: EntityCollection;
3
+ collection: CollectionConfig;
4
4
  parentPaths: string[];
5
5
  };
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren } from "react";
2
- import type { EntityCollection } from "./collections";
2
+ import type { CollectionConfig } from "./collections";
3
3
  import type { EntityStatus } from "./entities";
4
4
  import type { InferPropertyType, Property } from "./properties";
5
5
  import type { FormContext } from "./entity_views";
@@ -136,17 +136,17 @@ export interface PluginHooks {
136
136
  /**
137
137
  * Modify a single collection before it is rendered (synchronous).
138
138
  */
139
- modifyCollection?: (collection: EntityCollection) => EntityCollection;
139
+ modifyCollection?: (collection: CollectionConfig) => CollectionConfig;
140
140
  /**
141
141
  * Async version of modifyCollection — supports fetching remote config.
142
142
  * Runs during navigation resolution. If provided alongside `modifyCollection`,
143
143
  * the sync version runs first, then the async version.
144
144
  */
145
- modifyCollectionAsync?: (collection: EntityCollection) => Promise<EntityCollection>;
145
+ modifyCollectionAsync?: (collection: CollectionConfig) => Promise<CollectionConfig>;
146
146
  /**
147
147
  * Modify, add or remove collections.
148
148
  */
149
- injectCollections?: (collections: EntityCollection[]) => EntityCollection[];
149
+ injectCollections?: (collections: CollectionConfig[]) => CollectionConfig[];
150
150
  /**
151
151
  * Callback called when columns are reordered via drag and drop.
152
152
  */
@@ -154,7 +154,7 @@ export interface PluginHooks {
154
154
  fullPath: string;
155
155
  parentCollectionSlugs: string[];
156
156
  parentEntityIds: string[];
157
- collection: EntityCollection;
157
+ collection: CollectionConfig;
158
158
  newPropertiesOrder: string[];
159
159
  }) => void;
160
160
  /**
@@ -164,7 +164,7 @@ export interface PluginHooks {
164
164
  fullPath: string;
165
165
  parentCollectionSlugs: string[];
166
166
  parentEntityIds: string[];
167
- collection: EntityCollection;
167
+ collection: CollectionConfig;
168
168
  kanbanColumnProperty: string;
169
169
  newColumnsOrder: string[];
170
170
  }) => void;
@@ -226,7 +226,7 @@ export interface FieldBuilderConfig {
226
226
  * Props passed to home page collection card action components.
227
227
  * @group Models
228
228
  */
229
- export interface PluginHomePageActionsProps<EP extends object = object, M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User, EC extends EntityCollection<M> = EntityCollection<M>> {
229
+ export interface PluginHomePageActionsProps<EP extends object = object, M extends Record<string, unknown> = Record<string, unknown>, USER extends User = User, EC extends CollectionConfig<M> = CollectionConfig<M>> {
230
230
  slug: string;
231
231
  collection: EC;
232
232
  context: RebaseContext<USER>;
@@ -235,7 +235,7 @@ export interface PluginHomePageActionsProps<EP extends object = object, M extend
235
235
  * Props passed to form action components in entity edit/form views.
236
236
  * @group Models
237
237
  */
238
- export interface PluginFormActionProps<USER extends User = User, EC extends EntityCollection = EntityCollection> {
238
+ export interface PluginFormActionProps<USER extends User = User, EC extends CollectionConfig = CollectionConfig> {
239
239
  entityId?: string | number;
240
240
  path: string;
241
241
  parentCollectionSlugs: string[];
@@ -251,7 +251,7 @@ export interface PluginFormActionProps<USER extends User = User, EC extends Enti
251
251
  * Parameters passed to the field builder wrap function.
252
252
  * @group Models
253
253
  */
254
- export type PluginFieldBuilderParams<M extends Record<string, unknown> = Record<string, unknown>, EC extends EntityCollection<M> = EntityCollection<M>> = {
254
+ export type PluginFieldBuilderParams<M extends Record<string, unknown> = Record<string, unknown>, EC extends CollectionConfig<M> = CollectionConfig<M>> = {
255
255
  fieldConfigId: string;
256
256
  propertyKey: string;
257
257
  property: Property;
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Structured, engine-agnostic policy expressions.
3
+ *
4
+ * A {@link PolicyExpression} is the single source of truth for a row-level
5
+ * security condition. It is compiled to Postgres `USING`/`WITH CHECK` SQL
6
+ * (authoritative enforcement) and independently evaluated in JavaScript (to
7
+ * drive the admin UI, and — in future — to enforce on engines without native
8
+ * RLS such as MongoDB). Because both the SQL and the JS decision derive from
9
+ * the *same* expression, the UI matches database enforcement by construction —
10
+ * no drift between two hand-written implementations.
11
+ *
12
+ * The only escape hatch that cannot be evaluated client-side is the
13
+ * {@link RawPolicyExpression} node (`{ kind: "raw" }`): it preserves full
14
+ * PostgreSQL power but, being arbitrary SQL, is treated as *unknown* by the
15
+ * JavaScript evaluator (never silently allowed) and reflected exactly in the UI
16
+ * via server-computed capability flags.
17
+ *
18
+ * @group Models
19
+ */
20
+ export type PolicyExpression = TruePolicyExpression | FalsePolicyExpression | AndPolicyExpression | OrPolicyExpression | NotPolicyExpression | ComparePolicyExpression | RolesOverlapPolicyExpression | RolesContainPolicyExpression | AuthenticatedPolicyExpression | ExistsInPolicyExpression | RawPolicyExpression;
21
+ /** Always allows. Compiles to `true`. @group Models */
22
+ export interface TruePolicyExpression {
23
+ kind: "true";
24
+ }
25
+ /** Always denies. Compiles to `false`. @group Models */
26
+ export interface FalsePolicyExpression {
27
+ kind: "false";
28
+ }
29
+ /** Logical AND — every operand must pass. @group Models */
30
+ export interface AndPolicyExpression {
31
+ kind: "and";
32
+ operands: readonly PolicyExpression[];
33
+ }
34
+ /** Logical OR — at least one operand must pass. @group Models */
35
+ export interface OrPolicyExpression {
36
+ kind: "or";
37
+ operands: readonly PolicyExpression[];
38
+ }
39
+ /** Logical negation. @group Models */
40
+ export interface NotPolicyExpression {
41
+ kind: "not";
42
+ operand: PolicyExpression;
43
+ }
44
+ /** Comparison operators available to {@link ComparePolicyExpression}. @group Models */
45
+ export type PolicyCompareOperator = "eq" | "neq" | "lt" | "lte" | "gt" | "gte";
46
+ /**
47
+ * Compares two operands, e.g. `owner_id = auth.uid()`.
48
+ * @group Models
49
+ */
50
+ export interface ComparePolicyExpression {
51
+ kind: "compare";
52
+ op: PolicyCompareOperator;
53
+ left: PolicyOperand;
54
+ right: PolicyOperand;
55
+ }
56
+ /**
57
+ * True when the user holds *at least one* of the given application roles.
58
+ * Compiles to `string_to_array(auth.roles(), ',') && ARRAY[...]`.
59
+ * @group Models
60
+ */
61
+ export interface RolesOverlapPolicyExpression {
62
+ kind: "rolesOverlap";
63
+ roles: readonly string[];
64
+ }
65
+ /**
66
+ * True when the user holds *all* of the given application roles.
67
+ * Compiles to `string_to_array(auth.roles(), ',') @> ARRAY[...]`.
68
+ * @group Models
69
+ */
70
+ export interface RolesContainPolicyExpression {
71
+ kind: "rolesContain";
72
+ roles: readonly string[];
73
+ }
74
+ /**
75
+ * True when there is an authenticated user (`auth.uid() IS NOT NULL`).
76
+ * @group Models
77
+ */
78
+ export interface AuthenticatedPolicyExpression {
79
+ kind: "authenticated";
80
+ }
81
+ /**
82
+ * Membership / relational access: true when at least one row exists in another
83
+ * collection (a join/membership table) matching `where`. This is what lets you
84
+ * scope reads to "rows whose team the caller belongs to" without an N+1
85
+ * per-row lookup — it compiles to a single correlated `EXISTS` subquery.
86
+ *
87
+ * Inside `where`, {@link FieldPolicyOperand} (`policy.field`) references a column
88
+ * of the joined collection, while {@link OuterFieldPolicyOperand}
89
+ * (`policy.outerField`) references a column of the row being checked (the outer
90
+ * table under RLS). Combine with {@link AuthUidPolicyOperand} to correlate to
91
+ * the caller.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * // documents visible only to members of the document's team:
96
+ * policy.existsIn({
97
+ * collection: "team_members",
98
+ * where: policy.and(
99
+ * policy.compare(policy.field("team_id"), "eq", policy.outerField("team_id")),
100
+ * policy.compare(policy.field("user_id"), "eq", policy.authUid()),
101
+ * ),
102
+ * })
103
+ * // → EXISTS (SELECT 1 FROM team_members _ex0
104
+ * // WHERE _ex0.team_id = documents.team_id AND _ex0.user_id = auth.uid())
105
+ * ```
106
+ *
107
+ * Postgres-authoritative: like {@link RawPolicyExpression}, the JavaScript
108
+ * evaluator treats it as *unknown* (it cannot run a subquery client-side), so
109
+ * enforcement is always the database's.
110
+ * @group Models
111
+ */
112
+ export interface ExistsInPolicyExpression {
113
+ kind: "existsIn";
114
+ /** Slug of the collection to search (the join / membership table). */
115
+ collection: string;
116
+ /** Condition evaluated against the joined collection's rows. */
117
+ where: PolicyExpression;
118
+ }
119
+ /**
120
+ * A raw PostgreSQL boolean expression — the full-power escape hatch.
121
+ *
122
+ * Columns can be referenced as `{column_name}`. This is Postgres-only and
123
+ * **server-authoritative**: the JavaScript evaluator cannot evaluate arbitrary
124
+ * SQL, so it treats this node as *unknown* rather than guessing.
125
+ * @group Models
126
+ */
127
+ export interface RawPolicyExpression {
128
+ kind: "raw";
129
+ sql: string;
130
+ }
131
+ /**
132
+ * An operand referenced by a {@link ComparePolicyExpression}.
133
+ * @group Models
134
+ */
135
+ export type PolicyOperand = FieldPolicyOperand | OuterFieldPolicyOperand | LiteralPolicyOperand | AuthUidPolicyOperand | AuthRolesPolicyOperand;
136
+ /** A column value on the row being evaluated. @group Models */
137
+ export interface FieldPolicyOperand {
138
+ kind: "field";
139
+ /** The property/column name (resolved to its DB column when compiled). */
140
+ name: string;
141
+ }
142
+ /**
143
+ * A column value on the *outer* row when used inside {@link ExistsInPolicyExpression}
144
+ * — i.e. the row the RLS policy is being evaluated for, referenced from within the
145
+ * subquery. Outside an `existsIn` it is equivalent to {@link FieldPolicyOperand}.
146
+ * @group Models
147
+ */
148
+ export interface OuterFieldPolicyOperand {
149
+ kind: "outerField";
150
+ /** The property/column name on the outer collection. */
151
+ name: string;
152
+ }
153
+ /** A constant value. @group Models */
154
+ export interface LiteralPolicyOperand {
155
+ kind: "literal";
156
+ value: string | number | boolean | null;
157
+ }
158
+ /** The current user's id — compiles to `auth.uid()`. @group Models */
159
+ export interface AuthUidPolicyOperand {
160
+ kind: "authUid";
161
+ }
162
+ /**
163
+ * The current user's roles as an array — compiles to
164
+ * `string_to_array(auth.roles(), ',')`.
165
+ * @group Models
166
+ */
167
+ export interface AuthRolesPolicyOperand {
168
+ kind: "authRoles";
169
+ }
170
+ /** @group Models */
171
+ export declare const policy: {
172
+ true: () => TruePolicyExpression;
173
+ false: () => FalsePolicyExpression;
174
+ and: (...operands: readonly PolicyExpression[]) => AndPolicyExpression;
175
+ or: (...operands: readonly PolicyExpression[]) => OrPolicyExpression;
176
+ not: (operand: PolicyExpression) => NotPolicyExpression;
177
+ compare: (left: PolicyOperand, op: PolicyCompareOperator, right: PolicyOperand) => ComparePolicyExpression;
178
+ rolesOverlap: (roles: readonly string[]) => RolesOverlapPolicyExpression;
179
+ rolesContain: (roles: readonly string[]) => RolesContainPolicyExpression;
180
+ authenticated: () => AuthenticatedPolicyExpression;
181
+ existsIn: (args: {
182
+ collection: string;
183
+ where: PolicyExpression;
184
+ }) => ExistsInPolicyExpression;
185
+ raw: (sql: string) => RawPolicyExpression;
186
+ field: (name: string) => FieldPolicyOperand;
187
+ outerField: (name: string) => OuterFieldPolicyOperand;
188
+ literal: (value: string | number | boolean | null) => LiteralPolicyOperand;
189
+ authUid: () => AuthUidPolicyOperand;
190
+ authRoles: () => AuthRolesPolicyOperand;
191
+ };