@sequenceholdings/orm 0.1.1 → 0.1.2
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 +1 -1
- package/dist/authoring.cjs +794 -0
- package/dist/authoring.cjs.map +1 -0
- package/dist/authoring.d.cts +274 -0
- package/dist/authoring.d.ts +274 -0
- package/dist/authoring.js +763 -0
- package/dist/authoring.js.map +1 -0
- package/dist/canonical.cjs +146 -0
- package/dist/canonical.cjs.map +1 -0
- package/dist/canonical.d.cts +369 -0
- package/dist/canonical.d.ts +369 -0
- package/dist/canonical.js +131 -0
- package/dist/canonical.js.map +1 -0
- package/dist/cli.cjs +6172 -1683
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +8 -1
- package/dist/cli.d.ts +8 -1
- package/dist/cli.js +6172 -1685
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +120 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +74 -2
- package/dist/client.d.ts +74 -2
- package/dist/client.js +116 -1
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +3001 -0
- package/dist/compiler.cjs.map +1 -0
- package/dist/compiler.d.cts +581 -0
- package/dist/compiler.d.ts +581 -0
- package/dist/compiler.js +2947 -0
- package/dist/compiler.js.map +1 -0
- package/dist/index.cjs +1705 -326
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -56
- package/dist/index.d.ts +117 -56
- package/dist/index.js +1619 -323
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +407 -0
- package/dist/ir.cjs.map +1 -0
- package/dist/ir.d.cts +1179 -0
- package/dist/ir.d.ts +1179 -0
- package/dist/ir.js +388 -0
- package/dist/ir.js.map +1 -0
- package/dist/naming-CTvWSRTf.d.ts +79 -0
- package/dist/naming-DRyinU4u.d.cts +79 -0
- package/dist/sdl.cjs +833 -0
- package/dist/sdl.cjs.map +1 -0
- package/dist/sdl.d.cts +96 -0
- package/dist/sdl.d.ts +96 -0
- package/dist/sdl.js +809 -0
- package/dist/sdl.js.map +1 -0
- package/package.json +36 -3
- package/src/codegen-gql/apollo-hooks.cjs +98 -0
- package/src/codegen-gql/server-fns.cjs +101 -0
- package/templates/README.md +13 -0
- package/templates/orm-namespace/CLAUDE.md +81 -0
- package/templates/orm-namespace/codegen.ts +22 -0
- package/templates/orm-namespace/gitignore +5 -0
- package/templates/orm-namespace/graphql/example/queries.ts +56 -0
- package/templates/orm-namespace/package.json +24 -0
- package/templates/orm-namespace/schema/tables.ts +71 -0
- package/templates/orm-namespace/sequence.config.ts +32 -0
- package/templates/orm-namespace/tsconfig.json +15 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,61 +1,12 @@
|
|
|
1
|
+
export { ActionInput, ActionParamInput, AuthoringContext, AuthoringRegistration, COLUMN_BRAND, COLUMN_DEFAULT_FNS, ColumnBuilder, ColumnDefaultFn, ColumnDefaultLiteral, ColumnTypeSpec, ENUM_BRAND, EnumRef, IndexInput, LINK_BRAND, LinkKind, LoadNamespaceOptions, LoadedNamespaceV2, NAMESPACE_CONFIG_BRAND, NAMESPACE_CONFIG_FILE, NamespaceCapabilitiesInput, NamespaceConfigInput, PolicyInput, PolicyVariantInput, PolicyWithVariantsInput, SCHEMA_DIR, SeqLink, SeqNamespaceConfig, SeqTable, SerializeNamespaceInput, SyncedTableConfig, TABLE_BRAND, TableConfig, TablePoliciesInput, TableRef, ToManyOptions, ToOneOptions, ToPlatformUserOptions, activeAuthoringContext, beginAuthoringContext, computeCanonicalHash, defineEnum, defineNamespace, defineSyncedTable, defineTable, deriveColumnName, endAuthoringContext, isColumnBuilder, isEnumRef, isSeqLink, isSeqNamespaceConfig, isSeqTable, loadNamespaceFromDir, serializeNamespace, t, toMany, toOne, toPlatformUser } from './authoring.cjs';
|
|
2
|
+
import { CanonicalDefinition } from './canonical.cjs';
|
|
3
|
+
export { CANONICAL_FORMAT, CanonicalColumn, CanonicalEnum, CanonicalLink, CanonicalTable, IDENTIFIER_RE, PolicyExpression, canonicalActionSchema, canonicalColumnSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalTableSchema, normalizeCanonical, policyExpressionSchema, policyVariantSchema } from './canonical.cjs';
|
|
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';
|
|
2
7
|
import { generateDrizzleJson } from 'drizzle-kit/api';
|
|
3
8
|
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[];
|
|
9
|
+
export { CLAIMS_CONTRACT, CMP_OPS, ClaimKey, CmpOp, CompiledArtifact, CompiledOperation, INPUT_REF_KINDS, IR_VERSION, InputRefKind, IrVersionError, LimitIr, OrderIr, PredIr, RootIr, SelectionIr, TableMetaIr, ValueIr, VariableDefaultIr, VariableIr, compiledArtifactSchema, compiledOperationSchema, indexByHash, limitIrSchema, normalizeIr, orderIrSchema, predIrSchema, rootIrSchema, selectionIrSchema, tableMetaIrSchema, valueIrSchema, variableDefaultIrSchema, variableIrSchema } from './ir.cjs';
|
|
59
10
|
|
|
60
11
|
/**
|
|
61
12
|
* The reserved `namespace.yaml` — namespace-level settings beside the table
|
|
@@ -649,6 +600,42 @@ declare function planMigration({ definition, previousSnapshot, }: {
|
|
|
649
600
|
/** Full-create plan (empty previous snapshot) — what `plan` prints and first apply runs. */
|
|
650
601
|
declare const compileNamespace: (definition: NamespaceDefinition) => Promise<PlannedMigration>;
|
|
651
602
|
|
|
603
|
+
/**
|
|
604
|
+
* Canonical v2 → the in-memory schema bag drizzle-kit snapshots plus typed
|
|
605
|
+
* table handles — the same `DrizzleEntities` shape engine/snapshot.ts consumes.
|
|
606
|
+
*/
|
|
607
|
+
declare function buildDrizzleEntitiesV2(definition: CanonicalDefinition): DrizzleEntities;
|
|
608
|
+
/** drizzle-kit snapshot for a canonical definition — the v2 twin of engine/snapshot.ts generateSnapshot. */
|
|
609
|
+
declare function generateSnapshotV2(definition: CanonicalDefinition, previousId?: string): NamespaceSnapshot;
|
|
610
|
+
/**
|
|
611
|
+
* Renames and casts are declared in the canonical definition, never inferred:
|
|
612
|
+
* we emit the statement ourselves and rewrite the previous snapshot to match,
|
|
613
|
+
* so drizzle-kit never faces a create+drop ambiguity (its API resolves those
|
|
614
|
+
* interactively — fatal in a service). Semantics mirror engine/snapshot.ts
|
|
615
|
+
* applyMigrationHints exactly, plus the v2-only table-level `renamedFrom`
|
|
616
|
+
* (applied FIRST, so column hints find the table under its new name).
|
|
617
|
+
*
|
|
618
|
+
* This is a sibling of the v1 function rather than a wrapper: the v1 one is
|
|
619
|
+
* keyed to `NamespaceDefinition`'s record-shaped columns and cannot express
|
|
620
|
+
* table renames or enum-typed cast targets.
|
|
621
|
+
*/
|
|
622
|
+
declare function applyMigrationHintsV2(previous: NamespaceSnapshot, definition: CanonicalDefinition): MigrationHints;
|
|
623
|
+
/**
|
|
624
|
+
* Desired canonical definition + the previously applied snapshot → ordered
|
|
625
|
+
* statements. The v2 twin of engine/index.ts planMigration, reusing its
|
|
626
|
+
* exported internals (normalizeSnapshot/emptySnapshot/diffStatements — the
|
|
627
|
+
* assertUnambiguousDiff backstop rides along inside diffStatements).
|
|
628
|
+
*
|
|
629
|
+
* Deliberately absent relative to v1: policy drops, securityStatements, and
|
|
630
|
+
* action function statements. v2 enforces row policies inside compiled
|
|
631
|
+
* operations (no PG RLS policies) and executes actions on the data plane
|
|
632
|
+
* (no plpgsql functions), so a v2 plan is hints + kit DDL only.
|
|
633
|
+
*/
|
|
634
|
+
declare function planMigrationV2({ canonical, previousSnapshot, }: {
|
|
635
|
+
canonical: CanonicalDefinition;
|
|
636
|
+
previousSnapshot?: NamespaceSnapshot;
|
|
637
|
+
}): Promise<PlannedMigration>;
|
|
638
|
+
|
|
652
639
|
declare class OrmDefinitionError extends Error {
|
|
653
640
|
readonly file?: string | undefined;
|
|
654
641
|
readonly name = "OrmDefinitionError";
|
|
@@ -818,6 +805,80 @@ declare function writeMigration({ dir, workspace, plan, contentHash, destructive
|
|
|
818
805
|
destructive: boolean;
|
|
819
806
|
}): Promise<WrittenMigration>;
|
|
820
807
|
|
|
808
|
+
/**
|
|
809
|
+
* v1 YAML `NamespaceDefinition` → canonical v2 (`orm migrate-from-yaml`).
|
|
810
|
+
* Lossless where the v2 contract can express it, loud where it can't:
|
|
811
|
+
*
|
|
812
|
+
* - columns keep declaration order (order is meaningful for DDL); the v1
|
|
813
|
+
* `default` splits into literal `default` vs allowlisted `defaultFn`
|
|
814
|
+
* exactly along the isFunctionDefault line the v1 engine used;
|
|
815
|
+
* - the single v1 `primary_key: true` column becomes `primaryKey: [name]`;
|
|
816
|
+
* - policy expressions carry over as their verbatim DSL source strings
|
|
817
|
+
* (re-parsed by the v2 predicate compiler, never the parsed v1 AST);
|
|
818
|
+
* - actions carry over verbatim (multi-statement `executes` lists join on
|
|
819
|
+
* ';\n' — the boundaries stay recoverable for the compiled-op executor);
|
|
820
|
+
* - the capabilities block passes through untouched (verbatim custom-roles
|
|
821
|
+
* grammar in both formats);
|
|
822
|
+
* - qualified (cross-namespace) link targets have no v2 representation —
|
|
823
|
+
* links are namespace-local in v2 (plan §5) — so they fail the conversion
|
|
824
|
+
* rather than silently dropping.
|
|
825
|
+
*
|
|
826
|
+
* The result re-validates through canonicalDefinitionSchema and normalizes,
|
|
827
|
+
* so hashing and server-side re-validation see exactly what an authored v2
|
|
828
|
+
* definition would produce.
|
|
829
|
+
*/
|
|
830
|
+
declare function convertV1DefinitionToCanonical(definition: NamespaceDefinition): CanonicalDefinition;
|
|
831
|
+
|
|
832
|
+
/** Statement kinds that disqualify a plan from being a rebase no-op. */
|
|
833
|
+
interface RebaseNoopOptions {
|
|
834
|
+
/**
|
|
835
|
+
* v1 planned a drop-and-recreate of the RLS policies on every migration, so
|
|
836
|
+
* a plan produced by the V1 PIPELINE against an unchanged schema still
|
|
837
|
+
* carries `security` statements. v2 plans never emit them. Default false:
|
|
838
|
+
* a rebase verified through planMigrationV2 must be empty outright.
|
|
839
|
+
*/
|
|
840
|
+
readonly allowSecurityReemission?: boolean;
|
|
841
|
+
}
|
|
842
|
+
/** The statements that stop a plan from qualifying as a rebase no-op. */
|
|
843
|
+
declare function rebaseViolations(statements: readonly CompiledStatement[], options?: RebaseNoopOptions): CompiledStatement[];
|
|
844
|
+
/**
|
|
845
|
+
* True when the plan changes nothing: no DDL, no hint (rename/cast) ALTERs,
|
|
846
|
+
* no action functions — and, unless explicitly allowed, no security
|
|
847
|
+
* re-emission either. Pure predicate over the plan's statements.
|
|
848
|
+
*/
|
|
849
|
+
declare const verifyRebaseIsNoop: (plan: Pick<PlannedMigration, "statements">, options?: RebaseNoopOptions) => boolean;
|
|
850
|
+
interface RebaseEntryInput {
|
|
851
|
+
readonly namespace: string;
|
|
852
|
+
/** Content hash at the committed journal tip (the v1 hash being rebased from). */
|
|
853
|
+
readonly previousHash: string;
|
|
854
|
+
/** Content hash of the converted canonical v2 definition. */
|
|
855
|
+
readonly newHash: string;
|
|
856
|
+
/** Journal tip ordinal + 1. A rebase always sits on an existing tip. */
|
|
857
|
+
readonly ordinal: number;
|
|
858
|
+
/**
|
|
859
|
+
* The verified no-op plan's snapshot. Structurally identical to the tip
|
|
860
|
+
* snapshot but re-chained (fresh `id`, `prevId` = tip snapshot's id) so the
|
|
861
|
+
* `--check` snapshot-chain walk stays unbroken through the rebase.
|
|
862
|
+
*/
|
|
863
|
+
readonly snapshot: NamespaceSnapshot;
|
|
864
|
+
}
|
|
865
|
+
interface RebaseEntry {
|
|
866
|
+
readonly name: string;
|
|
867
|
+
/** Journal entry matching workspace.ts's journalEntrySchema exactly. */
|
|
868
|
+
readonly entry: JournalEntry;
|
|
869
|
+
/** `migrations/<name>.sql` contents — header only, zero statements. */
|
|
870
|
+
readonly sql: string;
|
|
871
|
+
/** `migrations/meta/NNNN.snapshot.json` contents (writeMigration's serialization). */
|
|
872
|
+
readonly snapshotText: string;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Build the no-op journal entry (+ the exact file contents its checksums
|
|
876
|
+
* commit to) recording a v1 → v2 content-hash rebase. Everything is
|
|
877
|
+
* deterministic from the inputs, so `--check`-style gates can regenerate and
|
|
878
|
+
* byte-compare it just like ordinary migrations.
|
|
879
|
+
*/
|
|
880
|
+
declare function buildRebaseJournalEntry({ namespace, previousHash, newHash, ordinal, snapshot }: RebaseEntryInput): RebaseEntry;
|
|
881
|
+
|
|
821
882
|
declare function parsePredicate(source: string): ParsedPredicate;
|
|
822
883
|
|
|
823
884
|
declare const identifierSchema: z.ZodString;
|
|
@@ -836,4 +897,4 @@ declare function parseCanonicalDefinition(value: unknown): NamespaceDefinition;
|
|
|
836
897
|
|
|
837
898
|
declare const parsedPredicateSchema: z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>;
|
|
838
899
|
|
|
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,
|
|
900
|
+
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 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, type Predicate, PredicateParseError, QUALIFIED_TABLE_PATTERN, RESERVED_COLUMN_NAMES, RESERVED_TABLE_NAMES, type RebaseEntry, type RebaseEntryInput, type RebaseNoopOptions, STATEMENT_KINDS, SYNCED_SOURCE_PATTERN, type StatementKind, 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, compilePredicate, computeDefinitionHash, consumerRoleName, convertV1DefinitionToCanonical, declaredCapabilityKeys, diffCommand, diffStatements, emptyJournal, emptySnapshot, extractNamedParams, generateNamespaceTypes, generateSnapshot, generateSnapshotV2, identifierSchema, isFunctionDefault, isOwnedStatement, isQualifiedReference, loadCommittedMigrations, loadCommittedTipMigration, loadNamespaceDefinition, migrationName, namespaceConfigSchema, namespaceSchema, normalizeSnapshot, ormSchemaName, parseCanonicalDefinition, parseDefinitionSources, parsePredicate, parseTableFile, parsedPredicateSchema, pendingKitStatements, planMigration, planMigrationV2, predicateOperands, quoteIdentifier, quoteLiteral, readMigrationSql, readMigrationWorkspace, readSnapshot, rebaseViolations, referencedCapabilities, referencedColumns, renderMigrationSql, securityStatements, sqlTypeName, stableJson, tableFileSchema, tableReferenceSchema, typesInterfaceName, verifyRebaseIsNoop, walkPredicate, writeMigration };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,61 +1,12 @@
|
|
|
1
|
+
export { ActionInput, ActionParamInput, AuthoringContext, AuthoringRegistration, COLUMN_BRAND, COLUMN_DEFAULT_FNS, ColumnBuilder, ColumnDefaultFn, ColumnDefaultLiteral, ColumnTypeSpec, ENUM_BRAND, EnumRef, IndexInput, LINK_BRAND, LinkKind, LoadNamespaceOptions, LoadedNamespaceV2, NAMESPACE_CONFIG_BRAND, NAMESPACE_CONFIG_FILE, NamespaceCapabilitiesInput, NamespaceConfigInput, PolicyInput, PolicyVariantInput, PolicyWithVariantsInput, SCHEMA_DIR, SeqLink, SeqNamespaceConfig, SeqTable, SerializeNamespaceInput, SyncedTableConfig, TABLE_BRAND, TableConfig, TablePoliciesInput, TableRef, ToManyOptions, ToOneOptions, ToPlatformUserOptions, activeAuthoringContext, beginAuthoringContext, computeCanonicalHash, defineEnum, defineNamespace, defineSyncedTable, defineTable, deriveColumnName, endAuthoringContext, isColumnBuilder, isEnumRef, isSeqLink, isSeqNamespaceConfig, isSeqTable, loadNamespaceFromDir, serializeNamespace, t, toMany, toOne, toPlatformUser } from './authoring.js';
|
|
2
|
+
import { CanonicalDefinition } from './canonical.js';
|
|
3
|
+
export { CANONICAL_FORMAT, CanonicalColumn, CanonicalEnum, CanonicalLink, CanonicalTable, IDENTIFIER_RE, PolicyExpression, canonicalActionSchema, canonicalColumnSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalTableSchema, 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';
|
|
2
7
|
import { generateDrizzleJson } from 'drizzle-kit/api';
|
|
3
8
|
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[];
|
|
9
|
+
export { CLAIMS_CONTRACT, CMP_OPS, ClaimKey, CmpOp, CompiledArtifact, CompiledOperation, INPUT_REF_KINDS, IR_VERSION, InputRefKind, IrVersionError, LimitIr, OrderIr, PredIr, RootIr, SelectionIr, TableMetaIr, ValueIr, VariableDefaultIr, VariableIr, compiledArtifactSchema, compiledOperationSchema, indexByHash, limitIrSchema, normalizeIr, orderIrSchema, predIrSchema, rootIrSchema, selectionIrSchema, tableMetaIrSchema, valueIrSchema, variableDefaultIrSchema, variableIrSchema } from './ir.js';
|
|
59
10
|
|
|
60
11
|
/**
|
|
61
12
|
* The reserved `namespace.yaml` — namespace-level settings beside the table
|
|
@@ -649,6 +600,42 @@ declare function planMigration({ definition, previousSnapshot, }: {
|
|
|
649
600
|
/** Full-create plan (empty previous snapshot) — what `plan` prints and first apply runs. */
|
|
650
601
|
declare const compileNamespace: (definition: NamespaceDefinition) => Promise<PlannedMigration>;
|
|
651
602
|
|
|
603
|
+
/**
|
|
604
|
+
* Canonical v2 → the in-memory schema bag drizzle-kit snapshots plus typed
|
|
605
|
+
* table handles — the same `DrizzleEntities` shape engine/snapshot.ts consumes.
|
|
606
|
+
*/
|
|
607
|
+
declare function buildDrizzleEntitiesV2(definition: CanonicalDefinition): DrizzleEntities;
|
|
608
|
+
/** drizzle-kit snapshot for a canonical definition — the v2 twin of engine/snapshot.ts generateSnapshot. */
|
|
609
|
+
declare function generateSnapshotV2(definition: CanonicalDefinition, previousId?: string): NamespaceSnapshot;
|
|
610
|
+
/**
|
|
611
|
+
* Renames and casts are declared in the canonical definition, never inferred:
|
|
612
|
+
* we emit the statement ourselves and rewrite the previous snapshot to match,
|
|
613
|
+
* so drizzle-kit never faces a create+drop ambiguity (its API resolves those
|
|
614
|
+
* interactively — fatal in a service). Semantics mirror engine/snapshot.ts
|
|
615
|
+
* applyMigrationHints exactly, plus the v2-only table-level `renamedFrom`
|
|
616
|
+
* (applied FIRST, so column hints find the table under its new name).
|
|
617
|
+
*
|
|
618
|
+
* This is a sibling of the v1 function rather than a wrapper: the v1 one is
|
|
619
|
+
* keyed to `NamespaceDefinition`'s record-shaped columns and cannot express
|
|
620
|
+
* table renames or enum-typed cast targets.
|
|
621
|
+
*/
|
|
622
|
+
declare function applyMigrationHintsV2(previous: NamespaceSnapshot, definition: CanonicalDefinition): MigrationHints;
|
|
623
|
+
/**
|
|
624
|
+
* Desired canonical definition + the previously applied snapshot → ordered
|
|
625
|
+
* statements. The v2 twin of engine/index.ts planMigration, reusing its
|
|
626
|
+
* exported internals (normalizeSnapshot/emptySnapshot/diffStatements — the
|
|
627
|
+
* assertUnambiguousDiff backstop rides along inside diffStatements).
|
|
628
|
+
*
|
|
629
|
+
* Deliberately absent relative to v1: policy drops, securityStatements, and
|
|
630
|
+
* action function statements. v2 enforces row policies inside compiled
|
|
631
|
+
* operations (no PG RLS policies) and executes actions on the data plane
|
|
632
|
+
* (no plpgsql functions), so a v2 plan is hints + kit DDL only.
|
|
633
|
+
*/
|
|
634
|
+
declare function planMigrationV2({ canonical, previousSnapshot, }: {
|
|
635
|
+
canonical: CanonicalDefinition;
|
|
636
|
+
previousSnapshot?: NamespaceSnapshot;
|
|
637
|
+
}): Promise<PlannedMigration>;
|
|
638
|
+
|
|
652
639
|
declare class OrmDefinitionError extends Error {
|
|
653
640
|
readonly file?: string | undefined;
|
|
654
641
|
readonly name = "OrmDefinitionError";
|
|
@@ -818,6 +805,80 @@ declare function writeMigration({ dir, workspace, plan, contentHash, destructive
|
|
|
818
805
|
destructive: boolean;
|
|
819
806
|
}): Promise<WrittenMigration>;
|
|
820
807
|
|
|
808
|
+
/**
|
|
809
|
+
* v1 YAML `NamespaceDefinition` → canonical v2 (`orm migrate-from-yaml`).
|
|
810
|
+
* Lossless where the v2 contract can express it, loud where it can't:
|
|
811
|
+
*
|
|
812
|
+
* - columns keep declaration order (order is meaningful for DDL); the v1
|
|
813
|
+
* `default` splits into literal `default` vs allowlisted `defaultFn`
|
|
814
|
+
* exactly along the isFunctionDefault line the v1 engine used;
|
|
815
|
+
* - the single v1 `primary_key: true` column becomes `primaryKey: [name]`;
|
|
816
|
+
* - policy expressions carry over as their verbatim DSL source strings
|
|
817
|
+
* (re-parsed by the v2 predicate compiler, never the parsed v1 AST);
|
|
818
|
+
* - actions carry over verbatim (multi-statement `executes` lists join on
|
|
819
|
+
* ';\n' — the boundaries stay recoverable for the compiled-op executor);
|
|
820
|
+
* - the capabilities block passes through untouched (verbatim custom-roles
|
|
821
|
+
* grammar in both formats);
|
|
822
|
+
* - qualified (cross-namespace) link targets have no v2 representation —
|
|
823
|
+
* links are namespace-local in v2 (plan §5) — so they fail the conversion
|
|
824
|
+
* rather than silently dropping.
|
|
825
|
+
*
|
|
826
|
+
* The result re-validates through canonicalDefinitionSchema and normalizes,
|
|
827
|
+
* so hashing and server-side re-validation see exactly what an authored v2
|
|
828
|
+
* definition would produce.
|
|
829
|
+
*/
|
|
830
|
+
declare function convertV1DefinitionToCanonical(definition: NamespaceDefinition): CanonicalDefinition;
|
|
831
|
+
|
|
832
|
+
/** Statement kinds that disqualify a plan from being a rebase no-op. */
|
|
833
|
+
interface RebaseNoopOptions {
|
|
834
|
+
/**
|
|
835
|
+
* v1 planned a drop-and-recreate of the RLS policies on every migration, so
|
|
836
|
+
* a plan produced by the V1 PIPELINE against an unchanged schema still
|
|
837
|
+
* carries `security` statements. v2 plans never emit them. Default false:
|
|
838
|
+
* a rebase verified through planMigrationV2 must be empty outright.
|
|
839
|
+
*/
|
|
840
|
+
readonly allowSecurityReemission?: boolean;
|
|
841
|
+
}
|
|
842
|
+
/** The statements that stop a plan from qualifying as a rebase no-op. */
|
|
843
|
+
declare function rebaseViolations(statements: readonly CompiledStatement[], options?: RebaseNoopOptions): CompiledStatement[];
|
|
844
|
+
/**
|
|
845
|
+
* True when the plan changes nothing: no DDL, no hint (rename/cast) ALTERs,
|
|
846
|
+
* no action functions — and, unless explicitly allowed, no security
|
|
847
|
+
* re-emission either. Pure predicate over the plan's statements.
|
|
848
|
+
*/
|
|
849
|
+
declare const verifyRebaseIsNoop: (plan: Pick<PlannedMigration, "statements">, options?: RebaseNoopOptions) => boolean;
|
|
850
|
+
interface RebaseEntryInput {
|
|
851
|
+
readonly namespace: string;
|
|
852
|
+
/** Content hash at the committed journal tip (the v1 hash being rebased from). */
|
|
853
|
+
readonly previousHash: string;
|
|
854
|
+
/** Content hash of the converted canonical v2 definition. */
|
|
855
|
+
readonly newHash: string;
|
|
856
|
+
/** Journal tip ordinal + 1. A rebase always sits on an existing tip. */
|
|
857
|
+
readonly ordinal: number;
|
|
858
|
+
/**
|
|
859
|
+
* The verified no-op plan's snapshot. Structurally identical to the tip
|
|
860
|
+
* snapshot but re-chained (fresh `id`, `prevId` = tip snapshot's id) so the
|
|
861
|
+
* `--check` snapshot-chain walk stays unbroken through the rebase.
|
|
862
|
+
*/
|
|
863
|
+
readonly snapshot: NamespaceSnapshot;
|
|
864
|
+
}
|
|
865
|
+
interface RebaseEntry {
|
|
866
|
+
readonly name: string;
|
|
867
|
+
/** Journal entry matching workspace.ts's journalEntrySchema exactly. */
|
|
868
|
+
readonly entry: JournalEntry;
|
|
869
|
+
/** `migrations/<name>.sql` contents — header only, zero statements. */
|
|
870
|
+
readonly sql: string;
|
|
871
|
+
/** `migrations/meta/NNNN.snapshot.json` contents (writeMigration's serialization). */
|
|
872
|
+
readonly snapshotText: string;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Build the no-op journal entry (+ the exact file contents its checksums
|
|
876
|
+
* commit to) recording a v1 → v2 content-hash rebase. Everything is
|
|
877
|
+
* deterministic from the inputs, so `--check`-style gates can regenerate and
|
|
878
|
+
* byte-compare it just like ordinary migrations.
|
|
879
|
+
*/
|
|
880
|
+
declare function buildRebaseJournalEntry({ namespace, previousHash, newHash, ordinal, snapshot }: RebaseEntryInput): RebaseEntry;
|
|
881
|
+
|
|
821
882
|
declare function parsePredicate(source: string): ParsedPredicate;
|
|
822
883
|
|
|
823
884
|
declare const identifierSchema: z.ZodString;
|
|
@@ -836,4 +897,4 @@ declare function parseCanonicalDefinition(value: unknown): NamespaceDefinition;
|
|
|
836
897
|
|
|
837
898
|
declare const parsedPredicateSchema: z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>;
|
|
838
899
|
|
|
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,
|
|
900
|
+
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 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, type Predicate, PredicateParseError, QUALIFIED_TABLE_PATTERN, RESERVED_COLUMN_NAMES, RESERVED_TABLE_NAMES, type RebaseEntry, type RebaseEntryInput, type RebaseNoopOptions, STATEMENT_KINDS, SYNCED_SOURCE_PATTERN, type StatementKind, 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, compilePredicate, computeDefinitionHash, consumerRoleName, convertV1DefinitionToCanonical, declaredCapabilityKeys, diffCommand, diffStatements, emptyJournal, emptySnapshot, extractNamedParams, generateNamespaceTypes, generateSnapshot, generateSnapshotV2, identifierSchema, isFunctionDefault, isOwnedStatement, isQualifiedReference, loadCommittedMigrations, loadCommittedTipMigration, loadNamespaceDefinition, migrationName, namespaceConfigSchema, namespaceSchema, normalizeSnapshot, ormSchemaName, parseCanonicalDefinition, parseDefinitionSources, parsePredicate, parseTableFile, parsedPredicateSchema, pendingKitStatements, planMigration, planMigrationV2, predicateOperands, quoteIdentifier, quoteLiteral, readMigrationSql, readMigrationWorkspace, readSnapshot, rebaseViolations, referencedCapabilities, referencedColumns, renderMigrationSql, securityStatements, sqlTypeName, stableJson, tableFileSchema, tableReferenceSchema, typesInterfaceName, verifyRebaseIsNoop, walkPredicate, writeMigration };
|