@speclynx/apidom-overlay 5.1.0 → 5.2.1
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 +25 -0
- package/README.md +4 -3
- package/dist/apidom-overlay.browser.js +2038 -346
- package/dist/apidom-overlay.browser.min.js +1 -1
- package/package.json +8 -8
- package/src/apply/realms/apidom.cjs +144 -30
- package/src/apply/realms/apidom.mjs +145 -31
- package/src/apply/realms/pojo.cjs +14 -2
- package/src/apply/realms/pojo.mjs +14 -2
- package/src/apply/realms/uri.cjs +5 -2
- package/src/apply/realms/uri.mjs +5 -2
- package/src/diff/realms/apidom.cjs +7 -3
- package/src/diff/realms/apidom.mjs +8 -4
- package/types/apidom-overlay.d.ts +29 -4
|
@@ -5,13 +5,25 @@ import { applyAction as applyActionApiDOM, applyOverlay as applyOverlayApiDOM }
|
|
|
5
5
|
/**
|
|
6
6
|
* Applies a single overlay action (POJO) to a target (POJO).
|
|
7
7
|
*
|
|
8
|
+
* The refracted target never escapes this function and the result is converted
|
|
9
|
+
* straight back to a POJO, so it is applied in place.
|
|
10
|
+
*
|
|
8
11
|
* @public
|
|
9
12
|
*/
|
|
10
|
-
export const applyAction = (action, target, options) => toValue(applyActionApiDOM(refractAction(action), refract(target),
|
|
13
|
+
export const applyAction = (action, target, options) => toValue(applyActionApiDOM(refractAction(action), refract(target), {
|
|
14
|
+
...options,
|
|
15
|
+
immutable: false
|
|
16
|
+
}));
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* Applies an entire overlay document (POJO) to a target (POJO).
|
|
14
20
|
*
|
|
21
|
+
* The refracted target never escapes this function and the result is converted
|
|
22
|
+
* straight back to a POJO, so it is applied in place.
|
|
23
|
+
*
|
|
15
24
|
* @public
|
|
16
25
|
*/
|
|
17
|
-
export const applyOverlay = (overlay, target, options) => toValue(applyOverlayApiDOM(refractOverlay1(overlay), refract(target),
|
|
26
|
+
export const applyOverlay = (overlay, target, options) => toValue(applyOverlayApiDOM(refractOverlay1(overlay), refract(target), {
|
|
27
|
+
...options,
|
|
28
|
+
immutable: false
|
|
29
|
+
}));
|
package/src/apply/realms/uri.cjs
CHANGED
|
@@ -81,7 +81,10 @@ const applyOverlay = async (overlayURI, targetURI, options = defaultOptions) =>
|
|
|
81
81
|
throw new _OverlayError.default('No target specified: provide targetURI or set the "extends" field in the overlay document');
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
// apply overlay actions to the target (
|
|
85
|
-
return (0, _apidom.applyOverlay)(overlayParseResult, targetParseResult,
|
|
84
|
+
// apply overlay actions to the target (mutable by default: targetParseResult with result replaced)
|
|
85
|
+
return (0, _apidom.applyOverlay)(overlayParseResult, targetParseResult, {
|
|
86
|
+
...options,
|
|
87
|
+
immutable: options.immutable ?? defaultOptions.immutable
|
|
88
|
+
});
|
|
86
89
|
};
|
|
87
90
|
var _default = exports.default = applyOverlay;
|
package/src/apply/realms/uri.mjs
CHANGED
|
@@ -73,7 +73,10 @@ const applyOverlay = async (overlayURI, targetURI, options = defaultOptions) =>
|
|
|
73
73
|
throw new OverlayError('No target specified: provide targetURI or set the "extends" field in the overlay document');
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
// apply overlay actions to the target (
|
|
77
|
-
return applyOverlayApiDOM(overlayParseResult, targetParseResult,
|
|
76
|
+
// apply overlay actions to the target (mutable by default: targetParseResult with result replaced)
|
|
77
|
+
return applyOverlayApiDOM(overlayParseResult, targetParseResult, {
|
|
78
|
+
...options,
|
|
79
|
+
immutable: options.immutable ?? defaultOptions.immutable
|
|
80
|
+
});
|
|
78
81
|
};
|
|
79
82
|
export default applyOverlay;
|
|
@@ -23,7 +23,13 @@ const defaultDiffOptions = {
|
|
|
23
23
|
const createUpdateAction = (segments, value) => {
|
|
24
24
|
const action = new _apidomNsOverlay.ActionElement();
|
|
25
25
|
action.target = new _apidomDatamodel.StringElement(_apidomJsonPath.NormalizedPath.from(segments));
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Every update value is built from nodes of the right document. Cloning here
|
|
28
|
+
* keeps the emitted overlay independent of the right document in both
|
|
29
|
+
* directions, and keeps two overlays diffed against the same right document
|
|
30
|
+
* from sharing element instances with each other.
|
|
31
|
+
*/
|
|
32
|
+
action.update = (0, _apidomDatamodel.cloneDeep)(value);
|
|
27
33
|
return action;
|
|
28
34
|
};
|
|
29
35
|
const createRemoveAction = segments => {
|
|
@@ -146,8 +152,6 @@ const diffArrays = (left, right, segments, actions) => {
|
|
|
146
152
|
* - Array items with a structural type change are handled via tail-reconstruct
|
|
147
153
|
* (remove tail + re-append from right), producing more actions than a minimal diff.
|
|
148
154
|
* - The overlay carries no "before" value, so it cannot be reversed without the original document.
|
|
149
|
-
* - Action `update` values reference elements from `rightElement` directly. Mutating `rightElement`
|
|
150
|
-
* after calling `diff` will affect the returned overlay.
|
|
151
155
|
*
|
|
152
156
|
* @public
|
|
153
157
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectElement, ArrayElement, StringElement, BooleanElement, isObjectElement, isArrayElement } from '@speclynx/apidom-datamodel';
|
|
1
|
+
import { ObjectElement, ArrayElement, StringElement, BooleanElement, isObjectElement, isArrayElement, cloneDeep } from '@speclynx/apidom-datamodel';
|
|
2
2
|
import { NormalizedPath } from '@speclynx/apidom-json-path';
|
|
3
3
|
import { ActionElement, Overlay1Element, InfoElement, OverlayElement, ActionsElement } from '@speclynx/apidom-ns-overlay-1';
|
|
4
4
|
import OverlayError from "../../errors/OverlayError.mjs";
|
|
@@ -15,7 +15,13 @@ const defaultDiffOptions = {
|
|
|
15
15
|
const createUpdateAction = (segments, value) => {
|
|
16
16
|
const action = new ActionElement();
|
|
17
17
|
action.target = new StringElement(NormalizedPath.from(segments));
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Every update value is built from nodes of the right document. Cloning here
|
|
20
|
+
* keeps the emitted overlay independent of the right document in both
|
|
21
|
+
* directions, and keeps two overlays diffed against the same right document
|
|
22
|
+
* from sharing element instances with each other.
|
|
23
|
+
*/
|
|
24
|
+
action.update = cloneDeep(value);
|
|
19
25
|
return action;
|
|
20
26
|
};
|
|
21
27
|
const createRemoveAction = segments => {
|
|
@@ -138,8 +144,6 @@ const diffArrays = (left, right, segments, actions) => {
|
|
|
138
144
|
* - Array items with a structural type change are handled via tail-reconstruct
|
|
139
145
|
* (remove tail + re-append from right), producing more actions than a minimal diff.
|
|
140
146
|
* - The overlay carries no "before" value, so it cannot be reversed without the original document.
|
|
141
|
-
* - Action `update` values reference elements from `rightElement` directly. Mutating `rightElement`
|
|
142
|
-
* after calling `diff` will affect the returned overlay.
|
|
143
147
|
*
|
|
144
148
|
* @public
|
|
145
149
|
*/
|
|
@@ -29,7 +29,13 @@ export declare type ActionTraceType = 'update' | 'copy' | 'remove' | 'noop';
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Applies a single overlay action to a target element.
|
|
32
|
-
*
|
|
32
|
+
*
|
|
33
|
+
* Immutable by default. The target is cloned once up front and the action is
|
|
34
|
+
* applied to the clone, so the returned element is always independent of the
|
|
35
|
+
* input, including when the action changes nothing. Pass `immutable: false` to
|
|
36
|
+
* apply the action in place; the one shape that cannot be applied in place is
|
|
37
|
+
* a `target: $` action replacing a primitive root with a differently typed
|
|
38
|
+
* value, so the return value is authoritative in both modes.
|
|
33
39
|
*
|
|
34
40
|
* @public
|
|
35
41
|
*/
|
|
@@ -38,6 +44,9 @@ export declare const applyActionApiDOM: (actionElement: ActionElement, targetEle
|
|
|
38
44
|
/**
|
|
39
45
|
* Applies a single overlay action (POJO) to a target (POJO).
|
|
40
46
|
*
|
|
47
|
+
* The refracted target never escapes this function and the result is converted
|
|
48
|
+
* straight back to a POJO, so it is applied in place.
|
|
49
|
+
*
|
|
41
50
|
* @public
|
|
42
51
|
*/
|
|
43
52
|
export declare const applyActionPOJO: (action: Record<string, unknown>, target: Record<string, unknown>, options?: ApplyOptions) => unknown;
|
|
@@ -70,7 +79,22 @@ export declare const applyOverlay: (overlayURI: string, targetURI?: string, opti
|
|
|
70
79
|
|
|
71
80
|
/**
|
|
72
81
|
* Applies an entire overlay document to a target element.
|
|
73
|
-
*
|
|
82
|
+
*
|
|
83
|
+
* Immutable by default. The target is cloned once up front and all actions are
|
|
84
|
+
* applied to the clone sequentially, so the returned element is always
|
|
85
|
+
* independent of the input, including when no action changes anything. Pass
|
|
86
|
+
* `immutable: false` to apply the actions in place; the one shape that cannot
|
|
87
|
+
* be applied in place is a `target: $` action replacing a primitive root with
|
|
88
|
+
* a differently typed value, so the return value is authoritative in both
|
|
89
|
+
* modes.
|
|
90
|
+
*
|
|
91
|
+
* When the target is a `ParseResultElement`, a new parse result is returned
|
|
92
|
+
* carrying the new tree as its result element; the caller's parse result and
|
|
93
|
+
* its result element are left untouched. Every other child — annotations, and
|
|
94
|
+
* an `api` element that is not the result element itself — is shared with the
|
|
95
|
+
* input rather than copied, since no overlay action can reach it.
|
|
96
|
+
* Under `immutable: false` the caller's parse result is updated in place
|
|
97
|
+
* instead, with its result element replaced by the new tree.
|
|
74
98
|
*
|
|
75
99
|
* @public
|
|
76
100
|
*/
|
|
@@ -86,6 +110,9 @@ export declare interface ApplyOverlayOptions extends ApplyOptions {
|
|
|
86
110
|
/**
|
|
87
111
|
* Applies an entire overlay document (POJO) to a target (POJO).
|
|
88
112
|
*
|
|
113
|
+
* The refracted target never escapes this function and the result is converted
|
|
114
|
+
* straight back to a POJO, so it is applied in place.
|
|
115
|
+
*
|
|
89
116
|
* @public
|
|
90
117
|
*/
|
|
91
118
|
export declare const applyOverlayPOJO: (overlay: Record<string, unknown>, target: Record<string, unknown>, options?: ApplyOptions) => unknown;
|
|
@@ -113,8 +140,6 @@ export declare const defaultDiffOverlayOptions: DiffOverlayOptions;
|
|
|
113
140
|
* - Array items with a structural type change are handled via tail-reconstruct
|
|
114
141
|
* (remove tail + re-append from right), producing more actions than a minimal diff.
|
|
115
142
|
* - The overlay carries no "before" value, so it cannot be reversed without the original document.
|
|
116
|
-
* - Action `update` values reference elements from `rightElement` directly. Mutating `rightElement`
|
|
117
|
-
* after calling `diff` will affect the returned overlay.
|
|
118
143
|
*
|
|
119
144
|
* @public
|
|
120
145
|
*/
|