UNPKG

@azure-utils/storybooks

Version:

Utils to upload and manage Storybooks via Azure Functions and storage.

186 lines (181 loc) 5.52 kB
const require_chunk = require('./chunk-DWy1uDak.cjs'); const __azure_data_tables = require_chunk.__toESM(require("@azure/data-tables")); //#region ../../node_modules/zod/v4/core/core.js /** A special constant with type `never` */ const NEVER = Object.freeze({ status: "aborted" }); function $constructor(name, initializer$1, params) { function init(inst, def) { var _a; Object.defineProperty(inst, "_zod", { value: inst._zod ?? {}, enumerable: false }); (_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set()); inst._zod.traits.add(name); initializer$1(inst, def); for (const k in _.prototype) if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) }); inst._zod.constr = _; inst._zod.def = def; } const Parent = params?.Parent ?? Object; class Definition extends Parent {} Object.defineProperty(Definition, "name", { value: name }); function _(def) { var _a; const inst = params?.Parent ? new Definition() : this; init(inst, def); (_a = inst._zod).deferred ?? (_a.deferred = []); for (const fn of inst._zod.deferred) fn(); return inst; } Object.defineProperty(_, "init", { value: init }); Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => { if (params?.Parent && inst instanceof params.Parent) return true; return inst?._zod?.traits?.has(name); } }); Object.defineProperty(_, "name", { value: name }); return _; } const $brand = Symbol("zod_brand"); //#endregion //#region ../../node_modules/zod/v4/core/util.js function jsonStringifyReplacer(_, value) { if (typeof value === "bigint") return value.toString(); return value; } function cached(getter) { const set = false; return { get value() { { const value = getter(); Object.defineProperty(this, "value", { value }); return value; } } }; } const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {}; const allowsEval = cached(() => { if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false; try { const F = Function; new F(""); return true; } catch (_) { return false; } }); const NUMBER_FORMAT_RANGES = { safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER], int32: [-2147483648, 2147483647], uint32: [0, 4294967295], float32: [-34028234663852886e22, 34028234663852886e22], float64: [-Number.MAX_VALUE, Number.MAX_VALUE] }; //#endregion //#region ../../node_modules/zod/v4/core/errors.js const initializer = (inst, def) => { inst.name = "$ZodError"; Object.defineProperty(inst, "_zod", { value: inst._zod, enumerable: false }); Object.defineProperty(inst, "issues", { value: def, enumerable: false }); inst.message = JSON.stringify(def, jsonStringifyReplacer, 2); Object.defineProperty(inst, "toString", { value: () => inst.message, enumerable: false }); }; const $ZodError = $constructor("$ZodError", initializer); const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error }); /** Format a ZodError as a human-readable string in the following form. * * From * * ```ts * ZodError { * issues: [ * { * expected: 'string', * code: 'invalid_type', * path: [ 'username' ], * message: 'Invalid input: expected string' * }, * { * expected: 'number', * code: 'invalid_type', * path: [ 'favoriteNumbers', 1 ], * message: 'Invalid input: expected number' * } * ]; * } * ``` * * to * * ``` * username * ✖ Expected number, received string at "username * favoriteNumbers[0] * ✖ Invalid input: expected number * ``` */ function toDotPath(_path) { const segs = []; const path = _path.map((seg) => typeof seg === "object" ? seg.key : seg); for (const seg of path) if (typeof seg === "number") segs.push(`[${seg}]`); else if (typeof seg === "symbol") segs.push(`[${JSON.stringify(String(seg))}]`); else if (/[^\w$]/.test(seg)) segs.push(`[${JSON.stringify(seg)}]`); else { if (segs.length) segs.push("."); segs.push(seg); } return segs.join(""); } function prettifyError(error) { const lines = []; const issues = [...error.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length); for (const issue of issues) { lines.push(`✖ ${issue.message}`); if (issue.path?.length) lines.push(` → at ${toDotPath(issue.path)}`); } return lines.join("\n"); } //#endregion //#region src/utils/error-utils.ts function parseErrorMessage(error) { console.log(error instanceof __azure_data_tables.RestError); return typeof error === "string" ? { errorMessage: error, errorType: "string" } : error instanceof __azure_data_tables.RestError ? parseAzureRestError(error) : error instanceof $ZodError ? { errorMessage: prettifyError(error), errorStatus: 400, errorType: "Zod" } : error instanceof Error || error && typeof error === "object" && "message" in error ? { errorMessage: String(error.message), errorType: "error" } : { errorMessage: String(error), errorType: "unknown" }; } function parseAzureRestError(error) { const details = error.details ?? {}; const message = details["odataError"]?.["message"]?.["value"] ?? details["errorMessage"] ?? error.message; return { errorMessage: `${details["errorCode"] ?? error.name} (${error.code ?? error.statusCode}): ${message}`, errorStatus: error.statusCode, errorType: "AzureRest" }; } //#endregion Object.defineProperty(exports, 'parseErrorMessage', { enumerable: true, get: function () { return parseErrorMessage; } });