@rebasepro/types 0.30.0 → 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 +12 -6
  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
@@ -0,0 +1,336 @@
1
+ import type { ResourceRef } from "../types/resources.js";
2
+ /**
3
+ * Who may read and who may write one column, by role.
4
+ *
5
+ * A list that is absent leaves that direction to the table's `rls`. An empty
6
+ * list closes it to every caller, the server's own code aside. Enforced on
7
+ * every door — REST, realtime, MCP, caller SQL, includes, filters and sorts —
8
+ * never only in the panel.
9
+ *
10
+ * @group Schema
11
+ */
12
+ export interface ColumnAccess {
13
+ /** Roles that receive the column on a read. */
14
+ read?: readonly string[];
15
+ /** Roles that may write the column. */
16
+ write?: readonly string[];
17
+ }
18
+ /**
19
+ * Per-role access in its stored form, checked: `read` and `write` must each be
20
+ * a list of non-empty role names, and nothing else may be given.
21
+ *
22
+ * Checked at runtime because a JavaScript caller writing
23
+ * `.access({ read: "admin" })` would otherwise have the string spread into
24
+ * one role per character, silently.
25
+ *
26
+ * @param where What is being configured, for the error: `column "title"`.
27
+ *
28
+ * @group Schema
29
+ */
30
+ export declare function normalizeColumnAccess(access: unknown, where: string): ColumnAccess;
31
+ /**
32
+ * A value the server writes into a column on its own: the time, or the caller.
33
+ *
34
+ * @group Schema
35
+ */
36
+ export interface ColumnStamp {
37
+ /** `create` stamps on insert only; `update` stamps on every write. */
38
+ on: "create" | "update";
39
+ /** `now` is the current instant; `user` is the id of the caller. */
40
+ value: "now" | "user";
41
+ }
42
+ /**
43
+ * The DEFAULT of a column.
44
+ *
45
+ * - `literal` — a value, written as a DDL default and applied by the driver on
46
+ * create, so every writer gets the same row.
47
+ * - `sql` — an expression Postgres evaluates.
48
+ * - `random-uuid` — `gen_random_uuid()`.
49
+ * - `identity` — `GENERATED BY DEFAULT AS IDENTITY`.
50
+ * - `database` — the database holds a default Rebase does not state and must
51
+ * not drop; a create may omit the column.
52
+ *
53
+ * @group Schema
54
+ */
55
+ export type ColumnDefault = {
56
+ kind: "literal";
57
+ value: unknown;
58
+ } | {
59
+ kind: "sql";
60
+ expression: string;
61
+ } | {
62
+ kind: "random-uuid";
63
+ } | {
64
+ kind: "identity";
65
+ } | {
66
+ kind: "database";
67
+ };
68
+ /** What every `.validate()` accepts. */
69
+ export interface BaseValidation {
70
+ /** The API error when a `.notNull()` column is missing from a create. */
71
+ requiredMessage?: string;
72
+ }
73
+ /**
74
+ * Validation of a text column, checked by the API before a write.
75
+ *
76
+ * @group Schema
77
+ */
78
+ export interface StringValidation extends BaseValidation {
79
+ /** Minimum length. */
80
+ min?: number;
81
+ /** Maximum length. */
82
+ max?: number;
83
+ /** Exact length. */
84
+ length?: number;
85
+ /** A pattern the value must match. A `RegExp` is kept as its source and flags. */
86
+ matches?: string | RegExp;
87
+ /** Flags of `matches`, when it was given as a string. */
88
+ matchesFlags?: string;
89
+ /** The API error when `matches` fails. */
90
+ matchesMessage?: string;
91
+ /** The value must be an e-mail address. */
92
+ email?: boolean;
93
+ /** The value must be a URL. */
94
+ url?: boolean;
95
+ /** Lower-case the value before it is stored. */
96
+ lowercase?: boolean;
97
+ /** Upper-case the value before it is stored. */
98
+ uppercase?: boolean;
99
+ /** Trim surrounding whitespace before the value is stored. */
100
+ trim?: boolean;
101
+ }
102
+ /**
103
+ * Validation of a numeric column, checked by the API before a write.
104
+ *
105
+ * @group Schema
106
+ */
107
+ export interface NumberValidation extends BaseValidation {
108
+ /** Inclusive lower bound. */
109
+ min?: number;
110
+ /** Inclusive upper bound. */
111
+ max?: number;
112
+ /** Exclusive upper bound. */
113
+ lessThan?: number;
114
+ /** Exclusive lower bound. */
115
+ moreThan?: number;
116
+ /** The value must be greater than zero. */
117
+ positive?: boolean;
118
+ /** The value must be less than zero. */
119
+ negative?: boolean;
120
+ /** The value must be a whole number. */
121
+ integer?: boolean;
122
+ }
123
+ /**
124
+ * Validation of a temporal column. Bounds are ISO strings.
125
+ *
126
+ * @group Schema
127
+ */
128
+ export interface DateValidation extends BaseValidation {
129
+ /** Earliest accepted value. */
130
+ min?: string | Date;
131
+ /** Latest accepted value. */
132
+ max?: string | Date;
133
+ }
134
+ /**
135
+ * Validation of an array column.
136
+ *
137
+ * @group Schema
138
+ */
139
+ export interface ArrayValidation extends BaseValidation {
140
+ /** Fewest items accepted. */
141
+ minItems?: number;
142
+ /** Most items accepted. */
143
+ maxItems?: number;
144
+ /** Refuse an array holding the same value twice. */
145
+ uniqueItems?: boolean;
146
+ /**
147
+ * For a JSON array of objects (`json.array(json.object({...}))`): refuse
148
+ * two items with the same value in any one of these fields — each field
149
+ * is unique across the items on its own (`["sku"]`: no SKU twice). The
150
+ * fields are keys of the item object; anything else is refused when the
151
+ * schema compiles.
152
+ */
153
+ uniqueBy?: string[];
154
+ }
155
+ /**
156
+ * Every validation rule a column can carry, as stored on its definition and
157
+ * served on the wire: patterns are strings, date bounds are ISO strings.
158
+ *
159
+ * @group Schema
160
+ */
161
+ export interface ColumnValidation {
162
+ /** The API error when a `.notNull()` column is missing from a create. */
163
+ requiredMessage?: string;
164
+ /**
165
+ * Lower bound: minimum length of text, inclusive minimum of a number, earliest
166
+ * accepted value of a temporal column (an ISO string).
167
+ */
168
+ min?: number | string;
169
+ /**
170
+ * Upper bound: maximum length of text, inclusive maximum of a number, latest
171
+ * accepted value of a temporal column (an ISO string).
172
+ */
173
+ max?: number | string;
174
+ /** Exact length of a text value. */
175
+ length?: number;
176
+ /** A pattern a text value must match: a `RegExp`'s source, its flags in `matchesFlags`. */
177
+ matches?: string;
178
+ /** Flags of `matches` (`"i"`, `"u"`, …). No flags when omitted. */
179
+ matchesFlags?: string;
180
+ /** The API error when `matches` fails. */
181
+ matchesMessage?: string;
182
+ /** A text value must be an e-mail address. */
183
+ email?: boolean;
184
+ /** A text value must be a URL. */
185
+ url?: boolean;
186
+ /** Lower-case a text value before it is stored. */
187
+ lowercase?: boolean;
188
+ /** Upper-case a text value before it is stored. */
189
+ uppercase?: boolean;
190
+ /** Trim surrounding whitespace from a text value before it is stored. */
191
+ trim?: boolean;
192
+ /** Exclusive upper bound of a number. */
193
+ lessThan?: number;
194
+ /** Exclusive lower bound of a number. */
195
+ moreThan?: number;
196
+ /** A number must be greater than zero. */
197
+ positive?: boolean;
198
+ /** A number must be less than zero. */
199
+ negative?: boolean;
200
+ /** A number must be a whole number. */
201
+ integer?: boolean;
202
+ /** Fewest items an array accepts. */
203
+ minItems?: number;
204
+ /** Most items an array accepts. */
205
+ maxItems?: number;
206
+ /** Refuse an array holding the same value twice. */
207
+ uniqueItems?: boolean;
208
+ /** Fields of a JSON array's object items, each unique across the items. See {@link ArrayValidation.uniqueBy}. */
209
+ uniqueBy?: string[];
210
+ }
211
+ /** The rules a builder method accepts, before they are normalized. */
212
+ export type ValidationInput = StringValidation | NumberValidation | DateValidation | ArrayValidation | BaseValidation;
213
+ /**
214
+ * Validation rules in their stored form: a `RegExp` becomes its source and
215
+ * flags, a `Date` bound becomes an ISO string. What a builder keeps is then
216
+ * exactly what the wire carries.
217
+ *
218
+ * @group Schema
219
+ */
220
+ export declare function normalizeValidation(rules: ValidationInput): ColumnValidation;
221
+ /**
222
+ * How an image is resized before it is stored.
223
+ *
224
+ * @group Schema
225
+ */
226
+ export interface StorageImageResize {
227
+ /**
228
+ * Largest width in pixels; a wider image is scaled down proportionally. No
229
+ * width limit when omitted.
230
+ */
231
+ maxWidth?: number;
232
+ /**
233
+ * Largest height in pixels; a taller image is scaled down proportionally. No
234
+ * height limit when omitted.
235
+ */
236
+ maxHeight?: number;
237
+ /**
238
+ * How the image fits `maxWidth` × `maxHeight`: `contain` (the default) scales
239
+ * it to fit inside, keeping its aspect ratio; `cover` scales it to fill the box,
240
+ * keeping its aspect ratio, and may crop.
241
+ */
242
+ mode?: "contain" | "cover";
243
+ /** The stored image's format. `original` (the default) keeps the uploaded one. */
244
+ format?: "original" | "jpeg" | "png" | "webp";
245
+ /**
246
+ * Quality of a lossy output (JPEG, WebP), 0–100: higher is sharper and larger.
247
+ * 80 when omitted.
248
+ */
249
+ quality?: number;
250
+ }
251
+ /**
252
+ * What `col.storage()` and `json.storage()` take.
253
+ *
254
+ * @group Schema
255
+ */
256
+ export interface StorageOptions {
257
+ /** The bucket, declared in `backend/resources.ts`. The default bucket when omitted. */
258
+ source?: ResourceRef;
259
+ /** Where files go, as a path template: `"posts/heroes/"`, `"users/{id}/"`. */
260
+ path: string;
261
+ /** MIME types accepted, with wildcards: `["image/*", "application/pdf"]`. */
262
+ accept?: readonly string[];
263
+ /** Largest file accepted, in bytes or as `"10MB"`. */
264
+ maxBytes?: number | string;
265
+ /** Resize images before storing them. */
266
+ imageResize?: StorageImageResize;
267
+ /** Files are readable without a signed URL. */
268
+ public?: boolean;
269
+ /** The stored file name, as a template. The uploaded name when omitted. */
270
+ fileName?: string;
271
+ /** Metadata stored with every file. */
272
+ metadata?: Record<string, unknown>;
273
+ /** Store the bucket URL in front of the path. */
274
+ includeBucketUrl?: boolean;
275
+ /** Store the download URL instead of the path. */
276
+ storeUrl?: boolean;
277
+ }
278
+ /**
279
+ * The storage rules of a column, as stored and served: the bucket by its key,
280
+ * the size limit in bytes.
281
+ *
282
+ * @group Schema
283
+ */
284
+ export interface ColumnStorage {
285
+ source?: string;
286
+ path: string;
287
+ accept?: readonly string[];
288
+ maxBytes?: number;
289
+ imageResize?: StorageImageResize;
290
+ public?: boolean;
291
+ fileName?: string;
292
+ metadata?: Record<string, unknown>;
293
+ includeBucketUrl?: boolean;
294
+ storeUrl?: boolean;
295
+ }
296
+ /**
297
+ * A size in bytes, from a number or from `"10MB"` / `"512 kb"` / `"1.5GB"`.
298
+ *
299
+ * Binary multiples (1 MB = 1,048,576 bytes), the unit a storage limit is
300
+ * enforced in. Throws on anything else: a limit that silently parsed to `NaN`
301
+ * is a limit that is never applied.
302
+ *
303
+ * @group Schema
304
+ */
305
+ export declare function parseByteSize(size: number | string): number;
306
+ /**
307
+ * Storage options in their stored form.
308
+ *
309
+ * @group Schema
310
+ */
311
+ export declare function normalizeStorage(options: StorageOptions): ColumnStorage;
312
+ /**
313
+ * The distance a vector index is built for.
314
+ *
315
+ * `ip` is the inner product (pgvector's `vector_ip_ops`).
316
+ *
317
+ * @group Schema
318
+ */
319
+ export type VectorMetric = "cosine" | "l2" | "ip";
320
+ /**
321
+ * The approximate-nearest-neighbour index of a `col.vector()` column.
322
+ *
323
+ * @group Schema
324
+ */
325
+ export interface VectorIndexOptions {
326
+ /** `hnsw` (the default) or `ivfflat`. */
327
+ method?: "hnsw" | "ivfflat";
328
+ /** The distance, or several: one index is built per metric. `cosine` by default. */
329
+ metric?: VectorMetric | readonly VectorMetric[];
330
+ /** HNSW: connections per layer. */
331
+ m?: number;
332
+ /** HNSW: size of the candidate list while building. */
333
+ efConstruction?: number;
334
+ /** IVFFlat: number of lists. */
335
+ lists?: number;
336
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * The Postgres type of a column, as a tag.
3
+ *
4
+ * One member per type Rebase creates, 1:1 with the planner's own `PgType`: a
5
+ * column says which Postgres type it is, and nothing downstream has to work it
6
+ * out from a document-shaped "string that is really a uuid". `other` is a type
7
+ * Rebase serves but does not create (`inet`, `citext`, `interval`, a range, a
8
+ * domain, a PostGIS type, an array of one of those, …): what introspection
9
+ * reports for such a column, and what `col.custom(sqlType)` declares. Its value
10
+ * is passed through as the driver returns it.
11
+ *
12
+ * @group Schema
13
+ */
14
+ export type ColumnType = {
15
+ kind: "text";
16
+ } | {
17
+ kind: "varchar";
18
+ length: number;
19
+ } | {
20
+ kind: "char";
21
+ length: number;
22
+ } | {
23
+ kind: "uuid";
24
+ } | {
25
+ kind: "enum";
26
+ values: readonly string[];
27
+ name?: string;
28
+ } | {
29
+ kind: "smallint";
30
+ } | {
31
+ kind: "integer";
32
+ } | {
33
+ kind: "bigint";
34
+ } | {
35
+ kind: "smallserial";
36
+ } | {
37
+ kind: "serial";
38
+ } | {
39
+ kind: "bigserial";
40
+ } | {
41
+ kind: "real";
42
+ } | {
43
+ kind: "doublePrecision";
44
+ } | {
45
+ kind: "numeric";
46
+ precision?: number;
47
+ scale?: number;
48
+ } | {
49
+ kind: "boolean";
50
+ } | {
51
+ kind: "timestamptz";
52
+ } | {
53
+ kind: "date";
54
+ } | {
55
+ kind: "time";
56
+ } | {
57
+ kind: "json";
58
+ } | {
59
+ kind: "jsonb";
60
+ } | {
61
+ kind: "vector";
62
+ dimensions: number;
63
+ } | {
64
+ kind: "bytea";
65
+ } | {
66
+ kind: "array";
67
+ of: ColumnType;
68
+ } | {
69
+ kind: "other";
70
+ sqlType: string;
71
+ };
72
+ /**
73
+ * The tag of a {@link ColumnType}.
74
+ *
75
+ * @group Schema
76
+ */
77
+ export type ColumnKind = ColumnType["kind"];
78
+ /** The kinds stored as text. */
79
+ export type TextColumnKind = "text" | "varchar" | "char";
80
+ /** The kinds a JavaScript `number` is read from and written to. */
81
+ export type NumericColumnKind = "smallint" | "integer" | "bigint" | "smallserial" | "serial" | "bigserial" | "real" | "doublePrecision" | "numeric";
82
+ /** The kinds that hold an instant, a day or a time of day. */
83
+ export type TemporalColumnKind = "timestamptz" | "date" | "time";
84
+ /**
85
+ * Whether a column type is stored as text (`text`, `varchar`, `char`).
86
+ *
87
+ * @group Schema
88
+ */
89
+ export declare function isTextColumnType(type: ColumnType): boolean;
90
+ /**
91
+ * Whether a column type is read and written as a JavaScript `number`.
92
+ *
93
+ * @group Schema
94
+ */
95
+ export declare function isNumericColumnType(type: ColumnType): boolean;
96
+ /**
97
+ * Whether a column type holds an instant, a day or a time of day.
98
+ *
99
+ * @group Schema
100
+ */
101
+ export declare function isTemporalColumnType(type: ColumnType): boolean;
102
+ /**
103
+ * Whether a column type is a JSON document (`json`, `jsonb`).
104
+ *
105
+ * @group Schema
106
+ */
107
+ export declare function isJsonColumnType(type: ColumnType): boolean;
108
+ /**
109
+ * The SQL spelling of a column type, for messages and generated comments.
110
+ *
111
+ * Not the DDL renderer: an enum prints as `enum(a, b)` because its type name
112
+ * belongs to the table it is planned in.
113
+ *
114
+ * @group Schema
115
+ */
116
+ export declare function columnTypeLabel(type: ColumnType): string;