@speclynx/apidom-overlay 4.6.0 → 4.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speclynx/apidom-overlay",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "Apply Overlay 1.x.y documents to API definitions.",
5
5
  "keywords": [
6
6
  "apidom",
@@ -53,12 +53,13 @@
53
53
  "license": "Apache-2.0",
54
54
  "dependencies": {
55
55
  "@babel/runtime-corejs3": "^7.28.4",
56
- "@speclynx/apidom-core": "4.6.0",
57
- "@speclynx/apidom-datamodel": "4.6.0",
58
- "@speclynx/apidom-error": "4.6.0",
59
- "@speclynx/apidom-json-path": "4.6.0",
60
- "@speclynx/apidom-ns-overlay-1": "4.6.0",
61
- "@speclynx/apidom-reference": "4.6.0"
56
+ "@speclynx/apidom-core": "4.7.0",
57
+ "@speclynx/apidom-datamodel": "4.7.0",
58
+ "@speclynx/apidom-error": "4.7.0",
59
+ "@speclynx/apidom-json-path": "4.7.0",
60
+ "@speclynx/apidom-ns-overlay-1": "4.7.0",
61
+ "@speclynx/apidom-reference": "4.7.0",
62
+ "type-fest": "^5.5.0"
62
63
  },
63
64
  "files": [
64
65
  "src/**/*.mjs",
@@ -70,5 +71,5 @@
70
71
  "README.md",
71
72
  "CHANGELOG.md"
72
73
  ],
73
- "gitHead": "c3cec30492f0e186ffdc7b1a761a016dab98b9d4"
74
+ "gitHead": "5afe50e432d90185f514e91bb35319aa4e23ba7b"
74
75
  }
@@ -278,10 +278,10 @@ const applyOverlay = (overlayElement, targetElement, options = defaultApplyOptio
278
278
  }
279
279
  let target;
280
280
  if (targetElement instanceof _apidomDatamodel.ParseResultElement) {
281
- if (targetElement.api === undefined) {
282
- throw new _OverlayError.default('Target ParseResultElement contains no API element');
281
+ if (targetElement.result === undefined) {
282
+ throw new _OverlayError.default('Target ParseResultElement contains no result element');
283
283
  }
284
- target = targetElement.api;
284
+ target = targetElement.result;
285
285
  } else {
286
286
  target = targetElement;
287
287
  }
@@ -297,7 +297,9 @@ const applyOverlay = (overlayElement, targetElement, options = defaultApplyOptio
297
297
  target = applyAction(action, target, internalOptions);
298
298
  }
299
299
  if (targetElement instanceof _apidomDatamodel.ParseResultElement) {
300
- targetElement.replaceResult(target);
300
+ if (target !== targetElement.result) {
301
+ targetElement.replaceResult(target);
302
+ }
301
303
  return targetElement;
302
304
  }
303
305
  return target;
@@ -267,10 +267,10 @@ export const applyOverlay = (overlayElement, targetElement, options = defaultApp
267
267
  }
268
268
  let target;
269
269
  if (targetElement instanceof ParseResultElement) {
270
- if (targetElement.api === undefined) {
271
- throw new OverlayError('Target ParseResultElement contains no API element');
270
+ if (targetElement.result === undefined) {
271
+ throw new OverlayError('Target ParseResultElement contains no result element');
272
272
  }
273
- target = targetElement.api;
273
+ target = targetElement.result;
274
274
  } else {
275
275
  target = targetElement;
276
276
  }
@@ -286,7 +286,9 @@ export const applyOverlay = (overlayElement, targetElement, options = defaultApp
286
286
  target = applyAction(action, target, internalOptions);
287
287
  }
288
288
  if (targetElement instanceof ParseResultElement) {
289
- targetElement.replaceResult(target);
289
+ if (target !== targetElement.result) {
290
+ targetElement.replaceResult(target);
291
+ }
290
292
  return targetElement;
291
293
  }
292
294
  return target;
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
- exports.default = void 0;
5
+ exports.defaultOptions = exports.default = void 0;
6
6
  var _apidomDatamodel = require("@speclynx/apidom-datamodel");
7
7
  var _apidomNsOverlay = require("@speclynx/apidom-ns-overlay-1");
8
8
  var _apidomReference = require("@speclynx/apidom-reference");
@@ -12,7 +12,7 @@ var _OverlayError = _interopRequireDefault(require("../../errors/OverlayError.cj
12
12
  * @public
13
13
  */
14
14
 
15
- const defaultOptions = {
15
+ const defaultReferenceOptions = {
16
16
  parse: {
17
17
  parserOpts: {
18
18
  strict: false,
@@ -36,6 +36,15 @@ const defaultOptions = {
36
36
  }
37
37
  };
38
38
 
39
+ /**
40
+ * @public
41
+ */
42
+ const defaultOptions = exports.defaultOptions = {
43
+ immutable: false,
44
+ strict: false,
45
+ reference: defaultReferenceOptions
46
+ };
47
+
39
48
  /**
40
49
  * Applies an overlay document from a file/URL to its target document.
41
50
  *
@@ -45,27 +54,23 @@ const defaultOptions = {
45
54
  *
46
55
  * @param overlayURI - URI to the overlay document (file path or URL)
47
56
  * @param targetURI - URI to the target document; if omitted, uses the overlay's `extends` field
48
- * @param options - apidom-reference options + overlay merge options
57
+ * @param options - overlay apply options; reference options live under `options.reference`
49
58
  * @returns ParseResultElement with the modified target document
50
59
  *
51
60
  * @public
52
61
  */
53
- const applyOverlay = async (overlayURI, targetURI, options = {
54
- immutable: false,
55
- strict: false
56
- }) => {
57
- const mergedOptions = (0, _apidomReference.mergeOptions)(defaultOptions, options);
62
+ const applyOverlay = async (overlayURI, targetURI, options = defaultOptions) => {
63
+ const mergedRefOptions = (0, _apidomReference.mergeOptions)(defaultReferenceOptions, options.reference ?? {});
58
64
 
59
65
  // parse the overlay document along with document attached to `extends` field (if present)
60
- const overlayParseResult = await (0, _apidomReference.parse)(overlayURI, mergedOptions);
66
+ const overlayParseResult = await (0, _apidomReference.parse)(overlayURI, mergedRefOptions);
61
67
  const overlayElement = overlayParseResult.api;
62
68
  if (!(0, _apidomNsOverlay.isOverlay1Element)(overlayElement)) {
63
69
  throw new _OverlayError.default(`Failed to parse overlay document "${overlayURI}"`);
64
70
  }
65
71
  let targetParseResult;
66
72
  if (targetURI) {
67
- const targetOptions = (0, _apidomReference.mergeOptions)(defaultOptions, options);
68
- targetParseResult = await (0, _apidomReference.parse)(targetURI, targetOptions);
73
+ targetParseResult = await (0, _apidomReference.parse)(targetURI, mergedRefOptions);
69
74
  } else {
70
75
  const extendsElement = overlayElement.get('extends');
71
76
  targetParseResult = extendsElement?.meta?.get('parseResult');
@@ -6,7 +6,7 @@ import OverlayError from "../../errors/OverlayError.mjs";
6
6
  /**
7
7
  * @public
8
8
  */
9
- const defaultOptions = {
9
+ const defaultReferenceOptions = {
10
10
  parse: {
11
11
  parserOpts: {
12
12
  strict: false,
@@ -30,6 +30,15 @@ const defaultOptions = {
30
30
  }
31
31
  };
32
32
 
33
+ /**
34
+ * @public
35
+ */
36
+ export const defaultOptions = {
37
+ immutable: false,
38
+ strict: false,
39
+ reference: defaultReferenceOptions
40
+ };
41
+
33
42
  /**
34
43
  * Applies an overlay document from a file/URL to its target document.
35
44
  *
@@ -39,27 +48,23 @@ const defaultOptions = {
39
48
  *
40
49
  * @param overlayURI - URI to the overlay document (file path or URL)
41
50
  * @param targetURI - URI to the target document; if omitted, uses the overlay's `extends` field
42
- * @param options - apidom-reference options + overlay merge options
51
+ * @param options - overlay apply options; reference options live under `options.reference`
43
52
  * @returns ParseResultElement with the modified target document
44
53
  *
45
54
  * @public
46
55
  */
47
- const applyOverlay = async (overlayURI, targetURI, options = {
48
- immutable: false,
49
- strict: false
50
- }) => {
51
- const mergedOptions = mergeOptions(defaultOptions, options);
56
+ const applyOverlay = async (overlayURI, targetURI, options = defaultOptions) => {
57
+ const mergedRefOptions = mergeOptions(defaultReferenceOptions, options.reference ?? {});
52
58
 
53
59
  // parse the overlay document along with document attached to `extends` field (if present)
54
- const overlayParseResult = await parse(overlayURI, mergedOptions);
60
+ const overlayParseResult = await parse(overlayURI, mergedRefOptions);
55
61
  const overlayElement = overlayParseResult.api;
56
62
  if (!isOverlay1Element(overlayElement)) {
57
63
  throw new OverlayError(`Failed to parse overlay document "${overlayURI}"`);
58
64
  }
59
65
  let targetParseResult;
60
66
  if (targetURI) {
61
- const targetOptions = mergeOptions(defaultOptions, options);
62
- targetParseResult = await parse(targetURI, targetOptions);
67
+ targetParseResult = await parse(targetURI, mergedRefOptions);
63
68
  } else {
64
69
  const extendsElement = overlayElement.get('extends');
65
70
  targetParseResult = extendsElement?.meta?.get('parseResult');
package/src/index.cjs CHANGED
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
5
  exports.__esModule = true;
5
- exports.validateAction = exports.applyOverlayPOJO = exports.applyOverlayApiDOM = exports.applyOverlay = exports.applyActionPOJO = exports.applyActionApiDOM = exports.OverlayError = void 0;
6
+ exports.validateAction = exports.defaultApplyOverlayOptions = exports.applyOverlayPOJO = exports.applyOverlayApiDOM = exports.applyOverlay = exports.applyActionPOJO = exports.applyActionApiDOM = exports.OverlayError = void 0;
6
7
  var _apidom = require("./apply/realms/apidom.cjs");
7
8
  exports.applyActionApiDOM = _apidom.applyAction;
8
9
  exports.applyOverlayApiDOM = _apidom.applyOverlay;
9
- var _uri = _interopRequireDefault(require("./apply/realms/uri.cjs"));
10
+ var _uri = _interopRequireWildcard(require("./apply/realms/uri.cjs"));
10
11
  exports.applyOverlay = _uri.default;
12
+ exports.defaultApplyOverlayOptions = _uri.defaultOptions;
11
13
  var _pojo = require("./apply/realms/pojo.cjs");
12
14
  exports.applyActionPOJO = _pojo.applyAction;
13
15
  exports.applyOverlayPOJO = _pojo.applyOverlay;
package/src/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  export { applyAction as applyActionApiDOM, applyOverlay as applyOverlayApiDOM } from "./apply/realms/apidom.mjs";
2
- export { default as applyOverlay } from "./apply/realms/uri.mjs";
2
+ export { default as applyOverlay, defaultOptions as defaultApplyOverlayOptions } from "./apply/realms/uri.mjs";
3
3
  export { applyAction as applyActionPOJO, applyOverlay as applyOverlayPOJO } from "./apply/realms/pojo.mjs";
4
4
  export { validateAction } from "./validate.mjs";
5
5
  export { default as OverlayError } from "./errors/OverlayError.mjs";
@@ -6,6 +6,7 @@ import { Element as Element_2 } from '@speclynx/apidom-datamodel';
6
6
  import { MemberElement } from '@speclynx/apidom-datamodel';
7
7
  import { Overlay1Element } from '@speclynx/apidom-ns-overlay-1';
8
8
  import { ParseResultElement } from '@speclynx/apidom-datamodel';
9
+ import type { PartialDeep } from 'type-fest';
9
10
 
10
11
  /**
11
12
  * Trace entry for a single overlay action application.
@@ -60,7 +61,7 @@ export declare interface ApplyOptions {
60
61
  *
61
62
  * @param overlayURI - URI to the overlay document (file path or URL)
62
63
  * @param targetURI - URI to the target document; if omitted, uses the overlay's `extends` field
63
- * @param options - apidom-reference options + overlay merge options
64
+ * @param options - overlay apply options; reference options live under `options.reference`
64
65
  * @returns ParseResultElement with the modified target document
65
66
  *
66
67
  * @public
@@ -78,7 +79,8 @@ export declare const applyOverlayApiDOM: <T extends Element_2 | ParseResultEleme
78
79
  /**
79
80
  * @public
80
81
  */
81
- export declare interface ApplyOverlayOptions extends Partial<ApiDOMReferenceOptions>, ApplyOptions {
82
+ export declare interface ApplyOverlayOptions extends ApplyOptions {
83
+ readonly reference?: PartialDeep<ApiDOMReferenceOptions>;
82
84
  }
83
85
 
84
86
  /**
@@ -88,6 +90,11 @@ export declare interface ApplyOverlayOptions extends Partial<ApiDOMReferenceOpti
88
90
  */
89
91
  export declare const applyOverlayPOJO: (overlay: Record<string, unknown>, target: Record<string, unknown>, options?: ApplyOptions) => unknown;
90
92
 
93
+ /**
94
+ * @public
95
+ */
96
+ export declare const defaultApplyOverlayOptions: ApplyOverlayOptions;
97
+
91
98
  /**
92
99
  * @public
93
100
  */