/** * Request Context Types * * Stage-based context metadata for request typing. * * @module */ import type { RequestFilters } from './filters.js'; import type { CollectionName } from './graph.js'; import type { InferResponseType } from './response-routes.js'; import type { FilterKeyForStage, NavigationMethodNamesForStage, OutValueForStage, RouteStage } from './schema.js'; type ResourceStage = Extract; type StageTerminalSegment = TStage extends `${string}.${infer TLast}` ? TLast : TStage; type StageLastSegment = TStage extends 'root' ? 'none' : TStage extends ResourceStage ? 'resource' : StageTerminalSegment extends CollectionName ? 'collection' : 'subResource'; export interface BaseRequestContext = never> { stage: TStage; selectedOut: TSelectedOut[]; pathSegments: string[]; filters: RequestFilters; method: 'GET' | 'POST' | 'PUT' | 'DELETE'; } export type RootRequestContext = BaseRequestContext<'root'> & { hasResource: false; lastSegment: 'none'; }; export type StageRequestContext = Exclude, TSelectedOut extends OutValueForStage = never> = BaseRequestContext & { hasResource: true; lastSegment: StageLastSegment; }; export type RequestContext = never> = TStage extends 'root' ? RootRequestContext : StageRequestContext, TSelectedOut>; export type FilterKeysForContext = FilterKeyForStage; type SelectedOutForContext = T extends RequestContext ? Extract> : never; export type ResponseTypeForContext = InferResponseType>; export type CanAddCollection = Extract, CollectionName> extends never ? false : true; export type CanAddSubResource = OutValueForStage extends never ? false : true; export type CanExecute = T['stage'] extends 'root' ? false : true; export type LastSegmentType = T['lastSegment']; export {}; //# sourceMappingURL=context.d.ts.map