@ifc-lite/ids 1.15.49 → 1.15.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/data-types.d.ts.map +1 -1
- package/dist/bridge/data-types.js +1 -0
- package/dist/bridge/data-types.js.map +1 -1
- package/dist/constraint-types.d.ts +110 -0
- package/dist/constraint-types.d.ts.map +1 -0
- package/dist/constraint-types.js +5 -0
- package/dist/constraint-types.js.map +1 -0
- package/dist/constraints/describe.d.ts +17 -0
- package/dist/constraints/describe.d.ts.map +1 -0
- package/dist/constraints/describe.js +140 -0
- package/dist/constraints/describe.js.map +1 -0
- package/dist/constraints/index.d.ts +1 -8
- package/dist/constraints/index.d.ts.map +1 -1
- package/dist/constraints/index.js +13 -361
- package/dist/constraints/index.js.map +1 -1
- package/dist/constraints/match-family.d.ts +20 -0
- package/dist/constraints/match-family.d.ts.map +1 -0
- package/dist/constraints/match-family.js +265 -0
- package/dist/constraints/match-family.js.map +1 -0
- package/dist/constraints/xsd-cast.d.ts +10 -1
- package/dist/constraints/xsd-cast.d.ts.map +1 -1
- package/dist/constraints/xsd-cast.js +66 -2
- package/dist/constraints/xsd-cast.js.map +1 -1
- package/dist/facets/property-facet.d.ts.map +1 -1
- package/dist/facets/property-facet.js +30 -33
- package/dist/facets/property-facet.js.map +1 -1
- package/dist/parser/dom.d.ts +11 -0
- package/dist/parser/dom.d.ts.map +1 -0
- package/dist/parser/dom.js +49 -0
- package/dist/parser/dom.js.map +1 -0
- package/dist/parser/xml-parser.d.ts.map +1 -1
- package/dist/parser/xml-parser.js +46 -58
- package/dist/parser/xml-parser.js.map +1 -1
- package/dist/translation/describe-constraint.d.ts +18 -0
- package/dist/translation/describe-constraint.d.ts.map +1 -0
- package/dist/translation/describe-constraint.js +77 -0
- package/dist/translation/describe-constraint.js.map +1 -0
- package/dist/translation/locales/de.d.ts +1 -0
- package/dist/translation/locales/de.d.ts.map +1 -1
- package/dist/translation/locales/de.js +1 -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 +1 -0
- package/dist/translation/locales/fr.d.ts.map +1 -1
- package/dist/translation/locales/fr.js +1 -0
- package/dist/translation/locales/fr.js.map +1 -1
- package/dist/translation/service.d.ts +4 -5
- package/dist/translation/service.d.ts.map +1 -1
- package/dist/translation/service.js +8 -58
- package/dist/translation/service.js.map +1 -1
- package/dist/types.d.ts +2 -59
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-types.d.ts","sourceRoot":"","sources":["../../src/bridge/data-types.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAsBhF;AAED,4CAA4C;AAC5C,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"data-types.d.ts","sourceRoot":"","sources":["../../src/bridge/data-types.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAsBhF;AAED,4CAA4C;AAC5C,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-types.js","sourceRoot":"","sources":["../../src/bridge/data-types.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAiC;IACtE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,IAAI,IAAI,CAAC,U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AClC,KAAK,CAAC,CAAC,CAAC,OAAO,gBAAgB,CAAC;QAChC,KAAK,CAAC,CAAC,CAAC,OAAO,kBAAkB,CAAC;QAClC,KAAK,CAAC,CAAC,CAAC,OAAO,iBAAiB,CAAC;QACjC,KAAK,CAAC,CAAC,CAAC,OAAO,gBAAgB,CAAC;QAChC,KAAK,CAAC,CAAC,CAAC,OAAO,gBAAgB,CAAC;QAChC,KAAK,CAAC,CAAC,CAAC,OAAO,mBAAmB,CAAC;QACnC,OAAO,CAAC,CAAC,OAAO,UAAU,CAAC;IAC7B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IDS constraint types — the value-matching half of the IDS type model.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `types.ts`, which re-exports every name here, so the two
|
|
5
|
+
* can grow independently. Import from `../types.js` (or the package
|
|
6
|
+
* root) as before; this module is an implementation detail of that
|
|
7
|
+
* re-export.
|
|
8
|
+
*/
|
|
9
|
+
/** Union of all constraint types */
|
|
10
|
+
export type IDSConstraint = IDSSimpleValue | IDSPatternConstraint | IDSEnumerationConstraint | IDSBoundsConstraint;
|
|
11
|
+
/** Simple value - exact match */
|
|
12
|
+
export interface IDSSimpleValue {
|
|
13
|
+
type: 'simpleValue';
|
|
14
|
+
/** The exact value to match */
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
/** Pattern constraint - regex match */
|
|
18
|
+
export interface IDSPatternConstraint {
|
|
19
|
+
type: 'pattern';
|
|
20
|
+
/** XSD regex pattern */
|
|
21
|
+
pattern: string;
|
|
22
|
+
/**
|
|
23
|
+
* The originating `xs:restriction @base` (e.g. `xs:string`, `xs:integer`).
|
|
24
|
+
* Set when the constraint came from an `<xs:restriction>` element; the
|
|
25
|
+
* auditor uses it to determine compatibility with an IFC dataType
|
|
26
|
+
* without inferring the base from the constraint shape.
|
|
27
|
+
*/
|
|
28
|
+
base?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Facets of the SAME `<xs:restriction>` beyond this one. XSD facets in
|
|
31
|
+
* a single restriction are conjunctive — a value must satisfy every
|
|
32
|
+
* one — but one `IDSConstraint` expresses only one family, so
|
|
33
|
+
* `parseRestriction` keeps the first here and hangs the rest off this
|
|
34
|
+
* list for `matchConstraint` to require as well. Unset for the
|
|
35
|
+
* overwhelmingly common single-family restriction. Matching
|
|
36
|
+
* (`matchConstraint`) and the two description paths
|
|
37
|
+
* (`formatConstraint`, `TranslationService.describeConstraint`)
|
|
38
|
+
* account for it. The IDS-document auditors under `audit/` still
|
|
39
|
+
* inspect only the primary family, so a malformed regex or an
|
|
40
|
+
* inverted bound in a sibling is not linted.
|
|
41
|
+
*/
|
|
42
|
+
and?: readonly IDSConstraint[];
|
|
43
|
+
}
|
|
44
|
+
/** Enumeration constraint - one of a list of values */
|
|
45
|
+
export interface IDSEnumerationConstraint {
|
|
46
|
+
type: 'enumeration';
|
|
47
|
+
/** List of allowed values */
|
|
48
|
+
values: string[];
|
|
49
|
+
/**
|
|
50
|
+
* The originating `xs:restriction @base` (e.g. `xs:string`,
|
|
51
|
+
* `xs:integer`). Set when the constraint came from an
|
|
52
|
+
* `<xs:restriction>`; numeric/boolean enumerations carry their base
|
|
53
|
+
* here so the auditor doesn't false-positive a string-base mismatch.
|
|
54
|
+
*/
|
|
55
|
+
base?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Facets of the SAME `<xs:restriction>` beyond this one. XSD facets in
|
|
58
|
+
* a single restriction are conjunctive — a value must satisfy every
|
|
59
|
+
* one — but one `IDSConstraint` expresses only one family, so
|
|
60
|
+
* `parseRestriction` keeps the first here and hangs the rest off this
|
|
61
|
+
* list for `matchConstraint` to require as well. Unset for the
|
|
62
|
+
* overwhelmingly common single-family restriction. Matching
|
|
63
|
+
* (`matchConstraint`) and the two description paths
|
|
64
|
+
* (`formatConstraint`, `TranslationService.describeConstraint`)
|
|
65
|
+
* account for it. The IDS-document auditors under `audit/` still
|
|
66
|
+
* inspect only the primary family, so a malformed regex or an
|
|
67
|
+
* inverted bound in a sibling is not linted.
|
|
68
|
+
*/
|
|
69
|
+
and?: readonly IDSConstraint[];
|
|
70
|
+
}
|
|
71
|
+
/** Bounds constraint - numeric range or string length */
|
|
72
|
+
export interface IDSBoundsConstraint {
|
|
73
|
+
type: 'bounds';
|
|
74
|
+
/** Minimum inclusive value */
|
|
75
|
+
minInclusive?: number;
|
|
76
|
+
/** Maximum inclusive value */
|
|
77
|
+
maxInclusive?: number;
|
|
78
|
+
/** Minimum exclusive value */
|
|
79
|
+
minExclusive?: number;
|
|
80
|
+
/** Maximum exclusive value */
|
|
81
|
+
maxExclusive?: number;
|
|
82
|
+
/** xs:length — exact string length */
|
|
83
|
+
length?: number;
|
|
84
|
+
/** xs:minLength — minimum string length */
|
|
85
|
+
minLength?: number;
|
|
86
|
+
/** xs:maxLength — maximum string length */
|
|
87
|
+
maxLength?: number;
|
|
88
|
+
/**
|
|
89
|
+
* The originating `xs:restriction @base` (e.g. `xs:double`,
|
|
90
|
+
* `xs:integer`). Set when the constraint came from an
|
|
91
|
+
* `<xs:restriction>` so the auditor can compare against the IFC
|
|
92
|
+
* dataType's backing type directly.
|
|
93
|
+
*/
|
|
94
|
+
base?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Facets of the SAME `<xs:restriction>` beyond this one. XSD facets in
|
|
97
|
+
* a single restriction are conjunctive — a value must satisfy every
|
|
98
|
+
* one — but one `IDSConstraint` expresses only one family, so
|
|
99
|
+
* `parseRestriction` keeps the first here and hangs the rest off this
|
|
100
|
+
* list for `matchConstraint` to require as well. Unset for the
|
|
101
|
+
* overwhelmingly common single-family restriction. Matching
|
|
102
|
+
* (`matchConstraint`) and the two description paths
|
|
103
|
+
* (`formatConstraint`, `TranslationService.describeConstraint`)
|
|
104
|
+
* account for it. The IDS-document auditors under `audit/` still
|
|
105
|
+
* inspect only the primary family, so a malformed regex or an
|
|
106
|
+
* inverted bound in a sibling is not linted.
|
|
107
|
+
*/
|
|
108
|
+
and?: readonly IDSConstraint[];
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=constraint-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint-types.d.ts","sourceRoot":"","sources":["../src/constraint-types.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH,oCAAoC;AACpC,MAAM,MAAM,aAAa,GACrB,cAAc,GACd,oBAAoB,GACpB,wBAAwB,GACxB,mBAAmB,CAAC;AAExB,iCAAiC;AACjC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,uCAAuC;AACvC,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CAChC;AAED,uDAAuD;AACvD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,aAAa,CAAC;IACpB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CAChC;AAED,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,QAAQ,CAAC;IACf,8BAA8B;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint-types.js","sourceRoot":"","sources":["../src/constraint-types.ts"],"names":[],"mappings":"AAAA;;+DAE+D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable rendering of an IDS constraint: the expected-value
|
|
3
|
+
* display and the mismatch reason embedded in validation results.
|
|
4
|
+
*
|
|
5
|
+
* Split out of `constraints/index.ts`, which re-exports both entry
|
|
6
|
+
* points, so matching and reporting can grow independently.
|
|
7
|
+
*/
|
|
8
|
+
import type { IDSConstraint } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Get a human-readable description of why a constraint match failed
|
|
11
|
+
*/
|
|
12
|
+
export declare function getConstraintMismatchReason(constraint: IDSConstraint, actualValue: string | number | boolean | null | undefined): string;
|
|
13
|
+
/**
|
|
14
|
+
* Format a constraint for display
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatConstraint(constraint: IDSConstraint): string;
|
|
17
|
+
//# sourceMappingURL=describe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.d.ts","sourceRoot":"","sources":["../../src/constraints/describe.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,aAAa,EAEd,MAAM,aAAa,CAAC;AAyBrB;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,aAAa,EACzB,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GACxD,MAAM,CA6BR;AAkDD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,aAAa,GAAG,MAAM,CAOlE"}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 { conjunctiveFacetsOf, matchOneFamily, NUMERIC_TOLERANCE, } from './match-family.js';
|
|
5
|
+
/**
|
|
6
|
+
* Cap enumeration rendering. These strings are embedded in per-entity
|
|
7
|
+
* validation results — an uncapped 800-value code list produced ~20KB
|
|
8
|
+
* per result and ballooned reports into the gigabytes (OOM crash on
|
|
9
|
+
* large models). The full value list stays available on the constraint
|
|
10
|
+
* object itself.
|
|
11
|
+
*/
|
|
12
|
+
const MAX_ENUM_DISPLAY_VALUES = 10;
|
|
13
|
+
function formatEnumValues(values) {
|
|
14
|
+
const shown = values
|
|
15
|
+
.slice(0, MAX_ENUM_DISPLAY_VALUES)
|
|
16
|
+
.map((v) => `"${v}"`)
|
|
17
|
+
.join(', ');
|
|
18
|
+
const more = values.length - MAX_ENUM_DISPLAY_VALUES;
|
|
19
|
+
return more > 0 ? `[${shown}, … +${more} more]` : `[${shown}]`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get a human-readable description of why a constraint match failed
|
|
23
|
+
*/
|
|
24
|
+
export function getConstraintMismatchReason(constraint, actualValue) {
|
|
25
|
+
if (actualValue === null || actualValue === undefined) {
|
|
26
|
+
return 'value is missing';
|
|
27
|
+
}
|
|
28
|
+
// Report the facet that actually rejected the value, not the primary
|
|
29
|
+
// one. With conjunctive facets the primary often matched and a
|
|
30
|
+
// sibling is what failed.
|
|
31
|
+
const siblings = conjunctiveFacetsOf(constraint);
|
|
32
|
+
if (siblings !== undefined && matchOneFamily(constraint, actualValue, false)) {
|
|
33
|
+
for (const sibling of siblings) {
|
|
34
|
+
if (!matchOneFamily(sibling, actualValue, false)) {
|
|
35
|
+
return getConstraintMismatchReason(sibling, actualValue);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
switch (constraint.type) {
|
|
40
|
+
case 'simpleValue':
|
|
41
|
+
return `expected "${constraint.value}", got "${actualValue}"`;
|
|
42
|
+
case 'pattern':
|
|
43
|
+
return `"${actualValue}" does not match pattern "${constraint.pattern}"`;
|
|
44
|
+
case 'enumeration':
|
|
45
|
+
return `"${actualValue}" is not one of ${formatEnumValues(constraint.values)}`;
|
|
46
|
+
case 'bounds':
|
|
47
|
+
return getBoundsMismatchReason(constraint, actualValue);
|
|
48
|
+
default:
|
|
49
|
+
return 'unknown constraint type';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function getBoundsMismatchReason(constraint, actualValue) {
|
|
53
|
+
const num = typeof actualValue === 'number'
|
|
54
|
+
? actualValue
|
|
55
|
+
: parseFloat(String(actualValue));
|
|
56
|
+
if (isNaN(num)) {
|
|
57
|
+
return `"${actualValue}" is not a valid number`;
|
|
58
|
+
}
|
|
59
|
+
const violations = [];
|
|
60
|
+
if (constraint.minInclusive !== undefined &&
|
|
61
|
+
num < constraint.minInclusive - NUMERIC_TOLERANCE) {
|
|
62
|
+
violations.push(`must be >= ${constraint.minInclusive}`);
|
|
63
|
+
}
|
|
64
|
+
if (constraint.maxInclusive !== undefined &&
|
|
65
|
+
num > constraint.maxInclusive + NUMERIC_TOLERANCE) {
|
|
66
|
+
violations.push(`must be <= ${constraint.maxInclusive}`);
|
|
67
|
+
}
|
|
68
|
+
if (constraint.minExclusive !== undefined && num <= constraint.minExclusive) {
|
|
69
|
+
violations.push(`must be > ${constraint.minExclusive}`);
|
|
70
|
+
}
|
|
71
|
+
if (constraint.maxExclusive !== undefined && num >= constraint.maxExclusive) {
|
|
72
|
+
violations.push(`must be < ${constraint.maxExclusive}`);
|
|
73
|
+
}
|
|
74
|
+
return `${num} ${violations.join(' and ')}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Per-constraint display-string cache. Failure paths format the same
|
|
78
|
+
* constraint for every non-matching entity — millions of times during
|
|
79
|
+
* applicability filtering — and the output depends only on the
|
|
80
|
+
* constraint object.
|
|
81
|
+
*/
|
|
82
|
+
const FORMAT_CACHE = new WeakMap();
|
|
83
|
+
/**
|
|
84
|
+
* Format a constraint for display
|
|
85
|
+
*/
|
|
86
|
+
export function formatConstraint(constraint) {
|
|
87
|
+
let formatted = FORMAT_CACHE.get(constraint);
|
|
88
|
+
if (formatted === undefined) {
|
|
89
|
+
formatted = formatConstraintUncached(constraint);
|
|
90
|
+
FORMAT_CACHE.set(constraint, formatted);
|
|
91
|
+
}
|
|
92
|
+
return formatted;
|
|
93
|
+
}
|
|
94
|
+
function formatConstraintUncached(constraint) {
|
|
95
|
+
const own = formatOneFamily(constraint);
|
|
96
|
+
const siblings = conjunctiveFacetsOf(constraint);
|
|
97
|
+
if (siblings === undefined)
|
|
98
|
+
return own;
|
|
99
|
+
// Conjunctive facets from the same restriction. Naming only the
|
|
100
|
+
// primary would report an expectation narrower than the one enforced.
|
|
101
|
+
return [own, ...siblings.map(formatOneFamily)].join(' and ');
|
|
102
|
+
}
|
|
103
|
+
function formatOneFamily(constraint) {
|
|
104
|
+
switch (constraint.type) {
|
|
105
|
+
case 'simpleValue':
|
|
106
|
+
return `"${constraint.value}"`;
|
|
107
|
+
case 'pattern':
|
|
108
|
+
return `pattern "${constraint.pattern}"`;
|
|
109
|
+
case 'enumeration':
|
|
110
|
+
if (constraint.values.length === 1) {
|
|
111
|
+
return `"${constraint.values[0]}"`;
|
|
112
|
+
}
|
|
113
|
+
return `one of ${formatEnumValues(constraint.values)}`;
|
|
114
|
+
case 'bounds':
|
|
115
|
+
return formatBounds(constraint);
|
|
116
|
+
default:
|
|
117
|
+
return 'unknown';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function formatBounds(constraint) {
|
|
121
|
+
const parts = [];
|
|
122
|
+
if (constraint.minInclusive !== undefined &&
|
|
123
|
+
constraint.maxInclusive !== undefined) {
|
|
124
|
+
return `between ${constraint.minInclusive} and ${constraint.maxInclusive}`;
|
|
125
|
+
}
|
|
126
|
+
if (constraint.minInclusive !== undefined) {
|
|
127
|
+
parts.push(`>= ${constraint.minInclusive}`);
|
|
128
|
+
}
|
|
129
|
+
if (constraint.maxInclusive !== undefined) {
|
|
130
|
+
parts.push(`<= ${constraint.maxInclusive}`);
|
|
131
|
+
}
|
|
132
|
+
if (constraint.minExclusive !== undefined) {
|
|
133
|
+
parts.push(`> ${constraint.minExclusive}`);
|
|
134
|
+
}
|
|
135
|
+
if (constraint.maxExclusive !== undefined) {
|
|
136
|
+
parts.push(`< ${constraint.maxExclusive}`);
|
|
137
|
+
}
|
|
138
|
+
return parts.join(' and ') || 'any value';
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=describe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe.js","sourceRoot":"","sources":["../../src/constraints/describe.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAc/D,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,SAAS,gBAAgB,CAAC,MAAgB;IACxC,MAAM,KAAK,GAAG,MAAM;SACjB,KAAK,CAAC,CAAC,EAAE,uBAAuB,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;SACpB,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,uBAAuB,CAAC;IACrD,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC;AACjE,CAA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CAAC;IAED,IAAI,UAAU,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,UAAU,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,UAAU,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,UAAU,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC,YAAY,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,WAAW,CAAC;AAC5C,CAAC"}
|
|
@@ -16,12 +16,5 @@ export interface MatchOptions {
|
|
|
16
16
|
* Check if a value matches a constraint
|
|
17
17
|
*/
|
|
18
18
|
export declare function matchConstraint(constraint: IDSConstraint, actualValue: string | number | boolean | null | undefined, options?: MatchOptions): boolean;
|
|
19
|
-
|
|
20
|
-
* Get a human-readable description of why a constraint match failed
|
|
21
|
-
*/
|
|
22
|
-
export declare function getConstraintMismatchReason(constraint: IDSConstraint, actualValue: string | number | boolean | null | undefined): string;
|
|
23
|
-
/**
|
|
24
|
-
* Format a constraint for display
|
|
25
|
-
*/
|
|
26
|
-
export declare function formatConstraint(constraint: IDSConstraint): string;
|
|
19
|
+
export { getConstraintMismatchReason, formatConstraint, } from './describe.js';
|
|
27
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constraints/index.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constraints/index.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,sCAAsC;AACtC,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,aAAa,EACzB,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EACzD,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAoBT;AAGD,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
|