@rebasepro/types 0.30.1 → 0.31.0-canary.g902a0ce

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 (57) hide show
  1. package/README.md +16 -18
  2. package/dist/call_context.d.ts +3 -3
  3. package/dist/controllers/client.d.ts +29 -0
  4. package/dist/controllers/data.d.ts +85 -332
  5. package/dist/controllers/data_driver.d.ts +47 -57
  6. package/dist/controllers/index.d.ts +0 -3
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.es.js +2567 -1151
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/schema/column_options.d.ts +336 -0
  11. package/dist/schema/column_type.d.ts +116 -0
  12. package/dist/schema/columns.d.ts +646 -0
  13. package/dist/schema/compiled.d.ts +114 -0
  14. package/dist/schema/descriptor.d.ts +349 -0
  15. package/dist/schema/hooks.d.ts +164 -0
  16. package/dist/schema/index.d.ts +13 -0
  17. package/dist/schema/infer.d.ts +340 -0
  18. package/dist/schema/json.d.ts +237 -0
  19. package/dist/schema/relations.d.ts +205 -0
  20. package/dist/schema/table.d.ts +304 -0
  21. package/dist/schema/table_options.d.ts +103 -0
  22. package/dist/schema/table_patch.d.ts +338 -0
  23. package/dist/types/auth_adapter.d.ts +5 -5
  24. package/dist/types/auth_hooks.d.ts +65 -0
  25. package/dist/types/backend.d.ts +85 -96
  26. package/dist/types/data_source.d.ts +4 -9
  27. package/dist/types/database_adapter.d.ts +30 -31
  28. package/dist/types/entities.d.ts +0 -162
  29. package/dist/types/filter-operators.d.ts +2 -26
  30. package/dist/types/history.d.ts +6 -9
  31. package/dist/types/index.d.ts +3 -9
  32. package/dist/types/mcp_app_modules.d.ts +0 -2
  33. package/dist/types/policy.d.ts +85 -10
  34. package/dist/types/project_manifest.d.ts +113 -46
  35. package/dist/types/read_query.d.ts +98 -0
  36. package/dist/types/register.d.ts +35 -5
  37. package/dist/types/relations.d.ts +0 -430
  38. package/dist/types/schema_editing.d.ts +54 -2
  39. package/dist/types/schema_version.d.ts +24 -4
  40. package/dist/types/security_rules.d.ts +225 -15
  41. package/dist/types/storage_authorize.d.ts +2 -2
  42. package/dist/types/tenancy.d.ts +3 -3
  43. package/dist/types/ui_preferences.d.ts +228 -0
  44. package/package.json +3 -2
  45. package/dist/controllers/auth_state.d.ts +0 -23
  46. package/dist/controllers/collection_registry.d.ts +0 -67
  47. package/dist/controllers/effective_role.d.ts +0 -4
  48. package/dist/types/admin_block.d.ts +0 -96
  49. package/dist/types/chips.d.ts +0 -16
  50. package/dist/types/collection_contract.d.ts +0 -43
  51. package/dist/types/collection_patch.d.ts +0 -74
  52. package/dist/types/collections.d.ts +0 -783
  53. package/dist/types/component_ref.d.ts +0 -81
  54. package/dist/types/conditions-contract.types.d.ts +0 -14
  55. package/dist/types/entity_callbacks.d.ts +0 -393
  56. package/dist/types/indexes.d.ts +0 -179
  57. package/dist/types/properties.d.ts +0 -1640
@@ -1,167 +1,5 @@
1
- import type { SearchMatch } from "./search.js";
2
1
  /**
3
2
  * New or existing status
4
3
  * @group Models
5
4
  */
6
5
  export type EntityStatus = "new" | "existing" | "copy";
7
- /**
8
- * Representation of a entity fetched from the driver
9
- * @group Models
10
- */
11
- export interface Entity<M extends Record<string, unknown> = Record<string, unknown>> {
12
- /**
13
- * ID of the entity
14
- */
15
- id: string | number;
16
- /**
17
- * A string representing the path of the referenced document (relative
18
- * to the root of the database).
19
- */
20
- path: string;
21
- /**
22
- * Current values
23
- */
24
- values: EntityValues<M>;
25
- /**
26
- * Why this entity is in a search result: which declared fields matched, and
27
- * the text around each hit.
28
- *
29
- * Present only on rows returned by a search that asked for it. A sibling of
30
- * `values` rather than a key inside it, because it describes the *query*,
31
- * not the record — nothing in the collection declares it, no form edits it,
32
- * and a record fetched by id never has one.
33
- */
34
- searchMatches?: SearchMatch[];
35
- /**
36
- * The version of the row this entity was read at: the `ETag` the read
37
- * reported, for a `findById`, a `PATCH` answer or a live row frame. A
38
- * form saves with it as `If-Match`, so a write made against a version
39
- * someone has since replaced is refused instead of reverting their change.
40
- *
41
- * Absent for a row from a list, from a cache, or from a server or data
42
- * source that does not report versions — a save then is unconditional,
43
- * as it always was.
44
- */
45
- etag?: string;
46
- /**
47
- * Which driver this entity belongs to (e.g., 'postgres', 'firestore').
48
- * If not specified, the default driver is assumed.
49
- */
50
- driver?: string;
51
- /**
52
- * Which database within the driver (e.g., for Firestore multi-database).
53
- * If not specified, the default database of the driver is used.
54
- */
55
- databaseId?: string;
56
- }
57
- /**
58
- * This type represents a record of key value pairs as described in an
59
- * entity collection.
60
- * @group Models
61
- */
62
- export type EntityValues<M extends Record<string, unknown>> = M;
63
- /**
64
- * Props for creating a EntityReference
65
- */
66
- export interface EntityReferenceProps {
67
- /** ID of the entity */
68
- id: string;
69
- /** Path of the collection (relative to the root of the database) */
70
- path: string;
71
- /** Which driver (e.g., 'postgres', 'firestore'). Defaults to "(default)" */
72
- driver?: string;
73
- /** Which database within the driver. Defaults to "(default)" */
74
- databaseId?: string;
75
- }
76
- /**
77
- * Class used to create a reference to a entity in a different path.
78
- *
79
- * @example
80
- * // Simple reference (most common case - single driver, single db)
81
- * new EntityReference({ id: "123", path: "users" })
82
- *
83
- * // Reference to a different driver (e.g., Firestore)
84
- * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
85
- *
86
- * // Reference to a specific database within a driver
87
- * new EntityReference({ id: "123", path: "orders", driver: "postgres", databaseId: "orders_db" })
88
- */
89
- export declare class EntityReference {
90
- readonly __type = "reference";
91
- /**
92
- * ID of the entity
93
- */
94
- readonly id: string;
95
- /**
96
- * A string representing the path of the referenced document (relative
97
- * to the root of the database).
98
- */
99
- readonly path: string;
100
- /**
101
- * Which driver (e.g., 'postgres', 'firestore').
102
- * Defaults to "(default)" if not specified.
103
- */
104
- readonly driver?: string;
105
- /**
106
- * Which database within the driver.
107
- * Defaults to "(default)" if not specified.
108
- */
109
- readonly databaseId?: string;
110
- /**
111
- * Create a reference to a entity.
112
- *
113
- * @example
114
- * // Simple reference (most common case)
115
- * new EntityReference({ id: "123", path: "users" })
116
- *
117
- * // With driver
118
- * new EntityReference({ id: "123", path: "analytics", driver: "firestore" })
119
- */
120
- constructor(props: EntityReferenceProps);
121
- get pathWithId(): string;
122
- /**
123
- * Get the full path including driver and database prefixes if specified.
124
- * For the common case (single driver, single db), this just returns pathWithId.
125
- */
126
- get fullPath(): string;
127
- isEntityReference(): boolean;
128
- }
129
- /**
130
- * Class used to create a reference to a entity in a different path
131
- */
132
- export declare class EntityRelation {
133
- readonly __type = "relation";
134
- /**
135
- * ID of the entity
136
- */
137
- readonly id: string | number;
138
- /**
139
- * A string representing the path of the referenced document (relative
140
- * to the root of the database).
141
- */
142
- readonly path: string;
143
- /**
144
- * Pre-fetched data payload to eliminate N+1 queries.
145
- * When present, clients can use this directly instead of fetching.
146
- */
147
- readonly data?: Record<string, unknown>;
148
- constructor(id: string | number, path: string, data?: Record<string, unknown>);
149
- get pathWithId(): string;
150
- isEntityReference(): boolean;
151
- isEntityRelation(): boolean;
152
- }
153
- export declare class GeoPoint {
154
- /**
155
- * The latitude of this GeoPoint instance.
156
- */
157
- readonly latitude: number;
158
- /**
159
- * The longitude of this GeoPoint instance.
160
- */
161
- readonly longitude: number;
162
- constructor(latitude: number, longitude: number);
163
- }
164
- export declare class Vector {
165
- readonly value: number[];
166
- constructor(value: number[]);
167
- }
@@ -32,9 +32,8 @@
32
32
  * └──────────────────────┴───────────────┴──────────────────────────────┘
33
33
  *
34
34
  * Pattern matching (`like`/`ilike`) uses SQL wildcard syntax: `%` matches any
35
- * sequence of characters, `_` matches a single character. On MongoDB these are
36
- * translated to anchored regular expressions; Firestore has no native pattern
37
- * matching and rejects these operators (use `searchString` instead).
35
+ * sequence of characters, `_` matches a single character. Firestore has no
36
+ * native pattern matching and rejects these operators (use `searchString` instead).
38
37
  *
39
38
  * @module
40
39
  */
@@ -312,29 +311,6 @@ export declare function parseCaseFoldedFieldPath(key: string): {
312
311
  * @internal
313
312
  */
314
313
  export type WireFilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp, unknown] | [WhereFilterOp, unknown][] | string>>;
315
- /**
316
- * A pre-defined filter preset for quick access in the collection toolbar.
317
- * Users can select a preset to instantly apply a set of filters and
318
- * optionally a sort order.
319
- *
320
- * @group Models
321
- */
322
- export interface FilterPreset<Key extends string = string> {
323
- /**
324
- * Display label shown in the preset menu.
325
- * If omitted, a summary is auto-generated from the filter keys.
326
- */
327
- label?: string;
328
- /**
329
- * The filter values to apply when this preset is selected.
330
- */
331
- filterValues: FilterValues<Key>;
332
- /**
333
- * Optional sort override to apply alongside the filter values.
334
- * One key, or several in order of significance.
335
- */
336
- sort?: OrderBySpec<Key>;
337
- }
338
314
  /**
339
315
  * PostgREST short-code operators. Wire format only — these never appear
340
316
  * in application code. Used by `serializeFilter`/`deserializeFilter`
@@ -1,16 +1,13 @@
1
1
  /**
2
2
  * Entity change history — the shape a history entry has on the wire.
3
3
  *
4
- * This was declared three times: once in `@rebasepro/server-postgres`, once in
5
- * `@rebasepro/server-mongo`, and once again in the admin's `useHistory` hook.
6
- * The two driver copies disagreed on the one field that matters for a consumer,
7
- * `updated_at`, which was a `string` in Postgres and a `Date` in MongoDB — so
8
- * nothing could read history without first choosing a driver.
4
+ * This was declared once per driver and once again in the admin's `useHistory`
5
+ * hook, and the copies disagreed on the one field that matters for a consumer,
6
+ * `updated_at` — so nothing could read history without first choosing a driver.
9
7
  *
10
8
  * The contract is the wire shape, and on the wire it is an ISO-8601 string.
11
- * A driver whose stored document differs (MongoDB keeps a `Date` and an
12
- * `ObjectId`) declares that storage row for itself and maps to this on the way
13
- * out; it is not the shared type.
9
+ * A driver whose stored row differs declares that storage row for itself and
10
+ * maps to this on the way out; it is not the shared type.
14
11
  *
15
12
  * @group Backend
16
13
  */
@@ -20,7 +17,7 @@
20
17
  */
21
18
  export interface EntityHistoryEntry {
22
19
  id: string;
23
- /** The table (Postgres) or collection (MongoDB) the row belongs to. */
20
+ /** The table the row belongs to. */
24
21
  table_name: string;
25
22
  /** The row's id, as a string regardless of its native type. */
26
23
  entity_id: string;
@@ -1,21 +1,16 @@
1
1
  export * from "./entities.js";
2
2
  export * from "./filter-operators.js";
3
- export * from "./chips.js";
4
- export * from "./properties.js";
5
- export * from "./admin_block.js";
6
- export * from "./collections.js";
7
3
  export * from "./search.js";
8
- export * from "./indexes.js";
9
4
  export * from "./relations.js";
5
+ export * from "./read_query.js";
6
+ export * from "./auth_hooks.js";
10
7
  export * from "./policy.js";
11
8
  export * from "./rls-functions.js";
12
9
  export * from "./security_rules.js";
13
10
  export * from "./tenancy.js";
14
- export * from "./entity_callbacks.js";
15
11
  export * from "./websockets.js";
16
12
  export * from "./backend.js";
17
13
  export * from "./schema_editing.js";
18
- export * from "./collection_patch.js";
19
14
  export * from "./channel_bus.js";
20
15
  export * from "./data_source.js";
21
16
  export * from "./resources.js";
@@ -24,7 +19,6 @@ export * from "./storage_source.js";
24
19
  export * from "./env_boolean.js";
25
20
  export * from "./cron.js";
26
21
  export * from "./backup.js";
27
- export * from "./component_ref.js";
28
22
  export * from "./auth_adapter.js";
29
23
  export * from "./database_adapter.js";
30
24
  export * from "./api_keys.js";
@@ -33,8 +27,8 @@ export * from "./history.js";
33
27
  export * from "./postgres_introspection.js";
34
28
  export * from "./project_manifest.js";
35
29
  export * from "./content_hash.js";
36
- export * from "./collection_contract.js";
37
30
  export * from "./schema_version.js";
38
31
  export * from "./storage_authorize.js";
39
32
  export * from "./register.js";
40
33
  export * from "./mcp_app_modules.js";
34
+ export * from "./ui_preferences.js";
@@ -24,5 +24,3 @@ export declare const MCP_APP_MODULES: {
24
24
  };
25
25
  /** A module an app may import. */
26
26
  export type McpAppModule = keyof typeof MCP_APP_MODULES;
27
- /** The names a module with a served list hands out. */
28
- export type McpAppModuleExport<M extends McpAppModule> = (typeof MCP_APP_MODULES)[M] extends readonly (infer N extends string)[] ? N : string;
@@ -4,8 +4,7 @@
4
4
  * A {@link PolicyExpression} is the single source of truth for a row-level
5
5
  * security condition. It is compiled to Postgres `USING`/`WITH CHECK` SQL
6
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
7
+ * drive the admin UI). Because both the SQL and the JS decision derive from
9
8
  * the *same* expression, the UI matches database enforcement by construction —
10
9
  * no drift between two hand-written implementations.
11
10
  *
@@ -184,12 +183,12 @@ export interface ServerContextPolicyExpression {
184
183
  }
185
184
  /**
186
185
  * Membership / relational access: true when at least one row exists in another
187
- * collection (a join/membership table) matching `where`. This is what lets you
186
+ * table (a join/membership table) matching `where`. This is what lets you
188
187
  * scope reads to "rows whose team the caller belongs to" without an N+1
189
188
  * per-row lookup — it compiles to a single correlated `EXISTS` subquery.
190
189
  *
191
190
  * Inside `where`, {@link FieldPolicyOperand} (`policy.field`) references a column
192
- * of the joined collection, while {@link OuterFieldPolicyOperand}
191
+ * of the joined table, while {@link OuterFieldPolicyOperand}
193
192
  * (`policy.outerField`) references a column of the row being checked (the outer
194
193
  * table under RLS). Combine with {@link AuthUidPolicyOperand} to correlate to
195
194
  * the caller.
@@ -198,7 +197,7 @@ export interface ServerContextPolicyExpression {
198
197
  * ```ts
199
198
  * // documents visible only to members of the document's team:
200
199
  * policy.existsIn({
201
- * collection: "team_members",
200
+ * table: "team_members",
202
201
  * where: policy.and(
203
202
  * policy.compare(policy.field("team_id"), "eq", policy.outerField("team_id")),
204
203
  * policy.compare(policy.field("user_id"), "eq", policy.authUid()),
@@ -215,9 +214,15 @@ export interface ServerContextPolicyExpression {
215
214
  */
216
215
  export interface ExistsInPolicyExpression {
217
216
  kind: "existsIn";
218
- /** Slug of the collection to search (the join / membership table). */
219
- collection: string;
220
- /** Condition evaluated against the joined collection's rows. */
217
+ /**
218
+ * The table to search (the join / membership table), by its slug.
219
+ *
220
+ * Spelled `collection` before tables replaced collections in the backend
221
+ * vocabulary. A policy's name hashes the rule as written, so the name
222
+ * hash still reads this field as `collection` (see `getPolicyNameHash`).
223
+ */
224
+ table: string;
225
+ /** Condition evaluated against the joined table's rows. */
221
226
  where: PolicyExpression;
222
227
  }
223
228
  /**
@@ -251,7 +256,7 @@ export interface FieldPolicyOperand {
251
256
  */
252
257
  export interface OuterFieldPolicyOperand {
253
258
  kind: "outerField";
254
- /** The property/column name on the outer collection. */
259
+ /** The property/column name on the outer table. */
255
260
  name: string;
256
261
  }
257
262
  /** A constant value. @group Models */
@@ -308,6 +313,76 @@ export interface AuthClaimPolicyOperand {
308
313
  /** The claim's name on the token, e.g. `"org_id"`. */
309
314
  name: string;
310
315
  }
316
+ /**
317
+ * A value a {@link PolicyShorthand} compares a column with.
318
+ * @group Models
319
+ */
320
+ export type PolicyShorthandValue = string | number | boolean | null;
321
+ /**
322
+ * The plain-object form of a row condition: `{ status: "published" }`.
323
+ *
324
+ * Every key is a column key of the table and every value a literal; the
325
+ * condition holds when **each** column equals its value (an AND of
326
+ * equalities), and a `null` value means the column `IS NULL`. It is what
327
+ * `policy.and(policy.compare(policy.field(k), "eq", policy.literal(v)), …)`
328
+ * spells longhand, and compiles to the same SQL — except `null`, which no
329
+ * comparison can express (`x = NULL` is never true) and which therefore
330
+ * compiles to `x IS NULL`.
331
+ *
332
+ * - **No key may be named `kind`.** `kind` is how a {@link PolicyExpression}
333
+ * is recognised at runtime, so `{ kind: "true" }` would be read as the
334
+ * expression that grants everything. The type refuses it and so does the
335
+ * compiler; compare a column called `kind` with the longhand form.
336
+ * - **At least one key.** `{}` would be an AND of nothing, which is `true`;
337
+ * the compiler refuses it — write `policy.true()` if every row is meant.
338
+ * - The keys are checked against the table when the rule is compiled: a key
339
+ * that names no column is refused, with the table and the key in the error.
340
+ *
341
+ * Use {@link isPolicyShorthand} to tell it apart from a `PolicyExpression`.
342
+ *
343
+ * @example
344
+ * { operation: "select", access: "public", condition: { status: "published" } }
345
+ * { operation: "select", condition: { orgId: "acme", deletedAt: null } }
346
+ *
347
+ * @group Models
348
+ */
349
+ export type PolicyShorthand = {
350
+ readonly [column: string]: PolicyShorthandValue;
351
+ } & {
352
+ readonly kind?: never;
353
+ };
354
+ /**
355
+ * What a rule's `condition` / `check` accepts: a structured
356
+ * {@link PolicyExpression}, or the {@link PolicyShorthand} object form.
357
+ * @group Models
358
+ */
359
+ export type PolicyCondition = PolicyExpression | PolicyShorthand;
360
+ /**
361
+ * Every `kind` a {@link PolicyExpression} node can have — the discriminator
362
+ * {@link isPolicyShorthand} and {@link isPolicyExpressionKind} read.
363
+ * @group Models
364
+ */
365
+ export declare const POLICY_EXPRESSION_KINDS: readonly PolicyExpression["kind"][];
366
+ /**
367
+ * Whether `kind` names a {@link PolicyExpression} node.
368
+ * @group Models
369
+ */
370
+ export declare function isPolicyExpressionKind(kind: unknown): kind is PolicyExpression["kind"];
371
+ /**
372
+ * Whether a rule's `condition` / `check` is a {@link PolicyShorthand} rather
373
+ * than a {@link PolicyExpression}.
374
+ *
375
+ * True only for a plain object with at least one key, none of them `kind`,
376
+ * whose every value is a string, a finite number, a boolean or `null`. Every
377
+ * expression node carries `kind`, so no expression is ever taken for a
378
+ * shorthand — and an object that has a `kind` key is never taken for a
379
+ * shorthand either, whatever its value: such an object is ambiguous (a column
380
+ * called `kind`, or a misspelt node) and the compiler refuses it rather than
381
+ * guessing.
382
+ *
383
+ * @group Models
384
+ */
385
+ export declare function isPolicyShorthand(value: unknown): value is PolicyShorthand;
311
386
  /** @group Models */
312
387
  export declare const policy: {
313
388
  true: () => TruePolicyExpression;
@@ -322,7 +397,7 @@ export declare const policy: {
322
397
  registered: () => RegisteredPolicyExpression;
323
398
  serverContext: () => ServerContextPolicyExpression;
324
399
  existsIn: (args: {
325
- collection: string;
400
+ table: string;
326
401
  where: PolicyExpression;
327
402
  }) => ExistsInPolicyExpression;
328
403
  raw: (sql: string) => RawPolicyExpression;