@rulecad/cad 0.8.0 → 0.9.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.
Files changed (83) hide show
  1. package/AGENTS.md +24 -10
  2. package/CHANGELOG.md +404 -0
  3. package/EXAMPLES.md +40 -38
  4. package/README.md +193 -67
  5. package/TUTORIAL.md +2 -2
  6. package/bin/cad.mjs +2250 -512
  7. package/lib/animate.mjs +173 -49
  8. package/lib/assembly.mjs +1847 -434
  9. package/lib/beams.mjs +256 -52
  10. package/lib/belts.mjs +66 -15
  11. package/lib/board-work.mjs +12 -0
  12. package/lib/bought.mjs +309 -53
  13. package/lib/buildpage.mjs +179 -29
  14. package/lib/carried.mjs +201 -0
  15. package/lib/clone.mjs +194 -42
  16. package/lib/design.mjs +649 -121
  17. package/lib/drive.mjs +187 -63
  18. package/lib/edit.mjs +899 -191
  19. package/lib/errors.mjs +16 -3
  20. package/lib/explain.mjs +62 -13
  21. package/lib/fasten.mjs +2702 -507
  22. package/lib/fittings.mjs +715 -121
  23. package/lib/fixings.mjs +21 -9
  24. package/lib/framebuild.mjs +790 -175
  25. package/lib/framecheck.mjs +1901 -368
  26. package/lib/framegen.mjs +100 -22
  27. package/lib/frameheat.mjs +225 -42
  28. package/lib/frameprint.mjs +513 -108
  29. package/lib/frames.mjs +81 -17
  30. package/lib/framesize.mjs +792 -120
  31. package/lib/frametip.mjs +235 -0
  32. package/lib/gait.mjs +135 -23
  33. package/lib/grip.mjs +62 -13
  34. package/lib/guides.mjs +1403 -230
  35. package/lib/host.mjs +123 -21
  36. package/lib/inplace.mjs +171 -36
  37. package/lib/jigs.mjs +360 -78
  38. package/lib/joins.mjs +697 -118
  39. package/lib/jsonedit.mjs +88 -26
  40. package/lib/kept.mjs +84 -0
  41. package/lib/kit.mjs +438 -68
  42. package/lib/layout.mjs +2 -1
  43. package/lib/links.mjs +149 -42
  44. package/lib/list.mjs +326 -64
  45. package/lib/live-guard.mjs +68 -0
  46. package/lib/live-shape.mjs +96 -24
  47. package/lib/live.mjs +189 -59
  48. package/lib/loads.mjs +579 -130
  49. package/lib/machine.mjs +372 -74
  50. package/lib/magnets.mjs +162 -44
  51. package/lib/measured.mjs +417 -94
  52. package/lib/mesh.mjs +526 -119
  53. package/lib/meshcmd.mjs +215 -60
  54. package/lib/motors.mjs +1021 -213
  55. package/lib/motorsvg.mjs +114 -32
  56. package/lib/names.mjs +3 -1
  57. package/lib/optimise.mjs +978 -283
  58. package/lib/order.mjs +519 -112
  59. package/lib/panels.mjs +482 -94
  60. package/lib/parts.mjs +78 -23
  61. package/lib/pins.mjs +163 -44
  62. package/lib/plates.mjs +223 -35
  63. package/lib/player.mjs +37 -9
  64. package/lib/power.mjs +64 -13
  65. package/lib/preview.mjs +83 -16
  66. package/lib/profilemeasure.mjs +572 -129
  67. package/lib/rules.mjs +15 -5
  68. package/lib/sandbox-hooks.mjs +77 -19
  69. package/lib/sandbox-run.mjs +117 -18
  70. package/lib/sandbox.mjs +509 -60
  71. package/lib/schema.mjs +42 -11
  72. package/lib/seats.mjs +227 -49
  73. package/lib/services.mjs +261 -52
  74. package/lib/sheet.mjs +851 -178
  75. package/lib/slotnuts.mjs +213 -34
  76. package/lib/targets/gist.mjs +4 -1
  77. package/lib/targets.mjs +22 -4
  78. package/lib/task.mjs +376 -79
  79. package/lib/versions.mjs +111 -28
  80. package/lib/wires.mjs +228 -45
  81. package/lib/workspace.mjs +197 -12
  82. package/package.json +19 -19
  83. package/schemas/assembly.schema.json +2 -2
package/lib/rules.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { host, readJson } from './host.mjs';
6
- import { RULE_DIRS, WS } from './workspace.mjs';
6
+ import { RULE_DIRS, WS, readOwnText } from './workspace.mjs';
7
7
  import { plainName } from './names.mjs';
8
8
  import { resolve as resolveWith } from '@rulecad/variables';
9
9
 
@@ -21,7 +21,7 @@ export function loadRuleSet(name, dir) {
21
21
  const own = path.join(WS, 'rules', `${name}.json`);
22
22
  if (!dir && file !== own) {
23
23
  insideWorkspace(own);
24
- host.writeText(own, host.readText(file));
24
+ host.writeText(own, readOwnText(file));
25
25
  console.error(`copied the ${name} rule set into rules/${name}.json: yours to keep and edit`);
26
26
  }
27
27
  return readJson(own);
@@ -38,12 +38,22 @@ export function insideWorkspace(file) {
38
38
  if (host.name !== 'node') return file; // (a workspace in memory has no links)
39
39
  const top = path.resolve(WS); // (the workspace's own folder may be reached by a link: only what is inside it counts)
40
40
  for (let p = path.resolve(file); p.startsWith(top + path.sep); p = path.dirname(p)) {
41
- let link = false; try { link = fs.lstatSync(p).isSymbolicLink(); } catch {} // (not there yet: nothing to follow)
42
- if (link) throw new Error(`${path.relative(WS, p)} is a link to somewhere else, so nothing was written to ${path.relative(WS, file)}: it could land outside the workspace. Make ${path.relative(WS, p)} a folder or file of the workspace's own`);
41
+ let link = false;
42
+ try {
43
+ link = fs.lstatSync(p).isSymbolicLink();
44
+ } catch {
45
+ // (not there yet: nothing to follow)
46
+ }
47
+ if (link)
48
+ throw new Error(
49
+ `${path.relative(WS, p)} is a link to somewhere else, so nothing was written to ${path.relative(WS, file)}: it could land outside the workspace. Make ${path.relative(WS, p)} a folder or file of the workspace's own`,
50
+ );
43
51
  }
44
52
  return file;
45
53
  }
46
- // A rule set read as it is, the workspace's if it has one: for figures a check only reads, leaving the workspace alone
54
+ // A rule set read as it is, the workspace's if it has one: for figures a check only reads, leaving the workspace alone.
55
+ // (Both read through readJson, which reads a file of the workspace only where it really is inside it: a rules/x.json
56
+ // that is a link to a file elsewhere is refused, code workspace.outside. workspace.mjs ownFile.)
47
57
  export function peekRuleSet(name) {
48
58
  plainName(name, 'rule set name');
49
59
  const file = RULE_DIRS.map((d) => path.join(d, `${name}.json`)).find((f) => host.exists(f));
@@ -10,7 +10,15 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
10
10
  // (Not @rulecad/pcb: a board design reaches the board engine as v.pcb, which the runner loads as the tool's own
11
11
  // module. The engine imports Node's modules, which a package a design may import may not, and the permission model
12
12
  // holds it to reads only.)
13
- const ALLOWED = ['@jscad/modeling', '@rulecad/shapes', '@rulecad/flexures', '@rulecad/gears', '@rulecad/motors', '@rulecad/frames', '@rulecad/fixings'];
13
+ const ALLOWED = [
14
+ '@jscad/modeling',
15
+ '@rulecad/shapes',
16
+ '@rulecad/flexures',
17
+ '@rulecad/gears',
18
+ '@rulecad/motors',
19
+ '@rulecad/frames',
20
+ '@rulecad/fixings',
21
+ ];
14
22
 
15
23
  // Each allowed package's real folder, as the tool itself finds it (from its entry up to the package.json of that
16
24
  // name: exports may hide that file), found once; null where the tool can't find the package
@@ -18,9 +26,12 @@ function home(name) {
18
26
  try {
19
27
  for (let d = path.dirname(fileURLToPath(import.meta.resolve(name))); path.dirname(d) !== d; d = path.dirname(d)) {
20
28
  const pj = path.join(d, 'package.json');
21
- if (fs.existsSync(pj) && JSON.parse(fs.readFileSync(pj, 'utf8')).name === name) return pathToFileURL(fs.realpathSync(d) + path.sep).href;
29
+ if (fs.existsSync(pj) && JSON.parse(fs.readFileSync(pj, 'utf8')).name === name)
30
+ return pathToFileURL(fs.realpathSync(d) + path.sep).href;
22
31
  }
23
- } catch { /* not where the tool can find it */ }
32
+ } catch {
33
+ /* not where the tool can find it */
34
+ }
24
35
  return null;
25
36
  }
26
37
 
@@ -28,8 +39,13 @@ function home(name) {
28
39
  function needs(url) {
29
40
  try {
30
41
  const j = JSON.parse(fs.readFileSync(new URL('package.json', url), 'utf8'));
31
- return [...ALLOWED, ...['dependencies', 'peerDependencies', 'optionalDependencies'].flatMap((k) => Object.keys(j[k] || {}))];
32
- } catch { return ALLOWED; }
42
+ return [
43
+ ...ALLOWED,
44
+ ...['dependencies', 'peerDependencies', 'optionalDependencies'].flatMap((k) => Object.keys(j[k] || {})),
45
+ ];
46
+ } catch {
47
+ return ALLOWED;
48
+ }
33
49
  }
34
50
 
35
51
  /**
@@ -40,7 +56,9 @@ function needs(url) {
40
56
  */
41
57
  export const homesOf = () => Object.fromEntries(ALLOWED.map((a) => [a, home(a)]));
42
58
 
43
- let project = '', homes = {}, deps = {};
59
+ let project = '',
60
+ homes = {},
61
+ deps = {};
44
62
  /**
45
63
  * Set the hooks up: the design's project (a file: URL ending in a slash) and, from the preload, the packages' folders.
46
64
  * @param {{ project?: string, homes?: Record<string, string | null> }} [data]
@@ -51,15 +69,18 @@ export async function initialize(data) {
51
69
  deps = Object.fromEntries(ALLOWED.filter((a) => homes[a]).map((a) => [a, needs(homes[a])]));
52
70
  }
53
71
 
54
- const deny = (spec, why) => Object.assign(new Error(`designs can't import "${spec}": ${why}`), { code: 'design.sandbox' });
72
+ const deny = (spec, why) =>
73
+ Object.assign(new Error(`designs can't import "${spec}": ${why}`), { code: 'design.sandbox' });
55
74
 
56
75
  // The same check, for in-thread hooks (synchronous) and worker hooks (async)
57
76
  export function resolveHook(spec, context, next) {
58
- const fromDesign = check(spec, context), r = next(spec, context);
77
+ const fromDesign = check(spec, context),
78
+ r = next(spec, context);
59
79
  return fromDesign ? after(spec, r) : inPackage(spec, context, r);
60
80
  }
61
81
  export async function resolve(spec, context, next) {
62
- const fromDesign = check(spec, context), r = await next(spec, context);
82
+ const fromDesign = check(spec, context),
83
+ r = await next(spec, context);
63
84
  return fromDesign ? after(spec, r) : inPackage(spec, context, r);
64
85
  }
65
86
  // A design may reach any file of an allowed package, and such a file isn't the design's, so it is free of the rules
@@ -67,17 +88,36 @@ export async function resolve(spec, context, next) {
67
88
  // own tests require('ava'), and an "ava" the workspace installs (a file: dependency, say) may do anything. So a file
68
89
  // of an allowed package (not of a package kept in its node_modules) may import only the allowed packages, what its
69
90
  // package.json depends on, and its own files.
70
- const packageAt = (url) => ALLOWED.find((a) => homes[a] && url?.startsWith(homes[a]) && !url.slice(homes[a].length).split('/').some((s) => s.toLowerCase() === 'node_modules'));
91
+ const packageAt = (url) =>
92
+ ALLOWED.find(
93
+ (a) =>
94
+ homes[a] &&
95
+ url?.startsWith(homes[a]) &&
96
+ !url
97
+ .slice(homes[a].length)
98
+ .split('/')
99
+ .some((s) => s.toLowerCase() === 'node_modules'),
100
+ );
71
101
  // (before Node looks for a name, and after it finds a relative file)
72
102
  function packageCheck(spec, context) {
73
103
  const name = packageAt(context.parentURL);
74
- if (name && !isRelative(spec) && (spec.startsWith('node:') || builtinModules.includes(spec) || !deps[name].some((d) => spec === d || spec.startsWith(`${d}/`)))) {
75
- throw deny(spec, `${fileURLToPath(context.parentURL)} would import it, and its package ${name} doesn't depend on it (a design may use a package's own files, not the tools its tests use)`);
104
+ if (
105
+ name &&
106
+ !isRelative(spec) &&
107
+ (spec.startsWith('node:') ||
108
+ builtinModules.includes(spec) ||
109
+ !deps[name].some((d) => spec === d || spec.startsWith(`${d}/`)))
110
+ ) {
111
+ throw deny(
112
+ spec,
113
+ `${fileURLToPath(context.parentURL)} would import it, and its package ${name} doesn't depend on it (a design may use a package's own files, not the tools its tests use)`,
114
+ );
76
115
  }
77
116
  }
78
117
  function inPackage(spec, context, r) {
79
118
  const name = isRelative(spec) && packageAt(context.parentURL);
80
- if (name && !r.url.startsWith(homes[name])) throw deny(spec, `${fileURLToPath(context.parentURL)} would reach outside its package, ${name}`);
119
+ if (name && !r.url.startsWith(homes[name]))
120
+ throw deny(spec, `${fileURLToPath(context.parentURL)} would reach outside its package, ${name}`);
81
121
  return r;
82
122
  }
83
123
  const isRelative = (spec) => spec.startsWith('./') || spec.startsWith('../');
@@ -90,29 +130,47 @@ const after = (spec, r) => {
90
130
  if (!r.url.startsWith(project)) throw deny(spec, 'it is outside the project');
91
131
  return r;
92
132
  }
93
- const name = packageOf(spec), inside = homes[name];
133
+ const name = packageOf(spec),
134
+ inside = homes[name];
94
135
  if (!r.url.startsWith(project) && !(inside && r.url.startsWith(inside))) {
95
136
  const to = r.url.startsWith('file:') ? fileURLToPath(r.url) : r.url;
96
137
  const own = inside ? ` (${fileURLToPath(inside)})` : '';
97
- throw deny(spec, `it leads outside the package ${name}, to ${to}. A design may use only the copy rulecad itself uses${own} or one inside its project: if the workspace installs another copy, give it the version rulecad uses (npm ls ${name} lists the copies)`);
138
+ throw deny(
139
+ spec,
140
+ `it leads outside the package ${name}, to ${to}. A design may use only the copy rulecad itself uses${own} or one inside its project: if the workspace installs another copy, give it the version rulecad uses (npm ls ${name} lists the copies)`,
141
+ );
98
142
  }
99
143
  return r;
100
144
  };
101
145
  // A file inside a package is named plainly: no '.' or '..' among the folders, no backslash, no %-encoded letters, and
102
146
  // never in the package's own node_modules (another package, which may read files: a nested graceful-fs, say). Windows
103
147
  // drops a name's trailing dots and spaces and knows NODE_M~1 for node_modules, so those spellings are refused too.
104
- const odd = (s) => { const t = s.replace(/[. ]+$/, '').toLowerCase(); return t === '' || t === 'node_modules' || s.includes('~'); };
105
- const climbs = (spec, name) => /[\\%]/.test(spec) || (spec !== name && spec.slice(name.length + 1).split('/').some(odd));
148
+ const odd = (s) => {
149
+ const t = s.replace(/[. ]+$/, '').toLowerCase();
150
+ return t === '' || t === 'node_modules' || s.includes('~');
151
+ };
152
+ const climbs = (spec, name) =>
153
+ /[\\%]/.test(spec) ||
154
+ (spec !== name &&
155
+ spec
156
+ .slice(name.length + 1)
157
+ .split('/')
158
+ .some(odd));
106
159
  // Everything under the project is the design's code, a node_modules folder there included
107
160
  function check(spec, context) {
108
161
  const fromDesign = project && context.parentURL?.startsWith(project);
109
162
  if (!fromDesign) packageCheck(spec, context);
110
163
  if (fromDesign) {
111
- if (spec.startsWith('node:') || builtinModules.includes(spec)) throw deny(spec, 'a design only makes shapes (no files, network or programs)');
164
+ if (spec.startsWith('node:') || builtinModules.includes(spec))
165
+ throw deny(spec, 'a design only makes shapes (no files, network or programs)');
112
166
  if (!isRelative(spec)) {
113
167
  const name = packageOf(spec);
114
168
  if (!name) throw deny(spec, `only ${ALLOWED.join(', ')} and files in its project`);
115
- if (climbs(spec, name)) throw deny(spec, `a file of ${name} is named by its path inside the package, with no "." or ".." folders, node_modules, backslashes, "%" or "~", and no folder whose name ends in a dot or a space`);
169
+ if (climbs(spec, name))
170
+ throw deny(
171
+ spec,
172
+ `a file of ${name} is named by its path inside the package, with no "." or ".." folders, node_modules, backslashes, "%" or "~", and no folder whose name ends in a dot or a space`,
173
+ );
116
174
  }
117
175
  }
118
176
  return fromDesign;
@@ -13,46 +13,145 @@ import { designFrames } from './frames.mjs';
13
13
  import { designFixings } from './fixings.mjs';
14
14
  import { named, faces, unpack, watch } from './parts.mjs';
15
15
  import { lineOf } from './errors.mjs';
16
+ import { keeper, STAGES_MOST, ROUTES_MOST } from './kept.mjs';
16
17
 
17
18
  for (const k of ['fetch', 'WebSocket', 'EventSource', 'XMLHttpRequest', 'Request', 'Response']) delete globalThis[k];
18
19
  // and the ways round the import hook that process itself offers: Node's own modules by name, its internals, other
19
20
  // processes. (sandbox.mjs's header says what this does and doesn't promise.)
20
21
  const exit = process.exit.bind(process);
21
- for (const k of ['getBuiltinModule', 'binding', '_linkedBinding', 'dlopen', 'kill', '_kill', '_getActiveHandles', '_getActiveRequests', '_debugProcess', '_startProfilerIdleNotifier']) {
22
+ for (const k of [
23
+ 'getBuiltinModule',
24
+ 'binding',
25
+ '_linkedBinding',
26
+ 'dlopen',
27
+ 'kill',
28
+ '_kill',
29
+ '_getActiveHandles',
30
+ '_getActiveRequests',
31
+ '_debugProcess',
32
+ '_startProfilerIdleNotifier',
33
+ ]) {
22
34
  if (k in process) Object.defineProperty(process, k, { value: undefined, configurable: false, writable: false });
23
35
  }
24
36
  const chunks = [];
25
37
  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;
38
+ const { js, values, meta, engine, optional, stages, bound, board } = JSON.parse(Buffer.concat(chunks).toString('utf8')),
39
+ context = bound?.fixings;
27
40
  // 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
- const kept = {}; // (what this run made of them)
30
- if (stages) flexures.laminaCache({ salt: stages.salt, get: (k) => { try { return fs.readFileSync(path.join(stages.dir, `${k}.json`), 'utf8'); } catch { return undefined; } }, put: (k, text) => { kept[k] = text; } });
41
+ // 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
42
+ // is used but not kept)
43
+ const stageKeeper = keeper(STAGES_MOST),
44
+ kept = stageKeeper.kept; // (what this run made of them)
45
+ // A file of a cache folder, read only where it really is in that folder: a cloned workspace may hold its own .cache/,
46
+ // 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
47
+ // the permission model, which follows links, and handed to the design. Such a file is a miss: the stage is made afresh.
48
+ // The folder itself the tool hands over only where its real path is inside the workspace (sandbox.mjs ownFolder), so
49
+ // 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
50
+ // native one spells a Windows folder by its long name where the permission model was given its short one, and refuses
51
+ // the read; Node's own is refused the lstat of /var on macOS.)
52
+ const fromFolder = (dir) => (k) => {
53
+ if (!dir) return undefined;
54
+ const f = path.join(dir, `${k}.json`);
55
+ if (path.dirname(f) !== path.resolve(dir)) return undefined;
56
+ try {
57
+ return fs.lstatSync(f).isFile() ? fs.readFileSync(f, 'utf8') : undefined;
58
+ } catch {
59
+ return undefined;
60
+ }
61
+ };
62
+ if (stages)
63
+ flexures.laminaCache({
64
+ salt: stages.salt,
65
+ get: fromFolder(stages.dir),
66
+ put: stageKeeper.put,
67
+ });
31
68
  // 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
- const routes = {};
34
- let pcb = null, mounted = false;
69
+ // data, like v.fixings), and its routes kept as the stages are: read from the design's own folder of the route cache,
70
+ // then from the one the tool's own process writes (board.routes, in that order), and handed back to go in the first
71
+ const routeKeeper = keeper(ROUTES_MOST),
72
+ routes = routeKeeper.kept,
73
+ routeFolders = (board?.routes || []).map(fromFolder),
74
+ routeOf = (k) => {
75
+ for (const get of routeFolders) {
76
+ const text = get(k);
77
+ if (text !== undefined) return text;
78
+ }
79
+ return undefined;
80
+ };
81
+ let pcb = null,
82
+ mounted = false;
35
83
  if (board) {
36
84
  pcb = await import('@rulecad/pcb');
37
- if (pcb.routeStore) pcb.routeStore({ get: (k) => { if (!board.routes) return undefined; try { return fs.readFileSync(path.join(board.routes, `${k}.json`), 'utf8'); } catch { return undefined; } }, put: (k, text) => { routes[k] = text; } });
85
+ if (pcb.routeStore)
86
+ pcb.routeStore({
87
+ get: routeOf,
88
+ put: routeKeeper.put,
89
+ });
38
90
  }
39
- const engineFor = () => ({ ...pcb, mount: (thread, x, y, o = {}) => { mounted = true; return pcb.mount(thread, x, y, { sets: context?.sets, ...o }); } });
40
- const stdout = process.stdout, done = (o) => stdout.write(JSON.stringify(o), () => exit(0));
91
+ const engineFor = () => ({
92
+ ...pcb,
93
+ mount: (thread, x, y, o = {}) => {
94
+ mounted = true;
95
+ return pcb.mount(thread, x, y, { sets: context?.sets, ...o });
96
+ },
97
+ });
98
+ const stdout = process.stdout,
99
+ done = (o) => stdout.write(JSON.stringify(o), () => exit(0));
41
100
  // stdout carries the result, so what a design prints (console.log, to see a value) goes to stderr, which the tool passes on
42
101
  console.log = console.info = console.debug = (...a) => console.error(...a);
43
102
  try {
44
103
  const mod = await import(js);
45
- if (typeof mod.main !== 'function') throw Object.assign(new Error('the design has no exported main(v)'), { code: 'design.main' });
46
- const ops = await shapes.ops(engine || 'jscad'), df = designFixings({ ...(context || {}), ops }); // (v.fixings: bound to the project, as the build's own is)
47
- const { v, read } = watch(values, { shapes, flexures, gears, motors, frames: designFrames(bound?.frames), fixings: df.fixings, ops, ...(pcb ? { pcb: engineFor() } : {}) }, optional);
104
+ if (typeof mod.main !== 'function')
105
+ throw Object.assign(new Error('the design has no exported main(v)'), { code: 'design.main' });
106
+ const ops = await shapes.ops(engine || 'jscad'),
107
+ df = designFixings({ ...(context || {}), ops }); // (v.fixings: bound to the project, as the build's own is)
108
+ const { v, read } = watch(
109
+ values,
110
+ {
111
+ shapes,
112
+ flexures,
113
+ gears,
114
+ motors,
115
+ frames: designFrames(bound?.frames),
116
+ fixings: df.fixings,
117
+ ops,
118
+ ...(pcb ? { pcb: engineFor() } : {}),
119
+ },
120
+ optional,
121
+ );
48
122
  const { shapes: made, mechanism } = unpack(await mod.main(v));
49
- const found = { read: [...read], ...(mechanism ? { mechanism } : {}), ...(df.used() ? { fixings: df.found() } : {}), ...(Object.keys(kept).length ? { stages: kept } : {}) };
50
- if (pcb) { // a circuit board: its Circuit JSON, for the tool to make the board's solid and files from
123
+ const found = {
124
+ read: [...read],
125
+ ...(mechanism ? { mechanism } : {}),
126
+ ...(df.used() ? { fixings: df.found() } : {}),
127
+ ...(Object.keys(kept).length ? { stages: kept } : {}),
128
+ };
129
+ if (pcb) {
130
+ // a circuit board: its Circuit JSON, for the tool to make the board's solid and files from
51
131
  const { board: b, matrix, clone } = made && made.board ? made : { board: made };
52
132
  const circuit = await pcb.render(b);
53
- done({ parts: [], ...found, board: { circuit, ...(matrix ? { matrix } : {}), ...(clone ? { source: clone } : {}) }, ...(mounted ? { mounted } : {}), ...(Object.keys(routes).length ? { routes } : {}) });
133
+ done({
134
+ parts: [],
135
+ ...found,
136
+ board: { circuit, ...(matrix ? { matrix } : {}), ...(clone ? { source: clone } : {}) },
137
+ ...(mounted ? { mounted } : {}),
138
+ ...(Object.keys(routes).length ? { routes } : {}),
139
+ });
54
140
  } else done({ parts: named(made, meta).map(({ geometry, ...p }) => ({ ...p, solid: faces(geometry) })), ...found });
55
141
  } catch (e) {
56
142
  const line = lineOf(e, js);
57
- done({ error: { message: e?.message || String(e), ...(line ? { line } : {}), ...(e?.name === 'SyntaxError' ? { syntax: true } : {}), code: e?.code && typeof e.code === 'string' && !/^ERR_/.test(e.code) ? e.code : e?.code === 'ERR_ACCESS_DENIED' ? 'design.sandbox' : 'design.run', ...(e?.code === 'ERR_ACCESS_DENIED' && e.resource ? { resource: e.resource } : {}) } });
143
+ done({
144
+ error: {
145
+ message: e?.message || String(e),
146
+ ...(line ? { line } : {}),
147
+ ...(e?.name === 'SyntaxError' ? { syntax: true } : {}),
148
+ code:
149
+ e?.code && typeof e.code === 'string' && !/^ERR_/.test(e.code)
150
+ ? e.code
151
+ : e?.code === 'ERR_ACCESS_DENIED'
152
+ ? 'design.sandbox'
153
+ : 'design.run',
154
+ ...(e?.code === 'ERR_ACCESS_DENIED' && e.resource ? { resource: e.resource } : {}),
155
+ },
156
+ });
58
157
  }