{"version":3,"file":"TransactionSerializer.cjs","names":[],"sources":["../../../src/outbox/TransactionSerializer.ts"],"sourcesContent":["import type {\n  MutationValueCodec,\n  OfflineTransaction,\n  SerializedError,\n  SerializedMutation,\n  SerializedOfflineTransaction,\n} from '../types'\nimport type { Collection, PendingMutation } from '@tanstack/db'\n\nconst temporalConstructorNames = [\n  `Duration`,\n  `Instant`,\n  `PlainDate`,\n  `PlainDateTime`,\n  `PlainMonthDay`,\n  `PlainTime`,\n  `PlainYearMonth`,\n  `ZonedDateTime`,\n] as const\n\ntype TemporalConstructorName = (typeof temporalConstructorNames)[number]\ntype TemporalConstructor = {\n  from: (value: string) => unknown\n  prototype?: { toString?: () => string }\n}\n\nfunction getTemporalConstructorName(\n  type: unknown,\n): TemporalConstructorName | undefined {\n  if (typeof type !== `string` || !type.startsWith(`Temporal.`)) return\n  const constructorName = type.slice(\n    `Temporal.`.length,\n  ) as TemporalConstructorName\n  return temporalConstructorNames.includes(constructorName)\n    ? constructorName\n    : undefined\n}\n\nfunction requireTemporalConstructor(\n  name: TemporalConstructorName,\n): TemporalConstructor {\n  const constructor = (\n    globalThis as {\n      Temporal?: Partial<Record<TemporalConstructorName, TemporalConstructor>>\n    }\n  ).Temporal?.[name]\n  if (typeof constructor?.from !== `function`)\n    throw new MissingTemporalConstructorError(\n      `Missing global Temporal.${name} constructor`,\n    )\n  return constructor\n}\n\nfunction serializeTemporalValue(\n  value: object,\n  name: TemporalConstructorName,\n): string | undefined {\n  const constructor = requireTemporalConstructor(name)\n  const toString = constructor.prototype?.toString\n  if (typeof toString !== `function` || toString === Object.prototype.toString)\n    return\n  try {\n    const serialized = toString.call(value)\n    return typeof serialized === `string` ? serialized : undefined\n  } catch {\n    // Temporal prototype methods brand-check their receiver. A matching\n    // Symbol.toStringTag without the corresponding internal slots is user data.\n    return\n  }\n}\n\nfunction mayBeNativeScalar(value: object): boolean {\n  const prototype = Object.getPrototypeOf(value)\n  return (\n    prototype !== null &&\n    prototype !== Object.prototype &&\n    !Array.isArray(value)\n  )\n}\n\nexport class MissingTemporalConstructorError extends Error {}\n\nexport class MutationCodecError extends Error {}\n\nfunction setDataProperty(\n  object: Record<string, unknown>,\n  key: string,\n  value: unknown,\n): void {\n  if (key !== `__proto__`) object[key] = value\n  else\n    Object.defineProperty(object, key, {\n      value,\n      enumerable: true,\n      configurable: true,\n      writable: true,\n    })\n}\n\nfunction assertOutboxPhase(\n  phase: unknown,\n): asserts phase is `deletion-pending` | `rejection-pending` | undefined {\n  if (\n    phase !== undefined &&\n    phase !== `deletion-pending` &&\n    phase !== `rejection-pending`\n  )\n    throw new Error(`Unsupported transaction outbox phase`)\n}\n\nexport class TransactionSerializer {\n  private collections: Record<string, Collection<any, any, any, any, any>>\n  private collectionIdToKey: Map<string, string>\n\n  constructor(\n    collections: Record<string, Collection<any, any, any, any, any>>,\n    private readonly mutationCodec?: MutationValueCodec,\n  ) {\n    this.collections = collections\n    // Create reverse lookup from collection.id to registry key\n    this.collectionIdToKey = new Map()\n    for (const [key, collection] of Object.entries(collections)) {\n      this.collectionIdToKey.set(collection.id, key)\n    }\n  }\n\n  serialize(transaction: OfflineTransaction): string {\n    assertOutboxPhase(transaction.outboxPhase)\n    const serialized: SerializedOfflineTransaction = {\n      ...transaction,\n      valueEncoding: this.mutationCodec ? 4 : 3,\n      ...(this.mutationCodec\n        ? { mutationEncoding: this.mutationCodec.id }\n        : {}),\n      createdAt: transaction.createdAt.toISOString(),\n      metadata: this.serializeValue(transaction.metadata, `metadata`),\n      mutations: transaction.mutations.map((mutation) =>\n        this.serializeMutation(mutation),\n      ),\n    }\n    return JSON.stringify(serialized)\n  }\n\n  deserialize(data: string): OfflineTransaction {\n    // Old records retain their Date-marker meaning. New records also escape\n    // marker-shaped user objects; the encoding tag is not application metadata.\n    const {\n      valueEncoding,\n      mutationEncoding,\n      outboxPhase,\n      ...parsed\n    }: Omit<\n      SerializedOfflineTransaction,\n      `valueEncoding` | `mutationEncoding` | `outboxPhase`\n    > & {\n      valueEncoding?: unknown\n      mutationEncoding?: unknown\n      outboxPhase?: unknown\n    } = JSON.parse(data)\n    if (\n      valueEncoding !== undefined &&\n      valueEncoding !== 2 &&\n      valueEncoding !== 3 &&\n      valueEncoding !== 4\n    ) {\n      throw new Error(\n        `Unsupported transaction value encoding: ${valueEncoding}`,\n      )\n    }\n    if (\n      valueEncoding === 4 &&\n      (!this.mutationCodec || mutationEncoding !== this.mutationCodec.id)\n    ) {\n      throw new MutationCodecError(`Unsupported mutation codec`)\n    }\n    assertOutboxPhase(outboxPhase)\n\n    const createdAt = new Date(parsed.createdAt)\n    if (isNaN(createdAt.getTime())) {\n      throw new Error(\n        `Failed to deserialize transaction: invalid createdAt value \"${parsed.createdAt}\"`,\n      )\n    }\n\n    return {\n      ...parsed,\n      ...(outboxPhase === undefined ? {} : { outboxPhase }),\n      createdAt,\n      metadata:\n        valueEncoding === 3 || valueEncoding === 4\n          ? this.deserializeValue(parsed.metadata, 3)\n          : parsed.metadata,\n      mutations: parsed.mutations.map((mutationData) =>\n        this.deserializeMutation(mutationData, valueEncoding),\n      ),\n    }\n  }\n\n  private serializeMutation(mutation: PendingMutation): SerializedMutation {\n    const registryKey = this.collectionIdToKey.get(mutation.collection.id)\n    if (!registryKey) {\n      throw new Error(\n        `Collection with id ${mutation.collection.id} not found in registry`,\n      )\n    }\n\n    return {\n      globalKey: mutation.globalKey,\n      type: mutation.type,\n      modified: this.encodeMutationValue(mutation.modified),\n      original: this.encodeMutationValue(mutation.original),\n      changes: this.encodeMutationValue(mutation.changes),\n      collectionId: registryKey, // Store registry key instead of collection.id\n    }\n  }\n\n  private encodeMutationValue(value: unknown): unknown {\n    if (!this.mutationCodec) return this.serializeValue(value)\n    const encoded = this.mutationCodec.encode(value)\n    if (typeof encoded !== `string`)\n      throw new MutationCodecError(`Mutation codec encode must return a string`)\n    return encoded\n  }\n\n  private deserializeMutation(\n    data: SerializedMutation,\n    valueEncoding: 2 | 3 | 4 | undefined,\n  ): PendingMutation {\n    const collection = this.collections[data.collectionId]\n    if (!collection) {\n      throw new Error(`Collection with id ${data.collectionId} not found`)\n    }\n\n    const decode = (value: unknown): unknown => {\n      if (valueEncoding !== 4)\n        return this.deserializeValue(value, valueEncoding)\n      try {\n        if (typeof value !== `string`)\n          throw new TypeError(`Expected a mutation codec string`)\n        return this.mutationCodec!.decode(value)\n      } catch (cause) {\n        throw new MutationCodecError(`Failed to decode mutation codec`, {\n          cause,\n        })\n      }\n    }\n    const modified = decode(data.modified)\n\n    // Extract the key from the modified data using the collection's getKey function\n    // This is needed for optimistic state restoration to work correctly\n    const key = modified ? collection.getKeyFromItem(modified) : null\n\n    // Create a partial PendingMutation - we can't fully reconstruct it but\n    // we provide what we can. The executor will need to handle the rest.\n    return {\n      globalKey: data.globalKey,\n      type: data.type as any,\n      modified,\n      original: decode(data.original),\n      changes: decode(data.changes) ?? {},\n      collection,\n      // These fields would need to be reconstructed by the executor\n      mutationId: ``, // Will be regenerated\n      key,\n      metadata: undefined,\n      syncMetadata: {},\n      optimistic: true,\n      createdAt: new Date(),\n      updatedAt: new Date(),\n    } as PendingMutation\n  }\n\n  private serializeValue(\n    value: any,\n    jsonKey?: string | false,\n    ancestors = new WeakSet<object>(),\n  ): any {\n    if (value === null || typeof value !== `object`) return value\n\n    if (jsonKey !== false && value instanceof Date) {\n      return { __type: `Date`, value: value.toISOString() }\n    }\n\n    const temporalConstructorName =\n      jsonKey !== false && mayBeNativeScalar(value)\n        ? getTemporalConstructorName(value[Symbol.toStringTag])\n        : undefined\n    if (temporalConstructorName) {\n      const temporalValue = serializeTemporalValue(\n        value,\n        temporalConstructorName,\n      )\n      if (temporalValue !== undefined)\n        return {\n          __type: `Temporal`,\n          type: `Temporal.${temporalConstructorName}`,\n          value: temporalValue,\n        }\n    }\n\n    if (ancestors.has(value))\n      throw new TypeError(`Converting circular structure to JSON`)\n\n    const toJSON = typeof jsonKey === `string` && value.toJSON\n    if (typeof toJSON === `function`) {\n      const replacement = toJSON.call(value, jsonKey)\n      if (replacement === value) {\n        return this.serializeValue(replacement, false, ancestors)\n      }\n\n      ancestors.add(value)\n      try {\n        return this.serializeValue(replacement, false, ancestors)\n      } finally {\n        ancestors.delete(value)\n      }\n    }\n    if (\n      jsonKey !== undefined &&\n      (value instanceof Boolean ||\n        value instanceof BigInt ||\n        value instanceof Number ||\n        value instanceof String)\n    ) {\n      return value.valueOf()\n    }\n\n    ancestors.add(value)\n\n    const isArray = Array.isArray(value)\n    const result: any = isArray ? [] : {}\n    try {\n      if (isArray) {\n        const length = value.length\n        for (let index = 0; index < length; index++) {\n          const key = String(index)\n          setDataProperty(\n            result,\n            key,\n            this.serializeValue(\n              value[index],\n              jsonKey === undefined ? undefined : key,\n              ancestors,\n            ),\n          )\n        }\n      } else {\n        for (const key of Object.keys(value)) {\n          setDataProperty(\n            result,\n            key,\n            this.serializeValue(\n              value[key],\n              jsonKey === undefined ? undefined : key,\n              ancestors,\n            ),\n          )\n        }\n      }\n    } finally {\n      ancestors.delete(value)\n    }\n    if (jsonKey === false && typeof result.toJSON === `function`)\n      delete result.toJSON\n    return !isArray && Object.prototype.hasOwnProperty.call(value, `__type`)\n      ? { __type: `Object`, value: result }\n      : result\n  }\n\n  private deserializeValue(value: any, valueEncoding: 2 | 3 | undefined): any {\n    if (value === null || value === undefined) {\n      return value\n    }\n\n    if (typeof value === `object` && value.__type === `Date`) {\n      if (value.value === undefined || value.value === null) {\n        throw new Error(`Corrupted Date marker: missing value field`)\n      }\n      const date = new Date(value.value)\n      if (isNaN(date.getTime())) {\n        throw new Error(\n          `Failed to deserialize Date marker: invalid date value \"${value.value}\"`,\n        )\n      }\n      return date\n    }\n\n    if (\n      valueEncoding === 3 &&\n      typeof value === `object` &&\n      value.__type === `Temporal`\n    ) {\n      const constructorName = getTemporalConstructorName(value.type)\n      if (!constructorName)\n        throw new Error(`Corrupted Temporal marker: invalid type field`)\n      if (typeof value.value !== `string`)\n        throw new Error(`Corrupted Temporal marker: missing value field`)\n      return requireTemporalConstructor(constructorName).from(value.value)\n    }\n\n    if (typeof value === `object`) {\n      // Unwrap once, then decode only the fields: the object's own __type is data.\n      if (valueEncoding !== undefined && value.__type === `Object`) {\n        if (\n          value.value === null ||\n          typeof value.value !== `object` ||\n          Array.isArray(value.value)\n        ) {\n          throw new Error(`Corrupted Object marker: expected an object value`)\n        }\n        value = value.value\n      }\n      const result: any = Array.isArray(value) ? [] : {}\n      for (const key in value) {\n        if (Object.prototype.hasOwnProperty.call(value, key)) {\n          setDataProperty(\n            result,\n            key,\n            this.deserializeValue(value[key], valueEncoding),\n          )\n        }\n      }\n      return result\n    }\n\n    return value\n  }\n\n  serializeError(error: Error): SerializedError {\n    return {\n      name: error.name,\n      message: error.message,\n      stack: error.stack,\n    }\n  }\n\n  deserializeError(data: SerializedError): Error {\n    const error = new Error(data.message)\n    error.name = data.name\n    error.stack = data.stack\n    return error\n  }\n}\n"],"mappings":";AASA,IAAM,2BAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAQA,SAAS,2BACP,MACqC;CACrC,IAAI,OAAO,SAAS,YAAY,CAAC,KAAK,WAAW,WAAW,GAAG;CAC/D,MAAM,kBAAkB,KAAK,MAC3B,YAAY,MACd;CACA,OAAO,yBAAyB,SAAS,eAAe,IACpD,kBACA,KAAA;AACN;AAEA,SAAS,2BACP,MACqB;CACrB,MAAM,cACJ,WAGA,WAAW;CACb,IAAI,OAAO,aAAa,SAAS,YAC/B,MAAM,IAAI,gCACR,2BAA2B,KAAK,aAClC;CACF,OAAO;AACT;AAEA,SAAS,uBACP,OACA,MACoB;CAEpB,MAAM,WADc,2BAA2B,IAC9B,CAAA,CAAY,WAAW;CACxC,IAAI,OAAO,aAAa,cAAc,aAAa,OAAO,UAAU,UAClE;CACF,IAAI;EACF,MAAM,aAAa,SAAS,KAAK,KAAK;EACtC,OAAO,OAAO,eAAe,WAAW,aAAa,KAAA;CACvD,QAAQ;EAGN;CACF;AACF;AAEA,SAAS,kBAAkB,OAAwB;CACj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