{"version":3,"file":"validate.js","names":[],"sources":["esm/platform/file-system/validate.js"],"sourcesContent":["import { FileMode } from \"./types\";\nconst modes = new Set(Object.values(FileMode));\nconst algorithms = /* @__PURE__ */ new Set([\"MD5\", \"SHA-1\", \"SHA-256\", \"SHA-384\", \"SHA-512\"]);\nconst encodings = /* @__PURE__ */ new Set([\"utf8\", \"base64\"]);\nfunction assertUri(uri, owner) {\n  if (typeof uri !== \"string\") throw new Error(`${owner}: expected a uri string`);\n  let parsed;\n  try {\n    parsed = new URL(uri);\n  } catch {\n    throw new Error(`${owner}: expected an absolute file uri`);\n  }\n  if (parsed.protocol !== \"file:\" && parsed.protocol !== \"opfs:\" || !parsed.pathname.startsWith(\"/\") || parsed.search || parsed.hash) {\n    throw new Error(`${owner}: expected an absolute file uri`);\n  }\n}\nfunction assertMode(mode, owner) {\n  if (typeof mode !== \"string\" || !modes.has(mode)) {\n    throw new Error(`${owner}: expected a FileMode`);\n  }\n}\nfunction assertEncoding(encoding, owner) {\n  if (typeof encoding !== \"string\" || !encodings.has(encoding)) {\n    throw new Error(`${owner}: expected encoding 'utf8' or 'base64'`);\n  }\n}\nfunction assertAlgorithm(algorithm, owner) {\n  if (typeof algorithm !== \"string\" || !algorithms.has(algorithm)) {\n    throw new Error(`${owner}: expected a digest algorithm`);\n  }\n}\nfunction assertByteLength(length, owner) {\n  if (typeof length !== \"number\" || !Number.isInteger(length) || length < 0) {\n    throw new Error(`${owner}: expected a nonnegative integer byte length`);\n  }\n}\nfunction assertOffset(offset, owner) {\n  if (typeof offset !== \"number\" || !Number.isFinite(offset) || offset < 0) {\n    throw new Error(`${owner}: expected a finite nonnegative offset`);\n  }\n}\nfunction assertName(name, owner) {\n  if (typeof name !== \"string\" || name === \"\" || name.includes(\"/\") || name === \".\" || name === \"..\") {\n    throw new Error(`${owner}: expected a single path segment`);\n  }\n}\nfunction assertWriteContent(content, owner) {\n  if (typeof content !== \"string\" && !(content instanceof Uint8Array) && !(content instanceof ArrayBuffer)) {\n    throw new Error(`${owner}: expected a string, Uint8Array or ArrayBuffer`);\n  }\n}\nfunction assertWriteBytes(bytes, owner) {\n  if (!(bytes instanceof Uint8Array) && !(bytes instanceof ArrayBuffer)) {\n    throw new Error(`${owner}: expected a Uint8Array or ArrayBuffer`);\n  }\n}\nfunction assertReadable(mode, verb) {\n  if (mode !== FileMode.ReadOnly && mode !== FileMode.ReadWrite) {\n    throw new Error(`${verb}: the handle is not readable`);\n  }\n}\nfunction assertWritable(mode, verb) {\n  if (mode === FileMode.ReadOnly) {\n    throw new Error(`${verb}: the handle is not writable`);\n  }\n}\nfunction assertDestination(destination, owner) {\n  if (typeof destination !== \"object\" || destination === null || typeof destination.uri !== \"string\") {\n    throw new Error(`${owner}: expected a File or Directory destination`);\n  }\n}\nexport {\n  assertAlgorithm,\n  assertByteLength,\n  assertDestination,\n  assertEncoding,\n  assertMode,\n  assertName,\n  assertOffset,\n  assertReadable,\n  assertUri,\n  assertWritable,\n  assertWriteBytes,\n  assertWriteContent\n};\n//# sourceMappingURL=validate.js.map\n"],"mappings":";;;AACA,MAAM,QAAQ,IAAI,IAAI,OAAO,OAAO,QAAQ,CAAC;AAC7C,MAAM,6BAA6B,IAAI,IAAI;CAAC;CAAO;CAAS;CAAW;CAAW;AAAS,CAAC;AAC5F,MAAM,4BAA4B,IAAI,IAAI,CAAC,QAAQ,QAAQ,CAAC;AAC5D,SAAS,UAAU,KAAK,OAAO;CAC7B,IAAI,OAAO,QAAQ,UAAU,MAAM,IAAI,MAAM,GAAG,MAAM,wBAAwB;CAC9E,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,GAAG;CACtB,QAAQ;EACN,MAAM,IAAI,MAAM,GAAG,MAAM,gCAAgC;CAC3D;CACA,IAAI,OAAO,aAAa,WAAW,OAAO,aAAa,WAAW,CAAC,OAAO,SAAS,WAAW,GAAG,KAAK,OAAO,UAAU,OAAO,MAAM;EAClI,MAAM,IAAI,MAAM,GAAG,MAAM,gCAAgC;CAC3D;A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