@stoplight/spectral-core 1.9.0 → 1.10.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.
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
"$ref": "shared#formats"
|
|
192
192
|
},
|
|
193
193
|
"given": {
|
|
194
|
-
"$ref": "shared#given"
|
|
194
|
+
"$ref": "shared#arrayish-given"
|
|
195
195
|
}
|
|
196
196
|
},
|
|
197
197
|
"required": ["formats", "given"],
|
|
@@ -208,7 +208,7 @@
|
|
|
208
208
|
}
|
|
209
209
|
},
|
|
210
210
|
"else": {
|
|
211
|
-
"$ref": "shared#given"
|
|
211
|
+
"$ref": "shared#arrayish-given"
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
}
|
package/dist/meta/shared.json
CHANGED
package/dist/ruleset/rule.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var _a, _Rule_severity, _Rule_enabled, _Rule_then, _Rule_given, _Rule_resolveAlias, _Rule_resolveAliasForFormats;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Rule = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
@@ -18,7 +18,6 @@ class Rule {
|
|
|
18
18
|
this.name = name;
|
|
19
19
|
this.definition = definition;
|
|
20
20
|
this.owner = owner;
|
|
21
|
-
_Rule_instances.add(this);
|
|
22
21
|
_Rule_severity.set(this, void 0);
|
|
23
22
|
_Rule_enabled.set(this, void 0);
|
|
24
23
|
_Rule_then.set(this, void 0);
|
|
@@ -91,10 +90,12 @@ class Rule {
|
|
|
91
90
|
const actualGiven = Array.isArray(given) ? given : [given];
|
|
92
91
|
(0, tslib_1.__classPrivateFieldSet)(this, _Rule_given, this.owner.hasComplexAliases
|
|
93
92
|
? actualGiven
|
|
94
|
-
: actualGiven.flatMap(expr => (0, tslib_1.__classPrivateFieldGet)(
|
|
93
|
+
: actualGiven.flatMap(expr => (0, tslib_1.__classPrivateFieldGet)(Rule, _a, "m", _Rule_resolveAlias).call(Rule, this.owner.aliases, expr, null, new Set())).filter(lodash_1.isString), "f");
|
|
95
94
|
}
|
|
96
95
|
getGivenForFormats(formats) {
|
|
97
|
-
return this.owner.hasComplexAliases
|
|
96
|
+
return this.owner.hasComplexAliases
|
|
97
|
+
? (0, tslib_1.__classPrivateFieldGet)(this, _Rule_given, "f").flatMap(expr => (0, tslib_1.__classPrivateFieldGet)(Rule, _a, "m", _Rule_resolveAlias).call(Rule, this.owner.aliases, expr, formats, new Set()))
|
|
98
|
+
: (0, tslib_1.__classPrivateFieldGet)(this, _Rule_given, "f");
|
|
98
99
|
}
|
|
99
100
|
matchesFormat(formats) {
|
|
100
101
|
if (this.formats === null) {
|
|
@@ -135,50 +136,36 @@ class Rule {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
exports.Rule = Rule;
|
|
138
|
-
_a = Rule, _Rule_severity = new WeakMap(), _Rule_enabled = new WeakMap(), _Rule_then = new WeakMap(), _Rule_given = new WeakMap(),
|
|
139
|
+
_a = Rule, _Rule_severity = new WeakMap(), _Rule_enabled = new WeakMap(), _Rule_then = new WeakMap(), _Rule_given = new WeakMap(), _Rule_resolveAlias = function _Rule_resolveAlias(aliases, expr, formats, stack) {
|
|
139
140
|
var _b;
|
|
140
|
-
const expressions = [expr];
|
|
141
141
|
const resolvedExpressions = [];
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
let actualAliasValue;
|
|
160
|
-
if ((0, guards_1.isSimpleAliasDefinition)(aliasValue)) {
|
|
161
|
-
actualAliasValue = aliasValue;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
actualAliasValue = (0, tslib_1.__classPrivateFieldGet)(Rule, _a, "m", _Rule_resolveAliasForFormats).call(Rule, aliasValue, formats);
|
|
165
|
-
}
|
|
166
|
-
if (actualAliasValue === null) {
|
|
167
|
-
continue resolve;
|
|
168
|
-
}
|
|
169
|
-
if (Array.isArray(actualAliasValue)) {
|
|
170
|
-
expressions.push(...actualAliasValue.map(item => item + resolvedExpr.slice(alias.length + 1)));
|
|
171
|
-
continue resolve;
|
|
172
|
-
}
|
|
173
|
-
if (actualAliasValue.length + 1 === expression.length) {
|
|
174
|
-
resolvedExpr = actualAliasValue;
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
resolvedExpr = actualAliasValue + resolvedExpr.slice(alias.length + 1);
|
|
178
|
-
}
|
|
142
|
+
if (expr.startsWith('#')) {
|
|
143
|
+
const alias = (_b = ALIAS.exec(expr)) === null || _b === void 0 ? void 0 : _b[1];
|
|
144
|
+
if (alias === void 0 || alias === null) {
|
|
145
|
+
throw new ReferenceError(`"${this.name}" rule references an invalid alias`);
|
|
146
|
+
}
|
|
147
|
+
if (stack.has(alias)) {
|
|
148
|
+
const _stack = [...stack, alias];
|
|
149
|
+
throw new ReferenceError(`Alias "${_stack[0]}" is circular. Resolution stack: ${_stack.join(' -> ')}`);
|
|
150
|
+
}
|
|
151
|
+
stack.add(alias);
|
|
152
|
+
if (aliases === null || !(alias in aliases)) {
|
|
153
|
+
throw new ReferenceError(`Alias "${alias}" does not exist`);
|
|
154
|
+
}
|
|
155
|
+
const aliasValue = aliases[alias];
|
|
156
|
+
let actualAliasValue;
|
|
157
|
+
if ((0, guards_1.isSimpleAliasDefinition)(aliasValue)) {
|
|
158
|
+
actualAliasValue = aliasValue;
|
|
179
159
|
}
|
|
180
|
-
|
|
181
|
-
|
|
160
|
+
else {
|
|
161
|
+
actualAliasValue = (0, tslib_1.__classPrivateFieldGet)(Rule, _a, "m", _Rule_resolveAliasForFormats).call(Rule, aliasValue, formats);
|
|
162
|
+
}
|
|
163
|
+
if (actualAliasValue !== null) {
|
|
164
|
+
resolvedExpressions.push(...actualAliasValue.flatMap(item => (0, tslib_1.__classPrivateFieldGet)(Rule, _a, "m", _Rule_resolveAlias).call(Rule, aliases, item + expr.slice(alias.length + 1), formats, new Set([...stack]))));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
resolvedExpressions.push(expr);
|
|
182
169
|
}
|
|
183
170
|
return resolvedExpressions;
|
|
184
171
|
}, _Rule_resolveAliasForFormats = function _Rule_resolveAliasForFormats({ targets }, formats) {
|
package/dist/ruleset/rule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule.js","sourceRoot":"","sources":["../../src/ruleset/rule.ts"],"names":[],"mappings":";;;;;AAAA,mCAAkC;AAElC,0CAAoD;AACpD,0CAAgD;AAChD,kEAAyD;AAEzD,+CAAiF;
|
|
1
|
+
{"version":3,"file":"rule.js","sourceRoot":"","sources":["../../src/ruleset/rule.ts"],"names":[],"mappings":";;;;;AAAA,mCAAkC;AAElC,0CAAoD;AACpD,0CAAgD;AAChD,kEAAyD;AAEzD,+CAAiF;AAUjF,iDAA8C;AAC9C,mDAAgD;AAChD,2CAAyD;AAEzD,MAAM,KAAK,GAAG,oBAAoB,CAAC;AAsBnC,MAAa,IAAI;IAYf,YACkB,IAAY,EACZ,UAA0B,EAC1B,KAAc;;QAFd,SAAI,GAAJ,IAAI,CAAQ;QACZ,eAAU,GAAV,UAAU,CAAgB;QAC1B,UAAK,GAAL,KAAK,CAAS;QAZhC,iCAA+B;QAG/B,gCAAkB;QAGlB,6BAAoB;QACpB,8BAAkB;QAOhB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,KAAK,KAAK,CAAC;QACpD,oCAAA,IAAI,iBAAY,IAAI,CAAC,WAAW,MAAA,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,MAAA,UAAU,CAAC,WAAW,mC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K,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAC/F,CACF,CAAC;SACH;KACF;SAAM;QACL,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAChC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC,uEAGC,EAAE,OAAO,EAAgC,EACzC,OAA2B;IAE3B,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE;QAC1C,OAAO,IAAI,CAAC;KACb;IAGD,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1B,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;gBACvB,OAAO,MAAM,CAAC,KAAK,CAAC;aACrB;SACF;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/ruleset/types.d.ts
CHANGED
|
@@ -44,10 +44,10 @@ export declare type RulesetScopedAliasDefinition = {
|
|
|
44
44
|
description?: string;
|
|
45
45
|
targets: {
|
|
46
46
|
formats: FormatsSet | Format[];
|
|
47
|
-
given:
|
|
47
|
+
given: string[];
|
|
48
48
|
}[];
|
|
49
49
|
};
|
|
50
|
-
export declare type RulesetAliasesDefinition = Record<string,
|
|
50
|
+
export declare type RulesetAliasesDefinition = Record<string, string[] | RulesetScopedAliasDefinition>;
|
|
51
51
|
export declare type RulesetDefinition = Readonly<{
|
|
52
52
|
documentationUrl?: string;
|
|
53
53
|
description?: string;
|