import { type Maybe } from '@dereekb/util'; import { type, type Type } from 'arktype'; /** * A value that can be set to a value of `T`, or cleared by setting to `null` or `undefined`. * * Structurally equivalent to {@link Maybe}, but semantically distinct: * - `Maybe` — the value might not exist (absence is passive) * - `Clearable` — `null` actively signals "clear/reset this field", while `undefined` means "leave unchanged" * * Used in API update params where `null` tells the server to delete/reset a field. * See {@link clearable} for the ArkType schema equivalent. * * @example * ```typescript * interface UpdateUserParams { * name?: string; // required when present * phone?: Clearable; // can be set, or cleared with null * } * ``` */ export type Clearable = Maybe; /** * An update to an object's values where every key is optional and {@link Clearable}. * * A `null` value clears the key, and an `undefined` value leaves it unchanged. Apply it with {@link mergeClearableObjectUpdate}. */ export type ClearableObjectUpdate = { readonly [K in keyof T]?: Clearable; }; /** * Merges a {@link ClearableObjectUpdate} into the current object and returns the result as a new object. * * A `null` value in the update deletes the key, and an `undefined` value leaves the current value unchanged. * `null` and `undefined` values already on the current object are dropped too, so the result only holds set values. * * @param current - The current object. Null/undefined is treated as an empty object. * @param update - The update to merge in. Null/undefined returns a copy of the current values. * @returns A new object with the update applied. Neither input is modified. * * @dbxUtil * @dbxUtilCategory object * @dbxUtilTags object, merge, update, patch, clear, clearable, null, delete * @dbxUtilRelated merge-objects, strip-object * * @example * ```ts * mergeClearableObjectUpdate({ a: 1, b: 2 }, { b: null, c: 3, d: undefined }); * // { a: 1, c: 3 } * ``` */ export declare function mergeClearableObjectUpdate(current: Maybe>, update: Maybe>): Partial; /** * Singleton ArkType schema that accepts any empty object (`{}`). * * Used as the canonical "no params" type for model API actions that require an ArkType schema but have no meaningful input fields. * * @example * ```typescript * export const doSomethingParamsType = emptyType(); * ``` */ export declare const EMPTY_ARKTYPE_TYPE: Type<{}>; /** * Returns the shared {@link EMPTY_ARKTYPE_TYPE} cast to the requested type, providing a typed empty-object schema * without creating a new ArkType instance each time. * * @returns The singleton empty type schema typed as `Type` * * @example * ```typescript * export interface ResyncAllParams {} // has no params currently * export const resyncAllParamsType = emptyType(); * ``` */ export declare function emptyType(): Type; /** * Creates an ArkType schema that accepts the given ArkType definition OR null/undefined. * Used for fields where null acts as a "clear/reset" signal for the model. * * The dbx-components library uses null in API calls to signal that something can be deleted entirely, * whereas undefined is simply treated as an ignore. * * Accepts either a string definition or a Type instance. * * @example * ```typescript * const schema = type({ * "sdat?": clearable("string.date.parse"), // string definition * "phone?": clearable(e164PhoneNumberType), // Type instance * "items?": clearable(mySchemaType.array()), // .array() result * }); * * // For tuple expressions (e.g. intersections), resolve to a Type first: * const zipType = type([/^\d{5}(-\d{4})?$/, '&', `string <= 11`]); * const schema2 = type({ * "zip?": clearable(zipType), * }); * ``` * * @param definition The ArkType definition string or Type instance to make clearable. * @returns An ArkType schema that accepts the defined type, null, or undefined. */ export declare function clearable(definition: def): Type>>; export declare function clearable(definition: Type): Type>; /** * JSON Schema export helper that compensates for arktype's lossy export of narrow predicates, * morphs, and `undefined`. Without this:. * * - narrowed strings like `type('string > 0').narrow(...)` export as the empty schema `{}` * because arktype drops the narrow predicate and has no JSON-shaped base to fall back on. * - {@link clearable} (a `T | null | undefined` union) exports as `anyOf: [, {}, {type:"null"}]` * because `undefined` has no JSON Schema equivalent. * * The fallback config: * - `predicate` / `morph` — drop the lossy wrapper, keep the JSON-shaped base (e.g. a narrowed * `string > 0` becomes `{type:"string", minLength:1}`). * - `default` — emit `false` (matches nothing). This is a no-op inside `anyOf`, and * {@link pruneFalseUnionBranches} strips it so `T | null | undefined` reads as `T | null`. * * The result is round-tripped through `JSON.parse(JSON.stringify(...))` to invoke arktype's * boxed-node `toJSON()` callbacks before pruning; `structuredClone` would not call them. * * @param t - The arktype Type to export. * @returns The pruned JSON Schema fragment as a plain object. */ export declare function arktypeToJsonSchemaForExport(t: Type): unknown; /** * Walks a JSON Schema and removes `false` entries from `anyOf` / `oneOf` arrays. `false` * schemas match nothing, so dropping them does not change what the schema accepts — it * just keeps the rendered output clean when {@link arktypeToJsonSchemaForExport}'s * `() => false` fallback emitted no-op branches for unjsonifiable types like `undefined`. * * @param value - JSON Schema fragment to clean. * @returns A structurally equivalent fragment with `false` branches dropped from any * `anyOf` / `oneOf` arrays. */ export declare function pruneFalseUnionBranches(value: unknown): unknown;