@rulecad/cad 0.8.0 → 0.10.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/AGENTS.md +45 -16
- package/CHANGELOG.md +724 -0
- package/EXAMPLES.md +61 -54
- package/README.md +376 -98
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2664 -541
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1883 -435
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/cache-file.mjs +105 -0
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/code-text.mjs +28 -0
- package/lib/design-imports.mjs +127 -0
- package/lib/design.mjs +871 -147
- package/lib/designshapes.mjs +142 -0
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +922 -192
- package/lib/errors.mjs +16 -3
- package/lib/estimates.mjs +51 -0
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2708 -507
- package/lib/fe-key.mjs +29 -0
- package/lib/fittings.mjs +721 -122
- package/lib/fixings.mjs +38 -13
- package/lib/framebuild.mjs +790 -175
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +108 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +86 -18
- package/lib/framesize.mjs +719 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +129 -23
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +439 -69
- package/lib/layout.mjs +2 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +334 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +597 -136
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +1080 -117
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1002 -214
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +18 -1
- package/lib/optimise.mjs +991 -287
- package/lib/order.mjs +515 -114
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +81 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +223 -35
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +17 -6
- package/lib/sandbox-hooks.mjs +179 -27
- package/lib/sandbox-lock.mjs +225 -0
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +122 -25
- package/lib/sandbox.mjs +667 -75
- package/lib/schema.mjs +42 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +963 -179
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +285 -39
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +200 -14
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
- package/schemas/project.schema.json +6 -0
- package/templates/coupons/MEASURE.md +109 -0
- package/templates/coupons/assemblies/fixings-test.json +20 -0
- package/templates/coupons/assemblies/slot-test.json +11 -0
- package/templates/coupons/objects/fixings-coupon.js +88 -0
- package/templates/coupons/objects/fixings-coupon.json +26 -0
- package/templates/coupons/objects/holds-coupon.js +130 -0
- package/templates/coupons/objects/holds-coupon.json +42 -0
- package/templates/coupons/objects/slot-coupon.js +89 -0
- package/templates/coupons/objects/slot-coupon.json +29 -0
- package/templates/coupons/project.json +10 -0
package/lib/sandbox-run.mjs
CHANGED
|
@@ -11,48 +11,145 @@ import * as gears from '@rulecad/gears';
|
|
|
11
11
|
import * as motors from '@rulecad/motors';
|
|
12
12
|
import { designFrames } from './frames.mjs';
|
|
13
13
|
import { designFixings } from './fixings.mjs';
|
|
14
|
+
import { designShapes } from './designshapes.mjs';
|
|
14
15
|
import { named, faces, unpack, watch } from './parts.mjs';
|
|
15
16
|
import { lineOf } from './errors.mjs';
|
|
17
|
+
import { keeper, STAGES_MOST, ROUTES_MOST } from './kept.mjs';
|
|
18
|
+
import { IMPORTED } from './sandbox-hooks.mjs';
|
|
19
|
+
import { shutLoader, shutProcess, shutStreams, shutWebClient, writeAll } from './sandbox-lock.mjs';
|
|
16
20
|
|
|
21
|
+
shutWebClient(); // (first: touching Headers and the like makes an agent that connects anywhere: sandbox-lock.mjs)
|
|
17
22
|
for (const k of ['fetch', 'WebSocket', 'EventSource', 'XMLHttpRequest', 'Request', 'Response']) delete globalThis[k];
|
|
18
23
|
// and the ways round the import hook that process itself offers: Node's own modules by name, its internals, other
|
|
19
|
-
// processes
|
|
24
|
+
// processes, files (sandbox-lock.mjs; sandbox.mjs's header says what this does and doesn't promise)
|
|
20
25
|
const exit = process.exit.bind(process);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
for await (const c of process.stdin) chunks.push(c);
|
|
26
|
-
const { js, values, meta, engine, optional, stages, bound, board } = JSON.parse(Buffer.concat(chunks).toString('utf8')), context = bound?.fixings;
|
|
26
|
+
shutProcess();
|
|
27
|
+
shutStreams(); // (the request is read, and the reply written, by file descriptor: sandbox-lock.mjs says why)
|
|
28
|
+
const { js, values, meta, engine, optional, stages, bound, board } = JSON.parse(fs.readFileSync(0, 'utf8')),
|
|
29
|
+
context = bound?.fixings;
|
|
27
30
|
// A lamina's slow stages: read from the tool's cache (the workspace is readable), and what this run makes handed back
|
|
28
|
-
// with the parts for the tool to write (this process can't)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
// with the parts for the tool to write (this process can't), up to the cap the tool takes (kept.mjs: past it, a stage
|
|
32
|
+
// is used but not kept)
|
|
33
|
+
const stageKeeper = keeper(STAGES_MOST),
|
|
34
|
+
kept = stageKeeper.kept; // (what this run made of them)
|
|
35
|
+
// A file of a cache folder, read only where it really is in that folder: a cloned workspace may hold its own .cache/,
|
|
36
|
+
// and a stage's file there that is a link to a file elsewhere (a key in the user's home folder) would be read, under
|
|
37
|
+
// the permission model, which follows links, and handed to the design. Such a file is a miss: the stage is made afresh.
|
|
38
|
+
// The folder itself the tool hands over only where its real path is inside the workspace (sandbox.mjs ownFolder), so
|
|
39
|
+
// here a key must name a file directly in it (no folder in the key) that is not itself a link. (Not by real path: the
|
|
40
|
+
// native one spells a Windows folder by its long name where the permission model was given its short one, and refuses
|
|
41
|
+
// the read; Node's own is refused the lstat of /var on macOS.)
|
|
42
|
+
const fromFolder = (dir) => (k) => {
|
|
43
|
+
if (!dir) return undefined;
|
|
44
|
+
const f = path.join(dir, `${k}.json`);
|
|
45
|
+
if (path.dirname(f) !== path.resolve(dir)) return undefined;
|
|
46
|
+
try {
|
|
47
|
+
return fs.lstatSync(f).isFile() ? fs.readFileSync(f, 'utf8') : undefined;
|
|
48
|
+
} catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
if (stages)
|
|
53
|
+
flexures.laminaCache({
|
|
54
|
+
salt: stages.salt,
|
|
55
|
+
get: fromFolder(stages.dir),
|
|
56
|
+
put: stageKeeper.put,
|
|
57
|
+
});
|
|
31
58
|
// A board's engine: @rulecad/pcb, loaded only for a board design, its mount bound to the workspace's thread sets (as
|
|
32
|
-
// data, like v.fixings), and its routes kept as the stages are
|
|
33
|
-
|
|
34
|
-
|
|
59
|
+
// data, like v.fixings), and its routes kept as the stages are: read from the design's own folder of the route cache,
|
|
60
|
+
// then from the one the tool's own process writes (board.routes, in that order), and handed back to go in the first
|
|
61
|
+
const routeKeeper = keeper(ROUTES_MOST),
|
|
62
|
+
routes = routeKeeper.kept,
|
|
63
|
+
routeFolders = (board?.routes || []).map(fromFolder),
|
|
64
|
+
routeOf = (k) => {
|
|
65
|
+
for (const get of routeFolders) {
|
|
66
|
+
const text = get(k);
|
|
67
|
+
if (text !== undefined) return text;
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
};
|
|
71
|
+
let pcb = null,
|
|
72
|
+
mounted = false;
|
|
35
73
|
if (board) {
|
|
36
74
|
pcb = await import('@rulecad/pcb');
|
|
37
|
-
if (pcb.routeStore)
|
|
75
|
+
if (pcb.routeStore)
|
|
76
|
+
pcb.routeStore({
|
|
77
|
+
get: routeOf,
|
|
78
|
+
put: routeKeeper.put,
|
|
79
|
+
});
|
|
38
80
|
}
|
|
39
|
-
const engineFor = () => ({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
81
|
+
const engineFor = () => ({
|
|
82
|
+
...pcb,
|
|
83
|
+
mount: (thread, x, y, o = {}) => {
|
|
84
|
+
mounted = true;
|
|
85
|
+
return pcb.mount(thread, x, y, { sets: context?.sets, ...o });
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
// stdout carries the result, so what a design prints (console.log, to see a value) goes to stderr (shutStreams), which
|
|
89
|
+
// the tool passes on
|
|
90
|
+
const done = (o) => {
|
|
91
|
+
writeAll(1, JSON.stringify(o));
|
|
92
|
+
exit(0);
|
|
93
|
+
};
|
|
43
94
|
try {
|
|
95
|
+
shutLoader(process.env.CAD_SANDBOX_PROJECT); // (the CommonJS loader: no design reaches Node's own modules by it)
|
|
44
96
|
const mod = await import(js);
|
|
45
|
-
if (typeof mod.main !== 'function')
|
|
46
|
-
|
|
47
|
-
const
|
|
97
|
+
if (typeof mod.main !== 'function')
|
|
98
|
+
throw Object.assign(new Error('the design has no exported main(v)'), { code: 'design.main' });
|
|
99
|
+
const ops = await shapes.ops(engine || 'jscad'),
|
|
100
|
+
df = designFixings({ ...(context || {}), ops }), // (v.fixings: bound to the project, as the build's own is)
|
|
101
|
+
ds = designShapes(shapes, { printer: context?.printer }); // (v.shapes: its seats said, as the build's own are)
|
|
102
|
+
const { v, read } = watch(
|
|
103
|
+
values,
|
|
104
|
+
{
|
|
105
|
+
shapes: ds.shapes,
|
|
106
|
+
flexures,
|
|
107
|
+
gears,
|
|
108
|
+
motors,
|
|
109
|
+
frames: designFrames(bound?.frames),
|
|
110
|
+
fixings: df.fixings,
|
|
111
|
+
ops,
|
|
112
|
+
...(pcb ? { pcb: engineFor() } : {}),
|
|
113
|
+
},
|
|
114
|
+
optional,
|
|
115
|
+
);
|
|
48
116
|
const { shapes: made, mechanism } = unpack(await mod.main(v));
|
|
49
|
-
|
|
50
|
-
|
|
117
|
+
// the files of its project the design imported, as the import hook saw them (after main: it may import as it runs)
|
|
118
|
+
const imports = (await import(IMPORTED)).default;
|
|
119
|
+
const found = {
|
|
120
|
+
read: [...read],
|
|
121
|
+
imports,
|
|
122
|
+
...(mechanism ? { mechanism } : {}),
|
|
123
|
+
...(df.used() ? { fixings: df.found() } : {}),
|
|
124
|
+
...(ds.used() ? { seats: ds.found() } : {}),
|
|
125
|
+
...(Object.keys(kept).length ? { stages: kept } : {}),
|
|
126
|
+
};
|
|
127
|
+
if (pcb) {
|
|
128
|
+
// a circuit board: its Circuit JSON, for the tool to make the board's solid and files from
|
|
51
129
|
const { board: b, matrix, clone } = made && made.board ? made : { board: made };
|
|
52
130
|
const circuit = await pcb.render(b);
|
|
53
|
-
done({
|
|
131
|
+
done({
|
|
132
|
+
parts: [],
|
|
133
|
+
...found,
|
|
134
|
+
board: { circuit, ...(matrix ? { matrix } : {}), ...(clone ? { source: clone } : {}) },
|
|
135
|
+
...(mounted ? { mounted } : {}),
|
|
136
|
+
...(Object.keys(routes).length ? { routes } : {}),
|
|
137
|
+
});
|
|
54
138
|
} else done({ parts: named(made, meta).map(({ geometry, ...p }) => ({ ...p, solid: faces(geometry) })), ...found });
|
|
55
139
|
} catch (e) {
|
|
56
140
|
const line = lineOf(e, js);
|
|
57
|
-
done({
|
|
141
|
+
done({
|
|
142
|
+
error: {
|
|
143
|
+
message: e?.message || String(e),
|
|
144
|
+
...(line ? { line } : {}),
|
|
145
|
+
...(e?.name === 'SyntaxError' ? { syntax: true } : {}),
|
|
146
|
+
code:
|
|
147
|
+
e?.code && typeof e.code === 'string' && !/^ERR_/.test(e.code)
|
|
148
|
+
? e.code
|
|
149
|
+
: e?.code === 'ERR_ACCESS_DENIED'
|
|
150
|
+
? 'design.sandbox'
|
|
151
|
+
: 'design.run',
|
|
152
|
+
...(e?.code === 'ERR_ACCESS_DENIED' && e.resource ? { resource: e.resource } : {}),
|
|
153
|
+
},
|
|
154
|
+
});
|
|
58
155
|
}
|