zodbridge 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +361 -0
- package/dist/async/index.cjs +146 -0
- package/dist/async/index.cjs.map +1 -0
- package/dist/async/index.d.cts +49 -0
- package/dist/async/index.d.ts +49 -0
- package/dist/async/index.js +65 -0
- package/dist/async/index.js.map +1 -0
- package/dist/chunk-3HB2CM5G.js +213 -0
- package/dist/chunk-3HB2CM5G.js.map +1 -0
- package/dist/chunk-7DUCUUPF.js +274 -0
- package/dist/chunk-7DUCUUPF.js.map +1 -0
- package/dist/chunk-U3W6PGFE.js +241 -0
- package/dist/chunk-U3W6PGFE.js.map +1 -0
- package/dist/context-B0f9mQWu.d.cts +140 -0
- package/dist/context-B0f9mQWu.d.ts +140 -0
- package/dist/index.cjs +786 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +204 -0
- package/dist/index.d.ts +204 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/resolver/index.cjs +250 -0
- package/dist/resolver/index.cjs.map +1 -0
- package/dist/resolver/index.d.cts +101 -0
- package/dist/resolver/index.d.ts +101 -0
- package/dist/resolver/index.js +17 -0
- package/dist/resolver/index.js.map +1 -0
- package/dist/rules-msHkZDR8.d.cts +59 -0
- package/dist/rules-msHkZDR8.d.ts +59 -0
- package/dist/serialize/index.cjs +258 -0
- package/dist/serialize/index.cjs.map +1 -0
- package/dist/serialize/index.d.cts +84 -0
- package/dist/serialize/index.d.ts +84 -0
- package/dist/serialize/index.js +3 -0
- package/dist/serialize/index.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/map/rules.ts","../src/resolver/context.ts","../src/resolver/createResolver.ts","../src/map/case-convert.ts","../src/map/map-ops.ts","../src/map/createMap.ts","../src/map/map-views.ts","../src/serialize/json-types.ts","../src/serialize/codec.ts","../src/index.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ds (by JS type):\n * - `string` — rename: copy `source[ruleValue]` to the dest key. Auto-reversible.\n * - `(source) => value` — computed function, one-way (no reverse unless paired).\n * - `{ to, from }` — explicit both-directions, reversible.\n * - `FromResolver` — value pulled from a resolver graph (async path, Phase 5).\n */\n\n/** A function rule: derive a dest value from the whole source object. */\nexport type FnRule<S, V> = (source: S) => V;\n\n/** A reversible rule with explicit forward (`to`) and inverse (`from`) maps. */\nexport interface PairRule<S, V> {\n to: (source: S) => V;\n from: (value: V) => unknown;\n}\n\n/** Marker for a dest field resolved from a resolver graph (consumed by Phase 5). */\nexport interface FromResolver {\n readonly __kind: \"fromResolver\";\n readonly field: string;\n}\n\n/**\n * Default-value rule: read `source` (a source key, defaults to the dest key)\n * and fall back to `value` when the source is `undefined`. Reverse-safe: the\n * default is dropped on reverse and only the read key round-trips.\n */\nexport interface DefaultRule<V = unknown> {\n readonly __kind: \"default\";\n readonly value: V;\n readonly source?: string;\n}\n\n/** Any rule a dest key may be configured with. */\nexport type Rule<S = any, V = any> =\n | string\n | FnRule<S, V>\n | PairRule<S, V>\n | FromResolver\n | DefaultRule<V>;\n\n/** Build a {@link FromResolver} marker for `field` in the resolver graph. */\nexport function fromResolver(field: string): FromResolver {\n return { __kind: \"fromResolver\", field };\n}\n\n/**\n * Build a {@link DefaultRule}: use `source` (or the dest key) from the entity,\n * falling back to `value` when absent.\n */\nexport function withDefault<V>(value: V, source?: string): DefaultRule<V> {\n return { __kind: \"default\", value, source };\n}\n\n// --- type guards ---\n\nexport function isStringRule(rule: Rule): rule is string {\n return typeof rule === \"string\";\n}\n\nexport function isFromResolverRule(rule: Rule): rule is FromResolver {\n return (\n typeof rule === \"object\" &&\n rule !== null &&\n (rule as FromResolver).__kind === \"fromResolver\"\n );\n}\n\nexport function isPairRule(rule: Rule): rule is PairRule<any, any> {\n return (\n typeof rule === \"object\" &&\n rule !== null &&\n typeof (rule as PairRule<any, any>).to === \"function\" &&\n typeof (rule as PairRule<any, any>).from === \"function\"\n );\n}\n\nexport function isDefaultRule(rule: Rule): rule is DefaultRule {\n return (\n typeof rule === \"object\" &&\n rule !== null &&\n (rule as DefaultRule).__kind === \"default\"\n );\n}\n\nexport function isFnRule(rule: Rule): rule is FnRule<any, any> {\n return typeof rule === \"function\";\n}\n\n// --- prototype-pollution-safe dot-path helpers ---\n\n/** Path segments that, if written, could poison `Object.prototype`. */\nconst FORBIDDEN_KEYS = new Set([\"__proto__\", \"prototype\", \"constructor\"]);\n\nfunction isForbidden(key: string): boolean {\n return FORBIDDEN_KEYS.has(key);\n}\n\n/** Split a dot-path into segments. A plain key (no dot) yields a single segment. */\nexport function splitPath(path: string): string[] {\n return path.split(\".\");\n}\n\n/**\n * Read a nested value by dot-path. Returns `undefined` if any segment is\n * missing or if a segment is a forbidden prototype key (read is skipped, not\n * served from the prototype chain).\n */\nexport function getPath(source: unknown, path: string): unknown {\n let current: unknown = source;\n for (const segment of splitPath(path)) {\n if (isForbidden(segment)) return undefined;\n if (current === null || current === undefined) return undefined;\n if (typeof current !== \"object\") return undefined;\n if (!Object.prototype.hasOwnProperty.call(current, segment)) return undefined;\n current = (current as Record<string, unknown>)[segment];\n }\n return current;\n}\n\n/**\n * Write a nested value by dot-path, auto-vivifying intermediate objects.\n * Forbidden prototype keys at any segment are skipped entirely, so a hostile\n * `__proto__.isAdmin` path can never mutate `Object.prototype`.\n */\nexport function setPath(target: Record<string, unknown>, path: string, value: unknown): void {\n const segments = splitPath(path);\n let current: Record<string, unknown> = target;\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i] as string;\n if (isForbidden(segment)) return;\n if (i === segments.length - 1) {\n current[segment] = value;\n return;\n }\n const next = current[segment];\n if (typeof next !== \"object\" || next === null) {\n const fresh: Record<string, unknown> = {};\n current[segment] = fresh;\n current = fresh;\n } else {\n current = next as Record<string, unknown>;\n }\n }\n}\n","/**\n * Resolver-graph context: dependency-aware, memoizing, cycle-guarded lazy field\n * resolution. A faithful generalization of a `ContextResolver`-style engine.\n *\n * Invariants (do not \"optimize\" away):\n * (a) The promise for a field is stored in `cache` BEFORE the first await, so\n * concurrent `Promise.all` over a shared dep fires its resolver once.\n * (b) The touched-check (`cache` ∪ `inProgress`) serializes a field's re-entry,\n * breaking cycles.\n * (c) A resolver that THROWS rejects and evicts its cache entry — errors are\n * never coerced to `undefined` and never cached. Only a RETURNED `undefined`\n * is cached as a terminal value.\n * (d) `fallback` retries the calling field by re-invoking its resolver FUNCTION\n * directly, bypassing the step-1 cache short-circuit, so a momentarily\n * `undefined` field can still resolve once a dependency becomes available.\n * (e) The calling field for `fallback` is bound per resolver invocation (a\n * field-bound context), NOT read from shared instance state — so two\n * fallback-using resolvers running concurrently never contaminate each\n * other's retry target.\n */\nimport type { z } from \"zod\";\nimport { getPath } from \"../map/rules.js\";\n\n/** A resolver function for one field; may use the context to derive its value. */\nexport type ResolverFn<Fields, TAdapter, K extends keyof Fields> = (\n ctx: ResolverContext<Fields, TAdapter>,\n) => Fields[K] | undefined | Promise<Fields[K] | undefined>;\n\n/** Registry of per-field resolvers (declarative; not class methods). */\nexport type ResolverRegistry<Fields, TAdapter> = {\n [K in keyof Fields]?: ResolverFn<Fields, TAdapter, K>;\n};\n\n/**\n * Per-field Zod schemas used to validate resolver outputs at runtime. Built by\n * the schema-driven `createResolver` overload from `maps` + `fields`; a field\n * with no entry here is not validated (e.g. hand-written-`Fields` callers).\n */\nexport type ResolverSchemas<Fields> = Partial<Record<keyof Fields, z.ZodType>>;\n\n/** Construction config for a resolver graph. */\nexport interface ResolverConfig<Fields, TAdapter> {\n adapter: TAdapter;\n seed?: Partial<Fields>;\n resolvers?: ResolverRegistry<Fields, TAdapter>;\n /**\n * Optional per-field schemas. When present for a field, its resolver's output\n * is parsed (and unknown keys stripped) before caching; a parse failure\n * rejects `resolve` and evicts the entry. Seed values are NOT validated.\n */\n schemas?: ResolverSchemas<Fields>;\n /**\n * Optional observer fired after a field's resolver settles successfully (post\n * validation), for tracing/debugging. Never fired for seed/terminal values.\n * Throwing here does not affect resolution (the hook is best-effort).\n */\n onResolve?: (field: keyof Fields, value: unknown) => void;\n}\n\n/** The context object handed to every resolver and returned to callers. */\nexport interface ResolverContext<Fields, TAdapter> {\n readonly adapter: TAdapter;\n /** Resolve one field: cache -> seed -> resolver -> `undefined`. Memoized. */\n resolve<K extends keyof Fields>(field: K): Promise<Fields[K] | undefined>;\n /** Resolve several fields; returns only the requested keys. */\n resolveMany<K extends keyof Fields>(\n ...fields: K[]\n ): Promise<Partial<Pick<Fields, K>>>;\n /** Cache peek: the resolved value if present, else `undefined`. No I/O. */\n get<K extends keyof Fields>(field: K): Fields[K] | undefined;\n /** Pure nested peek into seed + cache for `field`. Never resolves, never I/O. */\n path<K extends keyof Fields>(field: K, keyPath: string[]): unknown;\n /** Resolve untouched `deps`, then retry the calling field's resolver fn. */\n fallback(deps: Array<keyof Fields>): Promise<unknown>;\n /**\n * Forget a field's cached value (and any settled peek) so the next `resolve`\n * re-runs its resolver. Use after a write to force a fresh fetch from the\n * adapter. Seed values are also dropped for the field. Returns `this`.\n */\n invalidate(...fields: Array<keyof Fields>): ResolverContext<Fields, TAdapter>;\n /** Invalidate then re-resolve `field` — a forced sync re-fetch from the adapter. */\n refresh<K extends keyof Fields>(field: K): Promise<Fields[K] | undefined>;\n}\n\n/** Shared empty ancestor set for top-level resolution chains (never mutated). */\nconst EMPTY_ANCESTORS: ReadonlySet<never> = new Set<never>();\n\ninterface Deferred<T> {\n promise: Promise<T>;\n resolve: (value: T) => void;\n reject: (reason: unknown) => void;\n}\n\nfunction defer<T>(): Deferred<T> {\n let resolve!: (value: T) => void;\n let reject!: (reason: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n return { promise, resolve, reject };\n}\n\nexport class GraphContext<Fields, TAdapter>\n implements ResolverContext<Fields, TAdapter>\n{\n readonly adapter: TAdapter;\n private readonly seed: Partial<Fields>;\n private readonly resolvers: ResolverRegistry<Fields, TAdapter>;\n private readonly schemas: ResolverSchemas<Fields>;\n private readonly onResolve?: (field: keyof Fields, value: unknown) => void;\n /** Durable promise-cache: every attempted field lives here. */\n private readonly cache = new Map<keyof Fields, Promise<unknown>>();\n /** Synchronously-readable settled values, for `get`/`path` peeks. */\n private readonly settled = new Map<keyof Fields, unknown>();\n /** Fields with an in-flight resolver; transient cycle guard. */\n private readonly inProgress = new Set<keyof Fields>();\n /** Fields explicitly invalidated: prefer the resolver over seed on next resolve. */\n private readonly invalidated = new Set<keyof Fields>();\n\n constructor(config: ResolverConfig<Fields, TAdapter>) {\n this.adapter = config.adapter;\n this.seed = config.seed ?? {};\n this.resolvers = config.resolvers ?? {};\n this.schemas = config.schemas ?? {};\n this.onResolve = config.onResolve;\n }\n\n /** Synchronous peek of seed first, then any settled resolved value. */\n private peek<K extends keyof Fields>(field: K): Fields[K] | undefined {\n const seeded = this.seed[field];\n if (seeded !== undefined) return seeded;\n return this.settled.get(field) as Fields[K] | undefined;\n }\n\n get<K extends keyof Fields>(field: K): Fields[K] | undefined {\n return this.peek(field);\n }\n\n path<K extends keyof Fields>(field: K, keyPath: string[]): unknown {\n const base = this.peek(field);\n if (base === undefined) return undefined;\n if (keyPath.length === 0) return base;\n return getPath(base, keyPath.join(\".\"));\n }\n\n /** Public entry: a fresh resolution chain with no ancestors. */\n resolve<K extends keyof Fields>(field: K): Promise<Fields[K] | undefined> {\n return this.resolveWithin(field, EMPTY_ANCESTORS);\n }\n\n /**\n * Resolve `field` within a chain whose currently-resolving fields are\n * `ancestors`. If `field` is itself an ancestor, this is a dependency cycle\n * (mutual A<->B, longer A->B->C->A, or self x->x): return `undefined` so the\n * caller (e.g. a `strategies` candidate) falls through to its next route,\n * instead of awaiting its own still-pending promise (which would deadlock).\n *\n * The ancestor check runs BEFORE the `cache.has` short-circuit, so a CONCURRENT\n * caller (a parallel `Promise.all` chain — `field` is in-flight but NOT its\n * ancestor) still receives the shared pending promise and dedups normally.\n */\n private resolveWithin<K extends keyof Fields>(\n field: K,\n ancestors: ReadonlySet<keyof Fields>,\n ): Promise<Fields[K] | undefined> {\n // (0) Cycle guard: `field` is being resolved above me in THIS chain.\n if (ancestors.has(field)) {\n return Promise.resolve(undefined) as Promise<Fields[K] | undefined>;\n }\n\n // (1) Already attempted -> return the (possibly pending) cached promise.\n const cached = this.cache.get(field);\n if (cached !== undefined) return cached as Promise<Fields[K] | undefined>;\n\n const resolver = this.resolvers[field];\n // After an explicit invalidate, prefer the resolver over seed so `refresh`\n // pulls fresh adapter data instead of the stale seed value.\n const preferResolver = this.invalidated.has(field) && resolver !== undefined;\n\n // (2) Seed yields a value -> cache a resolved promise.\n const seeded = this.seed[field];\n if (seeded !== undefined && !preferResolver) {\n const p = Promise.resolve(seeded) as Promise<Fields[K] | undefined>;\n this.cache.set(field, p);\n return p;\n }\n\n // (3) A resolver exists -> store an in-flight promise BEFORE awaiting.\n if (resolver) {\n this.invalidated.delete(field);\n const deferred = defer<Fields[K] | undefined>();\n this.cache.set(field, deferred.promise);\n this.inProgress.add(field);\n // Child chain = my ancestors + me, so a transitive re-entry of `field` trips (0).\n const childAncestors = new Set(ancestors).add(field);\n this.runResolver(field, resolver, deferred, childAncestors);\n return deferred.promise;\n }\n\n // (4) No seed, no resolver -> terminal `undefined`.\n const p = Promise.resolve(undefined) as Promise<Fields[K] | undefined>;\n this.cache.set(field, p);\n return p;\n }\n\n /**\n * A context bound to `self` and the chain's `ancestors`: identical to the\n * top-level context except `resolve`/`fallback` carry the chain so cycles\n * break (see {@link resolveWithin}) and `fallback` retries the right field.\n * Binding per invocation (not shared instance state) keeps concurrent\n * resolutions from contaminating each other.\n */\n private boundContext<K extends keyof Fields>(\n self: K,\n ancestors: ReadonlySet<keyof Fields>,\n ): ResolverContext<Fields, TAdapter> {\n return {\n adapter: this.adapter,\n resolve: (field) => this.resolveWithin(field, ancestors),\n resolveMany: (...fields) => this.resolveMany(...fields),\n get: (field) => this.get(field),\n path: (field, keyPath) => this.path(field, keyPath),\n fallback: (deps) => this.fallbackFor(self, deps, ancestors),\n invalidate: (...fields) => this.invalidate(...fields),\n refresh: (field) => this.refresh(field),\n };\n }\n\n invalidate(...fields: Array<keyof Fields>): ResolverContext<Fields, TAdapter> {\n for (const field of fields) {\n this.cache.delete(field);\n this.settled.delete(field);\n // Only flag fields that have a resolver to prefer — a seed-only field has\n // nothing to prefer over seed, so flagging it would just leak a dead key.\n if (this.resolvers[field] !== undefined) this.invalidated.add(field);\n }\n return this;\n }\n\n refresh<K extends keyof Fields>(field: K): Promise<Fields[K] | undefined> {\n this.invalidate(field);\n return this.resolve(field);\n }\n\n /** Fire the best-effort `onResolve` observer; never let it break resolution. */\n private emitResolved(field: keyof Fields, value: unknown): void {\n if (!this.onResolve) return;\n try {\n this.onResolve(field, value);\n } catch {\n // observer is diagnostic only — swallow.\n }\n }\n\n private runResolver<K extends keyof Fields>(\n field: K,\n resolver: ResolverFn<Fields, TAdapter, K>,\n deferred: Deferred<Fields[K] | undefined>,\n ancestors: ReadonlySet<keyof Fields>,\n ): void {\n const ctx = this.boundContext(field, ancestors);\n Promise.resolve()\n .then(() => resolver(ctx))\n .then((value) => this.validate(field, value))\n .then(\n (value) => {\n this.settled.set(field, value);\n // Settled fields are guarded by the durable cache; drop the transient flag.\n this.inProgress.delete(field);\n this.emitResolved(field, value);\n deferred.resolve(value);\n },\n (error) => {\n // (c) Throw/validation-failure -> evict so a later retry can re-run;\n // never cache as undefined, never serve unvalidated data.\n this.cache.delete(field);\n this.inProgress.delete(field);\n deferred.reject(error);\n },\n );\n }\n\n /**\n * Validate a resolver's output against its field schema (if any). A defined\n * value is parsed (unknown keys stripped); a parse failure throws the ZodError,\n * which the reject branch turns into an eviction. `undefined` is the forgiving\n * absence terminal and is never validated.\n */\n private async validate<K extends keyof Fields>(\n field: K,\n value: Fields[K] | undefined,\n ): Promise<Fields[K] | undefined> {\n const schema = this.schemas[field];\n if (schema === undefined || value === undefined) return value;\n return (await schema.parseAsync(value)) as Fields[K];\n }\n\n /** Resolve untouched `deps`, then retry `self`'s resolver if any produced a value. */\n private async fallbackFor<K extends keyof Fields>(\n self: K,\n deps: Array<keyof Fields>,\n ancestors: ReadonlySet<keyof Fields>,\n ): Promise<unknown> {\n let resolvedAny = false;\n for (const dep of deps) {\n // (b) touched-check: skip deps already cached or in progress. This is\n // `fallback`'s own cycle guard and is intentionally SEPARATE from\n // `resolveWithin`'s step-0 ancestor check (which guards direct `c.resolve`\n // re-entry) — both entry points need their own guard; do not merge them.\n if (this.cache.has(dep) || this.inProgress.has(dep)) continue;\n const value = await this.resolveWithin(dep, ancestors);\n if (value) resolvedAny = true;\n }\n if (!resolvedAny) return undefined;\n // (d) Retry the calling field by re-invoking its resolver fn directly with a\n // context still bound to `self` (so nested fallbacks retry the right field).\n // `fallbackFor` is only reachable from a field-bound context built in\n // runResolver, which requires a resolver — so `self`'s resolver exists.\n const resolver = this.resolvers[self] as ResolverFn<Fields, TAdapter, K>;\n return resolver(this.boundContext(self, ancestors));\n }\n\n /**\n * Top-level `fallback` has no calling field, so there is nothing to retry.\n * Resolvers always receive a field-bound context whose `fallback` does retry;\n * this entry exists only to satisfy the public {@link ResolverContext} shape.\n */\n fallback(_deps: Array<keyof Fields>): Promise<unknown> {\n return Promise.resolve(undefined);\n }\n\n async resolveMany<K extends keyof Fields>(\n ...fields: K[]\n ): Promise<Partial<Pick<Fields, K>>> {\n // No reset needed: each field clears its own inProgress flag when it settles,\n // and the durable cache is the real guard — safe under concurrent callers.\n const out: Partial<Pick<Fields, K>> = {};\n for (const field of fields) {\n const value = await this.resolve(field);\n if (value !== undefined) out[field] = value as Fields[K];\n }\n return out;\n }\n}\n","/**\n * `createResolver` — factory for a dependency-aware, memoizing, cycle-guarded\n * resolver graph with an injected generic fetch adapter. See {@link GraphContext}\n * for the resolution algorithm and its invariants.\n *\n * Two call styles:\n * 1. **Hand-written fields** — `createResolver<Fields, Adapter>({ resolvers, ... })`.\n * Fields are statically typed; resolver outputs are NOT validated at runtime.\n * 2. **Schema-driven** — `createResolver({ maps, fields?, resolvers, ... })`.\n * Resolvable fields and their Zod schemas are derived from `createMap`\n * instances (`maps`) plus an optional scalar-dep `fields` object; each\n * resolver's output is parsed (unknown keys stripped) before caching.\n *\n * Field names that collide with JavaScript object internals (`__proto__`,\n * `constructor`, `prototype`) are not supported — the `resolvers`/`seed`\n * registries are plain objects, so such keys do not register as own properties.\n * Use ordinary identifier field names.\n */\nimport type { z } from \"zod\";\nimport {\n GraphContext,\n type ResolverConfig,\n type ResolverContext,\n type ResolverRegistry,\n type ResolverSchemas,\n} from \"./context.js\";\n\n/** Minimal structural view of a `createMap` instance (avoids a hard dep cycle). */\nexport interface SchemaSource<T = unknown> {\n readonly schema: z.ZodType<T>;\n}\n\n/** Field set derived from a map of {@link SchemaSource}s (each map's inferred DTO). */\ntype FieldsFromMaps<M extends Record<string, SchemaSource>> = {\n [K in keyof M]: M[K] extends SchemaSource<infer T> ? T : never;\n};\n\n/** Field set derived from an optional scalar `fields` object schema. */\ntype FieldsFromSchema<F extends z.ZodObject<any> | undefined> = F extends z.ZodObject<any>\n ? z.infer<F>\n : Record<never, never>;\n\n/** Merged resolvable field set: mapped DTO fields + scalar dep fields. */\nexport type SchemaResolverFields<\n M extends Record<string, SchemaSource>,\n F extends z.ZodObject<any> | undefined,\n> = FieldsFromMaps<M> & FieldsFromSchema<F>;\n\n/** Config for the schema-driven `createResolver` overload. */\nexport interface SchemaResolverConfig<\n M extends Record<string, SchemaSource>,\n F extends z.ZodObject<any> | undefined,\n TAdapter,\n> {\n adapter: TAdapter;\n /** `createMap` instances whose dest schemas define validated DTO fields. */\n maps: M;\n /** Optional object schema for scalar dependency fields (e.g. `orgId`). */\n fields?: F;\n seed?: Partial<SchemaResolverFields<M, F>>;\n resolvers?: ResolverRegistry<SchemaResolverFields<M, F>, TAdapter>;\n}\n\n// Hand-written-fields overload (validation off unless schemas supplied).\nexport function createResolver<Fields, TAdapter>(\n config: ResolverConfig<Fields, TAdapter>,\n): ResolverContext<Fields, TAdapter>;\n\n// Schema-driven overload: fields inferred from maps + scalar fields; outputs validated.\nexport function createResolver<\n M extends Record<string, SchemaSource>,\n TAdapter,\n F extends z.ZodObject<any> | undefined = undefined,\n>(\n config: SchemaResolverConfig<M, F, TAdapter>,\n): ResolverContext<SchemaResolverFields<M, F>, TAdapter>;\n\nexport function createResolver(\n config: ResolverConfig<unknown, unknown> & {\n maps?: Record<string, SchemaSource>;\n fields?: z.ZodObject<any>;\n },\n): ResolverContext<unknown, unknown> {\n const schemas = config.maps ? buildSchemas(config.maps, config.fields) : config.schemas;\n return new GraphContext<unknown, unknown>({\n adapter: config.adapter,\n seed: config.seed,\n resolvers: config.resolvers,\n schemas,\n onResolve: config.onResolve,\n });\n}\n\n/** Build the runtime `field -> Zod schema` lookup from maps + scalar fields. */\nfunction buildSchemas(\n maps: Record<string, SchemaSource>,\n fields: z.ZodObject<any> | undefined,\n): ResolverSchemas<Record<string, unknown>> {\n // Null-prototype map so the schema lookup is a clean own-key store. (Field\n // names that collide with object internals like `__proto__` are not a\n // supported case anyway — see the createResolver docs — but a null proto\n // keeps this lookup itself free of prototype-chain surprises.)\n const out: Record<string, z.ZodType> = Object.create(null);\n for (const key of Object.keys(maps)) {\n out[key] = maps[key]!.schema;\n }\n if (fields) {\n const shape = fields.shape as Record<string, z.ZodType>;\n for (const key of Object.keys(shape)) {\n out[key] = shape[key]!;\n }\n }\n return out;\n}\n\nexport type { ResolverConfig, ResolverContext };\nexport type { ResolverFn, ResolverRegistry, ResolverSchemas } from \"./context.js\";\n","/**\n * Recursive object-key case conversion. `toSnakeCase`/`toCamelCase` re-case ALL\n * property keys of a value to the target case regardless of the input keys'\n * original casing (snake, camel, Pascal, kebab, SCREAMING_SNAKE all normalize).\n *\n * Only KEYS change. Values pass through untouched; recursion descends plain\n * objects and arrays only — Dates, Maps, Sets, class instances, and primitives\n * are returned as-is so their internal data is never reshaped.\n */\n\n/** Keys that would poison `Object.prototype` — never emitted as output keys. */\nconst FORBIDDEN_KEYS = new Set([\"__proto__\", \"prototype\", \"constructor\"]);\n\n/**\n * Split an identifier into lowercase word tokens, the casing-neutral form every\n * target case is rebuilt from. Handles delimiters (`_`, `-`, space), camel/Pascal\n * humps, acronym runs (`HTTPServer` -> `http`,`server`), and digit groups.\n */\nexport function splitWords(key: string): string[] {\n return (\n key\n // acronym followed by a word: \"HTTPServer\" -> \"HTTP Server\"\n .replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n // lower/digit followed by upper: \"fooBar\"/\"foo2Bar\" -> \"foo Bar\"\n .replace(/([a-z\\d])([A-Z])/g, \"$1 $2\")\n // letter followed by digit group: \"v2\" -> \"v 2\"\n .replace(/([A-Za-z])(\\d)/g, \"$1 $2\")\n // any non-alphanumeric run is a delimiter\n .split(/[^A-Za-z0-9]+/)\n .filter((w) => w.length > 0)\n .map((w) => w.toLowerCase())\n );\n}\n\n/** Convert a single key to `snake_case`; leave unconvertible keys untouched. */\nexport function toSnakeKey(key: string): string {\n const words = splitWords(key);\n // Nothing tokenizable (e.g. \"$$$\", \"_\") -> leave the key as-is rather than\n // collapsing it to \"\" and losing the property.\n if (words.length === 0) return key;\n return words.join(\"_\");\n}\n\n/** Convert a single key to `camelCase`; leave unconvertible keys untouched. */\nexport function toCamelKey(key: string): string {\n const words = splitWords(key);\n if (words.length === 0) return key;\n return words\n .map((word, i) => (i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)))\n .join(\"\");\n}\n\n/** True only for plain objects (own data records), not Date/Map/Set/class instances. */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\nfunction convert(value: unknown, keyFn: (key: string) => string): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => convert(item, keyFn));\n }\n if (isPlainObject(value)) {\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n const converted = keyFn(key);\n if (FORBIDDEN_KEYS.has(converted)) continue;\n out[converted] = convert(value[key], keyFn);\n }\n return out;\n }\n // Primitives, Date, Map, Set, class instances: returned unchanged.\n return value;\n}\n\n// --- type-level key re-casing ---\n//\n// These mapped types model the COMMON case — camelCase/PascalCase <-> snake_case\n// on plain identifier keys (`firstName` <-> `first_name`). They intentionally do\n// NOT replicate the full runtime tokenizer: acronym grouping (`HTTPServer`),\n// digit boundaries, kebab/space delimiters, and multiple leading underscores\n// (`__id`) can yield a type that differs from the runtime key. For normal DTO\n// keys the type is exact; for these exotic cases the runtime is authoritative.\n// Values are preserved (only keys change), and Date/Map/Set/array/primitive are\n// passed through untouched.\n\n/** Insert `_` before each interior uppercase letter, then lowercase. */\ntype CamelToSnake<S extends string> = S extends `${infer Head}${infer Tail}`\n ? Head extends Uppercase<Head>\n ? Head extends Lowercase<Head>\n ? `${Head}${CamelToSnake<Tail>}` // digit/symbol: no separator\n : `_${Lowercase<Head>}${CamelToSnake<Tail>}`\n : `${Head}${CamelToSnake<Tail>}`\n : S;\n\n/** Drop a single leading `_` produced when the first letter was uppercase. */\ntype StripLeadingUnderscore<S extends string> = S extends `_${infer Rest}` ? Rest : S;\n\ntype SnakeKey<S extends string> = StripLeadingUnderscore<CamelToSnake<S>>;\n\n/** Collapse `_x` groups into `X` (snake/kebab -> camelCase). */\ntype SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}`\n ? `${Head}${Capitalize<SnakeToCamel<Tail>>}`\n : S extends `${infer Head}-${infer Tail}`\n ? `${Head}${Capitalize<SnakeToCamel<Tail>>}`\n : S;\n\n/** Public type of {@link toSnakeCase}: keys recursively snake_cased. */\nexport type SnakeCased<T> = T extends Array<infer E>\n ? Array<SnakeCased<E>>\n : T extends Date | Map<unknown, unknown> | Set<unknown>\n ? T\n : T extends object\n ? { [K in keyof T as K extends string ? SnakeKey<K> : K]: SnakeCased<T[K]> }\n : T;\n\n/** Public type of {@link toCamelCase}: keys recursively camelCased. */\nexport type CamelCased<T> = T extends Array<infer E>\n ? Array<CamelCased<E>>\n : T extends Date | Map<unknown, unknown> | Set<unknown>\n ? T\n : T extends object\n ? { [K in keyof T as K extends string ? SnakeToCamel<K> : K]: CamelCased<T[K]> }\n : T;\n\n/**\n * Recursively re-case all property keys of `value` to `snake_case`. The return\n * type maps keys for the common identifier case (see {@link SnakeCased}).\n */\nexport function toSnakeCase<T>(value: T): SnakeCased<T> {\n return convert(value, toSnakeKey) as SnakeCased<T>;\n}\n\n/**\n * Recursively re-case all property keys of `value` to `camelCase`. The return\n * type maps keys for the common identifier case (see {@link CamelCased}).\n */\nexport function toCamelCase<T>(value: T): CamelCased<T> {\n return convert(value, toCamelKey) as CamelCased<T>;\n}\n\nconst capitalize = (word: string): string =>\n word.charAt(0).toUpperCase() + word.slice(1);\n\n/** Convert a single key to `kebab-case`; leave unconvertible keys untouched. */\nexport function toKebabKey(key: string): string {\n const words = splitWords(key);\n if (words.length === 0) return key;\n return words.join(\"-\");\n}\n\n/** Convert a single key to `PascalCase`; leave unconvertible keys untouched. */\nexport function toPascalKey(key: string): string {\n const words = splitWords(key);\n if (words.length === 0) return key;\n return words.map(capitalize).join(\"\");\n}\n\n/** Convert a single key to `CONSTANT_CASE`; leave unconvertible keys untouched. */\nexport function toConstantKey(key: string): string {\n const words = splitWords(key);\n if (words.length === 0) return key;\n return words.join(\"_\").toUpperCase();\n}\n\n/** Recursively re-case all property keys of `value` to `kebab-case`. */\nexport function toKebabCase<T = unknown>(value: T): T {\n return convert(value, toKebabKey) as T;\n}\n\n/** Recursively re-case all property keys of `value` to `PascalCase`. */\nexport function toPascalCase<T = unknown>(value: T): T {\n return convert(value, toPascalKey) as T;\n}\n\n/** Recursively re-case all property keys of `value` to `CONSTANT_CASE`. */\nexport function toConstantCase<T = unknown>(value: T): T {\n return convert(value, toConstantKey) as T;\n}\n","/**\n * Composable operations over a {@link TypeMapper}: batch mapping, safe (non-throwing)\n * forward, sub-DTO views (pick/omit), and map composition. Kept out of\n * `createMap.ts` to respect the per-file size budget; `createMap` attaches thin\n * instance wrappers so these are available as both methods and free functions.\n */\nimport type { z } from \"zod\";\n\n/** Minimal mapper shape these ops need (avoids importing the full createMap type cycle). */\nexport interface MappableForward {\n forward(source: Record<string, unknown>): unknown;\n reverse(dto: unknown): Partial<Record<string, unknown>>;\n readonly schema: z.ZodObject<any>;\n}\n\n/** Result of {@link safeForward}: a discriminated success/failure union. */\nexport type SafeResult<T> =\n | { success: true; data: T }\n | { success: false; error: z.ZodError };\n\n/** Forward every item in `sources`, returning the validated DTO array. */\nexport function forwardMany<M extends MappableForward>(\n map: M,\n sources: Array<Record<string, unknown>>,\n): Array<ReturnType<M[\"forward\"]>> {\n return sources.map((s) => map.forward(s)) as Array<ReturnType<M[\"forward\"]>>;\n}\n\n/** Reverse every DTO in `dtos`, returning the mapped-source array. */\nexport function reverseMany<M extends MappableForward>(\n map: M,\n dtos: unknown[],\n): Array<Partial<Record<string, unknown>>> {\n return dtos.map((d) => map.reverse(d));\n}\n\n/**\n * Forward without throwing: returns `{ success: true, data }` or, on a Zod\n * validation failure, `{ success: false, error }`. Non-Zod errors still throw.\n */\nexport function safeForward<M extends MappableForward>(\n map: M,\n source: Record<string, unknown>,\n): SafeResult<ReturnType<M[\"forward\"]>> {\n try {\n return { success: true, data: map.forward(source) as ReturnType<M[\"forward\"]> };\n } catch (err) {\n if (isZodError(err)) return { success: false, error: err };\n throw err;\n }\n}\n\nfunction isZodError(err: unknown): err is z.ZodError {\n return (\n typeof err === \"object\" &&\n err !== null &&\n (err as { name?: string }).name === \"ZodError\" &&\n Array.isArray((err as { issues?: unknown }).issues)\n );\n}\n","/**\n * `createMap(destSchema, rules)` — synchronous, Zod-validated entity -> DTO\n * mapper. The dest Zod schema is the shape source of truth. Simple string\n * renames and `{ to, from }` pairs auto-reverse; computed function rules are\n * one-way unless paired.\n */\nimport type { z } from \"zod\";\nimport { createResolver } from \"../resolver/createResolver.js\";\nimport type { ResolverContext, ResolverRegistry } from \"../resolver/context.js\";\nimport {\n type CamelCased,\n type SnakeCased,\n toCamelCase,\n toSnakeCase,\n} from \"./case-convert.js\";\nimport {\n type SafeResult,\n forwardMany as forwardManyOp,\n reverseMany as reverseManyOp,\n safeForward as safeForwardOp,\n} from \"./map-ops.js\";\nimport {\n type DefaultRule,\n type FromResolver,\n type Rule,\n getPath,\n isDefaultRule,\n isFnRule,\n isFromResolverRule,\n isPairRule,\n isStringRule,\n setPath,\n} from \"./rules.js\";\n\n/**\n * Resolver graph declared on a map: each field of the dest DTO `Dest` may have\n * a resolver typed against `Dest` and the adapter `TAdapter`.\n */\nexport type MapResolvers<Dest = Record<string, unknown>, TAdapter = unknown> =\n ResolverRegistry<Dest, TAdapter>;\n\n/** Options for {@link createMap}, parameterized by the dest DTO and adapter type. */\nexport interface CreateMapOptions<Dest = Record<string, unknown>, TAdapter = unknown> {\n /**\n * Resolver graph for this map's fields, against the map's own dest schema.\n * Enables `map.toResolver(adapter)` and resolver-backed `forwardAsync` without\n * a separate `createResolver` call. Each resolver's output is typed against the\n * DTO field it produces. NOTE: `ctx.adapter` is typed as the concrete adapter\n * only at the `toResolver(adapter)` call site — inside these declarations it is\n * `unknown` (the adapter is not known at `createMap` time); cast it if needed.\n */\n resolvers?: MapResolvers<Dest, TAdapter>;\n}\n\n/** Thrown when `reverse` meets a one-way function rule that has no inverse. */\nexport class OneWayRuleError extends Error {\n readonly key: string;\n constructor(key: string) {\n super(\n `Cannot reverse dest key \"${key}\": it is mapped by a one-way function ` +\n `rule. Use a { to, from } pair rule to make it reversible.`,\n );\n this.name = \"OneWayRuleError\";\n this.key = key;\n }\n}\n\n/** Thrown when `toResolver` is called on a map that declared no resolvers. */\nexport class MapHasNoResolversError extends Error {\n constructor() {\n super(\n \"createMap.toResolver requires a resolver graph: pass \" +\n \"`createMap(schema, rules, { resolvers })`.\",\n );\n this.name = \"MapHasNoResolversError\";\n }\n}\n\n/** Thrown at build time when two rules reverse onto the same source key. */\nexport class ReverseKeyCollisionError extends Error {\n constructor(sourceKey: string, a: string, b: string) {\n super(\n `Reverse-key collision: dest keys \"${a}\" and \"${b}\" both map back to ` +\n `source key \"${sourceKey}\". Disambiguate one of them.`,\n );\n this.name = \"ReverseKeyCollisionError\";\n }\n}\n\ntype AnyZodObject = z.ZodObject<any>;\n\n/** Rule map: each dest key may carry a rule; unmapped keys are copied by name. */\nexport type RuleMap<Dest> = Partial<Record<keyof Dest & string, Rule>>;\n\nexport interface TypeMapper<S extends AnyZodObject, R extends RuleMap<z.infer<S>>> {\n /** Build a validated DTO from a source entity (sync path). */\n forward(source: Record<string, unknown>): z.infer<S>;\n /** Forward every item in a list, returning the validated DTO array. */\n forwardMany(sources: Array<Record<string, unknown>>): Array<z.infer<S>>;\n /** Forward without throwing: `{ success, data }` or `{ success: false, error }`. */\n safeForward(source: Record<string, unknown>): SafeResult<z.infer<S>>;\n /** Invert reversible rules; returns only mapped source fields. */\n reverse(dto: z.infer<S>): Partial<Record<string, unknown>>;\n /** Reverse every DTO in a list. */\n reverseMany(dtos: Array<z.infer<S>>): Array<Partial<Record<string, unknown>>>;\n /**\n * Recursively re-case ALL property keys of `value` to `snake_case`,\n * regardless of their original casing. Keys only; values pass through.\n */\n toSnakeCase<T>(value: T): SnakeCased<T>;\n /**\n * Recursively re-case ALL property keys of `value` to `camelCase`,\n * regardless of their original casing. Keys only; values pass through.\n */\n toCamelCase<T>(value: T): CamelCased<T>;\n /**\n * Build a resolver graph from THIS map's schema fields plus the resolver\n * graph declared in `createMap`'s options. The resolver validates each field's\n * output against the matching dest sub-schema (over-exposure protection).\n * Throws if no `resolvers` were declared on the map.\n */\n toResolver<TAdapter>(\n adapter: TAdapter,\n seed?: Partial<z.infer<S>>,\n ): ResolverContext<z.infer<S>, TAdapter>;\n /** The dest schema (shape source of truth). */\n readonly schema: S;\n /** Configured rules, frozen. */\n readonly rules: R;\n /** Raw `.shape` of the dest object — used by the async path (Phase 5). */\n readonly shape: Record<string, z.ZodType>;\n /** Resolver graph declared on this map (if any), for `toResolver`/forwardAsync. */\n readonly resolvers?: MapResolvers<z.infer<S>>;\n}\n\n/** Apply a single forward rule for `destKey`, returning the mapped value. */\nexport function applyForwardRule(\n rule: Rule | undefined,\n destKey: string,\n source: Record<string, unknown>,\n): unknown {\n if (rule === undefined) {\n // No rule: copy by matching dest key from source (dot-path aware).\n return getPath(source, destKey);\n }\n if (isStringRule(rule)) {\n return getPath(source, rule);\n }\n if (isPairRule(rule)) {\n return rule.to(source);\n }\n if (isDefaultRule(rule)) {\n const read = getPath(source, rule.source ?? destKey);\n return read === undefined ? rule.value : read;\n }\n if (isFnRule(rule)) {\n return rule(source);\n }\n // FromResolver markers are resolved only on the async path; sync forward\n // treats them as absent (the field is filled by forwardAsync).\n return undefined;\n}\n\n/**\n * Build a two-way mapper. The `const` type parameter on `R` preserves bare\n * object-literal rule values (string-literal renames) without the caller\n * writing `as const` (requires TypeScript >= 5.0).\n */\nexport function createMap<\n S extends AnyZodObject,\n const R extends RuleMap<z.infer<S>>,\n>(\n schema: S,\n rules: R = {} as R,\n options: CreateMapOptions<z.infer<S>> = {},\n): TypeMapper<S, R> {\n const shape = schema.shape as Record<string, z.ZodType>;\n const destKeys = Object.keys(shape);\n const mapResolvers = options.resolvers;\n\n // Build-time reverse-collision detection: any two reversible rules whose\n // inverse targets the same source key are a configuration error.\n const reverseTargets = new Map<string, string>();\n for (const destKey of Object.keys(rules) as Array<keyof R & string>) {\n const rule = rules[destKey] as Rule | undefined;\n if (rule !== undefined && isStringRule(rule)) {\n const existing = reverseTargets.get(rule);\n if (existing) throw new ReverseKeyCollisionError(rule, existing, destKey);\n reverseTargets.set(rule, destKey);\n }\n }\n\n function forward(source: Record<string, unknown>): z.infer<S> {\n const out: Record<string, unknown> = {};\n for (const destKey of destKeys) {\n const rule = rules[destKey as keyof R & string] as Rule | undefined;\n if (isFromResolverRule(rule as Rule)) continue; // async-only\n const value = applyForwardRule(rule, destKey, source);\n if (value !== undefined) setPath(out, destKey, value);\n }\n return schema.parse(out) as z.infer<S>;\n }\n\n function reverse(dto: z.infer<S>): Partial<Record<string, unknown>> {\n const out: Record<string, unknown> = {};\n const dtoObj = dto as Record<string, unknown>;\n for (const destKey of Object.keys(rules) as Array<keyof R & string>) {\n const rule = rules[destKey] as Rule | undefined;\n if (rule === undefined) continue;\n const destValue = getPath(dtoObj, destKey);\n if (isStringRule(rule)) {\n setPath(out, rule, destValue);\n } else if (isPairRule(rule)) {\n setPath(out, destKey, rule.from(destValue));\n } else if (isDefaultRule(rule)) {\n // Round-trip the read key; the default itself is forward-only.\n setPath(out, (rule as DefaultRule).source ?? destKey, destValue);\n } else if (isFromResolverRule(rule as Rule)) {\n // Resolver-backed fields have no source inverse; skip.\n continue;\n } else {\n // One-way function rule, no inverse.\n throw new OneWayRuleError(destKey);\n }\n }\n return out;\n }\n\n type Dest = z.infer<S>;\n\n function toResolver<TAdapter>(\n adapter: TAdapter,\n seed?: Partial<Dest>,\n ): ResolverContext<Dest, TAdapter> {\n if (!mapResolvers) {\n throw new MapHasNoResolversError();\n }\n // Per-field schemas from this map's own shape (over-exposure protection).\n const schemas: Record<string, z.ZodType> = {};\n for (const key of Object.keys(shape)) {\n schemas[key] = shape[key] as z.ZodType;\n }\n return createResolver<Dest, TAdapter>({\n adapter,\n seed,\n resolvers: mapResolvers as ResolverRegistry<Dest, TAdapter>,\n schemas: schemas as Record<keyof Dest, z.ZodType>,\n });\n }\n\n const mapper: TypeMapper<S, R> = {\n forward,\n reverse,\n forwardMany: (sources) => forwardManyOp(mapper, sources) as Array<Dest>,\n reverseMany: (dtos) => reverseManyOp(mapper, dtos),\n safeForward: (source) => safeForwardOp(mapper, source) as SafeResult<Dest>,\n toSnakeCase,\n toCamelCase,\n toResolver,\n schema,\n rules: Object.freeze({ ...rules }) as R,\n shape,\n resolvers: mapResolvers,\n };\n return mapper;\n}\n\nexport type { FromResolver };\n","/**\n * Map-deriving helpers that produce NEW {@link TypeMapper} instances: sub-DTO\n * views (`pick`/`omit`) and composition (`compose`). Kept separate from\n * `createMap.ts` so it can import `createMap` without a circular dependency.\n */\nimport { z } from \"zod\";\nimport { type TypeMapper, createMap } from \"./createMap.js\";\nimport { forwardMany, reverseMany, safeForward } from \"./map-ops.js\";\n\ntype AnyMapper = TypeMapper<z.ZodObject<any>, any>;\n\n/**\n * Build a fresh `z.object` from the chosen `keys` of `schema`'s raw `.shape`.\n * Uses the shape directly (never `.pick()`), so it is safe on refined schemas.\n */\nfunction subObject(schema: z.ZodObject<any>, keys: string[]): z.ZodObject<any> {\n const shape = schema.shape as Record<string, z.ZodType>;\n const picked: Record<string, z.ZodType> = {};\n for (const key of keys) {\n const field = shape[key];\n if (field !== undefined) picked[key] = field;\n }\n return z.object(picked);\n}\n\n/** A map over only `keys` of `map`'s DTO (identity rules; no transforms carried). */\nexport function pick<M extends AnyMapper>(map: M, keys: string[]): AnyMapper {\n return createMap(subObject(map.schema, keys));\n}\n\n/** A map over `map`'s DTO minus `keys`. */\nexport function omit<M extends AnyMapper>(map: M, keys: string[]): AnyMapper {\n const drop = new Set(keys);\n const remaining = Object.keys(map.schema.shape as object).filter((k) => !drop.has(k));\n return createMap(subObject(map.schema, remaining));\n}\n\n/**\n * Compose two maps into a DTO->DTO pipeline: `compose(a, b).forward(src)` runs\n * `b.forward(a.forward(src))`, validating against `b`'s schema. Reverse pipes\n * back through `a.reverse(b.reverse(dto))`.\n *\n * `forwardMany`/`safeForward`/`reverseMany` honor the composed pipeline. Reverse\n * only round-trips fields BOTH maps carry a reversible rule for (identity links\n * with no rule emit nothing on reverse). `toResolver` is unsupported on a\n * composed map (it declares no resolver graph) and throws.\n */\nexport function compose<A extends AnyMapper, B extends AnyMapper>(a: A, b: B): AnyMapper {\n // Base instance supplies schema/shape/case-helpers for b's DTO; forward and\n // reverse pipe through the ORIGINAL maps so their rules are honored.\n const base = createMap(b.schema);\n const composed = { ...base } as AnyMapper;\n composed.forward = (source: Record<string, unknown>) =>\n b.forward(a.forward(source) as Record<string, unknown>);\n composed.reverse = (dto: unknown) => a.reverse(b.reverse(dto as never) as never);\n // Re-wire derived ops over the COMPOSED forward/reverse — base's closures\n // would otherwise bypass the pipeline and silently skip a's transforms.\n composed.forwardMany = (sources) => forwardMany(composed, sources) as never;\n composed.reverseMany = (dtos) => reverseMany(composed, dtos);\n composed.safeForward = (source) => safeForward(composed, source) as never;\n return composed;\n}\n","/**\n * Leaf transforms between rich JS values and their JSON-safe wire forms.\n * Each inverse (wire -> JS) transform validates its input and throws a\n * {@link CodecError} on malformed data, so a hostile wire payload surfaces a\n * typed error instead of a raw `TypeError`/`SyntaxError` or an unbounded stall.\n */\n\n/** Thrown for malformed wire input or unsupported schema nodes during codec walk. */\nexport class CodecError extends Error {\n /** Path to the offending value, e.g. `user.createdAt`. */\n readonly path: ReadonlyArray<string | number>;\n constructor(message: string, path: ReadonlyArray<string | number> = []) {\n const where = path.length ? ` (at ${path.join(\".\")})` : \"\";\n super(`${message}${where}`);\n this.name = \"CodecError\";\n this.path = path;\n }\n}\n\n/** Thrown when `deserialize` is given a schema containing async refinements. */\nexport class AsyncSchemaError extends Error {\n constructor() {\n super(\n \"deserialize is sync-only; this schema has async refinements. \" +\n \"Remove async .refine()/.superRefine() or validate separately with parseAsync.\",\n );\n this.name = \"AsyncSchemaError\";\n }\n}\n\n/**\n * DoS guards on attacker-controlled wire input. A BigInt parsed from a very\n * long numeric string, or a Map rebuilt from a huge entries array, can stall\n * the event loop; these caps reject such input up front.\n */\nexport const LIMITS = {\n /** Max characters in a BigInt wire string (sign + digits). */\n bigintStringLength: 4096,\n /** Max entries when rebuilding a Map from a wire array. */\n mapEntries: 100_000,\n} as const;\n\n// --- Date <-> ISO string ---\n\nexport function dateToIso(value: Date, path: ReadonlyArray<string | number>): string {\n if (!(value instanceof Date) || Number.isNaN(value.getTime())) {\n throw new CodecError(\"expected a valid Date\", path);\n }\n return value.toISOString();\n}\n\nexport function isoToDate(value: unknown, path: ReadonlyArray<string | number>): Date {\n if (typeof value !== \"string\") {\n throw new CodecError(\"expected an ISO date string\", path);\n }\n const ms = Date.parse(value);\n if (Number.isNaN(ms)) {\n throw new CodecError(\"invalid ISO date string\", path);\n }\n return new Date(ms);\n}\n\n// --- BigInt <-> string ---\n\nexport function bigintToString(value: bigint, path: ReadonlyArray<string | number>): string {\n if (typeof value !== \"bigint\") {\n throw new CodecError(\"expected a bigint\", path);\n }\n return value.toString();\n}\n\nexport function stringToBigint(value: unknown, path: ReadonlyArray<string | number>): bigint {\n if (typeof value !== \"string\") {\n throw new CodecError(\"expected a bigint string\", path);\n }\n if (value.length > LIMITS.bigintStringLength) {\n throw new CodecError(\n `bigint string exceeds ${LIMITS.bigintStringLength} chars`,\n path,\n );\n }\n if (!/^-?\\d+$/.test(value)) {\n throw new CodecError(\"malformed bigint string\", path);\n }\n return BigInt(value);\n}\n\n// --- Map <-> entries array ---\n\nexport function mapToEntries(\n value: Map<unknown, unknown>,\n path: ReadonlyArray<string | number>,\n): Array<[unknown, unknown]> {\n if (!(value instanceof Map)) {\n throw new CodecError(\"expected a Map\", path);\n }\n return Array.from(value.entries());\n}\n\nexport function entriesToArray(\n value: unknown,\n path: ReadonlyArray<string | number>,\n): Array<[unknown, unknown]> {\n if (!Array.isArray(value)) {\n throw new CodecError(\"expected a Map entries array\", path);\n }\n if (value.length > LIMITS.mapEntries) {\n throw new CodecError(`Map entries exceed ${LIMITS.mapEntries}`, path);\n }\n for (const entry of value) {\n if (!Array.isArray(entry) || entry.length !== 2) {\n throw new CodecError(\"malformed Map entry (expected [key, value])\", path);\n }\n }\n return value as Array<[unknown, unknown]>;\n}\n\n// --- Set <-> array ---\n\nexport function setToArray(\n value: Set<unknown>,\n path: ReadonlyArray<string | number>,\n): unknown[] {\n if (!(value instanceof Set)) {\n throw new CodecError(\"expected a Set\", path);\n }\n return Array.from(value.values());\n}\n\nexport function arrayToSetItems(\n value: unknown,\n path: ReadonlyArray<string | number>,\n): unknown[] {\n if (!Array.isArray(value)) {\n throw new CodecError(\"expected a Set values array\", path);\n }\n if (value.length > LIMITS.mapEntries) {\n throw new CodecError(`Set values exceed ${LIMITS.mapEntries}`, path);\n }\n return value;\n}\n","/**\n * Schema-driven JSON-safe codec for Zod 4 schemas.\n *\n * `serialize` walks a value alongside its Zod schema and replaces rich runtime\n * types (Date, BigInt, Map) with JSON-safe representations; `deserialize` walks\n * the wire form back into rich values and then validates with Zod.\n *\n * Zod-4 only: all schema-shape reads go through {@link typeOf}/{@link unwrap},\n * which dispatch on the Zod 4 internal `_zod.def.type` (lowercase strings).\n * Zod 3's `_def.typeName` is intentionally unsupported.\n */\nimport type { z } from \"zod\";\nimport {\n AsyncSchemaError,\n CodecError,\n bigintToString,\n arrayToSetItems,\n dateToIso,\n entriesToArray,\n isoToDate,\n mapToEntries,\n setToArray,\n stringToBigint,\n} from \"./json-types.js\";\n\ntype AnyZod = z.ZodType;\ntype Path = ReadonlyArray<string | number>;\ntype Direction = \"serialize\" | \"deserialize\";\n\n// Minimal structural view of the Zod 4 internal def. Centralizes the one place\n// the library couples to `_zod.def`, so a Zod minor bump touches only this file.\ninterface ZodDef {\n type: string;\n innerType?: AnyZod;\n element?: AnyZod;\n shape?: Record<string, AnyZod>;\n keyType?: AnyZod;\n valueType?: AnyZod;\n options?: AnyZod[];\n getter?: () => AnyZod;\n in?: AnyZod;\n}\n\nfunction defOf(schema: AnyZod): ZodDef {\n return (schema as unknown as { _zod: { def: ZodDef } })._zod.def;\n}\n\n/** The Zod 4 node kind, e.g. `\"object\"`, `\"array\"`, `\"date\"`. */\nexport function typeOf(schema: AnyZod): string {\n return defOf(schema).type;\n}\n\n/**\n * Peel wrapper nodes that do not change the JSON-safe shape:\n * optional/nullable/default (innerType), pipe/transform (the `in` schema is the\n * wire-facing shape), and lazy (resolve the getter). Object `.refine()` in Zod\n * 4 stays a plain `object` node with its `shape` intact, so it needs no peeling.\n */\nexport function unwrap(schema: AnyZod): AnyZod {\n let current = schema;\n // Bounded by schema nesting depth; each step strictly descends.\n for (;;) {\n const def = defOf(current);\n switch (def.type) {\n case \"optional\":\n case \"nullable\":\n case \"default\":\n case \"nonoptional\":\n case \"readonly\":\n case \"catch\":\n current = def.innerType as AnyZod;\n break;\n case \"pipe\":\n // `.transform()` and `.pipe()` both produce a pipe; the `in` side is the\n // shape that wire data is validated against.\n current = def.in as AnyZod;\n break;\n case \"lazy\":\n current = (def.getter as () => AnyZod)();\n break;\n default:\n return current;\n }\n }\n}\n\nfunction walk(schema: AnyZod, value: unknown, dir: Direction, path: Path): unknown {\n if (value === null || value === undefined) return value;\n\n const node = unwrap(schema);\n const def = defOf(node);\n\n switch (def.type) {\n case \"object\": {\n if (typeof value !== \"object\" || Array.isArray(value)) {\n throw new CodecError(\"expected an object\", path);\n }\n const shape = def.shape as Record<string, AnyZod>;\n const src = value as Record<string, unknown>;\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(shape)) {\n if (Object.prototype.hasOwnProperty.call(src, key)) {\n out[key] = walk(shape[key] as AnyZod, src[key], dir, [...path, key]);\n }\n }\n return out;\n }\n\n case \"array\": {\n if (!Array.isArray(value)) throw new CodecError(\"expected an array\", path);\n const element = def.element as AnyZod;\n return value.map((item, i) => walk(element, item, dir, [...path, i]));\n }\n\n case \"map\": {\n const keyType = def.keyType as AnyZod;\n const valueType = def.valueType as AnyZod;\n if (dir === \"serialize\") {\n const entries = mapToEntries(value as Map<unknown, unknown>, path);\n return entries.map(([k, v], i) => [\n walk(keyType, k, dir, [...path, i, \"key\"]),\n walk(valueType, v, dir, [...path, i, \"value\"]),\n ]);\n }\n const entries = entriesToArray(value, path);\n const out = new Map<unknown, unknown>();\n entries.forEach(([k, v], i) => {\n out.set(\n walk(keyType, k, dir, [...path, i, \"key\"]),\n walk(valueType, v, dir, [...path, i, \"value\"]),\n );\n });\n return out;\n }\n\n case \"set\": {\n const valueType = def.valueType as AnyZod;\n if (dir === \"serialize\") {\n const items = setToArray(value as Set<unknown>, path);\n return items.map((item, i) => walk(valueType, item, dir, [...path, i]));\n }\n const items = arrayToSetItems(value, path);\n return new Set(items.map((item, i) => walk(valueType, item, dir, [...path, i])));\n }\n\n case \"union\": {\n // Try each member; first that walks without a CodecError wins. Mirrors\n // Zod's own \"first match\" union semantics for the JSON-safe shape. A\n // non-CodecError (e.g. a throwing z.lazy getter) is a real fault and\n // propagates immediately rather than being treated as a failed match.\n const options = def.options as AnyZod[];\n let lastError: CodecError = new CodecError(\"no union member matched\", path);\n for (const option of options) {\n try {\n return walk(option, value, dir, path);\n } catch (err) {\n if (!(err instanceof CodecError)) throw err;\n lastError = err;\n }\n }\n throw lastError;\n }\n\n case \"date\":\n return dir === \"serialize\"\n ? dateToIso(value as Date, path)\n : isoToDate(value, path);\n\n case \"bigint\":\n return dir === \"serialize\"\n ? bigintToString(value as bigint, path)\n : stringToBigint(value, path);\n\n // Scalars and explicit escape hatches pass through untouched.\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"nan\":\n case \"null\":\n case \"undefined\":\n case \"literal\":\n case \"enum\":\n case \"any\":\n case \"unknown\":\n case \"void\":\n case \"custom\":\n return value;\n\n default:\n // Fail closed: an unhandled object-like node would otherwise silently\n // skip its inner schema. Use z.custom() for genuinely opaque values.\n throw new CodecError(`unsupported schema node \"${def.type}\"`, path);\n }\n}\n\n/**\n * Convert a rich value into a JSON-safe plain value per its Zod schema.\n * Date -> ISO string, BigInt -> string, Map -> `[key, value][]`, recursing\n * through objects, arrays, maps and unions. The result survives\n * `JSON.parse(JSON.stringify(...))` with no loss for supported types.\n */\nexport function serialize<S extends AnyZod>(value: z.infer<S>, schema: S): unknown {\n return walk(schema, value, \"serialize\", []);\n}\n\nfunction isZodAsyncError(err: unknown): boolean {\n const name = (err as { constructor?: { name?: string } } | null)?.constructor?.name;\n return name === \"$ZodAsyncError\";\n}\n\n/**\n * Rebuild rich values from their JSON-safe wire form per `schema`, then\n * validate with Zod. Leaf transforms validate their input and surface a typed\n * {@link CodecError} on malformed data, so untrusted JSON never escapes as a\n * raw throw or an unbounded stall. Sync-only: an async-refined schema throws\n * {@link AsyncSchemaError}.\n */\nexport function deserialize<S extends AnyZod>(json: unknown, schema: S): z.infer<S> {\n const rebuilt = walk(schema, json, \"deserialize\", []);\n try {\n return schema.parse(rebuilt) as z.infer<S>;\n } catch (err) {\n if (isZodAsyncError(err)) throw new AsyncSchemaError();\n throw err;\n }\n}\n\n/**\n * Async variant of {@link deserialize}: rebuilds rich values then validates with\n * `parseAsync`, so schemas containing async `.refine`/`.superRefine` are\n * supported (no {@link AsyncSchemaError}). The same leaf-transform safety and\n * DoS bounds apply during the rebuild.\n */\nexport async function deserializeAsync<S extends AnyZod>(\n json: unknown,\n schema: S,\n): Promise<z.infer<S>> {\n const rebuilt = walk(schema, json, \"deserialize\", []);\n return (await schema.parseAsync(rebuilt)) as z.infer<S>;\n}\n","// Root entry: the core sync mapper plus the serialize codec.\nexport const VERSION = \"0.1.0\";\n\nexport {\n createMap,\n OneWayRuleError,\n ReverseKeyCollisionError,\n MapHasNoResolversError,\n fromResolver,\n getPath,\n setPath,\n isStringRule,\n isFnRule,\n isPairRule,\n isFromResolverRule,\n isDefaultRule,\n withDefault,\n toSnakeCase,\n toCamelCase,\n toKebabCase,\n toPascalCase,\n toConstantCase,\n toSnakeKey,\n toCamelKey,\n toKebabKey,\n toPascalKey,\n toConstantKey,\n splitWords,\n type SnakeCased,\n type CamelCased,\n forwardMany,\n reverseMany,\n safeForward,\n pick,\n omit,\n compose,\n type TypeMapper,\n type RuleMap,\n type Rule,\n type FnRule,\n type PairRule,\n type FromResolver,\n type DefaultRule,\n type SafeResult,\n} from \"./map/index.js\";\n\nexport {\n serialize,\n deserialize,\n deserializeAsync,\n CodecError,\n AsyncSchemaError,\n} from \"./serialize/index.js\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { R as ResolverContext, a as ResolverRegistry } from './context-B0f9mQWu.cjs';
|
|
3
|
+
import { R as Rule } from './rules-msHkZDR8.cjs';
|
|
4
|
+
export { D as DefaultRule, F as FnRule, a as FromResolver, P as PairRule, f as fromResolver, g as getPath, i as isDefaultRule, b as isFnRule, c as isFromResolverRule, d as isPairRule, e as isStringRule, s as setPath, w as withDefault } from './rules-msHkZDR8.cjs';
|
|
5
|
+
export { AsyncSchemaError, CodecError, deserialize, deserializeAsync, serialize } from './serialize/index.cjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Recursive object-key case conversion. `toSnakeCase`/`toCamelCase` re-case ALL
|
|
9
|
+
* property keys of a value to the target case regardless of the input keys'
|
|
10
|
+
* original casing (snake, camel, Pascal, kebab, SCREAMING_SNAKE all normalize).
|
|
11
|
+
*
|
|
12
|
+
* Only KEYS change. Values pass through untouched; recursion descends plain
|
|
13
|
+
* objects and arrays only — Dates, Maps, Sets, class instances, and primitives
|
|
14
|
+
* are returned as-is so their internal data is never reshaped.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Split an identifier into lowercase word tokens, the casing-neutral form every
|
|
18
|
+
* target case is rebuilt from. Handles delimiters (`_`, `-`, space), camel/Pascal
|
|
19
|
+
* humps, acronym runs (`HTTPServer` -> `http`,`server`), and digit groups.
|
|
20
|
+
*/
|
|
21
|
+
declare function splitWords(key: string): string[];
|
|
22
|
+
/** Convert a single key to `snake_case`; leave unconvertible keys untouched. */
|
|
23
|
+
declare function toSnakeKey(key: string): string;
|
|
24
|
+
/** Convert a single key to `camelCase`; leave unconvertible keys untouched. */
|
|
25
|
+
declare function toCamelKey(key: string): string;
|
|
26
|
+
/** Insert `_` before each interior uppercase letter, then lowercase. */
|
|
27
|
+
type CamelToSnake<S extends string> = S extends `${infer Head}${infer Tail}` ? Head extends Uppercase<Head> ? Head extends Lowercase<Head> ? `${Head}${CamelToSnake<Tail>}` : `_${Lowercase<Head>}${CamelToSnake<Tail>}` : `${Head}${CamelToSnake<Tail>}` : S;
|
|
28
|
+
/** Drop a single leading `_` produced when the first letter was uppercase. */
|
|
29
|
+
type StripLeadingUnderscore<S extends string> = S extends `_${infer Rest}` ? Rest : S;
|
|
30
|
+
type SnakeKey<S extends string> = StripLeadingUnderscore<CamelToSnake<S>>;
|
|
31
|
+
/** Collapse `_x` groups into `X` (snake/kebab -> camelCase). */
|
|
32
|
+
type SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<SnakeToCamel<Tail>>}` : S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<SnakeToCamel<Tail>>}` : S;
|
|
33
|
+
/** Public type of {@link toSnakeCase}: keys recursively snake_cased. */
|
|
34
|
+
type SnakeCased<T> = T extends Array<infer E> ? Array<SnakeCased<E>> : T extends Date | Map<unknown, unknown> | Set<unknown> ? T : T extends object ? {
|
|
35
|
+
[K in keyof T as K extends string ? SnakeKey<K> : K]: SnakeCased<T[K]>;
|
|
36
|
+
} : T;
|
|
37
|
+
/** Public type of {@link toCamelCase}: keys recursively camelCased. */
|
|
38
|
+
type CamelCased<T> = T extends Array<infer E> ? Array<CamelCased<E>> : T extends Date | Map<unknown, unknown> | Set<unknown> ? T : T extends object ? {
|
|
39
|
+
[K in keyof T as K extends string ? SnakeToCamel<K> : K]: CamelCased<T[K]>;
|
|
40
|
+
} : T;
|
|
41
|
+
/**
|
|
42
|
+
* Recursively re-case all property keys of `value` to `snake_case`. The return
|
|
43
|
+
* type maps keys for the common identifier case (see {@link SnakeCased}).
|
|
44
|
+
*/
|
|
45
|
+
declare function toSnakeCase<T>(value: T): SnakeCased<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Recursively re-case all property keys of `value` to `camelCase`. The return
|
|
48
|
+
* type maps keys for the common identifier case (see {@link CamelCased}).
|
|
49
|
+
*/
|
|
50
|
+
declare function toCamelCase<T>(value: T): CamelCased<T>;
|
|
51
|
+
/** Convert a single key to `kebab-case`; leave unconvertible keys untouched. */
|
|
52
|
+
declare function toKebabKey(key: string): string;
|
|
53
|
+
/** Convert a single key to `PascalCase`; leave unconvertible keys untouched. */
|
|
54
|
+
declare function toPascalKey(key: string): string;
|
|
55
|
+
/** Convert a single key to `CONSTANT_CASE`; leave unconvertible keys untouched. */
|
|
56
|
+
declare function toConstantKey(key: string): string;
|
|
57
|
+
/** Recursively re-case all property keys of `value` to `kebab-case`. */
|
|
58
|
+
declare function toKebabCase<T = unknown>(value: T): T;
|
|
59
|
+
/** Recursively re-case all property keys of `value` to `PascalCase`. */
|
|
60
|
+
declare function toPascalCase<T = unknown>(value: T): T;
|
|
61
|
+
/** Recursively re-case all property keys of `value` to `CONSTANT_CASE`. */
|
|
62
|
+
declare function toConstantCase<T = unknown>(value: T): T;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Composable operations over a {@link TypeMapper}: batch mapping, safe (non-throwing)
|
|
66
|
+
* forward, sub-DTO views (pick/omit), and map composition. Kept out of
|
|
67
|
+
* `createMap.ts` to respect the per-file size budget; `createMap` attaches thin
|
|
68
|
+
* instance wrappers so these are available as both methods and free functions.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/** Minimal mapper shape these ops need (avoids importing the full createMap type cycle). */
|
|
72
|
+
interface MappableForward {
|
|
73
|
+
forward(source: Record<string, unknown>): unknown;
|
|
74
|
+
reverse(dto: unknown): Partial<Record<string, unknown>>;
|
|
75
|
+
readonly schema: z.ZodObject<any>;
|
|
76
|
+
}
|
|
77
|
+
/** Result of {@link safeForward}: a discriminated success/failure union. */
|
|
78
|
+
type SafeResult<T> = {
|
|
79
|
+
success: true;
|
|
80
|
+
data: T;
|
|
81
|
+
} | {
|
|
82
|
+
success: false;
|
|
83
|
+
error: z.ZodError;
|
|
84
|
+
};
|
|
85
|
+
/** Forward every item in `sources`, returning the validated DTO array. */
|
|
86
|
+
declare function forwardMany<M extends MappableForward>(map: M, sources: Array<Record<string, unknown>>): Array<ReturnType<M["forward"]>>;
|
|
87
|
+
/** Reverse every DTO in `dtos`, returning the mapped-source array. */
|
|
88
|
+
declare function reverseMany<M extends MappableForward>(map: M, dtos: unknown[]): Array<Partial<Record<string, unknown>>>;
|
|
89
|
+
/**
|
|
90
|
+
* Forward without throwing: returns `{ success: true, data }` or, on a Zod
|
|
91
|
+
* validation failure, `{ success: false, error }`. Non-Zod errors still throw.
|
|
92
|
+
*/
|
|
93
|
+
declare function safeForward<M extends MappableForward>(map: M, source: Record<string, unknown>): SafeResult<ReturnType<M["forward"]>>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* `createMap(destSchema, rules)` — synchronous, Zod-validated entity -> DTO
|
|
97
|
+
* mapper. The dest Zod schema is the shape source of truth. Simple string
|
|
98
|
+
* renames and `{ to, from }` pairs auto-reverse; computed function rules are
|
|
99
|
+
* one-way unless paired.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Resolver graph declared on a map: each field of the dest DTO `Dest` may have
|
|
104
|
+
* a resolver typed against `Dest` and the adapter `TAdapter`.
|
|
105
|
+
*/
|
|
106
|
+
type MapResolvers<Dest = Record<string, unknown>, TAdapter = unknown> = ResolverRegistry<Dest, TAdapter>;
|
|
107
|
+
/** Options for {@link createMap}, parameterized by the dest DTO and adapter type. */
|
|
108
|
+
interface CreateMapOptions<Dest = Record<string, unknown>, TAdapter = unknown> {
|
|
109
|
+
/**
|
|
110
|
+
* Resolver graph for this map's fields, against the map's own dest schema.
|
|
111
|
+
* Enables `map.toResolver(adapter)` and resolver-backed `forwardAsync` without
|
|
112
|
+
* a separate `createResolver` call. Each resolver's output is typed against the
|
|
113
|
+
* DTO field it produces. NOTE: `ctx.adapter` is typed as the concrete adapter
|
|
114
|
+
* only at the `toResolver(adapter)` call site — inside these declarations it is
|
|
115
|
+
* `unknown` (the adapter is not known at `createMap` time); cast it if needed.
|
|
116
|
+
*/
|
|
117
|
+
resolvers?: MapResolvers<Dest, TAdapter>;
|
|
118
|
+
}
|
|
119
|
+
/** Thrown when `reverse` meets a one-way function rule that has no inverse. */
|
|
120
|
+
declare class OneWayRuleError extends Error {
|
|
121
|
+
readonly key: string;
|
|
122
|
+
constructor(key: string);
|
|
123
|
+
}
|
|
124
|
+
/** Thrown when `toResolver` is called on a map that declared no resolvers. */
|
|
125
|
+
declare class MapHasNoResolversError extends Error {
|
|
126
|
+
constructor();
|
|
127
|
+
}
|
|
128
|
+
/** Thrown at build time when two rules reverse onto the same source key. */
|
|
129
|
+
declare class ReverseKeyCollisionError extends Error {
|
|
130
|
+
constructor(sourceKey: string, a: string, b: string);
|
|
131
|
+
}
|
|
132
|
+
type AnyZodObject = z.ZodObject<any>;
|
|
133
|
+
/** Rule map: each dest key may carry a rule; unmapped keys are copied by name. */
|
|
134
|
+
type RuleMap<Dest> = Partial<Record<keyof Dest & string, Rule>>;
|
|
135
|
+
interface TypeMapper<S extends AnyZodObject, R extends RuleMap<z.infer<S>>> {
|
|
136
|
+
/** Build a validated DTO from a source entity (sync path). */
|
|
137
|
+
forward(source: Record<string, unknown>): z.infer<S>;
|
|
138
|
+
/** Forward every item in a list, returning the validated DTO array. */
|
|
139
|
+
forwardMany(sources: Array<Record<string, unknown>>): Array<z.infer<S>>;
|
|
140
|
+
/** Forward without throwing: `{ success, data }` or `{ success: false, error }`. */
|
|
141
|
+
safeForward(source: Record<string, unknown>): SafeResult<z.infer<S>>;
|
|
142
|
+
/** Invert reversible rules; returns only mapped source fields. */
|
|
143
|
+
reverse(dto: z.infer<S>): Partial<Record<string, unknown>>;
|
|
144
|
+
/** Reverse every DTO in a list. */
|
|
145
|
+
reverseMany(dtos: Array<z.infer<S>>): Array<Partial<Record<string, unknown>>>;
|
|
146
|
+
/**
|
|
147
|
+
* Recursively re-case ALL property keys of `value` to `snake_case`,
|
|
148
|
+
* regardless of their original casing. Keys only; values pass through.
|
|
149
|
+
*/
|
|
150
|
+
toSnakeCase<T>(value: T): SnakeCased<T>;
|
|
151
|
+
/**
|
|
152
|
+
* Recursively re-case ALL property keys of `value` to `camelCase`,
|
|
153
|
+
* regardless of their original casing. Keys only; values pass through.
|
|
154
|
+
*/
|
|
155
|
+
toCamelCase<T>(value: T): CamelCased<T>;
|
|
156
|
+
/**
|
|
157
|
+
* Build a resolver graph from THIS map's schema fields plus the resolver
|
|
158
|
+
* graph declared in `createMap`'s options. The resolver validates each field's
|
|
159
|
+
* output against the matching dest sub-schema (over-exposure protection).
|
|
160
|
+
* Throws if no `resolvers` were declared on the map.
|
|
161
|
+
*/
|
|
162
|
+
toResolver<TAdapter>(adapter: TAdapter, seed?: Partial<z.infer<S>>): ResolverContext<z.infer<S>, TAdapter>;
|
|
163
|
+
/** The dest schema (shape source of truth). */
|
|
164
|
+
readonly schema: S;
|
|
165
|
+
/** Configured rules, frozen. */
|
|
166
|
+
readonly rules: R;
|
|
167
|
+
/** Raw `.shape` of the dest object — used by the async path (Phase 5). */
|
|
168
|
+
readonly shape: Record<string, z.ZodType>;
|
|
169
|
+
/** Resolver graph declared on this map (if any), for `toResolver`/forwardAsync. */
|
|
170
|
+
readonly resolvers?: MapResolvers<z.infer<S>>;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Build a two-way mapper. The `const` type parameter on `R` preserves bare
|
|
174
|
+
* object-literal rule values (string-literal renames) without the caller
|
|
175
|
+
* writing `as const` (requires TypeScript >= 5.0).
|
|
176
|
+
*/
|
|
177
|
+
declare function createMap<S extends AnyZodObject, const R extends RuleMap<z.infer<S>>>(schema: S, rules?: R, options?: CreateMapOptions<z.infer<S>>): TypeMapper<S, R>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Map-deriving helpers that produce NEW {@link TypeMapper} instances: sub-DTO
|
|
181
|
+
* views (`pick`/`omit`) and composition (`compose`). Kept separate from
|
|
182
|
+
* `createMap.ts` so it can import `createMap` without a circular dependency.
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
type AnyMapper = TypeMapper<z.ZodObject<any>, any>;
|
|
186
|
+
/** A map over only `keys` of `map`'s DTO (identity rules; no transforms carried). */
|
|
187
|
+
declare function pick<M extends AnyMapper>(map: M, keys: string[]): AnyMapper;
|
|
188
|
+
/** A map over `map`'s DTO minus `keys`. */
|
|
189
|
+
declare function omit<M extends AnyMapper>(map: M, keys: string[]): AnyMapper;
|
|
190
|
+
/**
|
|
191
|
+
* Compose two maps into a DTO->DTO pipeline: `compose(a, b).forward(src)` runs
|
|
192
|
+
* `b.forward(a.forward(src))`, validating against `b`'s schema. Reverse pipes
|
|
193
|
+
* back through `a.reverse(b.reverse(dto))`.
|
|
194
|
+
*
|
|
195
|
+
* `forwardMany`/`safeForward`/`reverseMany` honor the composed pipeline. Reverse
|
|
196
|
+
* only round-trips fields BOTH maps carry a reversible rule for (identity links
|
|
197
|
+
* with no rule emit nothing on reverse). `toResolver` is unsupported on a
|
|
198
|
+
* composed map (it declares no resolver graph) and throws.
|
|
199
|
+
*/
|
|
200
|
+
declare function compose<A extends AnyMapper, B extends AnyMapper>(a: A, b: B): AnyMapper;
|
|
201
|
+
|
|
202
|
+
declare const VERSION = "0.1.0";
|
|
203
|
+
|
|
204
|
+
export { type CamelCased, MapHasNoResolversError, OneWayRuleError, ReverseKeyCollisionError, Rule, type RuleMap, type SafeResult, type SnakeCased, type TypeMapper, VERSION, compose, createMap, forwardMany, omit, pick, reverseMany, safeForward, splitWords, toCamelCase, toCamelKey, toConstantCase, toConstantKey, toKebabCase, toKebabKey, toPascalCase, toPascalKey, toSnakeCase, toSnakeKey };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { R as ResolverContext, a as ResolverRegistry } from './context-B0f9mQWu.js';
|
|
3
|
+
import { R as Rule } from './rules-msHkZDR8.js';
|
|
4
|
+
export { D as DefaultRule, F as FnRule, a as FromResolver, P as PairRule, f as fromResolver, g as getPath, i as isDefaultRule, b as isFnRule, c as isFromResolverRule, d as isPairRule, e as isStringRule, s as setPath, w as withDefault } from './rules-msHkZDR8.js';
|
|
5
|
+
export { AsyncSchemaError, CodecError, deserialize, deserializeAsync, serialize } from './serialize/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Recursive object-key case conversion. `toSnakeCase`/`toCamelCase` re-case ALL
|
|
9
|
+
* property keys of a value to the target case regardless of the input keys'
|
|
10
|
+
* original casing (snake, camel, Pascal, kebab, SCREAMING_SNAKE all normalize).
|
|
11
|
+
*
|
|
12
|
+
* Only KEYS change. Values pass through untouched; recursion descends plain
|
|
13
|
+
* objects and arrays only — Dates, Maps, Sets, class instances, and primitives
|
|
14
|
+
* are returned as-is so their internal data is never reshaped.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Split an identifier into lowercase word tokens, the casing-neutral form every
|
|
18
|
+
* target case is rebuilt from. Handles delimiters (`_`, `-`, space), camel/Pascal
|
|
19
|
+
* humps, acronym runs (`HTTPServer` -> `http`,`server`), and digit groups.
|
|
20
|
+
*/
|
|
21
|
+
declare function splitWords(key: string): string[];
|
|
22
|
+
/** Convert a single key to `snake_case`; leave unconvertible keys untouched. */
|
|
23
|
+
declare function toSnakeKey(key: string): string;
|
|
24
|
+
/** Convert a single key to `camelCase`; leave unconvertible keys untouched. */
|
|
25
|
+
declare function toCamelKey(key: string): string;
|
|
26
|
+
/** Insert `_` before each interior uppercase letter, then lowercase. */
|
|
27
|
+
type CamelToSnake<S extends string> = S extends `${infer Head}${infer Tail}` ? Head extends Uppercase<Head> ? Head extends Lowercase<Head> ? `${Head}${CamelToSnake<Tail>}` : `_${Lowercase<Head>}${CamelToSnake<Tail>}` : `${Head}${CamelToSnake<Tail>}` : S;
|
|
28
|
+
/** Drop a single leading `_` produced when the first letter was uppercase. */
|
|
29
|
+
type StripLeadingUnderscore<S extends string> = S extends `_${infer Rest}` ? Rest : S;
|
|
30
|
+
type SnakeKey<S extends string> = StripLeadingUnderscore<CamelToSnake<S>>;
|
|
31
|
+
/** Collapse `_x` groups into `X` (snake/kebab -> camelCase). */
|
|
32
|
+
type SnakeToCamel<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<SnakeToCamel<Tail>>}` : S extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<SnakeToCamel<Tail>>}` : S;
|
|
33
|
+
/** Public type of {@link toSnakeCase}: keys recursively snake_cased. */
|
|
34
|
+
type SnakeCased<T> = T extends Array<infer E> ? Array<SnakeCased<E>> : T extends Date | Map<unknown, unknown> | Set<unknown> ? T : T extends object ? {
|
|
35
|
+
[K in keyof T as K extends string ? SnakeKey<K> : K]: SnakeCased<T[K]>;
|
|
36
|
+
} : T;
|
|
37
|
+
/** Public type of {@link toCamelCase}: keys recursively camelCased. */
|
|
38
|
+
type CamelCased<T> = T extends Array<infer E> ? Array<CamelCased<E>> : T extends Date | Map<unknown, unknown> | Set<unknown> ? T : T extends object ? {
|
|
39
|
+
[K in keyof T as K extends string ? SnakeToCamel<K> : K]: CamelCased<T[K]>;
|
|
40
|
+
} : T;
|
|
41
|
+
/**
|
|
42
|
+
* Recursively re-case all property keys of `value` to `snake_case`. The return
|
|
43
|
+
* type maps keys for the common identifier case (see {@link SnakeCased}).
|
|
44
|
+
*/
|
|
45
|
+
declare function toSnakeCase<T>(value: T): SnakeCased<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Recursively re-case all property keys of `value` to `camelCase`. The return
|
|
48
|
+
* type maps keys for the common identifier case (see {@link CamelCased}).
|
|
49
|
+
*/
|
|
50
|
+
declare function toCamelCase<T>(value: T): CamelCased<T>;
|
|
51
|
+
/** Convert a single key to `kebab-case`; leave unconvertible keys untouched. */
|
|
52
|
+
declare function toKebabKey(key: string): string;
|
|
53
|
+
/** Convert a single key to `PascalCase`; leave unconvertible keys untouched. */
|
|
54
|
+
declare function toPascalKey(key: string): string;
|
|
55
|
+
/** Convert a single key to `CONSTANT_CASE`; leave unconvertible keys untouched. */
|
|
56
|
+
declare function toConstantKey(key: string): string;
|
|
57
|
+
/** Recursively re-case all property keys of `value` to `kebab-case`. */
|
|
58
|
+
declare function toKebabCase<T = unknown>(value: T): T;
|
|
59
|
+
/** Recursively re-case all property keys of `value` to `PascalCase`. */
|
|
60
|
+
declare function toPascalCase<T = unknown>(value: T): T;
|
|
61
|
+
/** Recursively re-case all property keys of `value` to `CONSTANT_CASE`. */
|
|
62
|
+
declare function toConstantCase<T = unknown>(value: T): T;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Composable operations over a {@link TypeMapper}: batch mapping, safe (non-throwing)
|
|
66
|
+
* forward, sub-DTO views (pick/omit), and map composition. Kept out of
|
|
67
|
+
* `createMap.ts` to respect the per-file size budget; `createMap` attaches thin
|
|
68
|
+
* instance wrappers so these are available as both methods and free functions.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/** Minimal mapper shape these ops need (avoids importing the full createMap type cycle). */
|
|
72
|
+
interface MappableForward {
|
|
73
|
+
forward(source: Record<string, unknown>): unknown;
|
|
74
|
+
reverse(dto: unknown): Partial<Record<string, unknown>>;
|
|
75
|
+
readonly schema: z.ZodObject<any>;
|
|
76
|
+
}
|
|
77
|
+
/** Result of {@link safeForward}: a discriminated success/failure union. */
|
|
78
|
+
type SafeResult<T> = {
|
|
79
|
+
success: true;
|
|
80
|
+
data: T;
|
|
81
|
+
} | {
|
|
82
|
+
success: false;
|
|
83
|
+
error: z.ZodError;
|
|
84
|
+
};
|
|
85
|
+
/** Forward every item in `sources`, returning the validated DTO array. */
|
|
86
|
+
declare function forwardMany<M extends MappableForward>(map: M, sources: Array<Record<string, unknown>>): Array<ReturnType<M["forward"]>>;
|
|
87
|
+
/** Reverse every DTO in `dtos`, returning the mapped-source array. */
|
|
88
|
+
declare function reverseMany<M extends MappableForward>(map: M, dtos: unknown[]): Array<Partial<Record<string, unknown>>>;
|
|
89
|
+
/**
|
|
90
|
+
* Forward without throwing: returns `{ success: true, data }` or, on a Zod
|
|
91
|
+
* validation failure, `{ success: false, error }`. Non-Zod errors still throw.
|
|
92
|
+
*/
|
|
93
|
+
declare function safeForward<M extends MappableForward>(map: M, source: Record<string, unknown>): SafeResult<ReturnType<M["forward"]>>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* `createMap(destSchema, rules)` — synchronous, Zod-validated entity -> DTO
|
|
97
|
+
* mapper. The dest Zod schema is the shape source of truth. Simple string
|
|
98
|
+
* renames and `{ to, from }` pairs auto-reverse; computed function rules are
|
|
99
|
+
* one-way unless paired.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Resolver graph declared on a map: each field of the dest DTO `Dest` may have
|
|
104
|
+
* a resolver typed against `Dest` and the adapter `TAdapter`.
|
|
105
|
+
*/
|
|
106
|
+
type MapResolvers<Dest = Record<string, unknown>, TAdapter = unknown> = ResolverRegistry<Dest, TAdapter>;
|
|
107
|
+
/** Options for {@link createMap}, parameterized by the dest DTO and adapter type. */
|
|
108
|
+
interface CreateMapOptions<Dest = Record<string, unknown>, TAdapter = unknown> {
|
|
109
|
+
/**
|
|
110
|
+
* Resolver graph for this map's fields, against the map's own dest schema.
|
|
111
|
+
* Enables `map.toResolver(adapter)` and resolver-backed `forwardAsync` without
|
|
112
|
+
* a separate `createResolver` call. Each resolver's output is typed against the
|
|
113
|
+
* DTO field it produces. NOTE: `ctx.adapter` is typed as the concrete adapter
|
|
114
|
+
* only at the `toResolver(adapter)` call site — inside these declarations it is
|
|
115
|
+
* `unknown` (the adapter is not known at `createMap` time); cast it if needed.
|
|
116
|
+
*/
|
|
117
|
+
resolvers?: MapResolvers<Dest, TAdapter>;
|
|
118
|
+
}
|
|
119
|
+
/** Thrown when `reverse` meets a one-way function rule that has no inverse. */
|
|
120
|
+
declare class OneWayRuleError extends Error {
|
|
121
|
+
readonly key: string;
|
|
122
|
+
constructor(key: string);
|
|
123
|
+
}
|
|
124
|
+
/** Thrown when `toResolver` is called on a map that declared no resolvers. */
|
|
125
|
+
declare class MapHasNoResolversError extends Error {
|
|
126
|
+
constructor();
|
|
127
|
+
}
|
|
128
|
+
/** Thrown at build time when two rules reverse onto the same source key. */
|
|
129
|
+
declare class ReverseKeyCollisionError extends Error {
|
|
130
|
+
constructor(sourceKey: string, a: string, b: string);
|
|
131
|
+
}
|
|
132
|
+
type AnyZodObject = z.ZodObject<any>;
|
|
133
|
+
/** Rule map: each dest key may carry a rule; unmapped keys are copied by name. */
|
|
134
|
+
type RuleMap<Dest> = Partial<Record<keyof Dest & string, Rule>>;
|
|
135
|
+
interface TypeMapper<S extends AnyZodObject, R extends RuleMap<z.infer<S>>> {
|
|
136
|
+
/** Build a validated DTO from a source entity (sync path). */
|
|
137
|
+
forward(source: Record<string, unknown>): z.infer<S>;
|
|
138
|
+
/** Forward every item in a list, returning the validated DTO array. */
|
|
139
|
+
forwardMany(sources: Array<Record<string, unknown>>): Array<z.infer<S>>;
|
|
140
|
+
/** Forward without throwing: `{ success, data }` or `{ success: false, error }`. */
|
|
141
|
+
safeForward(source: Record<string, unknown>): SafeResult<z.infer<S>>;
|
|
142
|
+
/** Invert reversible rules; returns only mapped source fields. */
|
|
143
|
+
reverse(dto: z.infer<S>): Partial<Record<string, unknown>>;
|
|
144
|
+
/** Reverse every DTO in a list. */
|
|
145
|
+
reverseMany(dtos: Array<z.infer<S>>): Array<Partial<Record<string, unknown>>>;
|
|
146
|
+
/**
|
|
147
|
+
* Recursively re-case ALL property keys of `value` to `snake_case`,
|
|
148
|
+
* regardless of their original casing. Keys only; values pass through.
|
|
149
|
+
*/
|
|
150
|
+
toSnakeCase<T>(value: T): SnakeCased<T>;
|
|
151
|
+
/**
|
|
152
|
+
* Recursively re-case ALL property keys of `value` to `camelCase`,
|
|
153
|
+
* regardless of their original casing. Keys only; values pass through.
|
|
154
|
+
*/
|
|
155
|
+
toCamelCase<T>(value: T): CamelCased<T>;
|
|
156
|
+
/**
|
|
157
|
+
* Build a resolver graph from THIS map's schema fields plus the resolver
|
|
158
|
+
* graph declared in `createMap`'s options. The resolver validates each field's
|
|
159
|
+
* output against the matching dest sub-schema (over-exposure protection).
|
|
160
|
+
* Throws if no `resolvers` were declared on the map.
|
|
161
|
+
*/
|
|
162
|
+
toResolver<TAdapter>(adapter: TAdapter, seed?: Partial<z.infer<S>>): ResolverContext<z.infer<S>, TAdapter>;
|
|
163
|
+
/** The dest schema (shape source of truth). */
|
|
164
|
+
readonly schema: S;
|
|
165
|
+
/** Configured rules, frozen. */
|
|
166
|
+
readonly rules: R;
|
|
167
|
+
/** Raw `.shape` of the dest object — used by the async path (Phase 5). */
|
|
168
|
+
readonly shape: Record<string, z.ZodType>;
|
|
169
|
+
/** Resolver graph declared on this map (if any), for `toResolver`/forwardAsync. */
|
|
170
|
+
readonly resolvers?: MapResolvers<z.infer<S>>;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Build a two-way mapper. The `const` type parameter on `R` preserves bare
|
|
174
|
+
* object-literal rule values (string-literal renames) without the caller
|
|
175
|
+
* writing `as const` (requires TypeScript >= 5.0).
|
|
176
|
+
*/
|
|
177
|
+
declare function createMap<S extends AnyZodObject, const R extends RuleMap<z.infer<S>>>(schema: S, rules?: R, options?: CreateMapOptions<z.infer<S>>): TypeMapper<S, R>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Map-deriving helpers that produce NEW {@link TypeMapper} instances: sub-DTO
|
|
181
|
+
* views (`pick`/`omit`) and composition (`compose`). Kept separate from
|
|
182
|
+
* `createMap.ts` so it can import `createMap` without a circular dependency.
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
type AnyMapper = TypeMapper<z.ZodObject<any>, any>;
|
|
186
|
+
/** A map over only `keys` of `map`'s DTO (identity rules; no transforms carried). */
|
|
187
|
+
declare function pick<M extends AnyMapper>(map: M, keys: string[]): AnyMapper;
|
|
188
|
+
/** A map over `map`'s DTO minus `keys`. */
|
|
189
|
+
declare function omit<M extends AnyMapper>(map: M, keys: string[]): AnyMapper;
|
|
190
|
+
/**
|
|
191
|
+
* Compose two maps into a DTO->DTO pipeline: `compose(a, b).forward(src)` runs
|
|
192
|
+
* `b.forward(a.forward(src))`, validating against `b`'s schema. Reverse pipes
|
|
193
|
+
* back through `a.reverse(b.reverse(dto))`.
|
|
194
|
+
*
|
|
195
|
+
* `forwardMany`/`safeForward`/`reverseMany` honor the composed pipeline. Reverse
|
|
196
|
+
* only round-trips fields BOTH maps carry a reversible rule for (identity links
|
|
197
|
+
* with no rule emit nothing on reverse). `toResolver` is unsupported on a
|
|
198
|
+
* composed map (it declares no resolver graph) and throws.
|
|
199
|
+
*/
|
|
200
|
+
declare function compose<A extends AnyMapper, B extends AnyMapper>(a: A, b: B): AnyMapper;
|
|
201
|
+
|
|
202
|
+
declare const VERSION = "0.1.0";
|
|
203
|
+
|
|
204
|
+
export { type CamelCased, MapHasNoResolversError, OneWayRuleError, ReverseKeyCollisionError, Rule, type RuleMap, type SafeResult, type SnakeCased, type TypeMapper, VERSION, compose, createMap, forwardMany, omit, pick, reverseMany, safeForward, splitWords, toCamelCase, toCamelKey, toConstantCase, toConstantKey, toKebabCase, toKebabKey, toPascalCase, toPascalKey, toSnakeCase, toSnakeKey };
|