import type { HookContext } from '@feathersjs/feathers' export const hasOwnProperty = ( obj: Record, ...keys: string[] ): boolean => { return keys.some((x) => Object.prototype.hasOwnProperty.call(obj, x)) } export type MaybeArray = T | readonly T[] export type UnpackMaybeArray = T extends readonly (infer E)[] ? E : T /** * Normalizes a value or array into an array. The returned array MUST be treated * as read-only — when the input is already an array it is returned as-is (no copy) * to avoid a per-call allocation on hook hot paths. */ export const toArray = (value: T | readonly T[]): T[] => Array.isArray(value) ? (value as T[]) : [value as T] export type Promisable = T | Promise export type KeyOf = Extract export type UnwrapArray = T extends Array ? U : T export type IsAny = 0 extends 1 & T ? true : false export type AnyFallback = IsAny extends true ? Fallback : T export type NeverFallback = [Never] extends [never] ? Fallback : Never export type KeyOfOrDotNotation = KeyOf | `${KeyOf}.${string}` /**+ * Can be used to early return a hook. * * If it's an around hook, it will call `next` if provided. */ export const early = ( context: H, next?: (context: H) => Promisable, ): Promisable => { if (next) { return next(context) } return }