@speclynx/apidom-overlay 4.4.0 → 4.6.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.4.0",
3
+ "version": "4.6.0",
4
4
  "description": "Apply Overlay 1.x.y documents to API definitions.",
5
5
  "keywords": [
6
6
  "apidom",
@@ -53,12 +53,12 @@
53
53
  "license": "Apache-2.0",
54
54
  "dependencies": {
55
55
  "@babel/runtime-corejs3": "^7.28.4",
56
- "@speclynx/apidom-core": "4.4.0",
57
- "@speclynx/apidom-datamodel": "4.4.0",
58
- "@speclynx/apidom-error": "4.4.0",
59
- "@speclynx/apidom-json-path": "4.4.0",
60
- "@speclynx/apidom-ns-overlay-1": "4.4.0",
61
- "@speclynx/apidom-reference": "4.4.0"
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"
62
62
  },
63
63
  "files": [
64
64
  "src/**/*.mjs",
@@ -70,5 +70,5 @@
70
70
  "README.md",
71
71
  "CHANGELOG.md"
72
72
  ],
73
- "gitHead": "5bf5f346de1f59b813bb87d232566827ee9d9798"
73
+ "gitHead": "c3cec30492f0e186ffdc7b1a761a016dab98b9d4"
74
74
  }
@@ -2,17 +2,22 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
- exports.applyUpdateAction = exports.applyRemoveAction = exports.applyOverlayApiDOM = exports.applyCopyAction = exports.applyAction = void 0;
5
+ exports.applyUpdateAction = exports.applyRemoveAction = exports.applyOverlay = exports.applyCopyAction = exports.applyAction = void 0;
6
6
  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
  };
@@ -214,7 +271,7 @@ const applyAction = (actionElement, targetElement, options = defaultApplyOptions
214
271
  * @public
215
272
  */
216
273
  exports.applyAction = applyAction;
217
- const applyOverlayApiDOM = (overlayElement, targetElement, options = defaultApplyOptions) => {
274
+ const applyOverlay = (overlayElement, targetElement, options = defaultApplyOptions) => {
218
275
  const overlay = overlayElement instanceof _apidomDatamodel.ParseResultElement ? overlayElement.api : overlayElement;
219
276
  if (!(0, _apidomNsOverlay.isOverlay1Element)(overlay)) {
220
277
  throw new _OverlayError.default('First argument must be an Overlay 1.x document');
@@ -231,8 +288,13 @@ const applyOverlayApiDOM = (overlayElement, targetElement, options = defaultAppl
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
300
  targetElement.replaceResult(target);
@@ -240,4 +302,4 @@ const applyOverlayApiDOM = (overlayElement, targetElement, options = defaultAppl
240
302
  }
241
303
  return target;
242
304
  };
243
- exports.applyOverlayApiDOM = applyOverlayApiDOM;
305
+ exports.applyOverlay = applyOverlay;
@@ -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
  };
@@ -204,7 +260,7 @@ export const applyAction = (actionElement, targetElement, options = defaultApply
204
260
  *
205
261
  * @public
206
262
  */
207
- export const applyOverlayApiDOM = (overlayElement, targetElement, options = defaultApplyOptions) => {
263
+ export const applyOverlay = (overlayElement, targetElement, options = defaultApplyOptions) => {
208
264
  const overlay = overlayElement instanceof ParseResultElement ? overlayElement.api : overlayElement;
209
265
  if (!isOverlay1Element(overlay)) {
210
266
  throw new OverlayError('First argument must be an Overlay 1.x document');
@@ -221,8 +277,13 @@ export const applyOverlayApiDOM = (overlayElement, targetElement, options = defa
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
289
  targetElement.replaceResult(target);
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.applyOverlay = exports.applyAction = void 0;
5
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
6
+ var _apidomCore = require("@speclynx/apidom-core");
7
+ var _apidomNsOverlay = require("@speclynx/apidom-ns-overlay-1");
8
+ var _apidom = require("./apidom.cjs");
9
+ /**
10
+ * Applies a single overlay action (POJO) to a target (POJO).
11
+ *
12
+ * @public
13
+ */
14
+ const applyAction = (action, target, options) => (0, _apidomCore.toValue)((0, _apidom.applyAction)((0, _apidomNsOverlay.refractAction)(action), (0, _apidomDatamodel.refract)(target), options));
15
+
16
+ /**
17
+ * Applies an entire overlay document (POJO) to a target (POJO).
18
+ *
19
+ * @public
20
+ */
21
+ exports.applyAction = applyAction;
22
+ const applyOverlay = (overlay, target, options) => (0, _apidomCore.toValue)((0, _apidom.applyOverlay)((0, _apidomNsOverlay.refractOverlay1)(overlay), (0, _apidomDatamodel.refract)(target), options));
23
+ exports.applyOverlay = applyOverlay;
@@ -0,0 +1,17 @@
1
+ import { refract } from '@speclynx/apidom-datamodel';
2
+ import { toValue } from '@speclynx/apidom-core';
3
+ import { refractAction, refractOverlay1 } from '@speclynx/apidom-ns-overlay-1';
4
+ import { applyAction as applyActionApiDOM, applyOverlay as applyOverlayApiDOM } from "./apidom.mjs";
5
+ /**
6
+ * Applies a single overlay action (POJO) to a target (POJO).
7
+ *
8
+ * @public
9
+ */
10
+ export const applyAction = (action, target, options) => toValue(applyActionApiDOM(refractAction(action), refract(target), options));
11
+
12
+ /**
13
+ * Applies an entire overlay document (POJO) to a target (POJO).
14
+ *
15
+ * @public
16
+ */
17
+ export const applyOverlay = (overlay, target, options) => toValue(applyOverlayApiDOM(refractOverlay1(overlay), refract(target), options));
@@ -6,8 +6,8 @@ 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
- var _apply = require("./apply.cjs");
10
- var _OverlayError = _interopRequireDefault(require("./errors/OverlayError.cjs"));
9
+ var _apidom = require("./apidom.cjs");
10
+ var _OverlayError = _interopRequireDefault(require("../../errors/OverlayError.cjs"));
11
11
  /**
12
12
  * @public
13
13
  */
@@ -75,6 +75,6 @@ const applyOverlay = async (overlayURI, targetURI, options = {
75
75
  }
76
76
 
77
77
  // apply overlay actions to the target (returns targetParseResult with result replaced)
78
- return (0, _apply.applyOverlayApiDOM)(overlayParseResult, targetParseResult, options);
78
+ return (0, _apidom.applyOverlay)(overlayParseResult, targetParseResult, options);
79
79
  };
80
80
  var _default = exports.default = applyOverlay;
@@ -1,8 +1,8 @@
1
1
  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
- import { applyOverlayApiDOM } from "./apply.mjs";
5
- import OverlayError from "./errors/OverlayError.mjs";
4
+ import { applyOverlay as applyOverlayApiDOM } from "./apidom.mjs";
5
+ import OverlayError from "../../errors/OverlayError.mjs";
6
6
  /**
7
7
  * @public
8
8
  */
@@ -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
@@ -2,13 +2,16 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
- exports.validateAction = exports.default = exports.applyOverlayApiDOM = exports.applyAction = exports.OverlayError = void 0;
6
- var _apply = require("./apply.cjs");
7
- exports.applyAction = _apply.applyAction;
8
- exports.applyOverlayApiDOM = _apply.applyOverlayApiDOM;
5
+ exports.validateAction = exports.applyOverlayPOJO = exports.applyOverlayApiDOM = exports.applyOverlay = exports.applyActionPOJO = exports.applyActionApiDOM = exports.OverlayError = void 0;
6
+ var _apidom = require("./apply/realms/apidom.cjs");
7
+ exports.applyActionApiDOM = _apidom.applyAction;
8
+ exports.applyOverlayApiDOM = _apidom.applyOverlay;
9
+ var _uri = _interopRequireDefault(require("./apply/realms/uri.cjs"));
10
+ exports.applyOverlay = _uri.default;
11
+ var _pojo = require("./apply/realms/pojo.cjs");
12
+ exports.applyActionPOJO = _pojo.applyAction;
13
+ exports.applyOverlayPOJO = _pojo.applyOverlay;
9
14
  var _validate = require("./validate.cjs");
10
15
  exports.validateAction = _validate.validateAction;
11
16
  var _OverlayError = _interopRequireDefault(require("./errors/OverlayError.cjs"));
12
- exports.OverlayError = _OverlayError.default;
13
- var _applyUri = _interopRequireDefault(require("./apply-uri.cjs"));
14
- exports.default = _applyUri.default;
17
+ exports.OverlayError = _OverlayError.default;
package/src/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- export { applyAction, applyOverlayApiDOM } from "./apply.mjs";
1
+ export { applyAction as applyActionApiDOM, applyOverlay as applyOverlayApiDOM } from "./apply/realms/apidom.mjs";
2
+ export { default as applyOverlay } from "./apply/realms/uri.mjs";
3
+ export { applyAction as applyActionPOJO, applyOverlay as applyOverlayPOJO } from "./apply/realms/pojo.mjs";
2
4
  export { validateAction } from "./validate.mjs";
3
- export { default as OverlayError } from "./errors/OverlayError.mjs";
4
- export { default } from "./apply-uri.mjs";
5
+ export { default as OverlayError } from "./errors/OverlayError.mjs";
@@ -7,13 +7,39 @@ 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
9
 
10
+ /**
11
+ * Trace entry for a single overlay action application.
12
+ *
13
+ * @public
14
+ */
15
+ export declare interface ActionTrace {
16
+ readonly target: string;
17
+ readonly type: ActionTraceType;
18
+ readonly matchCount: number;
19
+ readonly normalizedPaths: string[];
20
+ readonly success: boolean;
21
+ readonly error?: OverlayError;
22
+ }
23
+
24
+ /**
25
+ * @public
26
+ */
27
+ export declare type ActionTraceType = 'update' | 'copy' | 'remove' | 'noop';
28
+
10
29
  /**
11
30
  * Applies a single overlay action to a target element.
12
31
  * Immutable — returns a new element with the action applied.
13
32
  *
14
33
  * @public
15
34
  */
16
- export declare const applyAction: (actionElement: ActionElement, targetElement: Element_2, options?: ApplyOptions) => Element_2;
35
+ export declare const applyActionApiDOM: (actionElement: ActionElement, targetElement: Element_2, options?: ApplyOptions) => Element_2;
36
+
37
+ /**
38
+ * Applies a single overlay action (POJO) to a target (POJO).
39
+ *
40
+ * @public
41
+ */
42
+ export declare const applyActionPOJO: (action: Record<string, unknown>, target: Record<string, unknown>, options?: ApplyOptions) => unknown;
17
43
 
18
44
  /**
19
45
  * @public
@@ -22,6 +48,7 @@ export declare interface ApplyOptions {
22
48
  readonly deepmerge?: DeepMergeUserOptions;
23
49
  readonly strict?: boolean;
24
50
  readonly immutable?: boolean;
51
+ readonly trace?: OverlayTrace;
25
52
  }
26
53
 
27
54
  /**
@@ -38,8 +65,7 @@ export declare interface ApplyOptions {
38
65
  *
39
66
  * @public
40
67
  */
41
- declare const applyOverlay: (overlayURI: string, targetURI?: string, options?: ApplyOverlayOptions) => Promise<ParseResultElement>;
42
- export default applyOverlay;
68
+ export declare const applyOverlay: (overlayURI: string, targetURI?: string, options?: ApplyOverlayOptions) => Promise<ParseResultElement>;
43
69
 
44
70
  /**
45
71
  * Applies an entire overlay document to a target element.
@@ -55,6 +81,13 @@ export declare const applyOverlayApiDOM: <T extends Element_2 | ParseResultEleme
55
81
  export declare interface ApplyOverlayOptions extends Partial<ApiDOMReferenceOptions>, ApplyOptions {
56
82
  }
57
83
 
84
+ /**
85
+ * Applies an entire overlay document (POJO) to a target (POJO).
86
+ *
87
+ * @public
88
+ */
89
+ export declare const applyOverlayPOJO: (overlay: Record<string, unknown>, target: Record<string, unknown>, options?: ApplyOptions) => unknown;
90
+
58
91
  /**
59
92
  * @public
60
93
  */
@@ -74,6 +107,19 @@ export declare interface OverlayErrorOptions {
74
107
  readonly [key: string]: unknown;
75
108
  }
76
109
 
110
+ /**
111
+ * Top-level trace container populated during overlay application.
112
+ * Pass as `trace` option — it will be mutated in place.
113
+ *
114
+ * @public
115
+ */
116
+ export declare interface OverlayTrace {
117
+ actions: ActionTrace[];
118
+ failed: boolean;
119
+ failedAt: number;
120
+ message: string;
121
+ }
122
+
77
123
  /**
78
124
  * Validates that an ActionElement has the correct shape per the Overlay spec.
79
125
  *