import type { AjaxAdapter, BreezeFetch, DataServiceAdapter, ModelLibraryAdapter, UriBuilderAdapter } from './interface-registry.js'; import { BreezeEvent } from '../core/event.js'; /** @hidden */ export interface AdapterCtor { new (...args: any[]): T; } /** @hidden */ export interface IDef { ctor: AdapterCtor; defaultInstance?: T; } /** The names of the adapter interfaces, as passed to the 2.x-style methods on {@link BreezeConfig} such as `registerAdapter` and `initializeAdapterInstance`. With {@link configureBreeze} you pass the adapter classes instead and never need these names. */ export type AdapterType = 'dataService' | 'modelLibrary' | 'ajax' | 'uriBuilder'; export declare class InterfaceDef { name: string; defaultInstance?: T; constructor(name: string); /** Define an implementation of the given adaptername */ registerCtor(adapterName: string, ctor: AdapterCtor): void; /** Return the definition for the given adapterName */ getImpl(adapterName: string): IDef; /** Return the first implementation for this InterfaceDef */ getFirstImpl(): IDef; getDefaultInstance(): T; } /** Registers adapters used by Breeze */ export declare class InterfaceRegistry { /** Creates a registry with no adapters in it. {@link config} holds the one Breeze uses; applications do not create their own. */ constructor(); /** The registered {@link AjaxAdapter}s, and the default one if any. Deprecated: Breeze 3 sends requests through `config.fetch` and needs no ajax adapter. */ ajax: InterfaceDef; /** The registered {@link ModelLibraryAdapter}s, and the default one. */ modelLibrary: InterfaceDef; /** The registered {@link DataServiceAdapter}s, and the default one. */ dataService: InterfaceDef; /** The registered {@link UriBuilderAdapter}s, and the default one. */ uriBuilder: InterfaceDef; } /** What every Breeze adapter implements: the model library, data service, URI builder and (deprecated) ajax adapters all extend this interface. */ export interface BaseAdapter { /** The name the adapter is registered under, such as `'webApi'` or `'backingStore'`. Names are matched without regard to case. `registerAdapter` reads it from a throwaway instance and throws if it is empty. */ name: string; /** Called by Breeze each time the adapter is initialized: when it is first created, and again whenever it is initialized by name or registered again, for example by {@link configureBreeze}. Resolve anything the adapter depends on here, not in the constructor. */ initialize(): void; /** Optional. Called each time any adapter is initialized after this one first was, with `{ interfaceName, instance, isDefault }`, so that this adapter can pick up a new dependency. The data service adapters use it to re-resolve their ajax adapter when a new default ajax adapter is initialized. */ checkForRecomposition?: (context: any) => void; } /** An adapter Breeze falls back to for an interface when nothing has been registered for it. @hidden */ export interface DefaultAdapter { ctor: AdapterCtor; /** Use only when asked for by name, never as the unnamed default. */ namedOnly?: boolean; } /** Breeze's global configuration: the adapter registry, the `fetch` transport, and registries Breeze uses to find functions and objects by name when it deserializes metadata. The single instance is {@link config}. To configure Breeze, use {@link configureBreeze}. The adapter methods here (`registerAdapter`, `initializeAdapterInstance`, `getAdapterInstance` and the rest) are the 2.x API. They still work, and adapters' own static `register()` methods use them, but an application does not normally need to call them. */ export declare class BreezeConfig { /** Functions registered by name with {@link BreezeConfig.registerFunction}. Breeze looks up validator factories here, under `"Validator." + name`, when it imports metadata. Applications do not normally need it; use {@link Validator.register} and {@link Validator.registerFactory}. */ functionRegistry: Record; /** Constructors registered by name with {@link BreezeConfig.registerType}. Nothing in Breeze 3 reads it; applications do not normally need it. */ typeRegistry: Record; /** Named instances Breeze can find again by name, keyed `"."`: every {@link JsonResultsAdapter}, {@link NamingConvention} and {@link LocalQueryComparisonOptions} registers itself here when created. Breeze uses it to resolve the names in exported metadata and exported entities. Applications do not normally need it. */ objectRegistry: Record; /** Published each time an adapter is initialized, with the interface name, the adapter instance and whether it became the default for its interface. Breeze uses it to let adapters that depend on each other recompose (see {@link BaseAdapter.checkForRecomposition}); applications do not normally need it. */ interfaceInitialized: BreezeEvent<{ /** The interface the adapter implements: `"ajax"`, `"dataService"`, `"modelLibrary"` or `"uriBuilder"`. */ interfaceName: string; /** The adapter that was initialized. */ instance: BaseAdapter; /** Whether it became the default adapter for its interface. */ isDefault: boolean; }>; /** The indentation Breeze passes to `JSON.stringify` when it serializes exported entities (`EntityManager.exportEntities`) and exported metadata (`MetadataStore.exportMetadata`). The default, `''`, produces compact JSON; set it to, say, `' '` for readable output. */ stringifyPad: string; /** * The function Breeze makes HTTP requests with, unless a (deprecated) ajax adapter is * registered. Set it with `configureBreeze({ fetch })`. When unset, `globalThis.fetch`. */ fetch?: BreezeFetch; /** Creates a configuration with nothing registered. Breeze creates the one instance there is, {@link config}; applications do not create their own. */ constructor(); /** Method use to register implementations of standard breeze interfaces. Calls to this method are usually made as the last step within an adapter implementation. @param interfaceName {String} - one of the following interface names: "ajax", "dataService", "modelLibrary", "uriBuilder" @param adapterCtor {Function} - an ctor function that returns an instance of the specified interface. @deprecated For configuring an application, use `configureBreeze({ ajax: MyAdapter, ... })` instead: the adapter classes are passed directly, so a misspelled name is a compile error rather than a runtime one. An adapter's own static `register()` still calls this - that is how an adapter registers itself, and is not deprecated. Not scheduled for removal. */ registerAdapter(interfaceName: AdapterType, adapterCtor: AdapterCtor): void; /** Returns the ctor function used to implement a specific interface with a specific adapter name. @param interfaceName {String} One of the following interface names: "ajax", "dataService", "modelLibrary", "uriBuilder" @param [adapterName] {String} The name of any previously registered adapter. If this parameter is omitted then this method returns the "default" adapter for this interface. If there is no default adapter, then a null is returned. @returns {Function|null} Returns either a ctor function or null. */ getAdapter(interfaceName: AdapterType, adapterName: string): any; /** Initializes a single adapter implementation. Initialization means either newing a instance of the specified interface and then calling "initialize" on it or simply calling "initialize" on the instance if it already exists. @param interfaceName {String} The name of the interface to which the adapter to initialize belongs. @param adapterName {String} - The name of a previously registered adapter to initialize. @param [isDefault=true] {Boolean} - Whether to make this the default "adapter" for this interface. @returns {an instance of the specified adapter} @deprecated For configuring an application, use `configureBreeze({ ajax: MyAdapter, ... })` instead: the adapter classes are passed directly, so a misspelled name is a compile error rather than a runtime one. An adapter's own static `register()` still calls this - that is how an adapter registers itself, and is not deprecated. Not scheduled for removal. */ initializeAdapterInstance(interfaceName: AdapterType, adapterName: string, isDefault?: boolean): BaseAdapter; /** Returns the adapter instance corresponding to the specified interface and adapter names. @param interfaceName {String} The name of the interface. @param [adapterName] {String} - The name of a previously registered adapter. If this parameter is omitted then the default implementation of the specified interface is returned. If there is no defaultInstance of this interface, then the first registered instance of this interface is returned. @returns {an instance of the specified adapter} */ getAdapterInstance(interfaceName: AdapterType, adapterName?: string): T | undefined; /** this is needed for reflection purposes when deserializing an object that needs a fn or ctor. Used to register validators. */ registerFunction(fn: Function, fnName: string): void; /** Registers a constructor under a type name: stamps the name on its prototype as `_$typeName` and adds it to {@link BreezeConfig.typeRegistry}. Breeze registers `KeyGenerator` this way; applications do not normally need it. @param ctor - The constructor to register. @param typeName - The name to register it under. */ registerType(ctor: Function, typeName: string): void; /** Returns the function registered under the given name with {@link BreezeConfig.registerFunction}, or `undefined` if there is none. Validators are registered as `"Validator." + name`, so `config.getRegisteredFunction('Validator.maxLength')` returns the `maxLength` factory. @param fnName - The name the function was registered under. */ getRegisteredFunction(fnName: string): Function; /** Returns the registry entry for one adapter interface, which holds its registered adapters and its default instance. The name is matched without regard to case. Used by the adapter registration methods; applications do not normally need it. @param interfaceName - `'ajax'`, `'dataService'`, `'modelLibrary'` or `'uriBuilder'`. @throws if there is no interface with that name. */ getInterfaceDef(interfaceName: string): InterfaceDef; } /** The global {@link BreezeConfig}, used by every `EntityManager`, `MetadataStore` and `DataService`. To configure Breeze, use {@link configureBreeze}, which sets this object's adapters and `fetch`. The 2.x calls on it, such as `config.registerAdapter(...)` and `config.initializeAdapterInstance(...)`, still work and are not scheduled for removal. */ export declare const config: BreezeConfig;