{"version":3,"file":"settingsWire.mjs","names":[],"sources":["../../../src/web/lib/settingsWire.ts"],"sourcesContent":["import type {\n  RepositorySettingsView,\n  SettingsBatchWriteRequest,\n  SettingsConfigView,\n  SettingsFileScope,\n  SettingsKeyScope,\n  SettingsOrigin,\n  SettingsWireScope,\n  SettingsWriteRequest,\n} from '../../types/settings';\n\n/** Host settings wire values use the host tier exclusively. */\nfunction rejectLegacyScope(value: unknown): void {\n  if (value === 'global') throw new Error(\"The 'global' scope was renamed to 'host'. Update this client.\");\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** The wire spelling of the file a write targets. */\nexport function settingsScopeToWire(scope: SettingsFileScope): SettingsWireScope {\n  return scope;\n}\n\n/** A write request as the wire takes it. */\nexport function settingsWriteToWire<T extends SettingsWriteRequest | SettingsBatchWriteRequest>(\n  request: T,\n): Omit<T, 'scope'> & { scope: SettingsWireScope } {\n  return { ...request, scope: settingsScopeToWire(request.scope) };\n}\n\nfunction originFromWire(value: unknown): SettingsOrigin {\n  rejectLegacyScope(value);\n  return value as SettingsOrigin;\n}\n\nfunction keyScopeFromWire(value: unknown): SettingsKeyScope {\n  rejectLegacyScope(value);\n  return value as SettingsKeyScope;\n}\n\nexport function settingsConfigViewFromWire(body: Record<string, unknown>): SettingsConfigView {\n  const values: SettingsConfigView['values'] = {};\n  if (isRecord(body.values)) {\n    for (const [key, entry] of Object.entries(body.values)) {\n      if (!isRecord(entry)) continue;\n      values[key] = {\n        ...(typeof entry.value === 'string' ? { value: entry.value } : {}),\n        origin: originFromWire(entry.origin),\n        scope: keyScopeFromWire(entry.scope),\n      };\n    }\n  }\n  const hashes = isRecord(body.hashes) ? body.hashes : {};\n  rejectLegacyScope('global' in hashes ? 'global' : undefined);\n  const text = (value: unknown): string | undefined => (typeof value === 'string' ? value : undefined);\n  return {\n    repoRoot: text(body.repoRoot) ?? '',\n    values,\n    hashes: {\n      host: text(hashes.host) ?? '',\n      repository: text(hashes.repository) ?? '',\n    },\n  };\n}\n\n/** Reads repository selection origins. */\nexport function repositorySettingsViewFromWire(body: Record<string, unknown>): RepositorySettingsView {\n  const view = body as unknown as RepositorySettingsView;\n  const selection = view.selection as RepositorySettingsView['selection'] | undefined;\n  if (!selection) return view;\n  return {\n    ...view,\n    selection: {\n      preset: {\n        ...selection.preset,\n        origin: originFromWire(selection.preset?.origin),\n      },\n      domains: {\n        ...selection.domains,\n        origin: originFromWire(selection.domains?.origin),\n      },\n      profile: {\n        ...selection.profile,\n        origin: originFromWire(selection.profile?.origin),\n      },\n    },\n  };\n}\n"],"mappings":";;AAYA,SAAS,kBAAkB,OAAsB;CAC/C,IAAI,UAAU,UAAU,MAAM,IAAI,MAAM,+DAA+D;AACzG;AAEA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;AAGA,SAAgB,oBAAoB,OAA6C;CAC/E,OAAO;AACT;;AAGA,SAAgB,oBACd,SACiD;CACjD,OAAO;EAAE,GAAG;EAAS,OAAO,oBAAoB,QAAQ,KAAK;CAAE;AACjE;AAEA,SAAS,eAAe,OAAgC;CACtD,kBAAkB,KAAK;CACvB,OAAO;AACT;AAEA,SAAS,iBAAiB,OAAkC;CAC1D,kBAAkB,KAAK;CACvB,OAAO;AACT;AAEA,SAAgB,2BAA2B,MAAmD;CAC5F,MAAM,SAAuC,CAAC;CAC9C,IAAI,SAAS,KAAK,MAAM,GACtB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,MAAM,GAAG;EACtD,IAAI,CAAC,SAAS,KAAK,GAAG;EACtB,OAAO,OAAO;GACZ,GAAI,OAAO,MAAM,UAAU,WAAW,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAChE,QAAQ,eAAe,MAAM,MAAM;GACnC,OAAO,iBAAiB,MAAM,KAAK;EACrC;CACF;CAEF,MAAM,SAAS,S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