import type { Operation, OperationIndex, Parameters, Request, Response } from '../../internal/operation.js'; /** * This module contains functionality for narrowing the response type based on input parameters. * * For example, when requesting a product, specifying `{ include_fields: ['sku'] }` will cause BigCommerce * to only return the `id` and `sku` fields (as `id` is always returned). This module ensures that response * types reflect the query parameters which were passed in the request. * * Currently, this module supports `include`, `include_fields` and `exclude_fields`. */ /** * @description Modifies the response type to reflect optional include, include_fields, and exclude_fields parameters */ export type NarrowResponse = NarrowResponse_>; type Includes = Op['parameters'] extends { query?: { include?: infer T; }; } ? T extends ReadonlyArray ? E : T extends string ? T : never : never; type NarrowResponse_ = Rep extends { body: { data?: infer Data; meta?: infer Meta; }; } ? { status: Rep['status']; body: { data: NarrowData; meta: Meta; }; } : Rep; type NarrowData | undefined, Includes extends string> = Data extends ReadonlyArray ? ReadonlyArray> : Required, Query> & NarrowIncludes, Query>>; type NarrowFields | undefined> = Query extends { include_fields: ReadonlyArray; } ? Pick : Query extends { exclude_fields: ReadonlyArray; } ? Omit : Data; type NarrowIncludes | undefined> = Query extends { include: ReadonlyArray; } ? Pick : {}; export {};