@ifc-lite/ids 3.1.0 → 3.3.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/README.md +10 -1
- package/dist/audit/coherence/cardinality.js +4 -1
- package/dist/audit/coherence/cardinality.js.map +1 -1
- package/dist/audit/coherence/index.d.ts +0 -1
- package/dist/audit/coherence/index.d.ts.map +1 -1
- package/dist/audit/coherence/index.js +59 -45
- package/dist/audit/coherence/index.js.map +1 -1
- package/dist/audit/coherence/regex.d.ts +3 -3
- package/dist/audit/coherence/regex.js +3 -3
- package/dist/audit/ifc-schema/attribute-value.d.ts +19 -0
- package/dist/audit/ifc-schema/attribute-value.d.ts.map +1 -0
- package/dist/audit/ifc-schema/attribute-value.js +71 -0
- package/dist/audit/ifc-schema/attribute-value.js.map +1 -0
- package/dist/audit/ifc-schema/datatype-check.d.ts +9 -1
- package/dist/audit/ifc-schema/datatype-check.d.ts.map +1 -1
- package/dist/audit/ifc-schema/datatype-check.js +24 -2
- package/dist/audit/ifc-schema/datatype-check.js.map +1 -1
- package/dist/audit/ifc-schema/entity-requirement.d.ts +21 -0
- package/dist/audit/ifc-schema/entity-requirement.d.ts.map +1 -0
- package/dist/audit/ifc-schema/entity-requirement.js +45 -0
- package/dist/audit/ifc-schema/entity-requirement.js.map +1 -0
- package/dist/audit/ifc-schema/index.d.ts.map +1 -1
- package/dist/audit/ifc-schema/index.js +105 -19
- package/dist/audit/ifc-schema/index.js.map +1 -1
- package/dist/audit/index.d.ts.map +1 -1
- package/dist/audit/index.js +8 -2
- package/dist/audit/index.js.map +1 -1
- package/dist/audit/parser-shim.d.ts +15 -1
- package/dist/audit/parser-shim.d.ts.map +1 -1
- package/dist/audit/parser-shim.js +2 -2
- package/dist/audit/parser-shim.js.map +1 -1
- package/dist/audit/structural/index.d.ts +3 -1
- package/dist/audit/structural/index.d.ts.map +1 -1
- package/dist/audit/structural/index.js +48 -179
- package/dist/audit/structural/index.js.map +1 -1
- package/dist/audit/structural/shapes.d.ts +47 -0
- package/dist/audit/structural/shapes.d.ts.map +1 -0
- package/dist/audit/structural/shapes.js +185 -0
- package/dist/audit/structural/shapes.js.map +1 -0
- package/dist/audit/types.d.ts +9 -1
- package/dist/audit/types.d.ts.map +1 -1
- package/dist/audit/xsd/index.js +1 -1
- package/dist/audit/xsd/index.js.map +1 -1
- package/dist/bounded-cache.d.ts +18 -0
- package/dist/bounded-cache.d.ts.map +1 -0
- package/dist/bounded-cache.js +40 -0
- package/dist/bounded-cache.js.map +1 -0
- package/dist/bridge/data-accessor.d.ts.map +1 -1
- package/dist/bridge/data-accessor.js +49 -25
- package/dist/bridge/data-accessor.js.map +1 -1
- package/dist/bridge/index.d.ts +1 -0
- package/dist/bridge/index.d.ts.map +1 -1
- package/dist/bridge/index.js +1 -0
- package/dist/bridge/index.js.map +1 -1
- package/dist/bridge/measure-conversion.d.ts +51 -0
- package/dist/bridge/measure-conversion.d.ts.map +1 -0
- package/dist/bridge/measure-conversion.js +106 -0
- package/dist/bridge/measure-conversion.js.map +1 -0
- package/dist/bridge/predefined-property-sets.d.ts +24 -0
- package/dist/bridge/predefined-property-sets.d.ts.map +1 -0
- package/dist/bridge/predefined-property-sets.js +86 -0
- package/dist/bridge/predefined-property-sets.js.map +1 -0
- package/dist/bridge/predefined-types.d.ts +34 -13
- package/dist/bridge/predefined-types.d.ts.map +1 -1
- package/dist/bridge/predefined-types.js +40 -71
- package/dist/bridge/predefined-types.js.map +1 -1
- package/dist/bridge/project-property.d.ts +43 -0
- package/dist/bridge/project-property.d.ts.map +1 -0
- package/dist/bridge/project-property.js +60 -0
- package/dist/bridge/project-property.js.map +1 -0
- package/dist/bridge/properties.d.ts +4 -3
- package/dist/bridge/properties.d.ts.map +1 -1
- package/dist/bridge/properties.js +64 -111
- package/dist/bridge/properties.js.map +1 -1
- package/dist/bridge/property-overlay-resolver.d.ts +10 -0
- package/dist/bridge/property-overlay-resolver.d.ts.map +1 -1
- package/dist/bridge/property-overlay-resolver.js +53 -4
- package/dist/bridge/property-overlay-resolver.js.map +1 -1
- package/dist/bridge/units.d.ts +49 -20
- package/dist/bridge/units.d.ts.map +1 -1
- package/dist/bridge/units.js +134 -84
- package/dist/bridge/units.js.map +1 -1
- package/dist/constraint-types.d.ts +30 -14
- package/dist/constraint-types.d.ts.map +1 -1
- package/dist/constraints/comparators.d.ts +4 -1
- package/dist/constraints/comparators.d.ts.map +1 -1
- package/dist/constraints/comparators.js +6 -1
- package/dist/constraints/comparators.js.map +1 -1
- package/dist/constraints/describe.d.ts.map +1 -1
- package/dist/constraints/describe.js +67 -21
- package/dist/constraints/describe.js.map +1 -1
- package/dist/constraints/match-bounds.d.ts +25 -0
- package/dist/constraints/match-bounds.d.ts.map +1 -0
- package/dist/constraints/match-bounds.js +112 -0
- package/dist/constraints/match-bounds.js.map +1 -0
- package/dist/constraints/match-family.d.ts.map +1 -1
- package/dist/constraints/match-family.js +25 -90
- package/dist/constraints/match-family.js.map +1 -1
- package/dist/constraints/xsd-datetime.js +6 -6
- package/dist/constraints/xsd-examples.d.ts +20 -0
- package/dist/constraints/xsd-examples.d.ts.map +1 -0
- package/dist/constraints/xsd-examples.js +187 -0
- package/dist/constraints/xsd-examples.js.map +1 -0
- package/dist/constraints/xsd-lexical.d.ts +2 -0
- package/dist/constraints/xsd-lexical.d.ts.map +1 -0
- package/dist/constraints/xsd-lexical.js +49 -0
- package/dist/constraints/xsd-lexical.js.map +1 -0
- package/dist/constraints/xsd-order.d.ts +33 -0
- package/dist/constraints/xsd-order.d.ts.map +1 -0
- package/dist/constraints/xsd-order.js +211 -0
- package/dist/constraints/xsd-order.js.map +1 -0
- package/dist/constraints/xsd-regex-ast.d.ts +37 -0
- package/dist/constraints/xsd-regex-ast.d.ts.map +1 -0
- package/dist/constraints/xsd-regex-ast.js +137 -0
- package/dist/constraints/xsd-regex-ast.js.map +1 -0
- package/dist/constraints/xsd-regex-blocks.d.ts +7 -0
- package/dist/constraints/xsd-regex-blocks.d.ts.map +1 -0
- package/dist/constraints/xsd-regex-blocks.js +68 -0
- package/dist/constraints/xsd-regex-blocks.js.map +1 -0
- package/dist/constraints/xsd-regex.d.ts +2 -45
- package/dist/constraints/xsd-regex.d.ts.map +1 -1
- package/dist/constraints/xsd-regex.js +231 -134
- package/dist/constraints/xsd-regex.js.map +1 -1
- package/dist/facets/entity-facet.d.ts.map +1 -1
- package/dist/facets/entity-facet.js +4 -1
- package/dist/facets/entity-facet.js.map +1 -1
- package/dist/facets/partof-facet.d.ts.map +1 -1
- package/dist/facets/partof-facet.js +80 -19
- package/dist/facets/partof-facet.js.map +1 -1
- package/dist/facets/predefined-type-match.d.ts +8 -3
- package/dist/facets/predefined-type-match.d.ts.map +1 -1
- package/dist/facets/predefined-type-match.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/parser/dom.d.ts +4 -0
- package/dist/parser/dom.d.ts.map +1 -1
- package/dist/parser/dom.js +5 -0
- package/dist/parser/dom.js.map +1 -1
- package/dist/parser/parse-restriction.d.ts.map +1 -1
- package/dist/parser/parse-restriction.js +32 -14
- package/dist/parser/parse-restriction.js.map +1 -1
- package/dist/parser/xml-parser.d.ts +7 -4
- package/dist/parser/xml-parser.d.ts.map +1 -1
- package/dist/parser/xml-parser.js +30 -45
- package/dist/parser/xml-parser.js.map +1 -1
- package/dist/preview/audit.d.ts +16 -0
- package/dist/preview/audit.d.ts.map +1 -0
- package/dist/preview/audit.js +58 -0
- package/dist/preview/audit.js.map +1 -0
- package/dist/preview/features.d.ts +30 -0
- package/dist/preview/features.d.ts.map +1 -0
- package/dist/preview/features.js +96 -0
- package/dist/preview/features.js.map +1 -0
- package/dist/preview/parse-ids11.d.ts +9 -0
- package/dist/preview/parse-ids11.d.ts.map +1 -0
- package/dist/preview/parse-ids11.js +90 -0
- package/dist/preview/parse-ids11.js.map +1 -0
- package/dist/preview/partof-nested.d.ts +27 -0
- package/dist/preview/partof-nested.d.ts.map +1 -0
- package/dist/preview/partof-nested.js +61 -0
- package/dist/preview/partof-nested.js.map +1 -0
- package/dist/preview/tolerance.d.ts +15 -0
- package/dist/preview/tolerance.d.ts.map +1 -0
- package/dist/preview/tolerance.js +66 -0
- package/dist/preview/tolerance.js.map +1 -0
- package/dist/preview/types.d.ts +67 -0
- package/dist/preview/types.d.ts.map +1 -0
- package/dist/preview/types.js +5 -0
- package/dist/preview/types.js.map +1 -0
- package/dist/report-types.d.ts +7 -0
- package/dist/report-types.d.ts.map +1 -1
- package/dist/translation/describe-constraint.js +16 -14
- package/dist/translation/describe-constraint.js.map +1 -1
- package/dist/translation/locales/de.d.ts +2 -0
- package/dist/translation/locales/de.d.ts.map +1 -1
- package/dist/translation/locales/de.js +2 -0
- package/dist/translation/locales/de.js.map +1 -1
- package/dist/translation/locales/en.d.ts +2 -0
- package/dist/translation/locales/en.d.ts.map +1 -1
- package/dist/translation/locales/en.js +2 -0
- package/dist/translation/locales/en.js.map +1 -1
- package/dist/translation/locales/fr.d.ts +2 -0
- package/dist/translation/locales/fr.d.ts.map +1 -1
- package/dist/translation/locales/fr.js +2 -0
- package/dist/translation/locales/fr.js.map +1 -1
- package/dist/translation/locales/index.d.ts +1 -0
- package/dist/translation/locales/index.d.ts.map +1 -1
- package/dist/translation/locales/index.js +1 -0
- package/dist/translation/locales/index.js.map +1 -1
- package/dist/translation/locales/it.d.ts +198 -0
- package/dist/translation/locales/it.d.ts.map +1 -0
- package/dist/translation/locales/it.js +235 -0
- package/dist/translation/locales/it.js.map +1 -0
- package/dist/translation/service.d.ts +2 -6
- package/dist/translation/service.d.ts.map +1 -1
- package/dist/translation/service.js +17 -25
- package/dist/translation/service.js.map +1 -1
- package/dist/types.d.ts +26 -31
- package/dist/types.d.ts.map +1 -1
- package/dist/validation/format-failure-reason.js +1 -1
- package/dist/validation/format-failure-reason.js.map +1 -1
- package/dist/validation/pass-rate.d.ts +14 -0
- package/dist/validation/pass-rate.d.ts.map +1 -0
- package/dist/validation/pass-rate.js +25 -0
- package/dist/validation/pass-rate.js.map +1 -0
- package/dist/validation/prohibited-specification.d.ts +31 -0
- package/dist/validation/prohibited-specification.d.ts.map +1 -0
- package/dist/validation/prohibited-specification.js +25 -0
- package/dist/validation/prohibited-specification.js.map +1 -0
- package/dist/validation/validator.d.ts +4 -2
- package/dist/validation/validator.d.ts.map +1 -1
- package/dist/validation/validator.js +23 -18
- package/dist/validation/validator.js.map +1 -1
- package/dist/writer/constraint.d.ts +8 -0
- package/dist/writer/constraint.d.ts.map +1 -0
- package/dist/writer/constraint.js +142 -0
- package/dist/writer/constraint.js.map +1 -0
- package/dist/writer/index.d.ts +48 -0
- package/dist/writer/index.d.ts.map +1 -0
- package/dist/writer/index.js +209 -0
- package/dist/writer/index.js.map +1 -0
- package/dist/writer/xml-lines.d.ts +17 -0
- package/dist/writer/xml-lines.d.ts.map +1 -0
- package/dist/writer/xml-lines.js +69 -0
- package/dist/writer/xml-lines.js.map +1 -0
- package/package.json +5 -5
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
4
|
import { compareBoolean, compareNumeric, compareString, isStrictNumericLiteral, isBooleanLiteral, } from './comparators.js';
|
|
5
5
|
import { isNumericXsdBase, isBooleanXsdBase } from './xsd-cast.js';
|
|
6
|
-
import { translateXsdRegex
|
|
7
|
-
import {
|
|
6
|
+
import { translateXsdRegex } from './xsd-regex.js';
|
|
7
|
+
import { matchBounds } from './match-bounds.js';
|
|
8
8
|
import { assertGuardedRegexPattern, UnsafeRegexPatternError } from '@ifc-lite/regex-guard';
|
|
9
9
|
/** Tolerance for the bounds matcher's exclusive comparators. */
|
|
10
10
|
export const NUMERIC_TOLERANCE = 1e-6;
|
|
@@ -67,7 +67,7 @@ function matchSimpleValue(constraint, actualValue, caseInsensitive, stringOnly =
|
|
|
67
67
|
// equality — skip the comparators that would return undefined anyway.
|
|
68
68
|
if (!isCoercibleSimpleValue(constraint))
|
|
69
69
|
return false;
|
|
70
|
-
const numericResult = compareNumeric(expected, actualValue);
|
|
70
|
+
const numericResult = compareNumeric(expected, actualValue, constraint.toleranceRule);
|
|
71
71
|
if (numericResult !== undefined)
|
|
72
72
|
return numericResult;
|
|
73
73
|
const booleanResult = compareBoolean(expected, actualValue);
|
|
@@ -115,6 +115,7 @@ function matchPattern(constraint, actualValue, caseInsensitive = false) {
|
|
|
115
115
|
* constraint object is stable per parsed document.
|
|
116
116
|
*/
|
|
117
117
|
const PATTERN_REGEX_CACHE = new WeakMap();
|
|
118
|
+
/** The cached whole-value `RegExp` for `constraint`, or null if it cannot compile. */
|
|
118
119
|
function compilePatternRegex(constraint, caseInsensitive) {
|
|
119
120
|
let entry = PATTERN_REGEX_CACHE.get(constraint);
|
|
120
121
|
if (!entry) {
|
|
@@ -129,6 +130,7 @@ function compilePatternRegex(constraint, caseInsensitive) {
|
|
|
129
130
|
}
|
|
130
131
|
return regex;
|
|
131
132
|
}
|
|
133
|
+
/** Compile one XSD pattern for whole-value matching; throws when it cannot be evaluated. */
|
|
132
134
|
function buildPatternRegex(xsdPattern, caseInsensitive) {
|
|
133
135
|
// Reject a catastrophic-backtracking or over-long pattern BEFORE any
|
|
134
136
|
// translation/compilation is attempted. This throws (rather than
|
|
@@ -139,21 +141,19 @@ function buildPatternRegex(xsdPattern, caseInsensitive) {
|
|
|
139
141
|
// `validateSpecification`, which turns the thrown error into a
|
|
140
142
|
// failed specification result.
|
|
141
143
|
assertGuardedRegexPattern(xsdPattern);
|
|
142
|
-
// Shared XSD → JS translation
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
// any-character placeholder: they over-match rather than invert intent,
|
|
154
|
-
// and the coherence auditor flags them.
|
|
144
|
+
// Shared XSD → JS translation (XML Schema Part 2 Appendix F, see
|
|
145
|
+
// `xsd-regex.ts`): multi-char escapes, `\p{Is…}` blocks, class
|
|
146
|
+
// subtraction and negated escapes inside classes are translated exactly,
|
|
147
|
+
// and `^` / `$` are literals. The result requires the `u` flag.
|
|
148
|
+
// A construct with no exact translation (an unknown block or property
|
|
149
|
+
// name, an escape XSD does not define, an undelimitable subtraction) is
|
|
150
|
+
// refused rather than approximated: an any-character placeholder passed
|
|
151
|
+
// every value silently (#7400), and dropping a subtraction's exclusion
|
|
152
|
+
// accepted exactly the values it was written to exclude (#5183).
|
|
153
|
+
// `UnsafeRegexPatternError` becomes a failed specification result in
|
|
154
|
+
// `validateSpecification`, never a silent pass.
|
|
155
155
|
const { pattern, supported, reason } = translateXsdRegex(xsdPattern);
|
|
156
|
-
if (!supported
|
|
156
|
+
if (!supported) {
|
|
157
157
|
throw new UnsafeRegexPatternError(xsdPattern, reason);
|
|
158
158
|
}
|
|
159
159
|
// IDS patterns must match the entire lexical value. Wrapping in a
|
|
@@ -167,8 +167,13 @@ function buildPatternRegex(xsdPattern, caseInsensitive) {
|
|
|
167
167
|
}
|
|
168
168
|
catch {
|
|
169
169
|
// Some patterns are valid under JS's lenient (Annex-B) dialect but
|
|
170
|
-
// rejected under `u
|
|
171
|
-
// matching
|
|
170
|
+
// rejected under `u` (a lone `{` or `]`). Retry without it so plain
|
|
171
|
+
// patterns keep matching — but only when the translation emitted no
|
|
172
|
+
// `\p{…}` / `\P{…}` / `\u{…}`: without `u` those silently mean the
|
|
173
|
+
// literal text `p{L}` or a repeated `u`, which made e.g. `\p{L}+…`
|
|
174
|
+
// fail every value instead of reporting the bad pattern (#7400).
|
|
175
|
+
if (/\\[pPu]\{/.test(pattern))
|
|
176
|
+
return null;
|
|
172
177
|
try {
|
|
173
178
|
return new RegExp(anchored, caseInsensitive ? 'i' : '');
|
|
174
179
|
}
|
|
@@ -228,7 +233,7 @@ function matchEnumeration(constraint, actualValue, caseInsensitive, stringOnly =
|
|
|
228
233
|
const stringResult = compareString(v, actualValue, caseInsensitive);
|
|
229
234
|
if (stringResult !== undefined)
|
|
230
235
|
return stringResult;
|
|
231
|
-
const numericResult = compareNumeric(v, actualValue);
|
|
236
|
+
const numericResult = compareNumeric(v, actualValue, constraint.toleranceRule);
|
|
232
237
|
if (numericResult !== undefined)
|
|
233
238
|
return numericResult;
|
|
234
239
|
const booleanResult = compareBoolean(v, actualValue);
|
|
@@ -237,74 +242,4 @@ function matchEnumeration(constraint, actualValue, caseInsensitive, stringOnly =
|
|
|
237
242
|
return false;
|
|
238
243
|
});
|
|
239
244
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Match against numeric bounds
|
|
242
|
-
*/
|
|
243
|
-
function matchBounds(constraint, actualValue) {
|
|
244
|
-
// A facet element was present in the source `<xs:restriction>` but
|
|
245
|
-
// its `@value` could not be parsed (typo, wrong decimal separator, a
|
|
246
|
-
// negative digit-count facet, …). `parseRestriction` dropped it to
|
|
247
|
-
// `undefined` the same as a facet that was never present at all —
|
|
248
|
-
// which would otherwise make this an unconditional pass (an
|
|
249
|
-
// all-`undefined` bounds constraint satisfies every numeric value).
|
|
250
|
-
// Fail closed instead: we cannot verify compliance against a
|
|
251
|
-
// restriction we could not fully parse, so no value passes until the
|
|
252
|
-
// IDS is corrected. See `getBoundsMismatchReason` for the
|
|
253
|
-
// author-facing explanation and `audit/coherence` for the
|
|
254
|
-
// corresponding lint diagnostic.
|
|
255
|
-
if (constraint.unparseableFacets !== undefined && constraint.unparseableFacets.length > 0) {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
// String-length facets (xs:length / xs:minLength / xs:maxLength)
|
|
259
|
-
// operate on the textual length, not on numeric magnitude. When any
|
|
260
|
-
// of them are present, evaluate the length constraints first.
|
|
261
|
-
if (constraint.length !== undefined ||
|
|
262
|
-
constraint.minLength !== undefined ||
|
|
263
|
-
constraint.maxLength !== undefined) {
|
|
264
|
-
const str = String(actualValue);
|
|
265
|
-
if (constraint.length !== undefined && str.length !== constraint.length) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
if (constraint.minLength !== undefined && str.length < constraint.minLength) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
if (constraint.maxLength !== undefined && str.length > constraint.maxLength) {
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
// Length-only restrictions don't impose numeric bounds; if the
|
|
275
|
-
// constraint also carries min/max/totalDigits/fractionDigits we
|
|
276
|
-
// fall through to the numeric check below (rare in practice).
|
|
277
|
-
if (constraint.minInclusive === undefined &&
|
|
278
|
-
constraint.maxInclusive === undefined &&
|
|
279
|
-
constraint.minExclusive === undefined &&
|
|
280
|
-
constraint.maxExclusive === undefined &&
|
|
281
|
-
constraint.totalDigits === undefined &&
|
|
282
|
-
constraint.fractionDigits === undefined) {
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
const num = typeof actualValue === 'number'
|
|
287
|
-
? actualValue
|
|
288
|
-
: parseFloat(String(actualValue));
|
|
289
|
-
if (isNaN(num))
|
|
290
|
-
return false;
|
|
291
|
-
if (constraint.minInclusive !== undefined &&
|
|
292
|
-
num < constraint.minInclusive) {
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
if (constraint.maxInclusive !== undefined &&
|
|
296
|
-
num > constraint.maxInclusive) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
if (constraint.minExclusive !== undefined && num <= constraint.minExclusive) {
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
if (constraint.maxExclusive !== undefined && num >= constraint.maxExclusive) {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
const digitsOk = matchDigitFacets(constraint, actualValue);
|
|
306
|
-
if (digitsOk === false)
|
|
307
|
-
return false;
|
|
308
|
-
return true;
|
|
309
|
-
}
|
|
310
245
|
//# sourceMappingURL=match-family.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-family.js","sourceRoot":"","sources":["../../src/constraints/match-family.ts"],"names":[],"mappings":"AAAA;;+DAE+D;
|
|
1
|
+
{"version":3,"file":"match-family.js","sourceRoot":"","sources":["../../src/constraints/match-family.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAyB/D,OAAO,EACL,cAAc,EACd,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAE3F,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAyB;IAEzB,OAAO,UAAU,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,UAAyB,EACzB,WAAsC,EACtC,EAAW,EACX,UAAU,GAAG,KAAK;IAElB,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,KAAK,aAAa;YAChB,OAAO,gBAAgB,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QACnE,KAAK,SAAS;YACZ,OAAO,YAAY,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;QACnD,KAAK,aAAa;YAChB,OAAO,gBAAgB,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QACnE,KAAK,QAAQ;YACX,OAAO,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,CAA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AI,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IACtC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,eAAe,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5E,uDAAuD;IACvD,IAAI,UAAU;QAAE,OAAO,KAAK,CAAC;IAC7B,kEAAkE;IAClE,kEAAkE;IAClE,IAAI,CAAC,IAAI,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAErC,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QAClC,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;QACpE,IAAI,YAAY,KAAK,SAAS;YAAE,OAAO,YAAY,CAAC;QACpD,MAAM,aAAa,GAAG,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;QAC/E,IAAI,aAAa,KAAK,SAAS;YAAE,OAAO,aAAa,CAAC;QACtD,MAAM,aAAa,GAAG,cAAc,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;QACrD,IAAI,aAAa,KAAK,SAAS;YAAE,OAAO,aAAa,CAAC;QACtD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
* for these types encodes every one of those bounds except day-in-month, which
|
|
14
14
|
* it states as an assertion because no regex can express it.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
* `xs:restriction @base` check
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
16
|
+
* Several places decide the same question — the coherence audit's
|
|
17
|
+
* `xs:restriction @base` check and the `info/date` conformance check in
|
|
18
|
+
* `audit/xsd/index.ts` (both through `isValidLexicalForXsType` in
|
|
19
|
+
* `xsd-lexical.ts`), the facets' strict-cast gate, and the bound reader in
|
|
20
|
+
* `xsd-order.ts` (#7399) — so the calendar lives here once instead of in a
|
|
21
|
+
* regex table per caller.
|
|
22
22
|
*/
|
|
23
23
|
/** Hour 24 is end-of-day, so any fractional seconds on it must be zero. */
|
|
24
24
|
const ALL_ZERO_FRACTION = /^0+$/;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface PatternExampleOptions {
|
|
2
|
+
/** How many examples of each kind to return at most (default 5). */
|
|
3
|
+
count?: number;
|
|
4
|
+
/** Seed of the deterministic random walk (default 1). */
|
|
5
|
+
seed?: number;
|
|
6
|
+
/** Extra repetitions beyond a quantifier's minimum (default 3). */
|
|
7
|
+
maxRepeat?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface PatternExamples {
|
|
10
|
+
pattern: string;
|
|
11
|
+
/** Simplest first: the first entry uses every quantifier's minimum where possible. */
|
|
12
|
+
matching: string[];
|
|
13
|
+
/** Near misses first (one edit away from a matching example). */
|
|
14
|
+
nonMatching: string[];
|
|
15
|
+
/** False when the pattern cannot be checked (parse error, ReDoS guard). */
|
|
16
|
+
supported: boolean;
|
|
17
|
+
reason: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function generatePatternExamples(pattern: string, options?: PatternExampleOptions): PatternExamples;
|
|
20
|
+
//# sourceMappingURL=xsd-examples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-examples.d.ts","sourceRoot":"","sources":["../../src/constraints/xsd-examples.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,qBAAqB;IACpC,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,sFAAsF;IACtF,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,iEAAiE;IACjE,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,2EAA2E;IAC3E,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAsHD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,eAAe,CAqC7G"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
/**
|
|
5
|
+
* Example strings for an XSD pattern: values that match it and values that
|
|
6
|
+
* do not. Used to explain a pattern to an author ("matches: EI30, EI60;
|
|
7
|
+
* does not match: E30") and to build synthetic IFC test fixtures
|
|
8
|
+
* (`@ifc-lite/ids-testgen`).
|
|
9
|
+
*
|
|
10
|
+
* Candidates come from a random walk over the parsed pattern
|
|
11
|
+
* (`xsd-regex-ast.ts`); every candidate is then checked with
|
|
12
|
+
* `matchConstraint`, the exact function validation uses. So an example is
|
|
13
|
+
* never wrong about the checker: a "matching" example matches, a
|
|
14
|
+
* "non-matching" one does not. What the generator can miss is coverage (a
|
|
15
|
+
* satisfiable pattern for which no candidate was found); the property
|
|
16
|
+
* tests measure that.
|
|
17
|
+
*/
|
|
18
|
+
import { UnsafeRegexPatternError } from '@ifc-lite/regex-guard';
|
|
19
|
+
import { matchConstraint } from './index.js';
|
|
20
|
+
import { parseXsdRegex, XsdParseError } from './xsd-regex-ast.js';
|
|
21
|
+
import { translateXsdRegex } from './xsd-regex.js';
|
|
22
|
+
/**
|
|
23
|
+
* Characters tried for every class: printable ASCII plus a few letters,
|
|
24
|
+
* digits and symbols from other scripts, so `\d`, `\w`, `\i`, `\p{Lu}` and
|
|
25
|
+
* negated classes have members to pick from.
|
|
26
|
+
*/
|
|
27
|
+
const ALPHABET = [
|
|
28
|
+
...Array.from({ length: 95 }, (_, k) => String.fromCharCode(32 + k)),
|
|
29
|
+
'\t',
|
|
30
|
+
...'ÄäÖöÜüßéèçñÅøæ€°²µ·×÷αβΩЖж中日٣३١',
|
|
31
|
+
];
|
|
32
|
+
function mulberry32(seed) {
|
|
33
|
+
let a = seed >>> 0;
|
|
34
|
+
return () => {
|
|
35
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
36
|
+
let t = a;
|
|
37
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
38
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
39
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Characters a class source mentions, plus range midpoints. */
|
|
43
|
+
function mentioned(source) {
|
|
44
|
+
const out = [];
|
|
45
|
+
const chars = [...source];
|
|
46
|
+
chars.forEach((c, k) => {
|
|
47
|
+
if (c === '-' && k > 0 && k + 1 < chars.length) {
|
|
48
|
+
const lo = chars[k - 1].codePointAt(0) ?? 0;
|
|
49
|
+
const hi = chars[k + 1].codePointAt(0) ?? 0;
|
|
50
|
+
if (hi > lo)
|
|
51
|
+
out.push(String.fromCodePoint(lo + Math.floor((hi - lo) / 2)), String.fromCodePoint(hi));
|
|
52
|
+
}
|
|
53
|
+
out.push(c);
|
|
54
|
+
});
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
class Sampler {
|
|
58
|
+
rng;
|
|
59
|
+
maxRepeat;
|
|
60
|
+
members = new Map();
|
|
61
|
+
constructor(rng, maxRepeat) {
|
|
62
|
+
this.rng = rng;
|
|
63
|
+
this.maxRepeat = maxRepeat;
|
|
64
|
+
}
|
|
65
|
+
/** Members of a class (by its XSD source), per the shared translator. */
|
|
66
|
+
membersOf(source) {
|
|
67
|
+
let list = this.members.get(source);
|
|
68
|
+
if (list)
|
|
69
|
+
return list;
|
|
70
|
+
const { pattern } = translateXsdRegex(source);
|
|
71
|
+
// Compiled as the checker compiles it: under `u`, else without it.
|
|
72
|
+
let re = /(?!)/;
|
|
73
|
+
for (const flags of ['u', '']) {
|
|
74
|
+
try {
|
|
75
|
+
re = new RegExp(`^(?:${pattern})$`, flags);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (!(err instanceof SyntaxError))
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
list = [...new Set([...ALPHABET, ...mentioned(source)])].filter((c) => re.test(c));
|
|
84
|
+
this.members.set(source, list);
|
|
85
|
+
return list;
|
|
86
|
+
}
|
|
87
|
+
/** One candidate for `node`; `minimal` takes each quantifier's minimum and the first branch. */
|
|
88
|
+
walk(node, minimal) {
|
|
89
|
+
switch (node.type) {
|
|
90
|
+
case 'char':
|
|
91
|
+
return node.value;
|
|
92
|
+
case 'class': {
|
|
93
|
+
const list = this.membersOf(node.source);
|
|
94
|
+
if (!list.length)
|
|
95
|
+
return undefined;
|
|
96
|
+
return minimal ? list[0] : list[Math.floor(this.rng() * list.length)];
|
|
97
|
+
}
|
|
98
|
+
case 'group':
|
|
99
|
+
return this.walk(node.body, minimal);
|
|
100
|
+
case 'alt': {
|
|
101
|
+
const branch = minimal ? node.branches[0] : node.branches[Math.floor(this.rng() * node.branches.length)];
|
|
102
|
+
let out = '';
|
|
103
|
+
for (const item of branch) {
|
|
104
|
+
const part = this.walk(item, minimal);
|
|
105
|
+
if (part === undefined)
|
|
106
|
+
return undefined;
|
|
107
|
+
out += part;
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
case 'repeat': {
|
|
112
|
+
const top = Math.min(node.max, node.min + this.maxRepeat);
|
|
113
|
+
const n = minimal ? node.min : node.min + Math.floor(this.rng() * (top - node.min + 1));
|
|
114
|
+
let out = '';
|
|
115
|
+
for (let k = 0; k < n; k++) {
|
|
116
|
+
const part = this.walk(node.node, minimal);
|
|
117
|
+
if (part === undefined)
|
|
118
|
+
return undefined;
|
|
119
|
+
out += part;
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** One-edit variations of `s`, near misses first. */
|
|
127
|
+
function variations(s, rng) {
|
|
128
|
+
const chars = [...s];
|
|
129
|
+
const out = [];
|
|
130
|
+
const pick = () => ALPHABET[Math.floor(rng() * ALPHABET.length)];
|
|
131
|
+
for (let k = 0; k < Math.min(chars.length, 6); k++) {
|
|
132
|
+
out.push([...chars.slice(0, k), pick(), ...chars.slice(k + 1)].join(''));
|
|
133
|
+
out.push([...chars.slice(0, k), ...chars.slice(k + 1)].join(''));
|
|
134
|
+
}
|
|
135
|
+
out.push(`${s}${pick()}`, `${pick()}${s}`, `${s}${s}`, s.toLowerCase(), s.toUpperCase(), `${s} `);
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
export function generatePatternExamples(pattern, options = {}) {
|
|
139
|
+
const count = options.count ?? 5;
|
|
140
|
+
const rng = mulberry32(options.seed ?? 1);
|
|
141
|
+
const result = { pattern, matching: [], nonMatching: [], supported: true, reason: '' };
|
|
142
|
+
let tree;
|
|
143
|
+
try {
|
|
144
|
+
tree = parseXsdRegex(pattern);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
if (!(err instanceof XsdParseError))
|
|
148
|
+
throw err;
|
|
149
|
+
return { ...result, supported: false, reason: err.message };
|
|
150
|
+
}
|
|
151
|
+
const constraint = { type: 'pattern', pattern };
|
|
152
|
+
const matches = (s) => matchConstraint(constraint, s);
|
|
153
|
+
try {
|
|
154
|
+
matches('');
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
if (!(err instanceof UnsafeRegexPatternError))
|
|
158
|
+
throw err;
|
|
159
|
+
return { ...result, supported: false, reason: err.message };
|
|
160
|
+
}
|
|
161
|
+
const sampler = new Sampler(rng, options.maxRepeat ?? 3);
|
|
162
|
+
const seen = { true: new Set(), false: new Set() };
|
|
163
|
+
const keep = (list, s, want) => {
|
|
164
|
+
if (s === undefined || list.length >= count)
|
|
165
|
+
return;
|
|
166
|
+
const tried = seen[`${want}`];
|
|
167
|
+
if (tried.has(s))
|
|
168
|
+
return;
|
|
169
|
+
tried.add(s);
|
|
170
|
+
if (matches(s) === want)
|
|
171
|
+
list.push(s);
|
|
172
|
+
};
|
|
173
|
+
keep(result.matching, sampler.walk(tree, true), true);
|
|
174
|
+
for (let tries = 0; tries < count * 40 && result.matching.length < count; tries++)
|
|
175
|
+
keep(result.matching, sampler.walk(tree, false), true);
|
|
176
|
+
for (const m of result.matching)
|
|
177
|
+
for (const v of variations(m, rng))
|
|
178
|
+
keep(result.nonMatching, v, false);
|
|
179
|
+
for (const s of ['', '\n', 'x', '0', ' '])
|
|
180
|
+
keep(result.nonMatching, s, false);
|
|
181
|
+
for (let tries = 0; tries < count * 40 && result.nonMatching.length < count; tries++) {
|
|
182
|
+
const len = 1 + Math.floor(rng() * 8);
|
|
183
|
+
keep(result.nonMatching, Array.from({ length: len }, () => ALPHABET[Math.floor(rng() * ALPHABET.length)]).join(''), false);
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=xsd-examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-examples.js","sourceRoot":"","sources":["../../src/constraints/xsd-examples.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAgB,MAAM,oBA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;QACrF,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7H,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-lexical.d.ts","sourceRoot":"","sources":["../../src/constraints/xsd-lexical.ts"],"names":[],"mappings":"AAoCA,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAY5E"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
/**
|
|
5
|
+
* Whether a literal is in the lexical space of an `xs:restriction @base`.
|
|
6
|
+
*
|
|
7
|
+
* Moved here from `audit/coherence` so the restriction PARSER can ask the
|
|
8
|
+
* same question the auditor asks (#7399): a bound is read under its base, and
|
|
9
|
+
* the parser may not import from `audit/`. One answer, two callers, so an
|
|
10
|
+
* enumeration value and a bound under the same base cannot disagree.
|
|
11
|
+
*/
|
|
12
|
+
import { XSD_NUMERIC_SPECIALS } from './xsd-cast.js';
|
|
13
|
+
import { isValidXsdDateTimeLiteral, isXsdDateTimeBase } from './xsd-datetime.js';
|
|
14
|
+
/**
|
|
15
|
+
* Validate that `value` matches the lexical space of the supplied XSD
|
|
16
|
+
* primitive base. Mirrors upstream `XsTypes.IsValid` (see the table, and the
|
|
17
|
+
* date family it hands off); flags `<xs:enumeration value="12,0"/>` under
|
|
18
|
+
* `<xs:restriction base="xs:double">`.
|
|
19
|
+
*/
|
|
20
|
+
const XS_VALUE_REGEX = {
|
|
21
|
+
// Upstream `XmlRegex.cs`, except the mantissa: `[0-9]*(?:\.[0-9]*)?` not
|
|
22
|
+
// `[0-9]*\.?[0-9]*`, whose two adjacent digit runs make a failing lexeme
|
|
23
|
+
// retry every split (quadratic, #3113). Same language, one parse/prefix.
|
|
24
|
+
'xs:integer': /^[+-]?(\d+)$/,
|
|
25
|
+
'xs:double': /^([-+]?[0-9]*(?:\.[0-9]*)?([eE][-+]?[0-9]+)?|NaN|\+INF|-INF)$/,
|
|
26
|
+
'xs:float': /^([-+]?[0-9]*(?:\.[0-9]*)?([eE][-+]?[0-9]+)?|NaN|\+INF|-INF)$/,
|
|
27
|
+
'xs:decimal': /^([-+]?[0-9]*(?:\.[0-9]*)?([eE][-+]?[0-9]+)?|NaN|\+INF|-INF)$/,
|
|
28
|
+
'xs:boolean': /^(true|false|0|1)$/,
|
|
29
|
+
// The date family is absent on purpose: its value space is a calendar, not a
|
|
30
|
+
// digit-run shape, so it goes through `isValidXsdDateTimeLiteral` (#3721).
|
|
31
|
+
'xs:duration': /^[-+]?P(\d+Y)?(\d+M)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$/,
|
|
32
|
+
};
|
|
33
|
+
export function isValidLexicalForXsType(value, base) {
|
|
34
|
+
if (isXsdDateTimeBase(base))
|
|
35
|
+
return isValidXsdDateTimeLiteral(value, base);
|
|
36
|
+
const rx = XS_VALUE_REGEX[base];
|
|
37
|
+
if (!rx)
|
|
38
|
+
return true; // base we don't recognise → don't fabricate errors
|
|
39
|
+
if (base === 'xs:double' || base === 'xs:float' || base === 'xs:decimal') {
|
|
40
|
+
// Digit required in the MANTISSA, specials exempt (#3336). Testing the
|
|
41
|
+
// whole lexeme accepted 'e5' on the exponent's digit and rejected the
|
|
42
|
+
// digitless specials, which is how this and `literalCastsUnder` disagreed.
|
|
43
|
+
const bare = !XSD_NUMERIC_SPECIALS.has(value);
|
|
44
|
+
if (bare && !/[0-9]/.test(value.split(/[eE]/)[0]))
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return rx.test(value);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=xsd-lexical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-lexical.js","sourceRoot":"","sources":["../../src/constraints/xsd-lexical.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,cAAc,GAA2B;IAC7C,yEAAyE;IACzE,yEAAyE;IACzE,yEAAyE;IACzE,YAAY,EAAE,cAAc;IAC5B,WAAW,EAAE,+DAA+D;IAC5E,UAAU,EAAE,+DAA+D;IAC3E,YAAY,EAAE,+DAA+D;IAC7E,YAAY,EAAE,oBAAoB;IAClC,6EAA6E;IAC7E,2EAA2E;IAC3E,aAAa,EAAE,wDAAwD;CACxE,CAAC;AAEF,MAAM,UAAU,uBAAuB,CAAC,KAAa,EAAE,IAAY;IACjE,IAAI,iBAAiB,CAAC,IAAI,CAAC;QAAE,OAAO,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC3E,MAAM,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC,CAAC,mDAAmD;IACzE,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QACzE,uEAAuE;QACvE,sEAAsE;QACtE,2EAA2E;QAC3E,MAAM,IAAI,GAAG,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAClE,CAAC;IACD,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** How a base orders its bounds. */
|
|
2
|
+
export type BoundOrder = 'numeric' | 'temporal' | 'duration';
|
|
3
|
+
/**
|
|
4
|
+
* The order a restriction's bounds live in. A base that orders by neither
|
|
5
|
+
* the time line nor duration (numeric, `xs:string`, absent) keeps the numeric
|
|
6
|
+
* reading bounds have always had, now strict.
|
|
7
|
+
*/
|
|
8
|
+
export declare function boundOrderOf(base: string | undefined): BoundOrder;
|
|
9
|
+
/**
|
|
10
|
+
* A bound or value under a numeric base: the number its WHOLE text denotes,
|
|
11
|
+
* or `undefined`. `xs:integer` and its derivations reject a fraction; every
|
|
12
|
+
* other base takes the `xs:double` lexical space, except that only
|
|
13
|
+
* `xs:double` and `xs:float` have infinities — `+INF` under `xs:decimal`,
|
|
14
|
+
* `xs:string` or no base is not a number (PR #7411 review). `NaN` is a
|
|
15
|
+
* lexeme of `xs:double` but orders nothing, so it is not a usable bound
|
|
16
|
+
* either. Surrounding whitespace is collapsed, as XSD does for every
|
|
17
|
+
* numeric type.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readNumeric(raw: string, base: string | undefined): number | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* A bound under a temporal or duration base, as its validated, trimmed
|
|
22
|
+
* lexeme; `undefined` when it is not in the base's value space.
|
|
23
|
+
*/
|
|
24
|
+
export declare function readOrderedLexeme(raw: string, base: string | undefined): string | undefined;
|
|
25
|
+
/** Whether `value` is in the value space of a temporal or duration `base`. */
|
|
26
|
+
export declare function isOrderedValue(value: string, base: string | undefined): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Order `value` against `bound` under a temporal or duration `base`: -1, 0 or
|
|
29
|
+
* 1, or `undefined` when `value` is not in the base's value space or XSD
|
|
30
|
+
* leaves the pair unordered. Callers fail closed on `undefined`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function compareOrdered(value: string | number | boolean, bound: string, base: string | undefined): -1 | 0 | 1 | undefined;
|
|
33
|
+
//# sourceMappingURL=xsd-order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-order.d.ts","sourceRoot":"","sources":["../../src/constraints/xsd-order.ts"],"names":[],"mappings":"AA8BA,oCAAoC;AACpC,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAoB7D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAGjE;AAKD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAYrF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAG3F;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAE/E;AAuID;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,EAChC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAQxB"}
|