UNPKG

@shirudo/base-error

Version:

A cross-environment base error class for TypeScript applications, designed for seamless use across Node.js, browsers, and edge runtimes.

1 lines 68.2 kB
{"version":3,"sources":["../../src/public-error/locale.ts","../../src/public-error/LocalizedMessageSet.ts","../../src/public-error/LocaleResolver.ts","../../src/utils/error-resolution.ts","../../src/utils/problem-validation.ts","../../src/public-error/PublicErrorCatalog.ts","../../src/public-error/project.ts","../../src/public-error/localize.ts","../../src/utils/json-safe.ts","../../src/public-error/toProblem.ts"],"names":[],"mappings":";;;;;;;;;;;;AAUO,SAAS,mBAAmB,GAAA,EAAiC;AAClE,EAAA,IAAI;AACF,IAAA,OAAO,IAAA,CAAK,mBAAA,CAAoB,GAAG,CAAA,CAAE,CAAC,CAAA;AAAA,EACxC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAeO,SAAS,gBAAgB,YAAA,EAAgC;AAC9D,EAAA,IAAI,KAAA,GAAQ,YAAA,CAAa,KAAA,CAAM,GAAG,CAAA;AAClC,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,OAAO,KAAA,CAAM,SAAS,CAAA,EAAG;AACvB,IAAA,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAG,CAAC,CAAA;AAC1B,IAAA,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AACzB,IAAA,IAAI,KAAA,CAAM,SAAS,CAAA,IAAM,KAAA,CAAM,MAAM,MAAA,GAAS,CAAC,CAAA,CAAa,MAAA,KAAW,CAAA,EAAG;AACxE,MAAA,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;;;AC1CA,IAAA,SAAA;AA6BO,IAAM,sBAAN,MAA0B;AAAA,EAMxB,YAAY,OAAA,EAAqC;AAFxD,IAAA,YAAA,CAAA,IAAA,EAAS,SAAA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F;AACA,EAAA,OAAO,SAAA;AACT;AAOA,SAAS,qBAAqB,SAAA,EAAiC;AAC7D,EAAA,IAAI,CAAC,gBAAA,CAAiB,SAAA,CAAU,MAAM,CAAA,EAAG;AACvC,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,4EAAA,EAA+E,MAAA,CAAO,SAAA,CAAU,MAAM,CAAC,CAAA,CAAA;AAAA,KACzG;AAAA,EACF;AACA,EAAA,IAAI,UAAU,IAAA,KAAS,MAAA,IAAa,CAAC,gBAAA,CAAiB,SAAA,CAAU,IAAI,CAAA,EAAG;AACrE,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,SAAA;AACT","file":"index.cjs","sourcesContent":["// Internal BCP 47 locale utilities used by the public-error localization\n// primitives (LocalizedMessageSet, resolveUserMessage). Not part of the public\n// surface.\n\n/**\n * Canonicalizes a single BCP 47 tag with `Intl.getCanonicalLocales`, or returns\n * `undefined` if it is structurally invalid. `Intl.getCanonicalLocales` throws a\n * `RangeError` on invalid input; this wraps that into the read-side \"invalid is\n * a miss\" policy. Write-side callers turn the `undefined` into a throw.\n */\nexport function canonicalizeLocale(tag: string): string | undefined {\n try {\n return Intl.getCanonicalLocales(tag)[0];\n } catch {\n return undefined;\n }\n}\n\n/**\n * The RFC 4647 lookup fallback chain for a canonical tag: the tag itself, then\n * progressively truncated from the right one subtag at a time. Whenever\n * truncation would leave a single-character singleton subtag (a `u` extension,\n * an `x` private-use marker, and so on) as the trailing subtag, that singleton\n * is removed as well before the next candidate is yielded.\n *\n * `zh-Hant-TW` -> `zh-Hant` -> `zh`\n * `de-DE-u-co-phonebk` -> `de-DE-u-co` -> `de-DE` -> `de`\n * `en-US-x-private` -> `en-US` -> `en`\n *\n * The input is assumed already canonical, so each truncation stays canonical.\n */\nexport function truncationChain(canonicalTag: string): string[] {\n let parts = canonicalTag.split(\"-\");\n const chain: string[] = [];\n while (parts.length > 0) {\n chain.push(parts.join(\"-\"));\n parts = parts.slice(0, -1);\n if (parts.length > 0 && (parts[parts.length - 1] as string).length === 1) {\n parts = parts.slice(0, -1);\n }\n }\n return chain;\n}\n","import { canonicalizeLocale } from \"./locale.js\";\n\n/**\n * Options for {@link LocalizedMessageSet}.\n */\nexport type LocalizedMessageSetOptions = {\n /**\n * The guaranteed-fallback locale, made explicit (no hidden default). After\n * canonicalization it must have an entry in `messages`.\n */\n readonly baseLocale: string;\n /**\n * Locale tag to message text. Keys are canonicalized (BCP 47); message\n * contents are preserved verbatim and never trimmed or modified.\n */\n readonly messages: Readonly<Record<string, string>>;\n};\n\n/**\n * An immutable, canonicalized set of localized messages keyed by BCP 47 locale.\n *\n * Construction enforces the write-side invariants: every key is canonicalized\n * with `Intl.getCanonicalLocales` (invalid tags throw), keys that collide after\n * canonicalization throw, every message must contain at least one non-whitespace\n * character, and an entry for the (canonical) `baseLocale` must exist. Lookups\n * are exact, canonical matches with no parent fallback: walking up a tag\n * (`de-DE` to `de`) and choosing between preferences is the resolver's job, not\n * the set's. On the read side an invalid requested tag is a miss, never a throw.\n */\nexport class LocalizedMessageSet {\n /** Canonical BCP 47 tag of the guaranteed-fallback locale. */\n public readonly baseLocale: string;\n\n readonly #messages: ReadonlyMap<string, string>;\n\n public constructor(options: LocalizedMessageSetOptions) {\n const baseLocale = canonicalizeOrThrow(options.baseLocale, \"baseLocale\");\n\n const canonical = new Map<string, string>();\n const originalKeyFor = new Map<string, string>();\n for (const [rawKey, text] of Object.entries(options.messages)) {\n const key = canonicalizeOrThrow(rawKey, `messages key \"${rawKey}\"`);\n const prior = originalKeyFor.get(key);\n if (prior !== undefined) {\n throw new Error(\n `LocalizedMessageSet: keys \"${prior}\" and \"${rawKey}\" both canonicalize to \"${key}\".`,\n );\n }\n if (text.trim().length === 0) {\n throw new Error(\n `LocalizedMessageSet: message for \"${rawKey}\" is empty or whitespace-only.`,\n );\n }\n originalKeyFor.set(key, rawKey);\n canonical.set(key, text);\n }\n\n if (!canonical.has(baseLocale)) {\n throw new Error(\n `LocalizedMessageSet: no message for baseLocale \"${baseLocale}\".`,\n );\n }\n\n this.baseLocale = baseLocale;\n this.#messages = canonical;\n }\n\n /**\n * Whether an exact (canonical) entry exists for `locale`. No parent fallback.\n * An invalid tag is a miss.\n */\n public has(locale: string): boolean {\n const key = canonicalizeLocale(locale);\n return key !== undefined && this.#messages.has(key);\n }\n\n /**\n * The exact (canonical) message for `locale`, or `undefined`. No parent\n * fallback. An invalid tag yields `undefined`.\n */\n public get(locale: string): string | undefined {\n const key = canonicalizeLocale(locale);\n return key === undefined ? undefined : this.#messages.get(key);\n }\n\n /**\n * Fast-path lookup for a key that is **already canonical**. Skips\n * canonicalization, so the caller is responsible for passing a canonical tag\n * (a non-canonical spelling misses). Used by the resolver, which already\n * canonicalizes once and walks canonical truncation tags; prefer {@link get}\n * for untrusted input.\n */\n public getCanonical(canonicalLocale: string): string | undefined {\n return this.#messages.get(canonicalLocale);\n }\n\n /** A copy of the entries as `[canonicalLocale, message]` pairs. */\n public entries(): ReadonlyArray<readonly [string, string]> {\n return [...this.#messages.entries()];\n }\n}\n\n/**\n * Canonicalizes a single BCP 47 tag, or throws if it is invalid. Used on the\n * write side, where an invalid tag is a construction error.\n */\nfunction canonicalizeOrThrow(tag: string, label: string): string {\n const canonical = canonicalizeLocale(tag);\n if (canonical === undefined) {\n throw new Error(\n `LocalizedMessageSet: invalid locale tag for ${label}: \"${tag}\".`,\n );\n }\n return canonical;\n}\n","import type { LocalizedMessageSet } from \"./LocalizedMessageSet.js\";\nimport { canonicalizeLocale, truncationChain } from \"./locale.js\";\n\n/**\n * The outcome of resolving a localized message: the text plus the locale that\n * actually matched and how. `matchedPreferenceIndex` and `match` are diagnostic\n * (tests, finding missing translations) and need not reach a public view.\n */\nexport type ResolvedUserMessage = {\n /** Canonical BCP 47 tag that actually matched. */\n locale: string;\n /** The message for that locale. */\n message: string;\n /**\n * Index into the supplied `locales` whose tag (or one of its parents)\n * matched. `undefined` only when the match came from the appended baseLocale.\n */\n matchedPreferenceIndex?: number;\n /**\n * `exact` when the canonical supplied tag matched, `parent` when one of its\n * truncations matched, `base` only when the appended baseLocale matched.\n */\n match: \"exact\" | \"parent\" | \"base\";\n};\n\n/**\n * Resolves a single localized message from `set` against an ordered list of\n * locale preferences (RFC 4647 lookup). For each supplied locale, in order, the\n * canonical tag and its truncation chain are tried; the first present entry\n * wins. Candidates are deduped preserving first-seen order, so a duplicate is\n * attributed to the earlier preference's chain. The baseLocale is consulted only\n * after every supplied preference, and a match against it alone is reported as\n * `base`. An invalid supplied tag is skipped (a miss), never a throw.\n *\n * This never returns `undefined`: a {@link LocalizedMessageSet} always has an\n * entry for its baseLocale, which is the guaranteed floor.\n */\nexport function resolveUserMessage(\n set: LocalizedMessageSet,\n options?: { locales?: readonly string[] },\n): ResolvedUserMessage {\n const locales = options?.locales ?? [];\n const seen = new Set<string>();\n\n for (const [index, raw] of locales.entries()) {\n const canonical = canonicalizeLocale(raw);\n if (canonical === undefined) continue;\n for (const [depth, tag] of truncationChain(canonical).entries()) {\n if (seen.has(tag)) continue;\n seen.add(tag);\n // Tags from the truncation chain are already canonical; skip re-canonicalizing.\n const message = set.getCanonical(tag);\n if (message !== undefined) {\n return {\n locale: tag,\n message,\n matchedPreferenceIndex: index,\n match: depth === 0 ? \"exact\" : \"parent\",\n };\n }\n }\n }\n\n // Floor: the baseLocale entry is guaranteed to exist by the set's invariant.\n const baseMessage = set.getCanonical(set.baseLocale);\n if (baseMessage !== undefined) {\n return { locale: set.baseLocale, message: baseMessage, match: \"base\" };\n }\n\n // Unreachable for a valid LocalizedMessageSet; guards against a bypassed invariant.\n throw new Error(\n `LocaleResolver: LocalizedMessageSet has no entry for its baseLocale \"${set.baseLocale}\".`,\n );\n}\n","/**\n * Shared error-to-descriptor resolution: exact `code` match, then predicate\n * matchers in registration order. Used by the public-error catalog, keeping the\n * matching semantics (and the throwing-getter and throwing-matcher handling) in\n * a single definition.\n */\n\n/** A predicate matcher paired with the value it resolves to. */\nexport type PredicateEntry<T> = {\n readonly match: (error: unknown) => boolean;\n readonly value: T;\n};\n\n/** The outcome of resolving an error by code then predicates. */\nexport type CodeResolution<T> =\n | {\n readonly found: true;\n readonly via: \"code\" | \"predicate\";\n readonly value: T;\n readonly matcherThrew: boolean;\n }\n | { readonly found: false; readonly matcherThrew: boolean };\n\n/**\n * The string `code` of an error-like object, or `undefined`. A throwing `code`\n * getter is treated as no code, so resolution stays total.\n */\nexport function readErrorCode(error: unknown): string | undefined {\n if (typeof error === \"object\" && error !== null && \"code\" in error) {\n try {\n const code = (error as { code: unknown }).code;\n if (typeof code === \"string\") return code;\n } catch {\n return undefined;\n }\n }\n return undefined;\n}\n\n/**\n * Resolves `error` to a value by exact `code` match first, then predicate\n * matchers in order. A matcher that throws is treated as a miss and sets\n * `matcherThrew`, so a caller can distinguish a genuine miss from a broken\n * matcher.\n */\nexport function resolveByCodeThenPredicate<T>(\n error: unknown,\n byCode: ReadonlyMap<string, T>,\n predicates: readonly PredicateEntry<T>[],\n): CodeResolution<T> {\n const code = readErrorCode(error);\n if (code !== undefined) {\n const value = byCode.get(code);\n if (value !== undefined) {\n return { found: true, via: \"code\", value, matcherThrew: false };\n }\n }\n\n let matcherThrew = false;\n for (const { match, value } of predicates) {\n try {\n if (match(error)) {\n return { found: true, via: \"predicate\", value, matcherThrew };\n }\n } catch {\n matcherThrew = true;\n }\n }\n\n return { found: false, matcherThrew };\n}\n","/**\n * Shared RFC 9457 / HTTP helpers. One definition of \"a valid problem status\", \"a\n * usable type/title string\", and the problem media type, reused across the\n * public-error pipeline (projection, catalog registration, and the transport\n * stage) so the rules cannot drift between them.\n */\n\n/** Media type for RFC 9457 JSON problem details. */\nexport const PROBLEM_DETAILS_JSON = \"application/problem+json\" as const;\n\n/** True for an integer HTTP status in the RFC 9457 range [100, 599]. */\nexport function isHttpStatusCode(value: unknown): value is number {\n return (\n typeof value === \"number\" &&\n Number.isInteger(value) &&\n value >= 100 &&\n value <= 599\n );\n}\n\n/** True for a non-empty string (an RFC 9457 `type` URI reference, or a code). */\nexport function isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.length > 0;\n}\n\n/** True for a non-negative integer, the delay-seconds form of `Retry-After`. */\nexport function isRetryAfterSeconds(value: unknown): value is number {\n return typeof value === \"number\" && Number.isInteger(value) && value >= 0;\n}\n","import type { LocalizedMessageSet } from \"./LocalizedMessageSet.js\";\nimport { resolveByCodeThenPredicate } from \"../utils/error-resolution.js\";\nimport type { PredicateEntry } from \"../utils/error-resolution.js\";\nimport {\n isHttpStatusCode,\n isNonEmptyString,\n} from \"../utils/problem-validation.js\";\nimport type {\n OnProject,\n ProjectionOutcome,\n PublicError,\n PublicErrorDescriptor,\n} from \"./types.js\";\n\n/** A descriptor with its types erased, as stored and returned by the catalog. */\ntype AnyDescriptor = PublicErrorDescriptor<unknown, unknown>;\n\n/**\n * The static wire metadata of a public code, as read by {@link toProblem}:\n * status, the RFC 9457 type, and the static developer-facing title.\n */\nexport type Transport = {\n readonly status: number;\n readonly type?: string;\n /** Static, developer-facing problem-type summary (RFC 9457 `title`). */\n readonly title?: string;\n};\n\n/** Transport plus the curated category, kept internal for the conflict check. */\ntype StoredTransport = Transport & { readonly category?: string };\n\n/**\n * The outcome of resolving an error against the catalog. `matcherThrew` lets a\n * caller distinguish a genuine miss from a broken matcher, mirroring the\n * presentation registry.\n */\nexport type CatalogResolution =\n | {\n readonly found: true;\n readonly via: \"code\" | \"predicate\";\n readonly descriptor: AnyDescriptor;\n readonly matcherThrew: boolean;\n }\n | { readonly found: false; readonly matcherThrew: boolean };\n\n/**\n * The single source of truth: one descriptor per public error code, addressable\n * both by the internal error `code`/predicate (for {@link project}) and by\n * public code (for {@link toProblem}'s transport facet and {@link localize}'s\n * messages). Unifies what used to be a registry (messages/details) plus a\n * separate adapter map (status/type), so the two cannot drift.\n *\n * Resolution order matches the presentation registry: exact internal `code`,\n * then predicate matchers in registration order, then a miss (the `fallback`).\n */\nexport class PublicErrorCatalog<TPublicCode extends string = string> {\n readonly #byCode = new Map<string, AnyDescriptor>();\n readonly #predicates: Array<PredicateEntry<AnyDescriptor>> = [];\n readonly #transportByPublicCode = new Map<string, StoredTransport>();\n readonly #messagesByPublicCode = new Map<string, LocalizedMessageSet>();\n readonly #onProject: OnProject | undefined;\n readonly #categories: ReadonlySet<string> | undefined;\n\n /** The generic descriptor used for any unmatched error. */\n public readonly fallback: AnyDescriptor;\n\n public constructor(options: {\n fallback: PublicErrorDescriptor<never, never, TPublicCode>;\n /** Fire-and-forget observer invoked once per {@link project} through this catalog. */\n onProject?: OnProject;\n /**\n * Optional closed vocabulary for the advisory public `category`. When given,\n * every descriptor's `category` must be a member, validated at registration\n * to prevent drift. `category` remains advisory: branch on `publicCode`.\n */\n categories?: readonly string[];\n }) {\n this.fallback = options.fallback as AnyDescriptor;\n this.#onProject = options.onProject;\n this.#categories =\n options.categories !== undefined\n ? new Set(options.categories)\n : undefined;\n this.#index(this.fallback);\n if (\n this.#categories !== undefined &&\n this.fallback.category === undefined\n ) {\n throw new Error(\n \"PublicErrorCatalog: the fallback must declare a category when categories are declared; it is the bucket a client uses for codes it does not recognize.\",\n );\n }\n }\n\n /**\n * Invokes the configured {@link OnProject} observer, swallowing any error so\n * telemetry can never break projection totality. Called by `project`.\n */\n public observeProjection(\n error: unknown,\n view: PublicError,\n outcome: ProjectionOutcome,\n ): void {\n if (this.#onProject === undefined) return;\n try {\n this.#onProject(error, view, outcome);\n } catch {\n // Telemetry must never break totality.\n }\n }\n\n /**\n * Registers a descriptor keyed by an exact internal error `code`. Returns a\n * catalog widened with the new public code, so a chain of registrations\n * accumulates the public-code union for end-to-end typing.\n */\n public registerByCode<\n TError = unknown,\n TDetails = never,\n const TNewCode extends string = string,\n >(\n code: string,\n descriptor: PublicErrorDescriptor<TError, TDetails, TNewCode>,\n ): PublicErrorCatalog<TPublicCode | TNewCode> {\n if (this.#byCode.has(code)) {\n throw new Error(\n `PublicErrorCatalog: code \"${code}\" is already registered.`,\n );\n }\n this.#byCode.set(code, descriptor as AnyDescriptor);\n this.#index(descriptor as AnyDescriptor);\n return this as unknown as PublicErrorCatalog<TPublicCode | TNewCode>;\n }\n\n /** Registers a descriptor guarded by a type-guard matcher, tried after code matches. */\n public register<\n TError,\n TDetails = never,\n const TNewCode extends string = string,\n >(entry: {\n match: (error: unknown) => error is TError;\n descriptor: PublicErrorDescriptor<TError, TDetails, TNewCode>;\n }): PublicErrorCatalog<TPublicCode | TNewCode> {\n this.#predicates.push({\n match: entry.match as (error: unknown) => boolean,\n value: entry.descriptor as AnyDescriptor,\n });\n this.#index(entry.descriptor as AnyDescriptor);\n return this as unknown as PublicErrorCatalog<TPublicCode | TNewCode>;\n }\n\n /** Resolves the descriptor for `error`, or a miss. */\n public resolve(error: unknown): CatalogResolution {\n const resolution = resolveByCodeThenPredicate(\n error,\n this.#byCode,\n this.#predicates,\n );\n return resolution.found\n ? {\n found: true,\n via: resolution.via,\n descriptor: resolution.value,\n matcherThrew: resolution.matcherThrew,\n }\n : { found: false, matcherThrew: resolution.matcherThrew };\n }\n\n /**\n * The static wire metadata (status/type/title) for a registered public code,\n * or `undefined` if the code is not registered (including the fallback, which\n * is indexed at construction). An unknown code is a foreign/stale view that\n * must not be paired with this catalog's fallback status; the caller decides.\n */\n public transportFor(publicCode: string): Transport | undefined {\n return this.#transportByPublicCode.get(publicCode);\n }\n\n /** The localized messages registered for a public code, if any. */\n public messagesFor(publicCode: string): LocalizedMessageSet | undefined {\n return this.#messagesByPublicCode.get(publicCode);\n }\n\n /**\n * Asserts that every code in `knownCodes` has a `registerByCode` descriptor.\n * An opt-in completeness check for the consumer's composition root.\n */\n public assertCoverage(knownCodes: readonly string[]): void {\n const missing = knownCodes.filter((code) => !this.#byCode.has(code));\n if (missing.length > 0) {\n throw new Error(\n `PublicErrorCatalog: no descriptor registered for code(s): ${missing.join(\", \")}.`,\n );\n }\n }\n\n #index(descriptor: AnyDescriptor): void {\n if (!isNonEmptyString(descriptor.publicCode)) {\n throw new Error(\n \"PublicErrorCatalog: descriptor has an empty or invalid publicCode.\",\n );\n }\n if (!isHttpStatusCode(descriptor.status)) {\n throw new Error(\n `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" has an invalid status; expected an integer in [100, 599], got ${String(descriptor.status)}.`,\n );\n }\n if (descriptor.type !== undefined && !isNonEmptyString(descriptor.type)) {\n throw new Error(\n `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" has an empty type.`,\n );\n }\n if (descriptor.category !== undefined) {\n if (!isNonEmptyString(descriptor.category)) {\n throw new Error(\n `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" has an empty category.`,\n );\n }\n if (\n this.#categories !== undefined &&\n !this.#categories.has(descriptor.category)\n ) {\n throw new Error(\n `PublicErrorCatalog: descriptor \"${descriptor.publicCode}\" uses category \"${descriptor.category}\" not in the declared categories.`,\n );\n }\n }\n const transport: StoredTransport = {\n status: descriptor.status,\n ...(descriptor.type !== undefined && { type: descriptor.type }),\n ...(descriptor.title !== undefined && { title: descriptor.title }),\n ...(descriptor.category !== undefined && {\n category: descriptor.category,\n }),\n };\n const prior = this.#transportByPublicCode.get(descriptor.publicCode);\n if (\n prior !== undefined &&\n (prior.status !== transport.status ||\n prior.type !== transport.type ||\n prior.title !== transport.title ||\n prior.category !== transport.category)\n ) {\n throw new Error(\n `PublicErrorCatalog: publicCode \"${descriptor.publicCode}\" mapped to conflicting transport (status, type, title, or category).`,\n );\n }\n this.#transportByPublicCode.set(descriptor.publicCode, transport);\n if (descriptor.userMessages !== undefined) {\n const priorMessages = this.#messagesByPublicCode.get(\n descriptor.publicCode,\n );\n if (\n priorMessages !== undefined &&\n !sameMessages(priorMessages, descriptor.userMessages)\n ) {\n throw new Error(\n `PublicErrorCatalog: publicCode \"${descriptor.publicCode}\" mapped to conflicting userMessages.`,\n );\n }\n this.#messagesByPublicCode.set(\n descriptor.publicCode,\n descriptor.userMessages,\n );\n }\n }\n}\n\n/**\n * Content equality for two message sets: same `baseLocale` and the same\n * locale-to-message entries. One public code is one user-facing message, so two\n * internal codes mapping to it must agree (or be different public codes).\n */\nfunction sameMessages(a: LocalizedMessageSet, b: LocalizedMessageSet): boolean {\n if (a === b) return true;\n if (a.baseLocale !== b.baseLocale) return false;\n const aEntries = a.entries();\n const bEntries = b.entries();\n if (aEntries.length !== bEntries.length) return false;\n const bByLocale = new Map(bEntries);\n for (const [locale, message] of aEntries) {\n if (bByLocale.get(locale) !== message) return false;\n }\n return true;\n}\n\n/** The union of public codes a {@link PublicErrorCatalog} can produce. */\nexport type PublicCodeOf<TCatalog> =\n TCatalog extends PublicErrorCatalog<infer TPublicCode> ? TPublicCode : never;\n\n/**\n * Builds a catalog whose public-code union is inferred from the fallback (and\n * grows as you chain `registerByCode`/`register`). Prefer this over `new` when\n * you want the UI to switch exhaustively on `code` at compile time; `new`\n * leaves the union as the open `string`.\n */\nexport function definePublicErrors<const TCode extends string>(options: {\n fallback: PublicErrorDescriptor<never, never, TCode>;\n onProject?: OnProject;\n categories?: readonly string[];\n}): PublicErrorCatalog<TCode> {\n return new PublicErrorCatalog<TCode>(options);\n}\n","import { isRetryAfterSeconds } from \"../utils/problem-validation.js\";\nimport type { PublicErrorCatalog } from \"./PublicErrorCatalog.js\";\nimport type {\n FieldFault,\n ProjectionOutcome,\n ProjectionStatus,\n PublicError,\n PublicErrorDescriptor,\n} from \"./types.js\";\n\n/**\n * Stage 1: curation as a security boundary. Turns an unknown technical error\n * into a curated, transport-neutral, message-free {@link PublicError}. Total\n * over `unknown`: an unmatched error degrades to the catalog's fallback rather\n * than leaking or throwing. Nothing of the error reaches the view automatically;\n * only declared (`category`/`retryable`) or explicitly projected\n * (`details`/`fields`) values appear, and a throwing projector is contained.\n *\n * Invokes the catalog's {@link OnProject} observer once, so a single place can\n * log the technical error alongside the emitted code and outcome.\n */\nexport function project<TPublicCode extends string>(\n catalog: PublicErrorCatalog<TPublicCode>,\n error: unknown,\n): PublicError<unknown, TPublicCode> {\n const resolution = catalog.resolve(error);\n const descriptor = resolution.found\n ? resolution.descriptor\n : catalog.fallback;\n const { view, projection } = projectCore(descriptor, error);\n\n const outcome: ProjectionOutcome = resolution.found\n ? { kind: \"matched\", via: resolution.via, projection }\n : {\n kind: \"fallback\",\n reason: resolution.matcherThrew ? \"matcher_failed\" : \"no_match\",\n projection,\n };\n catalog.observeProjection(error, view, outcome);\n\n return view as PublicError<unknown, TPublicCode>;\n}\n\n/**\n * Catalog-free projection against a single descriptor the caller already chose.\n * The same curation rules as {@link project}, without resolution or the\n * observer: use this when you bring your own matching, or have no catalog.\n */\nexport function projectWithDescriptor<TCode extends string>(\n descriptor: PublicErrorDescriptor<never, unknown, TCode>,\n error: unknown,\n): PublicError<unknown, TCode> {\n return projectCore(descriptor, error).view as PublicError<unknown, TCode>;\n}\n\nfunction projectCore(\n descriptor: PublicErrorDescriptor<never, unknown, string>,\n error: unknown,\n): { view: PublicError; projection: ProjectionStatus } {\n const retryable = resolveRetryable(descriptor, error);\n const retryAfter = resolveRetryAfter(descriptor, error);\n\n let failed = false;\n const onThrow = (): void => {\n failed = true;\n };\n const details =\n descriptor.projectDetails === undefined\n ? undefined\n : safeCall(descriptor.projectDetails, error, onThrow);\n const fields =\n descriptor.projectFields === undefined\n ? undefined\n : safeFields(descriptor.projectFields, error, onThrow);\n\n const hasProjector =\n descriptor.projectDetails !== undefined ||\n descriptor.projectFields !== undefined;\n const projection: ProjectionStatus = !hasProjector\n ? \"none\"\n : failed\n ? \"failed\"\n : \"succeeded\";\n\n const view: PublicError = Object.freeze({\n code: descriptor.publicCode,\n ...(descriptor.category !== undefined && { category: descriptor.category }),\n ...(retryable !== undefined && { retryable }),\n ...(retryAfter !== undefined && { retryAfter }),\n ...(details !== undefined && { details }),\n ...(fields !== undefined && fields.length > 0 && { fields }),\n });\n return { view, projection };\n}\n\nfunction resolveRetryable(\n descriptor: PublicErrorDescriptor<never, unknown, string>,\n error: unknown,\n): boolean | undefined {\n if (descriptor.projectRetryable !== undefined) {\n try {\n const projected = descriptor.projectRetryable(error as never);\n if (typeof projected === \"boolean\") return projected;\n } catch {\n // Fall through to the declared default; totality must hold.\n }\n }\n return descriptor.retryable;\n}\n\nfunction resolveRetryAfter(\n descriptor: PublicErrorDescriptor<never, unknown, string>,\n error: unknown,\n): number | undefined {\n if (descriptor.projectRetryAfter === undefined) return undefined;\n try {\n const seconds = descriptor.projectRetryAfter(error as never);\n return isRetryAfterSeconds(seconds) ? seconds : undefined;\n } catch {\n // A retry hint must never break projection totality.\n return undefined;\n }\n}\n\nfunction safeCall(\n fn: (error: never) => unknown,\n error: unknown,\n onThrow: () => void,\n): unknown {\n try {\n return fn(error as never);\n } catch {\n onThrow();\n return undefined;\n }\n}\n\nfunction safeFields(\n fn: (error: never) => readonly FieldFault[],\n error: unknown,\n onThrow: () => void,\n): readonly FieldFault[] | undefined {\n try {\n const fields = fn(error as never);\n // A non-array or a malformed entry is a projector bug, not \"no faults\":\n // drop the member and mark the projection failed for telemetry.\n if (!Array.isArray(fields) || !fields.every(isFieldFault)) {\n onThrow();\n return undefined;\n }\n // Curated copy: exactly { field, code } per fault, frozen. Strips foreign\n // extras a projector passed through by reference (a fault is a closed\n // shape, unlike details) and decouples the view from the projector's\n // objects, so later mutation of internal state cannot reach it.\n return Object.freeze(\n fields.map((fault) =>\n Object.freeze({ field: fault.field, code: fault.code }),\n ),\n );\n } catch {\n onThrow();\n return undefined;\n }\n}\n\nfunction isFieldFault(value: unknown): value is FieldFault {\n return (\n typeof value === \"