import Evented from "@arcgis/core/core/Evented"; import type PortalItem from "@arcgis/core/portal/PortalItem"; import type { FailureMode } from "@vertigis/arcgis-extensions/FailureMode"; import { type IDeprecatedObservable } from "@vertigis/arcgis-extensions/support/Observable"; import type { SerializeMode } from "@vertigis/arcgis-extensions/support/Serializable"; import type { EventCallback } from "@vertigis/arcgis-extensions/support/esri"; import { ObservableMap } from "@vertigis/arcgis-extensions/utilities/ObservableMap"; import { ReadOnlyMap } from "@vertigis/arcgis-extensions/utilities/ReadOnlyMap"; import type { WatchCallback } from "@vertigis/arcgis-extensions/utilities/watch"; import type { AppConfig, Entity, ItemConfig } from "./AppConfig"; import { AppConfigError } from "./AppConfigError"; import type { ItemKey } from "./ItemKey"; import type { ConfigResolver } from "./config/ConfigResolver"; import type { ConfigUpgrader } from "./config/ConfigUpgrader"; /** * An item obtained from an {@link AppContainer}. */ export type Item = object; /** * A URI in the form "item://type/id". */ export type ItemUri = string; /** * An item type registered with the AppContainer, e.g. "map-extension". */ export type ItemType = string; /** * A factory method that is used to create items of a given type from item * configuration. */ export type ItemFactory = (itemConfig?: Omit, context?: AppContainerContext) => TItem | Promise; /** * Raised when there is an error resolving item config or creating an item. */ export interface AppConfigWarningEvent { /** * The error that was thrown or, if a non-Error failure mode is configured, * the error that would have been thrown. */ error: AppConfigError; /** * The {@link AppContainer} that raised the event. */ target: AppContainer; } /** * Options that can be passed to {@link AppContainer.export}. */ export interface ExportOptions { /** * If specified, only the given items and their dependencies will be * exported. */ items?: Iterable; /** * See {@link SerializeMode}. */ serializeMode?: SerializeMode; /** * Whether to upgrade all app config items prior to exporting. Defaults to * true. */ upgrade?: boolean; } /** * Raised when items are added or removed from an {@link AppContainer}. */ export interface AppContainerChangeEvent { /** * The items that were added. */ added: ItemKey[]; /** * The items that were removed. */ removed: ItemKey[]; /** * The {@link AppContainer} that raised the event. */ target: AppContainer; } /** * A callback that is invoked when {@link AppConfigWarningEvent} is raised. */ export type AppContainerChangeEventCallback = (event: AppContainerChangeEvent) => void; /** * A callback that is invoked when {@link AppConfigWarningEvent} is raised. */ export type AppConfigWarningEventCallback = (event: AppConfigError) => void; declare const AppContainer_base: typeof Evented & (abstract new (...args: any[]) => import("@vertigis/arcgis-extensions/support/observableUtils").ObservableMixin); /** * A container used for retrieving items defined in a VertiGIS Studio App (see * {@link AppConfig}). */ export declare class AppContainer extends AppContainer_base implements IDeprecatedObservable { /** * User-defined settings. Setting values can be referenced in item * properties via setting:// URIs. */ readonly settings: SettingsCollection; /** * User-defined failure modes for particular items. Items are referenced by * item uri. */ readonly failureModes: Map; /** * Used to resolve externally-referenced configuration. */ configResolver: ConfigResolver; /** * An optional base URL to use when resolving relative URLS. If unspecified, * it will default to the URL of the host application. */ baseUrl: string; /** * If the App is loaded from Portal, this will be the `PortalItem` that is * used for fetching the app config. */ portalItem: PortalItem | undefined; /** * A read only lookup for item factories keyed by type. */ readonly factories: ReadOnlyMap; /** * A read only lookup for item upgraders keyed by type. */ readonly upgraders: ReadOnlyMap; /** * A human-readable name for the App. */ title: string; /** * The root App config used to initialize the container. */ private _appConfig; private _initializePromise; private _destroyPromise; private _isInitialized; private _isDestroyed; private readonly _upgradedItems; /** * A lookup for item factories, keyed by type. */ private readonly _factories; /** * A lookup for item upgraders, keyed by type. */ private readonly _upgraders; /** * A lookup for item configuration, keyed by item URI. Each entry is an * array of item configs (the same item might be defined multiple times due * to imports). They are stored in the order that they need to be merged * (properties in later configs override earlier ones). */ private readonly _itemConfigs; /** * A lookup for resolved item configuration, keyed by item URI. This mapping * is used to store original app item configs that have been resolved and * upgraded during an import operation before the item had been created. */ private readonly _preprocessedItemConfigs; /** * A lookup for items that were added dynamically via set(), keyed by item * URI. */ private readonly _dynamicItems; /** * A lookup for items created from App configuration. Note that we need to * cache the _promise_ of the item, in case there are multiple requests for * the same item while it's being created and initialized. */ private readonly _items; /** * Maps {@link ItemType}s to a set of properties that may contain a URL or * portal URI. */ private _urlPropertyMappings; /** * Initializes a new instance of the {@link AppContainer} class. * * @param appConfig The {@link AppConfig} to load in the container, or a URL * to app config. */ constructor(appConfig?: AppConfig | string); /** * Gets the number of items in the container. */ get size(): number; /** * Indicates if the App container has been initialized. */ get isInitialized(): boolean; /** * Indicates whether this container has been destroyed. */ get isDestroyed(): boolean; /** * Iterates over the entries in the container. */ [Symbol.iterator](): Iterable<[ItemKey, Promise]>; /** * Returns the keys of items in the container that have been created. * * @param type Optional. If present, the results will be filtered to only * include items of the given type. */ createdKeys(type?: string): Iterable; /** * Exports App configuration. * * @param options Options that affect how the items are exported. */ export(options?: ExportOptions): Promise; /** * Flattens app configuration. All descendent models should be available in * the container once flattened. */ flattenConfig(): Promise; /** * Imports App configuration. Imported configuration will override any * existing configuration. If one or more imported items have already been * created, then the config will be applied to those objects. * * @param appConfig The configuration to import. */ import(appConfig: AppConfig | string): Promise; /** * Initializes the App container if it isn't already initialized. * * @returns A promise that is fulfilled when the container is initialized. */ initialize(): Promise; /** * Destroys the container and invokes a "destroy" hook if it exists on any * item that was created by the app container. */ destroy(): Promise; /** * Gets an item from the container. * * @param key The item's unique key. * @returns The requested item. * @throws {NotFoundError} No such item is defined in the container. * @throws {AccessDeniedError} The current user does not have permission to * access the given item. */ get(key: ItemKey): Promise; /** * Gets an item from the container. * * @param type The item's type. * @param id The item's ID. * @returns The requested item. * @throws {NotFoundError} No such item is defined in the container. * @throws {AccessDeniedError} The current user does not have permission to * access the given item. */ get(type: string, id: string): Promise; /** * Gets an item from the container. * * @param itemUri A URI that uniquely identifies the item, in the form * "item://type/id". * @returns The requested item. * @throws {NotFoundError} No such item is defined in the container. * @throws {AccessDeniedError} The current user does not have permission to * access the given item. */ get(itemUri: string): Promise; /** * Determines whether the container has a specific item. * * @param key The item's unique key. */ has(key: ItemKey): boolean; /** * Determines whether the container has a specific item, or a type of item. * * @param type The type of item. * @param id The ID of the specific item to look for. If omitted, this * function will instead determine whether there is any item of the given * type. */ has(type: string, id?: string): boolean; /** * Determines whether the container has a specific item. * * @param itemUri A URI that uniquely identifies the item, in the form * "item://type/id". */ has(itemUri: string): boolean; /** * Returns the keys of items in the container. * * @param type Optional. If present, the results will be filtered to only * include items of the given type. */ keys(type?: string): Iterable; /** * Returns all items in the container. */ values(): Iterable>; /** * Returns all items in the container of a given type. * * @param type The type of item. */ values(type: string): Iterable>; /** * Returns all key/item pairs in the container. */ entries(): Iterable<[ItemKey, Promise]>; /** * Returns all key/item pairs in the container of a given type. * * @param type The type of item. */ entries(type: string): Iterable<[ItemKey, Promise]>; /** * Executes a callback function once per each key/item pair in the * container. * * @param callback The callback function to invoke. * @param thisArg Value to use as "this" when executing the callback. */ forEach(callback: (entity: Promise, key?: ItemKey, container?: AppContainer) => void, thisArg?: unknown): void; /** * Converts item:// references in an object's property values to items. * * @param unresolvedObject The object or array that potentially contains * references. * @param itemUri The item URI associated with the object. * @param visited A set containing item:// URIs for items that were * previously visited while resolving references (used for detecting * circular references). */ resolveReferences(unresolvedObject: unknown, itemUri?: ItemUri, visited?: Set): Promise; /** * Not supported. This overload is a workaround for name conflicts between * Accessor and the ES2015 Map interface and should not be used. * * @deprecated */ set(properties: HashMap): this; /** * Adds an item to the container (or replaces an existing item). * * @param key The item's key. * @param item The object that will be returned when this item is requested. */ set(key: ItemKey, item: Item): this; /** * Adds an item to the container (or replaces an existing item). * * @param itemUri A URI that uniquely identifies the item, in the form * "item://type/id". * @param item The object that will be returned when this item is requested. */ set(itemUri: string, item: Item): this; /** * Adds an item to the container (or replaces an existing item). * * @param type The item's type. * @param entity The object that will be returned when this item is * requested. */ set(type: string, entity: Entity): this; /** * Removes an item from the container. * * @param key The item's unique key. */ delete(key: ItemKey): boolean; /** * Removes an item from the container. * * @param type The item's type. * @param id The item's ID. */ delete(type: string, id: string): boolean; /** * Removes an item from the container. * * @param itemUri A URI that uniquely identifies the item, in the form * "item://type/id". */ delete(itemUri: string): boolean; /** * Removes all items from the container. */ clear(): void; /** * Determines whether the container knows how to create items of the given * type. * * @param type The type name to check. */ isRegisteredType(type: string): boolean; /** * Registers a custom type with the App container, so that it may create * items of that type. If the given type is already registered, then its * factory will be replaced by the new one. By default, all types defined in * the VertiGIS Arc-X are already registered, though applications are free * to override or unregister them. * * @param type The type to register. * @param factory A factory function that will be invoked to create new item * instances. The function can either return items directly, or return a * promise that is fulfilled with the new item. The latter allows the * factory to perform asynchronous tasks, such as loading a module. * @param options Additional options that affect the behavior of the * factory. */ registerType(type: string, factory: ItemFactory, options?: RegistrationOptions): void; /** * Unregisters a type. The container will no longer be able to create items * of the given type until {@link registerType} is called again. * * @param type The type to unregister. */ unregisterType(type: string): void; /** * Gets the registered factory that is used to create instances of the given * type. * * @param type The registered type. * @returns The factory for the given type, or undefined if the type is not * registered. */ getFactory(type: string): ItemFactory | undefined; /** * Gets the registered upgrader that is used to upgrade item config for a * given type. * * @param type The registered type. * @returns The upgrader for the given type, or undefined if the type is not * registered. */ getUpgrader(type: string): ConfigUpgrader | undefined; /** * @inheritdoc */ on(name: string, callback: EventCallback): IHandle; /** * @inheritdoc */ emit(name: "configWarning", event: AppConfigWarningEvent): boolean; /** * @inheritdoc */ emit(name: "change", event: AppContainerChangeEvent): boolean; /** * @deprecated * @inheritdoc */ watch(path: string | string[], callback: WatchCallback, sync?: boolean): IHandle; /** * @deprecated * @inheritdoc */ notifyChange(propertyKey: keyof this): void; /** * @deprecated * @inheritdoc */ _watchProperty(propertyKey: keyof this, subpath: string, callback: WatchCallback, sync: boolean): IHandle; /** * Creates an item from configuration. * * @param key The item's key. * @param itemConfig The item configuration. */ protected _createItem(key: ItemKey, itemConfig: ItemConfig): Promise; /** * Gets an item's configuration. The returned configuration will be fully * pre-processed (i.e. import links will be followed, item references will * be resolved, and settings substitution will be performed). * * @param key The key specifying which item to retrieve. * @param visited Used by resolveReferences() to detect circular references. */ protected _getItemConfig(key: ItemKey, visited?: Set): Promise; /** * Gets the configuration for an item that will be exported. * * @param uri The uri specifying which item config to retrieve. */ protected _getExportedItemConfig(uri: ItemUri): ItemConfig; /** * Serializes an item to JSON. * * @param key The item key. * @param item The item to serialize. * @param serializeMode The serialization mode to use (for objects that * implement Serializable). */ protected _serializeItem(key: ItemKey, item: Item, serializeMode: SerializeMode): ItemConfig | undefined; private _preprocessItemConfigs; private _mergeItemConfigs; /** * Extracts an item key from arguments supplied to a method. * * @param args The value of "arguments" within a method. */ private _getItemKeyFromArguments; /** * Gets an item from the container. * * @param key The item to get. * @param visited Used by resolveReferences() to detect circular references. */ private _get; /** * Serializes an entity to JSON and adds it to a collection of results. * * @param uri The item URI. * @param results The collection of results, keyed by item URI. * @param serializeMode The serialization mode to use (for Serializable * objects). * @param item The item to serialize (used for items that part of the * serialized graph but not in the container). * @param itemResults Specify if the results should contain config or items, * defaults to config. */ private _serializeAndAddToResults; /** * Processes an App config, extracting all items and settings. * * @param appConfig The App config to process. * @param context The context containing information about the importing * app. */ private _processAppConfig; /** * Process the items in an App config and add them to _itemConfigs. * * @param itemConfigs The item configs to process. * @param context The context containing information necessary for resolving * URLs. */ private _processItemConfigs; private _processSettings; private _processFailureModes; /** * Looks for item:// URI references in a serialized object graph, and * includes the referenced item in the serialization results. * * @param json The serialized JSON for the original object. * @param results The collection of item results, keyed by item URI. * @param serializeMode The serialize mode to use. * @param original The original object. * @param itemResults Specify if the results should contain config or items, * defaults to config. */ private _serializeItemReferences; /** * Checks to see if the item is an item URI, or an array of item URIs. * * @param item The item. */ private _isItemUri; private _itemConfigToUri; private _ensureInitialized; private _ensureNotDestroyed; } /** * The name of a setting within an App. */ export type SettingName = string; /** * The value of a setting in an App. Will be a primitive value (string, number, * or boolean). */ export type Setting = string | number | boolean; /** * Backing store for {@link AppContainer.settings}. */ export declare class SettingsCollection extends ObservableMap { forEach(callback: (value: Setting, key: SettingName, map: Map) => void, thisArg?: unknown): void; /** * @inheritdoc */ set(properties: HashMap): this; /** * @inheritdoc */ set(key: SettingName, value?: Setting): this; /** * Converts any setting:// URIs in the input to setting values. * * @param obj The object to search for setting URIs. */ resolveSettings(obj: unknown): unknown; /** * Returns a serialized representation of the settings collection. */ toJSON(): Record; /** * Converts any setting:// URIs in the input to setting values. * * @param obj The object to search for setting URIs. * @param visited Used to keep track of visited settings while resolving a * setting's value in order to detect cycles. */ private _resolveSettings; /** * Gets the fully resolved value of a setting, i.e. the setting's value with * any contained setting:// URIs converted to their actual values * (recursively). * * @param key The setting key. * @param visited Used to keep track of visited settings while resolving a * setting's value in order to detect cycles. */ private _getResolvedValue; } /** * Context for an {@link AppContainer}, containing information for resolving * relative URLs and fetching portal items. */ export interface AppContainerContext { /** * The base URL used for resolving relative URLs. */ baseUrl?: string; /** * The portal used for resolving relative portal item references. */ portal?: string; } /** * Options that can be passed to {@link AppContainer.registerType}. */ export interface RegistrationOptions { /** * Properties that represent a URL. Relative URL values for these properties * will be interpreted as relative to the App config URL if there is one. */ urlProperties?: (string | RegExp)[]; /** * A callback for performing upgrade logic. */ upgrade?: ConfigUpgrader; } export {};