import type { ResourceCodec } from '../codec.js'; import type { ClientContext } from './request.js'; import type { CollectionMetadata, EncryptionOverride, IZcap } from '../types.js'; /** * The outcome of one codec resolution: the codec itself, plus the collection * metadata snapshot the resolution happened to read on the way (the index * schema read a blinded-index codec performs). `meta` is absent when the * resolution read no metadata at all -- a plaintext or non-indexing codec, or a * server with no Collection metadata surface -- and `null` when the read found * none (missing or not visible). */ export interface CodecResolution { codec: ResourceCodec; meta?: (CollectionMetadata & { etag?: string; }) | null; } /** * A per-handle codec cache. Memoizes the in-flight resolution so concurrent * callers share one round-trip, but drops it on rejection so a transient * failure (e.g. a 500/network error during descriptor discovery) does not * permanently poison the handle, and exposes `reset()` for when a handle's * encryption state changes (e.g. `Collection.configure()` adds the descriptor). * * It also carries the metadata snapshot a resolution read, so the caller that * paid for that read can reuse it instead of GETting `/meta` a second time. * The snapshot is consume-once and initiator-only (see {@link * CodecHolder.resolve}): it is a point-in-time copy, and handing it to a later * caller would serve metadata another client may have overwritten since. */ export declare class CodecHolder { #private; /** * @param resolve {function} resolves a fresh codec; re-invoked after a * rejection or a `reset()`, else called at most once */ constructor(resolve: () => Promise); /** * Returns the memoized codec, resolving it on first use. Discards any * metadata snapshot the resolution read, so no copy of it outlives the call. * * @returns {Promise} */ get(): Promise; /** * Returns the memoized codec together with the metadata snapshot its * resolution read -- but only when this very call started that resolution. * Any other caller (the codec was already resolved, or another call is * already resolving it) gets `meta: undefined` and must read `/meta` itself, * because a snapshot taken for an earlier operation may already be stale. The * snapshot is handed out at most once, and `reset()` drops it. * * @returns {Promise} */ resolve(): Promise; /** * Drops any memoized codec so the next `get()` re-resolves. * * @returns {void} */ reset(): void; } /** * The collection a codec is being resolved for, plus the per-handle inputs that * decide it: the encryption override and the handle's bound capability. Shared * by {@link collectionCodecHolder} and {@link resolveCodec}, which forwards it * through unchanged. */ interface CodecTarget { spaceId: string; collectionId: string; override?: EncryptionOverride; capability?: IZcap; } /** * Builds the per-handle {@link CodecHolder} for a collection's codec -- the * one resolver wiring shared by the `Collection` and standalone `Resource` * constructors, so the two cannot drift. * * @param context {ClientContext} * @param options {object} * @param options.spaceId {string} * @param options.collectionId {string} * @param [options.override] {EncryptionOverride} per-handle override * @param [options.capability] {IZcap} the handle's bound capability * @returns {CodecHolder} */ export declare function collectionCodecHolder(context: ClientContext, options: CodecTarget): CodecHolder; /** * The default codec: passes plaintext through unchanged. `encode` echoes the * caller's `id` (so `put(id, ...)` is a `PUT` and `add(...)`, with no id, stays * a server-minting `POST`) and reuses `prepareBody` -- including the * filename-extension content-type guess when an id is present. `decode` reuses * `parseResource`. `encodeMeta` / `decodeMeta` are the identity transform, so * metadata round-trips as server-visible plaintext byte-for-byte. */ export declare const identityCodec: ResourceCodec; /** * Resolves the codec for a collection by deciding policy (override > descriptor * > plaintext) and then, when encrypted, building the encrypting codec from the * keystore. Fails closed: a collection declared encrypted (by override or * descriptor) for which no codec can be built throws {@link EncryptionError} * rather than falling back to {@link identityCodec}. * * @param context {ClientContext} * @param options {object} * @param options.spaceId {string} * @param options.collectionId {string} * @param [options.override] {EncryptionOverride} per-handle override; wins * over the descriptor and skips the descriptor read * @param [options.capability] {IZcap} the handle's bound capability, used for * the descriptor-discovery describe (which happens only when there is no * override and the client has a keystore) * @returns {Promise} the codec, plus the metadata snapshot * the index-schema read produced when there was one */ export declare function resolveCodec(context: ClientContext, { spaceId, collectionId, override, capability }: CodecTarget): Promise; export {}; //# sourceMappingURL=codec.d.ts.map