@sequenceholdings/orm 0.1.0 → 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 +6208 -1693
- 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 +6262 -1749
- 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 +1730 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -56
- package/dist/index.d.ts +126 -56
- package/dist/index.js +1643 -324
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/authoring/columns.ts","../src/constants.ts","../src/errors.ts","../src/authoring/registry.ts","../src/authoring/table.ts","../src/canonical/v2.ts","../src/hash.ts","../src/authoring/namespace.ts","../src/authoring/load.ts"],"names":["z","t","createHash","realpath","join","stat","jiti","createJiti","readdir","require","createRequire","sep"],"mappings":";;;;;;;;;;;AAcO,IAAM,YAAA,GAAe;AACrB,IAAM,UAAA,GAAa;AASnB,SAAS,UAAU,KAAA,EAAkC;AAC1D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,IAAS,MAA6B,IAAA,KAAS,UAAA;AAC/F;AAGO,IAAM,kBAAA,GAAqB,CAAC,mBAAA,EAAqB,OAAO;AAQxD,SAAS,iBAAiB,YAAA,EAA8B;AAC7D,EAAA,OAAO,YAAA,CACJ,QAAQ,oBAAA,EAAsB,OAAO,EACrC,OAAA,CAAQ,uBAAA,EAAyB,OAAO,CAAA,CACxC,WAAA,EAAY;AACjB;AAiBO,IAAM,gBAAN,MAAoB;AAAA,EAChB,IAAA,GAAO,YAAA;AAAA,EAEC,KAAA;AAAA,EAEjB,WAAA,CAAY,MAAsB,UAAA,EAAqB;AACrD,IAAA,IAAA,CAAK,KAAA,GAAQ;AAAA,MACX,IAAA;AAAA,MACA,U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["/**\n * Fluent column builders for the v2 authoring surface — `t.uuid()`,\n * `t.text().notNull().unique()`, `t.enum(status).default('open')`, …\n *\n * Builders carry plain serializable state and produce `CanonicalColumn` data\n * (canonical definition v2). They never touch Drizzle: the server builds\n * Drizzle entities from canonical JSON, consumer TypeScript never runs\n * server-side (plan §2).\n *\n * Cross-copy safety: the jiti loader evaluates its own transpiled copy of\n * this module, so identification uses the `kind` brand — never `instanceof`.\n */\nimport type { CanonicalColumn, ColumnType } from '../canonical/v2.js'\n\nexport const COLUMN_BRAND = 'seq-column' as const\nexport const ENUM_BRAND = 'seq-enum' as const\n\n/** A namespace-level Postgres enum, created with `defineEnum` (table.ts). */\nexport interface EnumRef {\n readonly kind: typeof ENUM_BRAND\n readonly name: string\n readonly values: readonly string[]\n}\n\nexport function isEnumRef(value: unknown): value is EnumRef {\n return typeof value === 'object' && value !== null && (value as { kind?: unknown }).kind === ENUM_BRAND\n}\n\n/** The allowlisted SQL default functions — `.default('now()')` maps here, not to a literal. */\nexport const COLUMN_DEFAULT_FNS = ['gen_random_uuid()', 'now()'] as const\nexport type ColumnDefaultFn = (typeof COLUMN_DEFAULT_FNS)[number]\n\nexport type ColumnDefaultLiteral = string | number | boolean | null\n\nexport type ColumnTypeSpec = ColumnType | { readonly enum: string }\n\n/** `authorSub` → `author_sub`, `authorURLPath` → `author_url_path`. */\nexport function deriveColumnName(propertyName: string): string {\n return propertyName\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')\n .toLowerCase()\n}\n\ninterface ColumnState {\n type: ColumnTypeSpec\n columnName: string | undefined\n primaryKey: boolean\n notNull: boolean\n unique: boolean\n hasDefault: boolean\n defaultValue: ColumnDefaultLiteral | undefined\n defaultFn: ColumnDefaultFn | undefined\n description: string | undefined\n renamedFrom: string | undefined\n cast: string | undefined\n deprecated: boolean\n}\n\nexport class ColumnBuilder {\n readonly kind = COLUMN_BRAND\n\n private readonly state: ColumnState\n\n constructor(type: ColumnTypeSpec, columnName?: string) {\n this.state = {\n type,\n columnName,\n primaryKey: false,\n notNull: false,\n unique: false,\n hasDefault: false,\n defaultValue: undefined,\n defaultFn: undefined,\n description: undefined,\n renamedFrom: undefined,\n cast: undefined,\n deprecated: false,\n }\n }\n\n /** Marks this column as (part of) the primary key. Implies NOT NULL. */\n primaryKey(): this {\n this.state.primaryKey = true\n return this\n }\n\n notNull(): this {\n this.state.notNull = true\n return this\n }\n\n unique(): this {\n this.state.unique = true\n return this\n }\n\n /**\n * Column default: a literal, or one of the allowlisted SQL functions\n * (`'gen_random_uuid()'` / `'now()'`), which serialize as `defaultFn`.\n */\n default(value: ColumnDefaultLiteral): this {\n if (value === 'gen_random_uuid()' || value === 'now()') {\n this.state.defaultFn = value\n this.state.hasDefault = false\n this.state.defaultValue = undefined\n return this\n }\n this.state.hasDefault = true\n this.state.defaultValue = value\n this.state.defaultFn = undefined\n return this\n }\n\n description(text: string): this {\n this.state.description = text\n return this\n }\n\n /** Migration rename hint: the previous Postgres column name. */\n renamedFrom(previousColumnName: string): this {\n this.state.renamedFrom = previousColumnName\n return this\n }\n\n /** Migration cast hint: the `USING` SQL applied when this column changes type. */\n cast(usingSql: string): this {\n this.state.cast = usingSql\n return this\n }\n\n /** Emits `@deprecated` in the generated SDL; the column stays queryable. */\n deprecated(): this {\n this.state.deprecated = true\n return this\n }\n\n /** Whether `.primaryKey()` was called — collected into the table-level PK. */\n get isPrimaryKey(): boolean {\n return this.state.primaryKey\n }\n\n /** The enum name when this is an enum column, else undefined. */\n get enumName(): string | undefined {\n return typeof this.state.type === 'object' ? this.state.type.enum : undefined\n }\n\n /** Postgres column name: explicit override, else snake_case of the property name. */\n columnNameFor(propertyName: string): string {\n return this.state.columnName ?? deriveColumnName(propertyName)\n }\n\n /** Serialize to a canonical v2 column. Validation happens in serializeNamespace. */\n toCanonicalColumn(propertyName: string): CanonicalColumn {\n const column: CanonicalColumn = {\n name: propertyName,\n columnName: this.columnNameFor(propertyName),\n type: typeof this.state.type === 'object' ? { enum: this.state.type.enum } : this.state.type,\n nullable: !(this.state.notNull || this.state.primaryKey),\n unique: this.state.unique,\n deprecated: this.state.deprecated,\n }\n if (this.state.hasDefault) column.default = this.state.defaultValue ?? null\n if (this.state.defaultFn !== undefined) column.defaultFn = this.state.defaultFn\n if (this.state.description !== undefined) column.description = this.state.description\n if (this.state.renamedFrom !== undefined) column.renamedFrom = this.state.renamedFrom\n if (this.state.cast !== undefined) column.cast = this.state.cast\n return column\n }\n}\n\nexport function isColumnBuilder(value: unknown): value is ColumnBuilder {\n return typeof value === 'object' && value !== null && (value as { kind?: unknown }).kind === COLUMN_BRAND\n}\n\nconst scalar =\n (type: ColumnType) =>\n (columnName?: string): ColumnBuilder =>\n new ColumnBuilder(type, columnName)\n\n/**\n * The column-type factory. The optional argument overrides the derived\n * snake_case Postgres column name: `t.text('legacy_name')`.\n */\nexport const t = {\n uuid: scalar('uuid'),\n text: scalar('text'),\n integer: scalar('integer'),\n bigint: scalar('bigint'),\n numeric: scalar('numeric'),\n double: scalar('double'),\n boolean: scalar('boolean'),\n timestamptz: scalar('timestamptz'),\n date: scalar('date'),\n jsonb: scalar('jsonb'),\n enum: (ref: EnumRef, columnName?: string): ColumnBuilder => new ColumnBuilder({ enum: ref.name }, columnName),\n} as const\n","/** Namespace names become Postgres identifiers (`orm_<ns>` schema, `orm_<ns>_consumer` role) — the tight grammar is a security control, not cosmetics. */\nexport const NAMESPACE_PATTERN = /^[a-z][a-z0-9_]{0,40}$/\n\nexport const IDENTIFIER_PATTERN = /^[a-z][a-z0-9_]*$/\nexport const MAX_IDENTIFIER_LENGTH = 63\n\n/**\n * The Data API carries a delegated, attenuated data token on this header (not\n * `Authorization`, which stays the app-user/session bearer). One definition\n * shared by the client transport, the server's caller resolver, and the\n * function-invoke minter, so all three agree.\n */\nexport const ORM_DATA_TOKEN_HEADER = 'x-sequence-data-token'\n\n/**\n * The SEPARATE header the invoke proxy uses to hand a managed function its\n * *service* data token — the escalation path. A function receives BOTH this and\n * `ORM_DATA_TOKEN_HEADER`; the default `createOrmClient` reads the user token,\n * the deliberately-named `createServiceOrmClient` reads THIS one. Two distinct\n * headers so reaching for the service identity is always an explicit act, never\n * an accidental default. Both are sent to the Data API on `ORM_DATA_TOKEN_HEADER`\n * — the server stays mode-agnostic and resolves whatever sub the token carries.\n */\nexport const ORM_SERVICE_DATA_TOKEN_HEADER = 'x-sequence-data-token-service'\n\n/**\n * Custom Roles & Capabilities claim keys as policies reference them: a\n * host-scoped registry key, or an org pin's `org/<key>`. Matches the registry\n * key grammar EXACTLY (`[a-z0-9-]`, 1–64 chars, no `_` — the FGA object-id\n * delimiter) so any capability that's declarable/attachable in namespace.yaml\n * can also be referenced here — a stricter pattern would let a valid key\n * register yet fail at apply (e.g. `org/2fa`, a one-char or digit-led key).\n */\nexport const CAPABILITY_KEY_PATTERN = /^(?:org\\/)?[a-z0-9-]{1,64}$/\n\nexport const CLAIM_KEY_PATTERN = /^[a-z][a-z0-9_]*$/\n\n/** Qualified reference to a table outside the defining file: `<schema>.<table>`. */\nexport const QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]*\\.[a-z][a-z0-9_]*$/\n\n/** Synced reflected sources are restricted to the gold layer. */\nexport const SYNCED_SOURCE_PATTERN = /^gold\\.[a-z][a-z0-9_]*$/\n\nexport const ORM_SCHEMA_PREFIX = 'orm_'\nexport const CONSUMER_ROLE_SUFFIX = '_consumer'\n\nexport const ormSchemaName = (namespace: string): string => `${ORM_SCHEMA_PREFIX}${namespace}`\nexport const consumerRoleName = (namespace: string): string =>\n `${ORM_SCHEMA_PREFIX}${namespace}${CONSUMER_ROLE_SUFFIX}`\n\nexport const DEFINITION_FILE_EXTENSIONS = ['.yml', '.yaml'] as const\n\n/** Reserved basenames for the namespace-level config file (description, org capability pins). */\nexport const NAMESPACE_CONFIG_FILENAMES = new Set(['namespace.yaml', 'namespace.yml'])\n\nexport const HASH_DOMAIN = 'sequence-orm-definitions\\0'\n\n/**\n * The one size guard the package owns: a per-file byte cap where the loader\n * reads untrusted YAML into memory — a real failure mode, not a product\n * limit. Counts of tables/indexes/params and policy/SQL lengths are\n * deliberately uncapped; Postgres enforces its own limits loudly at apply.\n */\nexport const MAX_DEFINITION_FILE_BYTES = 1024 * 1024\n\n/** `/api/data/<ns>/actions/…` and `/api/data/<ns>/query` share the table path segment. */\nexport const RESERVED_TABLE_NAMES = new Set(['actions', 'query'])\n\n/**\n * The Data API's query-string grammar owns these parameter names — a column\n * with one of them could never be filtered over the wire, so definitions\n * refuse it up front (\"validate rejects only what can never work\").\n */\nexport const RESERVED_COLUMN_NAMES = new Set(['select', 'order', 'limit', 'offset'])\n","export class OrmDefinitionError extends Error {\n override readonly name = 'OrmDefinitionError'\n\n constructor(\n message: string,\n readonly file?: string,\n ) {\n super(file ? `${file}: ${message}` : message)\n }\n}\n\nexport class PredicateParseError extends Error {\n override readonly name = 'PredicateParseError'\n\n constructor(\n message: string,\n readonly position: number,\n ) {\n super(`${message} (at position ${position})`)\n }\n}\n","/**\n * Module-registry pattern for the authoring surface: `defineTable` /\n * `defineEnum` / `defineNamespace` register into the ACTIVE collection\n * context while `loadNamespaceFromDir` imports a consumer's files, so the\n * loader collects definitions without inspecting module exports.\n *\n * The context stack lives on `globalThis` under a `Symbol.for` key — NOT in\n * module scope — because the jiti loader evaluates its own transpiled copy of\n * this module when a consumer file imports '@sequenceholdings/orm'. Both\n * copies must observe the same registrations (the graphql-js dual-package\n * discipline), so everything registered is plain data identified by `kind`\n * brand strings, never `instanceof`.\n */\n\nexport interface AuthoringRegistration {\n readonly value: unknown\n readonly file: string | undefined\n}\n\nexport interface AuthoringContext {\n /** Set by the loader before importing each consumer file — error attribution. */\n currentFile: string | undefined\n readonly tables: AuthoringRegistration[]\n readonly enums: AuthoringRegistration[]\n readonly configs: AuthoringRegistration[]\n}\n\nconst CONTEXT_STACK_KEY = Symbol.for('sequence.orm.authoring.context-stack.v2')\n\nfunction contextStack(): AuthoringContext[] {\n const holder = globalThis as { [key: symbol]: unknown }\n const existing = holder[CONTEXT_STACK_KEY]\n if (Array.isArray(existing)) {\n // The slot is only ever written by this function with an AuthoringContext[];\n // the cast re-attaches the type the untyped global slot cannot carry.\n return existing as AuthoringContext[]\n }\n const created: AuthoringContext[] = []\n holder[CONTEXT_STACK_KEY] = created\n return created\n}\n\n/** Push a fresh collection context; every define* call registers into it until ended. */\nexport function beginAuthoringContext(): AuthoringContext {\n const context: AuthoringContext = { currentFile: undefined, tables: [], enums: [], configs: [] }\n contextStack().push(context)\n return context\n}\n\n/** Pop the context; throws if collection begin/end calls are mismatched (programmer error). */\nexport function endAuthoringContext(context: AuthoringContext): void {\n const stack = contextStack()\n const top = stack[stack.length - 1]\n if (top !== context) {\n throw new Error('endAuthoringContext: the given context is not the active one — begin/end calls are mismatched')\n }\n stack.pop()\n}\n\nexport function activeAuthoringContext(): AuthoringContext | undefined {\n const stack = contextStack()\n return stack[stack.length - 1]\n}\n\nfunction register(bucket: keyof Pick<AuthoringContext, 'tables' | 'enums' | 'configs'>, value: unknown): void {\n const context = activeAuthoringContext()\n if (!context) return\n context[bucket].push({ value, file: context.currentFile })\n}\n\nexport function registerTable(value: unknown): void {\n register('tables', value)\n}\n\nexport function registerEnum(value: unknown): void {\n register('enums', value)\n}\n\nexport function registerNamespaceConfig(value: unknown): void {\n register('configs', value)\n}\n","/**\n * `defineTable` / `defineSyncedTable` / `defineEnum` and the link factories\n * (`toOne` / `toMany` / `toPlatformUser`) — the consumer-facing table layer\n * of the v2 authoring surface.\n *\n * Tables are plain-data descriptors (`SeqTable`) carrying builder state;\n * `serializeNamespace` (namespace.ts) turns them into canonical definition\n * v2. Link targets accept lazy `() => table` thunks so mutually-referencing\n * tables can live in any file order (cycles resolve at serialize time).\n */\nimport { IDENTIFIER_PATTERN, MAX_IDENTIFIER_LENGTH, SYNCED_SOURCE_PATTERN } from '../constants.js'\nimport { OrmDefinitionError } from '../errors.js'\nimport { ENUM_BRAND, isColumnBuilder, type ColumnBuilder, type EnumRef } from './columns.js'\nimport { activeAuthoringContext, registerEnum, registerTable } from './registry.js'\nimport type { ColumnType } from '../canonical/v2.js'\n\nexport const TABLE_BRAND = 'seq-table' as const\nexport const LINK_BRAND = 'seq-link' as const\n\n// ---------------------------------------------------------------------------\n// Links\n// ---------------------------------------------------------------------------\n\n/** A link target: the table itself, or a lazy thunk for forward/cyclic references. */\nexport type TableRef = SeqTable | (() => SeqTable)\n\nexport type LinkKind = 'toOne' | 'toMany' | 'toPlatformUser'\n\nexport interface SeqLink {\n readonly kind: typeof LINK_BRAND\n readonly linkKind: LinkKind\n /** Absent for toPlatformUser — the platform-users view needs no target. */\n readonly target: TableRef | undefined\n /** FK column (property or column name). toOne/toPlatformUser: on this table; toMany: on the target. */\n readonly on: string\n readonly references: string | undefined\n readonly enforce: boolean\n readonly description: string | undefined\n}\n\nexport interface ToOneOptions {\n on: string\n references?: string\n /** Emit a real FK constraint (same-namespace toOne only). */\n enforce?: boolean\n description?: string\n}\n\nexport interface ToManyOptions {\n on: string\n references?: string\n description?: string\n}\n\nexport interface ToPlatformUserOptions {\n /** Column on this table holding the platform user `sub` (or `references` override). */\n on: string\n references?: string\n description?: string\n}\n\nexport function toOne(target: TableRef, options: ToOneOptions): SeqLink {\n return {\n kind: LINK_BRAND,\n linkKind: 'toOne',\n target,\n on: options.on,\n references: options.references,\n enforce: options.enforce ?? false,\n description: options.description,\n }\n}\n\nexport function toMany(target: TableRef, options: ToManyOptions): SeqLink {\n return {\n kind: LINK_BRAND,\n linkKind: 'toMany',\n target,\n on: options.on,\n references: options.references,\n enforce: false,\n description: options.description,\n }\n}\n\n/** Link to the built-in read-only platform-users view (plan §4b) — no table definition needed. */\nexport function toPlatformUser(options: ToPlatformUserOptions): SeqLink {\n return {\n kind: LINK_BRAND,\n linkKind: 'toPlatformUser',\n target: undefined,\n on: options.on,\n references: options.references,\n enforce: false,\n description: options.description,\n }\n}\n\nexport function isSeqLink(value: unknown): value is SeqLink {\n return typeof value === 'object' && value !== null && (value as { kind?: unknown }).kind === LINK_BRAND\n}\n\n// ---------------------------------------------------------------------------\n// Policies / indexes / actions (authoring input shapes)\n// ---------------------------------------------------------------------------\n\nexport interface PolicyVariantInput {\n /** Claims-only guard: `capability('x')` / `role('y')` / claim comparisons. */\n when: string\n /** Exactly one of `allow: true` or `policy` (validated at serialize time). */\n allow?: true\n policy?: string\n}\n\nexport interface PolicyWithVariantsInput {\n default: string\n variants?: readonly PolicyVariantInput[]\n}\n\n/** A policy: a DSL source string, or a default + per-role/capability variants (§4c). */\nexport type PolicyInput = string | PolicyWithVariantsInput\n\nexport interface TablePoliciesInput {\n read?: PolicyInput\n write?: PolicyInput\n}\n\nexport interface IndexInput {\n /** Property names (camelCase) or Postgres column names. */\n columns: readonly string[]\n unique?: boolean\n name?: string\n}\n\nexport interface ActionParamInput {\n type: ColumnType\n nullable?: boolean\n}\n\nexport interface ActionInput {\n name: string\n requires?: string\n params?: Record<string, ActionParamInput>\n executes: string\n returns?: 'rows' | 'rowsAffected' | 'scalar'\n audit?: { action: string; resource: string }\n}\n\nexport interface TableConfig {\n description?: string\n /** Table-level migration rename hint (new in v2). */\n renamedFrom?: string\n /** Composite primary key: property names (or column names). Mutually exclusive with column-level `.primaryKey()`. */\n primaryKey?: readonly string[]\n indexes?: readonly IndexInput[]\n links?: Record<string, SeqLink>\n policies?: TablePoliciesInput\n actions?: readonly ActionInput[]\n}\n\n// ---------------------------------------------------------------------------\n// Tables\n// ---------------------------------------------------------------------------\n\nexport interface SeqTable {\n readonly kind: typeof TABLE_BRAND\n readonly tableName: string\n readonly columns: Readonly<Record<string, ColumnBuilder>>\n readonly config: TableConfig\n /** Synced reflected source (`gold.*`) — set only by defineSyncedTable. */\n readonly source: string | undefined\n /** Consumer file that defined the table (set when loaded via loadNamespaceFromDir). */\n readonly file: string | undefined\n}\n\nexport function isSeqTable(value: unknown): value is SeqTable {\n return typeof value === 'object' && value !== null && (value as { kind?: unknown }).kind === TABLE_BRAND\n}\n\nfunction assertIdentifier({ value, what, file }: { value: string; what: string; file: string | undefined }): void {\n if (!IDENTIFIER_PATTERN.test(value) || value.length > MAX_IDENTIFIER_LENGTH) {\n throw new OrmDefinitionError(\n `${what} \"${value}\" must match ${IDENTIFIER_PATTERN} and be at most ${MAX_IDENTIFIER_LENGTH} characters`,\n file,\n )\n }\n}\n\nexport function defineTable(\n name: string,\n columns: Record<string, ColumnBuilder>,\n config: TableConfig = {},\n): SeqTable {\n const file = activeAuthoringContext()?.currentFile\n assertIdentifier({ value: name, what: 'table name', file })\n\n const entries = Object.entries(columns)\n if (entries.length === 0) {\n throw new OrmDefinitionError(`table \"${name}\" declares no columns`, file)\n }\n\n const seenColumnNames = new Map<string, string>()\n for (const [propertyName, builder] of entries) {\n if (!isColumnBuilder(builder)) {\n throw new OrmDefinitionError(\n `table \"${name}\": column \"${propertyName}\" is not a column builder — use the t.* factories (t.uuid(), t.text(), …)`,\n file,\n )\n }\n const columnName = builder.columnNameFor(propertyName)\n assertIdentifier({ value: columnName, what: `table \"${name}\": column \"${propertyName}\" column name`, file })\n const existing = seenColumnNames.get(columnName)\n if (existing !== undefined) {\n throw new OrmDefinitionError(\n `table \"${name}\": columns \"${existing}\" and \"${propertyName}\" both map to Postgres column \"${columnName}\"`,\n file,\n )\n }\n seenColumnNames.set(columnName, propertyName)\n }\n\n const table: SeqTable = { kind: TABLE_BRAND, tableName: name, columns, config, source: undefined, file }\n registerTable(table)\n return table\n}\n\nexport interface SyncedTableConfig {\n /** Reflected read-only source, restricted to the gold layer: `gold.<table>`. */\n source: string\n description?: string\n}\n\nexport function defineSyncedTable(name: string, config: SyncedTableConfig): SeqTable {\n const file = activeAuthoringContext()?.currentFile\n assertIdentifier({ value: name, what: 'table name', file })\n if (!SYNCED_SOURCE_PATTERN.test(config.source)) {\n throw new OrmDefinitionError(\n `synced table \"${name}\": source \"${config.source}\" must match ${SYNCED_SOURCE_PATTERN} (gold layer only)`,\n file,\n )\n }\n const table: SeqTable = {\n kind: TABLE_BRAND,\n tableName: name,\n columns: {},\n config: config.description !== undefined ? { description: config.description } : {},\n source: config.source,\n file,\n }\n registerTable(table)\n return table\n}\n\n// ---------------------------------------------------------------------------\n// Enums\n// ---------------------------------------------------------------------------\n\nexport function defineEnum(name: string, values: readonly string[]): EnumRef {\n const file = activeAuthoringContext()?.currentFile\n assertIdentifier({ value: name, what: 'enum name', file })\n if (values.length === 0 || values.length > 100) {\n throw new OrmDefinitionError(`enum \"${name}\" must declare between 1 and 100 values`, file)\n }\n const seen = new Set<string>()\n for (const value of values) {\n if (value.length === 0 || value.length > MAX_IDENTIFIER_LENGTH) {\n throw new OrmDefinitionError(\n `enum \"${name}\": value ${JSON.stringify(value)} must be 1-${MAX_IDENTIFIER_LENGTH} characters`,\n file,\n )\n }\n if (seen.has(value)) {\n throw new OrmDefinitionError(`enum \"${name}\" declares duplicate value \"${value}\"`, file)\n }\n seen.add(value)\n }\n const ref: EnumRef = { kind: ENUM_BRAND, name, values: [...values] }\n registerEnum(ref)\n return ref\n}\n","/**\n * Canonical namespace definition v2 — the data-only JSON a consumer's\n * TypeScript schema serializes to. This is v2's equivalent of the v1 YAML\n * `NamespaceDefinition`: the CLI's jiti loader produces it, the content hash\n * is computed over it, the server re-validates it (consumer TS never runs\n * server-side), and the SDL generator / GraphQL compiler / migration engine\n * all consume it.\n *\n * FROZEN CONTRACT (week 1): downstream tracks build against these shapes.\n * Additive evolution only; `definition_format` discriminates on the wire.\n */\nimport { z } from 'zod'\n\nexport const CANONICAL_FORMAT = 2 as const\n\n/** Identifier grammar shared with v1 (`^[a-z][a-z0-9_]*$`, ≤63 bytes). */\nexport const IDENTIFIER_RE = /^[a-z][a-z0-9_]*$/\nconst identifier = z.string().min(1).max(63).regex(IDENTIFIER_RE)\n\n/** The 10 v1 column types, unchanged in v2. */\nexport const COLUMN_TYPES = [\n 'uuid', 'text', 'integer', 'bigint', 'numeric', 'double',\n 'boolean', 'timestamptz', 'date', 'jsonb',\n] as const\nexport type ColumnType = (typeof COLUMN_TYPES)[number]\n\nconst columnTypeSchema = z.enum(COLUMN_TYPES)\n\n/** Enum columns reference a namespace-level `defineEnum` by name. */\nexport const canonicalEnumSchema = z.object({\n name: identifier,\n values: z.array(z.string().min(1).max(63)).min(1).max(100),\n})\nexport type CanonicalEnum = z.infer<typeof canonicalEnumSchema>\n\nexport const canonicalColumnSchema = z.object({\n /** Property name in TS (camelCase); columnName is the Postgres name. */\n name: z.string().min(1).max(63),\n columnName: identifier,\n type: z.union([columnTypeSchema, z.object({ enum: identifier })]),\n nullable: z.boolean().default(true),\n unique: z.boolean().default(false),\n /** Literal default, or one of the allowlisted SQL functions. */\n default: z.union([z.string(), z.number(), z.boolean(), z.null()]).optional(),\n defaultFn: z.enum(['gen_random_uuid()', 'now()']).optional(),\n description: z.string().max(500).optional(),\n /** Migration hints — same semantics as v1. */\n renamedFrom: identifier.optional(),\n cast: z.string().max(200).optional(),\n deprecated: z.boolean().default(false),\n})\nexport type CanonicalColumn = z.infer<typeof canonicalColumnSchema>\n\nexport const canonicalLinkSchema = z.object({\n name: z.string().min(1).max(63),\n kind: z.enum(['toOne', 'toMany', 'toPlatformUser']),\n /** Target table name (namespace-local). Absent for toPlatformUser. */\n target: identifier.optional(),\n /** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */\n on: identifier,\n /** Referenced column on the target (default: target's PK / platform user `sub`). */\n references: identifier.optional(),\n /** enforce: true emits a real FK constraint (same-namespace toOne only). */\n enforce: z.boolean().default(false),\n description: z.string().max(500).optional(),\n})\nexport type CanonicalLink = z.infer<typeof canonicalLinkSchema>\n\nexport const canonicalIndexSchema = z.object({\n columns: z.array(identifier).min(1),\n unique: z.boolean().default(false),\n name: identifier.optional(),\n})\n\n/**\n * Policy expressions stay DSL SOURCE STRINGS in the canonical form — parsing\n * and claim-key validation happen in both CLI and server via the shared\n * predicate parser. Variants follow §4c permissive-union semantics.\n */\nexport const policyVariantSchema = z.object({\n /** Claims-only guard (capability()/role()/claim() comparisons — no columns). */\n when: z.string().min(1).max(1000),\n /** Exactly one of: allow-all bypass, or a row predicate. */\n allow: z.literal(true).optional(),\n policy: z.string().min(1).max(2000).optional(),\n}).refine((v) => (v.allow === true) !== (typeof v.policy === 'string'), {\n message: 'A variant declares exactly one of allow: true or policy',\n})\n\nexport const policyExpressionSchema = z.union([\n z.string().min(1).max(2000),\n z.object({\n default: z.string().min(1).max(2000),\n variants: z.array(policyVariantSchema).max(10).default([]),\n }),\n])\nexport type PolicyExpression = z.infer<typeof policyExpressionSchema>\n\nexport const canonicalPoliciesSchema = z.object({\n read: policyExpressionSchema.optional(),\n write: policyExpressionSchema.optional(),\n})\n\n/** Actions carry over from v1 as compiled named-SQL ops (plan: resolved OQ-1). */\nexport const canonicalActionSchema = z.object({\n name: identifier,\n requires: z.string().max(1000).optional(),\n params: z.record(z.string(), z.object({\n type: columnTypeSchema,\n nullable: z.boolean().default(false),\n })).default({}),\n executes: z.string().min(1).max(10_000),\n returns: z.enum(['rows', 'rowsAffected', 'scalar']).default('rowsAffected'),\n audit: z.object({ action: z.string(), resource: z.string() }).optional(),\n})\n\nexport const canonicalTableSchema = z.object({\n table: identifier,\n description: z.string().max(2000).optional(),\n /** Table-level rename hint (new in v2). */\n renamedFrom: identifier.optional(),\n /** Synced/reflected read-only tables (`source: gold.*`) — v1 semantics. */\n source: z.string().regex(/^gold\\.[a-z][a-z0-9_]*$/).optional(),\n columns: z.array(canonicalColumnSchema).default([]),\n primaryKey: z.array(identifier).min(1).max(8).optional(),\n links: z.array(canonicalLinkSchema).default([]),\n indexes: z.array(canonicalIndexSchema).default([]),\n policies: canonicalPoliciesSchema.default({}),\n actions: z.array(canonicalActionSchema).default([]),\n})\nexport type CanonicalTable = z.infer<typeof canonicalTableSchema>\n\nexport const canonicalDefinitionSchema = z.object({\n definition_format: z.literal(CANONICAL_FORMAT),\n namespace: identifier.max(41),\n description: z.string().max(2000).optional(),\n enums: z.array(canonicalEnumSchema).default([]),\n tables: z.array(canonicalTableSchema).min(0).max(500),\n /** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */\n capabilities: z.object({\n roles: z.unknown().optional(),\n uses: z.array(z.string()).default([]),\n }).default({ uses: [] }),\n})\nexport type CanonicalDefinition = z.infer<typeof canonicalDefinitionSchema>\n\n/**\n * Deterministic serialization discipline: tables sorted by name, columns in\n * declaration order (order is meaningful for DDL), links/indexes/actions\n * sorted by name, object keys emitted in schema order. `serializeNamespace`\n * (authoring layer) and the server-side re-validation both normalize through\n * this function before hashing so CLI and server hash identical bytes.\n */\nexport function normalizeCanonical(definition: CanonicalDefinition): CanonicalDefinition {\n const sortByName = <T extends { name: string }>(items: T[]): T[] =>\n [...items].sort((a, b) => a.name.localeCompare(b.name))\n return {\n ...definition,\n enums: sortByName(definition.enums),\n tables: [...definition.tables]\n .sort((a, b) => a.table.localeCompare(b.table))\n .map((t) => ({\n ...t,\n links: sortByName(t.links),\n indexes: [...t.indexes].sort((a, b) =>\n (a.name ?? a.columns.join('_')).localeCompare(b.name ?? b.columns.join('_'))),\n actions: sortByName(t.actions),\n })),\n }\n}\n","import { createHash } from 'node:crypto'\nimport { HASH_DOMAIN } from './constants.js'\nimport type { NamespaceCapabilities, NamespaceDefinition } from './schema/namespace.js'\nimport type { TableFile } from './schema/table.js'\n\ntype JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue }\n\n/** `Object.entries` widens Zod record values to `unknown` under tsup's DTS check. */\ntype RoleDefinition = NonNullable<NamespaceCapabilities['roles']['definitions'][string]>\ntype CapabilityDeclaration = NonNullable<NamespaceCapabilities['roles']['capabilities'][string]>\n\n/** Key-sorted, undefined-skipped JSON — identical definitions hash identically regardless of YAML key order. */\nexport function stableJson(value: unknown): string {\n if (value === null || typeof value !== 'object') return JSON.stringify(value)\n if (Array.isArray(value)) return `[${value.map(stableJson).join(',')}]`\n const entries = Object.entries(value as Record<string, unknown>)\n .filter(([, entryValue]) => entryValue !== undefined)\n .sort(([a], [b]) => (a < b ? -1 : 1))\n .map(([key, entryValue]) => `${JSON.stringify(key)}:${stableJson(entryValue)}`)\n return `{${entries.join(',')}}`\n}\n\n/** Empty collections hash as omitted — `indexes: []` and no indexes are the same definition. */\nfunction emptyToNull(value: unknown): JsonValue {\n if (value == null) return null\n if (Array.isArray(value)) return value.length === 0 ? null : (value as JsonValue)\n if (typeof value === 'object' && Object.keys(value).length === 0) return null\n return value as JsonValue\n}\n\n/** Predicates hash by their source text; parsed ASTs are derived and excluded. */\nfunction canonicalTable(table: TableFile): JsonValue {\n return {\n table: table.table,\n description: table.description ?? null,\n columns: (table.columns ?? null) as JsonValue,\n source: table.source ?? null,\n links: emptyToNull(table.links),\n indexes: emptyToNull(table.indexes),\n policies: {\n read: table.policies?.read?.source ?? null,\n write: table.policies?.write?.source ?? null,\n },\n actions: emptyToNull(\n Object.fromEntries(\n Object.entries(table.actions ?? {}).map(([name, action]) => [\n name,\n {\n description: action.description ?? null,\n requires: action.requires?.source ?? null,\n params: emptyToNull(action.params),\n validates: emptyToNull(action.validates?.map((entry) => entry.source)),\n executes: action.executes,\n returns: emptyToNull(action.returns),\n audit: (action.audit ?? null) as JsonValue,\n },\n ]),\n ),\n ),\n }\n}\n\n/**\n * The capabilities block, canonicalized: record keys sort via stableJson, and\n * we sort every array (uses, each role's inherits/grants) so authoring order\n * never changes the hash. Absent optional descriptions are omitted, not null,\n * so the canonical block round-trips back through the manifest schema. An empty\n * block hashes as omitted — \"no capabilities\" and an empty block are the same.\n */\nfunction canonicalCapabilities(capabilities: NamespaceCapabilities): JsonValue {\n const { definitions, capabilities: declared } = capabilities.roles\n const isEmpty =\n Object.keys(definitions).length === 0 && Object.keys(declared).length === 0 && capabilities.uses.length === 0\n if (isEmpty) return null\n // JSON-safe by construction (omitted optionals are dropped by stableJson); the\n // conditional spreads defeat structural inference, so assert the JsonValue shape.\n return {\n roles: {\n definitions: Object.fromEntries(\n (Object.entries(definitions) as [string, RoleDefinition][]).map(([key, def]) => [\n key,\n {\n ...(def.description !== undefined ? { description: def.description } : {}),\n default: def.default,\n inherits: [...def.inherits].sort(),\n grants: [...def.grants].sort(),\n },\n ]),\n ),\n capabilities: Object.fromEntries(\n (Object.entries(declared) as [string, CapabilityDeclaration][]).map(([key, cap]) => [\n key,\n cap.description !== undefined ? { description: cap.description } : {},\n ]),\n ),\n },\n uses: [...capabilities.uses].sort(),\n } as JsonValue\n}\n\nexport function canonicalizeDefinition(definition: NamespaceDefinition): JsonValue {\n return {\n namespace: definition.namespace,\n description: definition.description,\n capabilities: canonicalCapabilities(definition.capabilities),\n tables: definition.tables.map(canonicalTable),\n }\n}\n\nexport function computeDefinitionHash(definition: NamespaceDefinition): string {\n return createHash('sha256')\n .update(HASH_DOMAIN)\n .update(stableJson(canonicalizeDefinition(definition)))\n .digest('hex')\n}\n","/**\n * `defineNamespace` + `serializeNamespace` — the bridge from the authoring\n * surface to canonical definition v2. Serialization is deterministic\n * (`normalizeCanonical` ordering, zod defaults materialized) so the CLI and\n * the server hash identical bytes; `computeCanonicalHash` reuses the v1\n * canonical-hash helper (`stableJson` + HASH_DOMAIN) over the normalized\n * canonical JSON.\n *\n * Every definition-time validation error names the offending table (and the\n * consumer file when loaded via `loadNamespaceFromDir`).\n */\nimport { createHash } from 'node:crypto'\nimport { z } from 'zod'\nimport {\n CANONICAL_FORMAT,\n canonicalDefinitionSchema,\n canonicalLinkSchema,\n canonicalTableSchema,\n normalizeCanonical,\n type CanonicalDefinition,\n type CanonicalEnum,\n type CanonicalTable,\n type PolicyExpression,\n} from '../canonical/v2.js'\nimport { HASH_DOMAIN, NAMESPACE_PATTERN } from '../constants.js'\nimport { OrmDefinitionError } from '../errors.js'\nimport { stableJson } from '../hash.js'\nimport { deriveColumnName, type EnumRef } from './columns.js'\nimport { registerNamespaceConfig, activeAuthoringContext } from './registry.js'\nimport { isSeqTable, type PolicyInput, type SeqLink, type SeqTable, type TableRef } from './table.js'\n\nexport const NAMESPACE_CONFIG_BRAND = 'seq-namespace-config' as const\n\nexport interface NamespaceCapabilitiesInput {\n /** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */\n roles?: unknown\n /** Org-level capability pins this namespace attaches to. */\n uses?: readonly string[]\n}\n\nexport interface NamespaceConfigInput {\n namespace: string\n description?: string\n capabilities?: NamespaceCapabilitiesInput\n}\n\nexport interface SeqNamespaceConfig {\n readonly kind: typeof NAMESPACE_CONFIG_BRAND\n readonly namespace: string\n readonly description: string | undefined\n readonly capabilities: NamespaceCapabilitiesInput\n readonly file: string | undefined\n}\n\nexport function isSeqNamespaceConfig(value: unknown): value is SeqNamespaceConfig {\n return (\n typeof value === 'object' && value !== null && (value as { kind?: unknown }).kind === NAMESPACE_CONFIG_BRAND\n )\n}\n\nexport function defineNamespace(input: NamespaceConfigInput): SeqNamespaceConfig {\n const file = activeAuthoringContext()?.currentFile\n if (!NAMESPACE_PATTERN.test(input.namespace)) {\n throw new OrmDefinitionError(`namespace \"${input.namespace}\" must match ${NAMESPACE_PATTERN}`, file)\n }\n const config: SeqNamespaceConfig = {\n kind: NAMESPACE_CONFIG_BRAND,\n namespace: input.namespace,\n description: input.description,\n capabilities: input.capabilities ?? {},\n file,\n }\n registerNamespaceConfig(config)\n return config\n}\n\n// ---------------------------------------------------------------------------\n// Serialization\n// ---------------------------------------------------------------------------\n\nexport interface SerializeNamespaceInput {\n config: SeqNamespaceConfig\n tables: readonly SeqTable[]\n enums?: readonly EnumRef[]\n}\n\n/**\n * Serialize the authored namespace to a validated, normalized\n * `CanonicalDefinition` (definition_format: 2). Throws `OrmDefinitionError`\n * naming the table/file on any inconsistency.\n */\nexport function serializeNamespace(input: SerializeNamespaceInput): CanonicalDefinition {\n const { config, tables } = input\n const enums = input.enums ?? []\n\n const tablesByName = new Map<string, SeqTable>()\n for (const table of tables) {\n const existing = tablesByName.get(table.tableName)\n if (existing) {\n throw new OrmDefinitionError(\n `duplicate table \"${table.tableName}\" (defined in ${describeFile(existing)} and ${describeFile(table)})`,\n table.file,\n )\n }\n tablesByName.set(table.tableName, table)\n }\n\n const enumsByName = new Map<string, EnumRef>()\n for (const ref of enums) {\n if (enumsByName.has(ref.name)) {\n throw new OrmDefinitionError(`duplicate enum \"${ref.name}\"`, config.file)\n }\n enumsByName.set(ref.name, ref)\n }\n\n const canonicalTables = tables.map((table) => buildCanonicalTable({ table, tablesByName, enumsByName }))\n const canonicalEnums: CanonicalEnum[] = [...enumsByName.values()].map((ref) => ({\n name: ref.name,\n values: [...ref.values],\n }))\n\n const candidate: z.input<typeof canonicalDefinitionSchema> = {\n definition_format: CANONICAL_FORMAT,\n namespace: config.namespace,\n enums: canonicalEnums,\n tables: canonicalTables,\n capabilities: {\n ...(config.capabilities.roles !== undefined ? { roles: config.capabilities.roles } : {}),\n uses: [...(config.capabilities.uses ?? [])],\n },\n }\n if (config.description !== undefined) candidate.description = config.description\n\n let parsed: CanonicalDefinition\n try {\n parsed = canonicalDefinitionSchema.parse(candidate)\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new OrmDefinitionError(`namespace \"${config.namespace}\": ${formatZodIssues(error)}`, config.file)\n }\n throw error\n }\n return normalizeCanonical(parsed)\n}\n\n/** sha256 over the v1 hash domain + key-sorted JSON of the normalized canonical definition. */\nexport function computeCanonicalHash(definition: CanonicalDefinition): string {\n return createHash('sha256').update(HASH_DOMAIN).update(stableJson(definition)).digest('hex')\n}\n\n// ---------------------------------------------------------------------------\n// Per-table serialization\n// ---------------------------------------------------------------------------\n\ninterface TableBuildContext {\n table: SeqTable\n tablesByName: Map<string, SeqTable>\n enumsByName: Map<string, EnumRef>\n}\n\nfunction buildCanonicalTable({ table, tablesByName, enumsByName }: TableBuildContext): CanonicalTable {\n const candidate: z.input<typeof canonicalTableSchema> = {\n table: table.tableName,\n columns: [],\n links: [],\n indexes: [],\n policies: {},\n actions: [],\n }\n if (table.config.description !== undefined) candidate.description = table.config.description\n if (table.config.renamedFrom !== undefined) candidate.renamedFrom = table.config.renamedFrom\n if (table.source !== undefined) candidate.source = table.source\n\n // Columns — declaration order is meaningful for DDL.\n const columnLevelPk: string[] = []\n for (const [propertyName, builder] of Object.entries(table.columns)) {\n const column = builder.toCanonicalColumn(propertyName)\n const enumName = builder.enumName\n if (enumName !== undefined && !enumsByName.has(enumName)) {\n throw new OrmDefinitionError(\n `table \"${table.tableName}\": column \"${propertyName}\" references enum \"${enumName}\" which is not passed to serializeNamespace — declare it with defineEnum and include it`,\n table.file,\n )\n }\n if (builder.isPrimaryKey) columnLevelPk.push(column.columnName)\n candidate.columns?.push(column)\n }\n\n // Primary key — column-level `.primaryKey()` or config-level composite, never both.\n if (table.config.primaryKey !== undefined) {\n if (columnLevelPk.length > 0) {\n throw new OrmDefinitionError(\n `table \"${table.tableName}\": declare the primary key either with .primaryKey() on columns or with config.primaryKey — not both`,\n table.file,\n )\n }\n candidate.primaryKey = table.config.primaryKey.map((ref) =>\n resolveColumnRef({ table, ref, role: 'primaryKey' }),\n )\n } else if (columnLevelPk.length > 0) {\n candidate.primaryKey = columnLevelPk\n }\n\n // Indexes.\n for (const index of table.config.indexes ?? []) {\n const entry: { columns: string[]; unique?: boolean; name?: string } = {\n columns: index.columns.map((ref) => resolveColumnRef({ table, ref, role: 'index' })),\n }\n if (index.unique !== undefined) entry.unique = index.unique\n if (index.name !== undefined) entry.name = index.name\n candidate.indexes?.push(entry)\n }\n\n // Links.\n for (const [linkName, link] of Object.entries(table.config.links ?? {})) {\n candidate.links?.push(buildCanonicalLink({ table, linkName, link, tablesByName }))\n }\n\n // Policies — DSL source strings pass through; variants validated by the canonical schema.\n const policies: { read?: PolicyExpression; write?: PolicyExpression } = {}\n if (table.config.policies?.read !== undefined) policies.read = toCanonicalPolicy(table.config.policies.read)\n if (table.config.policies?.write !== undefined) policies.write = toCanonicalPolicy(table.config.policies.write)\n candidate.policies = policies\n\n // Actions.\n for (const action of table.config.actions ?? []) {\n candidate.actions?.push({\n name: action.name,\n ...(action.requires !== undefined ? { requires: action.requires } : {}),\n params: Object.fromEntries(\n Object.entries(action.params ?? {}).map(([name, param]) => [\n name,\n { type: param.type, nullable: param.nullable ?? false },\n ]),\n ),\n executes: action.executes,\n returns: action.returns ?? 'rowsAffected',\n ...(action.audit !== undefined ? { audit: action.audit } : {}),\n })\n }\n\n try {\n return canonicalTableSchema.parse(candidate)\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new OrmDefinitionError(`table \"${table.tableName}\": ${formatZodIssues(error)}`, table.file)\n }\n throw error\n }\n}\n\nfunction buildCanonicalLink({\n table,\n linkName,\n link,\n tablesByName,\n}: {\n table: SeqTable\n linkName: string\n link: SeqLink\n tablesByName: Map<string, SeqTable>\n}): z.input<typeof canonicalLinkSchema> {\n const fail = (message: string): never => {\n throw new OrmDefinitionError(`table \"${table.tableName}\": link \"${linkName}\" ${message}`, table.file)\n }\n\n if (link.enforce && link.linkKind !== 'toOne') {\n return fail('sets enforce: true, which is only supported on toOne links')\n }\n\n if (link.linkKind === 'toPlatformUser') {\n if (link.target !== undefined) return fail('is toPlatformUser and must not declare a target table')\n return {\n name: linkName,\n kind: 'toPlatformUser',\n on: resolveColumnRef({ table, ref: link.on, role: `link \"${linkName}\" on` }),\n ...(link.references !== undefined ? { references: deriveColumnName(link.references) } : {}),\n enforce: false,\n ...(link.description !== undefined ? { description: link.description } : {}),\n }\n }\n\n const target = resolveTableRef({ ref: link.target, fail })\n if (!tablesByName.has(target.tableName)) {\n return fail(`targets table \"${target.tableName}\" which is not part of this namespace`)\n }\n\n // toOne: FK column lives on this table; toMany: on the target.\n const owningSide = link.linkKind === 'toOne' ? table : target\n return {\n name: linkName,\n kind: link.linkKind,\n target: target.tableName,\n on: resolveColumnRef({ table: owningSide, ref: link.on, role: `link \"${linkName}\" on` }),\n ...(link.references !== undefined\n ? { references: resolveColumnRef({ table: target, ref: link.references, role: `link \"${linkName}\" references` }) }\n : {}),\n enforce: link.enforce,\n ...(link.description !== undefined ? { description: link.description } : {}),\n }\n}\n\nfunction resolveTableRef({ ref, fail }: { ref: TableRef | undefined; fail: (message: string) => never }): SeqTable {\n if (ref === undefined) return fail('declares no target table')\n if (typeof ref !== 'function') return ref\n let resolved: unknown\n try {\n resolved = ref()\n } catch (error) {\n return fail(\n `target thunk threw (${error instanceof Error ? error.message : String(error)}) — lazy refs resolve at serialize time; make sure the target module ran`,\n )\n }\n if (!isSeqTable(resolved)) return fail('target thunk did not return a table defined with defineTable')\n return resolved\n}\n\n/**\n * Resolve a column reference that may be a TS property name (camelCase) or\n * an actual Postgres column name.\n */\nfunction resolveColumnRef({ table, ref, role }: { table: SeqTable; ref: string; role: string }): string {\n const direct = table.columns[ref]\n if (direct) return direct.columnNameFor(ref)\n for (const [propertyName, builder] of Object.entries(table.columns)) {\n if (builder.columnNameFor(propertyName) === ref) return ref\n }\n const known = Object.keys(table.columns).join(', ')\n throw new OrmDefinitionError(\n `table \"${table.tableName}\": ${role} references unknown column \"${ref}\" (known columns: ${known || 'none'})`,\n table.file,\n )\n}\n\nfunction toCanonicalPolicy(policy: PolicyInput): PolicyExpression {\n if (typeof policy === 'string') return policy\n return {\n default: policy.default,\n variants: (policy.variants ?? []).map((variant) => ({\n when: variant.when,\n ...(variant.allow === true ? { allow: true as const } : {}),\n ...(variant.policy !== undefined ? { policy: variant.policy } : {}),\n })),\n }\n}\n\nfunction describeFile(table: SeqTable): string {\n return table.file ?? '<unknown file>'\n}\n\nfunction formatZodIssues(error: z.ZodError): string {\n return error.issues\n .map((issue) => (issue.path.length > 0 ? `${issue.path.join('.')}: ${issue.message}` : issue.message))\n .join('; ')\n}\n","/**\n * `loadNamespaceFromDir` — the CLI-side loader that imports a consumer\n * namespace directory (`sequence.config.ts` + `schema/*.ts`) via jiti and\n * collects the `defineNamespace` / `defineTable` / `defineEnum`\n * registrations (module-registry pattern; see registry.ts).\n *\n * jiti caveats this file owns:\n * - jiti evaluates its OWN transpiled copy of '@sequenceholdings/orm' for\n * consumer imports; registrations still land in the shared globalThis\n * context (registry.ts).\n * - jiti populates the native CJS module cache, so files under the loaded\n * directory are PURGED from `require.cache` before each load — repeated\n * loads re-evaluate consumer modules (determinism checks, watch loops)\n * while intra-load imports still deduplicate (a schema file imported by a\n * sibling AND by the loader evaluates exactly once per load).\n */\nimport { createJiti } from 'jiti'\nimport { readdir, realpath, stat } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport { join, sep } from 'node:path'\nimport { OrmDefinitionError } from '../errors.js'\nimport type { CanonicalDefinition } from '../canonical/v2.js'\nimport { isEnumRef, type EnumRef } from './columns.js'\nimport {\n computeCanonicalHash,\n isSeqNamespaceConfig,\n serializeNamespace,\n type SeqNamespaceConfig,\n} from './namespace.js'\nimport { beginAuthoringContext, endAuthoringContext } from './registry.js'\nimport { isSeqTable, type SeqTable } from './table.js'\n\nexport const NAMESPACE_CONFIG_FILE = 'sequence.config.ts'\nexport const SCHEMA_DIR = 'schema'\n\nexport interface LoadNamespaceOptions {\n /**\n * Test/dev hook: absolute path that bare `'@sequenceholdings/orm'` imports\n * in consumer files resolve to (jiti alias). Leave unset in production —\n * the consumer's own installed package resolves naturally.\n */\n ormModulePath?: string\n}\n\nexport interface LoadedNamespaceV2 {\n readonly canonical: CanonicalDefinition\n readonly hash: string\n /** Relative paths of the files that were imported, config first. */\n readonly files: readonly string[]\n}\n\nexport async function loadNamespaceFromDir(\n dir: string,\n options: LoadNamespaceOptions = {},\n): Promise<LoadedNamespaceV2> {\n const root = await realpath(dir).catch(() => {\n throw new OrmDefinitionError(`namespace directory not found: ${dir}`)\n })\n\n const configPath = join(root, NAMESPACE_CONFIG_FILE)\n const configStat = await stat(configPath).catch(() => undefined)\n if (!configStat?.isFile()) {\n throw new OrmDefinitionError(`${NAMESPACE_CONFIG_FILE} not found in ${dir}`)\n }\n\n const schemaFiles = await listSchemaFiles(root)\n const files = [NAMESPACE_CONFIG_FILE, ...schemaFiles]\n\n purgeModuleCache(root)\n\n const jiti = createJiti(import.meta.url, {\n interopDefault: true,\n fsCache: false,\n ...(options.ormModulePath !== undefined\n ? { alias: { '@sequenceholdings/orm': options.ormModulePath } }\n : {}),\n })\n\n const context = beginAuthoringContext()\n try {\n for (const file of files) {\n context.currentFile = file\n try {\n await jiti.import(join(root, file))\n } catch (error) {\n // Cross-copy safe: the jiti copy's OrmDefinitionError is a different\n // class object, so match by name, never instanceof.\n if (error instanceof Error && error.name === 'OrmDefinitionError') throw error\n throw new OrmDefinitionError(\n `failed to load: ${error instanceof Error ? error.message : String(error)}`,\n file,\n )\n }\n }\n } finally {\n context.currentFile = undefined\n endAuthoringContext(context)\n }\n\n const configs: Array<{ value: SeqNamespaceConfig; file: string | undefined }> = []\n for (const entry of context.configs) {\n if (isSeqNamespaceConfig(entry.value)) configs.push({ value: entry.value, file: entry.file })\n }\n const configEntry = configs[0]\n if (!configEntry) {\n throw new OrmDefinitionError(\n 'no namespace config registered — sequence.config.ts must call defineNamespace(...) at import time',\n NAMESPACE_CONFIG_FILE,\n )\n }\n if (configs.length > 1) {\n const where = configs.map((entry) => entry.file ?? '<unknown file>').join(', ')\n throw new OrmDefinitionError(\n `defineNamespace called ${configs.length} times (${where}) — declare exactly one namespace config`,\n )\n }\n\n const tables: SeqTable[] = []\n for (const entry of context.tables) {\n if (isSeqTable(entry.value)) tables.push(entry.value)\n }\n if (tables.length === 0) {\n throw new OrmDefinitionError(\n `no tables registered — ${SCHEMA_DIR}/*.ts modules must call defineTable(...) at import time`,\n )\n }\n\n const enums: EnumRef[] = []\n for (const entry of context.enums) {\n if (isEnumRef(entry.value)) enums.push(entry.value)\n }\n\n const canonical = serializeNamespace({ config: configEntry.value, tables, enums })\n return { canonical, hash: computeCanonicalHash(canonical), files }\n}\n\nasync function listSchemaFiles(root: string): Promise<string[]> {\n const schemaDir = join(root, SCHEMA_DIR)\n const entries = await readdir(schemaDir, { withFileTypes: true }).catch(() => [])\n return entries\n .filter(\n (entry) =>\n entry.isFile() && entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts') && !entry.name.startsWith('.'),\n )\n .map((entry) => join(SCHEMA_DIR, entry.name))\n .sort()\n}\n\n/** Drop the directory's modules from the native CJS cache so a re-load re-evaluates them. */\nfunction purgeModuleCache(root: string): void {\n const require = createRequire(import.meta.url)\n const prefix = root.endsWith(sep) ? root : `${root}${sep}`\n for (const key of Object.keys(require.cache)) {\n if (key.startsWith(prefix)) delete require.cache[key]\n }\n}\n"]}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { ColumnType, CanonicalColumn, CanonicalDefinition } from './canonical.cjs';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fluent column builders for the v2 authoring surface — `t.uuid()`,
|
|
6
|
+
* `t.text().notNull().unique()`, `t.enum(status).default('open')`, …
|
|
7
|
+
*
|
|
8
|
+
* Builders carry plain serializable state and produce `CanonicalColumn` data
|
|
9
|
+
* (canonical definition v2). They never touch Drizzle: the server builds
|
|
10
|
+
* Drizzle entities from canonical JSON, consumer TypeScript never runs
|
|
11
|
+
* server-side (plan §2).
|
|
12
|
+
*
|
|
13
|
+
* Cross-copy safety: the jiti loader evaluates its own transpiled copy of
|
|
14
|
+
* this module, so identification uses the `kind` brand — never `instanceof`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare const COLUMN_BRAND: "seq-column";
|
|
18
|
+
declare const ENUM_BRAND: "seq-enum";
|
|
19
|
+
/** A namespace-level Postgres enum, created with `defineEnum` (table.ts). */
|
|
20
|
+
interface EnumRef {
|
|
21
|
+
readonly kind: typeof ENUM_BRAND;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly values: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
declare function isEnumRef(value: unknown): value is EnumRef;
|
|
26
|
+
/** The allowlisted SQL default functions — `.default('now()')` maps here, not to a literal. */
|
|
27
|
+
declare const COLUMN_DEFAULT_FNS: readonly ["gen_random_uuid()", "now()"];
|
|
28
|
+
type ColumnDefaultFn = (typeof COLUMN_DEFAULT_FNS)[number];
|
|
29
|
+
type ColumnDefaultLiteral = string | number | boolean | null;
|
|
30
|
+
type ColumnTypeSpec = ColumnType | {
|
|
31
|
+
readonly enum: string;
|
|
32
|
+
};
|
|
33
|
+
/** `authorSub` → `author_sub`, `authorURLPath` → `author_url_path`. */
|
|
34
|
+
declare function deriveColumnName(propertyName: string): string;
|
|
35
|
+
declare class ColumnBuilder {
|
|
36
|
+
readonly kind: "seq-column";
|
|
37
|
+
private readonly state;
|
|
38
|
+
constructor(type: ColumnTypeSpec, columnName?: string);
|
|
39
|
+
/** Marks this column as (part of) the primary key. Implies NOT NULL. */
|
|
40
|
+
primaryKey(): this;
|
|
41
|
+
notNull(): this;
|
|
42
|
+
unique(): this;
|
|
43
|
+
/**
|
|
44
|
+
* Column default: a literal, or one of the allowlisted SQL functions
|
|
45
|
+
* (`'gen_random_uuid()'` / `'now()'`), which serialize as `defaultFn`.
|
|
46
|
+
*/
|
|
47
|
+
default(value: ColumnDefaultLiteral): this;
|
|
48
|
+
description(text: string): this;
|
|
49
|
+
/** Migration rename hint: the previous Postgres column name. */
|
|
50
|
+
renamedFrom(previousColumnName: string): this;
|
|
51
|
+
/** Migration cast hint: the `USING` SQL applied when this column changes type. */
|
|
52
|
+
cast(usingSql: string): this;
|
|
53
|
+
/** Emits `@deprecated` in the generated SDL; the column stays queryable. */
|
|
54
|
+
deprecated(): this;
|
|
55
|
+
/** Whether `.primaryKey()` was called — collected into the table-level PK. */
|
|
56
|
+
get isPrimaryKey(): boolean;
|
|
57
|
+
/** The enum name when this is an enum column, else undefined. */
|
|
58
|
+
get enumName(): string | undefined;
|
|
59
|
+
/** Postgres column name: explicit override, else snake_case of the property name. */
|
|
60
|
+
columnNameFor(propertyName: string): string;
|
|
61
|
+
/** Serialize to a canonical v2 column. Validation happens in serializeNamespace. */
|
|
62
|
+
toCanonicalColumn(propertyName: string): CanonicalColumn;
|
|
63
|
+
}
|
|
64
|
+
declare function isColumnBuilder(value: unknown): value is ColumnBuilder;
|
|
65
|
+
/**
|
|
66
|
+
* The column-type factory. The optional argument overrides the derived
|
|
67
|
+
* snake_case Postgres column name: `t.text('legacy_name')`.
|
|
68
|
+
*/
|
|
69
|
+
declare const t: {
|
|
70
|
+
readonly uuid: (columnName?: string) => ColumnBuilder;
|
|
71
|
+
readonly text: (columnName?: string) => ColumnBuilder;
|
|
72
|
+
readonly integer: (columnName?: string) => ColumnBuilder;
|
|
73
|
+
readonly bigint: (columnName?: string) => ColumnBuilder;
|
|
74
|
+
readonly numeric: (columnName?: string) => ColumnBuilder;
|
|
75
|
+
readonly double: (columnName?: string) => ColumnBuilder;
|
|
76
|
+
readonly boolean: (columnName?: string) => ColumnBuilder;
|
|
77
|
+
readonly timestamptz: (columnName?: string) => ColumnBuilder;
|
|
78
|
+
readonly date: (columnName?: string) => ColumnBuilder;
|
|
79
|
+
readonly jsonb: (columnName?: string) => ColumnBuilder;
|
|
80
|
+
readonly enum: (ref: EnumRef, columnName?: string) => ColumnBuilder;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
declare const TABLE_BRAND: "seq-table";
|
|
84
|
+
declare const LINK_BRAND: "seq-link";
|
|
85
|
+
/** A link target: the table itself, or a lazy thunk for forward/cyclic references. */
|
|
86
|
+
type TableRef = SeqTable | (() => SeqTable);
|
|
87
|
+
type LinkKind = 'toOne' | 'toMany' | 'toPlatformUser';
|
|
88
|
+
interface SeqLink {
|
|
89
|
+
readonly kind: typeof LINK_BRAND;
|
|
90
|
+
readonly linkKind: LinkKind;
|
|
91
|
+
/** Absent for toPlatformUser — the platform-users view needs no target. */
|
|
92
|
+
readonly target: TableRef | undefined;
|
|
93
|
+
/** FK column (property or column name). toOne/toPlatformUser: on this table; toMany: on the target. */
|
|
94
|
+
readonly on: string;
|
|
95
|
+
readonly references: string | undefined;
|
|
96
|
+
readonly enforce: boolean;
|
|
97
|
+
readonly description: string | undefined;
|
|
98
|
+
}
|
|
99
|
+
interface ToOneOptions {
|
|
100
|
+
on: string;
|
|
101
|
+
references?: string;
|
|
102
|
+
/** Emit a real FK constraint (same-namespace toOne only). */
|
|
103
|
+
enforce?: boolean;
|
|
104
|
+
description?: string;
|
|
105
|
+
}
|
|
106
|
+
interface ToManyOptions {
|
|
107
|
+
on: string;
|
|
108
|
+
references?: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
}
|
|
111
|
+
interface ToPlatformUserOptions {
|
|
112
|
+
/** Column on this table holding the platform user `sub` (or `references` override). */
|
|
113
|
+
on: string;
|
|
114
|
+
references?: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
}
|
|
117
|
+
declare function toOne(target: TableRef, options: ToOneOptions): SeqLink;
|
|
118
|
+
declare function toMany(target: TableRef, options: ToManyOptions): SeqLink;
|
|
119
|
+
/** Link to the built-in read-only platform-users view (plan §4b) — no table definition needed. */
|
|
120
|
+
declare function toPlatformUser(options: ToPlatformUserOptions): SeqLink;
|
|
121
|
+
declare function isSeqLink(value: unknown): value is SeqLink;
|
|
122
|
+
interface PolicyVariantInput {
|
|
123
|
+
/** Claims-only guard: `capability('x')` / `role('y')` / claim comparisons. */
|
|
124
|
+
when: string;
|
|
125
|
+
/** Exactly one of `allow: true` or `policy` (validated at serialize time). */
|
|
126
|
+
allow?: true;
|
|
127
|
+
policy?: string;
|
|
128
|
+
}
|
|
129
|
+
interface PolicyWithVariantsInput {
|
|
130
|
+
default: string;
|
|
131
|
+
variants?: readonly PolicyVariantInput[];
|
|
132
|
+
}
|
|
133
|
+
/** A policy: a DSL source string, or a default + per-role/capability variants (§4c). */
|
|
134
|
+
type PolicyInput = string | PolicyWithVariantsInput;
|
|
135
|
+
interface TablePoliciesInput {
|
|
136
|
+
read?: PolicyInput;
|
|
137
|
+
write?: PolicyInput;
|
|
138
|
+
}
|
|
139
|
+
interface IndexInput {
|
|
140
|
+
/** Property names (camelCase) or Postgres column names. */
|
|
141
|
+
columns: readonly string[];
|
|
142
|
+
unique?: boolean;
|
|
143
|
+
name?: string;
|
|
144
|
+
}
|
|
145
|
+
interface ActionParamInput {
|
|
146
|
+
type: ColumnType;
|
|
147
|
+
nullable?: boolean;
|
|
148
|
+
}
|
|
149
|
+
interface ActionInput {
|
|
150
|
+
name: string;
|
|
151
|
+
requires?: string;
|
|
152
|
+
params?: Record<string, ActionParamInput>;
|
|
153
|
+
executes: string;
|
|
154
|
+
returns?: 'rows' | 'rowsAffected' | 'scalar';
|
|
155
|
+
audit?: {
|
|
156
|
+
action: string;
|
|
157
|
+
resource: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
interface TableConfig {
|
|
161
|
+
description?: string;
|
|
162
|
+
/** Table-level migration rename hint (new in v2). */
|
|
163
|
+
renamedFrom?: string;
|
|
164
|
+
/** Composite primary key: property names (or column names). Mutually exclusive with column-level `.primaryKey()`. */
|
|
165
|
+
primaryKey?: readonly string[];
|
|
166
|
+
indexes?: readonly IndexInput[];
|
|
167
|
+
links?: Record<string, SeqLink>;
|
|
168
|
+
policies?: TablePoliciesInput;
|
|
169
|
+
actions?: readonly ActionInput[];
|
|
170
|
+
}
|
|
171
|
+
interface SeqTable {
|
|
172
|
+
readonly kind: typeof TABLE_BRAND;
|
|
173
|
+
readonly tableName: string;
|
|
174
|
+
readonly columns: Readonly<Record<string, ColumnBuilder>>;
|
|
175
|
+
readonly config: TableConfig;
|
|
176
|
+
/** Synced reflected source (`gold.*`) — set only by defineSyncedTable. */
|
|
177
|
+
readonly source: string | undefined;
|
|
178
|
+
/** Consumer file that defined the table (set when loaded via loadNamespaceFromDir). */
|
|
179
|
+
readonly file: string | undefined;
|
|
180
|
+
}
|
|
181
|
+
declare function isSeqTable(value: unknown): value is SeqTable;
|
|
182
|
+
declare function defineTable(name: string, columns: Record<string, ColumnBuilder>, config?: TableConfig): SeqTable;
|
|
183
|
+
interface SyncedTableConfig {
|
|
184
|
+
/** Reflected read-only source, restricted to the gold layer: `gold.<table>`. */
|
|
185
|
+
source: string;
|
|
186
|
+
description?: string;
|
|
187
|
+
}
|
|
188
|
+
declare function defineSyncedTable(name: string, config: SyncedTableConfig): SeqTable;
|
|
189
|
+
declare function defineEnum(name: string, values: readonly string[]): EnumRef;
|
|
190
|
+
|
|
191
|
+
declare const NAMESPACE_CONFIG_BRAND: "seq-namespace-config";
|
|
192
|
+
interface NamespaceCapabilitiesInput {
|
|
193
|
+
/** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
|
|
194
|
+
roles?: unknown;
|
|
195
|
+
/** Org-level capability pins this namespace attaches to. */
|
|
196
|
+
uses?: readonly string[];
|
|
197
|
+
}
|
|
198
|
+
interface NamespaceConfigInput {
|
|
199
|
+
namespace: string;
|
|
200
|
+
description?: string;
|
|
201
|
+
capabilities?: NamespaceCapabilitiesInput;
|
|
202
|
+
}
|
|
203
|
+
interface SeqNamespaceConfig {
|
|
204
|
+
readonly kind: typeof NAMESPACE_CONFIG_BRAND;
|
|
205
|
+
readonly namespace: string;
|
|
206
|
+
readonly description: string | undefined;
|
|
207
|
+
readonly capabilities: NamespaceCapabilitiesInput;
|
|
208
|
+
readonly file: string | undefined;
|
|
209
|
+
}
|
|
210
|
+
declare function isSeqNamespaceConfig(value: unknown): value is SeqNamespaceConfig;
|
|
211
|
+
declare function defineNamespace(input: NamespaceConfigInput): SeqNamespaceConfig;
|
|
212
|
+
interface SerializeNamespaceInput {
|
|
213
|
+
config: SeqNamespaceConfig;
|
|
214
|
+
tables: readonly SeqTable[];
|
|
215
|
+
enums?: readonly EnumRef[];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Serialize the authored namespace to a validated, normalized
|
|
219
|
+
* `CanonicalDefinition` (definition_format: 2). Throws `OrmDefinitionError`
|
|
220
|
+
* naming the table/file on any inconsistency.
|
|
221
|
+
*/
|
|
222
|
+
declare function serializeNamespace(input: SerializeNamespaceInput): CanonicalDefinition;
|
|
223
|
+
/** sha256 over the v1 hash domain + key-sorted JSON of the normalized canonical definition. */
|
|
224
|
+
declare function computeCanonicalHash(definition: CanonicalDefinition): string;
|
|
225
|
+
|
|
226
|
+
declare const NAMESPACE_CONFIG_FILE = "sequence.config.ts";
|
|
227
|
+
declare const SCHEMA_DIR = "schema";
|
|
228
|
+
interface LoadNamespaceOptions {
|
|
229
|
+
/**
|
|
230
|
+
* Test/dev hook: absolute path that bare `'@sequenceholdings/orm'` imports
|
|
231
|
+
* in consumer files resolve to (jiti alias). Leave unset in production —
|
|
232
|
+
* the consumer's own installed package resolves naturally.
|
|
233
|
+
*/
|
|
234
|
+
ormModulePath?: string;
|
|
235
|
+
}
|
|
236
|
+
interface LoadedNamespaceV2 {
|
|
237
|
+
readonly canonical: CanonicalDefinition;
|
|
238
|
+
readonly hash: string;
|
|
239
|
+
/** Relative paths of the files that were imported, config first. */
|
|
240
|
+
readonly files: readonly string[];
|
|
241
|
+
}
|
|
242
|
+
declare function loadNamespaceFromDir(dir: string, options?: LoadNamespaceOptions): Promise<LoadedNamespaceV2>;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Module-registry pattern for the authoring surface: `defineTable` /
|
|
246
|
+
* `defineEnum` / `defineNamespace` register into the ACTIVE collection
|
|
247
|
+
* context while `loadNamespaceFromDir` imports a consumer's files, so the
|
|
248
|
+
* loader collects definitions without inspecting module exports.
|
|
249
|
+
*
|
|
250
|
+
* The context stack lives on `globalThis` under a `Symbol.for` key — NOT in
|
|
251
|
+
* module scope — because the jiti loader evaluates its own transpiled copy of
|
|
252
|
+
* this module when a consumer file imports '@sequenceholdings/orm'. Both
|
|
253
|
+
* copies must observe the same registrations (the graphql-js dual-package
|
|
254
|
+
* discipline), so everything registered is plain data identified by `kind`
|
|
255
|
+
* brand strings, never `instanceof`.
|
|
256
|
+
*/
|
|
257
|
+
interface AuthoringRegistration {
|
|
258
|
+
readonly value: unknown;
|
|
259
|
+
readonly file: string | undefined;
|
|
260
|
+
}
|
|
261
|
+
interface AuthoringContext {
|
|
262
|
+
/** Set by the loader before importing each consumer file — error attribution. */
|
|
263
|
+
currentFile: string | undefined;
|
|
264
|
+
readonly tables: AuthoringRegistration[];
|
|
265
|
+
readonly enums: AuthoringRegistration[];
|
|
266
|
+
readonly configs: AuthoringRegistration[];
|
|
267
|
+
}
|
|
268
|
+
/** Push a fresh collection context; every define* call registers into it until ended. */
|
|
269
|
+
declare function beginAuthoringContext(): AuthoringContext;
|
|
270
|
+
/** Pop the context; throws if collection begin/end calls are mismatched (programmer error). */
|
|
271
|
+
declare function endAuthoringContext(context: AuthoringContext): void;
|
|
272
|
+
declare function activeAuthoringContext(): AuthoringContext | undefined;
|
|
273
|
+
|
|
274
|
+
export { type ActionInput, type ActionParamInput, type AuthoringContext, type AuthoringRegistration, COLUMN_BRAND, COLUMN_DEFAULT_FNS, ColumnBuilder, type ColumnDefaultFn, type ColumnDefaultLiteral, type ColumnTypeSpec, ENUM_BRAND, type EnumRef, type IndexInput, LINK_BRAND, type LinkKind, type LoadNamespaceOptions, type LoadedNamespaceV2, NAMESPACE_CONFIG_BRAND, NAMESPACE_CONFIG_FILE, type NamespaceCapabilitiesInput, type NamespaceConfigInput, type PolicyInput, type PolicyVariantInput, type PolicyWithVariantsInput, SCHEMA_DIR, type SeqLink, type SeqNamespaceConfig, type SeqTable, type SerializeNamespaceInput, type SyncedTableConfig, TABLE_BRAND, type TableConfig, type TablePoliciesInput, type TableRef, type ToManyOptions, type ToOneOptions, type ToPlatformUserOptions, activeAuthoringContext, beginAuthoringContext, computeCanonicalHash, defineEnum, defineNamespace, defineSyncedTable, defineTable, deriveColumnName, endAuthoringContext, isColumnBuilder, isEnumRef, isSeqLink, isSeqNamespaceConfig, isSeqTable, loadNamespaceFromDir, serializeNamespace, t, toMany, toOne, toPlatformUser };
|