import { ComplexQueryExpression } from './ComplexQueryLang.js'; import { EventSource } from 'apprt-core/Events'; import '@arcgis/core/geometry/Geometry'; /** * An object that allows index based access. */ type IndexableThing = Readonly>; /** * Response of a synchronous query. */ interface ResultItems extends ReadonlyArray { /** Total number of available items in the result. */ readonly total?: number; /** * Set to true by the store to indicate that there are more results. * The client may query again with an appropriate `start` value. */ readonly hasMore?: boolean; /** Function to react on the provided result. It is always 'undefined' in synchronous responses. */ readonly then?: undefined; } /** * Response of an asynchronous query. */ interface AsyncQueryResult extends Promise> { /** * Total number of available items in the result. * @deprecated transport the 'total' value on the result array. */ readonly total?: Promise; } type QueryResult = ResultItems | AsyncQueryResult; /** Options to specify the results for queries. */ interface RetrievalOptions { /** * Determine the fields to be queried. * e.g. `{ geometry: true, id: true, name: true }` */ readonly fields?: Record; /** * Options for geometry retrieval. */ readonly geometry?: GeometryOptions & IndexableThing; } /** Options to specify geometry results for queries. */ interface GeometryOptions { /** * Offset value used for generalizing geometries. * Specifies how the geometry can be retrieved in less detailed resolution. * e.g. `{ maxAllowableOffset: 1000 }` */ readonly maxAllowableOffset?: number; /** * Specifies the output SpatialReferenceSystem (SRS) for the geometry. * If the store supports transformations, this property should be respected. */ readonly sr?: { readonly wkid: number; } | { readonly wkt: string; }; } /** Options to specify how query results are sorted */ interface SortOptions { /** * An array of sort definitions. * Each definition contains an attribute property to sort on * and a 'descending' property indicating the direction of sorting. */ readonly sort?: ReadonlyArray; /** * Defines that sorting should be done ignoring case. * Default is true. */ readonly sortIgnoreCase?: boolean; } /** Sort definition to specify the order of items. */ interface SortItem { /** * Attribute to sort on. */ readonly attribute: string; /** * Direction of the sort (ascending or descending). * Default value is 'false'. */ readonly descending?: boolean; } /** * Options to specify paging. */ interface PaginationOptions { /** * Starting offset. **/ readonly start?: number; /** * Number of items to return. **/ readonly count?: number; } /** Options to specify how the query input is interpreted **/ interface QueryInterpretationOptions { /** * Defines if conditions in the query should be case sensitive. * Default value is 'false'. */ readonly ignoreCase?: boolean; /** * Defines if a '$suggest' query should be interpreted as "contained in". * Default value is 'false'. In that case, matches "start" with the suggest string. */ readonly suggestContains?: boolean; /** * Locale used in the query. */ readonly locale?: { readonly language: string; readonly country?: string; }; } /** * Abort options to transport an AbortSignal */ interface AbortOptions { /** * AbortSignal to cancel query. It is transported via options. **/ readonly signal?: AbortSignal; } /** General options to manipulate the query interpretation. */ type QueryOptions = RetrievalOptions & SortOptions & PaginationOptions & QueryInterpretationOptions & AbortOptions & IndexableThing; /** Options to manipulate the get operation. */ type GetOptions = RetrievalOptions & AbortOptions & IndexableThing; /** List of types allowed as ID property **/ type AllowedIdTypes = string | number; /** * Events that may be emitted by a store. * * Note that not all stores implement events. */ interface StoreEvents { /** Emitted when the underlying data changed. */ changed: StoreChangedEvent; } /** Emitted when the underlying data of a store changed. */ interface StoreChangedEvent { /** IDs of items that were added. */ added?: IDType[] | undefined; /** IDs of items that were updated. */ updated?: IDType[] | undefined; /** IDs of items that were deleted. */ deleted?: IDType[] | undefined; } /** The general Store interface. */ type Store = SyncStore | AsyncStore; /** The general WritableStore interface. */ type WritableStore = SyncWritableStore | AsyncWritableStore; /** An asynchronous store. This is the preferred kind of store implementation.*/ interface AsyncStore extends Partial>> { /** ID of the store. */ readonly id: string | undefined; /** Name of the property used as ID. If not provided, the 'getIdentity' method must be declared.*/ readonly idProperty?: string; /** * Queries the store using the provided query. * @param query a query to execute. * @param options the query options. */ query(query?: ComplexQueryExpression, options?: QueryOptions): AsyncQueryResult; /** * Retrieves an item by its identifier. * @param id id of an item in the store. * @param options options to specify the result. */ get(id: IDType, options?: GetOptions): Promise; /** * Returns any available metadata about the store. * This may include attribution, available fields, cache directives, history or version information. */ getMetadata(): Promise; /** * Returns an items‘s identity. * This must always execute synchronously. * * @param item the item. * @returns the ID */ getIdentity?(item: Partial): IDType | undefined; } /** * A synchronous store. It is provided for legacy store implementations only and should not be actively used anymore. * @deprecated use AsyncStore instead */ interface SyncStore extends Partial>> { /** ID of the store. */ readonly id: string; /** Name of the property used as ID. If not provided, the 'getIdentity' method must be declared.*/ readonly idProperty?: string; /** * Queries the store using the provided query. * @param query a query to execute. * @param options the query options. */ query(query?: ComplexQueryExpression, options?: QueryOptions): ResultItems; /** * Retrieves an item by its identifier. * @param id id of an item in the store. * @param options options to specify the result. */ get(id: IDType, options?: GetOptions): undefined | ItemType; /** * Returns any available metadata about the store. * This may include attribution, available fields, cache directives, history or version information. */ getMetadata(): Metadata; /** * Returns an items‘s identity. This must always execute synchronously. * @param item the item * @returns the ID */ getIdentity?(item: Partial): IDType | undefined; } /** * Options to customize the Put/Add Operation. * Each option is optional and advisory. * stores are not required to implement or respond to any property. */ interface CreateOptions { /** Indicates the identity of the item, when a new object is created. **/ id?: IDType; /** * Flag that indicates that a new object should overwrite an existing object. * * If set to 'true', no new object should be created, but an existing object should be updated. * If set to 'false' a new object should be created (which is the same as an add() operation). **/ overwrite?: boolean; } /** * An asynchronous store that accepts changes to it's contents. */ interface AsyncWritableStore extends AsyncStore { /** * Saves the given item. * Depending on the specified options, a new item is created or a given item is updated. * @param item item to update/create * @param [options] options to specify the PUT operation */ put(item: Partial, options?: CreateOptions): Promise; /** * Create a new item. * Throws an error, if the item already exists. * The 'overwrite' option is assumed to be false). * @param item * @param options */ add(item: Partial, options?: CreateOptions): Promise; /** * Delete an item by id. * @param id id of item to delete */ remove(id: IDType): Promise; } /** * A synchronous store that accepts changes to it's contents. * @deprecated use WritableAsyncStore instead */ interface SyncWritableStore extends SyncStore { /** * Saves the given item. * Depending on the specified options, a new item is created or a given item is updated. * @param item item to update/create * @param [options] options to specify the PUT operation */ put(item: Partial, options?: CreateOptions): ItemType; /** * Create a new item. * Throws an error, if the item already exists. * The 'overwrite' option is assumed to be false). * @param item * @param options */ add(item: Partial, options?: CreateOptions): ItemType; /** * Delete an item by id. * @param id id of item to delete */ remove(id: IDType): void; } /** * Metadata to describe a store. */ interface Metadata { /** Stores may contain arbitrary custom metadata information. */ readonly [k: string]: any; /** * Title of the store. */ readonly title?: string; /** * Description of the store. */ readonly description?: string; /** * Name of the display field. * Used e.g. for search results to display items. */ readonly displayField?: string; /** * Fields available in the store. These are mandatory. */ readonly fields: readonly FieldData[]; /** * Flag to indicate, if the store supports spatial operations. * If set to 'true', this implicitly declares that the items have a 'geometry' field. * Default is 'false'. */ readonly supportsGeometry?: boolean; /** * Flag to indicate, if the store supports spatial geometry generalization. * If set to 'true' clients know that the usage of * the `GeometryOptions.maxAllowableOffset` is supported by the store. */ readonly supportsGeometryGeneralization?: boolean; /** * Flag to indicate, if the store can react to the 'sort' option in queries. * If this flag omitted, the default value is 'true'. */ readonly supportsSorting?: boolean; /** * Indicates whether the store supports listening for changes in the underlying data. * If this is true, `store.on("changed", ...)` must be implemented as well. * * Note that depending on the specific store, not all kinds of changes can be detected. * For example, a store based on a feature layer might report client side edits, but may * not report changes made to the service by other users. */ readonly supportsChangedEvent?: boolean; } /** * List of well known field types. */ type WellKnownFieldTypes = "string" | "number" | "date" | "geometry"; /** * Field information in the store's metadata to describe a single field available in the store. */ interface FieldData { readonly [k: string]: any; /** Name of the field. */ readonly name: string; /** Title of the field. */ readonly title?: string; /** Type of the field's value. */ readonly type: WellKnownFieldTypes | string; /** If 'type' of the field is 'number', the 'precision' property indicates the kind of the number. */ readonly precision?: "single" | "double" | "long" | "float" | "smallinteger" | "biginteger" | "integer"; /** Marks a field as identity field. Should correlate with 'store.idProperty' */ readonly identifier?: boolean; } export type { AbortOptions, AllowedIdTypes, AsyncQueryResult, AsyncStore, AsyncWritableStore, CreateOptions, FieldData, GeometryOptions, GetOptions, IndexableThing, Metadata, PaginationOptions, QueryInterpretationOptions, QueryOptions, QueryResult, ResultItems, RetrievalOptions, SortItem, SortOptions, Store, StoreChangedEvent, StoreEvents, SyncStore, SyncWritableStore, WellKnownFieldTypes, WritableStore };