import Entity, { type EntityInstanceType } from './Entity.js'; import type { EntityConstructor, EntityInterface, EntityJson, ServerCallResponse, ServerCallStaticResponse } from './Entity.types.js'; import EntityWeakCache from './EntityWeakCache.js'; import type { AbortableAsyncIterator } from './HttpRequester.js'; import type { EventType, NymphOptions, Options, RequestCallback, ResponseCallback, Selector } from './Nymph.types.js'; import type PubSub from './PubSub.js'; export default class Nymph { /** * And optional PubSub client instance. */ pubsub: PubSub | undefined; /** * A simple map of names to Entity classes. */ private entityClasses; /** * The entity class for this instance of Nymph. */ Entity: typeof Entity; private requestCallbacks; private responseCallbacks; private restUrl; private weakCache; /** * Headers that will be sent with every request. * * These are used by Tilmeld for authentication. */ headers: { [k: string]: string; }; /** * The entity cache. */ cache: EntityWeakCache; /** * Return `null` or empty array instead of error when entity/ies not found. */ returnNullOnNotFound: boolean; constructor(NymphOptions: NymphOptions); /** * Add your class to this instance. * * This will create a class that extends your class within this instance of * Nymph and return it. You can then use this class's constructor and methods, * which will use this instance of Nymph. * * Because this creates a subclass, don't use the class returned from * `getEntityClass` to check with `instanceof`. Instead, use the base class * that you passed into this method. */ addEntityClass(entityClass: T): T; getEntityClass(className: T): T; getEntityClass(className: string): EntityConstructor; newUID(name: string): Promise; setUID(name: string, value: number): Promise; getUID(name: string): Promise; deleteUID(name: string): Promise; saveEntity(entity: EntityInterface): Promise; saveEntities(entities: EntityInterface[]): Promise; patchEntity(entity: EntityInterface): Promise; patchEntities(entities: EntityInterface[]): Promise; private requestWithMethod; getEntity(options: Options & { return: 'count'; }, ...selectors: Selector[]): Promise; getEntity(options: Options & { return: 'guid'; }, ...selectors: Selector[]): Promise; getEntity(options: Options, ...selectors: Selector[]): Promise | null>; getEntity(options: Options & { return: 'count'; }, guid: string): Promise; getEntity(options: Options & { return: 'guid'; }, guid: string): Promise; getEntity(options: Options, guid: string): Promise | null>; getEntityData(options: Options & { return: 'count'; }, ...selectors: Selector[]): Promise; getEntityData(options: Options & { return: 'guid'; }, ...selectors: Selector[]): Promise; getEntityData(options: Options, ...selectors: Selector[]): Promise | null>; getEntityData(options: Options & { return: 'count'; }, guid: string): Promise; getEntityData(options: Options & { return: 'guid'; }, guid: string): Promise; getEntityData(options: Options, guid: string): Promise | null>; getEntities(options: Options & { return: 'count'; }, ...selectors: Selector[]): Promise; getEntities(options: Options & { return: 'guid'; }, ...selectors: Selector[]): Promise; getEntities(options: Options, ...selectors: Selector[]): Promise[]>; initEntity(entityJSON: EntityJson): EntityInstanceType; getEntityFromCache(EntityClass: EntityConstructor, guid: string): EntityInstanceType | null; setEntityToCache(EntityClass: EntityConstructor, entity: EntityInterface): void; initEntitiesFromData(item: T): T; deleteEntity(entity: EntityInterface | EntityInterface[], _plural?: boolean): Promise; deleteEntities(entities: EntityInterface[]): Promise; serverCall(entity: EntityInterface, method: string, params: any[], stateless?: boolean): Promise; serverCallStatic(className: string, method: string, params: any[]): Promise; serverCallStaticIterator(className: string, method: string, params: any[]): Promise>; on(event: T, callback: T extends 'request' ? RequestCallback : T extends 'response' ? ResponseCallback : never): () => boolean; off(event: T, callback: T extends 'request' ? RequestCallback : T extends 'response' ? ResponseCallback : never): boolean; } export declare class ClassNotAvailableError extends Error { constructor(message: string); } export declare class InvalidRequestError extends Error { constructor(message: string); }