gemi 0.51.0 → 0.51.1

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.
@@ -16,9 +16,9 @@
16
16
  "// Runtime model metadata: the shape the Prisma generator plugin emits into an\n// app's `app/models/generated/schema.ts`, and the only thing the compiler is\n// allowed to read identifiers from.\n//\n// Nothing here is discovered from the database at runtime. It is all generated,\n// which is what makes `compile` a pure function and what makes SQL injection\n// structurally impossible: every identifier the compiler emits is looked up in\n// one of these objects first (see the README's invariant 2).\n//\n// The generator deliberately emits *more* than the current iteration reads.\n// Regenerating an app's artifacts is free; changing the shape of the emitted\n// artifact after apps depend on it is not.\n\n/**\n * Bumped whenever the emitted artifact's shape changes in a way the runtime\n * cannot read. Generated `schema.ts` files carry their own literal copy, and\n * `assertSchemaArtifactVersion` compares the two at registration time so a stale\n * `app/models/generated` fails with \"run prisma generate\" rather than with a\n * `TypeError` five stack frames into the compiler.\n *\n * **`FieldSchema.isList` did not bump it**, and the argument given at the time\n * was that the generator is `bin/orm` and the runtime is `orm/`, both shipped\n * by the same `gemi` package at the same version — so a *new* artifact could\n * never be read by an *old* runtime.\n *\n * **That argument is wrong, and #350's review is what showed it.** The two\n * halves do not travel together. The artifact is committed to git; the runtime\n * is a version in a lockfile. A teammate who pulls a branch without installing,\n * or a deploy box a release behind, reads a freshly committed artifact with the\n * previous runtime — and because the version literal in that artifact was never\n * bumped, `assertSchemaArtifactVersion` sees `1 === 1` and says nothing.\n *\n * The consequence is worse than being unable to read the column, because\n * `isClientSideDefault` used to be a *denylist* — anything that was not\n * `autoincrement` or `dbgenerated` counted as gemi's. An old runtime meeting\n * `{ kind: \"nanoid\" }` therefore answered \"yes, gemi supplies this\", included\n * the column in the insert, asked `clientSideValue` for a value, got\n * `undefined` from its `default:` arm, and bound **NULL**. On a required column\n * that is a NOT NULL violation; on a nullable one it writes NULL into every row\n * forever, which is strictly harder to find than a column that was omitted.\n *\n * So this is now **2**, and `isClientSideDefault` is an allowlist. The bump is\n * the mechanism that catches the skew — both directions fail with \"run\n * `prisma generate`\" — and the allowlist is what makes the failure loud rather\n * than silent if one ever slips past it.\n */\nexport const SCHEMA_ARTIFACT_VERSION = 2;\n\n/**\n * Prisma's scalar types, verbatim. Not SQL types — the mapping from these to a\n * column type is the dialect's business, and it differs (SQLite has no\n * `DateTime` and no `Boolean`).\n */\nexport type ScalarType =\n | \"Int\"\n | \"String\"\n | \"DateTime\"\n | \"Boolean\"\n | \"Float\"\n | \"BigInt\"\n | \"Decimal\"\n | \"Json\"\n | \"Bytes\";\n\n/**\n * Prisma 6.19.2's parser accepts seven default functions, and its client\n * registers client-side generators for **four** of them — `cuid`, `nanoid`,\n * `ulid` and `uuid`. All four produce a column whose DDL carries no `DEFAULT`,\n * so all four are gemi's to supply; that is the whole of #350, and `ulid` was\n * the last one still missing when its review was written.\n *\n * Read off the shipped artifacts rather than the docs: the parser's own string\n * table is `autoincrement ulid cuid dbgenerated nanoid now uuid`, and\n * `prisma migrate diff` on a schema using every one of them emits\n * `TEXT NOT NULL` with no default for each.\n */\nexport type DefaultKind =\n | \"autoincrement\"\n | \"cuid\"\n | \"uuid\"\n | \"nanoid\"\n | \"ulid\"\n | \"now\"\n | \"dbgenerated\"\n | \"value\";\n\n/** What `@default(nanoid())` means when written without an argument. */\nexport const NANOID_DEFAULT_LENGTH = 21;\n\nexport interface DefaultSpec {\n kind: DefaultKind;\n /** Present only for `kind: \"value\"` — the literal written in the schema. */\n value?: unknown;\n /**\n * Present only for `kind: \"nanoid\"` — the id's length in characters.\n *\n * Part of the default rather than a detail of it: `nanoid()` is 21 characters\n * and `nanoid(10)` is 10, and the column Prisma's migration emits is a plain\n * `TEXT` that constrains neither. So the length lives nowhere but the schema,\n * and if it does not survive into this artifact the runtime cannot mint the\n * same id the Prisma client would.\n */\n length?: number;\n /**\n * Present only for `kind: \"uuid\"` — `4` or `7`.\n *\n * The same reasoning as `length`, and it took the same bug to notice: `uuid()`\n * and `uuid(7)` are one `TEXT` column apart in the DDL and two different\n * *kinds* of identifier in practice. A v7 is time-ordered, which is the entire\n * reason a schema asks for one — order by it and rows come back in insertion\n * order, and a B-tree insert lands next to the last one. Minting a v4 where\n * the schema said 7 loses both, silently, in a column that still looks like a\n * UUID.\n *\n * Absent on an artifact generated before this existed. The runtime reads a\n * missing version as 4, which is what `uuid()` meant then and means now —\n * though `SCHEMA_ARTIFACT_VERSION` makes that pairing fail loudly first.\n *\n * `cuid` has a version argument too and does **not** get a field here: `cuid(2)`\n * is refused by the generator rather than recorded, so the only cuid that\n * reaches an artifact is v1. See `emit.ts`.\n */\n version?: number;\n}\n\nexport interface FieldSchema {\n /** The field name as an app author writes it: `organizationId`. */\n name: string;\n /** The column name in the database: `@map(...)` if present, else `name`. */\n column: string;\n type: ScalarType;\n nullable: boolean;\n isId: boolean;\n isUpdatedAt: boolean;\n /**\n * A Prisma **scalar list** — `tags String[]`. Postgres only; SQLite has no\n * array type and Prisma refuses the declaration there outright.\n *\n * **A flag beside `type` rather than a `ScalarType` constructor**, and the\n * choice reaches further than it looks. `type` keeps meaning the *element*\n * type, so every `switch (field.type)` already written — `encode`, `decode`,\n * `castParameter`, the lateral strategy's `jsonConverter`, `COMPOSITE_IN_TYPES`\n * — keeps reading correctly and only has to ask this one extra question where\n * a list genuinely differs. A `\"String[]\"` member of the union would have made\n * every one of those switches silently non-exhaustive instead: no compile\n * error, just a `default:` branch answering for a shape it had never seen.\n *\n * Absent rather than `false` on a non-list field, so an artifact generated\n * before this existed is byte-identical to one generated after it — see the\n * note on `SCHEMA_ARTIFACT_VERSION`, which is deliberately *not* bumped here.\n */\n isList?: boolean;\n /**\n * Set when the field is a Prisma enum. The enum's members are strings on the\n * wire, so `type` is `\"String\"` and this carries the name for later.\n */\n enum?: string;\n default?: DefaultSpec;\n}\n\nexport interface RelationSchema {\n /** The field name on the owning model: `accounts`. */\n name: string;\n /** The related model's *name*, resolved through the registry at call time. */\n model: string;\n kind: \"one\" | \"many\";\n /**\n * Prisma's relation name, shared by both sides. It is what lets the planner\n * find the other side of a relation whose `from`/`to` live on that side only.\n */\n relationName: string;\n /** Local fields. Empty on the side that does not hold the foreign key. */\n from: string[];\n /** Fields on the related model. Empty on the non-owning side, as above. */\n to: string[];\n nullable: boolean;\n /** Implicit many-to-many join table. Emitted now, unused until iteration 3. */\n joinTable?: {\n table: string;\n a: string;\n b: string;\n /**\n * Which column holds the owner of **this** relation field, for a\n * *self*-referential implicit m-n where `a === b` and the model names\n * cannot say.\n *\n * Prisma assigns the columns by **field name, alphabetically**: the\n * alphabetically-first of the relation's two fields has its owner in `A`.\n * Determined by experiment against a generated client, in both directions,\n * rather than from the docs — the two candidate rules (declaration order\n * and field-name order) disagree only when a schema declares the fields out\n * of alphabetical order, which is exactly the case that would have shipped\n * reversed.\n *\n * Absent for a non-self m-n, where comparing the model names answers it,\n * and absent in artifacts generated before this existed — which is why\n * reading it is optional rather than required. Such an artifact behaves\n * exactly as it did: a self-referential m-n is refused.\n */\n ownerColumn?: \"A\" | \"B\";\n };\n}\n\nexport interface ModelSchema {\n /** Registry key: `\"User\"`. */\n name: string;\n /** `@@map(...)` if present, else `name`. Never inferred or pluralised. */\n table: string;\n /** Insertion-ordered by schema declaration — this is the `select` order. */\n fields: Record<string, FieldSchema>;\n primaryKey: string[];\n /** Single-field `@unique` and composite `@@unique`, in declaration order. */\n uniques: string[][];\n relations: Record<string, RelationSchema>;\n}\n\nexport class StaleSchemaArtifactError extends Error {\n constructor(found: number) {\n super(\n `The generated model artifact is version ${found}, but this version of ` +\n `gemi reads version ${SCHEMA_ARTIFACT_VERSION}. Re-run \\`prisma generate\\` ` +\n `to refresh app/models/generated.`,\n );\n this.name = \"StaleSchemaArtifactError\";\n }\n}\n\n/**\n * Called by the generated `index.ts` with its own artifact version literal.\n */\nexport function assertSchemaArtifactVersion(version: number): void {\n if (version !== SCHEMA_ARTIFACT_VERSION) {\n throw new StaleSchemaArtifactError(version);\n }\n}\n",
17
17
  "import {\n NANOID_DEFAULT_LENGTH,\n type DefaultKind,\n type DefaultSpec,\n type FieldSchema,\n} from \"./schema\";\n\n/**\n * The values gemi supplies itself on a write, rather than leaving to the\n * database.\n *\n * Which defaults have to be client-side is not a style question — it is forced\n * by the DDL Prisma emits. Reading the template's own migration:\n *\n * ```sql\n * \"publicId\" TEXT NOT NULL, -- @default(cuid())\n * \"createdAt\" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, -- @default(now())\n * \"updatedAt\" DATETIME NOT NULL, -- @updatedAt\n * ```\n *\n * - `publicId` and `updatedAt` carry **no database default at all**. Prisma\n * generates them in the client, so a row inserted without them violates a\n * NOT NULL constraint. Missing `@updatedAt` on *create* is the quiet version\n * of this bug: the column is only nullable on models where Prisma made it so.\n * `@default(nanoid())` is the same column with a different generator on it,\n * and was on the wrong side of this split until #350 — classified\n * `dbgenerated`, so the ORM omitted the column and the driver rejected the\n * row.\n *\n * **Prisma's client registers four of these, not three.** Its generator\n * registry reads `register(\"uuid\") register(\"cuid\") register(\"ulid\")\n * register(\"nanoid\")`, and `prisma migrate diff` gives every one of them a\n * `TEXT NOT NULL` with no `DEFAULT`. #350's first fix said \"three\" and left\n * `ulid` falling through to `dbgenerated` — the same bug, one function over,\n * which is what its review caught. All four are here now.\n * - `createdAt` does have a default, but it is `CURRENT_TIMESTAMP`, which SQLite\n * stores as the *text* `YYYY-MM-DD HH:MM:SS` — while Prisma stores a DateTime\n * as integer milliseconds. Letting the database fill it would write a\n * different storage form than Prisma writes, and drop sub-second precision.\n *\n * `autoincrement()` and `dbgenerated(...)` stay with the database, which is the\n * whole of the other side of this split.\n *\n * Verified against Prisma 6.19.2 rather than assumed: a `create` there returns\n * `createdAt` and `updatedAt` as the *same instant*, which is why `now` is\n * resolved once per logical operation and passed in rather than read per field.\n */\n\n/**\n * The kinds gemi supplies a value for, as an allowlist.\n *\n * **It was a denylist** — `kind !== \"autoincrement\" && kind !== \"dbgenerated\"`\n * — and the difference is what a *future* kind does on a runtime that predates\n * it. A denylist says \"yes, gemi supplies this\" for a kind it cannot generate,\n * so the column joins the insert and `clientSideValue` hands back `undefined`,\n * which the dialect encodes as **NULL**. A nullable column then takes NULL on\n * every row, silently, where an id belonged.\n *\n * An allowlist answers \"no\" instead, so the column is omitted and the database\n * decides — a NOT NULL violation where it matters, and nothing where it does\n * not. `SCHEMA_ARTIFACT_VERSION` should catch that skew first; this is what\n * makes it loud if it ever does not.\n *\n * Every member must have an arm in `clientSideValue`, which the exhaustive\n * `Record<DefaultKind, boolean>` in the tests is there to hold.\n */\nconst CLIENT_SIDE_KINDS: ReadonlySet<DefaultKind> = new Set<DefaultKind>([\n \"cuid\",\n \"uuid\",\n \"nanoid\",\n \"ulid\",\n \"now\",\n \"value\",\n]);\n\n/** Whether gemi supplies this default, or leaves the column to the database. */\nexport function isClientSideDefault(spec: DefaultSpec): boolean {\n return CLIENT_SIDE_KINDS.has(spec.kind);\n}\n\n/**\n * A field gemi must supply a value for when the caller did not: either it has a\n * client-side default, or it is `@updatedAt`, which Prisma sets on create as\n * well as on update.\n */\nexport function hasClientSideValue(field: FieldSchema): boolean {\n if (field.isUpdatedAt) return true;\n return field.default !== undefined && isClientSideDefault(field.default);\n}\n\n/**\n * The value for one field on one row. `now` is shared across every field and\n * every row of a single operation; everything else is generated per call.\n */\nexport function clientSideValue(field: FieldSchema, now: Date): unknown {\n // `@updatedAt` wins over any `@default`: Prisma stamps it on every write,\n // which is the entire point of the attribute.\n if (field.isUpdatedAt) return now;\n\n const spec = field.default;\n if (!spec) return undefined;\n\n switch (spec.kind) {\n case \"cuid\":\n // v1 only. `cuid(2)` is refused by the generator rather than recorded,\n // because gemi cannot reproduce `@paralleldrive/cuid2`'s output — see\n // `emit.ts`. So no artifact reaches here carrying a cuid version.\n return createCuid();\n case \"uuid\":\n // Absent means 4, which is what a bare `uuid()` has always meant. The\n // DMMF in fact normalises `uuid()` to `args: [4]`, so the generator\n // always records it; the fallback is for a hand-written spec.\n return createUuid(spec.version ?? 4);\n case \"nanoid\":\n // Likewise: the generator always records the length, so the fallback is\n // for a hand-written spec. 21 is what `nanoid()` means.\n return createNanoid(spec.length ?? NANOID_DEFAULT_LENGTH);\n case \"ulid\":\n return createUlid();\n case \"now\":\n return now;\n case \"value\":\n return spec.value;\n default:\n // autoincrement / dbgenerated — the database's business.\n return undefined;\n }\n}\n\n// --- random symbols --------------------------------------------------------\n\n/**\n * `size` symbols drawn uniformly from `alphabet`.\n *\n * The one place the uniformity argument lives, because it is the same argument\n * for every id below and it used to be made twice, half in `randomBlock`'s\n * comment and half in `createNanoid`'s.\n *\n * A byte is a draw from 256, and 256 is a multiple of the alphabet's size only\n * when that size is a power of two. When it is not, `byte % size` would favour\n * the first `256 % size` symbols — for cuid's 36 that is the first four,\n * delivered 8 times in 256 against everyone else's 7, which is 12.5% above\n * uniform and invisible in any single id. `limit` cuts the tail that causes it\n * and those bytes are redrawn.\n *\n * For a 64-symbol alphabet `256 % 64` is 0, so `limit` is 256, the loop never\n * rejects, and this is exactly the `& 63` mask nanoid ships — reached by\n * arithmetic rather than by special-casing it.\n */\nfunction randomChars(alphabet: string, size: number): string {\n const base = alphabet.length;\n const limit = 256 - (256 % base);\n\n const bytes = new Uint8Array(size);\n crypto.getRandomValues(bytes);\n\n let out = \"\";\n for (let i = 0; i < size; i++) {\n let byte = bytes[i];\n while (byte >= limit) {\n const resample = new Uint8Array(1);\n crypto.getRandomValues(resample);\n byte = resample[0];\n }\n out += alphabet[byte % base];\n }\n return out;\n}\n\n// --- cuid v1 ---------------------------------------------------------------\n\n// The format Prisma 6.19.2 actually emits for `@default(cuid())`, read off real\n// rows rather than taken from the docs:\n//\n// cms3j09fa0000a0452l77tbma\n// c ms3j09fa 0000 a045 2l77tbma\n// ^ ^ ^ ^ ^\n// | | | fingerprint random\n// | | counter\n// | timestamp, base 36\n// literal 'c'\n//\n// 25 characters, lowercase alphanumeric. Prisma's `cuid()` is still v1; `cuid2`\n// is a separate, opt-in generator with a different shape, so matching v1 is what\n// keeps a gemi-written `publicId` indistinguishable from a Prisma-written one in\n// length, prefix and charset.\n\nconst ALPHABET = \"0123456789abcdefghijklmnopqrstuvwxyz\";\nconst BASE = 36;\nconst BLOCK_SIZE = 4;\nconst DISCRETE_VALUES = BASE ** BLOCK_SIZE;\n\n/**\n * Monotonic within a process, rolling over at one block's worth of values. It\n * is what keeps two cuids minted in the same millisecond distinct, so it must\n * not be reset or made per-call.\n */\nlet counter = 0;\n\nfunction pad(text: string, size: number): string {\n return text.length >= size ? text : \"0\".repeat(size - text.length) + text;\n}\n\n/**\n * cuid v1 derives this from the process id and the hostname, to keep two\n * processes minting concurrently from colliding.\n *\n * gemi uses a random block generated once per process instead. It fills exactly\n * the same role with strictly better collision behaviour — containers routinely\n * share both a hostname and a low pid — and it keeps `node:os` off the ORM\n * runtime's import graph. Nothing observable changes: the fingerprint is four\n * characters of the same alphabet in the same position, and nothing parses it.\n */\nconst FINGERPRINT = randomBlock();\n\n/** One four-character block of cuid's base-36 alphabet. */\nfunction randomBlock(): string {\n return randomChars(ALPHABET, BLOCK_SIZE);\n}\n\nexport function createCuid(): string {\n const timestamp = Date.now().toString(BASE);\n const count = pad((counter++ % DISCRETE_VALUES).toString(BASE), BLOCK_SIZE);\n return `c${timestamp}${count}${FINGERPRINT}${randomBlock()}${randomBlock()}`;\n}\n\n// --- nanoid ----------------------------------------------------------------\n\n/**\n * The alphabet, verbatim from the `nanoid` package Prisma bundles. Its order is\n * not alphabetical and not arbitrary — it is what the library ships, and an id\n * is a uniform draw from it, so a reordering changes nothing observable. It is\n * copied exactly anyway, because \"the same alphabet\" is the property.\n *\n * 64 characters, so `randomChars` computes a `limit` of 256 for it and never\n * rejects a byte — the same draw as nanoid's own `& 63`.\n */\nconst NANOID_ALPHABET =\n \"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict\";\n\n/**\n * The id `@default(nanoid(size))` produces in the Prisma client, generated here\n * instead — same alphabet, same length, so a gemi-written column and a\n * Prisma-written one are indistinguishable.\n *\n * Unlike a cuid there is no structure to match: a nanoid is `size` independent\n * symbols and nothing more. No timestamp, no counter, no fingerprint — which is\n * also why none of the collision reasoning around `createCuid` applies here.\n */\nexport function createNanoid(size: number = NANOID_DEFAULT_LENGTH): string {\n return randomChars(NANOID_ALPHABET, size);\n}\n\n// --- ulid ------------------------------------------------------------------\n\n/**\n * Crockford's base32: the digits and the uppercase letters, less `I`, `L`, `O`\n * and `U` — the four that are misread as `1`, `1`, `0` and each other. Copied\n * from the string Prisma's client ships, which is the canonical one.\n *\n * 32 symbols, a power of two, so `randomChars` never rejects a byte here\n * either.\n */\nconst ULID_ALPHABET = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\n\n/** 48 bits of milliseconds, base 32. */\nconst ULID_TIME_CHARS = 10;\n/** 80 bits of randomness, base 32 — the width Prisma's generator uses. */\nconst ULID_RANDOM_CHARS = 16;\n\n/**\n * `@default(ulid())`, which #350's first fix missed: it never had a `case`, so\n * it fell through to `dbgenerated` and the column was omitted from every insert\n * — the same bug the fix was written for, on a fourth id function.\n *\n * A ULID is a timestamp followed by randomness, and the *order* is the point:\n * the time is big-endian and base 32 preserves byte order, so sorting ULIDs\n * lexicographically sorts them by creation time. That is why the timestamp is\n * built here digit by digit rather than through `toString(32)`, which would\n * emit a variable number of characters and destroy the alignment the ordering\n * depends on.\n */\nexport function createUlid(now: number = Date.now()): string {\n let time = \"\";\n let remaining = now;\n for (let i = 0; i < ULID_TIME_CHARS; i++) {\n time = ULID_ALPHABET[remaining % 32] + time;\n remaining = Math.floor(remaining / 32);\n }\n\n return time + randomChars(ULID_ALPHABET, ULID_RANDOM_CHARS);\n}\n\n// --- uuid ------------------------------------------------------------------\n\n/**\n * `@default(uuid(v))`. Prisma's client accepts 4 and 7 and throws on anything\n * else; the generator refuses the rest before an artifact can carry it, so this\n * only ever sees those two.\n *\n * **The version is not cosmetic**, which is why it had to travel with the spec.\n * A v4 is 122 random bits. A v7 puts 48 bits of big-endian milliseconds at the\n * front, so v7s sort by creation time and land next to each other in a B-tree —\n * the entire reason a schema asks for one. Minting a v4 where the schema said 7\n * loses both properties and leaves a column that still looks like a UUID, which\n * is how it went unnoticed.\n */\nexport function createUuid(version: number = 4): string {\n return version === 7 ? createUuidV7() : crypto.randomUUID();\n}\n\nconst HEX = Array.from({ length: 256 }, (_, i) =>\n i.toString(16).padStart(2, \"0\"),\n);\n\n/**\n * RFC 9562 §5.7: 48 bits of Unix milliseconds, the 4-bit version `7`, 12 random\n * bits, the 2-bit variant `0b10`, and 62 more random bits.\n *\n * The layout is asserted by the tests rather than trusted, because every field\n * but the timestamp is invisible in a rendered UUID.\n *\n * The ordering this buys is **per millisecond**. Everything after the timestamp\n * is random, so two ids minted in the same millisecond have no defined order\n * between them; §6.2's monotonic counter is what would fix that, and neither\n * Prisma's generator nor this one implements it. Sorting by a v7 orders rows by\n * the millisecond they were written, which is the property an index cares about.\n */\nfunction createUuidV7(): string {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n\n const now = Date.now();\n // Big-endian, and `Math.floor(now / 2 ** 32)` rather than a shift: `>>>`\n // truncates to 32 bits, and the timestamp needs 48.\n bytes[0] = Math.floor(now / 2 ** 40) & 0xff;\n bytes[1] = Math.floor(now / 2 ** 32) & 0xff;\n bytes[2] = (now >>> 24) & 0xff;\n bytes[3] = (now >>> 16) & 0xff;\n bytes[4] = (now >>> 8) & 0xff;\n bytes[5] = now & 0xff;\n\n bytes[6] = (bytes[6] & 0x0f) | 0x70; // version 7, keeping the random low bits\n bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 0b10, likewise\n\n const hex = HEX;\n return (\n hex[bytes[0]] + hex[bytes[1]] + hex[bytes[2]] + hex[bytes[3]] +\n \"-\" + hex[bytes[4]] + hex[bytes[5]] +\n \"-\" + hex[bytes[6]] + hex[bytes[7]] +\n \"-\" + hex[bytes[8]] + hex[bytes[9]] +\n \"-\" + hex[bytes[10]] + hex[bytes[11]] + hex[bytes[12]] +\n hex[bytes[13]] + hex[bytes[14]] + hex[bytes[15]]\n );\n}\n",
18
18
  "import type { SqlDialect } from \"./dialect\";\nimport type { FieldSchema } from \"./schema\";\n\n/**\n * Turns driver rows into the POJOs the caller sees. Built once per compiled\n * plan and closed over a fixed column list, so the hot loop does no per-row\n * schema lookups, no `for...in`, and no per-value type dispatch beyond the one\n * boolean decided at build time.\n *\n * This is a plain function today. `Model.$shape` is the static that calls it\n * (invariant 3), which is the seam a future `ActiveRecordModel` overrides to\n * build instances instead, and the seam iteration 8 hangs row provenance on.\n *\n * There are **two implementations**, and which one runs is decided once per\n * process — see `buildRowShaper`. Iteration 7 measured the difference at 3.4× on\n * a 1000-row read, roughly a third of that whole query, and that number is the\n * only reason the second one exists.\n */\nexport type RowShaper = (rows: unknown[]) => Record<string, unknown>[];\n\ninterface ShapedColumn {\n /** Key on the returned object — the Prisma field name. */\n key: string;\n /** Key on the driver row — the database column name. */\n column: string;\n field: FieldSchema;\n decode: boolean;\n}\n\n/**\n * One relation the plan will load. The shaper does not fetch anything; it\n * writes the *empty* value so the key exists on every row before the relation\n * loader fills in the rows that have children.\n *\n * These three lines are where most divergence bugs live, so they are stated\n * once, here: a to-one with no match is `null` — not `undefined`, not a missing\n * key — and an empty to-many is `[]` — not `null`, not absent. Prisma returns\n * exactly that, and the differential harness compares key presence.\n */\nexport interface ShapedRelation {\n key: string;\n kind: \"one\" | \"many\";\n}\n\n/**\n * Whether this runtime allows compiling a function from source.\n *\n * Probed once, at module load, by doing it. `new Function` is unavailable under\n * a strict Content-Security-Policy and on some edge runtimes, and the failure is\n * a throw at *construction* — so asking is the only way to know, and asking once\n * is better than a try/catch per compiled plan.\n */\nconst CAN_COMPILE = (() => {\n try {\n return new Function(\"return 1\")() === 1;\n } catch {\n return false;\n }\n})();\n\nlet compilationEnabled = true;\n\n/**\n * Forces the interpreted shaper.\n *\n * Exported because the two implementations must produce *identical* output, and\n * a test can only assert that if it can obtain both. That test is what stands\n * between this optimisation and a shape divergence visible only in production.\n */\nexport function setShaperCompilation(enabled: boolean): void {\n compilationEnabled = enabled;\n}\n\nexport function shaperCompilationAvailable(): boolean {\n return CAN_COMPILE;\n}\n\nexport function buildRowShaper(\n fields: FieldSchema[],\n dialect: SqlDialect,\n relations: readonly ShapedRelation[] = [],\n): RowShaper {\n if (CAN_COMPILE && compilationEnabled) {\n return buildCompiledShaper(fields, dialect, relations);\n }\n return buildInterpretedShaper(fields, dialect, relations);\n}\n\n/**\n * The portable implementation: a closure over the column list, assigning keys\n * dynamically.\n *\n * Kept as the fallback rather than deleted, and not dead code — it runs wherever\n * `new Function` is refused, and it is the reference the compiled one is\n * asserted equal to.\n */\nexport function buildInterpretedShaper(\n fields: FieldSchema[],\n dialect: SqlDialect,\n relations: readonly ShapedRelation[] = [],\n): RowShaper {\n const columns: ShapedColumn[] = fields.map((field) => ({\n key: field.name,\n column: field.column,\n field,\n decode: dialect.needsDecode(field),\n }));\n const width = columns.length;\n\n // Flattened to `(key, many)` pairs at build time for the same reason the\n // columns are: the per-row loop does no property lookups it can avoid, and\n // the common case — no relations — costs one comparison against zero.\n const related = relations.map((relation) => ({\n key: relation.key,\n many: relation.kind === \"many\",\n }));\n const relatedCount = related.length;\n\n return (rows: unknown[]) => {\n // Grown by `push` rather than preallocated: `new Array(n)` produces a holey\n // array, which is the slower of the two to write into.\n const out: Record<string, unknown>[] = [];\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i] as Record<string, unknown>;\n const shaped: Record<string, unknown> = {};\n for (let j = 0; j < width; j++) {\n const column = columns[j];\n const value = row[column.column];\n shaped[column.key] = column.decode\n ? dialect.decode(value, column.field)\n : (value ?? null);\n }\n for (let j = 0; j < relatedCount; j++) {\n // A fresh array per row: they are handed to the caller and pushed into\n // by the relation loader, so sharing one would alias every parent's\n // children together.\n shaped[related[j].key] = related[j].many ? [] : null;\n }\n out.push(shaped);\n }\n return out;\n };\n}\n\n/**\n * The fast implementation: a generated function body emitting one object literal\n * with every key spelled out.\n *\n * **Why it is 3.4× faster, since the reason decides what else is worth trying.**\n * Not the property-load indirection — a variant with the column data hoisted\n * into parallel arrays measured 0% different. It is the object's *shape*:\n * `shaped[key] = value` in a loop transitions the hidden class once per\n * property, thirteen times per row on `User`, while a literal with known keys\n * gets one hidden class and one allocation. That is also why there is little\n * further to win here without changing what is returned.\n *\n * Measured on 1000 `User` rows, 13 columns: 187µs interpreted, 55µs compiled,\n * byte-identical output including key order. The comparison is committed at\n * `templates/saas-starter/app/models/bench/shaper.ts` so the claim can be\n * re-run rather than believed.\n *\n * **On generating code.** Every identifier in the emitted source comes from the\n * generated schema — field names and column names — and nothing else, which is\n * the same property that makes the SQL compiler safe. `JSON.stringify` quotes\n * them, so a name containing a quote cannot break out of the literal. This must\n * never widen to anything a caller controls: if a future feature wants a\n * caller-supplied key in the output, it belongs in the interpreted path.\n */\nfunction buildCompiledShaper(\n fields: FieldSchema[],\n dialect: SqlDialect,\n relations: readonly ShapedRelation[],\n): RowShaper {\n const parts: string[] = [];\n\n for (let index = 0; index < fields.length; index++) {\n const field = fields[index];\n const key = JSON.stringify(field.name);\n const column = JSON.stringify(field.column);\n parts.push(\n dialect.needsDecode(field)\n ? `${key}: d.decode(row[${column}], f[${index}])`\n : `${key}: row[${column}] ?? null`,\n );\n }\n\n for (const relation of relations) {\n // Inside the literal, so every row gets its own array — the aliasing hazard\n // the interpreted path comments on is avoided by construction here.\n parts.push(\n `${JSON.stringify(relation.key)}: ${\n relation.kind === \"many\" ? \"[]\" : \"null\"\n }`,\n );\n }\n\n const source = `\n return function shape(rows) {\n const out = [];\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n out.push({ ${parts.join(\", \")} });\n }\n return out;\n };\n `;\n\n try {\n return new Function(\"d\", \"f\", source)(dialect, fields) as RowShaper;\n } catch {\n // `CAN_COMPILE` said yes and this still failed, which would be a schema\n // shape emitting something unparseable — a bug, not an environment. Falling\n // back keeps the query working rather than failing for every caller.\n return buildInterpretedShaper(fields, dialect, relations);\n }\n}\n",
19
- "import {\n InvalidArgumentError,\n RecordNotFoundError,\n UnsupportedQueryError,\n} from \"../errors\";\nimport type { SqlDialect } from \"../dialect\";\nimport type { ModelSchema, RelationSchema } from \"../schema\";\nimport type { Binder } from \"./fragment\";\nimport {\n type Link,\n type NestedWriteStep,\n type RelationExecutor,\n relatedSchema,\n resolveLink,\n singleFieldLink,\n} from \"./plan-relations\";\nimport { matchUniqueKey, type RefusalOrigin } from \"./unique\";\n\n/**\n * Nested writes: `connect`, `connectOrCreate`, shallow `create`, and\n * `createMany`.\n *\n * Which direction a nested write runs in is decided by *who holds the foreign\n * key*, and the two directions are genuinely different operations:\n *\n * ```ts\n * // this model holds organizationId — resolve the key, then insert once\n * User.create({ data: { email, organization: { connect: { id: 1 } } } })\n *\n * // Account holds userId — insert the user, then insert accounts pointing at it\n * User.create({ data: { email, accounts: { create: [{ ... }] } } })\n * ```\n *\n * The first is a `before` step (or, in the common case, no step at all — just a\n * column read straight out of the argument tree). The second is an `after` step,\n * because the key it needs does not exist until the parent row does.\n *\n * `createMany` is the second shape and only exists on the foreign side: the same\n * rows as a nested `create`, in one statement rather than one per row.\n *\n * Everything else in Prisma's nested-write grammar — `set`, `disconnect`,\n * `update`, `upsert`, `delete`, `deleteMany`, `updateMany` — throws\n * `UnsupportedQueryError` naming the operation *and the reason*; see `REFUSED`.\n *\n * **The line this file draws has two halves: which rows an operand can name,\n * and whose columns it writes.**\n *\n * Every supported operand names its rows — a new one, or an existing one the\n * caller identified by unique key — so it goes through the child's own\n * `findUnique`, `create` or `update`, and the child's policies decide whether\n * it is reachable at all. `set`, `disconnect`, `delete`, `deleteMany` and\n * `updateMany` act on rows the *call* did not name, and \"whatever is there\" has\n * no lookup to hang a scope on.\n *\n * `update` is the operand that shows the second half is needed, because it\n * *does* name its row: `update: { where, data }`. It is refused because of what\n * it writes — caller-supplied columns, which need the child's `onUpdate` and\n * the scope-escape guard run over the payload. Every supported operand writes\n * either a whole new row through the child's `create` (where `onCreate`\n * applies) or one foreign key the ORM itself chose.\n *\n * This used to say the line was \"each writes rows that **already exist**\", and\n * that was true until `connectOrCreate` arrived: on the foreign side a hit is\n * an `update` of the child's foreign key, because Prisma repoints the existing\n * row rather than duplicating it. So a supported operand does now write a row\n * that was already there. Restated rather than deleted, because the criterion\n * is what the next operand gets judged against — #75 built the whole `REFUSED`\n * table on it, with a per-entry reason derived from it, and #83's `set` on an\n * implicit many-to-many was fixed by exactly this reading: scope the delete to\n * the rows the caller can see. A stale criterion is worse than none, because it\n * is the one the next reader applies.\n *\n * Atomic since iteration 5: `$exec` opens a transaction for any plan carrying\n * steps, so a nested step that fails — or a child policy that denies — rolls\n * back the parent row too.\n */\n\nconst SUPPORTED_STATEMENTS = [\n \"connect\",\n \"connectOrCreate\",\n \"create\",\n \"createMany\",\n \"disconnect\",\n \"delete\",\n \"update\",\n \"set\",\n \"updateMany\",\n \"deleteMany\",\n \"upsert\",\n] as const;\n\n/**\n * One of {@link SUPPORTED_STATEMENTS}.\n *\n * `NestedCreate` and `NestedUpdate` in `../types` are mapped types over this\n * and the two tuples below, rather than four hand-written key lists in another\n * file. Which statements exist, and which exist only on a to-many or only on a\n * statement with a row to act on, are decisions made *here* — and until #369\n * the caller-facing type made them a second time, with nothing checking that\n * the two answers matched.\n */\nexport type NestedWriteStatement = (typeof SUPPORTED_STATEMENTS)[number];\n\nconst SUPPORTED: ReadonlySet<string> = new Set(SUPPORTED_STATEMENTS);\n\n/**\n * Operands that only exist on a statement with a row to act on.\n *\n * Prisma refuses `disconnect` and `delete` under a `create` — *\"Unknown\n * argument `disconnect`\"* — and it is right to: there is nothing linked to a\n * row that does not exist yet. Refused here rather than accepted and made a\n * no-op, so a caller who wrote one on the wrong operation hears about it.\n */\nconst EXISTING_ROW_ONLY_STATEMENTS = [\n \"disconnect\",\n \"delete\",\n \"update\",\n \"set\",\n \"updateMany\",\n \"deleteMany\",\n \"upsert\",\n] as const;\n\n/** One of {@link EXISTING_ROW_ONLY_STATEMENTS}. `NestedCreate` subtracts it. */\nexport type ExistingRowStatement = (typeof EXISTING_ROW_ONLY_STATEMENTS)[number];\n\nconst EXISTING_ROW_ONLY: ReadonlySet<string> = new Set(\n EXISTING_ROW_ONLY_STATEMENTS,\n);\n\n/**\n * The operands that describe *many* rows, and so exist on a to-many alone.\n *\n * Prisma's to-one nested input is `{ create, connectOrCreate, upsert,\n * disconnect, delete, connect, update }` — measured off a generated client —\n * with no `createMany`, `set`, `updateMany` or `deleteMany` key at all. Both\n * {@link planOwningSide} and {@link planForeignSide} refuse all four on a\n * to-one; this is the list they refuse, named once so the type can subtract it.\n */\nconst COLLECTION_ONLY_STATEMENTS = [\n \"createMany\",\n \"set\",\n \"updateMany\",\n \"deleteMany\",\n] as const;\n\n/** One of {@link COLLECTION_ONLY_STATEMENTS}. The to-one arms subtract it. */\nexport type CollectionOnlyStatement = (typeof COLLECTION_ONLY_STATEMENTS)[number];\n\n/**\n * The three of the four that share one refusal message.\n *\n * `createMany` is excluded because it is refused on its own, in both planners,\n * with a message about there being *one related row* rather than about there\n * being no *set of rows* — and on the foreign side that refusal also guards the\n * operand check that follows it. Derived by subtraction rather than written out\n * again, so a fifth collection-shaped operand added above lands here too.\n */\nconst NO_SET_OF_ROWS: ReadonlySet<string> = new Set(\n COLLECTION_ONLY_STATEMENTS.filter((statement) => statement !== \"createMany\"),\n);\n\n/** Statements that insert a new row, so nothing is linked to it yet. */\nconst CREATE_ONLY_STATEMENTS = new Set([\"create\", \"createMany\"]);\n\n/**\n * The operands still refused, and what each would take.\n *\n * Named individually rather than covered by one message, because \"not\n * implemented\" is much less useful than knowing whether the thing you reached\n * for is a rewrite or a wait. Each of these is a *write to rows that already\n * exist*, which is the line: everything supported writes new rows or repoints a\n * key, and none of it has to reason about what was there before.\n */\n/**\n * Nothing, now — and that is the point of leaving the table here.\n *\n * Every entry it once held described machinery that turned out to exist one\n * layer down: five of them said a pass was missing that the child's own\n * `$exec` already runs, and the sixth — `upsert`'s — said the branch could not\n * be decided from inside a nested step, when `connectOrCreate` had been\n * deciding one the same way since #94.\n *\n * Kept rather than deleted because the next operand added here should have to\n * write its reason down, and because a reason naming *machinery* is checkable\n * where one naming a *principle* is not. That distinction is the only thing\n * that made six stale entries findable.\n */\nconst REFUSED: Record<string, string> = {};\n\n/** A foreign-key column on *this* model that a nested write supplies. */\nexport interface ForeignKeyContribution {\n /** The field name on this model — `organizationId`. */\n field: string;\n /** Produces the value at bind time, already unencoded. */\n value: Binder;\n}\n\nexport interface NestedWritePlanning {\n contributions: ForeignKeyContribution[];\n before: NestedWriteStep[];\n after: NestedWriteStep[];\n /**\n * Fields of *this* model that the statement must return, because an `after`\n * step needs them to point its children at this row.\n */\n keyFields: string[];\n}\n\nconst EMPTY: NestedWritePlanning = {\n contributions: [],\n before: [],\n after: [],\n keyFields: [],\n};\n\nexport function planNestedWrites(\n schema: ModelSchema,\n data: unknown,\n operation: string,\n /** Re-locates `data` inside the call's argument tree at bind time. */\n locateData: (args: any) => any,\n /**\n * Needed only by the implicit many-to-many path, which emits statements\n * against a table with no model and therefore has no `Fragment` pipeline to\n * number its placeholders — SQLite writes `?` and Postgres `$1`.\n */\n dialect: SqlDialect,\n): NestedWritePlanning {\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) {\n return EMPTY;\n }\n\n const entries = Object.keys(data as Record<string, unknown>)\n .sort()\n .filter((key) => key in schema.relations)\n .filter((key) => (data as Record<string, unknown>)[key] !== undefined);\n\n if (entries.length === 0) return EMPTY;\n\n const planning: NestedWritePlanning = {\n contributions: [],\n before: [],\n after: [],\n keyFields: [],\n };\n\n /** Which relation contributed each foreign-key column, for the guard below. */\n const contributedBy = new Map<string, string>();\n\n for (const key of entries) {\n const relation = schema.relations[key];\n const node = (data as Record<string, unknown>)[key];\n const locate = (args: any) => locateData(args)?.[key];\n const before = planning.contributions.length;\n\n planOne(schema, relation, node, operation, locate, planning, dialect);\n\n // **Two relations that share a foreign-key column are refused by name**\n // (#271). A composite relation joins on *n* columns and nothing stops two\n // of them from sharing one — it is the tenant-scoped shape this whole\n // change is about:\n //\n // ledger Ledger @relation(fields: [tenantId, ledgerCode], …)\n // note Ledger @relation(fields: [tenantId, noteCode], …)\n //\n // `prisma validate` accepts that on 6.19.2, and before #271 both relations\n // were refused here for their width, so writing through both at once was\n // unreachable. It is reachable now, and the two `tenantId` contributions\n // collide: `insertColumns` folds contributions through a `Map` keyed by\n // field, so the later one wins, and `entries` above is sorted, so the\n // winner is whichever relation sorts last.\n //\n // **Prisma resolves the operands in the opposite direction and lets the\n // first resolved win, so the caller's last `data` key decides the shared\n // column** — measured on 6.19.2 with query events on: writing\n // `{ note: connect(2,\"b\"), ledger: connect(1,\"a\") }` stores `tenantId=1`\n // where `{ ledger: …, note: … }` stores `2`. gemi stores `2` either way.\n //\n // Matching that would mean giving up the sorted key order, which the plan\n // cache needs — two argument objects differing only in key order have to\n // be one plan. So this refuses instead, which is what the width refusal\n // this change replaced was buying: no plausible wrong row. A caller who\n // wants both links connects through one relation — which writes the shared\n // column — and sets the other relation's remaining columns directly, since\n // `insertColumns` only refuses a column that is written *both* ways.\n for (let index = before; index < planning.contributions.length; index++) {\n const field = planning.contributions[index].field;\n const owner = contributedBy.get(field);\n if (owner !== undefined && owner !== key) {\n throw new UnsupportedQueryError(\n `data.${key}`,\n schema.name,\n operation,\n `'${field}' is written by both the '${owner}' and '${key}' relations, ` +\n `which join on it in common. Prisma lets the last key in 'data' win; ` +\n `gemi plans relations in a fixed order and will not guess which row ` +\n `you meant. Write one of them through the relation and set the ` +\n `other's own columns directly.`,\n );\n }\n contributedBy.set(field, key);\n }\n }\n\n return planning;\n}\n\nfunction planOne(\n schema: ModelSchema,\n relation: RelationSchema,\n node: unknown,\n operation: string,\n locate: (args: any) => any,\n out: NestedWritePlanning,\n dialect: SqlDialect,\n): void {\n if (typeof node !== \"object\" || node === null || Array.isArray(node)) {\n throw new InvalidArgumentError(\n `data.${relation.name}`,\n schema.name,\n operation,\n \"Expected an object holding 'connect' or 'create'.\",\n );\n }\n\n // Sorted, and it is load-bearing twice over. The plan cache needs it — two\n // argument objects differing only in key order must be one plan — and the\n // *order the steps run in* falls out of it, because they are pushed in this\n // order and run in that order.\n //\n // Only one pair is order-sensitive today, and it happens to sort the right\n // way: `create` before `createMany` is what Prisma does, verified from the\n // ids it hands back. `connect` before `createMany` is the other pair and its\n // order is not observable — repointing an existing child and inserting new\n // ones do not interact — but it is pinned by a differential case rather than\n // left to be rediscovered.\n //\n // So: this is a coincidence that is currently correct. An operand added here\n // whose order *is* observable cannot rely on the alphabet and has to sequence\n // itself explicitly.\n const keys = Object.keys(node as Record<string, unknown>)\n .sort()\n .filter((key) => (node as Record<string, unknown>)[key] !== undefined);\n\n if (keys.length === 0) return;\n\n const child = relatedSchema(schema, relation);\n\n // **Every joined field, not the first one** (#271).\n //\n // This used to be `singleFieldLink(resolveLink(…))`: reading across\n // `@relation(fields: [tenantId, orderId], references: [tenantId, id])` was\n // implemented by #67 on all six read surfaces, and the write surface refused\n // it by name rather than joining on the first field and writing plausible\n // wrong rows. The refusal was honest and it was the only thing left on that\n // list, so the narrowing is gone and what follows contributes *n* foreign-key\n // columns wherever it used to contribute one.\n //\n // Nothing here branches on how many there are. The two sides read the link\n // through {@link childLink}, {@link keySelect} and {@link nullKey}, which are\n // the same three shapes for one field as for four — so a relation joining on\n // one field compiles to exactly the arguments it did before, and there is no\n // single-field path left to diverge from the composite one.\n const link = resolveLink(schema, child, relation, operation);\n\n // An implicit many-to-many is *neither* side: the keys live in a third table\n // with no model, so both directions are the same work and the operand set is\n // wider — `disconnect` and `set` are a delete against the join table, which\n // needs no schema to compile.\n if (link.join) {\n // **The one caller that still cannot take more than one field**, and it is\n // an invariant rather than a gap: Prisma's implicit many-to-many links\n // parent and child by their *primary keys*, one column each side, into a\n // two-column join table there is no schema to widen. `singleFieldLink`\n // states that rather than letting `planJoinTable` index into `[0]` and be\n // silently wrong if it ever stopped holding.\n const pair = singleFieldLink(link, schema, relation, operation);\n\n for (const key of keys) {\n planJoinTable(\n schema,\n relation,\n child,\n pair,\n key,\n (node as Record<string, unknown>)[key],\n operation,\n (args: any) => locate(args)?.[key],\n out,\n dialect,\n );\n }\n return;\n }\n\n for (const key of keys) {\n if (!SUPPORTED.has(key)) {\n const why = REFUSED[key];\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `Only ${[...SUPPORTED].sort().join(\", \")} are implemented.` +\n (why ? ` '${key}' is not: ${why}` : \"\"),\n );\n }\n\n // `create` has no row to disconnect from, and Prisma does not offer these\n // there either — it reports them as an unknown argument.\n if (EXISTING_ROW_ONLY.has(key) && CREATE_ONLY_STATEMENTS.has(operation)) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${key}' acts on rows already linked to this one, and a '${operation}' ` +\n `has none yet — Prisma refuses it here too. Use it on an 'update'.`,\n );\n }\n }\n\n // `from` is non-empty exactly on the side that holds the foreign key.\n const owning = relation.from.length > 0;\n\n for (const key of keys) {\n const operand = (node as Record<string, unknown>)[key];\n const at = (args: any) => locate(args)?.[key];\n\n if (owning) {\n planOwningSide(\n schema,\n relation,\n child,\n link,\n key,\n operand,\n operation,\n at,\n out,\n );\n } else {\n planForeignSide(\n schema,\n relation,\n child,\n link,\n key,\n operand,\n operation,\n at,\n out,\n );\n }\n }\n}\n\n/**\n * This model holds the foreign key, so the far row must exist — or be created —\n * before the insert can bind, and the whole thing collapses to *n* extra\n * columns — one, in the ordinary schema; as many as the relation joins on in a\n * tenant-scoped one (#271).\n *\n * **The columns are contributed to the statement the caller already asked for,\n * which is what makes a composite key here atomic without arranging anything.**\n * `contributions` is a list keyed by field, and `insertColumns` /\n * `updateAssignments` fold every entry into the single `INSERT` or `UPDATE`\n * this operation compiles to — so \"some keys written, some not\" is not a state\n * this side can reach: the `before` step either resolves the whole tuple or\n * throws, and the statement either runs or does not. The partial-write hazard\n * is real on the *foreign* side, where each linked row is its own statement,\n * and it is answered there by the transaction every plan carrying steps opens.\n */\nfunction planOwningSide(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n link: Link,\n key: string,\n operand: unknown,\n operation: string,\n at: (args: any) => any,\n out: NestedWritePlanning,\n): void {\n // `parentFields` are the FK columns on this model; `childFields` are what\n // they reference on the other one, paired positionally.\n const fkFields = link.parentFields;\n const referencedFields = link.childFields;\n\n /** Assign the resolved key onto the statement — one contribution per column. */\n const contributeResolved = () => {\n for (const field of fkFields) {\n out.contributions.push({\n field,\n value: (_args, context) => context.resolved[field],\n });\n }\n };\n\n /** Record a whole key on the plan's per-call scratch space. */\n const resolveKey = (\n context: { resolved: Record<string, unknown> },\n values: readonly unknown[],\n ) => {\n for (let index = 0; index < fkFields.length; index++) {\n context.resolved[fkFields[index]] = values[index] ?? null;\n }\n };\n\n /**\n * **Whether linking through this relation has to displace a sibling** — the\n * one-to-one case, where this row's foreign key carries the `@unique` that\n * makes the far row hold one partner, so pointing at an occupied one is a\n * collision rather than a second link (#363).\n *\n * **It takes both halves: the unique index *and* the far side's `kind`.** The\n * first draft of this used the index alone, on the argument that\n * `planForeignSide`'s `relation.kind` test and this one were \"the same\n * predicate, two spellings\". They are not, and the difference is a silent\n * destructive write rather than a wording problem.\n *\n * The implication holds one way only. P1012 gives *`kind !== \"many\"` implies\n * the key is unique* — Prisma will not let a non-list back-relation exist\n * beside a foreign key with no `@unique`. **The converse is false.** A\n * `@unique` foreign key beside a *list* back-relation is a schema Prisma\n * accepts:\n *\n * model Team { id Int @id players Player[] }\n * model Player { id Int @id teamId Int? @unique\n * team Team? @relation(fields: [teamId], references: [id]) }\n *\n * `prisma validate` on that is *\"The schema at b.prisma is valid\"* — measured,\n * not assumed. And the index alone would have displaced there, where Prisma\n * does not: `Player.update({ where: { id: 2 }, data: { team: { connect:\n * { id: 2 } } } })` with player 1 already on team 2 answers **P2002** and its\n * whole statement log is `SELECT Team.id`, the `UPDATE`, `ROLLBACK` — the\n * sibling is never even read. Against the same key with `keeper Keeper?` in\n * place of `players Player[]`, the identical call displaces and the log gains\n * the incumbent `SELECT` and its clear. So the *back-relation* is what\n * decides, and the index is a necessary condition rather than the answer.\n *\n * It is not an exotic shape either: a `@unique` added to a foreign key for\n * indexing, or a one-to-many half-migrated to a one-to-one, both land on it.\n * Without the second half gemi's two ends disagreed about one relation — the\n * foreign side saw `kind === \"many\"` and refused to displace, this side saw\n * the index and did.\n *\n * So `relation.kind` is still not readable from here — it says `\"one\"` for a\n * many-to-one and a one-to-one alike, because both point at a single far row,\n * which is the part of the original argument that survives. The question goes\n * to the *child's* copy of the relation instead, found by `relationName`, and\n * `uniques` narrows it rather than answering it.\n *\n * **A back-relation that cannot be identified does not displace.** Absent or\n * ambiguous, the answer is unknown, and of the two ways to be wrong only one\n * writes to a row nobody named — so the fallback is the collision this\n * operand raised before #363, which is also what a schema too malformed to\n * read should get. The self-relation exclusion is `otherSide`'s, restated\n * rather than shared because that function *throws* on the same condition and\n * has never run on this path: turning a schema that compiled yesterday into a\n * hard error is not this issue's to do.\n *\n * Nullable, for the same reason the foreign side is: a detach has to leave a\n * value behind. A required foreign key cannot be nulled, so the repoint\n * collides as it always did. That is not what Prisma answers — it refuses\n * ahead of the write with P2014, *\"The change you are trying to make would\n * violate the required relation\"*, measured on a scratch schema, since this\n * one carries no required one-to-one for a case to reach. Recorded rather\n * than matched: it is a divergence in the failure's *class* on a call that\n * fails either way, where every other line of this is about a call that\n * succeeds. `assertDisconnectable` is deliberately not called, exactly as on\n * the foreign side: it would refuse the whole operand, including the\n * empty-far-row case that has always worked.\n *\n * **An index over exactly the relation's own fields**, which is what the\n * single-field test used to say and reads differently now that there may be\n * several (#271). Prisma's rule is on the relation: *\"A one-to-one relation\n * must use unique fields on the defining side\"*, meaning `fields` — so\n * `@@unique([tenantId, ownerId])` beside `@relation(fields: [tenantId,\n * ownerId], …)` is the composite one-to-one, and it is the same fact the\n * single-column form was stating.\n *\n * **Both halves of that rule are Prisma's, measured on 6.19.2 rather than\n * inferred**, because between them they are the whole discriminator:\n *\n * @@unique([tenantId, ledgerCode]) accepted — the one-to-one\n * @@unique([tenantId, ledgerCode, seal]) P1012, \"Either add an\n * `@@unique([tenantId,\n * ledgerCode])` attribute\"\n * @@unique([ledgerCode, tenantId]) the identical P1012\n *\n * So a wider group does *not* make the relation one-to-one — reading it as\n * one would clear rows the schema never said were exclusive — and the order\n * has to match the relation's `fields` as well.\n *\n * Written as set equality all the same, and the second row is why that is not\n * laxity: the length check is what carries the weight, and a positional loop\n * would read as though order were a thing this had decided, when on any\n * schema Prisma accepted the two lists are already identical. It also keeps a\n * hand-built `ModelSchema` — a fixture, or a generator that reorders — out of\n * the branch where the index is not recognised at all.\n *\n * A foreign key that is also the `@id` would not be found in `uniques`, which\n * records `@unique` and `@@unique` rather than the primary key; it is out of\n * reach anyway, since `@id` implies `NOT NULL` and the nullable guard has\n * already excluded it.\n */\n const backRelations = Object.values(child.relations).filter(\n (candidate) =>\n candidate.relationName === relation.relationName &&\n // A self-relation names the same model on both ends, so the *field* is\n // what distinguishes them — `otherSide`'s test, and without it a\n // self-referencing one-to-many would find its own owning side here,\n // read `kind: \"one\"` off it and displace.\n !(child.name === schema.name && candidate.name === relation.name),\n );\n\n const keyed = new Set(fkFields);\n\n const displaces =\n fkFields.every((field) => schema.fields[field]?.nullable === true) &&\n schema.uniques.some(\n (unique) =>\n unique.length === keyed.size && unique.every((name) => keyed.has(name)),\n ) &&\n backRelations.length === 1 &&\n backRelations[0].kind !== \"many\";\n\n /**\n * Whether there is a row to displace *from* — false under a `create`, where\n * this row does not exist yet, so nothing it holds can be the incumbent.\n */\n const existing = !CREATE_ONLY_STATEMENTS.has(operation);\n\n // This side is a to-one by construction — it holds a single foreign key — so\n // there is nothing for a `createMany` to write many of. Prisma does not offer\n // it here either; refused with the reason rather than the grammar, because a\n // caller who reached for it has the direction of the relation wrong.\n // The *other* half of this refusal is in `planForeignSide`, which reaches the\n // same conclusion from the far side of the key: a one-to-one whose child\n // holds the foreign key is still a to-one. Both are reachable and neither\n // subsumes the other, so the message is duplicated rather than shared.\n if (key === \"createMany\") {\n throw new UnsupportedQueryError(\n `data.${relation.name}.createMany`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: this row holds the foreign key, so ` +\n `there is one related row at most and nothing to create many of. ` +\n `Prisma does not accept it here either.`,\n );\n }\n\n if (key === \"create\") {\n // The far row does not exist yet: create it first, through its own model's\n // `$exec` so it is subject to everything a top-level create is (invariant 1).\n out.before.push({\n relation: relation.name,\n operation: \"create\",\n async run(args, context, executor) {\n const created = (await executor.exec(\n relation.model,\n \"create\",\n { data: at(args), select: keySelect(referencedFields) },\n // NOT pre-scoped. Nothing walks `data.<relation>.create`, so the\n // child's own `onCreate` is the only thing that can scope this row.\n false,\n )) as Record<string, unknown> | null;\n\n resolveKey(context, valuesOf(created, referencedFields));\n },\n });\n contributeResolved();\n return;\n }\n\n /**\n * `connectOrCreate` — find the row by a unique key, and create it only if it\n * is not there.\n *\n * **A hit ignores `create` entirely**, which is not what the name suggests\n * and is worth pinning: it is `connect`-or-create, not upsert. Measured — an\n * existing organisation kept its own name where the `create` payload named a\n * different one.\n *\n * `findUnique`, not `findUniqueOrThrow`: a miss is the *other branch* here,\n * where for a plain `connect` it is an error.\n *\n * Object only on this side. The relation holds one foreign key, so there is\n * one row to point at, and Prisma refuses an array here too.\n */\n /**\n * `disconnect` on a to-one whose key is on **this** row — the same three arms\n * the foreign side takes, through the same two helpers (#359).\n *\n * Prisma's operand here is `XWhereInput | boolean`, read off the generated\n * client and measured against it:\n *\n * disconnect: true clears the link\n * disconnect: false nothing happens, the link survives\n * disconnect: {} clears it — the empty filter matches\n * disconnect: { name: \"Ada\" } clears it only if the linked row matches\n * disconnect: { name: \"Grace\" } no match, so nothing happens — and\n * **silently**, not P2025\n * disconnect: <filter>, nothing linked silently nothing\n *\n * The silence in the last two is what makes the filter arm a *conditional*\n * detach rather than a guarded one: there is no miss to report, which is the\n * same asymmetry the foreign side measured between `disconnect` and `delete`\n * (M8c). So the arms differ only in what decides the value of one column.\n *\n * **The boolean is structural here, where the foreign side re-reads it at\n * bind time**, and that difference is forced rather than chosen. The foreign\n * side's operands are *statements* — `listOf(null)` is no statement — so a\n * plan handed the wrong boolean can still write nothing. This side's is a\n * *column in the SET list*: `false` emits no assignment and `true` emits one,\n * so the two spellings cannot share a statement text and no bind-time check\n * could rescue a cache hit that got it wrong. What makes that sound is\n * `shapeOfMember`'s guard (#358), which gives a `disconnect` boolean its own\n * plan key precisely because this decision is made once, at compile time.\n * Before it, a plan compiled from `true` served `false` and nulled a foreign\n * key on a call that asked for nothing.\n *\n * `delete` has no meaning here for the same reason it has no `createMany`:\n * this side is a to-one, and deleting the far row through a `data` key would\n * be deleting a row the statement is not about. Prisma does offer it; it is\n * refused rather than guessed, because a `delete` that fires as a side effect\n * of an unrelated update is the kind of thing to implement deliberately.\n */\n if (key === \"disconnect\") {\n // Before the arms, so a required foreign key is refused whichever one was\n // spelled — including `false`, which asks for nothing and still cannot be\n // written. Prisma agrees for a reason of its own: it leaves `disconnect`\n // out of the input type entirely when the relation is required, so\n // `disconnect: false` there is *\"Unknown argument `disconnect`\"* rather\n // than an accepted no-op. Measured on `SocialAccount.user`.\n assertDisconnectable(schema, relation, fkFields, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.disconnect`,\n });\n\n // `true` -> `{}`, `false` -> `null`, a filter passes through: the same\n // translation and the same shape check the foreign side runs, reused rather\n // than restated so the two sides cannot answer one grammar differently\n // again — which is the defect #359 was filed for.\n //\n // The check goes **first**, on the operand as written: the translation is\n // lossy in the one direction that matters, since it maps `false` onto the\n // same `null` a caller may have spelled outright. See `assertToOneFilter`.\n assertToOneFilter(schema, relation, child, operand, key, operation);\n const filter = toOneOperand(key, operand);\n\n // `false` — no contribution and no step, so the operand contributes\n // *nothing at all*: a `data` carrying only this compiles to the read\n // `compileUpdate` emits for an empty assignment list, and the row comes\n // back with its link intact. That is Prisma's answer, and the reason the\n // differential asserts it by value: what this replaces was a write.\n if (filter === null || filter === undefined) return;\n\n /**\n * `true` — the link's columns bound to `null`, exactly as `connect`'s\n * direct form binds them to a value. No step, nothing on the child read or\n * written, and so no scoping question: the row being changed is the one the\n * statement already names.\n */\n if (operand === true) {\n for (const field of fkFields) {\n out.contributions.push({ field, value: () => null });\n }\n return;\n }\n\n /**\n * A filter — detach only if the row this one points at matches it.\n *\n * Two reads, and neither is avoidable from this side. The condition is a\n * property of the *linked* row, and which row that is lives in a column of\n * the row being updated, which the arguments do not carry — so the parent\n * is read first and the child second. The far side needs neither: its\n * filter goes straight into the `where` of the `updateMany` that clears the\n * key, because there the key is on the row being filtered.\n *\n * **The child read goes through the child's own `$exec`, un-pre-scoped**,\n * which is what puts this operand on the supported side of this file's\n * line. A `disconnect` that acts on \"whatever is there\" has no lookup to\n * hang a scope on; this one has, so a child the caller's policies hide\n * reads as absent and the link survives — the same conservative answer\n * `set` gives, and the same one the foreign side's `disconnect` gives for a\n * hidden row.\n *\n * The parent read is **pre-scoped**: `args.where` is the effective `where`\n * this call already put through this model's policies, so re-applying them\n * would `AND` the same predicate twice. It reads one column of one row —\n * `update` matched its `where` against a unique key — inside the\n * transaction the nested steps already run in, so the value it returns is\n * the one the statement below is about to write over.\n */\n out.before.push({\n relation: relation.name,\n operation: \"disconnect\",\n async run(args, context, executor) {\n // Default to the values that are already there, so a filter that\n // matches nothing writes the columns back unchanged. The contributions\n // are in the SET list either way — the statement's text cannot depend\n // on a value read at bind time — so \"nothing happens\" has to be spelled\n // as assignments that change nothing rather than as absent ones.\n resolveKey(context, nullsFor(fkFields));\n\n const parent = (await executor.exec(\n schema.name,\n \"findFirst\",\n { where: args?.where, select: keySelect(fkFields) },\n true,\n )) as Record<string, unknown> | null;\n\n const linked = valuesOf(parent, fkFields);\n // Nothing linked: no row for the filter to match, and Prisma is silent\n // about it. `null` is already what the columns hold. A *partially*\n // written composite key lands here too, and that is the right answer —\n // it joins to no row, so no filter can match through it.\n if (!isLinked(linked)) return;\n\n resolveKey(context, linked);\n\n const matched = await executor.exec(\n relation.model,\n \"findFirst\",\n {\n // `AND`, not a spread: a filter naming a referenced column itself\n // must narrow rather than replace the restriction that keeps this\n // on the linked row. Same rule as everywhere else here.\n // `link` reads the same way on this side: its `parentFields` are\n // this row's foreign key and its `childFields` are what they\n // reference, so `childLink` yields the far row's own columns bound\n // to the values just read off this one.\n where: conjoin(at(args), childLink(link, parent as Record<string, unknown>)),\n select: keySelect(referencedFields),\n },\n false,\n );\n\n if (matched) resolveKey(context, nullsFor(fkFields));\n },\n });\n\n contributeResolved();\n return;\n }\n\n if (key === \"delete\") {\n throw new UnsupportedQueryError(\n `data.${relation.name}.delete`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one whose foreign key lives on this row, so ` +\n `deleting through it would remove a row this statement is not about. ` +\n `Delete it directly, or 'disconnect' it first.`,\n );\n }\n\n /**\n * `update` through a to-one — this row holds the key, so the row being\n * written is the one it points at.\n *\n * Prisma accepts both spellings, measured: `update: { name: \"x\" }` and\n * `update: { data: { name: \"x\" } }`. The second is the documented one and the\n * first is what people write; accepting only one would refuse a legal query.\n *\n * An `after` step rather than a `before` one, and it needs the foreign key in\n * the statement's `RETURNING` — the far row is identified by *this* row's\n * column, whose current value the arguments do not carry. That is why\n * `keyFields` gains it here, where the other owning-side operands need\n * nothing returned at all.\n */\n if (key === \"update\") {\n out.keyFields.push(...fkFields);\n\n // The same check the foreign side runs, on the same operand grammar. Both\n // sides accept `{ where?, data }` and both must refuse an unknown key\n // inside it, or a misspelled `where` silently widens the write on whichever\n // side missed the check — the asymmetry #116 was filed about, arriving one\n // operand later.\n assertToOneWriteOperand(schema, relation, child, key, operand, operation);\n\n out.after.push({\n relation: relation.name,\n operation: \"update\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n // A composite key with any column null names no row — see\n // {@link isLinked} — so a half-written link is the *absent* case here\n // rather than a lookup that finds nothing later.\n if (!isLinked(valuesOf(parent, fkFields))) {\n // The same error as the foreign side's miss, and for the same reason\n // — this is one condition with two spellings, not two conditions.\n // Measured rather than inferred: Prisma answers P2025 here too,\n // *\"depends on one or more records that were required but not\n // found\"*, which `failureKind` maps to `notFound`.\n //\n // `UnsupportedQueryError` was wrong twice over. It classifies as\n // `other`, so the differential harness would have called it agreement\n // with a Prisma refusal of a different kind — and it prefixes \"does\n // not support … yet\", which reports a fully-implemented operation as\n // unimplemented because a row is missing. That vocabulary has been\n // corrected once each on #82 and #88.\n throw new RecordNotFoundError(relation.model, \"update\");\n }\n\n // `.data !== undefined` rather than `\"data\" in operandAt`, which is the\n // test {@link toOneOperand} makes and the one this used to disagree\n // with. `canonicalShape` drops an `undefined`-valued key, so `update:\n // {}` and `update: { data: undefined }` are one plan entry — and an\n // explicit `undefined` is the ordinary way a conditional write is\n // spelled, which is why `suppliedFields` skips it everywhere else.\n // Keying on presence sent `data: undefined` down to `updateMany` and\n // answered a no-op call with `updateMany requires 'data'`, on the side\n // this file cites as the precedent for the other one.\n const operandAt = at(args);\n const wrapped =\n operandAt !== null &&\n typeof operandAt === \"object\" &&\n (operandAt as Record<string, unknown>).data !== undefined;\n const record = operandAt as Record<string, unknown> | null;\n const data = wrapped ? record!.data : operandAt;\n\n // The caller's filter, conjoined with the link — so `update: { where,\n // data }` narrows *which* single row is written rather than being\n // decoration. Ignoring it was a silent wrong write: the operand\n // type-checks on both sides, the foreign side conjoins it and raises on\n // a miss, and this side renamed the linked row whether or not it\n // matched. Prisma answers P2025 for the non-matching case, which is\n // what the lookup below reproduces.\n //\n // The lookup only happens when a `where` is actually present, and that\n // is shape-stable — `canonicalShape` records a `where` key's presence —\n // so the common `update: { … }` spelling still costs one statement.\n const filter = wrapped ? record!.where : undefined;\n const where = conjoin(filter, childLink(link, parent));\n\n if (filter !== undefined) {\n const found = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(referencedFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (!found) throw new RecordNotFoundError(relation.model, \"update\");\n }\n\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data },\n // NOT pre-scoped: the child's own policies decide whether this row is\n // reachable and whether the payload is allowed to write what it\n // names — its `onUpdate` and its scope-escape guard.\n false,\n );\n },\n });\n return;\n }\n\n /**\n * `upsert` through a to-one, refused **by name**.\n *\n * The far row is identified by *this* row's foreign key, so an absent one\n * means creating the far row and then writing back to a parent that has\n * already been inserted — a shape no other operand here needs, and the\n * reason this side is not implemented.\n *\n * Named rather than left to fall through, which is what it did: with no\n * branch of its own it reached the `connect` handling below and reported\n * `'where' yet (Organization.update.organization.connect)` — a different\n * operand, a different model, and a claim that `{ id: 1 }` is not a unique\n * field when it is. The real failure was that a `{ where, create, update }`\n * operand was being read as a connect key.\n *\n * That is the shape #85 was filed for and #101 fixed on its own path: a\n * refusal that misnames its origin sends the reader to a query they did not\n * write.\n */\n /**\n * The list operands, refused by name on a to-one.\n *\n * `set`, `updateMany` and `deleteMany` describe *many* rows, and this side\n * has one by construction — Prisma does not offer them here either. They were\n * in `SUPPORTED` with no branch on this side, so they fell through to the\n * `connect` handling below and reported `connect` back to a caller who wrote\n * something else. Same fall-through as `upsert`'s, found by the same test.\n *\n * The fourth collection operand, `createMany`, is refused above this with its\n * own wording, which is why the set read here is {@link NO_SET_OF_ROWS} and\n * not {@link COLLECTION_ONLY_STATEMENTS} whole.\n */\n if (NO_SET_OF_ROWS.has(key)) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: this row holds a single foreign key, so ` +\n `there is no set of rows for '${key}' to act on. Prisma does not ` +\n `accept it here either. Use 'connect', 'disconnect' or 'update'.`,\n );\n }\n\n if (key === \"upsert\") {\n throw new UnsupportedQueryError(\n `data.${relation.name}.upsert`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one, and this row holds its foreign key — ` +\n `so an absent far row would have to be created and then written back ` +\n `to a ${schema.name} that has already been inserted. That is not ` +\n `implemented. Upsert the ${relation.model} directly, then 'connect' ` +\n `it.`,\n );\n }\n\n if (key === \"connectOrCreate\") {\n assertConnectOrCreateOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n false,\n );\n\n out.before.push({\n relation: relation.name,\n operation: \"connectOrCreate\",\n async run(args, context, executor) {\n const where = at(args)?.where;\n\n const found = (await executor.exec(\n relation.model,\n \"findUnique\",\n { where, select: keySelect(referencedFields) },\n // NOT pre-scoped, for the reason `connect` is not: this reads another\n // model's rows to decide what to attach, so that model's policies say\n // which rows exist. Scoped away, a hit becomes a miss and the row is\n // *created* — so the fallback branch is what keeps this from being a\n // way to observe another tenant's keys.\n false,\n )) as Record<string, unknown> | null;\n\n if (found) {\n const values = valuesOf(found, referencedFields);\n // A hit **is** a connect, so it displaces where the miss below cannot\n // — measured on both sides, and the reason `displaces` is consulted\n // per *branch* rather than per operand. `planForeignSide`'s table\n // records the same split from the other end (M14c / M15d).\n if (displaces) {\n await displaceSibling(\n schema,\n fkFields,\n values,\n args?.where,\n existing,\n executor,\n );\n }\n resolveKey(context, values);\n return;\n }\n\n const created = (await executor.exec(\n relation.model,\n \"create\",\n { data: at(args)?.create, select: keySelect(referencedFields) },\n // NOT pre-scoped — the child's own `onCreate` scopes the new row.\n false,\n )) as Record<string, unknown> | null;\n\n // No displacement on this branch, and it is not an omission: the far\n // row was minted a line ago, so nothing can already be pointing at it.\n // Prisma agrees by construction rather than by rule — its miss branch\n // logs the insert and the repoint and no incumbent lookup at all.\n resolveKey(context, valuesOf(created, referencedFields));\n },\n });\n\n contributeResolved();\n return;\n }\n\n // `connect`. In the common case the caller already handed us the referenced\n // value — `connect: { id: 1 }` where the relation references `id` — and no\n // query is needed at all: it is one more bound column.\n //\n // Whether that is the case is a property of the argument *shape*, not of its\n // values, so the choice is made here at compile time and the two forms are two\n // plans. That is what keeps a `connect` from silently costing a round trip.\n if (\n typeof operand !== \"object\" ||\n operand === null ||\n Array.isArray(operand)\n ) {\n throw new InvalidArgumentError(\n `data.${relation.name}.connect`,\n schema.name,\n operation,\n \"Expected an object naming a unique field.\",\n );\n }\n\n /**\n * **Single-field only, and a composite `connect` takes the lookup** (#271).\n *\n * The optimisation is \"the caller already handed us the value the column\n * needs\", and on a composite relation they did not: Prisma spells a\n * multi-column unique key in its *compound* form —\n * `connect: { tenantId_code: { tenantId: 1, code: \"a\" } }`, one argument key\n * named after the index — so there is no key here whose value is a referenced\n * column. Reading one out would mean reproducing the generator's `_`-joined\n * naming rule inside the planner, and then assuming the caller reached for\n * the group the relation *references* rather than any other unique key on the\n * child, which `connect` explicitly allows.\n *\n * So the composite case pays one `findUniqueOrThrow`, and that costs parity\n * nothing: Prisma issues the same lookup. Measured on 6.19.2 with query\n * events on, `LedgerEntry.create({ data: { amount: 1, ledger: { connect:\n * { tenantId_code: { tenantId: 1, code: \"ab\" } } } } })` logs\n *\n * BEGIN IMMEDIATE\n * select Ledger.tenantId, Ledger.code where tenantId = ? and code = ?\n * insert into LedgerEntry (tenantId, ledgerCode, amount) values (?,?,?)\n * select the row back\n * COMMIT\n *\n * — the resolve is a statement there too. The zero-query path was always a\n * gemi-only shortcut over the shape where the operand *is* the value.\n */\n const direct =\n referencedFields.length === 1 &&\n (operand as Record<string, unknown>)[referencedFields[0]] !== undefined &&\n Object.keys(operand as Record<string, unknown>).filter(\n (name) => (operand as Record<string, unknown>)[name] !== undefined,\n ).length === 1;\n\n if (direct) {\n const referenced = referencedFields[0];\n const fkField = fkFields[0];\n\n /**\n * **The direct form still costs a step when it has an incumbent to\n * displace**, and only then.\n *\n * \"No query is needed at all\" is a claim about resolving the *operand*, and\n * it survives: the value is still read straight out of the argument tree\n * and never looked up. What a one-to-one adds is a second row that has to\n * stop holding it, which no amount of knowing the value answers.\n *\n * The condition is the schema's, not the call's, so the two forms are\n * still decided once at compile time and a many-to-one `connect` — which\n * is every `connect` in an ordinary schema — keeps the zero-query path it\n * has always had.\n */\n if (displaces) {\n out.before.push({\n relation: relation.name,\n operation: \"connect\",\n async run(args, _context, executor) {\n await displaceSibling(\n schema,\n [fkField],\n [at(args)?.[referenced]],\n args?.where,\n existing,\n executor,\n );\n },\n });\n }\n\n out.contributions.push({\n field: fkField,\n value: (args) => at(args)?.[referenced],\n });\n return;\n }\n\n // `connect: { publicId: \"...\" }` against a relation that references `id`:\n // Prisma resolves it with a lookup, and so do we. Validated now so a\n // non-unique connect target fails at compile time rather than matching an\n // arbitrary row.\n matchUniqueKey(child, operand, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.connect`,\n });\n\n out.before.push({\n relation: relation.name,\n operation: \"connect\",\n async run(args, context, executor) {\n const found = (await executor.exec(\n relation.model,\n \"findUniqueOrThrow\",\n { where: at(args), select: keySelect(referencedFields) },\n // NOT pre-scoped. This lookup reads another model's rows to decide what\n // to attach, so it is that model's policies that say which rows exist —\n // otherwise a `connect` by any unique key reaches every tenant's.\n false,\n )) as Record<string, unknown> | null;\n\n const values = valuesOf(found, referencedFields);\n\n // After the lookup, which is the ordering #363 asked how to get: the\n // clear cannot be written until the referenced value is known, and\n // sitting in the same step is what orders it without having to order a\n // write between two reads that are otherwise independent. It also puts\n // the *miss* on the right side of the detach — `findUniqueOrThrow` has\n // already raised, so a `connect` naming no row displaces nothing, which\n // is Prisma's answer (P2025 with the incumbent untouched).\n if (displaces) {\n await displaceSibling(\n schema,\n fkFields,\n values,\n args?.where,\n existing,\n executor,\n );\n }\n\n resolveKey(context, values);\n },\n });\n contributeResolved();\n}\n\n/**\n * The *child* holds the foreign key, so nothing can be written until this row\n * exists and its key is known. Both forms are therefore `after` steps, and both\n * need the key in the statement's `RETURNING` list — **every column of it**,\n * since a composite link is only usable once the whole tuple is known (#271).\n *\n * **This is the side the partial-write hazard is real on**, and it is answered\n * rather than avoided. The owning side folds its columns into one statement;\n * here each linked row is its own `update` or `create`, so a composite key\n * whose second statement fails leaves the first row repointed. `$exec` opens a\n * transaction for any plan carrying steps — iteration 5 — so the failure rolls\n * the parent row back with it, which is the same guarantee that already covers\n * a `connect` of three rows where the third does not exist.\n */\nfunction planForeignSide(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n link: Link,\n key: string,\n operand: unknown,\n operation: string,\n at: (args: any) => any,\n out: NestedWritePlanning,\n): void {\n const parentFields = link.parentFields;\n const childFields = link.childFields;\n\n out.keyFields.push(...parentFields);\n\n /**\n * **Whether linking through this relation has to displace what is linked\n * already** — the to-one case, where the child's key carries the `@unique`\n * that makes the relation hold one row, so a second link is a collision\n * rather than a second row.\n *\n * Prisma detaches the incumbent rather than deleting it, and it does so for\n * some of the operands that link and not others. That split is not derivable\n * — it is measured, on one fixture, and it is the reason `displaces` is\n * consulted per operand rather than applied to \"anything that links\":\n *\n * create displaces the incumbent, links the new row\n * connect displaces the incumbent, links the named row\n * connectOrCreate, hit the same — it *is* a connect (#361)\n * connectOrCreate, miss collides: P2002 on the child's key\n * upsert, create branch collides: P2002 on the child's key\n *\n * So the two branches of one `connectOrCreate` answer differently, which is\n * Prisma's asymmetry and not an embellishment: what displaces is *linking an\n * existing row*, plus the bare `create` — and the create inside the two\n * compound operands does not.\n *\n * Nullable, because a detach has to leave a value behind. A required child\n * key cannot be nulled at all, so the insert or repoint collides as it always\n * did, which is the only thing the schema permits. `assertDisconnectable` is\n * deliberately not called here: it would refuse the whole operand, including\n * the empty-to-one case that has always worked.\n *\n * **`relation.kind` is the whole discriminator here, and it is *not* the same\n * predicate as the owning side's (#363) — it is the stronger half of it.**\n * `kind` is a property of this relation's back-reference, and Prisma will not\n * let a non-list back-relation exist without `@unique` on the child's foreign\n * key. Verified against 6.19.2 rather than assumed: `User.profile Profile?`\n * beside a `Profile.userId` carrying no `@unique` is refused at parse time\n * with P1012 — *\"A one-to-one relation must use unique fields on the defining\n * side. Either add an `@unique` attribute to the field `userId`, or change\n * the relation to one-to-many\"* — so a schema reaching this line with\n * `kind !== \"many\"` **has** the index, and `kind` alone is sufficient here.\n *\n * **The converse does not hold, which is why the owning side needs two tests\n * where this one needs one.** A `@unique` foreign key beside a *list*\n * back-relation validates: `Player.teamId Int? @unique` next to\n * `Team.players Player[]` is accepted, and Prisma refuses the displacing\n * `connect` there with P2002 without reading the sibling. So \"the key is\n * unique\" is strictly weaker than `kind !== \"many\"`, and an owning-side\n * discriminator built on the index alone displaces on schemas this side\n * correctly leaves alone. That is a real defect this file shipped for one\n * review cycle; `planOwningSide`'s `displaces` now reads the *child's* copy of\n * the relation for its `kind` and uses `uniques` only to narrow. From the\n * owning side `relation.kind` is still unreadable — it says `\"one\"` for a\n * many-to-one and a one-to-one alike, because both point at a single far row.\n *\n * **Every column has to be nullable, not the first one** (#271). Prisma makes\n * a composite relation optional or required as a whole and refuses a mixture,\n * so on a schema it accepted the columns agree — but the test is over all of\n * them because half a detach is worse than none: the incumbent would keep a\n * key that still joins nowhere while the unique index still holds it.\n */\n const displaces =\n relation.kind !== \"many\" &&\n childFields.every((field) => child.fields[field]?.nullable === true);\n\n /**\n * **A to-one whose key is on the child**, which this function otherwise plans\n * as though the child were a list.\n *\n * It had exactly one `kind` check — `createMany`'s, further down — because no\n * fixture had the shape, so nothing ever reached this side with `kind: \"one\"`\n * (#116). Everything else took the to-many spelling: `updateMany` and\n * `deleteMany` *compiled*, and `update` / `delete` / `upsert` were refused\n * for looking wrong rather than for being unimplemented here.\n *\n * Measured against the generated client rather than reasoned about. Prisma's\n * to-one nested input is\n *\n * { create, connectOrCreate, upsert, disconnect, delete, connect, update }\n *\n * with no `createMany`, `set`, `updateMany` or `deleteMany` key at all — so\n * the first group below is refused for the same reason `planOwningSide`\n * refuses it, and says so in the same words.\n *\n * The rest of that input — `update`, `delete`, `upsert` — was refused here\n * too, for being spelled unlike the to-many form. It is implemented now, and\n * the implementation is a *translation* rather than three new bodies: see\n * {@link toOneOperand}.\n */\n // The operand as the caller wrote it, kept because the rewrite below\n // overwrites `operand` in place and `assertToOneFilter` has to read the\n // spelling rather than the translation — `false` and `null` are one value\n // afterwards and two very different calls before. See that function.\n const spelledOperand = operand;\n\n if (relation.kind !== \"many\") {\n // {@link NO_SET_OF_ROWS} rather than {@link COLLECTION_ONLY_STATEMENTS}:\n // `createMany` is the fourth of them and is refused further down, where its\n // own message and its operand check live together.\n if (NO_SET_OF_ROWS.has(key)) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: there is a single ${child.name} row, ` +\n `so there is no set of rows for '${key}' to act on. Prisma does not ` +\n `offer it on a to-one either. Use 'connect', 'disconnect' or ` +\n `'update'.`,\n );\n }\n\n /**\n * **An array where the relation holds one row**, which compiled here and\n * wrote through it.\n *\n * Nothing below this point consults `kind`, so `create: [a, b]` inserted\n * two children, and `connect: [{ id: 1 }, { id: 2 }]` repointed *both* rows\n * through a relation that can hold one — the second silently winning. That\n * is a live divergence, not strictness: Prisma refuses all three, measured\n * off the generated client rather than reasoned from the docs.\n *\n * connect: [{ id: 1 }, { id: 2 }]\n * -> PrismaClientValidationError, neither row repointed\n * create: [{ bio: \"a\" }, { bio: \"b\" }]\n * -> \"Expected ProfileCreateWithoutUserInput or\n * ProfileUncheckedCreateWithoutUserInput, provided (Object, Object)\"\n *\n * `PrismaClientValidationError` carries **no `code`** — it is an argument\n * refusal rather than a database one — which is why this is\n * `InvalidArgumentError` and not either `Unsupported*`: the argument is\n * supported and the value is wrong. So the message names the shape that\n * would work rather than announcing that arrays are unimplemented.\n *\n * Sound at plan time because array-ness is *in the plan key*: an array and\n * a single object are different structures to `canonicalShape`, so they can\n * never share a cache entry and this refusal cannot be decided on one\n * call's behalf by another's.\n */\n if (Array.isArray(operand)) {\n throw new InvalidArgumentError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one — ${child.name} holds the foreign key, ` +\n `so there is one row here at most. Expected a single object for ` +\n `'${key}', not an array of them. Prisma refuses the array too.`,\n );\n }\n\n /**\n * The three that were refused are a **spelling** difference, not missing\n * machinery. `conjoin` returns the parent restriction alone when the\n * caller's filter is absent or `{}`, and `listOf(null)` is `[]` — so a\n * to-one is a to-many of one, and the bodies below already do the work\n * once the operand is written the way they read.\n *\n * **Rebinding `at` — translating at *bind* time and not only while the plan\n * is compiled — is load-bearing for exactly one branch, and that is the\n * correctness argument for this whole design.** Every other distinction the\n * table draws is *structural*, so it may safely be decided once when the\n * plan is built: `{ data }` against `{ where, data }`, a `where` present\n * against absent, an array against an object — `canonicalShape` records all\n * of those, so two calls that differ there are already two plans. The\n * boolean is the one that is not. `delete: true` and `delete: false` are\n * the same shape to everything except the guard `shapeOfMember` carries for\n * exactly this, and a plan key is a cache rather than a contract. Reading\n * the boolean inside `at` means the step consults the *call's* value on\n * every execution, so a plan handed the wrong one still writes nothing —\n * `listOf(null)` is `[]`. Belt and braces on purpose: the owning side's\n * version of the same collision was a silent wrong write for its whole\n * life, precisely because its `true`/`false` decision was made once at\n * compile time and never revisited.\n */\n // Checked *before* the rewrite, because the rewrite is lossy by\n // construction: it rebuilds the operand from the keys it knows, so a key it\n // does not know is gone by the time anything downstream could refuse it.\n assertToOneWriteOperand(schema, relation, child, key, operand, operation);\n\n const spelled = at;\n at = (args: any) => toOneOperand(key, spelled(args));\n operand = toOneOperand(key, operand);\n }\n\n /**\n * `disconnect` and `delete` on this side act on rows the caller named by\n * unique key — which is what makes them expressible at all, and what puts\n * them on the supported side of this file's line.\n *\n * **On a to-one the caller names a *filter*, or nothing at all**, and that\n * does not weaken the line: the row is still identified, by the parent's own\n * key, which is the strongest naming available. `assertToOneFilter` is what\n * replaces the unique-key match there, and the filter only narrows.\n *\n * They differ on a row that is *not* linked to this parent, and the\n * difference is Prisma's, measured rather than chosen — on both kinds, since\n * the second pair is the same asymmetry read through the to-one spelling:\n *\n * disconnect a row linked elsewhere -> succeeds, changes nothing\n * delete a row linked elsewhere -> raises \"are not connected\"\n * disconnect: true, nothing linked -> succeeds, changes nothing\n * delete: true, nothing linked -> P2025\n *\n * So both filter by the parent key as well as the caller's key, and only\n * `delete` treats a miss as an error. That filter is doing two jobs at once:\n * it reproduces Prisma's semantics, and it is what stops either operand from\n * reaching a row belonging to a different parent.\n *\n * **Scoping comes from the child's own operations**, as everywhere else here:\n * `updateMany` and `delete` go through the child's `$exec` un-pre-scoped, so\n * a row the child's policies hide is not reachable. For `delete` that means a\n * hidden row reports \"not connected\" rather than \"denied\" — the same answer\n * as a row that genuinely is not linked, which is the conservative one.\n */\n /**\n * `update: { where, data }` — the caller's columns, written to a row they\n * named by unique key.\n *\n * **The pass this was refused for turns out to exist**, one layer down. The\n * `REFUSED` entry said it \"needs its own scoping pass\" for `onUpdate` and the\n * scope-escape guard; both of those live in `applyPolicies`, which the\n * child's own `$exec` runs because this step is not pre-scoped. Verified\n * rather than assumed:\n *\n * another tenant's row -> { count: 0 } the child's scope\n * caller names a scoped column -> ScopeEscapeError\n *\n * So the refusal was describing a gap in the wrong place. What `update`\n * genuinely needs beyond `disconnect` is nothing: the parent-key filter that\n * keeps it off another parent's row is the same one, and the payload is the\n * child's business.\n *\n * `updateMany` stays refused because it names a *predicate* rather than a\n * row, which is the half of the line this file draws that has not moved.\n */\n /**\n * `set` — replace the whole set with the named rows.\n *\n * The one supported operand that acts on rows the **call** did not name: it\n * disconnects whatever is currently linked before connecting what was asked\n * for. That is the half of this file's line it appears to fail, and #83\n * already answered how — its implicit many-to-many `set` had the identical\n * problem and the fix was to give the disconnect a *lookup*: read the linked\n * rows through the child's own `findMany`, and clear only the ones the\n * caller can see.\n *\n * So `set` means **\"replace the set I can see\"**. With no policy on the child\n * every row is visible and it is Prisma's `set` exactly; with one, a row the\n * caller cannot see stays attached rather than being silently detached —\n * which is the same choice `disconnect` makes one operand over, and the\n * opposite of what an unscoped delete would do.\n *\n * Three measured details that are not obvious from the name:\n *\n * set [one of two] the unnamed row's key becomes null, the named stays\n * set [] every linked row is detached\n * set [another parent's row] it is repointed here, as `connect` does\n * set [a row that does not exist] silently ignored — no error\n *\n * The last is why the connect half is an `updateMany` rather than the\n * `update` a nested `connect` uses: Prisma does not raise here, and matching\n * that means not raising either.\n *\n * Both halves write the child's foreign key, so `set` inherits #98 exactly as\n * `connect` does: a child whose policy scopes on that column is refused by\n * the scope-escape guard, because it cannot tell a column the ORM wrote from\n * one the caller did. #99 fixes that for every relation operand at once, and\n * this needs no change when it lands.\n *\n * **The clearing half stopped inheriting it and the linking half must not,\n * which is measured rather than tidy.** `clearLinks` names the column as the\n * ORM's, because a nested `create` on an occupied to-one needs the same clear\n * and would otherwise be refused for a write nobody made. Naming it on the\n * *link* too makes `set` succeed — and succeed wrongly: the clear nulls the\n * key, which puts the row outside the very scope (`{ folderId: 2 }`) the link\n * then has to select it by, so the row is detached and never re-attached. A\n * silent half-write in place of a loud refusal. Left refused until #99 can\n * answer the scope as well as the guard.\n */\n /**\n * `updateMany` and `deleteMany` — a **filter**, applied to this parent's rows.\n *\n * These were the last two refused on the \"names a predicate rather than a\n * row\" reading of #94's line, and that reading was too strong. What the line\n * is really asking is whether there is a `where` the child's scope can be\n * `AND`ed into — and a predicate is exactly that. Both operations are in\n * `SCOPABLE`, so routing them through the child's own `$exec` gives the scope\n * on which rows match, and `updateMany` gets `onUpdate` and the scope-escape\n * guard over its payload, the same way #101's `update` does.\n *\n * The parent key goes into the filter for the same reason it does everywhere\n * else here: Prisma applies these to *this* parent's children only, verified\n * before implementing, and without it a `deleteMany: {}` would empty the\n * table.\n *\n * **The two operands are shaped differently**, which is easy to get backwards:\n *\n * updateMany: { where: { … }, data: { … } }\n * deleteMany: { … } the filter directly\n *\n * `upsert` stays refused, and its reason is the one that has not moved: it\n * needs to know which branch ran from inside a nested step, which neither\n * half of it provides.\n */\n /**\n * `upsert` — find by a unique key **within this parent's rows**, update it or\n * create it.\n *\n * Its refusal said it *\"needs a third thing neither half has: deciding which\n * branch ran, from inside a nested step\"*. It does not: the lookup decides\n * the branch, exactly as `connectOrCreate` has decided one since #94. That is\n * the sixth `REFUSED` reason in this series to describe machinery that was\n * already there.\n *\n * **Scoped to this parent, which is Prisma's own semantics and not an\n * embellishment** — measured, because it is the detail that decides what the\n * operand means:\n *\n * upsert a row belonging to another parent\n * -> Unique constraint failed on the fields: (`publicId`)\n *\n * Prisma looks only among *this* parent's children, does not find it, takes\n * the create branch, and collides. So the conjunction that keeps every other\n * filter operand on this parent is what produces the right branch here, not\n * merely what keeps it safe.\n */\n /**\n * **The to-one reaches this same body, and it needed nothing added.** Its\n * `where` is optional — `ProfileUpsertWithoutUserInput` is\n * `{ update, create, where? }` — so `conjoin(undefined, link)` is the link\n * alone and the lookup finds the single connected child. Measured on both\n * branches:\n *\n * no child, no `where` -> the create branch runs *and stamps the\n * foreign key* — Profile { bio: \"created\",\n * userId: 1 }\n * child present, no `where` -> the update branch runs against it\n * child present, `where` matching nothing\n * -> the create branch runs and collides:\n * P2002, \"Unique constraint failed on the\n * fields: (`userId`)\"\n *\n * The third is the note above transposed to the foreign side, and it is the\n * one to-one nested-write miss that is *not* P2025. It is left to happen\n * rather than pre-empted: the create is what Prisma runs, so surfacing\n * `UniqueConstraintError` from it is agreement, where refusing early would be\n * a different error for the same query.\n */\n if (key === \"upsert\") {\n assertUpsertOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n\n out.after.push({\n relation: relation.name,\n operation: \"upsert\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n for (const entry of listOf(at(args)) as Record<string, unknown>[]) {\n const where = conjoin(entry.where, childLink(link, parent));\n\n const hit = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (hit) {\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data: entry.update },\n // NOT pre-scoped: the child's `onUpdate` and scope-escape guard\n // judge the payload, as they do for a nested `update`.\n false,\n );\n continue;\n }\n\n await executor.exec(\n relation.model,\n \"create\",\n {\n // The foreign key is ours, as it is for every create here.\n data: { ...(entry.create as object), ...childLink(link, parent) },\n select: keySelect(childFields),\n },\n false,\n );\n }\n },\n });\n return;\n }\n\n if (key === \"updateMany\" || key === \"deleteMany\") {\n const updating = key === \"updateMany\";\n assertManyOperand(schema, relation, operand, key, operation);\n\n out.after.push({\n relation: relation.name,\n operation: key,\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const operandAt = at(args) as Record<string, unknown>;\n const filter = updating ? operandAt?.where : operandAt;\n\n // **`AND`, not a spread.** A spread lets the parent key *overwrite* a\n // caller filter naming the same column: `deleteMany: { userId: 9 }` on\n // this parent's relation became `{ userId: <this parent> }`, so a query\n // asking for children belonging to somebody else deleted every one of\n // this parent's instead. Silent, and in the deleting direction.\n //\n // Prisma conjoins — measured, because the whole question is what it\n // does rather than what is tidy:\n //\n // deleteMany { userId: <other> } -> nothing deleted\n //\n // Conjoining also keeps the parent restriction *unforgeable* while\n // letting the caller's predicate narrow, which is exactly what\n // `withScope` does for a policy fragment and for the same reason.\n const where = conjoin(filter, childLink(link, parent));\n\n await executor.exec(\n relation.model,\n key,\n updating ? { where, data: operandAt?.data } : { where },\n // NOT pre-scoped. The child's scope narrows which rows match, and for\n // `updateMany` its `onUpdate` and scope-escape guard judge the\n // payload — which is the whole reason these are expressible.\n false,\n );\n },\n });\n return;\n }\n\n if (key === \"set\") {\n assertNamedRows(schema, relation, child, operand, \"set\", operation);\n assertDisconnectable(child, relation, childFields, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.set`,\n });\n\n out.after.push({\n relation: relation.name,\n operation: \"set\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const attach = childLink(link, parent);\n\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n\n for (const entry of listOf(at(args))) {\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where: entry as object, data: attach },\n false,\n );\n }\n },\n });\n return;\n }\n\n if (key === \"update\") {\n assertNamedUpdates(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n\n out.after.push({\n relation: relation.name,\n operation: \"update\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const list = listOf(at(args));\n\n for (let index = 0; index < list.length; index++) {\n const entry = list[index] as Record<string, unknown>;\n // The caller's key *and* the link, so an `update` cannot reach a row\n // attached to a different parent — the same filter `delete` uses,\n // and it does the same two jobs. `AND` rather than a spread for the\n // reason `updateMany` documents: a key naming the foreign column\n // itself would otherwise be overwritten rather than honoured.\n const where = conjoin(entry.where, childLink(link, parent));\n\n const found = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (!found) {\n // `RecordNotFoundError`, not `UnsupportedQueryError`: nothing here\n // is unsupported, the row simply is not there. Prisma agrees —\n // P2025, *\"depends on one or more records that were required but\n // not found\"* — and the differential harness compares the failure\n // *kind* precisely so a refusal cannot pass as agreement with a\n // miss. This one was `other` against Prisma's `notFound` until the\n // harness said so.\n //\n // **Fatal on the to-one too, which was the open question and is\n // now measured.** The worry was that a to-one `update` naming a\n // non-matching `where` might be a no-op there, which would have\n // made this branch wrong for one `kind` and forced the two apart.\n // It does not: with a child present and `where: { bio: \"nope\" }`\n // Prisma raises P2025 — *\"No 'Profile' record was found for a\n // nested update on one-to-one relation 'ProfileToUser'\"* — with\n // wording identical to the no-child case, and the parent's own\n // assignments roll back with it. Absent and not-matching are one\n // condition to Prisma, so they stay one error here.\n throw new RecordNotFoundError(relation.model, \"update\");\n }\n\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data: entry.data },\n // NOT pre-scoped, and this is the whole reason `update` is\n // expressible: the child's own policies run over `data` — its\n // `onUpdate` defaults, its scope-escape guard refuses a caller\n // naming a scoped column — because they have not run yet.\n false,\n );\n }\n },\n });\n return;\n }\n\n if (key === \"disconnect\" || key === \"delete\") {\n const deleting = key === \"delete\";\n if (!deleting) {\n // Before any boolean normalisation would matter, and it has to be:\n // Prisma leaves `disconnect` out of the input type *entirely* when the\n // child's foreign key is required, so even `disconnect: false` is\n // rejected there — *\"Unknown argument `disconnect`. Did you mean\n // `connect`?\"*, with the available options listed as create /\n // connectOrCreate / upsert / connect / update. The refusal is on the\n // **key**, not on the value, and this one already reads only the schema.\n assertDisconnectable(child, relation, childFields, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.disconnect`,\n });\n }\n\n /**\n * **A to-one names a filter here; a to-many names rows by unique key.**\n *\n * `ProfileUpdateOneWithoutUserNestedInput` spells both operands\n * `ProfileWhereInput | boolean`, and it means it — measured:\n * `delete: { bio: \"seed\" }` is accepted with no `@unique` anywhere near\n * `bio`, and it deletes the connected row. Running `matchUniqueKey` on this\n * path would therefore refuse a query Prisma answers, which is why\n * `assertToOneFilter` replaces `assertNamedRows` rather than joining it.\n */\n if (relation.kind === \"many\") {\n assertNamedRows(schema, relation, child, operand, key, operation);\n } else {\n assertToOneFilter(\n schema,\n relation,\n child,\n spelledOperand,\n key,\n operation,\n );\n }\n\n out.after.push({\n relation: relation.name,\n operation: key,\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const list = listOf(at(args));\n\n for (let index = 0; index < list.length; index++) {\n // The caller's key *and* the link, so neither operand can reach a row\n // attached to a different parent. `AND` rather than a spread — see\n // `updateMany`.\n const where = conjoin(list[index], childLink(link, parent));\n\n if (!deleting) {\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data: nullKey(childFields) },\n // NOT pre-scoped: clearing a foreign key is a write to the child,\n // so the child's scope decides which rows are reachable.\n false,\n // ...but the columns are *ours*: the caller wrote `disconnect:\n // { id }` and the ORM chose to null the key. Without this a child\n // scoped on its own foreign key is refused for a write it never\n // made — the same case as `connect`, see #98 and\n // `ormAuthoredFields`.\n childFields,\n );\n continue;\n }\n\n const found = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (!found) {\n /**\n * **Two misses, two errors — and this is the third time this exact\n * mis-classification has had to be corrected** (see the notes at\n * `planOwningSide`'s `update` and at this file's own `update`\n * miss).\n *\n * On a to-one the caller named no row: `delete: true` means the\n * connected child, and there is either one or there is not.\n * Reporting *\"the row named by `true` is not connected\"* would be\n * nonsense to read, and worse it classifies as `other` where Prisma\n * answers P2025 — *\"No 'Profile' record was found for a nested\n * delete on one-to-one relation 'ProfileToUser'\"* — so the\n * differential harness would score a refusal as agreement with a\n * miss. Measured on both spellings: `delete: true` with no child\n * and `delete: { bio: \"nope\" }` with a child present give the same\n * P2025, so one error covers both.\n *\n * **`disconnect` does not come through here at all, and that\n * asymmetry is Prisma's.** A disconnect that matches nothing —\n * `disconnect: true` with no child, or a filter matching none — is\n * a *silent no-op* that still returns the parent, measured both\n * ways. The two operands share this body but must not share their\n * miss handling, which is why only `deleting` reaches this branch.\n */\n if (relation.kind !== \"many\") {\n throw new RecordNotFoundError(relation.model, \"delete\");\n }\n\n throw new UnsupportedQueryError(\n `data.${relation.name}.delete`,\n schema.name,\n operation,\n `the row named by ${JSON.stringify(list[index])} is not ` +\n `connected to this ${schema.name}. Prisma raises here too, ` +\n `rather than deleting a row belonging to somebody else.`,\n );\n }\n\n await executor.exec(\n relation.model,\n \"deleteMany\",\n { where },\n // NOT pre-scoped, for the reason above — and `deleteMany` rather\n // than `delete` because the `where` carries the link as well as the\n // unique key, which `delete` refuses as a non-unique target.\n false,\n );\n }\n },\n });\n return;\n }\n\n /**\n * `create` — insert the child, with this row's key stamped onto it.\n *\n * **On a to-one the new row has to displace the old one, and Prisma\n * *detaches* the incumbent rather than deleting it** (#360). Measured, with\n * user 1 already carrying a profile:\n *\n * user.update({ data: { profile: { create: { bio: \"second\" } } } })\n * -> (\"seed\", null) the incumbent, orphaned and still in the table\n * (\"second\", 1) the new row takes the link\n *\n * The orphaning is the half that is not guessable, and getting it wrong in\n * the other direction — deleting the displaced row — is silent data loss\n * wearing the same green test. So the differential reads the table back\n * rather than only checking that the call returned.\n *\n * Without the detach the insert simply collides: the child's foreign key\n * carries the `@unique` that makes the relation a to-one, so this was a\n * `UniqueConstraintError` on a call Prisma answers. `create` survived #354\n * because that change was about the operands refused *by name* on this side,\n * and `create` was never one of them — against an *empty* to-one it has\n * always been correct, and no fixture had a to-one whose key is on the child\n * until #358 added one.\n *\n * **`clearLinks`, so the scoping consequence is the same one `set` has** —\n * which is why the two share it. A child hidden by the caller's policies is\n * not detached, and the incumbent then wins the unique key: a\n * `UniqueConstraintError` rather than a silent detach of a row the caller\n * cannot see. Conservative in the direction this file always chooses.\n *\n * A to-many displaces nothing — clearing every child before a nested `create`\n * would be a `set: []` nobody asked for — which is half of what `displaces`\n * decides; see it for the other half and for which operands share this.\n */\n if (key === \"create\") {\n out.after.push({\n relation: relation.name,\n operation: \"create\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n // No row means the statement matched nothing; `update` and `delete`\n // raise before this runs, so there is nothing to attach to.\n if (!parent) return;\n\n // Runs on a parent `create` too, where nothing can be linked yet and it\n // finds nothing. Deliberately not skipped by operation: gemi does not\n // enable SQLite's foreign-key pragma, so \"a row that was just inserted\n // has no children\" is a property of the database's enforcement rather\n // than of the ORM — and a correctness argument resting on a pragma is\n // the kind that holds until someone reads it. One read, on a path that\n // already runs several.\n if (displaces) {\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n }\n\n for (const item of listOf(at(args))) {\n await executor.exec(\n relation.model,\n \"create\",\n {\n // The foreign key is set by us, not by the caller: a nested create\n // that also named it would be describing two different parents.\n data: { ...(item as object), ...childLink(link, parent) },\n // Nothing reads the result, and the narrowest select keeps the\n // returned payload from growing with the child's column count.\n select: keySelect(childFields),\n },\n // NOT pre-scoped — the child's `onCreate` is what scopes this row.\n false,\n );\n }\n },\n });\n return;\n }\n\n /**\n * `createMany`: the same rows as a nested `create`, in **one statement**.\n *\n * The biggest single item on #65 — parent-and-children in one call — and the\n * work is sequencing rather than SQL: `compileCreateMany` already exists, and\n * the parent's `RETURNING` already yields the key the children need. What this\n * step adds is running it once with the key stamped onto every row, instead of\n * once per row.\n *\n * That difference is the point. A nested `create` of forty rows is forty\n * statements; this is one, which is what makes the shape worth porting rather\n * than rewriting into a transaction with explicit foreign keys.\n */\n if (key === \"createMany\") {\n // The mirror of `planOwningSide`'s guard: that one catches a to-one whose\n // foreign key is on *this* row, this one catches a one-to-one whose key is\n // on the child. Same conclusion, different direction, and both reachable.\n if (relation.kind !== \"many\") {\n throw new UnsupportedQueryError(\n `data.${relation.name}.createMany`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one, so there is nothing to create many ` +\n `of. Prisma does not accept it here either.`,\n );\n }\n\n assertCreateManyOperand(schema, relation, operand, operation);\n\n out.after.push({\n relation: relation.name,\n operation: \"createMany\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const items = listOf(at(args)?.data).map((item) => ({\n // Same rule as the nested `create` beside this one: the foreign key\n // is ours to set, not the caller's. Prisma leaves it out of the\n // nested input type entirely, so a row naming it is describing a\n // different parent than the call is.\n ...(item as object),\n ...childLink(link, parent),\n }));\n\n // **No short-circuit on an empty list**, and that is worth the round\n // trip it costs.\n //\n // Returning early here would skip the child's `$exec`, and with it the\n // child's *policies* — so whether the ORM refuses a misconfigured\n // policy would depend on the length of an array at run time. A model\n // carrying a `scope` with no `onCreate` is refused on the call with one\n // row and accepted on the call with none, which means the\n // misconfiguration hides behind data that happens to be empty in\n // development and reports itself on the first request whose list is\n // not. Nothing is written either way, so it is not a leak — it is a\n // refusal that arrives late, which is the thing the rest of the\n // compiler is arranged to prevent by deciding everything from the\n // argument *shape*.\n //\n // The cost is one `select … where false`, which is what\n // `compileCreateMany` emits for an empty list. Prisma does accept the\n // empty list and write nothing — verified — and so does this.\n await executor.exec(\n relation.model,\n \"createMany\",\n { data: items },\n // NOT pre-scoped. `createMany` is in the set an `onCreate` applies\n // to, and it applies per row — so the child's policy stamps the\n // tenant column onto every one of these, exactly as it would for a\n // top-level `createMany`.\n false,\n );\n },\n });\n return;\n }\n\n /**\n * `connectOrCreate` on this side is the pair of branches the owning side has,\n * with `connect` spelled as an update of the child's foreign key.\n *\n * Both branches go through the child's own `$exec`, so both are scoped by the\n * child's policies — and they have to be, in opposite directions: an\n * unscopeable *update* would re-parent another tenant's row, and an unscoped\n * *read* would let a hit reveal that a row with that key exists. Scoped, a\n * hidden row reads as absent and the call creates its own, which is the same\n * answer the caller would get if it truly did not exist.\n */\n if (key === \"connectOrCreate\") {\n // `relation.kind === \"many\"`, not a hardcoded `true`. This side is reached\n // by both kinds — that is the whole of #116 — so a literal here told\n // `assertConnectOrCreateOperand` that a to-one takes a list, and its array\n // guard was unreachable from the one direction that needed it. The outer\n // to-one guard above now refuses the array first; this keeps the function\n // honest about which relation it was asked about rather than relying on\n // the order of two checks.\n assertConnectOrCreateOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n\n out.after.push({\n relation: relation.name,\n operation: \"connectOrCreate\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const list = listOf(at(args));\n\n for (let index = 0; index < list.length; index++) {\n const item = list[index] as Record<string, unknown>;\n\n const found = (await executor.exec(\n relation.model,\n \"findUnique\",\n { where: item.where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (found) {\n // **The row is already this parent's, so there is nothing to do.**\n //\n // Free here in a way it is not for the bare `connect` below: the\n // `findUnique` above already selected the child's foreign key, so\n // the comparison costs no statement. `connect` has no such read —\n // giving it the same short-circuit means buying a lookup, which is\n // why it is #372's question rather than this branch's.\n //\n // Without this the pair below is a **clear followed by a repoint of\n // the row the clear just nulled**, and on a child scoped by that\n // same foreign key the clear puts it outside the scope the repoint\n // selects it through — so the operand raises `RecordNotFoundError`\n // on a call that should change nothing. Net-nothing either way for\n // an unscoped child, which is why it stayed hidden; the scoped one\n // is where the wasted statement becomes a wrong answer.\n //\n // `displaces` gates it because that is the only shape the clear\n // runs in. On a to-many there is no clear, so the repoint is one\n // redundant `update` writing the value already there — measured to\n // agree with Prisma, and skipping it would be an unmeasured change\n // to a branch this issue is not about.\n if (\n displaces &&\n childFields.every((field, index) =>\n sameKey(found[field], parent[parentFields[index]]),\n )\n ) {\n continue;\n }\n\n // The hit branch **is** a connect, so it displaces what is linked\n // exactly as the bare operand does (#361) — and the miss branch\n // below does not, which is Prisma's own split rather than a\n // shortcut here. Measured on one fixture: `connectOrCreate` hitting\n // a row orphans the incumbent and takes the link, while the same\n // call missing collides on the child's unique key. See `displaces`.\n if (displaces) {\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n }\n\n await executor.exec(\n relation.model,\n \"update\",\n {\n where: item.where,\n data: childLink(link, parent),\n select: keySelect(childFields),\n },\n // NOT pre-scoped, for the reason the bare `connect` below is not:\n // this repoints an existing child, so the child's scope decides\n // which rows are reachable.\n false,\n // ...and the column is *ours*, the same one and for the same\n // reason (#98). Left off here while `connect` carried it, so one\n // operand spelled two ways answered a child scoped on its own\n // foreign key differently: `connect` went through and this raised\n // `ScopeEscapeError` about a `folderId` the caller never wrote\n // (#373). The hit branch **is** a connect — the docblock above\n // says so for displacement, and provenance follows from the same\n // fact. The miss branch below needs no marker: it creates the far\n // row, so there is no caller-supplied key to tell ours apart from.\n childFields,\n );\n continue;\n }\n\n await executor.exec(\n relation.model,\n \"create\",\n {\n // The foreign key is ours, not the caller's — the same rule the\n // nested `create` above follows, and Prisma leaves it out of the\n // nested input type entirely.\n data: { ...(item.create as object), ...childLink(link, parent) },\n select: keySelect(childFields),\n },\n false,\n );\n }\n },\n });\n return;\n }\n\n // `connect` on this side means \"point that existing row at me\", which is an\n // update of the child's foreign key — not something this row's insert can do.\n //\n // Checked here rather than in the step below, for the reason `assertNamedRows`\n // gives: the step runs after the parent row is written, so a key the child\n // does not declare unwinds an insert that should never have happened. The\n // owning side has always checked its `connect` at plan time; this side had\n // not, which made the same operand answer differently depending on which\n // table the foreign key is on (#110).\n assertNamedRows(schema, relation, child, operand, key, operation);\n\n /**\n * **On a to-one this repoint has to displace what is linked already** (#361),\n * the same way the nested `create` beside it does and through the same\n * `clearLinks`. Without it the child's `@unique` foreign key rejects the\n * second link, so `connect` was a `UniqueConstraintError` on a call Prisma\n * answers by orphaning the incumbent.\n *\n * Measured across the four shapes, because only one of them diverged and the\n * other three are what kept it hidden:\n *\n * connect onto an empty to-one attaches agreed already\n * connect a child of another parent repoints it agreed already\n * connect the row already linked here writes nothing see below\n * connect onto an occupied to-one displaces the divergence\n *\n * **The third is the one the clear and the link cross on, and #361 got it\n * right in the table and wrong in the statements** (#372). `clearLinks` nulls\n * the very row the caller named and the repoint puts the key straight back,\n * so the committed state agrees — and that is all `M15b` could see. The two\n * statements in between are not harmless. **The repoint has to re-select the\n * row by the column the clear just changed, so it fails whenever anything in\n * that `where` depends on the old value** — and there are two ways to get\n * one, not just the policy shape #372 was reported through:\n *\n * - a child whose policy scopes on *its own foreign key*\n * (`{ folderId: 2 }`) — the scope is `AND`ed into the repoint's `where`,\n * and the clear has just moved the row out of it;\n * - **no policy anywhere**, when the caller names the row *by* that foreign\n * key (`connect: { folderId: 2 }`). `assertNamedRows` accepts that\n * operand because the column is in `uniques`, which is the same fact that\n * makes the relation a to-one in the first place — and then the caller's\n * own `where` is the thing the clear invalidates.\n *\n * Either way the repoint matches nothing and the whole call raises\n * `RecordNotFoundError` naming a model and an operation the caller never\n * wrote. A call that worked before #361. The second shape is what makes this\n * a plain correctness bug rather than a policy interaction, and it is why the\n * differential can pin it at all: `M15e` in `writes.differential.test.ts` is\n * that spelling, `error` against `ok`, with no policy in it.\n *\n * So the named row is resolved first and the operand short-circuits when it\n * already points here — {@link alreadyLinked}. That is Prisma's own shape\n * rather than a repair invented for the scope: measured on 6.19.2/SQLite with\n * query logging, `folder.update({ data: { cover: { connect: { id: 30 } } } })`\n * where cover 30 already holds folder 2 logs **four selects and no `UPDATE`**\n * between its `BEGIN` and `COMMIT`, where the same call onto an occupied\n * folder logs the incumbent clear and the repoint. The lookup itself is\n * Prisma's too — every `connect` above begins by selecting the operand's row\n * with its foreign key in the projection.\n *\n * #361 declined this as \"a lookup on every `connect` to save one write on a\n * rare one\", which was the right trade for the fact it had in view. Two\n * things changed it: the write it saves is a live failure rather than a\n * redundancy, and the lookup is not on every `connect` — only where\n * `displaces` holds, which is a to-one, so every many-to-one and every\n * to-many `connect` costs exactly what it did.\n *\n * **A miss detaches nothing**, which is Prisma's answer (P2025, nothing\n * written) and is not a special case here: a row the lookup cannot find is\n * left to the repoint, which raises, and the clear is inside the transaction\n * the nested steps already run in. That covers the row that does not exist\n * and the row this caller's policies hide alike — both read as absent, and\n * both get the answer they had before this change.\n */\n out.after.push({\n relation: relation.name,\n operation: \"connect\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n // `displaces` is only ever true on a to-one, where the array spelling is\n // refused above — so this is one extra select at most, never one per item.\n const pending: unknown[] = [];\n for (const item of listOf(at(args))) {\n if (\n displaces &&\n (await alreadyLinked(\n relation.model,\n childFields,\n item,\n valuesOf(parent, parentFields),\n executor,\n ))\n ) {\n continue;\n }\n pending.push(item);\n }\n\n // Nothing left to link means nothing to displace either: the only row that\n // could hold this parent's key is the one the caller named, and it holds\n // it already. Returning here is what makes the call write nothing at all.\n if (pending.length === 0) return;\n\n if (displaces) {\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n }\n\n for (const item of pending) {\n await executor.exec(\n relation.model,\n \"update\",\n {\n where: item,\n data: childLink(link, parent),\n select: keySelect(childFields),\n },\n // NOT pre-scoped. Repointing an existing row at this parent is a write\n // to the child, and the child's scope decides which rows are reachable\n // — otherwise `connect` re-parents another tenant's row.\n false,\n // ...and the columns being written are *ours*, not the caller's.\n // Without this, a child whose policy scopes on its foreign key is\n // refused for a write it never made — see #98 and\n // `ormAuthoredFields`.\n childFields,\n );\n }\n },\n });\n}\n\n/**\n * What an implicit many-to-many accepts, and how it differs from\n * {@link SUPPORTED} — which is the ordinary-relation set.\n *\n * **The two must be reconciled deliberately.** `planOne` checks `link.join`\n * first and returns, so this path never consults `SUPPORTED` at all: the sets\n * drift without anything failing to compile and without a test noticing, and\n * they did — #83 landed this one while four branches were adding to the other,\n * none of which could see it from inside itself.\n *\n * **The gaps are unimplemented, not by design, and that is measured rather than\n * reasoned.** An earlier version of this comment claimed the split was \"the\n * link versus the far row\" — operands about the pair work here, operands about\n * the far row do not. It is a tidy rule and it is wrong. Prisma offers five of\n * the six through an implicit m-n:\n *\n * update OK the far row is updated\n * delete OK the far row is deleted, not just the pair\n * deleteMany OK\n * updateMany OK\n * connectOrCreate OK\n * createMany Unknown argument — Prisma refuses it here too\n *\n * So `delete` through a join table really does mean deleting the far row, which\n * is the opposite of what that rule predicted. Only `createMany` is a genuine\n * refusal, and it is Prisma's rather than ours.\n *\n * `connectOrCreate` is implemented here because #83 already had both of its\n * halves — `connect` inserts a pair for an existing row, `create` writes the\n * row and its pair — so it is those two selected by a lookup. The remaining\n * four reach the far row *through* the pairs, which is a second hop this path\n * does not have yet; {@link JOIN_TABLE_REFUSED} says so in those terms rather\n * than inventing a principle.\n *\n * `set` is the one operand with **two implementations** — this file's\n * join-table version from #83 and the ordinary-relation one — and they agree\n * because both were reasoned to \"replace the set I can see\" independently, not\n * because they share anything. Worth knowing when either is changed.\n */\nconst JOIN_TABLE_SUPPORTED = new Set([\n \"connect\",\n \"connectOrCreate\",\n \"disconnect\",\n \"set\",\n \"create\",\n]);\n\n/**\n * Why each ordinary-relation operand is not offered through a join table.\n *\n * Same shape as {@link REFUSED}, and for the same reason: \"not implemented\" is\n * much less useful than knowing whether the thing you reached for is a rewrite\n * or a wait — and here most of them are neither, they are a different operation\n * wearing the same name.\n */\nconst JOIN_TABLE_REFUSED: Record<string, string> = {\n // Prisma's own refusal, not this ORM's — the one entry here that is a\n // decision rather than a gap, and it is not gemi's decision.\n createMany:\n `Prisma does not offer 'createMany' through an implicit many-to-many ` +\n `either — it reports it as an unknown argument. Use 'create', which writes ` +\n `the row and its pair.`,\n // The four that reach the far row through the pairs. Prisma implements all\n // of them; this path does not have the second hop yet.\n update:\n `Reaching the far row means reading the pairs first, which this path does ` +\n `not do yet. Update the related model directly, filtered by its own key.`,\n updateMany:\n `As 'update': it needs the pairs read before the far rows can be matched.`,\n delete:\n `It deletes the far row rather than the pair — Prisma does this through a ` +\n `join table too — and reaching it means reading the pairs first, which ` +\n `this path does not do yet. Use 'disconnect' to remove the link, or delete ` +\n `the row through its own model.`,\n deleteMany:\n `As 'delete': the far rows have to be found through the pairs first.`,\n};\n\n/**\n * Writes through Prisma's implicit many-to-many join table.\n *\n * The table has **no model**: no registered class, no generated base, no\n * `$schema` — just `_PostToTag` with an `A` and a `B` column, named from the\n * two model names in alphabetical order, with the pair as its primary key. So\n * the two operands that work for an ordinary relation have nothing to compile\n * *to*, and these statements are emitted directly, the way the read side's\n * `readPairs` already does.\n *\n * Which column is which end comes from `resolveLink`, never from declaration\n * order. That distinction is invisible on `Post` / `Tag` and wrong on a\n * self-relation, where both ends are the same model and only the *field* name\n * separates them.\n *\n * Every operand is an `after` step: the pair cannot be written until this row\n * has a key. Two of them are more than one statement — `set` deletes before it\n * inserts — and `$exec` already opens a transaction for any plan carrying\n * steps, so the whole thing is atomic.\n *\n * **The rows the pairs point at are still read and written through the child's\n * own `$exec`**, so a `connect` cannot reach a row the child's policies hide,\n * and a `create` gets the child's `onCreate`. Only the join table itself —\n * which has no model and nothing an application could scope — is written\n * directly.\n */\nfunction planJoinTable(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n link: { parentField: string; childField: string; join?: Link[\"join\"] },\n key: string,\n operand: unknown,\n operation: string,\n at: (args: any) => any,\n out: NestedWritePlanning,\n dialect: SqlDialect,\n): void {\n if (key === \"connectOrCreate\") {\n assertConnectOrCreateOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n }\n\n if (!JOIN_TABLE_SUPPORTED.has(key)) {\n const why = JOIN_TABLE_REFUSED[key];\n if (why) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is an implicit many-to-many, and '${key}' means ` +\n `something different through a join table. ${why}`,\n );\n }\n\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is an implicit many-to-many. Only ` +\n `${[...JOIN_TABLE_SUPPORTED].sort().join(\", \")} are implemented ` +\n `through its join table.`,\n );\n }\n\n // `connect`, `disconnect` and `set` name existing rows by a unique key, and\n // the step below resolves them one at a time — after the parent row exists,\n // since a pair needs both ends. That made a key the child does not declare\n // refuse from mid-transaction, while the *same* operand on an ordinary\n // relation refuses from the compiler (#110). `create` names no existing row\n // and `connectOrCreate` is checked above, so those two are not this.\n if (key === \"connect\" || key === \"disconnect\" || key === \"set\") {\n assertNamedRows(schema, relation, child, operand, key, operation);\n }\n\n const join = link.join!;\n const parentField = link.parentField;\n const childField = link.childField;\n\n // `dialect.quoteIdent`, not a local helper. It does the same escaping *and*\n // rejects a NUL byte, which exists because NUL is the parameter sentinel in\n // `compile/fragment.ts`. Prisma generates these identifiers so nothing can\n // reach that check today — but this is the one file emitting SQL without the\n // `Fragment` pipeline, which makes it the one most worth holding to the rule\n // rather than the one to excuse from it.\n const quoted = (name: string) => dialect.quoteIdent(name);\n\n out.keyFields.push(parentField);\n\n out.after.push({\n relation: relation.name,\n // The operand this step implements, not a two-way split of it. This read\n // `key === \"create\" ? \"create\" : \"connect\"`, which labelled `disconnect`,\n // `set` and `connectOrCreate` as `connect` — the first of those being the\n // opposite operation. The field exists so a plan is legible from the\n // outside, so a wrong label is the whole of its cost.\n operation: key as NestedWriteStep[\"operation\"],\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const parentKey = parent[parentField];\n if (parentKey === null || parentKey === undefined) return;\n\n // `set` replaces the whole set, so what is there now goes first — but\n // **only the part of it this caller can see**.\n //\n // A bare `delete … where \"A\" = ?` removes every pair, including ones\n // pointing at children the child model's policies hide, and nothing on\n // that path consults the child. `disconnect` right below refuses the same\n // effect when it is named explicitly — it resolves through the child's\n // own `findUniqueOrThrow`, which raises for a row the caller cannot see —\n // so an unscoped `set` would make the authorization boundary disagree\n // with itself depending on which operand you reached for.\n //\n // Not a read leak: nothing comes back, and the caller cannot tell a\n // hidden link existed. It is an unscoped *write* to state they could not\n // otherwise reach, which is the thing this layer exists to prevent.\n //\n // So the existing links are read, filtered through the child's own\n // `findMany` — where its scope applies exactly as it does anywhere else —\n // and only those are deleted. `set` therefore means \"replace the set I\n // can see\", which is what every other policy in this ORM does: narrow,\n // never widen. With no policy on the child, every link is visible and\n // this is byte-for-byte the old behaviour, so Prisma parity is unchanged\n // wherever there is no policy to apply.\n if (key === \"set\") {\n const linked = (await executor.query(\n `select ${quoted(join.childColumn)} from ${quoted(join.table)} ` +\n `where ${quoted(join.parentColumn)} = ${dialect.placeholder(0)}`,\n [parentKey],\n )) as Record<string, unknown>[];\n\n const existing = Array.from(linked, (row) => row[join.childColumn]);\n\n if (existing.length > 0) {\n const visible = (await executor.exec(\n relation.model,\n \"findMany\",\n {\n where: { [childField]: { in: existing } },\n select: { [childField]: true },\n },\n // NOT pre-scoped: the child's scope is the whole point here.\n false,\n )) as Record<string, unknown>[];\n\n // One statement, not one per link. The scoped form is a `delete`\n // over an `in` list rather than a loop, because this repo counts\n // *statements*: `plans/orm/benchmarks.md` measures include trees that\n // way, and the lateral strategy exists to remove `N - 1` of them. A\n // loop here would have made `set` the one write that reintroduces\n // them — invisible on SQLite, where round trips are in-process, and\n // paid in full on Postgres, where they are not.\n //\n // Placeholders are built per length rather than bound as one array\n // parameter. `dialect.inList` does the latter on Postgres, but it\n // returns a `Fragment` and this is the one path that emits SQL\n // without that pipeline — there is no model to route the join table\n // through. The cost is one server-side plan per distinct link count;\n // the ORM's own plan cache is unaffected, since it keys on the\n // argument shape and this text never reaches it.\n const targets = Array.from(visible, (row) => row[childField]);\n\n // Every existing link points at a row this caller cannot see, so\n // there is nothing to clear and `in ()` is a syntax error on both\n // dialects. The loop this replaced degenerated to zero iterations\n // here; the single statement has to say so explicitly.\n if (targets.length > 0) {\n await runPairStatement(\n executor,\n `delete from ${quoted(join.table)} where ` +\n `${quoted(join.parentColumn)} = ${dialect.placeholder(0)} and ` +\n `${quoted(join.childColumn)} in (` +\n targets\n .map((_, index) => dialect.placeholder(index + 1))\n .join(\", \") +\n `)`,\n [parentKey, ...targets],\n );\n }\n }\n }\n\n const items = listOf(at(args));\n if (items.length === 0) return;\n\n const childKeys: unknown[] = [];\n\n for (const item of items) {\n if (key === \"create\") {\n const created = (await executor.exec(\n relation.model,\n \"create\",\n { data: item, select: { [childField]: true } },\n // NOT pre-scoped: the child's own `onCreate` is what scopes the row.\n false,\n )) as Record<string, unknown> | null;\n if (created) childKeys.push(created[childField]);\n continue;\n }\n\n /**\n * `connectOrCreate` is the two branches above selected by a lookup, so\n * it needed no new machinery here — which is why it is the one of the\n * five missing operands this change adds.\n *\n * `findUnique`, not the `findUniqueOrThrow` the `connect` path below\n * uses: a miss is the *other branch* here rather than an error. And a\n * scoped-away hit therefore takes the create branch, which is the same\n * answer the ordinary-relation `connectOrCreate` gives and closes the\n * same probe — `connect` raising where this succeeds would together\n * confirm a row the caller cannot see.\n */\n if (key === \"connectOrCreate\") {\n // The `where` was validated at plan time by\n // `assertConnectOrCreateOperand`, which the branch at the top of this\n // function runs for both relation kinds.\n const entry = item as Record<string, unknown>;\n\n const hit = (await executor.exec(\n relation.model,\n \"findUnique\",\n { where: entry.where, select: { [childField]: true } },\n false,\n )) as Record<string, unknown> | null;\n\n if (hit) {\n childKeys.push(hit[childField]);\n continue;\n }\n\n const made = (await executor.exec(\n relation.model,\n \"create\",\n { data: entry.create, select: { [childField]: true } },\n false,\n )) as Record<string, unknown> | null;\n if (made) childKeys.push(made[childField]);\n continue;\n }\n\n // `connect`, `disconnect` and `set` all name existing rows by a unique\n // key — checked at plan time above. Resolved through the child's own\n // `$exec`, so its policies decide which rows exist — otherwise a\n // connect by any unique key reaches every tenant's.\n const found = (await executor.exec(\n relation.model,\n \"findUniqueOrThrow\",\n { where: item, select: { [childField]: true } },\n false,\n )) as Record<string, unknown> | null;\n if (found) childKeys.push(found[childField]);\n }\n\n for (const childKey of childKeys) {\n if (key === \"disconnect\") {\n await runPairStatement(\n executor,\n `delete from ${quoted(join.table)} where ` +\n `${quoted(join.parentColumn)} = ${dialect.placeholder(0)} and ` +\n `${quoted(join.childColumn)} = ${dialect.placeholder(1)}`,\n [parentKey, childKey],\n );\n continue;\n }\n\n // `on conflict do nothing`, because the pair is the join table's\n // primary key and Prisma treats a repeated `connect` as a no-op rather\n // than an error. Without it the second connect of the same pair is a\n // raw driver unique violation, which is neither Prisma's behaviour nor\n // a useful one. Both dialects spell it the same way — SQLite has had it\n // since 3.24 — so this needs no dialect branch.\n await runPairStatement(\n executor,\n `insert into ${quoted(join.table)} ` +\n `(${quoted(join.parentColumn)}, ${quoted(join.childColumn)}) ` +\n `values (${dialect.placeholder(0)}, ${dialect.placeholder(1)}) ` +\n `on conflict do nothing`,\n [parentKey, childKey],\n );\n }\n },\n });\n}\n\n/**\n * One statement against a table with no model, on the connection this call\n * resolved — which is what keeps it inside the caller's transaction.\n *\n * Placeholders come from the dialect rather than being hardcoded, for the same\n * reason `readPairs` renders its statement: SQLite writes `?` and Postgres\n * `$1`, and this path has no `Fragment` pipeline to do it automatically.\n */\nasync function runPairStatement(\n executor: { query(text: string, values: unknown[]): Promise<unknown> },\n text: string,\n values: unknown[],\n): Promise<void> {\n await executor.query(text, values);\n}\n\n/**\n * `upsert`'s operand: `{ where, create, update }`, or a list of them.\n *\n * The two payloads are always required — one per branch. **The `where` is\n * required only on a to-many**, which is Prisma's own split rather than a\n * looseness: `AccountUpsertWithWhereUniqueWithoutUserInput` has `where:\n * AccountWhereUniqueInput`, while `ProfileUpsertWithoutUserInput` is\n * `{ update, create, where? }` — the to-one already knows which row it means,\n * because the parent's key names it. So the unique-key match is skipped there\n * too: a to-one `where` is a `WhereInput` filter narrowing the single linked\n * row, not a key selecting one out of many.\n *\n * Checked at plan time like every other operand here, so a missing key fails\n * when the query compiles rather than after the parent row is written.\n */\nfunction assertUpsertOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n operation: string,\n many: boolean,\n): void {\n const at = `data.${relation.name}.upsert`;\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n many\n ? `Expected an object with 'where', 'create' and 'update'.`\n : `Expected an object with 'create' and 'update' — on a to-one the ` +\n `'where' is optional, since the parent's key already names the row.`,\n );\n }\n\n const record = entry as Record<string, unknown>;\n const required = many\n ? ([\"where\", \"create\", \"update\"] as const)\n : ([\"create\", \"update\"] as const);\n\n for (const name of required) {\n if (record[name] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${name}' key — 'upsert' names the row to look for, ` +\n `what to write if it is there, and what to write if it is not.`,\n );\n }\n }\n\n if (!many) continue;\n\n matchUniqueKey(child, record.where, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.upsert.where`,\n });\n }\n}\n\n/**\n * The caller's filter and the parent restriction, as a conjunction.\n *\n * Never a spread. A spread merges by *key*, so a caller naming the foreign key\n * column silently replaces the restriction that keeps the operand on this\n * parent's rows — and the failure is a wider write, not an error. `AND` cannot\n * be overwritten by any key the caller chooses, and it still lets their\n * predicate narrow, which is the property `withScope` relies on for policy\n * fragments.\n *\n * An empty or absent filter contributes nothing, so the common case is the\n * restriction alone rather than `AND` of one thing.\n */\nfunction conjoin(\n filter: unknown,\n restriction: Record<string, unknown>,\n): Record<string, unknown> {\n if (\n filter === undefined ||\n filter === null ||\n typeof filter !== \"object\" ||\n Array.isArray(filter) ||\n Object.keys(filter as object).length === 0\n ) {\n return restriction;\n }\n return { AND: [filter as object, restriction] };\n}\n\n/**\n * The three shapes a link takes in an argument object, and the two questions\n * asked about its *values* — written once so that a relation joining on four\n * fields goes down the same path as one joining on one (#271).\n *\n * Before these, every site spelled the link as `{ [childField]: parent[\n * parentField] }` or `select: { [childField]: true }` by hand, in about forty\n * places across the two sides. Generalising each of them separately is how a\n * composite relation ends up correlating on every field in nine operands and on\n * the first field in the tenth — a silent wrong write, which is precisely what\n * the refusal these replace was protecting against. One function per shape\n * means the count of fields is invisible to the callers, so there is no\n * single-field spelling left for a new operand to copy.\n */\n\n/**\n * `{ <childField>: row[<parentField>], … }` — the far side's columns bound to\n * the values this row holds.\n *\n * On the foreign side that reads as \"belonging to this parent\": the child's\n * foreign key set to the parent's key. On the owning side the same call reads\n * as \"the row this one points at\": `link.parentFields` are this row's foreign\n * key and `link.childFields` are what they reference, so the object is the far\n * row's own columns. One function, because the arithmetic is identical and the\n * two sides differ only in which table the result is applied to.\n *\n * An object with several keys is a conjunction in every `where` this ORM\n * compiles, and several assignments in every `data`, so the same shape serves\n * both — which is why `create`, `connect`, `update`, `delete` and the two\n * `*Many` operands can all take it unchanged.\n */\nfunction childLink(\n link: { parentFields: string[]; childFields: string[] },\n parent: Record<string, unknown>,\n): Record<string, unknown> {\n const key: Record<string, unknown> = {};\n for (let index = 0; index < link.childFields.length; index++) {\n key[link.childFields[index]] = parent[link.parentFields[index]];\n }\n return key;\n}\n\n/** `{ <field>: true, … }` — the narrowest select that reads a whole link back. */\nfunction keySelect(fields: readonly string[]): Record<string, true> {\n const select: Record<string, true> = {};\n for (const field of fields) select[field] = true;\n return select;\n}\n\n/** `{ <field>: null, … }` — a detach, which has to clear *every* column. */\nfunction nullKey(fields: readonly string[]): Record<string, null> {\n const cleared: Record<string, null> = {};\n for (const field of fields) cleared[field] = null;\n return cleared;\n}\n\n/** The same detach spelled as *values* rather than as a `data` object. */\nfunction nullsFor(fields: readonly string[]): null[] {\n return fields.map(() => null);\n}\n\n/** The values of `fields` on `row`, positionally. */\nfunction valuesOf(\n row: Record<string, unknown> | null | undefined,\n fields: readonly string[],\n): unknown[] {\n return fields.map((field) => row?.[field]);\n}\n\n/**\n * Whether a link's columns actually name a row.\n *\n * **A partially-null composite key links nothing**, which is SQL's rule and not\n * a choice made here: `(tenantId, orderId) = (1, NULL)` is `UNKNOWN`, so the\n * join finds no row however many other columns match. Prisma agrees at the\n * type level — an optional relation over composite fields makes *all* of them\n * optional together, and `include` on a row holding `(1, NULL)` returns `null`.\n *\n * So every place that used to test one value for `null` — \"is anything linked\n * here\" — tests the whole key through this, and a half-written key reads as\n * *absent* rather than as a link to a row that does not exist. Getting this\n * backwards is what would make `clearLinks` null the key of every unlinked row\n * in the table, and `disconnect`'s filter arm read a child by a `NULL` key.\n */\nfunction isLinked(values: readonly unknown[]): boolean {\n return values.every((value) => value !== null && value !== undefined);\n}\n\n/**\n * Null the foreign-key columns of every row that currently holds `values` **and\n * that the caller can see** — the clearing half of `set`, the half a nested\n * `create` on an occupied to-one needs before it can insert (#360), and the\n * half the owning side's `connect` needs before it can repoint (#363).\n *\n * Shared rather than written three times because the *scoping* is the\n * interesting part and it has to be identical on all of them: the read goes\n * through the target model's own `findMany` un-pre-scoped, so a row that\n * model's policies hide is not detached. `set` therefore means \"replace the set\n * I can see\" (#83), the nested `create` means \"displace the child I can see\",\n * and the owning-side `connect` means \"displace the sibling I can see\" — with a\n * hidden incumbent the insert or repoint collides on the unique key instead,\n * which is the conservative answer rather than a silent detach of somebody\n * else's row.\n *\n * **`model` is a parameter rather than `relation.model` because the two\n * directions clear different tables.** On the foreign side the rows holding the\n * key belong to the *child*; on the owning side they are siblings of the row\n * being written, in the model the statement is already about. Same statement\n * pair, same scoping rule, two tables — so the only thing that varies is which\n * one, and passing it is what let #363 reuse this instead of restating it.\n *\n * The `findMany` decides whether to issue the write at all. The `updateMany`\n * would match the same rows on its own; what the read adds is that the common\n * case — nothing linked — costs a select rather than an update, and that the\n * scope is consulted through a read before anything is written.\n *\n * `fields` is ORM-authored: the caller named a row to `set`, or a payload to\n * `create`, or a row to `connect`, and the ORM chose to null these columns.\n * Without it a model scoped on one of them is refused by the scope-escape guard\n * for a write it never made — #98, and the reason `disconnect` one operand over\n * passes the same list. **Every** column of the link goes in it, because a\n * composite key is cleared by writing null to all of them and each one is as\n * much the ORM's as the first.\n *\n * **A key with a null component clears nothing** (#271), and the guard is not\n * defensive tidying. `where: { tenantId: 1, orderId: null }` matches every row\n * whose order is unset in that tenant — rows linked to *nothing*, which is the\n * opposite of the set this is asked for — and the `updateMany` behind it would\n * then write null over null across all of them. See {@link isLinked}. Nothing\n * reaches here with a null today (`displaceSibling` returns first, and the\n * foreign side reads its values out of a primary key), so this buys no\n * behaviour; it means a caller that one day does cannot silently rewrite the\n * table.\n */\nasync function clearLinks(\n model: string,\n fields: readonly string[],\n values: readonly unknown[],\n executor: RelationExecutor,\n): Promise<void> {\n if (!isLinked(values)) return;\n\n const where: Record<string, unknown> = {};\n for (let index = 0; index < fields.length; index++) {\n where[fields[index]] = values[index];\n }\n\n const linked = (await executor.exec(\n model,\n \"findMany\",\n { where, select: keySelect(fields) },\n false,\n )) as Record<string, unknown>[];\n\n if (linked.length === 0) return;\n\n await executor.exec(\n model,\n \"updateMany\",\n { where, data: nullKey(fields) },\n false,\n fields,\n );\n}\n\n/**\n * **Whether the row a `connect` named already points at this parent** — the\n * question that turns a clear-then-repoint into no statements at all (#372).\n *\n * The foreign-side twin of the `sameKey` test inside {@link displaceSibling},\n * and the same answer read from the other end of the key: on the owning side\n * the row that must not be cleared is the one being written, here it is the one\n * being named. Both exist because clearing a row and then selecting it by the\n * column just cleared is a contradiction the moment anything in that `where`\n * depends on the old value — a policy scoping on the column, or a caller who\n * named the row by it.\n *\n * **Prisma issues no write for an already-linked `connect` from either end, and\n * only this end matches that outright.** The owning side skips the *clear* and\n * still emits the repoint — {@link displaceSibling}'s docblock says so in plain\n * terms, and that residual divergence is #370's class, not something #363/#375\n * closed. Do not read the symmetry above as parity.\n *\n * **Un-pre-scoped, so the child's own policies decide what this can see** — the\n * same rule every other statement in this step follows, and it is what makes\n * the miss answer fall out rather than needing a branch. A row that does not\n * exist and a row this caller cannot see both read as absent, so both are\n * treated as \"not linked here\" and left to the repoint, which raises\n * `RecordNotFoundError` for them exactly as it did before.\n *\n * Getting that direction backwards would be the expensive mistake: a lookup\n * that ignored the scope could answer \"already linked\" for another tenant's row\n * and make the whole operand a silent no-op, which is a `connect` that reports\n * success and links nothing.\n *\n * `findUnique` rather than `findFirst` because `assertNamedRows` has already\n * run `matchUniqueKey` over this operand — the same lookup, and the same\n * spelling, that `connectOrCreate`'s hit branch uses one screen up.\n */\nasync function alreadyLinked(\n model: string,\n fields: readonly string[],\n where: unknown,\n values: readonly unknown[],\n executor: RelationExecutor,\n): Promise<boolean> {\n const named = (await executor.exec(\n model,\n \"findUnique\",\n { where, select: keySelect(fields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (named === null || named === undefined) return false;\n\n // **`every`, not `some`** — the row is already linked here only if the whole\n // key matches. A composite key agreeing on one column and not the rest points\n // somewhere else entirely, and short-circuiting on it would skip a repoint\n // that has to happen. This is the one site of #386's generalisation that is\n // not a rename: `sameKey` compares a single value, so the fold belongs here.\n return fields.every((field, index) => sameKey(named[field], values[index]));\n}\n\n/**\n * **Detach the sibling that already holds this foreign-key value, so the row\n * being written can take it** — the owning side of #361's displacement, and the\n * whole of #363.\n *\n * The two directions look alike and are not the same operation. On the foreign\n * side the incumbent is a row of the *child* model, reached through\n * `planForeignSide`; here it is a row of the model the statement is already\n * writing, one `@unique` foreign key away. `clearLinks` is shared between them\n * because the statement pair and the scoping rule are identical; everything\n * below is what only this side needs.\n *\n * Measured against Prisma 6.19.2 on SQLite before it was written, with query\n * logging on. `Profile.update({ where: { id: 1 }, data: { user: { connect:\n * { id: 2 } } } })` where user 2's profile is taken issues, in order:\n *\n * select User.id where id = 2 resolve the operand\n * select Profile.* where id = 1 the row being written\n * select Profile.id, userId where userId in (2) the incumbent\n * update Profile set userId = null where id in (2) detach it\n * update Profile set userId = 2 where id in (1) take the link\n *\n * all inside one `BEGIN IMMEDIATE` / `COMMIT`. The incumbent is left in the\n * table with a null key — **orphaned, not deleted** — which is the half a fix\n * in the wrong direction turns into silent data loss wearing a green test.\n *\n * **Why the row being written is skipped: because Prisma skips it too.**\n * `connect`ing the far row a caller is already connected to writes *nothing at\n * all* — measured with logging on, the whole call is\n *\n * BEGIN IMMEDIATE / select the operand / select this row /\n * select the operand again / select this row again / COMMIT\n *\n * with no `update` in it. So this is not a departure to be justified; it is the\n * behaviour. (An earlier draft of this docblock claimed Prisma nulls the column\n * and writes the same value straight back for a net nothing. It does not, and\n * the claim survived into four places before it was measured rather than\n * reasoned about.)\n *\n * The skip matters *more* here than it would as mere parity, which is worth\n * keeping: the repoint on this side is not a statement of its own but a\n * contribution to the main statement, whose `where` has already been through\n * this model's policies. A model scoped on the foreign key would have its own\n * row put outside that scope by a clear, so the main statement would match\n * nothing and leave the row detached and never re-attached — a silent\n * half-write, #98's hazard arriving on this side, and the same argument #362\n * used to leave `set`'s *link* half not naming its column.\n *\n * **The residual divergence runs the other way and is not fixed here.** Prisma\n * makes the whole call a no-op; gemi still emits the repoint `UPDATE`, because\n * the contribution is in the SET list at compile time and cannot be withdrawn\n * at bind time. Same rows either way — it writes the value already there — but\n * on a one-to-one owner carrying `@updatedAt` gemi bumps the stamp where Prisma\n * leaves it. That is an instance of the stamp divergence #370 documented rather\n * than a new one, no fixture can see it (neither `Profile` nor `Cover` has the\n * column), and it is specific to *this* path: on a many-to-one both clients\n * issue the update and both stamp.\n *\n * **Why a `create` reads nothing.** There is no row yet, so there is no self to\n * be the incumbent and no `where` to read one through.\n *\n * **Why an absent parent detaches nothing, which is belt and braces and is\n * kept anyway.** Prisma *does* detach and then rolls the whole thing back —\n * measured on `update({ where: { id: 99 } })`, which logs the\n * `update … set userId = null`, then `ROLLBACK`, then answers P2025. gemi\n * reaches the same committed state by the same route, because `update` raises\n * `RecordNotFoundError` on a `where` that matches nothing and every plan\n * carrying a step runs in a transaction — verified by dropping this return and\n * watching `O12g` stay green. So it buys no correctness today; it buys two\n * statements on a miss, and it makes this step's effect independent of whether\n * the statement *after* it raises, which is the assumption that would be\n * expensive to have baked in silently if that ever changed.\n */\nasync function displaceSibling(\n schema: ModelSchema,\n fkFields: readonly string[],\n /**\n * The values about to be written into this row's foreign key, positionally\n * paired with `fkFields`.\n *\n * **A key with a null component displaces nothing**, which is the composite\n * generalisation of the `value === null` return this has always had rather\n * than a new rule: the row is being *un*linked, and there is no incumbent for\n * a link that is not being made. See {@link isLinked}.\n */\n values: readonly unknown[],\n /**\n * This statement's own `where`, **already through this model's policies** —\n * so the read below is pre-scoped, exactly as the `disconnect` filter arm's\n * parent read is, and for the same reason: applying them again would `AND`\n * the same predicate twice.\n */\n where: unknown,\n /** False on a `create`, where the row does not exist yet. */\n existing: boolean,\n executor: RelationExecutor,\n): Promise<void> {\n if (!isLinked(values)) return;\n\n if (existing) {\n const self = (await executor.exec(\n schema.name,\n \"findFirst\",\n { where, select: keySelect(fkFields) },\n true,\n )) as Record<string, unknown> | null;\n\n if (self === null || self === undefined) return;\n // **Every column, not the first that differs** — the skip is \"this row\n // already points at that row\", and on a composite key that is only true\n // when the whole tuple matches. Reading it as \"some column matches\" would\n // skip the clear for a sibling holding `(1, \"b\")` while this row takes\n // `(1, \"a\")`, and the repoint would then collide on the unique index the\n // caller cannot see.\n if (fkFields.every((field, index) => sameKey(self[field], values[index]))) {\n return;\n }\n }\n\n await clearLinks(schema.name, fkFields, values, executor);\n}\n\n/**\n * Whether two foreign-key values name the same row.\n *\n * Not `===`, because the two operands reach this from different places and a\n * key type can survive the trip differently. One side is read out of the\n * database through a `select`; the other is either a caller's literal — `connect:\n * { id: 2 }`, taken straight from the argument tree by the direct form — or a\n * value read back off the far model. A `BigInt` key is the case that makes this\n * concrete rather than theoretical: `2n === 2` is `false`, and answering \"these\n * are different rows\" there is what would make the clear fire on the row it is\n * meant to skip.\n *\n * The fallback is deliberately loose in the other direction too — it calls the\n * number `2` and the string `\"2\"` the same row. Harmless for every key type in\n * reach: Prisma's unique keys are `Int`, `BigInt`, `String`, `Bytes` and the\n * date types, and a `String` key whose value is `\"2\"` can only be compared\n * against another `String`, since the column it came from decides both sides.\n * Stated rather than tightened, because the tightening would have to know the\n * field's type here and the looseness has no reachable victim.\n */\nfunction sameKey(a: unknown, b: unknown): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return false;\n }\n return a === b || String(a) === String(b);\n}\n\n/**\n * The filter operands, which are shaped differently from each other.\n *\n * `updateMany` wraps its filter in `where` and carries a `data` beside it;\n * `deleteMany` *is* the filter. Checked at plan time, so a caller who wrote one\n * shape for the other hears about it before the parent row is written.\n *\n * `UnsupportedQueryError` here because that is what this branch has; both are\n * argument *validation* and belong in #103's `InvalidArgumentError`. They need\n * no edit when it lands — its conversion selects sites by whether their detail\n * already says what a valid value looks like, and these say `Expected an\n * object with 'where' and 'data'`.\n */\nfunction assertManyOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n operand: unknown,\n key: string,\n operation: string,\n): void {\n const at = `data.${relation.name}.${key}`;\n\n if (typeof operand !== \"object\" || operand === null || Array.isArray(operand)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n key === \"updateMany\"\n ? `Expected an object with 'where' and 'data'.`\n : `Expected an object of filters — 'deleteMany' takes the filter ` +\n `directly, not wrapped in a 'where'.`,\n );\n }\n\n if (key !== \"updateMany\") return;\n\n const record = operand as Record<string, unknown>;\n for (const required of [\"where\", \"data\"] as const) {\n if (record[required] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${required}' key — 'updateMany' names which rows to ` +\n `write and what to write to them.`,\n );\n }\n }\n}\n\n/**\n * `update`'s operand: `{ where, data }`, or a list of them on a to-many.\n *\n * `data` is *not* inspected here — it is the child's, and the child's own\n * `$exec` validates it against the child's schema and policies. Checking it\n * against this model would be checking the wrong shape.\n *\n * **On a to-one only `data` is required, and it may have been written bare.**\n * `toOneOperand` has already turned `update: { bio: \"x\" }`,\n * `update: { data: … }` and `update: { where, data }` into the one form this\n * reads, so what arrives is always `{ where?, data }` — but the `where` is\n * genuinely optional there (`UpdateToOneWithWhereWithoutUserInput` spells it\n * `where?`) and it is a filter rather than a key, so `matchUniqueKey` does not\n * run on it either.\n */\nfunction assertNamedUpdates(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n operation: string,\n many: boolean,\n): Record<string, unknown>[] {\n const at = `data.${relation.name}.update`;\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n const out: Record<string, unknown>[] = [];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected an object with 'where' and 'data'.`,\n );\n }\n\n const record = entry as Record<string, unknown>;\n const required = many ? ([\"where\", \"data\"] as const) : ([\"data\"] as const);\n\n for (const name of required) {\n if (record[name] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${name}' key — 'update' names the row to write and ` +\n `the columns to write to it.`,\n );\n }\n }\n\n if (many) {\n matchUniqueKey(child, record.where, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.update.where`,\n });\n }\n\n out.push(record);\n }\n\n return out;\n}\n\n/**\n * The rows a `disconnect` / `delete` names, each by a unique key.\n *\n * Validated at plan time for the reason every operand here is: a refusal that\n * arrives mid-transaction has to unwind a parent row that should never have\n * been written.\n */\nfunction assertNamedRows(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n key: string,\n operation: string,\n): Record<string, unknown>[] {\n const at = `data.${relation.name}.${key}`;\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n const out: Record<string, unknown>[] = [];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected an object naming a unique field, or an array of them.`,\n );\n }\n matchUniqueKey(child, entry, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.${key}`,\n });\n out.push(entry as Record<string, unknown>);\n }\n\n return out;\n}\n\n/**\n * A to-one `disconnect` / `delete` operand, **as the caller spelled it** — a\n * boolean, or a filter object, and nothing else.\n *\n * The counterpart of {@link assertNamedRows}, and deliberately *not* it. That\n * one runs `matchUniqueKey`, which is right where the caller is picking one row\n * out of many and wrong here: Prisma's to-one operand is a `WhereInput`, and\n * `delete: { bio: \"seed\" }` — a column with no unique index anywhere near it —\n * is accepted and deletes the connected row. Sharing `assertNamedRows` would\n * have refused that at compile time with a list of unique keys the caller never\n * had to name.\n *\n * **Run before {@link toOneOperand} rather than after it, which is what makes\n * `null` reachable at all.** That translation maps `false` to `null`, so a\n * check downstream of it sees one value for two very different calls: the\n * deliberate no-op, and an operand of a type Prisma has no arm for. This used\n * to sit downstream and pass both, and the second is the one that mattered —\n * before #359 the owning side refused everything but `true`, so `disconnect:\n * null` was an `UnsupportedQueryError` there, and widening the grammar turned a\n * refusal into silence. That is the failure class the differential suite exists\n * to pin, arrived at from the tidy direction, and it is not one to inherit on\n * the strength of the far side having it too.\n *\n * Measured, so the refusal is matching Prisma rather than being stricter than\n * it (6.19.2, SQLite): `disconnect: null` is a `PrismaClientValidationError` on\n * all three shapes it can be written against — a one-to-one from either end and\n * a many-to-one — with nothing written. `undefined` is the *absent* key and\n * stays a no-op on both clients, which is why only `null` is named here:\n * `canonicalShape` drops an undefined member outright, so `disconnect:\n * undefined` and no `disconnect` at all are already one call.\n *\n * Sound at plan time for the same reason the boolean guard is (#358):\n * `canonicalShape` records `null` as `\"null\"`, the booleans as `\"true\"` /\n * `\"false\"` and a filter by its structure, so no two of them can share a cache\n * entry and this refusal can never be decided on one call's behalf by another's.\n *\n * `InvalidArgumentError` because the argument is supported and the value is\n * wrong — the same reading `assertCreateManyOperand` uses, and the reason the\n * message names the two shapes that work instead of announcing a gap.\n */\nfunction assertToOneFilter(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n key: string,\n operation: string,\n): void {\n if (operand === undefined) return;\n if (typeof operand === \"boolean\") return;\n if (operand !== null && typeof operand === \"object\" && !Array.isArray(operand)) {\n return;\n }\n\n throw new InvalidArgumentError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one, so '${key}' takes either a boolean — ` +\n `'true' for the connected ${child.name}, 'false' for nothing — or an ` +\n `object of filters it has to match. Prisma's operand here is ` +\n `'${child.name}WhereInput | boolean'.` +\n // Named rather than left to the list above, because `null` is the one\n // wrong value with an obvious intent: it is what an optional flag\n // degrades to, and `false` is the spelling that means what it was\n // reaching for. Prisma refuses it too, so pointing at `false` is a\n // correction and not a workaround.\n (operand === null\n ? ` 'null' is not one of them — write 'false' for the no-op. Prisma ` +\n `answers 'null' with a validation error rather than accepting it.`\n : \"\"),\n );\n}\n\n/**\n * The plan-time shape check for a to-one `update` / `upsert`, run **before**\n * {@link toOneOperand} rewrites the operand.\n *\n * Three holes it closes, all of the same kind: the to-one path dropped the\n * `matchUniqueKey` its to-many sibling runs — correctly, since Prisma's to-one\n * `where` is a `WhereInput` and not a unique key — and then put nothing in its\n * place, so the operand reached the step unexamined.\n *\n * 1. **A key the rewrite does not know is discarded silently.** The wrapper\n * branch rebuilds `{ where, data }` from the keys it recognises, so\n * `update: { data: { … }, wehre: { … } }` loses the typo and the filter\n * with it — and `conjoin(undefined, link)` is the parent link alone, so a\n * nested update the caller *guarded* runs unguarded. A write that should\n * not have happened, with nothing raised anywhere. Prisma answers `Unknown\n * argument 'wehre'`, and `assertConnectOrCreateOperand` in this file\n * already refuses extra keys for exactly this reason.\n * 2. **A `where` that is not an object is dropped by `conjoin`**, whose first\n * arm treats an array or a scalar as \"no filter\". So `upsert: { where:\n * [{ bio: \"old\" }], … }` finds the connected row and takes the *update*\n * branch, where Prisma applies the filter, matches nothing and takes the\n * *create* branch onto a unique violation. Two different rows written.\n * 3. **A non-object operand escapes to run time.** `update: null` normalises\n * to `{ where: undefined, data: null }`, which `assertNamedUpdates` passes\n * because its `data` key is present — and the failure then arrives from\n * inside the `after` step as `InvalidArgumentError('data', 'Profile',\n * 'updateMany')`, naming a model and an operation the caller never wrote,\n * after the parent row has already been written and has to be unwound.\n * Plan-time validation exists in this file precisely to prevent that.\n *\n * The payload spelling is deliberately *not* key-checked. `update: { bio: \"x\" }`\n * is the child's own `data`, so every key in it is the child's business and\n * belongs to the child's schema — checking it here would be checking the wrong\n * shape, which is the rule {@link assertNamedUpdates} states. The wrapper is\n * distinguishable because it carries a `data`, which is the same test the\n * rewrite makes one function down.\n */\nfunction assertToOneWriteOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n key: string,\n operand: unknown,\n operation: string,\n): void {\n if (key !== \"update\" && key !== \"upsert\") return;\n\n const argument = `data.${relation.name}.${key}`;\n const refuse = (reason: string): never => {\n throw new InvalidArgumentError(argument, schema.name, operation, reason);\n };\n\n if (operand === null || typeof operand !== \"object\" || Array.isArray(operand)) {\n refuse(\n `Expected an object, got ${JSON.stringify(operand) ?? typeof operand}. ` +\n (key === \"upsert\"\n ? `'upsert' on a to-one takes { create, update } — and an optional ` +\n `'where' the connected ${child.name} has to match.`\n : `'update' on a to-one takes the ${child.name} columns directly, ` +\n `or { data } — and an optional 'where' the connected row has to ` +\n `match.`),\n );\n }\n\n const record = operand as Record<string, unknown>;\n const wrapper = key === \"upsert\" || record.data !== undefined;\n if (!wrapper) return;\n\n const known =\n key === \"upsert\" ? [\"where\", \"create\", \"update\"] : [\"where\", \"data\"];\n\n for (const name of Object.keys(record)) {\n if (record[name] === undefined || known.includes(name)) continue;\n refuse(\n `Unknown key '${name}'. '${key}' on a to-one takes ` +\n `${known.map((one) => `'${one}'`).join(\", \")} and nothing else, so ` +\n `'${name}' would be dropped rather than applied — a misspelled ` +\n `'where' would turn a filtered write into an unconditional one. ` +\n `Prisma refuses the same key by name.`,\n );\n }\n\n if (\n record.where !== undefined &&\n (record.where === null ||\n typeof record.where !== \"object\" ||\n Array.isArray(record.where))\n ) {\n refuse(\n `'where' has to be an object of filters — Prisma's is a ` +\n `'${child.name}WhereInput', which narrows *which* single row is ` +\n `written rather than choosing among several. Anything else is dropped ` +\n `by the conjunction that keeps this operand on the connected row, so ` +\n `the write would land unfiltered.`,\n );\n }\n}\n\n/**\n * A `disconnect` clears a foreign key, so the column has to be nullable.\n *\n * Prisma refuses it on a required relation at the type level; here the schema\n * is the only thing that knows, so the refusal says which column and why rather\n * than letting the database report a not-null violation from inside a nested\n * step.\n *\n * `owner` and `caller` are separate parameters because they are separate\n * questions, and one parameter answering both is what went wrong. The column\n * lives on whichever side holds the foreign key — the caller's row on a to-one,\n * the child's on a to-many — and that is what the *message* has to name. The\n * *structured* model is always the caller's. Passing `owner` for both meant a\n * `User.update` reported `model = \"Account\"` on the foreign side while the\n * owning side reported `User`, from the same function (#112).\n *\n * **Every column of the link, and the first required one is named** (#271).\n * Prisma makes a composite relation optional or required as a whole — it\n * refuses a mixture, *\"The fields of a relation must either all be optional or\n * all be required\"* — so on a schema Prisma accepted the columns agree and any\n * one of them answers. Checking all of them anyway costs nothing and means the\n * refusal does not depend on a validation rule enforced in another program:\n * a hand-built `ModelSchema` with a nullable `tenantId` beside a required\n * `ledgerCode` is refused here rather than nulling half a key.\n *\n * That is a claim about behaviour, so it is measured rather than asserted —\n * `ledgerSealMixed` in `fixtures.ts` is exactly that schema, and\n * `composite-relations.test.ts` names the column this refuses on. **The\n * nullable column is first there deliberately**: `[fieldNames[0]]` is what this\n * collapses to if the generalisation is undone, and over `(nullable, required)`\n * that answers *\"detachable\"*. The same fixture pins the two `displaces`\n * predicates, which generalised the same way and were equally unpinned.\n */\nfunction assertDisconnectable(\n owner: ModelSchema,\n relation: RelationSchema,\n fieldNames: readonly string[],\n caller: RefusalOrigin,\n): void {\n const required = fieldNames.find((name) => !owner.fields[name]?.nullable);\n if (required === undefined) return;\n\n throw new UnsupportedQueryError(\n caller.argument,\n caller.model,\n caller.operation,\n `'${owner.name}.${required}' is required, so there is no value to leave ` +\n `behind — a disconnected row would have to be deleted or repointed ` +\n `instead. Prisma does not offer 'disconnect' on a required relation ` +\n `either.`,\n );\n}\n\n/**\n * `connectOrCreate`'s operand: `{ where, create }`, or a list of them on a\n * to-many.\n *\n * Validated at plan time so a misspelled key fails when the query is compiled,\n * rather than after the parent row has been written and the transaction has to\n * unwind it — the same reason `createMany`'s operand is checked here.\n *\n * The `where` has to be a unique key, which is Prisma's rule and not merely\n * ours: without it the lookup matches an arbitrary row and \"connect or create\"\n * silently becomes \"connect to whichever one came back first\".\n */\nfunction assertConnectOrCreateOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n operation: string,\n many: boolean,\n): Record<string, unknown>[] {\n const at = `data.${relation.name}.connectOrCreate`;\n\n if (Array.isArray(operand) && !many) {\n // **Which side holds the key is read off the relation, not assumed.** This\n // sentence used to say \"this row holds the foreign key\" unconditionally,\n // which was true of the only caller that could pass `many: false` — the\n // owning side — and false the moment the foreign side stopped hardcoding\n // `true`. `from` is non-empty exactly on the side that holds the key, the\n // same test `planOne` makes to choose between the two planners, so the two\n // cannot drift.\n const owning = relation.from.length > 0;\n\n throw new InvalidArgumentError(\n at,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: ` +\n (owning\n ? `this row holds the foreign key`\n : `${child.name} holds the foreign key`) +\n `, so there is one row to point at and a list has no meaning. Prisma ` +\n `refuses an array here too — as a validation error on the argument, ` +\n `which is why this is a bad value rather than a gap.`,\n );\n }\n\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n\n if (entries.length === 0) return [];\n\n const out: Record<string, unknown>[] = [];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected an object with 'where' and 'create'.`,\n );\n }\n\n const record = entry as Record<string, unknown>;\n\n for (const required of [\"where\", \"create\"] as const) {\n if (record[required] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${required}' key — 'connectOrCreate' names the row to ` +\n `look for and the row to write if it is not there.`,\n );\n }\n }\n\n const extra = Object.keys(record).filter(\n (key) => key !== \"where\" && key !== \"create\" && record[key] !== undefined,\n );\n if (extra.length > 0) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Unexpected ${extra.sort().join(\", \")} — 'connectOrCreate' takes ` +\n `'where' and 'create'.`,\n );\n }\n\n matchUniqueKey(child, record.where, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.connectOrCreate.where`,\n });\n out.push(record);\n }\n\n return out;\n}\n\n/**\n * `createMany`'s operand is `{ data }` — not the rows directly, which is the\n * one place Prisma's nested grammar adds a level.\n *\n * Checked at plan time, so a misspelled key fails when the query is compiled\n * rather than after the parent row has already been written and the transaction\n * has to unwind it.\n */\nfunction assertCreateManyOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n operand: unknown,\n operation: string,\n): void {\n const at = `data.${relation.name}.createMany`;\n\n if (typeof operand !== \"object\" || operand === null || Array.isArray(operand)) {\n throw new InvalidArgumentError(\n at,\n schema.name,\n operation,\n `Expected an object with a 'data' key — the rows go inside it, not ` +\n `directly under 'createMany'.`,\n );\n }\n\n const keys = Object.keys(operand as Record<string, unknown>).filter(\n (key) => (operand as Record<string, unknown>)[key] !== undefined,\n );\n\n if (!keys.includes(\"data\")) {\n throw new InvalidArgumentError(at, schema.name, operation, `Expected a 'data' key.`);\n }\n\n for (const key of keys) {\n if (key === \"data\") continue;\n\n // `skipDuplicates` is the one a caller will actually reach for, so it gets\n // the reason instead of the generic message.\n //\n // **Scoped to the nested form on purpose.** This used to say \"at any\n // level\", which was true when it was written and stops being true the\n // moment #69 lands: a top-level `Account.createMany({ data, skipDuplicates\n // })` compiles to `on conflict do nothing` on Postgres. Naming the level\n // keeps the sentence true either way, and points at the spelling that\n // works today rather than at a wait.\n //\n // Whether the nested form should simply pass it through is a real question\n // and not this change's: the step below already calls the child's own\n // `$exec(\"createMany\", …)`, so forwarding the flag is close to free — but\n // it would need the top-level support to exist first, and until then it\n // would fail with an error about an unknown argument on a model the caller\n // did not name.\n throw new UnsupportedQueryError(\n `${at}.${key}`,\n schema.name,\n operation,\n key === \"skipDuplicates\"\n ? `'skipDuplicates' is not implemented on a *nested* 'createMany'. ` +\n `Write the children with their own '${relation.model}.createMany' ` +\n `call, which takes it.`\n : `Expected only 'data'.`,\n );\n }\n}\n\n/**\n * Prisma accepts both a single object and an array everywhere a to-many nested\n * write is legal, and the singular form is the common one on a to-one.\n */\nfunction listOf(value: unknown): unknown[] {\n if (value === undefined || value === null) return [];\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * A to-one nested-write operand, rewritten in the spelling the to-many bodies\n * above already read.\n *\n * **Prisma's to-one nested input is a different grammar, not a subset of the\n * to-many one** — quoted from a generated client rather than from the docs\n * (`ProfileUpdateOneWithoutUserNestedInput`):\n *\n * update XOR<UpdateToOneWithWhereWithoutUserInput, UpdateWithoutUserInput>\n * where UpdateToOneWithWhereWithoutUserInput = { where?, data }\n * upsert { update, create, where? }\n * disconnect ProfileWhereInput | boolean\n * delete ProfileWhereInput | boolean\n * connect ProfileWhereUniqueInput\n *\n * Three of those differences would be got wrong by reading the to-many side and\n * assuming symmetry, so each is named with the measurement behind it:\n *\n * - **the `where` is optional, and it is a filter.** Not a unique key —\n * `WhereInput`, not `WhereUniqueInput` — which is why `assertToOneFilter`\n * replaces `assertNamedRows` here and `matchUniqueKey` does not run.\n * Measured: `delete: { bio: \"seed\" }` is accepted against a column with no\n * unique index and deletes the connected row.\n * - **the data may be written bare.** `update: { bio: \"x\" }` and\n * `update: { data: { bio: \"x\" } }` are one operation. The owning side\n * measured that years ago; this is the same measurement repeated on the\n * foreign side, because the owning side's said nothing about this one.\n * - **the boolean is not an empty filter.** `true` means the connected row;\n * `false` means *nothing at all*, measured — `delete: false` and\n * `disconnect: false` with a child present return the parent and leave the\n * child exactly as it was, foreign key included.\n *\n * So `true` becomes `{}`, which `conjoin` reduces to the parent link alone —\n * precisely the one connected row — and `false` becomes `null`, which `listOf`\n * reduces to `[]`, which is no statement.\n */\nfunction toOneOperand(key: string, operand: unknown): unknown {\n if (key === \"update\") {\n // A `data` key is the wrapper; anything else is the payload itself. The\n // same test `planOwningSide`'s `update` makes, deliberately — the two\n // spellings collapse to one operation, so the compiler should not have two\n // shapes of its own for them. It carries the same ambiguity, too: a child\n // with a scalar column called `data` would be read as the wrapper. Prisma's\n // own input types have that hazard by construction and it has never been\n // reachable in practice, so it is inherited rather than invented.\n //\n // **`!== undefined` rather than `in`**, and the difference is a plan-cache\n // bug rather than a style choice. `canonicalShape` drops a key whose value\n // is `undefined` (see its object branch), so `update: {}` and `update: {\n // data: undefined }` are ONE plan key. Branching on `in` gave them two\n // compilations: the first normalised and compiled, the second reached\n // `assertNamedUpdates` and was refused for a missing `data` — so whether\n // the refusal fired depended on which spelling warmed the cache. Testing\n // the value instead is what `assertNamedUpdates` itself does, one operand\n // over, and it puts both spellings on the same branch.\n //\n // This is the same defect as the `disconnect` boolean two functions down,\n // arrived at from the opposite direction: there the key was too coarse for\n // the code, here the code was finer than the key. Both are decided by\n // asking what `canonicalShape` actually records.\n if (\n operand !== null &&\n typeof operand === \"object\" &&\n (operand as Record<string, unknown>).data !== undefined\n ) {\n const record = operand as Record<string, unknown>;\n return { where: record.where, data: record.data };\n }\n return { where: undefined, data: operand };\n }\n\n if (key === \"delete\" || key === \"disconnect\") {\n if (operand === true) return {};\n if (operand === false) return null;\n return operand;\n }\n\n // `upsert` already arrives as `{ where?, create, update }`, and `create`,\n // `connect` and `connectOrCreate` are already singular. Returned untouched\n // rather than listed, so an operand added later does not silently acquire a\n // translation it was never measured for.\n return operand;\n}\n",
19
+ "import {\n InvalidArgumentError,\n RecordNotFoundError,\n UnsupportedQueryError,\n} from \"../errors\";\nimport type { SqlDialect } from \"../dialect\";\nimport type { ModelSchema, RelationSchema } from \"../schema\";\nimport type { Binder } from \"./fragment\";\nimport {\n type Link,\n type NestedWriteStep,\n type RelationExecutor,\n relatedSchema,\n resolveLink,\n singleFieldLink,\n} from \"./plan-relations\";\nimport { matchUniqueKey, type RefusalOrigin } from \"./unique\";\n\n/**\n * Nested writes: `connect`, `connectOrCreate`, shallow `create`, and\n * `createMany`.\n *\n * Which direction a nested write runs in is decided by *who holds the foreign\n * key*, and the two directions are genuinely different operations:\n *\n * ```ts\n * // this model holds organizationId — resolve the key, then insert once\n * User.create({ data: { email, organization: { connect: { id: 1 } } } })\n *\n * // Account holds userId — insert the user, then insert accounts pointing at it\n * User.create({ data: { email, accounts: { create: [{ ... }] } } })\n * ```\n *\n * The first is a `before` step (or, in the common case, no step at all — just a\n * column read straight out of the argument tree). The second is an `after` step,\n * because the key it needs does not exist until the parent row does.\n *\n * `createMany` is the second shape and only exists on the foreign side: the same\n * rows as a nested `create`, in one statement rather than one per row.\n *\n * The rest of Prisma's nested-write grammar — `set`, `disconnect`, `update`,\n * `upsert`, `delete`, `deleteMany`, `updateMany` — is implemented too, and this\n * paragraph used to say that all seven throw. What is left refused is refused\n * by *shape* rather than by name, at the site that knows why: the four\n * collection operands on a to-one, which Prisma's to-one input does not carry\n * either; `delete` through a key on this row, which would remove a row the\n * statement is not about (#391 left it the only one of the seven still refused\n * on that side); everything in {@link EXISTING_ROW_ONLY_STATEMENTS} under a\n * `create`; and the four that reach the far row *through* an implicit\n * many-to-many's pairs. `REFUSED` — the table this sentence pointed at — is\n * empty, and its docblock says why that is worth reading.\n *\n * **The line this file draws has two halves: which rows an operand can name,\n * and whose columns it writes.**\n *\n * Every supported operand names its rows — a new one, or an existing one the\n * caller identified by unique key — so it goes through the child's own\n * `findUnique`, `create` or `update`, and the child's policies decide whether\n * it is reachable at all. `set`, `disconnect`, `delete`, `deleteMany` and\n * `updateMany` act on rows the *call* did not name, and \"whatever is there\" has\n * no lookup to hang a scope on.\n *\n * `update` is the operand that shows the second half is needed, because it\n * *does* name its row: `update: { where, data }`. It is refused because of what\n * it writes — caller-supplied columns, which need the child's `onUpdate` and\n * the scope-escape guard run over the payload. Every supported operand writes\n * either a whole new row through the child's `create` (where `onCreate`\n * applies) or one foreign key the ORM itself chose.\n *\n * This used to say the line was \"each writes rows that **already exist**\", and\n * that was true until `connectOrCreate` arrived: on the foreign side a hit is\n * an `update` of the child's foreign key, because Prisma repoints the existing\n * row rather than duplicating it. So a supported operand does now write a row\n * that was already there. Restated rather than deleted, because the criterion\n * is what the next operand gets judged against — #75 built the whole `REFUSED`\n * table on it, with a per-entry reason derived from it, and #83's `set` on an\n * implicit many-to-many was fixed by exactly this reading: scope the delete to\n * the rows the caller can see. A stale criterion is worse than none, because it\n * is the one the next reader applies.\n *\n * Atomic since iteration 5: `$exec` opens a transaction for any plan carrying\n * steps, so a nested step that fails — or a child policy that denies — rolls\n * back the parent row too.\n */\n\nconst SUPPORTED_STATEMENTS = [\n \"connect\",\n \"connectOrCreate\",\n \"create\",\n \"createMany\",\n \"disconnect\",\n \"delete\",\n \"update\",\n \"set\",\n \"updateMany\",\n \"deleteMany\",\n \"upsert\",\n] as const;\n\n/**\n * One of {@link SUPPORTED_STATEMENTS}.\n *\n * `NestedCreate` and `NestedUpdate` in `../types` are mapped types over this\n * and the two tuples below, rather than four hand-written key lists in another\n * file. Which statements exist, and which exist only on a to-many or only on a\n * statement with a row to act on, are decisions made *here* — and until #369\n * the caller-facing type made them a second time, with nothing checking that\n * the two answers matched.\n */\nexport type NestedWriteStatement = (typeof SUPPORTED_STATEMENTS)[number];\n\nconst SUPPORTED: ReadonlySet<string> = new Set(SUPPORTED_STATEMENTS);\n\n/**\n * Operands that only exist on a statement with a row to act on.\n *\n * Prisma refuses `disconnect` and `delete` under a `create` — *\"Unknown\n * argument `disconnect`\"* — and it is right to: there is nothing linked to a\n * row that does not exist yet. Refused here rather than accepted and made a\n * no-op, so a caller who wrote one on the wrong operation hears about it.\n */\nconst EXISTING_ROW_ONLY_STATEMENTS = [\n \"disconnect\",\n \"delete\",\n \"update\",\n \"set\",\n \"updateMany\",\n \"deleteMany\",\n \"upsert\",\n] as const;\n\n/** One of {@link EXISTING_ROW_ONLY_STATEMENTS}. `NestedCreate` subtracts it. */\nexport type ExistingRowStatement = (typeof EXISTING_ROW_ONLY_STATEMENTS)[number];\n\nconst EXISTING_ROW_ONLY: ReadonlySet<string> = new Set(\n EXISTING_ROW_ONLY_STATEMENTS,\n);\n\n/**\n * The operands that describe *many* rows, and so exist on a to-many alone.\n *\n * Prisma's to-one nested input is `{ create, connectOrCreate, upsert,\n * disconnect, delete, connect, update }` — measured off a generated client —\n * with no `createMany`, `set`, `updateMany` or `deleteMany` key at all. Both\n * {@link planOwningSide} and {@link planForeignSide} refuse all four on a\n * to-one; this is the list they refuse, named once so the type can subtract it.\n */\nconst COLLECTION_ONLY_STATEMENTS = [\n \"createMany\",\n \"set\",\n \"updateMany\",\n \"deleteMany\",\n] as const;\n\n/** One of {@link COLLECTION_ONLY_STATEMENTS}. The to-one arms subtract it. */\nexport type CollectionOnlyStatement = (typeof COLLECTION_ONLY_STATEMENTS)[number];\n\n/**\n * The three of the four that share one refusal message.\n *\n * `createMany` is excluded because it is refused on its own, in both planners,\n * with a message about there being *one related row* rather than about there\n * being no *set of rows* — and on the foreign side that refusal also guards the\n * operand check that follows it. Derived by subtraction rather than written out\n * again, so a fifth collection-shaped operand added above lands here too.\n */\nconst NO_SET_OF_ROWS: ReadonlySet<string> = new Set(\n COLLECTION_ONLY_STATEMENTS.filter((statement) => statement !== \"createMany\"),\n);\n\n/** Statements that insert a new row, so nothing is linked to it yet. */\nconst CREATE_ONLY_STATEMENTS = new Set([\"create\", \"createMany\"]);\n\n/**\n * The operands still refused, and what each would take.\n *\n * Named individually rather than covered by one message, because \"not\n * implemented\" is much less useful than knowing whether the thing you reached\n * for is a rewrite or a wait. Each of these is a *write to rows that already\n * exist*, which is the line: everything supported writes new rows or repoints a\n * key, and none of it has to reason about what was there before.\n */\n/**\n * Nothing, now — and that is the point of leaving the table here.\n *\n * Every entry it once held described machinery that turned out to exist one\n * layer down: five of them said a pass was missing that the child's own\n * `$exec` already runs, and the sixth — `upsert`'s — said the branch could not\n * be decided from inside a nested step, when `connectOrCreate` had been\n * deciding one the same way since #94.\n *\n * Kept rather than deleted because the next operand added here should have to\n * write its reason down, and because a reason naming *machinery* is checkable\n * where one naming a *principle* is not. That distinction is the only thing\n * that made six stale entries findable.\n */\nconst REFUSED: Record<string, string> = {};\n\n/** A foreign-key column on *this* model that a nested write supplies. */\nexport interface ForeignKeyContribution {\n /** The field name on this model — `organizationId`. */\n field: string;\n /** Produces the value at bind time, already unencoded. */\n value: Binder;\n}\n\nexport interface NestedWritePlanning {\n contributions: ForeignKeyContribution[];\n before: NestedWriteStep[];\n after: NestedWriteStep[];\n /**\n * Fields of *this* model that the statement must return, because an `after`\n * step needs them to point its children at this row.\n */\n keyFields: string[];\n}\n\nconst EMPTY: NestedWritePlanning = {\n contributions: [],\n before: [],\n after: [],\n keyFields: [],\n};\n\nexport function planNestedWrites(\n schema: ModelSchema,\n data: unknown,\n operation: string,\n /** Re-locates `data` inside the call's argument tree at bind time. */\n locateData: (args: any) => any,\n /**\n * Needed only by the implicit many-to-many path, which emits statements\n * against a table with no model and therefore has no `Fragment` pipeline to\n * number its placeholders — SQLite writes `?` and Postgres `$1`.\n */\n dialect: SqlDialect,\n): NestedWritePlanning {\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) {\n return EMPTY;\n }\n\n const entries = Object.keys(data as Record<string, unknown>)\n .sort()\n .filter((key) => key in schema.relations)\n .filter((key) => (data as Record<string, unknown>)[key] !== undefined);\n\n if (entries.length === 0) return EMPTY;\n\n const planning: NestedWritePlanning = {\n contributions: [],\n before: [],\n after: [],\n keyFields: [],\n };\n\n /** Which relation contributed each foreign-key column, for the guard below. */\n const contributedBy = new Map<string, string>();\n\n for (const key of entries) {\n const relation = schema.relations[key];\n const node = (data as Record<string, unknown>)[key];\n const locate = (args: any) => locateData(args)?.[key];\n const before = planning.contributions.length;\n\n planOne(schema, relation, node, operation, locate, planning, dialect);\n\n // **Two relations that share a foreign-key column are refused by name**\n // (#271). A composite relation joins on *n* columns and nothing stops two\n // of them from sharing one — it is the tenant-scoped shape this whole\n // change is about:\n //\n // ledger Ledger @relation(fields: [tenantId, ledgerCode], …)\n // note Ledger @relation(fields: [tenantId, noteCode], …)\n //\n // `prisma validate` accepts that on 6.19.2, and before #271 both relations\n // were refused here for their width, so writing through both at once was\n // unreachable. It is reachable now, and the two `tenantId` contributions\n // collide: `insertColumns` folds contributions through a `Map` keyed by\n // field, so the later one wins, and `entries` above is sorted, so the\n // winner is whichever relation sorts last.\n //\n // **Prisma resolves the operands in the opposite direction and lets the\n // first resolved win, so the caller's last `data` key decides the shared\n // column** — measured on 6.19.2 with query events on: writing\n // `{ note: connect(2,\"b\"), ledger: connect(1,\"a\") }` stores `tenantId=1`\n // where `{ ledger: …, note: … }` stores `2`. gemi stores `2` either way.\n //\n // Matching that would mean giving up the sorted key order, which the plan\n // cache needs — two argument objects differing only in key order have to\n // be one plan. So this refuses instead, which is what the width refusal\n // this change replaced was buying: no plausible wrong row. A caller who\n // wants both links connects through one relation — which writes the shared\n // column — and sets the other relation's remaining columns directly, since\n // `insertColumns` only refuses a column that is written *both* ways.\n for (let index = before; index < planning.contributions.length; index++) {\n const field = planning.contributions[index].field;\n const owner = contributedBy.get(field);\n if (owner !== undefined && owner !== key) {\n throw new UnsupportedQueryError(\n `data.${key}`,\n schema.name,\n operation,\n `'${field}' is written by both the '${owner}' and '${key}' relations, ` +\n `which join on it in common. Prisma lets the last key in 'data' win; ` +\n `gemi plans relations in a fixed order and will not guess which row ` +\n `you meant. Write one of them through the relation and set the ` +\n `other's own columns directly.`,\n );\n }\n contributedBy.set(field, key);\n }\n }\n\n return planning;\n}\n\nfunction planOne(\n schema: ModelSchema,\n relation: RelationSchema,\n node: unknown,\n operation: string,\n locate: (args: any) => any,\n out: NestedWritePlanning,\n dialect: SqlDialect,\n): void {\n if (typeof node !== \"object\" || node === null || Array.isArray(node)) {\n throw new InvalidArgumentError(\n `data.${relation.name}`,\n schema.name,\n operation,\n \"Expected an object holding 'connect' or 'create'.\",\n );\n }\n\n // Sorted, and it is load-bearing twice over. The plan cache needs it — two\n // argument objects differing only in key order must be one plan — and the\n // *order the steps run in* falls out of it, because they are pushed in this\n // order and run in that order.\n //\n // Only one pair is order-sensitive today, and it happens to sort the right\n // way: `create` before `createMany` is what Prisma does, verified from the\n // ids it hands back. `connect` before `createMany` is the other pair and its\n // order is not observable — repointing an existing child and inserting new\n // ones do not interact — but it is pinned by a differential case rather than\n // left to be rediscovered.\n //\n // So: this is a coincidence that is currently correct. An operand added here\n // whose order *is* observable cannot rely on the alphabet and has to sequence\n // itself explicitly.\n const keys = Object.keys(node as Record<string, unknown>)\n .sort()\n .filter((key) => (node as Record<string, unknown>)[key] !== undefined);\n\n if (keys.length === 0) return;\n\n const child = relatedSchema(schema, relation);\n\n // **Every joined field, not the first one** (#271).\n //\n // This used to be `singleFieldLink(resolveLink(…))`: reading across\n // `@relation(fields: [tenantId, orderId], references: [tenantId, id])` was\n // implemented by #67 on all six read surfaces, and the write surface refused\n // it by name rather than joining on the first field and writing plausible\n // wrong rows. The refusal was honest and it was the only thing left on that\n // list, so the narrowing is gone and what follows contributes *n* foreign-key\n // columns wherever it used to contribute one.\n //\n // Nothing here branches on how many there are. The two sides read the link\n // through {@link childLink}, {@link keySelect} and {@link nullKey}, which are\n // the same three shapes for one field as for four — so a relation joining on\n // one field compiles to exactly the arguments it did before, and there is no\n // single-field path left to diverge from the composite one.\n const link = resolveLink(schema, child, relation, operation);\n\n // An implicit many-to-many is *neither* side: the keys live in a third table\n // with no model, so both directions are the same work and the operand set is\n // wider — `disconnect` and `set` are a delete against the join table, which\n // needs no schema to compile.\n if (link.join) {\n // **The one caller that still cannot take more than one field**, and it is\n // an invariant rather than a gap: Prisma's implicit many-to-many links\n // parent and child by their *primary keys*, one column each side, into a\n // two-column join table there is no schema to widen. `singleFieldLink`\n // states that rather than letting `planJoinTable` index into `[0]` and be\n // silently wrong if it ever stopped holding.\n const pair = singleFieldLink(link, schema, relation, operation);\n\n for (const key of keys) {\n planJoinTable(\n schema,\n relation,\n child,\n pair,\n key,\n (node as Record<string, unknown>)[key],\n operation,\n (args: any) => locate(args)?.[key],\n out,\n dialect,\n );\n }\n return;\n }\n\n for (const key of keys) {\n if (!SUPPORTED.has(key)) {\n const why = REFUSED[key];\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `Only ${[...SUPPORTED].sort().join(\", \")} are implemented.` +\n (why ? ` '${key}' is not: ${why}` : \"\"),\n );\n }\n\n // `create` has no row to disconnect from, and Prisma does not offer these\n // there either — it reports them as an unknown argument.\n if (EXISTING_ROW_ONLY.has(key) && CREATE_ONLY_STATEMENTS.has(operation)) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${key}' acts on rows already linked to this one, and a '${operation}' ` +\n `has none yet — Prisma refuses it here too. Use it on an 'update'.`,\n );\n }\n }\n\n // `from` is non-empty exactly on the side that holds the foreign key.\n const owning = relation.from.length > 0;\n\n for (const key of keys) {\n const operand = (node as Record<string, unknown>)[key];\n const at = (args: any) => locate(args)?.[key];\n\n if (owning) {\n planOwningSide(\n schema,\n relation,\n child,\n link,\n key,\n operand,\n operation,\n at,\n out,\n );\n } else {\n planForeignSide(\n schema,\n relation,\n child,\n link,\n key,\n operand,\n operation,\n at,\n out,\n );\n }\n }\n}\n\n/**\n * This model holds the foreign key, so the far row must exist — or be created —\n * before the insert can bind, and the whole thing collapses to *n* extra\n * columns — one, in the ordinary schema; as many as the relation joins on in a\n * tenant-scoped one (#271).\n *\n * **The columns are contributed to the statement the caller already asked for,\n * which is what makes a composite key here atomic without arranging anything.**\n * `contributions` is a list keyed by field, and `insertColumns` /\n * `updateAssignments` fold every entry into the single `INSERT` or `UPDATE`\n * this operation compiles to — so \"some keys written, some not\" is not a state\n * this side can reach: the `before` step either resolves the whole tuple or\n * throws, and the statement either runs or does not. The partial-write hazard\n * is real on the *foreign* side, where each linked row is its own statement,\n * and it is answered there by the transaction every plan carrying steps opens.\n */\nfunction planOwningSide(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n link: Link,\n key: string,\n operand: unknown,\n operation: string,\n at: (args: any) => any,\n out: NestedWritePlanning,\n): void {\n // `parentFields` are the FK columns on this model; `childFields` are what\n // they reference on the other one, paired positionally.\n const fkFields = link.parentFields;\n const referencedFields = link.childFields;\n\n /** Assign the resolved key onto the statement — one contribution per column. */\n const contributeResolved = () => {\n for (const field of fkFields) {\n out.contributions.push({\n field,\n value: (_args, context) => context.resolved[field],\n });\n }\n };\n\n /** Record a whole key on the plan's per-call scratch space. */\n const resolveKey = (\n context: { resolved: Record<string, unknown> },\n values: readonly unknown[],\n ) => {\n for (let index = 0; index < fkFields.length; index++) {\n context.resolved[fkFields[index]] = values[index] ?? null;\n }\n };\n\n /**\n * **Whether linking through this relation has to displace a sibling** — the\n * one-to-one case, where this row's foreign key carries the `@unique` that\n * makes the far row hold one partner, so pointing at an occupied one is a\n * collision rather than a second link (#363).\n *\n * **It takes both halves: the unique index *and* the far side's `kind`.** The\n * first draft of this used the index alone, on the argument that\n * `planForeignSide`'s `relation.kind` test and this one were \"the same\n * predicate, two spellings\". They are not, and the difference is a silent\n * destructive write rather than a wording problem.\n *\n * The implication holds one way only. P1012 gives *`kind !== \"many\"` implies\n * the key is unique* — Prisma will not let a non-list back-relation exist\n * beside a foreign key with no `@unique`. **The converse is false.** A\n * `@unique` foreign key beside a *list* back-relation is a schema Prisma\n * accepts:\n *\n * model Team { id Int @id players Player[] }\n * model Player { id Int @id teamId Int? @unique\n * team Team? @relation(fields: [teamId], references: [id]) }\n *\n * `prisma validate` on that is *\"The schema at b.prisma is valid\"* — measured,\n * not assumed. And the index alone would have displaced there, where Prisma\n * does not: `Player.update({ where: { id: 2 }, data: { team: { connect:\n * { id: 2 } } } })` with player 1 already on team 2 answers **P2002** and its\n * whole statement log is `SELECT Team.id`, the `UPDATE`, `ROLLBACK` — the\n * sibling is never even read. Against the same key with `keeper Keeper?` in\n * place of `players Player[]`, the identical call displaces and the log gains\n * the incumbent `SELECT` and its clear. So the *back-relation* is what\n * decides, and the index is a necessary condition rather than the answer.\n *\n * It is not an exotic shape either: a `@unique` added to a foreign key for\n * indexing, or a one-to-many half-migrated to a one-to-one, both land on it.\n * Without the second half gemi's two ends disagreed about one relation — the\n * foreign side saw `kind === \"many\"` and refused to displace, this side saw\n * the index and did.\n *\n * So `relation.kind` is still not readable from here — it says `\"one\"` for a\n * many-to-one and a one-to-one alike, because both point at a single far row,\n * which is the part of the original argument that survives. The question goes\n * to the *child's* copy of the relation instead, found by `relationName`, and\n * `uniques` narrows it rather than answering it.\n *\n * **A back-relation that cannot be identified does not displace.** Absent or\n * ambiguous, the answer is unknown, and of the two ways to be wrong only one\n * writes to a row nobody named — so the fallback is the collision this\n * operand raised before #363, which is also what a schema too malformed to\n * read should get. The self-relation exclusion is `otherSide`'s, restated\n * rather than shared because that function *throws* on the same condition and\n * has never run on this path: turning a schema that compiled yesterday into a\n * hard error is not this issue's to do.\n *\n * Nullable, for the same reason the foreign side is: a detach has to leave a\n * value behind. A required foreign key cannot be nulled, so the repoint\n * collides as it always did. That is not what Prisma answers — it refuses\n * ahead of the write with P2014, *\"The change you are trying to make would\n * violate the required relation\"*, measured on a scratch schema, since this\n * one carries no required one-to-one for a case to reach. Recorded rather\n * than matched: it is a divergence in the failure's *class* on a call that\n * fails either way, where every other line of this is about a call that\n * succeeds. `assertDisconnectable` is deliberately not called, exactly as on\n * the foreign side: it would refuse the whole operand, including the\n * empty-far-row case that has always worked.\n *\n * **An index over exactly the relation's own fields**, which is what the\n * single-field test used to say and reads differently now that there may be\n * several (#271). Prisma's rule is on the relation: *\"A one-to-one relation\n * must use unique fields on the defining side\"*, meaning `fields` — so\n * `@@unique([tenantId, ownerId])` beside `@relation(fields: [tenantId,\n * ownerId], …)` is the composite one-to-one, and it is the same fact the\n * single-column form was stating.\n *\n * **Both halves of that rule are Prisma's, measured on 6.19.2 rather than\n * inferred**, because between them they are the whole discriminator:\n *\n * @@unique([tenantId, ledgerCode]) accepted — the one-to-one\n * @@unique([tenantId, ledgerCode, seal]) P1012, \"Either add an\n * `@@unique([tenantId,\n * ledgerCode])` attribute\"\n * @@unique([ledgerCode, tenantId]) the identical P1012\n *\n * So a wider group does *not* make the relation one-to-one — reading it as\n * one would clear rows the schema never said were exclusive — and the order\n * has to match the relation's `fields` as well.\n *\n * Written as set equality all the same, and the second row is why that is not\n * laxity: the length check is what carries the weight, and a positional loop\n * would read as though order were a thing this had decided, when on any\n * schema Prisma accepted the two lists are already identical. It also keeps a\n * hand-built `ModelSchema` — a fixture, or a generator that reorders — out of\n * the branch where the index is not recognised at all.\n *\n * A foreign key that is also the `@id` would not be found in `uniques`, which\n * records `@unique` and `@@unique` rather than the primary key; it is out of\n * reach anyway, since `@id` implies `NOT NULL` and the nullable guard has\n * already excluded it.\n */\n const backRelations = Object.values(child.relations).filter(\n (candidate) =>\n candidate.relationName === relation.relationName &&\n // A self-relation names the same model on both ends, so the *field* is\n // what distinguishes them — `otherSide`'s test, and without it a\n // self-referencing one-to-many would find its own owning side here,\n // read `kind: \"one\"` off it and displace.\n !(child.name === schema.name && candidate.name === relation.name),\n );\n\n const keyed = new Set(fkFields);\n\n const displaces =\n fkFields.every((field) => schema.fields[field]?.nullable === true) &&\n schema.uniques.some(\n (unique) =>\n unique.length === keyed.size && unique.every((name) => keyed.has(name)),\n ) &&\n backRelations.length === 1 &&\n backRelations[0].kind !== \"many\";\n\n /**\n * Whether there is a row to displace *from* — false under a `create`, where\n * this row does not exist yet, so nothing it holds can be the incumbent.\n */\n const existing = !CREATE_ONLY_STATEMENTS.has(operation);\n\n // This side is a to-one by construction — it holds a single foreign key — so\n // there is nothing for a `createMany` to write many of. Prisma does not offer\n // it here either; refused with the reason rather than the grammar, because a\n // caller who reached for it has the direction of the relation wrong.\n // The *other* half of this refusal is in `planForeignSide`, which reaches the\n // same conclusion from the far side of the key: a one-to-one whose child\n // holds the foreign key is still a to-one. Both are reachable and neither\n // subsumes the other, so the message is duplicated rather than shared.\n if (key === \"createMany\") {\n throw new UnsupportedQueryError(\n `data.${relation.name}.createMany`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: this row holds the foreign key, so ` +\n `there is one related row at most and nothing to create many of. ` +\n `Prisma does not accept it here either.`,\n );\n }\n\n if (key === \"create\") {\n // The far row does not exist yet: create it first, through its own model's\n // `$exec` so it is subject to everything a top-level create is (invariant 1).\n out.before.push({\n relation: relation.name,\n operation: \"create\",\n async run(args, context, executor) {\n const created = (await executor.exec(\n relation.model,\n \"create\",\n { data: at(args), select: keySelect(referencedFields) },\n // NOT pre-scoped. Nothing walks `data.<relation>.create`, so the\n // child's own `onCreate` is the only thing that can scope this row.\n false,\n )) as Record<string, unknown> | null;\n\n resolveKey(context, valuesOf(created, referencedFields));\n },\n });\n contributeResolved();\n return;\n }\n\n /**\n * `connectOrCreate` — find the row by a unique key, and create it only if it\n * is not there.\n *\n * **A hit ignores `create` entirely**, which is not what the name suggests\n * and is worth pinning: it is `connect`-or-create, not upsert. Measured — an\n * existing organisation kept its own name where the `create` payload named a\n * different one.\n *\n * `findUnique`, not `findUniqueOrThrow`: a miss is the *other branch* here,\n * where for a plain `connect` it is an error.\n *\n * Object only on this side. The relation holds one foreign key, so there is\n * one row to point at, and Prisma refuses an array here too.\n */\n /**\n * `disconnect` on a to-one whose key is on **this** row — the same three arms\n * the foreign side takes, through the same two helpers (#359).\n *\n * Prisma's operand here is `XWhereInput | boolean`, read off the generated\n * client and measured against it:\n *\n * disconnect: true clears the link\n * disconnect: false nothing happens, the link survives\n * disconnect: {} clears it — the empty filter matches\n * disconnect: { name: \"Ada\" } clears it only if the linked row matches\n * disconnect: { name: \"Grace\" } no match, so nothing happens — and\n * **silently**, not P2025\n * disconnect: <filter>, nothing linked silently nothing\n *\n * The silence in the last two is what makes the filter arm a *conditional*\n * detach rather than a guarded one: there is no miss to report, which is the\n * same asymmetry the foreign side measured between `disconnect` and `delete`\n * (M8c). So the arms differ only in what decides the value of one column.\n *\n * **The boolean is structural here, where the foreign side re-reads it at\n * bind time**, and that difference is forced rather than chosen. The foreign\n * side's operands are *statements* — `listOf(null)` is no statement — so a\n * plan handed the wrong boolean can still write nothing. This side's is a\n * *column in the SET list*: `false` emits no assignment and `true` emits one,\n * so the two spellings cannot share a statement text and no bind-time check\n * could rescue a cache hit that got it wrong. What makes that sound is\n * `shapeOfMember`'s guard (#358), which gives a `disconnect` boolean its own\n * plan key precisely because this decision is made once, at compile time.\n * Before it, a plan compiled from `true` served `false` and nulled a foreign\n * key on a call that asked for nothing.\n *\n * `delete` has no meaning here for the same reason it has no `createMany`:\n * this side is a to-one, and deleting the far row through a `data` key would\n * be deleting a row the statement is not about. Prisma does offer it; it is\n * refused rather than guessed, because a `delete` that fires as a side effect\n * of an unrelated update is the kind of thing to implement deliberately.\n */\n if (key === \"disconnect\") {\n // Before the arms, so a required foreign key is refused whichever one was\n // spelled — including `false`, which asks for nothing and still cannot be\n // written. Prisma agrees for a reason of its own: it leaves `disconnect`\n // out of the input type entirely when the relation is required, so\n // `disconnect: false` there is *\"Unknown argument `disconnect`\"* rather\n // than an accepted no-op. Measured on `SocialAccount.user`.\n assertDisconnectable(schema, relation, fkFields, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.disconnect`,\n });\n\n // `true` -> `{}`, `false` -> `null`, a filter passes through: the same\n // translation and the same shape check the foreign side runs, reused rather\n // than restated so the two sides cannot answer one grammar differently\n // again — which is the defect #359 was filed for.\n //\n // The check goes **first**, on the operand as written: the translation is\n // lossy in the one direction that matters, since it maps `false` onto the\n // same `null` a caller may have spelled outright. See `assertToOneFilter`.\n assertToOneFilter(schema, relation, child, operand, key, operation);\n const filter = toOneOperand(key, operand);\n\n // `false` — no contribution and no step, so the operand contributes\n // *nothing at all*: a `data` carrying only this compiles to the read\n // `compileUpdate` emits for an empty assignment list, and the row comes\n // back with its link intact. That is Prisma's answer, and the reason the\n // differential asserts it by value: what this replaces was a write.\n if (filter === null || filter === undefined) return;\n\n /**\n * `true` — the link's columns bound to `null`, exactly as `connect`'s\n * direct form binds them to a value. No step, nothing on the child read or\n * written, and so no scoping question: the row being changed is the one the\n * statement already names.\n */\n if (operand === true) {\n for (const field of fkFields) {\n out.contributions.push({ field, value: () => null });\n }\n return;\n }\n\n /**\n * A filter — detach only if the row this one points at matches it.\n *\n * Two reads, and neither is avoidable from this side. The condition is a\n * property of the *linked* row, and which row that is lives in a column of\n * the row being updated, which the arguments do not carry — so the parent\n * is read first and the child second. The far side needs neither: its\n * filter goes straight into the `where` of the `updateMany` that clears the\n * key, because there the key is on the row being filtered.\n *\n * **The child read goes through the child's own `$exec`, un-pre-scoped**,\n * which is what puts this operand on the supported side of this file's\n * line. A `disconnect` that acts on \"whatever is there\" has no lookup to\n * hang a scope on; this one has, so a child the caller's policies hide\n * reads as absent and the link survives — the same conservative answer\n * `set` gives, and the same one the foreign side's `disconnect` gives for a\n * hidden row.\n *\n * The parent read is **pre-scoped**: `args.where` is the effective `where`\n * this call already put through this model's policies, so re-applying them\n * would `AND` the same predicate twice. It reads one column of one row —\n * `update` matched its `where` against a unique key — inside the\n * transaction the nested steps already run in, so the value it returns is\n * the one the statement below is about to write over.\n */\n out.before.push({\n relation: relation.name,\n operation: \"disconnect\",\n async run(args, context, executor) {\n // Default to the values that are already there, so a filter that\n // matches nothing writes the columns back unchanged. The contributions\n // are in the SET list either way — the statement's text cannot depend\n // on a value read at bind time — so \"nothing happens\" has to be spelled\n // as assignments that change nothing rather than as absent ones.\n resolveKey(context, nullsFor(fkFields));\n\n const parent = (await executor.exec(\n schema.name,\n \"findFirst\",\n { where: args?.where, select: keySelect(fkFields) },\n true,\n )) as Record<string, unknown> | null;\n\n const linked = valuesOf(parent, fkFields);\n // Nothing linked: no row for the filter to match, and Prisma is silent\n // about it. `null` is already what the columns hold. A *partially*\n // written composite key lands here too, and that is the right answer —\n // it joins to no row, so no filter can match through it.\n if (!isLinked(linked)) return;\n\n resolveKey(context, linked);\n\n const matched = await executor.exec(\n relation.model,\n \"findFirst\",\n {\n // `AND`, not a spread: a filter naming a referenced column itself\n // must narrow rather than replace the restriction that keeps this\n // on the linked row. Same rule as everywhere else here.\n // `link` reads the same way on this side: its `parentFields` are\n // this row's foreign key and its `childFields` are what they\n // reference, so `childLink` yields the far row's own columns bound\n // to the values just read off this one.\n where: conjoin(at(args), childLink(link, parent as Record<string, unknown>)),\n select: keySelect(referencedFields),\n },\n false,\n );\n\n if (matched) resolveKey(context, nullsFor(fkFields));\n },\n });\n\n contributeResolved();\n return;\n }\n\n if (key === \"delete\") {\n throw new UnsupportedQueryError(\n `data.${relation.name}.delete`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one whose foreign key lives on this row, so ` +\n `deleting through it would remove a row this statement is not about. ` +\n `Delete it directly, or 'disconnect' it first.`,\n );\n }\n\n /**\n * `update` through a to-one — this row holds the key, so the row being\n * written is the one it points at.\n *\n * Prisma accepts both spellings, measured: `update: { name: \"x\" }` and\n * `update: { data: { name: \"x\" } }`. The second is the documented one and the\n * first is what people write; accepting only one would refuse a legal query.\n *\n * An `after` step rather than a `before` one, and it needs the foreign key in\n * the statement's `RETURNING` — the far row is identified by *this* row's\n * column, whose current value the arguments do not carry. That is why\n * `keyFields` gains it here, where the other owning-side operands need\n * nothing returned at all.\n */\n if (key === \"update\") {\n out.keyFields.push(...fkFields);\n\n // The same check the foreign side runs, on the same operand grammar. Both\n // sides accept `{ where?, data }` and both must refuse an unknown key\n // inside it, or a misspelled `where` silently widens the write on whichever\n // side missed the check — the asymmetry #116 was filed about, arriving one\n // operand later.\n assertToOneWriteOperand(schema, relation, child, key, operand, operation);\n\n out.after.push({\n relation: relation.name,\n operation: \"update\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n // A composite key with any column null names no row — see\n // {@link isLinked} — so a half-written link is the *absent* case here\n // rather than a lookup that finds nothing later.\n if (!isLinked(valuesOf(parent, fkFields))) {\n // The same error as the foreign side's miss, and for the same reason\n // — this is one condition with two spellings, not two conditions.\n // Measured rather than inferred: Prisma answers P2025 here too,\n // *\"depends on one or more records that were required but not\n // found\"*, which `failureKind` maps to `notFound`.\n //\n // `UnsupportedQueryError` was wrong twice over. It classifies as\n // `other`, so the differential harness would have called it agreement\n // with a Prisma refusal of a different kind — and it prefixes \"does\n // not support … yet\", which reports a fully-implemented operation as\n // unimplemented because a row is missing. That vocabulary has been\n // corrected once each on #82 and #88.\n throw new RecordNotFoundError(relation.model, \"update\");\n }\n\n // `.data !== undefined` rather than `\"data\" in operandAt`, which is the\n // test {@link toOneOperand} makes and the one this used to disagree\n // with. `canonicalShape` drops an `undefined`-valued key, so `update:\n // {}` and `update: { data: undefined }` are one plan entry — and an\n // explicit `undefined` is the ordinary way a conditional write is\n // spelled, which is why `suppliedFields` skips it everywhere else.\n // Keying on presence sent `data: undefined` down to `updateMany` and\n // answered a no-op call with `updateMany requires 'data'`, on the side\n // this file cites as the precedent for the other one.\n const operandAt = at(args);\n const wrapped =\n operandAt !== null &&\n typeof operandAt === \"object\" &&\n (operandAt as Record<string, unknown>).data !== undefined;\n const record = operandAt as Record<string, unknown> | null;\n const data = wrapped ? record!.data : operandAt;\n\n // The caller's filter, conjoined with the link — so `update: { where,\n // data }` narrows *which* single row is written rather than being\n // decoration. Ignoring it was a silent wrong write: the operand\n // type-checks on both sides, the foreign side conjoins it and raises on\n // a miss, and this side renamed the linked row whether or not it\n // matched. Prisma answers P2025 for the non-matching case, which is\n // what the lookup below reproduces.\n //\n // The lookup only happens when a `where` is actually present, and that\n // is shape-stable — `canonicalShape` records a `where` key's presence —\n // so the common `update: { … }` spelling still costs one statement.\n const filter = wrapped ? record!.where : undefined;\n const where = conjoin(filter, childLink(link, parent));\n\n if (filter !== undefined) {\n const found = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(referencedFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (!found) throw new RecordNotFoundError(relation.model, \"update\");\n }\n\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data },\n // NOT pre-scoped: the child's own policies decide whether this row is\n // reachable and whether the payload is allowed to write what it\n // names — its `onUpdate` and its scope-escape guard.\n false,\n );\n },\n });\n return;\n }\n\n /**\n * The list operands, refused by name on a to-one.\n *\n * `set`, `updateMany` and `deleteMany` describe *many* rows, and this side\n * has one by construction — Prisma does not offer them here either. They were\n * in `SUPPORTED` with no branch on this side, so they fell through to the\n * `connect` handling below and reported `connect` back to a caller who wrote\n * something else. Same fall-through as `upsert`'s, found by the same test.\n *\n * The fourth collection operand, `createMany`, is refused above this with its\n * own wording, which is why the set read here is {@link NO_SET_OF_ROWS} and\n * not {@link COLLECTION_ONLY_STATEMENTS} whole.\n */\n if (NO_SET_OF_ROWS.has(key)) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: this row holds a single foreign key, so ` +\n `there is no set of rows for '${key}' to act on. Prisma does not ` +\n `accept it here either. Use 'connect', 'disconnect' or 'update'.`,\n );\n }\n\n /**\n * `upsert` through a to-one whose key is on **this** row — update the far row\n * this one points at, or mint one and point at it (#391).\n *\n * **Its refusal named a write-back that this side does not need**: *\"an\n * absent far row would have to be created and then written back to a\n * `<parent>` that has already been inserted\"*. It has not been inserted. The\n * statement the caller asked for is the one this step runs *before*, so a\n * created row's key reaches it as a contribution — which is exactly what the\n * `create` and `connectOrCreate` branches above already do, and they are the\n * two operands either side of this one. What was genuinely missing was\n * deciding the branch, and that is a lookup, the same one `connectOrCreate`\n * has been deciding since #94. The seventh refusal in this file to describe\n * machinery one layer down.\n *\n * The refusal also pointed at a workaround that does not exist here: *\"upsert\n * the `<child>` directly, then 'connect' it\"*. On the **foreign** side that\n * works, because the child carries the back-reference to key the upsert on —\n * `Image.upsert({ where: { thumbnailForMediaId: id }, … })`, which is what\n * #354 shipped. On this side there is no such column: the link is this row's\n * `previewImageId`, and `Image` has nothing pointing back. So the caller was\n * being sent to a spelling with nothing to put in its `where`, and the real\n * workaround — read the foreign key, then branch by hand into `create` or\n * `update` — was left to be rediscovered per call site. That is the half of\n * #391 a wording fix would not have closed.\n *\n * **A `before` step, and the branch is decided from the parent's own key.**\n * The far row is identified by a column of this row, which the arguments do\n * not carry, so the parent is read first — pre-scoped, exactly as the\n * `disconnect` filter arm's parent read is and for the same reason: `args.where`\n * has already been through this model's policies. Then:\n *\n * linked, and the far row matches -> update it, key written back unchanged\n * linked, filter matches nothing -> the create branch, as Prisma's does\n * nothing linked -> create it and take the new key\n *\n * Measured against 6.19.2/SQLite on `Profile.user` (a one-to-one) and\n * `User.organization` (a many-to-one), which answer identically:\n *\n * no where, nothing linked insert the far row, update this row's key\n * no where, linked select the far row, update it, **this row is\n * not written at all**\n * where matching, linked the same update, filtered\n *\n * **Nothing displaces**, and that is per branch rather than an omission. The\n * update branch keeps the link it found; the create branch mints a row a line\n * earlier, so nothing can already be pointing at it — `connectOrCreate`'s miss\n * branch says the same thing in the same words, and Prisma agrees by\n * construction: its log for the create branch is the insert and the repoint,\n * with no incumbent lookup in it.\n *\n * **KNOWN DIVERGENCE — a `where` that matches nothing is served here and is a\n * Prisma bug there.** Prisma splices the operand's filter into the *parent's*\n * `UPDATE`, so the create branch emits\n * `update \"Profile\" set \"userId\" = ? where (\"id\" in (?) and \"User\".\"name\" = ?)`\n * — a column of the far table in this row's statement — and answers P2022,\n * *\"The column `main.User.name` does not exist in the current database\"*,\n * having already inserted the far row inside the transaction it then rolls\n * back. Measured on SQLite on both relation shapes above and on the composite\n * `LedgerNote.ledger`; the statement is invalid on Postgres too, though as a\n * missing `FROM`-clause entry rather than an unknown column, so the pin\n * asserts the failure and not its class. gemi runs the create branch the\n * operand asks for. It is the same operand the *hit* branch serves correctly\n * on both clients, so refusing the `where` outright would refuse a query\n * Prisma answers; the divergence is pinned in `writes.differential.test.ts`\n * rather than matched.\n *\n * **The hit branch writes this row's foreign key back unchanged**, which is\n * the one thing here that costs anything: the contribution is in the SET list\n * whether or not the branch that changes it ran, because a statement's text\n * cannot depend on a value read at bind time. On a model carrying\n * `@updatedAt` that stamps a row Prisma leaves alone. Pre-existing rather than\n * introduced — it is the same mechanism, and the same trade, as the owning\n * side's `disconnect` filter arm, whose measurements are in\n * `updateAssignments`' docblock in `write.ts`.\n *\n * A branch of its own is also what keeps the refusals honest, and that is why\n * this sits above `connect` rather than after it. With none, the operand fell\n * through to the `connect` handling and reported *\"'where' yet\n * (Organization.update.organization.connect)\"* — a different operand, a\n * different model, and a claim that `{ id: 1 }` is not a unique field when it\n * is. That is the shape #85 was filed for and #101 fixed on its own path.\n */\n if (key === \"upsert\") {\n // Both checks, in this order, and neither subsumes the other: the first is\n // the to-one *shape* — an array, a scalar, a misspelled `where` that would\n // otherwise be dropped and turn a filtered write into an unconditional one\n // — and the second is `upsert`'s own grammar, that both payloads are there.\n // `false` rather than `many`, for the reason its docblock gives: a to-one's\n // `where` is an optional `WhereInput`, not a unique key.\n assertToOneWriteOperand(schema, relation, child, key, operand, operation);\n assertUpsertOperand(schema, relation, child, operand, operation, false);\n\n out.before.push({\n relation: relation.name,\n operation: \"upsert\",\n async run(args, context, executor) {\n // Optional throughout, the way `connectOrCreate`'s reads are: the\n // plan-time checks above ran on the *shape*, and `canonicalShape`\n // records a key's presence, so a plan hit implies the same keys — but\n // nothing in a step should be the first place a missing one is a\n // `TypeError` rather than an error naming the argument.\n const record = at(args) as Record<string, unknown> | null | undefined;\n\n // Pre-scoped: `args.where` is the effective `where` this call already\n // put through this model's policies, so re-applying them would `AND`\n // the same predicate twice. One column of one row, inside the\n // transaction the nested steps already run in.\n const parent = (await executor.exec(\n schema.name,\n \"findFirst\",\n { where: args?.where, select: keySelect(fkFields) },\n true,\n )) as Record<string, unknown> | null;\n\n // A composite key with any column null names no row — see\n // {@link isLinked} — so a half-written link is the *absent* case here\n // and takes the create branch, as does a parent this statement will go\n // on to match nothing of. Prisma reaches the second the same way: its\n // parent read finds nothing, it inserts the far row, and the failure\n // arrives from the write-back as P2025, rolling the insert back. gemi's\n // own `update` raises `RecordNotFoundError` for the same call and takes\n // this step down with it.\n if (isLinked(valuesOf(parent, fkFields))) {\n // `AND`, not a spread: a filter naming a referenced column itself\n // must narrow rather than replace the restriction that keeps this on\n // the linked row. `childLink` reads as \"the row this one points at\"\n // on this side — the far row's own columns bound to the values just\n // read off this one.\n const where = conjoin(\n record?.where,\n childLink(link, parent as Record<string, unknown>),\n );\n\n const hit = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(referencedFields) },\n // NOT pre-scoped: the child's own policies decide which rows exist,\n // and a row this caller cannot see reads as absent — which sends it\n // to the create branch, exactly as a hidden child does on the\n // foreign side. The conservative answer, and the same one there.\n false,\n )) as Record<string, unknown> | null;\n\n if (hit) {\n // The key this row already holds, written back unchanged. The\n // contribution is structural, so \"the link does not move\" has to be\n // spelled as an assignment that changes nothing rather than as an\n // absent one — the rule the `disconnect` filter arm states.\n resolveKey(context, valuesOf(hit, referencedFields));\n\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data: record?.update },\n // NOT pre-scoped: the child's `onUpdate` and its scope-escape\n // guard judge the payload, as they do for a nested `update`.\n false,\n );\n return;\n }\n }\n\n const created = (await executor.exec(\n relation.model,\n \"create\",\n { data: record?.create, select: keySelect(referencedFields) },\n // NOT pre-scoped — the child's own `onCreate` scopes the new row.\n false,\n )) as Record<string, unknown> | null;\n\n resolveKey(context, valuesOf(created, referencedFields));\n },\n });\n\n contributeResolved();\n return;\n }\n\n if (key === \"connectOrCreate\") {\n assertConnectOrCreateOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n false,\n );\n\n out.before.push({\n relation: relation.name,\n operation: \"connectOrCreate\",\n async run(args, context, executor) {\n const where = at(args)?.where;\n\n const found = (await executor.exec(\n relation.model,\n \"findUnique\",\n { where, select: keySelect(referencedFields) },\n // NOT pre-scoped, for the reason `connect` is not: this reads another\n // model's rows to decide what to attach, so that model's policies say\n // which rows exist. Scoped away, a hit becomes a miss and the row is\n // *created* — so the fallback branch is what keeps this from being a\n // way to observe another tenant's keys.\n false,\n )) as Record<string, unknown> | null;\n\n if (found) {\n const values = valuesOf(found, referencedFields);\n // A hit **is** a connect, so it displaces where the miss below cannot\n // — measured on both sides, and the reason `displaces` is consulted\n // per *branch* rather than per operand. `planForeignSide`'s table\n // records the same split from the other end (M14c / M15d).\n if (displaces) {\n await displaceSibling(\n schema,\n fkFields,\n values,\n args?.where,\n existing,\n executor,\n );\n }\n resolveKey(context, values);\n return;\n }\n\n const created = (await executor.exec(\n relation.model,\n \"create\",\n { data: at(args)?.create, select: keySelect(referencedFields) },\n // NOT pre-scoped — the child's own `onCreate` scopes the new row.\n false,\n )) as Record<string, unknown> | null;\n\n // No displacement on this branch, and it is not an omission: the far\n // row was minted a line ago, so nothing can already be pointing at it.\n // Prisma agrees by construction rather than by rule — its miss branch\n // logs the insert and the repoint and no incumbent lookup at all.\n resolveKey(context, valuesOf(created, referencedFields));\n },\n });\n\n contributeResolved();\n return;\n }\n\n // `connect`. In the common case the caller already handed us the referenced\n // value — `connect: { id: 1 }` where the relation references `id` — and no\n // query is needed at all: it is one more bound column.\n //\n // Whether that is the case is a property of the argument *shape*, not of its\n // values, so the choice is made here at compile time and the two forms are two\n // plans. That is what keeps a `connect` from silently costing a round trip.\n if (\n typeof operand !== \"object\" ||\n operand === null ||\n Array.isArray(operand)\n ) {\n throw new InvalidArgumentError(\n `data.${relation.name}.connect`,\n schema.name,\n operation,\n \"Expected an object naming a unique field.\",\n );\n }\n\n /**\n * **Single-field only, and a composite `connect` takes the lookup** (#271).\n *\n * The optimisation is \"the caller already handed us the value the column\n * needs\", and on a composite relation they did not: Prisma spells a\n * multi-column unique key in its *compound* form —\n * `connect: { tenantId_code: { tenantId: 1, code: \"a\" } }`, one argument key\n * named after the index — so there is no key here whose value is a referenced\n * column. Reading one out would mean reproducing the generator's `_`-joined\n * naming rule inside the planner, and then assuming the caller reached for\n * the group the relation *references* rather than any other unique key on the\n * child, which `connect` explicitly allows.\n *\n * So the composite case pays one `findUniqueOrThrow`, and that costs parity\n * nothing: Prisma issues the same lookup. Measured on 6.19.2 with query\n * events on, `LedgerEntry.create({ data: { amount: 1, ledger: { connect:\n * { tenantId_code: { tenantId: 1, code: \"ab\" } } } } })` logs\n *\n * BEGIN IMMEDIATE\n * select Ledger.tenantId, Ledger.code where tenantId = ? and code = ?\n * insert into LedgerEntry (tenantId, ledgerCode, amount) values (?,?,?)\n * select the row back\n * COMMIT\n *\n * — the resolve is a statement there too. The zero-query path was always a\n * gemi-only shortcut over the shape where the operand *is* the value.\n */\n const direct =\n referencedFields.length === 1 &&\n (operand as Record<string, unknown>)[referencedFields[0]] !== undefined &&\n Object.keys(operand as Record<string, unknown>).filter(\n (name) => (operand as Record<string, unknown>)[name] !== undefined,\n ).length === 1;\n\n if (direct) {\n const referenced = referencedFields[0];\n const fkField = fkFields[0];\n\n /**\n * **The direct form still costs a step when it has an incumbent to\n * displace**, and only then.\n *\n * \"No query is needed at all\" is a claim about resolving the *operand*, and\n * it survives: the value is still read straight out of the argument tree\n * and never looked up. What a one-to-one adds is a second row that has to\n * stop holding it, which no amount of knowing the value answers.\n *\n * The condition is the schema's, not the call's, so the two forms are\n * still decided once at compile time and a many-to-one `connect` — which\n * is every `connect` in an ordinary schema — keeps the zero-query path it\n * has always had.\n */\n if (displaces) {\n out.before.push({\n relation: relation.name,\n operation: \"connect\",\n async run(args, _context, executor) {\n await displaceSibling(\n schema,\n [fkField],\n [at(args)?.[referenced]],\n args?.where,\n existing,\n executor,\n );\n },\n });\n }\n\n out.contributions.push({\n field: fkField,\n value: (args) => at(args)?.[referenced],\n });\n return;\n }\n\n // `connect: { publicId: \"...\" }` against a relation that references `id`:\n // Prisma resolves it with a lookup, and so do we. Validated now so a\n // non-unique connect target fails at compile time rather than matching an\n // arbitrary row.\n matchUniqueKey(child, operand, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.connect`,\n });\n\n out.before.push({\n relation: relation.name,\n operation: \"connect\",\n async run(args, context, executor) {\n const found = (await executor.exec(\n relation.model,\n \"findUniqueOrThrow\",\n { where: at(args), select: keySelect(referencedFields) },\n // NOT pre-scoped. This lookup reads another model's rows to decide what\n // to attach, so it is that model's policies that say which rows exist —\n // otherwise a `connect` by any unique key reaches every tenant's.\n false,\n )) as Record<string, unknown> | null;\n\n const values = valuesOf(found, referencedFields);\n\n // After the lookup, which is the ordering #363 asked how to get: the\n // clear cannot be written until the referenced value is known, and\n // sitting in the same step is what orders it without having to order a\n // write between two reads that are otherwise independent. It also puts\n // the *miss* on the right side of the detach — `findUniqueOrThrow` has\n // already raised, so a `connect` naming no row displaces nothing, which\n // is Prisma's answer (P2025 with the incumbent untouched).\n if (displaces) {\n await displaceSibling(\n schema,\n fkFields,\n values,\n args?.where,\n existing,\n executor,\n );\n }\n\n resolveKey(context, values);\n },\n });\n contributeResolved();\n}\n\n/**\n * The *child* holds the foreign key, so nothing can be written until this row\n * exists and its key is known. Both forms are therefore `after` steps, and both\n * need the key in the statement's `RETURNING` list — **every column of it**,\n * since a composite link is only usable once the whole tuple is known (#271).\n *\n * **This is the side the partial-write hazard is real on**, and it is answered\n * rather than avoided. The owning side folds its columns into one statement;\n * here each linked row is its own `update` or `create`, so a composite key\n * whose second statement fails leaves the first row repointed. `$exec` opens a\n * transaction for any plan carrying steps — iteration 5 — so the failure rolls\n * the parent row back with it, which is the same guarantee that already covers\n * a `connect` of three rows where the third does not exist.\n */\nfunction planForeignSide(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n link: Link,\n key: string,\n operand: unknown,\n operation: string,\n at: (args: any) => any,\n out: NestedWritePlanning,\n): void {\n const parentFields = link.parentFields;\n const childFields = link.childFields;\n\n out.keyFields.push(...parentFields);\n\n /**\n * **Whether linking through this relation has to displace what is linked\n * already** — the to-one case, where the child's key carries the `@unique`\n * that makes the relation hold one row, so a second link is a collision\n * rather than a second row.\n *\n * Prisma detaches the incumbent rather than deleting it, and it does so for\n * some of the operands that link and not others. That split is not derivable\n * — it is measured, on one fixture, and it is the reason `displaces` is\n * consulted per operand rather than applied to \"anything that links\":\n *\n * create displaces the incumbent, links the new row\n * connect displaces the incumbent, links the named row\n * connectOrCreate, hit the same — it *is* a connect (#361)\n * connectOrCreate, miss collides: P2002 on the child's key\n * upsert, create branch collides: P2002 on the child's key\n *\n * So the two branches of one `connectOrCreate` answer differently, which is\n * Prisma's asymmetry and not an embellishment: what displaces is *linking an\n * existing row*, plus the bare `create` — and the create inside the two\n * compound operands does not.\n *\n * Nullable, because a detach has to leave a value behind. A required child\n * key cannot be nulled at all, so the insert or repoint collides as it always\n * did, which is the only thing the schema permits. `assertDisconnectable` is\n * deliberately not called here: it would refuse the whole operand, including\n * the empty-to-one case that has always worked.\n *\n * **`relation.kind` is the whole discriminator here, and it is *not* the same\n * predicate as the owning side's (#363) — it is the stronger half of it.**\n * `kind` is a property of this relation's back-reference, and Prisma will not\n * let a non-list back-relation exist without `@unique` on the child's foreign\n * key. Verified against 6.19.2 rather than assumed: `User.profile Profile?`\n * beside a `Profile.userId` carrying no `@unique` is refused at parse time\n * with P1012 — *\"A one-to-one relation must use unique fields on the defining\n * side. Either add an `@unique` attribute to the field `userId`, or change\n * the relation to one-to-many\"* — so a schema reaching this line with\n * `kind !== \"many\"` **has** the index, and `kind` alone is sufficient here.\n *\n * **The converse does not hold, which is why the owning side needs two tests\n * where this one needs one.** A `@unique` foreign key beside a *list*\n * back-relation validates: `Player.teamId Int? @unique` next to\n * `Team.players Player[]` is accepted, and Prisma refuses the displacing\n * `connect` there with P2002 without reading the sibling. So \"the key is\n * unique\" is strictly weaker than `kind !== \"many\"`, and an owning-side\n * discriminator built on the index alone displaces on schemas this side\n * correctly leaves alone. That is a real defect this file shipped for one\n * review cycle; `planOwningSide`'s `displaces` now reads the *child's* copy of\n * the relation for its `kind` and uses `uniques` only to narrow. From the\n * owning side `relation.kind` is still unreadable — it says `\"one\"` for a\n * many-to-one and a one-to-one alike, because both point at a single far row.\n *\n * **Every column has to be nullable, not the first one** (#271). Prisma makes\n * a composite relation optional or required as a whole and refuses a mixture,\n * so on a schema it accepted the columns agree — but the test is over all of\n * them because half a detach is worse than none: the incumbent would keep a\n * key that still joins nowhere while the unique index still holds it.\n */\n const displaces =\n relation.kind !== \"many\" &&\n childFields.every((field) => child.fields[field]?.nullable === true);\n\n /**\n * **A to-one whose key is on the child**, which this function otherwise plans\n * as though the child were a list.\n *\n * It had exactly one `kind` check — `createMany`'s, further down — because no\n * fixture had the shape, so nothing ever reached this side with `kind: \"one\"`\n * (#116). Everything else took the to-many spelling: `updateMany` and\n * `deleteMany` *compiled*, and `update` / `delete` / `upsert` were refused\n * for looking wrong rather than for being unimplemented here.\n *\n * Measured against the generated client rather than reasoned about. Prisma's\n * to-one nested input is\n *\n * { create, connectOrCreate, upsert, disconnect, delete, connect, update }\n *\n * with no `createMany`, `set`, `updateMany` or `deleteMany` key at all — so\n * the first group below is refused for the same reason `planOwningSide`\n * refuses it, and says so in the same words.\n *\n * The rest of that input — `update`, `delete`, `upsert` — was refused here\n * too, for being spelled unlike the to-many form. It is implemented now, and\n * the implementation is a *translation* rather than three new bodies: see\n * {@link toOneOperand}.\n */\n // The operand as the caller wrote it, kept because the rewrite below\n // overwrites `operand` in place and `assertToOneFilter` has to read the\n // spelling rather than the translation — `false` and `null` are one value\n // afterwards and two very different calls before. See that function.\n const spelledOperand = operand;\n\n if (relation.kind !== \"many\") {\n // {@link NO_SET_OF_ROWS} rather than {@link COLLECTION_ONLY_STATEMENTS}:\n // `createMany` is the fourth of them and is refused further down, where its\n // own message and its operand check live together.\n if (NO_SET_OF_ROWS.has(key)) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: there is a single ${child.name} row, ` +\n `so there is no set of rows for '${key}' to act on. Prisma does not ` +\n `offer it on a to-one either. Use 'connect', 'disconnect' or ` +\n `'update'.`,\n );\n }\n\n /**\n * **An array where the relation holds one row**, which compiled here and\n * wrote through it.\n *\n * Nothing below this point consults `kind`, so `create: [a, b]` inserted\n * two children, and `connect: [{ id: 1 }, { id: 2 }]` repointed *both* rows\n * through a relation that can hold one — the second silently winning. That\n * is a live divergence, not strictness: Prisma refuses all three, measured\n * off the generated client rather than reasoned from the docs.\n *\n * connect: [{ id: 1 }, { id: 2 }]\n * -> PrismaClientValidationError, neither row repointed\n * create: [{ bio: \"a\" }, { bio: \"b\" }]\n * -> \"Expected ProfileCreateWithoutUserInput or\n * ProfileUncheckedCreateWithoutUserInput, provided (Object, Object)\"\n *\n * `PrismaClientValidationError` carries **no `code`** — it is an argument\n * refusal rather than a database one — which is why this is\n * `InvalidArgumentError` and not either `Unsupported*`: the argument is\n * supported and the value is wrong. So the message names the shape that\n * would work rather than announcing that arrays are unimplemented.\n *\n * Sound at plan time because array-ness is *in the plan key*: an array and\n * a single object are different structures to `canonicalShape`, so they can\n * never share a cache entry and this refusal cannot be decided on one\n * call's behalf by another's.\n */\n if (Array.isArray(operand)) {\n throw new InvalidArgumentError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one — ${child.name} holds the foreign key, ` +\n `so there is one row here at most. Expected a single object for ` +\n `'${key}', not an array of them. Prisma refuses the array too.`,\n );\n }\n\n /**\n * The three that were refused are a **spelling** difference, not missing\n * machinery. `conjoin` returns the parent restriction alone when the\n * caller's filter is absent or `{}`, and `listOf(null)` is `[]` — so a\n * to-one is a to-many of one, and the bodies below already do the work\n * once the operand is written the way they read.\n *\n * **Rebinding `at` — translating at *bind* time and not only while the plan\n * is compiled — is load-bearing for exactly one branch, and that is the\n * correctness argument for this whole design.** Every other distinction the\n * table draws is *structural*, so it may safely be decided once when the\n * plan is built: `{ data }` against `{ where, data }`, a `where` present\n * against absent, an array against an object — `canonicalShape` records all\n * of those, so two calls that differ there are already two plans. The\n * boolean is the one that is not. `delete: true` and `delete: false` are\n * the same shape to everything except the guard `shapeOfMember` carries for\n * exactly this, and a plan key is a cache rather than a contract. Reading\n * the boolean inside `at` means the step consults the *call's* value on\n * every execution, so a plan handed the wrong one still writes nothing —\n * `listOf(null)` is `[]`. Belt and braces on purpose: the owning side's\n * version of the same collision was a silent wrong write for its whole\n * life, precisely because its `true`/`false` decision was made once at\n * compile time and never revisited.\n */\n // Checked *before* the rewrite, because the rewrite is lossy by\n // construction: it rebuilds the operand from the keys it knows, so a key it\n // does not know is gone by the time anything downstream could refuse it.\n assertToOneWriteOperand(schema, relation, child, key, operand, operation);\n\n const spelled = at;\n at = (args: any) => toOneOperand(key, spelled(args));\n operand = toOneOperand(key, operand);\n }\n\n /**\n * `disconnect` and `delete` on this side act on rows the caller named by\n * unique key — which is what makes them expressible at all, and what puts\n * them on the supported side of this file's line.\n *\n * **On a to-one the caller names a *filter*, or nothing at all**, and that\n * does not weaken the line: the row is still identified, by the parent's own\n * key, which is the strongest naming available. `assertToOneFilter` is what\n * replaces the unique-key match there, and the filter only narrows.\n *\n * They differ on a row that is *not* linked to this parent, and the\n * difference is Prisma's, measured rather than chosen — on both kinds, since\n * the second pair is the same asymmetry read through the to-one spelling:\n *\n * disconnect a row linked elsewhere -> succeeds, changes nothing\n * delete a row linked elsewhere -> raises \"are not connected\"\n * disconnect: true, nothing linked -> succeeds, changes nothing\n * delete: true, nothing linked -> P2025\n *\n * So both filter by the parent key as well as the caller's key, and only\n * `delete` treats a miss as an error. That filter is doing two jobs at once:\n * it reproduces Prisma's semantics, and it is what stops either operand from\n * reaching a row belonging to a different parent.\n *\n * **Scoping comes from the child's own operations**, as everywhere else here:\n * `updateMany` and `delete` go through the child's `$exec` un-pre-scoped, so\n * a row the child's policies hide is not reachable. For `delete` that means a\n * hidden row reports \"not connected\" rather than \"denied\" — the same answer\n * as a row that genuinely is not linked, which is the conservative one.\n */\n /**\n * `update: { where, data }` — the caller's columns, written to a row they\n * named by unique key.\n *\n * **The pass this was refused for turns out to exist**, one layer down. The\n * `REFUSED` entry said it \"needs its own scoping pass\" for `onUpdate` and the\n * scope-escape guard; both of those live in `applyPolicies`, which the\n * child's own `$exec` runs because this step is not pre-scoped. Verified\n * rather than assumed:\n *\n * another tenant's row -> { count: 0 } the child's scope\n * caller names a scoped column -> ScopeEscapeError\n *\n * So the refusal was describing a gap in the wrong place. What `update`\n * genuinely needs beyond `disconnect` is nothing: the parent-key filter that\n * keeps it off another parent's row is the same one, and the payload is the\n * child's business.\n *\n * `updateMany` stays refused because it names a *predicate* rather than a\n * row, which is the half of the line this file draws that has not moved.\n */\n /**\n * `set` — replace the whole set with the named rows.\n *\n * The one supported operand that acts on rows the **call** did not name: it\n * disconnects whatever is currently linked before connecting what was asked\n * for. That is the half of this file's line it appears to fail, and #83\n * already answered how — its implicit many-to-many `set` had the identical\n * problem and the fix was to give the disconnect a *lookup*: read the linked\n * rows through the child's own `findMany`, and clear only the ones the\n * caller can see.\n *\n * So `set` means **\"replace the set I can see\"**. With no policy on the child\n * every row is visible and it is Prisma's `set` exactly; with one, a row the\n * caller cannot see stays attached rather than being silently detached —\n * which is the same choice `disconnect` makes one operand over, and the\n * opposite of what an unscoped delete would do.\n *\n * Three measured details that are not obvious from the name:\n *\n * set [one of two] the unnamed row's key becomes null, the named stays\n * set [] every linked row is detached\n * set [another parent's row] it is repointed here, as `connect` does\n * set [a row that does not exist] silently ignored — no error\n *\n * The last is why the connect half is an `updateMany` rather than the\n * `update` a nested `connect` uses: Prisma does not raise here, and matching\n * that means not raising either.\n *\n * Both halves write the child's foreign key, so `set` inherits #98 exactly as\n * `connect` does: a child whose policy scopes on that column is refused by\n * the scope-escape guard, because it cannot tell a column the ORM wrote from\n * one the caller did. #99 fixes that for every relation operand at once, and\n * this needs no change when it lands.\n *\n * **The clearing half stopped inheriting it and the linking half must not,\n * which is measured rather than tidy.** `clearLinks` names the column as the\n * ORM's, because a nested `create` on an occupied to-one needs the same clear\n * and would otherwise be refused for a write nobody made. Naming it on the\n * *link* too makes `set` succeed — and succeed wrongly: the clear nulls the\n * key, which puts the row outside the very scope (`{ folderId: 2 }`) the link\n * then has to select it by, so the row is detached and never re-attached. A\n * silent half-write in place of a loud refusal. Left refused until #99 can\n * answer the scope as well as the guard.\n */\n /**\n * `updateMany` and `deleteMany` — a **filter**, applied to this parent's rows.\n *\n * These were the last two refused on the \"names a predicate rather than a\n * row\" reading of #94's line, and that reading was too strong. What the line\n * is really asking is whether there is a `where` the child's scope can be\n * `AND`ed into — and a predicate is exactly that. Both operations are in\n * `SCOPABLE`, so routing them through the child's own `$exec` gives the scope\n * on which rows match, and `updateMany` gets `onUpdate` and the scope-escape\n * guard over its payload, the same way #101's `update` does.\n *\n * The parent key goes into the filter for the same reason it does everywhere\n * else here: Prisma applies these to *this* parent's children only, verified\n * before implementing, and without it a `deleteMany: {}` would empty the\n * table.\n *\n * **The two operands are shaped differently**, which is easy to get backwards:\n *\n * updateMany: { where: { … }, data: { … } }\n * deleteMany: { … } the filter directly\n *\n * `upsert` stays refused, and its reason is the one that has not moved: it\n * needs to know which branch ran from inside a nested step, which neither\n * half of it provides.\n */\n /**\n * `upsert` — find by a unique key **within this parent's rows**, update it or\n * create it.\n *\n * Its refusal said it *\"needs a third thing neither half has: deciding which\n * branch ran, from inside a nested step\"*. It does not: the lookup decides\n * the branch, exactly as `connectOrCreate` has decided one since #94. That is\n * the sixth `REFUSED` reason in this series to describe machinery that was\n * already there.\n *\n * **Scoped to this parent, which is Prisma's own semantics and not an\n * embellishment** — measured, because it is the detail that decides what the\n * operand means:\n *\n * upsert a row belonging to another parent\n * -> Unique constraint failed on the fields: (`publicId`)\n *\n * Prisma looks only among *this* parent's children, does not find it, takes\n * the create branch, and collides. So the conjunction that keeps every other\n * filter operand on this parent is what produces the right branch here, not\n * merely what keeps it safe.\n */\n /**\n * **The to-one reaches this same body, and it needed nothing added.** Its\n * `where` is optional — `ProfileUpsertWithoutUserInput` is\n * `{ update, create, where? }` — so `conjoin(undefined, link)` is the link\n * alone and the lookup finds the single connected child. Measured on both\n * branches:\n *\n * no child, no `where` -> the create branch runs *and stamps the\n * foreign key* — Profile { bio: \"created\",\n * userId: 1 }\n * child present, no `where` -> the update branch runs against it\n * child present, `where` matching nothing\n * -> the create branch runs and collides:\n * P2002, \"Unique constraint failed on the\n * fields: (`userId`)\"\n *\n * The third is the note above transposed to the foreign side, and it is the\n * one to-one nested-write miss that is *not* P2025. It is left to happen\n * rather than pre-empted: the create is what Prisma runs, so surfacing\n * `UniqueConstraintError` from it is agreement, where refusing early would be\n * a different error for the same query.\n */\n if (key === \"upsert\") {\n assertUpsertOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n\n out.after.push({\n relation: relation.name,\n operation: \"upsert\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n for (const entry of listOf(at(args)) as Record<string, unknown>[]) {\n const where = conjoin(entry.where, childLink(link, parent));\n\n const hit = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (hit) {\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data: entry.update },\n // NOT pre-scoped: the child's `onUpdate` and scope-escape guard\n // judge the payload, as they do for a nested `update`.\n false,\n );\n continue;\n }\n\n await executor.exec(\n relation.model,\n \"create\",\n {\n // The foreign key is ours, as it is for every create here.\n data: { ...(entry.create as object), ...childLink(link, parent) },\n select: keySelect(childFields),\n },\n false,\n );\n }\n },\n });\n return;\n }\n\n if (key === \"updateMany\" || key === \"deleteMany\") {\n const updating = key === \"updateMany\";\n assertManyOperand(schema, relation, operand, key, operation);\n\n out.after.push({\n relation: relation.name,\n operation: key,\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const operandAt = at(args) as Record<string, unknown>;\n const filter = updating ? operandAt?.where : operandAt;\n\n // **`AND`, not a spread.** A spread lets the parent key *overwrite* a\n // caller filter naming the same column: `deleteMany: { userId: 9 }` on\n // this parent's relation became `{ userId: <this parent> }`, so a query\n // asking for children belonging to somebody else deleted every one of\n // this parent's instead. Silent, and in the deleting direction.\n //\n // Prisma conjoins — measured, because the whole question is what it\n // does rather than what is tidy:\n //\n // deleteMany { userId: <other> } -> nothing deleted\n //\n // Conjoining also keeps the parent restriction *unforgeable* while\n // letting the caller's predicate narrow, which is exactly what\n // `withScope` does for a policy fragment and for the same reason.\n const where = conjoin(filter, childLink(link, parent));\n\n await executor.exec(\n relation.model,\n key,\n updating ? { where, data: operandAt?.data } : { where },\n // NOT pre-scoped. The child's scope narrows which rows match, and for\n // `updateMany` its `onUpdate` and scope-escape guard judge the\n // payload — which is the whole reason these are expressible.\n false,\n );\n },\n });\n return;\n }\n\n if (key === \"set\") {\n assertNamedRows(schema, relation, child, operand, \"set\", operation);\n assertDisconnectable(child, relation, childFields, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.set`,\n });\n\n out.after.push({\n relation: relation.name,\n operation: \"set\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const attach = childLink(link, parent);\n\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n\n for (const entry of listOf(at(args))) {\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where: entry as object, data: attach },\n false,\n );\n }\n },\n });\n return;\n }\n\n if (key === \"update\") {\n assertNamedUpdates(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n\n out.after.push({\n relation: relation.name,\n operation: \"update\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const list = listOf(at(args));\n\n for (let index = 0; index < list.length; index++) {\n const entry = list[index] as Record<string, unknown>;\n // The caller's key *and* the link, so an `update` cannot reach a row\n // attached to a different parent — the same filter `delete` uses,\n // and it does the same two jobs. `AND` rather than a spread for the\n // reason `updateMany` documents: a key naming the foreign column\n // itself would otherwise be overwritten rather than honoured.\n const where = conjoin(entry.where, childLink(link, parent));\n\n const found = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (!found) {\n // `RecordNotFoundError`, not `UnsupportedQueryError`: nothing here\n // is unsupported, the row simply is not there. Prisma agrees —\n // P2025, *\"depends on one or more records that were required but\n // not found\"* — and the differential harness compares the failure\n // *kind* precisely so a refusal cannot pass as agreement with a\n // miss. This one was `other` against Prisma's `notFound` until the\n // harness said so.\n //\n // **Fatal on the to-one too, which was the open question and is\n // now measured.** The worry was that a to-one `update` naming a\n // non-matching `where` might be a no-op there, which would have\n // made this branch wrong for one `kind` and forced the two apart.\n // It does not: with a child present and `where: { bio: \"nope\" }`\n // Prisma raises P2025 — *\"No 'Profile' record was found for a\n // nested update on one-to-one relation 'ProfileToUser'\"* — with\n // wording identical to the no-child case, and the parent's own\n // assignments roll back with it. Absent and not-matching are one\n // condition to Prisma, so they stay one error here.\n throw new RecordNotFoundError(relation.model, \"update\");\n }\n\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data: entry.data },\n // NOT pre-scoped, and this is the whole reason `update` is\n // expressible: the child's own policies run over `data` — its\n // `onUpdate` defaults, its scope-escape guard refuses a caller\n // naming a scoped column — because they have not run yet.\n false,\n );\n }\n },\n });\n return;\n }\n\n if (key === \"disconnect\" || key === \"delete\") {\n const deleting = key === \"delete\";\n if (!deleting) {\n // Before any boolean normalisation would matter, and it has to be:\n // Prisma leaves `disconnect` out of the input type *entirely* when the\n // child's foreign key is required, so even `disconnect: false` is\n // rejected there — *\"Unknown argument `disconnect`. Did you mean\n // `connect`?\"*, with the available options listed as create /\n // connectOrCreate / upsert / connect / update. The refusal is on the\n // **key**, not on the value, and this one already reads only the schema.\n assertDisconnectable(child, relation, childFields, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.disconnect`,\n });\n }\n\n /**\n * **A to-one names a filter here; a to-many names rows by unique key.**\n *\n * `ProfileUpdateOneWithoutUserNestedInput` spells both operands\n * `ProfileWhereInput | boolean`, and it means it — measured:\n * `delete: { bio: \"seed\" }` is accepted with no `@unique` anywhere near\n * `bio`, and it deletes the connected row. Running `matchUniqueKey` on this\n * path would therefore refuse a query Prisma answers, which is why\n * `assertToOneFilter` replaces `assertNamedRows` rather than joining it.\n */\n if (relation.kind === \"many\") {\n assertNamedRows(schema, relation, child, operand, key, operation);\n } else {\n assertToOneFilter(\n schema,\n relation,\n child,\n spelledOperand,\n key,\n operation,\n );\n }\n\n out.after.push({\n relation: relation.name,\n operation: key,\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const list = listOf(at(args));\n\n for (let index = 0; index < list.length; index++) {\n // The caller's key *and* the link, so neither operand can reach a row\n // attached to a different parent. `AND` rather than a spread — see\n // `updateMany`.\n const where = conjoin(list[index], childLink(link, parent));\n\n if (!deleting) {\n await executor.exec(\n relation.model,\n \"updateMany\",\n { where, data: nullKey(childFields) },\n // NOT pre-scoped: clearing a foreign key is a write to the child,\n // so the child's scope decides which rows are reachable.\n false,\n // ...but the columns are *ours*: the caller wrote `disconnect:\n // { id }` and the ORM chose to null the key. Without this a child\n // scoped on its own foreign key is refused for a write it never\n // made — the same case as `connect`, see #98 and\n // `ormAuthoredFields`.\n childFields,\n );\n continue;\n }\n\n const found = (await executor.exec(\n relation.model,\n \"findFirst\",\n { where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (!found) {\n /**\n * **Two misses, two errors — and this is the third time this exact\n * mis-classification has had to be corrected** (see the notes at\n * `planOwningSide`'s `update` and at this file's own `update`\n * miss).\n *\n * On a to-one the caller named no row: `delete: true` means the\n * connected child, and there is either one or there is not.\n * Reporting *\"the row named by `true` is not connected\"* would be\n * nonsense to read, and worse it classifies as `other` where Prisma\n * answers P2025 — *\"No 'Profile' record was found for a nested\n * delete on one-to-one relation 'ProfileToUser'\"* — so the\n * differential harness would score a refusal as agreement with a\n * miss. Measured on both spellings: `delete: true` with no child\n * and `delete: { bio: \"nope\" }` with a child present give the same\n * P2025, so one error covers both.\n *\n * **`disconnect` does not come through here at all, and that\n * asymmetry is Prisma's.** A disconnect that matches nothing —\n * `disconnect: true` with no child, or a filter matching none — is\n * a *silent no-op* that still returns the parent, measured both\n * ways. The two operands share this body but must not share their\n * miss handling, which is why only `deleting` reaches this branch.\n */\n if (relation.kind !== \"many\") {\n throw new RecordNotFoundError(relation.model, \"delete\");\n }\n\n throw new UnsupportedQueryError(\n `data.${relation.name}.delete`,\n schema.name,\n operation,\n `the row named by ${JSON.stringify(list[index])} is not ` +\n `connected to this ${schema.name}. Prisma raises here too, ` +\n `rather than deleting a row belonging to somebody else.`,\n );\n }\n\n await executor.exec(\n relation.model,\n \"deleteMany\",\n { where },\n // NOT pre-scoped, for the reason above — and `deleteMany` rather\n // than `delete` because the `where` carries the link as well as the\n // unique key, which `delete` refuses as a non-unique target.\n false,\n );\n }\n },\n });\n return;\n }\n\n /**\n * `create` — insert the child, with this row's key stamped onto it.\n *\n * **On a to-one the new row has to displace the old one, and Prisma\n * *detaches* the incumbent rather than deleting it** (#360). Measured, with\n * user 1 already carrying a profile:\n *\n * user.update({ data: { profile: { create: { bio: \"second\" } } } })\n * -> (\"seed\", null) the incumbent, orphaned and still in the table\n * (\"second\", 1) the new row takes the link\n *\n * The orphaning is the half that is not guessable, and getting it wrong in\n * the other direction — deleting the displaced row — is silent data loss\n * wearing the same green test. So the differential reads the table back\n * rather than only checking that the call returned.\n *\n * Without the detach the insert simply collides: the child's foreign key\n * carries the `@unique` that makes the relation a to-one, so this was a\n * `UniqueConstraintError` on a call Prisma answers. `create` survived #354\n * because that change was about the operands refused *by name* on this side,\n * and `create` was never one of them — against an *empty* to-one it has\n * always been correct, and no fixture had a to-one whose key is on the child\n * until #358 added one.\n *\n * **`clearLinks`, so the scoping consequence is the same one `set` has** —\n * which is why the two share it. A child hidden by the caller's policies is\n * not detached, and the incumbent then wins the unique key: a\n * `UniqueConstraintError` rather than a silent detach of a row the caller\n * cannot see. Conservative in the direction this file always chooses.\n *\n * A to-many displaces nothing — clearing every child before a nested `create`\n * would be a `set: []` nobody asked for — which is half of what `displaces`\n * decides; see it for the other half and for which operands share this.\n */\n if (key === \"create\") {\n out.after.push({\n relation: relation.name,\n operation: \"create\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n // No row means the statement matched nothing; `update` and `delete`\n // raise before this runs, so there is nothing to attach to.\n if (!parent) return;\n\n // Runs on a parent `create` too, where nothing can be linked yet and it\n // finds nothing. Deliberately not skipped by operation: gemi does not\n // enable SQLite's foreign-key pragma, so \"a row that was just inserted\n // has no children\" is a property of the database's enforcement rather\n // than of the ORM — and a correctness argument resting on a pragma is\n // the kind that holds until someone reads it. One read, on a path that\n // already runs several.\n if (displaces) {\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n }\n\n for (const item of listOf(at(args))) {\n await executor.exec(\n relation.model,\n \"create\",\n {\n // The foreign key is set by us, not by the caller: a nested create\n // that also named it would be describing two different parents.\n data: { ...(item as object), ...childLink(link, parent) },\n // Nothing reads the result, and the narrowest select keeps the\n // returned payload from growing with the child's column count.\n select: keySelect(childFields),\n },\n // NOT pre-scoped — the child's `onCreate` is what scopes this row.\n false,\n );\n }\n },\n });\n return;\n }\n\n /**\n * `createMany`: the same rows as a nested `create`, in **one statement**.\n *\n * The biggest single item on #65 — parent-and-children in one call — and the\n * work is sequencing rather than SQL: `compileCreateMany` already exists, and\n * the parent's `RETURNING` already yields the key the children need. What this\n * step adds is running it once with the key stamped onto every row, instead of\n * once per row.\n *\n * That difference is the point. A nested `create` of forty rows is forty\n * statements; this is one, which is what makes the shape worth porting rather\n * than rewriting into a transaction with explicit foreign keys.\n */\n if (key === \"createMany\") {\n // The mirror of `planOwningSide`'s guard: that one catches a to-one whose\n // foreign key is on *this* row, this one catches a one-to-one whose key is\n // on the child. Same conclusion, different direction, and both reachable.\n if (relation.kind !== \"many\") {\n throw new UnsupportedQueryError(\n `data.${relation.name}.createMany`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one, so there is nothing to create many ` +\n `of. Prisma does not accept it here either.`,\n );\n }\n\n assertCreateManyOperand(schema, relation, operand, operation);\n\n out.after.push({\n relation: relation.name,\n operation: \"createMany\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const items = listOf(at(args)?.data).map((item) => ({\n // Same rule as the nested `create` beside this one: the foreign key\n // is ours to set, not the caller's. Prisma leaves it out of the\n // nested input type entirely, so a row naming it is describing a\n // different parent than the call is.\n ...(item as object),\n ...childLink(link, parent),\n }));\n\n // **No short-circuit on an empty list**, and that is worth the round\n // trip it costs.\n //\n // Returning early here would skip the child's `$exec`, and with it the\n // child's *policies* — so whether the ORM refuses a misconfigured\n // policy would depend on the length of an array at run time. A model\n // carrying a `scope` with no `onCreate` is refused on the call with one\n // row and accepted on the call with none, which means the\n // misconfiguration hides behind data that happens to be empty in\n // development and reports itself on the first request whose list is\n // not. Nothing is written either way, so it is not a leak — it is a\n // refusal that arrives late, which is the thing the rest of the\n // compiler is arranged to prevent by deciding everything from the\n // argument *shape*.\n //\n // The cost is one `select … where false`, which is what\n // `compileCreateMany` emits for an empty list. Prisma does accept the\n // empty list and write nothing — verified — and so does this.\n await executor.exec(\n relation.model,\n \"createMany\",\n { data: items },\n // NOT pre-scoped. `createMany` is in the set an `onCreate` applies\n // to, and it applies per row — so the child's policy stamps the\n // tenant column onto every one of these, exactly as it would for a\n // top-level `createMany`.\n false,\n );\n },\n });\n return;\n }\n\n /**\n * `connectOrCreate` on this side is the pair of branches the owning side has,\n * with `connect` spelled as an update of the child's foreign key.\n *\n * Both branches go through the child's own `$exec`, so both are scoped by the\n * child's policies — and they have to be, in opposite directions: an\n * unscopeable *update* would re-parent another tenant's row, and an unscoped\n * *read* would let a hit reveal that a row with that key exists. Scoped, a\n * hidden row reads as absent and the call creates its own, which is the same\n * answer the caller would get if it truly did not exist.\n */\n if (key === \"connectOrCreate\") {\n // `relation.kind === \"many\"`, not a hardcoded `true`. This side is reached\n // by both kinds — that is the whole of #116 — so a literal here told\n // `assertConnectOrCreateOperand` that a to-one takes a list, and its array\n // guard was unreachable from the one direction that needed it. The outer\n // to-one guard above now refuses the array first; this keeps the function\n // honest about which relation it was asked about rather than relying on\n // the order of two checks.\n assertConnectOrCreateOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n\n out.after.push({\n relation: relation.name,\n operation: \"connectOrCreate\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const list = listOf(at(args));\n\n for (let index = 0; index < list.length; index++) {\n const item = list[index] as Record<string, unknown>;\n\n const found = (await executor.exec(\n relation.model,\n \"findUnique\",\n { where: item.where, select: keySelect(childFields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (found) {\n // **The row is already this parent's, so there is nothing to do.**\n //\n // Free here in a way it is not for the bare `connect` below: the\n // `findUnique` above already selected the child's foreign key, so\n // the comparison costs no statement. `connect` has no such read —\n // giving it the same short-circuit means buying a lookup, which is\n // why it is #372's question rather than this branch's.\n //\n // Without this the pair below is a **clear followed by a repoint of\n // the row the clear just nulled**, and on a child scoped by that\n // same foreign key the clear puts it outside the scope the repoint\n // selects it through — so the operand raises `RecordNotFoundError`\n // on a call that should change nothing. Net-nothing either way for\n // an unscoped child, which is why it stayed hidden; the scoped one\n // is where the wasted statement becomes a wrong answer.\n //\n // `displaces` gates it because that is the only shape the clear\n // runs in. On a to-many there is no clear, so the repoint is one\n // redundant `update` writing the value already there — measured to\n // agree with Prisma, and skipping it would be an unmeasured change\n // to a branch this issue is not about.\n if (\n displaces &&\n childFields.every((field, index) =>\n sameKey(found[field], parent[parentFields[index]]),\n )\n ) {\n continue;\n }\n\n // The hit branch **is** a connect, so it displaces what is linked\n // exactly as the bare operand does (#361) — and the miss branch\n // below does not, which is Prisma's own split rather than a\n // shortcut here. Measured on one fixture: `connectOrCreate` hitting\n // a row orphans the incumbent and takes the link, while the same\n // call missing collides on the child's unique key. See `displaces`.\n if (displaces) {\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n }\n\n await executor.exec(\n relation.model,\n \"update\",\n {\n where: item.where,\n data: childLink(link, parent),\n select: keySelect(childFields),\n },\n // NOT pre-scoped, for the reason the bare `connect` below is not:\n // this repoints an existing child, so the child's scope decides\n // which rows are reachable.\n false,\n // ...and the column is *ours*, the same one and for the same\n // reason (#98). Left off here while `connect` carried it, so one\n // operand spelled two ways answered a child scoped on its own\n // foreign key differently: `connect` went through and this raised\n // `ScopeEscapeError` about a `folderId` the caller never wrote\n // (#373). The hit branch **is** a connect — the docblock above\n // says so for displacement, and provenance follows from the same\n // fact. The miss branch below needs no marker: it creates the far\n // row, so there is no caller-supplied key to tell ours apart from.\n childFields,\n );\n continue;\n }\n\n await executor.exec(\n relation.model,\n \"create\",\n {\n // The foreign key is ours, not the caller's — the same rule the\n // nested `create` above follows, and Prisma leaves it out of the\n // nested input type entirely.\n data: { ...(item.create as object), ...childLink(link, parent) },\n select: keySelect(childFields),\n },\n false,\n );\n }\n },\n });\n return;\n }\n\n // `connect` on this side means \"point that existing row at me\", which is an\n // update of the child's foreign key — not something this row's insert can do.\n //\n // Checked here rather than in the step below, for the reason `assertNamedRows`\n // gives: the step runs after the parent row is written, so a key the child\n // does not declare unwinds an insert that should never have happened. The\n // owning side has always checked its `connect` at plan time; this side had\n // not, which made the same operand answer differently depending on which\n // table the foreign key is on (#110).\n assertNamedRows(schema, relation, child, operand, key, operation);\n\n /**\n * **On a to-one this repoint has to displace what is linked already** (#361),\n * the same way the nested `create` beside it does and through the same\n * `clearLinks`. Without it the child's `@unique` foreign key rejects the\n * second link, so `connect` was a `UniqueConstraintError` on a call Prisma\n * answers by orphaning the incumbent.\n *\n * Measured across the four shapes, because only one of them diverged and the\n * other three are what kept it hidden:\n *\n * connect onto an empty to-one attaches agreed already\n * connect a child of another parent repoints it agreed already\n * connect the row already linked here writes nothing see below\n * connect onto an occupied to-one displaces the divergence\n *\n * **The third is the one the clear and the link cross on, and #361 got it\n * right in the table and wrong in the statements** (#372). `clearLinks` nulls\n * the very row the caller named and the repoint puts the key straight back,\n * so the committed state agrees — and that is all `M15b` could see. The two\n * statements in between are not harmless. **The repoint has to re-select the\n * row by the column the clear just changed, so it fails whenever anything in\n * that `where` depends on the old value** — and there are two ways to get\n * one, not just the policy shape #372 was reported through:\n *\n * - a child whose policy scopes on *its own foreign key*\n * (`{ folderId: 2 }`) — the scope is `AND`ed into the repoint's `where`,\n * and the clear has just moved the row out of it;\n * - **no policy anywhere**, when the caller names the row *by* that foreign\n * key (`connect: { folderId: 2 }`). `assertNamedRows` accepts that\n * operand because the column is in `uniques`, which is the same fact that\n * makes the relation a to-one in the first place — and then the caller's\n * own `where` is the thing the clear invalidates.\n *\n * Either way the repoint matches nothing and the whole call raises\n * `RecordNotFoundError` naming a model and an operation the caller never\n * wrote. A call that worked before #361. The second shape is what makes this\n * a plain correctness bug rather than a policy interaction, and it is why the\n * differential can pin it at all: `M15e` in `writes.differential.test.ts` is\n * that spelling, `error` against `ok`, with no policy in it.\n *\n * So the named row is resolved first and the operand short-circuits when it\n * already points here — {@link alreadyLinked}. That is Prisma's own shape\n * rather than a repair invented for the scope: measured on 6.19.2/SQLite with\n * query logging, `folder.update({ data: { cover: { connect: { id: 30 } } } })`\n * where cover 30 already holds folder 2 logs **four selects and no `UPDATE`**\n * between its `BEGIN` and `COMMIT`, where the same call onto an occupied\n * folder logs the incumbent clear and the repoint. The lookup itself is\n * Prisma's too — every `connect` above begins by selecting the operand's row\n * with its foreign key in the projection.\n *\n * #361 declined this as \"a lookup on every `connect` to save one write on a\n * rare one\", which was the right trade for the fact it had in view. Two\n * things changed it: the write it saves is a live failure rather than a\n * redundancy, and the lookup is not on every `connect` — only where\n * `displaces` holds, which is a to-one, so every many-to-one and every\n * to-many `connect` costs exactly what it did.\n *\n * **A miss detaches nothing**, which is Prisma's answer (P2025, nothing\n * written) and is not a special case here: a row the lookup cannot find is\n * left to the repoint, which raises, and the clear is inside the transaction\n * the nested steps already run in. That covers the row that does not exist\n * and the row this caller's policies hide alike — both read as absent, and\n * both get the answer they had before this change.\n */\n out.after.push({\n relation: relation.name,\n operation: \"connect\",\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n // `displaces` is only ever true on a to-one, where the array spelling is\n // refused above — so this is one extra select at most, never one per item.\n const pending: unknown[] = [];\n for (const item of listOf(at(args))) {\n if (\n displaces &&\n (await alreadyLinked(\n relation.model,\n childFields,\n item,\n valuesOf(parent, parentFields),\n executor,\n ))\n ) {\n continue;\n }\n pending.push(item);\n }\n\n // Nothing left to link means nothing to displace either: the only row that\n // could hold this parent's key is the one the caller named, and it holds\n // it already. Returning here is what makes the call write nothing at all.\n if (pending.length === 0) return;\n\n if (displaces) {\n await clearLinks(\n relation.model,\n childFields,\n valuesOf(parent, parentFields),\n executor,\n );\n }\n\n for (const item of pending) {\n await executor.exec(\n relation.model,\n \"update\",\n {\n where: item,\n data: childLink(link, parent),\n select: keySelect(childFields),\n },\n // NOT pre-scoped. Repointing an existing row at this parent is a write\n // to the child, and the child's scope decides which rows are reachable\n // — otherwise `connect` re-parents another tenant's row.\n false,\n // ...and the columns being written are *ours*, not the caller's.\n // Without this, a child whose policy scopes on its foreign key is\n // refused for a write it never made — see #98 and\n // `ormAuthoredFields`.\n childFields,\n );\n }\n },\n });\n}\n\n/**\n * What an implicit many-to-many accepts, and how it differs from\n * {@link SUPPORTED} — which is the ordinary-relation set.\n *\n * **The two must be reconciled deliberately.** `planOne` checks `link.join`\n * first and returns, so this path never consults `SUPPORTED` at all: the sets\n * drift without anything failing to compile and without a test noticing, and\n * they did — #83 landed this one while four branches were adding to the other,\n * none of which could see it from inside itself.\n *\n * **The gaps are unimplemented, not by design, and that is measured rather than\n * reasoned.** An earlier version of this comment claimed the split was \"the\n * link versus the far row\" — operands about the pair work here, operands about\n * the far row do not. It is a tidy rule and it is wrong. Prisma offers five of\n * the six through an implicit m-n:\n *\n * update OK the far row is updated\n * delete OK the far row is deleted, not just the pair\n * deleteMany OK\n * updateMany OK\n * connectOrCreate OK\n * createMany Unknown argument — Prisma refuses it here too\n *\n * So `delete` through a join table really does mean deleting the far row, which\n * is the opposite of what that rule predicted. Only `createMany` is a genuine\n * refusal, and it is Prisma's rather than ours.\n *\n * `connectOrCreate` is implemented here because #83 already had both of its\n * halves — `connect` inserts a pair for an existing row, `create` writes the\n * row and its pair — so it is those two selected by a lookup. The remaining\n * four reach the far row *through* the pairs, which is a second hop this path\n * does not have yet; {@link JOIN_TABLE_REFUSED} says so in those terms rather\n * than inventing a principle.\n *\n * `set` is the one operand with **two implementations** — this file's\n * join-table version from #83 and the ordinary-relation one — and they agree\n * because both were reasoned to \"replace the set I can see\" independently, not\n * because they share anything. Worth knowing when either is changed.\n */\nconst JOIN_TABLE_SUPPORTED = new Set([\n \"connect\",\n \"connectOrCreate\",\n \"disconnect\",\n \"set\",\n \"create\",\n]);\n\n/**\n * Why each ordinary-relation operand is not offered through a join table.\n *\n * Same shape as {@link REFUSED}, and for the same reason: \"not implemented\" is\n * much less useful than knowing whether the thing you reached for is a rewrite\n * or a wait — and here most of them are neither, they are a different operation\n * wearing the same name.\n */\nconst JOIN_TABLE_REFUSED: Record<string, string> = {\n // Prisma's own refusal, not this ORM's — the one entry here that is a\n // decision rather than a gap, and it is not gemi's decision.\n createMany:\n `Prisma does not offer 'createMany' through an implicit many-to-many ` +\n `either — it reports it as an unknown argument. Use 'create', which writes ` +\n `the row and its pair.`,\n // The four that reach the far row through the pairs. Prisma implements all\n // of them; this path does not have the second hop yet.\n update:\n `Reaching the far row means reading the pairs first, which this path does ` +\n `not do yet. Update the related model directly, filtered by its own key.`,\n updateMany:\n `As 'update': it needs the pairs read before the far rows can be matched.`,\n delete:\n `It deletes the far row rather than the pair — Prisma does this through a ` +\n `join table too — and reaching it means reading the pairs first, which ` +\n `this path does not do yet. Use 'disconnect' to remove the link, or delete ` +\n `the row through its own model.`,\n deleteMany:\n `As 'delete': the far rows have to be found through the pairs first.`,\n};\n\n/**\n * Writes through Prisma's implicit many-to-many join table.\n *\n * The table has **no model**: no registered class, no generated base, no\n * `$schema` — just `_PostToTag` with an `A` and a `B` column, named from the\n * two model names in alphabetical order, with the pair as its primary key. So\n * the two operands that work for an ordinary relation have nothing to compile\n * *to*, and these statements are emitted directly, the way the read side's\n * `readPairs` already does.\n *\n * Which column is which end comes from `resolveLink`, never from declaration\n * order. That distinction is invisible on `Post` / `Tag` and wrong on a\n * self-relation, where both ends are the same model and only the *field* name\n * separates them.\n *\n * Every operand is an `after` step: the pair cannot be written until this row\n * has a key. Two of them are more than one statement — `set` deletes before it\n * inserts — and `$exec` already opens a transaction for any plan carrying\n * steps, so the whole thing is atomic.\n *\n * **The rows the pairs point at are still read and written through the child's\n * own `$exec`**, so a `connect` cannot reach a row the child's policies hide,\n * and a `create` gets the child's `onCreate`. Only the join table itself —\n * which has no model and nothing an application could scope — is written\n * directly.\n */\nfunction planJoinTable(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n link: { parentField: string; childField: string; join?: Link[\"join\"] },\n key: string,\n operand: unknown,\n operation: string,\n at: (args: any) => any,\n out: NestedWritePlanning,\n dialect: SqlDialect,\n): void {\n if (key === \"connectOrCreate\") {\n assertConnectOrCreateOperand(\n schema,\n relation,\n child,\n operand,\n operation,\n relation.kind === \"many\",\n );\n }\n\n if (!JOIN_TABLE_SUPPORTED.has(key)) {\n const why = JOIN_TABLE_REFUSED[key];\n if (why) {\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is an implicit many-to-many, and '${key}' means ` +\n `something different through a join table. ${why}`,\n );\n }\n\n throw new UnsupportedQueryError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is an implicit many-to-many. Only ` +\n `${[...JOIN_TABLE_SUPPORTED].sort().join(\", \")} are implemented ` +\n `through its join table.`,\n );\n }\n\n // `connect`, `disconnect` and `set` name existing rows by a unique key, and\n // the step below resolves them one at a time — after the parent row exists,\n // since a pair needs both ends. That made a key the child does not declare\n // refuse from mid-transaction, while the *same* operand on an ordinary\n // relation refuses from the compiler (#110). `create` names no existing row\n // and `connectOrCreate` is checked above, so those two are not this.\n if (key === \"connect\" || key === \"disconnect\" || key === \"set\") {\n assertNamedRows(schema, relation, child, operand, key, operation);\n }\n\n const join = link.join!;\n const parentField = link.parentField;\n const childField = link.childField;\n\n // `dialect.quoteIdent`, not a local helper. It does the same escaping *and*\n // rejects a NUL byte, which exists because NUL is the parameter sentinel in\n // `compile/fragment.ts`. Prisma generates these identifiers so nothing can\n // reach that check today — but this is the one file emitting SQL without the\n // `Fragment` pipeline, which makes it the one most worth holding to the rule\n // rather than the one to excuse from it.\n const quoted = (name: string) => dialect.quoteIdent(name);\n\n out.keyFields.push(parentField);\n\n out.after.push({\n relation: relation.name,\n // The operand this step implements, not a two-way split of it. This read\n // `key === \"create\" ? \"create\" : \"connect\"`, which labelled `disconnect`,\n // `set` and `connectOrCreate` as `connect` — the first of those being the\n // opposite operation. The field exists so a plan is legible from the\n // outside, so a wrong label is the whole of its cost.\n operation: key as NestedWriteStep[\"operation\"],\n async run(args, _context, executor, rows) {\n const parent = rows[0];\n if (!parent) return;\n\n const parentKey = parent[parentField];\n if (parentKey === null || parentKey === undefined) return;\n\n // `set` replaces the whole set, so what is there now goes first — but\n // **only the part of it this caller can see**.\n //\n // A bare `delete … where \"A\" = ?` removes every pair, including ones\n // pointing at children the child model's policies hide, and nothing on\n // that path consults the child. `disconnect` right below refuses the same\n // effect when it is named explicitly — it resolves through the child's\n // own `findUniqueOrThrow`, which raises for a row the caller cannot see —\n // so an unscoped `set` would make the authorization boundary disagree\n // with itself depending on which operand you reached for.\n //\n // Not a read leak: nothing comes back, and the caller cannot tell a\n // hidden link existed. It is an unscoped *write* to state they could not\n // otherwise reach, which is the thing this layer exists to prevent.\n //\n // So the existing links are read, filtered through the child's own\n // `findMany` — where its scope applies exactly as it does anywhere else —\n // and only those are deleted. `set` therefore means \"replace the set I\n // can see\", which is what every other policy in this ORM does: narrow,\n // never widen. With no policy on the child, every link is visible and\n // this is byte-for-byte the old behaviour, so Prisma parity is unchanged\n // wherever there is no policy to apply.\n if (key === \"set\") {\n const linked = (await executor.query(\n `select ${quoted(join.childColumn)} from ${quoted(join.table)} ` +\n `where ${quoted(join.parentColumn)} = ${dialect.placeholder(0)}`,\n [parentKey],\n )) as Record<string, unknown>[];\n\n const existing = Array.from(linked, (row) => row[join.childColumn]);\n\n if (existing.length > 0) {\n const visible = (await executor.exec(\n relation.model,\n \"findMany\",\n {\n where: { [childField]: { in: existing } },\n select: { [childField]: true },\n },\n // NOT pre-scoped: the child's scope is the whole point here.\n false,\n )) as Record<string, unknown>[];\n\n // One statement, not one per link. The scoped form is a `delete`\n // over an `in` list rather than a loop, because this repo counts\n // *statements*: `plans/orm/benchmarks.md` measures include trees that\n // way, and the lateral strategy exists to remove `N - 1` of them. A\n // loop here would have made `set` the one write that reintroduces\n // them — invisible on SQLite, where round trips are in-process, and\n // paid in full on Postgres, where they are not.\n //\n // Placeholders are built per length rather than bound as one array\n // parameter. `dialect.inList` does the latter on Postgres, but it\n // returns a `Fragment` and this is the one path that emits SQL\n // without that pipeline — there is no model to route the join table\n // through. The cost is one server-side plan per distinct link count;\n // the ORM's own plan cache is unaffected, since it keys on the\n // argument shape and this text never reaches it.\n const targets = Array.from(visible, (row) => row[childField]);\n\n // Every existing link points at a row this caller cannot see, so\n // there is nothing to clear and `in ()` is a syntax error on both\n // dialects. The loop this replaced degenerated to zero iterations\n // here; the single statement has to say so explicitly.\n if (targets.length > 0) {\n await runPairStatement(\n executor,\n `delete from ${quoted(join.table)} where ` +\n `${quoted(join.parentColumn)} = ${dialect.placeholder(0)} and ` +\n `${quoted(join.childColumn)} in (` +\n targets\n .map((_, index) => dialect.placeholder(index + 1))\n .join(\", \") +\n `)`,\n [parentKey, ...targets],\n );\n }\n }\n }\n\n const items = listOf(at(args));\n if (items.length === 0) return;\n\n const childKeys: unknown[] = [];\n\n for (const item of items) {\n if (key === \"create\") {\n const created = (await executor.exec(\n relation.model,\n \"create\",\n { data: item, select: { [childField]: true } },\n // NOT pre-scoped: the child's own `onCreate` is what scopes the row.\n false,\n )) as Record<string, unknown> | null;\n if (created) childKeys.push(created[childField]);\n continue;\n }\n\n /**\n * `connectOrCreate` is the two branches above selected by a lookup, so\n * it needed no new machinery here — which is why it is the one of the\n * five missing operands this change adds.\n *\n * `findUnique`, not the `findUniqueOrThrow` the `connect` path below\n * uses: a miss is the *other branch* here rather than an error. And a\n * scoped-away hit therefore takes the create branch, which is the same\n * answer the ordinary-relation `connectOrCreate` gives and closes the\n * same probe — `connect` raising where this succeeds would together\n * confirm a row the caller cannot see.\n */\n if (key === \"connectOrCreate\") {\n // The `where` was validated at plan time by\n // `assertConnectOrCreateOperand`, which the branch at the top of this\n // function runs for both relation kinds.\n const entry = item as Record<string, unknown>;\n\n const hit = (await executor.exec(\n relation.model,\n \"findUnique\",\n { where: entry.where, select: { [childField]: true } },\n false,\n )) as Record<string, unknown> | null;\n\n if (hit) {\n childKeys.push(hit[childField]);\n continue;\n }\n\n const made = (await executor.exec(\n relation.model,\n \"create\",\n { data: entry.create, select: { [childField]: true } },\n false,\n )) as Record<string, unknown> | null;\n if (made) childKeys.push(made[childField]);\n continue;\n }\n\n // `connect`, `disconnect` and `set` all name existing rows by a unique\n // key — checked at plan time above. Resolved through the child's own\n // `$exec`, so its policies decide which rows exist — otherwise a\n // connect by any unique key reaches every tenant's.\n const found = (await executor.exec(\n relation.model,\n \"findUniqueOrThrow\",\n { where: item, select: { [childField]: true } },\n false,\n )) as Record<string, unknown> | null;\n if (found) childKeys.push(found[childField]);\n }\n\n for (const childKey of childKeys) {\n if (key === \"disconnect\") {\n await runPairStatement(\n executor,\n `delete from ${quoted(join.table)} where ` +\n `${quoted(join.parentColumn)} = ${dialect.placeholder(0)} and ` +\n `${quoted(join.childColumn)} = ${dialect.placeholder(1)}`,\n [parentKey, childKey],\n );\n continue;\n }\n\n // `on conflict do nothing`, because the pair is the join table's\n // primary key and Prisma treats a repeated `connect` as a no-op rather\n // than an error. Without it the second connect of the same pair is a\n // raw driver unique violation, which is neither Prisma's behaviour nor\n // a useful one. Both dialects spell it the same way — SQLite has had it\n // since 3.24 — so this needs no dialect branch.\n await runPairStatement(\n executor,\n `insert into ${quoted(join.table)} ` +\n `(${quoted(join.parentColumn)}, ${quoted(join.childColumn)}) ` +\n `values (${dialect.placeholder(0)}, ${dialect.placeholder(1)}) ` +\n `on conflict do nothing`,\n [parentKey, childKey],\n );\n }\n },\n });\n}\n\n/**\n * One statement against a table with no model, on the connection this call\n * resolved — which is what keeps it inside the caller's transaction.\n *\n * Placeholders come from the dialect rather than being hardcoded, for the same\n * reason `readPairs` renders its statement: SQLite writes `?` and Postgres\n * `$1`, and this path has no `Fragment` pipeline to do it automatically.\n */\nasync function runPairStatement(\n executor: { query(text: string, values: unknown[]): Promise<unknown> },\n text: string,\n values: unknown[],\n): Promise<void> {\n await executor.query(text, values);\n}\n\n/**\n * `upsert`'s operand: `{ where, create, update }`, or a list of them.\n *\n * The two payloads are always required — one per branch. **The `where` is\n * required only on a to-many**, which is Prisma's own split rather than a\n * looseness: `AccountUpsertWithWhereUniqueWithoutUserInput` has `where:\n * AccountWhereUniqueInput`, while `ProfileUpsertWithoutUserInput` is\n * `{ update, create, where? }` — the to-one already knows which row it means,\n * because the parent's key names it. So the unique-key match is skipped there\n * too: a to-one `where` is a `WhereInput` filter narrowing the single linked\n * row, not a key selecting one out of many.\n *\n * Checked at plan time like every other operand here, so a missing key fails\n * when the query compiles rather than after the parent row is written.\n */\nfunction assertUpsertOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n operation: string,\n many: boolean,\n): void {\n const at = `data.${relation.name}.upsert`;\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n many\n ? `Expected an object with 'where', 'create' and 'update'.`\n : `Expected an object with 'create' and 'update' — on a to-one the ` +\n `'where' is optional, since the parent's key already names the row.`,\n );\n }\n\n const record = entry as Record<string, unknown>;\n const required = many\n ? ([\"where\", \"create\", \"update\"] as const)\n : ([\"create\", \"update\"] as const);\n\n for (const name of required) {\n if (record[name] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${name}' key — 'upsert' names the row to look for, ` +\n `what to write if it is there, and what to write if it is not.`,\n );\n }\n }\n\n if (!many) continue;\n\n matchUniqueKey(child, record.where, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.upsert.where`,\n });\n }\n}\n\n/**\n * The caller's filter and the parent restriction, as a conjunction.\n *\n * Never a spread. A spread merges by *key*, so a caller naming the foreign key\n * column silently replaces the restriction that keeps the operand on this\n * parent's rows — and the failure is a wider write, not an error. `AND` cannot\n * be overwritten by any key the caller chooses, and it still lets their\n * predicate narrow, which is the property `withScope` relies on for policy\n * fragments.\n *\n * An empty or absent filter contributes nothing, so the common case is the\n * restriction alone rather than `AND` of one thing.\n */\nfunction conjoin(\n filter: unknown,\n restriction: Record<string, unknown>,\n): Record<string, unknown> {\n if (\n filter === undefined ||\n filter === null ||\n typeof filter !== \"object\" ||\n Array.isArray(filter) ||\n Object.keys(filter as object).length === 0\n ) {\n return restriction;\n }\n return { AND: [filter as object, restriction] };\n}\n\n/**\n * The three shapes a link takes in an argument object, and the two questions\n * asked about its *values* — written once so that a relation joining on four\n * fields goes down the same path as one joining on one (#271).\n *\n * Before these, every site spelled the link as `{ [childField]: parent[\n * parentField] }` or `select: { [childField]: true }` by hand, in about forty\n * places across the two sides. Generalising each of them separately is how a\n * composite relation ends up correlating on every field in nine operands and on\n * the first field in the tenth — a silent wrong write, which is precisely what\n * the refusal these replace was protecting against. One function per shape\n * means the count of fields is invisible to the callers, so there is no\n * single-field spelling left for a new operand to copy.\n */\n\n/**\n * `{ <childField>: row[<parentField>], … }` — the far side's columns bound to\n * the values this row holds.\n *\n * On the foreign side that reads as \"belonging to this parent\": the child's\n * foreign key set to the parent's key. On the owning side the same call reads\n * as \"the row this one points at\": `link.parentFields` are this row's foreign\n * key and `link.childFields` are what they reference, so the object is the far\n * row's own columns. One function, because the arithmetic is identical and the\n * two sides differ only in which table the result is applied to.\n *\n * An object with several keys is a conjunction in every `where` this ORM\n * compiles, and several assignments in every `data`, so the same shape serves\n * both — which is why `create`, `connect`, `update`, `delete` and the two\n * `*Many` operands can all take it unchanged.\n */\nfunction childLink(\n link: { parentFields: string[]; childFields: string[] },\n parent: Record<string, unknown>,\n): Record<string, unknown> {\n const key: Record<string, unknown> = {};\n for (let index = 0; index < link.childFields.length; index++) {\n key[link.childFields[index]] = parent[link.parentFields[index]];\n }\n return key;\n}\n\n/** `{ <field>: true, … }` — the narrowest select that reads a whole link back. */\nfunction keySelect(fields: readonly string[]): Record<string, true> {\n const select: Record<string, true> = {};\n for (const field of fields) select[field] = true;\n return select;\n}\n\n/** `{ <field>: null, … }` — a detach, which has to clear *every* column. */\nfunction nullKey(fields: readonly string[]): Record<string, null> {\n const cleared: Record<string, null> = {};\n for (const field of fields) cleared[field] = null;\n return cleared;\n}\n\n/** The same detach spelled as *values* rather than as a `data` object. */\nfunction nullsFor(fields: readonly string[]): null[] {\n return fields.map(() => null);\n}\n\n/** The values of `fields` on `row`, positionally. */\nfunction valuesOf(\n row: Record<string, unknown> | null | undefined,\n fields: readonly string[],\n): unknown[] {\n return fields.map((field) => row?.[field]);\n}\n\n/**\n * Whether a link's columns actually name a row.\n *\n * **A partially-null composite key links nothing**, which is SQL's rule and not\n * a choice made here: `(tenantId, orderId) = (1, NULL)` is `UNKNOWN`, so the\n * join finds no row however many other columns match. Prisma agrees at the\n * type level — an optional relation over composite fields makes *all* of them\n * optional together, and `include` on a row holding `(1, NULL)` returns `null`.\n *\n * So every place that used to test one value for `null` — \"is anything linked\n * here\" — tests the whole key through this, and a half-written key reads as\n * *absent* rather than as a link to a row that does not exist. Getting this\n * backwards is what would make `clearLinks` null the key of every unlinked row\n * in the table, and `disconnect`'s filter arm read a child by a `NULL` key.\n */\nfunction isLinked(values: readonly unknown[]): boolean {\n return values.every((value) => value !== null && value !== undefined);\n}\n\n/**\n * Null the foreign-key columns of every row that currently holds `values` **and\n * that the caller can see** — the clearing half of `set`, the half a nested\n * `create` on an occupied to-one needs before it can insert (#360), and the\n * half the owning side's `connect` needs before it can repoint (#363).\n *\n * Shared rather than written three times because the *scoping* is the\n * interesting part and it has to be identical on all of them: the read goes\n * through the target model's own `findMany` un-pre-scoped, so a row that\n * model's policies hide is not detached. `set` therefore means \"replace the set\n * I can see\" (#83), the nested `create` means \"displace the child I can see\",\n * and the owning-side `connect` means \"displace the sibling I can see\" — with a\n * hidden incumbent the insert or repoint collides on the unique key instead,\n * which is the conservative answer rather than a silent detach of somebody\n * else's row.\n *\n * **`model` is a parameter rather than `relation.model` because the two\n * directions clear different tables.** On the foreign side the rows holding the\n * key belong to the *child*; on the owning side they are siblings of the row\n * being written, in the model the statement is already about. Same statement\n * pair, same scoping rule, two tables — so the only thing that varies is which\n * one, and passing it is what let #363 reuse this instead of restating it.\n *\n * The `findMany` decides whether to issue the write at all. The `updateMany`\n * would match the same rows on its own; what the read adds is that the common\n * case — nothing linked — costs a select rather than an update, and that the\n * scope is consulted through a read before anything is written.\n *\n * `fields` is ORM-authored: the caller named a row to `set`, or a payload to\n * `create`, or a row to `connect`, and the ORM chose to null these columns.\n * Without it a model scoped on one of them is refused by the scope-escape guard\n * for a write it never made — #98, and the reason `disconnect` one operand over\n * passes the same list. **Every** column of the link goes in it, because a\n * composite key is cleared by writing null to all of them and each one is as\n * much the ORM's as the first.\n *\n * **A key with a null component clears nothing** (#271), and the guard is not\n * defensive tidying. `where: { tenantId: 1, orderId: null }` matches every row\n * whose order is unset in that tenant — rows linked to *nothing*, which is the\n * opposite of the set this is asked for — and the `updateMany` behind it would\n * then write null over null across all of them. See {@link isLinked}. Nothing\n * reaches here with a null today (`displaceSibling` returns first, and the\n * foreign side reads its values out of a primary key), so this buys no\n * behaviour; it means a caller that one day does cannot silently rewrite the\n * table.\n */\nasync function clearLinks(\n model: string,\n fields: readonly string[],\n values: readonly unknown[],\n executor: RelationExecutor,\n): Promise<void> {\n if (!isLinked(values)) return;\n\n const where: Record<string, unknown> = {};\n for (let index = 0; index < fields.length; index++) {\n where[fields[index]] = values[index];\n }\n\n const linked = (await executor.exec(\n model,\n \"findMany\",\n { where, select: keySelect(fields) },\n false,\n )) as Record<string, unknown>[];\n\n if (linked.length === 0) return;\n\n await executor.exec(\n model,\n \"updateMany\",\n { where, data: nullKey(fields) },\n false,\n fields,\n );\n}\n\n/**\n * **Whether the row a `connect` named already points at this parent** — the\n * question that turns a clear-then-repoint into no statements at all (#372).\n *\n * The foreign-side twin of the `sameKey` test inside {@link displaceSibling},\n * and the same answer read from the other end of the key: on the owning side\n * the row that must not be cleared is the one being written, here it is the one\n * being named. Both exist because clearing a row and then selecting it by the\n * column just cleared is a contradiction the moment anything in that `where`\n * depends on the old value — a policy scoping on the column, or a caller who\n * named the row by it.\n *\n * **Prisma issues no write for an already-linked `connect` from either end, and\n * only this end matches that outright.** The owning side skips the *clear* and\n * still emits the repoint — {@link displaceSibling}'s docblock says so in plain\n * terms, and that residual divergence is #370's class, not something #363/#375\n * closed. Do not read the symmetry above as parity.\n *\n * **Un-pre-scoped, so the child's own policies decide what this can see** — the\n * same rule every other statement in this step follows, and it is what makes\n * the miss answer fall out rather than needing a branch. A row that does not\n * exist and a row this caller cannot see both read as absent, so both are\n * treated as \"not linked here\" and left to the repoint, which raises\n * `RecordNotFoundError` for them exactly as it did before.\n *\n * Getting that direction backwards would be the expensive mistake: a lookup\n * that ignored the scope could answer \"already linked\" for another tenant's row\n * and make the whole operand a silent no-op, which is a `connect` that reports\n * success and links nothing.\n *\n * `findUnique` rather than `findFirst` because `assertNamedRows` has already\n * run `matchUniqueKey` over this operand — the same lookup, and the same\n * spelling, that `connectOrCreate`'s hit branch uses one screen up.\n */\nasync function alreadyLinked(\n model: string,\n fields: readonly string[],\n where: unknown,\n values: readonly unknown[],\n executor: RelationExecutor,\n): Promise<boolean> {\n const named = (await executor.exec(\n model,\n \"findUnique\",\n { where, select: keySelect(fields) },\n false,\n )) as Record<string, unknown> | null;\n\n if (named === null || named === undefined) return false;\n\n // **`every`, not `some`** — the row is already linked here only if the whole\n // key matches. A composite key agreeing on one column and not the rest points\n // somewhere else entirely, and short-circuiting on it would skip a repoint\n // that has to happen. This is the one site of #386's generalisation that is\n // not a rename: `sameKey` compares a single value, so the fold belongs here.\n return fields.every((field, index) => sameKey(named[field], values[index]));\n}\n\n/**\n * **Detach the sibling that already holds this foreign-key value, so the row\n * being written can take it** — the owning side of #361's displacement, and the\n * whole of #363.\n *\n * The two directions look alike and are not the same operation. On the foreign\n * side the incumbent is a row of the *child* model, reached through\n * `planForeignSide`; here it is a row of the model the statement is already\n * writing, one `@unique` foreign key away. `clearLinks` is shared between them\n * because the statement pair and the scoping rule are identical; everything\n * below is what only this side needs.\n *\n * Measured against Prisma 6.19.2 on SQLite before it was written, with query\n * logging on. `Profile.update({ where: { id: 1 }, data: { user: { connect:\n * { id: 2 } } } })` where user 2's profile is taken issues, in order:\n *\n * select User.id where id = 2 resolve the operand\n * select Profile.* where id = 1 the row being written\n * select Profile.id, userId where userId in (2) the incumbent\n * update Profile set userId = null where id in (2) detach it\n * update Profile set userId = 2 where id in (1) take the link\n *\n * all inside one `BEGIN IMMEDIATE` / `COMMIT`. The incumbent is left in the\n * table with a null key — **orphaned, not deleted** — which is the half a fix\n * in the wrong direction turns into silent data loss wearing a green test.\n *\n * **Why the row being written is skipped: because Prisma skips it too.**\n * `connect`ing the far row a caller is already connected to writes *nothing at\n * all* — measured with logging on, the whole call is\n *\n * BEGIN IMMEDIATE / select the operand / select this row /\n * select the operand again / select this row again / COMMIT\n *\n * with no `update` in it. So this is not a departure to be justified; it is the\n * behaviour. (An earlier draft of this docblock claimed Prisma nulls the column\n * and writes the same value straight back for a net nothing. It does not, and\n * the claim survived into four places before it was measured rather than\n * reasoned about.)\n *\n * The skip matters *more* here than it would as mere parity, which is worth\n * keeping: the repoint on this side is not a statement of its own but a\n * contribution to the main statement, whose `where` has already been through\n * this model's policies. A model scoped on the foreign key would have its own\n * row put outside that scope by a clear, so the main statement would match\n * nothing and leave the row detached and never re-attached — a silent\n * half-write, #98's hazard arriving on this side, and the same argument #362\n * used to leave `set`'s *link* half not naming its column.\n *\n * **The residual divergence runs the other way and is not fixed here.** Prisma\n * makes the whole call a no-op; gemi still emits the repoint `UPDATE`, because\n * the contribution is in the SET list at compile time and cannot be withdrawn\n * at bind time. Same rows either way — it writes the value already there — but\n * on a one-to-one owner carrying `@updatedAt` gemi bumps the stamp where Prisma\n * leaves it. That is an instance of the stamp divergence #370 documented rather\n * than a new one, no fixture can see it (neither `Profile` nor `Cover` has the\n * column), and it is specific to *this* path: on a many-to-one both clients\n * issue the update and both stamp.\n *\n * **Why a `create` reads nothing.** There is no row yet, so there is no self to\n * be the incumbent and no `where` to read one through.\n *\n * **Why an absent parent detaches nothing, which is belt and braces and is\n * kept anyway.** Prisma *does* detach and then rolls the whole thing back —\n * measured on `update({ where: { id: 99 } })`, which logs the\n * `update … set userId = null`, then `ROLLBACK`, then answers P2025. gemi\n * reaches the same committed state by the same route, because `update` raises\n * `RecordNotFoundError` on a `where` that matches nothing and every plan\n * carrying a step runs in a transaction — verified by dropping this return and\n * watching `O12g` stay green. So it buys no correctness today; it buys two\n * statements on a miss, and it makes this step's effect independent of whether\n * the statement *after* it raises, which is the assumption that would be\n * expensive to have baked in silently if that ever changed.\n */\nasync function displaceSibling(\n schema: ModelSchema,\n fkFields: readonly string[],\n /**\n * The values about to be written into this row's foreign key, positionally\n * paired with `fkFields`.\n *\n * **A key with a null component displaces nothing**, which is the composite\n * generalisation of the `value === null` return this has always had rather\n * than a new rule: the row is being *un*linked, and there is no incumbent for\n * a link that is not being made. See {@link isLinked}.\n */\n values: readonly unknown[],\n /**\n * This statement's own `where`, **already through this model's policies** —\n * so the read below is pre-scoped, exactly as the `disconnect` filter arm's\n * parent read is, and for the same reason: applying them again would `AND`\n * the same predicate twice.\n */\n where: unknown,\n /** False on a `create`, where the row does not exist yet. */\n existing: boolean,\n executor: RelationExecutor,\n): Promise<void> {\n if (!isLinked(values)) return;\n\n if (existing) {\n const self = (await executor.exec(\n schema.name,\n \"findFirst\",\n { where, select: keySelect(fkFields) },\n true,\n )) as Record<string, unknown> | null;\n\n if (self === null || self === undefined) return;\n // **Every column, not the first that differs** — the skip is \"this row\n // already points at that row\", and on a composite key that is only true\n // when the whole tuple matches. Reading it as \"some column matches\" would\n // skip the clear for a sibling holding `(1, \"b\")` while this row takes\n // `(1, \"a\")`, and the repoint would then collide on the unique index the\n // caller cannot see.\n if (fkFields.every((field, index) => sameKey(self[field], values[index]))) {\n return;\n }\n }\n\n await clearLinks(schema.name, fkFields, values, executor);\n}\n\n/**\n * Whether two foreign-key values name the same row.\n *\n * Not `===`, because the two operands reach this from different places and a\n * key type can survive the trip differently. One side is read out of the\n * database through a `select`; the other is either a caller's literal — `connect:\n * { id: 2 }`, taken straight from the argument tree by the direct form — or a\n * value read back off the far model. A `BigInt` key is the case that makes this\n * concrete rather than theoretical: `2n === 2` is `false`, and answering \"these\n * are different rows\" there is what would make the clear fire on the row it is\n * meant to skip.\n *\n * The fallback is deliberately loose in the other direction too — it calls the\n * number `2` and the string `\"2\"` the same row. Harmless for every key type in\n * reach: Prisma's unique keys are `Int`, `BigInt`, `String`, `Bytes` and the\n * date types, and a `String` key whose value is `\"2\"` can only be compared\n * against another `String`, since the column it came from decides both sides.\n * Stated rather than tightened, because the tightening would have to know the\n * field's type here and the looseness has no reachable victim.\n */\nfunction sameKey(a: unknown, b: unknown): boolean {\n if (a === null || a === undefined || b === null || b === undefined) {\n return false;\n }\n return a === b || String(a) === String(b);\n}\n\n/**\n * The filter operands, which are shaped differently from each other.\n *\n * `updateMany` wraps its filter in `where` and carries a `data` beside it;\n * `deleteMany` *is* the filter. Checked at plan time, so a caller who wrote one\n * shape for the other hears about it before the parent row is written.\n *\n * `UnsupportedQueryError` here because that is what this branch has; both are\n * argument *validation* and belong in #103's `InvalidArgumentError`. They need\n * no edit when it lands — its conversion selects sites by whether their detail\n * already says what a valid value looks like, and these say `Expected an\n * object with 'where' and 'data'`.\n */\nfunction assertManyOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n operand: unknown,\n key: string,\n operation: string,\n): void {\n const at = `data.${relation.name}.${key}`;\n\n if (typeof operand !== \"object\" || operand === null || Array.isArray(operand)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n key === \"updateMany\"\n ? `Expected an object with 'where' and 'data'.`\n : `Expected an object of filters — 'deleteMany' takes the filter ` +\n `directly, not wrapped in a 'where'.`,\n );\n }\n\n if (key !== \"updateMany\") return;\n\n const record = operand as Record<string, unknown>;\n for (const required of [\"where\", \"data\"] as const) {\n if (record[required] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${required}' key — 'updateMany' names which rows to ` +\n `write and what to write to them.`,\n );\n }\n }\n}\n\n/**\n * `update`'s operand: `{ where, data }`, or a list of them on a to-many.\n *\n * `data` is *not* inspected here — it is the child's, and the child's own\n * `$exec` validates it against the child's schema and policies. Checking it\n * against this model would be checking the wrong shape.\n *\n * **On a to-one only `data` is required, and it may have been written bare.**\n * `toOneOperand` has already turned `update: { bio: \"x\" }`,\n * `update: { data: … }` and `update: { where, data }` into the one form this\n * reads, so what arrives is always `{ where?, data }` — but the `where` is\n * genuinely optional there (`UpdateToOneWithWhereWithoutUserInput` spells it\n * `where?`) and it is a filter rather than a key, so `matchUniqueKey` does not\n * run on it either.\n */\nfunction assertNamedUpdates(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n operation: string,\n many: boolean,\n): Record<string, unknown>[] {\n const at = `data.${relation.name}.update`;\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n const out: Record<string, unknown>[] = [];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected an object with 'where' and 'data'.`,\n );\n }\n\n const record = entry as Record<string, unknown>;\n const required = many ? ([\"where\", \"data\"] as const) : ([\"data\"] as const);\n\n for (const name of required) {\n if (record[name] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${name}' key — 'update' names the row to write and ` +\n `the columns to write to it.`,\n );\n }\n }\n\n if (many) {\n matchUniqueKey(child, record.where, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.update.where`,\n });\n }\n\n out.push(record);\n }\n\n return out;\n}\n\n/**\n * The rows a `disconnect` / `delete` names, each by a unique key.\n *\n * Validated at plan time for the reason every operand here is: a refusal that\n * arrives mid-transaction has to unwind a parent row that should never have\n * been written.\n */\nfunction assertNamedRows(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n key: string,\n operation: string,\n): Record<string, unknown>[] {\n const at = `data.${relation.name}.${key}`;\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n const out: Record<string, unknown>[] = [];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected an object naming a unique field, or an array of them.`,\n );\n }\n matchUniqueKey(child, entry, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.${key}`,\n });\n out.push(entry as Record<string, unknown>);\n }\n\n return out;\n}\n\n/**\n * A to-one `disconnect` / `delete` operand, **as the caller spelled it** — a\n * boolean, or a filter object, and nothing else.\n *\n * The counterpart of {@link assertNamedRows}, and deliberately *not* it. That\n * one runs `matchUniqueKey`, which is right where the caller is picking one row\n * out of many and wrong here: Prisma's to-one operand is a `WhereInput`, and\n * `delete: { bio: \"seed\" }` — a column with no unique index anywhere near it —\n * is accepted and deletes the connected row. Sharing `assertNamedRows` would\n * have refused that at compile time with a list of unique keys the caller never\n * had to name.\n *\n * **Run before {@link toOneOperand} rather than after it, which is what makes\n * `null` reachable at all.** That translation maps `false` to `null`, so a\n * check downstream of it sees one value for two very different calls: the\n * deliberate no-op, and an operand of a type Prisma has no arm for. This used\n * to sit downstream and pass both, and the second is the one that mattered —\n * before #359 the owning side refused everything but `true`, so `disconnect:\n * null` was an `UnsupportedQueryError` there, and widening the grammar turned a\n * refusal into silence. That is the failure class the differential suite exists\n * to pin, arrived at from the tidy direction, and it is not one to inherit on\n * the strength of the far side having it too.\n *\n * Measured, so the refusal is matching Prisma rather than being stricter than\n * it (6.19.2, SQLite): `disconnect: null` is a `PrismaClientValidationError` on\n * all three shapes it can be written against — a one-to-one from either end and\n * a many-to-one — with nothing written. `undefined` is the *absent* key and\n * stays a no-op on both clients, which is why only `null` is named here:\n * `canonicalShape` drops an undefined member outright, so `disconnect:\n * undefined` and no `disconnect` at all are already one call.\n *\n * Sound at plan time for the same reason the boolean guard is (#358):\n * `canonicalShape` records `null` as `\"null\"`, the booleans as `\"true\"` /\n * `\"false\"` and a filter by its structure, so no two of them can share a cache\n * entry and this refusal can never be decided on one call's behalf by another's.\n *\n * `InvalidArgumentError` because the argument is supported and the value is\n * wrong — the same reading `assertCreateManyOperand` uses, and the reason the\n * message names the two shapes that work instead of announcing a gap.\n */\nfunction assertToOneFilter(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n key: string,\n operation: string,\n): void {\n if (operand === undefined) return;\n if (typeof operand === \"boolean\") return;\n if (operand !== null && typeof operand === \"object\" && !Array.isArray(operand)) {\n return;\n }\n\n throw new InvalidArgumentError(\n `data.${relation.name}.${key}`,\n schema.name,\n operation,\n `'${relation.name}' is a to-one, so '${key}' takes either a boolean — ` +\n `'true' for the connected ${child.name}, 'false' for nothing — or an ` +\n `object of filters it has to match. Prisma's operand here is ` +\n `'${child.name}WhereInput | boolean'.` +\n // Named rather than left to the list above, because `null` is the one\n // wrong value with an obvious intent: it is what an optional flag\n // degrades to, and `false` is the spelling that means what it was\n // reaching for. Prisma refuses it too, so pointing at `false` is a\n // correction and not a workaround.\n (operand === null\n ? ` 'null' is not one of them — write 'false' for the no-op. Prisma ` +\n `answers 'null' with a validation error rather than accepting it.`\n : \"\"),\n );\n}\n\n/**\n * The plan-time shape check for a to-one `update` / `upsert`, run **before**\n * {@link toOneOperand} rewrites the operand.\n *\n * Three holes it closes, all of the same kind: the to-one path dropped the\n * `matchUniqueKey` its to-many sibling runs — correctly, since Prisma's to-one\n * `where` is a `WhereInput` and not a unique key — and then put nothing in its\n * place, so the operand reached the step unexamined.\n *\n * 1. **A key the rewrite does not know is discarded silently.** The wrapper\n * branch rebuilds `{ where, data }` from the keys it recognises, so\n * `update: { data: { … }, wehre: { … } }` loses the typo and the filter\n * with it — and `conjoin(undefined, link)` is the parent link alone, so a\n * nested update the caller *guarded* runs unguarded. A write that should\n * not have happened, with nothing raised anywhere. Prisma answers `Unknown\n * argument 'wehre'`, and `assertConnectOrCreateOperand` in this file\n * already refuses extra keys for exactly this reason.\n * 2. **A `where` that is not an object is dropped by `conjoin`**, whose first\n * arm treats an array or a scalar as \"no filter\". So `upsert: { where:\n * [{ bio: \"old\" }], … }` finds the connected row and takes the *update*\n * branch, where Prisma applies the filter, matches nothing and takes the\n * *create* branch onto a unique violation. Two different rows written.\n * 3. **A non-object operand escapes to run time.** `update: null` normalises\n * to `{ where: undefined, data: null }`, which `assertNamedUpdates` passes\n * because its `data` key is present — and the failure then arrives from\n * inside the `after` step as `InvalidArgumentError('data', 'Profile',\n * 'updateMany')`, naming a model and an operation the caller never wrote,\n * after the parent row has already been written and has to be unwound.\n * Plan-time validation exists in this file precisely to prevent that.\n *\n * The payload spelling is deliberately *not* key-checked. `update: { bio: \"x\" }`\n * is the child's own `data`, so every key in it is the child's business and\n * belongs to the child's schema — checking it here would be checking the wrong\n * shape, which is the rule {@link assertNamedUpdates} states. The wrapper is\n * distinguishable because it carries a `data`, which is the same test the\n * rewrite makes one function down.\n */\nfunction assertToOneWriteOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n key: string,\n operand: unknown,\n operation: string,\n): void {\n if (key !== \"update\" && key !== \"upsert\") return;\n\n const argument = `data.${relation.name}.${key}`;\n const refuse = (reason: string): never => {\n throw new InvalidArgumentError(argument, schema.name, operation, reason);\n };\n\n if (operand === null || typeof operand !== \"object\" || Array.isArray(operand)) {\n refuse(\n `Expected an object, got ${JSON.stringify(operand) ?? typeof operand}. ` +\n (key === \"upsert\"\n ? `'upsert' on a to-one takes { create, update } — and an optional ` +\n `'where' the connected ${child.name} has to match.`\n : `'update' on a to-one takes the ${child.name} columns directly, ` +\n `or { data } — and an optional 'where' the connected row has to ` +\n `match.`),\n );\n }\n\n const record = operand as Record<string, unknown>;\n const wrapper = key === \"upsert\" || record.data !== undefined;\n if (!wrapper) return;\n\n const known =\n key === \"upsert\" ? [\"where\", \"create\", \"update\"] : [\"where\", \"data\"];\n\n for (const name of Object.keys(record)) {\n if (record[name] === undefined || known.includes(name)) continue;\n refuse(\n `Unknown key '${name}'. '${key}' on a to-one takes ` +\n `${known.map((one) => `'${one}'`).join(\", \")} and nothing else, so ` +\n `'${name}' would be dropped rather than applied — a misspelled ` +\n `'where' would turn a filtered write into an unconditional one. ` +\n `Prisma refuses the same key by name.`,\n );\n }\n\n if (\n record.where !== undefined &&\n (record.where === null ||\n typeof record.where !== \"object\" ||\n Array.isArray(record.where))\n ) {\n refuse(\n `'where' has to be an object of filters — Prisma's is a ` +\n `'${child.name}WhereInput', which narrows *which* single row is ` +\n `written rather than choosing among several. Anything else is dropped ` +\n `by the conjunction that keeps this operand on the connected row, so ` +\n `the write would land unfiltered.`,\n );\n }\n}\n\n/**\n * A `disconnect` clears a foreign key, so the column has to be nullable.\n *\n * Prisma refuses it on a required relation at the type level; here the schema\n * is the only thing that knows, so the refusal says which column and why rather\n * than letting the database report a not-null violation from inside a nested\n * step.\n *\n * `owner` and `caller` are separate parameters because they are separate\n * questions, and one parameter answering both is what went wrong. The column\n * lives on whichever side holds the foreign key — the caller's row on a to-one,\n * the child's on a to-many — and that is what the *message* has to name. The\n * *structured* model is always the caller's. Passing `owner` for both meant a\n * `User.update` reported `model = \"Account\"` on the foreign side while the\n * owning side reported `User`, from the same function (#112).\n *\n * **Every column of the link, and the first required one is named** (#271).\n * Prisma makes a composite relation optional or required as a whole — it\n * refuses a mixture, *\"The fields of a relation must either all be optional or\n * all be required\"* — so on a schema Prisma accepted the columns agree and any\n * one of them answers. Checking all of them anyway costs nothing and means the\n * refusal does not depend on a validation rule enforced in another program:\n * a hand-built `ModelSchema` with a nullable `tenantId` beside a required\n * `ledgerCode` is refused here rather than nulling half a key.\n *\n * That is a claim about behaviour, so it is measured rather than asserted —\n * `ledgerSealMixed` in `fixtures.ts` is exactly that schema, and\n * `composite-relations.test.ts` names the column this refuses on. **The\n * nullable column is first there deliberately**: `[fieldNames[0]]` is what this\n * collapses to if the generalisation is undone, and over `(nullable, required)`\n * that answers *\"detachable\"*. The same fixture pins the two `displaces`\n * predicates, which generalised the same way and were equally unpinned.\n */\nfunction assertDisconnectable(\n owner: ModelSchema,\n relation: RelationSchema,\n fieldNames: readonly string[],\n caller: RefusalOrigin,\n): void {\n const required = fieldNames.find((name) => !owner.fields[name]?.nullable);\n if (required === undefined) return;\n\n throw new UnsupportedQueryError(\n caller.argument,\n caller.model,\n caller.operation,\n `'${owner.name}.${required}' is required, so there is no value to leave ` +\n `behind — a disconnected row would have to be deleted or repointed ` +\n `instead. Prisma does not offer 'disconnect' on a required relation ` +\n `either.`,\n );\n}\n\n/**\n * `connectOrCreate`'s operand: `{ where, create }`, or a list of them on a\n * to-many.\n *\n * Validated at plan time so a misspelled key fails when the query is compiled,\n * rather than after the parent row has been written and the transaction has to\n * unwind it — the same reason `createMany`'s operand is checked here.\n *\n * The `where` has to be a unique key, which is Prisma's rule and not merely\n * ours: without it the lookup matches an arbitrary row and \"connect or create\"\n * silently becomes \"connect to whichever one came back first\".\n */\nfunction assertConnectOrCreateOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n child: ModelSchema,\n operand: unknown,\n operation: string,\n many: boolean,\n): Record<string, unknown>[] {\n const at = `data.${relation.name}.connectOrCreate`;\n\n if (Array.isArray(operand) && !many) {\n // **Which side holds the key is read off the relation, not assumed.** This\n // sentence used to say \"this row holds the foreign key\" unconditionally,\n // which was true of the only caller that could pass `many: false` — the\n // owning side — and false the moment the foreign side stopped hardcoding\n // `true`. `from` is non-empty exactly on the side that holds the key, the\n // same test `planOne` makes to choose between the two planners, so the two\n // cannot drift.\n const owning = relation.from.length > 0;\n\n throw new InvalidArgumentError(\n at,\n schema.name,\n operation,\n `'${relation.name}' is a to-one: ` +\n (owning\n ? `this row holds the foreign key`\n : `${child.name} holds the foreign key`) +\n `, so there is one row to point at and a list has no meaning. Prisma ` +\n `refuses an array here too — as a validation error on the argument, ` +\n `which is why this is a bad value rather than a gap.`,\n );\n }\n\n const entries = (Array.isArray(operand) ? operand : [operand]) as unknown[];\n\n if (entries.length === 0) return [];\n\n const out: Record<string, unknown>[] = [];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null || Array.isArray(entry)) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected an object with 'where' and 'create'.`,\n );\n }\n\n const record = entry as Record<string, unknown>;\n\n for (const required of [\"where\", \"create\"] as const) {\n if (record[required] === undefined) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Expected a '${required}' key — 'connectOrCreate' names the row to ` +\n `look for and the row to write if it is not there.`,\n );\n }\n }\n\n const extra = Object.keys(record).filter(\n (key) => key !== \"where\" && key !== \"create\" && record[key] !== undefined,\n );\n if (extra.length > 0) {\n throw new UnsupportedQueryError(\n at,\n schema.name,\n operation,\n `Unexpected ${extra.sort().join(\", \")} — 'connectOrCreate' takes ` +\n `'where' and 'create'.`,\n );\n }\n\n matchUniqueKey(child, record.where, {\n model: schema.name,\n operation,\n argument: `data.${relation.name}.connectOrCreate.where`,\n });\n out.push(record);\n }\n\n return out;\n}\n\n/**\n * `createMany`'s operand is `{ data }` — not the rows directly, which is the\n * one place Prisma's nested grammar adds a level.\n *\n * Checked at plan time, so a misspelled key fails when the query is compiled\n * rather than after the parent row has already been written and the transaction\n * has to unwind it.\n */\nfunction assertCreateManyOperand(\n schema: ModelSchema,\n relation: RelationSchema,\n operand: unknown,\n operation: string,\n): void {\n const at = `data.${relation.name}.createMany`;\n\n if (typeof operand !== \"object\" || operand === null || Array.isArray(operand)) {\n throw new InvalidArgumentError(\n at,\n schema.name,\n operation,\n `Expected an object with a 'data' key — the rows go inside it, not ` +\n `directly under 'createMany'.`,\n );\n }\n\n const keys = Object.keys(operand as Record<string, unknown>).filter(\n (key) => (operand as Record<string, unknown>)[key] !== undefined,\n );\n\n if (!keys.includes(\"data\")) {\n throw new InvalidArgumentError(at, schema.name, operation, `Expected a 'data' key.`);\n }\n\n for (const key of keys) {\n if (key === \"data\") continue;\n\n // `skipDuplicates` is the one a caller will actually reach for, so it gets\n // the reason instead of the generic message.\n //\n // **Scoped to the nested form on purpose.** This used to say \"at any\n // level\", which was true when it was written and stops being true the\n // moment #69 lands: a top-level `Account.createMany({ data, skipDuplicates\n // })` compiles to `on conflict do nothing` on Postgres. Naming the level\n // keeps the sentence true either way, and points at the spelling that\n // works today rather than at a wait.\n //\n // Whether the nested form should simply pass it through is a real question\n // and not this change's: the step below already calls the child's own\n // `$exec(\"createMany\", …)`, so forwarding the flag is close to free — but\n // it would need the top-level support to exist first, and until then it\n // would fail with an error about an unknown argument on a model the caller\n // did not name.\n throw new UnsupportedQueryError(\n `${at}.${key}`,\n schema.name,\n operation,\n key === \"skipDuplicates\"\n ? `'skipDuplicates' is not implemented on a *nested* 'createMany'. ` +\n `Write the children with their own '${relation.model}.createMany' ` +\n `call, which takes it.`\n : `Expected only 'data'.`,\n );\n }\n}\n\n/**\n * Prisma accepts both a single object and an array everywhere a to-many nested\n * write is legal, and the singular form is the common one on a to-one.\n */\nfunction listOf(value: unknown): unknown[] {\n if (value === undefined || value === null) return [];\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * A to-one nested-write operand, rewritten in the spelling the to-many bodies\n * above already read.\n *\n * **Prisma's to-one nested input is a different grammar, not a subset of the\n * to-many one** — quoted from a generated client rather than from the docs\n * (`ProfileUpdateOneWithoutUserNestedInput`):\n *\n * update XOR<UpdateToOneWithWhereWithoutUserInput, UpdateWithoutUserInput>\n * where UpdateToOneWithWhereWithoutUserInput = { where?, data }\n * upsert { update, create, where? }\n * disconnect ProfileWhereInput | boolean\n * delete ProfileWhereInput | boolean\n * connect ProfileWhereUniqueInput\n *\n * Three of those differences would be got wrong by reading the to-many side and\n * assuming symmetry, so each is named with the measurement behind it:\n *\n * - **the `where` is optional, and it is a filter.** Not a unique key —\n * `WhereInput`, not `WhereUniqueInput` — which is why `assertToOneFilter`\n * replaces `assertNamedRows` here and `matchUniqueKey` does not run.\n * Measured: `delete: { bio: \"seed\" }` is accepted against a column with no\n * unique index and deletes the connected row.\n * - **the data may be written bare.** `update: { bio: \"x\" }` and\n * `update: { data: { bio: \"x\" } }` are one operation. The owning side\n * measured that years ago; this is the same measurement repeated on the\n * foreign side, because the owning side's said nothing about this one.\n * - **the boolean is not an empty filter.** `true` means the connected row;\n * `false` means *nothing at all*, measured — `delete: false` and\n * `disconnect: false` with a child present return the parent and leave the\n * child exactly as it was, foreign key included.\n *\n * So `true` becomes `{}`, which `conjoin` reduces to the parent link alone —\n * precisely the one connected row — and `false` becomes `null`, which `listOf`\n * reduces to `[]`, which is no statement.\n */\nfunction toOneOperand(key: string, operand: unknown): unknown {\n if (key === \"update\") {\n // A `data` key is the wrapper; anything else is the payload itself. The\n // same test `planOwningSide`'s `update` makes, deliberately — the two\n // spellings collapse to one operation, so the compiler should not have two\n // shapes of its own for them. It carries the same ambiguity, too: a child\n // with a scalar column called `data` would be read as the wrapper. Prisma's\n // own input types have that hazard by construction and it has never been\n // reachable in practice, so it is inherited rather than invented.\n //\n // **`!== undefined` rather than `in`**, and the difference is a plan-cache\n // bug rather than a style choice. `canonicalShape` drops a key whose value\n // is `undefined` (see its object branch), so `update: {}` and `update: {\n // data: undefined }` are ONE plan key. Branching on `in` gave them two\n // compilations: the first normalised and compiled, the second reached\n // `assertNamedUpdates` and was refused for a missing `data` — so whether\n // the refusal fired depended on which spelling warmed the cache. Testing\n // the value instead is what `assertNamedUpdates` itself does, one operand\n // over, and it puts both spellings on the same branch.\n //\n // This is the same defect as the `disconnect` boolean two functions down,\n // arrived at from the opposite direction: there the key was too coarse for\n // the code, here the code was finer than the key. Both are decided by\n // asking what `canonicalShape` actually records.\n if (\n operand !== null &&\n typeof operand === \"object\" &&\n (operand as Record<string, unknown>).data !== undefined\n ) {\n const record = operand as Record<string, unknown>;\n return { where: record.where, data: record.data };\n }\n return { where: undefined, data: operand };\n }\n\n if (key === \"delete\" || key === \"disconnect\") {\n if (operand === true) return {};\n if (operand === false) return null;\n return operand;\n }\n\n // `upsert` already arrives as `{ where?, create, update }`, and `create`,\n // `connect` and `connectOrCreate` are already singular. Returned untouched\n // rather than listed, so an operand added later does not silently acquire a\n // translation it was never measured for.\n return operand;\n}\n",
20
20
  "import type { SqlDialect } from \"../dialect\";\nimport {\n InvalidArgumentError,\n UnknownRelationError,\n UnsupportedQueryError,\n} from \"../errors\";\nimport type { ModelSchema, RelationSchema } from \"../schema\";\nimport { COUNT_KEY } from \"../relation-filters\";\nimport { type Fragment, concat, sql } from \"./fragment\";\nimport { correlate } from \"./correlate\";\nimport { compileWhere } from \"./where\";\n\n/**\n * `include: { _count: { select: { accounts: true } } }` -> a correlated\n * `count(*)` in the select list.\n *\n * The last item iteration 3 listed as out of scope and never rescheduled. It is\n * the same machinery relation filters use — a correlated subquery over the child,\n * aliased so a self-relation cannot shadow the outer table — projected instead of\n * predicated:\n *\n * select …, (select count(*) from \"Account\" as \"_c0\"\n * where \"_c0\".\"userId\" = \"User\".\"id\") as \"_count.accounts\"\n *\n * One statement, no extra round trip, and no row multiplication: a `group by`\n * against a to-many would fold the parents together and a join would duplicate\n * them, which is the same reason relation filters are `exists` rather than joins.\n */\n\nexport interface CountPlan {\n /** The relation being counted, as the caller named it. */\n as: string;\n /** The projected column, aliased so `shape` can find it in the raw row. */\n column: Fragment;\n /** The alias, which is also the raw row's key. */\n alias: string;\n}\n\n/**\n * Reads `_count` out of an `include` or a `select`.\n *\n * Returns an empty list when there is none, which is the overwhelmingly common\n * case and costs one property read.\n */\nexport function planRelationCounts(\n schema: ModelSchema,\n args: any,\n dialect: SqlDialect,\n operation: string,\n): CountPlan[] {\n const container = args?.include ?? args?.select;\n if (typeof container !== \"object\" || container === null) return [];\n\n const node = container[COUNT_KEY];\n if (node === undefined || node === false) return [];\n\n const selection = readCountSelection(schema, node, operation);\n const plans: CountPlan[] = [];\n\n // Sorted for the reason every walk here is: the plan cache canonicalises key\n // order, so two argument objects differing only in key order are one entry and\n // must produce one statement.\n for (const key of Object.keys(selection).sort()) {\n const value = selection[key];\n if (value === undefined || value === false) continue;\n\n const relation = schema.relations[key];\n if (!relation) {\n throw new UnknownRelationError(\n key,\n schema.name,\n Object.keys(schema.relations),\n );\n }\n\n plans.push(\n countPlan(schema, relation, value, dialect, operation, plans.length, args),\n );\n }\n\n return plans;\n}\n\nfunction countPlan(\n schema: ModelSchema,\n relation: RelationSchema,\n node: unknown,\n dialect: SqlDialect,\n operation: string,\n index: number,\n args: any,\n): CountPlan {\n const path = `_count.select.${relation.name}`;\n\n if (relation.kind !== \"many\") {\n // Prisma only counts to-many relations, and the reason is that the answer is\n // 0 or 1 — which the relation's own nullability already says.\n throw new UnsupportedQueryError(\n path,\n schema.name,\n operation,\n `${relation.name} is a to-one relation. Counting it can only ever ` +\n `return 0 or 1, which is what its nullability already tells you.`,\n );\n }\n\n const source = correlate(\n schema,\n relation,\n dialect,\n `_c${index}`,\n `${dialect.quoteIdent(schema.table)}.`,\n operation,\n );\n\n const where = node === true ? undefined : (node as any)?.where;\n const container = args?.include !== undefined ? \"include\" : \"select\";\n const locate = (a: any) =>\n a?.[container]?.[COUNT_KEY]?.select?.[relation.name]?.where;\n\n const filter = compileWhere(\n source.child,\n where,\n { dialect, operation, qualifier: source.qualifier },\n locate,\n );\n\n const parts: Fragment[] = [\n sql(`(select count(*) from ${source.source} where ${source.correlation}`),\n ];\n if (filter) parts.push(sql(\" and \"), filter);\n // The alias carries a dot on purpose: it cannot collide with a column, since\n // an identifier that needs quoting to contain one could not have come from the\n // schema, and it keeps the raw row self-describing when a query is logged.\n parts.push(sql(`) as ${dialect.quoteIdent(`_count.${relation.name}`)}`));\n\n return {\n as: relation.name,\n alias: `_count.${relation.name}`,\n column: concat(...parts),\n };\n}\n\n/** `_count: { select: { … } }`, which is the only form that carries a policy. */\nfunction readCountSelection(\n schema: ModelSchema,\n node: unknown,\n operation: string,\n): Record<string, unknown> {\n if (node === true) {\n // Prisma's shorthand counts *every* to-many relation. Not implemented, and\n // the reason is worth stating rather than leaving as a gap: it names no\n // relation, so a policy has nowhere to attach per-relation — and what it\n // returns changes silently when the schema grows a relation.\n throw new UnsupportedQueryError(\n \"_count\",\n schema.name,\n operation,\n `'_count: true' is not implemented. Name the relations: ` +\n `_count: { select: { <relation>: true } }.`,\n );\n }\n\n if (typeof node !== \"object\" || node === null || Array.isArray(node)) {\n throw new InvalidArgumentError(\n \"_count\",\n schema.name,\n operation,\n \"Expected an object holding 'select'.\",\n );\n }\n\n const selection = (node as Record<string, unknown>).select;\n if (\n typeof selection !== \"object\" ||\n selection === null ||\n Array.isArray(selection)\n ) {\n throw new InvalidArgumentError(\n \"_count.select\",\n schema.name,\n operation,\n \"Expected an object naming the relations to count.\",\n );\n }\n\n return selection as Record<string, unknown>;\n}\n\n",
21
- "import { clientSideValue, hasClientSideValue } from \"../defaults\";\nimport type { SqlDialect } from \"../dialect\";\nimport {\n InvalidArgumentError,\n MissingRequiredValueError,\n ReturningUnsupportedError,\n UnknownFieldError,\n UnsupportedQueryError,\n} from \"../errors\";\nimport { jsonNullKind } from \"../json-null\";\nimport type { Operation, QueryPlan } from \"../plan\";\nimport type { FieldSchema, ModelSchema } from \"../schema\";\nimport { buildRowShaper } from \"../shape\";\nimport {\n type Binder,\n type Fragment,\n bindValues,\n concat,\n joinFragments,\n param,\n render,\n sql,\n} from \"./fragment\";\nimport { fieldParam } from \"./cast\";\nimport {\n type ForeignKeyContribution,\n type NestedWritePlanning,\n planNestedWrites,\n} from \"./nested-writes\";\nimport { planRelations, strategiesOf } from \"./plan-relations\";\nimport { type CountPlan, planRelationCounts } from \"./relation-count\";\nimport { resolveSelection, withKeyFields } from \"./select\";\nimport { matchUniqueKey } from \"./unique\";\nimport { assertListDialect, compileWhere } from \"./where\";\n\n/**\n * The write surface: `create`, `createMany`, `update`, `updateMany`, `delete`,\n * `deleteMany`, `upsert`.\n *\n * Everything here obeys the same two rules the read compiler does, and for the\n * same reasons (invariant 2): the SQL text is a pure function of the argument\n * *shape*, and every value is a bound parameter. A `create` with the same field\n * set is one plan whatever the values are.\n *\n * Two decisions worth finding here rather than inferring from the code:\n *\n * **1. Row counts come from `RETURNING`, not from driver metadata.**\n * `updateMany` and `deleteMany` return `{ count }`, and the obvious source is\n * whatever the driver reports about the statement. Measured, that source is\n * undocumented: Bun's SQLite driver leaves `affectedRows` **null** on every\n * statement and puts the number on a `count` property instead. So the count is\n * the number of rows a `RETURNING <primary key>` gives back — one statement\n * shape on every dialect, exact by construction, and dependent on nothing\n * undocumented.\n *\n * `count` has since been measured on Postgres too, and it agrees: same property,\n * same value, `affectedRows` null on both, across `update`, `delete`, `insert`,\n * a statement matching nothing and one carrying `returning`. That does not\n * change the decision here — `RETURNING` is still exact and still asks the\n * driver for nothing — but it is what lets `DB.execute` report a *raw* write's\n * rowcount, where the statement is the caller's and there is no `RETURNING` to\n * add. See `facades/DB.ts`.\n * It costs one key column per affected row on the wire, which is a real cost on\n * a very large `deleteMany`; iteration 7 owns performance and can revisit it\n * with a benchmark rather than a guess.\n *\n * **2. `createMany` fills defaults explicitly rather than grouping rows.**\n * Prisma allows rows with different key sets in one call, and a single multi-row\n * `INSERT` cannot express that directly — every row must supply every column.\n * The column list is therefore the union of every row's keys, and a row missing\n * one gets its client-side default, or `NULL` if the column is nullable. The one\n * case that cannot be filled is a column with a *database* default that some\n * rows supply and others do not: `NULL` would override the default rather than\n * request it, and the `DEFAULT` keyword is not available — SQLite rejects it\n * inside a `VALUES` list (verified: `near \"DEFAULT\": syntax error`). That case\n * is refused with an error naming the column, rather than silently written wrong.\n */\n\n// `omit` rides along wherever a payload comes back, which is every write but\n// the three that return a count — Prisma types it the same way. It is resolved\n// by `resolveSelection`, so the `RETURNING` list narrows exactly as a read's\n// column list does and the omitted column is never read.\nexport const WRITE_ARGS: Record<string, Set<string>> = {\n create: new Set([\"data\", \"select\", \"include\", \"omit\"]),\n createMany: new Set([\"data\", \"skipDuplicates\"]),\n update: new Set([\"data\", \"where\", \"select\", \"include\", \"omit\"]),\n updateMany: new Set([\"data\", \"where\"]),\n delete: new Set([\"where\", \"select\", \"include\", \"omit\"]),\n deleteMany: new Set([\"where\"]),\n upsert: new Set([\"where\", \"create\", \"update\", \"select\", \"include\", \"omit\"]),\n};\n\n/** The writes that return one row, and raise when they match none. */\nconst SINGLE_ROW = new Set([\"create\", \"update\", \"delete\", \"upsert\"]);\n\n/** The writes that return `{ count }` rather than rows. */\nconst COUNTING = new Set([\"createMany\", \"updateMany\", \"deleteMany\"]);\n\nexport function isWriteOperation(op: Operation): boolean {\n return op in WRITE_ARGS;\n}\n\nexport function compileWrite(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n assertArgs(schema, op, args);\n\n // Every write reports its result — the row, or the number of rows — through\n // `RETURNING`. Asked rather than assumed so MySQL is a named gap.\n if (!dialect.supportsReturning) {\n throw new ReturningUnsupportedError(schema.name, op, dialect.name);\n }\n\n switch (op) {\n case \"create\":\n return compileCreate(schema, op, args, dialect);\n case \"createMany\":\n return compileCreateMany(schema, op, args, dialect);\n case \"update\":\n case \"updateMany\":\n return compileUpdate(schema, op, args, dialect);\n case \"delete\":\n case \"deleteMany\":\n return compileDelete(schema, op, args, dialect);\n case \"upsert\":\n return compileUpsert(schema, op, args, dialect);\n default:\n throw new UnsupportedQueryError(\n op,\n schema.name,\n op,\n `'${op}' is not a write operation. The writes are ` +\n `${Object.keys(WRITE_ARGS).sort().join(\", \")}.`,\n );\n }\n}\n\n// --- create ----------------------------------------------------------------\n\nfunction compileCreate(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const nested = planNestedWrites(\n schema,\n args?.data,\n op,\n (callArgs) => callArgs?.data,\n dialect,\n );\n\n const columns = insertColumns(\n schema,\n args?.data,\n nested.contributions,\n op,\n dialect,\n (callArgs) => callArgs?.data,\n );\n\n const returning = returningClause(schema, args, dialect, op, nested);\n\n const statement = concat(\n sql(`insert into ${dialect.quoteIdent(schema.table)}`),\n valuesClause([columns], dialect),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, nested);\n}\n\n// --- createMany ------------------------------------------------------------\n\nfunction compileCreateMany(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const rows = args?.data === undefined ? [] : listOf(args.data);\n\n // Before the empty-list shortcut below, so that an unsupported argument is\n // refused whether or not there was anything to write. Prisma rejects it on\n // SQLite for an empty list too, and validation that depends on how much data\n // happened to be supplied is the kind that passes in a test and fails in\n // production.\n const ignore = skipDuplicatesClause(schema, op, args, dialect);\n\n // Prisma returns `{ count: 0 }` for an empty list without touching the\n // database. See {@link zeroCountPlan} for how that is spelled as a plan.\n if (rows.length === 0) {\n return zeroCountPlan(schema, op, dialect);\n }\n\n const grid = createManyColumns(schema, rows, op, dialect);\n\n // `insert ... default values` inserts exactly one row and has no multi-row\n // spelling: `values (DEFAULT), (DEFAULT)` is rejected by SQLite, and the\n // zero-column list leaves nothing else to repeat. So a grid with no columns\n // and more than one row would quietly insert one — a wrong row count *and* a\n // wrong `{ count }`, from a statement that succeeds.\n //\n // Only reachable on a model where every field is autoincrement, database\n // default or nullable *and* no row supplies any of them, so the template's\n // schema cannot produce it. Refused by name anyway, because a silent wrong\n // count is the failure class this file is arranged to prevent.\n if (grid[0].length === 0 && rows.length > 1) {\n throw new UnsupportedQueryError(\n \"data\",\n schema.name,\n op,\n `All ${rows.length} rows are empty and ${schema.name} has no ` +\n `client-side default to fill, so there is no column to insert. A ` +\n `multi-row insert of nothing but database defaults cannot be ` +\n `expressed on both dialects. Call create ${rows.length} times, or ` +\n `set at least one field per row.`,\n );\n }\n\n const returning = returningClause(schema, undefined, dialect, op, undefined);\n\n const statement = concat(\n sql(`insert into ${dialect.quoteIdent(schema.table)}`),\n valuesClause(grid, dialect),\n ignore ?? sql(\"\"),\n returning.clause,\n );\n\n const { text, binders } = render(statement, dialect, { model: schema.name, operation: op });\n return {\n text,\n bind: bindValues(binders),\n // The rows a conflict skipped never reach `RETURNING`, so this is the\n // number *inserted* rather than the number supplied — which is what Prisma\n // returns, and what makes the count usable for \"how many were new\".\n shape: (returned) => ({ count: returned.length }),\n };\n}\n\n/**\n * `skipDuplicates`, or `null` when the caller did not ask for it.\n *\n * The whole point is that the check and the insert are one statement. Without\n * it a caller reads first to find out which rows exist, which is a second query\n * *and* a race: between the read and the insert a concurrent importer writes one\n * of them, and the insert fails on a unique violation anyway.\n *\n * Refused on a dialect that does not offer it, naming the dialect rather than\n * saying \"yet\" — the answer there is not \"wait\", it is \"Prisma does not offer\n * this on SQLite either, so neither do we\". See `SqlDialect.ignoreConflicts`\n * for why that is a parity decision rather than a gap.\n */\nfunction skipDuplicatesClause(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): Fragment | null {\n const requested = args?.skipDuplicates;\n if (requested === undefined) return null;\n\n if (typeof requested !== \"boolean\") {\n throw new InvalidArgumentError(\n \"skipDuplicates\",\n schema.name,\n op,\n `Expected true or false, got ${JSON.stringify(requested)}.`,\n );\n }\n\n const clause = dialect.ignoreConflicts();\n if (clause === null) {\n // Refused whatever the value, which is exactly what Prisma does: on SQLite\n // it reports `skipDuplicates` as an unknown argument for `false` as well as\n // for `true`. Accepting `false` because it happens to be a no-op would make\n // the two dialects disagree about which calls are legal.\n throw new UnsupportedQueryError(\n \"skipDuplicates\",\n schema.name,\n op,\n `'skipDuplicates' is not available on ${dialect.name}. Prisma does not ` +\n `offer it there either — it is a Postgres and MySQL argument. To ` +\n `import a batch that may overlap, write the rows one at a time and ` +\n `catch UniqueConstraintError, or move this model to Postgres.`,\n );\n }\n\n return requested ? clause : null;\n}\n\n/**\n * The column grid for a multi-row insert: one `WriteColumn[]` per row, every\n * row carrying the same fields in the same order.\n *\n * The order is the *schema's*, never the first row's key order. That is not a\n * tidiness point: with the column list taken from row one and the values taken\n * per row by key order, a second row whose keys were written in a different\n * order binds its values into the wrong columns. Same types, no error, wrong\n * data — the worst shape of bug this file could have. Every value is looked up\n * by field name, and there is a test for exactly this.\n */\nfunction createManyColumns(\n schema: ModelSchema,\n rows: unknown[],\n op: Operation,\n dialect: SqlDialect,\n): WriteColumn[][] {\n const supplied = rows.map((row, index) => {\n if (typeof row !== \"object\" || row === null || Array.isArray(row)) {\n throw new InvalidArgumentError(\n `data[${index}]`,\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n\n const keys = new Set<string>();\n for (const [key, value] of Object.entries(row as Record<string, unknown>)) {\n if (value === undefined) continue;\n if (key in schema.relations) {\n // Prisma's `createMany` takes unchecked input — scalars and foreign\n // keys only. A nested write there has no defined ordering across rows.\n throw new UnsupportedQueryError(\n `data.${key}`,\n schema.name,\n op,\n \"createMany cannot contain nested writes. Use create per row.\",\n );\n }\n if (!(key in schema.fields)) {\n throw new UnknownFieldError(key, schema.name, Object.keys(schema.fields));\n }\n keys.add(key);\n }\n return keys;\n });\n\n // The union, walked in schema order so the emitted column list depends only\n // on *which* fields appear, never on how any row was written.\n const union: FieldSchema[] = [];\n for (const field of Object.values(schema.fields)) {\n const inSome = supplied.some((keys) => keys.has(field.name));\n if (inSome || hasClientSideValue(field) || suppliesEmptyList(field)) {\n union.push(field);\n }\n }\n\n for (const field of union) {\n const missing = supplied.some((keys) => !keys.has(field.name));\n if (!missing) continue;\n\n if (hasClientSideValue(field)) continue;\n if (field.nullable) continue;\n // The empty list stands in for an absent one — see `insertColumns`. It also\n // resolves the \"some rows set it and others do not\" refusal below, which\n // exists because a single `VALUES` list cannot ask for a database default\n // per row. A list needs no default asked for: `{}` is a value, so the rows\n // that omitted it get one written rather than needing the statement split.\n //\n // `suppliesEmptyList` rather than `field.isList`, which is the whole of the\n // distinction: this stands in for a list that has **nothing else** to fall\n // back on. A list with a *database-side* default still cannot be expressed\n // per row, so it falls through to the refusal below rather than silently\n // acquiring `{}` — and one with a client-side default never reaches here,\n // because `hasClientSideValue` answered above.\n if (suppliesEmptyList(field)) continue;\n\n // A database-side default that only some rows override. `NULL` would\n // *overwrite* the default rather than request it, and SQLite has no\n // `DEFAULT` keyword inside a `VALUES` list to ask for it with.\n if (field.default) {\n throw new UnsupportedQueryError(\n `data.${field.name}`,\n schema.name,\n op,\n `Some rows set '${field.name}' and others leave it to the database ` +\n `default. A single multi-row insert cannot express both. Split the ` +\n `call, or set '${field.name}' on every row.`,\n );\n }\n\n const index = supplied.findIndex((keys) => !keys.has(field.name));\n throw new MissingRequiredValueError(\n schema.name,\n `${op}.data[${index}]`,\n field.name,\n );\n }\n\n for (const field of union) {\n if (field.isList) {\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n }\n }\n\n return rows.map((row, index) =>\n union.map((field) => {\n if (!supplied[index].has(field.name)) {\n // **`suppliesEmptyList`, not `field.isList`**, and the difference is a\n // row that comes out wrong rather than a statement that fails.\n //\n // `@default([])` and `@default([\"seed\"])` are *client-side* defaults —\n // `kind: \"value\"`, which `isClientSideDefault` admits — so `create`\n // binds the declared value through `defaultBinder`. Asking `isList`\n // here put `{}` ahead of that, so one `createMany` row omitting a\n // defaulted list wrote the empty array where `create` wrote the\n // default, and where Prisma writes the default — so `create` and\n // `createMany` disagreed about one schema, silently, in the row.\n //\n // Invisible to the differential until the fixture changed: the template\n // declared `@default([])`, where the correct value and the wrong one are\n // the same array. It now declares a non-empty default, and the\n // `createMany` case supplies it on one row and omits it on the other.\n return {\n field,\n value: suppliesEmptyList(field)\n ? emptyList(field, dialect)\n : defaultBinder(field, dialect),\n };\n }\n\n if (field.isList) {\n // Compile-time, like `insertColumns` and `assignment` — this was the\n // one write path that let a bad operand reach the binder. `[\"set\"]`\n // because an insert takes no `push`, and a refusal naming `push` on the\n // operation where it is never legal is a puzzle rather than a next step.\n assertListOperand(schema, field, (row as any)?.[field.name], op, [\"set\"]);\n }\n\n // Per row, because two rows of one `createMany` may legitimately spell\n // the same list differently — `[\"a\"]` and `{ set: [\"a\"] }`. The plan key\n // records the whole `data` array's shape, so the two are already\n // different entries and this stays a compile-time decision.\n const setForm = isListSetOperand(field, (row as any)?.[field.name]);\n\n return {\n field,\n value: valueBinder(schema, op, field, dialect, (callArgs) => {\n const value = listOf(callArgs?.data)[index]?.[field.name];\n return setForm ? value?.set : value;\n }),\n };\n }),\n );\n}\n\n// --- update / updateMany ---------------------------------------------------\n\nfunction compileUpdate(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const many = op === \"updateMany\";\n\n // `data: null` reaches here: `requiredArgs` asks only about `undefined`, and\n // `updateAssignments` admits a nullish `data` because `upsert`'s halves may\n // legitimately be absent. It used to land on \"At least one field must be\n // updated\", which was a poor message but a refusal. Now that an empty `data`\n // reads the row back, a null one would read it back too — a malformed call\n // answered with a row. Refused on the shape rather than on a Prisma code,\n // because Prisma's client rejects this at the type level and the query engine\n // never sees it, so there is no behaviour to match here, only one to not\n // invent.\n if (args?.data === null) {\n throw new InvalidArgumentError(\n \"data\",\n schema.name,\n op,\n \"Expected an object of the fields to set, like { name: 'new name' }. \" +\n \"An empty object is accepted and reads the row back unchanged; null \" +\n \"is not.\",\n );\n }\n\n if (!many) {\n matchUniqueKey(schema, args?.where, {\n model: schema.name,\n operation: op,\n argument: \"where\",\n });\n }\n\n // Prisma's `updateMany` takes unchecked input — scalars and foreign keys, no\n // relation keys — and rejects one with `Unknown argument 'organization'`.\n // Refused by name here for the same reason `createMany` refuses it: without\n // this the key is neither executed nor reported, since `planNestedWrites`\n // never runs and `suppliedFields` skips relation keys silently.\n //\n // This guard carries more weight than it used to. A `data` of only a relation\n // key leaves no assignment behind, so it used to land on \"At least one field\n // must be updated\" — the wrong problem, but still a refusal. Now that an\n // empty `data` is a legitimate `{ count: 0 }` (see below), the same call would\n // instead *succeed*, having written nothing and said nothing. Remove this and\n // the failure mode goes from a misleading error to no error at all.\n if (many) {\n assertNoNestedWrites(\n schema,\n args?.data,\n op,\n \"data\",\n \"updateMany cannot contain nested writes — it has no single row to \" +\n \"attach them to. Use update per row.\",\n );\n }\n\n const nested = many\n ? undefined\n : planNestedWrites(schema, args?.data, op, (callArgs) => callArgs?.data, dialect);\n\n const assignments = updateAssignments(\n schema,\n args?.data,\n nested?.contributions ?? [],\n op,\n dialect,\n );\n\n const where = compileWhere(\n schema,\n args?.where,\n { dialect, operation: op },\n (callArgs) => callArgs?.where,\n );\n\n // MEASURED (Prisma 6.19.2, SQLite): `updateMany({ where, data: {} })` is\n // accepted and answers `{ count: 0 }` — with three rows in the table and two\n // matching the filter, again with a filter matching none, and again with no\n // `where` at all. The count is a *constant*, not a row count: Prisma's own\n // answer does not depend on how many rows the filter selects, and no row is\n // touched. So there is nothing here to derive from the filter, and the\n // cheapest honest match is the `createMany([])` plan — same shape, same\n // reason, same `{ count: <rows returned> }` shaping, no special case in the\n // choke point.\n //\n // The `where` above is compiled and then discarded on this path, deliberately:\n // an unknown field in a filter must be refused whether or not there happened\n // to be anything to write, for the reason `createMany` gives for validating\n // `skipDuplicates` ahead of its own empty-list shortcut — validation that\n // depends on how much data was supplied is the kind that passes in a test and\n // fails in production.\n if (many && assignments.length === 0) {\n return zeroCountPlan(schema, op, dialect);\n }\n\n // An `update` whose `data` sets no column has no `UPDATE … SET` to emit, and\n // there are two ways to get there. `Post.update({ where, data: { tags: {\n // connect: … } } })` changes the join table and nothing on `Post` itself; and\n // `data: {}` changes nothing at all. Prisma accepts both.\n //\n // So the row is *selected* instead. The nested steps need the parent's key\n // and the caller's `select` / `include` still has to be honoured, and both\n // come from the same `returning` list — which a select produces just as well\n // as an `update … returning` does. Same plan shape, same steps, one statement\n // that happens to read rather than write.\n //\n // The empty `data` used to be refused here, on the reasoning that with\n // neither an assignment nor a nested write there is genuinely nothing to do.\n // That is true of the *write* and false of the *call*. MEASURED, same client:\n // `post.update({ where: { id: 1 }, data: {} })` returns `{ id: 1, title:\n // \"p1\" }` with the row unchanged; with `include: { tags: true }` it returns\n // the tags as well; with `select: { title: true }` it returns `{ title:\n // \"p1\" }` and no `id`. A caller who passed an `include` asked a question with\n // a defined answer, and this select is already exactly that answer — which is\n // why the fix is deleting a condition rather than adding a branch.\n //\n // A miss is still fatal and costs nothing here: `{ where: { id: 99 }, data:\n // {} }` raises P2025, and `update` is in `ORTHROW`, so `RecordNotFoundError`\n // comes out of the existing machinery.\n //\n // Reachable on every model, including one carrying `@updatedAt`. That took a\n // change in `updateAssignments`: the stamp used to be unconditional, so it\n // was itself the assignment that kept this count off zero and made the whole\n // branch dead on the models most likely to want it. Prisma does not stamp a\n // call that sets no column — measured, see that function's docblock — so the\n // two fixes are the same fix. `many` is excluded by the branch above, so this\n // is `update` alone.\n const readInstead = assignments.length === 0;\n\n const returning = returningClause(schema, args, dialect, op, nested);\n\n const statement = readInstead\n ? concat(\n sql(`select `),\n returning.selected,\n sql(` from ${dialect.quoteIdent(schema.table)}`),\n where ? concat(sql(\" where \"), where) : sql(\"\"),\n )\n : concat(\n sql(`update ${dialect.quoteIdent(schema.table)} set `),\n joinFragments(assignments, \", \"),\n where ? concat(sql(\" where \"), where) : sql(\"\"),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, nested);\n}\n\n// --- delete / deleteMany ---------------------------------------------------\n\n/**\n * ~~KNOWN DIVERGENCE~~ — **fixed**, in `Model.$exec`, once iteration 5 existed.\n *\n * `delete` with an `include` on a cascading relation used to come back with the\n * children empty: the relation reads ran *after* the delete statement, and where\n * the schema declares `onDelete: Cascade` the database had already removed them.\n *\n * This note said the fix was \"to read the relations before the delete inside one\n * transaction, which is iteration 5's to provide — and once it does, this is the\n * case to write the test for\". Both happened:\n * `templates/saas-starter/app/models/delete-include.test.ts`.\n *\n * Nothing changed *here*. A `delete` with no relation to read still compiles to\n * one statement and opens no transaction; the read-then-delete pair lives at the\n * choke point, where a transaction is available and where the decision to open\n * one belongs.\n */\nfunction compileDelete(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n if (op === \"delete\") {\n matchUniqueKey(schema, args?.where, {\n model: schema.name,\n operation: op,\n argument: \"where\",\n });\n }\n\n const where = compileWhere(\n schema,\n args?.where,\n { dialect, operation: op },\n (callArgs) => callArgs?.where,\n );\n\n const returning = returningClause(schema, args, dialect, op, undefined);\n\n const statement = concat(\n sql(`delete from ${dialect.quoteIdent(schema.table)}`),\n where ? concat(sql(\" where \"), where) : sql(\"\"),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, undefined);\n}\n\n// --- upsert ----------------------------------------------------------------\n\n/**\n * `insert ... on conflict (<key>) do update set ...`, which both dialects\n * support and which does in one statement what Prisma's `upsert` describes.\n *\n * The alternative — read, then branch to a create or an update — is two\n * statements with a race between them: two concurrent upserts of the same key\n * both see \"absent\" and both insert, and one gets a unique violation. Since\n * there is no transaction until iteration 5, the single-statement form is not\n * just faster here, it is the only correct one.\n *\n * The conflict target comes from the `where`'s unique key, so it is a schema\n * identifier like every other. Nested writes are refused inside an upsert:\n * they would have to run before an insert that may turn out to be an update,\n * and there is nothing sensible to do with the row they created if it does.\n */\nfunction compileUpsert(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const key = matchUniqueKey(schema, args?.where, {\n model: schema.name,\n operation: op,\n argument: \"where\",\n });\n\n // Since Prisma 5 a `WhereUniqueInput` may carry extra non-unique filters\n // beside the key, and they narrow the match further. `update` and `delete`\n // honour that for free: their whole `where` goes through `compileWhere`.\n //\n // An upsert cannot. Its `where` becomes an `on conflict (...)` target, which\n // is a *key*, not a predicate — there is nowhere to put `deletedAt: null`.\n // Compiling only the key part would mean `where: { publicId, deletedAt: null }`\n // updating a soft-deleted row that Prisma would have left alone (Prisma would\n // find no match, attempt the create, and hit a unique violation). Refused\n // rather than narrowed, for the same reason the create-omits-the-key shape a\n // few lines down is.\n // KNOWN DIFFERENCE, and deliberate: this also refuses a `where` naming *two\n // different unique keys* — `{ id: 1, publicId: \"p\" }` — which Prisma accepts.\n // `on conflict` takes one target, so honouring both is not expressible;\n // picking `id` and ignoring `publicId` is the same silent narrowing the rest\n // of this guard exists to remove. A migrating application does hit a compile\n // error on a call Prisma ran happily, which is why it is listed under known\n // differences in the plan rather than only here.\n //\n // Note which key gets *named* in that case is an artifact of declaration\n // order — `matchUniqueKey` returns the primary key first, then `uniques` in\n // schema order — not of anything the caller wrote. Fine for a message that\n // lists every other member by name and tells the caller to choose, and not\n // worth resolving, since there is no principled way to prefer one.\n const named = key.length > 1 ? key.join(\"_\") : key[0];\n const extra = Object.keys(args.where as Record<string, unknown>).filter(\n (name) => name !== named && args.where[name] !== undefined,\n );\n if (extra.length > 0) {\n throw new UnsupportedQueryError(\n \"where\",\n schema.name,\n op,\n `The where clause carries ${extra.join(\", \")} beside the unique key ` +\n `'${named}'. An upsert compiles its where into an 'on conflict' ` +\n `target, which can only be a key, so the extra ${\n extra.length === 1 ? \"filter would be\" : \"filters would be\"\n } silently dropped. Name exactly one unique key here — or, if you meant ` +\n `to filter further, use findFirst plus update / create.`,\n );\n }\n\n for (const branch of [\"create\", \"update\"] as const) {\n assertNoNestedWrites(\n schema,\n args?.[branch],\n op,\n branch,\n \"Nested writes inside an upsert are not implemented: they would have \" +\n \"to run before it is known whether the row is being inserted or \" +\n \"updated.\",\n );\n }\n\n // `on conflict` only fires if the row being inserted actually collides on the\n // target. `upsert({ where: { id: 1 }, create: { email } })` never can — the\n // `create` supplies no `id`, so the insert mints a fresh one and the update\n // branch is unreachable. Prisma means something different by that call: find\n // by `where`, then update or create. Expressing *that* takes a read and a\n // write with no transaction between them, which is iteration 5's to give.\n //\n // So the case is refused rather than silently turned into an insert. This is\n // narrow: the ordinary shape — `where: { email }, create: { email, ... }` —\n // supplies the key and works.\n const absent = upsertAbsentConflictKey(schema, args, key);\n if (absent.length > 0) {\n throw new UnsupportedQueryError(\n \"upsert\",\n schema.name,\n op,\n `The where clause selects on ${key.join(\", \")}, but 'create' does not ` +\n `set ${absent.join(\", \")}, so 'on conflict' cannot express it. ` +\n `Model.upsert runs this as a read and a write inside one transaction ` +\n `instead; reaching this means the statement was compiled directly.`,\n );\n }\n\n const columns = withConflictKeyCheck(\n insertColumns(\n schema,\n args?.create,\n [],\n op,\n dialect,\n (callArgs) => callArgs?.create,\n ),\n schema,\n key,\n op,\n dialect,\n );\n\n // Inside the conflict clause every column read on the right of an `=` has to\n // name its table, or Postgres cannot tell the existing row from `excluded`.\n const qualifier = `${dialect.quoteIdent(schema.table)}.`;\n\n const assignments = updateAssignments(\n schema,\n args?.update,\n [],\n op,\n dialect,\n (callArgs) => callArgs?.update,\n qualifier,\n );\n\n const target = joinFragments(\n key.map((name) => sql(dialect.quoteIdent(fieldOf(schema, name).column))),\n \", \",\n );\n\n // `update: {}` is legal in Prisma and means \"leave the existing row alone,\n // but return it\". `do nothing` would return no row at all, so the row is\n // assigned to itself: an unqualified column on the right of a `do update set`\n // reads the *existing* row on both dialects.\n const effective =\n assignments.length > 0\n ? assignments\n : [\n sql(\n `${dialect.quoteIdent(fieldOf(schema, key[0]).column)} = ` +\n `${qualifier}${dialect.quoteIdent(fieldOf(schema, key[0]).column)}`,\n ),\n ];\n\n const returning = returningClause(schema, args, dialect, op, undefined);\n\n const statement = concat(\n sql(`insert into ${dialect.quoteIdent(schema.table)}`),\n valuesClause([columns], dialect),\n sql(\" on conflict (\"),\n target,\n sql(\") do update set \"),\n joinFragments(effective, \", \"),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, undefined);\n}\n\n/**\n * Which of the conflict key's fields `create` leaves unset — empty when\n * `on conflict` can express the upsert.\n *\n * **Exported because two callers must agree about it**, and a second copy of the\n * rule would be a rule that can drift: `compileUpsert` throws when it is\n * non-empty, and `Model.$exec` diverts the same calls to a read-then-write\n * before ever compiling them. If the two disagreed, either a divertable call\n * would raise or a raising call would be diverted into SQL that cannot conflict.\n */\nexport function upsertAbsentConflictKey(\n schema: ModelSchema,\n args: any,\n key: string[],\n): string[] {\n const supplied = suppliedFields(schema, args?.create);\n return key.filter((name) => !supplied.has(name));\n}\n\n/**\n * The other half of making `on conflict` mean what Prisma's `upsert` means.\n *\n * Compilation can prove the conflict key is *present* in `create`, but not that\n * it holds the same value as `where` — values do not exist at compile time, and\n * putting them there would break the plan cache. So the check happens at bind\n * time, where values are exactly what is in scope.\n *\n * Without it, `upsert({ where: { email: \"a\" }, create: { email: \"b\" }, ... })`\n * inserts \"b\" and conflicts — or does not — on \"b\", while Prisma looks for \"a\".\n * That is a silent divergence on a write, which is the failure this whole file\n * is arranged to prevent. Loud is better.\n */\nfunction withConflictKeyCheck(\n columns: WriteColumn[],\n schema: ModelSchema,\n key: string[],\n op: Operation,\n dialect: SqlDialect,\n): WriteColumn[] {\n const keyed = new Set(key);\n\n return columns.map((column) => {\n if (!keyed.has(column.field.name)) return column;\n\n const locate = whereValue(key, column.field.name);\n\n return {\n field: column.field,\n value: (args, context) => {\n const inserted = column.value(args, context);\n const selected = dialect.encode(locate(args), column.field);\n\n if (!sameEncoded(inserted, selected)) {\n throw new UnsupportedQueryError(\n \"upsert\",\n schema.name,\n op,\n `'${column.field.name}' is ${describe(selected)} in ` +\n `the where clause but ${describe(inserted)} in ` +\n `'create'. An upsert looks the row up by the where clause and ` +\n `inserts what 'create' says, so the two must agree on the key.`,\n );\n }\n\n return inserted;\n },\n };\n });\n}\n\n/**\n * Do two *encoded* values stand for the same thing?\n *\n * Not `===`, because `encode` is a per-dialect pass-through for whatever the\n * driver binds natively, and what a driver binds natively is not always a\n * primitive. Postgres passes a `DateTime` through as the `Date` it was given,\n * and both dialects pass `Bytes` through as a `Uint8Array` — so the same\n * instant and the same bytes arrive here as two distinct objects, and identity\n * refuses a correct upsert with a message printing two equal-looking strings.\n *\n * That is exactly the SQLite/Postgres asymmetry this codebase keeps finding:\n * SQLite encodes `DateTime` to a number and never noticed.\n *\n * Everything else falls through to `!==`, which is right for the string,\n * number, boolean and bigint an encoder can produce. `NaN` is not reachable —\n * it cannot be a unique key value that also round-trips through a `where`.\n */\nfunction sameEncoded(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {\n const left = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);\n const right = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);\n if (left.length !== right.length) return false;\n for (let i = 0; i < left.length; i++) {\n if (left[i] !== right[i]) return false;\n }\n return true;\n }\n\n return false;\n}\n\n/**\n * A value for an error message, distinct whenever `sameEncoded` says the two\n * values differ.\n *\n * That equivalence is the whole requirement, and it is easy to half-meet: the\n * first version of this stringified a `Date`, which made a genuine mismatch\n * read as `is X ... but X` and look like a framework bug rather than a wrong\n * argument. Two more ways to land back there:\n *\n * - Two different `Uint8Array`s of the same length both describing as\n * `\"2 bytes\"`. Hence the hex, truncated so a large blob does not fill the\n * message.\n * - `1n` and `1`, which `sameEncoded` separates and `String()` collapses.\n * Reachable because Prisma coerces a number into a `BigInt` field. Hence the\n * `typeof` suffix on anything that is not a string.\n */\nfunction describe(value: unknown): string {\n if (value instanceof Date) return JSON.stringify(value.toISOString());\n\n if (ArrayBuffer.isView(value)) {\n const bytes = new Uint8Array(\n value.buffer,\n value.byteOffset,\n value.byteLength,\n );\n // `Array.from` rather than a spread + `.map`: a `Uint8Array`'s own `map`\n // returns another `Uint8Array`, so the strings would be coerced back to\n // bytes and every one of them would become 0.\n const shown = Array.from(bytes.slice(0, 8), (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\");\n const ellipsis = bytes.length > 8 ? \"…\" : \"\";\n return `${bytes.length} bytes (0x${shown}${ellipsis})`;\n }\n\n if (typeof value === \"string\") return JSON.stringify(value);\n if (value === null || value === undefined) return String(value);\n\n return `${JSON.stringify(String(value))} (${typeof value})`;\n}\n\n/**\n * Reads one key field out of a `where`, in either of the two forms Prisma\n * accepts: named directly, or inside the compound object a composite\n * `@@unique` is addressed through (`{ username_provider: { username, ... } }`).\n */\nfunction whereValue(key: string[], field: string): (args: any) => unknown {\n const compound = key.length > 1 ? key.join(\"_\") : undefined;\n return (args) => {\n const where = args?.where;\n if (where === undefined || where === null) return undefined;\n if (compound !== undefined && where[compound] !== undefined) {\n return where[compound][field];\n }\n return where[field];\n };\n}\n\n// --- shared pieces ---------------------------------------------------------\n\ninterface WriteColumn {\n field: FieldSchema;\n value: Binder;\n}\n\n/**\n * `(cols) values (?, ?), (?, ?)`, or `default values` when the row supplies no\n * column at all — legal on both dialects, and the only way to insert a row made\n * entirely of database defaults.\n */\nfunction valuesClause(grid: WriteColumn[][], dialect: SqlDialect): Fragment {\n const columns = grid[0];\n if (columns.length === 0) return sql(\" default values\");\n\n const names = joinFragments(\n columns.map((column) => sql(dialect.quoteIdent(column.field.column))),\n \", \",\n );\n\n const tuples = grid.map((row) =>\n concat(\n sql(\"(\"),\n joinFragments(\n row.map((column) => fieldParam(column.field, dialect, column.value)),\n \", \",\n ),\n sql(\")\"),\n ),\n );\n\n return concat(\n sql(\" (\"),\n names,\n sql(\") values \"),\n joinFragments(tuples, \", \"),\n );\n}\n\n/**\n * Which columns an insert writes, and where each value comes from.\n *\n * The four sources, in the order they are consulted: a nested write that\n * resolved a foreign key, the caller's own `data`, a client-side default, and\n * the database. A required field that reaches the end of that list is an error\n * raised here, naming the field — rather than a `NOT NULL constraint failed`\n * from the driver naming a column and nothing else.\n */\nfunction insertColumns(\n schema: ModelSchema,\n data: unknown,\n contributions: readonly ForeignKeyContribution[],\n op: Operation,\n dialect: SqlDialect,\n locateData: (args: any) => any,\n): WriteColumn[] {\n if (data !== undefined && data !== null) {\n if (typeof data !== \"object\" || Array.isArray(data)) {\n throw new InvalidArgumentError(\n \"data\",\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n }\n\n const supplied = suppliedFields(schema, data);\n const contributed = new Map(\n contributions.map((contribution) => [contribution.field, contribution]),\n );\n\n for (const name of contributed.keys()) {\n if (supplied.has(name)) {\n throw new UnsupportedQueryError(\n `data.${name}`,\n schema.name,\n op,\n `'${name}' is set both directly and through a nested relation write. ` +\n `Prisma keeps those two forms exclusive; use one of them.`,\n );\n }\n }\n\n const columns: WriteColumn[] = [];\n\n for (const field of Object.values(schema.fields)) {\n const contribution = contributed.get(field.name);\n if (contribution) {\n columns.push({\n field,\n value: (args, context) =>\n dialect.encode(contribution.value(args, context), field),\n });\n continue;\n }\n\n if (supplied.has(field.name)) {\n if (field.isList) {\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n assertListOperand(schema, field, (data as any)?.[field.name], op, [\"set\"]);\n }\n\n // `{ tags: { set: [...] } }` is what Prisma documents for a list, and it\n // is accepted in `create` as well as in `update` — where a bare array is\n // also accepted, and means the same thing. Unwrapped at *compile* time\n // rather than in the binder because the two spellings are two argument\n // shapes and so already two plan-cache entries; deciding it here keeps\n // the binder a pure function of the value it is handed.\n const setForm = isListSetOperand(field, (data as any)?.[field.name]);\n\n columns.push({\n field,\n value: valueBinder(schema, op, field, dialect, (args) => {\n const value = locateData(args)?.[field.name];\n return setForm ? value?.set : value;\n }),\n });\n continue;\n }\n\n if (hasClientSideValue(field)) {\n columns.push({ field, value: defaultBinder(field, dialect) });\n continue;\n }\n\n // Left out of the statement entirely: the database supplies it, either from\n // its own default or as NULL.\n if (field.default || field.nullable) continue;\n\n // **A scalar list is never missing**, whatever the schema says about\n // required-ness. Measured against a generated 6.19 client: `create({ data:\n // { id: 900 } })` on a model whose every list is `NOT NULL` with no\n // `@default` succeeds, and every one of them reads back as `[]`. So Prisma\n // treats \"no value\" as the empty list rather than as an omission, and a\n // column with no database default gives it no choice — leaving the column\n // out would violate the NOT NULL constraint.\n //\n // This was a `MissingRequiredValueError` until the differential harness ran:\n // four `create` cases refused a call Prisma answers. It is exactly the kind\n // of divergence no amount of reading the docs produces, because the docs\n // describe the *input type* — where the field is optional — and say nothing\n // about what is written when it is absent.\n if (field.isList) {\n // Asked *here* as well as on the supplied path above, because this branch\n // invents a value the caller never wrote — and an unasked dialect is how\n // `create({ data: { id: 1 } })` on SQLite compiled a statement binding\n // raw JS arrays for the driver to reject with a type error, where naming\n // the column would have said \"sqlite has no array type … It works on\n // postgres\". The check belongs to the *column*, not to the caller\n // mentioning it.\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n columns.push({ field, value: emptyList(field, dialect) });\n continue;\n }\n\n throw new MissingRequiredValueError(schema.name, op, field.name);\n }\n\n return columns;\n}\n\n/**\n * Refuses an operator map a scalar list does not take — `{ increment: 1 }` —\n * at **compile** time.\n *\n * The value-shaped refusal in `valueBinder` would eventually catch it, and too\n * late: `isOperatorObject` answers false for an operator a list does not have,\n * so `{ counts: { increment: 1 } }` was read as a *value* and travelled all the\n * way to the binder before anything objected. Compile is a pure function of the\n * argument shape and this is a shape question, so it belongs here — the same\n * call `assertCompositeInOperand` records making for the same reason.\n *\n * Note this is unambiguous even for a `Json[]`, where an object is a plausible\n * element: the column's value is an *array*, so a bare object in this position\n * is never data. `isOperatorObject` relies on the same fact.\n */\nfunction assertListOperand(\n schema: ModelSchema,\n field: FieldSchema,\n value: unknown,\n op: Operation,\n /**\n * The operators legal in *this* position. An insert takes `set` only —\n * Prisma's create input for a list is `T[] | { set: T[] }`, with no `push`,\n * and there is nothing for a `push` to append to on a row that does not exist\n * yet.\n */\n allowed: readonly string[],\n): void {\n if (!field.isList) return;\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Date ||\n ArrayBuffer.isView(value)\n ) {\n return;\n }\n\n const given = Object.keys(value as Record<string, unknown>).filter(\n (key) => (value as Record<string, unknown>)[key] !== undefined,\n );\n if (given.length === 1 && allowed.includes(given[0])) return;\n\n throw new UnsupportedQueryError(\n `data.${field.name}`,\n schema.name,\n op,\n `'${field.name}' is a scalar list, so it takes ${allowed.join(\" or \")} — ` +\n `or a bare array. Received ${\n given.length === 0 ? \"an empty object\" : `{ ${given.join(\", \")} }`\n }. The arithmetic operators apply to a number, not to a list of them.`,\n );\n}\n\n/**\n * `{ set: [...] }` on a scalar list, which is the spelling Prisma documents and\n * which an insert accepts as readily as an update.\n *\n * Unambiguous in a way the scalar `Json` case is not — see `isOperatorObject` —\n * because a list column's data form is always an array, so an object here can\n * only be the operator.\n */\nfunction isListSetOperand(field: FieldSchema, value: unknown): boolean {\n return (\n field.isList === true &&\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n !(value instanceof Date) &&\n !ArrayBuffer.isView(value) &&\n Object.keys(value).length === 1 &&\n \"set\" in value\n );\n}\n\n/** The scalar fields a `data` object actually sets, validated against the schema. */\nfunction suppliedFields(\n schema: ModelSchema,\n data: unknown,\n): Set<string> {\n const out = new Set<string>();\n if (typeof data !== \"object\" || data === null) return out;\n\n for (const [key, value] of Object.entries(data as Record<string, unknown>)) {\n // Prisma treats an explicit `undefined` as absent, which is how conditional\n // writes are expressed in application code.\n if (value === undefined) continue;\n // Relations are the nested-write planner's business.\n if (key in schema.relations) continue;\n if (!(key in schema.fields)) {\n throw new UnknownFieldError(key, schema.name, Object.keys(schema.fields));\n }\n out.add(key);\n }\n\n return out;\n}\n\n/**\n * Refuse a `data` object that names a relation, for the operations that have no\n * nested-write planner behind them.\n *\n * `suppliedFields` skips relation keys rather than rejecting them, because on\n * `create` and `update` they are the nested planner's business. Everywhere else\n * that same skip is a silent drop, so those callers say so here — by name, and\n * before anything is compiled.\n */\nfunction assertNoNestedWrites(\n schema: ModelSchema,\n data: unknown,\n op: Operation,\n path: string,\n reason: string,\n): void {\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) return;\n\n for (const [name, value] of Object.entries(data as Record<string, unknown>)) {\n if (value === undefined) continue;\n if (name in schema.relations) {\n throw new UnsupportedQueryError(`${path}.${name}`, schema.name, op, reason);\n }\n }\n}\n\n/**\n * `set` assignments for an update, in schema order.\n *\n * `@updatedAt` is appended unless the caller set it explicitly. Applying it on\n * *create* as well is handled by `hasClientSideValue`; missing that half is the\n * easy and quiet version of this bug, since the column is usually NOT NULL and\n * only fails on the models where Prisma made it nullable.\n *\n * **The stamp needs a column beside it**, which is not what \"every write stamps\n * `@updatedAt`\" would suggest and is the rule Prisma actually follows. Measured\n * against 6.19.2/SQLite, seeding `updatedAt` to the epoch and reading it back:\n *\n * data: {} epoch not stamped\n * data: { profile: { create: … } } epoch not stamped\n * data: { profile: { update: … } } epoch not stamped\n * data: { name: \"real\" } now stamped\n * data: { organization: { connect: … } } now stamped\n * data: { organizationId: null } now stamped\n *\n * The first three write no column of *this* row — a to-one whose key is on the\n * child changes the child — and Prisma leaves the stamp alone for all three. So\n * the condition is \"this statement sets at least one other column\", which is\n * what `writesAColumn` asks, rather than \"this call happened\".\n *\n * Stamping unconditionally was load-bearing in the wrong direction twice. It\n * made #355's empty-`data` read unreachable on any model carrying the attribute\n * — the majority case, and the one the issue was filed from — because the stamp\n * *was* the assignment that kept `assignments.length` off zero. And it put a\n * timestamp Prisma does not write on every nested to-one write #354 added,\n * where the differential harness could not see it: `updatedAt` is volatile, so\n * both sides compare as the descriptor `\"date\"` and two different instants\n * match. It took a by-value assertion to catch.\n *\n * **KNOWN DIVERGENCE — an owning-side `disconnect` stamps here and does not in\n * Prisma.** Measured beside the rest: `data: { organization: { disconnect: true\n * } }` writes `organizationId = NULL` (verified, the column really is cleared)\n * and leaves `updatedAt` at the epoch, while `connect` one line above stamps\n * it. Both write the same column through the same operand family, so this is\n * Prisma disagreeing with itself rather than a rule to follow. gemi contributes\n * the null as an ordinary assignment and therefore stamps, which is the answer\n * `connect`, a hand-written `organizationId: null`, and every other column\n * write already give. Pre-existing, unchanged here, and matching it would mean\n * special-casing one operand to reproduce an inconsistency.\n *\n * **...and the *filter* arm (#359) carries it one step further: it stamps even\n * when it detaches nothing.** `nested-writes.ts`'s owning-side `disconnect`\n * defaults `context.resolved[fkField]` to the value already in the column and\n * pushes the contribution unconditionally — it has to, because the statement's\n * text cannot depend on a value read at bind time — so the assignment is in the\n * SET list whether or not the linked row matched. Measured on both sides\n * against a schema built for it, since the template's `Profile` has no\n * `@updatedAt` (Prisma 6.19.2, SQLite, a one-to-one whose *owner* carries the\n * attribute, `updatedAt` seeded to the epoch):\n *\n * disconnect: true update … set \"userId\" = ?\n * -> key nulled, updatedAt at the epoch\n * disconnect: { name: \"Ada\" } update … set \"userId\" = ? where … and\n * exists(select … where \"name\" = ? …)\n * -> key nulled, updatedAt at the epoch\n * disconnect: { name: \"Nobody\" } the same statement, matching zero rows\n * -> nothing written at all\n * disconnect: false no update statement at all\n * -> nothing written at all\n *\n * So Prisma never stamps through this operand, matching filter or not — that is\n * the paragraph above — and on a miss it writes *no row*, because the filter\n * rides inside the `UPDATE`'s own `where` as an `exists` subquery. gemi's plan\n * text is fixed at compile time and reads\n * `update \"User\" set \"organizationId\" = ?, \"updatedAt\" = ? where \"id\" = ?` for\n * every arm that writes, so `User.update({ where: { id: 1 }, data: {\n * organization: { disconnect: { name: \"Nobody\" } } } })` leaves\n * `organizationId` at 1 and moves `updatedAt` from the epoch to now: a call\n * that changed no column of the row still stamps it.\n *\n * **There is no test for the stamp half and there cannot be one in this\n * fixture**, which is why this docblock is the deliverable rather than a\n * pointer to one. The template's only one-to-one owner is `Profile`, which has\n * no `@updatedAt` column, and the differential harness lists `updatedAt` in its\n * volatile set (`differential.ts`), so both sides compare as the descriptor\n * `\"date\"` and two different instants match. The measurements above were taken\n * against a purpose-built schema, not against the template's.\n *\n * **The two statements are also a lost-update window**, which `disconnect: true`\n * does not have and Prisma does not have on either arm. The filter arm reads the\n * current key with a `findFirst` and writes it back in a *second* statement, so\n * under READ COMMITTED a concurrent transaction that `connect`s a different\n * partner in between has its value silently reverted — by the call that decided\n * to do nothing. Prisma's single guarded `UPDATE` above cannot lose it: there is\n * no read to be stale, and on a miss there is no write at all.\n */\nfunction updateAssignments(\n schema: ModelSchema,\n data: unknown,\n contributions: readonly ForeignKeyContribution[],\n op: Operation,\n dialect: SqlDialect,\n locateData: (args: any) => any = (args) => args?.data,\n /**\n * Prefix for a column read on the *right* of an assignment — `\"User\".`\n * inside an `on conflict do update`, empty in a plain `update`.\n *\n * Postgres puts both the target row and the proposed `excluded` row in scope\n * inside a conflict clause, so a bare `\"n\" = \"n\" + $1` there is rejected:\n * `column reference \"n\" is ambiguous`. SQLite accepts either form, and so\n * does Postgres in a plain `update` — verified against both — which is why\n * the qualifier is applied where it is needed rather than everywhere.\n */\n qualifier = \"\",\n): Fragment[] {\n if (data !== undefined && data !== null) {\n if (typeof data !== \"object\" || Array.isArray(data)) {\n throw new InvalidArgumentError(\n \"data\",\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n }\n\n const supplied = suppliedFields(schema, data);\n const contributed = new Map(\n contributions.map((contribution) => [contribution.field, contribution]),\n );\n\n // Asked before the loop rather than from `out.length`, so the answer does not\n // depend on where `@updatedAt` happens to sit in schema order: a model that\n // declares it first would otherwise see an empty `out` and skip a stamp it\n // owes. Both sets hold scalar field names only — `suppliedFields` skips\n // relation keys, which is exactly the distinction being drawn here.\n const writesAColumn = contributed.size > 0 || supplied.size > 0;\n\n const out: Fragment[] = [];\n\n for (const field of Object.values(schema.fields)) {\n const column = dialect.quoteIdent(field.column);\n const contribution = contributed.get(field.name);\n\n if (contribution) {\n out.push(\n concat(\n sql(`${column} = `),\n param((args, context) =>\n dialect.encode(contribution.value(args, context), field),\n ),\n ),\n );\n continue;\n }\n\n if (supplied.has(field.name)) {\n out.push(\n assignment(\n schema,\n field,\n column,\n `${qualifier}${column}`,\n data,\n op,\n dialect,\n (args) => locateData(args)?.[field.name],\n ),\n );\n continue;\n }\n\n // A write that sets a column stamps `@updatedAt`; one that sets none does\n // not, because there is no write to date. See the docblock's table.\n if (field.isUpdatedAt && writesAColumn) {\n out.push(\n concat(\n sql(`${column} = `),\n fieldParam(field, dialect, defaultBinder(field, dialect)),\n ),\n );\n }\n }\n\n return out;\n}\n\n/**\n * Prisma's update operators. `set` is the explicit spelling of a plain\n * assignment; the arithmetic four read the column and write it back, so they\n * are the one place a column name appears on the right of an `=`.\n *\n * `push` is the sixth and belongs to scalar lists only, so it lives beside them\n * rather than here — see {@link listOperators}. Keeping it out of this table is\n * what makes `{ tags: { increment: 1 } }` and `{ count: { push: 1 } }` both\n * errors that name the field's kind, rather than one of them compiling.\n */\nconst ARITHMETIC: Record<string, string> = {\n increment: \"+\",\n decrement: \"-\",\n multiply: \"*\",\n divide: \"/\",\n};\n\n/** The update operators a scalar list takes: `set` and `push`, and nothing else. */\nconst LIST_OPERATORS = [\"set\", \"push\"] as const;\n\nfunction listOperators(field: FieldSchema): readonly string[] {\n return field.isList ? LIST_OPERATORS : [\"set\", ...Object.keys(ARITHMETIC)];\n}\n\nfunction assignment(\n schema: ModelSchema,\n field: FieldSchema,\n /** The column as the assignment's target, always unqualified. */\n column: string,\n /** The same column read as a value — qualified inside a conflict clause. */\n source: string,\n data: unknown,\n op: Operation,\n dialect: SqlDialect,\n locate: (args: any) => any,\n): Fragment {\n const value = (data as Record<string, unknown>)[field.name];\n\n if (field.isList) {\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n assertListOperand(schema, field, value, op, LIST_OPERATORS);\n }\n\n if (isOperatorObject(value, field)) {\n const keys = Object.keys(value as Record<string, unknown>).filter(\n (key) => (value as Record<string, unknown>)[key] !== undefined,\n );\n\n if (keys.length !== 1) {\n throw new UnsupportedQueryError(\n `data.${field.name}`,\n schema.name,\n op,\n `Expected exactly one of ${listOperators(field).join(\", \")}.`,\n );\n }\n\n const [key] = keys;\n const at = (args: any) => locate(args)?.[key];\n\n if (key === \"set\") {\n return concat(\n sql(`${column} = `),\n fieldParam(field, dialect, valueBinder(schema, op, field, dialect, at)),\n );\n }\n\n if (key === \"push\") {\n // `array_cat(<column>, $1)` — the column on the right of an `=`, like the\n // arithmetic four below, and for the same reason: the new value is a\n // function of the old one.\n //\n // The operand is normalised to a list **at bind time**, because Prisma\n // accepts both `push: \"a\"` and `push: [\"a\", \"b\"]` and the two are the\n // same statement. That normalisation is also what lets the dialect use a\n // single-signature function: `||` would read the two spellings as\n // different operators — see `PostgresDialect.listPush`.\n return concat(\n sql(`${column} = `),\n dialect.listPush(\n source,\n fieldParam(\n field,\n dialect,\n valueBinder(schema, op, field, dialect, (args) => {\n const supplied = at(args);\n return Array.isArray(supplied) ? supplied : [supplied];\n }),\n ),\n ),\n );\n }\n\n return concat(\n sql(`${column} = ${source} ${ARITHMETIC[key]} `),\n fieldParam(field, dialect, valueBinder(schema, op, field, dialect, at)),\n );\n }\n\n return concat(\n sql(`${column} = `),\n fieldParam(field, dialect, valueBinder(schema, op, field, dialect, locate)),\n );\n}\n\n/**\n * True for `{ increment: 1 }`, false for a plain value.\n *\n * A `Json` column is excluded because `{ set: ... }` is a legal *value* there as\n * well as an operator, and there is no way to tell them apart structurally.\n * Prisma resolves the ambiguity through its types; we resolve it by treating a\n * Json column's object as data, which is the reading that never loses the\n * caller's value.\n *\n * **A `Json[]` is not excluded**, and the exclusion above is why: the ambiguity\n * it exists for cannot arise on a list. A `Json` column can legitimately hold\n * the object `{ set: 1 }`; a `Json[]` column holds an *array*, so an object\n * operand is never data there and reading it as an operator loses nothing.\n * Without this the one spelling Prisma documents for writing a list —\n * `{ tags: { set: [...] } }` — would have been stored as a single JSON object\n * on exactly the element type where that is a plausible-looking value.\n */\nfunction isOperatorObject(value: unknown, field: FieldSchema): boolean {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Date ||\n ArrayBuffer.isView(value) ||\n (field.type === \"Json\" && !field.isList)\n ) {\n return false;\n }\n\n const operators = listOperators(field);\n const keys = Object.keys(value as Record<string, unknown>);\n if (keys.length === 0) return false;\n return keys.every((key) => operators.includes(key));\n}\n\n/**\n * Every write value passes through here — `create`, `createMany`, `update`'s\n * `set` and its bare form, and `upsert` — which is what makes it the one place\n * a value-dependent refusal has to live.\n *\n * It throws at **bind** time rather than compile time, and that is forced\n * rather than chosen: compile is a pure function of the argument *shape* and\n * never sees a value (invariant 2), so a value nobody may write cannot be\n * detected there. The schema and operation are closed over instead, so the\n * error still says which field of which model on which operation — the context\n * `fieldParam` does not have, and the reason the refusal is not down there.\n */\nfunction valueBinder(\n schema: ModelSchema,\n op: Operation,\n field: FieldSchema,\n dialect: SqlDialect,\n locate: (args: any) => any,\n): Binder {\n return (args) => {\n const value = locate(args);\n\n // `AnyNull` means \"either kind of null\", which is a question about existing\n // rows and not something a column can hold. Prisma raises here too. Left\n // alone it has no enumerable properties, so it serialised to the jsonb\n // object `{}` — a plausible-looking value, silently wrong, with nothing\n // raised: #259, and the same silent mis-store #222 closed for the other two\n // sentinels.\n if (jsonNullKind(value) === \"any\") {\n throw new InvalidArgumentError(\n `data.${field.name}`,\n schema.name,\n op,\n `Prisma.AnyNull is a filter operand, not a value — Prisma rejects it ` +\n `in a write here too. Write Prisma.DbNull for a SQL NULL column, or ` +\n `Prisma.JsonNull for the JSON value null.`,\n );\n }\n\n // A list operand is checked here rather than left to `encode`, for the\n // reason this whole function exists: the dialect has the value and nothing\n // else, so its refusal can only report an ORM bug. The schema and operation\n // are closed over here, so this one says which field of which model.\n if (field.isList && value !== null && value !== undefined) {\n if (!Array.isArray(value)) {\n throw new InvalidArgumentError(\n `data.${field.name}`,\n schema.name,\n op,\n `'${field.name}' is a scalar list, so it takes an array — or ` +\n `{ set: [...] } / { push: … }. Received ${typeof value}.`,\n );\n }\n if (value.some((element) => jsonNullKind(element) === \"any\")) {\n throw new InvalidArgumentError(\n `data.${field.name}`,\n schema.name,\n op,\n `Prisma.AnyNull is a filter operand, not a value, and that does not ` +\n `change for being inside a list.`,\n );\n }\n }\n\n return dialect.encode(value, field);\n };\n}\n\n/**\n * `{}` for a scalar list nobody supplied — what Prisma writes, measured rather\n * than assumed. See the note in `insertColumns`.\n */\nfunction emptyList(field: FieldSchema, dialect: SqlDialect): Binder {\n return () => dialect.encode([], field);\n}\n\n/**\n * Whether an absent value for this field means \"write the empty list\" — a\n * scalar list with no database default of its own to fall back to.\n *\n * A list *with* a default stays out of the statement so the default fires,\n * which is the same rule every other field follows and produces the same rows.\n */\nfunction suppliesEmptyList(field: FieldSchema): boolean {\n return field.isList === true && !field.default && !field.nullable;\n}\n\nfunction defaultBinder(field: FieldSchema, dialect: SqlDialect): Binder {\n // Read per call, never at compile time: a cuid must differ per row and `now`\n // must be the instant of *this* operation, not of the compilation that may\n // have happened thousands of calls ago.\n return (_args, context) =>\n dialect.encode(clientSideValue(field, context.now), field);\n}\n\ninterface Returning {\n clause: Fragment;\n /** The same columns without the `returning` keyword, for a select. */\n selected: Fragment;\n fields: FieldSchema[];\n hidden?: string[];\n relations: ReturnType<typeof planRelations>[\"plans\"];\n counts: CountPlan[];\n}\n\n/**\n * The `RETURNING` list.\n *\n * For a row-returning write it is the caller's `select` — the same resolution a\n * read does — plus any key columns the relation planner or a nested `after`\n * step needs and the caller did not ask for. Those extra columns are stripped\n * from the result once they have been used, exactly as on the read path.\n *\n * For a counting write it is one column, because the count is the number of\n * rows that come back.\n */\nfunction returningClause(\n schema: ModelSchema,\n args: any,\n dialect: SqlDialect,\n op: Operation,\n nested: NestedWritePlanning | undefined,\n): Returning {\n if (COUNTING.has(op)) {\n return {\n clause: sql(` returning ${keyColumn(schema, dialect)}`),\n selected: sql(keyColumn(schema, dialect)),\n fields: [],\n relations: [],\n counts: [],\n };\n }\n\n const selection = resolveSelection(schema, args, op);\n const { plans, keyFields } = planRelations(schema, args, dialect, op);\n const { fields, hidden } = withKeyFields(schema, selection, [\n ...keyFields,\n ...(nested?.keyFields ?? []),\n ]);\n const counts = planRelationCounts(schema, args, dialect, op);\n\n const columns = joinFragments(\n [\n ...fields.map((field) => sql(dialect.quoteIdent(field.column))),\n // Last, for the same reason they go last on a read: the shaper reads\n // scalars by position and `_count` is attached afterwards from the raw\n // row. The reading `update` below projects the same list, so a `_count`\n // survives that path too.\n ...counts.map((count) => count.column),\n ],\n \", \",\n );\n\n return {\n clause: concat(sql(\" returning \"), columns),\n // The same list without the keyword, for the one statement that reads the\n // row rather than writing it — an `update` with no column to set, whether\n // because its `data` held only nested writes or because it was empty. See\n // `compileUpdate`.\n selected: columns,\n fields,\n hidden,\n relations: plans,\n counts,\n };\n}\n\n/**\n * The plan for a counting write that Prisma answers `{ count: 0 }` to without\n * touching the database: `createMany` with an empty list, and `updateMany` with\n * an empty `data`.\n *\n * A plan must have a statement, so there is one. A constant-false select is the\n * cheapest thing that yields zero rows on both dialects, and it keeps these\n * cases on exactly the same code path as every other write — no branch in the\n * choke point, no plan that is a plan in name only, and the count still comes\n * from the number of rows returned rather than from a hard-coded zero, so the\n * shaper is the shaper every other counting write uses.\n *\n * It costs one round trip that Prisma does not make. That is the price of the\n * uniformity above, and it is paid only by calls that asked for nothing.\n */\nfunction zeroCountPlan(\n schema: ModelSchema,\n op: Operation,\n dialect: SqlDialect,\n): QueryPlan {\n const key = keyColumn(schema, dialect);\n const { text, binders } = render(\n sql(`select ${key} from ${dialect.quoteIdent(schema.table)} where false`),\n dialect,\n { model: schema.name, operation: op },\n );\n return {\n text,\n bind: bindValues(binders),\n shape: (returned) => ({ count: returned.length }),\n };\n}\n\n/** The narrowest column that still identifies a row, for counting writes. */\nfunction keyColumn(schema: ModelSchema, dialect: SqlDialect): string {\n const name = schema.primaryKey[0] ?? Object.keys(schema.fields)[0];\n return dialect.quoteIdent(schema.fields[name].column);\n}\n\nfunction fieldOf(schema: ModelSchema, name: string): FieldSchema {\n const field = schema.fields[name];\n if (!field) {\n throw new UnknownFieldError(name, schema.name, Object.keys(schema.fields));\n }\n return field;\n}\n\nfunction plan(\n schema: ModelSchema,\n statement: Fragment,\n dialect: SqlDialect,\n op: Operation,\n returning: Returning,\n nested: NestedWritePlanning | undefined,\n): QueryPlan {\n const { text, binders } = render(statement, dialect, { model: schema.name, operation: op });\n\n const shaper = buildRowShaper(\n returning.fields,\n dialect,\n returning.relations.map((relation) => ({\n key: relation.as,\n kind: relation.kind,\n })),\n );\n\n const single = SINGLE_ROW.has(op);\n const counting = COUNTING.has(op);\n\n return {\n text,\n bind: bindValues(binders),\n relations: returning.relations.length > 0 ? returning.relations : undefined,\n strategies:\n returning.relations.length > 0\n ? strategiesOf(returning.relations)\n : undefined,\n hidden: returning.hidden,\n before: nested && nested.before.length > 0 ? nested.before : undefined,\n after: nested && nested.after.length > 0 ? nested.after : undefined,\n counts: returning.counts.length > 0 ? true : undefined,\n shape(rows) {\n // The count *is* the number of returned rows — see the note at the top of\n // this file on why it does not come from driver metadata.\n if (counting) return { count: rows.length };\n\n const shaped = shaper(rows);\n\n // `_count` came back as extra columns the shaper knows nothing about,\n // under aliases carrying a dot. Assembled into one object per row,\n // because that is the shape Prisma returns — and the same assembly\n // `compileRead` does, deliberately spelled the same way.\n if (returning.counts.length > 0) {\n for (let i = 0; i < shaped.length; i++) {\n const raw = (rows[i] as Record<string, unknown>) ?? {};\n const totals: Record<string, number> = {};\n for (const count of returning.counts) {\n totals[count.as] = Number(raw[count.alias] ?? 0);\n }\n shaped[i]._count = totals;\n }\n }\n // `null` when nothing matched. `$exec` turns that into\n // `RecordNotFoundError` for the operations Prisma raises on, where the\n // model's name is in scope for the message.\n return single ? (shaped[0] ?? null) : shaped;\n },\n };\n}\n\nfunction listOf(value: unknown): any[] {\n if (value === undefined || value === null) return [];\n return Array.isArray(value) ? value : [value];\n}\n\nfunction assertArgs(schema: ModelSchema, op: Operation, args: any): void {\n if (args === undefined || args === null) {\n throw new UnsupportedQueryError(\n \"args\",\n schema.name,\n op,\n `${op} requires arguments.`,\n );\n }\n\n if (typeof args !== \"object\" || Array.isArray(args)) {\n throw new InvalidArgumentError(\n String(args),\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n\n if (args.select !== undefined && args.include !== undefined) {\n throw new UnsupportedQueryError(\n \"select + include\",\n schema.name,\n op,\n \"Prisma allows only one of them on the same query.\",\n );\n }\n\n const allowed = WRITE_ARGS[op];\n for (const key of Object.keys(args).sort()) {\n if (args[key] === undefined) continue;\n if (!allowed.has(key)) {\n throw new UnsupportedQueryError(\n key,\n schema.name,\n op,\n `${op} takes ${[...allowed].sort().join(\", \")}.`,\n );\n }\n }\n\n for (const required of requiredArgs(op)) {\n if (args[required] === undefined) {\n throw new UnsupportedQueryError(\n required,\n schema.name,\n op,\n `${op} requires '${required}'.`,\n );\n }\n }\n}\n\n/**\n * Which arguments Prisma makes non-optional, matched exactly.\n *\n * `updateMany` and `deleteMany` take an *optional* `where` — `deleteMany({})`\n * legitimately empties a table. Requiring one here would be a safety rail\n * Prisma does not have, and the differential harness would call it a\n * divergence, which is the right verdict: a guard belongs in a policy\n * (iteration 6), not in the compiler.\n */\nfunction requiredArgs(op: Operation): string[] {\n switch (op) {\n case \"create\":\n case \"createMany\":\n return [\"data\"];\n case \"update\":\n return [\"data\", \"where\"];\n case \"updateMany\":\n return [\"data\"];\n case \"delete\":\n return [\"where\"];\n case \"upsert\":\n return [\"where\", \"create\", \"update\"];\n default:\n return [];\n }\n}\n",
21
+ "import { clientSideValue, hasClientSideValue } from \"../defaults\";\nimport type { SqlDialect } from \"../dialect\";\nimport {\n InvalidArgumentError,\n MissingRequiredValueError,\n ReturningUnsupportedError,\n UnknownFieldError,\n UnsupportedQueryError,\n} from \"../errors\";\nimport { jsonNullKind } from \"../json-null\";\nimport type { Operation, QueryPlan } from \"../plan\";\nimport type { FieldSchema, ModelSchema } from \"../schema\";\nimport { buildRowShaper } from \"../shape\";\nimport {\n type Binder,\n type Fragment,\n bindValues,\n concat,\n joinFragments,\n param,\n render,\n sql,\n} from \"./fragment\";\nimport { fieldParam } from \"./cast\";\nimport {\n type ForeignKeyContribution,\n type NestedWritePlanning,\n planNestedWrites,\n} from \"./nested-writes\";\nimport { planRelations, strategiesOf } from \"./plan-relations\";\nimport { type CountPlan, planRelationCounts } from \"./relation-count\";\nimport { resolveSelection, withKeyFields } from \"./select\";\nimport { matchUniqueKey } from \"./unique\";\nimport { assertListDialect, compileWhere } from \"./where\";\n\n/**\n * The write surface: `create`, `createMany`, `update`, `updateMany`, `delete`,\n * `deleteMany`, `upsert`.\n *\n * Everything here obeys the same two rules the read compiler does, and for the\n * same reasons (invariant 2): the SQL text is a pure function of the argument\n * *shape*, and every value is a bound parameter. A `create` with the same field\n * set is one plan whatever the values are.\n *\n * Two decisions worth finding here rather than inferring from the code:\n *\n * **1. Row counts come from `RETURNING`, not from driver metadata.**\n * `updateMany` and `deleteMany` return `{ count }`, and the obvious source is\n * whatever the driver reports about the statement. Measured, that source is\n * undocumented: Bun's SQLite driver leaves `affectedRows` **null** on every\n * statement and puts the number on a `count` property instead. So the count is\n * the number of rows a `RETURNING <primary key>` gives back — one statement\n * shape on every dialect, exact by construction, and dependent on nothing\n * undocumented.\n *\n * `count` has since been measured on Postgres too, and it agrees: same property,\n * same value, `affectedRows` null on both, across `update`, `delete`, `insert`,\n * a statement matching nothing and one carrying `returning`. That does not\n * change the decision here — `RETURNING` is still exact and still asks the\n * driver for nothing — but it is what lets `DB.execute` report a *raw* write's\n * rowcount, where the statement is the caller's and there is no `RETURNING` to\n * add. See `facades/DB.ts`.\n * It costs one key column per affected row on the wire, which is a real cost on\n * a very large `deleteMany`; iteration 7 owns performance and can revisit it\n * with a benchmark rather than a guess.\n *\n * **2. `createMany` fills defaults explicitly rather than grouping rows.**\n * Prisma allows rows with different key sets in one call, and a single multi-row\n * `INSERT` cannot express that directly — every row must supply every column.\n * The column list is therefore the union of every row's keys, and a row missing\n * one gets its client-side default, or `NULL` if the column is nullable. The one\n * case that cannot be filled is a column with a *database* default that some\n * rows supply and others do not: `NULL` would override the default rather than\n * request it, and the `DEFAULT` keyword is not available — SQLite rejects it\n * inside a `VALUES` list (verified: `near \"DEFAULT\": syntax error`). That case\n * is refused with an error naming the column, rather than silently written wrong.\n */\n\n// `omit` rides along wherever a payload comes back, which is every write but\n// the three that return a count — Prisma types it the same way. It is resolved\n// by `resolveSelection`, so the `RETURNING` list narrows exactly as a read's\n// column list does and the omitted column is never read.\nexport const WRITE_ARGS: Record<string, Set<string>> = {\n create: new Set([\"data\", \"select\", \"include\", \"omit\"]),\n createMany: new Set([\"data\", \"skipDuplicates\"]),\n update: new Set([\"data\", \"where\", \"select\", \"include\", \"omit\"]),\n updateMany: new Set([\"data\", \"where\"]),\n delete: new Set([\"where\", \"select\", \"include\", \"omit\"]),\n deleteMany: new Set([\"where\"]),\n upsert: new Set([\"where\", \"create\", \"update\", \"select\", \"include\", \"omit\"]),\n};\n\n/** The writes that return one row, and raise when they match none. */\nconst SINGLE_ROW = new Set([\"create\", \"update\", \"delete\", \"upsert\"]);\n\n/** The writes that return `{ count }` rather than rows. */\nconst COUNTING = new Set([\"createMany\", \"updateMany\", \"deleteMany\"]);\n\nexport function isWriteOperation(op: Operation): boolean {\n return op in WRITE_ARGS;\n}\n\nexport function compileWrite(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n assertArgs(schema, op, args);\n\n // Every write reports its result — the row, or the number of rows — through\n // `RETURNING`. Asked rather than assumed so MySQL is a named gap.\n if (!dialect.supportsReturning) {\n throw new ReturningUnsupportedError(schema.name, op, dialect.name);\n }\n\n switch (op) {\n case \"create\":\n return compileCreate(schema, op, args, dialect);\n case \"createMany\":\n return compileCreateMany(schema, op, args, dialect);\n case \"update\":\n case \"updateMany\":\n return compileUpdate(schema, op, args, dialect);\n case \"delete\":\n case \"deleteMany\":\n return compileDelete(schema, op, args, dialect);\n case \"upsert\":\n return compileUpsert(schema, op, args, dialect);\n default:\n throw new UnsupportedQueryError(\n op,\n schema.name,\n op,\n `'${op}' is not a write operation. The writes are ` +\n `${Object.keys(WRITE_ARGS).sort().join(\", \")}.`,\n );\n }\n}\n\n// --- create ----------------------------------------------------------------\n\nfunction compileCreate(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const nested = planNestedWrites(\n schema,\n args?.data,\n op,\n (callArgs) => callArgs?.data,\n dialect,\n );\n\n const columns = insertColumns(\n schema,\n args?.data,\n nested.contributions,\n op,\n dialect,\n (callArgs) => callArgs?.data,\n );\n\n const returning = returningClause(schema, args, dialect, op, nested);\n\n const statement = concat(\n sql(`insert into ${dialect.quoteIdent(schema.table)}`),\n valuesClause([columns], dialect),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, nested);\n}\n\n// --- createMany ------------------------------------------------------------\n\nfunction compileCreateMany(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const rows = args?.data === undefined ? [] : listOf(args.data);\n\n // Before the empty-list shortcut below, so that an unsupported argument is\n // refused whether or not there was anything to write. Prisma rejects it on\n // SQLite for an empty list too, and validation that depends on how much data\n // happened to be supplied is the kind that passes in a test and fails in\n // production.\n const ignore = skipDuplicatesClause(schema, op, args, dialect);\n\n // Prisma returns `{ count: 0 }` for an empty list without touching the\n // database. See {@link zeroCountPlan} for how that is spelled as a plan.\n if (rows.length === 0) {\n return zeroCountPlan(schema, op, dialect);\n }\n\n const grid = createManyColumns(schema, rows, op, dialect);\n\n // `insert ... default values` inserts exactly one row and has no multi-row\n // spelling: `values (DEFAULT), (DEFAULT)` is rejected by SQLite, and the\n // zero-column list leaves nothing else to repeat. So a grid with no columns\n // and more than one row would quietly insert one — a wrong row count *and* a\n // wrong `{ count }`, from a statement that succeeds.\n //\n // Only reachable on a model where every field is autoincrement, database\n // default or nullable *and* no row supplies any of them, so the template's\n // schema cannot produce it. Refused by name anyway, because a silent wrong\n // count is the failure class this file is arranged to prevent.\n if (grid[0].length === 0 && rows.length > 1) {\n throw new UnsupportedQueryError(\n \"data\",\n schema.name,\n op,\n `All ${rows.length} rows are empty and ${schema.name} has no ` +\n `client-side default to fill, so there is no column to insert. A ` +\n `multi-row insert of nothing but database defaults cannot be ` +\n `expressed on both dialects. Call create ${rows.length} times, or ` +\n `set at least one field per row.`,\n );\n }\n\n const returning = returningClause(schema, undefined, dialect, op, undefined);\n\n const statement = concat(\n sql(`insert into ${dialect.quoteIdent(schema.table)}`),\n valuesClause(grid, dialect),\n ignore ?? sql(\"\"),\n returning.clause,\n );\n\n const { text, binders } = render(statement, dialect, { model: schema.name, operation: op });\n return {\n text,\n bind: bindValues(binders),\n // The rows a conflict skipped never reach `RETURNING`, so this is the\n // number *inserted* rather than the number supplied — which is what Prisma\n // returns, and what makes the count usable for \"how many were new\".\n shape: (returned) => ({ count: returned.length }),\n };\n}\n\n/**\n * `skipDuplicates`, or `null` when the caller did not ask for it.\n *\n * The whole point is that the check and the insert are one statement. Without\n * it a caller reads first to find out which rows exist, which is a second query\n * *and* a race: between the read and the insert a concurrent importer writes one\n * of them, and the insert fails on a unique violation anyway.\n *\n * Refused on a dialect that does not offer it, naming the dialect rather than\n * saying \"yet\" — the answer there is not \"wait\", it is \"Prisma does not offer\n * this on SQLite either, so neither do we\". See `SqlDialect.ignoreConflicts`\n * for why that is a parity decision rather than a gap.\n */\nfunction skipDuplicatesClause(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): Fragment | null {\n const requested = args?.skipDuplicates;\n if (requested === undefined) return null;\n\n if (typeof requested !== \"boolean\") {\n throw new InvalidArgumentError(\n \"skipDuplicates\",\n schema.name,\n op,\n `Expected true or false, got ${JSON.stringify(requested)}.`,\n );\n }\n\n const clause = dialect.ignoreConflicts();\n if (clause === null) {\n // Refused whatever the value, which is exactly what Prisma does: on SQLite\n // it reports `skipDuplicates` as an unknown argument for `false` as well as\n // for `true`. Accepting `false` because it happens to be a no-op would make\n // the two dialects disagree about which calls are legal.\n throw new UnsupportedQueryError(\n \"skipDuplicates\",\n schema.name,\n op,\n `'skipDuplicates' is not available on ${dialect.name}. Prisma does not ` +\n `offer it there either — it is a Postgres and MySQL argument. To ` +\n `import a batch that may overlap, write the rows one at a time and ` +\n `catch UniqueConstraintError, or move this model to Postgres.`,\n );\n }\n\n return requested ? clause : null;\n}\n\n/**\n * The column grid for a multi-row insert: one `WriteColumn[]` per row, every\n * row carrying the same fields in the same order.\n *\n * The order is the *schema's*, never the first row's key order. That is not a\n * tidiness point: with the column list taken from row one and the values taken\n * per row by key order, a second row whose keys were written in a different\n * order binds its values into the wrong columns. Same types, no error, wrong\n * data — the worst shape of bug this file could have. Every value is looked up\n * by field name, and there is a test for exactly this.\n */\nfunction createManyColumns(\n schema: ModelSchema,\n rows: unknown[],\n op: Operation,\n dialect: SqlDialect,\n): WriteColumn[][] {\n const supplied = rows.map((row, index) => {\n if (typeof row !== \"object\" || row === null || Array.isArray(row)) {\n throw new InvalidArgumentError(\n `data[${index}]`,\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n\n const keys = new Set<string>();\n for (const [key, value] of Object.entries(row as Record<string, unknown>)) {\n if (value === undefined) continue;\n if (key in schema.relations) {\n // Prisma's `createMany` takes unchecked input — scalars and foreign\n // keys only. A nested write there has no defined ordering across rows.\n throw new UnsupportedQueryError(\n `data.${key}`,\n schema.name,\n op,\n \"createMany cannot contain nested writes. Use create per row.\",\n );\n }\n if (!(key in schema.fields)) {\n throw new UnknownFieldError(key, schema.name, Object.keys(schema.fields));\n }\n keys.add(key);\n }\n return keys;\n });\n\n // The union, walked in schema order so the emitted column list depends only\n // on *which* fields appear, never on how any row was written.\n const union: FieldSchema[] = [];\n for (const field of Object.values(schema.fields)) {\n const inSome = supplied.some((keys) => keys.has(field.name));\n if (inSome || hasClientSideValue(field) || suppliesEmptyList(field)) {\n union.push(field);\n }\n }\n\n for (const field of union) {\n const missing = supplied.some((keys) => !keys.has(field.name));\n if (!missing) continue;\n\n if (hasClientSideValue(field)) continue;\n if (field.nullable) continue;\n // The empty list stands in for an absent one — see `insertColumns`. It also\n // resolves the \"some rows set it and others do not\" refusal below, which\n // exists because a single `VALUES` list cannot ask for a database default\n // per row. A list needs no default asked for: `{}` is a value, so the rows\n // that omitted it get one written rather than needing the statement split.\n //\n // `suppliesEmptyList` rather than `field.isList`, which is the whole of the\n // distinction: this stands in for a list that has **nothing else** to fall\n // back on. A list with a *database-side* default still cannot be expressed\n // per row, so it falls through to the refusal below rather than silently\n // acquiring `{}` — and one with a client-side default never reaches here,\n // because `hasClientSideValue` answered above.\n if (suppliesEmptyList(field)) continue;\n\n // A database-side default that only some rows override. `NULL` would\n // *overwrite* the default rather than request it, and SQLite has no\n // `DEFAULT` keyword inside a `VALUES` list to ask for it with.\n if (field.default) {\n throw new UnsupportedQueryError(\n `data.${field.name}`,\n schema.name,\n op,\n `Some rows set '${field.name}' and others leave it to the database ` +\n `default. A single multi-row insert cannot express both. Split the ` +\n `call, or set '${field.name}' on every row.`,\n );\n }\n\n const index = supplied.findIndex((keys) => !keys.has(field.name));\n throw new MissingRequiredValueError(\n schema.name,\n `${op}.data[${index}]`,\n field.name,\n );\n }\n\n for (const field of union) {\n if (field.isList) {\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n }\n }\n\n return rows.map((row, index) =>\n union.map((field) => {\n if (!supplied[index].has(field.name)) {\n // **`suppliesEmptyList`, not `field.isList`**, and the difference is a\n // row that comes out wrong rather than a statement that fails.\n //\n // `@default([])` and `@default([\"seed\"])` are *client-side* defaults —\n // `kind: \"value\"`, which `isClientSideDefault` admits — so `create`\n // binds the declared value through `defaultBinder`. Asking `isList`\n // here put `{}` ahead of that, so one `createMany` row omitting a\n // defaulted list wrote the empty array where `create` wrote the\n // default, and where Prisma writes the default — so `create` and\n // `createMany` disagreed about one schema, silently, in the row.\n //\n // Invisible to the differential until the fixture changed: the template\n // declared `@default([])`, where the correct value and the wrong one are\n // the same array. It now declares a non-empty default, and the\n // `createMany` case supplies it on one row and omits it on the other.\n return {\n field,\n value: suppliesEmptyList(field)\n ? emptyList(field, dialect)\n : defaultBinder(field, dialect),\n };\n }\n\n if (field.isList) {\n // Compile-time, like `insertColumns` and `assignment` — this was the\n // one write path that let a bad operand reach the binder. `[\"set\"]`\n // because an insert takes no `push`, and a refusal naming `push` on the\n // operation where it is never legal is a puzzle rather than a next step.\n assertListOperand(schema, field, (row as any)?.[field.name], op, [\"set\"]);\n }\n\n // Per row, because two rows of one `createMany` may legitimately spell\n // the same list differently — `[\"a\"]` and `{ set: [\"a\"] }`. The plan key\n // records the whole `data` array's shape, so the two are already\n // different entries and this stays a compile-time decision.\n const setForm = isListSetOperand(field, (row as any)?.[field.name]);\n\n return {\n field,\n value: valueBinder(schema, op, field, dialect, (callArgs) => {\n const value = listOf(callArgs?.data)[index]?.[field.name];\n return setForm ? value?.set : value;\n }),\n };\n }),\n );\n}\n\n// --- update / updateMany ---------------------------------------------------\n\nfunction compileUpdate(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const many = op === \"updateMany\";\n\n // `data: null` reaches here: `requiredArgs` asks only about `undefined`, and\n // `updateAssignments` admits a nullish `data` because `upsert`'s halves may\n // legitimately be absent. It used to land on \"At least one field must be\n // updated\", which was a poor message but a refusal. Now that an empty `data`\n // reads the row back, a null one would read it back too — a malformed call\n // answered with a row. Refused on the shape rather than on a Prisma code,\n // because Prisma's client rejects this at the type level and the query engine\n // never sees it, so there is no behaviour to match here, only one to not\n // invent.\n if (args?.data === null) {\n throw new InvalidArgumentError(\n \"data\",\n schema.name,\n op,\n \"Expected an object of the fields to set, like { name: 'new name' }. \" +\n \"An empty object is accepted and reads the row back unchanged; null \" +\n \"is not.\",\n );\n }\n\n if (!many) {\n matchUniqueKey(schema, args?.where, {\n model: schema.name,\n operation: op,\n argument: \"where\",\n });\n }\n\n // Prisma's `updateMany` takes unchecked input — scalars and foreign keys, no\n // relation keys — and rejects one with `Unknown argument 'organization'`.\n // Refused by name here for the same reason `createMany` refuses it: without\n // this the key is neither executed nor reported, since `planNestedWrites`\n // never runs and `suppliedFields` skips relation keys silently.\n //\n // This guard carries more weight than it used to. A `data` of only a relation\n // key leaves no assignment behind, so it used to land on \"At least one field\n // must be updated\" — the wrong problem, but still a refusal. Now that an\n // empty `data` is a legitimate `{ count: 0 }` (see below), the same call would\n // instead *succeed*, having written nothing and said nothing. Remove this and\n // the failure mode goes from a misleading error to no error at all.\n if (many) {\n assertNoNestedWrites(\n schema,\n args?.data,\n op,\n \"data\",\n \"updateMany cannot contain nested writes — it has no single row to \" +\n \"attach them to. Use update per row.\",\n );\n }\n\n const nested = many\n ? undefined\n : planNestedWrites(schema, args?.data, op, (callArgs) => callArgs?.data, dialect);\n\n const assignments = updateAssignments(\n schema,\n args?.data,\n nested?.contributions ?? [],\n op,\n dialect,\n );\n\n const where = compileWhere(\n schema,\n args?.where,\n { dialect, operation: op },\n (callArgs) => callArgs?.where,\n );\n\n // MEASURED (Prisma 6.19.2, SQLite): `updateMany({ where, data: {} })` is\n // accepted and answers `{ count: 0 }` — with three rows in the table and two\n // matching the filter, again with a filter matching none, and again with no\n // `where` at all. The count is a *constant*, not a row count: Prisma's own\n // answer does not depend on how many rows the filter selects, and no row is\n // touched. So there is nothing here to derive from the filter, and the\n // cheapest honest match is the `createMany([])` plan — same shape, same\n // reason, same `{ count: <rows returned> }` shaping, no special case in the\n // choke point.\n //\n // The `where` above is compiled and then discarded on this path, deliberately:\n // an unknown field in a filter must be refused whether or not there happened\n // to be anything to write, for the reason `createMany` gives for validating\n // `skipDuplicates` ahead of its own empty-list shortcut — validation that\n // depends on how much data was supplied is the kind that passes in a test and\n // fails in production.\n if (many && assignments.length === 0) {\n return zeroCountPlan(schema, op, dialect);\n }\n\n // An `update` whose `data` sets no column has no `UPDATE … SET` to emit, and\n // there are two ways to get there. `Post.update({ where, data: { tags: {\n // connect: … } } })` changes the join table and nothing on `Post` itself; and\n // `data: {}` changes nothing at all. Prisma accepts both.\n //\n // So the row is *selected* instead. The nested steps need the parent's key\n // and the caller's `select` / `include` still has to be honoured, and both\n // come from the same `returning` list — which a select produces just as well\n // as an `update … returning` does. Same plan shape, same steps, one statement\n // that happens to read rather than write.\n //\n // The empty `data` used to be refused here, on the reasoning that with\n // neither an assignment nor a nested write there is genuinely nothing to do.\n // That is true of the *write* and false of the *call*. MEASURED, same client:\n // `post.update({ where: { id: 1 }, data: {} })` returns `{ id: 1, title:\n // \"p1\" }` with the row unchanged; with `include: { tags: true }` it returns\n // the tags as well; with `select: { title: true }` it returns `{ title:\n // \"p1\" }` and no `id`. A caller who passed an `include` asked a question with\n // a defined answer, and this select is already exactly that answer — which is\n // why the fix is deleting a condition rather than adding a branch.\n //\n // A miss is still fatal and costs nothing here: `{ where: { id: 99 }, data:\n // {} }` raises P2025, and `update` is in `ORTHROW`, so `RecordNotFoundError`\n // comes out of the existing machinery.\n //\n // Reachable on every model, including one carrying `@updatedAt`. That took a\n // change in `updateAssignments`: the stamp used to be unconditional, so it\n // was itself the assignment that kept this count off zero and made the whole\n // branch dead on the models most likely to want it. Prisma does not stamp a\n // call that sets no column — measured, see that function's docblock — so the\n // two fixes are the same fix. `many` is excluded by the branch above, so this\n // is `update` alone.\n const readInstead = assignments.length === 0;\n\n const returning = returningClause(schema, args, dialect, op, nested);\n\n const statement = readInstead\n ? concat(\n sql(`select `),\n returning.selected,\n sql(` from ${dialect.quoteIdent(schema.table)}`),\n where ? concat(sql(\" where \"), where) : sql(\"\"),\n )\n : concat(\n sql(`update ${dialect.quoteIdent(schema.table)} set `),\n joinFragments(assignments, \", \"),\n where ? concat(sql(\" where \"), where) : sql(\"\"),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, nested);\n}\n\n// --- delete / deleteMany ---------------------------------------------------\n\n/**\n * ~~KNOWN DIVERGENCE~~ — **fixed**, in `Model.$exec`, once iteration 5 existed.\n *\n * `delete` with an `include` on a cascading relation used to come back with the\n * children empty: the relation reads ran *after* the delete statement, and where\n * the schema declares `onDelete: Cascade` the database had already removed them.\n *\n * This note said the fix was \"to read the relations before the delete inside one\n * transaction, which is iteration 5's to provide — and once it does, this is the\n * case to write the test for\". Both happened:\n * `templates/saas-starter/app/models/delete-include.test.ts`.\n *\n * Nothing changed *here*. A `delete` with no relation to read still compiles to\n * one statement and opens no transaction; the read-then-delete pair lives at the\n * choke point, where a transaction is available and where the decision to open\n * one belongs.\n */\nfunction compileDelete(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n if (op === \"delete\") {\n matchUniqueKey(schema, args?.where, {\n model: schema.name,\n operation: op,\n argument: \"where\",\n });\n }\n\n const where = compileWhere(\n schema,\n args?.where,\n { dialect, operation: op },\n (callArgs) => callArgs?.where,\n );\n\n const returning = returningClause(schema, args, dialect, op, undefined);\n\n const statement = concat(\n sql(`delete from ${dialect.quoteIdent(schema.table)}`),\n where ? concat(sql(\" where \"), where) : sql(\"\"),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, undefined);\n}\n\n// --- upsert ----------------------------------------------------------------\n\n/**\n * `insert ... on conflict (<key>) do update set ...`, which both dialects\n * support and which does in one statement what Prisma's `upsert` describes.\n *\n * The alternative — read, then branch to a create or an update — is two\n * statements with a race between them: two concurrent upserts of the same key\n * both see \"absent\" and both insert, and one gets a unique violation. Since\n * there is no transaction until iteration 5, the single-statement form is not\n * just faster here, it is the only correct one.\n *\n * The conflict target comes from the `where`'s unique key, so it is a schema\n * identifier like every other. Nested writes are refused inside an upsert:\n * they would have to run before an insert that may turn out to be an update,\n * and there is nothing sensible to do with the row they created if it does.\n */\nfunction compileUpsert(\n schema: ModelSchema,\n op: Operation,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const key = matchUniqueKey(schema, args?.where, {\n model: schema.name,\n operation: op,\n argument: \"where\",\n });\n\n // Since Prisma 5 a `WhereUniqueInput` may carry extra non-unique filters\n // beside the key, and they narrow the match further. `update` and `delete`\n // honour that for free: their whole `where` goes through `compileWhere`.\n //\n // An upsert cannot. Its `where` becomes an `on conflict (...)` target, which\n // is a *key*, not a predicate — there is nowhere to put `deletedAt: null`.\n // Compiling only the key part would mean `where: { publicId, deletedAt: null }`\n // updating a soft-deleted row that Prisma would have left alone (Prisma would\n // find no match, attempt the create, and hit a unique violation). Refused\n // rather than narrowed, for the same reason the create-omits-the-key shape a\n // few lines down is.\n // KNOWN DIFFERENCE, and deliberate: this also refuses a `where` naming *two\n // different unique keys* — `{ id: 1, publicId: \"p\" }` — which Prisma accepts.\n // `on conflict` takes one target, so honouring both is not expressible;\n // picking `id` and ignoring `publicId` is the same silent narrowing the rest\n // of this guard exists to remove. A migrating application does hit a compile\n // error on a call Prisma ran happily, which is why it is listed under known\n // differences in the plan rather than only here.\n //\n // Note which key gets *named* in that case is an artifact of declaration\n // order — `matchUniqueKey` returns the primary key first, then `uniques` in\n // schema order — not of anything the caller wrote. Fine for a message that\n // lists every other member by name and tells the caller to choose, and not\n // worth resolving, since there is no principled way to prefer one.\n const named = key.length > 1 ? key.join(\"_\") : key[0];\n const extra = Object.keys(args.where as Record<string, unknown>).filter(\n (name) => name !== named && args.where[name] !== undefined,\n );\n if (extra.length > 0) {\n throw new UnsupportedQueryError(\n \"where\",\n schema.name,\n op,\n `The where clause carries ${extra.join(\", \")} beside the unique key ` +\n `'${named}'. An upsert compiles its where into an 'on conflict' ` +\n `target, which can only be a key, so the extra ${\n extra.length === 1 ? \"filter would be\" : \"filters would be\"\n } silently dropped. Name exactly one unique key here — or, if you meant ` +\n `to filter further, use findFirst plus update / create.`,\n );\n }\n\n for (const branch of [\"create\", \"update\"] as const) {\n assertNoNestedWrites(\n schema,\n args?.[branch],\n op,\n branch,\n \"Nested writes inside an upsert are not implemented: they would have \" +\n \"to run before it is known whether the row is being inserted or \" +\n \"updated.\",\n );\n }\n\n // `on conflict` only fires if the row being inserted actually collides on the\n // target. `upsert({ where: { id: 1 }, create: { email } })` never can — the\n // `create` supplies no `id`, so the insert mints a fresh one and the update\n // branch is unreachable. Prisma means something different by that call: find\n // by `where`, then update or create. Expressing *that* takes a read and a\n // write with no transaction between them, which is iteration 5's to give.\n //\n // So the case is refused rather than silently turned into an insert. This is\n // narrow: the ordinary shape — `where: { email }, create: { email, ... }` —\n // supplies the key and works.\n const absent = upsertAbsentConflictKey(schema, args, key);\n if (absent.length > 0) {\n throw new UnsupportedQueryError(\n \"upsert\",\n schema.name,\n op,\n `The where clause selects on ${key.join(\", \")}, but 'create' does not ` +\n `set ${absent.join(\", \")}, so 'on conflict' cannot express it. ` +\n `Model.upsert runs this as a read and a write inside one transaction ` +\n `instead; reaching this means the statement was compiled directly.`,\n );\n }\n\n const columns = withConflictKeyCheck(\n insertColumns(\n schema,\n args?.create,\n [],\n op,\n dialect,\n (callArgs) => callArgs?.create,\n ),\n schema,\n key,\n op,\n dialect,\n );\n\n // Inside the conflict clause every column read on the right of an `=` has to\n // name its table, or Postgres cannot tell the existing row from `excluded`.\n const qualifier = `${dialect.quoteIdent(schema.table)}.`;\n\n const assignments = updateAssignments(\n schema,\n args?.update,\n [],\n op,\n dialect,\n (callArgs) => callArgs?.update,\n qualifier,\n );\n\n const target = joinFragments(\n key.map((name) => sql(dialect.quoteIdent(fieldOf(schema, name).column))),\n \", \",\n );\n\n // `update: {}` is legal in Prisma and means \"leave the existing row alone,\n // but return it\". `do nothing` would return no row at all, so the row is\n // assigned to itself: an unqualified column on the right of a `do update set`\n // reads the *existing* row on both dialects.\n const effective =\n assignments.length > 0\n ? assignments\n : [\n sql(\n `${dialect.quoteIdent(fieldOf(schema, key[0]).column)} = ` +\n `${qualifier}${dialect.quoteIdent(fieldOf(schema, key[0]).column)}`,\n ),\n ];\n\n const returning = returningClause(schema, args, dialect, op, undefined);\n\n const statement = concat(\n sql(`insert into ${dialect.quoteIdent(schema.table)}`),\n valuesClause([columns], dialect),\n sql(\" on conflict (\"),\n target,\n sql(\") do update set \"),\n joinFragments(effective, \", \"),\n returning.clause,\n );\n\n return plan(schema, statement, dialect, op, returning, undefined);\n}\n\n/**\n * Which of the conflict key's fields `create` leaves unset — empty when\n * `on conflict` can express the upsert.\n *\n * **Exported because two callers must agree about it**, and a second copy of the\n * rule would be a rule that can drift: `compileUpsert` throws when it is\n * non-empty, and `Model.$exec` diverts the same calls to a read-then-write\n * before ever compiling them. If the two disagreed, either a divertable call\n * would raise or a raising call would be diverted into SQL that cannot conflict.\n */\nexport function upsertAbsentConflictKey(\n schema: ModelSchema,\n args: any,\n key: string[],\n): string[] {\n const supplied = suppliedFields(schema, args?.create);\n return key.filter((name) => !supplied.has(name));\n}\n\n/**\n * The other half of making `on conflict` mean what Prisma's `upsert` means.\n *\n * Compilation can prove the conflict key is *present* in `create`, but not that\n * it holds the same value as `where` — values do not exist at compile time, and\n * putting them there would break the plan cache. So the check happens at bind\n * time, where values are exactly what is in scope.\n *\n * Without it, `upsert({ where: { email: \"a\" }, create: { email: \"b\" }, ... })`\n * inserts \"b\" and conflicts — or does not — on \"b\", while Prisma looks for \"a\".\n * That is a silent divergence on a write, which is the failure this whole file\n * is arranged to prevent. Loud is better.\n */\nfunction withConflictKeyCheck(\n columns: WriteColumn[],\n schema: ModelSchema,\n key: string[],\n op: Operation,\n dialect: SqlDialect,\n): WriteColumn[] {\n const keyed = new Set(key);\n\n return columns.map((column) => {\n if (!keyed.has(column.field.name)) return column;\n\n const locate = whereValue(key, column.field.name);\n\n return {\n field: column.field,\n value: (args, context) => {\n const inserted = column.value(args, context);\n const selected = dialect.encode(locate(args), column.field);\n\n if (!sameEncoded(inserted, selected)) {\n throw new UnsupportedQueryError(\n \"upsert\",\n schema.name,\n op,\n `'${column.field.name}' is ${describe(selected)} in ` +\n `the where clause but ${describe(inserted)} in ` +\n `'create'. An upsert looks the row up by the where clause and ` +\n `inserts what 'create' says, so the two must agree on the key.`,\n );\n }\n\n return inserted;\n },\n };\n });\n}\n\n/**\n * Do two *encoded* values stand for the same thing?\n *\n * Not `===`, because `encode` is a per-dialect pass-through for whatever the\n * driver binds natively, and what a driver binds natively is not always a\n * primitive. Postgres passes a `DateTime` through as the `Date` it was given,\n * and both dialects pass `Bytes` through as a `Uint8Array` — so the same\n * instant and the same bytes arrive here as two distinct objects, and identity\n * refuses a correct upsert with a message printing two equal-looking strings.\n *\n * That is exactly the SQLite/Postgres asymmetry this codebase keeps finding:\n * SQLite encodes `DateTime` to a number and never noticed.\n *\n * Everything else falls through to `!==`, which is right for the string,\n * number, boolean and bigint an encoder can produce. `NaN` is not reachable —\n * it cannot be a unique key value that also round-trips through a `where`.\n */\nfunction sameEncoded(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {\n const left = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);\n const right = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);\n if (left.length !== right.length) return false;\n for (let i = 0; i < left.length; i++) {\n if (left[i] !== right[i]) return false;\n }\n return true;\n }\n\n return false;\n}\n\n/**\n * A value for an error message, distinct whenever `sameEncoded` says the two\n * values differ.\n *\n * That equivalence is the whole requirement, and it is easy to half-meet: the\n * first version of this stringified a `Date`, which made a genuine mismatch\n * read as `is X ... but X` and look like a framework bug rather than a wrong\n * argument. Two more ways to land back there:\n *\n * - Two different `Uint8Array`s of the same length both describing as\n * `\"2 bytes\"`. Hence the hex, truncated so a large blob does not fill the\n * message.\n * - `1n` and `1`, which `sameEncoded` separates and `String()` collapses.\n * Reachable because Prisma coerces a number into a `BigInt` field. Hence the\n * `typeof` suffix on anything that is not a string.\n */\nfunction describe(value: unknown): string {\n if (value instanceof Date) return JSON.stringify(value.toISOString());\n\n if (ArrayBuffer.isView(value)) {\n const bytes = new Uint8Array(\n value.buffer,\n value.byteOffset,\n value.byteLength,\n );\n // `Array.from` rather than a spread + `.map`: a `Uint8Array`'s own `map`\n // returns another `Uint8Array`, so the strings would be coerced back to\n // bytes and every one of them would become 0.\n const shown = Array.from(bytes.slice(0, 8), (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\");\n const ellipsis = bytes.length > 8 ? \"…\" : \"\";\n return `${bytes.length} bytes (0x${shown}${ellipsis})`;\n }\n\n if (typeof value === \"string\") return JSON.stringify(value);\n if (value === null || value === undefined) return String(value);\n\n return `${JSON.stringify(String(value))} (${typeof value})`;\n}\n\n/**\n * Reads one key field out of a `where`, in either of the two forms Prisma\n * accepts: named directly, or inside the compound object a composite\n * `@@unique` is addressed through (`{ username_provider: { username, ... } }`).\n */\nfunction whereValue(key: string[], field: string): (args: any) => unknown {\n const compound = key.length > 1 ? key.join(\"_\") : undefined;\n return (args) => {\n const where = args?.where;\n if (where === undefined || where === null) return undefined;\n if (compound !== undefined && where[compound] !== undefined) {\n return where[compound][field];\n }\n return where[field];\n };\n}\n\n// --- shared pieces ---------------------------------------------------------\n\ninterface WriteColumn {\n field: FieldSchema;\n value: Binder;\n}\n\n/**\n * `(cols) values (?, ?), (?, ?)`, or `default values` when the row supplies no\n * column at all — legal on both dialects, and the only way to insert a row made\n * entirely of database defaults.\n */\nfunction valuesClause(grid: WriteColumn[][], dialect: SqlDialect): Fragment {\n const columns = grid[0];\n if (columns.length === 0) return sql(\" default values\");\n\n const names = joinFragments(\n columns.map((column) => sql(dialect.quoteIdent(column.field.column))),\n \", \",\n );\n\n const tuples = grid.map((row) =>\n concat(\n sql(\"(\"),\n joinFragments(\n row.map((column) => fieldParam(column.field, dialect, column.value)),\n \", \",\n ),\n sql(\")\"),\n ),\n );\n\n return concat(\n sql(\" (\"),\n names,\n sql(\") values \"),\n joinFragments(tuples, \", \"),\n );\n}\n\n/**\n * Which columns an insert writes, and where each value comes from.\n *\n * The four sources, in the order they are consulted: a nested write that\n * resolved a foreign key, the caller's own `data`, a client-side default, and\n * the database. A required field that reaches the end of that list is an error\n * raised here, naming the field — rather than a `NOT NULL constraint failed`\n * from the driver naming a column and nothing else.\n */\nfunction insertColumns(\n schema: ModelSchema,\n data: unknown,\n contributions: readonly ForeignKeyContribution[],\n op: Operation,\n dialect: SqlDialect,\n locateData: (args: any) => any,\n): WriteColumn[] {\n if (data !== undefined && data !== null) {\n if (typeof data !== \"object\" || Array.isArray(data)) {\n throw new InvalidArgumentError(\n \"data\",\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n }\n\n const supplied = suppliedFields(schema, data);\n const contributed = new Map(\n contributions.map((contribution) => [contribution.field, contribution]),\n );\n\n for (const name of contributed.keys()) {\n if (supplied.has(name)) {\n throw new UnsupportedQueryError(\n `data.${name}`,\n schema.name,\n op,\n `'${name}' is set both directly and through a nested relation write. ` +\n `Prisma keeps those two forms exclusive; use one of them.`,\n );\n }\n }\n\n const columns: WriteColumn[] = [];\n\n for (const field of Object.values(schema.fields)) {\n const contribution = contributed.get(field.name);\n if (contribution) {\n columns.push({\n field,\n value: (args, context) =>\n dialect.encode(contribution.value(args, context), field),\n });\n continue;\n }\n\n if (supplied.has(field.name)) {\n if (field.isList) {\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n assertListOperand(schema, field, (data as any)?.[field.name], op, [\"set\"]);\n }\n\n // `{ tags: { set: [...] } }` is what Prisma documents for a list, and it\n // is accepted in `create` as well as in `update` — where a bare array is\n // also accepted, and means the same thing. Unwrapped at *compile* time\n // rather than in the binder because the two spellings are two argument\n // shapes and so already two plan-cache entries; deciding it here keeps\n // the binder a pure function of the value it is handed.\n const setForm = isListSetOperand(field, (data as any)?.[field.name]);\n\n columns.push({\n field,\n value: valueBinder(schema, op, field, dialect, (args) => {\n const value = locateData(args)?.[field.name];\n return setForm ? value?.set : value;\n }),\n });\n continue;\n }\n\n if (hasClientSideValue(field)) {\n columns.push({ field, value: defaultBinder(field, dialect) });\n continue;\n }\n\n // Left out of the statement entirely: the database supplies it, either from\n // its own default or as NULL.\n if (field.default || field.nullable) continue;\n\n // **A scalar list is never missing**, whatever the schema says about\n // required-ness. Measured against a generated 6.19 client: `create({ data:\n // { id: 900 } })` on a model whose every list is `NOT NULL` with no\n // `@default` succeeds, and every one of them reads back as `[]`. So Prisma\n // treats \"no value\" as the empty list rather than as an omission, and a\n // column with no database default gives it no choice — leaving the column\n // out would violate the NOT NULL constraint.\n //\n // This was a `MissingRequiredValueError` until the differential harness ran:\n // four `create` cases refused a call Prisma answers. It is exactly the kind\n // of divergence no amount of reading the docs produces, because the docs\n // describe the *input type* — where the field is optional — and say nothing\n // about what is written when it is absent.\n if (field.isList) {\n // Asked *here* as well as on the supplied path above, because this branch\n // invents a value the caller never wrote — and an unasked dialect is how\n // `create({ data: { id: 1 } })` on SQLite compiled a statement binding\n // raw JS arrays for the driver to reject with a type error, where naming\n // the column would have said \"sqlite has no array type … It works on\n // postgres\". The check belongs to the *column*, not to the caller\n // mentioning it.\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n columns.push({ field, value: emptyList(field, dialect) });\n continue;\n }\n\n throw new MissingRequiredValueError(schema.name, op, field.name);\n }\n\n return columns;\n}\n\n/**\n * Refuses an operator map a scalar list does not take — `{ increment: 1 }` —\n * at **compile** time.\n *\n * The value-shaped refusal in `valueBinder` would eventually catch it, and too\n * late: `isOperatorObject` answers false for an operator a list does not have,\n * so `{ counts: { increment: 1 } }` was read as a *value* and travelled all the\n * way to the binder before anything objected. Compile is a pure function of the\n * argument shape and this is a shape question, so it belongs here — the same\n * call `assertCompositeInOperand` records making for the same reason.\n *\n * Note this is unambiguous even for a `Json[]`, where an object is a plausible\n * element: the column's value is an *array*, so a bare object in this position\n * is never data. `isOperatorObject` relies on the same fact.\n */\nfunction assertListOperand(\n schema: ModelSchema,\n field: FieldSchema,\n value: unknown,\n op: Operation,\n /**\n * The operators legal in *this* position. An insert takes `set` only —\n * Prisma's create input for a list is `T[] | { set: T[] }`, with no `push`,\n * and there is nothing for a `push` to append to on a row that does not exist\n * yet.\n */\n allowed: readonly string[],\n): void {\n if (!field.isList) return;\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Date ||\n ArrayBuffer.isView(value)\n ) {\n return;\n }\n\n const given = Object.keys(value as Record<string, unknown>).filter(\n (key) => (value as Record<string, unknown>)[key] !== undefined,\n );\n if (given.length === 1 && allowed.includes(given[0])) return;\n\n throw new UnsupportedQueryError(\n `data.${field.name}`,\n schema.name,\n op,\n `'${field.name}' is a scalar list, so it takes ${allowed.join(\" or \")} — ` +\n `or a bare array. Received ${\n given.length === 0 ? \"an empty object\" : `{ ${given.join(\", \")} }`\n }. The arithmetic operators apply to a number, not to a list of them.`,\n );\n}\n\n/**\n * `{ set: [...] }` on a scalar list, which is the spelling Prisma documents and\n * which an insert accepts as readily as an update.\n *\n * Unambiguous in a way the scalar `Json` case is not — see `isOperatorObject` —\n * because a list column's data form is always an array, so an object here can\n * only be the operator.\n */\nfunction isListSetOperand(field: FieldSchema, value: unknown): boolean {\n return (\n field.isList === true &&\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n !(value instanceof Date) &&\n !ArrayBuffer.isView(value) &&\n Object.keys(value).length === 1 &&\n \"set\" in value\n );\n}\n\n/** The scalar fields a `data` object actually sets, validated against the schema. */\nfunction suppliedFields(\n schema: ModelSchema,\n data: unknown,\n): Set<string> {\n const out = new Set<string>();\n if (typeof data !== \"object\" || data === null) return out;\n\n for (const [key, value] of Object.entries(data as Record<string, unknown>)) {\n // Prisma treats an explicit `undefined` as absent, which is how conditional\n // writes are expressed in application code.\n if (value === undefined) continue;\n // Relations are the nested-write planner's business.\n if (key in schema.relations) continue;\n if (!(key in schema.fields)) {\n throw new UnknownFieldError(key, schema.name, Object.keys(schema.fields));\n }\n out.add(key);\n }\n\n return out;\n}\n\n/**\n * Refuse a `data` object that names a relation, for the operations that have no\n * nested-write planner behind them.\n *\n * `suppliedFields` skips relation keys rather than rejecting them, because on\n * `create` and `update` they are the nested planner's business. Everywhere else\n * that same skip is a silent drop, so those callers say so here — by name, and\n * before anything is compiled.\n */\nfunction assertNoNestedWrites(\n schema: ModelSchema,\n data: unknown,\n op: Operation,\n path: string,\n reason: string,\n): void {\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) return;\n\n for (const [name, value] of Object.entries(data as Record<string, unknown>)) {\n if (value === undefined) continue;\n if (name in schema.relations) {\n throw new UnsupportedQueryError(`${path}.${name}`, schema.name, op, reason);\n }\n }\n}\n\n/**\n * `set` assignments for an update, in schema order.\n *\n * `@updatedAt` is appended unless the caller set it explicitly. Applying it on\n * *create* as well is handled by `hasClientSideValue`; missing that half is the\n * easy and quiet version of this bug, since the column is usually NOT NULL and\n * only fails on the models where Prisma made it nullable.\n *\n * **The stamp needs a column beside it**, which is not what \"every write stamps\n * `@updatedAt`\" would suggest and is the rule Prisma actually follows. Measured\n * against 6.19.2/SQLite, seeding `updatedAt` to the epoch and reading it back:\n *\n * data: {} epoch not stamped\n * data: { profile: { create: … } } epoch not stamped\n * data: { profile: { update: … } } epoch not stamped\n * data: { name: \"real\" } now stamped\n * data: { organization: { connect: … } } now stamped\n * data: { organizationId: null } now stamped\n *\n * The first three write no column of *this* row — a to-one whose key is on the\n * child changes the child — and Prisma leaves the stamp alone for all three. So\n * the condition is \"this statement sets at least one other column\", which is\n * what `writesAColumn` asks, rather than \"this call happened\".\n *\n * Stamping unconditionally was load-bearing in the wrong direction twice. It\n * made #355's empty-`data` read unreachable on any model carrying the attribute\n * — the majority case, and the one the issue was filed from — because the stamp\n * *was* the assignment that kept `assignments.length` off zero. And it put a\n * timestamp Prisma does not write on every nested to-one write #354 added,\n * where the differential harness could not see it: `updatedAt` is volatile, so\n * both sides compare as the descriptor `\"date\"` and two different instants\n * match. It took a by-value assertion to catch.\n *\n * **KNOWN DIVERGENCE — an owning-side `disconnect` stamps here and does not in\n * Prisma.** Measured beside the rest: `data: { organization: { disconnect: true\n * } }` writes `organizationId = NULL` (verified, the column really is cleared)\n * and leaves `updatedAt` at the epoch, while `connect` one line above stamps\n * it. Both write the same column through the same operand family, so this is\n * Prisma disagreeing with itself rather than a rule to follow. gemi contributes\n * the null as an ordinary assignment and therefore stamps, which is the answer\n * `connect`, a hand-written `organizationId: null`, and every other column\n * write already give. Pre-existing, unchanged here, and matching it would mean\n * special-casing one operand to reproduce an inconsistency.\n *\n * **...and the *filter* arm (#359) carries it one step further: it stamps even\n * when it detaches nothing.** `nested-writes.ts`'s owning-side `disconnect`\n * defaults `context.resolved[fkField]` to the value already in the column and\n * pushes the contribution unconditionally — it has to, because the statement's\n * text cannot depend on a value read at bind time — so the assignment is in the\n * SET list whether or not the linked row matched. Measured on both sides\n * against a schema built for it, since the template's `Profile` has no\n * `@updatedAt` (Prisma 6.19.2, SQLite, a one-to-one whose *owner* carries the\n * attribute, `updatedAt` seeded to the epoch):\n *\n * disconnect: true update … set \"userId\" = ?\n * -> key nulled, updatedAt at the epoch\n * disconnect: { name: \"Ada\" } update … set \"userId\" = ? where … and\n * exists(select … where \"name\" = ? …)\n * -> key nulled, updatedAt at the epoch\n * disconnect: { name: \"Nobody\" } the same statement, matching zero rows\n * -> nothing written at all\n * disconnect: false no update statement at all\n * -> nothing written at all\n *\n * So Prisma never stamps through this operand, matching filter or not — that is\n * the paragraph above — and on a miss it writes *no row*, because the filter\n * rides inside the `UPDATE`'s own `where` as an `exists` subquery. gemi's plan\n * text is fixed at compile time and reads\n * `update \"User\" set \"organizationId\" = ?, \"updatedAt\" = ? where \"id\" = ?` for\n * every arm that writes, so `User.update({ where: { id: 1 }, data: {\n * organization: { disconnect: { name: \"Nobody\" } } } })` leaves\n * `organizationId` at 1 and moves `updatedAt` from the epoch to now: a call\n * that changed no column of the row still stamps it.\n *\n * **There is no test for `disconnect`'s stamp and there cannot be one in this\n * fixture**, which is why this docblock is the deliverable rather than a\n * pointer to one. The template's only one-to-one owner is `Profile`, which has\n * no `@updatedAt` column, and the differential harness lists `updatedAt` in its\n * volatile set (`differential.ts`), so both sides compare as the descriptor\n * `\"date\"` and two different instants match. The measurements above were taken\n * against a purpose-built schema, not against the template's. `User` carries\n * the attribute and is a *many*-to-one owner, which is the shape Prisma answers\n * by ignoring the operand outright — so there the divergence to compare against\n * is a different one.\n *\n * **The owning-side `upsert` (#391) is the third operand here and the one that\n * *is* pinned**, for exactly the reason the paragraph above cannot be. Its\n * update branch resolves the key to the value already in the column and writes\n * it back, on the identical mechanism — the create branch needs the column and\n * the branch is a run-time answer, so the assignment is unconditional. Prisma\n * honours this operand on a many-to-one, unlike `disconnect`, so `User` can ask\n * the question: `User.update({ where: { id: 1 }, data: { organization: {\n * upsert: { create, update } } } })` issues no `UPDATE` on `User` at all there\n * and leaves `updatedAt` at the epoch, where gemi writes `organizationId` back\n * and stamps. Asserted by value in `writes.differential.test.ts`'s \"where the\n * two clients still disagree\" — the harness's own comparison cannot see it, for\n * the volatility reason above.\n *\n * **The two statements are also a lost-update window**, which `disconnect: true`\n * does not have and Prisma does not have on either arm. The filter arm reads the\n * current key with a `findFirst` and writes it back in a *second* statement, so\n * under READ COMMITTED a concurrent transaction that `connect`s a different\n * partner in between has its value silently reverted — by the call that decided\n * to do nothing. Prisma's single guarded `UPDATE` above cannot lose it: there is\n * no read to be stale, and on a miss there is no write at all.\n */\nfunction updateAssignments(\n schema: ModelSchema,\n data: unknown,\n contributions: readonly ForeignKeyContribution[],\n op: Operation,\n dialect: SqlDialect,\n locateData: (args: any) => any = (args) => args?.data,\n /**\n * Prefix for a column read on the *right* of an assignment — `\"User\".`\n * inside an `on conflict do update`, empty in a plain `update`.\n *\n * Postgres puts both the target row and the proposed `excluded` row in scope\n * inside a conflict clause, so a bare `\"n\" = \"n\" + $1` there is rejected:\n * `column reference \"n\" is ambiguous`. SQLite accepts either form, and so\n * does Postgres in a plain `update` — verified against both — which is why\n * the qualifier is applied where it is needed rather than everywhere.\n */\n qualifier = \"\",\n): Fragment[] {\n if (data !== undefined && data !== null) {\n if (typeof data !== \"object\" || Array.isArray(data)) {\n throw new InvalidArgumentError(\n \"data\",\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n }\n\n const supplied = suppliedFields(schema, data);\n const contributed = new Map(\n contributions.map((contribution) => [contribution.field, contribution]),\n );\n\n // Asked before the loop rather than from `out.length`, so the answer does not\n // depend on where `@updatedAt` happens to sit in schema order: a model that\n // declares it first would otherwise see an empty `out` and skip a stamp it\n // owes. Both sets hold scalar field names only — `suppliedFields` skips\n // relation keys, which is exactly the distinction being drawn here.\n const writesAColumn = contributed.size > 0 || supplied.size > 0;\n\n const out: Fragment[] = [];\n\n for (const field of Object.values(schema.fields)) {\n const column = dialect.quoteIdent(field.column);\n const contribution = contributed.get(field.name);\n\n if (contribution) {\n out.push(\n concat(\n sql(`${column} = `),\n param((args, context) =>\n dialect.encode(contribution.value(args, context), field),\n ),\n ),\n );\n continue;\n }\n\n if (supplied.has(field.name)) {\n out.push(\n assignment(\n schema,\n field,\n column,\n `${qualifier}${column}`,\n data,\n op,\n dialect,\n (args) => locateData(args)?.[field.name],\n ),\n );\n continue;\n }\n\n // A write that sets a column stamps `@updatedAt`; one that sets none does\n // not, because there is no write to date. See the docblock's table.\n if (field.isUpdatedAt && writesAColumn) {\n out.push(\n concat(\n sql(`${column} = `),\n fieldParam(field, dialect, defaultBinder(field, dialect)),\n ),\n );\n }\n }\n\n return out;\n}\n\n/**\n * Prisma's update operators. `set` is the explicit spelling of a plain\n * assignment; the arithmetic four read the column and write it back, so they\n * are the one place a column name appears on the right of an `=`.\n *\n * `push` is the sixth and belongs to scalar lists only, so it lives beside them\n * rather than here — see {@link listOperators}. Keeping it out of this table is\n * what makes `{ tags: { increment: 1 } }` and `{ count: { push: 1 } }` both\n * errors that name the field's kind, rather than one of them compiling.\n */\nconst ARITHMETIC: Record<string, string> = {\n increment: \"+\",\n decrement: \"-\",\n multiply: \"*\",\n divide: \"/\",\n};\n\n/** The update operators a scalar list takes: `set` and `push`, and nothing else. */\nconst LIST_OPERATORS = [\"set\", \"push\"] as const;\n\nfunction listOperators(field: FieldSchema): readonly string[] {\n return field.isList ? LIST_OPERATORS : [\"set\", ...Object.keys(ARITHMETIC)];\n}\n\nfunction assignment(\n schema: ModelSchema,\n field: FieldSchema,\n /** The column as the assignment's target, always unqualified. */\n column: string,\n /** The same column read as a value — qualified inside a conflict clause. */\n source: string,\n data: unknown,\n op: Operation,\n dialect: SqlDialect,\n locate: (args: any) => any,\n): Fragment {\n const value = (data as Record<string, unknown>)[field.name];\n\n if (field.isList) {\n assertListDialect(schema, field, `data.${field.name}`, op, dialect);\n assertListOperand(schema, field, value, op, LIST_OPERATORS);\n }\n\n if (isOperatorObject(value, field)) {\n const keys = Object.keys(value as Record<string, unknown>).filter(\n (key) => (value as Record<string, unknown>)[key] !== undefined,\n );\n\n if (keys.length !== 1) {\n throw new UnsupportedQueryError(\n `data.${field.name}`,\n schema.name,\n op,\n `Expected exactly one of ${listOperators(field).join(\", \")}.`,\n );\n }\n\n const [key] = keys;\n const at = (args: any) => locate(args)?.[key];\n\n if (key === \"set\") {\n return concat(\n sql(`${column} = `),\n fieldParam(field, dialect, valueBinder(schema, op, field, dialect, at)),\n );\n }\n\n if (key === \"push\") {\n // `array_cat(<column>, $1)` — the column on the right of an `=`, like the\n // arithmetic four below, and for the same reason: the new value is a\n // function of the old one.\n //\n // The operand is normalised to a list **at bind time**, because Prisma\n // accepts both `push: \"a\"` and `push: [\"a\", \"b\"]` and the two are the\n // same statement. That normalisation is also what lets the dialect use a\n // single-signature function: `||` would read the two spellings as\n // different operators — see `PostgresDialect.listPush`.\n return concat(\n sql(`${column} = `),\n dialect.listPush(\n source,\n fieldParam(\n field,\n dialect,\n valueBinder(schema, op, field, dialect, (args) => {\n const supplied = at(args);\n return Array.isArray(supplied) ? supplied : [supplied];\n }),\n ),\n ),\n );\n }\n\n return concat(\n sql(`${column} = ${source} ${ARITHMETIC[key]} `),\n fieldParam(field, dialect, valueBinder(schema, op, field, dialect, at)),\n );\n }\n\n return concat(\n sql(`${column} = `),\n fieldParam(field, dialect, valueBinder(schema, op, field, dialect, locate)),\n );\n}\n\n/**\n * True for `{ increment: 1 }`, false for a plain value.\n *\n * A `Json` column is excluded because `{ set: ... }` is a legal *value* there as\n * well as an operator, and there is no way to tell them apart structurally.\n * Prisma resolves the ambiguity through its types; we resolve it by treating a\n * Json column's object as data, which is the reading that never loses the\n * caller's value.\n *\n * **A `Json[]` is not excluded**, and the exclusion above is why: the ambiguity\n * it exists for cannot arise on a list. A `Json` column can legitimately hold\n * the object `{ set: 1 }`; a `Json[]` column holds an *array*, so an object\n * operand is never data there and reading it as an operator loses nothing.\n * Without this the one spelling Prisma documents for writing a list —\n * `{ tags: { set: [...] } }` — would have been stored as a single JSON object\n * on exactly the element type where that is a plausible-looking value.\n */\nfunction isOperatorObject(value: unknown, field: FieldSchema): boolean {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Date ||\n ArrayBuffer.isView(value) ||\n (field.type === \"Json\" && !field.isList)\n ) {\n return false;\n }\n\n const operators = listOperators(field);\n const keys = Object.keys(value as Record<string, unknown>);\n if (keys.length === 0) return false;\n return keys.every((key) => operators.includes(key));\n}\n\n/**\n * Every write value passes through here — `create`, `createMany`, `update`'s\n * `set` and its bare form, and `upsert` — which is what makes it the one place\n * a value-dependent refusal has to live.\n *\n * It throws at **bind** time rather than compile time, and that is forced\n * rather than chosen: compile is a pure function of the argument *shape* and\n * never sees a value (invariant 2), so a value nobody may write cannot be\n * detected there. The schema and operation are closed over instead, so the\n * error still says which field of which model on which operation — the context\n * `fieldParam` does not have, and the reason the refusal is not down there.\n */\nfunction valueBinder(\n schema: ModelSchema,\n op: Operation,\n field: FieldSchema,\n dialect: SqlDialect,\n locate: (args: any) => any,\n): Binder {\n return (args) => {\n const value = locate(args);\n\n // `AnyNull` means \"either kind of null\", which is a question about existing\n // rows and not something a column can hold. Prisma raises here too. Left\n // alone it has no enumerable properties, so it serialised to the jsonb\n // object `{}` — a plausible-looking value, silently wrong, with nothing\n // raised: #259, and the same silent mis-store #222 closed for the other two\n // sentinels.\n if (jsonNullKind(value) === \"any\") {\n throw new InvalidArgumentError(\n `data.${field.name}`,\n schema.name,\n op,\n `Prisma.AnyNull is a filter operand, not a value — Prisma rejects it ` +\n `in a write here too. Write Prisma.DbNull for a SQL NULL column, or ` +\n `Prisma.JsonNull for the JSON value null.`,\n );\n }\n\n // A list operand is checked here rather than left to `encode`, for the\n // reason this whole function exists: the dialect has the value and nothing\n // else, so its refusal can only report an ORM bug. The schema and operation\n // are closed over here, so this one says which field of which model.\n if (field.isList && value !== null && value !== undefined) {\n if (!Array.isArray(value)) {\n throw new InvalidArgumentError(\n `data.${field.name}`,\n schema.name,\n op,\n `'${field.name}' is a scalar list, so it takes an array — or ` +\n `{ set: [...] } / { push: … }. Received ${typeof value}.`,\n );\n }\n if (value.some((element) => jsonNullKind(element) === \"any\")) {\n throw new InvalidArgumentError(\n `data.${field.name}`,\n schema.name,\n op,\n `Prisma.AnyNull is a filter operand, not a value, and that does not ` +\n `change for being inside a list.`,\n );\n }\n }\n\n return dialect.encode(value, field);\n };\n}\n\n/**\n * `{}` for a scalar list nobody supplied — what Prisma writes, measured rather\n * than assumed. See the note in `insertColumns`.\n */\nfunction emptyList(field: FieldSchema, dialect: SqlDialect): Binder {\n return () => dialect.encode([], field);\n}\n\n/**\n * Whether an absent value for this field means \"write the empty list\" — a\n * scalar list with no database default of its own to fall back to.\n *\n * A list *with* a default stays out of the statement so the default fires,\n * which is the same rule every other field follows and produces the same rows.\n */\nfunction suppliesEmptyList(field: FieldSchema): boolean {\n return field.isList === true && !field.default && !field.nullable;\n}\n\nfunction defaultBinder(field: FieldSchema, dialect: SqlDialect): Binder {\n // Read per call, never at compile time: a cuid must differ per row and `now`\n // must be the instant of *this* operation, not of the compilation that may\n // have happened thousands of calls ago.\n return (_args, context) =>\n dialect.encode(clientSideValue(field, context.now), field);\n}\n\ninterface Returning {\n clause: Fragment;\n /** The same columns without the `returning` keyword, for a select. */\n selected: Fragment;\n fields: FieldSchema[];\n hidden?: string[];\n relations: ReturnType<typeof planRelations>[\"plans\"];\n counts: CountPlan[];\n}\n\n/**\n * The `RETURNING` list.\n *\n * For a row-returning write it is the caller's `select` — the same resolution a\n * read does — plus any key columns the relation planner or a nested `after`\n * step needs and the caller did not ask for. Those extra columns are stripped\n * from the result once they have been used, exactly as on the read path.\n *\n * For a counting write it is one column, because the count is the number of\n * rows that come back.\n */\nfunction returningClause(\n schema: ModelSchema,\n args: any,\n dialect: SqlDialect,\n op: Operation,\n nested: NestedWritePlanning | undefined,\n): Returning {\n if (COUNTING.has(op)) {\n return {\n clause: sql(` returning ${keyColumn(schema, dialect)}`),\n selected: sql(keyColumn(schema, dialect)),\n fields: [],\n relations: [],\n counts: [],\n };\n }\n\n const selection = resolveSelection(schema, args, op);\n const { plans, keyFields } = planRelations(schema, args, dialect, op);\n const { fields, hidden } = withKeyFields(schema, selection, [\n ...keyFields,\n ...(nested?.keyFields ?? []),\n ]);\n const counts = planRelationCounts(schema, args, dialect, op);\n\n const columns = joinFragments(\n [\n ...fields.map((field) => sql(dialect.quoteIdent(field.column))),\n // Last, for the same reason they go last on a read: the shaper reads\n // scalars by position and `_count` is attached afterwards from the raw\n // row. The reading `update` below projects the same list, so a `_count`\n // survives that path too.\n ...counts.map((count) => count.column),\n ],\n \", \",\n );\n\n return {\n clause: concat(sql(\" returning \"), columns),\n // The same list without the keyword, for the one statement that reads the\n // row rather than writing it — an `update` with no column to set, whether\n // because its `data` held only nested writes or because it was empty. See\n // `compileUpdate`.\n selected: columns,\n fields,\n hidden,\n relations: plans,\n counts,\n };\n}\n\n/**\n * The plan for a counting write that Prisma answers `{ count: 0 }` to without\n * touching the database: `createMany` with an empty list, and `updateMany` with\n * an empty `data`.\n *\n * A plan must have a statement, so there is one. A constant-false select is the\n * cheapest thing that yields zero rows on both dialects, and it keeps these\n * cases on exactly the same code path as every other write — no branch in the\n * choke point, no plan that is a plan in name only, and the count still comes\n * from the number of rows returned rather than from a hard-coded zero, so the\n * shaper is the shaper every other counting write uses.\n *\n * It costs one round trip that Prisma does not make. That is the price of the\n * uniformity above, and it is paid only by calls that asked for nothing.\n */\nfunction zeroCountPlan(\n schema: ModelSchema,\n op: Operation,\n dialect: SqlDialect,\n): QueryPlan {\n const key = keyColumn(schema, dialect);\n const { text, binders } = render(\n sql(`select ${key} from ${dialect.quoteIdent(schema.table)} where false`),\n dialect,\n { model: schema.name, operation: op },\n );\n return {\n text,\n bind: bindValues(binders),\n shape: (returned) => ({ count: returned.length }),\n };\n}\n\n/** The narrowest column that still identifies a row, for counting writes. */\nfunction keyColumn(schema: ModelSchema, dialect: SqlDialect): string {\n const name = schema.primaryKey[0] ?? Object.keys(schema.fields)[0];\n return dialect.quoteIdent(schema.fields[name].column);\n}\n\nfunction fieldOf(schema: ModelSchema, name: string): FieldSchema {\n const field = schema.fields[name];\n if (!field) {\n throw new UnknownFieldError(name, schema.name, Object.keys(schema.fields));\n }\n return field;\n}\n\nfunction plan(\n schema: ModelSchema,\n statement: Fragment,\n dialect: SqlDialect,\n op: Operation,\n returning: Returning,\n nested: NestedWritePlanning | undefined,\n): QueryPlan {\n const { text, binders } = render(statement, dialect, { model: schema.name, operation: op });\n\n const shaper = buildRowShaper(\n returning.fields,\n dialect,\n returning.relations.map((relation) => ({\n key: relation.as,\n kind: relation.kind,\n })),\n );\n\n const single = SINGLE_ROW.has(op);\n const counting = COUNTING.has(op);\n\n return {\n text,\n bind: bindValues(binders),\n relations: returning.relations.length > 0 ? returning.relations : undefined,\n strategies:\n returning.relations.length > 0\n ? strategiesOf(returning.relations)\n : undefined,\n hidden: returning.hidden,\n before: nested && nested.before.length > 0 ? nested.before : undefined,\n after: nested && nested.after.length > 0 ? nested.after : undefined,\n counts: returning.counts.length > 0 ? true : undefined,\n shape(rows) {\n // The count *is* the number of returned rows — see the note at the top of\n // this file on why it does not come from driver metadata.\n if (counting) return { count: rows.length };\n\n const shaped = shaper(rows);\n\n // `_count` came back as extra columns the shaper knows nothing about,\n // under aliases carrying a dot. Assembled into one object per row,\n // because that is the shape Prisma returns — and the same assembly\n // `compileRead` does, deliberately spelled the same way.\n if (returning.counts.length > 0) {\n for (let i = 0; i < shaped.length; i++) {\n const raw = (rows[i] as Record<string, unknown>) ?? {};\n const totals: Record<string, number> = {};\n for (const count of returning.counts) {\n totals[count.as] = Number(raw[count.alias] ?? 0);\n }\n shaped[i]._count = totals;\n }\n }\n // `null` when nothing matched. `$exec` turns that into\n // `RecordNotFoundError` for the operations Prisma raises on, where the\n // model's name is in scope for the message.\n return single ? (shaped[0] ?? null) : shaped;\n },\n };\n}\n\nfunction listOf(value: unknown): any[] {\n if (value === undefined || value === null) return [];\n return Array.isArray(value) ? value : [value];\n}\n\nfunction assertArgs(schema: ModelSchema, op: Operation, args: any): void {\n if (args === undefined || args === null) {\n throw new UnsupportedQueryError(\n \"args\",\n schema.name,\n op,\n `${op} requires arguments.`,\n );\n }\n\n if (typeof args !== \"object\" || Array.isArray(args)) {\n throw new InvalidArgumentError(\n String(args),\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n\n if (args.select !== undefined && args.include !== undefined) {\n throw new UnsupportedQueryError(\n \"select + include\",\n schema.name,\n op,\n \"Prisma allows only one of them on the same query.\",\n );\n }\n\n const allowed = WRITE_ARGS[op];\n for (const key of Object.keys(args).sort()) {\n if (args[key] === undefined) continue;\n if (!allowed.has(key)) {\n throw new UnsupportedQueryError(\n key,\n schema.name,\n op,\n `${op} takes ${[...allowed].sort().join(\", \")}.`,\n );\n }\n }\n\n for (const required of requiredArgs(op)) {\n if (args[required] === undefined) {\n throw new UnsupportedQueryError(\n required,\n schema.name,\n op,\n `${op} requires '${required}'.`,\n );\n }\n }\n}\n\n/**\n * Which arguments Prisma makes non-optional, matched exactly.\n *\n * `updateMany` and `deleteMany` take an *optional* `where` — `deleteMany({})`\n * legitimately empties a table. Requiring one here would be a safety rail\n * Prisma does not have, and the differential harness would call it a\n * divergence, which is the right verdict: a guard belongs in a policy\n * (iteration 6), not in the compiler.\n */\nfunction requiredArgs(op: Operation): string[] {\n switch (op) {\n case \"create\":\n case \"createMany\":\n return [\"data\"];\n case \"update\":\n return [\"data\", \"where\"];\n case \"updateMany\":\n return [\"data\"];\n case \"delete\":\n return [\"where\"];\n case \"upsert\":\n return [\"where\", \"create\", \"update\"];\n default:\n return [];\n }\n}\n",
22
22
  "import type { ModelSchema } from \"./schema\";\n\n/**\n * The one configuration where a `DateTime` read comes back as the wrong instant.\n *\n * `dialect/postgres.ts` records it as a KNOWN DIVERGENCE and `docs/orm.md` now\n * states the requirement — run Postgres deployments with `TZ=UTC`. Prisma maps\n * `DateTime` to `timestamp(3)`, and Bun decodes that column differently\n * depending on which wire protocol carried the statement, which in turn depends\n * on whether the query bound a parameter:\n *\n * TZ=America/New_York findMany() -> 2021-03-04T10:06:07.008Z\n * where id = $1 -> 2021-03-04T05:06:07.008Z\n *\n * A reader who has seen the documentation sets `TZ=UTC` and never meets this. A\n * reader who has not gets two different instants for the same row and no signal\n * at all — the values look plausible, nothing raises, and the difference is\n * exactly the machine's UTC offset, which is the kind of wrongness that reaches\n * a report or an invoice before anyone notices.\n *\n * So this says it once. The project's stated trade, from the `Json` encoder that\n * had the same shape of bug, is that \"a loud failure replaces a silent\n * mis-store\"; a warning is the most that can be done here, because the value is\n * already decoded by the time anything in this package sees it and it does not\n * carry which protocol produced it.\n *\n * **Not gated on `NODE_ENV`, unlike the slow-transaction warning.** That one is\n * a performance hint, and a hint is worth having only where somebody is\n * watching. This is a correctness fault, and production is exactly where an\n * unnoticed wrong timestamp costs something. It fires once per process, and\n * only when every condition below holds, so a correctly configured deployment\n * never sees it.\n *\n * Pure, and returns the message rather than printing it, so the conditions can\n * be tested without capturing console output or depending on the machine's\n * clock — `offsetMinutes` is a parameter for exactly that reason.\n */\nexport function protocolSkewWarning(\n dialect: string,\n schema: ModelSchema,\n text: string,\n values: readonly unknown[],\n offsetMinutes: number,\n): string | null {\n // Cheapest discriminators first: three of the four are a comparison, and the\n // field scan only runs for a parameterless Postgres select on a machine that\n // is not already UTC.\n if (dialect !== \"postgres\") return null;\n if (values.length > 0) return null;\n if (offsetMinutes === 0) return null;\n\n // A statement that binds nothing and returns no rows cannot show the skew.\n // `RETURNING` writes always bind at least the values they write, so in\n // practice this is the parameterless read.\n if (!/^\\s*select/i.test(text)) return null;\n\n const columns = Object.values(schema.fields)\n .filter((field) => field.type === \"DateTime\")\n .map((field) => field.name);\n\n if (columns.length === 0) return null;\n\n return (\n `[gemi] ${schema.name} was read with a query that binds no parameters, on ` +\n `Postgres, in a process whose clock is not UTC. Bun decodes ` +\n `timestamp(3) over the simple query protocol as local time, so ` +\n `${columns.length === 1 ? \"the column\" : \"columns\"} ` +\n `${columns.join(\", \")} will be off by this machine's UTC offset — the same ` +\n `row read through a query that binds a parameter returns a different ` +\n `instant. Set TZ=UTC on this process. See \"Run Postgres deployments with ` +\n `TZ=UTC\" in docs/orm.md. (Warned once.)`\n );\n}\n\n/**\n * A zone's UTC offset at one instant, asked of a *named* zone.\n *\n * `Date.prototype.getTimezoneOffset` can only answer for the ambient zone, so a\n * test — which runs under `TZ=UTC`, in CI and per the note above — cannot use\n * it to ask what `Europe/London` does in July. `Intl` can: formatting an\n * instant into a zone and reading the fields back as though they were UTC\n * recovers the offset, because the difference between the two *is* what the\n * zone added.\n *\n * With no zone it defers to the clock, which is the call site's path and avoids\n * making the process's own answer depend on `Intl` agreeing with `TZ`.\n */\nfunction offsetMinutesAt(instant: number, timeZone?: string): number {\n if (timeZone === undefined) return new Date(instant).getTimezoneOffset();\n\n const parts = new Intl.DateTimeFormat(\"en-US\", {\n timeZone,\n hourCycle: \"h23\",\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n }).formatToParts(new Date(instant));\n\n const at = (type: string) =>\n Number(parts.find((part) => part.type === type)?.value);\n\n const local = Date.UTC(\n at(\"year\"),\n at(\"month\") - 1,\n at(\"day\"),\n at(\"hour\"),\n at(\"minute\"),\n at(\"second\"),\n );\n\n // `getTimezoneOffset`'s sign convention — minutes to add to local time to get\n // UTC, so positive west of Greenwich — because that is what the caller and\n // `protocolSkewWarning` above both already speak.\n return (instant - local) / 60_000;\n}\n\n/**\n * Whether this process's clock can be off UTC **at any point in the year**.\n *\n * The call site reads this once, at module load, so that a correctly configured\n * deployment pays a boolean per query rather than a `Date` allocation. The\n * thing that may be cached for the life of a process is the *zone*, though, and\n * not the offset it happens to have today:\n *\n * TZ=Europe/London January 0 July -60\n * TZ=Europe/Lisbon January 0 July -60\n * TZ=Africa/Accra January 0 July 0 (genuinely fixed)\n * TZ=UTC January 0 July 0\n *\n * Reading `new Date().getTimezoneOffset()` once would put London in the same\n * bucket as UTC for any process started between late October and late March,\n * and switch the diagnostic off for the whole of BST — when the skew is real.\n * That is the wrong way round: the entire audience for this warning is\n * deployments that did not set `TZ=UTC`.\n *\n * So the question is asked of the zone, by probing a year of it. Twelve probes\n * rather than the two that separate the table above, because northern-summer\n * DST is not the only shape a transition comes in — `Africa/Casablanca` moves\n * with Ramadan, which walks through the calendar — and twelve `Date`s at module\n * load is a cost paid once, against a rule this has to get right for years.\n *\n * `timeZone` exists so the predicate is answerable from a UTC machine, which is\n * the same move that made `protocolSkewWarning` testable: the call site passes\n * nothing and gets the clock.\n */\nexport function clockCouldSkew(timeZone?: string): boolean {\n // The current year, so a zone that has since abolished its DST is read as it\n // is now rather than as some pinned year remembers it.\n const year = new Date().getUTCFullYear();\n\n for (let month = 0; month < 12; month++) {\n if (offsetMinutesAt(Date.UTC(year, month, 1), timeZone) !== 0) return true;\n }\n\n return false;\n}\n\n/** Reports the skew at most once, and only while it is still possible. */\nexport type ProtocolSkewWarner = (\n dialect: string,\n schema: ModelSchema,\n text: string,\n values: readonly unknown[],\n) => string | null;\n\n/**\n * The call site's half of the warning: the gate, the once-per-process latch,\n * and nothing else.\n *\n * It lives here rather than as two module-level bindings in `Model.ts` because\n * of what CI can see. `Model.ts` needs a database to exercise, and the one\n * configuration CI runs — `TZ=UTC` — is the configuration where *neither*\n * branch of the gate can produce a warning. So a gate written inline is\n * invisible to the suite in both directions: inverting it, or deleting the line\n * that sets the latch, leaves every test green. Behind this seam both are\n * ordinary assertions, with no database and no dependence on the ambient clock.\n *\n * `offsetMinutes` is a function, and read per call rather than captured,\n * because caching it is the same mistake `clockCouldSkew` exists to avoid one\n * level up: a London process that cached a winter `0` would clear the gate and\n * then be silenced by `protocolSkewWarning`'s own `offsetMinutes === 0` test\n * all summer. Only a process that could skew ever reads the clock, and it stops\n * as soon as it has said so — which is exactly the deployment the cost is worth\n * paying for.\n */\nexport function createProtocolSkewWarner(\n couldSkew: boolean,\n offsetMinutes: () => number,\n): ProtocolSkewWarner {\n let warned = false;\n\n return (dialect, schema, text, values) => {\n if (!couldSkew || warned) return null;\n\n const warning = protocolSkewWarning(\n dialect,\n schema,\n text,\n values,\n offsetMinutes(),\n );\n\n // Latched on firing, not on asking: the first statement of a process is\n // rarely the parameterless read, and a query that could not have shown the\n // skew is no evidence that none will.\n if (warning !== null) warned = true;\n\n return warning;\n };\n}\n",
23
23
  "import type { SqlDialect } from \"../dialect\";\nimport {\n InvalidArgumentError,\n UnknownFieldError,\n UnsupportedQueryError,\n} from \"../errors\";\nimport type { QueryPlan } from \"../plan\";\nimport type { FieldSchema, ModelSchema, ScalarType } from \"../schema\";\nimport {\n type Fragment,\n bindValues,\n concat,\n joinFragments,\n render,\n sql,\n} from \"./fragment\";\nimport { compileOrderBy, parseOrderBy } from \"./orderBy\";\nimport { pagination } from \"./paginate\";\nimport { compileWhere } from \"./where\";\n\n/**\n * `aggregate`, and the `select` form of `count`.\n *\n * The fourteenth operation, and the first read whose result is neither rows nor\n * a bare number. Its shape is Prisma's, verified against a generated client\n * rather than inferred from the docs — every claim in this file's comments is a\n * line of that probe's output.\n *\n * ## Why it is not just `count` with more functions\n *\n * Three things differ, and each one is a place a plausible implementation is\n * wrong:\n *\n * 1. **`_count` has two shapes.** `_count: true` returns a *number*;\n * `_count: { _all: true, email: true }` returns an object, and a per-field\n * count is `count(\"email\")` — the number of rows where that column is **not\n * null**, which is a different number from `count(*)` and is the whole point\n * of asking per field.\n * 2. **The empty set is not zeroes.** `_count` over no rows is `0`, but `_sum`,\n * `_avg`, `_min` and `_max` are all `null` — per field, inside their objects.\n * An implementation that coalesced to `0` would be wrong in the direction\n * nobody checks.\n * 3. **The driver's types are not the column's types.** `sum(integer)` is\n * `bigint` in Postgres and `avg(integer)` is `numeric`, and Bun hands both\n * back as *strings*. So the coercion cannot be `dialect.decode(value, field)`\n * — that decodes a value of the column's type, and an aggregate is not one.\n * See `coerce` below, where each rule is a measurement.\n *\n * ## Pagination\n *\n * `take` / `skip` describe the rows being aggregated, not the one row the\n * aggregate produces — exactly as they do for `count`, and for the same reason:\n * `limit` beside an aggregate caps the result, which is always one row. So a\n * paginated aggregate wraps its row query in a subquery, the same shape\n * `compileRead` uses. Verified against Prisma: `take: 2` with\n * `orderBy: { globalRole: \"asc\" }` over rows 0, 5, 10 sums to 5, not 15.\n */\n\n/** The aggregate functions Prisma exposes, in the order it returns them. */\nexport const KINDS = [\"_count\", \"_avg\", \"_sum\", \"_min\", \"_max\"] as const;\nexport type Kind = (typeof KINDS)[number];\n\nconst AGGREGATE_ARGS = new Set<string>([\n \"where\",\n \"orderBy\",\n \"take\",\n \"skip\",\n ...KINDS,\n]);\n\n/**\n * `_sum` and `_avg` need arithmetic, so Prisma restricts them to these.\n *\n * `Decimal` is listed for completeness and cannot occur: `emit.ts` refuses a\n * Decimal field at generation time, so no generated schema has one.\n */\nconst NUMERIC = new Set<ScalarType>([\"Int\", \"Float\", \"BigInt\", \"Decimal\"]);\n\n/**\n * `_min` / `_max` need an ordering. `Json` has none in either dialect, and\n * `Bytes` orders bytewise in a way Prisma does not expose — both are refused\n * rather than emitted and left to disagree.\n */\nconst UNORDERABLE = new Set<ScalarType>([\"Json\", \"Bytes\"]);\n\n/** The SQL function each kind compiles to. */\nexport const FUNCTION: Record<Kind, string> = {\n _count: \"count\",\n _avg: \"avg\",\n _sum: \"sum\",\n _min: \"min\",\n _max: \"max\",\n};\n\nexport interface Term {\n kind: Kind;\n /** Absent for `_count`'s `_all`, which is `count(*)`. */\n field?: FieldSchema;\n /** The key this term is written to inside its kind's object. */\n as: string;\n /** The column alias it comes back under. Positional, so it cannot collide. */\n alias: string;\n}\n\nexport function isAggregateOperation(op: string): boolean {\n return op === \"aggregate\";\n}\n\n/**\n * `aggregate`, and `count({ select })` — which is the same statement with a\n * flatter result.\n *\n * Prisma's `count({ select: { _all: true, email: true } })` returns\n * `{ _all: 3, email: 2 }`: no `_count` wrapper, because the operation already\n * says what the numbers are. It was refused here until now as \"aggregate\n * territory\", which was the right call while there was no aggregate to put it\n * beside; the two decisions belong together and this is the together.\n *\n * **No `ExecOptions`**, unlike every neighbouring read, and that is deliberate\n * rather than an omission: `strategy` chooses how an include tree loads and an\n * aggregate has no relations, `track` records where a row came from so `save`\n * can update it and an aggregate returns no rows. Accepting either and ignoring\n * it would be worse than not accepting it.\n */\nexport function compileAggregate(\n schema: ModelSchema,\n op: string,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n const flat = op === \"count\";\n assertArgs(schema, op, args, flat);\n\n const terms = flat\n ? countSelectTerms(schema, op, args?.select)\n : aggregateTerms(schema, op, args);\n\n if (terms.length === 0) {\n throw new UnsupportedQueryError(\n op,\n schema.name,\n op,\n flat\n ? `A 'select' on a count must name at least one field, or '_all'.`\n : `An aggregate needs at least one of ${KINDS.join(\", \")}. Prisma ` +\n `rejects an empty one too.`,\n );\n }\n\n const where = compileWhere(\n schema,\n args?.where,\n { dialect, operation: op },\n (a) => a?.where,\n );\n const whereClause = where ? concat(sql(\" where \"), where) : sql(\"\");\n const from = sql(` from ${dialect.quoteIdent(schema.table)}`);\n\n const projection = joinFragments(\n terms.map((term) =>\n sql(\n `${FUNCTION[term.kind]}(${\n term.field ? dialect.quoteIdent(term.field.column) : \"*\"\n }) as ${dialect.quoteIdent(term.alias)}`,\n ),\n ),\n \", \",\n );\n\n // Parsed unconditionally, so that validation does not depend on whether a\n // *different* argument was also supplied — the same rule `count` follows.\n const parsed = parseOrderBy(schema, args?.orderBy, op, {\n dialect,\n locate: (a: any) => a?.orderBy,\n });\n const paginating = args?.take !== undefined || args?.skip !== undefined;\n\n let statement: Fragment;\n\n if (!paginating) {\n statement = concat(sql(\"select \"), projection, from, whereClause);\n } else {\n const { clause, terms: order } = pagination(\n schema,\n op,\n args,\n dialect,\n parsed,\n );\n const ordering = compileOrderBy(order, dialect);\n\n // The subquery selects every column an aggregate names — an `order by` may\n // reference columns beyond them, which is fine, since it is resolved\n // against the table rather than against the select list.\n //\n // With only `count(*)` there is no such column, so it selects the primary\n // key: the narrowest thing that keeps a row identity, which is what\n // `compileRead`'s paginated count does for the same reason.\n const columns = new Map<string, string>();\n for (const term of terms) {\n if (term.field) columns.set(term.field.column, term.field.column);\n }\n if (columns.size === 0) {\n const key = schema.primaryKey[0] ?? Object.keys(schema.fields)[0];\n const column = schema.fields[key]?.column ?? key;\n columns.set(column, column);\n }\n\n statement = concat(\n sql(\"select \"),\n projection,\n sql(\n ` from (select ${[...columns.values()]\n .map((column) => dialect.quoteIdent(column))\n .join(\", \")}`,\n ),\n from,\n whereClause,\n ordering ? concat(sql(\" order by \"), ordering) : sql(\"\"),\n clause,\n sql(`) as ${dialect.quoteIdent(\"sub\")}`),\n );\n }\n\n const { text, binders } = render(statement, dialect, {\n model: schema.name,\n operation: op,\n });\n\n return {\n text,\n bind: bindValues(binders),\n shape(rows) {\n const row = (rows as Record<string, unknown>[])[0] ?? {};\n\n if (flat) {\n const out: Record<string, unknown> = {};\n for (const term of terms)\n out[term.as] = coerce(term, row[term.alias], dialect);\n return out;\n }\n\n const out: Record<string, unknown> = {};\n for (const term of terms) {\n // `_count: true` is a number rather than an object, and it is the only\n // aggregate that can be either.\n if (term.kind === \"_count\" && term.as === BARE) {\n out._count = coerce(term, row[term.alias], dialect);\n continue;\n }\n const bucket = (out[term.kind] ??= {}) as Record<string, unknown>;\n bucket[term.as] = coerce(term, row[term.alias], dialect);\n }\n return out;\n },\n };\n}\n\n/** The `as` a bare `_count: true` carries, which no field name can be. */\nexport const BARE = \"\";\n\nexport function aggregateTerms(\n schema: ModelSchema,\n op: string,\n args: any,\n): Term[] {\n const terms: Term[] = [];\n\n for (const kind of KINDS) {\n const requested = args?.[kind];\n if (requested === undefined || requested === false) continue;\n\n if (kind === \"_count\" && requested === true) {\n terms.push({ kind, as: BARE, alias: alias(kind, terms.length) });\n continue;\n }\n\n if (\n typeof requested !== \"object\" ||\n requested === null ||\n Array.isArray(requested)\n ) {\n throw new InvalidArgumentError(\n kind,\n schema.name,\n op,\n kind === \"_count\"\n ? `Expected true or an object of fields.`\n : `Expected an object of fields.`,\n );\n }\n\n for (const key of Object.keys(requested).sort()) {\n const wanted = (requested as Record<string, unknown>)[key];\n if (wanted === undefined || wanted === false) continue;\n\n if (kind === \"_count\" && key === \"_all\") {\n terms.push({ kind, as: \"_all\", alias: alias(kind, terms.length) });\n continue;\n }\n\n const field = resolveField(schema, op, kind, key);\n assertAggregable(schema, op, kind, field);\n terms.push({ kind, field, as: key, alias: alias(kind, terms.length) });\n }\n }\n\n return terms;\n}\n\n/** `count({ select: { _all: true, email: true } })` — every term a `count`. */\nfunction countSelectTerms(\n schema: ModelSchema,\n op: string,\n select: any,\n): Term[] {\n if (typeof select !== \"object\" || select === null || Array.isArray(select)) {\n throw new InvalidArgumentError(\n \"select\",\n schema.name,\n op,\n `Expected an object of fields.`,\n );\n }\n\n const terms: Term[] = [];\n for (const key of Object.keys(select).sort()) {\n const wanted = select[key];\n if (wanted === undefined || wanted === false) continue;\n\n if (key === \"_all\") {\n terms.push({\n kind: \"_count\",\n as: \"_all\",\n alias: alias(\"_count\", terms.length),\n });\n continue;\n }\n\n const field = resolveField(schema, op, \"_count\", key);\n terms.push({\n kind: \"_count\",\n field,\n as: key,\n alias: alias(\"_count\", terms.length),\n });\n }\n return terms;\n}\n\n/**\n * Positional, so two terms can never collide however the model is named — a\n * field called `_all` would otherwise produce the same alias as `_count`'s own.\n * The kind stays in the name because a query log is read by a person.\n */\nconst alias = (kind: Kind, index: number) => `${kind}_${index}`;\n\nexport function resolveField(\n schema: ModelSchema,\n op: string,\n kind: Kind,\n name: string,\n): FieldSchema {\n const field = schema.fields[name];\n if (!field) {\n // A relation named here is a plausible mistake with an unhelpful default\n // message, so it gets its own.\n if (name in schema.relations) {\n throw new UnsupportedQueryError(\n `${kind}.${name}`,\n schema.name,\n op,\n `'${name}' is a relation. Aggregate its own model instead, or use ` +\n `'_count' inside an 'include' to count it per row.`,\n );\n }\n throw new UnknownFieldError(name, schema.name, Object.keys(schema.fields));\n }\n return field;\n}\n\nexport function assertAggregable(\n schema: ModelSchema,\n op: string,\n kind: Kind,\n field: FieldSchema,\n): void {\n if ((kind === \"_sum\" || kind === \"_avg\") && !NUMERIC.has(field.type)) {\n throw new UnsupportedQueryError(\n `${kind}.${field.name}`,\n schema.name,\n op,\n `'${field.name}' is a ${field.type}, and ${kind} needs a number. ` +\n `Prisma does not offer it on this field either.`,\n );\n }\n\n if ((kind === \"_min\" || kind === \"_max\") && UNORDERABLE.has(field.type)) {\n throw new UnsupportedQueryError(\n `${kind}.${field.name}`,\n schema.name,\n op,\n `'${field.name}' is a ${field.type}, which has no ordering the two ` +\n `dialects agree on.`,\n );\n }\n}\n\n/**\n * The driver's value for one aggregate, as the value Prisma returns.\n *\n * **Every line here is a measurement**, taken through Bun against Postgres 16\n * and SQLite, because the obvious rule — \"decode it as the column's type\" — is\n * wrong for three of the five kinds. What Postgres returns:\n *\n * count(*) \"2\" string\n * count(text) \"2\" string\n * sum(integer) \"4\" string <- bigint\n * sum(bigint) \"9007199254740995\" string\n * sum(double) 4 number\n * avg(integer) \"2.0000000000000000\" string <- numeric\n * avg(double) 2 number\n * min(integer) 1 number\n * max(text) \"b\" string\n * min(timestamp) Date object\n * max(bigint) \"9007199254740993\" string\n *\n * ...and over an empty set every one of them is `null` except the counts, which\n * are `\"0\"`.\n *\n * So:\n *\n * - **`_count` is always a number**, and always present. `Number(\"0\")` rather\n * than a coalesce, because the driver gives a string and `?? 0` would leave it\n * one.\n * - **`_avg` is always a number**, whatever the column is — Prisma returns a\n * float for the average of an `Int`, and Postgres hands back `numeric` text.\n * - **`_sum` keeps the column's type**, so it is the one kind where a `BigInt`\n * column matters: `sum(bigint)` crosses as an exact string, and `Number()` on\n * 9007199254740995 would silently drop the low bits. Same trap the lateral\n * strategy's `::text` cast exists for.\n * - **`_min` / `_max` are values of the column**, so here — and only here — the\n * dialect's own `decode` is exactly right. It is what turns SQLite's integer\n * milliseconds back into a `Date`.\n */\nexport function coerce(\n term: Term,\n value: unknown,\n dialect: SqlDialect,\n): unknown {\n if (term.kind === \"_count\") return Number(value ?? 0);\n\n // Every other aggregate is null over an empty set, and per field.\n if (value === null || value === undefined) return null;\n\n if (term.kind === \"_avg\") return Number(value);\n\n if (term.kind === \"_sum\") {\n const type = term.field?.type;\n if (type === \"BigInt\") return BigInt(String(value));\n // `Decimal` is **unreachable**, not merely untested: `emit.ts`'s\n // `UNSUPPORTED_SCALARS` refuses a Decimal field at generation time, so no\n // generated schema can carry one and neither this branch nor `Decimal`'s\n // membership of `NUMERIC` can be entered.\n //\n // Kept, and kept as a pass-through, because the day Decimal becomes\n // supported is the day this needs a real decision — Postgres returns\n // `sum(numeric)` as text, and whether that becomes a `Prisma.Decimal`, a\n // string or a number is the same question the generator declined to answer.\n // Silently `Number()`-ing it would answer it wrongly and lose exactly the\n // precision the type exists to keep.\n if (type === \"Decimal\") return value;\n return Number(value);\n }\n\n // `_min` / `_max` are values *of the column*, so here — and only here — the\n // dialect's own `decode` is exactly right. It is what turns SQLite's integer\n // milliseconds back into a `Date`, and Postgres's `bigint` text into a\n // `BigInt`. Without it a `_max: { createdAt: true }` comes back as\n // 1600000004000 where Prisma returns a `Date`, on SQLite only — which is the\n // shape of every bug this file's coercion table exists to prevent.\n return term.field ? dialect.decode(value, term.field) : value;\n}\n\nfunction assertArgs(\n schema: ModelSchema,\n op: string,\n args: any,\n flat: boolean,\n): void {\n if (args === undefined || args === null) {\n if (flat) return;\n throw new UnsupportedQueryError(\n op,\n schema.name,\n op,\n `An aggregate needs at least one of ${KINDS.join(\", \")}.`,\n );\n }\n\n if (typeof args !== \"object\" || Array.isArray(args)) {\n throw new InvalidArgumentError(\n String(args),\n schema.name,\n op,\n \"Expected an object.\",\n );\n }\n\n if (flat) return;\n\n for (const key of Object.keys(args).sort()) {\n if (args[key] === undefined) continue;\n if (AGGREGATE_ARGS.has(key)) continue;\n\n // `select` and `include` are the two a caller reaches for by habit, and\n // neither means anything here: an aggregate's shape is decided entirely by\n // which functions were asked for.\n if (key === \"select\" || key === \"include\") {\n throw new UnsupportedQueryError(\n key,\n schema.name,\n op,\n `An aggregate returns the functions it was given, so there is nothing ` +\n `to ${key === \"select\" ? \"select\" : \"include\"}. Prisma does not ` +\n `accept it either.`,\n );\n }\n\n throw new UnsupportedQueryError(\n key,\n schema.name,\n op,\n `${op} takes ${[...AGGREGATE_ARGS].sort().join(\", \")}.`,\n );\n }\n}\n",
24
24
  "import type { SqlDialect } from \"../dialect\";\nimport { UnknownFieldError, UnsupportedQueryError } from \"../errors\";\nimport type { QueryPlan } from \"../plan\";\nimport type { FieldSchema, ModelSchema } from \"../schema\";\nimport {\n BARE,\n FUNCTION,\n KINDS,\n type Kind,\n type Term,\n aggregateTerms,\n assertAggregable,\n coerce,\n resolveField,\n} from \"./aggregate\";\nimport {\n type Fragment,\n bindValues,\n concat,\n joinFragments,\n param,\n render,\n sql,\n} from \"./fragment\";\nimport { pagination } from \"./paginate\";\nimport { compileWhere } from \"./where\";\n\n/**\n * `groupBy` — the second half of #64, and the half that is not just `aggregate`\n * with a `group by` bolted on.\n *\n * Three things make it its own compiler rather than a flag on `compileAggregate`:\n *\n * - The result is **many rows with a mixed shape**: the grouped columns arrive\n * flat, the aggregates arrive nested under their kind, in one object.\n * - `having` is a second predicate compiler. It filters *groups*, so its\n * operands are aggregate expressions as well as columns, and it has to emit\n * `count(\"x\") > $1` where `compileWhere` would emit `\"x\" > $1`.\n * - `orderBy` is restricted in a way no other operation's is, and it can name an\n * aggregate.\n *\n * Every rule below was read off a live Prisma 6 client rather than from its\n * documentation, because several of them are not what the shape suggests — most\n * of all that `orderBy` is *optional* here, where the issue that asked for this\n * predicted it would be mandatory.\n */\n\nconst GROUP_BY_ARGS = new Set<string>([\n \"by\",\n \"where\",\n \"orderBy\",\n \"having\",\n \"take\",\n \"skip\",\n ...KINDS,\n]);\n\nexport function isGroupByOperation(op: string): boolean {\n return op === \"groupBy\";\n}\n\n/** One grouped column, and the key it comes back under. */\ninterface Grouped {\n field: FieldSchema;\n alias: string;\n}\n\n/**\n * **No `ExecOptions`**, for the reason `aggregate` has none: `strategy` chooses\n * how an include tree loads and there are no relations here, `track` records\n * where a row came from so `save` can update it and a group is not a row.\n */\nexport function compileGroupBy(\n schema: ModelSchema,\n op: string,\n args: any,\n dialect: SqlDialect,\n): QueryPlan {\n assertArgs(schema, op, args);\n\n const grouped = groupedColumns(schema, op, args?.by);\n const terms = aggregateTerms(schema, op, args);\n\n const from = sql(` from ${dialect.quoteIdent(schema.table)}`);\n const where = compileWhere(schema, args?.where, { dialect, operation: op }, (a) => a?.where);\n const whereClause = where ? concat(sql(\" where \"), where) : sql(\"\");\n\n // The grouped columns first, then the aggregates. Prisma returns them the\n // other way round in key order, which `shape` reproduces; the *select* list\n // order is ours and the readable one is grouping first.\n const projection = joinFragments(\n [\n ...grouped.map((column) =>\n sql(\n `${dialect.quoteIdent(column.field.column)} as ${dialect.quoteIdent(column.alias)}`,\n ),\n ),\n ...terms.map((term) => sql(functionOf(term, dialect))),\n ],\n \", \",\n );\n\n const groupClause = concat(\n sql(\" group by \"),\n joinFragments(\n grouped.map((column) => sql(dialect.quoteIdent(column.field.column))),\n \", \",\n ),\n );\n\n const having = compileHaving(schema, op, args?.having, grouped, dialect);\n const havingClause = having ? concat(sql(\" having \"), having) : sql(\"\");\n\n const ordering = compileGroupOrdering(schema, op, args?.orderBy, grouped, dialect);\n const orderClause = ordering ? concat(sql(\" order by \"), ordering) : sql(\"\");\n\n // `take` / `skip` page the **groups**, which is what `limit` after `group by`\n // already means — so unlike `aggregate`, which has to wrap its rows in a\n // subquery to keep the limit off the single result row, this needs no\n // subquery at all.\n //\n // `parsed` is empty because the ordering above is already compiled: a group's\n // `order by` may name an aggregate, which `parseOrderBy` has no way to\n // express. Passing an empty list means `pagination` contributes only the\n // `limit` / `offset`, and its \"paginating with no orderBy sorts by the primary\n // key\" fallback cannot fire — correctly, because the primary key is not\n // grouped and Prisma does not add one either.\n //\n // **This is the fourth pager, and it inherited #84's validation for free.**\n // #88 moved the `take` / `skip` integer check into `pagination` itself rather\n // than into each caller's argument allowlist, arguing that a fourth pager\n // should not be able to arrive without one. This is that fourth pager: it was\n // written against a base where #88 had not merged, gained the check when it\n // did, and the only line that had to change is the `operation` argument here.\n const paginating = args?.take !== undefined || args?.skip !== undefined;\n const page = paginating\n ? pagination(schema, op, args, dialect, []).clause\n : sql(\"\");\n\n const statement = concat(\n sql(\"select \"),\n projection,\n from,\n whereClause,\n groupClause,\n havingClause,\n orderClause,\n page,\n );\n\n const { text, binders } = render(statement, dialect, {\n model: schema.name,\n operation: op,\n });\n\n return {\n text,\n bind: bindValues(binders),\n shape(rows) {\n return (rows as Record<string, unknown>[]).map((row) => {\n const out: Record<string, unknown> = {};\n\n // Aggregates first, then the grouped columns: Prisma's own key order,\n // which matters only for a caller reading `Object.keys` but costs\n // nothing to match.\n for (const term of terms) {\n if (term.kind === \"_count\" && term.as === BARE) {\n out._count = coerce(term, row[term.alias], dialect);\n continue;\n }\n const bucket = (out[term.kind] ??= {}) as Record<string, unknown>;\n bucket[term.as] = coerce(term, row[term.alias], dialect);\n }\n\n for (const column of grouped) {\n out[column.field.name] = dialect.needsDecode(column.field)\n ? dialect.decode(row[column.alias], column.field)\n : row[column.alias];\n }\n\n return out;\n });\n },\n };\n}\n\n/** `count(\"x\") as \"_count_0\"`, or `count(*)` for `_count: true` / `_all`. */\nfunction functionOf(term: Term, dialect: SqlDialect): string {\n const operand = term.field ? dialect.quoteIdent(term.field.column) : \"*\";\n return `${FUNCTION[term.kind]}(${operand}) as ${dialect.quoteIdent(term.alias)}`;\n}\n\n/**\n * `by: [\"role\"]` and `by: \"role\"` are both Prisma, and the string form is the\n * one a caller reaches for with a single field. Measured, not assumed — it is\n * easy to read the generated types as array-only.\n */\nfunction groupedColumns(schema: ModelSchema, op: string, by: unknown): Grouped[] {\n const names = typeof by === \"string\" ? [by] : by;\n\n if (!Array.isArray(names)) {\n throw new UnsupportedQueryError(\n \"by\",\n schema.name,\n op,\n `Expected a field name or an array of them, got ${JSON.stringify(by)}.`,\n );\n }\n\n if (names.length === 0) {\n throw new UnsupportedQueryError(\n \"by\",\n schema.name,\n op,\n `At least one field is required to group by. Prisma rejects an empty ` +\n `'by' too — without one there is nothing to group, and the answer ` +\n `would be 'aggregate'.`,\n );\n }\n\n const grouped: Grouped[] = [];\n const seen = new Set<string>();\n\n for (const name of names) {\n if (typeof name !== \"string\") {\n throw new UnsupportedQueryError(\n \"by\",\n schema.name,\n op,\n `Expected field names, got ${JSON.stringify(name)}.`,\n );\n }\n // A duplicate is harmless in SQL and would return the column twice under\n // one key, so it is dropped rather than refused.\n if (seen.has(name)) continue;\n seen.add(name);\n\n if (name in schema.relations) {\n throw new UnsupportedQueryError(\n `by.${name}`,\n schema.name,\n op,\n `'${name}' is a relation. A group is a set of rows of this model, so ` +\n `only its own columns can name one.`,\n );\n }\n\n const field = schema.fields[name];\n if (!field) {\n throw new UnknownFieldError(name, schema.name, Object.keys(schema.fields));\n }\n\n grouped.push({ field, alias: `_by_${grouped.length}` });\n }\n\n return grouped;\n}\n\n/**\n * `having`, which filters **groups** rather than rows.\n *\n * Two operand shapes, and Prisma accepts both against the same key:\n *\n * having: { role: { gt: 0 } } the grouped column itself\n * having: { role: { _count: { gt: 1 } } } an aggregate over the group\n *\n * The first is only legal because `role` is in `by` — SQL would reject a bare\n * column in `having` otherwise, and Prisma refuses it first with *\"Every field\n * used in `having` filters must either be an aggregation filter or be included\n * in the selection of the query\"*. That refusal is reproduced rather than left\n * to the database, because the database's version of it names neither the\n * argument nor the model.\n *\n * Written here rather than threaded through `compileWhere` as an option: the\n * operand of an aggregate filter is a *function call*, not a column, and\n * teaching the row-predicate compiler to sometimes wrap its left-hand side\n * would put a group's rules inside the file every ordinary query uses.\n */\nfunction compileHaving(\n schema: ModelSchema,\n op: string,\n having: unknown,\n grouped: Grouped[],\n dialect: SqlDialect,\n path: (args: any) => any = (a) => a?.having,\n): Fragment | null {\n if (having === undefined || having === null) return null;\n if (typeof having !== \"object\" || Array.isArray(having)) {\n throw new UnsupportedQueryError(\n \"having\",\n schema.name,\n op,\n `Expected an object of field filters.`,\n );\n }\n\n const source = having as Record<string, unknown>;\n const parts: Fragment[] = [];\n\n // Sorted, for the reason every walk in this compiler is: the plan cache\n // canonicalises key order, so two argument objects differing only in it have\n // to produce one statement.\n for (const key of Object.keys(source).sort()) {\n const operand = source[key];\n if (operand === undefined) continue;\n\n if (key === \"AND\" || key === \"OR\" || key === \"NOT\") {\n const combined = combinator(schema, op, key, operand, grouped, dialect, path);\n if (combined) parts.push(combined);\n continue;\n }\n\n const aggregated = isAggregateFilter(operand);\n const field = havingField(schema, op, key, grouped, aggregated);\n\n if (aggregated) {\n assertPureAggregate(schema, op, key, operand);\n for (const kind of KINDS) {\n const filter = (operand as Record<string, unknown>)[kind];\n if (filter === undefined) continue;\n assertAggregable(schema, op, kind, field);\n parts.push(\n comparison(\n `${FUNCTION[kind]}(${dialect.quoteIdent(field.column)})`,\n filter,\n schema,\n op,\n `having.${key}.${kind}`,\n (args) => path(args)?.[key]?.[kind],\n dialect,\n ),\n );\n }\n continue;\n }\n\n parts.push(\n comparison(\n dialect.quoteIdent(field.column),\n operand,\n schema,\n op,\n `having.${key}`,\n (args) => path(args)?.[key],\n dialect,\n ),\n );\n }\n\n if (parts.length === 0) return null;\n return parts.length === 1\n ? parts[0]\n : concat(sql(\"(\"), joinFragments(parts, \" and \"), sql(\")\"));\n}\n\nfunction combinator(\n schema: ModelSchema,\n op: string,\n key: \"AND\" | \"OR\" | \"NOT\",\n operand: unknown,\n grouped: Grouped[],\n dialect: SqlDialect,\n path: (args: any) => any,\n): Fragment | null {\n const list = Array.isArray(operand) ? operand : [operand];\n const parts: Fragment[] = [];\n\n for (let index = 0; index < list.length; index++) {\n const at = Array.isArray(operand)\n ? (args: any) => path(args)?.[key]?.[index]\n : (args: any) => path(args)?.[key];\n const compiled = compileHaving(schema, op, list[index], grouped, dialect, at);\n if (compiled) parts.push(compiled);\n }\n\n if (parts.length === 0) {\n // Matching `compileWhere`: an empty `AND` is vacuously true, an empty `OR`\n // matches nothing. `NOT` of nothing is the same as `AND` of nothing.\n return key === \"OR\" ? sql(\"false\") : null;\n }\n\n const joined =\n parts.length === 1\n ? parts[0]\n : concat(sql(\"(\"), joinFragments(parts, key === \"OR\" ? \" or \" : \" and \"), sql(\")\"));\n\n return key === \"NOT\" ? concat(sql(\"not (\"), joined, sql(\")\")) : joined;\n}\n\n/** `{ _count: { gt: 1 } }` rather than `{ gt: 1 }`. */\nfunction isAggregateFilter(operand: unknown): boolean {\n if (typeof operand !== \"object\" || operand === null || Array.isArray(operand)) {\n return false;\n }\n return KINDS.some((kind) => kind in (operand as Record<string, unknown>));\n}\n\n/**\n * The field a `having` key names.\n *\n * **The rule is Prisma's own sentence, and it is an `or`:** *\"Every field used\n * in `having` filters must either be an aggregation filter or be included in\n * the selection of the query\"*. So which form the operand takes decides whether\n * the field has to be grouped:\n *\n * having: { role: { gt: 0 } } role must be in `by`\n * having: { email: { _count: { gt: 1 } } } any field — it is aggregated\n *\n * The second is legal SQL for the same reason it is legal Prisma: `count(email)`\n * has one value per group whether or not `email` is grouped. Measured against a\n * live client rather than inferred from the refusal of the first — reading that\n * message as \"the field must be in `by`\" would have refused a query Prisma\n * accepts, which is how this was nearly written.\n */\nfunction havingField(\n schema: ModelSchema,\n op: string,\n name: string,\n grouped: Grouped[],\n aggregated: boolean,\n): FieldSchema {\n const field = resolveField(schema, op, \"_count\", name);\n if (aggregated) return field;\n if (grouped.some((column) => column.field.name === field.name)) return field;\n\n throw new UnsupportedQueryError(\n `having.${name}`,\n schema.name,\n op,\n `'${name}' is not in 'by'. A 'having' filter on a plain column needs the ` +\n `column to be grouped — a group has one value for those and many for ` +\n `everything else. Prisma refuses this too. Add '${name}' to 'by', ` +\n `aggregate it instead ('having: { ${name}: { _count: { … } } }'), or ` +\n `filter the rows with 'where' rather than the groups with 'having'.`,\n );\n}\n\n/**\n * An operand is one form or the other, never both.\n *\n * `having: { role: { gt: 0, _count: { gt: 1 } } }` reads as though it should\n * mean \"the group's role is above 0 *and* it has more than one row\", and there\n * is a sensible statement for it. Prisma does not produce that statement — its\n * query engine **panics**:\n *\n * thread 'tokio-runtime-worker' panicked at\n * query-engine/core/src/query_graph_builder/read/aggregations/group_by.rs:136\n * internal error: entered unreachable code\n *\n * So there is nothing to match, and inventing a meaning would put gemi ahead of\n * Prisma on a shape Prisma cannot express — which is exactly where a\n * differential test has no oracle. Refused by name instead, with the spelling\n * that does work.\n */\nfunction assertPureAggregate(\n schema: ModelSchema,\n op: string,\n name: string,\n operand: unknown,\n): void {\n const extra = Object.keys(operand as Record<string, unknown>).filter(\n (key) => !(KINDS as readonly string[]).includes(key),\n );\n if (extra.length === 0) return;\n\n throw new UnsupportedQueryError(\n `having.${name}`,\n schema.name,\n op,\n `A 'having' filter is either a comparison on a grouped column or a filter ` +\n `on an aggregate of it, not both — this one mixes ` +\n `${extra.sort().join(\", \")} with an aggregate. Prisma's query engine ` +\n `panics on this shape rather than answering it, so there is no ` +\n `behaviour to match. Use an 'AND' of the two filters instead.`,\n );\n}\n\n/**\n * The comparison operators a `having` operand may use.\n *\n * **`as const`, so `HavingComparison` in `../types` can be a mapped type over\n * its keys rather than a second copy of them.** The type used to list the same\n * six names in another file, with nothing making the two agree — the same\n * mechanism as `JSON_FILTER_NAMES` in `./where.ts`, and the one that let #326,\n * #333, #336 and #337 each ship a compiler and a type that disagreed.\n *\n * Narrower than a `where`'s set on purpose: `having` walks this table and\n * nothing else, so `contains`, `in`, `startsWith` and `mode` are refused here.\n */\nconst OPERATORS = {\n equals: \"=\",\n not: \"<>\",\n lt: \"<\",\n lte: \"<=\",\n gt: \">\",\n gte: \">=\",\n} as const;\n\n/** One of {@link OPERATORS}' keys. `HavingComparison` maps over this. */\nexport type HavingOperator = keyof typeof OPERATORS;\n\n/**\n * The same table, widened for lookup: the key comes from a caller's object and\n * is `string`, not {@link HavingOperator} — that is the question being asked.\n *\n * `Readonly`, because this alias points at the object {@link HavingOperator} is\n * derived from: without it `OPERATOR_SQL.contains = \"like\"` would typecheck and\n * mutate the source of truth. The `| undefined` is the load-bearing half — it\n * is what makes the `if (!operator)` guard below honest rather than a cast that\n * claims every string is a key.\n */\nconst OPERATOR_SQL: Readonly<Record<string, string | undefined>> = OPERATORS;\n\nfunction comparison(\n lhs: string,\n operand: unknown,\n schema: ModelSchema,\n op: string,\n argument: string,\n locate: (args: any) => any,\n dialect: SqlDialect,\n): Fragment {\n // A bare value is `equals`, the same shorthand `where` accepts.\n if (typeof operand !== \"object\" || operand === null || operand instanceof Date) {\n return concat(sql(`${lhs} = `), param((args) => dialect.encodeUntyped(locate(args))));\n }\n\n const source = operand as Record<string, unknown>;\n const parts: Fragment[] = [];\n\n for (const key of Object.keys(source).sort()) {\n const value = source[key];\n if (value === undefined) continue;\n\n const operator = OPERATOR_SQL[key];\n if (!operator) {\n throw new UnsupportedQueryError(\n `${argument}.${key}`,\n schema.name,\n op,\n `A 'having' filter takes ${Object.keys(OPERATORS).sort().join(\", \")}.`,\n );\n }\n\n if (value === null) {\n parts.push(sql(`${lhs} is ${key === \"not\" ? \"not \" : \"\"}null`));\n continue;\n }\n\n parts.push(\n concat(\n sql(`${lhs} ${operator} `),\n param((args) => dialect.encodeUntyped(locate(args)?.[key])),\n ),\n );\n }\n\n if (parts.length === 0) return sql(\"true\");\n return parts.length === 1\n ? parts[0]\n : concat(sql(\"(\"), joinFragments(parts, \" and \"), sql(\")\"));\n}\n\n/**\n * `orderBy`, under the one restriction no other operation has.\n *\n * *\"Every field used for orderBy must be included in the by-arguments of the\n * query\"* — Prisma's own words, and the reason is that a group has one value\n * for a grouped column and many for everything else, so ordering by an\n * ungrouped column is a question with no answer. Reproduced rather than passed\n * through, because SQLite answers it anyway by picking an arbitrary row's\n * value, and a silently arbitrary order is worse than a refusal.\n *\n * An **aggregate** may be named — `orderBy: { _count: { role: \"desc\" } }` is\n * the top-N-by-count query — and it is the one ordering term that is a function\n * call rather than a column, which is why this does not go through\n * `parseOrderBy`.\n *\n * `orderBy` is *optional* here. #64 predicted Prisma would require it whenever\n * `by` is given; measured against a live client, `groupBy` with no `orderBy` at\n * all is accepted, so requiring one would have refused a legal query.\n */\nfunction compileGroupOrdering(\n schema: ModelSchema,\n op: string,\n orderBy: unknown,\n grouped: Grouped[],\n dialect: SqlDialect,\n): Fragment | null {\n if (orderBy === undefined || orderBy === null) return null;\n\n const entries = Array.isArray(orderBy) ? orderBy : [orderBy];\n const parts: string[] = [];\n\n for (const entry of entries) {\n if (typeof entry !== \"object\" || entry === null) {\n throw new UnsupportedQueryError(\n \"orderBy\",\n schema.name,\n op,\n `Expected an object of fields, or an array of them.`,\n );\n }\n\n for (const key of Object.keys(entry)) {\n const value = (entry as Record<string, unknown>)[key];\n if (value === undefined) continue;\n\n if ((KINDS as readonly string[]).includes(key)) {\n parts.push(...aggregateOrdering(schema, op, key as Kind, value, dialect));\n continue;\n }\n\n const field = schema.fields[key];\n if (!field) {\n throw new UnknownFieldError(key, schema.name, Object.keys(schema.fields));\n }\n if (!grouped.some((column) => column.field.name === field.name)) {\n throw new UnsupportedQueryError(\n `orderBy.${key}`,\n schema.name,\n op,\n `'${key}' is not in 'by'. Every field an 'orderBy' names has to be ` +\n `one of the grouped columns, because a group has one value for ` +\n `those and many for everything else. Prisma refuses this too.`,\n );\n }\n\n parts.push(`${dialect.quoteIdent(field.column)} ${direction(schema, op, key, value)}`);\n }\n }\n\n if (parts.length === 0) return null;\n return sql(parts.join(\", \"));\n}\n\nfunction aggregateOrdering(\n schema: ModelSchema,\n op: string,\n kind: Kind,\n operand: unknown,\n dialect: SqlDialect,\n): string[] {\n if (typeof operand !== \"object\" || operand === null || Array.isArray(operand)) {\n throw new UnsupportedQueryError(\n `orderBy.${kind}`,\n schema.name,\n op,\n `Expected an object of fields.`,\n );\n }\n\n const parts: string[] = [];\n const source = operand as Record<string, unknown>;\n\n for (const key of Object.keys(source)) {\n const value = source[key];\n if (value === undefined) continue;\n\n if (kind === \"_count\" && key === \"_all\") {\n parts.push(`count(*) ${direction(schema, op, `${kind}._all`, value)}`);\n continue;\n }\n\n const field = resolveField(schema, op, kind, key);\n assertAggregable(schema, op, kind, field);\n parts.push(\n `${FUNCTION[kind]}(${dialect.quoteIdent(field.column)}) ` +\n `${direction(schema, op, `${kind}.${key}`, value)}`,\n );\n }\n\n return parts;\n}\n\n/**\n * A direction is structural, never a parameter — the same rule `orderBy` has.\n *\n * **And the same grammar, which is why the long form is here too.** `groupBy` is\n * the one caller that does not go through `parseOrderBy`; it reimplements the\n * parse because its `orderBy` may also name an aggregate, which `parseOrderBy`\n * knows nothing about. That made `{ sort, nulls }` a compile error here long\n * after `findMany` accepted it, and when `OrderByInput` learned the long form\n * (#337) this became the divergence that type widening is supposed to remove —\n * a type accepting what the compiler refuses, in the operation the ordering\n * matters most in. `nulls first` / `nulls last` is valid on a grouped ordering\n * on both dialects, including after an aggregate.\n *\n * Kept as its own reader rather than shared with `parseOrderBy`: that one\n * resolves columns and relations and returns `OrderTerm`s, where this needs a\n * string to append to an already-built expression.\n */\nfunction direction(schema: ModelSchema, op: string, at: string, value: unknown): string {\n if (value === \"asc\" || value === \"desc\") return value;\n\n if (typeof value === \"object\" && value !== null && !Array.isArray(value)) {\n const { sort, nulls } = value as Record<string, unknown>;\n const sorted = direction(schema, op, at, sort);\n\n if (nulls === undefined) return sorted;\n if (nulls !== \"first\" && nulls !== \"last\") {\n throw new UnsupportedQueryError(\n `orderBy.${at}.nulls`,\n schema.name,\n op,\n `Expected 'first' or 'last', got ${JSON.stringify(nulls)}.`,\n );\n }\n return `${sorted} nulls ${nulls}`;\n }\n\n throw new UnsupportedQueryError(\n `orderBy.${at}`,\n schema.name,\n op,\n `Expected 'asc', 'desc', or { sort, nulls }, got ${JSON.stringify(value)}.`,\n );\n}\n\nfunction assertArgs(schema: ModelSchema, op: string, args: any): void {\n if (args === undefined || args === null || typeof args !== \"object\") {\n throw new UnsupportedQueryError(\n \"by\",\n schema.name,\n op,\n `groupBy requires 'by'.`,\n );\n }\n\n for (const key of Object.keys(args).sort()) {\n if (args[key] === undefined) continue;\n if (GROUP_BY_ARGS.has(key)) continue;\n // The same wording `read.ts` uses for an argument an operation does not\n // take, and for the reason #61's second half gives: this is the path a\n // typo arrives on, so naming the set is the whole of the answer.\n throw new UnsupportedQueryError(\n key,\n schema.name,\n op,\n `${op} takes ${[...GROUP_BY_ARGS].sort().join(\", \")}.`,\n );\n }\n\n if (args.by === undefined) {\n throw new UnsupportedQueryError(\n \"by\",\n schema.name,\n op,\n `groupBy requires 'by'.`,\n );\n }\n}\n",
@@ -31,7 +31,7 @@
31
31
  "import { UnsupportedQueryError } from \"./errors\";\nimport type { ModelPolicy } from \"./policy\";\n\n/**\n * Soft deletes, as a policy.\n *\n * This ships as a small built-in because it is the proof that the policy hook is\n * expressive enough to be worth having: hiding deleted rows from *every* read\n * including nested ones, and turning a `delete` into an `update`, is the thing\n * ORMs traditionally implement as a special case threaded through the query\n * builder. Here it is thirty lines against the same `ModelPolicy` interface an\n * application writes, with no privileged access to anything.\n *\n * Usage — `deletedAt` must be a nullable `DateTime` on the model:\n *\n * export class User extends UserModel {\n * static $policies = [softDeletes<typeof User>()]\n * }\n *\n * `typeof User` rather than `User`: the class carries `$schema`, which is what\n * constrains `field` to real columns (#262). The instance spelling still\n * compiles and simply checks nothing.\n *\n * await User.findMany({}) // deleted rows are not there\n * await User.expire({ where }) // sets deletedAt, does not remove the row\n *\n * **`User.delete()` is still a hard delete**, and cannot be made otherwise —\n * see the note on #263 above `softDelete` below. The policy scopes reads; it is\n * the wrapper that rewrites a write, and the wrapper cannot be named `delete`.\n *\n * Composing it with a policy of your own is now just a longer list, in the order\n * they should apply:\n *\n * static $policies = [softDeletes<typeof User>(), new TenantPolicy()]\n *\n * That ordering is the author's, and within a class it is the array's. Across\n * classes `policiesFor` still walks base to derived, so a `$policies` on a\n * shared base is applied before a subclass's and can only be narrowed further.\n *\n * It stays a **factory** rather than a class because it takes configuration and\n * a model type parameter, and a bare constructor in a `$policies` array has\n * nowhere to put either. `PolicyEntry` accepts both forms for exactly this\n * reason.\n */\n\n/**\n * The column names a model *class* declares, read off its generated `$schema`.\n *\n * This is the part of #262 that made it worth doing. The old constraint was\n * `keyof M & string` against an **instance** type, which is not a column check:\n * `softDeletes<User>({ field: \"save\" })` compiled clean and then raised\n * `UnknownFieldError` at runtime, because `save` is a method. Reading\n * `$schema.fields` instead asks the schema what the columns are, so the check\n * and the runtime error now disagree about nothing.\n *\n * It works because the generator emits `satisfies ModelSchema` rather than a\n * `: ModelSchema` annotation — see `bin/orm/emit.ts`. An annotation would widen\n * `fields` to `Record<string, FieldSchema>` and `keyof` it back to `string`.\n *\n * **Falls back to `string` rather than to `never`.** A caller can pass anything\n * that behaves like a model — the structural fakes in `soft-deletes.test.ts` do\n * — and those carry no literal schema. Degrading to unchecked keeps them\n * working; degrading to `never` would reject every `field` they pass.\n */\nexport type SchemaFields<M> = M extends { $schema: { fields: infer F } }\n ? Extract<keyof F, string> extends never\n ? string\n : Extract<keyof F, string>\n : string;\n\n/**\n * The row a model class describes, so one type parameter can carry both.\n *\n * `softDeletes` hands its parameter to `ModelPolicy`, which uses it as the\n * **row** type — `redact` is called with a `Partial` of it. The schema, though,\n * hangs off the *class*. Taking the class and recovering the row through\n * `prototype` is what lets one spelling supply both, and it is the mechanism\n * #243 found and recorded rather than a new invention.\n *\n * An instance type has no `prototype`, so `softDeletes<User>()` still resolves\n * to `User` and keeps compiling — it simply gets no field checking, because an\n * instance type is not where the column names live.\n */\ntype RowOf<M> = M extends { prototype: infer Row } ? Row : M;\n\n/**\n * **The parameter is still the model type, not the field union.**\n *\n * `SoftDeleteOptions` is exported, so an application can annotate with it —\n * `const opts: SoftDeleteOptions<User> = …`. Constraining the parameter to\n * `extends string` and taking the union directly read more honestly from inside\n * this file and broke every such annotation from outside it, with *\"Type 'User'\n * does not satisfy the constraint 'string'\"*. Keeping the model type and\n * resolving the union here costs nothing and keeps those compiling: a row type\n * has no `$schema`, so it degrades to `string` exactly as it did before, and\n * `SoftDeleteOptions<typeof User>` is the spelling that gains the check.\n */\nexport interface SoftDeleteOptions<M = any> {\n /**\n * The timestamp column. Defaults to `deletedAt`, which the template uses.\n *\n * Constrained to the model's **schema fields** when the model is reachable —\n * `softDeletes<typeof User>()`, `softDelete(User)`, `softDeleteMany(User)` —\n * so a typo, or a column the model does not have, is a compile error instead\n * of an `UnknownFieldError` on the first read.\n *\n * Passing no model leaves it `string`, and therefore unchecked. That is the\n * one spelling that cannot be constrained: there is nothing to constrain it\n * against.\n */\n field?: SchemaFields<M>;\n}\n\n/**\n * The read half: every query is scoped to rows whose delete timestamp is null.\n *\n * It applies to nested relation reads for the same reason every policy does —\n * a relation read is `$exec` on the related model — which is the half that\n * ORM-level soft deletes usually get wrong. A deleted `Account` does not appear\n * under `User.findMany({ include: { accounts: true } })` without anything being\n * written at the include site.\n */\nexport function softDeletes<M = any>(\n options: SoftDeleteOptions<M> = {},\n): ModelPolicy<any, any, RowOf<M>> {\n const field = options.field ?? \"deletedAt\";\n\n return {\n scope: () => ({ [field]: null }),\n\n // A soft-deleted model still creates ordinary rows; the column is left to\n // its own default (null). Present because a policy carrying `scope` with no\n // `onCreate` is refused — deliberately, since for a tenant scope that\n // combination is a half-written policy. Here the pass-through *is* the\n // correct behaviour, so it is stated rather than implied.\n onCreate: (_context, data) => data,\n\n // The same statement for updates, and here it is doing real work rather than\n // satisfying a formality. This policy scopes on `deletedAt`, and\n // `softDelete()` below turns a delete into an update that *writes*\n // `deletedAt` — which is precisely the \"an update moves a row out of the\n // scope that selected it\" shape `ScopeEscapeError` refuses. It is also\n // exactly what soft deleting means, so this policy is the one that gets to\n // say the write is intended.\n //\n // Note it does not authorise anything else: the guard is per policy, so a\n // tenant policy sitting beside this one in `$policies` still has to answer\n // for its own column. That separation is the point of the per-policy check.\n onUpdate: (_context, data) => data,\n };\n}\n\n/**\n * What `softDelete` needs from the model it wraps: the write to delegate to,\n * and the schema to name in a refusal.\n *\n * Structural rather than `typeof Model`, so a caller can pass anything that\n * behaves like one — which is why `$schema` is optional here even though every\n * generated model has it.\n */\ntype SoftDeletable<T, Op extends string> = {\n [K in Op]: (args: any) => Promise<T>;\n} & { $schema?: { name: string } };\n\n/**\n * The write half: rewrites a `delete` into an `update` that sets the timestamp.\n *\n * Kept separate from `softDeletes()` and applied at the call site rather than\n * folded into the policy, because a policy rewrites *arguments* and this\n * changes the *operation* — and `$exec` dispatches on the operation before a\n * policy is consulted. Widening `ModelPolicy` to let a policy swap the\n * operation would make every `$exec` call's meaning depend on a hook, which is\n * a much larger claim than scoping a `where`.\n *\n * export class User extends UserModel {\n * static $policies = [softDeletes<typeof User>()]\n * static expire = softDelete(User)\n * static expireMany = softDeleteMany(User)\n * }\n *\n * **The name is not `delete`, and cannot be** — the reason is below.\n * `User.delete()` stays a hard delete.\n *\n * Both return the row(s) the way the real operations do, and both are still\n * subject to the model's policies, because they go through `update` /\n * `updateMany` — which means the soft-delete scope applies and a\n * `expire({ where })` naming an already-deleted row finds nothing, exactly as\n * a hard delete of a missing row would.\n *\n * Why this does not return the generated `delete`'s own signature — #263.\n *\n * `static delete = softDelete(User)` is the recipe the docs used to teach, and\n * it does not type-check. The obvious repair is to have this return the model's\n * own `delete` type so the override is assignable to what it overrides. That\n * cannot work, and the reason is the language rather than the typing:\n *\n * static delete = softDelete(User)\n * // ^ the type of this member would be read off `User`...\n * // ^ ...whose `delete` is the member being defined\n *\n * TypeScript answers `TS7022: 'delete' implicitly has type 'any' because it\n * does not have a type annotation and is referenced directly or indirectly in\n * its own initializer.` Annotating it does not help either: the annotation has\n * to name `typeof UserModel.delete`, and `softDelete(User)` is then checked\n * against a generic signature it still cannot satisfy.\n *\n * Passing the *base* instead of the subclass would break the cycle and break\n * the feature: `softDelete` delegates to `model.update`, policies are resolved\n * per registered class, and `UserModel` carries none — so the soft-delete scope\n * would not apply and `delete` would hide rows it never filtered.\n *\n * So the recipe changed instead of the types, and `delete` stays a hard delete.\n * `docs/orm.md` says so in the words a reader needs, and\n * `soft-delete.test-d.ts` holds the documented snippet verbatim so it cannot\n * drift back.\n \n */\nexport function softDelete<T, M = any>(\n model: SoftDeletable<T, \"update\"> & M,\n options: SoftDeleteOptions<M> = {},\n): (args: any) => Promise<T> {\n const field = options.field ?? \"deletedAt\";\n\n return (args: any) => {\n assertNoData(model, args, \"delete\");\n return model.update({\n ...args,\n data: { [field]: new Date() },\n });\n };\n}\n\nexport function softDeleteMany<T, M = any>(\n model: SoftDeletable<T, \"updateMany\"> & M,\n options: SoftDeleteOptions<M> = {},\n): (args: any) => Promise<T> {\n const field = options.field ?? \"deletedAt\";\n\n return (args: any = {}) => {\n assertNoData(model, args, \"deleteMany\");\n return model.updateMany({\n ...args,\n data: { [field]: new Date() },\n });\n };\n}\n\n/**\n * A `delete` takes no `data`, so one being present means the caller thinks they\n * are calling something else — most likely they wrote `update` and meant it.\n * Refused rather than silently overwritten by the timestamp.\n */\nfunction assertNoData(\n model: { $schema?: { name: string } },\n args: any,\n operation: string,\n): void {\n if (args?.data === undefined) return;\n\n throw new UnsupportedQueryError(\n \"data\",\n // The real model, not the literal `\"soft delete\"` this used to pass.\n // `UnsupportedQueryError` documents `model` as inspectable, and a string\n // that is not a model name can never be what an application matches on\n // (#112). `$schema` is optional only because the parameter is structural —\n // every generated model carries it.\n model.$schema?.name ?? \"unknown\",\n operation,\n `${operation} takes no 'data' — the soft-delete rewrite supplies it. ` +\n `Call update directly if you meant to change other fields at the same ` +\n `time.`,\n );\n}\n",
32
32
  "/**\n * `take` / `skip` built from a request, so that a query string cannot produce a\n * value the compiler refuses.\n *\n * **This file is not `compile/paginate.ts`, and the two do opposite jobs.** That\n * one is the compiler's *validator*: `assertPageArgument` refuses a `take` or a\n * `skip` that is not an integer, and its note explains at length why refusing is\n * the only honest answer — a fraction is an opaque `SQLITE_MISMATCH` on one\n * dialect and a silent disagreement with both Prisma and the other dialect on\n * the second. Read that note (`compile/paginate.ts:9-63`) for the reasoning; it\n * is not restated here.\n *\n * This file is the other half, and the half that was missing. A refusal is only\n * useful if the correct spelling is available and short — otherwise the fix a\n * caller reaches for is `Math.floor` sprinkled at whichever call site happened\n * to throw, which fixes one of them. `paginate` is the shorter spelling:\n *\n * const { take, skip } = paginate({\n * page: req.search.get(\"page\"),\n * perPage: req.search.get(\"perPage\"),\n * })\n * await Post.findMany({ take, skip, orderBy: { createdAt: \"desc\" } })\n *\n * against the shape gemi's own documentation used to teach, which breaks:\n *\n * const limit = Number(req.search.get(\"limit\")) || 25 // ?limit=1.5\n *\n * **Why the arguments are `unknown` and not `number`.** A query string is where\n * these values come from — that is the entire point of the helper, and typing\n * them as `number` would mean every caller writes the `Number(...)` that is the\n * bug. `req.search.get` hands back `string | string[]` (`http/HttpRequest.ts:211-223`\n * collects repeated keys into an array), a JSON body hands back whatever was\n * sent, and both arrive here unconverted.\n *\n * **The coercions, measured rather than assumed.** Each of these is a shape a\n * real query string produces, and each one is why the rules below are not simply\n * `Number(...)`:\n *\n * Number(\"\") 0 `?perPage=` — a form's blank field\n * Number(\" \") 0 the same, url-encoded\n * Number(null) 0 an absent key read off a plain object\n * Number([\"2\"]) 2 a single repeated key\n * Number([\"1\",\"2\"]) NaN two of them — so `Number` honours a\n * repeated param sometimes and not others\n * Number(\"1e400\") Infinity not a number `Math.trunc` can fix\n * Number(true) 1\n *\n * The `0`s are the dangerous ones. `page: 0` computes `skip: -25`, and\n * `assertPageArgument` refuses a negative `skip` outright — so a blank field in\n * a form is a 500. `perPage: 0` is worse, because it is *not* refused: `take: 0`\n * is a perfectly good integer and returns an empty page for ever.\n *\n * So an empty or blank string means **absent**, not zero, and anything that is\n * not a number or a string is absent too. Coercing a boolean or a one-element\n * array would be honouring input no HTTP surface can actually send, at the cost\n * of the rule being explainable.\n *\n * **Why `skip` is capped.** `?page=1e300` is finite, so it survives every check\n * above and multiplies out to a `skip` of `2.5e301`. Measured through Bun\n * against SQLite, binding an offset past int64:\n *\n * offset 1e18 -> ok\n * offset 9223372036854775807 -> SQLiteError: datatype mismatch\n * offset 1e20 -> SQLiteError: datatype mismatch\n *\n * — the same `SQLITE_MISMATCH` the fractional-`take` note records, reached from\n * the other end. The cap is `Number.MAX_SAFE_INTEGER` rather than int64's\n * ceiling: it is well inside what both drivers bind, it needs no per-dialect\n * measurement, and above it JavaScript's own arithmetic stops being exact, so a\n * number past it was never a page anybody could count to.\n *\n * **The guarantee, which is the whole contract:** every return value is a pair\n * of integers with `take >= 1` and `skip >= 0`, for every input. It is therefore\n * impossible for `paginate`'s output to be something `assertPageArgument`\n * refuses, and `page-args.test.ts` asserts exactly that by running the validator\n * over the output of a table of hostile query-string values rather than by\n * re-checking the arithmetic.\n */\n\n/**\n * The default page size, and it is not an invented number: `docs/controllers.md`\n * and `docs/routing.md` both taught `Number(req.search.get(\"limit\")) || 25`. The\n * helper replaces those examples, and picking a different default would silently\n * change the page size of every call site rewritten onto it.\n */\nconst DEFAULT_PER_PAGE = 25;\n\n/**\n * The ceiling on a *request-supplied* page size. Its job is that `?perPage=100000`\n * cannot ask for the whole table — one request that reads a million rows into\n * memory is a denial of service the caller did not have to authenticate for.\n *\n * A hundred rather than \"no ceiling at all\", because a helper whose ceiling is\n * opt-in has no ceiling in the code that most needs one. An endpoint that\n * genuinely serves larger pages says so at the call site — `paginate(args,\n * { maxPerPage: 500 })` — which is one visible decision instead of an invisible\n * default.\n */\nconst DEFAULT_MAX_PER_PAGE = 100;\n\n/**\n * See the cap discussion above. Exported so the test can assert the boundary\n * against the same constant the implementation clamps to, rather than repeating\n * the literal and agreeing with itself.\n */\nexport const MAX_SKIP = Number.MAX_SAFE_INTEGER;\n\n/**\n * A query-string value as a whole number, or `null` for \"absent\".\n *\n * `null` rather than a default, so the two callers below can apply *their* own\n * default — the page defaults to 1 and the size defaults to `perPage`, and\n * folding that in here would mean one of them lying about which.\n */\nfunction toWholeNumber(value: unknown): number | null {\n if (typeof value === \"string\") {\n // Measured above: `Number(\"\")` is 0. `?perPage=` is what a browser sends\n // for a blank field, and reading it as zero rather than as absent is how a\n // cleared filter box becomes an empty page.\n if (value.trim() === \"\") return null;\n } else if (typeof value !== \"number\") {\n // Arrays, objects, booleans, `null`, `undefined`. Every one of them has a\n // `Number()` answer and not one of them has a *meaning* — see the table.\n return null;\n }\n\n const parsed = Number(value);\n // Catches `NaN` and both infinities in one test, which is what `Math.trunc`\n // cannot do: `Math.trunc(Infinity)` is `Infinity`, and `Number.isInteger`\n // then says false, so an untruncatable value would reach the compiler and be\n // refused there — by this helper, which exists so that cannot happen.\n if (!Number.isFinite(parsed)) return null;\n\n // Toward zero, which is what Prisma does with a fractional `take` (measured\n // in `compile/paginate.ts`). Matching it means a caller who moves off Prisma\n // keeps the same page, rather than trading a crash for a different answer.\n return Math.trunc(parsed);\n}\n\nconst clamp = (value: number, low: number, high: number) =>\n Math.min(Math.max(value, low), high);\n\n/**\n * Turn `{ page, perPage }` — as read off a query string, in whatever state the\n * client left them — into a `take` / `skip` pair the ORM accepts.\n *\n * paginate({ page: \"2\" }) { take: 25, skip: 25 }\n * paginate({ page: \"2.5\" }) { take: 25, skip: 25 }\n * paginate({ page: \"0\" }) { take: 25, skip: 0 }\n * paginate({ page: \"abc\" }) { take: 25, skip: 0 }\n * paginate({ perPage: \"1000\" }) { take: 100, skip: 0 }\n * paginate({ perPage: \"10\" }, { maxPerPage: 5 }) { take: 5, skip: 0 }\n */\nexport function paginate(\n args: { page?: unknown; perPage?: unknown },\n options: {\n /** The page size when the request does not name one. Default 25. */\n perPage?: number;\n /** The largest page size a *request* may ask for. Default 100. */\n maxPerPage?: number;\n } = {},\n): { take: number; skip: number } {\n // The options are code rather than user input, so it is tempting to trust\n // them. They are clamped anyway, because the guarantee this function makes is\n // unconditional — `paginate(args, { perPage: 0 })` returning `take: 0` would\n // be an empty page for ever, with the helper's own name on it.\n //\n // `Infinity` is honoured rather than rejected, and it is the one place the\n // options are read differently from the arguments. `toWholeNumber` refuses a\n // non-finite value because that rule is about hostile input — `?perPage=1e400`\n // is `Infinity`, and binding it as a `take` is not a page size. Reusing the\n // same rule here made `{ maxPerPage: Infinity }`, the natural spelling of \"no\n // ceiling\", fall back to the default 100 instead: an internal export written\n // to opt out of the cap silently got it back, returned a plausible first page,\n // and was found when somebody noticed 900 rows missing. The caller who writes\n // `Infinity` here is the application, saying so deliberately.\n const maxPerPage =\n options.maxPerPage === Infinity\n ? Infinity\n : Math.max(1, toWholeNumber(options.maxPerPage) ?? DEFAULT_MAX_PER_PAGE);\n const fallback = clamp(\n toWholeNumber(options.perPage) ?? DEFAULT_PER_PAGE,\n 1,\n maxPerPage,\n );\n\n const perPage = clamp(toWholeNumber(args?.perPage) ?? fallback, 1, maxPerPage);\n\n // Page 1 is the first page, and there is no page 0 — a `page` below 1 is\n // clamped up rather than refused, because the values that land there are\n // `\"\"`, `\"0\"` and `\"-1\"`, and none of them is a request for a page that does\n // not exist. Refusing would put a 500 on a link somebody edited by hand.\n const page = Math.max(toWholeNumber(args?.page) ?? 1, 1);\n\n // Clamped after multiplying rather than by bounding `page` first: the product\n // is the thing that has to stay exact, and `page` alone cannot be bounded\n // without knowing `perPage` anyway.\n const skip = Math.min((page - 1) * perPage, MAX_SKIP);\n\n return { take: perPage, skip };\n}\n"
33
33
  ],
34
- "mappings": ";+iCAgDO,IAAS,HAAS,JACvB,HACA,HACA,HAEA,HAEA,HAKA,EACY,CACZ,IAAM,EAAQ,EAAc,EAAQ,CAAQ,EAItC,EAAO,GAAY,EAAQ,EAAO,EAAU,CAAS,EAErD,EAAS,EAAQ,WAAW,CAAK,EACjC,EAAY,GAAG,KAUf,EAAc,EAAK,aACtB,IAAI,CAAC,EAAa,IAAU,CAC3B,IAAM,EAAW,GAAG,IAAY,EAAQ,WACtC,GAAO,EAAO,EAAU,EAAK,YAAY,EAAM,CACjD,IACM,EAAY,GAAG,IAAkB,EAAQ,WAC7C,GAAO,EAAQ,EAAU,CAAW,CACtC,IACA,MAAO,GAAG,OAAc,IACzB,EACA,KAAK,OAAO,EAEf,GAAI,CAAC,EAAK,KACR,MAAO,CACL,QACA,OAAQ,GAAG,EAAQ,WAAW,EAAM,KAAK,QAAQ,IACjD,cACA,WACF,EAKF,IAAM,EAAW,GAAG,IAAY,EAAQ,WACtC,GAAO,EAAO,EAAU,EAAK,YAAY,EAAE,CAC7C,IACM,EAAY,GAAG,IAAkB,EAAQ,WAC7C,GAAO,EAAQ,EAAU,EAAK,aAAa,EAAE,CAC/C,IAIM,EAAY,EAAQ,WAAW,GAAG,IAAQ,EAEhD,MAAO,CACL,QACA,OACE,GAAG,EAAQ,WAAW,EAAM,KAAK,QAAQ,UACjC,EAAQ,WAAW,EAAK,KAAK,KAAK,QAAQ,QAC5C,KAAa,EAAQ,WAAW,EAAK,KAAK,WAAW,OAAO,IACpE,YAAa,GAAG,KAAa,EAAQ,WAAW,EAAK,KAAK,YAAY,OAAO,IAC7E,WACF,EAGF,SAAS,EAAM,CACb,EACA,EACA,EACQ,CACR,IAAM,EAAQ,EA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