@sequenceholdings/orm 0.1.2 → 0.1.3
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 +11 -1
- package/dist/authoring.cjs +1066 -59
- package/dist/authoring.cjs.map +1 -1
- package/dist/authoring.d.cts +289 -24
- package/dist/authoring.d.ts +289 -24
- package/dist/authoring.js +1056 -60
- package/dist/authoring.js.map +1 -1
- package/dist/canonical.cjs +415 -9
- package/dist/canonical.cjs.map +1 -1
- package/dist/canonical.d.cts +235 -1
- package/dist/canonical.d.ts +235 -1
- package/dist/canonical.js +411 -10
- package/dist/canonical.js.map +1 -1
- package/dist/cli.cjs +1764 -225
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1765 -226
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +506 -54
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.d.cts +39 -231
- package/dist/compiler.d.ts +39 -231
- package/dist/compiler.js +504 -55
- package/dist/compiler.js.map +1 -1
- package/dist/drizzle.cjs +14 -0
- package/dist/drizzle.cjs.map +1 -0
- package/dist/drizzle.d.cts +1 -0
- package/dist/drizzle.d.ts +1 -0
- package/dist/drizzle.js +3 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/dynamic-input.cjs +391 -0
- package/dist/dynamic-input.cjs.map +1 -0
- package/dist/dynamic-input.d.cts +111 -0
- package/dist/dynamic-input.d.ts +111 -0
- package/dist/dynamic-input.js +380 -0
- package/dist/dynamic-input.js.map +1 -0
- package/dist/index.cjs +2223 -219
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +125 -9
- package/dist/index.d.ts +125 -9
- package/dist/index.js +2199 -220
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +249 -14
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +20 -80
- package/dist/ir.d.ts +20 -80
- package/dist/ir.js +249 -14
- package/dist/ir.js.map +1 -1
- package/dist/predicate-v2.cjs +1093 -0
- package/dist/predicate-v2.cjs.map +1 -0
- package/dist/predicate-v2.d.cts +139 -0
- package/dist/predicate-v2.d.ts +139 -0
- package/dist/predicate-v2.js +1083 -0
- package/dist/predicate-v2.js.map +1 -0
- package/dist/sdl.cjs +344 -55
- package/dist/sdl.cjs.map +1 -1
- package/dist/sdl.d.cts +1 -3
- package/dist/sdl.d.ts +1 -3
- package/dist/sdl.js +344 -55
- package/dist/sdl.js.map +1 -1
- package/package.json +16 -1
- package/templates/orm-namespace/CLAUDE.md +6 -5
package/dist/authoring.d.cts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { ColumnType, CanonicalColumn, CanonicalDefinition } from './canonical.cjs';
|
|
1
|
+
import { ColumnType, CanonicalColumn, CanonicalDefinition, CanonicalTable } from './canonical.cjs';
|
|
2
|
+
import { ColumnsSelection } from 'drizzle-orm';
|
|
3
|
+
import { TypedQueryBuilder } from 'drizzle-orm/query-builders/query-builder';
|
|
4
|
+
import { QueryBuilder, PgView, PgTable, AnyPgColumn } from 'drizzle-orm/pg-core';
|
|
2
5
|
import 'zod';
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -80,10 +83,184 @@ declare const t: {
|
|
|
80
83
|
readonly enum: (ref: EnumRef, columnName?: string) => ColumnBuilder;
|
|
81
84
|
};
|
|
82
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Overlay identity for CoW helpers. Prefer a plain `{ tableName, columns }`
|
|
88
|
+
* descriptor when declaring `cowMutations` inside the same `defineTable` call
|
|
89
|
+
* (the `SeqTable` handle does not exist yet). A finished `SeqTable` also works.
|
|
90
|
+
*/
|
|
91
|
+
type OverlayTableRef<TColumns extends Record<string, ColumnBuilder> = Record<string, ColumnBuilder>> = {
|
|
92
|
+
readonly tableName: string;
|
|
93
|
+
readonly columns: Readonly<TColumns>;
|
|
94
|
+
/** Optional — used only when a finished `SeqTable` is passed. */
|
|
95
|
+
readonly config?: TableConfig;
|
|
96
|
+
};
|
|
97
|
+
/** Structured CoW mutation declaration — serialized into canonical `cowMutations`. */
|
|
98
|
+
interface CowMutationInput {
|
|
99
|
+
kind: 'override' | 'revert';
|
|
100
|
+
/** Mutation name (snake identifier); the GraphQL field is its camelCase form. */
|
|
101
|
+
name: string;
|
|
102
|
+
/** Synced table (same namespace) the overlay copies from / falls back to. */
|
|
103
|
+
synced: string;
|
|
104
|
+
/** Single-column primary key property shared by overlay and synced. */
|
|
105
|
+
pk: string;
|
|
106
|
+
/** Override: contract properties copied INSERT…SELECT from synced (pk included). */
|
|
107
|
+
copy: readonly string[];
|
|
108
|
+
/** Override: overlay properties written by the UPDATE (never the pk). */
|
|
109
|
+
set: readonly string[];
|
|
110
|
+
}
|
|
111
|
+
interface OverrideRowMutationInput<TOverlay extends OverlayTableRef = OverlayTableRef, TSynced extends SeqTable = SeqTable> {
|
|
112
|
+
/** Writable ORM overlay table (or `{ tableName, columns }` descriptor). */
|
|
113
|
+
overlay: TOverlay;
|
|
114
|
+
/** Read-only synced table reflecting the gold-layer source. */
|
|
115
|
+
synced: TSynced;
|
|
116
|
+
/**
|
|
117
|
+
* Property name of the single-column primary key shared by both tables.
|
|
118
|
+
* Must be the declared PK on overlay and synced.
|
|
119
|
+
*/
|
|
120
|
+
pk: string & keyof TOverlay['columns'] & keyof TSynced['columns'];
|
|
121
|
+
/**
|
|
122
|
+
* Overlay property names that become required mutation arguments and are
|
|
123
|
+
* written by the UPDATE. Defaults to every non-PK column shared with the
|
|
124
|
+
* synced table. PK changes are always rejected.
|
|
125
|
+
*/
|
|
126
|
+
set?: ReadonlyArray<string & keyof TOverlay['columns']>;
|
|
127
|
+
/** Mutation name. Defaults to `override_<overlay.tableName>`. */
|
|
128
|
+
name?: string;
|
|
129
|
+
}
|
|
130
|
+
interface RevertOverlayMutationInput<TOverlay extends OverlayTableRef = OverlayTableRef, TSynced extends SeqTable = SeqTable> {
|
|
131
|
+
/** Writable ORM overlay table (or `{ tableName, columns }` descriptor). */
|
|
132
|
+
overlay: TOverlay;
|
|
133
|
+
/**
|
|
134
|
+
* Read-only synced table — required so revert only deletes overrides that
|
|
135
|
+
* have a synced row to fall back to (never overlay-only creates).
|
|
136
|
+
*/
|
|
137
|
+
synced: TSynced;
|
|
138
|
+
/**
|
|
139
|
+
* Property name of the single-column primary key shared by both tables.
|
|
140
|
+
* Must be the declared PK on overlay and synced.
|
|
141
|
+
*/
|
|
142
|
+
pk: string & keyof TOverlay['columns'] & keyof TSynced['columns'];
|
|
143
|
+
/** Mutation name. Defaults to `revert_<overlay.tableName>`. */
|
|
144
|
+
name?: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Declares an explicit copy-on-write override mutation for an overlay table.
|
|
148
|
+
*
|
|
149
|
+
* Executes atomically in the data plane (both statements engine-generated):
|
|
150
|
+
* 1. `INSERT … SELECT` contract columns from synced, `ON CONFLICT (pk) DO NOTHING`
|
|
151
|
+
* 2. `UPDATE` overlay with the declared `set` arguments (PK pinned; gated on a
|
|
152
|
+
* matching synced row; overlay write policy injected)
|
|
153
|
+
*
|
|
154
|
+
* Serializes into the overlay table's canonical `cowMutations`. Revert with
|
|
155
|
+
* {@link revertOverlayMutation}.
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* const columns = { uid: t.uuid().primaryKey(), name: t.text().notNull(), balance: t.numeric() }
|
|
159
|
+
* defineTable('loan_overlay', columns, {
|
|
160
|
+
* policies: { read: 'true', write: 'true' },
|
|
161
|
+
* cowMutations: [
|
|
162
|
+
* overrideRowMutation({
|
|
163
|
+
* overlay: { tableName: 'loan_overlay', columns },
|
|
164
|
+
* synced: syncedLoans,
|
|
165
|
+
* pk: 'uid',
|
|
166
|
+
* set: ['name', 'balance'],
|
|
167
|
+
* }),
|
|
168
|
+
* revertOverlayMutation({
|
|
169
|
+
* overlay: { tableName: 'loan_overlay', columns },
|
|
170
|
+
* synced: syncedLoans,
|
|
171
|
+
* pk: 'uid',
|
|
172
|
+
* }),
|
|
173
|
+
* ],
|
|
174
|
+
* })
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function overrideRowMutation<TOverlay extends OverlayTableRef, TSynced extends SeqTable>(input: OverrideRowMutationInput<TOverlay, TSynced>): CowMutationInput;
|
|
178
|
+
/**
|
|
179
|
+
* Declares a revert mutation that deletes an overlay override by PK so the
|
|
180
|
+
* coalesce view falls back to synced.
|
|
181
|
+
*
|
|
182
|
+
* The DELETE is gated on a matching synced row — overlay-only creates (or rows
|
|
183
|
+
* whose synced source disappeared) are not deleted by revert.
|
|
184
|
+
*/
|
|
185
|
+
declare function revertOverlayMutation<TOverlay extends OverlayTableRef, TSynced extends SeqTable>(input: RevertOverlayMutationInput<TOverlay, TSynced>): CowMutationInput;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Managed regular-view authoring. A view keeps its GraphQL contract in the
|
|
189
|
+
* Sequence column/policy DSL, while its SELECT is authored with Drizzle and
|
|
190
|
+
* compiled to inert canonical SQL before crossing the CLI → Atlas boundary.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
declare const VIEW_BRAND: "seq-view";
|
|
194
|
+
type ViewSelectQuery = TypedQueryBuilder<ColumnsSelection>;
|
|
195
|
+
interface ViewQueryContext {
|
|
196
|
+
readonly qb: QueryBuilder;
|
|
197
|
+
relation<TRelation extends SeqTable | SeqView>(relation: TRelation | (() => TRelation)): DrizzleRelation<TRelation>;
|
|
198
|
+
}
|
|
199
|
+
interface ViewPoliciesInput {
|
|
200
|
+
read: PolicyInput;
|
|
201
|
+
}
|
|
202
|
+
interface ViewConfig {
|
|
203
|
+
description?: string;
|
|
204
|
+
/** Logical GraphQL identity only; PostgreSQL does not create a PK for a view. */
|
|
205
|
+
primaryKey?: readonly string[];
|
|
206
|
+
links?: Record<string, SeqLink>;
|
|
207
|
+
policies: ViewPoliciesInput;
|
|
208
|
+
query: (context: ViewQueryContext) => ViewSelectQuery;
|
|
209
|
+
}
|
|
210
|
+
interface SeqView<TColumns extends Record<string, ColumnBuilder> = Record<string, ColumnBuilder>> {
|
|
211
|
+
readonly kind: typeof VIEW_BRAND;
|
|
212
|
+
readonly viewName: string;
|
|
213
|
+
readonly columns: Readonly<TColumns>;
|
|
214
|
+
readonly config: ViewConfig;
|
|
215
|
+
readonly file: string | undefined;
|
|
216
|
+
}
|
|
217
|
+
type RelationColumnKeys<TRelation extends SeqTable | SeqView> = keyof TRelation['columns'] & string;
|
|
218
|
+
/** Property-keyed Drizzle handle supplied by `relation(...)` inside a view query. */
|
|
219
|
+
type DrizzleRelation<TRelation extends SeqTable | SeqView> = (TRelation extends SeqView ? PgView : PgTable) & Record<RelationColumnKeys<TRelation>, AnyPgColumn>;
|
|
220
|
+
declare function isSeqView(value: unknown): value is SeqView;
|
|
221
|
+
declare function defineView<const TColumns extends Record<string, ColumnBuilder>>(name: string, columns: TColumns, config: ViewConfig): SeqView<TColumns>;
|
|
222
|
+
interface OverlayWinsUnionInput<TOverlay extends SeqTable = SeqTable, TSynced extends SeqTable = SeqTable> {
|
|
223
|
+
/** The ORM overlay table (writable, has `tombstone` if soft-delete is used). */
|
|
224
|
+
overlay: TOverlay;
|
|
225
|
+
/** The synced (read-only) table reflecting the gold-layer source. */
|
|
226
|
+
synced: TSynced;
|
|
227
|
+
/**
|
|
228
|
+
* Property name of the single-column primary key shared by both tables.
|
|
229
|
+
* Must be the declared PK on overlay and synced (`.primaryKey()` or
|
|
230
|
+
* `config.primaryKey`), not merely a unique/not-null column.
|
|
231
|
+
*/
|
|
232
|
+
pk: string;
|
|
233
|
+
/**
|
|
234
|
+
* Property name of a non-null boolean tombstone column on the overlay table.
|
|
235
|
+
* When set, tombstoned overlay rows are excluded (and therefore suppress the
|
|
236
|
+
* matching synced row). Omit if the overlay table has no tombstone column.
|
|
237
|
+
*/
|
|
238
|
+
tombstone?: string;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Builds the overlay-wins coalesce `query` callback for `defineView`.
|
|
242
|
+
*
|
|
243
|
+
* Row-level overlay wins: every overlay row (minus tombstones) appears with
|
|
244
|
+
* `provenance = 'overlay'`; every synced row whose PK is NOT present in the
|
|
245
|
+
* overlay appears with `provenance = 'synced'`.
|
|
246
|
+
*
|
|
247
|
+
* The returned callback is passed directly as `ViewConfig.query`.
|
|
248
|
+
*
|
|
249
|
+
* ```ts
|
|
250
|
+
* const view = defineView('unified_loans', columns, {
|
|
251
|
+
* query: overlayWinsUnion({ overlay: loanOverlay, synced: syncedLoans, pk: 'uid' }),
|
|
252
|
+
* policies: { read: 'true' },
|
|
253
|
+
* })
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
declare function overlayWinsUnion<TOverlay extends SeqTable, TSynced extends SeqTable>(input: OverlayWinsUnionInput<TOverlay, TSynced>): ViewConfig['query'];
|
|
257
|
+
|
|
83
258
|
declare const TABLE_BRAND: "seq-table";
|
|
84
259
|
declare const LINK_BRAND: "seq-link";
|
|
85
|
-
/** A link target:
|
|
86
|
-
type
|
|
260
|
+
/** A link target: a managed table/view, or a lazy thunk for forward/cyclic references. */
|
|
261
|
+
type RelationRef = SeqTable | SeqView | (() => SeqTable | SeqView);
|
|
262
|
+
/** Backward-compatible alias retained for existing consumers. */
|
|
263
|
+
type TableRef = RelationRef;
|
|
87
264
|
type LinkKind = 'toOne' | 'toMany' | 'toPlatformUser';
|
|
88
265
|
interface SeqLink {
|
|
89
266
|
readonly kind: typeof LINK_BRAND;
|
|
@@ -134,7 +311,12 @@ interface PolicyWithVariantsInput {
|
|
|
134
311
|
type PolicyInput = string | PolicyWithVariantsInput;
|
|
135
312
|
interface TablePoliciesInput {
|
|
136
313
|
read?: PolicyInput;
|
|
314
|
+
/** Legacy single policy for every write command; use insert/update when they differ. */
|
|
137
315
|
write?: PolicyInput;
|
|
316
|
+
/** Insert WITH CHECK; falls back to write when omitted. */
|
|
317
|
+
insert?: PolicyInput;
|
|
318
|
+
/** Update USING + WITH CHECK; falls back to write when omitted. */
|
|
319
|
+
update?: PolicyInput;
|
|
138
320
|
}
|
|
139
321
|
interface IndexInput {
|
|
140
322
|
/** Property names (camelCase) or Postgres column names. */
|
|
@@ -142,21 +324,6 @@ interface IndexInput {
|
|
|
142
324
|
unique?: boolean;
|
|
143
325
|
name?: string;
|
|
144
326
|
}
|
|
145
|
-
interface ActionParamInput {
|
|
146
|
-
type: ColumnType;
|
|
147
|
-
nullable?: boolean;
|
|
148
|
-
}
|
|
149
|
-
interface ActionInput {
|
|
150
|
-
name: string;
|
|
151
|
-
requires?: string;
|
|
152
|
-
params?: Record<string, ActionParamInput>;
|
|
153
|
-
executes: string;
|
|
154
|
-
returns?: 'rows' | 'rowsAffected' | 'scalar';
|
|
155
|
-
audit?: {
|
|
156
|
-
action: string;
|
|
157
|
-
resource: string;
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
327
|
interface TableConfig {
|
|
161
328
|
description?: string;
|
|
162
329
|
/** Table-level migration rename hint (new in v2). */
|
|
@@ -166,12 +333,18 @@ interface TableConfig {
|
|
|
166
333
|
indexes?: readonly IndexInput[];
|
|
167
334
|
links?: Record<string, SeqLink>;
|
|
168
335
|
policies?: TablePoliciesInput;
|
|
169
|
-
|
|
336
|
+
/**
|
|
337
|
+
* Copy-on-write mutations for overlay tables backed by a synced twin —
|
|
338
|
+
* declare with `overrideRowMutation` / `revertOverlayMutation`. v2 has no
|
|
339
|
+
* action surface: writes are mutations, and these compile to structured
|
|
340
|
+
* mutation roots whose SQL the engine generates.
|
|
341
|
+
*/
|
|
342
|
+
cowMutations?: readonly CowMutationInput[];
|
|
170
343
|
}
|
|
171
|
-
interface SeqTable {
|
|
344
|
+
interface SeqTable<TColumns extends Record<string, ColumnBuilder> = Record<string, ColumnBuilder>> {
|
|
172
345
|
readonly kind: typeof TABLE_BRAND;
|
|
173
346
|
readonly tableName: string;
|
|
174
|
-
readonly columns: Readonly<
|
|
347
|
+
readonly columns: Readonly<TColumns>;
|
|
175
348
|
readonly config: TableConfig;
|
|
176
349
|
/** Synced reflected source (`gold.*`) — set only by defineSyncedTable. */
|
|
177
350
|
readonly source: string | undefined;
|
|
@@ -179,13 +352,36 @@ interface SeqTable {
|
|
|
179
352
|
readonly file: string | undefined;
|
|
180
353
|
}
|
|
181
354
|
declare function isSeqTable(value: unknown): value is SeqTable;
|
|
182
|
-
declare function defineTable(name: string, columns:
|
|
355
|
+
declare function defineTable<const TColumns extends Record<string, ColumnBuilder>>(name: string, columns: TColumns, config?: TableConfig): SeqTable<TColumns>;
|
|
356
|
+
interface SyncedTablePoliciesInput {
|
|
357
|
+
/** Claims-filtered read policy compiled onto the ORM materialization view. */
|
|
358
|
+
read?: PolicyInput;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Config for a read-only gold reflection. Columns (typed overload) are a contract
|
|
362
|
+
* for views/clients — ORM does not own synced DDL.
|
|
363
|
+
*/
|
|
183
364
|
interface SyncedTableConfig {
|
|
184
365
|
/** Reflected read-only source, restricted to the gold layer: `gold.<table>`. */
|
|
185
366
|
source: string;
|
|
186
367
|
description?: string;
|
|
368
|
+
/** Composite primary key: property names (or column names). Mutually exclusive with column-level `.primaryKey()`. */
|
|
369
|
+
primaryKey?: readonly string[];
|
|
370
|
+
links?: Record<string, SeqLink>;
|
|
371
|
+
policies?: SyncedTablePoliciesInput;
|
|
187
372
|
}
|
|
373
|
+
/** @deprecated Alias — typed and untyped share SyncedTableConfig. */
|
|
374
|
+
type TypedSyncedTableConfig = SyncedTableConfig;
|
|
375
|
+
/**
|
|
376
|
+
* Untyped: schema-less synced table (columns discovered at apply time).
|
|
377
|
+
*/
|
|
188
378
|
declare function defineSyncedTable(name: string, config: SyncedTableConfig): SeqTable;
|
|
379
|
+
/**
|
|
380
|
+
* Typed: synced table with explicit column declarations for use in view
|
|
381
|
+
* queries (e.g. overlay-wins coalesce). Columns are authored with `t.*`
|
|
382
|
+
* builders like regular tables; the table remains read-only.
|
|
383
|
+
*/
|
|
384
|
+
declare function defineSyncedTable<const TColumns extends Record<string, ColumnBuilder>>(name: string, columns: TColumns, config: SyncedTableConfig): SeqTable<TColumns>;
|
|
189
385
|
declare function defineEnum(name: string, values: readonly string[]): EnumRef;
|
|
190
386
|
|
|
191
387
|
declare const NAMESPACE_CONFIG_BRAND: "seq-namespace-config";
|
|
@@ -212,6 +408,7 @@ declare function defineNamespace(input: NamespaceConfigInput): SeqNamespaceConfi
|
|
|
212
408
|
interface SerializeNamespaceInput {
|
|
213
409
|
config: SeqNamespaceConfig;
|
|
214
410
|
tables: readonly SeqTable[];
|
|
411
|
+
views?: readonly SeqView[];
|
|
215
412
|
enums?: readonly EnumRef[];
|
|
216
413
|
}
|
|
217
414
|
/**
|
|
@@ -223,6 +420,73 @@ declare function serializeNamespace(input: SerializeNamespaceInput): CanonicalDe
|
|
|
223
420
|
/** sha256 over the v1 hash domain + key-sorted JSON of the normalized canonical definition. */
|
|
224
421
|
declare function computeCanonicalHash(definition: CanonicalDefinition): string;
|
|
225
422
|
|
|
423
|
+
/** Domain separation so synced-contract hashes never collide with definition hashes. */
|
|
424
|
+
declare const SYNCED_CONTRACT_HASH_DOMAIN = "sequence-orm-synced-contract\0";
|
|
425
|
+
/**
|
|
426
|
+
* Pipeline-side ORM-mappable scalars. Inverse of pipeline-spec's
|
|
427
|
+
* `PIPELINE_TO_ORM_TYPE` — every ORM scalar has exactly one preimage.
|
|
428
|
+
*/
|
|
429
|
+
declare const ORM_TO_PIPELINE_TYPE: {
|
|
430
|
+
readonly uuid: "uuid";
|
|
431
|
+
readonly text: "string";
|
|
432
|
+
readonly integer: "int";
|
|
433
|
+
readonly bigint: "long";
|
|
434
|
+
readonly numeric: "numeric";
|
|
435
|
+
readonly double: "double";
|
|
436
|
+
readonly boolean: "boolean";
|
|
437
|
+
readonly timestamptz: "timestamp";
|
|
438
|
+
readonly date: "date";
|
|
439
|
+
readonly jsonb: "json";
|
|
440
|
+
};
|
|
441
|
+
type OrmToPipelineType = (typeof ORM_TO_PIPELINE_TYPE)[ColumnType];
|
|
442
|
+
/**
|
|
443
|
+
* Column shape a serving projection / `checkCompatibility` consumer expects.
|
|
444
|
+
* Structurally aligned with pipeline-spec `Column` (type + nullable + key);
|
|
445
|
+
* intentionally local so `@sequenceholdings/orm` does not depend on
|
|
446
|
+
* `@sequenceholdings/pipeline-spec`.
|
|
447
|
+
*/
|
|
448
|
+
interface OrmContractPipelineColumn {
|
|
449
|
+
readonly type: OrmToPipelineType;
|
|
450
|
+
readonly nullable: boolean;
|
|
451
|
+
/** True when the column participates in the synced table primary key. */
|
|
452
|
+
readonly key: boolean;
|
|
453
|
+
}
|
|
454
|
+
type OrmContractColumnMap = Readonly<Record<string, OrmContractPipelineColumn>>;
|
|
455
|
+
/** Published contract artifact for one typed synced table. */
|
|
456
|
+
interface OrmSyncedTableContract {
|
|
457
|
+
readonly namespace: string;
|
|
458
|
+
readonly table: string;
|
|
459
|
+
/** Columns keyed by Postgres column name (pipeline identifier plane). */
|
|
460
|
+
readonly columns: OrmContractColumnMap;
|
|
461
|
+
/** Postgres column names, exact order from the canonical primary key. */
|
|
462
|
+
readonly primary_key: readonly string[];
|
|
463
|
+
/** sha256 hex of the contract-bearing surface (stable across cosmetic fields). */
|
|
464
|
+
readonly content_hash: string;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Contract-bearing surface hashed into `content_hash`. Descriptions, links,
|
|
468
|
+
* policies, and source string are intentionally excluded — they are not part
|
|
469
|
+
* of the projection↔ORM column contract.
|
|
470
|
+
*/
|
|
471
|
+
declare function syncedContractSurface({ namespace, table, columns, primary_key, }: {
|
|
472
|
+
namespace: string;
|
|
473
|
+
table: string;
|
|
474
|
+
columns: OrmContractColumnMap;
|
|
475
|
+
primary_key: readonly string[];
|
|
476
|
+
}): Record<string, unknown>;
|
|
477
|
+
declare function computeSyncedContractHash(surface: Record<string, unknown>): string;
|
|
478
|
+
/**
|
|
479
|
+
* Extract the Managed Pipelines contract from a typed canonical synced table.
|
|
480
|
+
*
|
|
481
|
+
* Requires non-empty columns and a primary key (the typed `defineSyncedTable`
|
|
482
|
+
* authoring rules). Enum columns are rejected — they have no pipeline-type
|
|
483
|
+
* preimage in the ORM↔pipeline bijection.
|
|
484
|
+
*/
|
|
485
|
+
declare function extractOrmSyncedTableContract({ namespace, table, }: {
|
|
486
|
+
namespace: string;
|
|
487
|
+
table: CanonicalTable;
|
|
488
|
+
}): OrmSyncedTableContract;
|
|
489
|
+
|
|
226
490
|
declare const NAMESPACE_CONFIG_FILE = "sequence.config.ts";
|
|
227
491
|
declare const SCHEMA_DIR = "schema";
|
|
228
492
|
interface LoadNamespaceOptions {
|
|
@@ -243,7 +507,7 @@ declare function loadNamespaceFromDir(dir: string, options?: LoadNamespaceOption
|
|
|
243
507
|
|
|
244
508
|
/**
|
|
245
509
|
* Module-registry pattern for the authoring surface: `defineTable` /
|
|
246
|
-
* `defineEnum` / `defineNamespace` register into the ACTIVE collection
|
|
510
|
+
* `defineView` / `defineEnum` / `defineNamespace` register into the ACTIVE collection
|
|
247
511
|
* context while `loadNamespaceFromDir` imports a consumer's files, so the
|
|
248
512
|
* loader collects definitions without inspecting module exports.
|
|
249
513
|
*
|
|
@@ -262,6 +526,7 @@ interface AuthoringContext {
|
|
|
262
526
|
/** Set by the loader before importing each consumer file — error attribution. */
|
|
263
527
|
currentFile: string | undefined;
|
|
264
528
|
readonly tables: AuthoringRegistration[];
|
|
529
|
+
readonly views: AuthoringRegistration[];
|
|
265
530
|
readonly enums: AuthoringRegistration[];
|
|
266
531
|
readonly configs: AuthoringRegistration[];
|
|
267
532
|
}
|
|
@@ -271,4 +536,4 @@ declare function beginAuthoringContext(): AuthoringContext;
|
|
|
271
536
|
declare function endAuthoringContext(context: AuthoringContext): void;
|
|
272
537
|
declare function activeAuthoringContext(): AuthoringContext | undefined;
|
|
273
538
|
|
|
274
|
-
export { type
|
|
539
|
+
export { type AuthoringContext, type AuthoringRegistration, COLUMN_BRAND, COLUMN_DEFAULT_FNS, ColumnBuilder, type ColumnDefaultFn, type ColumnDefaultLiteral, type ColumnTypeSpec, type CowMutationInput, type DrizzleRelation, ENUM_BRAND, type EnumRef, type IndexInput, LINK_BRAND, type LinkKind, type LoadNamespaceOptions, type LoadedNamespaceV2, NAMESPACE_CONFIG_BRAND, NAMESPACE_CONFIG_FILE, type NamespaceCapabilitiesInput, type NamespaceConfigInput, ORM_TO_PIPELINE_TYPE, type OrmContractColumnMap, type OrmContractPipelineColumn, type OrmSyncedTableContract, type OrmToPipelineType, type OverlayTableRef, type OverlayWinsUnionInput, type OverrideRowMutationInput, type PolicyInput, type PolicyVariantInput, type PolicyWithVariantsInput, type RelationRef, type RevertOverlayMutationInput, SCHEMA_DIR, SYNCED_CONTRACT_HASH_DOMAIN, type SeqLink, type SeqNamespaceConfig, type SeqTable, type SeqView, type SerializeNamespaceInput, type SyncedTableConfig, type SyncedTablePoliciesInput, TABLE_BRAND, type TableConfig, type TablePoliciesInput, type TableRef, type ToManyOptions, type ToOneOptions, type ToPlatformUserOptions, type TypedSyncedTableConfig, VIEW_BRAND, type ViewConfig, type ViewPoliciesInput, type ViewQueryContext, type ViewSelectQuery, activeAuthoringContext, beginAuthoringContext, computeCanonicalHash, computeSyncedContractHash, defineEnum, defineNamespace, defineSyncedTable, defineTable, defineView, deriveColumnName, endAuthoringContext, extractOrmSyncedTableContract, isColumnBuilder, isEnumRef, isSeqLink, isSeqNamespaceConfig, isSeqTable, isSeqView, loadNamespaceFromDir, overlayWinsUnion, overrideRowMutation, revertOverlayMutation, serializeNamespace, syncedContractSurface, t, toMany, toOne, toPlatformUser };
|