import { t as Id } from "./types-hGBnCpJj.mjs"; import { a as IdVerifiableCodec, t as IdCodec } from "./adapter-types-B-GLKPOm.mjs"; import { n as IdsErrorCode, r as isIdsError, t as IdsError } from "./error-JLZfeGOx.mjs"; import { GraphQLFieldResolver, GraphQLScalarType } from "graphql"; //#region src/adapters/graphql.d.ts /** Extension of {@link IdCodec} that also requires `is()` — used by `idScalar` so `serialize` can validate strictly on the trusted outbound path. All concrete codec variants satisfy this. */ type GraphQLCodec = IdCodec & { is(value: unknown): value is Id; }; /** {@link IdsError} class, {@link isIdsError} type guard, and {@link IdsErrorCode} union — re-exported from `"@smonn/ids"` for convenience. */ /** * Builds a `GraphQLScalarType` for the given codec and brand. * * - `serialize` — validates strictly via `codec.is()`; throws `GraphQLError` on a non-canonical * value and returns the value **unchanged** (no normalization) on success. * - `parseValue` — validates variables via `codec.safeParse`; throws `GraphQLError` on failure. * Accepts mixed-case and Crockford visual aliases; always returns the canonical form. * - `parseLiteral` — validates inline `Kind.STRING` literals the same way as `parseValue`; throws * `GraphQLError` for any other AST kind or on a failed `safeParse`. * * `graphql` must be installed as a peer dependency. * * @example * ```ts * import { idScalar } from "@smonn/ids/graphql"; * import { createTimestampId } from "@smonn/ids"; * * const usr = createTimestampId("usr"); * const UserIdScalar = idScalar(usr, { name: "UserId", description: "A branded user ID." }); * ``` */ declare function idScalar(codec: GraphQLCodec, config: { name: string; description?: string; }): GraphQLScalarType, string>; /** * Wraps a GraphQL field resolver so the named ID arguments are authenticated before the resolver * body runs. * * GraphQL scalar coercers (`parseValue`/`parseLiteral`) are synchronous and cannot await the HMAC * check, so `idScalar` cannot verify a Signed Timestamp tag itself. `verifyIdArgs` performs that * async verification one layer out, at the resolver. For each `argName → codec` entry it calls * `codec.safeVerify(args[argName])`; a forged or tampered tag throws `GraphQLError` **before** the * wrapped resolver runs. A `null`/`undefined` arg is skipped (nullable/absent args pass through). * Present args are verified in map order and the first failure short-circuits. * * Both the **Signed Timestamp codec** and the **Wrapped key codec** satisfy * {@link IdVerifiableCodec}; passing any other codec is a compile-time type error. Verification * covers top-level args only — IDs nested inside input objects are not reached. * * **Pair with {@link idScalar}.** The wrapper checks the tag but returns `args` unchanged — it does * not substitute the canonical `id` from `safeVerify`. Front each verified arg with an `idScalar` * built from the same codec so `parseValue`/`parseLiteral` canonicalises the value (case, Crockford * aliases) before the resolver runs; on a plain `GraphQLString` arg a non-canonical variant would * verify yet reach the resolver un-normalised. * * **Only listed args are verified, and keys must match the field's argument names exactly.** On the * first invocation **for each schema coordinate** (`ParentType.fieldName`) the wrapper resolves * the field's declared argument names from `info` and throws a `GraphQLError` if any codec-map key * does not match a declared argument — hardening so a typo cannot silently disable verification. * Subsequent invocations on the **same coordinate** use the cached result. If the field cannot be * found in `parentType.getFields()`, the arg-name guard is skipped for that coordinate — this path * is **not** fail-closed for unknown fields — but per-ID `safeVerify` still runs on every * invocation regardless. * * @example * ```ts * import { verifyIdArgs } from "@smonn/ids/graphql"; * * const resolve = verifyIdArgs({ userId: usr }, (_root, args, ctx) => { * // args.userId is an authenticated Id<"usr"> * return ctx.loadUser(args.userId); * }); * ``` */ declare function verifyIdArgs = Record>(codecs: { [K in keyof TArgs]?: IdVerifiableCodec }, resolver: GraphQLFieldResolver): GraphQLFieldResolver; //#endregion export { IdsError, type IdsErrorCode, idScalar, isIdsError, verifyIdArgs }; //# sourceMappingURL=graphql.d.mts.map