@adobe/acc-js-sdk 1.1.42 → 1.1.43

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.
@@ -2,6 +2,15 @@
2
2
  layout: page
3
3
  title: Change Log
4
4
  ---
5
+ <section class="changelog"><h1>Version 1.1.43</h1>
6
+ <h2>2023/12/21</h2>
7
+ <li>
8
+ Do not throw an error in case of duplicate enumeration value. Use the last one instead. This introduces a small behavior change
9
+ because this was causing an exception before.
10
+ </li>
11
+ </section>
12
+
13
+
5
14
  <section class="changelog"><h1>Version 1.1.42</h1>
6
15
  <h2>2023/12/20</h2>
7
16
  <li>
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.42",
3
+ "version": "1.1.43",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@adobe/acc-js-sdk",
9
- "version": "1.1.42",
9
+ "version": "1.1.43",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "axios": "^1.2.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.42",
3
+ "version": "1.1.43",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",
package/src/util.js CHANGED
@@ -196,13 +196,17 @@ class ArrayMap {
196
196
 
197
197
  _push(key, value, withoutIndexing) {
198
198
  let isNumKey = false;
199
+ let updateIndex = -1;
200
+
199
201
  if (key) {
200
202
  // reserved keyworkds
201
203
  const isReserved = key === "_items" || key === "length" || key === "_push" || key === "forEach" || key === "map" || key === "_map" || key === "get" || key === "find" || key === "flatMap" || key === "filter";
202
204
 
203
205
  // already a child with the name => there's a problem with the schema
204
- if (!isReserved && this[key])
205
- throw new Error(`Failed to add element '${key}' to ArrayMap. There's already an item with the same name`);
206
+ // it seems the current behavior is to replace the existing item with the new one
207
+ if (!isReserved && this[key]) {
208
+ updateIndex = this._items.indexOf(this[key]);
209
+ }
206
210
 
207
211
  // Set key as a enumerable property, so that elements can be accessed by key,
208
212
  // but also iterated on with a for ... in loop
@@ -222,14 +226,19 @@ class ArrayMap {
222
226
  if (!withoutIndexing && !isNumKey) {
223
227
  // Set the index property so that items can be accessed by array index.
224
228
  // However, make it non-enumerable to make sure indexes do not show up in a for .. in loop
225
- Object.defineProperty(this, this._items.length, {
229
+ const numKey = updateIndex == -1 ? this._items.length : updateIndex;
230
+ Object.defineProperty(this, numKey, {
226
231
  value: value,
227
232
  writable: false,
228
233
  enumerable: false,
234
+ configurable: true, // Allow to redefine the property later in case there's a duplicate key
229
235
  });
230
236
  }
231
237
  // Add to array and set length
232
- this._items.push(value);
238
+ if (updateIndex == -1)
239
+ this._items.push(value);
240
+ else
241
+ this._items[updateIndex] = value;
233
242
  this.length = this._items.length;
234
243
  }
235
244
 
@@ -45,13 +45,37 @@ describe('Application', () => {
45
45
  });
46
46
 
47
47
  it("Duplicate root nodes", () => {
48
- expect(() => {
49
- var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
50
- <element name='recipient' label='Recipients'/>
51
- <element name='recipient' label='Recipients2'/>
52
- </schema>`);
53
- newSchema(xml);
54
- }).toThrow("Failed to add element 'recipient' to ArrayMap. There's already an item with the same name");
48
+ var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
49
+ <element name='recipient' label='Recipients'/>
50
+ <element name='recipient' label='Recipients2'/>
51
+ </schema>`);
52
+ var schema = newSchema(xml);
53
+ var root = schema.root;
54
+ expect(root).toBeTruthy();
55
+ expect(root.name).toBe("recipient");
56
+ expect(root.label).toBe("Recipients2");
57
+ });
58
+
59
+ it("Duplicate enumeration value", () => {
60
+ const xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
61
+ <enumeration basetype="string" name="AKA">
62
+ <value name="PC" value="1"/>
63
+ <value name="CL2" value="2"/>
64
+ <value name="CL3" value="3"/>
65
+ <value name="Null" value="4"/>
66
+ <value name="Null" value="NULL"/>
67
+ </enumeration>
68
+ <element name='recipient' label='Recipients'/>
69
+ </schema>`);
70
+ const schema = newSchema(xml);
71
+ const enumerations = schema.enumerations;
72
+ const enumeration = enumerations.AKA.values;
73
+ expect(enumeration.length).toBe(4);
74
+ expect(enumeration[0].name).toBe("PC");
75
+ expect(enumeration[1].name).toBe("CL2");
76
+ expect(enumeration[2].name).toBe("CL3");
77
+ expect(enumeration[3].name).toBe("Null");
78
+ expect(enumeration[3].value).toBe("NULL");
55
79
  });
56
80
 
57
81
  it("Should find root node", () => {
package/test/util.test.js CHANGED
@@ -371,10 +371,26 @@ describe('Util', function() {
371
371
  expect(cat).toBe("012");
372
372
  });
373
373
 
374
- it("Should not support adding the same key twice", () => {
374
+ it("Should support adding the same key twice. The last value overwrites", () => {
375
375
  const am = new ArrayMap();
376
376
  am._push("hello", "Hello");
377
- expect(() => { am._push("hello", "World"); }).toThrow("Failed to add element 'hello' to ArrayMap. There's already an item with the same name");
377
+ expect(am.length).toBe(1);
378
+ am._push("hello", "World");
379
+ expect(am.length).toBe(1);
380
+ expect(am.get(0)).toBe("World");
381
+ });
382
+
383
+ it("Should support adding the same key twice. The last value overwrites in the middle of the array", () => {
384
+ const am = new ArrayMap();
385
+ am._push("hello", "Hello");
386
+ am._push("cruel", "Cruel");
387
+ am._push("world", "World");
388
+ expect(am.length).toBe(3);
389
+ am._push("cruel", "*cruel*");
390
+ expect(am.length).toBe(3);
391
+ expect(am.get(0)).toBe("Hello");
392
+ expect(am.get(1)).toBe("*cruel*");
393
+ expect(am.get(2)).toBe("World");
378
394
  });
379
395
 
380
396
  it("Should support missing names", () => {