@ifc-lite/ids 3.1.0 → 3.3.2
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
|
@@ -0,0 +1,211 @@
|
|
|
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
|
+
* Reading and ordering `xs:restriction` bound facets by the restriction's
|
|
6
|
+
* `@base` (#7399).
|
|
7
|
+
*
|
|
8
|
+
* `parseFloat` read every bound, and every value it bounded, whatever the
|
|
9
|
+
* base: `2024-03-31` became 2024 and `6,5` became 6, so a date range collapsed
|
|
10
|
+
* to one year and a malformed bound silently truncated. Here a bound is read
|
|
11
|
+
* only when its whole text is in the base's lexical space, and compared in the
|
|
12
|
+
* base's own order:
|
|
13
|
+
*
|
|
14
|
+
* - numeric bases: a number, accepted only as a whole lexeme of the base
|
|
15
|
+
* (`xs:integer` and its derivations take no fraction);
|
|
16
|
+
* - `xs:date` / `xs:dateTime` / `xs:time`: a point on the time line,
|
|
17
|
+
* normalised to UTC, with XSD's ±14:00 rule for a zone-less value against a
|
|
18
|
+
* zoned one (Part 2 §3.2.7.4);
|
|
19
|
+
* - `xs:duration`: XSD's partial order, decided at the four reference
|
|
20
|
+
* instants the spec names (§3.2.6.2).
|
|
21
|
+
*
|
|
22
|
+
* Where XSD calls an order indeterminate, `compareOrdered` returns
|
|
23
|
+
* `undefined`, and the matcher fails closed.
|
|
24
|
+
*/
|
|
25
|
+
import { isWhollyNumeric } from '@ifc-lite/encoding';
|
|
26
|
+
import { isValidXsdDateTimeLiteral } from './xsd-datetime.js';
|
|
27
|
+
import { isValidLexicalForXsType } from './xsd-lexical.js';
|
|
28
|
+
const INTEGER_LOCALS = new Set([
|
|
29
|
+
'integer', 'long', 'int', 'short', 'byte',
|
|
30
|
+
'nonNegativeInteger', 'positiveInteger', 'nonPositiveInteger', 'negativeInteger',
|
|
31
|
+
'unsignedLong', 'unsignedInt', 'unsignedShort', 'unsignedByte',
|
|
32
|
+
]);
|
|
33
|
+
/** `xs:date`, `xsd:date` and `date` all name the same base. */
|
|
34
|
+
function localName(base) {
|
|
35
|
+
if (!base)
|
|
36
|
+
return '';
|
|
37
|
+
const colon = base.lastIndexOf(':');
|
|
38
|
+
return colon >= 0 ? base.slice(colon + 1) : base;
|
|
39
|
+
}
|
|
40
|
+
function dateTimeBaseOf(base) {
|
|
41
|
+
const local = localName(base);
|
|
42
|
+
return local === 'date' || local === 'dateTime' || local === 'time' ? `xs:${local}` : undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The order a restriction's bounds live in. A base that orders by neither
|
|
46
|
+
* the time line nor duration (numeric, `xs:string`, absent) keeps the numeric
|
|
47
|
+
* reading bounds have always had, now strict.
|
|
48
|
+
*/
|
|
49
|
+
export function boundOrderOf(base) {
|
|
50
|
+
if (dateTimeBaseOf(base) !== undefined)
|
|
51
|
+
return 'temporal';
|
|
52
|
+
return localName(base) === 'duration' ? 'duration' : 'numeric';
|
|
53
|
+
}
|
|
54
|
+
/** The bases whose value space includes the infinities (`+INF`, `-INF`). */
|
|
55
|
+
const INFINITE_LOCALS = new Set(['double', 'float']);
|
|
56
|
+
/**
|
|
57
|
+
* A bound or value under a numeric base: the number its WHOLE text denotes,
|
|
58
|
+
* or `undefined`. `xs:integer` and its derivations reject a fraction; every
|
|
59
|
+
* other base takes the `xs:double` lexical space, except that only
|
|
60
|
+
* `xs:double` and `xs:float` have infinities — `+INF` under `xs:decimal`,
|
|
61
|
+
* `xs:string` or no base is not a number (PR #7411 review). `NaN` is a
|
|
62
|
+
* lexeme of `xs:double` but orders nothing, so it is not a usable bound
|
|
63
|
+
* either. Surrounding whitespace is collapsed, as XSD does for every
|
|
64
|
+
* numeric type.
|
|
65
|
+
*/
|
|
66
|
+
export function readNumeric(raw, base) {
|
|
67
|
+
const text = raw.trim();
|
|
68
|
+
const local = localName(base);
|
|
69
|
+
const integer = INTEGER_LOCALS.has(local);
|
|
70
|
+
if (!isValidLexicalForXsType(text, integer ? 'xs:integer' : 'xs:double'))
|
|
71
|
+
return undefined;
|
|
72
|
+
if (text === '+INF' || text === '-INF') {
|
|
73
|
+
if (!INFINITE_LOCALS.has(local))
|
|
74
|
+
return undefined;
|
|
75
|
+
return text === '+INF' ? Infinity : -Infinity;
|
|
76
|
+
}
|
|
77
|
+
if (!isWhollyNumeric(text))
|
|
78
|
+
return undefined;
|
|
79
|
+
const n = Number(text);
|
|
80
|
+
return Number.isFinite(n) ? n : undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A bound under a temporal or duration base, as its validated, trimmed
|
|
84
|
+
* lexeme; `undefined` when it is not in the base's value space.
|
|
85
|
+
*/
|
|
86
|
+
export function readOrderedLexeme(raw, base) {
|
|
87
|
+
const text = raw.trim();
|
|
88
|
+
return parseKey(text, base) === undefined ? undefined : text;
|
|
89
|
+
}
|
|
90
|
+
/** Whether `value` is in the value space of a temporal or duration `base`. */
|
|
91
|
+
export function isOrderedValue(value, base) {
|
|
92
|
+
return parseKey(value.trim(), base) !== undefined;
|
|
93
|
+
}
|
|
94
|
+
/** Days since 1970-01-01 in the proleptic Gregorian calendar (Hinnant). */
|
|
95
|
+
function daysFromCivil(year, month, day) {
|
|
96
|
+
const y = month <= 2 ? year - 1 : year;
|
|
97
|
+
const era = Math.floor(y / 400);
|
|
98
|
+
const yoe = y - era * 400;
|
|
99
|
+
const doy = Math.floor((153 * ((month + 9) % 12) + 2) / 5) + day - 1;
|
|
100
|
+
const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
|
|
101
|
+
return era * 146097 + doe - 719468;
|
|
102
|
+
}
|
|
103
|
+
const DATE_TIME_PARTS = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?$/;
|
|
104
|
+
/** XSD 1.0 maps an `xs:time` onto this date to order it (§3.2.8). */
|
|
105
|
+
const TIME_REFERENCE_DATE = '1972-12-31T';
|
|
106
|
+
function toInstant(text, base) {
|
|
107
|
+
if (!isValidXsdDateTimeLiteral(text, base))
|
|
108
|
+
return undefined;
|
|
109
|
+
const m = DATE_TIME_PARTS.exec(base === 'xs:time' ? TIME_REFERENCE_DATE + text : text);
|
|
110
|
+
if (!m)
|
|
111
|
+
return undefined;
|
|
112
|
+
const [, y, mo, d, h = '0', mi = '0', s = '0', frac = '', tz] = m;
|
|
113
|
+
let seconds = daysFromCivil(Number(y), Number(mo), Number(d)) * 86400 +
|
|
114
|
+
Number(h) * 3600 + Number(mi) * 60 + Number(s);
|
|
115
|
+
if (tz !== undefined && tz !== 'Z') {
|
|
116
|
+
const offset = (Number(tz.slice(1, 3)) * 60 + Number(tz.slice(4, 6))) * 60;
|
|
117
|
+
seconds -= tz[0] === '+' ? offset : -offset;
|
|
118
|
+
}
|
|
119
|
+
return { seconds, fraction: frac.replace(/0+$/, ''), zoned: tz !== undefined };
|
|
120
|
+
}
|
|
121
|
+
function sign(n) {
|
|
122
|
+
return n < 0 ? -1 : n > 0 ? 1 : 0;
|
|
123
|
+
}
|
|
124
|
+
function compareAt(aSeconds, aFraction, bSeconds, bFraction) {
|
|
125
|
+
if (aSeconds !== bSeconds)
|
|
126
|
+
return sign(aSeconds - bSeconds);
|
|
127
|
+
const width = Math.max(aFraction.length, bFraction.length);
|
|
128
|
+
const fa = aFraction.padEnd(width, '0');
|
|
129
|
+
const fb = bFraction.padEnd(width, '0');
|
|
130
|
+
return fa === fb ? 0 : fa < fb ? -1 : 1;
|
|
131
|
+
}
|
|
132
|
+
/** XSD's widest zone offset, in seconds: a zone-less value spans ±14:00. */
|
|
133
|
+
const ZONE_SPAN = 14 * 3600;
|
|
134
|
+
function compareInstants(a, b) {
|
|
135
|
+
if (a.zoned === b.zoned)
|
|
136
|
+
return compareAt(a.seconds, a.fraction, b.seconds, b.fraction);
|
|
137
|
+
// One side has no zone, so it stands for every instant within ±14:00 of
|
|
138
|
+
// its clock reading; the order is decided only if it holds for all of them.
|
|
139
|
+
const [zoned, local, flip] = a.zoned ? [a, b, 1] : [b, a, -1];
|
|
140
|
+
if (compareAt(zoned.seconds, zoned.fraction, local.seconds - ZONE_SPAN, local.fraction) < 0) {
|
|
141
|
+
return flip === 1 ? -1 : 1;
|
|
142
|
+
}
|
|
143
|
+
if (compareAt(zoned.seconds, zoned.fraction, local.seconds + ZONE_SPAN, local.fraction) > 0) {
|
|
144
|
+
return flip === 1 ? 1 : -1;
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const DURATION_PARTS = /^(-)?P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/;
|
|
149
|
+
function toDuration(text) {
|
|
150
|
+
const m = DURATION_PARTS.exec(text);
|
|
151
|
+
if (!m)
|
|
152
|
+
return undefined;
|
|
153
|
+
const [, neg, y, mo, d, h, mi, s] = m;
|
|
154
|
+
// `P` alone, or a `T` with nothing after it, is not a duration.
|
|
155
|
+
if ([y, mo, d, h, mi, s].every((part) => part === undefined))
|
|
156
|
+
return undefined;
|
|
157
|
+
if (text.includes('T') && [h, mi, s].every((part) => part === undefined))
|
|
158
|
+
return undefined;
|
|
159
|
+
const k = neg ? -1 : 1;
|
|
160
|
+
return {
|
|
161
|
+
months: k * (Number(y ?? 0) * 12 + Number(mo ?? 0)),
|
|
162
|
+
seconds: k * (Number(d ?? 0) * 86400 + Number(h ?? 0) * 3600 + Number(mi ?? 0) * 60 + Number(s ?? 0)),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** The four starting instants XSD orders durations from (§3.2.6.2). */
|
|
166
|
+
const DURATION_REFERENCES = [
|
|
167
|
+
[1696, 9], [1697, 2], [1903, 3], [1903, 7],
|
|
168
|
+
];
|
|
169
|
+
function endFrom([year, month], d) {
|
|
170
|
+
// Every reference is the first of its month, so adding months never needs
|
|
171
|
+
// the end-of-month pinning XSD's addition algorithm otherwise applies.
|
|
172
|
+
const index = month - 1 + d.months;
|
|
173
|
+
const y = year + Math.floor(index / 12);
|
|
174
|
+
const m = index - Math.floor(index / 12) * 12 + 1;
|
|
175
|
+
return daysFromCivil(y, m, 1) * 86400 + d.seconds;
|
|
176
|
+
}
|
|
177
|
+
function compareDurations(a, b) {
|
|
178
|
+
const signs = DURATION_REFERENCES.map((ref) => sign(endFrom(ref, a) - endFrom(ref, b)));
|
|
179
|
+
return signs.every((s) => s === signs[0]) ? signs[0] : undefined;
|
|
180
|
+
}
|
|
181
|
+
function parseKey(text, base) {
|
|
182
|
+
const dateTimeBase = dateTimeBaseOf(base);
|
|
183
|
+
if (dateTimeBase !== undefined) {
|
|
184
|
+
const instant = toInstant(text, dateTimeBase);
|
|
185
|
+
return instant && { kind: 'instant', instant };
|
|
186
|
+
}
|
|
187
|
+
if (localName(base) === 'duration') {
|
|
188
|
+
const duration = toDuration(text);
|
|
189
|
+
return duration && { kind: 'duration', duration };
|
|
190
|
+
}
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Order `value` against `bound` under a temporal or duration `base`: -1, 0 or
|
|
195
|
+
* 1, or `undefined` when `value` is not in the base's value space or XSD
|
|
196
|
+
* leaves the pair unordered. Callers fail closed on `undefined`.
|
|
197
|
+
*/
|
|
198
|
+
export function compareOrdered(value, bound, base) {
|
|
199
|
+
if (typeof value !== 'string')
|
|
200
|
+
return undefined;
|
|
201
|
+
const a = parseKey(value.trim(), base);
|
|
202
|
+
const b = parseKey(bound, base);
|
|
203
|
+
if (a === undefined || b === undefined)
|
|
204
|
+
return undefined;
|
|
205
|
+
if (a.kind === 'instant' && b.kind === 'instant')
|
|
206
|
+
return compareInstants(a.instant, b.instant);
|
|
207
|
+
if (a.kind === 'duration' && b.kind === 'duration')
|
|
208
|
+
return compareDurations(a.duration, b.duration);
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=xsd-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-order.js","sourceRoot":"","sources":["../../src/constraints/xsd-order.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAwB,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAK3D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM;IACzC,oBAAoB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,iBAAiB;IAChF,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc;CAC/D,CAAC,CAAC;AAEH,+DAA+D;AAC/D,SAAS,S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AAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC9C,OAAO,OAAO,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IACjD,CAAC;IACD,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO,QAAQ,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;IACpD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAgC,EAChC,KAAa,EACb,IAAwB;IAExB,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IACvC,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzD,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IAC/F,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,gBAAgB,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpG,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small parser for XSD regular expressions (XML Schema Part 2,
|
|
3
|
+
* Appendix F), producing the tree the example generator walks. It does
|
|
4
|
+
* not decide what a pattern MEANS: every character class keeps its source
|
|
5
|
+
* text, and membership is answered by the same translator the checker
|
|
6
|
+
* uses (`translateXsdRegex`), so the generator can never disagree with
|
|
7
|
+
* validation about a class.
|
|
8
|
+
*
|
|
9
|
+
* Grammar: regExp ::= branch ('|' branch)*; branch ::= piece*;
|
|
10
|
+
* piece ::= atom quantifier?; atom ::= char | charClass | '(' regExp ')'.
|
|
11
|
+
* XSD has no anchors, lookaround or back-references.
|
|
12
|
+
*/
|
|
13
|
+
export type XsdNode = {
|
|
14
|
+
type: 'alt';
|
|
15
|
+
branches: XsdNode[][];
|
|
16
|
+
} | {
|
|
17
|
+
type: 'char';
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
/** A class (`[…]`, `\d`, `\p{Lu}`, `.`) by its XSD source text. */
|
|
21
|
+
| {
|
|
22
|
+
type: 'class';
|
|
23
|
+
source: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'group';
|
|
26
|
+
body: XsdNode;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'repeat';
|
|
29
|
+
node: XsdNode;
|
|
30
|
+
min: number;
|
|
31
|
+
max: number;
|
|
32
|
+
};
|
|
33
|
+
export declare class XsdParseError extends Error {
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
export declare function parseXsdRegex(pattern: string): XsdNode;
|
|
37
|
+
//# sourceMappingURL=xsd-regex-ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-regex-ast.d.ts","sourceRoot":"","sources":["../../src/constraints/xsd-regex-ast.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AACjC,mEAAmE;GACjE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAMD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAgHtD"}
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
export class XsdParseError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'XsdParseError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const SINGLE_ESCAPES = { n: '\n', r: '\r', t: '\t' };
|
|
11
|
+
const CLASS_ESCAPES = new Set(['s', 'S', 'i', 'I', 'c', 'C', 'd', 'D', 'w', 'W']);
|
|
12
|
+
const META = new Set(['\\', '|', '.', '-', '^', '?', '*', '+', '{', '}', '(', ')', '[', ']']);
|
|
13
|
+
export function parseXsdRegex(pattern) {
|
|
14
|
+
let i = 0;
|
|
15
|
+
const classEnd = (start) => {
|
|
16
|
+
// `start` holds `[`; returns the index just past the matching `]`
|
|
17
|
+
// (nested `-[…]` subtraction included).
|
|
18
|
+
let j = start + 1;
|
|
19
|
+
if (pattern[j] === '^')
|
|
20
|
+
j++;
|
|
21
|
+
let first = true;
|
|
22
|
+
while (j < pattern.length) {
|
|
23
|
+
const c = pattern[j];
|
|
24
|
+
if (c === '\\') {
|
|
25
|
+
const prop = /^\\[pP]\{[^}]*\}/.exec(pattern.slice(j));
|
|
26
|
+
j += prop ? prop[0].length : 2;
|
|
27
|
+
}
|
|
28
|
+
else if (c === '-' && pattern[j + 1] === '[') {
|
|
29
|
+
j = classEnd(j + 1);
|
|
30
|
+
if (pattern[j] !== ']')
|
|
31
|
+
throw new XsdParseError(`a subtraction must end its class at ${j}`);
|
|
32
|
+
return j + 1;
|
|
33
|
+
}
|
|
34
|
+
else if (c === ']' && !first) {
|
|
35
|
+
return j + 1;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
j++;
|
|
39
|
+
}
|
|
40
|
+
first = false;
|
|
41
|
+
}
|
|
42
|
+
throw new XsdParseError(`unterminated character class at ${start}`);
|
|
43
|
+
};
|
|
44
|
+
const atom = () => {
|
|
45
|
+
const c = pattern[i];
|
|
46
|
+
if (c === '(') {
|
|
47
|
+
i++;
|
|
48
|
+
// `(?:…)` is not XSD, but checkers (and ours) read it as a plain group (IDSL-REGEX-003).
|
|
49
|
+
if (pattern.startsWith('?:', i))
|
|
50
|
+
i += 2;
|
|
51
|
+
const body = alt();
|
|
52
|
+
if (pattern[i] !== ')')
|
|
53
|
+
throw new XsdParseError(`missing ) at ${i}`);
|
|
54
|
+
i++;
|
|
55
|
+
return { type: 'group', body };
|
|
56
|
+
}
|
|
57
|
+
if (c === '[') {
|
|
58
|
+
const end = classEnd(i);
|
|
59
|
+
const source = pattern.slice(i, end);
|
|
60
|
+
i = end;
|
|
61
|
+
return { type: 'class', source };
|
|
62
|
+
}
|
|
63
|
+
if (c === '.') {
|
|
64
|
+
i++;
|
|
65
|
+
return { type: 'class', source: '.' };
|
|
66
|
+
}
|
|
67
|
+
if (c === '\\') {
|
|
68
|
+
const n = pattern[i + 1];
|
|
69
|
+
if (n === undefined)
|
|
70
|
+
throw new XsdParseError('dangling \\ at the end');
|
|
71
|
+
if (n === 'p' || n === 'P') {
|
|
72
|
+
const m = /^\\[pP]\{[^}]*\}/.exec(pattern.slice(i));
|
|
73
|
+
if (!m)
|
|
74
|
+
throw new XsdParseError(`malformed \\${n}{…} at ${i}`);
|
|
75
|
+
i += m[0].length;
|
|
76
|
+
return { type: 'class', source: m[0] };
|
|
77
|
+
}
|
|
78
|
+
i += 2;
|
|
79
|
+
if (CLASS_ESCAPES.has(n))
|
|
80
|
+
return { type: 'class', source: `\\${n}` };
|
|
81
|
+
if (n in SINGLE_ESCAPES)
|
|
82
|
+
return { type: 'char', value: SINGLE_ESCAPES[n] };
|
|
83
|
+
if (META.has(n))
|
|
84
|
+
return { type: 'char', value: n };
|
|
85
|
+
// Not a valid XSD escape, but checkers (and ours) read an escaped
|
|
86
|
+
// punctuation character as itself (`\/` occurs in real IDS files).
|
|
87
|
+
if (!/[\p{L}\p{N}]/u.test(n))
|
|
88
|
+
return { type: 'char', value: n };
|
|
89
|
+
throw new XsdParseError(`unknown escape \\${n}`);
|
|
90
|
+
}
|
|
91
|
+
if (c === ')' || c === '|' || c === '?' || c === '*' || c === '+' || c === '{') {
|
|
92
|
+
throw new XsdParseError(`unexpected ${c} at ${i}`);
|
|
93
|
+
}
|
|
94
|
+
const cp = pattern.codePointAt(i);
|
|
95
|
+
const value = String.fromCodePoint(cp);
|
|
96
|
+
i += value.length;
|
|
97
|
+
return { type: 'char', value };
|
|
98
|
+
};
|
|
99
|
+
const quantified = (node) => {
|
|
100
|
+
const c = pattern[i];
|
|
101
|
+
if (c === '?' || c === '*' || c === '+') {
|
|
102
|
+
i++;
|
|
103
|
+
return { type: 'repeat', node, min: c === '+' ? 1 : 0, max: c === '?' ? 1 : Infinity };
|
|
104
|
+
}
|
|
105
|
+
if (c === '{') {
|
|
106
|
+
const m = /^\{(\d+)(,(\d*))?\}/.exec(pattern.slice(i));
|
|
107
|
+
if (!m)
|
|
108
|
+
throw new XsdParseError(`malformed quantifier at ${i}`);
|
|
109
|
+
i += m[0].length;
|
|
110
|
+
const min = Number(m[1]);
|
|
111
|
+
const max = m[2] === undefined ? min : m[3] === '' ? Infinity : Number(m[3]);
|
|
112
|
+
if (max < min)
|
|
113
|
+
throw new XsdParseError(`quantifier {${min},${max}} has max < min`);
|
|
114
|
+
return { type: 'repeat', node, min, max };
|
|
115
|
+
}
|
|
116
|
+
return node;
|
|
117
|
+
};
|
|
118
|
+
const branch = () => {
|
|
119
|
+
const items = [];
|
|
120
|
+
while (i < pattern.length && pattern[i] !== '|' && pattern[i] !== ')')
|
|
121
|
+
items.push(quantified(atom()));
|
|
122
|
+
return items;
|
|
123
|
+
};
|
|
124
|
+
const alt = () => {
|
|
125
|
+
const branches = [branch()];
|
|
126
|
+
while (pattern[i] === '|') {
|
|
127
|
+
i++;
|
|
128
|
+
branches.push(branch());
|
|
129
|
+
}
|
|
130
|
+
return { type: 'alt', branches };
|
|
131
|
+
};
|
|
132
|
+
const root = alt();
|
|
133
|
+
if (i !== pattern.length)
|
|
134
|
+
throw new XsdParseError(`unexpected ${pattern[i]} at ${i}`);
|
|
135
|
+
return root;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=xsd-regex-ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-regex-ast.js","sourceRoot":"","sources":["../../src/constraints/xsd-regex-ast.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAuB/D,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,cAAc,GAAqC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;AACvF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAClF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,EAAE,CAAC;IACnB,IAAI,CAAC,KAAK,OAAO,CAAC,MAAM;QAAE,MAAM,IAAI,aAAa,CAAC,cAAc,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The class members (`\u0000-\u007F`, ready to splice inside `[ … ]`) for
|
|
3
|
+
* an XSD block name without its `Is` prefix, or `undefined` when XSD
|
|
4
|
+
* defines no such block.
|
|
5
|
+
*/
|
|
6
|
+
export declare function xsdBlockClassMembers(name: string): string | undefined;
|
|
7
|
+
//# sourceMappingURL=xsd-regex-blocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-regex-blocks.d.ts","sourceRoot":"","sources":["../../src/constraints/xsd-regex-blocks.ts"],"names":[],"mappings":"AAuDA;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUrE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
* The Unicode blocks an XSD `\p{IsName}` / `\P{IsName}` block escape may
|
|
6
|
+
* name: XML Schema Part 2, Appendix F.1.1 (the Unicode 3.1 `Blocks.txt`
|
|
7
|
+
* list, with its ranges). JS regex has no block escapes, so the translator
|
|
8
|
+
* replaces each with the code-point range(s) below.
|
|
9
|
+
*
|
|
10
|
+
* Packed as `Name start end` triples (hex code points). `PrivateUse` and
|
|
11
|
+
* `Specials` appear more than once in the spec's table; every range listed
|
|
12
|
+
* for a name belongs to that name's block escape.
|
|
13
|
+
*/
|
|
14
|
+
const PACKED = `
|
|
15
|
+
BasicLatin 0 7F|Latin-1Supplement 80 FF|LatinExtended-A 100 17F|LatinExtended-B 180 24F
|
|
16
|
+
IPAExtensions 250 2AF|SpacingModifierLetters 2B0 2FF|CombiningDiacriticalMarks 300 36F
|
|
17
|
+
Greek 370 3FF|Cyrillic 400 4FF|Armenian 530 58F|Hebrew 590 5FF|Arabic 600 6FF|Syriac 700 74F
|
|
18
|
+
Thaana 780 7BF|Devanagari 900 97F|Bengali 980 9FF|Gurmukhi A00 A7F|Gujarati A80 AFF
|
|
19
|
+
Oriya B00 B7F|Tamil B80 BFF|Telugu C00 C7F|Kannada C80 CFF|Malayalam D00 D7F|Sinhala D80 DFF
|
|
20
|
+
Thai E00 E7F|Lao E80 EFF|Tibetan F00 FFF|Myanmar 1000 109F|Georgian 10A0 10FF
|
|
21
|
+
HangulJamo 1100 11FF|Ethiopic 1200 137F|Cherokee 13A0 13FF
|
|
22
|
+
UnifiedCanadianAboriginalSyllabics 1400 167F|Ogham 1680 169F|Runic 16A0 16FF|Khmer 1780 17FF
|
|
23
|
+
Mongolian 1800 18AF|LatinExtendedAdditional 1E00 1EFF|GreekExtended 1F00 1FFF
|
|
24
|
+
GeneralPunctuation 2000 206F|SuperscriptsandSubscripts 2070 209F|CurrencySymbols 20A0 20CF
|
|
25
|
+
CombiningMarksforSymbols 20D0 20FF|LetterlikeSymbols 2100 214F|NumberForms 2150 218F
|
|
26
|
+
Arrows 2190 21FF|MathematicalOperators 2200 22FF|MiscellaneousTechnical 2300 23FF
|
|
27
|
+
ControlPictures 2400 243F|OpticalCharacterRecognition 2440 245F
|
|
28
|
+
EnclosedAlphanumerics 2460 24FF|BoxDrawing 2500 257F|BlockElements 2580 259F
|
|
29
|
+
GeometricShapes 25A0 25FF|MiscellaneousSymbols 2600 26FF|Dingbats 2700 27BF
|
|
30
|
+
BraillePatterns 2800 28FF|CJKRadicalsSupplement 2E80 2EFF|KangxiRadicals 2F00 2FDF
|
|
31
|
+
IdeographicDescriptionCharacters 2FF0 2FFF|CJKSymbolsandPunctuation 3000 303F
|
|
32
|
+
Hiragana 3040 309F|Katakana 30A0 30FF|Bopomofo 3100 312F|HangulCompatibilityJamo 3130 318F
|
|
33
|
+
Kanbun 3190 319F|BopomofoExtended 31A0 31BF|EnclosedCJKLettersandMonths 3200 32FF
|
|
34
|
+
CJKCompatibility 3300 33FF|CJKUnifiedIdeographsExtensionA 3400 4DB5
|
|
35
|
+
CJKUnifiedIdeographs 4E00 9FFF|YiSyllables A000 A48F|YiRadicals A490 A4CF
|
|
36
|
+
HangulSyllables AC00 D7A3|HighSurrogates D800 DB7F|HighPrivateUseSurrogates DB80 DBFF
|
|
37
|
+
LowSurrogates DC00 DFFF|PrivateUse E000 F8FF|CJKCompatibilityIdeographs F900 FAFF
|
|
38
|
+
AlphabeticPresentationForms FB00 FB4F|ArabicPresentationForms-A FB50 FDFF
|
|
39
|
+
CombiningHalfMarks FE20 FE2F|CJKCompatibilityForms FE30 FE4F|SmallFormVariants FE50 FE6F
|
|
40
|
+
ArabicPresentationForms-B FE70 FEFE|Specials FEFF FEFF|HalfwidthandFullwidthForms FF00 FFEF
|
|
41
|
+
Specials FFF0 FFFD|OldItalic 10300 1032F|Gothic 10330 1034F|Deseret 10400 1044F
|
|
42
|
+
ByzantineMusicalSymbols 1D000 1D0FF|MusicalSymbols 1D100 1D1FF
|
|
43
|
+
MathematicalAlphanumericSymbols 1D400 1D7FF|CJKUnifiedIdeographsExtensionB 20000 2A6D6
|
|
44
|
+
CJKCompatibilityIdeographsSupplement 2F800 2FA1F|Tags E0000 E007F
|
|
45
|
+
PrivateUse F0000 FFFFD|PrivateUse 100000 10FFFD`;
|
|
46
|
+
/** JS class-escape spelling of one code point, valid under the `u` flag. */
|
|
47
|
+
function codePointEscape(cp) {
|
|
48
|
+
const hex = cp.toString(16).toUpperCase();
|
|
49
|
+
return cp <= 0xffff ? `\\u${hex.padStart(4, '0')}` : `\\u{${hex}}`;
|
|
50
|
+
}
|
|
51
|
+
let blockMembers;
|
|
52
|
+
/**
|
|
53
|
+
* The class members (`\u0000-\u007F`, ready to splice inside `[ … ]`) for
|
|
54
|
+
* an XSD block name without its `Is` prefix, or `undefined` when XSD
|
|
55
|
+
* defines no such block.
|
|
56
|
+
*/
|
|
57
|
+
export function xsdBlockClassMembers(name) {
|
|
58
|
+
if (!blockMembers) {
|
|
59
|
+
blockMembers = new Map();
|
|
60
|
+
for (const entry of PACKED.trim().split(/[|\n]/)) {
|
|
61
|
+
const [block, start, end] = entry.split(' ');
|
|
62
|
+
const range = `${codePointEscape(parseInt(start, 16))}-${codePointEscape(parseInt(end, 16))}`;
|
|
63
|
+
blockMembers.set(block, (blockMembers.get(block) ?? '') + range);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return blockMembers.get(name);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=xsd-regex-blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xsd-regex-blocks.js","sourceRoot":"","sources":["../../src/constraints/xsd-regex-blocks.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;;;;GASG;AACH,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gDA+BiC,CAAC;AAEjD,4EAA4E;AAC5E,SAAS,eAAe,CAAC,EAAU;IACjC,MAAM,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1C,OAAO,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC;AACrE,CAAC;AAED,IAAI,YAA6C,CAAC;AAElD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACjD,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC7C,MAAM,KAAK,GAAG,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,eAAe,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;YAC9F,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -1,37 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canonical XSD-regex → JavaScript-regex translator shared by the
|
|
3
|
-
* constraint matcher (`matchPattern`) and the document auditor
|
|
4
|
-
* (`audit/coherence`). Keeping a single implementation avoids the two
|
|
5
|
-
* dialects drifting apart.
|
|
6
|
-
*
|
|
7
|
-
* Ported from `IdsLib/IdsSchema/XsNodes/XmlRegex.cs` (MIT) which itself
|
|
8
|
-
* mirrors Microsoft's reference XSD facet checker. XSD regex extends
|
|
9
|
-
* the JS dialect with:
|
|
10
|
-
*
|
|
11
|
-
* - `\i` — XML name start char (letter, `_`, `:` plus a swathe of
|
|
12
|
-
* Unicode letters)
|
|
13
|
-
* - `\c` — XML name char (`\i` plus digits, `.`, `-`, U+00B7, etc.)
|
|
14
|
-
* - `\d` — Unicode digit (broader than JS `[0-9]`)
|
|
15
|
-
* - `\w` — Unicode word char (letters + digits, no `_`)
|
|
16
|
-
* - `\D`, `\C`, `\I`, `\W` — negations
|
|
17
|
-
* - `\p{IsBasicLatin}`-style Unicode *block* escapes — .NET supports
|
|
18
|
-
* these but JS does not, so they are approximated.
|
|
19
|
-
* - char-class subtraction `[a-z-[aeiou]]` — no JS class syntax under
|
|
20
|
-
* `u`, translated exactly to a negative lookahead (`translateSubtraction`).
|
|
21
|
-
*
|
|
22
|
-
* The translation maps to JS Unicode property escapes, so the compiled
|
|
23
|
-
* `RegExp` MUST use the `u` flag. Verbatim `\p{…}` / `\P{…}` *category*
|
|
24
|
-
* classes pass through unchanged — they too require `u`.
|
|
25
|
-
*
|
|
26
|
-
* Translation is character-class aware: a multi-character escape like
|
|
27
|
-
* `\w` expands to a bracketed class `[\p{L}\p{Nd}]` at top level but to
|
|
28
|
-
* its bare members `\p{L}\p{Nd}` when it already sits inside `[ … ]`, so
|
|
29
|
-
* `[\w]` does not become the invalid nested class `[[\p{L}\p{Nd}]]`.
|
|
30
|
-
* Constructs with no faithful JS form (block escapes, a negated class
|
|
31
|
-
* escape inside `[ … ]`) are replaced with an any-character placeholder
|
|
32
|
-
* and `supported` is set to `false` so callers can warn instead of
|
|
33
|
-
* trusting the (approximate) result.
|
|
34
|
-
*/
|
|
35
1
|
export interface TranslateResult {
|
|
36
2
|
/** The pattern usable with the JS `RegExp` constructor (under `u`). */
|
|
37
3
|
pattern: string;
|
|
@@ -43,19 +9,10 @@ export interface TranslateResult {
|
|
|
43
9
|
*/
|
|
44
10
|
reason: string;
|
|
45
11
|
}
|
|
46
|
-
/**
|
|
47
|
-
* `TranslateResult.reason` when the pattern uses XSD character-class
|
|
48
|
-
* subtraction (`[a-z-[aeiou]]`). Exported so a caller that needs to
|
|
49
|
-
* distinguish this specific construct — rather than "some construct is
|
|
50
|
-
* unsupported" in general — doesn't have to duplicate the message
|
|
51
|
-
* string (see `matchPattern`'s fail-closed check, which refuses only
|
|
52
|
-
* a subtraction pattern rather than every approximated construct).
|
|
53
|
-
*/
|
|
54
|
-
export declare const SUBTRACTION_UNSUPPORTED_REASON = "XSD character-class subtraction is not supported in JS regex";
|
|
55
12
|
/**
|
|
56
13
|
* Translate the XSD pattern. Returns the JS-compatible pattern plus a
|
|
57
|
-
* `supported` flag — when `false`,
|
|
58
|
-
*
|
|
14
|
+
* `supported` flag — when `false`, `reason` names the construct that has
|
|
15
|
+
* no exact JS form and the pattern must not be trusted.
|
|
59
16
|
*/
|
|
60
17
|
export declare function translateXsdRegex(pattern: string): TranslateResult;
|
|
61
18
|
//# sourceMappingURL=xsd-regex.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xsd-regex.d.ts","sourceRoot":"","sources":["../../src/constraints/xsd-regex.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xsd-regex.d.ts","sourceRoot":"","sources":["../../src/constraints/xsd-regex.ts"],"names":[],"mappings":"AAwDA,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAwDD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CA0DlE"}
|