import { ServiceInstance } from './modeling/index.js'; import { AnyData, Params, Query } from './types.js'; import { UseFindOptions, UseFindParams, UseGetParams } from './use-find-get/index.js'; import { ComputedRef } from 'vue-demi'; import { MaybeRef } from '@vueuse/core'; import { FeathersService, Id, Paginated, PaginationOptions } from '@feathersjs/feathers'; interface PiniaServiceOptions { servicePath: string; store: any; methods?: string[]; events?: string[]; } type SvcResult = S extends { get: (...args: any[]) => Promise; } ? T : never; type SvcParams = (S extends { find: (params: infer T) => any; } ? T : never) & Params; type SvcData = S extends { create: (data: (infer T)[]) => any; } ? T : never; type SvcPatchData = S extends { patch: (id: any, data: infer T) => any; } ? T : never; type SvcModel = ServiceInstance>; export declare class PiniaService { service: Svc; options: PiniaServiceOptions; store: any; servicePath: string; constructor(service: Svc, options: PiniaServiceOptions); /** * Prepare new "instances" outside of store * * Functionally upgrades plain data to a service model "instance". * - flags each record with `__isSetup` to avoid duplicate work. */ new(data?: Partial>): SvcModel; /** * finds records from the API server by query. Each record is reactive. Lists are non reactive. * For reactive lists, use `findInStore`. */ find(params?: MaybeRef & { paginate?: PaginationOptions; }>): Promise>>; find(params?: MaybeRef & { paginate: false; }>): Promise[]>; find(params?: MaybeRef>): Promise> | SvcModel[]>; find(params?: MaybeRef>): Promise> | SvcModel[]>; /** * finds a single record from the API server by query. The record is reactive. */ findOne(params?: MaybeRef>): Promise>; /** * count records on the API server by query. Returns the number of matching records. */ count(params?: MaybeRef>): Promise>; /** * retrieve a record from the API server by id. The record is reactive. */ get(id: Id, params?: MaybeRef>): Promise>; /** * create a record on the API server. */ create(data: SvcData, params?: MaybeRef>): Promise>; /** * patch a record on the API server. */ patch(id: Id, data: SvcPatchData, params?: MaybeRef>): Promise>; patch(id: null, data: SvcPatchData, params: MaybeRef>): Promise[]>; /** * remove a record from the API server. */ remove(id: MaybeRef, params?: MaybeRef>): Promise>; remove(id: MaybeRef, params: MaybeRef>): Promise[]>; /** * find records in the local store. The returned list and records are reactive. */ findInStore(params?: MaybeRef & { paginate?: PaginationOptions; }>): Paginated>; findInStore(params?: MaybeRef & { paginate: false; }>): SvcModel[]; findInStore(params?: MaybeRef>): Paginated> | SvcModel[]; findInStore(params?: MaybeRef>): Paginated> | SvcModel[]; /** * find a single record in the local store by query. */ findOneInStore(params?: MaybeRef>): ComputedRef>; /** * count records matching a query in the store. */ countInStore(params?: MaybeRef>): Paginated; /** * get a single record from the store by id */ getFromStore(id: MaybeRef, params: MaybeRef>): ComputedRef>; getFromStore(id: MaybeRef, params?: MaybeRef>): ComputedRef>; /** * creates or adds an item to the store. */ createInStore(data: SvcData): SvcModel; /** * patches an item in the store */ patchInStore(id: MaybeRef>, data: SvcPatchData, params?: MaybeRef>): SvcModel; patchInStore(id: MaybeRef[]>, data: SvcPatchData, params: MaybeRef>): SvcModel[]; /** * removes one or more items from the store. */ removeFromStore(id: Id, params?: MaybeRef>): SvcModel; removeFromStore(id: undefined | null, params: MaybeRef>): SvcModel[]; useFind(params: ComputedRef, options?: UseFindOptions): { paramsWithPagination: Params; isSsr: boolean; qid: string; data: (SvcModel | M)[]; allLocalData: (SvcModel | M)[]; total: number; limit: number; skip: number; currentQuery: import('./types.js').ExtendedQueryInfo; cachedQuery: import('./types.js').ExtendedQueryInfo; latestQuery: import('./types.js').ExtendedQueryInfo; previousQuery: import('./types.js').ExtendedQueryInfo; find: () => Promise; request: Promise | M>> | null; requestCount: number; queryWhen: (queryWhenFn: () => boolean) => void; isPending: boolean; haveBeenRequested: boolean; haveLoaded: boolean; error: any; clearError: () => void; pageCount: number; currentPage: number; canPrev: boolean; canNext: boolean; next: () => Promise; prev: () => Promise; toStart: () => Promise; toEnd: () => Promise; toPage: (page: number) => Promise; }; useGet(id: MaybeRef, params?: MaybeRef): { params: UseGetParams; isSsr: boolean; data: SvcModel | M | null; ids: Id[]; getFromStore: any; get: () => Promise; request: { then: (onfulfilled?: ((value: AnyData) => TResult1 | PromiseLike) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null | undefined) => Promise; catch: (onrejected?: ((reason: any) => TResult | PromiseLike) | null | undefined) => Promise; finally: (onfinally?: (() => void) | null | undefined) => Promise; readonly [Symbol.toStringTag]: string; } | null; requestCount: number; queryWhen: (_queryWhenFn: () => boolean) => void; isPending: boolean; hasBeenRequested: boolean; hasLoaded: boolean; error: any; clearError: () => null; }; useGetOnce(_id: MaybeRef, params?: MaybeRef): { params: UseGetParams; isSsr: boolean; data: SvcModel | M | null; ids: Id[]; getFromStore: any; get: () => Promise; request: { then: (onfulfilled?: ((value: AnyData) => TResult1 | PromiseLike) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null | undefined) => Promise; catch: (onrejected?: ((reason: any) => TResult | PromiseLike) | null | undefined) => Promise; finally: (onfinally?: (() => void) | null | undefined) => Promise; readonly [Symbol.toStringTag]: string; } | null; requestCount: number; queryWhen: (_queryWhenFn: () => boolean) => void; isPending: boolean; hasBeenRequested: boolean; hasLoaded: boolean; error: any; clearError: () => null; }; on(eventName: string | symbol, listener: (...args: any[]) => void): FeathersService | undefined; emit(eventName: string | symbol, ...args: any[]): boolean; removeListener(eventName: string | symbol, listener: (...args: any[]) => void): FeathersService | undefined; } export {};