import * as _feathersjs_feathers from '@feathersjs/feathers'; import { HookContext, Id, Application, Service, Query, Paginated, Params } from '@feathersjs/feathers'; import { GraphQLFieldResolver, parse } from 'graphql'; import { Ajv, Options, ErrorObject } from 'ajv'; declare const hookTypes: readonly ["around", "before", "after", "error"]; type HookType = typeof hookTypes[number]; declare const methodNames: readonly ["find", "get", "create", "update", "patch", "remove"]; type MethodName = typeof methodNames[number]; type TransportName = 'socketio' | 'rest' | 'external' | 'server'; type SyncContextFunction = (context: H) => T; type AsyncContextFunction = (context: H) => Promise; type ContextFunction = (context: H) => T | Promise; type SyncPredicateFn = SyncContextFunction; type AsyncPredicateFn = AsyncContextFunction; type PredicateFn = ContextFunction; declare type HookFunction = (context: H) => Promise | H | void; /** * Runs a series of hooks which mutate context.data or context.result (the Feathers default). * @see https://hooks-common.feathersjs.com/hooks.html#actondefault */ declare const actOnDefault: , any>>(...hooks: HookFunction[]) => (context: H) => Promise; /** * Runs a series of hooks which mutate context.dispatch. * @see https://hooks-common.feathersjs.com/hooks.html#actondispatch */ declare const actOnDispatch: , any>>(...hooks: HookFunction[]) => (context: H) => Promise; /** * Make changes to data or result items. Very flexible. * @see https://hooks-common.feathersjs.com/hooks.html#alteritems */ declare function alterItems(cb: (record: T, context: H) => any): (context: H) => H | Promise; type CacheMap = Map; interface CacheOptions { clone?(item: T): T; makeCacheKey?(id: Id): string; } /** * Persistent, most-recently-used record cache for services. * * @see https://hooks-common.feathersjs.com/hooks.html#cache */ declare function cache(cacheMap: CacheMap, keyField?: string, options?: CacheOptions): (context: H) => H; /** * Like checkContext, but only if the given type matches the hook's type. * Restrict a hook to run for certain methods and method types. (Utility function.) * * @see https://hooks-common.feathersjs.com/hooks.html#checkcontextif */ declare function checkContextIf(context: H, type: HookType | HookType[], methods?: MethodName | MethodName[] | null, label?: string): void; /** * Display the current hook context for debugging. * @see https://hooks-common.feathersjs.com/hooks.html#debug */ declare function debug(msg: string, ...fieldNames: string[]): (context: H) => void; /** * Remove records and properties created by the populate hook. * @see https://hooks-common.feathersjs.com/hooks.html#depopulate */ declare function dePopulate(func?: (item: any) => void): (context: H) => H; /** * Disables pagination when query.$limit is -1 or '-1'. * @see https://hooks-common.feathersjs.com/hooks.html#disablepagination */ declare function disablePagination(): (context: H) => H; /** * Prevents access to a service method completely or for specific transports. * @see https://hooks-common.feathersjs.com/hooks.html#disallow */ declare function disallow(...transports: TransportName[]): (context: H) => void; /** * Delete certain fields from the record(s). * @see https://hooks-common.feathersjs.com/hooks.html#discard */ declare function discard(...fieldNames: string[]): (context: H) => H; /** * Delete certain fields from the query object. * @see https://hooks-common.feathersjs.com/hooks.html#discardquery */ declare function discardQuery(...fieldNames: string[]): (context: H) => H; interface ResolverContext extends HookContext { _loaders: any; } type SimpleResolver = (...args: any[]) => (item: any, context: H) => Promise; interface RecursiveResolver { resolver: SimpleResolver; joins: ResolverMap; } interface ResolverMap { after?: (context: H) => void | Promise; before?: (context: H) => void | Promise; joins: { [property: string]: SimpleResolver | RecursiveResolver; }; } /** * We often want to combine rows from two or more tables based on a relationship between them. The fastJoin hook * will select records that have matching values in both tables. It can batch service calls and cache records, * thereby needing roughly an order of magnitude fewer database calls than the populate hook, i.e. 2 calls instead * of 20. It uses a GraphQL-like imperative API. * * fastJoin is not restricted to using data from Feathers services. Resources for which there are no Feathers * adapters can also be used. * * * fastJoin(postResolvers) * fastJoin(postResolvers, query) * fastJoin(context => postResolvers) * fastJoin(postResolvers, context => query) // supports queries from client * @see https://hooks-common.feathersjs.com/hooks.html#fastjoin */ declare function fastJoin(resolvers: ResolverMap | SyncContextFunction, H>, query?: Query | SyncContextFunction): (context: H) => H | Promise; type FGraphQLResolverMapFactory = (app: Application, runtime: any) => FGraphQLResolverMap; interface FGraphQLResolverMap { [i: string]: { [i: string]: GraphQLFieldResolver; }; Query: { [i: string]: GraphQLFieldResolver; }; } interface FGraphQLOptions { skipHookWhen?: SyncContextFunction; inclAllFieldsServer?: boolean; inclAllFieldsClient?: boolean; inclAllFields?: boolean; inclJoinedNames?: boolean; extraAuthProps?: string[]; } interface FGraphQLHookOptions { recordType: string; schema: string; resolvers: FGraphQLResolverMap | FGraphQLResolverMapFactory; query: Query | SyncContextFunction; options?: FGraphQLOptions; runTime: any; parse: typeof parse; } /** * Generate Graphql Resolvers for services * @see https://medium.com/@eddyystop/38faee75dd1 */ declare function fgraphql(options1: FGraphQLHookOptions): (context: H) => any; interface IffHook extends HookFunction { else(...hooks: HookFunction[]): HookFunction; } /** * Execute one or another series of hooks depending on a sync or async predicate. * @see https://hooks-common.feathersjs.com/hooks.html#iff */ declare function iff(predicate: boolean | PredicateFn, ...hooks: HookFunction[]): IffHook; /** * Execute one array of hooks or another based on a sync or async predicate. * @see https://hooks-common.feathersjs.com/hooks.html#iffelse */ declare function iffElse(predicate: boolean | PredicateFn, trueHook: HookFunction | HookFunction[] | undefined, falseHook?: HookFunction | HookFunction[] | undefined): (this: any, ctx: H) => HookContext<_feathersjs_feathers.Application, any> | Promise, any>>; /** * Keep certain fields in the record(s), deleting the rest. * @see https://hooks-common.feathersjs.com/hooks.html#keep */ declare function keep(...fieldNames: string[]): (context: H) => H; /** * Keep certain fields in a nested array inside the record(s), deleting the rest. * @see https://hooks-common.feathersjs.com/hooks.html#keepinarray */ declare function keepInArray(arrayName: string, fieldNames: string[]): (context: H) => H; /** * Keep certain fields in the query object, deleting the rest. * @see https://hooks-common.feathersjs.com/hooks.html#keepquery */ declare function keepQuery(...fieldNames: string[]): (context: H) => H; /** * Keep certain fields in a nested array inside the query object, deleting the rest. * @see https://hooks-common.feathersjs.com/hooks.html#keepqueryinarray */ declare function keepQueryInArray(arrayName: string, fieldNames: string[]): (context: H) => H; /** * Convert certain field values to lower case. * @see https://hooks-common.feathersjs.com/hooks.html#lowercase */ declare function lowerCase(...fieldNames: string[]): (context: H) => H; /** * Wrap MongoDB foreign keys in ObjectId. * * @see https://hooks-common.feathersjs.com/hooks.html#mongokeys */ declare function mongoKeys(ObjectId: new (id?: string | number) => any, keyFields: string | string[]): (context: H) => H; /** * Pass context.params from client to server. Server hook. * @see https://hooks-common.feathersjs.com/hooks.html#paramsfromclient */ declare function paramsFromClient(...whitelist: string[]): (context: H) => H; interface PopulateOptions { schema: Partial | ((context: H, options: PopulateOptions) => Partial); checkPermissions?: (context: H, path: string, permissions: any, depth: number) => boolean; profile?: boolean; } interface PopulateSchema { /** * The name of the service providing the items, actually its path. */ service: string; /** * Where to place the items from the join * dot notation */ nameAs: string; /** * The name of the field in the parent item for the relation. * dot notation */ parentField: string; /** * The name of the field in the child item for the relation. * Dot notation is allowed and will result in a query like { 'name.first': 'John' } which is not suitable for all DBs. * You may use query or select to create a query suitable for your DB. */ childField: string; /** * Who is allowed to perform this join. See checkPermissions above. */ permissions: any; /** * An object to inject into context.params.query. */ query: any; /** * A function whose result is injected into the query. */ select: (context: HookContext, parentItem: any, depth: number) => any; /** * Force a single joined item to be stored as an array. */ asArray: boolean; /** * Controls pagination for this service. */ paginate: boolean | number; /** * Perform any populate or fastJoin registered on this service. */ useInnerPopulate: boolean; /** * Call the service as the server, not with the client’s transport. */ provider: string; include: Partial | Partial[]; } declare function populate(options: PopulateOptions): (context: H) => H | Promise; /** * Prevent patch service calls from changing certain fields. * @see https://hooks-common.feathersjs.com/hooks.html#preventchanges */ declare function preventChanges(ifThrow: boolean, ...fieldNames: string[]): (context: H) => H; /** * Check selected fields exist and are not falsey. Numeric 0 is acceptable. * @see https://hooks-common.feathersjs.com/hooks.html#required */ declare function required(...fieldNames: string[]): (context: H) => void; /** * Let's you call a hook right after the service call. (Utility function.) * @see https://hooks-common.feathersjs.com/utilities.html#runhook */ declare function runHook(context?: H): (hook: any) => (data: any[] | Paginated) => Promise; /** * Run a hook in parallel to the other hooks and the service call. * * @see https://hooks-common.feathersjs.com/hooks.html#runparallel */ declare function runParallel(hook: HookFunction, clone?: (item: H) => H): (this: any, context: H) => void; interface SequelizeConversion { js: (sqlValue: any) => any; sql: (jsValue: any) => any; } interface SequelizeConverts { [name: string]: keyof C | 'boolean' | 'date' | 'json'; } /** * @see https://hooks-common.feathersjs.com/hooks.html#sequelizeconvert */ declare function sequelizeConvert(converts: SequelizeConverts | null | undefined | false, ignores?: string[] | null | undefined | false, conversions?: C): (context: H) => H; interface SerializeSchema { only?: string | string[]; exclude?: string | string[]; computed?: { [propName: string]: (record: any, context: H) => any; }; [key: string]: SerializeSchema | SerializeSchema['computed'] | string | string[] | undefined; } /** * Prune values from related records. Calculate new values. * @see https://hooks-common.feathersjs.com/hooks.html#serialize */ declare function serialize(schema1: SerializeSchema | SyncContextFunction): (context: H) => H; interface SetFieldOptions { as: string; from: string; allowUndefined?: boolean; } /** * The `setField` hook allows to set a field on the hook context based on the value of another field on the hook context. * @see https://hooks-common.feathersjs.com/hooks.html#setfield */ declare function setField({ as, from, allowUndefined, }: SetFieldOptions): (context: H) => H; /** * Create/update certain fields to the current date-time. * * @see https://hooks-common.feathersjs.com/hooks.html#setnow */ declare function setNow(...fieldNames: string[]): (context: H) => H; /** * Fix slugs in URL, e.g. /stores/:storeId. * * @see https://hooks-common.feathersjs.com/hooks.html#setslug */ declare function setSlug(slug: string, fieldName?: string): (context: H) => void; declare function sifter(siftFunc: SyncContextFunction<(item: any) => boolean, H>): (context: H) => H; type SoftDeleteOptionFunction = (context?: H) => Promise<{ [key: string]: any; }>; interface SoftDeleteOptions { deletedQuery?: { [key: string]: any; } | SoftDeleteOptionFunction; removeData?: { [key: string]: any; } | SoftDeleteOptionFunction; } /** * Allow to mark items as deleted instead of removing them. */ declare function softDelete({ deletedQuery, removeData, }?: SoftDeleteOptions): (context: H) => Promise; /** * Stash current value of record, usually before mutating it. Performs a get call. * @see https://hooks-common.feathersjs.com/hooks.html#stashbefore */ declare function stashBefore(fieldName?: string): (context: H) => any; /** * Transform fields & objects in place in the record(s) using a recursive walk. Powerful. * Check docs at https://github.com/substack/js-traverse for info on transformContext! * @see https://hooks-common.feathersjs.com/hooks.html#traverse */ declare function traverse(transformer: (transformContext: any) => any, getObject?: SyncContextFunction): (context: H) => H; /** * Execute a series of hooks if a sync or async predicate is falsey. * * @see https://hooks-common.feathersjs.com/hooks.html#unless */ declare function unless(predicate: boolean | PredicateFn, ...hooks: HookFunction[]): (this: any, ctx: H) => HookContext<_feathersjs_feathers.Application, any> | Promise, any>>; type SyncValidatorFn = (values: any, context: H) => { [key: string]: string; } | null; type AsyncValidatorFn = (values: any, context: H) => Promise; type ValidatorFn = SyncValidatorFn | AsyncValidatorFn; type AjvOrNewable = Ajv | (new (options?: Options) => Ajv); interface ValidateSchemaOptions extends Options { /** * The hook will throw if the data does not match the JSON-Schema. error.errors will, by default, contain an array * of error messages. You may change this with a custom formatting function. Its a reducing function which works * similarly to Array.reduce(). */ addNewError: (currentFormattedMessages: any, ajvErrorObject: ErrorObject, itemsLen: number, itemIndex: number) => any; } /** * Validate data using a validation function. * @see https://hooks-common.feathersjs.com/hooks.html#validate */ declare function validate(validator: ValidatorFn): (context: H) => H | Promise; /** * Validate data using JSON-Schema. * @see https://hooks-common.feathersjs.com/hooks.html#validateschema */ declare function validateSchema(schema: object | string, ajvOrAjv: AjvOrNewable, options?: ValidateSchemaOptions): (context: H) => Promise | H; type Disablable = 'populate' | 'fastJoin' | 'ignoreDeletedAt' | 'softDelete' | 'softDelete2' | 'stashBefore'; interface CallingParamsOptions { /** * The params.query for the calling params. */ query?: any; /** * The names of the props in context.params to include in the new params. */ propNames?: string[]; /** * Additional props to add to the new params. */ newProps?: any; /** * The names of hooks to disable during the service call. populate, fastJoin, softDelete and stashBefore are supported. */ hooksToDisable?: Disablable[] | Disablable; /** * Ignore the defaults propNames and newProps. */ ignoreDefaults?: boolean; } /** * Set defaults for building params for service calls with callingParams. (Utility function.) * @see https://hooks-common.feathersjs.com/utilities.html#callingparamsdefaults */ declare function callingParamsDefaults(propNames: string[], newProps?: any): void; /** * Build params for a service call. (Utility function.) * @see https://hooks-common.feathersjs.com/utilities.html#callingparams */ declare function callingParams({ query, propNames, newProps, hooksToDisable, ignoreDefaults, }?: CallingParamsOptions): (context: H) => Params<_feathersjs_feathers.Query>; /** * You should prefer using the callingParams utility to makeCallingParams. * Build context.params for service calls. (Utility function.) * @see https://hooks-common.feathersjs.com/utilities.html#makecallingparams */ declare function makeCallingParams(context: H, query?: any, include?: string | string[], inject?: {}): Params<_feathersjs_feathers.Query>; /** * Restrict a hook to run for certain methods and method types. (Utility function.) * @see https://hooks-common.feathersjs.com/utilities.html#checkcontext */ declare function checkContext(context: H, type?: HookType | HookType[] | null, methods?: MethodName | MethodName[] | null, label?: string): void; /** * Sequentially execute multiple sync or async hooks. * @see https://hooks-common.feathersjs.com/utilities.html#combine */ declare function combine(...serviceHooks: HookFunction[]): (context: H) => Promise; /** * Return the and of a series of sync or async predicate functions. * @see https://hooks-common.feathersjs.com/utilities.html#every */ declare function every(...predicates: PredicateFn[]): AsyncPredicateFn; /** * Get the records in context.data or context.result[.data]. (Utility function.) * * @see https://hooks-common.feathersjs.com/utilities.html#getitems */ declare function getItems(context: H): any; /** * Negate a sync or async predicate function. * * @see https://hooks-common.feathersjs.com/utilities.html#isnot */ declare function isNot(predicate: boolean | PredicateFn): PredicateFn; /** * Check which transport provided the service call. * @see https://hooks-common.feathersjs.com/utilities.html#isprovider */ declare function isProvider(...providers: TransportName[]): (context: H) => boolean; /** * Pass an explicit context.params from client to server. Client-side. (Utility function.) * * @see https://hooks-common.feathersjs.com/utilities.html#paramsforserver */ declare function paramsForServer(params?: Params, ...whitelist: string[]): Params; /** * Replace the records in context.data or context.result[.data]. (Utility function.) * @see https://hooks-common.feathersjs.com/utilities.html#replaceitems */ declare function replaceItems(context: H, items: any): void; /** * Return the or of a series of sync or async predicate functions. * @see https://hooks-common.feathersjs.com/utilities.html#some */ declare function some(...predicates: PredicateFn[]): AsyncPredicateFn; export { type AjvOrNewable, type AsyncContextFunction, type AsyncPredicateFn, type AsyncValidatorFn, type CacheMap, type CacheOptions, type CallingParamsOptions, type ContextFunction, type Disablable, type FGraphQLHookOptions, type FGraphQLOptions, type FGraphQLResolverMap, type FGraphQLResolverMapFactory, type HookFunction, type HookType, type IffHook, type MethodName, type PopulateOptions, type PopulateSchema, type PredicateFn, type RecursiveResolver, type ResolverContext, type ResolverMap, type SequelizeConversion, type SequelizeConverts, type SerializeSchema, type SetFieldOptions, type SimpleResolver, type SoftDeleteOptionFunction, type SoftDeleteOptions, type SyncContextFunction, type SyncPredicateFn, type SyncValidatorFn, type TransportName, type ValidateSchemaOptions, type ValidatorFn, actOnDefault, actOnDispatch, alterItems, cache, callingParams, callingParamsDefaults, checkContext, checkContextIf, combine, dePopulate, debug, disablePagination, disallow, discard, discardQuery, every, fastJoin, fgraphql, getItems, hookTypes, iff, iffElse, isNot, isProvider, keep, keepInArray, keepQuery, keepQueryInArray, lowerCase, makeCallingParams, methodNames, mongoKeys, paramsForServer, paramsFromClient, populate, preventChanges, replaceItems, required, runHook, runParallel, sequelizeConvert, serialize, setField, setNow, setSlug, sifter, softDelete, some, stashBefore, traverse, unless, validate, validateSchema, iff as when };