@rulecad/variables 0.3.4 → 0.3.6
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/CHANGELOG.md +16 -0
- package/package.json +3 -2
- package/variables.d.mts +2 -1
- package/variables.mjs +9 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog: @rulecad/variables
|
|
2
|
+
|
|
3
|
+
What changed in each release, for someone upgrading a workspace.
|
|
4
|
+
|
|
5
|
+
## 0.3.6: material ranges
|
|
6
|
+
### Added
|
|
7
|
+
|
|
8
|
+
- `checkRuleSet` holds a rule's range to its value: `low` at most it, `high` at least it, both numbers (`rules.range`).
|
|
9
|
+
|
|
10
|
+
## 0.3.5: points in a rule set
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- A vocabulary field may be `points` (so many numbers each, one after another), and a rule set's list is checked to
|
|
15
|
+
hold whole points.
|
|
16
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/variables",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Design values you can trace: every number says where it comes from, and expressions are parsed, never run.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"variables.mjs",
|
|
12
12
|
"variables.d.mts",
|
|
13
13
|
"README.md",
|
|
14
|
-
"LICENSE"
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"CHANGELOG.md"
|
|
15
16
|
],
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"keywords": [
|
package/variables.d.mts
CHANGED
|
@@ -33,7 +33,7 @@ export function resolve(object: DesignObject, { sets, set, display, load }?: {
|
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* @param {RuleSet & { part?: string, interface?: Record<string, string> }} set
|
|
36
|
-
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
36
|
+
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean, points?: number }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
37
37
|
* @returns {{ level: 'fail', code: string, text: string, rule?: string, values?: Record<string, number> }[]} what's wrong with it: nothing, if it passes
|
|
38
38
|
*/
|
|
39
39
|
export function checkRuleSet(set: RuleSet & {
|
|
@@ -46,6 +46,7 @@ export function checkRuleSet(set: RuleSet & {
|
|
|
46
46
|
unit?: string;
|
|
47
47
|
choice?: string[];
|
|
48
48
|
list?: boolean;
|
|
49
|
+
points?: number;
|
|
49
50
|
}>;
|
|
50
51
|
parts: Record<string, string[]>;
|
|
51
52
|
checks?: Record<string, {
|
package/variables.mjs
CHANGED
|
@@ -276,11 +276,13 @@ export function resolve(object, { sets = {}, set = {}, display = {}, load } = {}
|
|
|
276
276
|
// { "ascending": ["tap_drill", "major_diameter", "clearance"], "says": "…" } the names it has, each larger than the last
|
|
277
277
|
// { "near": "tap_drill", "to": "major_diameter - pitch", "within": "0.2 * pitch", "says": "…" } expressions over its own rules
|
|
278
278
|
// and a field marked "list": true holds a list (the lengths a screw is sold in), which must ascend.
|
|
279
|
+
// A number may carry the range it is found in, "low" and "high" (a printed plastic's, which varies with the printer and
|
|
280
|
+
// the spool), each a number in its unit, low at most the value and high at least it.
|
|
279
281
|
const KINDS = ['measured', 'spec', 'community', 'default', 'derived', 'estimate'];
|
|
280
282
|
const finite = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
281
283
|
/**
|
|
282
284
|
* @param {RuleSet & { part?: string, interface?: Record<string, string> }} set
|
|
283
|
-
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
285
|
+
* @param {{ units: string[], prefixes: string[], fields: Record<string, { unit?: string, choice?: string[], list?: boolean, points?: number }>, parts: Record<string, string[]>, checks?: Record<string, { ascending?: string[], near?: string, to?: string, within?: string, says: string }[]> }} vocabulary
|
|
284
286
|
* @returns {{ level: 'fail', code: string, text: string, rule?: string, values?: Record<string, number> }[]} what's wrong with it: nothing, if it passes
|
|
285
287
|
*/
|
|
286
288
|
export function checkRuleSet(set, vocabulary) {
|
|
@@ -289,10 +291,16 @@ export function checkRuleSet(set, vocabulary) {
|
|
|
289
291
|
for (const [name, r] of Object.entries(rules)) {
|
|
290
292
|
const list = Array.isArray(r.value);
|
|
291
293
|
if (!(list ? r.value.length && r.value.every(finite) : finite(r.value) || (typeof r.value === 'string' && r.value))) f('rules.value', list ? `${name} is a list, so every entry is a number and there is at least one` : `${name} has no value`, name);
|
|
294
|
+
else if (list && fields?.[name]?.points) { const n = fields[name].points; if (r.value.length % n) f('rules.list', `${name} is points of ${n} numbers each, one after another: ${r.value.length} numbers is not a whole number of them`, name); } // (points: in the order they are, not ascending)
|
|
292
295
|
else if (list) { const i = r.value.findIndex((x, k) => k && x <= r.value[k - 1]); if (i > 0) f('rules.order', `${name} is a list in ascending order: ${r.value[i]} follows ${r.value[i - 1]}`, name, { before: r.value[i - 1], after: r.value[i] }); }
|
|
293
296
|
if (!(typeof r.rule === 'string' && r.rule.length > 5)) f('rules.says', `${name} doesn't say what it is ("rule")`, name);
|
|
294
297
|
if (!KINDS.includes(r.kind)) f('rules.kind', `${name}: kind ${JSON.stringify(r.kind)} is not one of ${KINDS.join(', ')}`, name);
|
|
295
298
|
if (!(typeof r.source === 'string' && r.source)) f('rules.source', `${name} has no source`, name);
|
|
299
|
+
for (const [k, ok] of [['low', (v) => v <= r.value], ['high', (v) => v >= r.value]]) {
|
|
300
|
+
if (r[k] == null) continue;
|
|
301
|
+
if (!finite(r[k]) || !finite(r.value)) f('rules.range', `${name}: ${k} is a number in the rule's unit, beside a number value (got ${JSON.stringify(r[k])})`, name);
|
|
302
|
+
else if (!ok(r[k])) f('rules.range', `${name}: ${k} (${r[k]}) is ${k === 'low' ? 'above' : 'below'} its value (${r.value}): the range it is found in holds the value`, name, { value: r.value, [k]: r[k] });
|
|
303
|
+
}
|
|
296
304
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(String(r.checked))) f('rules.checked', `${name}: checked is the date it was last checked, YYYY-MM-DD (got ${JSON.stringify(r.checked)})`, name);
|
|
297
305
|
if (set.part) {
|
|
298
306
|
if (r.unit != null && !units.includes(r.unit)) f('rules.unit', `${name}: unit ${JSON.stringify(r.unit)} is not one of ${units.filter(Boolean).join(', ')}`, name);
|