@arcgis/toolkit 5.0.0-next.9 → 5.0.0-next.90
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.
- package/dist/array/index.d.cts +1 -1
- package/dist/array/index.d.ts +1 -1
- package/dist/dom/index.d.cts +3 -3
- package/dist/dom/index.d.ts +3 -3
- package/dist/error/index.d.cts +2 -2
- package/dist/error/index.d.ts +2 -2
- package/dist/intl/index.d.cts +4 -4
- package/dist/intl/index.d.ts +4 -4
- package/dist/log/index.cjs +69 -0
- package/dist/log/index.d.cts +101 -0
- package/dist/log/index.d.ts +101 -0
- package/dist/log/index.js +69 -0
- package/dist/predicate/index.d.cts +1 -1
- package/dist/predicate/index.d.ts +1 -1
- package/dist/type/index.cjs +4 -0
- package/dist/type/index.d.cts +14 -0
- package/dist/type/index.d.ts +14 -0
- package/dist/type/index.js +4 -0
- package/package.json +9 -2
package/dist/array/index.d.cts
CHANGED
package/dist/array/index.d.ts
CHANGED
package/dist/dom/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { nil } from '../type';
|
|
2
|
-
export * from './slots';
|
|
1
|
+
import { nil } from '../type/index.ts';
|
|
2
|
+
export * from './slots.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Combine multiple class names into a single string.
|
|
5
5
|
*
|
|
@@ -76,7 +76,7 @@ export declare function unsafeGetCalciteModeName(el: HTMLElement): "dark" | "lig
|
|
|
76
76
|
* expected to respect what was set by the consumer.
|
|
77
77
|
*
|
|
78
78
|
* @remarks
|
|
79
|
-
* Prefer [useDirection()](https://
|
|
79
|
+
* Prefer [useDirection()](https://webgis.esri.com/references/lumina/controllers/useDirection)
|
|
80
80
|
* to ensure your component is responsive to direction changes.
|
|
81
81
|
*/
|
|
82
82
|
export declare const unsafeGetElementDirection: (el: HTMLElement) => "ltr" | "rtl";
|
package/dist/dom/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { nil } from '../type';
|
|
2
|
-
export * from './slots';
|
|
1
|
+
import { nil } from '../type/index.ts';
|
|
2
|
+
export * from './slots.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Combine multiple class names into a single string.
|
|
5
5
|
*
|
|
@@ -76,7 +76,7 @@ export declare function unsafeGetCalciteModeName(el: HTMLElement): "dark" | "lig
|
|
|
76
76
|
* expected to respect what was set by the consumer.
|
|
77
77
|
*
|
|
78
78
|
* @remarks
|
|
79
|
-
* Prefer [useDirection()](https://
|
|
79
|
+
* Prefer [useDirection()](https://webgis.esri.com/references/lumina/controllers/useDirection)
|
|
80
80
|
* to ensure your component is responsive to direction changes.
|
|
81
81
|
*/
|
|
82
82
|
export declare const unsafeGetElementDirection: (el: HTMLElement) => "ltr" | "rtl";
|
package/dist/error/index.d.cts
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
* - `process.env.NODE_ENV === "development"`
|
|
11
11
|
* - `process.env.NODE_ENV === "test"`
|
|
12
12
|
*
|
|
13
|
-
* [Documentation](https://
|
|
13
|
+
* [Documentation](https://webgis.esri.com/references/lumina/publishing#internal-esri-environment)
|
|
14
14
|
*
|
|
15
15
|
* @remarks
|
|
16
16
|
* This function is primary for usage in support packages. In Lumina component
|
|
17
17
|
* packages, simpler alternatives are provided:
|
|
18
|
-
* https://
|
|
18
|
+
* https://webgis.esri.com/references/lumina/publishing#bundling-code-conditionally
|
|
19
19
|
*/
|
|
20
20
|
export declare const isEsriInternalEnv: () => boolean;
|
|
21
21
|
/**
|
package/dist/error/index.d.ts
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
* - `process.env.NODE_ENV === "development"`
|
|
11
11
|
* - `process.env.NODE_ENV === "test"`
|
|
12
12
|
*
|
|
13
|
-
* [Documentation](https://
|
|
13
|
+
* [Documentation](https://webgis.esri.com/references/lumina/publishing#internal-esri-environment)
|
|
14
14
|
*
|
|
15
15
|
* @remarks
|
|
16
16
|
* This function is primary for usage in support packages. In Lumina component
|
|
17
17
|
* packages, simpler alternatives are provided:
|
|
18
|
-
* https://
|
|
18
|
+
* https://webgis.esri.com/references/lumina/publishing#bundling-code-conditionally
|
|
19
19
|
*/
|
|
20
20
|
export declare const isEsriInternalEnv: () => boolean;
|
|
21
21
|
/**
|
package/dist/intl/index.d.cts
CHANGED
|
@@ -23,7 +23,7 @@ export declare const defaultLocale = "en";
|
|
|
23
23
|
*
|
|
24
24
|
* @remarks
|
|
25
25
|
* Rather than using this function directly, prefer the
|
|
26
|
-
* [useT9n()](https://
|
|
26
|
+
* [useT9n()](https://webgis.esri.com/references/lumina/controllers/useT9n)
|
|
27
27
|
* controller.
|
|
28
28
|
*
|
|
29
29
|
* @remarks
|
|
@@ -39,7 +39,7 @@ export declare const defaultLocale = "en";
|
|
|
39
39
|
* );
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
|
-
* @see [Lumina asset handling](https://
|
|
42
|
+
* @see [Lumina asset handling](https://webgis.esri.com/references/lumina/assets)
|
|
43
43
|
*/
|
|
44
44
|
export declare const fetchT9nStringsBundle: <Strings extends GenericT9nStrings>(locale: string, assetsPath: string, prefix?: string) => Promise<Strings>;
|
|
45
45
|
/**
|
|
@@ -55,7 +55,7 @@ export interface GenericT9nStrings {
|
|
|
55
55
|
*
|
|
56
56
|
* @returns an object with the `lang` and `t9nLocale` properties.
|
|
57
57
|
*
|
|
58
|
-
* @see [lang vs t9nLocale](https://
|
|
58
|
+
* @see [lang vs t9nLocale](https://webgis.esri.com/references/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
|
|
59
59
|
*/
|
|
60
60
|
export declare const getElementLocale: (element: HTMLElement) => {
|
|
61
61
|
readonly lang: string;
|
|
@@ -103,7 +103,7 @@ export interface LocaleObserverResult<Strings extends GenericT9nStrings = Generi
|
|
|
103
103
|
*
|
|
104
104
|
* @remarks
|
|
105
105
|
* Rather than using this function directly, prefer the
|
|
106
|
-
* [useT9n()](https://
|
|
106
|
+
* [useT9n()](https://webgis.esri.com/references/lumina/controllers/useT9n)
|
|
107
107
|
* controller.
|
|
108
108
|
*
|
|
109
109
|
* @example
|
package/dist/intl/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare const defaultLocale = "en";
|
|
|
23
23
|
*
|
|
24
24
|
* @remarks
|
|
25
25
|
* Rather than using this function directly, prefer the
|
|
26
|
-
* [useT9n()](https://
|
|
26
|
+
* [useT9n()](https://webgis.esri.com/references/lumina/controllers/useT9n)
|
|
27
27
|
* controller.
|
|
28
28
|
*
|
|
29
29
|
* @remarks
|
|
@@ -39,7 +39,7 @@ export declare const defaultLocale = "en";
|
|
|
39
39
|
* );
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
|
-
* @see [Lumina asset handling](https://
|
|
42
|
+
* @see [Lumina asset handling](https://webgis.esri.com/references/lumina/assets)
|
|
43
43
|
*/
|
|
44
44
|
export declare const fetchT9nStringsBundle: <Strings extends GenericT9nStrings>(locale: string, assetsPath: string, prefix?: string) => Promise<Strings>;
|
|
45
45
|
/**
|
|
@@ -55,7 +55,7 @@ export interface GenericT9nStrings {
|
|
|
55
55
|
*
|
|
56
56
|
* @returns an object with the `lang` and `t9nLocale` properties.
|
|
57
57
|
*
|
|
58
|
-
* @see [lang vs t9nLocale](https://
|
|
58
|
+
* @see [lang vs t9nLocale](https://webgis.esri.com/references/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
|
|
59
59
|
*/
|
|
60
60
|
export declare const getElementLocale: (element: HTMLElement) => {
|
|
61
61
|
readonly lang: string;
|
|
@@ -103,7 +103,7 @@ export interface LocaleObserverResult<Strings extends GenericT9nStrings = Generi
|
|
|
103
103
|
*
|
|
104
104
|
* @remarks
|
|
105
105
|
* Rather than using this function directly, prefer the
|
|
106
|
-
* [useT9n()](https://
|
|
106
|
+
* [useT9n()](https://webgis.esri.com/references/lumina/controllers/useT9n)
|
|
107
107
|
* controller.
|
|
108
108
|
*
|
|
109
109
|
* @example
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
get() {
|
|
37
|
+
return weakRefValue.deref();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
memorySafeDetail[key] = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
esriConfig?.log.interceptors?.forEach(
|
|
45
|
+
(interceptor) => interceptor(level, contextString, message, memorySafeDetail)
|
|
46
|
+
);
|
|
47
|
+
console[level](`[${contextString}]`, message, memorySafeDetail);
|
|
48
|
+
} else {
|
|
49
|
+
esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
|
|
50
|
+
console[level](`[${contextString}]`, message);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const composeMissingPropertyMessage = (property) => (
|
|
54
|
+
//#endregion composeMissingPropertyMessage
|
|
55
|
+
`The property \`${property.toString()}\` is required but missing.`
|
|
56
|
+
);
|
|
57
|
+
const composeEmptyPropertyMessage = (property) => (
|
|
58
|
+
//#endregion composeEmptyPropertyMessage
|
|
59
|
+
`The property \`${property.toString()}\` is empty but must have at least one element.`
|
|
60
|
+
);
|
|
61
|
+
const logDeprecatedProperty = (context, oldName, newName, options) => (
|
|
62
|
+
//#endregion logDeprecatedProperty
|
|
63
|
+
log("warn", context, `\`${oldName.toString()}\` is deprecated. Use \`${newName.toString()}\` instead.`, options)
|
|
64
|
+
);
|
|
65
|
+
exports.composeEmptyPropertyMessage = composeEmptyPropertyMessage;
|
|
66
|
+
exports.composeMissingPropertyMessage = composeMissingPropertyMessage;
|
|
67
|
+
exports.log = log;
|
|
68
|
+
exports.logDeprecatedProperty = logDeprecatedProperty;
|
|
69
|
+
exports.setEsriConfig = setEsriConfig;
|
|
@@ -0,0 +1,101 @@
|
|
|
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/api-reference/esri-config.html#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/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}.
|
|
29
|
+
* @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
|
|
30
|
+
* @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
|
|
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
|
+
* @see [setEsriConfig](#setEsriConfig)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // Basic usage
|
|
53
|
+
* log("error", this, "message to log");
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Optional usage
|
|
59
|
+
* log("warn", this, "message to log", {
|
|
60
|
+
* once: true,
|
|
61
|
+
* detail: { object1, object2 }
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
64
|
+
export declare const log: (level: LogLevel, context: LogContext, message: string, options?: LogOptions) => void;
|
|
65
|
+
type LogContextOrObject = Exclude<LogContext, string> | object;
|
|
66
|
+
type InferPropertyType<T extends LogContextOrObject> = [object] extends [T] ? string : keyof T;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a string that can be used in log messages for missing required properties.
|
|
69
|
+
* @param property The name of the required property
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* // returns "The property `x` is required but missing."
|
|
73
|
+
* composeMissingPropertyMessage<YourClass>("x");
|
|
74
|
+
* // you don't need to provide a generic type argument if you don't have one
|
|
75
|
+
* composeMissingPropertyMessage("object.sub.property");
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare const composeMissingPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a string that can be used in log messages for empty required arrays.
|
|
81
|
+
* @param property The name of the required property
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* // returns "The property `x` is empty but must have at least one element."
|
|
85
|
+
* composeEmptyPropertyMessage<YourClass>("x");
|
|
86
|
+
* // you don't need to provide a generic type argument if you don't have one
|
|
87
|
+
* composeEmptyPropertyMessage("object.sub.property");
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare const composeEmptyPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
|
|
91
|
+
/**
|
|
92
|
+
* Logs a warning message for deprecated object properties.
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* logDeprecatedProperty(this, "oldName", "newName", {
|
|
96
|
+
* once: true,
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare const logDeprecatedProperty: <T extends LogContext>(context: T, oldName: keyof T, newName: keyof T, options?: LogOptions) => ReturnType<typeof log>;
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
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/api-reference/esri-config.html#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/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}.
|
|
29
|
+
* @see {@link https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/74935}
|
|
30
|
+
* @param config {@link https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html}
|
|
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
|
+
* @see [setEsriConfig](#setEsriConfig)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // Basic usage
|
|
53
|
+
* log("error", this, "message to log");
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Optional usage
|
|
59
|
+
* log("warn", this, "message to log", {
|
|
60
|
+
* once: true,
|
|
61
|
+
* detail: { object1, object2 }
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
64
|
+
export declare const log: (level: LogLevel, context: LogContext, message: string, options?: LogOptions) => void;
|
|
65
|
+
type LogContextOrObject = Exclude<LogContext, string> | object;
|
|
66
|
+
type InferPropertyType<T extends LogContextOrObject> = [object] extends [T] ? string : keyof T;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a string that can be used in log messages for missing required properties.
|
|
69
|
+
* @param property The name of the required property
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* // returns "The property `x` is required but missing."
|
|
73
|
+
* composeMissingPropertyMessage<YourClass>("x");
|
|
74
|
+
* // you don't need to provide a generic type argument if you don't have one
|
|
75
|
+
* composeMissingPropertyMessage("object.sub.property");
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare const composeMissingPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a string that can be used in log messages for empty required arrays.
|
|
81
|
+
* @param property The name of the required property
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* // returns "The property `x` is empty but must have at least one element."
|
|
85
|
+
* composeEmptyPropertyMessage<YourClass>("x");
|
|
86
|
+
* // you don't need to provide a generic type argument if you don't have one
|
|
87
|
+
* composeEmptyPropertyMessage("object.sub.property");
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare const composeEmptyPropertyMessage: <T extends LogContextOrObject = object>(property: InferPropertyType<T>) => string;
|
|
91
|
+
/**
|
|
92
|
+
* Logs a warning message for deprecated object properties.
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* logDeprecatedProperty(this, "oldName", "newName", {
|
|
96
|
+
* once: true,
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare const logDeprecatedProperty: <T extends LogContext>(context: T, oldName: keyof T, newName: keyof T, options?: LogOptions) => ReturnType<typeof log>;
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
let memorySafeDetail;
|
|
28
|
+
if (options?.detail) {
|
|
29
|
+
memorySafeDetail = {};
|
|
30
|
+
for (const [key, value] of Object.entries(options.detail)) {
|
|
31
|
+
if ((typeof value === "object" || typeof value === "function") && value !== null) {
|
|
32
|
+
const weakRefValue = new WeakRef(value);
|
|
33
|
+
Object.defineProperty(memorySafeDetail, key, {
|
|
34
|
+
get() {
|
|
35
|
+
return weakRefValue.deref();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
memorySafeDetail[key] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
esriConfig?.log.interceptors?.forEach(
|
|
43
|
+
(interceptor) => interceptor(level, contextString, message, memorySafeDetail)
|
|
44
|
+
);
|
|
45
|
+
console[level](`[${contextString}]`, message, memorySafeDetail);
|
|
46
|
+
} else {
|
|
47
|
+
esriConfig?.log.interceptors?.forEach((interceptor) => interceptor(level, contextString, message));
|
|
48
|
+
console[level](`[${contextString}]`, message);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const composeMissingPropertyMessage = (property) => (
|
|
52
|
+
//#endregion composeMissingPropertyMessage
|
|
53
|
+
`The property \`${property.toString()}\` is required but missing.`
|
|
54
|
+
);
|
|
55
|
+
const composeEmptyPropertyMessage = (property) => (
|
|
56
|
+
//#endregion composeEmptyPropertyMessage
|
|
57
|
+
`The property \`${property.toString()}\` is empty but must have at least one element.`
|
|
58
|
+
);
|
|
59
|
+
const logDeprecatedProperty = (context, oldName, newName, options) => (
|
|
60
|
+
//#endregion logDeprecatedProperty
|
|
61
|
+
log("warn", context, `\`${oldName.toString()}\` is deprecated. Use \`${newName.toString()}\` instead.`, options)
|
|
62
|
+
);
|
|
63
|
+
export {
|
|
64
|
+
composeEmptyPropertyMessage,
|
|
65
|
+
composeMissingPropertyMessage,
|
|
66
|
+
log,
|
|
67
|
+
logDeprecatedProperty,
|
|
68
|
+
setEsriConfig
|
|
69
|
+
};
|
package/dist/type/index.d.cts
CHANGED
|
@@ -13,3 +13,17 @@ export type IHandle = {
|
|
|
13
13
|
* @deprecated Import type { nil } from `@arcgis/toolkit/type` instead
|
|
14
14
|
*/
|
|
15
15
|
export type Nil = nil;
|
|
16
|
+
/**
|
|
17
|
+
* A helper for doing TypeScript type tests.
|
|
18
|
+
* This complements the TypeScript's `satisfies` operator.
|
|
19
|
+
*
|
|
20
|
+
* See usage examples:
|
|
21
|
+
* https://webgis.esri.com/webgis/additional-resources/typescript-tips#use-satisfies-operator-for-type-tests
|
|
22
|
+
*
|
|
23
|
+
* During production end-application build, such type tests will be removed as
|
|
24
|
+
* they have no runtime impact.
|
|
25
|
+
*
|
|
26
|
+
* @privateRemarks
|
|
27
|
+
* Using `0` over `undefined` to take fewer bytes if minifier is disabled.
|
|
28
|
+
*/
|
|
29
|
+
export declare const typeTest: unknown;
|
package/dist/type/index.d.ts
CHANGED
|
@@ -13,3 +13,17 @@ export type IHandle = {
|
|
|
13
13
|
* @deprecated Import type { nil } from `@arcgis/toolkit/type` instead
|
|
14
14
|
*/
|
|
15
15
|
export type Nil = nil;
|
|
16
|
+
/**
|
|
17
|
+
* A helper for doing TypeScript type tests.
|
|
18
|
+
* This complements the TypeScript's `satisfies` operator.
|
|
19
|
+
*
|
|
20
|
+
* See usage examples:
|
|
21
|
+
* https://webgis.esri.com/webgis/additional-resources/typescript-tips#use-satisfies-operator-for-type-tests
|
|
22
|
+
*
|
|
23
|
+
* During production end-application build, such type tests will be removed as
|
|
24
|
+
* they have no runtime impact.
|
|
25
|
+
*
|
|
26
|
+
* @privateRemarks
|
|
27
|
+
* Using `0` over `undefined` to take fewer bytes if minifier is disabled.
|
|
28
|
+
*/
|
|
29
|
+
export declare const typeTest: unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcgis/toolkit",
|
|
3
|
-
"version": "5.0.0-next.
|
|
3
|
+
"version": "5.0.0-next.90",
|
|
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",
|
|
@@ -52,7 +57,9 @@
|
|
|
52
57
|
"require": "./dist/string/index.cjs"
|
|
53
58
|
},
|
|
54
59
|
"./type": {
|
|
55
|
-
"types": "./dist/type/index.d.ts"
|
|
60
|
+
"types": "./dist/type/index.d.ts",
|
|
61
|
+
"import": "./dist/type/index.js",
|
|
62
|
+
"require": "./dist/type/index.cjs"
|
|
56
63
|
},
|
|
57
64
|
"./url": {
|
|
58
65
|
"types": "./dist/url/index.d.ts",
|