@interopio/iocd-cli 0.0.70 → 0.0.71
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/changelog.md +7 -0
- package/dist/utils/deep.merge.js +102 -4
- package/dist/utils/deep.merge.js.map +1 -1
- package/package.json +1 -1
package/changelog.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.0.71](https://github.com/InteropIO/iocd-cli/compare/iocd-cli-v0.0.70...iocd-cli-v0.0.71) (2026-01-29)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add array merge directives for .json.merge files ([#27](https://github.com/InteropIO/iocd-cli/issues/27)) ([7b86d55](https://github.com/InteropIO/iocd-cli/commit/7b86d55b9a695e1a975d720b511b8f68b637a81e))
|
|
14
|
+
|
|
8
15
|
## [0.0.70](https://github.com/InteropIO/iocd-cli/compare/iocd-cli-v0.0.69...iocd-cli-v0.0.70) (2026-01-27)
|
|
9
16
|
|
|
10
17
|
|
package/dist/utils/deep.merge.js
CHANGED
|
@@ -1,25 +1,123 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deepMerge = deepMerge;
|
|
4
|
+
/**
|
|
5
|
+
* Array merge directive keys
|
|
6
|
+
*/
|
|
7
|
+
const ARRAY_DIRECTIVES = [
|
|
8
|
+
"$replace",
|
|
9
|
+
"$prepend",
|
|
10
|
+
"$append",
|
|
11
|
+
"$remove",
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Check if an object is an array directive object
|
|
15
|
+
* e.g., { "$replace": [...] } or { "$prepend": [...] }
|
|
16
|
+
*/
|
|
17
|
+
function isArrayDirective(obj) {
|
|
18
|
+
if (!isObject(obj))
|
|
19
|
+
return null;
|
|
20
|
+
const keys = Object.keys(obj);
|
|
21
|
+
if (keys.length !== 1)
|
|
22
|
+
return null;
|
|
23
|
+
const key = keys[0];
|
|
24
|
+
if (ARRAY_DIRECTIVES.includes(key) && Array.isArray(obj[key])) {
|
|
25
|
+
return { directive: key, value: obj[key] };
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Merge arrays based on directive or default behavior (concatenate)
|
|
31
|
+
*/
|
|
32
|
+
function mergeArrays(targetArray, sourceArray) {
|
|
33
|
+
// If source is a directive object
|
|
34
|
+
if (!Array.isArray(sourceArray)) {
|
|
35
|
+
const { directive, value } = sourceArray;
|
|
36
|
+
switch (directive) {
|
|
37
|
+
case "$replace":
|
|
38
|
+
return value;
|
|
39
|
+
case "$prepend":
|
|
40
|
+
return [...value, ...targetArray];
|
|
41
|
+
case "$append":
|
|
42
|
+
return [...targetArray, ...value];
|
|
43
|
+
case "$remove":
|
|
44
|
+
return targetArray.filter(item => {
|
|
45
|
+
// For primitives, use direct comparison
|
|
46
|
+
// For objects, use JSON stringify comparison
|
|
47
|
+
return !value.some(removeItem => typeof item === "object"
|
|
48
|
+
? JSON.stringify(item) === JSON.stringify(removeItem)
|
|
49
|
+
: item === removeItem);
|
|
50
|
+
});
|
|
51
|
+
default:
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Default behavior: concatenate arrays
|
|
56
|
+
return [...targetArray, ...sourceArray];
|
|
57
|
+
}
|
|
4
58
|
/**
|
|
5
59
|
* Deep merge two objects
|
|
60
|
+
*
|
|
61
|
+
* Arrays are concatenated by default. Use directive objects to control array merge behavior:
|
|
62
|
+
* - `{ "$replace": [...] }` - Replace the array entirely
|
|
63
|
+
* - `{ "$prepend": [...] }` - Add items to the beginning
|
|
64
|
+
* - `{ "$append": [...] }` - Add items to the end (explicit version of default)
|
|
65
|
+
* - `{ "$remove": [...] }` - Remove matching items from the array
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Default: concatenate
|
|
69
|
+
* deepMerge({ items: [1, 2] }, { items: [3, 4] })
|
|
70
|
+
* // Result: { items: [1, 2, 3, 4] }
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* // Replace array
|
|
74
|
+
* deepMerge({ items: [1, 2] }, { items: { "$replace": [3, 4] } })
|
|
75
|
+
* // Result: { items: [3, 4] }
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Prepend to array
|
|
79
|
+
* deepMerge({ items: [1, 2] }, { items: { "$prepend": [0] } })
|
|
80
|
+
* // Result: { items: [0, 1, 2] }
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Remove from array
|
|
84
|
+
* deepMerge({ items: [1, 2, 3] }, { items: { "$remove": [2] } })
|
|
85
|
+
* // Result: { items: [1, 3] }
|
|
6
86
|
*/
|
|
7
87
|
function deepMerge(target, source) {
|
|
8
88
|
const result = { ...target };
|
|
9
89
|
for (const key in source) {
|
|
10
90
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
11
|
-
|
|
12
|
-
|
|
91
|
+
const sourceValue = source[key];
|
|
92
|
+
const targetValue = result[key];
|
|
93
|
+
// Check if source is an array directive
|
|
94
|
+
const directive = isArrayDirective(sourceValue);
|
|
95
|
+
if (directive && Array.isArray(targetValue)) {
|
|
96
|
+
// Apply array directive to existing array
|
|
97
|
+
result[key] = mergeArrays(targetValue, directive);
|
|
98
|
+
}
|
|
99
|
+
else if (directive && !Array.isArray(targetValue)) {
|
|
100
|
+
// Directive but no target array - use directive value directly
|
|
101
|
+
result[key] = directive.value;
|
|
102
|
+
}
|
|
103
|
+
else if (Array.isArray(sourceValue) && Array.isArray(targetValue)) {
|
|
104
|
+
// Both are arrays - concatenate by default
|
|
105
|
+
result[key] = mergeArrays(targetValue, sourceValue);
|
|
106
|
+
}
|
|
107
|
+
else if (isObject(sourceValue) && isObject(targetValue)) {
|
|
108
|
+
// Both are objects - deep merge
|
|
109
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
13
110
|
}
|
|
14
111
|
else {
|
|
15
|
-
|
|
112
|
+
// Primitives or type mismatch - replace
|
|
113
|
+
result[key] = sourceValue;
|
|
16
114
|
}
|
|
17
115
|
}
|
|
18
116
|
}
|
|
19
117
|
return result;
|
|
20
118
|
}
|
|
21
119
|
/**
|
|
22
|
-
* Check if a value is a plain object
|
|
120
|
+
* Check if a value is a plain object (not null, not array)
|
|
23
121
|
*/
|
|
24
122
|
function isObject(obj) {
|
|
25
123
|
return obj !== null && typeof obj === "object" && !Array.isArray(obj);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep.merge.js","sourceRoot":"","sources":["../../src/utils/deep.merge.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"deep.merge.js","sourceRoot":"","sources":["../../src/utils/deep.merge.ts"],"names":[],"mappings":";;AAiGA,8BA+BC;AAhID;;GAEG;AACH,MAAM,gBAAgB,GAAG;IACvB,UAAU;IACV,UAAU;IACV,SAAS;IACT,SAAS;CACD,CAAC;AAGX;;;GAGG;AACH,SAAS,gBAAgB,CACvB,GAAQ;IAER,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEhC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEnC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAmB,CAAC;IACtC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,KA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