@arcgis/toolkit 5.0.0-next.94 → 5.0.0-next.96

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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const dom_index = require("../dom/index.cjs");
4
+ const log_index = require("../log/index.cjs");
4
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(
5
6
  ","
6
7
  );
@@ -40,12 +41,14 @@ const fetchBundle = async (locale, path) => {
40
41
  if (process.env.NODE_ENV !== "production") {
41
42
  const is404ViteFallback = String(error).includes(`Unexpected token '<', "<!doctype "... is not valid JSON`);
42
43
  if (is404ViteFallback) {
43
- console.error(`[404] Localization strings not found at ${filePath}`);
44
+ log_index.log("error", "intl", `Localization strings not found at ${filePath}`);
44
45
  } else {
45
- console.error(`Error fetching localization strings at ${filePath}`, error);
46
+ log_index.log("error", "intl", `Error fetching localization strings at ${filePath}`, { detail: { error } });
46
47
  }
47
48
  } else {
48
- console.error(error);
49
+ log_index.log("error", "intl", `An unknown error occurred while fetching localization strings at ${filePath}`, {
50
+ detail: { error }
51
+ });
49
52
  }
50
53
  return {};
51
54
  }
@@ -81,7 +84,9 @@ const startLocaleObserver = (element, getAssetsPath, onUpdated, assetName) => {
81
84
  onUpdated(newResult);
82
85
  }
83
86
  result = newResult;
84
- }).catch(console.error);
87
+ }).catch((error) => {
88
+ log_index.log("error", "intl", "Error updating component locale state", { detail: { error } });
89
+ });
85
90
  queueMicrotask(callback);
86
91
  return dom_index.observeAncestorsMutation(element, ["lang"], callback);
87
92
  };
@@ -2,7 +2,7 @@ declare const supportedLocalesArray: ["ar", "bg", "bs", "ca", "cs", "da", "de",
2
2
  /**
3
3
  * The list of supported locales for ArcGIS Maps SDK for JavaScript components.
4
4
  */
5
- export declare const supportedLocales: Set<"hr" | "th" | "tr" | "ar" | "bg" | "bs" | "ca" | "cs" | "da" | "de" | "el" | "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">;
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
6
  /**
7
7
  * TypeScript union type for each locale supported by WebGIS SDK
8
8
  */
@@ -2,7 +2,7 @@ declare const supportedLocalesArray: ["ar", "bg", "bs", "ca", "cs", "da", "de",
2
2
  /**
3
3
  * The list of supported locales for ArcGIS Maps SDK for JavaScript components.
4
4
  */
5
- export declare const supportedLocales: Set<"hr" | "th" | "tr" | "ar" | "bg" | "bs" | "ca" | "cs" | "da" | "de" | "el" | "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">;
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
6
  /**
7
7
  * TypeScript union type for each locale supported by WebGIS SDK
8
8
  */
@@ -1,4 +1,5 @@
1
1
  import { getElementAttribute, observeAncestorsMutation } from "../dom/index.js";
2
+ import { log } from "../log/index.js";
2
3
  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(
3
4
  ","
4
5
  );
@@ -38,12 +39,14 @@ const fetchBundle = async (locale, path) => {
38
39
  if (process.env.NODE_ENV !== "production") {
39
40
  const is404ViteFallback = String(error).includes(`Unexpected token '<', "<!doctype "... is not valid JSON`);
40
41
  if (is404ViteFallback) {
41
- console.error(`[404] Localization strings not found at ${filePath}`);
42
+ log("error", "intl", `Localization strings not found at ${filePath}`);
42
43
  } else {
43
- console.error(`Error fetching localization strings at ${filePath}`, error);
44
+ log("error", "intl", `Error fetching localization strings at ${filePath}`, { detail: { error } });
44
45
  }
45
46
  } else {
46
- console.error(error);
47
+ log("error", "intl", `An unknown error occurred while fetching localization strings at ${filePath}`, {
48
+ detail: { error }
49
+ });
47
50
  }
48
51
  return {};
49
52
  }
@@ -79,7 +82,9 @@ const startLocaleObserver = (element, getAssetsPath, onUpdated, assetName) => {
79
82
  onUpdated(newResult);
80
83
  }
81
84
  result = newResult;
82
- }).catch(console.error);
85
+ }).catch((error) => {
86
+ log("error", "intl", "Error updating component locale state", { detail: { error } });
87
+ });
83
88
  queueMicrotask(callback);
84
89
  return observeAncestorsMutation(element, ["lang"], callback);
85
90
  };
@@ -44,12 +44,22 @@ const log = (level, context, message, options) => {
44
44
  esriConfig?.log.interceptors?.forEach(
45
45
  (interceptor) => interceptor(level, contextString, message, memorySafeDetail)
46
46
  );
47
- console[level](`[${contextString}]`, message, memorySafeDetail);
47
+ console[level](`[${contextString}]: ${message}`, memorySafeDetail);
48
48
  } else {
49
49
  esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
50
- console[level](`[${contextString}]`, message);
50
+ console[level](`[${contextString}]: ${message}`);
51
51
  }
52
52
  };
53
+ const rethrowError = (context) => {
54
+ const prefix = `[${getContextString(context)}] `;
55
+ return (error) => {
56
+ const errorToRethrow = error instanceof Error && error.message ? error : new Error(String(error));
57
+ errorToRethrow.message = `${prefix}${errorToRethrow.message}`;
58
+ setTimeout(() => {
59
+ throw error;
60
+ });
61
+ };
62
+ };
53
63
  const composeMissingPropertyMessage = (property) => (
54
64
  //#endregion composeMissingPropertyMessage
55
65
  `The property \`${property.toString()}\` is required but missing.`
@@ -66,4 +76,5 @@ exports.composeEmptyPropertyMessage = composeEmptyPropertyMessage;
66
76
  exports.composeMissingPropertyMessage = composeMissingPropertyMessage;
67
77
  exports.log = log;
68
78
  exports.logDeprecatedProperty = logDeprecatedProperty;
79
+ exports.rethrowError = rethrowError;
69
80
  exports.setEsriConfig = setEsriConfig;
@@ -45,6 +45,11 @@ export declare const setEsriConfig: (config: EsriConfig) => void;
45
45
  /**
46
46
  * Helper utility for logging messages in a consistent manner.
47
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
+ *
48
53
  * @see [setEsriConfig](#setEsriConfig)
49
54
  *
50
55
  * @example
@@ -62,6 +67,28 @@ export declare const setEsriConfig: (config: EsriConfig) => void;
62
67
  * });
63
68
  */
64
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);
65
92
  type LogContextOrObject = Exclude<LogContext, string> | object;
66
93
  type InferPropertyType<T extends LogContextOrObject> = [object] extends [T] ? string : keyof T;
67
94
  /**
@@ -45,6 +45,11 @@ export declare const setEsriConfig: (config: EsriConfig) => void;
45
45
  /**
46
46
  * Helper utility for logging messages in a consistent manner.
47
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
+ *
48
53
  * @see [setEsriConfig](#setEsriConfig)
49
54
  *
50
55
  * @example
@@ -62,6 +67,28 @@ export declare const setEsriConfig: (config: EsriConfig) => void;
62
67
  * });
63
68
  */
64
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);
65
92
  type LogContextOrObject = Exclude<LogContext, string> | object;
66
93
  type InferPropertyType<T extends LogContextOrObject> = [object] extends [T] ? string : keyof T;
67
94
  /**
package/dist/log/index.js CHANGED
@@ -42,12 +42,22 @@ const log = (level, context, message, options) => {
42
42
  esriConfig?.log.interceptors?.forEach(
43
43
  (interceptor) => interceptor(level, contextString, message, memorySafeDetail)
44
44
  );
45
- console[level](`[${contextString}]`, message, memorySafeDetail);
45
+ console[level](`[${contextString}]: ${message}`, memorySafeDetail);
46
46
  } else {
47
47
  esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
48
- console[level](`[${contextString}]`, message);
48
+ console[level](`[${contextString}]: ${message}`);
49
49
  }
50
50
  };
51
+ const rethrowError = (context) => {
52
+ const prefix = `[${getContextString(context)}] `;
53
+ return (error) => {
54
+ const errorToRethrow = error instanceof Error && error.message ? error : new Error(String(error));
55
+ errorToRethrow.message = `${prefix}${errorToRethrow.message}`;
56
+ setTimeout(() => {
57
+ throw error;
58
+ });
59
+ };
60
+ };
51
61
  const composeMissingPropertyMessage = (property) => (
52
62
  //#endregion composeMissingPropertyMessage
53
63
  `The property \`${property.toString()}\` is required but missing.`
@@ -65,5 +75,6 @@ export {
65
75
  composeMissingPropertyMessage,
66
76
  log,
67
77
  logDeprecatedProperty,
78
+ rethrowError,
68
79
  setEsriConfig
69
80
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/toolkit",
3
- "version": "5.0.0-next.94",
3
+ "version": "5.0.0-next.96",
4
4
  "description": "Collection of common internal patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
5
5
  "homepage": "https://developers.arcgis.com/javascript/latest/",
6
6
  "sideEffects": false,