{"version":3,"file":"verify-mongo-schema-mSoRJYt-.mjs","names":["MongoSchemaIRCtor","MongoSchemaCollectionCtor","MongoSchemaIndexCtor","MongoSchemaCollectionOptionsCtor"],"sources":["../src/core/contract-to-schema.ts","../src/core/schema-verify/verifier-disposition.ts","../src/core/schema-diff.ts","../src/core/schema-verify/canonicalize-introspection.ts","../src/core/schema-verify/verify-mongo-schema.ts"],"sourcesContent":["import type {\n  MongoCollection,\n  MongoCollectionOptions,\n  MongoContract,\n  MongoIndex,\n  MongoValidator,\n} from '@prisma-next/mongo-contract';\nimport {\n  MongoSchemaCollection,\n  MongoSchemaCollectionOptions,\n  MongoSchemaIndex,\n  MongoSchemaIR,\n  MongoSchemaValidator,\n} from '@prisma-next/mongo-schema-ir';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\nfunction convertIndex(index: MongoIndex): MongoSchemaIndex {\n  return new MongoSchemaIndex({\n    keys: index.keys,\n    unique: index.unique,\n    sparse: index.sparse,\n    expireAfterSeconds: index.expireAfterSeconds,\n    partialFilterExpression: index.partialFilterExpression,\n    wildcardProjection: index.wildcardProjection,\n    collation: index.collation,\n    weights: index.weights,\n    default_language: index.default_language,\n    language_override: index.language_override,\n  });\n}\n\nfunction convertValidator(v: MongoValidator): MongoSchemaValidator {\n  return new MongoSchemaValidator({\n    jsonSchema: v.jsonSchema,\n    validationLevel: v.validationLevel,\n    validationAction: v.validationAction,\n  });\n}\n\nfunction convertOptions(o: MongoCollectionOptions): MongoSchemaCollectionOptions {\n  return new MongoSchemaCollectionOptions({\n    ...ifDefined(\n      'capped',\n      o.capped !== undefined\n        ? { size: o.capped.size, ...ifDefined('max', o.capped.max) }\n        : undefined,\n    ),\n    ...(o.timeseries !== undefined\n      ? {\n          timeseries: {\n            timeField: o.timeseries.timeField,\n            ...ifDefined('metaField', o.timeseries.metaField),\n            ...ifDefined('granularity', o.timeseries.granularity),\n          },\n        }\n      : {}),\n    ...(o.collation !== undefined\n      ? {\n          collation: {\n            locale: o.collation.locale,\n            ...ifDefined('caseLevel', o.collation.caseLevel),\n            ...ifDefined('caseFirst', o.collation.caseFirst),\n            ...ifDefined('strength', o.collation.strength),\n            ...ifDefined('numericOrdering', o.collation.numericOrdering),\n            ...ifDefined('alternate', o.collation.alternate),\n            ...ifDefined('maxVariable', o.collation.maxVariable),\n            ...ifDefined('backwards', o.collation.backwards),\n            ...ifDefined('normalization', o.collation.normalization),\n          },\n        }\n      : {}),\n    ...ifDefined(\n      'changeStreamPreAndPostImages',\n      o.changeStreamPreAndPostImages !== undefined\n        ? { enabled: o.changeStreamPreAndPostImages.enabled }\n        : undefined,\n    ),\n    ...ifDefined('clusteredIndex', o.clusteredIndex),\n  });\n}\n\nfunction convertCollection(name: string, def: MongoCollection): MongoSchemaCollection {\n  const indexes = (def.indexes ?? []).map(convertIndex);\n  return new MongoSchemaCollection({\n    name,\n    indexes,\n    ...ifDefined('validator', def.validator != null ? convertValidator(def.validator) : undefined),\n    ...ifDefined('options', def.options != null ? convertOptions(def.options) : undefined),\n  });\n}\n\nexport function contractToMongoSchemaIR(contract: MongoContract | null): MongoSchemaIR {\n  if (!contract) {\n    return new MongoSchemaIR([]);\n  }\n\n  const collections: MongoSchemaCollection[] = [];\n  for (const ns of Object.values(contract.storage.namespaces)) {\n    for (const [name, def] of Object.entries(ns.entries.collection ?? {})) {\n      collections.push(convertCollection(name, def));\n    }\n  }\n\n  return new MongoSchemaIR(collections);\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport type {\n  SchemaDiffIssue,\n  VerifierIssueCategory,\n  VerifierOutcome,\n} from '@prisma-next/framework-components/control';\nimport { dispositionForCategory, issueOutcome } from '@prisma-next/framework-components/control';\n\n/**\n * Classifies a Mongo schema-diff issue into the target-neutral categories the\n * framework grades. Mongo issues carry their coordinate as `path`\n * (`[collectionName]` for a whole collection, `[collectionName, auxiliary]`\n * for an index/validator/options finding), so a `not-expected` issue at\n * depth 1 is an undeclared whole collection and anything deeper is an\n * undeclared auxiliary. Mongo owns this mapping rather than importing the\n * SQL classifier — the two families share only the framework's category\n * grading.\n */\nexport function classifyMongoDiffIssue(issue: SchemaDiffIssue): VerifierIssueCategory {\n  if (issueOutcome(issue) === 'not-found') {\n    return 'declaredMissing';\n  }\n  if (issueOutcome(issue) === 'not-expected') {\n    return issue.path.length <= 1 ? 'extraTopLevelObject' : 'extraAuxiliary';\n  }\n  return 'declaredIncompatible';\n}\n\nexport function verifierDisposition(\n  controlPolicy: ControlPolicy,\n  issue: SchemaDiffIssue,\n): VerifierOutcome {\n  return dispositionForCategory(controlPolicy, classifyMongoDiffIssue(issue));\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport type { SchemaDiffIssue, VerifierOutcome } from '@prisma-next/framework-components/control';\nimport type {\n  MongoSchemaCollection,\n  MongoSchemaIndex,\n  MongoSchemaIR,\n} from '@prisma-next/mongo-schema-ir';\nimport { canonicalize, deepEqual } from '@prisma-next/mongo-schema-ir';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { verifierDisposition } from './schema-verify/verifier-disposition';\n\n/**\n * The Mongo schema diff, issue-only: `failures` carry the verdict (a verify\n * passes exactly when it is empty), `warnings` the surviving warn-graded\n * findings (live-only extras in non-strict mode, `observed` subjects).\n *\n * Each issue's `path` carries the coordinate — `[collectionName]` for a\n * whole-collection finding, `[collectionName, 'index:…' | 'validator' |\n * 'options']` for an auxiliary — and `expected`/`actual` carry the real\n * Mongo schema-IR node the finding concerns.\n */\nexport interface MongoSchemaDiff {\n  readonly failures: readonly SchemaDiffIssue[];\n  readonly warnings: readonly SchemaDiffIssue[];\n}\n\n/**\n * Reconciles a control-policy disposition with the Mongo family's strict-mode\n * contract for live-only extras — the single point where `strict` and the\n * control policy meet.\n *\n * The control policy decides first; only a `fail` is reconciled against the\n * caller's base outcome. Call sites grade a live-only extra with\n * `strict ? 'fail' : 'warn'` and a declared missing/mismatch with `fail`, so\n * this one step encodes the whole matrix:\n *\n * | live-vs-declared                    | strict   | non-strict |\n * |-------------------------------------|----------|------------|\n * | declared missing / mismatch         | fail     | fail       |\n * | live-only extra (managed/tolerated) | fail     | warn       |\n * | live-only extra (external)          | suppress (extras ignored, both modes) |\n * | anything (observed)                 | warn (both modes)     |\n *\n * `tolerated` does not diverge from `managed` on a non-strict extra index:\n * both soften to `warn`, because the softening comes from the base outcome the\n * caller already computed from `strict`, not from per-policy special-casing.\n */\nfunction emitMongoIssueUnderControlPolicy(\n  controlPolicy: ControlPolicy,\n  issue: SchemaDiffIssue,\n  baseOutcome: 'fail' | 'warn',\n  failures: SchemaDiffIssue[],\n  warnings: SchemaDiffIssue[],\n): VerifierOutcome {\n  const disposition = verifierDisposition(controlPolicy, issue);\n  const outcome = disposition === 'fail' ? baseOutcome : disposition;\n  if (outcome === 'suppress') {\n    return 'suppress';\n  }\n  if (outcome === 'warn') {\n    warnings.push(issue);\n  } else {\n    failures.push(issue);\n  }\n  return outcome;\n}\n\nexport function diffMongoSchemas(\n  live: MongoSchemaIR,\n  expected: MongoSchemaIR,\n  strict: boolean,\n  collectionControlPolicy: (collectionName: string) => ControlPolicy,\n): MongoSchemaDiff {\n  const failures: SchemaDiffIssue[] = [];\n  const warnings: SchemaDiffIssue[] = [];\n\n  const allNames = new Set([...live.collectionNames, ...expected.collectionNames]);\n\n  for (const name of [...allNames].sort()) {\n    const liveColl = live.collection(name);\n    const expectedColl = expected.collection(name);\n\n    if (!liveColl && expectedColl) {\n      emitMongoIssueUnderControlPolicy(\n        collectionControlPolicy(name),\n        {\n          path: [name],\n          expected: expectedColl,\n        },\n        'fail',\n        failures,\n        warnings,\n      );\n      continue;\n    }\n\n    if (liveColl && !expectedColl) {\n      emitMongoIssueUnderControlPolicy(\n        collectionControlPolicy(name),\n        {\n          path: [name],\n          actual: liveColl,\n        },\n        strict ? 'fail' : 'warn',\n        failures,\n        warnings,\n      );\n      continue;\n    }\n\n    const lc = liveColl as MongoSchemaCollection;\n    const ec = expectedColl as MongoSchemaCollection;\n    const controlPolicy = collectionControlPolicy(name);\n    diffIndexes(name, lc, ec, strict, controlPolicy, failures, warnings);\n    diffValidator(name, lc, ec, strict, controlPolicy, failures, warnings);\n    diffOptions(name, lc, ec, strict, controlPolicy, failures, warnings);\n  }\n\n  return { failures, warnings };\n}\n\nfunction buildIndexLookupKey(index: MongoSchemaIndex): string {\n  const keys = index.keys.map((k) => `${k.field}:${k.direction}`).join(',');\n  const opts = [\n    index.unique ? 'unique' : '',\n    index.sparse ? 'sparse' : '',\n    index.expireAfterSeconds != null ? `ttl:${index.expireAfterSeconds}` : '',\n    index.partialFilterExpression ? `pfe:${canonicalize(index.partialFilterExpression)}` : '',\n    index.wildcardProjection ? `wp:${canonicalize(index.wildcardProjection)}` : '',\n    index.collation ? `col:${canonicalize(index.collation)}` : '',\n    index.weights ? `wt:${canonicalize(index.weights)}` : '',\n    index.default_language ? `dl:${index.default_language}` : '',\n    index.language_override ? `lo:${index.language_override}` : '',\n  ]\n    .filter(Boolean)\n    .join(';');\n  return opts ? `${keys}|${opts}` : keys;\n}\n\nfunction formatIndexName(index: MongoSchemaIndex): string {\n  return index.keys.map((k) => `${k.field}:${k.direction}`).join(', ');\n}\n\nfunction diffIndexes(\n  collName: string,\n  live: MongoSchemaCollection,\n  expected: MongoSchemaCollection,\n  strict: boolean,\n  collectionControlPolicy: ControlPolicy,\n  failures: SchemaDiffIssue[],\n  warnings: SchemaDiffIssue[],\n): void {\n  const liveLookup = new Map<string, MongoSchemaIndex>();\n  for (const idx of live.indexes) liveLookup.set(buildIndexLookupKey(idx), idx);\n\n  const expectedLookup = new Map<string, MongoSchemaIndex>();\n  for (const idx of expected.indexes) expectedLookup.set(buildIndexLookupKey(idx), idx);\n\n  for (const [key, idx] of expectedLookup) {\n    if (!liveLookup.has(key)) {\n      emitMongoIssueUnderControlPolicy(\n        collectionControlPolicy,\n        {\n          path: [collName, `index:${formatIndexName(idx)}`],\n          expected: idx,\n        },\n        'fail',\n        failures,\n        warnings,\n      );\n    }\n  }\n\n  for (const [key, idx] of liveLookup) {\n    if (!expectedLookup.has(key)) {\n      emitMongoIssueUnderControlPolicy(\n        collectionControlPolicy,\n        {\n          path: [collName, `index:${formatIndexName(idx)}`],\n          actual: idx,\n        },\n        strict ? 'fail' : 'warn',\n        failures,\n        warnings,\n      );\n    }\n  }\n}\n\nfunction diffValidator(\n  collName: string,\n  live: MongoSchemaCollection,\n  expected: MongoSchemaCollection,\n  strict: boolean,\n  collectionControlPolicy: ControlPolicy,\n  failures: SchemaDiffIssue[],\n  warnings: SchemaDiffIssue[],\n): void {\n  if (!live.validator && !expected.validator) return;\n\n  if (expected.validator && !live.validator) {\n    emitMongoIssueUnderControlPolicy(\n      collectionControlPolicy,\n      {\n        path: [collName, 'validator'],\n        expected: expected.validator,\n      },\n      'fail',\n      failures,\n      warnings,\n    );\n    return;\n  }\n\n  if (!expected.validator && live.validator) {\n    emitMongoIssueUnderControlPolicy(\n      collectionControlPolicy,\n      {\n        path: [collName, 'validator'],\n        actual: live.validator,\n      },\n      strict ? 'fail' : 'warn',\n      failures,\n      warnings,\n    );\n    return;\n  }\n\n  const liveVal = live.validator as NonNullable<typeof live.validator>;\n  const expectedVal = expected.validator as NonNullable<typeof expected.validator>;\n  const liveSchema = canonicalize(liveVal.jsonSchema);\n  const expectedSchema = canonicalize(expectedVal.jsonSchema);\n\n  if (\n    liveSchema !== expectedSchema ||\n    liveVal.validationLevel !== expectedVal.validationLevel ||\n    liveVal.validationAction !== expectedVal.validationAction\n  ) {\n    emitMongoIssueUnderControlPolicy(\n      collectionControlPolicy,\n      {\n        path: [collName, 'validator'],\n        expected: expectedVal,\n        actual: liveVal,\n      },\n      'fail',\n      failures,\n      warnings,\n    );\n  }\n}\n\nfunction diffOptions(\n  collName: string,\n  live: MongoSchemaCollection,\n  expected: MongoSchemaCollection,\n  strict: boolean,\n  collectionControlPolicy: ControlPolicy,\n  failures: SchemaDiffIssue[],\n  warnings: SchemaDiffIssue[],\n): void {\n  if (!live.options && !expected.options) return;\n\n  if (!expected.options && live.options) {\n    emitMongoIssueUnderControlPolicy(\n      collectionControlPolicy,\n      {\n        path: [collName, 'options'],\n        actual: live.options,\n      },\n      strict ? 'fail' : 'warn',\n      failures,\n      warnings,\n    );\n    return;\n  }\n\n  if (deepEqual(live.options, expected.options)) {\n    return;\n  }\n\n  emitMongoIssueUnderControlPolicy(\n    collectionControlPolicy,\n    {\n      path: [collName, 'options'],\n      ...ifDefined('expected', expected.options),\n      ...ifDefined('actual', live.options),\n    },\n    'fail',\n    failures,\n    warnings,\n  );\n}\n","/**\n * Canonicalizes a live (introspected) `MongoSchemaIR` against the expected\n * (contract-built) IR before diffing. MongoDB applies server-side defaults\n * to several option/index families that are absent from authored contracts,\n * which would otherwise cause `verifyMongoSchema` to report false-positive\n * drift on a fresh `migrate` run.\n *\n * The normalization is contract-aware where it has to be: server defaults\n * are stripped from the live IR for fields the contract did not specify, so\n * a contract that *does* specify a value still gets compared faithfully.\n *\n * Symmetric defaults — like `changeStreamPreAndPostImages: { enabled: false }`,\n * which is equivalent to \"absent\" on both sides — are stripped from both IRs\n * so either authoring style verifies.\n */\n\nimport type {\n  MongoSchemaCollection,\n  MongoSchemaCollectionOptions,\n  MongoSchemaIndex,\n  MongoSchemaIR,\n} from '@prisma-next/mongo-schema-ir';\nimport {\n  MongoSchemaCollection as MongoSchemaCollectionCtor,\n  MongoSchemaCollectionOptions as MongoSchemaCollectionOptionsCtor,\n  MongoSchemaIndex as MongoSchemaIndexCtor,\n  MongoSchemaIR as MongoSchemaIRCtor,\n} from '@prisma-next/mongo-schema-ir';\nimport type { CollationOptions } from '@prisma-next/mongo-value/mongodb-types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\nexport interface CanonicalizedSchemas {\n  readonly live: MongoSchemaIR;\n  readonly expected: MongoSchemaIR;\n}\n\nexport function canonicalizeSchemasForVerification(\n  live: MongoSchemaIR,\n  expected: MongoSchemaIR,\n): CanonicalizedSchemas {\n  const expectedByName = new Map<string, MongoSchemaCollection>();\n  for (const c of expected.collections) expectedByName.set(c.name, c);\n\n  const liveByName = new Map<string, MongoSchemaCollection>();\n  for (const c of live.collections) liveByName.set(c.name, c);\n\n  const canonicalLive = live.collections.map((c) =>\n    canonicalizeLiveCollection(c, expectedByName.get(c.name)),\n  );\n  const canonicalExpected = expected.collections.map((c) =>\n    canonicalizeExpectedCollection(c, liveByName.get(c.name)),\n  );\n\n  return {\n    live: new MongoSchemaIRCtor(canonicalLive),\n    expected: new MongoSchemaIRCtor(canonicalExpected),\n  };\n}\n\nfunction canonicalizeLiveCollection(\n  liveColl: MongoSchemaCollection,\n  expectedColl: MongoSchemaCollection | undefined,\n): MongoSchemaCollection {\n  const expectedIndexes = expectedColl?.indexes ?? [];\n  const indexes = liveColl.indexes.map((idx) =>\n    canonicalizeLiveIndex(idx, findExpectedIndexCounterpart(idx, expectedIndexes)),\n  );\n\n  const options = liveColl.options\n    ? canonicalizeLiveOptions(liveColl.options, expectedColl?.options)\n    : undefined;\n\n  return new MongoSchemaCollectionCtor({\n    name: liveColl.name,\n    indexes,\n    ...ifDefined('validator', liveColl.validator),\n    ...ifDefined('options', options),\n  });\n}\n\nfunction canonicalizeExpectedCollection(\n  expectedColl: MongoSchemaCollection,\n  liveColl: MongoSchemaCollection | undefined,\n): MongoSchemaCollection {\n  // Symmetric text-index key ordering: a contract-shaped text index preserves\n  // the user-authored field order, but the introspected counterpart comes\n  // back from MongoDB with `weights` keys in alphabetical order, so we\n  // canonicalize both sides to alphabetical text-key order. The order of\n  // text fields within the text block is semantically irrelevant — relevance\n  // is governed by `weights`, not key order.\n  const indexes = expectedColl.indexes.map(canonicalizeTextIndexKeyOrder);\n\n  const options = expectedColl.options\n    ? canonicalizeExpectedOptions(expectedColl.options, liveColl?.options)\n    : undefined;\n\n  return new MongoSchemaCollectionCtor({\n    name: expectedColl.name,\n    indexes,\n    ...ifDefined('validator', expectedColl.validator),\n    ...ifDefined('options', options),\n  });\n}\n\nfunction canonicalizeTextIndexKeyOrder(index: MongoSchemaIndex): MongoSchemaIndex {\n  const hasTextKey = index.keys.some((k) => k.direction === 'text');\n  if (!hasTextKey) return index;\n  return new MongoSchemaIndexCtor({\n    keys: sortTextKeys(index.keys),\n    unique: index.unique,\n    ...ifDefined('sparse', index.sparse),\n    ...ifDefined('expireAfterSeconds', index.expireAfterSeconds),\n    ...ifDefined('partialFilterExpression', index.partialFilterExpression),\n    ...ifDefined('wildcardProjection', index.wildcardProjection),\n    ...ifDefined('collation', index.collation),\n    ...ifDefined('weights', index.weights),\n    ...ifDefined('default_language', index.default_language),\n    ...ifDefined('language_override', index.language_override),\n  });\n}\n\n/**\n * Returns a copy of `keys` with text-direction entries sorted alphabetically\n * while preserving the relative position of non-text entries. Compound text\n * indexes (`{a: 1, _fts: 'text', _ftsx: 1, b: 1}`) keep their scalar\n * prefix/suffix layout; only the contiguous text block is reordered.\n */\nfunction sortTextKeys(\n  keys: ReadonlyArray<{\n    readonly field: string;\n    readonly direction: 'text' | 1 | -1 | '2dsphere' | '2d' | 'hashed';\n  }>,\n): ReadonlyArray<{\n  readonly field: string;\n  readonly direction: 'text' | 1 | -1 | '2dsphere' | '2d' | 'hashed';\n}> {\n  const textEntries = keys.filter((k) => k.direction === 'text');\n  if (textEntries.length <= 1) return keys;\n  const sortedText = [...textEntries].sort((a, b) => a.field.localeCompare(b.field));\n  let textIdx = 0;\n  return keys.map((k) => {\n    if (k.direction !== 'text') return k;\n    const next = sortedText[textIdx++];\n    /* v8 ignore next 3 -- @preserve invariant guard: textIdx is always < sortedText.length here because we only consume sortedText for text-direction entries and sortedText is built from the same filter. */\n    if (next === undefined) {\n      throw new Error('sortTextKeys: text-key counts mismatched');\n    }\n    return next;\n  });\n}\n\nfunction canonicalizeLiveIndex(\n  liveIndex: MongoSchemaIndex,\n  expectedIndex: MongoSchemaIndex | undefined,\n): MongoSchemaIndex {\n  const projectedKeys = sortTextKeys(projectTextIndexKeys(liveIndex));\n  const collation = liveIndex.collation\n    ? stripCollationFields(liveIndex.collation, expectedIndex?.collation)\n    : liveIndex.collation;\n\n  // Text-index server defaults: when the contract did not set\n  // `weights`/`default_language`/`language_override`, MongoDB applies\n  // `weights = {<field>: 1, ...}` (uniform), `'english'`, and `'language'`\n  // respectively. Strip them from live *only* when the live value matches\n  // those defaults — preserving non-default live values lets the verifier\n  // surface drift when the live index is tampered (e.g. weights tuned\n  // out-of-band, custom `default_language`/`language_override`) even though\n  // the contract authored neither.\n  const weights =\n    expectedIndex?.weights === undefined && hasDefaultTextWeights(projectedKeys, liveIndex.weights)\n      ? undefined\n      : liveIndex.weights;\n  const default_language =\n    expectedIndex?.default_language === undefined && liveIndex.default_language === 'english'\n      ? undefined\n      : liveIndex.default_language;\n  const language_override =\n    expectedIndex?.language_override === undefined && liveIndex.language_override === 'language'\n      ? undefined\n      : liveIndex.language_override;\n\n  return new MongoSchemaIndexCtor({\n    keys: projectedKeys,\n    unique: liveIndex.unique,\n    ...ifDefined('sparse', liveIndex.sparse),\n    ...ifDefined('expireAfterSeconds', liveIndex.expireAfterSeconds),\n    ...ifDefined('partialFilterExpression', liveIndex.partialFilterExpression),\n    ...ifDefined('wildcardProjection', liveIndex.wildcardProjection),\n    ...ifDefined('collation', collation),\n    ...ifDefined('weights', weights),\n    ...ifDefined('default_language', default_language),\n    ...ifDefined('language_override', language_override),\n  });\n}\n\n/**\n * Locate the contract-side index that corresponds to a live index for the\n * purpose of contract-aware normalization. We deliberately match by the\n * *projected* (contract-shaped) key list — so a live `_fts/_ftsx` index\n * resolves to a contract `{title: 'text', body: 'text'}` index — and pick\n * the first match. Contracts very rarely contain duplicate-key indexes; if\n * we have no counterpart we fall back to no normalization for that index.\n */\nfunction findExpectedIndexCounterpart(\n  liveIndex: MongoSchemaIndex,\n  expectedIndexes: ReadonlyArray<MongoSchemaIndex>,\n): MongoSchemaIndex | undefined {\n  const projectedLiveKeys = sortTextKeys(projectTextIndexKeys(liveIndex));\n  const liveKeySig = projectedLiveKeys.map((k) => `${k.field}:${k.direction}`).join(',');\n  for (const expected of expectedIndexes) {\n    const expectedKeySig = sortTextKeys(expected.keys)\n      .map((k) => `${k.field}:${k.direction}`)\n      .join(',');\n    if (expectedKeySig === liveKeySig) return expected;\n  }\n  return undefined;\n}\n\n/**\n * MongoDB expands a contract-shaped text index like\n * `[{title: 'text'}, {body: 'text'}]` into its internal weighted vector\n * representation `[{_fts: 'text'}, {_ftsx: 1}]`. We project back to\n * contract-shaped keys via `weights`, iterating in whatever order MongoDB\n * returns them (alphabetical, in practice). `sortTextKeys` is applied\n * downstream to canonicalize the order on both sides, so this projection\n * does not depend on a specific iteration order.\n */\nfunction projectTextIndexKeys(liveIndex: MongoSchemaIndex): ReadonlyArray<{\n  readonly field: string;\n  readonly direction: 'text' | 1 | -1 | '2dsphere' | '2d' | 'hashed';\n}> {\n  const isTextIndex =\n    liveIndex.keys.length >= 1 &&\n    liveIndex.keys.some((k) => k.field === '_fts' && k.direction === 'text');\n\n  if (!isTextIndex || !liveIndex.weights) return liveIndex.keys;\n\n  const textKeys = Object.keys(liveIndex.weights).map((field) => ({\n    field,\n    direction: 'text' as const,\n  }));\n\n  // Splice the projected text fields into the original `_fts/_ftsx` slot so\n  // compound text indexes that mix scalar prefixes *and* suffixes — e.g.\n  // `[prefix, _fts, _ftsx, suffix]` — keep their original layout. Flattening\n  // scalars first would yield `[prefix, suffix, ...text]`, which `sortTextKeys`\n  // (downstream) cannot recover because it only reorders text-direction\n  // entries within their existing positions. MongoDB always emits exactly one\n  // `_fts`/`_ftsx` pair per index, so we don't need to guard against\n  // duplicates.\n  type IndexKey = (typeof liveIndex.keys)[number];\n  const projectedKeys: IndexKey[] = [];\n  for (const key of liveIndex.keys) {\n    if (key.field === '_ftsx') continue;\n    if (key.field === '_fts') {\n      projectedKeys.push(...textKeys);\n      continue;\n    }\n    projectedKeys.push(key);\n  }\n  return projectedKeys;\n}\n\n/**\n * MongoDB's server-default `weights` for an authored-without-weights text\n * index assigns `1` to every text-direction field. Returns `true` only when\n * `liveWeights` is exactly that uniform shape (every projected text-direction\n * key weighted at `1`) so the canonicalizer leaves non-default weights —\n * including out-of-band relevance tweaks — visible to the verifier.\n *\n * `projectTextIndexKeys` derives text-direction keys from the live weights\n * map, so the count is guaranteed to match; we only have to check the value\n * shape.\n */\nfunction hasDefaultTextWeights(\n  projectedKeys: ReadonlyArray<{\n    readonly field: string;\n    readonly direction: 'text' | 1 | -1 | '2dsphere' | '2d' | 'hashed';\n  }>,\n  liveWeights: MongoSchemaIndex['weights'],\n): boolean {\n  if (liveWeights === undefined) return false;\n  const textFields = projectedKeys.filter((k) => k.direction === 'text').map((k) => k.field);\n  return textFields.every((field) => liveWeights[field] === 1);\n}\n\nfunction canonicalizeLiveOptions(\n  liveOptions: MongoSchemaCollectionOptions,\n  expectedOptions: MongoSchemaCollectionOptions | undefined,\n): MongoSchemaCollectionOptions | undefined {\n  const collation = liveOptions.collation\n    ? stripCollationFields(liveOptions.collation, expectedOptions?.collation)\n    : undefined;\n\n  // Timeseries: drop `bucketMaxSpanSeconds` (and any other server-applied\n  // extras) when the contract did not specify them.\n  const timeseries = liveOptions.timeseries\n    ? (stripUnspecifiedFields(\n        liveOptions.timeseries as Record<string, unknown>,\n        expectedOptions?.timeseries as Record<string, unknown> | undefined,\n      ) as MongoSchemaCollectionOptions['timeseries'])\n    : undefined;\n\n  // ClusteredIndex: drop `key`, `unique`, `v` and any other server-applied\n  // extras when the contract did not specify them.\n  const clusteredIndex = liveOptions.clusteredIndex\n    ? (stripUnspecifiedFields(\n        liveOptions.clusteredIndex as Record<string, unknown>,\n        expectedOptions?.clusteredIndex as Record<string, unknown> | undefined,\n      ) as MongoSchemaCollectionOptions['clusteredIndex'])\n    : undefined;\n\n  // changeStreamPreAndPostImages: `{enabled: false}` is equivalent to\n  // \"absent\". Strip it from live so it round-trips with a contract that\n  // omits the field, and is symmetric with the expected-side stripping.\n  const changeStreamPreAndPostImages = isDisabledChangeStream(\n    liveOptions.changeStreamPreAndPostImages,\n  )\n    ? undefined\n    : liveOptions.changeStreamPreAndPostImages;\n\n  const hasMeaningful =\n    liveOptions.capped || timeseries || collation || changeStreamPreAndPostImages || clusteredIndex;\n  if (!hasMeaningful) return undefined;\n\n  return new MongoSchemaCollectionOptionsCtor({\n    ...ifDefined('capped', liveOptions.capped),\n    ...ifDefined('timeseries', timeseries),\n    ...ifDefined('collation', collation),\n    ...ifDefined('changeStreamPreAndPostImages', changeStreamPreAndPostImages),\n    ...ifDefined('clusteredIndex', clusteredIndex),\n  });\n}\n\nfunction canonicalizeExpectedOptions(\n  expectedOptions: MongoSchemaCollectionOptions,\n  _liveOptions: MongoSchemaCollectionOptions | undefined,\n): MongoSchemaCollectionOptions | undefined {\n  // Symmetric: a contract `{enabled: false}` is equivalent to absent.\n  const changeStreamPreAndPostImages = isDisabledChangeStream(\n    expectedOptions.changeStreamPreAndPostImages,\n  )\n    ? undefined\n    : expectedOptions.changeStreamPreAndPostImages;\n\n  const hasMeaningful =\n    expectedOptions.capped ||\n    expectedOptions.timeseries ||\n    expectedOptions.collation ||\n    changeStreamPreAndPostImages ||\n    expectedOptions.clusteredIndex;\n  if (!hasMeaningful) return undefined;\n\n  return new MongoSchemaCollectionOptionsCtor({\n    ...ifDefined('capped', expectedOptions.capped),\n    ...ifDefined('timeseries', expectedOptions.timeseries),\n    ...ifDefined('collation', expectedOptions.collation),\n    ...ifDefined('changeStreamPreAndPostImages', changeStreamPreAndPostImages),\n    ...ifDefined('clusteredIndex', expectedOptions.clusteredIndex),\n  });\n}\n\nfunction isDisabledChangeStream(value: { enabled: boolean } | undefined): boolean {\n  return value !== undefined && value.enabled === false;\n}\n\n/**\n * Returns a copy of `live` containing only the keys that `expected` defines.\n * Used for option families whose individual sub-fields are server-extended\n * with platform defaults (collation, timeseries, clusteredIndex), so the\n * verifier should compare only what the contract actually authored.\n *\n * When `expected` is `undefined` — i.e. the contract authored nothing for\n * this whole option family but the live IR has it — we return `live`\n * unchanged so the verifier still sees the entire live block and can\n * surface it as drift. (Returning `undefined` here would silently strip a\n * server-attached collation/timeseries/clusteredIndex that the contract\n * never asked for, hiding real drift.)\n */\nfunction stripCollationFields(\n  live: CollationOptions,\n  expected: CollationOptions | undefined,\n): CollationOptions {\n  return blindCast<\n    CollationOptions,\n    'locale is required in CollationOptions so stripUnspecifiedFields preserves it when expected is defined'\n  >(stripUnspecifiedFields(live, expected));\n}\n\nfunction stripUnspecifiedFields<T extends object>(live: T, expected: T | undefined): Partial<T> {\n  if (expected === undefined) return live;\n  const out: Partial<T> = {};\n  for (const key of Object.keys(expected) as (keyof T)[]) {\n    if (Object.hasOwn(live, key)) out[key] = live[key];\n  }\n  return out;\n}\n","import { type ControlPolicy, effectiveControlPolicy } from '@prisma-next/contract/types';\nimport type { TargetBoundComponentDescriptor } from '@prisma-next/framework-components/components';\nimport type {\n  OperationContext,\n  VerifyDatabaseSchemaResult,\n} from '@prisma-next/framework-components/control';\nimport { VERIFY_CODE_SCHEMA_FAILURE } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { MongoCollection, MongoContract } from '@prisma-next/mongo-contract';\nimport type { MongoSchemaIR } from '@prisma-next/mongo-schema-ir';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { contractToMongoSchemaIR } from '../contract-to-schema';\nimport { diffMongoSchemas } from '../schema-diff';\nimport { canonicalizeSchemasForVerification } from './canonicalize-introspection';\n\nexport interface VerifyMongoSchemaOptions {\n  readonly contract: MongoContract;\n  readonly schema: MongoSchemaIR;\n  readonly strict: boolean;\n  readonly context?: OperationContext;\n  /**\n   * Active framework components participating in this composition. Mongo\n   * verification does not currently consult them, but the parameter exists\n   * for parity with the SQL family verify so callers can pass the same envelope.\n   */\n  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'mongo', string>>;\n}\n\nexport function verifyMongoSchema(options: VerifyMongoSchemaOptions): VerifyDatabaseSchemaResult {\n  const { contract, schema, strict, context } = options;\n  const startTime = Date.now();\n\n  const expectedIR = contractToMongoSchemaIR(contract);\n  // Strip server-applied defaults (and authored equivalents) before diffing so\n  // the verifier compares like-with-like — see `canonicalize-introspection.ts`.\n  const { live: canonicalLive, expected: canonicalExpected } = canonicalizeSchemasForVerification(\n    schema,\n    expectedIR,\n  );\n  const collectionControlPolicy = resolveMongoCollectionControlPolicy(contract);\n  const { failures, warnings } = diffMongoSchemas(\n    canonicalLive,\n    canonicalExpected,\n    strict,\n    collectionControlPolicy,\n  );\n\n  const ok = failures.length === 0;\n  const profileHash = typeof contract.profileHash === 'string' ? contract.profileHash : '';\n\n  return {\n    ok,\n    ...ifDefined('code', ok ? undefined : VERIFY_CODE_SCHEMA_FAILURE),\n    summary: ok\n      ? 'Schema matches contract'\n      : `Schema verification found ${failures.length} issue(s)`,\n    contract: {\n      storageHash: contract.storage.storageHash,\n      ...(profileHash ? { profileHash } : {}),\n    },\n    target: { expected: contract.target },\n    schema: {\n      issues: failures,\n      warnings: { issues: warnings },\n    },\n    meta: {\n      strict,\n      ...ifDefined('contractPath', context?.contractPath),\n      ...ifDefined('configPath', context?.configPath),\n    },\n    timings: { total: Date.now() - startTime },\n  };\n}\n\nfunction resolveMongoCollectionControlPolicy(\n  contract: MongoContract,\n): (collectionName: string) => ControlPolicy {\n  const namespace = contract.storage.namespaces[UNBOUND_NAMESPACE_ID];\n  const collections: Record<string, MongoCollection> = namespace?.entries.collection ?? {};\n  const defaultControlPolicy = contract.defaultControlPolicy;\n  return (collectionName: string) =>\n    effectiveControlPolicy(collections[collectionName]?.control, defaultControlPolicy);\n}\n"],"mappings":";;;;;;;AAgBA,SAAS,aAAa,OAAqC;CACzD,OAAO,IAAI,iBAAiB;EAC1B,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,oBAAoB,MAAM;EAC1B,yBAAyB,MAAM;EAC/B,oBAAoB,MAAM;EAC1B,WAAW,MAAM;EACjB,SAAS,MAAM;EACf,kBAAkB,MAAM;EACxB,mBAAmB,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