import type { Application, Id, Paginated, Params } from '@feathersjs/feathers' import type { UnwrapArray } from '../internal.utils.js' type AsArray = T extends any[] ? T : [T] // MARK: get export type InferGetResult = S extends { get: (id: any, params: any) => infer R } ? Awaited : never export type InferGetResultFromPath< App extends Application, Path extends string, > = InferGetResult> // MARK: find export type InferFindResult = S extends { find: (params: any) => infer R } ? Awaited : never export type InferFindResultFromPath< App extends Application, Path extends string, > = InferFindResult> export type InferFindResultSingle< S, R extends InferFindResult = InferFindResult, > = R extends Paginated ? UnwrapArray : R extends any[] ? UnwrapArray : R export type InferFindParams = S extends { find: (params: infer P) => any } ? P extends Params ? P : Params : Params // MARK: create export type InferCreateData = S extends { create: (data: infer D, params: any) => any } ? D : never export type InferCreateDataSingle = UnwrapArray> export type InferCreateResult = S extends { create: (data: any, params: any) => infer R } ? D extends any[] ? AsArray> : D extends InferCreateDataSingle ? UnwrapArray> : Awaited : never export type InferCreateResultSingle = UnwrapArray> export type InferCreateDataFromPath< App extends Application, Path extends string, > = InferCreateData> export type InferCreateDataSingleFromPath< App extends Application, Path extends string, > = InferCreateDataSingle> export type InferCreateResultFromPath< App extends Application, Path extends string, D = unknown, > = InferCreateResult, D> export type InferCreateResultSingleFromPath< App extends Application, Path extends string, > = InferCreateResultSingle> // MARK: update export type InferUpdateData = S extends { update: (id: any, data: infer D, params: any) => any } ? D : never export type InferUpdateResult = S extends { update: (id: any, data: any, params: any) => infer R } ? Awaited : never export type InferUpdateDataFromPath< App extends Application, Path extends string, > = InferUpdateData> export type InferUpdateResultFromPath< App extends Application, Path extends string, > = InferUpdateResult> // MARK: patch export type InferPatchData = S extends { patch: (id: any, data: infer D, params: any) => any } ? D : never export type InferPatchResult = S extends { patch: (id: Id, data: any, params: any) => infer R } ? IdOrNullable extends Id ? UnwrapArray> : IdOrNullable extends null ? AsArray> : Awaited : never export type InferPatchDataFromPath< App extends Application, Path extends string, > = InferPatchData> export type InferPatchResultFromPath< App extends Application, Path extends string, IdOrNullable = any, > = InferPatchResult, IdOrNullable> // MARK: remove export type InferRemoveResult = S extends { remove: (id: IdOrNullable, params: any) => infer R } ? IdOrNullable extends Id ? UnwrapArray> : IdOrNullable extends null ? AsArray> : Awaited : never export type InferRemoveResultFromPath< App extends Application, Path extends string, IdOrNullable = any, > = InferRemoveResult, IdOrNullable> export type GetService< App extends Application, Path extends string, > = App['services'][Path] export type InferDataFromPath< App extends Application, Path extends string, Method extends 'create' | 'update' | 'patch', > = Method extends 'create' ? InferCreateDataFromPath : Method extends 'update' ? InferUpdateDataFromPath : Method extends 'patch' ? InferPatchDataFromPath : never export type InferResultFromPath< App extends Application, Path extends string, Method extends 'get' | 'find' | 'create' | 'update' | 'patch' | 'remove', > = Method extends 'get' ? InferGetResultFromPath : Method extends 'find' ? InferFindResultFromPath : Method extends 'create' ? InferCreateResultFromPath : Method extends 'update' ? InferUpdateResultFromPath : Method extends 'patch' ? InferPatchResultFromPath : Method extends 'remove' ? InferRemoveResultFromPath : never