@bitbybit-dev/base 1.4.0 → 1.5.0-rc.0
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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/color-space.d.ts +14 -0
- package/lib/api/color-space.js +24 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +2 -0
- package/lib/api/inputs/base-inputs.d.ts +382 -5
- package/lib/api/inputs/base-inputs.js +0 -3
- package/lib/api/inputs/color-inputs.d.ts +1 -1
- package/lib/api/inputs/color-inputs.js +0 -1
- package/lib/api/inputs/dates-inputs.js +0 -1
- package/lib/api/inputs/frame-inputs.d.ts +1 -1
- package/lib/api/inputs/inputs.js +0 -1
- package/lib/api/inputs/io-inputs.d.ts +1 -1
- package/lib/api/inputs/line-inputs.d.ts +1 -1
- package/lib/api/inputs/lists-inputs.js +0 -1
- package/lib/api/inputs/logic-inputs.d.ts +1 -1
- package/lib/api/inputs/logic-inputs.js +0 -1
- package/lib/api/inputs/math-inputs.js +0 -1
- package/lib/api/inputs/mesh-inputs.d.ts +29 -1
- package/lib/api/inputs/mesh-inputs.js +25 -1
- package/lib/api/inputs/point-inputs.d.ts +30 -1
- package/lib/api/inputs/point-inputs.js +28 -0
- package/lib/api/inputs/polyline-inputs.d.ts +1 -1
- package/lib/api/inputs/transforms-inputs.d.ts +1 -1
- package/lib/api/inputs/vector-inputs.d.ts +1 -1
- package/lib/api/kernel-calls/describe-failure.d.ts +3 -2
- package/lib/api/kernel-calls/describe-failure.js +9 -17
- package/lib/api/kernel-calls/failure-message.d.ts +1 -1
- package/lib/api/kernel-calls/hashing.d.ts +14 -0
- package/lib/api/kernel-calls/hashing.js +47 -0
- package/lib/api/kernel-calls/index.d.ts +3 -0
- package/lib/api/kernel-calls/index.js +3 -0
- package/lib/api/kernel-calls/input-rules.d.ts +1 -1
- package/lib/api/kernel-calls/input-rules.js +10 -5
- package/lib/api/kernel-calls/input-validation.d.ts +3 -3
- package/lib/api/kernel-calls/input-validation.js +24 -14
- package/lib/api/kernel-calls/kernel-steps.d.ts +19 -0
- package/lib/api/kernel-calls/kernel-steps.js +19 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +5 -3
- package/lib/api/kernel-calls/resolve-dto.js +9 -4
- package/lib/api/kernel-calls/unknown-values.d.ts +12 -0
- package/lib/api/kernel-calls/unknown-values.js +16 -0
- package/lib/api/kernel-calls/with-defaults.d.ts +1 -1
- package/lib/api/models/point/hex-grid-data.d.ts +1 -1
- package/lib/api/models/text/vector-char-data.d.ts +1 -1
- package/lib/api/models/text/vector-text-data.d.ts +1 -1
- package/lib/api/recipes/checker-types.d.ts +14 -0
- package/lib/api/recipes/checker-types.js +1 -0
- package/lib/api/recipes/index.d.ts +4 -0
- package/lib/api/recipes/index.js +3 -0
- package/lib/api/recipes/limits.constants.d.ts +23 -0
- package/lib/api/recipes/limits.constants.js +23 -0
- package/lib/api/recipes/recipe-types.d.ts +48 -0
- package/lib/api/recipes/recipe-types.js +1 -0
- package/lib/api/recipes/sources.d.ts +16 -0
- package/lib/api/recipes/sources.js +23 -0
- package/lib/api/recipes/surface-mesh.d.ts +16 -0
- package/lib/api/recipes/surface-mesh.js +86 -0
- package/lib/api/recipes/validate.d.ts +36 -0
- package/lib/api/recipes/validate.js +427 -0
- package/lib/api/resolved-inputs/index.d.ts +3 -0
- package/lib/api/services/color.d.ts +1 -1
- package/lib/api/services/frame.d.ts +3 -95
- package/lib/api/services/frame.js +24 -135
- package/lib/api/services/geometry-helper.d.ts +1 -1
- package/lib/api/services/helpers/arcs.d.ts +6 -0
- package/lib/api/services/helpers/arcs.js +30 -0
- package/lib/api/services/helpers/crc32.d.ts +1 -0
- package/lib/api/services/helpers/crc32.js +21 -0
- package/lib/api/services/helpers/dxf/dxf-generator.d.ts +0 -83
- package/lib/api/services/helpers/dxf/dxf-generator.js +5 -86
- package/lib/api/services/helpers/frame-axes.d.ts +9 -1
- package/lib/api/services/helpers/frame-axes.js +34 -0
- package/lib/api/services/helpers/helper-types.d.ts +34 -0
- package/lib/api/services/helpers/helper-types.js +1 -0
- package/lib/api/services/helpers/inflate.constants.d.ts +41 -0
- package/lib/api/services/helpers/inflate.constants.js +41 -0
- package/lib/api/services/helpers/inflate.d.ts +3 -0
- package/lib/api/services/helpers/inflate.js +228 -0
- package/lib/api/services/helpers/matrices.constants.d.ts +2 -0
- package/lib/api/services/helpers/matrices.constants.js +2 -0
- package/lib/api/services/helpers/matrices.d.ts +9 -1
- package/lib/api/services/helpers/matrices.js +18 -0
- package/lib/api/services/helpers/mesh-measures.d.ts +1 -0
- package/lib/api/services/helpers/mesh-measures.js +28 -0
- package/lib/api/services/helpers/mesh-normals.d.ts +2 -0
- package/lib/api/services/helpers/mesh-normals.js +118 -26
- package/lib/api/services/helpers/mesh-primitives.constants.d.ts +2 -0
- package/lib/api/services/helpers/mesh-primitives.constants.js +12 -0
- package/lib/api/services/helpers/mesh-primitives.d.ts +3 -0
- package/lib/api/services/helpers/mesh-primitives.js +46 -0
- package/lib/api/services/helpers/nurbs.d.ts +7 -0
- package/lib/api/services/helpers/nurbs.js +50 -0
- package/lib/api/services/helpers/paths.d.ts +8 -0
- package/lib/api/services/helpers/paths.js +96 -0
- package/lib/api/services/helpers/polygons.d.ts +8 -0
- package/lib/api/services/helpers/polygons.js +59 -0
- package/lib/api/services/helpers/surface-triangulation.d.ts +6 -0
- package/lib/api/services/helpers/surface-triangulation.js +298 -0
- package/lib/api/services/helpers/triangulation.d.ts +2 -0
- package/lib/api/services/helpers/triangulation.js +295 -0
- package/lib/api/services/helpers/vectors.d.ts +18 -0
- package/lib/api/services/helpers/vectors.js +17 -0
- package/lib/api/services/helpers/zip.constants.d.ts +34 -0
- package/lib/api/services/helpers/zip.constants.js +34 -0
- package/lib/api/services/helpers/zip.d.ts +4 -0
- package/lib/api/services/helpers/zip.js +89 -0
- package/lib/api/services/line.d.ts +3 -3
- package/lib/api/services/mesh.d.ts +37 -2
- package/lib/api/services/mesh.js +60 -3
- package/lib/api/services/point.d.ts +22 -10
- package/lib/api/services/point.js +42 -13
- package/lib/api/services/polyline.d.ts +39 -4
- package/lib/api/services/polyline.js +56 -6
- package/lib/api/services/text.d.ts +2 -2
- package/lib/api/services/text.js +10 -5
- package/lib/api/services/transforms.d.ts +3 -9
- package/lib/api/services/transforms.js +0 -6
- package/lib/api/services/vector.d.ts +2 -2
- package/lib/api/services/vector.js +2 -5
- package/package.json +1 -1
|
@@ -869,4 +869,32 @@ export var Point;
|
|
|
869
869
|
}
|
|
870
870
|
}
|
|
871
871
|
Point.HexGridCentersDto = HexGridCentersDto;
|
|
872
|
+
/**
|
|
873
|
+
* Three points on a circular arc and how finely to divide it, for `point.arcThroughThreePoints`.
|
|
874
|
+
*/
|
|
875
|
+
class ArcThroughThreePointsDto {
|
|
876
|
+
constructor(start, middle, end, segments) {
|
|
877
|
+
/**
|
|
878
|
+
* How many equal steps the arc is divided into; more steps follow the circle more closely.
|
|
879
|
+
* @default 16
|
|
880
|
+
* @minimum 1
|
|
881
|
+
* @maximum Infinity
|
|
882
|
+
* @step 1
|
|
883
|
+
*/
|
|
884
|
+
this.segments = 16;
|
|
885
|
+
if (start !== undefined) {
|
|
886
|
+
this.start = start;
|
|
887
|
+
}
|
|
888
|
+
if (middle !== undefined) {
|
|
889
|
+
this.middle = middle;
|
|
890
|
+
}
|
|
891
|
+
if (end !== undefined) {
|
|
892
|
+
this.end = end;
|
|
893
|
+
}
|
|
894
|
+
if (segments !== undefined) {
|
|
895
|
+
this.segments = segments;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
Point.ArcThroughThreePointsDto = ArcThroughThreePointsDto;
|
|
872
900
|
})(Point || (Point = {}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Base } from "./base-inputs";
|
|
1
|
+
import type { Base } from "./base-inputs";
|
|
2
2
|
/**
|
|
3
3
|
* Parameters for connected sequences of line segments: the point list that defines the path, whether
|
|
4
4
|
* it closes back on itself, and the options for measuring, transforming and converting a polyline into
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Base } from "./base-inputs";
|
|
1
|
+
import type { Base } from "./base-inputs";
|
|
2
2
|
/**
|
|
3
3
|
* Parameters for building transformation matrices: translations, rotations around an axis or a center,
|
|
4
4
|
* uniform and non-uniform scaling, and the composition of several transforms into one. The result is a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KernelFailureDetails, KernelFailureKind } from "./errors";
|
|
1
|
+
import type { KernelFailureDetails, KernelFailureKind } from "./errors";
|
|
2
2
|
/**
|
|
3
3
|
* What a kernel worker reports when a call fails: the message a caller reads, whether the inputs
|
|
4
4
|
* or the kernel were at fault, the stable code and the details of a failure the kernel named, and
|
|
@@ -15,7 +15,8 @@ export type KernelFailure = {
|
|
|
15
15
|
* Describes a failed kernel call in one shape for every kernel. An `InputError` reads
|
|
16
16
|
* `<path>: <message>`, because the message already names the input at fault. A WebAssembly trap
|
|
17
17
|
* (`RuntimeError`, such as an out-of-bounds access) is a `crash`: it reads `<kernel> crashed while
|
|
18
|
-
* executing function '<path>': <message>.`, then the inputs
|
|
18
|
+
* executing function '<path>': <message>.`, then the inputs, with the code and details its caller
|
|
19
|
+
* tagged it with, as a design build names the feature it was making. Any other failure
|
|
19
20
|
* reads `<kernel> computation failed while executing function '<path>': <message>.` followed by the
|
|
20
21
|
* inputs; a `KernelOperationError` gives its message without its type's name, its code and its
|
|
21
22
|
* details, when they are a plain record of strings, numbers, booleans and lists of them. A message
|
|
@@ -81,16 +81,11 @@ function inputText(key, value) {
|
|
|
81
81
|
return `${key}: [unserializable]`;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
function isTrap(error) {
|
|
84
|
+
function isWebAssemblyTrap(error) {
|
|
86
85
|
return error instanceof Error && error.name === "RuntimeError";
|
|
87
86
|
}
|
|
88
|
-
/**
|
|
89
|
-
* The code and details of a `KernelOperationError`, whichever copy of the class threw it; undefined
|
|
90
|
-
* for any other error, and for one whose code is not a string.
|
|
91
|
-
*/
|
|
92
87
|
function namedFailure(error) {
|
|
93
|
-
if (!(error instanceof Error) || error.name !== "KernelOperationError") {
|
|
88
|
+
if (!(error instanceof Error) || (error.name !== "KernelOperationError" && !isWebAssemblyTrap(error))) {
|
|
94
89
|
return undefined;
|
|
95
90
|
}
|
|
96
91
|
const code = Reflect.get(error, "code");
|
|
@@ -102,10 +97,6 @@ function isDetail(value) {
|
|
|
102
97
|
}
|
|
103
98
|
return Array.isArray(value) && (value.every((item) => typeof item === "number") || value.every((item) => typeof item === "string"));
|
|
104
99
|
}
|
|
105
|
-
/**
|
|
106
|
-
* A failure's details, when they are a plain record of strings, numbers, booleans and lists of
|
|
107
|
-
* either, which is all that crosses to another thread and fills a template.
|
|
108
|
-
*/
|
|
109
100
|
function checkedDetails(details) {
|
|
110
101
|
if (details === null || typeof details !== "object" || Array.isArray(details)) {
|
|
111
102
|
return undefined;
|
|
@@ -119,15 +110,15 @@ function checkedDetails(details) {
|
|
|
119
110
|
}
|
|
120
111
|
return checked;
|
|
121
112
|
}
|
|
122
|
-
|
|
123
|
-
function sentence(text) {
|
|
113
|
+
function withFullStop(text) {
|
|
124
114
|
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
125
115
|
}
|
|
126
116
|
/**
|
|
127
117
|
* Describes a failed kernel call in one shape for every kernel. An `InputError` reads
|
|
128
118
|
* `<path>: <message>`, because the message already names the input at fault. A WebAssembly trap
|
|
129
119
|
* (`RuntimeError`, such as an out-of-bounds access) is a `crash`: it reads `<kernel> crashed while
|
|
130
|
-
* executing function '<path>': <message>.`, then the inputs
|
|
120
|
+
* executing function '<path>': <message>.`, then the inputs, with the code and details its caller
|
|
121
|
+
* tagged it with, as a design build names the feature it was making. Any other failure
|
|
131
122
|
* reads `<kernel> computation failed while executing function '<path>': <message>.` followed by the
|
|
132
123
|
* inputs; a `KernelOperationError` gives its message without its type's name, its code and its
|
|
133
124
|
* details, when they are a plain record of strings, numbers, booleans and lists of them. A message
|
|
@@ -150,12 +141,13 @@ export function describeKernelFailure(kernel, functionName, inputs, error) {
|
|
|
150
141
|
const where = functionName ? ` while executing function '${functionName}'` : "";
|
|
151
142
|
const entries = inputs !== null && typeof inputs === "object" && binaryText(inputs) === undefined ? Object.entries(inputs) : [];
|
|
152
143
|
const props = entries.length > 0 ? ` Input values were: {${entries.map(([key, value]) => inputText(key, value)).join(", ")}}.` : "";
|
|
153
|
-
if (
|
|
154
|
-
|
|
144
|
+
if (isWebAssemblyTrap(error)) {
|
|
145
|
+
const tagged = namedFailure(error);
|
|
146
|
+
return { message: `${kernel} crashed${where}: ${withFullStop(errorText(error))}${props}`, kind: "crash", code: tagged === null || tagged === void 0 ? void 0 : tagged.code, details: tagged === null || tagged === void 0 ? void 0 : tagged.details, stack };
|
|
155
147
|
}
|
|
156
148
|
const named = namedFailure(error);
|
|
157
149
|
const text = named !== undefined && error instanceof Error ? error.message : errorText(error);
|
|
158
|
-
return { message: `${kernel} computation failed${where}: ${
|
|
150
|
+
return { message: `${kernel} computation failed${where}: ${withFullStop(text)}${props}`, kind: "kernel", code: named === null || named === void 0 ? void 0 : named.code, details: named === null || named === void 0 ? void 0 : named.details, stack };
|
|
159
151
|
}
|
|
160
152
|
catch (_a) {
|
|
161
153
|
const where = typeof functionName === "string" && functionName !== "" ? ` while executing function '${functionName}'` : "";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hashes a text to a whole number from 0 to 2^53 - 1 with cyrb53, over its UTF-16 code units. Both
|
|
3
|
+
* lanes mix with `Math.imul`, so every JavaScript engine gives the same number.
|
|
4
|
+
* @param text - The text to hash
|
|
5
|
+
* @returns The hash, a safe integer
|
|
6
|
+
*/
|
|
7
|
+
export declare function hashOfText(text: string): number;
|
|
8
|
+
/**
|
|
9
|
+
* Hashes bytes the way `hashOfText` hashes code units, so ASCII text gives the same number as a
|
|
10
|
+
* string or as its bytes.
|
|
11
|
+
* @param bytes - The bytes to hash
|
|
12
|
+
* @returns The hash, a safe integer
|
|
13
|
+
*/
|
|
14
|
+
export declare function hashOfBytes(bytes: Uint8Array): number;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const FIRST_SEED = 0xdeadbeef;
|
|
2
|
+
const SECOND_SEED = 0x41c6ce57;
|
|
3
|
+
const FIRST_PRIME = 2654435761;
|
|
4
|
+
const SECOND_PRIME = 1597334677;
|
|
5
|
+
const FIRST_MIX = 2246822507;
|
|
6
|
+
const SECOND_MIX = 3266489909;
|
|
7
|
+
const LOW_WORD = 4294967296;
|
|
8
|
+
const HIGH_BITS = 2097151;
|
|
9
|
+
function folded(first, second) {
|
|
10
|
+
let low = Math.imul(first ^ (first >>> 16), FIRST_MIX);
|
|
11
|
+
low ^= Math.imul(second ^ (second >>> 13), SECOND_MIX);
|
|
12
|
+
let high = Math.imul(second ^ (second >>> 16), FIRST_MIX);
|
|
13
|
+
high ^= Math.imul(low ^ (low >>> 13), SECOND_MIX);
|
|
14
|
+
return LOW_WORD * (HIGH_BITS & high) + (low >>> 0);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hashes a text to a whole number from 0 to 2^53 - 1 with cyrb53, over its UTF-16 code units. Both
|
|
18
|
+
* lanes mix with `Math.imul`, so every JavaScript engine gives the same number.
|
|
19
|
+
* @param text - The text to hash
|
|
20
|
+
* @returns The hash, a safe integer
|
|
21
|
+
*/
|
|
22
|
+
export function hashOfText(text) {
|
|
23
|
+
let first = FIRST_SEED;
|
|
24
|
+
let second = SECOND_SEED;
|
|
25
|
+
for (let index = 0; index < text.length; index++) {
|
|
26
|
+
const code = text.charCodeAt(index);
|
|
27
|
+
first = Math.imul(first ^ code, FIRST_PRIME);
|
|
28
|
+
second = Math.imul(second ^ code, SECOND_PRIME);
|
|
29
|
+
}
|
|
30
|
+
return folded(first, second);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Hashes bytes the way `hashOfText` hashes code units, so ASCII text gives the same number as a
|
|
34
|
+
* string or as its bytes.
|
|
35
|
+
* @param bytes - The bytes to hash
|
|
36
|
+
* @returns The hash, a safe integer
|
|
37
|
+
*/
|
|
38
|
+
export function hashOfBytes(bytes) {
|
|
39
|
+
let first = FIRST_SEED;
|
|
40
|
+
let second = SECOND_SEED;
|
|
41
|
+
for (let index = 0; index < bytes.length; index++) {
|
|
42
|
+
const code = bytes[index];
|
|
43
|
+
first = Math.imul(first ^ code, FIRST_PRIME);
|
|
44
|
+
second = Math.imul(second ^ code, SECOND_PRIME);
|
|
45
|
+
}
|
|
46
|
+
return folded(first, second);
|
|
47
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DtoRules, InputRule, RuleTarget } from "./input-validation";
|
|
1
|
+
import type { DtoRules, InputRule, RuleTarget } from "./input-validation";
|
|
2
2
|
type Key<T> = keyof T & string;
|
|
3
3
|
/**
|
|
4
4
|
* The rules one DTO's inputs have to satisfy together, beyond what each property accepts on its own.
|
|
@@ -47,8 +47,9 @@ export function lessThan(property, limit, message, reads = []) {
|
|
|
47
47
|
check: (inputs) => {
|
|
48
48
|
const value = numberAt(inputs, property);
|
|
49
49
|
const bound = limitOf(inputs);
|
|
50
|
-
if (value === undefined || bound === undefined || value < bound)
|
|
50
|
+
if (value === undefined || bound === undefined || value < bound) {
|
|
51
51
|
return undefined;
|
|
52
|
+
}
|
|
52
53
|
return { property, code: "less-than", params: { limit: bound }, message: message !== null && message !== void 0 ? message : `must be less than ${typeof limit === "function" ? bound : limit}` };
|
|
53
54
|
},
|
|
54
55
|
};
|
|
@@ -65,8 +66,9 @@ export function sameLength(property, other) {
|
|
|
65
66
|
check: (inputs) => {
|
|
66
67
|
const list = listAt(inputs, property);
|
|
67
68
|
const partner = listAt(inputs, other);
|
|
68
|
-
if (!list || !partner || list.length === partner.length)
|
|
69
|
+
if (!list || !partner || list.length === partner.length) {
|
|
69
70
|
return undefined;
|
|
71
|
+
}
|
|
70
72
|
return { property, code: "same-length", params: { expected: partner.length, actual: list.length }, message: `must have as many items as ${other} (${partner.length}), not ${list.length}` };
|
|
71
73
|
},
|
|
72
74
|
};
|
|
@@ -83,8 +85,9 @@ export function distinct(property, other) {
|
|
|
83
85
|
check: (inputs) => {
|
|
84
86
|
const a = listAt(inputs, property);
|
|
85
87
|
const b = listAt(inputs, other);
|
|
86
|
-
if (!a || !b || a.length !== b.length || a.some((value, index) => value !== b[index]))
|
|
88
|
+
if (!a || !b || a.length !== b.length || a.some((value, index) => value !== b[index])) {
|
|
87
89
|
return undefined;
|
|
90
|
+
}
|
|
88
91
|
return { property, code: "distinct", message: `must differ from ${other}` };
|
|
89
92
|
},
|
|
90
93
|
};
|
|
@@ -99,8 +102,9 @@ export function notZeroVector(property) {
|
|
|
99
102
|
reads: [property],
|
|
100
103
|
check: (inputs) => {
|
|
101
104
|
const vector = listAt(inputs, property);
|
|
102
|
-
if (!vector || vector.some((value) => value !== 0))
|
|
105
|
+
if (!vector || vector.some((value) => value !== 0)) {
|
|
103
106
|
return undefined;
|
|
107
|
+
}
|
|
104
108
|
return { property, code: "zero-vector", message: "must not be a zero vector" };
|
|
105
109
|
},
|
|
106
110
|
};
|
|
@@ -117,8 +121,9 @@ export function atLeastOne(property, holds, message) {
|
|
|
117
121
|
reads: [property],
|
|
118
122
|
check: (inputs) => {
|
|
119
123
|
const list = listAt(inputs, property);
|
|
120
|
-
if (!list || list.some(holds))
|
|
124
|
+
if (!list || list.some(holds)) {
|
|
121
125
|
return undefined;
|
|
126
|
+
}
|
|
122
127
|
return { property, code: "at-least-one", message };
|
|
123
128
|
},
|
|
124
129
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DtoConstraints } from "./constraints";
|
|
2
|
-
import { DtoRegistry } from "./resolve-dto";
|
|
1
|
+
import type { DtoConstraints } from "./constraints";
|
|
2
|
+
import type { DtoRegistry } from "./resolve-dto";
|
|
3
3
|
/**
|
|
4
4
|
* Something wrong with the inputs of a call. `property` names the input at fault, `code` says what
|
|
5
5
|
* is wrong in a form a program can match - an editor can translate it and mark the field - and
|
|
@@ -83,7 +83,7 @@ export type InputIssueReport = {
|
|
|
83
83
|
};
|
|
84
84
|
/**
|
|
85
85
|
* Where input issues go; by default a console warning. Passing nothing restores the default. The
|
|
86
|
-
* reporter says each distinct issue once, so a
|
|
86
|
+
* reporter says each distinct issue once, so a caller that redraws on every change is not
|
|
87
87
|
* flooded.
|
|
88
88
|
* @param next - The function that receives each new issue, or undefined for the console
|
|
89
89
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isRegisteredOperation, resolveInputs } from "./resolve-dto";
|
|
2
|
+
import { isRecord } from "./unknown-values";
|
|
2
3
|
const HEX_COLOR = /^#[0-9a-f]{6}$/i;
|
|
3
4
|
const TUPLE_LENGTH = { point2: 2, vector2: 2, point3: 3, vector3: 3 };
|
|
4
|
-
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
5
|
const issue = (property, code, message, params) => (params ? { property, code, message, params } : { property, code, message });
|
|
6
6
|
function checkBounds(property, value, bounds) {
|
|
7
7
|
const { min, max, exclusiveMin, exclusiveMax } = bounds;
|
|
@@ -20,10 +20,12 @@ function checkValue(property, value, constraint) {
|
|
|
20
20
|
}
|
|
21
21
|
switch (constraint.kind) {
|
|
22
22
|
case "number":
|
|
23
|
-
if (typeof value !== "number")
|
|
23
|
+
if (typeof value !== "number") {
|
|
24
24
|
return issue(property, "type", "must be a number");
|
|
25
|
-
|
|
25
|
+
}
|
|
26
|
+
if (Number.isNaN(value)) {
|
|
26
27
|
return issue(property, "not-a-number", "is not a number (NaN)");
|
|
28
|
+
}
|
|
27
29
|
return constraint.bounds ? checkBounds(property, value, constraint.bounds) : undefined;
|
|
28
30
|
case "boolean":
|
|
29
31
|
return typeof value === "boolean" ? undefined : issue(property, "type", "must be true or false");
|
|
@@ -38,22 +40,27 @@ function checkValue(property, value, constraint) {
|
|
|
38
40
|
case "vector3": {
|
|
39
41
|
const expected = TUPLE_LENGTH[constraint.kind];
|
|
40
42
|
const count = expected === undefined ? "2 or 3" : String(expected);
|
|
41
|
-
if (!Array.isArray(value))
|
|
43
|
+
if (!Array.isArray(value)) {
|
|
42
44
|
return issue(property, "type", `must be a list of ${count} numbers`);
|
|
45
|
+
}
|
|
43
46
|
const fits = expected === undefined ? value.length === 2 || value.length === 3 : value.length === expected;
|
|
44
|
-
if (!fits)
|
|
47
|
+
if (!fits) {
|
|
45
48
|
return issue(property, "arity", `must have ${count} numbers, not ${value.length}`, { expected: expected !== null && expected !== void 0 ? expected : [2, 3], actual: value.length });
|
|
49
|
+
}
|
|
46
50
|
return value.every((n) => typeof n === "number" && !Number.isNaN(n)) ? undefined : issue(property, "type", `must be a list of ${count} numbers`);
|
|
47
51
|
}
|
|
48
52
|
case "list": {
|
|
49
|
-
if (!Array.isArray(value) && !ArrayBuffer.isView(value))
|
|
53
|
+
if (!Array.isArray(value) && !ArrayBuffer.isView(value)) {
|
|
50
54
|
return issue(property, "type", "must be a list");
|
|
51
|
-
|
|
55
|
+
}
|
|
56
|
+
if (!constraint.items || !Array.isArray(value)) {
|
|
52
57
|
return undefined;
|
|
58
|
+
}
|
|
53
59
|
for (let index = 0; index < value.length; index++) {
|
|
54
60
|
const itemIssue = checkValue(property, value[index], Object.assign({ required: true }, constraint.items));
|
|
55
|
-
if (itemIssue)
|
|
61
|
+
if (itemIssue) {
|
|
56
62
|
return Object.assign(Object.assign({}, itemIssue), { message: `item ${index} ${itemIssue.message}`, params: Object.assign(Object.assign({}, itemIssue.params), { index }) });
|
|
63
|
+
}
|
|
57
64
|
}
|
|
58
65
|
return undefined;
|
|
59
66
|
}
|
|
@@ -76,8 +83,9 @@ export function checkStructure(constraints, inputs) {
|
|
|
76
83
|
const issues = [];
|
|
77
84
|
for (const [property, constraint] of Object.entries(constraints)) {
|
|
78
85
|
const found = checkValue(property, record[property], constraint);
|
|
79
|
-
if (found)
|
|
86
|
+
if (found) {
|
|
80
87
|
issues.push(found);
|
|
88
|
+
}
|
|
81
89
|
}
|
|
82
90
|
return issues;
|
|
83
91
|
}
|
|
@@ -126,8 +134,9 @@ export function validateInputs(registry, path, inputs, rules) {
|
|
|
126
134
|
const issues = checkStructure(entry.constraints, inputs);
|
|
127
135
|
const failed = new Set(issues.map((found) => found.property));
|
|
128
136
|
rulesOf(entry.dto, rules).forEach((rule, index) => {
|
|
129
|
-
if (rule.reads.some((property) => failed.has(property)))
|
|
137
|
+
if (rule.reads.some((property) => failed.has(property))) {
|
|
130
138
|
return;
|
|
139
|
+
}
|
|
131
140
|
const found = rule.check(inputs);
|
|
132
141
|
if (found) {
|
|
133
142
|
ruleOfIssue.set(found, index);
|
|
@@ -159,7 +168,7 @@ const MAX_REMEMBERED_ISSUES = 1000;
|
|
|
159
168
|
const reported = new Set();
|
|
160
169
|
/**
|
|
161
170
|
* Where input issues go; by default a console warning. Passing nothing restores the default. The
|
|
162
|
-
* reporter says each distinct issue once, so a
|
|
171
|
+
* reporter says each distinct issue once, so a caller that redraws on every change is not
|
|
163
172
|
* flooded.
|
|
164
173
|
* @param next - The function that receives each new issue, or undefined for the console
|
|
165
174
|
*/
|
|
@@ -186,13 +195,15 @@ export function reportInputIssues(kernel, path, issues, unknown = []) {
|
|
|
186
195
|
for (const found of all) {
|
|
187
196
|
const rule = ruleOfIssue.get(found);
|
|
188
197
|
const key = `${kernel}|${path}|${found.property}|${found.code}${rule === undefined ? "" : `|rule ${rule}`}`;
|
|
189
|
-
if (reported.has(key))
|
|
198
|
+
if (reported.has(key)) {
|
|
190
199
|
continue;
|
|
200
|
+
}
|
|
191
201
|
reported.add(key);
|
|
192
202
|
if (reported.size > MAX_REMEMBERED_ISSUES) {
|
|
193
203
|
const oldest = reported.values().next();
|
|
194
|
-
if (!oldest.done)
|
|
204
|
+
if (!oldest.done) {
|
|
195
205
|
reported.delete(oldest.value);
|
|
206
|
+
}
|
|
196
207
|
}
|
|
197
208
|
sink({ kernel, path, issue: found });
|
|
198
209
|
}
|
|
@@ -214,7 +225,6 @@ export function prepareKernelCall(kernel, registry, path, given, rules) {
|
|
|
214
225
|
reportInputIssues(kernel, path, validateInputs(registry, path, inputs, rules), unknownProperties(registry, path, given));
|
|
215
226
|
}
|
|
216
227
|
catch (_a) {
|
|
217
|
-
// Issues are only reported for now, so a check or a sink that throws must not fail the call.
|
|
218
228
|
}
|
|
219
229
|
};
|
|
220
230
|
return { inputs, reportIssues };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** How far a call that works in steps has come: `done` of `total` steps, such as the features of a design build. */
|
|
2
|
+
export interface KernelSteps {
|
|
3
|
+
done: number;
|
|
4
|
+
total: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Where `reportKernelSteps` sends the steps of the call running now; by default nowhere. A worker
|
|
8
|
+
* sets it to share them with the thread that waits on the call, and a caller that runs the kernel
|
|
9
|
+
* on its own thread may set it to show progress. Passing nothing stops the reports.
|
|
10
|
+
* @param next - The function that receives each report, or undefined for none
|
|
11
|
+
*/
|
|
12
|
+
export declare function setKernelStepSink(next?: (steps: KernelSteps) => void): void;
|
|
13
|
+
/**
|
|
14
|
+
* Says how many steps of the call running now are done, out of how many, to the sink
|
|
15
|
+
* `setKernelStepSink` set, if any. `total` may grow while the call runs, as when a build finds more
|
|
16
|
+
* to make; `done` never passes it.
|
|
17
|
+
* @param steps - The steps done and the steps there are
|
|
18
|
+
*/
|
|
19
|
+
export declare function reportKernelSteps(steps: KernelSteps): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
let stepSink;
|
|
2
|
+
/**
|
|
3
|
+
* Where `reportKernelSteps` sends the steps of the call running now; by default nowhere. A worker
|
|
4
|
+
* sets it to share them with the thread that waits on the call, and a caller that runs the kernel
|
|
5
|
+
* on its own thread may set it to show progress. Passing nothing stops the reports.
|
|
6
|
+
* @param next - The function that receives each report, or undefined for none
|
|
7
|
+
*/
|
|
8
|
+
export function setKernelStepSink(next) {
|
|
9
|
+
stepSink = next;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Says how many steps of the call running now are done, out of how many, to the sink
|
|
13
|
+
* `setKernelStepSink` set, if any. `total` may grow while the call runs, as when a build finds more
|
|
14
|
+
* to make; `done` never passes it.
|
|
15
|
+
* @param steps - The steps done and the steps there are
|
|
16
|
+
*/
|
|
17
|
+
export function reportKernelSteps(steps) {
|
|
18
|
+
stepSink === null || stepSink === void 0 ? void 0 : stepSink({ done: Math.min(steps.done, steps.total), total: steps.total });
|
|
19
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DtoConstraints } from "./constraints";
|
|
1
|
+
import type { DtoConstraints } from "./constraints";
|
|
2
2
|
/**
|
|
3
3
|
* A DTO class that can be constructed with no arguments, which gives every defaulted property its
|
|
4
4
|
* default.
|
|
@@ -28,8 +28,10 @@ export type WithDefaults<T, K extends keyof T> = Omit<T, K> & {
|
|
|
28
28
|
/**
|
|
29
29
|
* Builds the DTO a service reads from what a caller passed: the defaults a new `Dto` holds, with the
|
|
30
30
|
* caller's properties laid over them. A property the caller set to undefined keeps its default, and
|
|
31
|
-
* so does one the caller set to null when the DTO has a default for it - a
|
|
32
|
-
* payload spells "not set" as null - while null on a property with no default stays null.
|
|
31
|
+
* so does one the caller set to null when the DTO has a default for it - a form or a JSON
|
|
32
|
+
* payload spells "not set" as null - while null on a property with no default stays null. An empty
|
|
33
|
+
* text on a property with no default is left out, since an empty text there means "not set", while an empty
|
|
34
|
+
* text in place of a default stays, since the caller chose it over the default. A caller
|
|
33
35
|
* that passed nothing gets the defaults alone. The result is a new plain object - a DTO carries data
|
|
34
36
|
* and no behaviour, and a plain object is what crosses a worker boundary and what a walk over the
|
|
35
37
|
* inputs treats as data - and the caller's object is never changed. Properties named in `nested`
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { isRecord } from "./unknown-values";
|
|
2
2
|
/**
|
|
3
3
|
* Builds the DTO a service reads from what a caller passed: the defaults a new `Dto` holds, with the
|
|
4
4
|
* caller's properties laid over them. A property the caller set to undefined keeps its default, and
|
|
5
|
-
* so does one the caller set to null when the DTO has a default for it - a
|
|
6
|
-
* payload spells "not set" as null - while null on a property with no default stays null.
|
|
5
|
+
* so does one the caller set to null when the DTO has a default for it - a form or a JSON
|
|
6
|
+
* payload spells "not set" as null - while null on a property with no default stays null. An empty
|
|
7
|
+
* text on a property with no default is left out, since an empty text there means "not set", while an empty
|
|
8
|
+
* text in place of a default stays, since the caller chose it over the default. A caller
|
|
7
9
|
* that passed nothing gets the defaults alone. The result is a new plain object - a DTO carries data
|
|
8
10
|
* and no behaviour, and a plain object is what crosses a worker boundary and what a walk over the
|
|
9
11
|
* inputs treats as data - and the caller's object is never changed. Properties named in `nested`
|
|
@@ -17,9 +19,12 @@ export function resolveDto(Dto, inputs, nested) {
|
|
|
17
19
|
const resolved = {};
|
|
18
20
|
Object.assign(resolved, new Dto());
|
|
19
21
|
const hasDefault = (key) => Object.prototype.hasOwnProperty.call(resolved, key) && resolved[key] !== undefined;
|
|
22
|
+
const isUnset = (key, value) => value === undefined
|
|
23
|
+
|| (value === null && hasDefault(key))
|
|
24
|
+
|| (value === "" && !hasDefault(key));
|
|
20
25
|
if (isRecord(inputs)) {
|
|
21
26
|
for (const [key, value] of Object.entries(inputs)) {
|
|
22
|
-
if (
|
|
27
|
+
if (!isUnset(key, value)) {
|
|
23
28
|
resolved[key] = value;
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a value is an object with string keys: not null, and not an array.
|
|
3
|
+
* @param value - The value to test
|
|
4
|
+
* @returns Whether it is such an object
|
|
5
|
+
*/
|
|
6
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* The message of a thrown value: an error's own message, or anything else written as text.
|
|
9
|
+
* @param thrown - What was thrown
|
|
10
|
+
* @returns Its message
|
|
11
|
+
*/
|
|
12
|
+
export declare function messageOf(thrown: unknown): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a value is an object with string keys: not null, and not an array.
|
|
3
|
+
* @param value - The value to test
|
|
4
|
+
* @returns Whether it is such an object
|
|
5
|
+
*/
|
|
6
|
+
export function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The message of a thrown value: an error's own message, or anything else written as text.
|
|
11
|
+
* @param thrown - What was thrown
|
|
12
|
+
* @returns Its message
|
|
13
|
+
*/
|
|
14
|
+
export function messageOf(thrown) {
|
|
15
|
+
return thrown instanceof Error ? thrown.message : String(thrown);
|
|
16
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DtoRegistry } from "./resolve-dto";
|
|
1
|
+
import type { DtoRegistry } from "./resolve-dto";
|
|
2
2
|
/**
|
|
3
3
|
* A kernel used in the same thread, whose operations lay a caller's inputs over the defaults of the
|
|
4
4
|
* DTO each takes - what a worker does for a call that crossed to it. `occt.shapes.solid.createBox({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Base } from "../../inputs/base-inputs";
|
|
1
|
+
import type { Base } from "../../inputs/base-inputs";
|
|
2
2
|
/**
|
|
3
3
|
* A generated hexagonal grid: the center point of every hexagon, its corner points, and the
|
|
4
4
|
* row and column structure that placed them. The layout used for honeycomb patterns, perforations
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Base } from "../inputs/base-inputs";
|
|
2
|
+
import type { RecipeIssue } from "./recipe-types";
|
|
3
|
+
export type Kind = "profile" | "solid" | "halfSpace";
|
|
4
|
+
export interface Checker {
|
|
5
|
+
readonly issues: RecipeIssue[];
|
|
6
|
+
readonly buffers: Base.RecipeBuffers;
|
|
7
|
+
readonly kinds: (Kind | undefined)[];
|
|
8
|
+
readonly depths: number[];
|
|
9
|
+
referenced: number;
|
|
10
|
+
}
|
|
11
|
+
export interface NodeSummary {
|
|
12
|
+
readonly kind: Kind | undefined;
|
|
13
|
+
readonly depth: number;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const RECIPE_FORMAT = "bitbybit.recipe";
|
|
2
|
+
export declare const RECIPE_VERSION = 1;
|
|
3
|
+
export declare const MAX_RECIPE_NODES = 10000000;
|
|
4
|
+
export declare const MAX_RECIPE_ROOTS = 10000000;
|
|
5
|
+
export declare const MAX_RECIPE_GROUPS = 10000000;
|
|
6
|
+
export declare const MAX_RECIPE_DEPTH = 1000;
|
|
7
|
+
export declare const MAX_BUFFER_LENGTH = 1000000000;
|
|
8
|
+
export declare const MAX_REFERENCED_NUMBERS = 1000000000;
|
|
9
|
+
export declare const MAX_RECIPE_COORDINATE = 1000000000;
|
|
10
|
+
export declare const MAX_RECIPE_PLACEMENT = 10000000000000;
|
|
11
|
+
export declare const MATRIX_SIZE = 16;
|
|
12
|
+
export declare const POINT2_SIZE = 2;
|
|
13
|
+
export declare const POINT3_SIZE = 3;
|
|
14
|
+
export declare const MIN_POLYGON_NUMBERS = 6;
|
|
15
|
+
export declare const TRIANGLE_CORNERS = 3;
|
|
16
|
+
export declare const DEGENERATE_DETERMINANT = 1e-12;
|
|
17
|
+
export declare const FULL_TURN: number;
|
|
18
|
+
export declare const MIN_LOFT_FRAMES = 2;
|
|
19
|
+
export declare const MIN_INTERSECTED = 2;
|
|
20
|
+
export declare const MAX_ISSUES = 100;
|
|
21
|
+
export declare const INT32_LOWEST: number;
|
|
22
|
+
export declare const INT32_HIGHEST: number;
|
|
23
|
+
export declare const ISSUES_IN_MESSAGE = 3;
|