@rebasepro/types 0.30.1 → 0.31.0-canary.g59cd6fd

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
@@ -0,0 +1,340 @@
1
+ import type { TemporalColumnKind } from "./column_type.js";
2
+ import type { BuilderKind, ColumnBuilder, ColumnFlags, ColumnsShape } from "./columns.js";
3
+ import type { BelongsToDef, RelationsShape } from "./relations.js";
4
+ import type { TABLE_BRAND, TableSlugOf, VIEW_BRAND } from "./table.js";
5
+ type Simplify<T> = {
6
+ [K in keyof T]: T[K];
7
+ } & {};
8
+ type DataOf<C> = C extends ColumnBuilder<infer D, BuilderKind, ColumnFlags> ? D : never;
9
+ type KindOf<C> = C extends ColumnBuilder<unknown, infer K, ColumnFlags> ? K : never;
10
+ type FlagsOf<C> = C extends ColumnBuilder<unknown, BuilderKind, infer F> ? F : never;
11
+ type Exposed<C> = FlagsOf<C>["exposed"] extends false ? false : true;
12
+ type Writable<C> = FlagsOf<C>["writable"] extends false ? false : true;
13
+ type NotNull<C> = FlagsOf<C>["notNull"] extends true ? true : false;
14
+ type HasDefault<C> = FlagsOf<C>["hasDefault"] extends true ? true : false;
15
+ type IsPrimaryKey<C> = FlagsOf<C>["primaryKey"] extends true ? true : false;
16
+ /** What a client may send for a column: its data, plus a `Date` for a temporal column. */
17
+ type WriteValue<C> = KindOf<C> extends TemporalColumnKind ? DataOf<C> | Date : DataOf<C>;
18
+ /**
19
+ * A row as it is served, from a table's columns: a `NOT NULL` column is its
20
+ * type, every other column may be `null`, a `.private()` column is absent.
21
+ *
22
+ * @group Schema
23
+ */
24
+ export type RowOfColumns<C extends ColumnsShape> = Simplify<{
25
+ [K in keyof C as Exposed<C[K]> extends true ? K : never]: NotNull<C[K]> extends true ? DataOf<C[K]> : DataOf<C[K]> | null;
26
+ }>;
27
+ type RequiredInsertKeys<C extends ColumnsShape> = {
28
+ [K in keyof C]: Writable<C[K]> extends true ? NotNull<C[K]> extends true ? HasDefault<C[K]> extends true ? never : K : never : never;
29
+ }[keyof C];
30
+ type OptionalInsertKeys<C extends ColumnsShape> = {
31
+ [K in keyof C]: Writable<C[K]> extends true ? (K extends RequiredInsertKeys<C> ? never : K) : never;
32
+ }[keyof C];
33
+ type InsertValue<C> = NotNull<C> extends true ? WriteValue<C> : WriteValue<C> | null;
34
+ /**
35
+ * What a create accepts, from a table's columns: a `NOT NULL` column without a
36
+ * default is required, the rest are optional; a generated, read-only or
37
+ * private column is not accepted at all.
38
+ *
39
+ * @group Schema
40
+ */
41
+ export type InsertOfColumns<C extends ColumnsShape> = Simplify<{
42
+ [K in RequiredInsertKeys<C>]: InsertValue<C[K]>;
43
+ } & {
44
+ [K in OptionalInsertKeys<C>]?: InsertValue<C[K]>;
45
+ }>;
46
+ /**
47
+ * What an update accepts, from a table's columns: every writable column,
48
+ * optional, the primary key aside.
49
+ *
50
+ * @group Schema
51
+ */
52
+ export type UpdateOfColumns<C extends ColumnsShape> = Simplify<{
53
+ [K in keyof C as Writable<C[K]> extends true ? (IsPrimaryKey<C[K]> extends true ? never : K) : never]?: InsertValue<C[K]>;
54
+ }>;
55
+ /** `author_id` → `authorId`, the way a derived foreign key reaches the wire. */
56
+ type WireKey<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<WireKey<Tail>>}` : S;
57
+ /** The key a `belongsTo`'s foreign key is served under. */
58
+ type ForeignKeyField<Name extends string, D> = D extends {
59
+ readonly localKey: infer L;
60
+ } ? L extends string ? (string extends L ? never : WireKey<L>) : `${Name}Id` : `${Name}Id`;
61
+ /**
62
+ * The foreign keys relations derive, as optional keys.
63
+ *
64
+ * Best effort: when the foreign-key column is declared in `columns` it is typed
65
+ * there, exactly; a derived one is typed from the relation's `localKey` (or its
66
+ * name) and may be `null`. The generated SDK types are exact.
67
+ */
68
+ type DerivedForeignKeys<C extends ColumnsShape, R extends RelationsShape> = {
69
+ [Name in Extract<keyof R, string> as R[Name] extends BelongsToDef ? ForeignKeyField<Name, R[Name]> extends keyof C ? never : ForeignKeyField<Name, R[Name]> : never]?: string | number | null;
70
+ };
71
+ /** What `InferRow` and its siblings read: a table or a view, structurally. */
72
+ interface Schematic<C extends ColumnsShape = ColumnsShape, R extends RelationsShape = RelationsShape> {
73
+ readonly config: {
74
+ readonly columns: C;
75
+ readonly relations?: R;
76
+ };
77
+ }
78
+ /**
79
+ * The row type of a table or view: `InferRow<typeof posts>`.
80
+ *
81
+ * Wire types — a timestamp is an ISO string, a foreign key is the key — which
82
+ * is what REST, the SDK and hooks all see.
83
+ *
84
+ * @group Schema
85
+ */
86
+ export type InferRow<T extends Schematic> = T extends Schematic<infer C, infer R> ? Simplify<RowOfColumns<C> & DerivedForeignKeys<C, R>> : never;
87
+ /**
88
+ * What a create accepts: `InferInsert<typeof posts>`.
89
+ *
90
+ * @group Schema
91
+ */
92
+ export type InferInsert<T extends Schematic> = T extends Schematic<infer C, infer R> ? Simplify<InsertOfColumns<C> & DerivedForeignKeys<C, R>> : never;
93
+ /**
94
+ * What an update accepts: `InferUpdate<typeof posts>`.
95
+ *
96
+ * @group Schema
97
+ */
98
+ export type InferUpdate<T extends Schematic> = T extends Schematic<infer C, infer R> ? Simplify<UpdateOfColumns<C> & DerivedForeignKeys<C, R>> : never;
99
+ /**
100
+ * The column keys of a table or view: `ColumnKeyOf<typeof posts>`.
101
+ *
102
+ * @group Schema
103
+ */
104
+ export type ColumnKeyOf<T extends Schematic> = T extends Schematic<infer C> ? Extract<keyof C, string> : never;
105
+ /**
106
+ * The relation names of a table or view: `RelationKeyOf<typeof posts>`.
107
+ *
108
+ * @group Schema
109
+ */
110
+ export type RelationKeyOf<T extends Schematic> = T extends Schematic<ColumnsShape, infer R> ? Extract<keyof R, string> : never;
111
+ /** A table or view export of a schema module, by its brand alone. */
112
+ interface SchemaTableLike {
113
+ readonly brand: typeof TABLE_BRAND | typeof VIEW_BRAND;
114
+ readonly name: string;
115
+ }
116
+ /** The table and view exports of a module namespace; anything else (`defaultRls`, helpers) is ignored. */
117
+ type TableExportsOf<M> = {
118
+ [K in keyof M]: M[K] extends SchemaTableLike ? M[K] : never;
119
+ }[keyof M];
120
+ type AccessorSeparator = "_" | "-" | " ";
121
+ type AccessorWords<S extends string> = S extends `${infer Head}${AccessorSeparator}${infer Tail}` ? [Head, ...AccessorWords<Tail>] : [S];
122
+ /** One word of `toPascalCase`: capitalised, a SHOUTING word folded down. */
123
+ type PascalWord<W extends string> = W extends "" ? "" : W extends Uppercase<W> ? Capitalize<Lowercase<W>> : Capitalize<W>;
124
+ type JoinPascal<T extends string[]> = T extends [infer Head extends string, ...infer Rest extends string[]] ? `${PascalWord<Head>}${JoinPascal<Rest>}` : "";
125
+ type SafeAccessor<S extends string> = S extends `${string}${AccessorSeparator}${string}` ? Uncapitalize<JoinPascal<AccessorWords<S>>> : Uncapitalize<S>;
126
+ /** The names `client.data` never serves as a table (`toTableAccessor` in `@rebasepro/common`). */
127
+ type ReservedAccessor = "table" | "then" | "toJSON" | "$$typeof";
128
+ /**
129
+ * The property a slug is reachable under on `client.data`, as the type system
130
+ * spells it: `order_items` → `orderItems`, `my-notes` → `myNotes`, a reserved
131
+ * name → `<name>Table`. The same rule codegen applies
132
+ * (`toTableAccessor`), for slugs made of letters, digits, `_`, `-` and
133
+ * spaces.
134
+ *
135
+ * @group Schema
136
+ */
137
+ export type TableAccessorOf<S extends string> = string extends S ? string : SafeAccessor<S> extends ReservedAccessor ? `${SafeAccessor<S>}Table` : SafeAccessor<S>;
138
+ type ColumnsOfTable<T> = T extends {
139
+ readonly config: {
140
+ readonly columns: infer C;
141
+ };
142
+ } ? C : never;
143
+ type RelationsOfTable<T> = T extends {
144
+ readonly config: {
145
+ readonly relations?: infer R;
146
+ };
147
+ } ? ([R] extends [undefined] ? Record<never, never> : NonNullable<R>) : Record<never, never>;
148
+ type PData<C> = C extends {
149
+ readonly $data: infer D;
150
+ } ? D : never;
151
+ type PKind<C> = C extends {
152
+ readonly $kind: infer K;
153
+ } ? K : never;
154
+ type PFlags<C> = C extends {
155
+ readonly $flags: infer F;
156
+ } ? F : never;
157
+ type PExposed<C> = PFlags<C> extends {
158
+ exposed: false;
159
+ } ? false : true;
160
+ type PWritable<C> = PFlags<C> extends {
161
+ writable: false;
162
+ } ? false : true;
163
+ type PNotNull<C> = PFlags<C> extends {
164
+ notNull: true;
165
+ } ? true : false;
166
+ type PHasDefault<C> = PFlags<C> extends {
167
+ hasDefault: true;
168
+ } ? true : false;
169
+ type PPrimaryKey<C> = PFlags<C> extends {
170
+ primaryKey: true;
171
+ } ? true : false;
172
+ type PWriteValue<C> = PKind<C> extends TemporalColumnKind ? PData<C> | Date : PData<C>;
173
+ type PInsertValue<C> = PNotNull<C> extends true ? PWriteValue<C> : PWriteValue<C> | null;
174
+ /**
175
+ * The columns of a row as the generated `Row` writes them: a `NOT NULL` column
176
+ * required, a nullable one optional and `| null`.
177
+ */
178
+ type SdkRowColumns<C> = Simplify<{
179
+ [K in keyof C as PExposed<C[K]> extends true ? (PNotNull<C[K]> extends true ? K : never) : never]: PData<C[K]>;
180
+ } & {
181
+ [K in keyof C as PExposed<C[K]> extends true ? (PNotNull<C[K]> extends true ? never : K) : never]?: PData<C[K]> | null;
182
+ }>;
183
+ type SdkInsertColumns<C> = Simplify<{
184
+ [K in keyof C as PWritable<C[K]> extends true ? (PNotNull<C[K]> extends true ? (PHasDefault<C[K]> extends true ? never : K) : never) : never]: PInsertValue<C[K]>;
185
+ } & {
186
+ [K in keyof C as PWritable<C[K]> extends true ? (PNotNull<C[K]> extends true ? (PHasDefault<C[K]> extends true ? K : never) : K) : never]?: PInsertValue<C[K]>;
187
+ }>;
188
+ type SdkUpdateColumns<C> = Simplify<{
189
+ [K in keyof C as PWritable<C[K]> extends true ? (PPrimaryKey<C[K]> extends true ? never : K) : never]?: PInsertValue<C[K]>;
190
+ }>;
191
+ /** A key whose target table the type system cannot see: relation thunks are untyped so tables can point at each other. */
192
+ type LinkKey = string | number;
193
+ /** The loosest correct row of an included relation; the generated SDK types it exactly. */
194
+ type IncludedRow = Record<string, unknown>;
195
+ type Names<R> = Extract<keyof R, string>;
196
+ type BelongsToNames<R> = {
197
+ [N in Names<R>]: R[N] extends {
198
+ readonly kind: "belongsTo";
199
+ } ? N : never;
200
+ }[Names<R>];
201
+ type FkKey<R, N extends keyof R & string> = ForeignKeyField<N, R[N]>;
202
+ /** A `belongsTo` whose key column is declared in `columns` (under its derived key). */
203
+ type DeclaredFk<C, R, N extends keyof R & string> = FkKey<R, N> extends keyof C ? true : false;
204
+ type RequiredLink<R, N extends keyof R> = R[N] extends {
205
+ readonly notNull: true;
206
+ } ? true : false;
207
+ type Unconstrained<R, N extends keyof R> = R[N] extends {
208
+ readonly constraint: false;
209
+ } ? true : false;
210
+ /** A link follows its declared key column's closure: hidden with it, unwritable with it. */
211
+ type LinkExposed<C, R, N extends keyof R & string> = FkKey<R, N> extends keyof C ? PExposed<C[FkKey<R, N>]> : true;
212
+ type LinkWritable<C, R, N extends keyof R & string> = FkKey<R, N> extends keyof C ? PWritable<C[FkKey<R, N>]> : true;
213
+ /** The value of a link written by name: the declared key column's type, or any key. */
214
+ type LinkValue<C, R, N extends keyof R & string> = FkKey<R, N> extends keyof C ? NonNullable<PData<C[FkKey<R, N>]>> : LinkKey;
215
+ /** The relations a read may include: every relation, minus a link whose key column is hidden. */
216
+ type IncludableNames<C, R> = {
217
+ [N in Names<R>]: R[N] extends {
218
+ readonly kind: "belongsTo";
219
+ } ? (LinkExposed<C, R, N> extends true ? N : never) : N;
220
+ }[Names<R>];
221
+ type PivotOf<D> = D extends {
222
+ readonly kind: "manyToMany";
223
+ readonly pivot?: infer P;
224
+ } ? ([P] extends [undefined] ? Record<never, never> : NonNullable<P>) : Record<never, never>;
225
+ /** A junction's payload on a read, as the generated SDK writes it: a nullable column optional. */
226
+ type PivotRow<P> = SdkRowColumns<P>;
227
+ type PivotWrite<P> = Simplify<{
228
+ [K in keyof P as PWritable<P[K]> extends true ? K : never]?: PInsertValue<P[K]>;
229
+ }>;
230
+ /** One or many, as the relation's kind says; a `via` whose cardinality the type does not carry is either. */
231
+ type IncludedOf<D> = D extends {
232
+ readonly kind: "belongsTo" | "hasOne";
233
+ } ? IncludedRow : D extends {
234
+ readonly kind: "via";
235
+ readonly cardinality: "one";
236
+ } ? IncludedRow : D extends {
237
+ readonly kind: "via";
238
+ readonly cardinality: "many";
239
+ } ? IncludedRow[] : D extends {
240
+ readonly kind: "via";
241
+ } ? IncludedRow | IncludedRow[] : keyof PivotOf<D> extends never ? IncludedRow[] : Array<IncludedRow & {
242
+ _pivot?: PivotRow<PivotOf<D>>;
243
+ }>;
244
+ /** The foreign keys relations derive (a key column declared in `columns` is typed there). */
245
+ type DerivedLinkColumns<C, R, Write extends boolean> = Simplify<{
246
+ [N in BelongsToNames<R> as DeclaredFk<C, R, N> extends true ? never : RequiredLink<R, N> extends true ? (Write extends true ? never : FkKey<R, N>) : never]: LinkKey;
247
+ } & {
248
+ [N in BelongsToNames<R> as DeclaredFk<C, R, N> extends true ? never : RequiredLink<R, N> extends true ? (Write extends true ? FkKey<R, N> : never) : FkKey<R, N>]?: RequiredLink<R, N> extends true ? LinkKey : LinkKey | null;
249
+ }>;
250
+ type RowOfTable<C, R> = Simplify<SdkRowColumns<C> & DerivedLinkColumns<C, R, false> & {
251
+ [N in IncludableNames<C, R>]?: IncludedOf<R[N]>;
252
+ }>;
253
+ /** The relation-side writes: a link by name, a `hasOne` by the target's key, a to-many membership. */
254
+ type RelationWrites<C, R> = Simplify<{
255
+ [N in BelongsToNames<R> as Unconstrained<R, N> extends true ? never : LinkWritable<C, R, N> extends true ? N : never]?: RequiredLink<R, N> extends true ? LinkValue<C, R, N> : LinkValue<C, R, N> | null;
256
+ } & {
257
+ [N in Names<R> as R[N] extends {
258
+ readonly kind: "hasOne";
259
+ } ? N : never]?: LinkKey | null;
260
+ } & {
261
+ [N in Names<R> as R[N] extends {
262
+ readonly kind: "hasMany" | "manyToMany";
263
+ } ? N : never]?: Array<LinkKey | (keyof PivotOf<R[N]> extends never ? {
264
+ id: LinkKey;
265
+ } : {
266
+ id: LinkKey;
267
+ _pivot?: PivotWrite<PivotOf<R[N]>>;
268
+ })>;
269
+ }>;
270
+ type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
271
+ /** Boxed, so a relation's two spellings stay one union while the relations are intersected. */
272
+ interface SpellingBox<T> {
273
+ spellings: T;
274
+ }
275
+ type Unbox<B> = B extends SpellingBox<infer T> ? T : never;
276
+ /** A required derived link is named on a create under either of its names. */
277
+ type RequiredLinkSpellings<C, R> = Unbox<UnionToIntersection<{
278
+ [N in BelongsToNames<R>]: DeclaredFk<C, R, N> extends true ? never : RequiredLink<R, N> extends true ? SpellingBox<Unconstrained<R, N> extends true ? Record<FkKey<R, N>, LinkKey> : Record<FkKey<R, N>, LinkKey> | Record<N, LinkKey>> : never;
279
+ }[BelongsToNames<R>]>>;
280
+ type InsertOfTable<C, R> = Simplify<SdkInsertColumns<C> & DerivedLinkColumns<C, R, true> & RelationWrites<C, R>> & ([RequiredLinkSpellings<C, R>] extends [never] ? unknown : RequiredLinkSpellings<C, R>);
281
+ type UpdateOfTable<C, R> = Simplify<SdkUpdateColumns<C> & {
282
+ [N in BelongsToNames<R> as DeclaredFk<C, R, N> extends true ? never : FkKey<R, N>]?: RequiredLink<R, N> extends true ? LinkKey : LinkKey | null;
283
+ } & RelationWrites<C, R>>;
284
+ type RelationsMapOf<C, R> = [
285
+ IncludableNames<C, R>
286
+ ] extends [never] ? Record<never, never> : {
287
+ [N in IncludableNames<C, R>]: string;
288
+ };
289
+ /** One table's entry, shaped as the generated `Database`'s. */
290
+ type TableEntryOf<T> = T extends SchemaTableLike ? {
291
+ Row: RowOfTable<ColumnsOfTable<T>, RelationsOfTable<T>>;
292
+ Insert: T extends {
293
+ readonly brand: typeof VIEW_BRAND;
294
+ } ? never : InsertOfTable<ColumnsOfTable<T>, RelationsOfTable<T>>;
295
+ Update: T extends {
296
+ readonly brand: typeof VIEW_BRAND;
297
+ } ? never : UpdateOfTable<ColumnsOfTable<T>, RelationsOfTable<T>>;
298
+ Relations: RelationsMapOf<ColumnsOfTable<T>, RelationsOfTable<T>>;
299
+ Slug: TableSlugOf<T>;
300
+ } : never;
301
+ /**
302
+ * The typed `Database` of a schema module, with no codegen run:
303
+ * `DatabaseOf<typeof import("./backend/schema")>`.
304
+ *
305
+ * The same shape `rebase generate-sdk` emits — per table, under its accessor
306
+ * (`orderItems` for `order_items`): `Row`, `Insert`, `Update`, `Relations` and
307
+ * `Slug` — as far as the type system can know it. Every export of the module
308
+ * that is a `defineTable` / `defineAuthTable` / `defineView` result is a
309
+ * table; the rest (`defaultRls`, helpers) is ignored.
310
+ *
311
+ * Exact: every declared column — nullability, `.private()`, `.readOnly()`,
312
+ * `.generatedAlwaysAs()`, defaults and stamps (optional on create), enums and
313
+ * `.oneOf()` unions, `col.jsonb().$type<T>()` documents, temporal columns writable as
314
+ * a `Date` — the slug, the view's missing writes, the relation names and their
315
+ * cardinality, a junction's `_pivot`, a link hidden or read-only with its key
316
+ * column, and a required derived link written by either name.
317
+ *
318
+ * Loose, because a relation's target is behind an untyped thunk (so tables
319
+ * can point at each other): a derived foreign key is `string | number`, an
320
+ * included row is `Record<string, unknown>`, `Relations` names the relations
321
+ * but not the table each reaches (so a nested `include` is unchecked), a
322
+ * `via`'s cardinality is either unless the type carries it, and a `via` is not
323
+ * offered as a write. A key column named `"author_id"` by its builder (`col.uuid("author_id")`) under a
324
+ * key other than the derived one (`authorId`) is not recognised as the link's.
325
+ * The generated SDK is the exact source for all of these.
326
+ *
327
+ * Register it once instead of a generated `Database`:
328
+ *
329
+ * ```ts
330
+ * declare module "@rebasepro/types" {
331
+ * interface Register { tables: typeof import("./backend/schema") }
332
+ * }
333
+ * ```
334
+ *
335
+ * @group Schema
336
+ */
337
+ export type DatabaseOf<M> = {
338
+ [T in TableExportsOf<M> as TableAccessorOf<TableSlugOf<T>>]: TableEntryOf<T>;
339
+ };
340
+ export {};
@@ -0,0 +1,237 @@
1
+ import type { ArrayValidation, BaseValidation, ColumnStorage, ColumnValidation, DateValidation, NumberValidation, StorageOptions, StringValidation } from "./column_options.js";
2
+ import type { ColumnTransform } from "./hooks.js";
3
+ /** What every node of a JSON shape may carry. */
4
+ interface JsonNodeBase {
5
+ /** The key must be present in the document. */
6
+ required?: boolean;
7
+ /** The value written when the key is absent on create. */
8
+ default?: unknown;
9
+ /** What the value is, for OpenAPI and MCP. */
10
+ description?: string;
11
+ }
12
+ type JsonNode<Extra> = Extra & JsonNodeBase & ({
13
+ kind: "string";
14
+ validate?: ColumnValidation;
15
+ oneOf?: readonly string[];
16
+ storage?: ColumnStorage;
17
+ /**
18
+ * The server writes the caller's user id into the field: on create
19
+ * only (`"createUser"`, `.onCreateUser()`) or on every write
20
+ * (`"updateUser"`, `.onUpdateUser()`).
21
+ */
22
+ stamp?: "createUser" | "updateUser";
23
+ /** `"user"`: the field holds a user's id (`.userId()`). */
24
+ semantic?: "user";
25
+ } | {
26
+ kind: "number";
27
+ validate?: ColumnValidation;
28
+ oneOf?: readonly number[];
29
+ } | {
30
+ kind: "boolean";
31
+ } | {
32
+ kind: "date";
33
+ validate?: ColumnValidation;
34
+ /**
35
+ * The server writes the current time into the field: on create only
36
+ * (`"create"`, `.onCreateNow()`) or on every write (`"update"`,
37
+ * `.onUpdateNow()`).
38
+ */
39
+ stamp?: "create" | "update";
40
+ } | {
41
+ kind: "geopoint";
42
+ } | {
43
+ kind: "object";
44
+ fields: Record<string, JsonNode<Extra>>;
45
+ additional?: boolean;
46
+ } | {
47
+ kind: "array";
48
+ of: JsonNode<Extra>;
49
+ validate?: ColumnValidation;
50
+ } | {
51
+ kind: "oneOf";
52
+ typeField: string;
53
+ valueField: string;
54
+ variants: Record<string, JsonNode<Extra>>;
55
+ } | {
56
+ kind: "unknown";
57
+ });
58
+ /**
59
+ * The shape of a `json`/`jsonb` document, as served on the wire.
60
+ *
61
+ * It is what lets the server validate a nested field, stamp a nested date,
62
+ * find the files a document references, and search a JSON path — and what lets
63
+ * the panel build a form for the document without being told how.
64
+ *
65
+ * @group Schema
66
+ */
67
+ export type JsonShape = JsonNode<unknown>;
68
+ /**
69
+ * A {@link JsonShape} as authored: the same tree, with field-level hooks on
70
+ * its nodes. Hooks stay on the server.
71
+ *
72
+ * @group Schema
73
+ */
74
+ export type JsonShapeDef = JsonNode<{
75
+ transform?: ColumnTransform;
76
+ }>;
77
+ /**
78
+ * The kind of one node of a JSON shape.
79
+ *
80
+ * @group Schema
81
+ */
82
+ export type JsonKind = JsonShape["kind"];
83
+ /** A point on Earth, as a JSON document stores it. */
84
+ export interface JsonGeoPoint {
85
+ /** Degrees north of the equator, −90 to 90 (south is negative). */
86
+ latitude: number;
87
+ /** Degrees east of Greenwich, −180 to 180 (west is negative). */
88
+ longitude: number;
89
+ }
90
+ type JsonValidationFor<K extends JsonKind> = K extends "string" ? StringValidation : K extends "number" ? NumberValidation : K extends "date" ? DateValidation : K extends "array" ? ArrayValidation : BaseValidation;
91
+ /**
92
+ * The value a JSON field's `.transform()` hooks receive and return: the
93
+ * field's type, plus `undefined` while the field is not `.required()`.
94
+ *
95
+ * Read when `.transform()` is called: `.required().transform(…)` receives
96
+ * `TData`, `.transform(…).required()` keeps `TData | undefined`.
97
+ *
98
+ * @group Schema
99
+ */
100
+ export type JsonTransformValue<TData, TRequired extends boolean> = TRequired extends true ? TData : TData | undefined;
101
+ /** The brand every JSON field builder carries, so one built by another copy of this package is still recognised. */
102
+ export declare const JSON_FIELD_BRAND = "rebase.json-field";
103
+ /**
104
+ * One field of a JSON document: `json.string()`, `json.object({...})`, ….
105
+ *
106
+ * Immutable: every modifier returns a new field.
107
+ *
108
+ * @group Schema
109
+ */
110
+ export declare class JsonField<TData, TKind extends JsonKind = JsonKind, TRequired extends boolean = false> {
111
+ /** The shape this field describes. */
112
+ readonly shape: JsonShapeDef;
113
+ /** Type-level only: the TypeScript type of the value. */
114
+ readonly $data: TData;
115
+ /** Type-level only: the node kind. */
116
+ readonly $kind: TKind;
117
+ /** Type-level only: whether the key must be present. */
118
+ readonly $required: TRequired;
119
+ readonly brand = "rebase.json-field";
120
+ constructor(
121
+ /** The shape this field describes. */
122
+ shape: JsonShapeDef);
123
+ private with;
124
+ /** The key must be present in the document. */
125
+ required(): JsonField<TData, TKind, true>;
126
+ /** The value written when the key is absent on create. */
127
+ default(value: TData): JsonField<TData, TKind, TRequired>;
128
+ /** What the value is, for OpenAPI and MCP. */
129
+ describe(description: string): JsonField<TData, TKind, TRequired>;
130
+ /** Rules the API checks before a write. */
131
+ validate(rules: JsonValidationFor<TKind>): JsonField<TData, TKind, TRequired>;
132
+ /** A closed set of accepted values. */
133
+ oneOf<const V extends readonly TData[], K extends "string" | "number">(this: JsonField<TData, K, TRequired>, values: V): JsonField<V[number], K, TRequired>;
134
+ /** The server writes the current time into the field when the row is created. */
135
+ onCreateNow(this: JsonField<string, "date", TRequired>): JsonField<string, "date", TRequired>;
136
+ /** The server writes the current time into the field on every write. */
137
+ onUpdateNow(this: JsonField<string, "date", TRequired>): JsonField<string, "date", TRequired>;
138
+ /** The server writes the caller's user id into the field when the row is created. */
139
+ onCreateUser(this: JsonField<string, "string", TRequired>): JsonField<string, "string", TRequired>;
140
+ /** The server writes the caller's user id into the field on every write. */
141
+ onUpdateUser(this: JsonField<string, "string", TRequired>): JsonField<string, "string", TRequired>;
142
+ /**
143
+ * The field holds the id of a user. The panel offers a user picker for it,
144
+ * and callers who may write the table may look users up to fill it.
145
+ * Only on `json.string()`; anything else throws.
146
+ */
147
+ userId(this: JsonField<string, "string", TRequired>): JsonField<string, "string", TRequired>;
148
+ /**
149
+ * Field-level hooks. They run on the server only.
150
+ *
151
+ * The value is `TData | undefined` on a field not (yet) marked
152
+ * `.required()` — the key can be absent from the document — and `TData` on
153
+ * one that is; see {@link JsonTransformValue}. Chain `.required()` before
154
+ * `.transform()` to get the narrower type.
155
+ */
156
+ transform(transform: ColumnTransform<JsonTransformValue<TData, TRequired>>): JsonField<TData, TKind, TRequired>;
157
+ }
158
+ /** Any JSON field, whatever it holds. */
159
+ export type AnyJsonField = JsonField<unknown, JsonKind, boolean>;
160
+ /** The TypeScript type a JSON field holds. */
161
+ export type JsonDataOf<F> = F extends JsonField<infer T, JsonKind, boolean> ? T : never;
162
+ type Simplify<T> = {
163
+ [K in keyof T]: T[K];
164
+ } & {};
165
+ /** The TypeScript type of a `json.object({...})`: required keys required, the rest optional. */
166
+ export type JsonObjectOf<S extends Record<string, AnyJsonField>> = Simplify<{
167
+ [K in keyof S as S[K] extends JsonField<unknown, JsonKind, true> ? K : never]: JsonDataOf<S[K]>;
168
+ } & {
169
+ [K in keyof S as S[K] extends JsonField<unknown, JsonKind, true> ? never : K]?: JsonDataOf<S[K]>;
170
+ }>;
171
+ /** One block of a `json.oneOf(...)`: its discriminator and its value. */
172
+ export type JsonOneOfOf<S extends Record<string, AnyJsonField>, TypeField extends string, ValueField extends string> = {
173
+ [K in keyof S]: Simplify<Record<TypeField, K> & Record<ValueField, JsonDataOf<S[K]>>>;
174
+ }[keyof S];
175
+ /**
176
+ * Builders for the shape of a `json`/`jsonb` document.
177
+ *
178
+ * ```ts
179
+ * metadata: col.jsonb(json.object({
180
+ * seoTitle: json.string().validate({ max: 60 }),
181
+ * canonicalUrl: json.string().validate({ url: true }),
182
+ * })),
183
+ * content: col.jsonb(json.array(json.oneOf({
184
+ * text: json.string(),
185
+ * image: json.storage({ path: "posts/content/" }),
186
+ * }))),
187
+ * ```
188
+ *
189
+ * `col.jsonb().$type<T>()` on its own types the document statically; a shape also
190
+ * tells the server what is inside it.
191
+ *
192
+ * @group Schema
193
+ */
194
+ export declare const json: {
195
+ /** A string. */
196
+ string(): JsonField<string, "string">;
197
+ /** A number. */
198
+ number(): JsonField<number, "number">;
199
+ /** A boolean. */
200
+ boolean(): JsonField<boolean, "boolean">;
201
+ /** An instant, stored as an ISO string. */
202
+ date(): JsonField<string, "date">;
203
+ /** A point on Earth: `{ latitude, longitude }`. */
204
+ geopoint(): JsonField<JsonGeoPoint, "geopoint">;
205
+ /** The path of a stored file. Counted by the orphan sweep like a `col.storage()` column. */
206
+ storage(options: StorageOptions): JsonField<string, "string">;
207
+ /** An object with known keys. `additional: true` also accepts keys it does not name. */
208
+ object<S extends Record<string, AnyJsonField>>(fields: S, options?: {
209
+ additional?: boolean;
210
+ }): JsonField<JsonObjectOf<S>, "object">;
211
+ /** An array of one shape. */
212
+ array<F extends AnyJsonField>(of: F): JsonField<JsonDataOf<F>[], "array">;
213
+ /**
214
+ * A typed block: `{ type: "<variant>", value: <its shape> }`. The keys are
215
+ * `type` and `value` unless `typeField` / `valueField` say otherwise.
216
+ */
217
+ oneOf<S extends Record<string, AnyJsonField>, const TypeField extends string = "type", const ValueField extends string = "value">(variants: S, options?: {
218
+ typeField?: TypeField;
219
+ valueField?: ValueField;
220
+ }): JsonField<JsonOneOfOf<S, TypeField, ValueField>, "oneOf">;
221
+ /** Anything. */
222
+ unknown(): JsonField<unknown, "unknown">;
223
+ };
224
+ /**
225
+ * Whether a value is a JSON field builder, from this copy of the package or
226
+ * another.
227
+ *
228
+ * @group Schema
229
+ */
230
+ export declare function isJsonField(value: unknown): value is AnyJsonField;
231
+ /**
232
+ * A JSON shape without its hooks: what the wire carries.
233
+ *
234
+ * @group Schema
235
+ */
236
+ export declare function describeJsonShape(shape: JsonShapeDef): JsonShape;
237
+ export {};