@arcgis/toolkit 5.0.0-next.3 → 5.0.0-next.30

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.
@@ -0,0 +1,47 @@
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
+ esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
30
+ console[level](`[${contextString}]`, message);
31
+ };
32
+ const logIfMissingProperty = (level, context, property, options) => {
33
+ const value = context[property];
34
+ if (Array.isArray(value) && !value.length) {
35
+ return log(level, context, `The \`${property.toString()}\` property must have at least one element.`, options);
36
+ } else if (value == null) {
37
+ return log(level, context, `The \`${property.toString()}\` property is required but missing.`, options);
38
+ }
39
+ };
40
+ const logDeprecatedProperty = (context, oldName, newName, options) => (
41
+ //#endregion logDeprecatedProperty
42
+ log("warn", context, `\`${oldName.toString()}\` is deprecated. Use \`${newName.toString()}\` instead.`, options)
43
+ );
44
+ exports.log = log;
45
+ exports.logDeprecatedProperty = logDeprecatedProperty;
46
+ exports.logIfMissingProperty = logIfMissingProperty;
47
+ exports.setEsriConfig = setEsriConfig;
@@ -0,0 +1,79 @@
1
+ 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
+ type ErrorContext = AccessorLike | CustomElementLike | string;
13
+ export type Logger = (level: LogLevel, context: ErrorContext, message: unknown, options: LoggerOptions) => void;
14
+ type LoggerOptions = {
15
+ /** Whether the message should only be logged once */
16
+ once?: boolean;
17
+ };
18
+ type EsriConfig = {
19
+ log: {
20
+ /**
21
+ * @link {https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#LogInterceptor}
22
+ */
23
+ interceptors?: ((level: LogLevel | "none", module: string, ...args: any[]) => void)[];
24
+ };
25
+ };
26
+ /**
27
+ * Workaround for setting {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#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}.
28
+ * @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
29
+ * @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
30
+ * @example
31
+ * ```ts
32
+ * // IMPORTANT: do this only in config.ts or another early-loaded module
33
+ * import esriConfig from "@arcgis/core/config.js";
34
+ * import { setEsriConfig } from "@arcgis/toolkit/log";
35
+ *
36
+ * setEsriConfig(esriConfig);
37
+ *
38
+ * // either here or in another file, you can add your interceptors
39
+ * // and they will be respected when log is called later on
40
+ * esriConfig.log.interceptors?.push(yourInterceptor);
41
+ * ```
42
+ */
43
+ export declare const setEsriConfig: (config: EsriConfig) => void;
44
+ /**
45
+ * Helper utility for logging messages in a consistent manner.
46
+ *
47
+ * @see [setEsriConfig](#setEsriConfig)
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * log("error", this, "message to log",
52
+ * {
53
+ * once: true, // only log this message once
54
+ * }
55
+ * );
56
+ * ```
57
+ */
58
+ export declare const log: Logger;
59
+ /**
60
+ * Logs a message if a required property of the given context object is nullish (or an empty array).
61
+ * @param property The missing property to check for
62
+ * @param params Parameters to forward to the logger
63
+ * @example
64
+ * ```ts
65
+ * logIfMissingProperty<typeof this>("warn", this, "items", { once: true });
66
+ * ```
67
+ */
68
+ export declare const logIfMissingProperty: <T extends ErrorContext>(level: LogLevel, context: T, property: keyof T, options: LoggerOptions) => ReturnType<typeof log>;
69
+ /**
70
+ * Logs a warning message for deprecated object properties.
71
+ * @example
72
+ * ```ts
73
+ * logDeprecatedProperty(this, "oldName", "newName", {
74
+ * once: true,
75
+ * });
76
+ * ```
77
+ */
78
+ export declare const logDeprecatedProperty: <T extends ErrorContext>(context: T, oldName: keyof T, newName: keyof T, options: LoggerOptions) => ReturnType<typeof log>;
79
+ export {};
@@ -0,0 +1,79 @@
1
+ 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
+ type ErrorContext = AccessorLike | CustomElementLike | string;
13
+ export type Logger = (level: LogLevel, context: ErrorContext, message: unknown, options: LoggerOptions) => void;
14
+ type LoggerOptions = {
15
+ /** Whether the message should only be logged once */
16
+ once?: boolean;
17
+ };
18
+ type EsriConfig = {
19
+ log: {
20
+ /**
21
+ * @link {https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#LogInterceptor}
22
+ */
23
+ interceptors?: ((level: LogLevel | "none", module: string, ...args: any[]) => void)[];
24
+ };
25
+ };
26
+ /**
27
+ * Workaround for setting {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#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}.
28
+ * @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
29
+ * @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
30
+ * @example
31
+ * ```ts
32
+ * // IMPORTANT: do this only in config.ts or another early-loaded module
33
+ * import esriConfig from "@arcgis/core/config.js";
34
+ * import { setEsriConfig } from "@arcgis/toolkit/log";
35
+ *
36
+ * setEsriConfig(esriConfig);
37
+ *
38
+ * // either here or in another file, you can add your interceptors
39
+ * // and they will be respected when log is called later on
40
+ * esriConfig.log.interceptors?.push(yourInterceptor);
41
+ * ```
42
+ */
43
+ export declare const setEsriConfig: (config: EsriConfig) => void;
44
+ /**
45
+ * Helper utility for logging messages in a consistent manner.
46
+ *
47
+ * @see [setEsriConfig](#setEsriConfig)
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * log("error", this, "message to log",
52
+ * {
53
+ * once: true, // only log this message once
54
+ * }
55
+ * );
56
+ * ```
57
+ */
58
+ export declare const log: Logger;
59
+ /**
60
+ * Logs a message if a required property of the given context object is nullish (or an empty array).
61
+ * @param property The missing property to check for
62
+ * @param params Parameters to forward to the logger
63
+ * @example
64
+ * ```ts
65
+ * logIfMissingProperty<typeof this>("warn", this, "items", { once: true });
66
+ * ```
67
+ */
68
+ export declare const logIfMissingProperty: <T extends ErrorContext>(level: LogLevel, context: T, property: keyof T, options: LoggerOptions) => ReturnType<typeof log>;
69
+ /**
70
+ * Logs a warning message for deprecated object properties.
71
+ * @example
72
+ * ```ts
73
+ * logDeprecatedProperty(this, "oldName", "newName", {
74
+ * once: true,
75
+ * });
76
+ * ```
77
+ */
78
+ export declare const logDeprecatedProperty: <T extends ErrorContext>(context: T, oldName: keyof T, newName: keyof T, options: LoggerOptions) => ReturnType<typeof log>;
79
+ export {};
@@ -0,0 +1,47 @@
1
+ const loggedMessages = /* @__PURE__ */ new Set();
2
+ let esriConfig;
3
+ const setEsriConfig = (config) => {
4
+ esriConfig = config;
5
+ };
6
+ const getContextString = (context) => {
7
+ if (typeof context === "string") {
8
+ return context;
9
+ }
10
+ if ("el" in context) {
11
+ return context.el.localName;
12
+ }
13
+ if ("localName" in context) {
14
+ return context.localName;
15
+ }
16
+ return context.declaredClass;
17
+ };
18
+ const log = (level, context, message, options) => {
19
+ const contextString = getContextString(context);
20
+ if (options.once) {
21
+ const key = `${level}${contextString}${message}`;
22
+ if (loggedMessages.has(key)) {
23
+ return;
24
+ }
25
+ loggedMessages.add(key);
26
+ }
27
+ esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
28
+ console[level](`[${contextString}]`, message);
29
+ };
30
+ const logIfMissingProperty = (level, context, property, options) => {
31
+ const value = context[property];
32
+ if (Array.isArray(value) && !value.length) {
33
+ return log(level, context, `The \`${property.toString()}\` property must have at least one element.`, options);
34
+ } else if (value == null) {
35
+ return log(level, context, `The \`${property.toString()}\` property is required but missing.`, options);
36
+ }
37
+ };
38
+ const logDeprecatedProperty = (context, oldName, newName, options) => (
39
+ //#endregion logDeprecatedProperty
40
+ log("warn", context, `\`${oldName.toString()}\` is deprecated. Use \`${newName.toString()}\` instead.`, options)
41
+ );
42
+ export {
43
+ log,
44
+ logDeprecatedProperty,
45
+ logIfMissingProperty,
46
+ setEsriConfig
47
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/toolkit",
3
- "version": "5.0.0-next.3",
3
+ "version": "5.0.0-next.30",
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,
@@ -31,6 +31,11 @@
31
31
  "import": "./dist/intl/index.js",
32
32
  "require": "./dist/intl/index.cjs"
33
33
  },
34
+ "./log": {
35
+ "types": "./dist/log/index.d.ts",
36
+ "import": "./dist/log/index.js",
37
+ "require": "./dist/log/index.cjs"
38
+ },
34
39
  "./number": {
35
40
  "types": "./dist/number/index.d.ts",
36
41
  "import": "./dist/number/index.js",