@arcgis/toolkit 5.2.0-next.1 → 5.2.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,110 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const dom_index = require("../dom/index.cjs");
4
- const log_index = require("../log/index.cjs");
5
- const supportedLocalesArray = "ar,bg,bs,ca,cs,da,de,el,en,es,et,fi,fr,he,hr,hu,id,it,ja,ko,lt,lv,nl,nb,no,pl,pt-BR,pt-PT,ro,ru,sk,sl,sr,sv,th,tr,uk,vi,zh-CN,zh-HK,zh-TW".split(
6
- ","
7
- );
8
- const supportedLocales = (
9
- //#endregion supportedLocales
10
- /* @__PURE__ */ new Set(supportedLocalesArray)
11
- );
12
- const defaultLocale = "en";
13
- const localeEquivalencies = {
14
- //#region localeEquivalencies
15
- // Locale equivalencies aligned with ArcGIS Maps SDK for JavaScript:
16
- // https://developers.arcgis.com/javascript/latest/localization/#locale-support
17
- // We resolve to `pt-BR` as it will have the same translations as `pt`, which has no corresponding bundle
18
- pt: "pt-BR",
19
- // We support both 'nb' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
20
- nb: "no",
21
- // We support both 'nn' and 'no' (BCP 47) for Norwegian but only `no` has corresponding bundle
22
- // See https://devtopia.esri.com/WebGIS/arcgis-web-components/issues/4667
23
- nn: "no",
24
- // We use `zh-CN` as base translation for chinese locales which has no corresponding bundle.
25
- zh: "zh-CN"
26
- //#endregion localeEquivalencies
27
- };
28
- const fetchT9nStringsBundle = async (locale, assetsPath, prefix = "") => {
29
- const path = `${assetsPath}/${prefix}`;
30
- const filePath = `${path}${locale}.json`;
31
- t9nStringsCache[filePath] ?? (t9nStringsCache[filePath] = fetchBundle(locale, path));
32
- return await t9nStringsCache[filePath];
33
- };
34
- const t9nStringsCache = {};
35
- const fetchBundle = async (locale, path) => {
36
- const filePath = `${path}${locale}.json`;
37
- try {
38
- const response = await fetch(filePath);
39
- if (response.ok) {
40
- return await response.json();
41
- }
42
- } catch (error) {
43
- if (process.env.NODE_ENV !== "production") {
44
- const is404ViteFallback = String(error).includes(`Unexpected token '<', "<!doctype "... is not valid JSON`);
45
- if (is404ViteFallback) {
46
- log_index.log("error", "intl", `Localization strings not found at ${filePath}`);
47
- } else {
48
- log_index.log("error", "intl", `Error fetching localization strings at ${filePath}`, { detail: { error } });
49
- }
50
- } else {
51
- log_index.log("error", "intl", `An unknown error occurred while fetching localization strings at ${filePath}`, {
52
- detail: { error }
53
- });
54
- }
55
- return {};
56
- }
57
- if (locale === defaultLocale) {
58
- return {};
59
- }
60
- return await fetchBundle(defaultLocale, path);
61
- };
62
- const getElementLocale = (element) => {
63
- const lang = dom_index.getElementAttribute(element, "lang", globalThis.navigator?.language || defaultLocale);
64
- return { lang, t9nLocale: normalizeLocale(lang) };
65
- };
66
- const normalizeLocale = (lang) => {
67
- const [rawLanguageCode, regionCode] = lang.split("-");
68
- const languageCode = rawLanguageCode.toLowerCase();
69
- let normalizedLocale = languageCode;
70
- if (regionCode) {
71
- normalizedLocale = `${languageCode}-${regionCode.toUpperCase()}`;
72
- }
73
- normalizedLocale = localeEquivalencies[normalizedLocale] ?? normalizedLocale;
74
- if (supportedLocales.has(normalizedLocale)) {
75
- return normalizedLocale;
76
- }
77
- if (regionCode) {
78
- return normalizeLocale(languageCode);
79
- }
80
- return defaultLocale;
81
- };
82
- const startLocaleObserver = (element, getAssetsPath, onUpdated, assetName) => {
83
- let result = void 0;
84
- const callback = () => updateComponentLocaleState(element, getAssetsPath(), assetName).then((newResult) => {
85
- if (result?.lang !== newResult.lang || result.t9nLocale !== newResult.t9nLocale || result.t9nStrings !== newResult.t9nStrings) {
86
- onUpdated(newResult);
87
- }
88
- result = newResult;
89
- }).catch((error) => {
90
- log_index.log("error", "intl", "Error updating component locale state", { detail: { error } });
91
- });
92
- queueMicrotask(callback);
93
- return dom_index.observeAncestorsMutation(element, ["lang"], callback);
94
- };
95
- const updateComponentLocaleState = async (element, assetsPath, assetName = element.localName.split("-").slice(1).join("-")) => {
96
- const { lang, t9nLocale } = getElementLocale(element);
97
- const t9nAssetsPath = `${assetsPath}/${assetName}/t9n`;
98
- const prefix = `messages.`;
99
- const t9nStrings = (
100
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
101
- assetName === null ? {} : await fetchT9nStringsBundle(t9nLocale, t9nAssetsPath, prefix)
102
- );
103
- return { lang, t9nLocale, t9nStrings };
104
- };
105
- exports.defaultLocale = defaultLocale;
106
- exports.fetchT9nStringsBundle = fetchT9nStringsBundle;
107
- exports.getElementLocale = getElementLocale;
108
- exports.normalizeLocale = normalizeLocale;
109
- exports.startLocaleObserver = startLocaleObserver;
110
- exports.supportedLocales = supportedLocales;
@@ -1,124 +0,0 @@
1
- declare const supportedLocalesArray: ["ar", "bg", "bs", "ca", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr", "he", "hr", "hu", "id", "it", "ja", "ko", "lt", "lv", "nl", "nb", "no", "pl", "pt-BR", "pt-PT", "ro", "ru", "sk", "sl", "sr", "sv", "th", "tr", "uk", "vi", "zh-CN", "zh-HK", "zh-TW"];
2
- /**
3
- * The list of supported locales for ArcGIS Maps SDK for JavaScript components.
4
- */
5
- export declare const supportedLocales: Set<"hr" | "th" | "tr" | "el" | "ar" | "bg" | "bs" | "ca" | "cs" | "da" | "de" | "en" | "es" | "et" | "fi" | "fr" | "he" | "hu" | "id" | "it" | "ja" | "ko" | "lt" | "lv" | "nl" | "nb" | "no" | "pl" | "pt-BR" | "pt-PT" | "ro" | "ru" | "sk" | "sl" | "sr" | "sv" | "uk" | "vi" | "zh-CN" | "zh-HK" | "zh-TW">;
6
- /**
7
- * TypeScript union type for each locale supported by WebGIS SDK
8
- */
9
- export type SupportedLocale = (typeof supportedLocalesArray)[number];
10
- /**
11
- * The default locale for WebGIS SDK.
12
- */
13
- export declare const defaultLocale = "en";
14
- /**
15
- * Fetch the T9N strings bundle for the given locale, assets path and prefix.
16
- * The locale must be one of the supported locales.
17
- * If the locale is not supported, it will default to 'en'.
18
- * If the T9N strings bundle cannot be found, it will default to 'en'.
19
- *
20
- * @param locale The locale for which to fetch the T9N strings
21
- * @param assetsPath The path to the assets folder where the T9N strings are located
22
- * @param prefix The prefix to use for the T9N strings file name.
23
- *
24
- * @remarks
25
- * Rather than using this function directly, prefer the
26
- * [useT9n()](https://webgis.esri.com/references/lumina/controllers/useT9n)
27
- * controller.
28
- *
29
- * @remarks
30
- * The function implements cache. Frequent calls are safe.
31
- *
32
- * @example
33
- * ```ts
34
- * // Will make a request for ./assets/coding-editor/t9n/messages.en.json
35
- * const t9nStrings = await fetchT9nStringsBundle(
36
- * "en",
37
- * getAssetPath("./assets/coding-editor/t9n"),
38
- * "messages."
39
- * );
40
- * ```
41
- *
42
- * @see [Lumina asset handling](https://webgis.esri.com/references/lumina/assets)
43
- */
44
- export declare const fetchT9nStringsBundle: <Strings extends GenericT9nStrings>(locale: string, assetsPath: string, prefix?: string) => Promise<Strings>;
45
- /**
46
- * The interface for translated strings.
47
- */
48
- export interface GenericT9nStrings {
49
- [key: string]: GenericT9nStrings | string;
50
- }
51
- /**
52
- * Get the locale of the given element.
53
- * It will look for the lang attribute on the element and its ancestors.
54
- * If not lang is found, it will default to 'en'.
55
- *
56
- * @returns an object with the `lang` and `t9nLocale` properties.
57
- *
58
- * @see [lang vs t9nLocale](https://webgis.esri.com/references/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
59
- */
60
- export declare const getElementLocale: (element: HTMLElement) => {
61
- readonly lang: string;
62
- readonly t9nLocale: SupportedLocale;
63
- };
64
- /**
65
- * Try to parse any language string into one of the locales supported by WebGIS SDK.
66
- *
67
- * @remarks
68
- * Follows the ArcGIS Maps SDK for JavaScript locale support:
69
- * https://developers.arcgis.com/javascript/latest/localization/#locale-support
70
- *
71
- * If language includes a region code, but we don't have a bundle for it, the
72
- * language is normalized to the language code only.
73
- */
74
- export declare const normalizeLocale: (lang: string) => SupportedLocale;
75
- export interface LocaleObserverResult<Strings extends GenericT9nStrings = GenericT9nStrings> {
76
- /** The T9N strings of the component */
77
- t9nStrings: Strings;
78
- /**
79
- * The locale of the component set by the `lang` attribute on the component host element or one of its ancestors.
80
- */
81
- lang: string;
82
- /**
83
- * The locale used by the component to load the T9N strings.
84
- * It may be different than the locale of the component host element that was set by the `lang` attribute.
85
- */
86
- t9nLocale: SupportedLocale;
87
- }
88
- /**
89
- * Start the locale observer for the given component.
90
- * The callback will be called when the locale changes for the component.
91
- * It will observe the lang attribute on the component and its ancestors.
92
- * The callback is called once at the beginning.
93
- *
94
- * @param element The HTML element that is doing the fetching
95
- * This is used to determine the locale to fetch, observe the `lang` attribute
96
- * changes, and is used as the default value for the `assetName` parameter.
97
- * @param getAssetsPath The callback to get path to the assets folder where the
98
- * T9N strings are located.
99
- * @param onUpdated The callback to call when the locale changes.
100
- * @param assetName Optionally override the asset file name.
101
- * Default file name is the element tag name without the part before the
102
- * first dash (e.g. `arcgis-map` becomes `map`).
103
- *
104
- * Set to null if the component has no localization strings, but you still
105
- * wish to use `startLocaleObserver` to get the locale information.
106
- *
107
- * @remarks
108
- * Rather than using this function directly, prefer the
109
- * [useT9n()](https://webgis.esri.com/references/lumina/controllers/useT9n)
110
- * controller.
111
- *
112
- * @example
113
- * ```ts
114
- * const observer = startLocaleObserver(
115
- * element,
116
- * () => getAssetPath("./assets"),
117
- * ({ strings, lang, t9nLocale }) => console.log({ strings, lang, t9nLocale }),
118
- * );
119
- * // Later: cleanup
120
- * observer();
121
- * ```
122
- */
123
- export declare const startLocaleObserver: <Strings extends GenericT9nStrings = GenericT9nStrings>(element: HTMLElement, getAssetsPath: () => string, onUpdated: (payload: LocaleObserverResult<Strings>) => void, assetName?: string | null) => (() => void);
124
- export {};
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const loggedMessages = /* @__PURE__ */ new Set();
4
- let esriConfig;
5
- const setEsriConfig = (config) => {
6
- esriConfig = config;
7
- };
8
- const getContextString = (context) => {
9
- if (typeof context === "string") {
10
- return context;
11
- }
12
- if ("el" in context) {
13
- return context.el.localName;
14
- }
15
- if ("localName" in context) {
16
- return context.localName;
17
- }
18
- return context.declaredClass;
19
- };
20
- const log = (level, context, message, options) => {
21
- const contextString = getContextString(context);
22
- if (options?.once) {
23
- const key = `${level}${contextString}${message}`;
24
- if (loggedMessages.has(key)) {
25
- return;
26
- }
27
- loggedMessages.add(key);
28
- }
29
- let memorySafeDetail;
30
- if (options?.detail) {
31
- memorySafeDetail = {};
32
- for (const [key, value] of Object.entries(options.detail)) {
33
- if ((typeof value === "object" || typeof value === "function") && value !== null) {
34
- const weakRefValue = new WeakRef(value);
35
- Object.defineProperty(memorySafeDetail, key, {
36
- enumerable: true,
37
- get() {
38
- return weakRefValue.deref();
39
- }
40
- });
41
- } else {
42
- memorySafeDetail[key] = value;
43
- }
44
- }
45
- esriConfig?.log.interceptors?.forEach(
46
- (interceptor) => interceptor(level, contextString, message, memorySafeDetail)
47
- );
48
- console[level](`[${contextString}]: ${message}`, memorySafeDetail);
49
- } else {
50
- esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
51
- console[level](`[${contextString}]: ${message}`);
52
- }
53
- };
54
- const rethrowError = (context) => {
55
- const prefix = `[${getContextString(context)}] `;
56
- return (error) => {
57
- const errorToRethrow = error instanceof Error && error.message ? error : new Error(String(error));
58
- errorToRethrow.message = `${prefix}${errorToRethrow.message}`;
59
- setTimeout(() => {
60
- throw error;
61
- });
62
- };
63
- };
64
- const composeMissingPropertyMessage = (property) => (
65
- //#endregion composeMissingPropertyMessage
66
- `The property \`${property.toString()}\` is required but missing.`
67
- );
68
- const composeEmptyPropertyMessage = (property) => (
69
- //#endregion composeEmptyPropertyMessage
70
- `The property \`${property.toString()}\` is empty but must have at least one element.`
71
- );
72
- const logDeprecatedProperty = (context, oldName, newName, options) => (
73
- //#endregion logDeprecatedProperty
74
- log("warn", context, `\`${oldName.toString()}\` is deprecated. Use \`${newName.toString()}\` instead.`, options)
75
- );
76
- exports.composeEmptyPropertyMessage = composeEmptyPropertyMessage;
77
- exports.composeMissingPropertyMessage = composeMissingPropertyMessage;
78
- exports.log = log;
79
- exports.logDeprecatedProperty = logDeprecatedProperty;
80
- exports.rethrowError = rethrowError;
81
- exports.setEsriConfig = setEsriConfig;
@@ -1,128 +0,0 @@
1
- export type LogLevel = "error" | "info" | "warn";
2
- type CustomElementLike = {
3
- el: {
4
- localName: string;
5
- };
6
- } | {
7
- localName: string;
8
- };
9
- type AccessorLike = {
10
- declaredClass: string;
11
- };
12
- export type LogContext = AccessorLike | CustomElementLike | string;
13
- type LogOptions = {
14
- /** Whether the message should only be logged once. */
15
- once?: boolean;
16
- /** Additional objects to log after `message`. Use this to avoid memory leaks when logging objects to the console. Each object value will be automatically wrapped in a `WeakRef` before logging so it can be garbage-collected. */
17
- detail?: Record<string, unknown>;
18
- };
19
- type EsriConfig = {
20
- log: {
21
- /**
22
- * @link {https://developers.arcgis.com/javascript/latest/references/core/config/#LogInterceptor}
23
- */
24
- interceptors?: ((level: LogLevel | "none", module: string, ...args: any[]) => void)[];
25
- };
26
- };
27
- /**
28
- * Workaround for setting {@link https://developers.arcgis.com/javascript/latest/references/core/config/#log log interceptors} and maintaining compatibility with {@link https://devtopia.esri.com/WebGIS/arcgis-websceneviewer-app/blob/8f0a1bbcf12d1193134d94589d9e187f0afa72fa/src/js/support/ApiLoggerInstrumentation.ts#L17 js-api's interceptor usage}.
29
- * @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
30
- * @param config {@link https://developers.arcgis.com/javascript/latest/references/core/config/}
31
- * @example
32
- * ```ts
33
- * // IMPORTANT: do this only in config.ts or another early-loaded module
34
- * import esriConfig from "@arcgis/core/config.js";
35
- * import { setEsriConfig } from "@arcgis/toolkit/log";
36
- *
37
- * setEsriConfig(esriConfig);
38
- *
39
- * // either here or in another file, you can add your interceptors
40
- * // and they will be respected when log is called later on
41
- * esriConfig.log.interceptors?.push(yourInterceptor);
42
- * ```
43
- */
44
- export declare const setEsriConfig: (config: EsriConfig) => void;
45
- /**
46
- * Helper utility for logging messages in a consistent manner.
47
- *
48
- * @param level The log level
49
- * @param context The context of the log message (e.g., `this` inside a Lit-like component, or just a custom string)
50
- * @param message A custom message to log
51
- * @param options Additional options for logging, such as to provide a context object
52
- *
53
- * @see [setEsriConfig](#setEsriConfig)
54
- *
55
- * @example
56
- * ```ts
57
- * // Basic usage
58
- * log("error", this, "message to log");
59
- * ```
60
- *
61
- * @example
62
- * ```ts
63
- * // Optional usage
64
- * log("warn", this, "message to log", {
65
- * once: true,
66
- * detail: { object1, object2 }
67
- * });
68
- */
69
- export declare const log: (level: LogLevel, context: LogContext, message: string, options?: LogOptions) => void;
70
- /**
71
- * Rethrows an error and prepends context information to the error message. The error is
72
- * thrown asynchronously to avoid interrupting the current execution stack, so it cannot be caught
73
- * with `try/catch` and will bubble to the global object.
74
- * @param context From where the error is being thrown (e.g., `this` inside a Lit-like component, or just a custom string)
75
- * @returns A function that can be used in `try-catch`/`.catch` to rethrow an error
76
- *
77
- * @example
78
- * ```ts
79
- * try {
80
- * functionThatMightThrow();
81
- * } catch (error) {
82
- * rethrowError(this)(error);
83
- * }
84
- * ```
85
- *
86
- * @example
87
- * ```ts
88
- * promise.then().catch(rethrowError("context string"));
89
- * ```
90
- */
91
- export declare const rethrowError: (context: LogContext) => ((error: unknown) => void);
92
- type LogContextOrObject = Exclude<LogContext, string> | object;
93
- type InferPropertyType<T extends LogContextOrObject> = [object] extends [T] ? string : keyof T;
94
- /**
95
- * Returns a string that can be used in log messages for missing required properties.
96
- * @param property The name of the required property
97
- * @example
98
- * ```ts
99
- * // returns "The property `x` is required but missing."
100
- * composeMissingPropertyMessage<YourClass>("x");
101
- * // you don't need to provide a generic type argument if you don't have one
102
- * composeMissingPropertyMessage("object.sub.property");
103
- * ```
104
- */
105
- export declare const composeMissingPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
106
- /**
107
- * Returns a string that can be used in log messages for empty required arrays.
108
- * @param property The name of the required property
109
- * @example
110
- * ```ts
111
- * // returns "The property `x` is empty but must have at least one element."
112
- * composeEmptyPropertyMessage<YourClass>("x");
113
- * // you don't need to provide a generic type argument if you don't have one
114
- * composeEmptyPropertyMessage("object.sub.property");
115
- * ```
116
- */
117
- export declare const composeEmptyPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
118
- /**
119
- * Logs a warning message for deprecated object properties.
120
- * @example
121
- * ```ts
122
- * logDeprecatedProperty(this, "oldName", "newName", {
123
- * once: true,
124
- * });
125
- * ```
126
- */
127
- export declare const logDeprecatedProperty: <T extends LogContext>(context: T, oldName: keyof T, newName: keyof T, options?: LogOptions) => ReturnType<typeof log>;
128
- export {};
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- function clamp(value, min, max) {
4
- return Math.max(min, Math.min(max, value));
5
- }
6
- function lerp(min, max, t) {
7
- return min + (max - min) * t;
8
- }
9
- exports.clamp = clamp;
10
- exports.lerp = lerp;
@@ -1,19 +0,0 @@
1
- /**
2
- * Clamps a value between a minimum and maximum value.
3
- *
4
- * @param value The number to clamp.
5
- * @param min The minimum value.
6
- * @param max The maximum value.
7
- *
8
- * @returns The clamped value.
9
- */
10
- export declare function clamp(value: number, min: number, max: number): number;
11
- /**
12
- * Linearly interpolates between two numbers.
13
- *
14
- * @param min - The start value.
15
- * @param max - The end value.
16
- * @param t - The interpolation factor, typically between 0 and 1.
17
- * @returns The interpolated value between `min` and `max` based on `t`.
18
- */
19
- export declare function lerp(min: number, max: number, t: number): number;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const isNotUndefined = (item) => item !== void 0;
4
- const isNotNull = (item) => item !== null;
5
- const isNotNil = (x) => x != null;
6
- exports.isNotNil = isNotNil;
7
- exports.isNotNull = isNotNull;
8
- exports.isNotUndefined = isNotUndefined;
@@ -1,24 +0,0 @@
1
- import { nil } from '../type/index.ts';
2
- /**
3
- * Safeguard to ensure that an item is not undefined.
4
- * @param item The item to check.
5
- * @returns Returns true if the item is not undefined.
6
- * @example
7
- * ```ts
8
- * const arr = [1, undefined, 3];
9
- * const result = arr.filter(isNotUndefined);
10
- * ```
11
- */
12
- export declare const isNotUndefined: <T>(item: T | undefined) => item is T;
13
- /**
14
- * Safeguard to ensure that an item is not null.
15
- * @param item The item to check.
16
- * @returns Returns true if the item is not null.
17
- */
18
- export declare const isNotNull: <T>(item: T | null) => item is T;
19
- /**
20
- * Safeguard to ensure that an item is not null.
21
- * @param item The item to check.
22
- * @returns Returns true if the item is not and not undefined and not null.
23
- */
24
- export declare const isNotNil: <T>(x: nil | T) => x is T;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- class Deferred {
4
- /**
5
- * Creates a new deferred promise.
6
- */
7
- constructor() {
8
- this.promise = new Promise((resolve, reject) => {
9
- this.resolve = resolve;
10
- this.reject = reject;
11
- });
12
- }
13
- }
14
- async function forEachWithConcurrency(items, concurrency, callback) {
15
- if (items.length === 0) {
16
- return;
17
- }
18
- let index = 0;
19
- async function consumeItems() {
20
- while (index < items.length) {
21
- const item = items[index];
22
- index += 1;
23
- await callback(item);
24
- }
25
- }
26
- await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, async () => await consumeItems()));
27
- }
28
- const devToolsAwareTimeout = (callback, timeout) => {
29
- const interval = timeout > longTimeoutThreshold ? longTimeoutInterval : timeout / shortTimeoutIntervals;
30
- let elapsed = 0;
31
- const reference = setInterval(() => {
32
- elapsed += interval;
33
- if (elapsed >= timeout) {
34
- clearInterval(reference);
35
- callback();
36
- }
37
- }, interval);
38
- return reference;
39
- };
40
- const longTimeoutThreshold = 4e3;
41
- const longTimeoutInterval = 2e3;
42
- const shortTimeoutIntervals = 4;
43
- exports.Deferred = Deferred;
44
- exports.devToolsAwareTimeout = devToolsAwareTimeout;
45
- exports.forEachWithConcurrency = forEachWithConcurrency;
@@ -1,60 +0,0 @@
1
- /**
2
- * A deferred promise.
3
- * Useful for when you want to return a promise but don't have the value yet.
4
- *
5
- * @example
6
- * ```ts
7
- * const deferred = new Deferred<string>();
8
- * setTimeout(() => deferred.resolve("Hello World"), 1000);
9
- * return deferred.promise;
10
- * ```
11
- *
12
- * @deprecated
13
- * If browser support permits, prefer using
14
- * [Promise.withResolvers()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers)
15
- */
16
- export declare class Deferred<T> {
17
- /**
18
- * The promise that can be awaited.
19
- */
20
- promise: Promise<T>;
21
- /**
22
- * Creates a new deferred promise.
23
- */
24
- constructor();
25
- }
26
- export interface Deferred<T> {
27
- /**
28
- * Resolves the promise.
29
- * @param value The value to resolve the promise with.
30
- *
31
- * @privateRemarks
32
- * Defined as a method to disable covariance checks. Overridden in constructor.
33
- */
34
- resolve(_value: PromiseLike<T> | T): void;
35
- /**
36
- * Rejects the promise.
37
- */
38
- reject(_error: unknown): void;
39
- }
40
- /**
41
- * Execute async callbacks against a list with a fixed number of in-flight
42
- * operations.
43
- * Useful for rate-limiting or to avoid overwhelming resources with too many concurrent operations.
44
- *
45
- * @example
46
- * ```ts
47
- * const items = [...lotsOfItems];
48
- * await forEachWithConcurrency(items, 5, async (item) => {
49
- * await doSomethingAsync(item);
50
- * });
51
- * ```
52
- */
53
- export declare function forEachWithConcurrency<T>(items: readonly T[], concurrency: number, callback: (item: T) => Promise<void>): Promise<void>;
54
- /**
55
- * Like setTimeout(), but does not advance the clock if the program is
56
- * stopped on a debugger breakpoint.
57
- *
58
- * @see https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/60405
59
- */
60
- export declare const devToolsAwareTimeout: (callback: () => void, timeout: number) => ReturnType<typeof setInterval>;