@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
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
function refuse(what) {
|
|
5
|
+
throw new Error(`writeIdsXml: ${what} are not supported by this writer`);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The facet families of one `<xs:restriction>`: the primary constraint and
|
|
9
|
+
* its conjunctive `and` siblings (see `constraint-types.ts`). One restriction
|
|
10
|
+
* holds one base and at most one family of each kind, since XSD ORs sibling
|
|
11
|
+
* patterns and enumerations; anything else has no single-restriction XML and
|
|
12
|
+
* is refused, never written as a weaker or different check.
|
|
13
|
+
*/
|
|
14
|
+
function restrictionFamilies(constraint) {
|
|
15
|
+
const families = [constraint];
|
|
16
|
+
for (const sibling of constraint.and ?? []) {
|
|
17
|
+
if (sibling.type === 'simpleValue')
|
|
18
|
+
refuse('simple values inside a conjunctive restriction');
|
|
19
|
+
if (sibling.and?.length)
|
|
20
|
+
refuse('nested conjunctive restriction facets');
|
|
21
|
+
if (families.some((family) => family.type === sibling.type))
|
|
22
|
+
refuse(`two ${sibling.type} families in one conjunctive restriction`);
|
|
23
|
+
families.push(sibling);
|
|
24
|
+
}
|
|
25
|
+
const bases = new Set(families.map((family) => family.base).filter((base) => base !== undefined));
|
|
26
|
+
if (bases.size > 1)
|
|
27
|
+
refuse('conjunctive restriction facets with different bases');
|
|
28
|
+
return families;
|
|
29
|
+
}
|
|
30
|
+
/** `xs:length`, `xs:minLength`, `xs:maxLength` and the digit counts are `xs:nonNegativeInteger`. */
|
|
31
|
+
function countLexical(facet, value) {
|
|
32
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
33
|
+
throw new Error(`writeIdsXml: ${facet} must be a non-negative integer, got ${value}`);
|
|
34
|
+
}
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
/** Bases whose lexical space has an exponent: `xs:double` and `xs:float`. */
|
|
38
|
+
const EXPONENT_BASES = new Set(['xs:double', 'xs:float']);
|
|
39
|
+
/**
|
|
40
|
+
* A bound in its base's lexical space. `String(1e-7)` is `"1e-7"`, which
|
|
41
|
+
* `xs:decimal` and the integer types cannot read, so the exponent is expanded
|
|
42
|
+
* into plain digits there; the digits are the same, so `parseFloat` reads
|
|
43
|
+
* back the identical number.
|
|
44
|
+
*/
|
|
45
|
+
function boundLexical(facet, value, base) {
|
|
46
|
+
if (!Number.isFinite(value))
|
|
47
|
+
throw new Error(`writeIdsXml: ${facet} must be a finite number, got ${value}`);
|
|
48
|
+
const text = String(value);
|
|
49
|
+
if (EXPONENT_BASES.has(base) || !/e/i.test(text))
|
|
50
|
+
return text;
|
|
51
|
+
return expandExponent(text);
|
|
52
|
+
}
|
|
53
|
+
function expandExponent(text) {
|
|
54
|
+
const match = /^(-?)(\d+)(?:\.(\d+))?e([+-]\d+)$/i.exec(text);
|
|
55
|
+
if (!match)
|
|
56
|
+
return text;
|
|
57
|
+
const [, sign, whole, fraction = '', exponentText] = match;
|
|
58
|
+
const digits = whole + fraction;
|
|
59
|
+
const point = whole.length + Number(exponentText);
|
|
60
|
+
if (point <= 0)
|
|
61
|
+
return `${sign}0.${'0'.repeat(-point)}${digits}`;
|
|
62
|
+
if (point >= digits.length)
|
|
63
|
+
return `${sign}${digits}${'0'.repeat(point - digits.length)}`;
|
|
64
|
+
return `${sign}${digits.slice(0, point)}.${digits.slice(point)}`;
|
|
65
|
+
}
|
|
66
|
+
function writeBounds(xml, constraint, base) {
|
|
67
|
+
if (constraint.unparseableFacets?.length)
|
|
68
|
+
refuse('unparseable bound facets');
|
|
69
|
+
const bounds = [
|
|
70
|
+
['xs:minInclusive', constraint.minInclusive],
|
|
71
|
+
['xs:minExclusive', constraint.minExclusive],
|
|
72
|
+
['xs:maxInclusive', constraint.maxInclusive],
|
|
73
|
+
['xs:maxExclusive', constraint.maxExclusive],
|
|
74
|
+
];
|
|
75
|
+
// Date, time and duration bounds are kept as their validated lexemes, not numbers (#7399).
|
|
76
|
+
const temporal = constraint.temporalBounds;
|
|
77
|
+
const temporalBounds = [
|
|
78
|
+
['xs:minInclusive', temporal?.minInclusive],
|
|
79
|
+
['xs:minExclusive', temporal?.minExclusive],
|
|
80
|
+
['xs:maxInclusive', temporal?.maxInclusive],
|
|
81
|
+
['xs:maxExclusive', temporal?.maxExclusive],
|
|
82
|
+
];
|
|
83
|
+
const counts = [
|
|
84
|
+
['xs:length', constraint.length],
|
|
85
|
+
['xs:minLength', constraint.minLength],
|
|
86
|
+
['xs:maxLength', constraint.maxLength],
|
|
87
|
+
['xs:totalDigits', constraint.totalDigits],
|
|
88
|
+
['xs:fractionDigits', constraint.fractionDigits],
|
|
89
|
+
];
|
|
90
|
+
// With no facet the restriction would be empty, which reads back as an empty enumeration.
|
|
91
|
+
if ([...bounds, ...temporalBounds, ...counts].every(([, value]) => value === undefined))
|
|
92
|
+
refuse('bounds restrictions without any facet');
|
|
93
|
+
for (const [facet, value] of bounds) {
|
|
94
|
+
if (value !== undefined)
|
|
95
|
+
xml.empty(facet, { value: boundLexical(facet, value, base) });
|
|
96
|
+
}
|
|
97
|
+
for (const [facet, value] of temporalBounds) {
|
|
98
|
+
if (value !== undefined)
|
|
99
|
+
xml.empty(facet, { value });
|
|
100
|
+
}
|
|
101
|
+
for (const [facet, value] of counts) {
|
|
102
|
+
if (value !== undefined)
|
|
103
|
+
xml.empty(facet, { value: countLexical(facet, value) });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The base written when the model carries none: `xs:double` for a numeric bounds restriction, else `xs:string`. */
|
|
107
|
+
function defaultBase(families) {
|
|
108
|
+
const primary = families[0];
|
|
109
|
+
if (primary.type !== 'bounds')
|
|
110
|
+
return 'xs:string';
|
|
111
|
+
const numeric = [primary.minInclusive, primary.minExclusive, primary.maxInclusive, primary.maxExclusive, primary.totalDigits, primary.fractionDigits];
|
|
112
|
+
return numeric.some((value) => value !== undefined) ? 'xs:double' : 'xs:string';
|
|
113
|
+
}
|
|
114
|
+
function writeRestriction(xml, constraint) {
|
|
115
|
+
const families = restrictionFamilies(constraint);
|
|
116
|
+
const base = families.find((family) => family.base !== undefined)?.base ?? defaultBase(families);
|
|
117
|
+
xml.open('xs:restriction', { base });
|
|
118
|
+
for (const family of families) {
|
|
119
|
+
switch (family.type) {
|
|
120
|
+
case 'pattern':
|
|
121
|
+
xml.empty('xs:pattern', { value: family.pattern });
|
|
122
|
+
break;
|
|
123
|
+
case 'enumeration':
|
|
124
|
+
for (const value of family.values)
|
|
125
|
+
xml.empty('xs:enumeration', { value });
|
|
126
|
+
break;
|
|
127
|
+
case 'bounds':
|
|
128
|
+
writeBounds(xml, family, base);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
xml.close('xs:restriction');
|
|
133
|
+
}
|
|
134
|
+
export function writeConstraint(xml, tag, constraint) {
|
|
135
|
+
xml.open(tag);
|
|
136
|
+
if (constraint.type === 'simpleValue')
|
|
137
|
+
xml.leaf('simpleValue', constraint.value);
|
|
138
|
+
else
|
|
139
|
+
writeRestriction(xml, constraint);
|
|
140
|
+
xml.close(tag);
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=constraint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint.js","sourceRoot":"","sources":["../../src/writer/constraint.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAY/D,SAAS,MAAM,CAAC,IAAY;IAC1B,MAAM,IAAI,KAAK,CAAC,gBAAgB,IAAI,mCAAmC,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,UAA6B;IACxD,MAAM,QAAQ,GAAwB,CAAC,UAAU,CAAC,CAAC;IACnD,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC;QAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,aAAa;YAAE,MAAM,CAAC,gDAAgD,CAAC,CAAC;QAC7F,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM;YAAE,MAAM,CAAC,uCAAuC,CAAC,CAAC;QACzE,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC;YAAE,MAAM,CAAC,OAAO,OAAO,CAAC,IAAI,0CAA0C,CAAC,CAAC;QACnI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC;IAClG,IAAI,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C;IACH,CAAC;IACD,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAa,EAAE,GAAW,EAAE,UAAyB;IACnF,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACd,IAAI,UAAU,CAAC,IAAI,KAAK,aAAa;QAAE,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;;QAC5E,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACvC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialise an `IDSDocument` as IDS 1.0 XML (#5225). Covers entity,
|
|
3
|
+
* attribute, property (with `dataType`), classification, material and
|
|
4
|
+
* partOf facets, requirement `instructions`, and every `IDSConstraint`
|
|
5
|
+
* shape: simple values, patterns, enumerations, numeric/length/digit bounds
|
|
6
|
+
* and conjunctive (`and`) restrictions. Element order within a facet
|
|
7
|
+
* follows `ids.xsd`, so `parseIDS` and `auditIDSDocument` read the result
|
|
8
|
+
* back; applicability facets are written in the order given (the caller
|
|
9
|
+
* owns the XSD's entity, partOf, classification, attribute, property,
|
|
10
|
+
* material sequence there). `@ifc-lite/rules`' `ruleSetToIds` and the
|
|
11
|
+
* viewer's reviewed IDS drafts (#6915) serialise through here (moved from
|
|
12
|
+
* `@ifc-lite/rules` by ADR-005).
|
|
13
|
+
*/
|
|
14
|
+
import type { IDSDocument } from '../types.js';
|
|
15
|
+
import type { IDSPreviewFlags } from '../preview/types.js';
|
|
16
|
+
/** Formatting of `writeIdsXml`'s output. Every option changes layout or order only, never meaning. */
|
|
17
|
+
export interface IdsXmlFormat {
|
|
18
|
+
/** Indentation of one nesting level: a number of spaces (0–8) or `'\t'`. Default `2`. */
|
|
19
|
+
indent?: number | '\t';
|
|
20
|
+
/** Line ending. Default `'\n'`. */
|
|
21
|
+
newline?: '\n' | '\r\n';
|
|
22
|
+
/**
|
|
23
|
+
* Canonical order, so two documents with the same checks write the same
|
|
24
|
+
* bytes: applicability facets in the `ids.xsd` sequence (entity, partOf,
|
|
25
|
+
* classification, attribute, property, material; stable within a kind)
|
|
26
|
+
* and `ifcVersion` tokens in schema order without duplicates. Both are
|
|
27
|
+
* order-insensitive in IDS. Requirements keep their authored order, which
|
|
28
|
+
* reports show. Default `false`: everything is written in the order given.
|
|
29
|
+
*/
|
|
30
|
+
canonical?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** What `writeIdsXml` may write, as opposed to how (`IdsXmlFormat`). */
|
|
33
|
+
export interface IdsXmlWriteOptions {
|
|
34
|
+
/**
|
|
35
|
+
* IDS 1.1 PREVIEW (unstable). Without `ids11`, a document using a 1.1
|
|
36
|
+
* candidate feature is refused with `IDS11PreviewRequiredError`; with it,
|
|
37
|
+
* such a document is written against the 1.1 schema location. A document
|
|
38
|
+
* using no 1.1 feature is written as IDS 1.0 either way, byte for byte.
|
|
39
|
+
*/
|
|
40
|
+
preview?: IDSPreviewFlags;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `doc` as an IDS 1.0 XML string, laid out per `fmt` (two-space indent,
|
|
44
|
+
* `\n`, authored order by default). IDS 1.1 PREVIEW output needs
|
|
45
|
+
* `options.preview.ids11`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function writeIdsXml(doc: IDSDocument, fmt?: IdsXmlFormat, options?: IdsXmlWriteOptions): string;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/writer/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,WAAW,EAMZ,MAAM,aAAa,CAAC;AAIrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAoH3D,sGAAsG;AACtG,MAAM,WAAW,YAAY;IAC3B,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,mCAAmC;IACnC,OAAO,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IACxB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAqDD,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,GAAE,YAAiB,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CA8B9G"}
|
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
import { XmlLines } from './xml-lines.js';
|
|
5
|
+
import { writeConstraint } from './constraint.js';
|
|
6
|
+
import { assertIds11Allowed } from '../preview/features.js';
|
|
7
|
+
const IDS_NS = 'http://standards.buildingsmart.org/IDS';
|
|
8
|
+
const XS_NS = 'http://www.w3.org/2001/XMLSchema';
|
|
9
|
+
const XSI_NS = 'http://www.w3.org/2001/XMLSchema-instance';
|
|
10
|
+
const SCHEMA_LOCATION = `${IDS_NS} http://standards.buildingsmart.org/IDS/1.0/ids.xsd`;
|
|
11
|
+
/**
|
|
12
|
+
* IDS 1.1 PREVIEW. buildingSMART has not published a 1.1 schema URL; this
|
|
13
|
+
* follows the 1.0 pattern and the `version="1.1.0"` of the upstream
|
|
14
|
+
* `ver/1.1.x` branch's `ids.xsd`. An assumption, recorded in the P-12 worklog.
|
|
15
|
+
*/
|
|
16
|
+
const SCHEMA_LOCATION_11_PREVIEW = `${IDS_NS} http://standards.buildingsmart.org/IDS/1.1/ids.xsd`;
|
|
17
|
+
const IDS11_PREVIEW_NOTE = 'IDS 1.1 PREVIEW: uses unreleased candidate features; not valid IDS 1.0.';
|
|
18
|
+
/**
|
|
19
|
+
* `IfcRelContainedInSpatialStructure` -> the XSD's upper-case `relations`
|
|
20
|
+
* token. Voids and fills exist in IDS 1.0 only as the combined token, so
|
|
21
|
+
* either alone has no valid XML and is refused.
|
|
22
|
+
*/
|
|
23
|
+
function relationToken(relation) {
|
|
24
|
+
if (relation === 'IfcRelVoidsElement' || relation === 'IfcRelFillsElement') {
|
|
25
|
+
throw new Error(`writeIdsXml: partOf relation ${relation} on its own is not supported by this writer (IDS 1.0 has only "IFCRELVOIDSELEMENT IFCRELFILLSELEMENT")`);
|
|
26
|
+
}
|
|
27
|
+
return relation.toUpperCase();
|
|
28
|
+
}
|
|
29
|
+
function writeEntity(xml, facet, attrs = {}) {
|
|
30
|
+
xml.open('entity', attrs);
|
|
31
|
+
writeConstraint(xml, 'name', facet.name);
|
|
32
|
+
if (facet.predefinedType)
|
|
33
|
+
writeConstraint(xml, 'predefinedType', facet.predefinedType);
|
|
34
|
+
xml.close('entity');
|
|
35
|
+
}
|
|
36
|
+
/** `dataType` is an XSD attribute holding one upper-case name, never a restriction. */
|
|
37
|
+
function dataTypeAttr(facet) {
|
|
38
|
+
if (!facet.dataType)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (facet.dataType.type !== 'simpleValue')
|
|
41
|
+
throw new Error('writeIdsXml: a property dataType must be a simple value');
|
|
42
|
+
return facet.dataType.value;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The facet's `instructions` attribute. A requirement's comes from
|
|
46
|
+
* `IDSRequirement.instructions` (IDS 1.0); an applicability facet's from the
|
|
47
|
+
* facet itself (IDS 1.1 PREVIEW, #154). The facet-level field anywhere else
|
|
48
|
+
* has no XML home and is refused rather than dropped.
|
|
49
|
+
*/
|
|
50
|
+
function instructionsFor(facet, context, requirementInstructions) {
|
|
51
|
+
if (context === 'applicability')
|
|
52
|
+
return facet.instructions;
|
|
53
|
+
if (facet.instructions !== undefined) {
|
|
54
|
+
throw new Error(`writeIdsXml: a ${context} ${facet.type} facet cannot carry facet-level instructions${context === 'requirement' ? '; use IDSRequirement.instructions' : ''}`);
|
|
55
|
+
}
|
|
56
|
+
return requirementInstructions;
|
|
57
|
+
}
|
|
58
|
+
function writeFacet(xml, facet, cardinality, context, requirementInstructions) {
|
|
59
|
+
const instructions = instructionsFor(facet, context, requirementInstructions);
|
|
60
|
+
switch (facet.type) {
|
|
61
|
+
case 'entity':
|
|
62
|
+
writeEntity(xml, facet, { instructions });
|
|
63
|
+
return;
|
|
64
|
+
case 'attribute':
|
|
65
|
+
xml.open('attribute', { cardinality, instructions });
|
|
66
|
+
writeConstraint(xml, 'name', facet.name);
|
|
67
|
+
if (facet.value)
|
|
68
|
+
writeConstraint(xml, 'value', facet.value);
|
|
69
|
+
xml.close('attribute');
|
|
70
|
+
return;
|
|
71
|
+
case 'property':
|
|
72
|
+
xml.open('property', { dataType: dataTypeAttr(facet), cardinality, instructions, uri: facet.uri });
|
|
73
|
+
writeConstraint(xml, 'propertySet', facet.propertySet);
|
|
74
|
+
writeConstraint(xml, 'baseName', facet.baseName);
|
|
75
|
+
if (facet.value)
|
|
76
|
+
writeConstraint(xml, 'value', facet.value);
|
|
77
|
+
xml.close('property');
|
|
78
|
+
return;
|
|
79
|
+
case 'classification':
|
|
80
|
+
xml.open('classification', { cardinality, instructions, uri: facet.uri });
|
|
81
|
+
if (facet.value)
|
|
82
|
+
writeConstraint(xml, 'value', facet.value);
|
|
83
|
+
if (facet.system)
|
|
84
|
+
writeConstraint(xml, 'system', facet.system);
|
|
85
|
+
xml.close('classification');
|
|
86
|
+
return;
|
|
87
|
+
case 'material':
|
|
88
|
+
xml.open('material', { cardinality, instructions, uri: facet.uri });
|
|
89
|
+
if (facet.value)
|
|
90
|
+
writeConstraint(xml, 'value', facet.value);
|
|
91
|
+
xml.close('material');
|
|
92
|
+
return;
|
|
93
|
+
case 'partOf':
|
|
94
|
+
// `ruleSetToIds` never produces one (a rule's `parent` subject matches
|
|
95
|
+
// an ancestor's Name, not its class). The XSD requires the related
|
|
96
|
+
// entity, so a partOf without one is refused rather than written invalid.
|
|
97
|
+
if (!facet.entity)
|
|
98
|
+
throw new Error('writeIdsXml: a partOf facet needs its related entity');
|
|
99
|
+
// No relation means any part-of relation (#7401), so it stays unwritten;
|
|
100
|
+
// an unrecognised one is written as read, for the auditor to flag.
|
|
101
|
+
xml.open('partOf', {
|
|
102
|
+
relation: facet.anyRelation ? undefined : facet.rawRelation ?? relationToken(facet.relation),
|
|
103
|
+
cardinality,
|
|
104
|
+
instructions,
|
|
105
|
+
});
|
|
106
|
+
writeEntity(xml, facet.entity);
|
|
107
|
+
// IDS 1.1 PREVIEW (#379/#380): conditions on the related parent.
|
|
108
|
+
for (const nested of facet.facets ?? [])
|
|
109
|
+
writeFacet(xml, nested, undefined, 'nested');
|
|
110
|
+
xml.close('partOf');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function writeRequirement(xml, requirement) {
|
|
115
|
+
// IDS 1.0 has no cardinality on an entity facet inside requirements.
|
|
116
|
+
const cardinality = requirement.facet.type === 'entity' ? undefined : requirement.optionality;
|
|
117
|
+
writeFacet(xml, requirement.facet, cardinality, 'requirement', requirement.instructions);
|
|
118
|
+
}
|
|
119
|
+
/** The `ids.xsd` applicability sequence; an applicability in another order is not schema-valid. */
|
|
120
|
+
const FACET_ORDER = {
|
|
121
|
+
entity: 0, partOf: 1, classification: 2, attribute: 3, property: 4, material: 5,
|
|
122
|
+
};
|
|
123
|
+
/** `ids.xsd`'s `ifcVersion` tokens, in schema order. The parser reads `IFC4X3_ADD2` as `IFC4X3`. */
|
|
124
|
+
const VERSION_TOKENS = ['IFC2X3', 'IFC4', 'IFC4X3_ADD2'];
|
|
125
|
+
/** `IFC4X3` has no token of its own in IDS 1.0: it is written as `IFC4X3_ADD2`, which reads back as `IFC4X3`. */
|
|
126
|
+
function versionToken(version) {
|
|
127
|
+
return version === 'IFC4X3' ? 'IFC4X3_ADD2' : version;
|
|
128
|
+
}
|
|
129
|
+
function versionTokens(versions, canonical) {
|
|
130
|
+
const tokens = versions.map(versionToken);
|
|
131
|
+
if (!canonical)
|
|
132
|
+
return tokens;
|
|
133
|
+
return VERSION_TOKENS.filter((token) => tokens.includes(token));
|
|
134
|
+
}
|
|
135
|
+
function indentUnit(indent) {
|
|
136
|
+
if (indent === undefined)
|
|
137
|
+
return ' ';
|
|
138
|
+
if (indent === '\t')
|
|
139
|
+
return '\t';
|
|
140
|
+
if (!Number.isInteger(indent) || indent < 0 || indent > 8) {
|
|
141
|
+
throw new Error(`writeIdsXml: indent must be '\\t' or an integer from 0 to 8, got ${indent}`);
|
|
142
|
+
}
|
|
143
|
+
return ' '.repeat(indent);
|
|
144
|
+
}
|
|
145
|
+
function writeSpecification(xml, spec, canonical) {
|
|
146
|
+
const versions = versionTokens(spec.ifcVersions, canonical);
|
|
147
|
+
const facets = canonical
|
|
148
|
+
? [...spec.applicability.facets].sort((a, b) => FACET_ORDER[a.type] - FACET_ORDER[b.type])
|
|
149
|
+
: spec.applicability.facets;
|
|
150
|
+
xml.open('specification', {
|
|
151
|
+
name: spec.name,
|
|
152
|
+
ifcVersion: versions.join(' '),
|
|
153
|
+
identifier: spec.identifier,
|
|
154
|
+
description: spec.description,
|
|
155
|
+
instructions: spec.instructions,
|
|
156
|
+
});
|
|
157
|
+
const maxOccurs = spec.maxOccurs === undefined ? 'unbounded' : String(spec.maxOccurs);
|
|
158
|
+
xml.open('applicability', { minOccurs: String(spec.minOccurs ?? 0), maxOccurs });
|
|
159
|
+
for (const facet of facets)
|
|
160
|
+
writeFacet(xml, facet, undefined, 'applicability');
|
|
161
|
+
xml.close('applicability');
|
|
162
|
+
if (spec.requirements.length > 0) {
|
|
163
|
+
xml.open('requirements');
|
|
164
|
+
for (const requirement of spec.requirements)
|
|
165
|
+
writeRequirement(xml, requirement);
|
|
166
|
+
xml.close('requirements');
|
|
167
|
+
}
|
|
168
|
+
xml.close('specification');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* `doc` as an IDS 1.0 XML string, laid out per `fmt` (two-space indent,
|
|
172
|
+
* `\n`, authored order by default). IDS 1.1 PREVIEW output needs
|
|
173
|
+
* `options.preview.ids11`.
|
|
174
|
+
*/
|
|
175
|
+
export function writeIdsXml(doc, fmt = {}, options = {}) {
|
|
176
|
+
const ids11 = assertIds11Allowed(doc, options.preview, 'writeIdsXml', true).length > 0;
|
|
177
|
+
const xml = new XmlLines(indentUnit(fmt.indent));
|
|
178
|
+
const newline = fmt.newline ?? '\n';
|
|
179
|
+
const canonical = fmt.canonical ?? false;
|
|
180
|
+
xml.open('ids', {
|
|
181
|
+
xmlns: IDS_NS,
|
|
182
|
+
'xmlns:xs': XS_NS,
|
|
183
|
+
'xmlns:xsi': XSI_NS,
|
|
184
|
+
'xsi:schemaLocation': ids11 ? SCHEMA_LOCATION_11_PREVIEW : SCHEMA_LOCATION,
|
|
185
|
+
});
|
|
186
|
+
if (ids11)
|
|
187
|
+
xml.comment(IDS11_PREVIEW_NOTE);
|
|
188
|
+
xml.open('info');
|
|
189
|
+
// The `ids.xsd` info sequence. `date` (xs:date) and `author` (an e-mail
|
|
190
|
+
// pattern) are written as given; `auditIDSDocument` reports malformed ones.
|
|
191
|
+
const { title, copyright, version, description, author, date, purpose, milestone } = doc.info;
|
|
192
|
+
xml.leaf('title', title);
|
|
193
|
+
const optional = [
|
|
194
|
+
['copyright', copyright], ['version', version], ['description', description], ['author', author],
|
|
195
|
+
['date', date], ['purpose', purpose], ['milestone', milestone],
|
|
196
|
+
];
|
|
197
|
+
for (const [tag, text] of optional) {
|
|
198
|
+
if (text)
|
|
199
|
+
xml.leaf(tag, text);
|
|
200
|
+
}
|
|
201
|
+
xml.close('info');
|
|
202
|
+
xml.open('specifications');
|
|
203
|
+
for (const spec of doc.specifications)
|
|
204
|
+
writeSpecification(xml, spec, canonical);
|
|
205
|
+
xml.close('specifications');
|
|
206
|
+
xml.close('ids');
|
|
207
|
+
return ['<?xml version="1.0" encoding="UTF-8"?>', ...xml.lines, ''].join(newline);
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/writer/index.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAwB/D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAG5D,MAAM,MAAM,GAAG,wCAAwC,CAAC;AACxD,MAAM,KAAK,GAAG,kCAAkC,CAAC;AACjD,MAAM,MAAM,GAAG,2CAA2C,CAAC;AAC3D,MAAM,eAAe,GAAG,GAAG,MAAM,qDAAqD,CAAC;AACvF;;;;GAIG;AACH,MAAM,0BAA0B,GAAG,GAAG,MAAM,qDAAqD,CAAC;AAClG,MAAM,kBAAkB,GAAG,yEAAyE,CAAC;AAErG;;;;GAIG;AACH,SAAS,aAAa,CAAC,QAAwB;IAC7C,IAAI,QAAQ,KAAK,oBAAoB,IAAI,QAAQ,KAAK,oBAAoB,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,gCAAgC,QAAQ,wGAAwG,CAAC,CAAC;IACpK,CAAC;IACD,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;AAChC,CAAC;AAED,SAAS,WAAW,CAAC,GAAa,EAAE,KAA4C,EAAE,QAA4C,EAAE;IAC9H,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1B,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,cAAc;QAAE,eAAe,CAAC,GA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AQ,EAAE,MAAM,CAAC;QAChG,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,CAAC;KAC/D,CAAC;IACF,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC;QACnC,IAAI,IAAI;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAClB,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,cAAc;QAAE,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAChF,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC5B,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjB,OAAO,CAAC,wCAAwC,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** `field` names the element or attribute, so a refusal says what to fix. */
|
|
2
|
+
export declare function escapeXml(text: string, field: string): string;
|
|
3
|
+
export declare class XmlLines {
|
|
4
|
+
private readonly unit;
|
|
5
|
+
readonly lines: string[];
|
|
6
|
+
private depth;
|
|
7
|
+
/** `unit` is the indentation of one nesting level. */
|
|
8
|
+
constructor(unit?: string);
|
|
9
|
+
open(tag: string, attrs?: Record<string, string | undefined>): void;
|
|
10
|
+
close(tag: string): void;
|
|
11
|
+
leaf(tag: string, text: string, attrs?: Record<string, string | undefined>): void;
|
|
12
|
+
/** An XML comment line; `--` cannot appear inside one and is refused. */
|
|
13
|
+
comment(text: string): void;
|
|
14
|
+
empty(tag: string, attrs?: Record<string, string | undefined>): void;
|
|
15
|
+
private indent;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=xml-lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-lines.d.ts","sourceRoot":"","sources":["../../src/writer/xml-lines.ts"],"names":[],"mappings":"AAWA,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAc7D;AAOD,qBAAa,QAAQ;IAKP,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJjC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAM;IAC9B,OAAO,CAAC,KAAK,CAAK;IAElB,sDAAsD;gBACzB,IAAI,SAAO;IAExC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAM,GAAG,IAAI;IAKvE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKxB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAM,GAAG,IAAI;IAIrF,yEAAyE;IACzE,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK3B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAM,GAAG,IAAI;IAIxE,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
/** XML escaping and the indented line buffer behind `writeIdsXml`. */
|
|
5
|
+
/** Characters XML 1.0 cannot carry, even as character references. */
|
|
6
|
+
// Matching control characters is the point: they are refused, not allowed through.
|
|
7
|
+
// eslint-disable-next-line no-control-regex
|
|
8
|
+
const NOT_XML = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/;
|
|
9
|
+
/** `field` names the element or attribute, so a refusal says what to fix. */
|
|
10
|
+
export function escapeXml(text, field) {
|
|
11
|
+
const bad = NOT_XML.exec(text);
|
|
12
|
+
if (bad) {
|
|
13
|
+
const code = bad[0].charCodeAt(0).toString(16).toUpperCase().padStart(4, '0');
|
|
14
|
+
throw new Error(`writeIdsXml: ${field} contains control character U+${code}, which XML 1.0 cannot carry`);
|
|
15
|
+
}
|
|
16
|
+
return text
|
|
17
|
+
.replace(/&/g, '&')
|
|
18
|
+
.replace(/</g, '<')
|
|
19
|
+
.replace(/>/g, '>')
|
|
20
|
+
.replace(/"/g, '"')
|
|
21
|
+
.replace(/'/g, ''')
|
|
22
|
+
// A raw CR is normalised away by every XML reader; a reference survives.
|
|
23
|
+
.replace(/\r/g, ' ');
|
|
24
|
+
}
|
|
25
|
+
/** Attribute-value normalisation turns raw line breaks and tabs into spaces; references keep them. */
|
|
26
|
+
function escapeAttr(text, field) {
|
|
27
|
+
return escapeXml(text, field).replace(/\n/g, ' ').replace(/\t/g, '	');
|
|
28
|
+
}
|
|
29
|
+
export class XmlLines {
|
|
30
|
+
unit;
|
|
31
|
+
lines = [];
|
|
32
|
+
depth = 0;
|
|
33
|
+
/** `unit` is the indentation of one nesting level. */
|
|
34
|
+
constructor(unit = ' ') {
|
|
35
|
+
this.unit = unit;
|
|
36
|
+
}
|
|
37
|
+
open(tag, attrs = {}) {
|
|
38
|
+
this.lines.push(`${this.indent()}<${tag}${renderAttrs(tag, attrs)}>`);
|
|
39
|
+
this.depth++;
|
|
40
|
+
}
|
|
41
|
+
close(tag) {
|
|
42
|
+
this.depth--;
|
|
43
|
+
this.lines.push(`${this.indent()}</${tag}>`);
|
|
44
|
+
}
|
|
45
|
+
leaf(tag, text, attrs = {}) {
|
|
46
|
+
this.lines.push(`${this.indent()}<${tag}${renderAttrs(tag, attrs)}>${escapeXml(text, tag)}</${tag}>`);
|
|
47
|
+
}
|
|
48
|
+
/** An XML comment line; `--` cannot appear inside one and is refused. */
|
|
49
|
+
comment(text) {
|
|
50
|
+
if (text.includes('--'))
|
|
51
|
+
throw new Error('writeIdsXml: an XML comment cannot contain "--"');
|
|
52
|
+
this.lines.push(`${this.indent()}<!-- ${escapeXml(text, 'comment')} -->`);
|
|
53
|
+
}
|
|
54
|
+
empty(tag, attrs = {}) {
|
|
55
|
+
this.lines.push(`${this.indent()}<${tag}${renderAttrs(tag, attrs)}/>`);
|
|
56
|
+
}
|
|
57
|
+
indent() {
|
|
58
|
+
return this.unit.repeat(this.depth);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function renderAttrs(tag, attrs) {
|
|
62
|
+
let out = '';
|
|
63
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
64
|
+
if (value !== undefined)
|
|
65
|
+
out += ` ${key}="${escapeAttr(value, `${tag} "${key}"`)}"`;
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=xml-lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-lines.js","sourceRoot":"","sources":["../../src/writer/xml-lines.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D,sEAAsE;AAEtE,qEAAqE;AACrE,mFAAmF;AACnF,4CAA4C;AAC5C,MAAM,OAAO,GAAG,sDAAsD,CAAC;AAEvE,6EAA6E;AAC7E,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAA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OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ifc-lite/ids",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "IDS (Information Delivery Specification) support for IFC-Lite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@xmldom/xmldom": "^0.9.12",
|
|
21
21
|
"@ifc-lite/codegen": "1.18.1",
|
|
22
|
-
"@ifc-lite/data": "6.
|
|
22
|
+
"@ifc-lite/data": "6.2.0",
|
|
23
23
|
"@ifc-lite/encoding": "2.3.0",
|
|
24
|
-
"@ifc-lite/parser": "9.
|
|
24
|
+
"@ifc-lite/parser": "9.4.0",
|
|
25
25
|
"@ifc-lite/regex-guard": "0.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"happy-dom": "^20.14.
|
|
28
|
+
"happy-dom": "^20.14.6",
|
|
29
29
|
"typescript": "^6.0.3",
|
|
30
|
-
"vitest": "^5.0.
|
|
30
|
+
"vitest": "^5.0.3",
|
|
31
31
|
"xmllint-wasm": "5.3.0",
|
|
32
32
|
"@ifc-lite/timing-ladder": "^0.1.0"
|
|
33
33
|
},
|