UNPKG

@arcgis/coding-components

Version:

Contains components for editing code in different languages. The currently supported languages are html, css, json, TypeScript, JavaScript, and Arcade.

164 lines (163 loc) 6.16 kB
/// <reference types="@arcgis/core/interfaces.d.ts" /> import { IEditorProfileDefinition } from './profile/types'; /** * An object of key/value pairs where the key is the name of a profile variable. * The key's value must be of type ArcGIS core ProfileVariableInstanceType. */ export type ProfileVariableInstances = Record<string, __esri.ProfileVariableInstanceType>; interface IContextReferences { /** * Spatial reference object used to define the spatial reference for the arcade runtime. * By defaults, the spatial reference is set to Web Mercator (wkid: 3857). */ spatialReference?: __esri.SpatialReference | { wkid: number; } | null; /** * Defines the default time zone in which to create and display Arcade date types. * By default, the time zone is set to "system". */ timeZone?: string; } /** * If a profile doesn't contain a map, the spatial reference of geometries will be defaulted to * wkid: 3857. * The test context objects allows to set the execution spatial reference for such scenario. */ export interface IEditorTestContext extends IContextReferences { /** * An object of key/value pairs where the key is the name of a profile variable. * The key's value must be of type ArcGIS core ProfileVariableInstanceType. */ profileVariableInstances: ProfileVariableInstances; } /** * @deprecated Use IEditorTestContext instead. */ export type EditorTestContext = IEditorTestContext; export interface IArcadeRuntimeDictionary { declaredClass?: string; arcadeDeclaredClass?: string; keys: () => string[]; field: (name: string) => unknown; geometry?: () => __esri.Geometry; castAsJson: () => Record<string, unknown>; } export interface IAbortSignal { aborted: boolean; } interface IArcadeRuntimeFeatureSet { declaredRootClass: string; fields: __esri.Field[] | null; load: () => Promise<IArcadeRuntimeFeatureSet>; iterator: (abortSignal: IAbortSignal) => IArcadeRuntimeFeatureSetIterator; } interface IArcadeRuntimeFeatureSetIterator { nextBatchAsArcadeFeatures: (bsize: number, timeZone: string) => Promise<IArcadeRuntimeDictionary[] | null>; } interface IArcadeRuntimeDate { declaredRootClass: string; toDateTime: () => { setLocale: (locale: string) => { toFormat: (format: string) => string; }; }; isUnknownTimeZone: boolean; } interface IArcadeRuntimeDateOnly { declaredRootClass: string; /** * To ISO Date format */ toString: () => string; } interface IArcadeRuntimeTimeOnly { declaredRootClass: string; /** * To ISO Time format */ toString: () => string; } export type ResultType = "array" | "attachment" | "boolean" | "date" | "dateOnly" | "dictionary" | "error" | "feature" | "featureSet" | "geometry" | "knowledgeGraph" | "null" | "number" | "portal" | "text" | "time" | "unknown"; interface IArcadeResultBase { type: ResultType; timeStamp?: Date; compilationTime?: number; executionTime?: number; } export interface IArcadeResultUnknown extends IArcadeResultBase { type: "unknown"; } export interface IArcadeResultNull extends IArcadeResultBase { type: "null"; } export interface IArcadeResultError extends IArcadeResultBase { type: "error"; value: string; error: unknown; } export interface IArcadeResultArray extends IArcadeResultBase { type: "array"; value: unknown[]; } export interface IArcadeResultDate extends IArcadeResultBase { type: "date"; value: Date | IArcadeRuntimeDate; } export interface IArcadeResultDateOnly extends IArcadeResultBase { type: "dateOnly"; value: IArcadeRuntimeDateOnly; } export interface IArcadeResultTimeOnly extends IArcadeResultBase { type: "time"; value: IArcadeRuntimeTimeOnly; } export interface IArcadeResultString extends IArcadeResultBase { type: "text"; value: string; } export interface IArcadeResultNumber extends IArcadeResultBase { type: "number"; value: number; } export interface IArcadeResultBoolean extends IArcadeResultBase { type: "boolean"; value: boolean; } export interface IArcadeResultDictionary extends IArcadeResultBase { type: "dictionary"; value: IArcadeRuntimeDictionary; } export interface IArcadeResultGeometry extends IArcadeResultBase { type: "geometry"; value: __esri.Geometry; } export interface IArcadeResultKnowledgeGraph extends IArcadeResultBase { type: "knowledgeGraph"; value: __esri.KnowledgeGraph; } export interface IArcadeResultFeature extends IArcadeResultBase { type: "feature"; value: IArcadeRuntimeDictionary; } export interface IArcadeResultFeatureSet extends IArcadeResultBase { type: "featureSet"; value: IArcadeRuntimeFeatureSet; iterator: IArcadeRuntimeFeatureSetIterator | null; features: IArcadeRuntimeDictionary[]; } export interface IArcadeResultPortal extends IArcadeResultBase { type: "portal"; value: IArcadeRuntimeDictionary; } export interface IArcadeResultAttachment extends IArcadeResultBase { type: "attachment"; value: IArcadeRuntimeDictionary; } export type ArcadeResult = IArcadeResultArray | IArcadeResultAttachment | IArcadeResultBoolean | IArcadeResultDate | IArcadeResultDateOnly | IArcadeResultDictionary | IArcadeResultError | IArcadeResultFeature | IArcadeResultFeatureSet | IArcadeResultGeometry | IArcadeResultKnowledgeGraph | IArcadeResultNull | IArcadeResultNumber | IArcadeResultPortal | IArcadeResultString | IArcadeResultTimeOnly | IArcadeResultUnknown; export declare function valueToArcadeResult(value: unknown): ArcadeResult; export declare function formatArcadeResultDate(dateObject: IArcadeResultDate, lang?: string): string; export declare function formatArcadeResultDateOnly(dateObject: IArcadeResultDateOnly): string; export declare function formatArcadeResultTimeOnly(dateObject: IArcadeResultTimeOnly): string; export declare function executeScript(editorProfile: IEditorProfileDefinition | undefined, script: string | undefined, testContext: IEditorTestContext, console?: (log: string) => void): Promise<ArcadeResult>; export {};