@speclynx/apidom-overlay 4.5.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.5.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.5.0",
57
- "@speclynx/apidom-datamodel": "4.5.0",
58
- "@speclynx/apidom-error": "4.5.0",
59
- "@speclynx/apidom-json-path": "4.5.0",
60
- "@speclynx/apidom-ns-overlay-1": "4.5.0",
61
- "@speclynx/apidom-reference": "4.5.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": "2df7f3dcd368bdbc0644117fb677610a8b4a03a5"
74
+ "gitHead": "5afe50e432d90185f514e91bb35319aa4e23ba7b"
74
75
  }
@@ -7,12 +7,17 @@ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
7
7
  var _apidomCore = require("@speclynx/apidom-core");
8
8
  var _apidomJsonPath = require("@speclynx/apidom-json-path");
9
9
  var _apidomNsOverlay = require("@speclynx/apidom-ns-overlay-1");
10
- var _OverlayError = _interopRequireDefault(require("../errors/OverlayError.cjs"));
11
- var _validate = require("../validate.cjs");
10
+ var _OverlayError = _interopRequireDefault(require("../../errors/OverlayError.cjs"));
11
+ var _validate = require("../../validate.cjs");
12
+ var _TraceBuilder = _interopRequireDefault(require("../trace/TraceBuilder.cjs"));
12
13
  /**
13
14
  * @public
14
15
  */
15
16
 
17
+ /**
18
+ * Internal options that carry the tracer instance.
19
+ */
20
+
16
21
  const defaultApplyOptions = {
17
22
  immutable: true,
18
23
  strict: false
@@ -157,6 +162,8 @@ const applyRemoveAction = (normalizedPaths, targetElement, options = defaultAppl
157
162
  */
158
163
  exports.applyRemoveAction = applyRemoveAction;
159
164
  const applyAction = (actionElement, targetElement, options = defaultApplyOptions) => {
165
+ const internalOpts = options;
166
+ const tracer = internalOpts.tracer ?? (options.trace ? new _TraceBuilder.default(options.trace) : undefined);
160
167
  const actionValidation = (0, _validate.validateAction)(actionElement);
161
168
  if (!actionValidation.valid) throw actionValidation.error;
162
169
  const targetExpression = (0, _apidomCore.toValue)(actionElement.target);
@@ -170,24 +177,53 @@ const applyAction = (actionElement, targetElement, options = defaultApplyOptions
170
177
  });
171
178
  if (matches.length === 0) {
172
179
  if (options.strict) {
173
- throw new _OverlayError.default(`Action target "${targetExpression}" matched zero nodes (strict mode)`, {
180
+ const error = new _OverlayError.default(`Action target "${targetExpression}" matched zero nodes (strict mode)`, {
174
181
  action: actionElement
175
182
  });
183
+ tracer?.action({
184
+ target: targetExpression,
185
+ type: 'noop',
186
+ matchCount: 0,
187
+ normalizedPaths: [],
188
+ success: false,
189
+ error
190
+ });
191
+ throw error;
176
192
  }
193
+ tracer?.action({
194
+ target: targetExpression,
195
+ type: 'noop',
196
+ matchCount: 0,
197
+ normalizedPaths: []
198
+ });
177
199
  return targetElement;
178
200
  }
179
201
  try {
180
202
  // remove action
181
203
  const removeValue = actionElement.removeField;
182
204
  if (removeValue !== undefined && (0, _apidomCore.toValue)(removeValue) === true) {
183
- return applyRemoveAction(normalizedPaths, targetElement, options);
205
+ const result = applyRemoveAction(normalizedPaths, targetElement, options);
206
+ tracer?.action({
207
+ target: targetExpression,
208
+ type: 'remove',
209
+ matchCount: matches.length,
210
+ normalizedPaths
211
+ });
212
+ return result;
184
213
  }
185
214
 
186
215
  // update action
187
216
  if (actionElement.update !== undefined) {
188
217
  const nodesValidation = (0, _validate.validateTargetNodes)(matches);
189
218
  if (!nodesValidation.valid) throw nodesValidation.error;
190
- return applyUpdateAction(normalizedPaths, actionElement.update, targetElement, options);
219
+ const result = applyUpdateAction(normalizedPaths, actionElement.update, targetElement, options);
220
+ tracer?.action({
221
+ target: targetExpression,
222
+ type: 'update',
223
+ matchCount: matches.length,
224
+ normalizedPaths
225
+ });
226
+ return result;
191
227
  }
192
228
 
193
229
  // copy action
@@ -195,14 +231,35 @@ const applyAction = (actionElement, targetElement, options = defaultApplyOptions
195
231
  const nodesValidation = (0, _validate.validateTargetNodes)(matches);
196
232
  if (!nodesValidation.valid) throw nodesValidation.error;
197
233
  const copyExpression = (0, _apidomCore.toValue)(actionElement.copy);
198
- return applyCopyAction(normalizedPaths, copyExpression, targetElement, options);
234
+ const result = applyCopyAction(normalizedPaths, copyExpression, targetElement, options);
235
+ tracer?.action({
236
+ target: targetExpression,
237
+ type: 'copy',
238
+ matchCount: matches.length,
239
+ normalizedPaths
240
+ });
241
+ return result;
199
242
  }
243
+ tracer?.action({
244
+ target: targetExpression,
245
+ type: 'noop',
246
+ matchCount: matches.length,
247
+ normalizedPaths
248
+ });
200
249
  return targetElement;
201
250
  } catch (error) {
202
251
  // enrich OverlayError with action context, preserving original stack
203
252
  if (error instanceof _OverlayError.default && !error.action) {
204
253
  error.action = actionElement;
205
254
  }
255
+ tracer?.action({
256
+ target: targetExpression,
257
+ type: 'noop',
258
+ matchCount: matches.length,
259
+ normalizedPaths,
260
+ success: false,
261
+ error: error instanceof _OverlayError.default ? error : undefined
262
+ });
206
263
  throw error;
207
264
  }
208
265
  };
@@ -221,21 +278,28 @@ const applyOverlay = (overlayElement, targetElement, options = defaultApplyOptio
221
278
  }
222
279
  let target;
223
280
  if (targetElement instanceof _apidomDatamodel.ParseResultElement) {
224
- if (targetElement.api === undefined) {
225
- 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');
226
283
  }
227
- target = targetElement.api;
284
+ target = targetElement.result;
228
285
  } else {
229
286
  target = targetElement;
230
287
  }
231
288
  if (!(0, _apidomDatamodel.isArrayElement)(overlay.actions)) {
232
289
  return targetElement;
233
290
  }
291
+ const tracer = options.trace ? new _TraceBuilder.default(options.trace) : undefined;
292
+ const internalOptions = tracer ? {
293
+ ...options,
294
+ tracer
295
+ } : options;
234
296
  for (const action of overlay.actions) {
235
- target = applyAction(action, target, options);
297
+ target = applyAction(action, target, internalOptions);
236
298
  }
237
299
  if (targetElement instanceof _apidomDatamodel.ParseResultElement) {
238
- targetElement.replaceResult(target);
300
+ if (target !== targetElement.result) {
301
+ targetElement.replaceResult(target);
302
+ }
239
303
  return targetElement;
240
304
  }
241
305
  return target;
@@ -2,11 +2,15 @@ import { isObjectElement, isArrayElement, cloneDeep, ParseResultElement } from '
2
2
  import { deepmerge, toValue } from '@speclynx/apidom-core';
3
3
  import { evaluate, NormalizedPath } from '@speclynx/apidom-json-path';
4
4
  import { isOverlay1Element } from '@speclynx/apidom-ns-overlay-1';
5
- import OverlayError from "../errors/OverlayError.mjs";
6
- import { validateAction, validateTargetNodes } from "../validate.mjs";
5
+ import OverlayError from "../../errors/OverlayError.mjs";
6
+ import { validateAction, validateTargetNodes } from "../../validate.mjs";
7
+ import TraceBuilder from "../trace/TraceBuilder.mjs";
7
8
  /**
8
9
  * @public
9
10
  */
11
+ /**
12
+ * Internal options that carry the tracer instance.
13
+ */
10
14
  const defaultApplyOptions = {
11
15
  immutable: true,
12
16
  strict: false
@@ -148,6 +152,8 @@ export const applyRemoveAction = (normalizedPaths, targetElement, options = defa
148
152
  * @public
149
153
  */
150
154
  export const applyAction = (actionElement, targetElement, options = defaultApplyOptions) => {
155
+ const internalOpts = options;
156
+ const tracer = internalOpts.tracer ?? (options.trace ? new TraceBuilder(options.trace) : undefined);
151
157
  const actionValidation = validateAction(actionElement);
152
158
  if (!actionValidation.valid) throw actionValidation.error;
153
159
  const targetExpression = toValue(actionElement.target);
@@ -161,24 +167,53 @@ export const applyAction = (actionElement, targetElement, options = defaultApply
161
167
  });
162
168
  if (matches.length === 0) {
163
169
  if (options.strict) {
164
- throw new OverlayError(`Action target "${targetExpression}" matched zero nodes (strict mode)`, {
170
+ const error = new OverlayError(`Action target "${targetExpression}" matched zero nodes (strict mode)`, {
165
171
  action: actionElement
166
172
  });
173
+ tracer?.action({
174
+ target: targetExpression,
175
+ type: 'noop',
176
+ matchCount: 0,
177
+ normalizedPaths: [],
178
+ success: false,
179
+ error
180
+ });
181
+ throw error;
167
182
  }
183
+ tracer?.action({
184
+ target: targetExpression,
185
+ type: 'noop',
186
+ matchCount: 0,
187
+ normalizedPaths: []
188
+ });
168
189
  return targetElement;
169
190
  }
170
191
  try {
171
192
  // remove action
172
193
  const removeValue = actionElement.removeField;
173
194
  if (removeValue !== undefined && toValue(removeValue) === true) {
174
- return applyRemoveAction(normalizedPaths, targetElement, options);
195
+ const result = applyRemoveAction(normalizedPaths, targetElement, options);
196
+ tracer?.action({
197
+ target: targetExpression,
198
+ type: 'remove',
199
+ matchCount: matches.length,
200
+ normalizedPaths
201
+ });
202
+ return result;
175
203
  }
176
204
 
177
205
  // update action
178
206
  if (actionElement.update !== undefined) {
179
207
  const nodesValidation = validateTargetNodes(matches);
180
208
  if (!nodesValidation.valid) throw nodesValidation.error;
181
- return applyUpdateAction(normalizedPaths, actionElement.update, targetElement, options);
209
+ const result = applyUpdateAction(normalizedPaths, actionElement.update, targetElement, options);
210
+ tracer?.action({
211
+ target: targetExpression,
212
+ type: 'update',
213
+ matchCount: matches.length,
214
+ normalizedPaths
215
+ });
216
+ return result;
182
217
  }
183
218
 
184
219
  // copy action
@@ -186,14 +221,35 @@ export const applyAction = (actionElement, targetElement, options = defaultApply
186
221
  const nodesValidation = validateTargetNodes(matches);
187
222
  if (!nodesValidation.valid) throw nodesValidation.error;
188
223
  const copyExpression = toValue(actionElement.copy);
189
- return applyCopyAction(normalizedPaths, copyExpression, targetElement, options);
224
+ const result = applyCopyAction(normalizedPaths, copyExpression, targetElement, options);
225
+ tracer?.action({
226
+ target: targetExpression,
227
+ type: 'copy',
228
+ matchCount: matches.length,
229
+ normalizedPaths
230
+ });
231
+ return result;
190
232
  }
233
+ tracer?.action({
234
+ target: targetExpression,
235
+ type: 'noop',
236
+ matchCount: matches.length,
237
+ normalizedPaths
238
+ });
191
239
  return targetElement;
192
240
  } catch (error) {
193
241
  // enrich OverlayError with action context, preserving original stack
194
242
  if (error instanceof OverlayError && !error.action) {
195
243
  error.action = actionElement;
196
244
  }
245
+ tracer?.action({
246
+ target: targetExpression,
247
+ type: 'noop',
248
+ matchCount: matches.length,
249
+ normalizedPaths,
250
+ success: false,
251
+ error: error instanceof OverlayError ? error : undefined
252
+ });
197
253
  throw error;
198
254
  }
199
255
  };
@@ -211,21 +267,28 @@ export const applyOverlay = (overlayElement, targetElement, options = defaultApp
211
267
  }
212
268
  let target;
213
269
  if (targetElement instanceof ParseResultElement) {
214
- if (targetElement.api === undefined) {
215
- throw new OverlayError('Target ParseResultElement contains no API element');
270
+ if (targetElement.result === undefined) {
271
+ throw new OverlayError('Target ParseResultElement contains no result element');
216
272
  }
217
- target = targetElement.api;
273
+ target = targetElement.result;
218
274
  } else {
219
275
  target = targetElement;
220
276
  }
221
277
  if (!isArrayElement(overlay.actions)) {
222
278
  return targetElement;
223
279
  }
280
+ const tracer = options.trace ? new TraceBuilder(options.trace) : undefined;
281
+ const internalOptions = tracer ? {
282
+ ...options,
283
+ tracer
284
+ } : options;
224
285
  for (const action of overlay.actions) {
225
- target = applyAction(action, target, options);
286
+ target = applyAction(action, target, internalOptions);
226
287
  }
227
288
  if (targetElement instanceof ParseResultElement) {
228
- targetElement.replaceResult(target);
289
+ if (target !== targetElement.result) {
290
+ targetElement.replaceResult(target);
291
+ }
229
292
  return targetElement;
230
293
  }
231
294
  return target;
@@ -11,7 +11,7 @@ var _apidom = require("./apidom.cjs");
11
11
  *
12
12
  * @public
13
13
  */
14
- const applyAction = (action, target) => (0, _apidomCore.toValue)((0, _apidom.applyAction)((0, _apidomNsOverlay.refractAction)(action), (0, _apidomDatamodel.refract)(target)));
14
+ const applyAction = (action, target, options) => (0, _apidomCore.toValue)((0, _apidom.applyAction)((0, _apidomNsOverlay.refractAction)(action), (0, _apidomDatamodel.refract)(target), options));
15
15
 
16
16
  /**
17
17
  * Applies an entire overlay document (POJO) to a target (POJO).
@@ -19,5 +19,5 @@ const applyAction = (action, target) => (0, _apidomCore.toValue)((0, _apidom.app
19
19
  * @public
20
20
  */
21
21
  exports.applyAction = applyAction;
22
- const applyOverlay = (overlay, target) => (0, _apidomCore.toValue)((0, _apidom.applyOverlay)((0, _apidomNsOverlay.refractOverlay1)(overlay), (0, _apidomDatamodel.refract)(target)));
22
+ const applyOverlay = (overlay, target, options) => (0, _apidomCore.toValue)((0, _apidom.applyOverlay)((0, _apidomNsOverlay.refractOverlay1)(overlay), (0, _apidomDatamodel.refract)(target), options));
23
23
  exports.applyOverlay = applyOverlay;
@@ -7,11 +7,11 @@ import { applyAction as applyActionApiDOM, applyOverlay as applyOverlayApiDOM }
7
7
  *
8
8
  * @public
9
9
  */
10
- export const applyAction = (action, target) => toValue(applyActionApiDOM(refractAction(action), refract(target)));
10
+ export const applyAction = (action, target, options) => toValue(applyActionApiDOM(refractAction(action), refract(target), options));
11
11
 
12
12
  /**
13
13
  * Applies an entire overlay document (POJO) to a target (POJO).
14
14
  *
15
15
  * @public
16
16
  */
17
- export const applyOverlay = (overlay, target) => toValue(applyOverlayApiDOM(refractOverlay1(overlay), refract(target)));
17
+ export const applyOverlay = (overlay, target, options) => toValue(applyOverlayApiDOM(refractOverlay1(overlay), refract(target), options));
@@ -2,17 +2,17 @@
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");
9
9
  var _apidom = require("./apidom.cjs");
10
- var _OverlayError = _interopRequireDefault(require("../errors/OverlayError.cjs"));
10
+ var _OverlayError = _interopRequireDefault(require("../../errors/OverlayError.cjs"));
11
11
  /**
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');
@@ -2,11 +2,11 @@ import { isParseResultElement } from '@speclynx/apidom-datamodel';
2
2
  import { isOverlay1Element } from '@speclynx/apidom-ns-overlay-1';
3
3
  import { parse, mergeOptions } from '@speclynx/apidom-reference';
4
4
  import { applyOverlay as applyOverlayApiDOM } from "./apidom.mjs";
5
- import OverlayError from "../errors/OverlayError.mjs";
5
+ 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');
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ /**
6
+ * Collects trace entries during overlay application.
7
+ * Instantiated internally when `options.trace` is provided.
8
+ */
9
+ class TraceBuilder {
10
+ #trace;
11
+ constructor(trace) {
12
+ this.#trace = trace;
13
+ this.#trace.actions = [];
14
+ this.#trace.failed = false;
15
+ this.#trace.failedAt = -1;
16
+ this.#trace.message = 'Overlay was successfully applied';
17
+ }
18
+ action(step) {
19
+ const {
20
+ target,
21
+ type,
22
+ matchCount,
23
+ normalizedPaths,
24
+ success = true,
25
+ error
26
+ } = step;
27
+ const position = this.#trace.actions.length;
28
+ this.#trace.actions.push({
29
+ target,
30
+ type,
31
+ matchCount,
32
+ normalizedPaths,
33
+ success,
34
+ ...(error !== undefined ? {
35
+ error
36
+ } : {})
37
+ });
38
+ if (!success) {
39
+ this.#trace.failed = true;
40
+ this.#trace.failedAt = position;
41
+ this.#trace.message = error?.message ?? 'Action failed';
42
+ }
43
+ }
44
+ }
45
+ var _default = exports.default = TraceBuilder;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Collects trace entries during overlay application.
3
+ * Instantiated internally when `options.trace` is provided.
4
+ */
5
+ class TraceBuilder {
6
+ #trace;
7
+ constructor(trace) {
8
+ this.#trace = trace;
9
+ this.#trace.actions = [];
10
+ this.#trace.failed = false;
11
+ this.#trace.failedAt = -1;
12
+ this.#trace.message = 'Overlay was successfully applied';
13
+ }
14
+ action(step) {
15
+ const {
16
+ target,
17
+ type,
18
+ matchCount,
19
+ normalizedPaths,
20
+ success = true,
21
+ error
22
+ } = step;
23
+ const position = this.#trace.actions.length;
24
+ this.#trace.actions.push({
25
+ target,
26
+ type,
27
+ matchCount,
28
+ normalizedPaths,
29
+ success,
30
+ ...(error !== undefined ? {
31
+ error
32
+ } : {})
33
+ });
34
+ if (!success) {
35
+ this.#trace.failed = true;
36
+ this.#trace.failedAt = position;
37
+ this.#trace.message = error?.message ?? 'Action failed';
38
+ }
39
+ }
40
+ }
41
+ export default TraceBuilder;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.TraceBuilder = void 0;
6
+ var _TraceBuilder = _interopRequireDefault(require("./TraceBuilder.cjs"));
7
+ exports.TraceBuilder = _TraceBuilder.default;
@@ -0,0 +1 @@
1
+ export { default as TraceBuilder } from "./TraceBuilder.mjs";
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
@@ -0,0 +1 @@
1
+ export {};
package/src/index.cjs CHANGED
@@ -1,14 +1,16 @@
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
- var _apidom = require("./apply/apidom.cjs");
6
+ exports.validateAction = exports.defaultApplyOverlayOptions = exports.applyOverlayPOJO = exports.applyOverlayApiDOM = exports.applyOverlay = exports.applyActionPOJO = exports.applyActionApiDOM = exports.OverlayError = void 0;
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/uri.cjs"));
10
+ var _uri = _interopRequireWildcard(require("./apply/realms/uri.cjs"));
10
11
  exports.applyOverlay = _uri.default;
11
- var _pojo = require("./apply/pojo.cjs");
12
+ exports.defaultApplyOverlayOptions = _uri.defaultOptions;
13
+ var _pojo = require("./apply/realms/pojo.cjs");
12
14
  exports.applyActionPOJO = _pojo.applyAction;
13
15
  exports.applyOverlayPOJO = _pojo.applyOverlay;
14
16
  var _validate = require("./validate.cjs");
package/src/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { applyAction as applyActionApiDOM, applyOverlay as applyOverlayApiDOM } from "./apply/apidom.mjs";
2
- export { default as applyOverlay } from "./apply/uri.mjs";
3
- export { applyAction as applyActionPOJO, applyOverlay as applyOverlayPOJO } from "./apply/pojo.mjs";
1
+ export { applyAction as applyActionApiDOM, applyOverlay as applyOverlayApiDOM } from "./apply/realms/apidom.mjs";
2
+ export { default as applyOverlay, defaultOptions as defaultApplyOverlayOptions } from "./apply/realms/uri.mjs";
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";