@prisma-next/target-postgres 0.14.0-dev.61 → 0.14.0-dev.62
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/dist/{authoring-BLkL4fFG.mjs → authoring-CdIZ0yvD.mjs} +2 -2
- package/dist/{authoring-BLkL4fFG.mjs.map → authoring-CdIZ0yvD.mjs.map} +1 -1
- package/dist/contract-free.d.mts +1 -1
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +2 -2
- package/dist/{control-policy-BpmChlAK.mjs → control-policy-DKp0HKpY.mjs} +180 -45
- package/dist/control-policy-DKp0HKpY.mjs.map +1 -0
- package/dist/control.mjs +21 -25
- package/dist/control.mjs.map +1 -1
- package/dist/{ddl-BovUVFVi.mjs → ddl-gmxHf68z.mjs} +20 -4
- package/dist/{ddl-BovUVFVi.mjs.map → ddl-gmxHf68z.mjs.map} +1 -1
- package/dist/ddl.d.mts +2 -2
- package/dist/ddl.mjs +2 -2
- package/dist/{descriptor-meta-C1T4BXJ8.mjs → descriptor-meta-DEuXJfpR.mjs} +3 -3
- package/dist/{descriptor-meta-C1T4BXJ8.mjs.map → descriptor-meta-DEuXJfpR.mjs.map} +1 -1
- package/dist/{diff-database-schema-RMwnSOnz.mjs → diff-database-schema-D2sjvMw9.mjs} +14 -10
- package/dist/diff-database-schema-D2sjvMw9.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +1 -1
- package/dist/diff-database-schema.d.mts.map +1 -1
- package/dist/diff-database-schema.mjs +1 -1
- package/dist/issue-planner.d.mts +1 -1
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +2 -2
- package/dist/migration.mjs +2 -2
- package/dist/{nodes-BtQyZha6.d.mts → nodes-Bc2N3tMy.d.mts} +27 -3
- package/dist/nodes-Bc2N3tMy.d.mts.map +1 -0
- package/dist/{nodes-B815pj_X.mjs → nodes-DJC5B8Id.mjs} +32 -2
- package/dist/nodes-DJC5B8Id.mjs.map +1 -0
- package/dist/{op-factory-call-CI00nS4z.mjs → op-factory-call-C4flTtTG.mjs} +105 -6
- package/dist/op-factory-call-C4flTtTG.mjs.map +1 -0
- package/dist/{op-factory-call-D6_7-7Vc.d.mts → op-factory-call-CSIg5XDu.d.mts} +26 -3
- package/dist/{op-factory-call-D6_7-7Vc.d.mts.map → op-factory-call-CSIg5XDu.d.mts.map} +1 -1
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CAHZN1Ez.mjs → planner-BtEd5LMr.mjs} +32 -64
- package/dist/planner-BtEd5LMr.mjs.map +1 -0
- package/dist/{planner-ddl-builders-B8Nn6nHN.mjs → planner-ddl-builders-BKlmGDJl.mjs} +7 -3
- package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-a-tjfKsA.d.mts → planner-produced-postgres-migration-CXue-6M9.d.mts} +2 -2
- package/dist/{planner-produced-postgres-migration-a-tjfKsA.d.mts.map → planner-produced-postgres-migration-CXue-6M9.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-flkG4Y7n.mjs → planner-produced-postgres-migration-Jat3hg4u.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-flkG4Y7n.mjs.map → planner-produced-postgres-migration-Jat3hg4u.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-C1-Kk3Eu.mjs → planner-sql-checks-Br1c_QsH.mjs} +3 -3
- package/dist/{planner-sql-checks-C1-Kk3Eu.mjs.map → planner-sql-checks-Br1c_QsH.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.d.mts +2 -2
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-view-DWLNQbdR.mjs → postgres-contract-view-BAPW0ec1.mjs} +3 -3
- package/dist/{postgres-contract-view-DWLNQbdR.mjs.map → postgres-contract-view-BAPW0ec1.mjs.map} +1 -1
- package/dist/{postgres-database-schema-node-BVdOffjC.d.mts → postgres-database-schema-node-CJv5bfbs.d.mts} +62 -21
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
- package/dist/{postgres-migration-C92swCzd.mjs → postgres-migration-ChLMQRd-.mjs} +19 -3
- package/dist/postgres-migration-ChLMQRd-.mjs.map +1 -0
- package/dist/{postgres-migration-Bzzi0Asr.d.mts → postgres-migration-DkmgGNcv.d.mts} +21 -2
- package/dist/postgres-migration-DkmgGNcv.d.mts.map +1 -0
- package/dist/{postgres-role-schema-node-BmCboEa_.mjs → postgres-role-schema-node-Cm-j0ZGM.mjs} +11 -19
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
- package/dist/{postgres-schema-COEca21H.mjs → postgres-schema-DWQ0-CPb.mjs} +13 -2
- package/dist/postgres-schema-DWQ0-CPb.mjs.map +1 -0
- package/dist/postgres-schema-DsrtYp2v.d.mts.map +1 -1
- package/dist/{postgres-table-schema-node-9FCtCUz2.mjs → postgres-table-schema-node-D6LvInCe.mjs} +71 -8
- package/dist/postgres-table-schema-node-D6LvInCe.mjs.map +1 -0
- package/dist/{resolve-ddl-schema-ZkKxt2Fm.mjs → resolve-ddl-schema-CAza65Iy.mjs} +2 -2
- package/dist/{resolve-ddl-schema-ZkKxt2Fm.mjs.map → resolve-ddl-schema-CAza65Iy.mjs.map} +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/schema-ir-annotations.mjs +1 -1
- package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
- package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
- package/dist/sql-utils.d.mts +8 -1
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +4 -4
- package/package.json +20 -20
- package/src/contract-free/ddl.ts +27 -0
- package/src/core/ddl/nodes.ts +44 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +12 -1
- package/src/core/migrations/control-policy.ts +143 -45
- package/src/core/migrations/diff-database-schema.ts +1 -2
- package/src/core/migrations/issue-planner.ts +77 -4
- package/src/core/migrations/op-factory-call.ts +84 -0
- package/src/core/migrations/operations/native-enum-types.ts +62 -0
- package/src/core/migrations/planner-ddl-builders.ts +12 -2
- package/src/core/migrations/planner.ts +25 -62
- package/src/core/migrations/postgres-migration.ts +31 -0
- package/src/core/migrations/verify-postgres-namespaces.ts +0 -1
- package/src/core/postgres-schema.ts +22 -1
- package/src/core/psl-infer/infer-psl-contract.ts +6 -16
- package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +18 -27
- package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
- package/src/core/schema-ir/schema-node-kinds.ts +12 -3
- package/src/core/sql-utils.ts +15 -2
- package/src/exports/ddl.ts +2 -0
- package/src/exports/op-factory-call.ts +2 -0
- package/src/exports/sql-utils.ts +1 -0
- package/src/exports/types.ts +4 -1
- package/dist/control-policy-BpmChlAK.mjs.map +0 -1
- package/dist/diff-database-schema-RMwnSOnz.mjs.map +0 -1
- package/dist/nodes-B815pj_X.mjs.map +0 -1
- package/dist/nodes-BtQyZha6.d.mts.map +0 -1
- package/dist/op-factory-call-CI00nS4z.mjs.map +0 -1
- package/dist/planner-CAHZN1Ez.mjs.map +0 -1
- package/dist/planner-ddl-builders-B8Nn6nHN.mjs.map +0 -1
- package/dist/postgres-database-schema-node-BVdOffjC.d.mts.map +0 -1
- package/dist/postgres-migration-Bzzi0Asr.d.mts.map +0 -1
- package/dist/postgres-migration-C92swCzd.mjs.map +0 -1
- package/dist/postgres-role-schema-node-BmCboEa_.mjs.map +0 -1
- package/dist/postgres-schema-COEca21H.mjs.map +0 -1
- package/dist/postgres-table-schema-node-9FCtCUz2.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-table-schema-node-D6LvInCe.mjs","names":[],"sources":["../src/core/schema-ir/schema-node-kinds.ts","../src/core/schema-ir/postgres-native-enum-schema-node.ts","../src/core/schema-ir/postgres-table-schema-node.ts"],"sourcesContent":["import type {\n DiffableNode,\n DiffSubjectGranularity,\n} from '@prisma-next/framework-components/control';\nimport {\n relationalNodeEntityKind,\n relationalNodeGranularity,\n type SqlSchemaIRNode,\n} from '@prisma-next/sql-schema-ir/types';\n\n/**\n * A Postgres schema-diff-tree node: a `SqlSchemaIRNode` that also implements\n * `DiffableNode` (the five `Postgres*SchemaNode` classes). `SqlSchemaIRNode`\n * alone is not a `DiffableNode` — its relational subclasses (`SqlColumnIR`, …)\n * carry no `id`/`isEqualTo`/`children` — so this intersection is the honest node\n * type the differ produces and the planner consumes (`SchemaDiff<SqlSchemaDiffNode>`).\n */\nexport type SqlSchemaDiffNode = SqlSchemaIRNode & DiffableNode;\n\n/**\n * The `nodeKind` discriminant for each Postgres schema-diff node. Each node\n * carries a unique value; the static `is`/`assert` guards compare against these\n * identifiers rather than spelling the string inline or using `instanceof`. The\n * field is an enumerable own property carried on every node instance.\n */\nexport const PostgresSchemaNodeKind = {\n database: 'postgres-database',\n namespace: 'postgres-namespace',\n table: 'postgres-table',\n policy: 'postgres-policy',\n role: 'postgres-role',\n nativeEnum: 'postgres-native-enum',\n} as const;\n\nexport type PostgresSchemaNodeKind =\n (typeof PostgresSchemaNodeKind)[keyof typeof PostgresSchemaNodeKind];\n\n/**\n * The one real map from a Postgres-specific `nodeKind` to the\n * framework-neutral {@link DiffSubjectGranularity} its diff issues carry —\n * resolution is by `nodeKind` equality against this map, never a\n * `nodeKind`-suffix string match and never anything stamped on the node.\n */\nconst POSTGRES_NODE_GRANULARITY: Readonly<Record<PostgresSchemaNodeKind, DiffSubjectGranularity>> =\n {\n [PostgresSchemaNodeKind.database]: 'structural',\n [PostgresSchemaNodeKind.namespace]: 'namespace',\n [PostgresSchemaNodeKind.table]: 'entity',\n // A policy set is owned by the managed table it attaches to; a role is\n // referenced by the contract but not owned (the framework names it in a\n // policy but never owns the cluster's role list). Both classify as\n // `structural`. The asymmetry for roles — a missing declared one fails, an\n // undeclared live one is tolerated unconditionally — comes from the\n // control policy the diff resolves a role issue against (`external`),\n // not from the granularity.\n [PostgresSchemaNodeKind.policy]: 'structural',\n [PostgresSchemaNodeKind.role]: 'structural',\n [PostgresSchemaNodeKind.nativeEnum]: 'entity',\n };\n\nfunction isPostgresSchemaNodeKind(nodeKind: string): nodeKind is PostgresSchemaNodeKind {\n return Object.hasOwn(POSTGRES_NODE_GRANULARITY, nodeKind);\n}\n\n/** Looks up the subject granularity for a Postgres-specific `nodeKind`. */\nexport function postgresNodeGranularity(nodeKind: PostgresSchemaNodeKind): DiffSubjectGranularity {\n return POSTGRES_NODE_GRANULARITY[nodeKind];\n}\n\n/**\n * The subject granularity for any node kind that appears in a Postgres diff\n * tree — the tree mixes Postgres-specific kinds (database/namespace/table/\n * policy/role) with the relational leaf kinds (columns, constraints, indexes,\n * …), so this dispatches to whichever family/target map owns the kind. Called\n * on demand by consumers (the family verdict, the framework aggregate's\n * unclaimed-elements sweep, via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability) — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectGranularity(nodeKind: string): DiffSubjectGranularity {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeGranularity(nodeKind)\n : relationalNodeGranularity(nodeKind);\n}\n\n/**\n * The map from a Postgres-specific `nodeKind` to its storage `entityKind` — the\n * same vocabulary the contract storage's `entries` dictionary keys use. The\n * whole-table and native-enum kinds each have an entity of their own;\n * database/namespace/policy/role nodes map to nothing here (a namespace is\n * addressed by id, not by an `entries` kind; policies and roles are\n * structural, never a sibling space's unclaimed entity).\n *\n * The native enum keys under its PHYSICAL type name in `entries.native_enum`\n * (ADR 221), so its diff node's `typeName` addresses the entity on the generic\n * coordinate directly — no by-type-name walk needed. This lets the framework's\n * unclaimed-elements sweep classify enum ownership the same coordinate way it\n * classifies tables.\n */\nconst POSTGRES_NODE_ENTITY_KIND: Partial<Readonly<Record<PostgresSchemaNodeKind, string>>> = {\n [PostgresSchemaNodeKind.table]: 'table',\n [PostgresSchemaNodeKind.nativeEnum]: 'native_enum',\n};\n\n/** Looks up the storage entityKind for a Postgres-specific `nodeKind`. */\nexport function postgresNodeEntityKind(nodeKind: PostgresSchemaNodeKind): string | undefined {\n return POSTGRES_NODE_ENTITY_KIND[nodeKind];\n}\n\n/**\n * The storage `entityKind` for any node kind that appears in a Postgres diff\n * tree — sibling of {@link postgresDiffSubjectGranularity}, dispatching the\n * same way to whichever family/target map owns the kind. Called on demand by\n * the framework aggregate's unclaimed-elements sweep via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectEntityKind(nodeKind: string): string | undefined {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeEntityKind(nodeKind)\n : relationalNodeEntityKind(nodeKind);\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { assertNode, SqlSchemaIRNode } from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresNativeEnumSchemaNodeInput {\n /** The Postgres type name (`CREATE TYPE <typeName> AS ENUM (…)`). */\n readonly typeName: string;\n /** The owning DDL schema name — enum types are schema-scoped. */\n readonly namespaceId: string;\n /** Member values in declaration (`pg_enum.enumsortorder`) order. */\n readonly members: readonly string[];\n /** The contract entity's control grade — expected-side nodes only. */\n readonly control?: ControlPolicy;\n}\n\n/**\n * Schema-diff leaf node for a native Postgres enum type.\n *\n * This is a derived, transient node walked by the differ — it is NEVER\n * serialized. Both sides derive it on the namespace node: the expected side\n * from the contract's hydrated `entries.native_enum` entities, the actual\n * side from the adapter's introspected `nativeEnums`.\n *\n * Enum types are schema-scoped, so identity is (namespace, type name): the\n * namespace coordinate comes from tree position (the differ pairs enum nodes\n * only inside an already-paired namespace) and `id` carries the type name,\n * prefixed with the entries-kind vocabulary (`native_enum:<typeName>`) so it\n * cannot collide with a sibling table of the same name — the same\n * sibling-prefix convention relational column nodes use (`column:<name>`).\n *\n * `isEqualTo` compares members POSITIONALLY — `['a','b'] ≠ ['b','a']` —\n * because Postgres enum sort order is semantic. `control` is contract\n * metadata, not database state, and does not participate in equality.\n */\nexport class PostgresNativeEnumSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.nativeEnum;\n\n readonly typeName: string;\n readonly namespaceId: string;\n readonly members: readonly string[];\n declare readonly control?: ControlPolicy;\n\n constructor(input: PostgresNativeEnumSchemaNodeInput) {\n super();\n this.typeName = input.typeName;\n this.namespaceId = input.namespaceId;\n this.members = Object.freeze([...input.members]);\n if (input.control !== undefined) this.control = input.control;\n freezeNode(this);\n }\n\n get id(): string {\n return `native_enum:${this.typeName}`;\n }\n\n children(): readonly DiffableNode[] {\n return [];\n }\n\n isEqualTo(other: DiffableNode): boolean {\n const node = blindCast<\n SqlSchemaIRNode,\n 'every diff-tree node the differ pairs is a SqlSchemaIRNode; the guard rejects non-enum kinds'\n >(other);\n PostgresNativeEnumSchemaNode.assert(node);\n return (\n this.typeName === node.typeName &&\n this.members.length === node.members.length &&\n this.members.every((member, index) => member === node.members[index])\n );\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresNativeEnumSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.nativeEnum;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresNativeEnumSchemaNode {\n assertNode(node, 'PostgresNativeEnumSchemaNode', PostgresNativeEnumSchemaNode.is);\n }\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport {\n assertNode,\n PrimaryKey,\n type SqlAnnotations,\n SqlCheckConstraintIR,\n SqlColumnIR,\n SqlForeignKeyIR,\n SqlIndexIR,\n SqlSchemaIRNode,\n type SqlTableIRInput,\n SqlUniqueIR,\n} from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { PostgresPolicySchemaNode } from './postgres-policy-schema-node';\nimport { PostgresSchemaNodeKind } from './schema-node-kinds';\n\nexport interface PostgresTableSchemaNodeInput extends SqlTableIRInput {\n readonly policies?: readonly PostgresPolicySchemaNode[];\n /**\n * Whether row-level security is enabled on this table. Expected side:\n * stamped from the contract's `entries.rls` marker (never from the\n * policy set). Actual side: stamped from `pg_class.relrowsecurity` at\n * introspection. Required with no default so every construction site\n * supplies a deliberate value.\n */\n readonly rlsEnabled: boolean;\n}\n\n/**\n * Postgres-specific table schema-diff node. Carries all `SqlTableIR` fields\n * plus `policies`, and implements `DiffableNode` so the table instance is\n * directly the diff-tree node — no separate wrapper needed.\n *\n * Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because\n * `SqlTableIR` calls `freezeNode` in its own constructor, which prevents\n * subclass field initialisation.\n *\n * `id` is the table name. `isEqualTo` compares id + `rlsEnabled` — the\n * table's one own diffable attribute; all other structural drift is\n * expressed by its children. `children()` returns every column, the primary\n * key (when present), every foreign key, unique, index, and check constraint,\n * plus the policy nodes — one flat list, so a drifted column and a drifted\n * policy are both reported by the same walk. Order is deterministic (object\n * key order for columns, array order for the rest) so two structurally equal\n * tables always produce the same child list.\n */\nexport class PostgresTableSchemaNode extends SqlSchemaIRNode implements DiffableNode {\n override readonly nodeKind = PostgresSchemaNodeKind.table;\n\n readonly name: string;\n readonly columns: Readonly<Record<string, SqlColumnIR>>;\n readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;\n readonly uniques: ReadonlyArray<SqlUniqueIR>;\n readonly indexes: ReadonlyArray<SqlIndexIR>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly annotations?: SqlAnnotations;\n declare readonly checks?: ReadonlyArray<SqlCheckConstraintIR>;\n readonly policies: readonly PostgresPolicySchemaNode[];\n readonly rlsEnabled: boolean;\n\n constructor(input: PostgresTableSchemaNodeInput) {\n super();\n this.name = input.name;\n this.rlsEnabled = input.rlsEnabled;\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([key, col]) => [\n key,\n col instanceof SqlColumnIR ? col : new SqlColumnIR(col),\n ]),\n ),\n );\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk))),\n );\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u))),\n );\n this.indexes = Object.freeze(\n input.indexes.map((i) => (i instanceof SqlIndexIR ? i : new SqlIndexIR(i))),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n if (input.annotations !== undefined) this.annotations = input.annotations;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(\n input.checks.map((c) =>\n c instanceof SqlCheckConstraintIR ? c : new SqlCheckConstraintIR(c),\n ),\n );\n }\n this.policies = Object.freeze([...(input.policies ?? [])]);\n freezeNode(this);\n }\n\n get id(): string {\n return this.name;\n }\n\n /**\n * Equal iff the ids (names) match AND `rlsEnabled` matches — the table's\n * one own attribute in the diff; all other structural drift is expressed\n * by children. A paired `not-equal` therefore always means enablement\n * drift, which the planner maps to ENABLE/DISABLE ROW LEVEL SECURITY.\n */\n isEqualTo(other: DiffableNode): boolean {\n const node = blindCast<\n SqlSchemaIRNode,\n 'every diff-tree node the differ pairs is a SqlSchemaIRNode'\n >(other);\n PostgresTableSchemaNode.assert(node);\n return this.id === node.id && this.rlsEnabled === node.rlsEnabled;\n }\n\n children(): readonly DiffableNode[] {\n return [\n ...Object.values(this.columns),\n ...(this.primaryKey ? [this.primaryKey] : []),\n ...this.foreignKeys,\n ...this.uniques,\n ...this.indexes,\n ...(this.checks ?? []),\n ...this.policies,\n ];\n }\n\n static is(node: SqlSchemaIRNode): node is PostgresTableSchemaNode {\n return node.nodeKind === PostgresSchemaNodeKind.table;\n }\n\n static assert(node: SqlSchemaIRNode): asserts node is PostgresTableSchemaNode {\n assertNode(node, 'PostgresTableSchemaNode', PostgresTableSchemaNode.is);\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86.mjs";
|
|
2
|
-
import { r as isPostgresSchema } from "./postgres-schema-
|
|
2
|
+
import { r as isPostgresSchema } from "./postgres-schema-DWQ0-CPb.mjs";
|
|
3
3
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
4
4
|
//#region src/core/migrations/resolve-ddl-schema.ts
|
|
5
5
|
/**
|
|
@@ -19,4 +19,4 @@ function resolveDdlSchemaForNamespaceStorage(storage, namespaceId) {
|
|
|
19
19
|
//#endregion
|
|
20
20
|
export { resolveDdlSchemaForNamespaceStorage as t };
|
|
21
21
|
|
|
22
|
-
//# sourceMappingURL=resolve-ddl-schema-
|
|
22
|
+
//# sourceMappingURL=resolve-ddl-schema-CAza65Iy.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-ddl-schema-
|
|
1
|
+
{"version":3,"file":"resolve-ddl-schema-CAza65Iy.mjs","names":[],"sources":["../src/core/migrations/resolve-ddl-schema.ts"],"sourcesContent":["import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { DEFAULT_NAMESPACE_ID } from '../namespace-ids';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Given the contract's storage and a namespace id, returns the live Postgres\n * DDL schema name that namespace maps to. A named Postgres namespace dispatches\n * to its `ddlSchemaName(storage)`; the unbound sentinel resolves to\n * `DEFAULT_NAMESPACE_ID` (the search-path default for offline planning); a\n * bare object payload (used by some tests) falls back to the namespace id\n * itself.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return DEFAULT_NAMESPACE_ID;\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,oCACd,SACA,aACQ;CACR,IAAI,gBAAgB,sBAClB,OAAO;CAET,MAAM,YAAY,QAAQ,WAAW;CACrC,IAAI,aAAa,iBAAiB,SAAS,GACzC,OAAO,UAAU,cAAc,OAAO;CAExC,OAAO;AACT"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-UwYdV8fD.mjs";
|
|
2
|
-
import { n as PostgresContractSerializer, t as PostgresContractView } from "./postgres-contract-view-
|
|
2
|
+
import { n as PostgresContractSerializer, t as PostgresContractView } from "./postgres-contract-view-BAPW0ec1.mjs";
|
|
3
3
|
//#region src/exports/runtime.ts
|
|
4
4
|
/**
|
|
5
5
|
* Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-
|
|
1
|
+
import { t as resolveDdlSchemaForNamespaceStorage } from "./resolve-ddl-schema-CAza65Iy.mjs";
|
|
2
2
|
export { resolveDdlSchemaForNamespaceStorage };
|
|
@@ -59,6 +59,15 @@ function qualifyName(schemaName, objectName) {
|
|
|
59
59
|
return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
+
* Quotes a possibly dot-qualified name segment-by-segment:
|
|
63
|
+
* `order_status` -> `"order_status"`, `auth.aal_level` -> `"auth"."aal_level"`.
|
|
64
|
+
* A single-segment name round-trips to exactly {@link quoteIdentifier}; whole-
|
|
65
|
+
* string quoting (`"auth.aal_level"`) would be one wrong identifier.
|
|
66
|
+
*/
|
|
67
|
+
function quoteQualifiedName(name) {
|
|
68
|
+
return name.split(".").map((segment) => quoteIdentifier(segment)).join(".");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
62
71
|
* Validates that an enum value doesn't exceed PostgreSQL's label length limit.
|
|
63
72
|
*
|
|
64
73
|
* PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).
|
|
@@ -70,9 +79,9 @@ function qualifyName(schemaName, objectName) {
|
|
|
70
79
|
* @throws {SqlEscapeError} If the value exceeds the maximum length
|
|
71
80
|
*/
|
|
72
81
|
function validateEnumValueLength(value, enumTypeName) {
|
|
73
|
-
if (value.length > MAX_IDENTIFIER_LENGTH) throw new SqlEscapeError(`Enum value "${value.slice(0, 20)}..." for type "${enumTypeName}" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-
|
|
82
|
+
if (new TextEncoder().encode(value).length > MAX_IDENTIFIER_LENGTH) throw new SqlEscapeError(`Enum value "${value.slice(0, 20)}..." for type "${enumTypeName}" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-byte label limit`, value, "literal");
|
|
74
83
|
}
|
|
75
84
|
//#endregion
|
|
76
|
-
export {
|
|
85
|
+
export { quoteQualifiedName as a, quoteIdentifier as i, escapeLiteral as n, validateEnumValueLength as o, qualifyName as r, SqlEscapeError as t };
|
|
77
86
|
|
|
78
|
-
//# sourceMappingURL=sql-utils-
|
|
87
|
+
//# sourceMappingURL=sql-utils-SU4FDvIV.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-utils-
|
|
1
|
+
{"version":3,"file":"sql-utils-SU4FDvIV.mjs","names":[],"sources":["../src/core/sql-utils.ts"],"sourcesContent":["/**\n * Shared SQL utility functions for the Postgres target.\n *\n * These functions handle safe SQL identifier and literal escaping\n * with security validations to prevent injection and encoding issues.\n *\n * They live in `target-postgres` because both the control adapter (used at\n * emit time) and the runtime adapter (used at execute time) need the same\n * escaping/validation behavior, and the target package is the natural shared\n * home that both adapters can depend on without crossing planes.\n */\n\nexport class SqlEscapeError extends Error {\n constructor(\n message: string,\n public readonly value: string,\n public readonly kind: 'identifier' | 'literal',\n ) {\n super(message);\n this.name = 'SqlEscapeError';\n }\n}\n\nconst MAX_IDENTIFIER_LENGTH = 63;\n\n/**\n * Validates and quotes a PostgreSQL identifier (table, column, type, schema names).\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n * - Rejects empty identifiers\n * - Warns on identifiers exceeding PostgreSQL's 63-character limit\n *\n * @throws {SqlEscapeError} If the identifier contains null bytes or is empty\n */\nexport function quoteIdentifier(identifier: string): string {\n if (identifier.length === 0) {\n throw new SqlEscapeError('Identifier cannot be empty', identifier, 'identifier');\n }\n if (identifier.includes('\\0')) {\n throw new SqlEscapeError(\n 'Identifier cannot contain null bytes',\n identifier.replace(/\\0/g, '\\\\0'),\n 'identifier',\n );\n }\n if (identifier.length > MAX_IDENTIFIER_LENGTH) {\n console.warn(\n `Identifier \"${identifier.slice(0, 20)}...\" exceeds PostgreSQL's ${MAX_IDENTIFIER_LENGTH}-character limit and will be truncated`,\n );\n }\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\n/**\n * Escapes a string literal for safe use in SQL statements.\n *\n * Security validations:\n * - Rejects null bytes which could cause truncation or unexpected behavior\n *\n * Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).\n * Backslashes are treated as literal characters, not escape sequences.\n *\n * @throws {SqlEscapeError} If the value contains null bytes\n */\nexport function escapeLiteral(value: string): string {\n if (value.includes('\\0')) {\n throw new SqlEscapeError(\n 'Literal value cannot contain null bytes',\n value.replace(/\\0/g, '\\\\0'),\n 'literal',\n );\n }\n return value.replace(/'/g, \"''\");\n}\n\n/**\n * Builds a qualified name (schema.object) with proper quoting.\n */\nexport function qualifyName(schemaName: string, objectName: string): string {\n return `${quoteIdentifier(schemaName)}.${quoteIdentifier(objectName)}`;\n}\n\n/**\n * Quotes a possibly dot-qualified name segment-by-segment:\n * `order_status` -> `\"order_status\"`, `auth.aal_level` -> `\"auth\".\"aal_level\"`.\n * A single-segment name round-trips to exactly {@link quoteIdentifier}; whole-\n * string quoting (`\"auth.aal_level\"`) would be one wrong identifier.\n */\nexport function quoteQualifiedName(name: string): string {\n return name\n .split('.')\n .map((segment) => quoteIdentifier(segment))\n .join('.');\n}\n\n/**\n * Validates that an enum value doesn't exceed PostgreSQL's label length limit.\n *\n * PostgreSQL enum labels have a maximum length of NAMEDATALEN-1 (63 bytes by default).\n * Unlike identifiers, enum labels that exceed this limit cause an error rather than\n * silent truncation.\n *\n * @param value - The enum value to validate\n * @param enumTypeName - Name of the enum type (for error messages)\n * @throws {SqlEscapeError} If the value exceeds the maximum length\n */\nexport function validateEnumValueLength(value: string, enumTypeName: string): void {\n if (new TextEncoder().encode(value).length > MAX_IDENTIFIER_LENGTH) {\n throw new SqlEscapeError(\n `Enum value \"${value.slice(0, 20)}...\" for type \"${enumTypeName}\" exceeds PostgreSQL's ` +\n `${MAX_IDENTIFIER_LENGTH}-byte label limit`,\n value,\n 'literal',\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,iBAAb,cAAoC,MAAM;CAGtB;CACA;CAHlB,YACE,SACA,OACA,MACA;EACA,MAAM,OAAO;EAHG,KAAA,QAAA;EACA,KAAA,OAAA;EAGhB,KAAK,OAAO;CACd;AACF;AAEA,MAAM,wBAAwB;;;;;;;;;;;AAY9B,SAAgB,gBAAgB,YAA4B;CAC1D,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,eAAe,8BAA8B,YAAY,YAAY;CAEjF,IAAI,WAAW,SAAS,IAAI,GAC1B,MAAM,IAAI,eACR,wCACA,WAAW,QAAQ,OAAO,KAAK,GAC/B,YACF;CAEF,IAAI,WAAW,SAAS,uBACtB,QAAQ,KACN,eAAe,WAAW,MAAM,GAAG,EAAE,EAAE,4BAA4B,sBAAsB,uCAC3F;CAEF,OAAO,IAAI,WAAW,QAAQ,MAAM,MAAI,EAAE;AAC5C;;;;;;;;;;;;AAaA,SAAgB,cAAc,OAAuB;CACnD,IAAI,MAAM,SAAS,IAAI,GACrB,MAAM,IAAI,eACR,2CACA,MAAM,QAAQ,OAAO,KAAK,GAC1B,SACF;CAEF,OAAO,MAAM,QAAQ,MAAM,IAAI;AACjC;;;;AAKA,SAAgB,YAAY,YAAoB,YAA4B;CAC1E,OAAO,GAAG,gBAAgB,UAAU,EAAE,GAAG,gBAAgB,UAAU;AACrE;;;;;;;AAQA,SAAgB,mBAAmB,MAAsB;CACvD,OAAO,KACJ,MAAM,GAAG,CAAC,CACV,KAAK,YAAY,gBAAgB,OAAO,CAAC,CAAC,CAC1C,KAAK,GAAG;AACb;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,OAAe,cAA4B;CACjF,IAAI,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,SAAS,uBAC3C,MAAM,IAAI,eACR,eAAe,MAAM,MAAM,GAAG,EAAE,EAAE,iBAAiB,aAAa,yBAC3D,sBAAsB,oBAC3B,OACA,SACF;AAEJ"}
|
package/dist/sql-utils.d.mts
CHANGED
|
@@ -42,6 +42,13 @@ declare function escapeLiteral(value: string): string;
|
|
|
42
42
|
* Builds a qualified name (schema.object) with proper quoting.
|
|
43
43
|
*/
|
|
44
44
|
declare function qualifyName(schemaName: string, objectName: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Quotes a possibly dot-qualified name segment-by-segment:
|
|
47
|
+
* `order_status` -> `"order_status"`, `auth.aal_level` -> `"auth"."aal_level"`.
|
|
48
|
+
* A single-segment name round-trips to exactly {@link quoteIdentifier}; whole-
|
|
49
|
+
* string quoting (`"auth.aal_level"`) would be one wrong identifier.
|
|
50
|
+
*/
|
|
51
|
+
declare function quoteQualifiedName(name: string): string;
|
|
45
52
|
/**
|
|
46
53
|
* Validates that an enum value doesn't exceed PostgreSQL's label length limit.
|
|
47
54
|
*
|
|
@@ -55,5 +62,5 @@ declare function qualifyName(schemaName: string, objectName: string): string;
|
|
|
55
62
|
*/
|
|
56
63
|
declare function validateEnumValueLength(value: string, enumTypeName: string): void;
|
|
57
64
|
//#endregion
|
|
58
|
-
export { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier, validateEnumValueLength };
|
|
65
|
+
export { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier, quoteQualifiedName, validateEnumValueLength };
|
|
59
66
|
//# sourceMappingURL=sql-utils.d.mts.map
|
package/dist/sql-utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-utils.d.mts","names":[],"sources":["../src/core/sql-utils.ts"],"mappings":";;AAYA;;;;;;;;;;cAAa,cAAA,SAAuB,KAAK;EAAA,SAGrB,KAAA;EAAA,SACA,IAAA;cAFhB,OAAA,UACgB,KAAA,UACA,IAAA;AAAA;;;AAmB8B;AA8BlD;;;;AAA2C;AAc3C;;iBA5CgB,eAAA,CAAgB,UAAkB;;AA4CgB;
|
|
1
|
+
{"version":3,"file":"sql-utils.d.mts","names":[],"sources":["../src/core/sql-utils.ts"],"mappings":";;AAYA;;;;;;;;;;cAAa,cAAA,SAAuB,KAAK;EAAA,SAGrB,KAAA;EAAA,SACA,IAAA;cAFhB,OAAA,UACgB,KAAA,UACA,IAAA;AAAA;;;AAmB8B;AA8BlD;;;;AAA2C;AAc3C;;iBA5CgB,eAAA,CAAgB,UAAkB;;AA4CgB;AAUlE;;;;AAA+C;AAkB/C;;;;iBA1CgB,aAAA,CAAc,KAAa;;;;iBAc3B,WAAA,CAAY,UAAA,UAAoB,UAAkB;;;;;;;iBAUlD,kBAAA,CAAmB,IAAY;;;;;;;;;;;;iBAkB/B,uBAAA,CAAwB,KAAA,UAAe,YAAoB"}
|
package/dist/sql-utils.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier, validateEnumValueLength };
|
|
1
|
+
import { a as quoteQualifiedName, i as quoteIdentifier, n as escapeLiteral, o as validateEnumValueLength, r as qualifyName, t as SqlEscapeError } from "./sql-utils-SU4FDvIV.mjs";
|
|
2
|
+
export { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier, quoteQualifiedName, validateEnumValueLength };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { a as PostgresNamespaceSchemaNode, c as PostgresTableSchemaNodeInput, d as PostgresNativeEnumSchemaNode, f as PostgresNativeEnumSchemaNodeInput, i as PostgresRoleSchemaNodeInput, l as PostgresPolicySchemaNode, n as PostgresDatabaseSchemaNodeInput, o as PostgresNamespaceSchemaNodeInput, r as PostgresRoleSchemaNode, s as PostgresTableSchemaNode, t as PostgresDatabaseSchemaNode, u as PostgresPolicySchemaNodeInput } from "./postgres-database-schema-node-CJv5bfbs.mjs";
|
|
1
2
|
import { n as PostgresRlsPolicyInput, r as RlsPolicyOperation, t as PostgresRlsPolicy } from "./postgres-rls-policy--CSddvMR.mjs";
|
|
2
|
-
import { a as PostgresNamespaceSchemaNode, c as PostgresTableSchemaNode, d as PostgresPolicySchemaNodeInput, i as PostgresRoleSchemaNodeInput, l as PostgresTableSchemaNodeInput, n as PostgresDatabaseSchemaNodeInput, o as PostgresNamespaceSchemaNodeInput, r as PostgresRoleSchemaNode, s as PostgresNativeEnumIntrospection, t as PostgresDatabaseSchemaNode, u as PostgresPolicySchemaNode } from "./postgres-database-schema-node-BVdOffjC.mjs";
|
|
3
3
|
import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
|
|
4
4
|
import { a as postgresCreateNamespace, c as PostgresRlsEnablement, d as PostgresRoleInput, i as isPostgresSchema, l as PostgresRlsEnablementInput, n as PostgresSchema, o as PostgresNativeEnum, r as PostgresUnboundSchema, s as PostgresNativeEnumInput, t as PostgresContract, u as PostgresRole } from "./postgres-schema-DsrtYp2v.mjs";
|
|
5
|
-
export { type PostgresColumnDefault, type PostgresContract, PostgresDatabaseSchemaNode, type PostgresDatabaseSchemaNodeInput, PostgresNamespaceSchemaNode, type PostgresNamespaceSchemaNodeInput, PostgresNativeEnum, type PostgresNativeEnumInput, type
|
|
5
|
+
export { type PostgresColumnDefault, type PostgresContract, PostgresDatabaseSchemaNode, type PostgresDatabaseSchemaNodeInput, PostgresNamespaceSchemaNode, type PostgresNamespaceSchemaNodeInput, PostgresNativeEnum, type PostgresNativeEnumInput, PostgresNativeEnumSchemaNode, type PostgresNativeEnumSchemaNodeInput, PostgresPolicySchemaNode, type PostgresPolicySchemaNodeInput, PostgresRlsEnablement, type PostgresRlsEnablementInput, PostgresRlsPolicy, type PostgresRlsPolicyInput, PostgresRole, type PostgresRoleInput, PostgresRoleSchemaNode, type PostgresRoleSchemaNodeInput, PostgresSchema, PostgresTableSchemaNode, type PostgresTableSchemaNodeInput, PostgresUnboundSchema, type RlsPolicyOperation, isPostgresSchema, postgresCreateNamespace };
|
package/dist/types.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as PostgresNativeEnum } from "./postgres-native-enum-xdiqmBf_.mjs";
|
|
2
|
-
import { _ as PostgresRlsEnablement, g as PostgresRlsPolicy, i as postgresCreateNamespace, m as PostgresRole, n as PostgresUnboundSchema, r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-
|
|
3
|
-
import { t as PostgresTableSchemaNode } from "./postgres-table-schema-node-
|
|
4
|
-
import { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode, t as PostgresRoleSchemaNode } from "./postgres-role-schema-node-
|
|
5
|
-
export { PostgresDatabaseSchemaNode, PostgresNamespaceSchemaNode, PostgresNativeEnum, PostgresPolicySchemaNode, PostgresRlsEnablement, PostgresRlsPolicy, PostgresRole, PostgresRoleSchemaNode, PostgresSchema, PostgresTableSchemaNode, PostgresUnboundSchema, isPostgresSchema, postgresCreateNamespace };
|
|
2
|
+
import { _ as PostgresRlsEnablement, g as PostgresRlsPolicy, i as postgresCreateNamespace, m as PostgresRole, n as PostgresUnboundSchema, r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-DWQ0-CPb.mjs";
|
|
3
|
+
import { n as PostgresNativeEnumSchemaNode, t as PostgresTableSchemaNode } from "./postgres-table-schema-node-D6LvInCe.mjs";
|
|
4
|
+
import { i as PostgresDatabaseSchemaNode, n as PostgresPolicySchemaNode, r as PostgresNamespaceSchemaNode, t as PostgresRoleSchemaNode } from "./postgres-role-schema-node-Cm-j0ZGM.mjs";
|
|
5
|
+
export { PostgresDatabaseSchemaNode, PostgresNamespaceSchemaNode, PostgresNativeEnum, PostgresNativeEnumSchemaNode, PostgresPolicySchemaNode, PostgresRlsEnablement, PostgresRlsPolicy, PostgresRole, PostgresRoleSchemaNode, PostgresSchema, PostgresTableSchemaNode, PostgresUnboundSchema, isPostgresSchema, postgresCreateNamespace };
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
3
|
+
"version": "0.14.0-dev.62",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.14.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.14.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.14.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.14.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.14.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.14.0-dev.
|
|
15
|
-
"@prisma-next/psl-parser": "0.14.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract": "0.14.0-dev.
|
|
17
|
-
"@prisma-next/sql-errors": "0.14.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.14.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.14.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.14.0-dev.
|
|
21
|
-
"@prisma-next/ts-render": "0.14.0-dev.
|
|
22
|
-
"@prisma-next/utils": "0.14.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.14.0-dev.62",
|
|
10
|
+
"@prisma-next/contract": "0.14.0-dev.62",
|
|
11
|
+
"@prisma-next/errors": "0.14.0-dev.62",
|
|
12
|
+
"@prisma-next/family-sql": "0.14.0-dev.62",
|
|
13
|
+
"@prisma-next/framework-components": "0.14.0-dev.62",
|
|
14
|
+
"@prisma-next/migration-tools": "0.14.0-dev.62",
|
|
15
|
+
"@prisma-next/psl-parser": "0.14.0-dev.62",
|
|
16
|
+
"@prisma-next/sql-contract": "0.14.0-dev.62",
|
|
17
|
+
"@prisma-next/sql-errors": "0.14.0-dev.62",
|
|
18
|
+
"@prisma-next/sql-operations": "0.14.0-dev.62",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.14.0-dev.62",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.14.0-dev.62",
|
|
21
|
+
"@prisma-next/ts-render": "0.14.0-dev.62",
|
|
22
|
+
"@prisma-next/utils": "0.14.0-dev.62",
|
|
23
23
|
"@standard-schema/spec": "^1.1.0",
|
|
24
24
|
"arktype": "^2.2.0",
|
|
25
25
|
"pathe": "^2.0.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@prisma-next/psl-printer": "0.14.0-dev.
|
|
29
|
-
"@prisma-next/sql-contract-psl": "0.14.0-dev.
|
|
30
|
-
"@prisma-next/test-utils": "0.14.0-dev.
|
|
31
|
-
"@prisma-next/tsconfig": "0.14.0-dev.
|
|
32
|
-
"@prisma-next/tsdown": "0.14.0-dev.
|
|
28
|
+
"@prisma-next/psl-printer": "0.14.0-dev.62",
|
|
29
|
+
"@prisma-next/sql-contract-psl": "0.14.0-dev.62",
|
|
30
|
+
"@prisma-next/test-utils": "0.14.0-dev.62",
|
|
31
|
+
"@prisma-next/tsconfig": "0.14.0-dev.62",
|
|
32
|
+
"@prisma-next/tsdown": "0.14.0-dev.62",
|
|
33
33
|
"tsdown": "0.22.1",
|
|
34
34
|
"typescript": "5.9.3",
|
|
35
35
|
"vitest": "4.1.8"
|
package/src/contract-free/ddl.ts
CHANGED
|
@@ -8,8 +8,10 @@ import {
|
|
|
8
8
|
PostgresCreatePolicy,
|
|
9
9
|
PostgresCreateSchema,
|
|
10
10
|
PostgresCreateTable,
|
|
11
|
+
PostgresCreateType,
|
|
11
12
|
PostgresDisableRowLevelSecurity,
|
|
12
13
|
PostgresDropPolicy,
|
|
14
|
+
PostgresDropType,
|
|
13
15
|
type RlsPolicyOperation,
|
|
14
16
|
} from '../core/ddl/nodes';
|
|
15
17
|
|
|
@@ -48,6 +50,31 @@ export function createSchema(options: {
|
|
|
48
50
|
return new PostgresCreateSchema(options);
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Build a Postgres `CREATE TYPE … AS ENUM (…)` DDL node. The type name (and
|
|
55
|
+
* optional schema) are quoted by the renderer; the enum member `values` are
|
|
56
|
+
* emitted as single-quote-escaped string literals. An absent `schema` renders
|
|
57
|
+
* the type name unqualified so the connection's `search_path` resolves it.
|
|
58
|
+
*/
|
|
59
|
+
export function createType(options: {
|
|
60
|
+
readonly schema?: string;
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly values: readonly string[];
|
|
63
|
+
}): PostgresCreateType {
|
|
64
|
+
return new PostgresCreateType(options);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build a Postgres `DROP TYPE` DDL node. See {@link createType} for the
|
|
69
|
+
* identifier-quoting and unqualified-when-schemaless behaviour.
|
|
70
|
+
*/
|
|
71
|
+
export function dropType(options: {
|
|
72
|
+
readonly schema?: string;
|
|
73
|
+
readonly name: string;
|
|
74
|
+
}): PostgresDropType {
|
|
75
|
+
return new PostgresDropType(options);
|
|
76
|
+
}
|
|
77
|
+
|
|
51
78
|
/**
|
|
52
79
|
* Build an `ADD COLUMN` action for use inside {@link alterTable}.
|
|
53
80
|
* The column is a structured `DdlColumn` so codec-encoded defaults flow
|
package/src/core/ddl/nodes.ts
CHANGED
|
@@ -67,6 +67,8 @@ export type AnyAlterTableAction = AddColumnAction | DropDefaultAction;
|
|
|
67
67
|
export interface PostgresDdlVisitor<R> {
|
|
68
68
|
createTable(node: PostgresCreateTable): R;
|
|
69
69
|
createSchema(node: PostgresCreateSchema): R;
|
|
70
|
+
createType(node: PostgresCreateType): R;
|
|
71
|
+
dropType(node: PostgresDropType): R;
|
|
70
72
|
alterTable(node: PostgresAlterTable): R;
|
|
71
73
|
createPolicy(node: PostgresCreatePolicy): R;
|
|
72
74
|
dropPolicy(node: PostgresDropPolicy): R;
|
|
@@ -134,6 +136,46 @@ export class PostgresCreateSchema extends PostgresDdlNode {
|
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
|
|
139
|
+
export class PostgresCreateType extends PostgresDdlNode {
|
|
140
|
+
readonly kind = 'create-type' as const;
|
|
141
|
+
readonly schema: string | undefined;
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly values: ReadonlyArray<string>;
|
|
144
|
+
|
|
145
|
+
constructor(options: {
|
|
146
|
+
readonly schema?: string;
|
|
147
|
+
readonly name: string;
|
|
148
|
+
readonly values: readonly string[];
|
|
149
|
+
}) {
|
|
150
|
+
super();
|
|
151
|
+
this.schema = options.schema;
|
|
152
|
+
this.name = options.name;
|
|
153
|
+
this.values = Object.freeze([...options.values]);
|
|
154
|
+
this.freeze();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
override accept<R>(visitor: PostgresDdlVisitor<R>): R {
|
|
158
|
+
return visitor.createType(this);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export class PostgresDropType extends PostgresDdlNode {
|
|
163
|
+
readonly kind = 'drop-type' as const;
|
|
164
|
+
readonly schema: string | undefined;
|
|
165
|
+
readonly name: string;
|
|
166
|
+
|
|
167
|
+
constructor(options: { readonly schema?: string; readonly name: string }) {
|
|
168
|
+
super();
|
|
169
|
+
this.schema = options.schema;
|
|
170
|
+
this.name = options.name;
|
|
171
|
+
this.freeze();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
override accept<R>(visitor: PostgresDdlVisitor<R>): R {
|
|
175
|
+
return visitor.dropType(this);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
137
179
|
export class PostgresAlterTable extends PostgresDdlNode {
|
|
138
180
|
readonly kind = 'alter-table' as const;
|
|
139
181
|
readonly table: string;
|
|
@@ -262,6 +304,8 @@ export class PostgresDisableRowLevelSecurity extends PostgresDdlNode {
|
|
|
262
304
|
export type AnyPostgresDdlNode =
|
|
263
305
|
| PostgresCreateTable
|
|
264
306
|
| PostgresCreateSchema
|
|
307
|
+
| PostgresCreateType
|
|
308
|
+
| PostgresDropType
|
|
265
309
|
| PostgresAlterTable
|
|
266
310
|
| PostgresCreatePolicy
|
|
267
311
|
| PostgresDropPolicy
|
|
@@ -8,6 +8,7 @@ import type { PostgresContract } from '../postgres-schema';
|
|
|
8
8
|
import { isPostgresSchema } from '../postgres-schema';
|
|
9
9
|
import { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';
|
|
10
10
|
import { PostgresNamespaceSchemaNode } from '../schema-ir/postgres-namespace-schema-node';
|
|
11
|
+
import { PostgresNativeEnumSchemaNode } from '../schema-ir/postgres-native-enum-schema-node';
|
|
11
12
|
import { PostgresPolicySchemaNode } from '../schema-ir/postgres-policy-schema-node';
|
|
12
13
|
import { PostgresRoleSchemaNode } from '../schema-ir/postgres-role-schema-node';
|
|
13
14
|
import { PostgresTableSchemaNode } from '../schema-ir/postgres-table-schema-node';
|
|
@@ -140,10 +141,20 @@ export function contractToPostgresDatabaseSchemaNode(
|
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
|
|
144
|
+
const nativeEnums = Object.values(ns.entries.native_enum ?? {}).map(
|
|
145
|
+
(entity) =>
|
|
146
|
+
new PostgresNativeEnumSchemaNode({
|
|
147
|
+
typeName: entity.typeName,
|
|
148
|
+
namespaceId: ddlSchema,
|
|
149
|
+
members: entity.members,
|
|
150
|
+
...ifDefined('control', entity.control),
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
|
|
143
154
|
namespaces[ddlSchema] = new PostgresNamespaceSchemaNode({
|
|
144
155
|
schemaName: ddlSchema,
|
|
145
156
|
tables,
|
|
146
|
-
|
|
157
|
+
nativeEnums,
|
|
147
158
|
});
|
|
148
159
|
|
|
149
160
|
for (const role of Object.values(ns.role)) {
|