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C/D,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { SnapManifest, VirtualFile } from '@metamask/snaps-utils';\nimport { LocalSnapIdStruct, SnapIdPrefixes } from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { HttpOptions } from './http';\nimport { HttpLocation } from './http';\nimport type { SnapLocation } from './location';\n\nexport class LocalLocation implements SnapLocation {\n  readonly #http: HttpLocation;\n\n  constructor(url: URL, opts: HttpOptions = {}) {\n    assertStruct(url.toString(), LocalSnapIdStruct, 'Invalid Snap Id');\n    // TODO(ritave): Write deepMerge() which merges fetchOptions.\n    assert(\n      opts.fetchOptions === undefined,\n      'Currently adding fetch options to local: is unsupported.',\n    );\n\n    this.#http = new HttpLocation(\n      new URL(url.toString().slice(SnapIdPrefixes.local.length)),\n      { ...opts, fetchOptions: { cache: 'no-cache' } },\n    );\n  }\n\n  async manifest(): Promise<VirtualFile<SnapManifest>> {\n    const vfile = await this.#http.manifest();\n\n    return convertCanonical(vfile);\n  }\n\n  async fetch(path: string): Promise<VirtualFile> {\n    return convertCanonical(await this.#http.fetch(path));\n  }\n\n  get shouldAlwaysReload() {\n    return true;\n  }\n}\n\n/**\n * Converts vfiles with canonical `http:` paths into `local:` paths.\n *\n * @param vfile - The {@link VirtualFile} to convert.\n * @returns The same object with updated `.data.canonicalPath`.\n */\nfunction convertCanonical<Result>(\n  vfile: VirtualFile<Result>,\n): VirtualFile<Result> {\n  assert(vfile.data.canonicalPath !== undefined);\n  vfile.data.canonicalPath = `local:${vfile.data.canonicalPath}`;\n  return vfile;\n}\n"]}