agent-contracts 0.30.0 → 0.30.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/dist/index.js CHANGED
@@ -40341,17 +40341,19 @@ var require_errors = __commonJS({
40341
40341
  exports.convertAjvErrors = exports.RulesetValidationError = void 0;
40342
40342
  var isAggregateError_1 = require_isAggregateError();
40343
40343
  var RulesetValidationError = class extends Error {
40344
- constructor(code, message, path) {
40344
+ constructor(code, message, path, location2) {
40345
40345
  super(message);
40346
40346
  this.code = code;
40347
40347
  this.message = message;
40348
40348
  this.path = path;
40349
+ this.range = location2 === null || location2 === void 0 ? void 0 : location2.range;
40350
+ this.source = location2 === null || location2 === void 0 ? void 0 : location2.source;
40349
40351
  }
40350
40352
  };
40351
40353
  exports.RulesetValidationError = RulesetValidationError;
40352
40354
  var RULE_INSTANCE_PATH = /^\/rules\/[^/]+/;
40353
40355
  var GENERIC_INSTANCE_PATH = /^\/(?:aliases|extends|overrides(?:\/\d+\/extends)?)/;
40354
- function convertAjvErrors(errors) {
40356
+ function convertAjvErrors(errors, sourceContext) {
40355
40357
  const sortedErrors = [...errors].sort((errorA, errorB) => {
40356
40358
  const diff = errorA.instancePath.length - errorB.instancePath.length;
40357
40359
  return diff === 0 ? errorA.keyword === "errorMessage" && errorB.keyword !== "errorMessage" ? -1 : 0 : diff;
@@ -40384,10 +40386,12 @@ var require_errors = __commonJS({
40384
40386
  return filteredErrors.flatMap((error) => {
40385
40387
  var _a;
40386
40388
  if (error.keyword === "x-spectral-runtime") {
40387
- return flatErrors(error.params.errors);
40389
+ const flat = flatErrors(error.params.errors);
40390
+ const list = Array.isArray(flat) ? flat : [flat];
40391
+ return list.map((e3) => enrichWithLocation(e3, sourceContext));
40388
40392
  }
40389
40393
  const path = error.instancePath.slice(1).split("/");
40390
- return new RulesetValidationError(inferErrorCode(path, error.keyword), (_a = error.message) !== null && _a !== void 0 ? _a : "unknown error", path);
40394
+ return new RulesetValidationError(inferErrorCode(path, error.keyword), (_a = error.message) !== null && _a !== void 0 ? _a : "unknown error", path, resolveLocation(path, sourceContext));
40391
40395
  });
40392
40396
  }
40393
40397
  exports.convertAjvErrors = convertAjvErrors;
@@ -40397,6 +40401,22 @@ var require_errors = __commonJS({
40397
40401
  }
40398
40402
  return error;
40399
40403
  }
40404
+ function resolveLocation(path, sourceContext) {
40405
+ var _a;
40406
+ if (sourceContext === void 0) {
40407
+ return void 0;
40408
+ }
40409
+ return {
40410
+ source: sourceContext.source,
40411
+ range: (_a = sourceContext.getLocationForJsonPath(path)) === null || _a === void 0 ? void 0 : _a.range
40412
+ };
40413
+ }
40414
+ function enrichWithLocation(error, sourceContext) {
40415
+ if (sourceContext === void 0 || error.source !== void 0 || error.range !== void 0) {
40416
+ return error;
40417
+ }
40418
+ return new RulesetValidationError(error.code, error.message, error.path, resolveLocation(error.path, sourceContext));
40419
+ }
40400
40420
  function inferErrorCode(path, keyword) {
40401
40421
  if (path.length === 0) {
40402
40422
  return "generic-validation-error";
@@ -45917,17 +45937,17 @@ var require_assertions = __commonJS({
45917
45937
  var ajv_1 = require_ajv();
45918
45938
  var errors_1 = require_errors();
45919
45939
  var es_aggregate_error_1 = (0, tslib_1.__importDefault)(require_es_aggregate_error());
45920
- function assertValidRuleset(ruleset2, format2 = "js") {
45921
- var _a;
45940
+ function assertValidRuleset(ruleset2, format2 = "js", sourceContext) {
45941
+ var _a, _b;
45922
45942
  if (!(0, json_1.isPlainObject)(ruleset2)) {
45923
- throw new errors_1.RulesetValidationError("invalid-ruleset-definition", "Provided ruleset is not an object", []);
45943
+ throw new errors_1.RulesetValidationError("invalid-ruleset-definition", "Provided ruleset is not an object", [], sourceContext === void 0 ? void 0 : { source: sourceContext.source });
45924
45944
  }
45925
45945
  if (!("rules" in ruleset2) && !("extends" in ruleset2) && !("overrides" in ruleset2)) {
45926
- throw new errors_1.RulesetValidationError("invalid-ruleset-definition", "Ruleset must have rules or extends or overrides defined", []);
45946
+ throw new errors_1.RulesetValidationError("invalid-ruleset-definition", "Ruleset must have rules or extends or overrides defined", [], sourceContext === void 0 ? void 0 : { source: sourceContext.source, range: (_a = sourceContext.getLocationForJsonPath([])) === null || _a === void 0 ? void 0 : _a.range });
45927
45947
  }
45928
45948
  const validate = (0, ajv_1.createValidator)(format2);
45929
45949
  if (!validate(ruleset2)) {
45930
- throw new es_aggregate_error_1.default((0, errors_1.convertAjvErrors)((_a = validate.errors) !== null && _a !== void 0 ? _a : []));
45950
+ throw new es_aggregate_error_1.default((0, errors_1.convertAjvErrors)((_b = validate.errors) !== null && _b !== void 0 ? _b : [], sourceContext));
45931
45951
  }
45932
45952
  }
45933
45953
  exports.assertValidRuleset = assertValidRuleset;
@@ -46097,10 +46117,10 @@ var require_ruleset = __commonJS({
46097
46117
  let definition;
46098
46118
  if ((0, json_1.isPlainObject)(maybeDefinition) && "extends" in maybeDefinition) {
46099
46119
  const { extends: _2, ...def } = maybeDefinition;
46100
- (0, index_1.assertValidRuleset)({ extends: [], ...def }, "js");
46120
+ (0, index_1.assertValidRuleset)({ extends: [], ...def }, "js", context === null || context === void 0 ? void 0 : context.sourceContext);
46101
46121
  definition = maybeDefinition;
46102
46122
  } else {
46103
- (0, index_1.assertValidRuleset)(maybeDefinition, "js");
46123
+ (0, index_1.assertValidRuleset)(maybeDefinition, "js", context === null || context === void 0 ? void 0 : context.sourceContext);
46104
46124
  definition = maybeDefinition;
46105
46125
  }
46106
46126
  this.definition = definition;