@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
package/dist/index.d.ts CHANGED
@@ -1,61 +1,15 @@
1
+ export { AuthoringContext, AuthoringRegistration, COLUMN_BRAND, COLUMN_DEFAULT_FNS, ColumnBuilder, ColumnDefaultFn, ColumnDefaultLiteral, ColumnTypeSpec, CowMutationInput, DrizzleRelation, ENUM_BRAND, EnumRef, IndexInput, LINK_BRAND, LinkKind, LoadNamespaceOptions, LoadedNamespaceV2, NAMESPACE_CONFIG_BRAND, NAMESPACE_CONFIG_FILE, NamespaceCapabilitiesInput, NamespaceConfigInput, ORM_TO_PIPELINE_TYPE, OrmContractColumnMap, OrmContractPipelineColumn, OrmSyncedTableContract, OrmToPipelineType, OverlayTableRef, OverlayWinsUnionInput, OverrideRowMutationInput, PolicyInput, PolicyVariantInput, PolicyWithVariantsInput, RelationRef, RevertOverlayMutationInput, SCHEMA_DIR, SYNCED_CONTRACT_HASH_DOMAIN, SeqLink, SeqNamespaceConfig, SeqTable, SeqView, SerializeNamespaceInput, SyncedTableConfig, SyncedTablePoliciesInput, TABLE_BRAND, TableConfig, TablePoliciesInput, TableRef, ToManyOptions, ToOneOptions, ToPlatformUserOptions, TypedSyncedTableConfig, VIEW_BRAND, ViewConfig, ViewPoliciesInput, ViewQueryContext, 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 } from './authoring.js';
2
+ import { CanonicalDefinition } from './canonical.js';
3
+ export { CANONICAL_FORMAT, CanonicalColumn, CanonicalEnum, CanonicalLink, CanonicalTable, CanonicalView, IDENTIFIER_RE, PolicyExpression, canonicalActionSchema, canonicalColumnSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalRelations, canonicalTableSchema, canonicalViewSchema, normalizeCanonical, policyExpressionSchema, policyVariantSchema } from './canonical.js';
4
+ import { CustomRolesBlock } from '@sequenceholdings/custom-roles-manifest';
5
+ export { CustomRolesBlock, capabilityPinsSchema, customRolesBlockSchema, customRolesDeclared, parseCapabilityPin, validateCapabilityPins } from '@sequenceholdings/custom-roles-manifest';
1
6
  import { z } from 'zod';
7
+ import { PredIr } from './ir.js';
8
+ export { CLAIMS_CONTRACT, CMP_OPS, ClaimKey, CmpOp, CompiledArtifact, CompiledOperation, INPUT_REF_KINDS, IR_VERSION, InputRefKind, IrVersionError, LimitIr, OrderIr, RootIr, SelectionIr, TableMetaIr, ValueIr, VariableDefaultIr, VariableIr, compiledArtifactSchema, compiledOperationSchema, indexByHash, limitIrSchema, normalizeIr, orderIrSchema, predIrSchema, rootIrSchema, selectionIrSchema, tableMetaIrSchema, valueIrSchema, variableDefaultIrSchema, variableIrSchema } from './ir.js';
2
9
  import { generateDrizzleJson } from 'drizzle-kit/api';
3
10
  import { PgTableWithColumns } from 'drizzle-orm/pg-core';
4
-
5
- /**
6
- * Custom Roles & Capabilities manifest grammar — the `capabilities.roles`
7
- * block and the `capabilities.uses` pin set. This is a VERBATIM mirror of the
8
- * platform's canonical grammar so an ORM namespace declares roles/capabilities
9
- * the exact same way an artifact or managed function does; apply feeds it to
10
- * the shared `reconcileHostRegistryOnActivation` reconciler untouched.
11
- *
12
- * Canonical sources — keep the grammar in sync by hand (schema shape, key
13
- * regexes, limits, and superRefine rules). The behavioral guards in
14
- * definitions.test.ts exercise this copy (inherit cycle, unknown grant,
15
- * pin-names-role, key collision) so a drifted rule fails there:
16
- * atlas/src/server/services/custom-roles/manifest-block.ts (server)
17
- * shared/services/artifact-studio/src/manifest-custom-roles.ts (CLI)
18
- */
19
-
20
- /**
21
- * Manifest-declared custom roles & capabilities. Roles and capabilities are
22
- * both `custom_role` FGA objects; deploy reconciliation turns this block into
23
- * the structural waterfall edges (role→capability / senior→junior `assignee`
24
- * userset tuples) — nothing else. The host floor is enforced app-layer at the
25
- * resolution points, never in the model. Runtime grants (user/group/org →
26
- * role) are NEVER declared here — they are written through host-admin-gated
27
- * endpoints.
28
- */
29
- declare const customRolesBlockSchema: z.ZodObject<{
30
- definitions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
31
- description: z.ZodOptional<z.ZodString>;
32
- default: z.ZodDefault<z.ZodBoolean>;
33
- inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
34
- grants: z.ZodDefault<z.ZodArray<z.ZodString>>;
35
- }, z.core.$strip>>>;
36
- capabilities: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
37
- description: z.ZodOptional<z.ZodString>;
38
- }, z.core.$strip>>>;
39
- }, z.core.$strip>;
40
- type CustomRolesBlock = z.infer<typeof customRolesBlockSchema>;
41
- /** True when the block declares at least one role or capability. */
42
- declare function customRolesDeclared(block: CustomRolesBlock | null | undefined): boolean;
43
- declare const capabilityPinsSchema: z.ZodDefault<z.ZodArray<z.ZodString>>;
44
- interface ParsedCapabilityPin {
45
- scope: 'org' | 'host';
46
- key: string;
47
- }
48
- /** Split a pin into its scope and key. Assumes the pin grammar validated. */
49
- declare function parseCapabilityPin(pin: string): ParsedCapabilityPin;
50
- /**
51
- * Cross-field pin validation (the `uses` array and the roles block are
52
- * siblings under `capabilities`). Purely structural — registry existence
53
- * checks are server-side, at activation, where atomicity lives.
54
- */
55
- declare function validateCapabilityPins({ uses, roles, }: {
56
- uses: readonly string[];
57
- roles: CustomRolesBlock | null | undefined;
58
- }): string[];
11
+ import 'drizzle-orm';
12
+ import 'drizzle-orm/query-builders/query-builder';
59
13
 
60
14
  /**
61
15
  * The reserved `namespace.yaml` — namespace-level settings beside the table
@@ -148,8 +102,8 @@ declare const actionSchema: z.ZodObject<{
148
102
  }>>>;
149
103
  audit: z.ZodOptional<z.ZodObject<{
150
104
  action: z.ZodEnum<{
151
- create: "create";
152
105
  update: "update";
106
+ create: "create";
153
107
  delete: "delete";
154
108
  }>;
155
109
  resource: z.ZodOptional<z.ZodString>;
@@ -295,6 +249,8 @@ declare const tableFileSchema: z.ZodObject<{
295
249
  policies: z.ZodOptional<z.ZodObject<{
296
250
  read: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
297
251
  write: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
252
+ insert: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
253
+ update: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
298
254
  }, z.core.$strict>>;
299
255
  actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
300
256
  description: z.ZodOptional<z.ZodString>;
@@ -331,8 +287,8 @@ declare const tableFileSchema: z.ZodObject<{
331
287
  }>>>;
332
288
  audit: z.ZodOptional<z.ZodObject<{
333
289
  action: z.ZodEnum<{
334
- create: "create";
335
290
  update: "update";
291
+ create: "create";
336
292
  delete: "delete";
337
293
  }>;
338
294
  resource: z.ZodOptional<z.ZodString>;
@@ -396,6 +352,24 @@ declare function compileActionStatements(action: ActionDefinition, renderParam?:
396
352
  /** Compiled `requires` gate — a SQL boolean over the transaction claims, or null when unguarded. */
397
353
  declare function compileActionRequires(action: ActionDefinition): string | null;
398
354
 
355
+ /** Canonical column types can be enums — v1 `PredicateColumnTypes` cannot carry them. */
356
+ type SyncedColumnType = ColumnType | {
357
+ readonly enum: string;
358
+ };
359
+ type SyncedPredicateColumnTypes = Readonly<Record<string, SyncedColumnType>>;
360
+ interface CompilePredIrToSqlOptions {
361
+ /** Column name → declared type, for claim casts in comparisons. */
362
+ readonly columnTypes?: SyncedPredicateColumnTypes;
363
+ /** Logical column name → physical column name for the synced backing. */
364
+ readonly columnNames?: Readonly<Record<string, string>>;
365
+ }
366
+ /**
367
+ * PredIr → a static SQL boolean for synced-view WHERE clauses. Capability and
368
+ * role leaves stay as runtime claim checks (mirroring table RLS), unlike the
369
+ * data-plane executor which pre-resolves them per caller.
370
+ */
371
+ declare function compilePredIrToSql(pred: PredIr, options?: CompilePredIrToSqlOptions): string;
372
+
399
373
  declare const COMPARE_OPS: readonly ["=", "!=", "<", "<=", ">", ">="];
400
374
  type CompareOp = (typeof COMPARE_OPS)[number];
401
375
  type Operand = {
@@ -444,11 +418,15 @@ declare function compilePredicate(predicate: Predicate, columnTypes?: PredicateC
444
418
  declare const CLAIMS_SETTING = "request.jwt.claims";
445
419
  /** Claims JSON key holding the caller's granted capability pins (a string array). */
446
420
  declare const CAPABILITIES_CLAIM_KEY = "capabilities";
421
+ /** Claims JSON key holding the caller's granted custom roles (a string array). */
422
+ declare const ROLES_CLAIM_KEY = "roles";
447
423
  declare const quoteIdentifier: (name: string) => string;
448
424
  declare const quoteLiteral: (value: string) => string;
449
425
  declare const claimExpression: (key: string) => string;
450
426
  /** NULL claims (or a missing capabilities array) coalesce to false — capability checks fail closed. */
451
427
  declare const capabilityExpression: (key: string) => string;
428
+ /** NULL claims (or a missing roles array) coalesce to false — role checks fail closed. */
429
+ declare const roleExpression: (key: string) => string;
452
430
 
453
431
  /** Namespace names become Postgres identifiers (`orm_<ns>` schema, `orm_<ns>_consumer` role) — the tight grammar is a security control, not cosmetics. */
454
432
  declare const NAMESPACE_PATTERN: RegExp;
@@ -543,6 +521,7 @@ declare function applyMigrationHints(previous: NamespaceSnapshot, definition: Na
543
521
  * pending statement and lets a non-converged schema pass.
544
522
  */
545
523
  declare function isOwnedStatement(statement: string): boolean;
524
+ declare function isOwnedStatementV2(statement: string): boolean;
546
525
  /**
547
526
  * The kit-owned statements a live database would still need to match the
548
527
  * definition — drizzle-kit's `pushSchema` introspection diffed against the
@@ -555,6 +534,12 @@ declare function pendingKitStatements({ definition, db, }: {
555
534
  /** A drizzle PgDatabase over the target — typed loose because pushSchema's own parameter is `PgDatabase<any>`. */
556
535
  db: unknown;
557
536
  }): Promise<string[]>;
537
+ /** V2 convergence includes managed regular views in drizzle-kit's verdict. */
538
+ declare function pendingKitStatementsV2({ canonical, db, }: {
539
+ canonical: CanonicalDefinition;
540
+ /** A drizzle PgDatabase over the target — typed loose because pushSchema's own parameter is `PgDatabase<any>`. */
541
+ db: unknown;
542
+ }): Promise<string[]>;
558
543
 
559
544
  interface DrizzleEntities {
560
545
  /** The in-memory schema bag drizzle-kit snapshots (`generateDrizzleJson(imports)`). */
@@ -618,10 +603,68 @@ declare function actionPrepareChecks(definition: NamespaceDefinition): string[];
618
603
  * write-capable callers SELECT rows the read policy hides.
619
604
  */
620
605
  declare function securityStatements(definition: NamespaceDefinition): string[];
606
+ declare const syncedTables: (definition: NamespaceDefinition) => TableFile[];
607
+ /**
608
+ * A resolved synced-table backing: the physical Lakebase relation name
609
+ * (captured at provision, never derived) plus optional projection column
610
+ * types for claim-cast compilation.
611
+ */
612
+ interface SyncedBacking {
613
+ readonly table: string;
614
+ /** Physical Lakebase relation (e.g. `synced_loans` or `df_retail_customers`). */
615
+ readonly physicalRelation: string;
616
+ /** Column name → ORM column type, for claim casts in the view's WHERE. */
617
+ readonly columnTypes?: PredicateColumnTypes;
618
+ }
619
+ /**
620
+ * Emit CREATE OR REPLACE VIEW + SELECT-only grants for synced tables that have
621
+ * a registered backing. Synced tables cannot use table-level RLS (they may be
622
+ * foreign tables), so claims filtering compiles into the view's WHERE clause.
623
+ *
624
+ * Each view lives in `orm_<ns>` alongside regular tables, named identically to
625
+ * the synced table definition so read routing is transparent.
626
+ */
627
+ /**
628
+ * Atlas reassigns every relation in `orm_<ns>` to this role after apply.
629
+ * Synced views resolve backing access as their owner, so the emitter must
630
+ * grant this role narrow SELECT on each physical relation before CREATE VIEW.
631
+ */
632
+ declare const SYNCED_VIEW_EXECUTION_OWNER_ROLE = "orm_exec";
633
+ declare function syncedViewStatements({ definition, backings, readPolicyIrByTable, columnNamesByTable, columnTypesByTable, executionOwnerRole, }: {
634
+ definition: NamespaceDefinition;
635
+ backings: readonly SyncedBacking[];
636
+ /** v2 compiled read policies (preserves capability/role variants). */
637
+ readPolicyIrByTable?: ReadonlyMap<string, PredIr>;
638
+ /** Logical column name → physical backing column name per synced table. */
639
+ columnNamesByTable?: ReadonlyMap<string, Readonly<Record<string, string>>>;
640
+ /**
641
+ * Canonical declared types per synced table (keyed by logical AND physical
642
+ * name). Carries what the TableFile adapter cannot — enum types — so IN/NIN
643
+ * policies never silently downgrade an enum comparison to text[]-vs-enum.
644
+ */
645
+ columnTypesByTable?: ReadonlyMap<string, SyncedPredicateColumnTypes>;
646
+ /** Role that will own the view after ensureExecutionOwner (default orm_exec). */
647
+ executionOwnerRole?: string;
648
+ }): string[];
649
+ /**
650
+ * Drop synced views — idempotent cleanup for apply retries and removal.
651
+ */
652
+ declare function syncedViewDropStatements({ schemaName, tables, }: {
653
+ schemaName: string;
654
+ tables: readonly string[];
655
+ }): string[];
656
+ /**
657
+ * Revoke orm_exec backing privileges for physical relations that are no longer
658
+ * active for this namespace (removed / renamed / rebound away).
659
+ */
660
+ declare function syncedBackingRevokeStatements({ backings, executionOwnerRole, }: {
661
+ backings: readonly SyncedBacking[];
662
+ executionOwnerRole?: string;
663
+ }): string[];
621
664
 
622
665
  declare const sqlTypeName: (type: ColumnType) => string;
623
666
 
624
- declare const STATEMENT_KINDS: readonly ["hint", "ddl", "security", "function"];
667
+ declare const STATEMENT_KINDS: readonly ["hint", "ddl", "security", "function", "synced_view"];
625
668
  type StatementKind = (typeof STATEMENT_KINDS)[number];
626
669
  interface CompiledStatement {
627
670
  readonly kind: StatementKind;
@@ -649,6 +692,64 @@ declare function planMigration({ definition, previousSnapshot, }: {
649
692
  /** Full-create plan (empty previous snapshot) — what `plan` prints and first apply runs. */
650
693
  declare const compileNamespace: (definition: NamespaceDefinition) => Promise<PlannedMigration>;
651
694
 
695
+ /**
696
+ * Canonical v2 → the in-memory schema bag drizzle-kit snapshots plus typed
697
+ * table handles — the same `DrizzleEntities` shape engine/snapshot.ts consumes.
698
+ */
699
+ declare function buildDrizzleEntitiesV2(definition: CanonicalDefinition): DrizzleEntities;
700
+ declare function rewriteSyncedSourceRelationsInViewQuery({ query, canonical, schemaName, dependencies, }: {
701
+ query: string;
702
+ canonical: CanonicalDefinition;
703
+ schemaName: string;
704
+ /** The view's declared logical dependencies — disambiguates shared sources. */
705
+ dependencies?: readonly string[];
706
+ }): string;
707
+ /** drizzle-kit snapshot for a canonical definition — the v2 twin of engine/snapshot.ts generateSnapshot. */
708
+ declare function generateSnapshotV2(definition: CanonicalDefinition, previousId?: string): NamespaceSnapshot;
709
+ /**
710
+ * Renames and casts are declared in the canonical definition, never inferred:
711
+ * we emit the statement ourselves and rewrite the previous snapshot to match,
712
+ * so drizzle-kit never faces a create+drop ambiguity (its API resolves those
713
+ * interactively — fatal in a service). Semantics mirror engine/snapshot.ts
714
+ * applyMigrationHints exactly, plus the v2-only table-level `renamedFrom`
715
+ * (applied FIRST, so column hints find the table under its new name).
716
+ *
717
+ * This is a sibling of the v1 function rather than a wrapper: the v1 one is
718
+ * keyed to `NamespaceDefinition`'s record-shaped columns and cannot express
719
+ * table renames or enum-typed cast targets.
720
+ */
721
+ declare function applyMigrationHintsV2(previous: NamespaceSnapshot, definition: CanonicalDefinition): MigrationHints;
722
+ /**
723
+ * Desired canonical definition + the previously applied snapshot → ordered
724
+ * statements. The v2 twin of engine/index.ts planMigration, reusing its
725
+ * exported internals (normalizeSnapshot/emptySnapshot/diffStatements — the
726
+ * assertUnambiguousDiff backstop rides along inside diffStatements).
727
+ *
728
+ * Deliberately absent relative to v1: policy drops, securityStatements, and
729
+ * action function statements. v2 enforces row policies inside compiled
730
+ * operations (no PG RLS policies) and executes actions on the data plane
731
+ * (no plpgsql functions), so a v2 plan is hints + kit DDL only.
732
+ */
733
+ declare function planMigrationV2({ canonical, previousSnapshot, }: {
734
+ canonical: CanonicalDefinition;
735
+ previousSnapshot?: NamespaceSnapshot;
736
+ }): Promise<PlannedMigration>;
737
+ /**
738
+ * Drizzle's manual-view snapshot stores declared columns, but PostgreSQL names
739
+ * and types the live view from the SELECT itself. Assert the live catalog in
740
+ * the same transaction so a stale alias/type or an incomplete dependency
741
+ * declaration can never be persisted as a successful schema version.
742
+ */
743
+ /**
744
+ * Assert live view columns/types/dependencies match the canonical contract.
745
+ * Used by planMigrationV2 and by CASCADE recovery recreates (same transaction).
746
+ */
747
+ declare function validateViewCatalogStatement({ canonical, view, schema, }: {
748
+ canonical: CanonicalDefinition;
749
+ view: NonNullable<CanonicalDefinition['views']>[number];
750
+ schema: string;
751
+ }): string;
752
+
652
753
  declare class OrmDefinitionError extends Error {
653
754
  readonly file?: string | undefined;
654
755
  readonly name = "OrmDefinitionError";
@@ -818,6 +919,82 @@ declare function writeMigration({ dir, workspace, plan, contentHash, destructive
818
919
  destructive: boolean;
819
920
  }): Promise<WrittenMigration>;
820
921
 
922
+ /**
923
+ * v1 YAML `NamespaceDefinition` → canonical v2 (`orm migrate-from-yaml`).
924
+ * Lossless where the v2 contract can express it, loud where it can't:
925
+ *
926
+ * - columns keep declaration order (order is meaningful for DDL); the v1
927
+ * `default` splits into literal `default` vs allowlisted `defaultFn`
928
+ * exactly along the isFunctionDefault line the v1 engine used;
929
+ * - the single v1 `primary_key: true` column becomes `primaryKey: [name]`;
930
+ * - policy expressions carry over as their verbatim DSL source strings
931
+ * (re-parsed by the v2 predicate compiler, never the parsed v1 AST);
932
+ * - v1 actions are DROPPED, loudly: v2 has no action surface — writes are
933
+ * persisted mutations — and the v1→v2 apply sweep removes the `action_*`
934
+ * functions anyway. The emitter leaves a TODO listing each dropped action
935
+ * so it gets re-authored as a mutation (or a CoW `overrideRowMutation`);
936
+ * - the capabilities block passes through untouched (verbatim custom-roles
937
+ * grammar in both formats);
938
+ * - qualified (cross-namespace) link targets have no v2 representation —
939
+ * links are namespace-local in v2 (plan §5) — so they fail the conversion
940
+ * rather than silently dropping.
941
+ *
942
+ * The result re-validates through canonicalDefinitionSchema and normalizes,
943
+ * so hashing and server-side re-validation see exactly what an authored v2
944
+ * definition would produce.
945
+ */
946
+ declare function convertV1DefinitionToCanonical(definition: NamespaceDefinition): CanonicalDefinition;
947
+
948
+ /** Statement kinds that disqualify a plan from being a rebase no-op. */
949
+ interface RebaseNoopOptions {
950
+ /**
951
+ * v1 planned a drop-and-recreate of the RLS policies on every migration, so
952
+ * a plan produced by the V1 PIPELINE against an unchanged schema still
953
+ * carries `security` statements. v2 plans never emit them. Default false:
954
+ * a rebase verified through planMigrationV2 must be empty outright.
955
+ */
956
+ readonly allowSecurityReemission?: boolean;
957
+ }
958
+ /** The statements that stop a plan from qualifying as a rebase no-op. */
959
+ declare function rebaseViolations(statements: readonly CompiledStatement[], options?: RebaseNoopOptions): CompiledStatement[];
960
+ /**
961
+ * True when the plan changes nothing: no DDL, no hint (rename/cast) ALTERs,
962
+ * no action functions — and, unless explicitly allowed, no security
963
+ * re-emission either. Pure predicate over the plan's statements.
964
+ */
965
+ declare const verifyRebaseIsNoop: (plan: Pick<PlannedMigration, "statements">, options?: RebaseNoopOptions) => boolean;
966
+ interface RebaseEntryInput {
967
+ readonly namespace: string;
968
+ /** Content hash at the committed journal tip (the v1 hash being rebased from). */
969
+ readonly previousHash: string;
970
+ /** Content hash of the converted canonical v2 definition. */
971
+ readonly newHash: string;
972
+ /** Journal tip ordinal + 1. A rebase always sits on an existing tip. */
973
+ readonly ordinal: number;
974
+ /**
975
+ * The verified no-op plan's snapshot. Structurally identical to the tip
976
+ * snapshot but re-chained (fresh `id`, `prevId` = tip snapshot's id) so the
977
+ * `--check` snapshot-chain walk stays unbroken through the rebase.
978
+ */
979
+ readonly snapshot: NamespaceSnapshot;
980
+ }
981
+ interface RebaseEntry {
982
+ readonly name: string;
983
+ /** Journal entry matching workspace.ts's journalEntrySchema exactly. */
984
+ readonly entry: JournalEntry;
985
+ /** `migrations/<name>.sql` contents — header only, zero statements. */
986
+ readonly sql: string;
987
+ /** `migrations/meta/NNNN.snapshot.json` contents (writeMigration's serialization). */
988
+ readonly snapshotText: string;
989
+ }
990
+ /**
991
+ * Build the no-op journal entry (+ the exact file contents its checksums
992
+ * commit to) recording a v1 → v2 content-hash rebase. Everything is
993
+ * deterministic from the inputs, so `--check`-style gates can regenerate and
994
+ * byte-compare it just like ordinary migrations.
995
+ */
996
+ declare function buildRebaseJournalEntry({ namespace, previousHash, newHash, ordinal, snapshot }: RebaseEntryInput): RebaseEntry;
997
+
821
998
  declare function parsePredicate(source: string): ParsedPredicate;
822
999
 
823
1000
  declare const identifierSchema: z.ZodString;
@@ -836,4 +1013,4 @@ declare function parseCanonicalDefinition(value: unknown): NamespaceDefinition;
836
1013
 
837
1014
  declare const parsedPredicateSchema: z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>;
838
1015
 
839
- export { ACTION_REQUIRES_DENIED_SQLSTATE, ACTION_VALIDATES_FAILED_SQLSTATE, AUDIT_ACTIONS, type ActionDefinition, CAPABILITIES_CLAIM_KEY, CAPABILITY_KEY_PATTERN, CLAIMS_SETTING, CLAIM_KEY_PATTERN, COLUMN_TYPES, COMPARE_OPS, CONSUMER_ROLE_SUFFIX, type ColumnDefault, type ColumnDefinition, type ColumnType, type CommittedChainEntry, type CommittedMigration, type CompareOp, type CompiledStatement, type CustomRolesBlock, DEFINITION_FILE_EXTENSIONS, type DefinitionFile, type DefinitionSource, type DestructiveStatement, type DiffOptions, type DrizzleEntities, HASH_DOMAIN, IDENTIFIER_PATTERN, type IndexDefinition, type JournalEntry, type LinkDefinition, type LoadedNamespace, MAX_DEFINITION_FILE_BYTES, MAX_IDENTIFIER_LENGTH, MIGRATIONS_DIRNAME, type MigrationJournal, type MigrationWorkspace, NAMESPACE_CONFIG_FILENAMES, NAMESPACE_PATTERN, type NamespaceCapabilities, type NamespaceConfig, type NamespaceDefinition, type NamespaceSnapshot, ORM_DATA_TOKEN_HEADER, ORM_SCHEMA_PREFIX, ORM_SERVICE_DATA_TOKEN_HEADER, type Operand, OrmDefinitionError, type ParsedPredicate, type PlannedMigration, type Predicate, PredicateParseError, QUALIFIED_TABLE_PATTERN, RESERVED_COLUMN_NAMES, RESERVED_TABLE_NAMES, STATEMENT_KINDS, SYNCED_SOURCE_PATTERN, type StatementKind, type TableFile, type ValidatesEntry, type WrittenMigration, actionFunctionName, actionFunctionStatements, actionParamArg, actionParamOrder, actionParamSchema, actionPrepareChecks, actionSchema, actionWriteTargets, actionsInterfaceName, applyMigrationHints, buildActionParamsSchema, buildDrizzleEntities, buildNamespaceDefinition, canonicalizeDefinition, capabilityExpression, capabilityPinsSchema, castParts, checksumOf, claimExpression, classifyDestructive, columnSchema, columnTypeSchema, compileActionRequires, compileActionStatements, compileNamespace, compilePredicate, computeDefinitionHash, consumerRoleName, customRolesBlockSchema, customRolesDeclared, declaredCapabilityKeys, diffCommand, diffStatements, emptyJournal, emptySnapshot, extractNamedParams, generateNamespaceTypes, generateSnapshot, identifierSchema, isFunctionDefault, isOwnedStatement, isQualifiedReference, loadCommittedMigrations, loadCommittedTipMigration, loadNamespaceDefinition, migrationName, namespaceConfigSchema, namespaceSchema, normalizeSnapshot, ormSchemaName, parseCanonicalDefinition, parseCapabilityPin, parseDefinitionSources, parsePredicate, parseTableFile, parsedPredicateSchema, pendingKitStatements, planMigration, predicateOperands, quoteIdentifier, quoteLiteral, readMigrationSql, readMigrationWorkspace, readSnapshot, referencedCapabilities, referencedColumns, renderMigrationSql, securityStatements, sqlTypeName, stableJson, tableFileSchema, tableReferenceSchema, typesInterfaceName, validateCapabilityPins, walkPredicate, writeMigration };
1016
+ export { ACTION_REQUIRES_DENIED_SQLSTATE, ACTION_VALIDATES_FAILED_SQLSTATE, AUDIT_ACTIONS, type ActionDefinition, CAPABILITIES_CLAIM_KEY, CAPABILITY_KEY_PATTERN, CLAIMS_SETTING, CLAIM_KEY_PATTERN, COLUMN_TYPES, COMPARE_OPS, CONSUMER_ROLE_SUFFIX, CanonicalDefinition, type ColumnDefault, type ColumnDefinition, type ColumnType, type CommittedChainEntry, type CommittedMigration, type CompareOp, type CompilePredIrToSqlOptions, type CompiledStatement, DEFINITION_FILE_EXTENSIONS, type DefinitionFile, type DefinitionSource, type DestructiveStatement, type DiffOptions, type DrizzleEntities, HASH_DOMAIN, IDENTIFIER_PATTERN, type IndexDefinition, type JournalEntry, type LinkDefinition, type LoadedNamespace, MAX_DEFINITION_FILE_BYTES, MAX_IDENTIFIER_LENGTH, MIGRATIONS_DIRNAME, type MigrationJournal, type MigrationWorkspace, NAMESPACE_CONFIG_FILENAMES, NAMESPACE_PATTERN, type NamespaceCapabilities, type NamespaceConfig, type NamespaceDefinition, type NamespaceSnapshot, ORM_DATA_TOKEN_HEADER, ORM_SCHEMA_PREFIX, ORM_SERVICE_DATA_TOKEN_HEADER, type Operand, OrmDefinitionError, type ParsedPredicate, type PlannedMigration, PredIr, type Predicate, type PredicateColumnTypes, PredicateParseError, QUALIFIED_TABLE_PATTERN, RESERVED_COLUMN_NAMES, RESERVED_TABLE_NAMES, ROLES_CLAIM_KEY, type RebaseEntry, type RebaseEntryInput, type RebaseNoopOptions, STATEMENT_KINDS, SYNCED_SOURCE_PATTERN, SYNCED_VIEW_EXECUTION_OWNER_ROLE, type StatementKind, type SyncedBacking, type SyncedColumnType, type SyncedPredicateColumnTypes, type TableFile, type ValidatesEntry, type WrittenMigration, actionFunctionName, actionFunctionStatements, actionParamArg, actionParamOrder, actionParamSchema, actionPrepareChecks, actionSchema, actionWriteTargets, actionsInterfaceName, applyMigrationHints, applyMigrationHintsV2, buildActionParamsSchema, buildDrizzleEntities, buildDrizzleEntitiesV2, buildNamespaceDefinition, buildRebaseJournalEntry, canonicalizeDefinition, capabilityExpression, castParts, checksumOf, claimExpression, classifyDestructive, columnSchema, columnTypeSchema, compileActionRequires, compileActionStatements, compileNamespace, compilePredIrToSql, compilePredicate, computeDefinitionHash, consumerRoleName, convertV1DefinitionToCanonical, declaredCapabilityKeys, diffCommand, diffStatements, emptyJournal, emptySnapshot, extractNamedParams, generateNamespaceTypes, generateSnapshot, generateSnapshotV2, identifierSchema, isFunctionDefault, isOwnedStatement, isOwnedStatementV2, isQualifiedReference, loadCommittedMigrations, loadCommittedTipMigration, loadNamespaceDefinition, migrationName, namespaceConfigSchema, namespaceSchema, normalizeSnapshot, ormSchemaName, parseCanonicalDefinition, parseDefinitionSources, parsePredicate, parseTableFile, parsedPredicateSchema, pendingKitStatements, pendingKitStatementsV2, planMigration, planMigrationV2, predicateOperands, quoteIdentifier, quoteLiteral, readMigrationSql, readMigrationWorkspace, readSnapshot, rebaseViolations, referencedCapabilities, referencedColumns, renderMigrationSql, rewriteSyncedSourceRelationsInViewQuery, roleExpression, securityStatements, sqlTypeName, stableJson, syncedBackingRevokeStatements, syncedTables, syncedViewDropStatements, syncedViewStatements, tableFileSchema, tableReferenceSchema, typesInterfaceName, validateViewCatalogStatement, verifyRebaseIsNoop, walkPredicate, writeMigration };