@rebasepro/types 0.30.0 → 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.
- package/README.md +16 -18
- package/dist/call_context.d.ts +3 -3
- package/dist/controllers/client.d.ts +29 -0
- package/dist/controllers/data.d.ts +85 -332
- package/dist/controllers/data_driver.d.ts +47 -57
- package/dist/controllers/index.d.ts +0 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +2567 -1151
- package/dist/index.es.js.map +1 -1
- package/dist/schema/column_options.d.ts +336 -0
- package/dist/schema/column_type.d.ts +116 -0
- package/dist/schema/columns.d.ts +646 -0
- package/dist/schema/compiled.d.ts +114 -0
- package/dist/schema/descriptor.d.ts +349 -0
- package/dist/schema/hooks.d.ts +164 -0
- package/dist/schema/index.d.ts +13 -0
- package/dist/schema/infer.d.ts +340 -0
- package/dist/schema/json.d.ts +237 -0
- package/dist/schema/relations.d.ts +205 -0
- package/dist/schema/table.d.ts +304 -0
- package/dist/schema/table_options.d.ts +103 -0
- package/dist/schema/table_patch.d.ts +338 -0
- package/dist/types/auth_adapter.d.ts +12 -6
- package/dist/types/auth_hooks.d.ts +65 -0
- package/dist/types/backend.d.ts +85 -96
- package/dist/types/data_source.d.ts +4 -9
- package/dist/types/database_adapter.d.ts +30 -31
- package/dist/types/entities.d.ts +0 -162
- package/dist/types/filter-operators.d.ts +2 -26
- package/dist/types/history.d.ts +6 -9
- package/dist/types/index.d.ts +3 -9
- package/dist/types/mcp_app_modules.d.ts +0 -2
- package/dist/types/policy.d.ts +85 -10
- package/dist/types/project_manifest.d.ts +113 -46
- package/dist/types/read_query.d.ts +98 -0
- package/dist/types/register.d.ts +35 -5
- package/dist/types/relations.d.ts +0 -430
- package/dist/types/schema_editing.d.ts +54 -2
- package/dist/types/schema_version.d.ts +24 -4
- package/dist/types/security_rules.d.ts +225 -15
- package/dist/types/storage_authorize.d.ts +2 -2
- package/dist/types/tenancy.d.ts +3 -3
- package/dist/types/ui_preferences.d.ts +228 -0
- package/package.json +3 -2
- package/dist/controllers/auth_state.d.ts +0 -23
- package/dist/controllers/collection_registry.d.ts +0 -67
- package/dist/controllers/effective_role.d.ts +0 -4
- package/dist/types/admin_block.d.ts +0 -96
- package/dist/types/chips.d.ts +0 -16
- package/dist/types/collection_contract.d.ts +0 -43
- package/dist/types/collection_patch.d.ts +0 -74
- package/dist/types/collections.d.ts +0 -783
- package/dist/types/component_ref.d.ts +0 -81
- package/dist/types/conditions-contract.types.d.ts +0 -14
- package/dist/types/entity_callbacks.d.ts +0 -393
- package/dist/types/indexes.d.ts +0 -179
- package/dist/types/properties.d.ts +0 -1640
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { AnyCollectionConfig } from "./collections.js";
|
|
2
|
-
import type { Properties } from "./properties.js";
|
|
3
1
|
/**
|
|
4
2
|
* @group Models
|
|
5
3
|
*/
|
|
@@ -58,434 +56,6 @@ export declare const INCLUDE_COUNT_KEY = "_count";
|
|
|
58
56
|
* @group Models
|
|
59
57
|
*/
|
|
60
58
|
export type RelationKind = "belongsTo" | "hasOne" | "hasMany" | "manyToMany" | "via";
|
|
61
|
-
/** Fields every relation carries, whatever its kind. @group Models */
|
|
62
|
-
export interface RelationBase {
|
|
63
|
-
/**
|
|
64
|
-
* The name this link is addressed by: the key in `include`, the tab in the
|
|
65
|
-
* admin panel, and the path segment of a nested URL.
|
|
66
|
-
*
|
|
67
|
-
* Defaults to the declaring property's key, or to the target's slug for an
|
|
68
|
-
* entry in `relations`.
|
|
69
|
-
*/
|
|
70
|
-
relationName?: string;
|
|
71
|
-
/** The collection on the other end. */
|
|
72
|
-
target: () => AnyCollectionConfig;
|
|
73
|
-
/**
|
|
74
|
-
* What the database does to this side's foreign key when the target row's
|
|
75
|
-
* key changes. Emitted as the constraint's `ON UPDATE`.
|
|
76
|
-
*
|
|
77
|
-
* Unset means no clause, which Postgres reads as `NO ACTION`. Set
|
|
78
|
-
* `"cascade"` when the target's key is a natural key that can be edited —
|
|
79
|
-
* a slug, a SKU — so the pointers follow it.
|
|
80
|
-
*
|
|
81
|
-
* Only a `belongsTo` puts the key on this table, so this is the only kind
|
|
82
|
-
* where the clause is written here; on the other kinds it describes the
|
|
83
|
-
* constraint the target's own column carries.
|
|
84
|
-
*/
|
|
85
|
-
onUpdate?: OnAction;
|
|
86
|
-
/**
|
|
87
|
-
* What the database does to this side's rows when the target row is
|
|
88
|
-
* deleted. Emitted as the constraint's `ON DELETE`.
|
|
89
|
-
*
|
|
90
|
-
* Defaults, when unset, to `"set null"` for an optional relation and
|
|
91
|
-
* **`"restrict"`** for a required one. `NOT NULL` says a child cannot exist
|
|
92
|
-
* without a parent; it does not say deleting the parent should delete the
|
|
93
|
-
* child. Ask for `"cascade"` when that is what you mean — it is the one
|
|
94
|
-
* value that destroys rows you did not name.
|
|
95
|
-
*
|
|
96
|
-
* A `manyToMany` is the exception: its junction rows default to
|
|
97
|
-
* `"cascade"`, because the row deleted there is the link and not the target.
|
|
98
|
-
*/
|
|
99
|
-
onDelete?: OnAction;
|
|
100
|
-
/**
|
|
101
|
-
* Presentation overrides applied when this relation is rendered as a tab.
|
|
102
|
-
*
|
|
103
|
-
* Whether the link is *required* is not here: it is
|
|
104
|
-
* `validation: { required: true }` on the declaring property, the same key
|
|
105
|
-
* every other field uses. A relation carried its own copy until 0.18, and
|
|
106
|
-
* the two disagreed by construction — the DDL generator read the property
|
|
107
|
-
* (so the column was `NOT NULL`) while codegen read the relation (so the
|
|
108
|
-
* generated `Insert` type made it optional), and a `create()` that
|
|
109
|
-
* typechecked failed at the database.
|
|
110
|
-
*/
|
|
111
|
-
overrides?: Partial<AnyCollectionConfig>;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* This collection holds the foreign key. One target row per source row.
|
|
115
|
-
*
|
|
116
|
-
* ```ts
|
|
117
|
-
* author: { kind: "belongsTo", target: () => authors, localKey: "author_id" }
|
|
118
|
-
* ```
|
|
119
|
-
* @group Models
|
|
120
|
-
*/
|
|
121
|
-
export interface BelongsToRelation extends RelationBase {
|
|
122
|
-
kind: "belongsTo";
|
|
123
|
-
/**
|
|
124
|
-
* Column on **this** collection's table holding the target's key.
|
|
125
|
-
* Defaults to `<relationName>_id`.
|
|
126
|
-
*/
|
|
127
|
-
localKey?: string;
|
|
128
|
-
/**
|
|
129
|
-
* Whether Rebase creates a btree index on {@link localKey}. Defaults to
|
|
130
|
-
* `true`.
|
|
131
|
-
*
|
|
132
|
-
* Postgres indexes the key a foreign key *points at* but never the column
|
|
133
|
-
* holding it, so without one every read from the other side seq-scans this
|
|
134
|
-
* table: a `hasMany`/`hasOne` include, a nested listing such as
|
|
135
|
-
* `/authors/5/posts`, and the `ON DELETE` check when a target row is
|
|
136
|
-
* deleted. The derived index is skipped on its own when the column already
|
|
137
|
-
* leads one — the primary key, a `validation.unique`, or an entry in
|
|
138
|
-
* `indexes:` — so it never duplicates an index you declared.
|
|
139
|
-
*
|
|
140
|
-
* Set `false` for a table so write-heavy that the index costs more than
|
|
141
|
-
* the lookups it serves, or when you keep an index of your own on the
|
|
142
|
-
* column outside Rebase's `indexes:` block.
|
|
143
|
-
*/
|
|
144
|
-
index?: boolean;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* The target holds the foreign key, and at most one target row points back.
|
|
148
|
-
*
|
|
149
|
-
* ```ts
|
|
150
|
-
* profile: { kind: "hasOne", target: () => profiles, foreignKeyOnTarget: "user_id" }
|
|
151
|
-
* ```
|
|
152
|
-
* @group Models
|
|
153
|
-
*/
|
|
154
|
-
export interface HasOneRelation extends RelationBase {
|
|
155
|
-
kind: "hasOne";
|
|
156
|
-
/**
|
|
157
|
-
* Column on the **target's** table holding this collection's key.
|
|
158
|
-
* Defaults to `<thisCollection>_id`.
|
|
159
|
-
*/
|
|
160
|
-
foreignKeyOnTarget?: string;
|
|
161
|
-
/**
|
|
162
|
-
* Column on **this** collection's table whose value `foreignKeyOnTarget`
|
|
163
|
-
* holds. Defaults to this collection's primary key.
|
|
164
|
-
*
|
|
165
|
-
* Set it when the two sides are joined on a natural key rather than on the
|
|
166
|
-
* row id — an external identity id, a SKU, a tenant slug. See
|
|
167
|
-
* {@link HasManyRelation.sourceKey}, which this mirrors.
|
|
168
|
-
*/
|
|
169
|
-
sourceKey?: string;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* The target holds the foreign key, and many target rows point back. The
|
|
173
|
-
* children belong to this parent alone — deleting one deletes a row.
|
|
174
|
-
*
|
|
175
|
-
* ```ts
|
|
176
|
-
* posts: { kind: "hasMany", target: () => posts, foreignKeyOnTarget: "author_id" }
|
|
177
|
-
* ```
|
|
178
|
-
* @group Models
|
|
179
|
-
*/
|
|
180
|
-
export interface HasManyRelation extends RelationBase {
|
|
181
|
-
kind: "hasMany";
|
|
182
|
-
/**
|
|
183
|
-
* Column on the **target's** table holding this collection's key.
|
|
184
|
-
* Defaults to `<thisCollection>_id`.
|
|
185
|
-
*/
|
|
186
|
-
foreignKeyOnTarget?: string;
|
|
187
|
-
/**
|
|
188
|
-
* Column on **this** collection's table whose value `foreignKeyOnTarget`
|
|
189
|
-
* holds. Defaults to this collection's primary key.
|
|
190
|
-
*
|
|
191
|
-
* The mirror of `localKey` on {@link BelongsToRelation}: that one names the
|
|
192
|
-
* column this side reads from, this one names the column the other side
|
|
193
|
-
* points at. Without it the pair can only be joined on the row id, which
|
|
194
|
-
* makes a natural-key link — `auth_user_id ↔ auth_user_id`, a SKU, a tenant
|
|
195
|
-
* slug — inexpressible as `hasMany`, and it has to drop to the read-only
|
|
196
|
-
* `via`.
|
|
197
|
-
*
|
|
198
|
-
* The column must be unique: the link addresses one source row per value,
|
|
199
|
-
* and Postgres will not accept a foreign key against a non-unique column.
|
|
200
|
-
*
|
|
201
|
-
* ```ts
|
|
202
|
-
* applications: {
|
|
203
|
-
* kind: "hasMany",
|
|
204
|
-
* target: () => talentApplications,
|
|
205
|
-
* sourceKey: "auth_user_id",
|
|
206
|
-
* foreignKeyOnTarget: "auth_user_id"
|
|
207
|
-
* }
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
sourceKey?: string;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Both sides hold many, through a junction table. The target rows are shared,
|
|
214
|
-
* so this collection owns the *link* and not the row: removing one removes a
|
|
215
|
-
* junction row and leaves the target alone.
|
|
216
|
-
*
|
|
217
|
-
* Declared the same way from either side — there is no owning and inverse
|
|
218
|
-
* version. Swap `sourceColumn` and `targetColumn` to describe the other
|
|
219
|
-
* direction.
|
|
220
|
-
*
|
|
221
|
-
* ```ts
|
|
222
|
-
* tags: { kind: "manyToMany", target: () => tags }
|
|
223
|
-
* ```
|
|
224
|
-
* @group Models
|
|
225
|
-
*/
|
|
226
|
-
export interface ManyToManyRelation extends RelationBase {
|
|
227
|
-
kind: "manyToMany";
|
|
228
|
-
/**
|
|
229
|
-
* The junction table and its two key columns. Every part defaults: the
|
|
230
|
-
* table to both table names sorted and joined, the columns to
|
|
231
|
-
* `<collection>_id` and `<relationName>_id`.
|
|
232
|
-
*/
|
|
233
|
-
through?: {
|
|
234
|
-
table?: string;
|
|
235
|
-
/** Junction column holding **this** collection's key. */
|
|
236
|
-
sourceColumn?: string;
|
|
237
|
-
/** Junction column holding the **target's** key. */
|
|
238
|
-
targetColumn?: string;
|
|
239
|
-
/**
|
|
240
|
-
* Extra columns the junction row carries, declared exactly like a
|
|
241
|
-
* collection's properties.
|
|
242
|
-
*
|
|
243
|
-
* A membership is often not only a membership. "This user is in that
|
|
244
|
-
* organisation" is really "…as an `owner`, since March"; "this tag is
|
|
245
|
-
* on that post" is really "…in third place". Until this existed the
|
|
246
|
-
* junction was two key columns and nothing else, so the role and the
|
|
247
|
-
* position had to become a collection of their own — which is a
|
|
248
|
-
* different data model, a different set of policies and a different
|
|
249
|
-
* URL, for what is still one link.
|
|
250
|
-
*
|
|
251
|
-
* The properties are read by the same planner that reads a
|
|
252
|
-
* collection's, so a payload column gets the type, `NOT NULL`,
|
|
253
|
-
* `DEFAULT`, `UNIQUE` and enum type it would get on a table. What it
|
|
254
|
-
* does **not** get is `indexes` (declared per collection, and no
|
|
255
|
-
* collection declares a junction), `search`, `vector`, or anything a
|
|
256
|
-
* relation would put on it — a payload property may not be a
|
|
257
|
-
* `relation`, a `reference` or a `vector`, and config validation
|
|
258
|
-
* refuses one that is.
|
|
259
|
-
*
|
|
260
|
-
* On the wire the values travel under {@link JUNCTION_PIVOT_KEY}: a
|
|
261
|
-
* read serves `{ …target, _pivot: { role } }`, and a membership write
|
|
262
|
-
* accepts `{ id, _pivot: { role } }` beside the bare ids.
|
|
263
|
-
*
|
|
264
|
-
* ```ts
|
|
265
|
-
* members: {
|
|
266
|
-
* kind: "manyToMany",
|
|
267
|
-
* target: () => users,
|
|
268
|
-
* through: {
|
|
269
|
-
* table: "org_members",
|
|
270
|
-
* properties: {
|
|
271
|
-
* role: { type: "string", enum: { owner: "Owner", admin: "Admin", member: "Member" },
|
|
272
|
-
* defaultValue: "member", validation: { required: true } },
|
|
273
|
-
* joinedAt: { type: "date", autoValue: "on_create" }
|
|
274
|
-
* }
|
|
275
|
-
* }
|
|
276
|
-
* }
|
|
277
|
-
* ```
|
|
278
|
-
*
|
|
279
|
-
* Both sides of the same junction may declare it, and both must agree:
|
|
280
|
-
* `resolveJunctionSpecs` refuses two declarations of the same payload
|
|
281
|
-
* key that do not describe the same column, because only one of them
|
|
282
|
-
* could ever be created.
|
|
283
|
-
*/
|
|
284
|
-
properties?: Properties;
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* An explicit chain of joins, for links the four shapes above cannot express:
|
|
289
|
-
* multi-hop paths, composite keys, or a join whose condition is not a plain
|
|
290
|
-
* foreign key.
|
|
291
|
-
*
|
|
292
|
-
* Read-only. Rebase will not infer how to write through an arbitrary join
|
|
293
|
-
* chain, and guessing is what this type exists to stop.
|
|
294
|
-
*
|
|
295
|
-
* ```ts
|
|
296
|
-
* permissions: {
|
|
297
|
-
* kind: "via",
|
|
298
|
-
* target: () => permissions,
|
|
299
|
-
* cardinality: "many",
|
|
300
|
-
* joinPath: [
|
|
301
|
-
* { table: "user_roles", on: { from: "id", to: "user_id" } },
|
|
302
|
-
* { table: "role_permissions", on: { from: "role_id", to: "role_id" } },
|
|
303
|
-
* { table: "permissions", on: { from: "permission_id", to: "id" } }
|
|
304
|
-
* ]
|
|
305
|
-
* }
|
|
306
|
-
* ```
|
|
307
|
-
* @group Models
|
|
308
|
-
*/
|
|
309
|
-
export interface ViaRelation extends RelationBase {
|
|
310
|
-
kind: "via";
|
|
311
|
-
/** Whether the chain yields one row or many. Cannot be derived from a join chain. */
|
|
312
|
-
cardinality: "one" | "many";
|
|
313
|
-
/**
|
|
314
|
-
* The joins, in order, from this collection's table to the target's.
|
|
315
|
-
*
|
|
316
|
-
* Each step names a table and the columns to join it on; the last step's
|
|
317
|
-
* table is the target. A single-hop chain is writable through a create or
|
|
318
|
-
* update — to-one in one step (the target holds the key), to-many through
|
|
319
|
-
* one junction table — and a longer one is read-only, because Rebase will
|
|
320
|
-
* not work out how to write through an arbitrary chain, and guessing is
|
|
321
|
-
* what this kind exists to stop.
|
|
322
|
-
*/
|
|
323
|
-
joinPath: JoinStep[];
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* A link from one collection to another, as authored.
|
|
327
|
-
*
|
|
328
|
-
* A closed union: pick the kind that describes the link and the type offers
|
|
329
|
-
* exactly the fields that kind needs. See {@link ResolvedRelation} for the form
|
|
330
|
-
* the runtime works with, which has every default filled in.
|
|
331
|
-
*
|
|
332
|
-
* @group Models
|
|
333
|
-
*/
|
|
334
|
-
export type Relation = BelongsToRelation | HasOneRelation | HasManyRelation | ManyToManyRelation | ViaRelation;
|
|
335
|
-
/**
|
|
336
|
-
* A relation with every default filled in — the form the runtime works with.
|
|
337
|
-
*
|
|
338
|
-
* The authored {@link Relation} and this are deliberately different types.
|
|
339
|
-
* They used to be one, which meant no reader could tell which fields had been
|
|
340
|
-
* supplied and which had been guessed, and so every consumer re-derived what it
|
|
341
|
-
* needed with its own chain of `if (through) … else if (localKey) …` fallbacks.
|
|
342
|
-
* Those chains disagreed with each other; that disagreement is what produced
|
|
343
|
-
* silently wrong reads and corrupt writes.
|
|
344
|
-
*
|
|
345
|
-
* Here each variant carries exactly its own fields, all required. A consumer
|
|
346
|
-
* switches on `kind` and gets what it needs without a fallback, and the cases
|
|
347
|
-
* it forgot are a compile error rather than a wrong answer at runtime.
|
|
348
|
-
*
|
|
349
|
-
* @group Models
|
|
350
|
-
*/
|
|
351
|
-
export type ResolvedRelation = ResolvedBelongsTo | ResolvedHasOne | ResolvedHasMany | ResolvedManyToMany | ResolvedVia;
|
|
352
|
-
/** Fields present on every resolved relation. @group Models */
|
|
353
|
-
export interface ResolvedRelationBase {
|
|
354
|
-
/** Always set: defaulted during resolution if the author omitted it. */
|
|
355
|
-
relationName: string;
|
|
356
|
-
/**
|
|
357
|
-
* The collection on the other end.
|
|
358
|
-
*
|
|
359
|
-
* Still a thunk — a relation between two collections that import each other
|
|
360
|
-
* has to be — but normalised: resolution unwraps the module namespace the
|
|
361
|
-
* author's `() => import(…)` may hand back, so every consumer gets the
|
|
362
|
-
* config and not a `{ default: … }` wrapper.
|
|
363
|
-
*/
|
|
364
|
-
target: () => AnyCollectionConfig;
|
|
365
|
-
/** The target's slug, resolved once so consumers need not call `target()`. */
|
|
366
|
-
targetSlug: string;
|
|
367
|
-
/** As authored — see {@link RelationBase.onUpdate}. Defaults are not filled in. */
|
|
368
|
-
onUpdate?: OnAction;
|
|
369
|
-
/**
|
|
370
|
-
* As authored — see {@link RelationBase.onDelete}. `undefined` here means
|
|
371
|
-
* the author said nothing, and the DDL generator picks the default; it does
|
|
372
|
-
* **not** mean "no action".
|
|
373
|
-
*/
|
|
374
|
-
onDelete?: OnAction;
|
|
375
|
-
/** Presentation overrides applied when this relation is rendered as a tab. */
|
|
376
|
-
overrides?: Partial<AnyCollectionConfig>;
|
|
377
|
-
/**
|
|
378
|
-
* Whether one row or many come back. Derived from `kind` — kept because it
|
|
379
|
-
* is what most consumers actually branch on, and because `via` is the one
|
|
380
|
-
* kind where it is authored rather than implied.
|
|
381
|
-
*/
|
|
382
|
-
cardinality: "one" | "many";
|
|
383
|
-
/**
|
|
384
|
-
* Whether Rebase writes this link through a create or update. True for
|
|
385
|
-
* every kind but a multi-hop {@link ResolvedVia}: a `via` is writable when
|
|
386
|
-
* it has a single link to set — a to-one chain of one step (the target
|
|
387
|
-
* holds the key) or a to-many chain through one junction table — and
|
|
388
|
-
* read-only otherwise, since Rebase will not invent a write for a longer
|
|
389
|
-
* chain.
|
|
390
|
-
*/
|
|
391
|
-
writable: boolean;
|
|
392
|
-
/**
|
|
393
|
-
* Whether the target rows are shared with other parents. True for
|
|
394
|
-
* many-to-many and for multi-hop `via`: what the parent owns is the link,
|
|
395
|
-
* so removing one must not delete the row.
|
|
396
|
-
*/
|
|
397
|
-
shared: boolean;
|
|
398
|
-
}
|
|
399
|
-
/** @group Models */
|
|
400
|
-
export interface ResolvedBelongsTo extends ResolvedRelationBase {
|
|
401
|
-
kind: "belongsTo";
|
|
402
|
-
cardinality: "one";
|
|
403
|
-
writable: true;
|
|
404
|
-
shared: false;
|
|
405
|
-
/** Column on this collection's table. */
|
|
406
|
-
localKey: string;
|
|
407
|
-
/** As authored, with the default filled in — see {@link BelongsToRelation.index}. */
|
|
408
|
-
index: boolean;
|
|
409
|
-
}
|
|
410
|
-
/** @group Models */
|
|
411
|
-
export interface ResolvedHasOne extends ResolvedRelationBase {
|
|
412
|
-
kind: "hasOne";
|
|
413
|
-
cardinality: "one";
|
|
414
|
-
writable: true;
|
|
415
|
-
shared: false;
|
|
416
|
-
/** Column on the target's table. */
|
|
417
|
-
foreignKeyOnTarget: string;
|
|
418
|
-
/** @see ResolvedHasMany.sourceKey */
|
|
419
|
-
sourceKey?: string;
|
|
420
|
-
}
|
|
421
|
-
/** @group Models */
|
|
422
|
-
export interface ResolvedHasMany extends ResolvedRelationBase {
|
|
423
|
-
kind: "hasMany";
|
|
424
|
-
cardinality: "many";
|
|
425
|
-
writable: true;
|
|
426
|
-
shared: false;
|
|
427
|
-
/** Column on the target's table. */
|
|
428
|
-
foreignKeyOnTarget: string;
|
|
429
|
-
/**
|
|
430
|
-
* Column on the source's table that `foreignKeyOnTarget` points at, or
|
|
431
|
-
* `undefined` for the source's primary key.
|
|
432
|
-
*
|
|
433
|
-
* The one optional field on a resolved relation, and deliberately so. Every
|
|
434
|
-
* other default is filled in here because it can be: a table name and a
|
|
435
|
-
* column name are derivable from the relation and its two endpoints alone.
|
|
436
|
-
* The primary key is not — this driver resolves it from `isId`, then the
|
|
437
|
-
* Drizzle schema, then a column named `id`, and the middle tier does not
|
|
438
|
-
* exist at resolution time.
|
|
439
|
-
*
|
|
440
|
-
* So `undefined` is a sentinel with exactly one meaning, not a field a
|
|
441
|
-
* consumer is invited to guess at. Read it through `sourceKeyField()`,
|
|
442
|
-
* which is the only place that turns it into a column name.
|
|
443
|
-
*/
|
|
444
|
-
sourceKey?: string;
|
|
445
|
-
}
|
|
446
|
-
/** @group Models */
|
|
447
|
-
export interface ResolvedManyToMany extends ResolvedRelationBase {
|
|
448
|
-
kind: "manyToMany";
|
|
449
|
-
cardinality: "many";
|
|
450
|
-
writable: true;
|
|
451
|
-
shared: true;
|
|
452
|
-
/**
|
|
453
|
-
* The junction table and its two key columns, with every default filled in:
|
|
454
|
-
* the table from both table names sorted and joined, the columns from each
|
|
455
|
-
* endpoint's slug.
|
|
456
|
-
*/
|
|
457
|
-
through: {
|
|
458
|
-
table: string;
|
|
459
|
-
sourceColumn: string;
|
|
460
|
-
targetColumn: string;
|
|
461
|
-
/**
|
|
462
|
-
* The payload columns as authored, or `{}` when there are none —
|
|
463
|
-
* never `undefined`, so a consumer reads one shape.
|
|
464
|
-
* See {@link ManyToManyRelation.through}.
|
|
465
|
-
*/
|
|
466
|
-
properties: Properties;
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
/** @group Models */
|
|
470
|
-
export interface ResolvedVia extends ResolvedRelationBase {
|
|
471
|
-
kind: "via";
|
|
472
|
-
/**
|
|
473
|
-
* True for a single-hop chain — to-one through one step, or to-many through
|
|
474
|
-
* one junction table — and false for anything longer. See
|
|
475
|
-
* {@link ResolvedRelationBase.writable}.
|
|
476
|
-
*/
|
|
477
|
-
writable: boolean;
|
|
478
|
-
/** The chain as authored — see {@link ViaRelation.joinPath}. Nothing to default. */
|
|
479
|
-
joinPath: JoinStep[];
|
|
480
|
-
}
|
|
481
|
-
/** Relations whose target row carries this collection's key. @group Models */
|
|
482
|
-
export type ResolvedForeignKeyOnTarget = ResolvedHasOne | ResolvedHasMany;
|
|
483
|
-
/** @group Models */
|
|
484
|
-
export declare function hasForeignKeyOnTarget(relation: ResolvedRelation): relation is ResolvedForeignKeyOnTarget;
|
|
485
|
-
/** @group Models */
|
|
486
|
-
export declare function isManyToMany(relation: ResolvedRelation): relation is ResolvedManyToMany;
|
|
487
|
-
/** @group Models */
|
|
488
|
-
export declare function isToMany(relation: ResolvedRelation): boolean;
|
|
489
59
|
/**
|
|
490
60
|
* Defines a single, explicit step in a multi-join path.
|
|
491
61
|
*
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Nothing here executes anything. These are the nouns.
|
|
12
12
|
*/
|
|
13
|
+
import type { CompiledTable } from "../schema/compiled.js";
|
|
14
|
+
import type { TableDescriptor } from "../schema/descriptor.js";
|
|
13
15
|
/**
|
|
14
16
|
* What a change will do to a live database.
|
|
15
17
|
*
|
|
@@ -148,8 +150,11 @@ export interface SchemaEditingAdmin {
|
|
|
148
150
|
*
|
|
149
151
|
* Rejects when the change is not applicable, carrying the classification so
|
|
150
152
|
* a caller can say which change was the problem.
|
|
153
|
+
*
|
|
154
|
+
* @param before The tables the running server serves, compiled.
|
|
155
|
+
* @param after The edited definitions, compiled (`compileSchemaDefs`).
|
|
151
156
|
*/
|
|
152
|
-
planSchemaChange(before:
|
|
157
|
+
planSchemaChange(before: readonly CompiledTable[], after: readonly CompiledTable[], options?: {
|
|
153
158
|
paths?: Partial<SchemaCommitPaths>;
|
|
154
159
|
/**
|
|
155
160
|
* Plan a commit of the source alone — "Edit source only": never
|
|
@@ -171,10 +176,57 @@ export interface SchemaEditingAdmin {
|
|
|
171
176
|
*
|
|
172
177
|
* Optional so a driver that cannot answer stays a valid admin.
|
|
173
178
|
*/
|
|
174
|
-
planSchemaReconcile?(
|
|
179
|
+
planSchemaReconcile?(
|
|
180
|
+
/** The tables the running server serves, compiled. */
|
|
181
|
+
tables: readonly CompiledTable[], options?: {
|
|
175
182
|
/** Undeclared columns to drop, as `<collection slug>.<column>`. */
|
|
176
183
|
drop?: string[];
|
|
177
184
|
}): Promise<SchemaReconcilePlan>;
|
|
185
|
+
/**
|
|
186
|
+
* The tables of one Postgres schema that no declared table maps — what
|
|
187
|
+
* "Import an existing table" offers — each described as introspection
|
|
188
|
+
* reads it, ready to adopt (`adoptTable`). Junction tables and Rebase's
|
|
189
|
+
* own are left out. Only `SELECT`s.
|
|
190
|
+
*
|
|
191
|
+
* Optional so a driver that cannot answer stays a valid admin.
|
|
192
|
+
*
|
|
193
|
+
* @param schema The Postgres schema to read.
|
|
194
|
+
* @param mapped The SQL names of the tables already declared in it.
|
|
195
|
+
*/
|
|
196
|
+
describeUnmappedTables?(schema: string, mapped: ReadonlySet<string>): Promise<UnmappedTable[]>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* A table the database has and no declared table maps, as "Import an
|
|
200
|
+
* existing table" reads it.
|
|
201
|
+
*
|
|
202
|
+
* @group Schema
|
|
203
|
+
*/
|
|
204
|
+
export interface UnmappedTable {
|
|
205
|
+
/** The Postgres schema holding it. */
|
|
206
|
+
schema: string;
|
|
207
|
+
/** The SQL table. */
|
|
208
|
+
table: string;
|
|
209
|
+
/** Row-level security is on (`relrowsecurity`). */
|
|
210
|
+
rlsEnabled: boolean;
|
|
211
|
+
/** How many policies the database holds on it. */
|
|
212
|
+
policies: number;
|
|
213
|
+
/**
|
|
214
|
+
* The table as introspection describes it — columns as their Postgres
|
|
215
|
+
* types, defaults, keys, foreign keys to declared tables as `belongsTo`,
|
|
216
|
+
* enums, the policies as rules — which `adoptTable` writes as its
|
|
217
|
+
* `defineTable` source. Absent when it cannot be imported.
|
|
218
|
+
*
|
|
219
|
+
* Its `rls` is never weaker than what the database enforces: a table whose
|
|
220
|
+
* row-level security is off, or that has no policy, is described
|
|
221
|
+
* `"admin-only"` ({@link rlsRaised} says so).
|
|
222
|
+
*/
|
|
223
|
+
descriptor?: TableDescriptor;
|
|
224
|
+
/** Set when {@link descriptor}'s `rls` is `"admin-only"` because the database protects the table with no rule: the sentence the import shows. */
|
|
225
|
+
rlsRaised?: string;
|
|
226
|
+
/** Why it cannot be imported, when it cannot (no primary key, …). */
|
|
227
|
+
unimportable?: string;
|
|
228
|
+
/** What introspection noted: what a push would not reproduce exactly, and decisions the file states. */
|
|
229
|
+
notes: string[];
|
|
178
230
|
}
|
|
179
231
|
/** A column that exists in a collection's table and that no property declares. */
|
|
180
232
|
export interface SchemaReconcileColumn {
|
|
@@ -1,11 +1,31 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableDescriptor } from "../schema/descriptor.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The prefix of a version computed before 0.31, from collections.
|
|
4
|
+
*
|
|
5
|
+
* A database stamped with one was provisioned under the collection model. Its
|
|
6
|
+
* version can never equal a descriptor version, so the first boot of a 0.31
|
|
7
|
+
* runtime against it reports a mismatch once — and says why, and how to
|
|
8
|
+
* restamp.
|
|
9
|
+
*/
|
|
10
|
+
export declare const LEGACY_SCHEMA_VERSION_PREFIX = "v1:";
|
|
11
|
+
/**
|
|
12
|
+
* Compute the canonical string a schema version hashes: the tables'
|
|
13
|
+
* descriptors, ordered by slug, every object's keys sorted.
|
|
14
|
+
*
|
|
15
|
+
* A descriptor is the compiled table — every default applied, every name
|
|
16
|
+
* derived, `rls` resolved against `defaultRls` — so the same source compiles to
|
|
17
|
+
* the same descriptor before or after anything loads it, and a build-time
|
|
18
|
+
* stamp can match the server that serves it. It is plain JSON by
|
|
19
|
+
* construction: hooks appear only as presence flags (`hooks.afterRead: true`),
|
|
20
|
+
* so editing what a hook does never moves the version, while adding or
|
|
21
|
+
* removing one does.
|
|
22
|
+
*
|
|
23
|
+
* Ordered by slug, so the order the tables were exported in cannot alter it.
|
|
4
24
|
*
|
|
5
25
|
* Exposed separately so the hashing itself can differ by environment: Node has
|
|
6
26
|
* `crypto`, and callers without it can still compare canonical forms directly.
|
|
7
27
|
*/
|
|
8
|
-
export declare function canonicalSchemaPayload(
|
|
28
|
+
export declare function canonicalSchemaPayload(tables: readonly TableDescriptor[]): string;
|
|
9
29
|
/**
|
|
10
30
|
* A short, non-cryptographic digest of the canonical payload.
|
|
11
31
|
*
|
|
@@ -15,4 +35,4 @@ export declare function canonicalSchemaPayload(collections: CollectionConfig[]):
|
|
|
15
35
|
* module free of `node:crypto`, so the identical function runs in the browser,
|
|
16
36
|
* in the CLI, and in the runtime — which is the property that actually matters.
|
|
17
37
|
*/
|
|
18
|
-
export declare function computeSchemaVersion(
|
|
38
|
+
export declare function computeSchemaVersion(tables: readonly TableDescriptor[]): string;
|