@sequenceholdings/orm 0.1.1 → 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.
Files changed (81) hide show
  1. package/README.md +12 -2
  2. package/dist/authoring.cjs +1801 -0
  3. package/dist/authoring.cjs.map +1 -0
  4. package/dist/authoring.d.cts +539 -0
  5. package/dist/authoring.d.ts +539 -0
  6. package/dist/authoring.js +1759 -0
  7. package/dist/authoring.js.map +1 -0
  8. package/dist/canonical.cjs +552 -0
  9. package/dist/canonical.cjs.map +1 -0
  10. package/dist/canonical.d.cts +603 -0
  11. package/dist/canonical.d.ts +603 -0
  12. package/dist/canonical.js +532 -0
  13. package/dist/canonical.js.map +1 -0
  14. package/dist/cli.cjs +7843 -1815
  15. package/dist/cli.cjs.map +1 -1
  16. package/dist/cli.d.cts +8 -1
  17. package/dist/cli.d.ts +8 -1
  18. package/dist/cli.js +7854 -1828
  19. package/dist/cli.js.map +1 -1
  20. package/dist/client.cjs +120 -0
  21. package/dist/client.cjs.map +1 -1
  22. package/dist/client.d.cts +74 -2
  23. package/dist/client.d.ts +74 -2
  24. package/dist/client.js +116 -1
  25. package/dist/client.js.map +1 -1
  26. package/dist/compiler.cjs +3453 -0
  27. package/dist/compiler.cjs.map +1 -0
  28. package/dist/compiler.d.cts +389 -0
  29. package/dist/compiler.d.ts +389 -0
  30. package/dist/compiler.js +3396 -0
  31. package/dist/compiler.js.map +1 -0
  32. package/dist/drizzle.cjs +14 -0
  33. package/dist/drizzle.cjs.map +1 -0
  34. package/dist/drizzle.d.cts +1 -0
  35. package/dist/drizzle.d.ts +1 -0
  36. package/dist/drizzle.js +3 -0
  37. package/dist/drizzle.js.map +1 -0
  38. package/dist/dynamic-input.cjs +391 -0
  39. package/dist/dynamic-input.cjs.map +1 -0
  40. package/dist/dynamic-input.d.cts +111 -0
  41. package/dist/dynamic-input.d.ts +111 -0
  42. package/dist/dynamic-input.js +380 -0
  43. package/dist/dynamic-input.js.map +1 -0
  44. package/dist/index.cjs +3727 -344
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.d.cts +236 -59
  47. package/dist/index.d.ts +236 -59
  48. package/dist/index.js +3757 -482
  49. package/dist/index.js.map +1 -1
  50. package/dist/ir.cjs +642 -0
  51. package/dist/ir.cjs.map +1 -0
  52. package/dist/ir.d.cts +1119 -0
  53. package/dist/ir.d.ts +1119 -0
  54. package/dist/ir.js +623 -0
  55. package/dist/ir.js.map +1 -0
  56. package/dist/naming-CTvWSRTf.d.ts +79 -0
  57. package/dist/naming-DRyinU4u.d.cts +79 -0
  58. package/dist/predicate-v2.cjs +1093 -0
  59. package/dist/predicate-v2.cjs.map +1 -0
  60. package/dist/predicate-v2.d.cts +139 -0
  61. package/dist/predicate-v2.d.ts +139 -0
  62. package/dist/predicate-v2.js +1083 -0
  63. package/dist/predicate-v2.js.map +1 -0
  64. package/dist/sdl.cjs +1122 -0
  65. package/dist/sdl.cjs.map +1 -0
  66. package/dist/sdl.d.cts +94 -0
  67. package/dist/sdl.d.ts +94 -0
  68. package/dist/sdl.js +1098 -0
  69. package/dist/sdl.js.map +1 -0
  70. package/package.json +51 -3
  71. package/src/codegen-gql/apollo-hooks.cjs +98 -0
  72. package/src/codegen-gql/server-fns.cjs +101 -0
  73. package/templates/README.md +13 -0
  74. package/templates/orm-namespace/CLAUDE.md +82 -0
  75. package/templates/orm-namespace/codegen.ts +22 -0
  76. package/templates/orm-namespace/gitignore +5 -0
  77. package/templates/orm-namespace/graphql/example/queries.ts +56 -0
  78. package/templates/orm-namespace/package.json +24 -0
  79. package/templates/orm-namespace/schema/tables.ts +71 -0
  80. package/templates/orm-namespace/sequence.config.ts +32 -0
  81. package/templates/orm-namespace/tsconfig.json +15 -0
@@ -0,0 +1,539 @@
1
+ import { ColumnType, CanonicalColumn, CanonicalDefinition, CanonicalTable } from './canonical.js';
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';
5
+ import 'zod';
6
+
7
+ /**
8
+ * Fluent column builders for the v2 authoring surface — `t.uuid()`,
9
+ * `t.text().notNull().unique()`, `t.enum(status).default('open')`, …
10
+ *
11
+ * Builders carry plain serializable state and produce `CanonicalColumn` data
12
+ * (canonical definition v2). They never touch Drizzle: the server builds
13
+ * Drizzle entities from canonical JSON, consumer TypeScript never runs
14
+ * server-side (plan §2).
15
+ *
16
+ * Cross-copy safety: the jiti loader evaluates its own transpiled copy of
17
+ * this module, so identification uses the `kind` brand — never `instanceof`.
18
+ */
19
+
20
+ declare const COLUMN_BRAND: "seq-column";
21
+ declare const ENUM_BRAND: "seq-enum";
22
+ /** A namespace-level Postgres enum, created with `defineEnum` (table.ts). */
23
+ interface EnumRef {
24
+ readonly kind: typeof ENUM_BRAND;
25
+ readonly name: string;
26
+ readonly values: readonly string[];
27
+ }
28
+ declare function isEnumRef(value: unknown): value is EnumRef;
29
+ /** The allowlisted SQL default functions — `.default('now()')` maps here, not to a literal. */
30
+ declare const COLUMN_DEFAULT_FNS: readonly ["gen_random_uuid()", "now()"];
31
+ type ColumnDefaultFn = (typeof COLUMN_DEFAULT_FNS)[number];
32
+ type ColumnDefaultLiteral = string | number | boolean | null;
33
+ type ColumnTypeSpec = ColumnType | {
34
+ readonly enum: string;
35
+ };
36
+ /** `authorSub` → `author_sub`, `authorURLPath` → `author_url_path`. */
37
+ declare function deriveColumnName(propertyName: string): string;
38
+ declare class ColumnBuilder {
39
+ readonly kind: "seq-column";
40
+ private readonly state;
41
+ constructor(type: ColumnTypeSpec, columnName?: string);
42
+ /** Marks this column as (part of) the primary key. Implies NOT NULL. */
43
+ primaryKey(): this;
44
+ notNull(): this;
45
+ unique(): this;
46
+ /**
47
+ * Column default: a literal, or one of the allowlisted SQL functions
48
+ * (`'gen_random_uuid()'` / `'now()'`), which serialize as `defaultFn`.
49
+ */
50
+ default(value: ColumnDefaultLiteral): this;
51
+ description(text: string): this;
52
+ /** Migration rename hint: the previous Postgres column name. */
53
+ renamedFrom(previousColumnName: string): this;
54
+ /** Migration cast hint: the `USING` SQL applied when this column changes type. */
55
+ cast(usingSql: string): this;
56
+ /** Emits `@deprecated` in the generated SDL; the column stays queryable. */
57
+ deprecated(): this;
58
+ /** Whether `.primaryKey()` was called — collected into the table-level PK. */
59
+ get isPrimaryKey(): boolean;
60
+ /** The enum name when this is an enum column, else undefined. */
61
+ get enumName(): string | undefined;
62
+ /** Postgres column name: explicit override, else snake_case of the property name. */
63
+ columnNameFor(propertyName: string): string;
64
+ /** Serialize to a canonical v2 column. Validation happens in serializeNamespace. */
65
+ toCanonicalColumn(propertyName: string): CanonicalColumn;
66
+ }
67
+ declare function isColumnBuilder(value: unknown): value is ColumnBuilder;
68
+ /**
69
+ * The column-type factory. The optional argument overrides the derived
70
+ * snake_case Postgres column name: `t.text('legacy_name')`.
71
+ */
72
+ declare const t: {
73
+ readonly uuid: (columnName?: string) => ColumnBuilder;
74
+ readonly text: (columnName?: string) => ColumnBuilder;
75
+ readonly integer: (columnName?: string) => ColumnBuilder;
76
+ readonly bigint: (columnName?: string) => ColumnBuilder;
77
+ readonly numeric: (columnName?: string) => ColumnBuilder;
78
+ readonly double: (columnName?: string) => ColumnBuilder;
79
+ readonly boolean: (columnName?: string) => ColumnBuilder;
80
+ readonly timestamptz: (columnName?: string) => ColumnBuilder;
81
+ readonly date: (columnName?: string) => ColumnBuilder;
82
+ readonly jsonb: (columnName?: string) => ColumnBuilder;
83
+ readonly enum: (ref: EnumRef, columnName?: string) => ColumnBuilder;
84
+ };
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
+
258
+ declare const TABLE_BRAND: "seq-table";
259
+ declare const LINK_BRAND: "seq-link";
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;
264
+ type LinkKind = 'toOne' | 'toMany' | 'toPlatformUser';
265
+ interface SeqLink {
266
+ readonly kind: typeof LINK_BRAND;
267
+ readonly linkKind: LinkKind;
268
+ /** Absent for toPlatformUser — the platform-users view needs no target. */
269
+ readonly target: TableRef | undefined;
270
+ /** FK column (property or column name). toOne/toPlatformUser: on this table; toMany: on the target. */
271
+ readonly on: string;
272
+ readonly references: string | undefined;
273
+ readonly enforce: boolean;
274
+ readonly description: string | undefined;
275
+ }
276
+ interface ToOneOptions {
277
+ on: string;
278
+ references?: string;
279
+ /** Emit a real FK constraint (same-namespace toOne only). */
280
+ enforce?: boolean;
281
+ description?: string;
282
+ }
283
+ interface ToManyOptions {
284
+ on: string;
285
+ references?: string;
286
+ description?: string;
287
+ }
288
+ interface ToPlatformUserOptions {
289
+ /** Column on this table holding the platform user `sub` (or `references` override). */
290
+ on: string;
291
+ references?: string;
292
+ description?: string;
293
+ }
294
+ declare function toOne(target: TableRef, options: ToOneOptions): SeqLink;
295
+ declare function toMany(target: TableRef, options: ToManyOptions): SeqLink;
296
+ /** Link to the built-in read-only platform-users view (plan §4b) — no table definition needed. */
297
+ declare function toPlatformUser(options: ToPlatformUserOptions): SeqLink;
298
+ declare function isSeqLink(value: unknown): value is SeqLink;
299
+ interface PolicyVariantInput {
300
+ /** Claims-only guard: `capability('x')` / `role('y')` / claim comparisons. */
301
+ when: string;
302
+ /** Exactly one of `allow: true` or `policy` (validated at serialize time). */
303
+ allow?: true;
304
+ policy?: string;
305
+ }
306
+ interface PolicyWithVariantsInput {
307
+ default: string;
308
+ variants?: readonly PolicyVariantInput[];
309
+ }
310
+ /** A policy: a DSL source string, or a default + per-role/capability variants (§4c). */
311
+ type PolicyInput = string | PolicyWithVariantsInput;
312
+ interface TablePoliciesInput {
313
+ read?: PolicyInput;
314
+ /** Legacy single policy for every write command; use insert/update when they differ. */
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;
320
+ }
321
+ interface IndexInput {
322
+ /** Property names (camelCase) or Postgres column names. */
323
+ columns: readonly string[];
324
+ unique?: boolean;
325
+ name?: string;
326
+ }
327
+ interface TableConfig {
328
+ description?: string;
329
+ /** Table-level migration rename hint (new in v2). */
330
+ renamedFrom?: string;
331
+ /** Composite primary key: property names (or column names). Mutually exclusive with column-level `.primaryKey()`. */
332
+ primaryKey?: readonly string[];
333
+ indexes?: readonly IndexInput[];
334
+ links?: Record<string, SeqLink>;
335
+ policies?: TablePoliciesInput;
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[];
343
+ }
344
+ interface SeqTable<TColumns extends Record<string, ColumnBuilder> = Record<string, ColumnBuilder>> {
345
+ readonly kind: typeof TABLE_BRAND;
346
+ readonly tableName: string;
347
+ readonly columns: Readonly<TColumns>;
348
+ readonly config: TableConfig;
349
+ /** Synced reflected source (`gold.*`) — set only by defineSyncedTable. */
350
+ readonly source: string | undefined;
351
+ /** Consumer file that defined the table (set when loaded via loadNamespaceFromDir). */
352
+ readonly file: string | undefined;
353
+ }
354
+ declare function isSeqTable(value: unknown): value is SeqTable;
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
+ */
364
+ interface SyncedTableConfig {
365
+ /** Reflected read-only source, restricted to the gold layer: `gold.<table>`. */
366
+ source: string;
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;
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
+ */
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>;
385
+ declare function defineEnum(name: string, values: readonly string[]): EnumRef;
386
+
387
+ declare const NAMESPACE_CONFIG_BRAND: "seq-namespace-config";
388
+ interface NamespaceCapabilitiesInput {
389
+ /** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
390
+ roles?: unknown;
391
+ /** Org-level capability pins this namespace attaches to. */
392
+ uses?: readonly string[];
393
+ }
394
+ interface NamespaceConfigInput {
395
+ namespace: string;
396
+ description?: string;
397
+ capabilities?: NamespaceCapabilitiesInput;
398
+ }
399
+ interface SeqNamespaceConfig {
400
+ readonly kind: typeof NAMESPACE_CONFIG_BRAND;
401
+ readonly namespace: string;
402
+ readonly description: string | undefined;
403
+ readonly capabilities: NamespaceCapabilitiesInput;
404
+ readonly file: string | undefined;
405
+ }
406
+ declare function isSeqNamespaceConfig(value: unknown): value is SeqNamespaceConfig;
407
+ declare function defineNamespace(input: NamespaceConfigInput): SeqNamespaceConfig;
408
+ interface SerializeNamespaceInput {
409
+ config: SeqNamespaceConfig;
410
+ tables: readonly SeqTable[];
411
+ views?: readonly SeqView[];
412
+ enums?: readonly EnumRef[];
413
+ }
414
+ /**
415
+ * Serialize the authored namespace to a validated, normalized
416
+ * `CanonicalDefinition` (definition_format: 2). Throws `OrmDefinitionError`
417
+ * naming the table/file on any inconsistency.
418
+ */
419
+ declare function serializeNamespace(input: SerializeNamespaceInput): CanonicalDefinition;
420
+ /** sha256 over the v1 hash domain + key-sorted JSON of the normalized canonical definition. */
421
+ declare function computeCanonicalHash(definition: CanonicalDefinition): string;
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
+
490
+ declare const NAMESPACE_CONFIG_FILE = "sequence.config.ts";
491
+ declare const SCHEMA_DIR = "schema";
492
+ interface LoadNamespaceOptions {
493
+ /**
494
+ * Test/dev hook: absolute path that bare `'@sequenceholdings/orm'` imports
495
+ * in consumer files resolve to (jiti alias). Leave unset in production —
496
+ * the consumer's own installed package resolves naturally.
497
+ */
498
+ ormModulePath?: string;
499
+ }
500
+ interface LoadedNamespaceV2 {
501
+ readonly canonical: CanonicalDefinition;
502
+ readonly hash: string;
503
+ /** Relative paths of the files that were imported, config first. */
504
+ readonly files: readonly string[];
505
+ }
506
+ declare function loadNamespaceFromDir(dir: string, options?: LoadNamespaceOptions): Promise<LoadedNamespaceV2>;
507
+
508
+ /**
509
+ * Module-registry pattern for the authoring surface: `defineTable` /
510
+ * `defineView` / `defineEnum` / `defineNamespace` register into the ACTIVE collection
511
+ * context while `loadNamespaceFromDir` imports a consumer's files, so the
512
+ * loader collects definitions without inspecting module exports.
513
+ *
514
+ * The context stack lives on `globalThis` under a `Symbol.for` key — NOT in
515
+ * module scope — because the jiti loader evaluates its own transpiled copy of
516
+ * this module when a consumer file imports '@sequenceholdings/orm'. Both
517
+ * copies must observe the same registrations (the graphql-js dual-package
518
+ * discipline), so everything registered is plain data identified by `kind`
519
+ * brand strings, never `instanceof`.
520
+ */
521
+ interface AuthoringRegistration {
522
+ readonly value: unknown;
523
+ readonly file: string | undefined;
524
+ }
525
+ interface AuthoringContext {
526
+ /** Set by the loader before importing each consumer file — error attribution. */
527
+ currentFile: string | undefined;
528
+ readonly tables: AuthoringRegistration[];
529
+ readonly views: AuthoringRegistration[];
530
+ readonly enums: AuthoringRegistration[];
531
+ readonly configs: AuthoringRegistration[];
532
+ }
533
+ /** Push a fresh collection context; every define* call registers into it until ended. */
534
+ declare function beginAuthoringContext(): AuthoringContext;
535
+ /** Pop the context; throws if collection begin/end calls are mismatched (programmer error). */
536
+ declare function endAuthoringContext(context: AuthoringContext): void;
537
+ declare function activeAuthoringContext(): AuthoringContext | undefined;
538
+
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 };