@esri/hub-common 12.26.0 → 12.27.0

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.
@@ -10,4 +10,5 @@ export * from "./deep-string-replace";
10
10
  export * from "./merge-objects";
11
11
  export * from "./set-prop";
12
12
  export * from "./deepFind";
13
+ export * from "./resolveReferences";
13
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/objects/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/objects/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { _isDate, _isFunction, _isObject, _isRegExp } from ".";
2
+ import { cloneObject } from "../util";
3
+ import { getProp } from "./get-prop";
4
+ /**
5
+ * Resolve all $use references in an object graph.
6
+ * The $use syntax is relative to an entire object so
7
+ * the developer must ensure they resolve the references
8
+ * on the same graph they were defined on.
9
+ * Put another way, you can't resolve references on a subset
10
+ * of an object graph.
11
+ * @param obj
12
+ * @param ctx
13
+ * @returns
14
+ */
15
+ export function resolveReferences(obj, ctx) {
16
+ const keys = Object.keys(obj);
17
+ ctx = ctx || cloneObject(obj);
18
+ const newObject = keys.reduce(function (acc, currentKey) {
19
+ // if the value is an array, map over it
20
+ if (Array.isArray(obj[currentKey])) {
21
+ acc[currentKey] = obj[currentKey].map((entry) => {
22
+ return resolveReferences(entry, ctx);
23
+ });
24
+ }
25
+ // if the value is an object, resolve it's references
26
+ else if (obj[currentKey] &&
27
+ _isObject(obj[currentKey]) &&
28
+ !_isDate(obj[currentKey]) &&
29
+ !_isRegExp(obj[currentKey]) &&
30
+ !_isFunction(obj[currentKey])) {
31
+ // if the value is an object it may be a reference
32
+ if (obj[currentKey] && obj[currentKey].$use) {
33
+ // use getProp to resolve the reference
34
+ const useRef = getProp(ctx, obj[currentKey].$use);
35
+ if (_isObject(useRef)) {
36
+ // references could contain references, so resolve them
37
+ acc[currentKey] = resolveReferences(useRef, ctx);
38
+ }
39
+ else {
40
+ acc[currentKey] = useRef;
41
+ }
42
+ }
43
+ else {
44
+ acc[currentKey] = resolveReferences(obj[currentKey], ctx);
45
+ }
46
+ }
47
+ else {
48
+ // assign value
49
+ acc[currentKey] = obj[currentKey];
50
+ }
51
+ return acc;
52
+ }, {});
53
+ return newObject;
54
+ }
55
+ //# sourceMappingURL=resolveReferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveReferences.js","sourceRoot":"","sources":["../../../src/objects/resolveReferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;;;;;;;;;GAUG;AACH,MAAM,UAA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G,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,CAAC;aAC3D;SACF;aAAM;YACL,eAAe;YACf,GAAG,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;SACnC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CAAC,CAAC;IACJ,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -13,4 +13,5 @@ tslib_1.__exportStar(require("./deep-string-replace"), exports);
13
13
  tslib_1.__exportStar(require("./merge-objects"), exports);
14
14
  tslib_1.__exportStar(require("./set-prop"), exports);
15
15
  tslib_1.__exportStar(require("./deepFind"), exports);
16
+ tslib_1.__exportStar(require("./resolveReferences"), exports);
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/objects/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,wDAA8B;AAC9B,qDAA2B;AAC3B,wDAA8B;AAC9B,qDAA2B;AAC3B,sDAA4B;AAC5B,6DAAmC;AACnC,+DAAqC;AACrC,gEAAsC;AACtC,0DAAgC;AAChC,qDAA2B;AAC3B,qDAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/objects/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,wDAA8B;AAC9B,qDAA2B;AAC3B,wDAA8B;AAC9B,qDAA2B;AAC3B,sDAA4B;AAC5B,6DAAmC;AACnC,+DAAqC;AACrC,gEAAsC;AACtC,0DAAgC;AAChC,qDAA2B;AAC3B,qDAA2B;AAC3B,8DAAoC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveReferences = void 0;
4
+ const _1 = require(".");
5
+ const util_1 = require("../util");
6
+ const get_prop_1 = require("./get-prop");
7
+ /**
8
+ * Resolve all $use references in an object graph.
9
+ * The $use syntax is relative to an entire object so
10
+ * the developer must ensure they resolve the references
11
+ * on the same graph they were defined on.
12
+ * Put another way, you can't resolve references on a subset
13
+ * of an object graph.
14
+ * @param obj
15
+ * @param ctx
16
+ * @returns
17
+ */
18
+ function resolveReferences(obj, ctx) {
19
+ const keys = Object.keys(obj);
20
+ ctx = ctx || util_1.cloneObject(obj);
21
+ const newObject = keys.reduce(function (acc, currentKey) {
22
+ // if the value is an array, map over it
23
+ if (Array.isArray(obj[currentKey])) {
24
+ acc[currentKey] = obj[currentKey].map((entry) => {
25
+ return resolveReferences(entry, ctx);
26
+ });
27
+ }
28
+ // if the value is an object, resolve it's references
29
+ else if (obj[currentKey] &&
30
+ _1._isObject(obj[currentKey]) &&
31
+ !_1._isDate(obj[currentKey]) &&
32
+ !_1._isRegExp(obj[currentKey]) &&
33
+ !_1._isFunction(obj[currentKey])) {
34
+ // if the value is an object it may be a reference
35
+ if (obj[currentKey] && obj[currentKey].$use) {
36
+ // use getProp to resolve the reference
37
+ const useRef = get_prop_1.getProp(ctx, obj[currentKey].$use);
38
+ if (_1._isObject(useRef)) {
39
+ // references could contain references, so resolve them
40
+ acc[currentKey] = resolveReferences(useRef, ctx);
41
+ }
42
+ else {
43
+ acc[currentKey] = useRef;
44
+ }
45
+ }
46
+ else {
47
+ acc[currentKey] = resolveReferences(obj[currentKey], ctx);
48
+ }
49
+ }
50
+ else {
51
+ // assign value
52
+ acc[currentKey] = obj[currentKey];
53
+ }
54
+ return acc;
55
+ }, {});
56
+ return newObject;
57
+ }
58
+ exports.resolveReferences = resolveReferences;
59
+ //# sourceMappingURL=resolveReferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveReferences.js","sourceRoot":"","sources":["../../../src/objects/resolveReferences.ts"],"names":[],"mappings":";;;AAAA,wBAA+D;AAC/D,kCAAsC;AAEtC,yCAAqC;AAErC;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAC/B,GAAwB,EACxB,GAAyB;IAEzB,MA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,CAAC,UAAU,CAAC,EAAE,GAAG,CAAC,CAAC;aAC3D;SACF;aAAM;YACL,eAAe;YACf,GAAG,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;SACnC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CAAC,CAAC;IACJ,OAAO,SAAS,CAAC;AACnB,CAAC;AA9CD,8CA8CC"}
@@ -10,3 +10,4 @@ export * from "./deep-string-replace";
10
10
  export * from "./merge-objects";
11
11
  export * from "./set-prop";
12
12
  export * from "./deepFind";
13
+ export * from "./resolveReferences";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Resolve all $use references in an object graph.
3
+ * The $use syntax is relative to an entire object so
4
+ * the developer must ensure they resolve the references
5
+ * on the same graph they were defined on.
6
+ * Put another way, you can't resolve references on a subset
7
+ * of an object graph.
8
+ * @param obj
9
+ * @param ctx
10
+ * @returns
11
+ */
12
+ export declare function resolveReferences(obj: Record<string, any>, ctx?: Record<string, any>): Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esri/hub-common",
3
- "version": "12.26.0",
3
+ "version": "12.27.0",
4
4
  "description": "Common TypeScript types and utility functions for @esri/hub.js.",
5
5
  "main": "dist/node/index.js",
6
6
  "module": "dist/esm/index.js",