{"version":3,"file":"native.mjs","names":[],"sources":["../src/native.ts"],"sourcesContent":["import type { NativePreparedSearchConfig } from \"./native-search-config\";\nimport type { OperatorSelection, OperatorType } from \"./types\";\n\nexport type { NativePreparedSearchConfig } from \"./native-search-config\";\n\ntype NativeBindingOperatorConfig = {\n  operators?: Record<string, OperatorSelection>;\n  redactString?: string;\n};\n\ntype NativeBindingCallerRedactionOptions = {\n  requestJson: string;\n  operators?: NativeBindingOperatorConfig;\n};\n\ntype NativeBindingSessionCallerRedactionInput = {\n  fullText: string;\n  requestJson: string;\n};\n\ntype NativeBindingSessionCallerRedactionPlanOptions = {\n  inputs: NativeBindingSessionCallerRedactionInput[];\n  operators?: NativeBindingOperatorConfig;\n  observedAtEpochSeconds?: number;\n};\n\ntype NativeBindingOpenSessionArchiveOptions = {\n  archive: Uint8Array;\n  key: Uint8Array;\n  expectedSessionId: string;\n  observedAtEpochSeconds?: number;\n};\n\nexport type NativeDiagnosticsBatchCallback = (diagnosticsJson: string) => void;\nexport type NativeResultEventCallback = (eventJson: string) => void;\n\ntype NativeBindingRedactionEntry = {\n  placeholder: string;\n  original: string;\n};\n\ntype NativeBindingOperatorEntry = {\n  placeholder: string;\n  operator: OperatorType;\n};\n\ntype NativeBindingPipelineEntity = {\n  start: number;\n  end: number;\n  label: string;\n  text: string;\n  score: number;\n  source: string;\n  sourceDetail?: string | null;\n  providerId?: string | null;\n  detectionId?: string | null;\n};\n\ntype NativeBindingRedactionResult = {\n  redactedText: string;\n  redactionMap: NativeBindingRedactionEntry[];\n  operatorMap: NativeBindingOperatorEntry[];\n  entityCount: number;\n};\n\ntype NativeBindingStaticRedactionResult = {\n  resolvedEntities: NativeBindingPipelineEntity[];\n  redaction: NativeBindingRedactionResult;\n};\n\ntype CanonicalPipelineEntity = {\n  start: number;\n  end: number;\n  label: string;\n  text: string;\n  score: number;\n  source: string;\n  source_detail?: string | null;\n  provider_id?: string | null;\n  detection_id?: string | null;\n};\n\ntype CanonicalStaticRedactionResult = {\n  resolved_entities: CanonicalPipelineEntity[];\n  redaction: {\n    redacted_text: string;\n    redaction_map: NativeBindingRedactionEntry[];\n    operator_map: NativeBindingOperatorEntry[];\n    entity_count: number;\n  };\n};\n\ntype CanonicalSessionMetadata = {\n  session_id: string;\n  created_at_epoch_seconds: number | null;\n  expires_at_epoch_seconds: number | null;\n  mapping_count: number;\n  status: NativeSessionStatus;\n};\n\ntype CanonicalSessionDeletionSummary = {\n  session_id: string;\n  deleted_mapping_count: number;\n};\n\ntype CanonicalSessionRedactionPlanResult = {\n  replacements: Array<{ start: number; end: number; replacement: string }>;\n  entity_count: number;\n  caller_entity_count: number;\n};\n\nexport type NativeSessionStatus =\n  | \"active\"\n  | \"not_yet_active\"\n  | \"expired\"\n  | \"deleted\";\n\nexport type NativeSessionLifecycle = {\n  createdAtEpochSeconds: number;\n  expiresAtEpochSeconds?: number;\n};\n\nexport type NativeSessionMetadata = {\n  sessionId: string;\n  createdAtEpochSeconds: number | null;\n  expiresAtEpochSeconds: number | null;\n  mappingCount: number;\n  status: NativeSessionStatus;\n};\n\nexport type NativeSessionDeletionSummary = {\n  sessionId: string;\n  deletedMappingCount: number;\n};\n\nexport type NativeSessionRedactionAtOptions = {\n  fullText: string;\n  observedAtEpochSeconds: number;\n  operators?: NativeOperatorConfig;\n};\n\nexport type NativeCreateSessionWithLifecycleOptions = NativeSessionLifecycle & {\n  sessionId: string;\n};\n\nexport type NativeOpenSessionArchiveOptions = {\n  archive: Uint8Array;\n  key: Uint8Array;\n  expectedSessionId: string;\n  observedAtEpochSeconds?: number;\n};\n\nexport type NativePreparedRedactionSessionBinding = {\n  sessionId: () => string;\n  mappingCount: () => number;\n  restoreText: (fullText: string) => string;\n  restoreTextAt: (fullText: string, observedAtEpochSeconds: number) => string;\n  toPlaintextJson: () => string;\n  toPlaintextJsonAt: (observedAtEpochSeconds: number) => string;\n  toEncryptedArchive: (key: Uint8Array) => Uint8Array;\n  toEncryptedArchiveAt: (\n    key: Uint8Array,\n    observedAtEpochSeconds: number,\n  ) => Uint8Array;\n  inspectJson: (observedAtEpochSeconds?: number) => string;\n  deleteJson: () => string;\n  redactStaticEntitiesJson: (\n    fullText: string,\n    operators?: NativeBindingOperatorConfig,\n  ) => string;\n  redactStaticEntitiesJsonAt: (\n    fullText: string,\n    observedAtEpochSeconds: number,\n    operators?: NativeBindingOperatorConfig,\n  ) => string;\n  planStaticEntitiesWithCallerDetections: (\n    options: NativeBindingSessionCallerRedactionPlanOptions,\n  ) => NativePreparedSessionRedactionPlanBinding;\n};\n\nexport type NativePreparedSessionRedactionPlanBinding = {\n  resultJson: () => string;\n  commit: () => void;\n};\n\nexport type NativePreparedSearchBinding = {\n  prepareDiagnosticsJson: () => string;\n  warmLazyRegex: () => void;\n  warmLazyRegexDiagnosticsJson: () => string;\n  createRedactionSession: (\n    sessionId: string,\n  ) => NativePreparedRedactionSessionBinding;\n  createRedactionSessionWithLifecycle: (\n    sessionId: string,\n    createdAtEpochSeconds: number,\n    expiresAtEpochSeconds?: number,\n  ) => NativePreparedRedactionSessionBinding;\n  restoreRedactionSession: (\n    plaintextJson: string,\n  ) => NativePreparedRedactionSessionBinding;\n  restoreEncryptedRedactionSession: (\n    options: NativeBindingOpenSessionArchiveOptions,\n  ) => NativePreparedRedactionSessionBinding;\n  redactStaticEntities: (\n    fullText: string,\n    operators?: NativeBindingOperatorConfig,\n  ) => NativeBindingStaticRedactionResult;\n  redactStaticEntitiesJson: (\n    fullText: string,\n    operators?: NativeBindingOperatorConfig,\n  ) => string;\n  redactStaticEntitiesWithCallerDetectionsJson: (\n    fullText: string,\n    options: NativeBindingCallerRedactionOptions,\n  ) => string;\n  redactStaticEntitiesWithCallerDetectionsDiagnosticsJson: (\n    fullText: string,\n    options: NativeBindingCallerRedactionOptions,\n  ) => string;\n  redactStaticEntitiesResultStreamJson: (\n    fullText: string,\n    operators: NativeBindingOperatorConfig | undefined,\n    onEvent: NativeResultEventCallback,\n  ) => string;\n  redactStaticEntitiesDiagnosticsJson: (\n    fullText: string,\n    operators?: NativeBindingOperatorConfig,\n  ) => string;\n  redactStaticEntitiesDiagnosticsStreamJson: (\n    fullText: string,\n    operators: NativeBindingOperatorConfig | undefined,\n    onBatch: NativeDiagnosticsBatchCallback,\n  ) => string;\n  redactStaticEntitiesSummaryDiagnosticsJson: (\n    fullText: string,\n    operators?: NativeBindingOperatorConfig,\n  ) => string;\n};\n\nexport type NativeAnonymizeBinding = {\n  convertExternalDetectionBatch: (\n    document: Uint8Array,\n    batchJson: string,\n  ) => NativeCallerDetection[];\n  externalDetectionLimitsJson: () => string;\n  extractDocxTextJson: (document: Uint8Array) => string;\n  inspectPdfJson: (document: Uint8Array, observationsJson?: string) => string;\n  rewritePdfRasterFromDetectionsJson: (\n    document: Uint8Array,\n    requestJson: string,\n    pagePixels: readonly Uint8Array[],\n  ) => { document: Uint8Array; certificateJson: string };\n  rewriteDocxTextNative: (\n    document: Uint8Array,\n    rewritesJson: string,\n  ) => {\n    document: Uint8Array;\n    rewrittenBlockCount: number;\n    appliedReplacementCount: number;\n  };\n  planDocxRestorationJson: (document: Uint8Array, sessionId: string) => string;\n  normalizeForSearch: (text: string) => string;\n  nativePackageVersion: () => string;\n  NativePreparedSearch: {\n    fromConfigJsonBytes: (\n      configJson: Uint8Array,\n    ) => NativePreparedSearchBinding;\n    fromPreparedPackageBytes: (\n      packageBytes: Uint8Array,\n    ) => NativePreparedSearchBinding;\n    fromPreparedPackageBytesWithoutCache: (\n      packageBytes: Uint8Array,\n    ) => NativePreparedSearchBinding;\n    fromTrustedPreparedPackageBytes: (\n      packageBytes: Uint8Array,\n    ) => NativePreparedSearchBinding;\n    fromTrustedPreparedPackageBytesWithoutCache: (\n      packageBytes: Uint8Array,\n    ) => NativePreparedSearchBinding;\n  };\n  prepareStaticSearchPackageBytes: (configJson: Uint8Array) => Uint8Array;\n  prepareStaticSearchCompressedPackageBytes: (\n    configJson: Uint8Array,\n  ) => Uint8Array;\n  // Rust config assembler (replaces the retired TypeScript config-assembly\n  // layer). Takes the pipeline config plus out-of-band dictionaries and\n  // gazetteer JSON and returns either the assembled config JSON or ready\n  // package bytes. Every parity runtime must expose these required members.\n  assembleStaticSearchConfigJson: (\n    pipelineConfigJson: Uint8Array,\n    dictionariesJson?: Uint8Array,\n    gazetteerJson?: Uint8Array,\n  ) => Uint8Array;\n  assembleStaticSearchPackageBytes: (\n    pipelineConfigJson: Uint8Array,\n    dictionariesJson?: Uint8Array,\n    gazetteerJson?: Uint8Array,\n  ) => Uint8Array;\n  assembleStaticSearchCompressedPackageBytes: (\n    pipelineConfigJson: Uint8Array,\n    dictionariesJson?: Uint8Array,\n    gazetteerJson?: Uint8Array,\n  ) => Uint8Array;\n};\n\ntype FunctionMemberNames<T> = {\n  [Key in keyof T]-?: T[Key] extends (...args: never[]) => unknown\n    ? Key\n    : never;\n}[keyof T];\n\n/** Exhaustive runtime-member contract shared by loaders and parity gates. */\nexport const NATIVE_BINDING_PARITY_MEMBERS = {\n  root: [\n    \"convertExternalDetectionBatch\",\n    \"externalDetectionLimitsJson\",\n    \"extractDocxTextJson\",\n    \"inspectPdfJson\",\n    \"rewritePdfRasterFromDetectionsJson\",\n    \"rewriteDocxTextNative\",\n    \"planDocxRestorationJson\",\n    \"normalizeForSearch\",\n    \"nativePackageVersion\",\n    \"prepareStaticSearchPackageBytes\",\n    \"prepareStaticSearchCompressedPackageBytes\",\n    \"assembleStaticSearchConfigJson\",\n    \"assembleStaticSearchPackageBytes\",\n    \"assembleStaticSearchCompressedPackageBytes\",\n  ],\n  factories: [\n    \"fromConfigJsonBytes\",\n    \"fromPreparedPackageBytes\",\n    \"fromPreparedPackageBytesWithoutCache\",\n    \"fromTrustedPreparedPackageBytes\",\n    \"fromTrustedPreparedPackageBytesWithoutCache\",\n  ],\n  prepared: [\n    \"prepareDiagnosticsJson\",\n    \"warmLazyRegex\",\n    \"warmLazyRegexDiagnosticsJson\",\n    \"createRedactionSession\",\n    \"createRedactionSessionWithLifecycle\",\n    \"restoreRedactionSession\",\n    \"restoreEncryptedRedactionSession\",\n    \"redactStaticEntities\",\n    \"redactStaticEntitiesJson\",\n    \"redactStaticEntitiesWithCallerDetectionsJson\",\n    \"redactStaticEntitiesWithCallerDetectionsDiagnosticsJson\",\n    \"redactStaticEntitiesResultStreamJson\",\n    \"redactStaticEntitiesDiagnosticsJson\",\n    \"redactStaticEntitiesDiagnosticsStreamJson\",\n    \"redactStaticEntitiesSummaryDiagnosticsJson\",\n  ],\n  session: [\n    \"sessionId\",\n    \"mappingCount\",\n    \"restoreText\",\n    \"restoreTextAt\",\n    \"toPlaintextJson\",\n    \"toPlaintextJsonAt\",\n    \"toEncryptedArchive\",\n    \"toEncryptedArchiveAt\",\n    \"inspectJson\",\n    \"deleteJson\",\n    \"redactStaticEntitiesJson\",\n    \"redactStaticEntitiesJsonAt\",\n    \"planStaticEntitiesWithCallerDetections\",\n  ],\n  plan: [\"resultJson\", \"commit\"],\n} as const satisfies {\n  root: readonly FunctionMemberNames<NativeAnonymizeBinding>[];\n  factories: readonly FunctionMemberNames<\n    NativeAnonymizeBinding[\"NativePreparedSearch\"]\n  >[];\n  prepared: readonly FunctionMemberNames<NativePreparedSearchBinding>[];\n  session: readonly FunctionMemberNames<NativePreparedRedactionSessionBinding>[];\n  plan: readonly FunctionMemberNames<NativePreparedSessionRedactionPlanBinding>[];\n};\n\nconst ROOT_PARITY_IS_EXHAUSTIVE: Exclude<\n  FunctionMemberNames<NativeAnonymizeBinding>,\n  (typeof NATIVE_BINDING_PARITY_MEMBERS.root)[number]\n> extends never\n  ? true\n  : never = true;\nconst FACTORY_PARITY_IS_EXHAUSTIVE: Exclude<\n  FunctionMemberNames<NativeAnonymizeBinding[\"NativePreparedSearch\"]>,\n  (typeof NATIVE_BINDING_PARITY_MEMBERS.factories)[number]\n> extends never\n  ? true\n  : never = true;\nconst PREPARED_PARITY_IS_EXHAUSTIVE: Exclude<\n  FunctionMemberNames<NativePreparedSearchBinding>,\n  (typeof NATIVE_BINDING_PARITY_MEMBERS.prepared)[number]\n> extends never\n  ? true\n  : never = true;\nconst SESSION_PARITY_IS_EXHAUSTIVE: Exclude<\n  FunctionMemberNames<NativePreparedRedactionSessionBinding>,\n  (typeof NATIVE_BINDING_PARITY_MEMBERS.session)[number]\n> extends never\n  ? true\n  : never = true;\nconst PLAN_PARITY_IS_EXHAUSTIVE: Exclude<\n  FunctionMemberNames<NativePreparedSessionRedactionPlanBinding>,\n  (typeof NATIVE_BINDING_PARITY_MEMBERS.plan)[number]\n> extends never\n  ? true\n  : never = true;\nvoid [\n  ROOT_PARITY_IS_EXHAUSTIVE,\n  FACTORY_PARITY_IS_EXHAUSTIVE,\n  PREPARED_PARITY_IS_EXHAUSTIVE,\n  SESSION_PARITY_IS_EXHAUSTIVE,\n  PLAN_PARITY_IS_EXHAUSTIVE,\n];\n\nconst isBindingPropertyBag = (\n  value: unknown,\n): value is Record<string, unknown> =>\n  (typeof value === \"object\" && value !== null) || typeof value === \"function\";\n\n/** Validate the complete runtime-neutral root and factory binding shape. */\nexport const isNativeAnonymizeBinding = (\n  candidate: unknown,\n): candidate is NativeAnonymizeBinding => {\n  if (!isBindingPropertyBag(candidate)) {\n    return false;\n  }\n  if (\n    !NATIVE_BINDING_PARITY_MEMBERS.root.every(\n      (name) => typeof candidate[name] === \"function\",\n    )\n  ) {\n    return false;\n  }\n  const preparedSearch = candidate[\"NativePreparedSearch\"];\n  return (\n    isBindingPropertyBag(preparedSearch) &&\n    NATIVE_BINDING_PARITY_MEMBERS.factories.every(\n      (name) => typeof preparedSearch[name] === \"function\",\n    )\n  );\n};\n\nexport type NativeOperatorConfig = {\n  operators?: Record<string, OperatorSelection>;\n  redactString?: string;\n};\n\nexport const CALLER_DETECTION_CONTRACT_VERSION = 2;\nexport const CALLER_DETECTION_MAX_COUNT = 1_000_000;\nexport const CALLER_DETECTION_TEXT_MAX_BYTES = 64 * 1024 * 1024;\nexport const CALLER_DETECTION_REQUEST_JSON_MAX_BYTES = 16 * 1024 * 1024;\nexport const SESSION_CALLER_MAX_INPUTS = 100_000;\nexport const SESSION_CALLER_INPUTS_JSON_MAX_BYTES = 64 * 1024 * 1024;\n\nexport const EXTERNAL_DETECTION_BATCH_VERSION = 1 as const;\nexport const EXTERNAL_DETECTION_BATCH_MAX_BYTES = 16 * 1024 * 1024;\nexport const EXTERNAL_DETECTION_DOCUMENT_MAX_BYTES = 64 * 1024 * 1024;\nexport const EXTERNAL_DETECTION_MAX_DETECTIONS = 100_000;\nexport const EXTERNAL_DETECTION_MAX_LABEL_MAPPINGS = 4_096;\nexport const EXTERNAL_DETECTION_MAX_METADATA_BYTES = 256;\nexport const EXTERNAL_DETECTION_PROVIDER_ID_MAX_BYTES = 128;\n\nexport const EXTERNAL_DETECTION_OFFSET_UNITS = {\n  unicodeCodePoint: \"unicode-code-point\",\n  utf16CodeUnit: \"utf16-code-unit\",\n  utf8Byte: \"utf8-byte\",\n} as const;\n\nexport type ExternalDetectionOffsetUnit =\n  (typeof EXTERNAL_DETECTION_OFFSET_UNITS)[keyof typeof EXTERNAL_DETECTION_OFFSET_UNITS];\n\nexport type ExternalDetectionBatch = {\n  version: typeof EXTERNAL_DETECTION_BATCH_VERSION;\n  document: { sha256: string };\n  offsetUnit: ExternalDetectionOffsetUnit;\n  provider: { id: string; name: string; version: string };\n  labelMap: readonly {\n    providerLabel: string;\n    entityLabel: string;\n  }[];\n  detections: readonly {\n    id: string;\n    start: number;\n    end: number;\n    label: string;\n    score: number;\n  }[];\n};\n\nexport type NativeCallerDetection = {\n  start: number;\n  end: number;\n  label: string;\n  score: number;\n  providerId: string;\n  detectionId: string;\n};\n\nexport type ConvertExternalDetectionBatchOptions = {\n  binding: NativeAnonymizeBinding;\n  document: Uint8Array;\n  batch: ExternalDetectionBatch | string;\n};\n\nexport const convert_external_detection_batch = ({\n  binding,\n  document,\n  batch,\n}: ConvertExternalDetectionBatchOptions): NativeCallerDetection[] => {\n  return binding.convertExternalDetectionBatch(\n    document,\n    typeof batch === \"string\" ? batch : JSON.stringify(batch),\n  );\n};\n\nexport type NativeCallerRedactionOptions = {\n  detections: readonly NativeCallerDetection[];\n  operators?: NativeOperatorConfig;\n};\n\nexport type NativeSessionCallerRedactionInput = {\n  fullText: string;\n  detections: readonly NativeCallerDetection[];\n};\n\nexport type NativeSessionCallerRedactionPlanOptions = {\n  inputs: readonly NativeSessionCallerRedactionInput[];\n  operators?: NativeOperatorConfig;\n  observedAtEpochSeconds?: number;\n};\n\nexport type NativeTextReplacement = {\n  start: number;\n  end: number;\n  replacement: string;\n};\n\nexport type NativeSessionBlockRedactionPlan = {\n  replacements: readonly NativeTextReplacement[];\n  entityCount: number;\n  callerEntityCount: number;\n};\n\nconst utf8ByteLengthWithin = (\n  text: string,\n  maximum: number,\n): number | undefined => {\n  let bytes = 0;\n  for (let index = 0; index < text.length; index += 1) {\n    const unit = text.charCodeAt(index);\n    if (unit <= 0x7f) {\n      bytes += 1;\n    } else if (unit <= 0x7ff) {\n      bytes += 2;\n    } else if (\n      unit >= 0xd800 &&\n      unit <= 0xdbff &&\n      index + 1 < text.length &&\n      text.charCodeAt(index + 1) >= 0xdc00 &&\n      text.charCodeAt(index + 1) <= 0xdfff\n    ) {\n      bytes += 4;\n      index += 1;\n    } else {\n      bytes += 3;\n    }\n    if (bytes > maximum) {\n      return undefined;\n    }\n  }\n  return bytes;\n};\n\nconst validateCallerDetectionInput = (\n  fullText: string,\n  detections: readonly NativeCallerDetection[],\n): number => {\n  if (!Array.isArray(detections)) {\n    throw new TypeError(\"Caller detections must be an array\");\n  }\n  if (detections.length > CALLER_DETECTION_MAX_COUNT) {\n    throw new RangeError(\n      `Caller detections contains ${detections.length} items; the maximum is ${CALLER_DETECTION_MAX_COUNT}`,\n    );\n  }\n  const textBytes = utf8ByteLengthWithin(\n    fullText,\n    CALLER_DETECTION_TEXT_MAX_BYTES,\n  );\n  if (textBytes === undefined) {\n    throw new RangeError(\n      `Caller detection text exceeds the ${CALLER_DETECTION_TEXT_MAX_BYTES}-byte maximum`,\n    );\n  }\n  return textBytes;\n};\n\nabstract class BoundedJsonSink {\n  readonly #maximumBytes: number;\n  readonly #label: string;\n  readonly #reportedMaximumBytes: number;\n  #bytes = 0;\n\n  constructor(maximumBytes: number, label: string, suffix: string) {\n    this.#maximumBytes = maximumBytes - suffix.length;\n    this.#label = label;\n    this.#reportedMaximumBytes = maximumBytes;\n  }\n\n  appendAscii(value: string): void {\n    this.#reserve(value.length);\n    this.capture(value);\n  }\n\n  appendOffset(value: number, field: string): void {\n    this.#requireNumber(value, field);\n    if (!Number.isInteger(value) || value < 0 || value > 0xff_ff_ff_ff) {\n      throw new RangeError(\n        `${field} must be an integer between 0 and 4294967295`,\n      );\n    }\n    this.#appendNumber(value);\n  }\n\n  appendScore(value: number, field: string): void {\n    this.#requireNumber(value, field);\n    if (!Number.isFinite(value) || value < 0 || value > 1) {\n      throw new RangeError(`${field} must be finite and between 0 and 1`);\n    }\n    this.#appendNumber(value);\n  }\n\n  appendString(value: string, field: string): void {\n    if (typeof value !== \"string\") {\n      throw new TypeError(`${field} must be a string`);\n    }\n    this.appendAscii('\"');\n    let runStart = 0;\n    for (let index = 0; index < value.length; index += 1) {\n      const unit = value.charCodeAt(index);\n      const escape = jsonEscape(unit);\n      if (escape !== undefined) {\n        this.#appendReservedRun(value, runStart, index);\n        this.appendAscii(escape);\n        runStart = index + 1;\n        continue;\n      }\n      if (\n        unit >= 0xd800 &&\n        unit <= 0xdbff &&\n        index + 1 < value.length &&\n        value.charCodeAt(index + 1) >= 0xdc00 &&\n        value.charCodeAt(index + 1) <= 0xdfff\n      ) {\n        this.#reserve(4);\n        index += 1;\n        continue;\n      }\n      if (unit >= 0xd800 && unit <= 0xdfff) {\n        this.#appendReservedRun(value, runStart, index);\n        this.appendAscii(`\\\\u${unit.toString(16).padStart(4, \"0\")}`);\n        runStart = index + 1;\n        continue;\n      }\n      let unitBytes = 3;\n      if (unit <= 0x7f) {\n        unitBytes = 1;\n      } else if (unit <= 0x7ff) {\n        unitBytes = 2;\n      }\n      this.#reserve(unitBytes);\n    }\n    this.#appendReservedRun(value, runStart, value.length);\n    this.appendAscii('\"');\n  }\n\n  #appendReservedRun(value: string, start: number, end: number): void {\n    if (end > start) {\n      this.capture(value.slice(start, end));\n    }\n  }\n\n  #appendNumber(value: number): void {\n    this.appendAscii(JSON.stringify(value));\n  }\n\n  #requireNumber(value: number, field: string): void {\n    if (typeof value !== \"number\") {\n      throw new TypeError(`${field} must be a number`);\n    }\n  }\n\n  #reserve(bytes: number): void {\n    if (bytes > this.#maximumBytes - this.#bytes) {\n      throw new RangeError(\n        `${this.#label} exceeds the ${this.#reportedMaximumBytes}-byte maximum`,\n      );\n    }\n    this.#bytes += bytes;\n  }\n\n  protected abstract capture(value: string): void;\n}\n\nclass CountingJsonBudget extends BoundedJsonSink {\n  protected capture(value: string): void {\n    void value;\n  }\n}\n\nclass BoundedJsonWriter extends BoundedJsonSink {\n  readonly #chunks: string[] = [];\n  readonly #suffix: string;\n\n  constructor(maximumBytes: number, label: string, suffix: string) {\n    super(maximumBytes, label, suffix);\n    this.#suffix = suffix;\n  }\n\n  finish(): string {\n    return this.#chunks.join(\"\") + this.#suffix;\n  }\n\n  protected capture(value: string): void {\n    this.#chunks.push(value);\n  }\n}\n\nconst jsonEscape = (unit: number): string | undefined => {\n  switch (unit) {\n    case 0x08:\n      return \"\\\\b\";\n    case 0x09:\n      return \"\\\\t\";\n    case 0x0a:\n      return \"\\\\n\";\n    case 0x0c:\n      return \"\\\\f\";\n    case 0x0d:\n      return \"\\\\r\";\n    case 0x22:\n      return '\\\\\"';\n    case 0x5c:\n      return \"\\\\\\\\\";\n    default:\n      return unit < 0x20\n        ? `\\\\u${unit.toString(16).padStart(4, \"0\")}`\n        : undefined;\n  }\n};\n\nconst callerDetectionRequestJson = (\n  fullText: string,\n  detections: readonly NativeCallerDetection[],\n): string => {\n  validateCallerDetectionInput(fullText, detections);\n  return serializeCallerDetectionRequest(detections);\n};\n\nconst serializeCallerDetectionRequest = (\n  detections: readonly NativeCallerDetection[],\n): string => {\n  const writer = new BoundedJsonWriter(\n    CALLER_DETECTION_REQUEST_JSON_MAX_BYTES,\n    \"Caller detection request JSON\",\n    \"]}\",\n  );\n  writer.appendAscii(\n    `{\"version\":${CALLER_DETECTION_CONTRACT_VERSION},\"detections\":[`,\n  );\n  for (let index = 0; index < detections.length; index += 1) {\n    const detection = detections[index];\n    if (detection === undefined) {\n      throw new TypeError(\"Caller detections must not be sparse\");\n    }\n    if (index > 0) {\n      writer.appendAscii(\",\");\n    }\n    writer.appendAscii('{\"start\":');\n    writer.appendOffset(detection.start, \"Caller detection start\");\n    writer.appendAscii(',\"end\":');\n    writer.appendOffset(detection.end, \"Caller detection end\");\n    writer.appendAscii(',\"label\":');\n    writer.appendString(detection.label, \"Caller detection label\");\n    writer.appendAscii(',\"score\":');\n    writer.appendScore(detection.score, \"Caller detection score\");\n    writer.appendAscii(',\"provider_id\":');\n    writer.appendString(detection.providerId, \"Caller detection providerId\");\n    writer.appendAscii(',\"detection_id\":');\n    writer.appendString(detection.detectionId, \"Caller detection detectionId\");\n    writer.appendAscii(\"}\");\n  }\n  return writer.finish();\n};\n\nconst toBindingSessionCallerInputs = (\n  inputs: readonly NativeSessionCallerRedactionInput[],\n) => {\n  if (!Array.isArray(inputs)) {\n    throw new TypeError(\"Session caller inputs must be an array\");\n  }\n  if (inputs.length > SESSION_CALLER_MAX_INPUTS) {\n    throw new RangeError(\n      `Session caller inputs contains ${inputs.length} items; the maximum is ${SESSION_CALLER_MAX_INPUTS}`,\n    );\n  }\n  let detectionCount = 0;\n  let textBytes = 0;\n  const bindingInputs: NativeBindingSessionCallerRedactionInput[] = [];\n  const budget = new CountingJsonBudget(\n    SESSION_CALLER_INPUTS_JSON_MAX_BYTES,\n    \"Session caller inputs JSON\",\n    \"]\",\n  );\n  budget.appendAscii(\"[\");\n  for (let index = 0; index < inputs.length; index += 1) {\n    const input = inputs[index];\n    if (input === undefined) {\n      throw new TypeError(\"Session caller inputs must not be sparse\");\n    }\n    const { detections, fullText } = input;\n    const inputTextBytes = validateCallerDetectionInput(fullText, detections);\n    detectionCount += detections.length;\n    if (detectionCount > CALLER_DETECTION_MAX_COUNT) {\n      throw new RangeError(\n        `Session caller detections contains ${detectionCount} items; the maximum is ${CALLER_DETECTION_MAX_COUNT}`,\n      );\n    }\n    textBytes += inputTextBytes;\n    if (textBytes > CALLER_DETECTION_TEXT_MAX_BYTES) {\n      throw new RangeError(\n        `Session caller text contains ${textBytes} bytes; the maximum is ${CALLER_DETECTION_TEXT_MAX_BYTES}`,\n      );\n    }\n    const requestJson = serializeCallerDetectionRequest(detections);\n    if (index > 0) {\n      budget.appendAscii(\",\");\n    }\n    budget.appendAscii('{\"full_text\":');\n    budget.appendString(fullText, \"Session caller fullText\");\n    budget.appendAscii(',\"request_json\":');\n    budget.appendString(requestJson, \"Session caller requestJson\");\n    budget.appendAscii(\"}\");\n    bindingInputs.push({ fullText, requestJson });\n  }\n  return bindingInputs;\n};\n\nexport type NativePipelineEntity = {\n  start: number;\n  end: number;\n  label: string;\n  text: string;\n  score: number;\n  source: string;\n  sourceDetail?: string;\n  providerId?: string;\n  detectionId?: string;\n};\n\nexport type NativeRedactionResult = {\n  redactedText: string;\n  redactionMap: Map<string, string>;\n  operatorMap: Map<string, OperatorType>;\n  entityCount: number;\n};\n\nexport type NativeStaticRedactionResult = {\n  resolvedEntities: NativePipelineEntity[];\n  redaction: NativeRedactionResult;\n};\n\nexport type NativeSearchPackageOptions = {\n  binding: NativeAnonymizeBinding;\n  config: NativePreparedSearchConfig;\n  compressed?: boolean;\n};\n\nexport type NativeSearchPackageInput =\n  | NativePreparedSearchConfig\n  | string\n  | Uint8Array;\n\nexport type SharedNativeSearchPackageOptions = {\n  binding: NativeAnonymizeBinding;\n  config: NativeSearchPackageInput;\n  compressed?: boolean;\n};\n\nexport type SharedNativePreparedPackageOptions = {\n  binding: NativeAnonymizeBinding;\n  packageBytes: Uint8Array;\n};\n\nexport type SharedNativeRedactTextJsonOptions = {\n  binding: NativeAnonymizeBinding;\n  config: NativeSearchPackageInput;\n  fullText: string;\n  operators?: NativeOperatorConfig;\n};\n\nexport type SharedNativeRedactTextOptions = SharedNativeRedactTextJsonOptions;\n\nexport type SharedNativeDiagnosticsJsonOptions =\n  SharedNativeRedactTextJsonOptions;\n\nexport type SharedNativeDiagnosticsStreamJsonOptions =\n  SharedNativeRedactTextJsonOptions & {\n    onBatch: NativeDiagnosticsBatchCallback;\n  };\n\nexport type SharedNativeRedactTextStreamJsonOptions =\n  SharedNativeRedactTextJsonOptions & {\n    onEvent: NativeResultEventCallback;\n  };\n\nexport type NativeNormalizeOptions = {\n  binding: NativeAnonymizeBinding;\n  text: string;\n};\n\nexport type NativeAnonymizerFromConfigOptions = {\n  binding: NativeAnonymizeBinding;\n  config: NativePreparedSearchConfig;\n};\n\nexport type NativeAnonymizerFromPackageOptions = {\n  binding: NativeAnonymizeBinding;\n  packageBytes: Uint8Array;\n};\n\nexport type NativePipelineFromPackageOptions =\n  NativeAnonymizerFromPackageOptions;\n\nexport type NativeBindingVersionOptions = {\n  binding: NativeAnonymizeBinding;\n  expectedVersion: string;\n};\n\nexport class PreparedNativeRedactionSession {\n  readonly #session: NativePreparedRedactionSessionBinding;\n\n  constructor(session: NativePreparedRedactionSessionBinding) {\n    this.#session = session;\n  }\n\n  sessionId(): string {\n    return this.#session.sessionId();\n  }\n\n  session_id(): string {\n    return this.sessionId();\n  }\n\n  mappingCount(): number {\n    return this.#session.mappingCount();\n  }\n\n  mapping_count(): number {\n    return this.mappingCount();\n  }\n\n  restoreText(fullText: string, observedAtEpochSeconds?: number): string {\n    if (observedAtEpochSeconds === undefined) {\n      return this.#session.restoreText(fullText);\n    }\n    return this.#session.restoreTextAt(fullText, observedAtEpochSeconds);\n  }\n\n  restore_text(fullText: string, observedAtEpochSeconds?: number): string {\n    return this.restoreText(fullText, observedAtEpochSeconds);\n  }\n\n  toPlaintextJson(): string {\n    return this.#session.toPlaintextJson();\n  }\n\n  to_plaintext_json(): string {\n    return this.toPlaintextJson();\n  }\n\n  toPlaintextJsonAt(observedAtEpochSeconds: number): string {\n    return this.#session.toPlaintextJsonAt(observedAtEpochSeconds);\n  }\n\n  to_plaintext_json_at(observedAtEpochSeconds: number): string {\n    return this.toPlaintextJsonAt(observedAtEpochSeconds);\n  }\n\n  toEncryptedArchive(key: Uint8Array): Uint8Array {\n    return this.#session.toEncryptedArchive(key);\n  }\n\n  to_encrypted_archive(key: Uint8Array): Uint8Array {\n    return this.toEncryptedArchive(key);\n  }\n\n  toEncryptedArchiveAt(\n    key: Uint8Array,\n    observedAtEpochSeconds: number,\n  ): Uint8Array {\n    return this.#session.toEncryptedArchiveAt(key, observedAtEpochSeconds);\n  }\n\n  to_encrypted_archive_at(\n    key: Uint8Array,\n    observedAtEpochSeconds: number,\n  ): Uint8Array {\n    return this.toEncryptedArchiveAt(key, observedAtEpochSeconds);\n  }\n\n  inspect(observedAtEpochSeconds?: number): NativeSessionMetadata {\n    const metadata: CanonicalSessionMetadata = JSON.parse(\n      this.#session.inspectJson(observedAtEpochSeconds),\n    );\n    return {\n      sessionId: metadata.session_id,\n      createdAtEpochSeconds: metadata.created_at_epoch_seconds,\n      expiresAtEpochSeconds: metadata.expires_at_epoch_seconds,\n      mappingCount: metadata.mapping_count,\n      status: metadata.status,\n    };\n  }\n\n  delete(): NativeSessionDeletionSummary {\n    const summary: CanonicalSessionDeletionSummary = JSON.parse(\n      this.#session.deleteJson(),\n    );\n    return {\n      sessionId: summary.session_id,\n      deletedMappingCount: summary.deleted_mapping_count,\n    };\n  }\n\n  redactStaticEntities(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): NativeStaticRedactionResult {\n    const result: CanonicalStaticRedactionResult = JSON.parse(\n      this.redact_text_json(fullText, operators),\n    );\n    return fromCanonicalStaticRedactionResult(result);\n  }\n\n  redactText(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): NativeStaticRedactionResult {\n    return this.redactStaticEntities(fullText, operators);\n  }\n\n  redact_text(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): NativeStaticRedactionResult {\n    return this.redactText(fullText, operators);\n  }\n\n  redactTextJson(fullText: string, operators?: NativeOperatorConfig): string {\n    return this.redact_text_json(fullText, operators);\n  }\n\n  redact_text_json(fullText: string, operators?: NativeOperatorConfig): string {\n    return this.#session.redactStaticEntitiesJson(\n      fullText,\n      toBindingOperatorConfig(operators),\n    );\n  }\n\n  redactStaticEntitiesAt(\n    options: NativeSessionRedactionAtOptions,\n  ): NativeStaticRedactionResult {\n    const result: CanonicalStaticRedactionResult = JSON.parse(\n      this.redactTextJsonAt(options),\n    );\n    return fromCanonicalStaticRedactionResult(result);\n  }\n\n  redactTextAt(\n    options: NativeSessionRedactionAtOptions,\n  ): NativeStaticRedactionResult {\n    return this.redactStaticEntitiesAt(options);\n  }\n\n  redact_text_at(\n    options: NativeSessionRedactionAtOptions,\n  ): NativeStaticRedactionResult {\n    return this.redactTextAt(options);\n  }\n\n  redact_static_entities_at(\n    options: NativeSessionRedactionAtOptions,\n  ): NativeStaticRedactionResult {\n    return this.redactStaticEntitiesAt(options);\n  }\n\n  redactTextJsonAt({\n    fullText,\n    observedAtEpochSeconds,\n    operators,\n  }: NativeSessionRedactionAtOptions): string {\n    return this.#session.redactStaticEntitiesJsonAt(\n      fullText,\n      observedAtEpochSeconds,\n      toBindingOperatorConfig(operators),\n    );\n  }\n\n  redact_text_json_at(options: NativeSessionRedactionAtOptions): string {\n    return this.redactTextJsonAt(options);\n  }\n\n  planTextBatchWithCallerDetections({\n    inputs,\n    operators,\n    observedAtEpochSeconds,\n  }: NativeSessionCallerRedactionPlanOptions): PreparedNativeSessionRedactionPlan {\n    const bindingOperators = toBindingOperatorConfig(operators);\n    const bindingPlan = this.#session.planStaticEntitiesWithCallerDetections({\n      inputs: toBindingSessionCallerInputs(inputs),\n      ...(bindingOperators === undefined\n        ? {}\n        : { operators: bindingOperators }),\n      ...(observedAtEpochSeconds === undefined\n        ? {}\n        : { observedAtEpochSeconds }),\n    });\n    return new PreparedNativeSessionRedactionPlan(bindingPlan);\n  }\n}\n\nexport class PreparedNativeSessionRedactionPlan {\n  readonly blocks: readonly NativeSessionBlockRedactionPlan[];\n  readonly #plan: NativePreparedSessionRedactionPlanBinding;\n\n  constructor(plan: NativePreparedSessionRedactionPlanBinding) {\n    this.#plan = plan;\n    const blocks: CanonicalSessionRedactionPlanResult[] = JSON.parse(\n      plan.resultJson(),\n    );\n    this.blocks = blocks.map(\n      ({ caller_entity_count, entity_count, replacements }) => ({\n        replacements,\n        entityCount: entity_count,\n        callerEntityCount: caller_entity_count,\n      }),\n    );\n  }\n\n  commit(): void {\n    this.#plan.commit();\n  }\n}\n\nexport class PreparedNativeAnonymizer {\n  readonly #prepared: NativePreparedSearchBinding;\n\n  constructor(prepared: NativePreparedSearchBinding) {\n    this.#prepared = prepared;\n  }\n\n  prepareDiagnosticsJson(): string {\n    return this.#prepared.prepareDiagnosticsJson();\n  }\n\n  prepare_diagnostics_json(): string {\n    return this.prepareDiagnosticsJson();\n  }\n\n  warmLazyRegex(): void {\n    this.#prepared.warmLazyRegex();\n  }\n\n  warm_lazy_regex(): void {\n    this.warmLazyRegex();\n  }\n\n  warmLazyRegexDiagnosticsJson(): string {\n    return this.#prepared.warmLazyRegexDiagnosticsJson();\n  }\n\n  warm_lazy_regex_diagnostics_json(): string {\n    return this.warmLazyRegexDiagnosticsJson();\n  }\n\n  createRedactionSession(sessionId: string): PreparedNativeRedactionSession {\n    return new PreparedNativeRedactionSession(\n      this.#prepared.createRedactionSession(sessionId),\n    );\n  }\n\n  create_redaction_session(sessionId: string): PreparedNativeRedactionSession {\n    return this.createRedactionSession(sessionId);\n  }\n\n  createRedactionSessionWithLifecycle({\n    sessionId,\n    createdAtEpochSeconds,\n    expiresAtEpochSeconds,\n  }: NativeCreateSessionWithLifecycleOptions): PreparedNativeRedactionSession {\n    return new PreparedNativeRedactionSession(\n      this.#prepared.createRedactionSessionWithLifecycle(\n        sessionId,\n        createdAtEpochSeconds,\n        expiresAtEpochSeconds,\n      ),\n    );\n  }\n\n  create_redaction_session_with_lifecycle(\n    options: NativeCreateSessionWithLifecycleOptions,\n  ): PreparedNativeRedactionSession {\n    return this.createRedactionSessionWithLifecycle(options);\n  }\n\n  restoreRedactionSession(\n    plaintextJson: string,\n  ): PreparedNativeRedactionSession {\n    return new PreparedNativeRedactionSession(\n      this.#prepared.restoreRedactionSession(plaintextJson),\n    );\n  }\n\n  restore_redaction_session(\n    plaintextJson: string,\n  ): PreparedNativeRedactionSession {\n    return this.restoreRedactionSession(plaintextJson);\n  }\n\n  restoreEncryptedRedactionSession({\n    archive,\n    key,\n    expectedSessionId,\n    observedAtEpochSeconds,\n  }: NativeOpenSessionArchiveOptions): PreparedNativeRedactionSession {\n    return new PreparedNativeRedactionSession(\n      this.#prepared.restoreEncryptedRedactionSession({\n        archive,\n        key,\n        expectedSessionId,\n        ...(observedAtEpochSeconds === undefined\n          ? {}\n          : { observedAtEpochSeconds }),\n      }),\n    );\n  }\n\n  restore_encrypted_redaction_session(\n    options: NativeOpenSessionArchiveOptions,\n  ): PreparedNativeRedactionSession {\n    return this.restoreEncryptedRedactionSession(options);\n  }\n\n  redactStaticEntities(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): NativeStaticRedactionResult {\n    return toNativeStaticRedactionResult(\n      this.#prepared.redactStaticEntities(\n        fullText,\n        toBindingOperatorConfig(operators),\n      ),\n    );\n  }\n\n  redact_text(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): NativeStaticRedactionResult {\n    return this.redactStaticEntities(fullText, operators);\n  }\n\n  redact_text_json(fullText: string, operators?: NativeOperatorConfig): string {\n    const bindingOperators = toBindingOperatorConfig(operators);\n    return this.#prepared.redactStaticEntitiesJson(fullText, bindingOperators);\n  }\n\n  redactStaticEntitiesWithCallerDetections(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): NativeStaticRedactionResult {\n    const requestJson = callerDetectionRequestJson(\n      fullText,\n      options.detections,\n    );\n    const operators = toBindingOperatorConfig(options.operators);\n    const result: CanonicalStaticRedactionResult = JSON.parse(\n      this.#prepared.redactStaticEntitiesWithCallerDetectionsJson(fullText, {\n        requestJson,\n        ...(operators ? { operators } : {}),\n      }),\n    );\n    return fromCanonicalStaticRedactionResult(result);\n  }\n\n  redact_text_with_caller_detections(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): NativeStaticRedactionResult {\n    return this.redactStaticEntitiesWithCallerDetections(fullText, options);\n  }\n\n  redactStaticEntitiesWithCallerDetectionsDiagnosticsJson(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): string {\n    const requestJson = callerDetectionRequestJson(\n      fullText,\n      options.detections,\n    );\n    const operators = toBindingOperatorConfig(options.operators);\n    return this.#prepared.redactStaticEntitiesWithCallerDetectionsDiagnosticsJson(\n      fullText,\n      {\n        requestJson,\n        ...(operators ? { operators } : {}),\n      },\n    );\n  }\n\n  redact_static_entities_with_caller_detections_diagnostics_json(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): string {\n    return this.redactStaticEntitiesWithCallerDetectionsDiagnosticsJson(\n      fullText,\n      options,\n    );\n  }\n\n  redactTextJson(fullText: string, operators?: NativeOperatorConfig): string {\n    return this.redact_text_json(fullText, operators);\n  }\n\n  redactTextStreamJson(\n    fullText: string,\n    onEvent: NativeResultEventCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#prepared.redactStaticEntitiesResultStreamJson(\n      fullText,\n      toBindingOperatorConfig(operators),\n      onEvent,\n    );\n  }\n\n  redact_text_stream_json(\n    fullText: string,\n    onEvent: NativeResultEventCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.redactTextStreamJson(fullText, onEvent, operators);\n  }\n\n  redactStaticEntitiesDiagnosticsJson(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#prepared.redactStaticEntitiesDiagnosticsJson(\n      fullText,\n      toBindingOperatorConfig(operators),\n    );\n  }\n\n  diagnostics_json(fullText: string, operators?: NativeOperatorConfig): string {\n    return this.redactStaticEntitiesDiagnosticsJson(fullText, operators);\n  }\n\n  diagnosticsStreamJson(\n    fullText: string,\n    onBatch: NativeDiagnosticsBatchCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#prepared.redactStaticEntitiesDiagnosticsStreamJson(\n      fullText,\n      toBindingOperatorConfig(operators),\n      onBatch,\n    );\n  }\n\n  diagnostics_stream_json(\n    fullText: string,\n    onBatch: NativeDiagnosticsBatchCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.diagnosticsStreamJson(fullText, onBatch, operators);\n  }\n\n  redactStaticEntitiesSummaryDiagnosticsJson(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#prepared.redactStaticEntitiesSummaryDiagnosticsJson(\n      fullText,\n      toBindingOperatorConfig(operators),\n    );\n  }\n\n  summary_diagnostics_json(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.redactStaticEntitiesSummaryDiagnosticsJson(fullText, operators);\n  }\n}\n\nexport class PreparedNativePipeline {\n  readonly #anonymizer: PreparedNativeAnonymizer;\n\n  constructor(anonymizer: PreparedNativeAnonymizer) {\n    this.#anonymizer = anonymizer;\n  }\n\n  prepareDiagnosticsJson(): string {\n    return this.#anonymizer.prepareDiagnosticsJson();\n  }\n\n  prepare_diagnostics_json(): string {\n    return this.prepareDiagnosticsJson();\n  }\n\n  warmLazyRegex(): void {\n    this.#anonymizer.warmLazyRegex();\n  }\n\n  warm_lazy_regex(): void {\n    this.warmLazyRegex();\n  }\n\n  warmLazyRegexDiagnosticsJson(): string {\n    return this.#anonymizer.warmLazyRegexDiagnosticsJson();\n  }\n\n  warm_lazy_regex_diagnostics_json(): string {\n    return this.warmLazyRegexDiagnosticsJson();\n  }\n\n  createRedactionSession(sessionId: string): PreparedNativeRedactionSession {\n    return this.#anonymizer.createRedactionSession(sessionId);\n  }\n\n  create_redaction_session(sessionId: string): PreparedNativeRedactionSession {\n    return this.createRedactionSession(sessionId);\n  }\n\n  createRedactionSessionWithLifecycle(\n    options: NativeCreateSessionWithLifecycleOptions,\n  ): PreparedNativeRedactionSession {\n    return this.#anonymizer.createRedactionSessionWithLifecycle(options);\n  }\n\n  create_redaction_session_with_lifecycle(\n    options: NativeCreateSessionWithLifecycleOptions,\n  ): PreparedNativeRedactionSession {\n    return this.createRedactionSessionWithLifecycle(options);\n  }\n\n  restoreRedactionSession(\n    plaintextJson: string,\n  ): PreparedNativeRedactionSession {\n    return this.#anonymizer.restoreRedactionSession(plaintextJson);\n  }\n\n  restore_redaction_session(\n    plaintextJson: string,\n  ): PreparedNativeRedactionSession {\n    return this.restoreRedactionSession(plaintextJson);\n  }\n\n  restoreEncryptedRedactionSession(\n    options: NativeOpenSessionArchiveOptions,\n  ): PreparedNativeRedactionSession {\n    return this.#anonymizer.restoreEncryptedRedactionSession(options);\n  }\n\n  restore_encrypted_redaction_session(\n    options: NativeOpenSessionArchiveOptions,\n  ): PreparedNativeRedactionSession {\n    return this.restoreEncryptedRedactionSession(options);\n  }\n\n  redactText(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): NativeStaticRedactionResult {\n    return this.#anonymizer.redactStaticEntities(fullText, operators);\n  }\n\n  redact_text(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): NativeStaticRedactionResult {\n    return this.redactText(fullText, operators);\n  }\n\n  redact_text_json(fullText: string, operators?: NativeOperatorConfig): string {\n    return this.#anonymizer.redact_text_json(fullText, operators);\n  }\n\n  redactTextWithCallerDetections(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): NativeStaticRedactionResult {\n    return this.#anonymizer.redactStaticEntitiesWithCallerDetections(\n      fullText,\n      options,\n    );\n  }\n\n  redact_text_with_caller_detections(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): NativeStaticRedactionResult {\n    return this.redactTextWithCallerDetections(fullText, options);\n  }\n\n  redactTextWithCallerDetectionsDiagnosticsJson(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): string {\n    return this.#anonymizer.redactStaticEntitiesWithCallerDetectionsDiagnosticsJson(\n      fullText,\n      options,\n    );\n  }\n\n  redact_text_with_caller_detections_diagnostics_json(\n    fullText: string,\n    options: NativeCallerRedactionOptions,\n  ): string {\n    return this.redactTextWithCallerDetectionsDiagnosticsJson(\n      fullText,\n      options,\n    );\n  }\n\n  redactTextJson(fullText: string, operators?: NativeOperatorConfig): string {\n    return this.redact_text_json(fullText, operators);\n  }\n\n  redactTextStreamJson(\n    fullText: string,\n    onEvent: NativeResultEventCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#anonymizer.redactTextStreamJson(fullText, onEvent, operators);\n  }\n\n  redact_text_stream_json(\n    fullText: string,\n    onEvent: NativeResultEventCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.redactTextStreamJson(fullText, onEvent, operators);\n  }\n\n  redactTextDiagnosticsJson(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#anonymizer.redactStaticEntitiesDiagnosticsJson(\n      fullText,\n      operators,\n    );\n  }\n\n  diagnostics_json(fullText: string, operators?: NativeOperatorConfig): string {\n    return this.redactTextDiagnosticsJson(fullText, operators);\n  }\n\n  diagnosticsStreamJson(\n    fullText: string,\n    onBatch: NativeDiagnosticsBatchCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#anonymizer.diagnosticsStreamJson(fullText, onBatch, operators);\n  }\n\n  diagnostics_stream_json(\n    fullText: string,\n    onBatch: NativeDiagnosticsBatchCallback,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.diagnosticsStreamJson(fullText, onBatch, operators);\n  }\n\n  redactTextSummaryDiagnosticsJson(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.#anonymizer.redactStaticEntitiesSummaryDiagnosticsJson(\n      fullText,\n      operators,\n    );\n  }\n\n  summary_diagnostics_json(\n    fullText: string,\n    operators?: NativeOperatorConfig,\n  ): string {\n    return this.redactTextSummaryDiagnosticsJson(fullText, operators);\n  }\n}\n\nexport const encodeNativeSearchConfig = (\n  config: NativePreparedSearchConfig,\n): Uint8Array => new TextEncoder().encode(JSON.stringify(config));\n\nexport const encodeNativeSearchConfigInput = (\n  config: NativeSearchPackageInput,\n): Uint8Array => {\n  if (typeof config === \"string\") {\n    return new TextEncoder().encode(config);\n  }\n  if (config instanceof Uint8Array) {\n    return config;\n  }\n  return encodeNativeSearchConfig(config);\n};\n\nexport const getNativeBindingVersion = (\n  binding: NativeAnonymizeBinding,\n): string => binding.nativePackageVersion();\n\nexport const native_package_version = getNativeBindingVersion;\n\nexport const normalize_for_search = ({\n  binding,\n  text,\n}: NativeNormalizeOptions): string => binding.normalizeForSearch(text);\n\nexport const assertNativeBindingVersion = ({\n  binding,\n  expectedVersion,\n}: NativeBindingVersionOptions): void => {\n  const actualVersion = getNativeBindingVersion(binding);\n  if (actualVersion !== expectedVersion) {\n    throw new Error(\n      `Native anonymize binding version ${actualVersion} does not match ${expectedVersion}`,\n    );\n  }\n};\n\nexport const prepareNativeSearchPackage = ({\n  binding,\n  config,\n  compressed = false,\n}: NativeSearchPackageOptions): Uint8Array => {\n  const configBytes = encodeNativeSearchConfig(config);\n  return compressed\n    ? binding.prepareStaticSearchCompressedPackageBytes(configBytes)\n    : binding.prepareStaticSearchPackageBytes(configBytes);\n};\n\nexport const prepare_search_package = ({\n  binding,\n  config,\n  compressed = false,\n}: SharedNativeSearchPackageOptions): Uint8Array => {\n  const configBytes = encodeNativeSearchConfigInput(config);\n  return compressed\n    ? binding.prepareStaticSearchCompressedPackageBytes(configBytes)\n    : binding.prepareStaticSearchPackageBytes(configBytes);\n};\n\nexport const createNativeAnonymizerFromConfig = ({\n  binding,\n  config,\n}: NativeAnonymizerFromConfigOptions): PreparedNativeAnonymizer =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromConfigJsonBytes(\n      encodeNativeSearchConfig(config),\n    ),\n  );\n\nexport const createNativeAnonymizerFromPackage = ({\n  binding,\n  packageBytes,\n}: NativeAnonymizerFromPackageOptions): PreparedNativeAnonymizer =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromPreparedPackageBytes(packageBytes),\n  );\n\nexport const load_prepared_package = ({\n  binding,\n  packageBytes,\n}: SharedNativePreparedPackageOptions): PreparedNativeAnonymizer =>\n  createNativeAnonymizerFromPackage({ binding, packageBytes });\n\nexport const redact_text_json = ({\n  binding,\n  config,\n  fullText,\n  operators,\n}: SharedNativeRedactTextJsonOptions): string =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromConfigJsonBytes(\n      encodeNativeSearchConfigInput(config),\n    ),\n  ).redact_text_json(fullText, operators);\n\nexport const redact_text = ({\n  binding,\n  config,\n  fullText,\n  operators,\n}: SharedNativeRedactTextOptions): NativeStaticRedactionResult =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromConfigJsonBytes(\n      encodeNativeSearchConfigInput(config),\n    ),\n  ).redact_text(fullText, operators);\n\nexport const redact_text_stream_json = ({\n  binding,\n  config,\n  fullText,\n  operators,\n  onEvent,\n}: SharedNativeRedactTextStreamJsonOptions): string =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromConfigJsonBytes(\n      encodeNativeSearchConfigInput(config),\n    ),\n  ).redact_text_stream_json(fullText, onEvent, operators);\n\nexport const diagnostics_json = ({\n  binding,\n  config,\n  fullText,\n  operators,\n}: SharedNativeDiagnosticsJsonOptions): string =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromConfigJsonBytes(\n      encodeNativeSearchConfigInput(config),\n    ),\n  ).diagnostics_json(fullText, operators);\n\nexport const diagnostics_stream_json = ({\n  binding,\n  config,\n  fullText,\n  operators,\n  onBatch,\n}: SharedNativeDiagnosticsStreamJsonOptions): string =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromConfigJsonBytes(\n      encodeNativeSearchConfigInput(config),\n    ),\n  ).diagnostics_stream_json(fullText, onBatch, operators);\n\nexport const summary_diagnostics_json = ({\n  binding,\n  config,\n  fullText,\n  operators,\n}: SharedNativeDiagnosticsJsonOptions): string =>\n  new PreparedNativeAnonymizer(\n    binding.NativePreparedSearch.fromConfigJsonBytes(\n      encodeNativeSearchConfigInput(config),\n    ),\n  ).summary_diagnostics_json(fullText, operators);\n\nexport const createNativePipelineFromPackage = ({\n  binding,\n  packageBytes,\n}: NativePipelineFromPackageOptions): PreparedNativePipeline =>\n  new PreparedNativePipeline(\n    createNativeAnonymizerFromPackage({ binding, packageBytes }),\n  );\n\nexport const PreparedSearch = PreparedNativeAnonymizer;\nexport type PreparedSearch = PreparedNativeAnonymizer;\nexport const PreparedAnonymizer = PreparedNativeAnonymizer;\nexport type PreparedAnonymizer = PreparedNativeAnonymizer;\n\nconst toBindingOperatorConfig = (\n  config: NativeOperatorConfig | undefined,\n): NativeBindingOperatorConfig | undefined => {\n  if (!config) {\n    return undefined;\n  }\n  const bindingConfig: NativeBindingOperatorConfig = {};\n  if (config.operators !== undefined) {\n    bindingConfig.operators = config.operators;\n  }\n  if (config.redactString !== undefined) {\n    bindingConfig.redactString = config.redactString;\n  }\n  return bindingConfig;\n};\n\nconst toNativeStaticRedactionResult = (\n  result: NativeBindingStaticRedactionResult,\n): NativeStaticRedactionResult => ({\n  resolvedEntities: result.resolvedEntities.map(toNativePipelineEntity),\n  redaction: toNativeRedactionResult(result.redaction),\n});\n\nconst fromCanonicalStaticRedactionResult = (\n  result: CanonicalStaticRedactionResult,\n): NativeStaticRedactionResult => ({\n  resolvedEntities: result.resolved_entities.map(\n    ({ source_detail, provider_id, detection_id, ...entity }) => ({\n      ...entity,\n      ...(source_detail ? { sourceDetail: source_detail } : {}),\n      ...(provider_id ? { providerId: provider_id } : {}),\n      ...(detection_id ? { detectionId: detection_id } : {}),\n    }),\n  ),\n  redaction: {\n    redactedText: result.redaction.redacted_text,\n    redactionMap: toRedactionMap(result.redaction.redaction_map),\n    operatorMap: toOperatorMap(result.redaction.operator_map),\n    entityCount: result.redaction.entity_count,\n  },\n});\n\nconst toNativePipelineEntity = (\n  entity: NativeBindingPipelineEntity,\n): NativePipelineEntity => ({\n  start: entity.start,\n  end: entity.end,\n  label: entity.label,\n  text: entity.text,\n  score: entity.score,\n  source: entity.source,\n  ...(entity.sourceDetail ? { sourceDetail: entity.sourceDetail } : {}),\n  ...(entity.providerId ? { providerId: entity.providerId } : {}),\n  ...(entity.detectionId ? { detectionId: entity.detectionId } : {}),\n});\n\nconst toNativeRedactionResult = (\n  result: NativeBindingRedactionResult,\n): NativeRedactionResult => ({\n  redactedText: result.redactedText,\n  redactionMap: toRedactionMap(result.redactionMap),\n  operatorMap: toOperatorMap(result.operatorMap),\n  entityCount: result.entityCount,\n});\n\nconst toRedactionMap = (\n  entries: readonly NativeBindingRedactionEntry[],\n): Map<string, string> => {\n  const map = new Map<string, string>();\n  for (const entry of entries) {\n    map.set(entry.placeholder, entry.original);\n  }\n  return map;\n};\n\nconst toOperatorMap = (\n  entries: readonly NativeBindingOperatorEntry[],\n): Map<string, OperatorType> => {\n  const map = new Map<string, OperatorType>();\n  for (const entry of entries) {\n    map.set(entry.placeholder, entry.operator);\n  }\n  return map;\n};\n"],"mappings":";;AAwTA,MAAa,gCAAgC;CAC3C,MAAM;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,WAAW;EACT;EACA;EACA;EACA;EACA;CACF;CACA,UAAU;EACR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,SAAS;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,MAAM,CAAC,cAAc,QAAQ;AAC/B;AAgDA,MAAM,wBACJ,UAEC,OAAO,UAAU,YAAY,UAAU,QAAS,OAAO,UAAU;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