@snaptrude/plugin-core 0.9.13 → 0.9.14-networks-20260930.1

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 (72) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/api/core/geom/create/index.d.ts +935 -100
  3. package/dist/api/core/geom/create/index.d.ts.map +1 -1
  4. package/dist/api/core/geom/query/brep.d.ts +59 -2
  5. package/dist/api/core/geom/query/brep.d.ts.map +1 -1
  6. package/dist/api/core/geom/query/curve.d.ts +59 -35
  7. package/dist/api/core/geom/query/curve.d.ts.map +1 -1
  8. package/dist/api/core/geom/query/edge.d.ts +2 -2
  9. package/dist/api/core/geom/query/face.d.ts +105 -0
  10. package/dist/api/core/geom/query/face.d.ts.map +1 -1
  11. package/dist/api/core/geom/update/contour.d.ts +2 -0
  12. package/dist/api/core/geom/update/contour.d.ts.map +1 -1
  13. package/dist/api/core/geom/update/curve.d.ts +5 -5
  14. package/dist/api/core/geom/update/profile.d.ts +3 -1
  15. package/dist/api/core/geom/update/profile.d.ts.map +1 -1
  16. package/dist/api/core/handles/index.d.ts +4 -2
  17. package/dist/api/core/handles/index.d.ts.map +1 -1
  18. package/dist/api/design/create/grids.d.ts +1 -1
  19. package/dist/api/design/family.d.ts +67 -10
  20. package/dist/api/design/family.d.ts.map +1 -1
  21. package/dist/api/design/index.d.ts +6 -0
  22. package/dist/api/design/index.d.ts.map +1 -1
  23. package/dist/api/design/networks.d.ts +530 -0
  24. package/dist/api/design/networks.d.ts.map +1 -0
  25. package/dist/api/design/query/geometry/index.d.ts +33 -5
  26. package/dist/api/design/query/geometry/index.d.ts.map +1 -1
  27. package/dist/api/design/query/grids.d.ts +3 -3
  28. package/dist/api/design/query/index.d.ts +47 -0
  29. package/dist/api/design/query/index.d.ts.map +1 -1
  30. package/dist/api/design/query/spaces.d.ts +5 -5
  31. package/dist/api/design/update/index.d.ts +99 -0
  32. package/dist/api/design/update/index.d.ts.map +1 -1
  33. package/dist/api/entity/referenceLine.d.ts +1 -1
  34. package/dist/api/entity/space.d.ts +4 -4
  35. package/dist/api/entity/story.d.ts +4 -4
  36. package/dist/api/presentation/aiInspiration.d.ts +5 -5
  37. package/dist/api/program/site.d.ts +4 -4
  38. package/dist/api/program/spreadsheet.d.ts +4 -4
  39. package/dist/handles.d.ts +13 -3
  40. package/dist/handles.d.ts.map +1 -1
  41. package/dist/index.cjs +3623 -2949
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3561 -2949
  46. package/dist/index.js.map +1 -1
  47. package/dist/massParameters.d.ts +287 -0
  48. package/dist/massParameters.d.ts.map +1 -0
  49. package/dist/massParameters.ops.d.ts +138 -0
  50. package/dist/massParameters.ops.d.ts.map +1 -0
  51. package/package.json +2 -1
  52. package/scripts/check-dist-fresh.mjs +22 -0
  53. package/src/api/core/geom/create/index.ts +1030 -101
  54. package/src/api/core/geom/query/brep.ts +60 -2
  55. package/src/api/core/geom/query/curve.ts +26 -2
  56. package/src/api/core/geom/query/edge.ts +2 -2
  57. package/src/api/core/geom/query/face.ts +109 -4
  58. package/src/api/core/geom/update/contour.ts +2 -0
  59. package/src/api/core/geom/update/profile.ts +2 -0
  60. package/src/api/core/handles/index.ts +3 -2
  61. package/src/api/design/family.ts +68 -10
  62. package/src/api/design/index.ts +7 -0
  63. package/src/api/design/networks.ts +315 -0
  64. package/src/api/design/query/geometry/index.ts +35 -4
  65. package/src/api/design/query/index.ts +50 -0
  66. package/src/api/design/update/index.ts +106 -0
  67. package/src/handles.ts +18 -3
  68. package/src/index.ts +2 -0
  69. package/src/massParameters.ops.ts +246 -0
  70. package/src/massParameters.ts +427 -0
  71. package/test/massParameters.test.mjs +952 -0
  72. package/api-manifest.json +0 -8371
@@ -0,0 +1,246 @@
1
+ import * as z from "zod"
2
+ import {
3
+ ContourRecord,
4
+ CurveRecord,
5
+ LoftOptions,
6
+ MAX_LOFT_SECTIONS,
7
+ MAX_PATH_CURVES,
8
+ MAX_SWEEP_PATH_POINTS,
9
+ SweepAlongCurveRecordOptions,
10
+ SweepOptions,
11
+ XYZ,
12
+ } from "./massParameters"
13
+ import type { CurveKind, SurfaceKind } from "./massParameters"
14
+
15
+ /**
16
+ * The **operation half** of a mass creation-parameter record: which edge or
17
+ * face of the recipe's solid a kernel step used, the step itself, and the
18
+ * values a `design.update.parameters` patch may carry.
19
+ *
20
+ * Split out of `massParameters.ts` so that each file stays under the size limit
21
+ * at which the agent runtime still serves a type module in ONE whole read (the
22
+ * record module alone had grown past it). Do not merge the two back. It is
23
+ * re-exported from there and from the package root, so every import path keeps
24
+ * working.
25
+ *
26
+ * Everything here is **pure JSON** by construction, exactly as in
27
+ * {@linkcode MassParametersRecord}: plain objects, numbers and arrays only, one
28
+ * `{x, y, z}` point shape, no class instances.
29
+ */
30
+
31
+ /** Maximum kernel operations chained onto one recipe. */
32
+ export const MAX_OPERATIONS = 8
33
+ /** Maximum edges one fillet/chamfer operation may select. */
34
+ export const MAX_OPERATION_EDGES = 64
35
+ /** Maximum faces one shell operation may open. */
36
+ export const MAX_OPERATION_FACES = 32
37
+ /** Maximum rows in a variable-fillet radius law. */
38
+ export const MAX_FILLET_LAW_SAMPLES = 32
39
+
40
+ // `XYZ` and the record schemas below are resolved through `z.lazy`: this module
41
+ // and `massParameters.ts` re-export each other, and this one is evaluated first,
42
+ // so their consts are not yet initialised while these schemas are built. The
43
+ // closures run at parse time, when both modules are live.
44
+ const At: z.ZodType<XYZ, XYZ> = z.lazy(() => XYZ)
45
+
46
+ /**
47
+ * Which EDGE of the input solid an operation used: its index in
48
+ * `core.geom.query.brep.listEdges` order at authoring time, the indices of the
49
+ * two faces it lies between, and its curve kind. This is topology, not
50
+ * coordinates — it survives a scalar edit of the base recipe (which moves every
51
+ * edge) and trips on a reorder or a topology change. Read-only: to blend a
52
+ * different edge, re-select it on the new shape and re-apply the operation.
53
+ */
54
+ export type EdgeSelector = {
55
+ index: number
56
+ faces: [number, number]
57
+ curve: CurveKind
58
+ /** Where the edge sits INSIDE its solid: its midpoint in the record's own
59
+ * frame, divided by the solid's bounding-box extent — a ratio per axis,
60
+ * never a length, so it survives a scalar edit that scales the whole shape.
61
+ * Written only when the discriminators above cannot tell two edges apart. A
62
+ * tiebreak, never a coordinate fingerprint: a replay checks it within 0.02 of
63
+ * the solid's own box and refuses on a miss — it never searches for a better
64
+ * candidate. */
65
+ at?: XYZ
66
+ }
67
+
68
+ /**
69
+ * Which FACE of the input solid an operation used: its index in
70
+ * `core.geom.query.brep.listFaces` order, its surface kind, and the number of
71
+ * edges in its outer loop. Read-only, like {@linkcode EdgeSelector}.
72
+ */
73
+ export type FaceSelector = {
74
+ index: number
75
+ kind: SurfaceKind
76
+ edgeCount: number
77
+ /** The face's centroid under the same normalisation and the same tiebreak
78
+ * rule as {@linkcode EdgeSelector}'s `at` — written only where the
79
+ * discriminators above cannot separate two faces, which on a freeform solid
80
+ * (every face answers `"spline"`) is the common case. */
81
+ at?: XYZ
82
+ }
83
+
84
+ /** The input solid's topology at authoring time — the counts a replay checks first. */
85
+ export type TopologyCounts = { faceCount: number; edgeCount: number }
86
+
87
+ /**
88
+ * One kernel operation applied to the base recipe's solid, in order. `input`
89
+ * pins the topology the operation was authored against, so a base edit that
90
+ * changes the topology is refused rather than mis-applied.
91
+ *
92
+ * Edit one by patching the whole list back:
93
+ * `design.update.parameters(mass, { operations })`.
94
+ */
95
+ export type OperationRecord =
96
+ | {
97
+ op: "fillet"
98
+ edges: EdgeSelector[]
99
+ radius: number
100
+ /** Radius at the far end of the blend contour, internal length units — a
101
+ * linear variable blend from `radius`. One edge, and never with `radii`. */
102
+ endRadius?: number
103
+ /** The blend's radius law instead: `position` is normalised arc length
104
+ * along the blend contour (a ratio 0..1, never converted), `radius` is
105
+ * internal length units. 2..32 rows, strictly increasing `position`.
106
+ * One edge, and never with `endRadius`. */
107
+ radii?: { position: number; radius: number }[]
108
+ input: TopologyCounts
109
+ }
110
+ | { op: "chamfer"; edges: EdgeSelector[]; distance: number; input: TopologyCounts }
111
+ | { op: "shell"; openFaces: FaceSelector[]; thickness: number; input: TopologyCounts }
112
+ | { op: "offset"; distance: number; input: TopologyCounts }
113
+
114
+ /**
115
+ * One value of a `MassParametersPatch` — whatever a record's `values` key (or
116
+ * `operations`) may hold. Each key you send replaces that value whole — a
117
+ * scalar, a point, a list or a record (`contour`, `profile`, `sections`,
118
+ * `path`, `options`, `operations`) alike — so send the complete value you read.
119
+ */
120
+ export type ParameterPatchValue =
121
+ | number
122
+ | XYZ
123
+ | XYZ[]
124
+ | ContourRecord
125
+ | ContourRecord[]
126
+ | CurveRecord[]
127
+ | LoftOptions
128
+ | SweepOptions
129
+ | SweepAlongCurveRecordOptions
130
+ | OperationRecord[]
131
+
132
+ const FaceIndex = z.number().int().nonnegative()
133
+
134
+ /** See {@linkcode EdgeSelector}. */
135
+ export const EdgeSelector: z.ZodType<EdgeSelector, EdgeSelector> = z.strictObject({
136
+ index: FaceIndex,
137
+ faces: z.tuple([FaceIndex, FaceIndex]),
138
+ curve: z.enum(["line", "arc", "circle", "spline"]),
139
+ at: At.optional(),
140
+ })
141
+
142
+ /** See {@linkcode FaceSelector}. */
143
+ export const FaceSelector: z.ZodType<FaceSelector, FaceSelector> = z.strictObject({
144
+ index: FaceIndex,
145
+ kind: z.enum(["plane", "cylinder", "cone", "sphere", "torus", "spline"]),
146
+ edgeCount: z.number().int().positive(),
147
+ at: At.optional(),
148
+ })
149
+
150
+ /** See {@linkcode TopologyCounts}. */
151
+ export const TopologyCounts: z.ZodType<TopologyCounts, TopologyCounts> = z.strictObject({
152
+ faceCount: z.number().int().positive(),
153
+ edgeCount: z.number().int().positive(),
154
+ })
155
+
156
+ /** One row of a variable fillet's radius law. See {@linkcode OperationRecord}. */
157
+ const FilletLawRow = z.strictObject({
158
+ position: z.number().finite().min(0).max(1),
159
+ radius: z.number().finite().positive(),
160
+ })
161
+
162
+ /**
163
+ * See {@linkcode OperationRecord}.
164
+ *
165
+ * A variable fillet — `endRadius` or `radii` — names ONE edge: the law is a
166
+ * property of the blend contour that edge belongs to, and `position` is measured
167
+ * from that edge's start, so a second edge would have no origin. The two forms
168
+ * are mutually exclusive and `radii` rows run strictly forward.
169
+ */
170
+ export const OperationRecord: z.ZodType<OperationRecord, OperationRecord> = z
171
+ .discriminatedUnion("op", [
172
+ z.strictObject({
173
+ op: z.literal("fillet"),
174
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
175
+ radius: z.number().finite().positive(),
176
+ endRadius: z.number().finite().positive().optional(),
177
+ radii: z.array(FilletLawRow).min(2).max(MAX_FILLET_LAW_SAMPLES).optional(),
178
+ input: TopologyCounts,
179
+ }),
180
+ z.strictObject({
181
+ op: z.literal("chamfer"),
182
+ edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
183
+ distance: z.number().finite().positive(),
184
+ input: TopologyCounts,
185
+ }),
186
+ z.strictObject({
187
+ op: z.literal("shell"),
188
+ openFaces: z.array(FaceSelector).min(1).max(MAX_OPERATION_FACES),
189
+ thickness: z.number().finite().positive(),
190
+ input: TopologyCounts,
191
+ }),
192
+ z.strictObject({
193
+ op: z.literal("offset"),
194
+ distance: z
195
+ .number()
196
+ .finite()
197
+ .refine((value) => value !== 0, { message: "distance must be non-zero" }),
198
+ input: TopologyCounts,
199
+ }),
200
+ ])
201
+ .superRefine((operation, ctx) => {
202
+ if (operation.op !== "fillet") return
203
+ const { edges, endRadius, radii } = operation
204
+ if (endRadius === undefined && radii === undefined) return
205
+ if (endRadius !== undefined && radii !== undefined) {
206
+ ctx.addIssue({
207
+ code: "custom",
208
+ message: "endRadius is mutually exclusive with radii",
209
+ })
210
+ }
211
+ if (edges.length !== 1) {
212
+ ctx.addIssue({
213
+ code: "custom",
214
+ message: "a variable fillet names exactly one edge — the blend contour it runs along",
215
+ })
216
+ }
217
+ if (radii?.some((row, i) => i > 0 && row.position <= radii[i - 1].position)) {
218
+ ctx.addIssue({
219
+ code: "custom",
220
+ message: "radii positions must strictly increase",
221
+ })
222
+ }
223
+ })
224
+
225
+ /**
226
+ * One value of a parameter patch. See {@linkcode ParameterPatchValue}.
227
+ *
228
+ * Deliberately a CLOSED union of the shapes a record's `values` actually hold —
229
+ * no `z.unknown()`, nothing recursive: an unrecognised value is a VALIDATION at
230
+ * the wire, not a silent write of nonsense onto a mass. It only ever widens, so
231
+ * every value it accepted before it still accepts.
232
+ */
233
+ export const ParameterPatchValue: z.ZodType<ParameterPatchValue, ParameterPatchValue> = z.lazy(() =>
234
+ z.union([
235
+ z.number().finite(),
236
+ XYZ,
237
+ z.array(XYZ).max(MAX_SWEEP_PATH_POINTS),
238
+ ContourRecord,
239
+ z.array(ContourRecord).max(MAX_LOFT_SECTIONS),
240
+ z.array(CurveRecord).max(MAX_PATH_CURVES),
241
+ LoftOptions,
242
+ SweepOptions,
243
+ SweepAlongCurveRecordOptions,
244
+ z.array(OperationRecord).max(MAX_OPERATIONS),
245
+ ]),
246
+ )
@@ -0,0 +1,427 @@
1
+ import * as z from "zod"
2
+ import { MAX_OPERATIONS, OperationRecord, ParameterPatchValue } from "./massParameters.ops"
3
+
4
+ // The selectors, the operation record and the patch-value union live in
5
+ // `massParameters.ops.ts` (split so each module stays small enough for the
6
+ // agent to read in one go) and are re-exported here, so every import path
7
+ // keeps working.
8
+ export * from "./massParameters.ops"
9
+
10
+ /**
11
+ * Mass **creation-parameter records** — the recipe a parametric mass was built
12
+ * from, shared verbatim by plugin-core, the Snaptrude host, and the agent
13
+ * runtime. There is one schema, not three hand-kept copies.
14
+ *
15
+ * A record is present on a mass committed from a `core.geom.create` brep
16
+ * constructor that carries a recipe (the four primitives, extrusion,
17
+ * revolution, loft, sweep). A fillet, chamfer, shell or offset of a **recorded**
18
+ * solid keeps the record: `kind` stays the base constructor and the step is
19
+ * appended to the record's `operations` list (see {@linkcode OperationRecord}).
20
+ * The record is absent — `null` — for everything
21
+ * else: drawn masses, imported geometry, booleans, split parts,
22
+ * `brepFromFaces`/`brepFromMesh`, and any operation on a solid that carried no
23
+ * record. Geometry there is not a pure function of a legible parameter set, and
24
+ * a record must never be a lie.
25
+ *
26
+ * Read one with `design.query.getParameters`.
27
+ *
28
+ * Everything here is **pure JSON** by construction — plain objects, numbers and
29
+ * arrays only, one `{x, y, z}` point shape everywhere (no tuples, no class
30
+ * instances): records are persisted by enumerable-field reflection, cloned with
31
+ * `structuredClone`, and round-tripped through the collaboration wire.
32
+ */
33
+
34
+ /** A point in space. The single point shape used across every record. */
35
+ export type XYZ = { x: number; y: number; z: number }
36
+
37
+ /**
38
+ * One boundary curve of a profile record.
39
+ *
40
+ * The two spline forms are either/or, never both: a curve authored through
41
+ * points carries `splineThrough` (patch the points and the fit re-runs), and a
42
+ * curve with no through-point provenance — read back off an edge, or authored
43
+ * from control vertices — carries `splinePoles` and is re-minted verbatim.
44
+ * There is no variant holding both, so a `throughPoints` edit can never leave
45
+ * stale poles behind.
46
+ */
47
+ export type CurveRecord =
48
+ | { type: "line"; start: XYZ; end: XYZ }
49
+ | { type: "arc"; start: XYZ; end: XYZ; centre: XYZ; axis: XYZ }
50
+ | { type: "circle"; centre: XYZ; axis: XYZ; radius: number }
51
+ /** Authored via splineFromPoints / profileFromSplinePoints. The through-points
52
+ * ARE the recipe; regeneration re-runs the fit version named by
53
+ * `fitVersion`. Several chained runs in one contour re-fit as ONE loop; use
54
+ * splinePoles to keep their tangents. */
55
+ | { type: "splineThrough"; fitVersion: 1; throughPoints: XYZ[] }
56
+ /** No through-points known (authored from control points, or read back off
57
+ * an edge). Rebuilt verbatim from these exact poles, knots and
58
+ * multiplicities. */
59
+ | { type: "splinePoles"; degree: number; knots: number[]; mults: number[]; poles: XYZ[] }
60
+
61
+ /** A closed boundary loop, as an ordered list of curves. */
62
+ export type ProfileRecord = { curves: CurveRecord[] }
63
+
64
+ /** An outer loop plus its holes — the cross-section shape of a recipe. */
65
+ export type ContourRecord = { outer: ProfileRecord; holes: ProfileRecord[] }
66
+
67
+ /** Optional loft behaviour switches, mirroring `core.geom.create.brepFromLoft`. */
68
+ export type LoftOptions = {
69
+ compatibility?: "strict" | "auto"
70
+ seamAlignment?: "authored" | "auto"
71
+ /** `"ruled"` (default) keeps the sides straight: every pair of sections
72
+ * joined by flat sides. `"smooth"` lofts every section in ONE pass, so the
73
+ * sides curve continuously through the intermediates. */
74
+ smoothing?: "ruled" | "smooth"
75
+ }
76
+
77
+ /**
78
+ * How a swept profile turns along its path, mirroring
79
+ * `core.geom.create.brepFromSweepAlongCurve`. `"upright"` keeps the profile's up
80
+ * aligned with world up, `"frenet"` lets it roll with the path's curvature, and
81
+ * `"fixed"` carries the authored frame along unchanged.
82
+ */
83
+ export type SweepOrientation = "frenet" | "fixed" | "upright"
84
+
85
+ /** Optional sweep-along-a-curve switches. Pure JSON: the creator's own bag also
86
+ * takes a `rail` curve, which is a live handle and never reaches a record. */
87
+ export type SweepAlongCurveRecordOptions = { orientation?: SweepOrientation }
88
+
89
+ /** Optional sweep scale law and corner transition, mirroring `core.geom.create.brepFromSweep`. */
90
+ export type SweepOptions = {
91
+ startScale?: number
92
+ endScale?: number
93
+ scales?: number[]
94
+ transition?: "miter" | "round" | { bevel: number }
95
+ }
96
+
97
+ /** A face's surface kind — the vocabulary of `core.geom.query.face.getSurfaceKind`. */
98
+ export type SurfaceKind = "plane" | "cylinder" | "cone" | "sphere" | "torus" | "spline"
99
+
100
+ /** An edge's curve kind. Both spline forms of {@linkcode CurveRecord} report `"spline"`. */
101
+ export type CurveKind = "line" | "arc" | "circle" | "spline"
102
+
103
+ /**
104
+ * A mass's creation recipe: the constructor `kind`, a schema `version`, the
105
+ * `values` that constructor was called with, and the kernel `operations`
106
+ * (fillet / chamfer / shell / offset) applied on top, in order. Points and axes
107
+ * are in the mass's own local frame when stored; `design.query.getParameters`
108
+ * returns them in world coordinates. `operations` is frame-free. One variant
109
+ * per constructor `kind`; its `values` are that constructor's own arguments.
110
+ *
111
+ * `kind` stays the base constructor even after operations: a shelled, filleted
112
+ * sphere is still `{ kind: "sphere", operations: [shell, fillet] }`.
113
+ */
114
+ export type MassParametersRecord =
115
+ | {
116
+ kind: "sphere"
117
+ version: 1
118
+ values: { centre: XYZ; radius: number }
119
+ operations?: OperationRecord[]
120
+ }
121
+ | {
122
+ kind: "cylinder"
123
+ version: 1
124
+ values: { base: XYZ; axis: XYZ; radius: number; height: number }
125
+ operations?: OperationRecord[]
126
+ }
127
+ | {
128
+ kind: "cone"
129
+ version: 1
130
+ values: { base: XYZ; axis: XYZ; baseRadius: number; topRadius: number; height: number }
131
+ operations?: OperationRecord[]
132
+ }
133
+ | {
134
+ kind: "torus"
135
+ version: 1
136
+ values: { centre: XYZ; axis: XYZ; majorRadius: number; minorRadius: number }
137
+ operations?: OperationRecord[]
138
+ }
139
+ | {
140
+ kind: "extrusion"
141
+ version: 1
142
+ values: {
143
+ contour: ContourRecord
144
+ direction: XYZ
145
+ amount: number
146
+ /** Total rotation base → top about `direction`, through the base
147
+ * contour's centroid, in DEGREES — an angle, never converted. Absent
148
+ * or 0 is a straight extrusion. Positive turns the top CLOCKWISE seen
149
+ * from the far end of `direction` looking back at the base — for the
150
+ * usual upward extrusion, that is the plan view from above. */
151
+ twistInDegrees?: number
152
+ /** Top outline scale about the same axis, a ratio — never converted.
153
+ * Absent or 1 is a straight extrusion. */
154
+ topScale?: number
155
+ /** How many sections the twist/taper was built from, a count (2..64).
156
+ * Resolved and stamped at create time, so an existing mass regenerates
157
+ * from the record and never from a heuristic that may change; it is
158
+ * re-resolved (and an echoed value overridden) when an edit changes
159
+ * `twistInDegrees`, so a retwisted mass matches a fresh build of the
160
+ * same angle. Absent exactly when the mass is neither twisted nor
161
+ * tapered. */
162
+ levels?: number
163
+ }
164
+ operations?: OperationRecord[]
165
+ }
166
+ | {
167
+ kind: "revolution"
168
+ version: 1
169
+ values: {
170
+ contour: ContourRecord
171
+ axisOrigin: XYZ
172
+ axisDirection: XYZ
173
+ angleInDegrees: number
174
+ }
175
+ operations?: OperationRecord[]
176
+ }
177
+ | {
178
+ kind: "loft"
179
+ version: 1
180
+ values: { sections: ContourRecord[]; options?: LoftOptions }
181
+ operations?: OperationRecord[]
182
+ }
183
+ | {
184
+ kind: "sweep"
185
+ version: 1
186
+ values: { profile: ContourRecord; path: XYZ[]; options?: SweepOptions }
187
+ operations?: OperationRecord[]
188
+ }
189
+ | {
190
+ kind: "sweepAlongCurve"
191
+ version: 1
192
+ values: {
193
+ profile: ContourRecord
194
+ path: CurveRecord[]
195
+ options?: SweepAlongCurveRecordOptions
196
+ }
197
+ operations?: OperationRecord[]
198
+ }
199
+
200
+ /**
201
+ * The argument of `design.update.parameters`: either a **partial** of a
202
+ * record's `values` (plus an optional `operations` list) — keys you leave out
203
+ * stay as they are — or the **whole record** you read from
204
+ * `design.query.getParameters`, edited. `kind` and `version` are immutable.
205
+ */
206
+ export type MassParametersPatch = MassParametersRecord | Record<string, ParameterPatchValue>
207
+
208
+ // ── Schemas ─────────────────────────────────────────────────────────────────
209
+ // Array bounds are CONTRACT, not silent truncation: a record beyond them fails
210
+ // validation. They keep a record inside the serialization budget of the save
211
+ // and collaboration payloads it rides in. They bind RECORDS only — the shipped
212
+ // creator schemas (loft sections, sweep path, fillet/chamfer edges, shell faces)
213
+ // stay uncapped; an over-cap call still builds and the host simply mints no
214
+ // record for it (the mass is then ordinary, non-parametric geometry).
215
+
216
+ /** Maximum through-points in one authored spline curve record. */
217
+ export const MAX_SPLINE_THROUGH_POINTS = 256
218
+ /** Maximum control points in one exact-NURBS spline curve record. */
219
+ export const MAX_SPLINE_POLES = 512
220
+ /** Maximum path points in a sweep record. */
221
+ export const MAX_SWEEP_PATH_POINTS = 512
222
+ /** Maximum path curves in a sweep-along-a-curve record. */
223
+ export const MAX_PATH_CURVES = 64
224
+ /** Maximum cross-sections in a loft record. */
225
+ export const MAX_LOFT_SECTIONS = 32
226
+ /** Maximum sections a twisted or tapered extrusion record is built from. */
227
+ export const MAX_TWIST_LEVELS = 64
228
+ /** Maximum boundary curves in one profile loop record. */
229
+ export const MAX_PROFILE_CURVES = 256
230
+ /** Maximum hole loops in one contour record. */
231
+ export const MAX_CONTOUR_HOLES = 64
232
+
233
+ /** A point in space — `{ x, y, z }`, all finite. */
234
+ export const XYZ: z.ZodType<XYZ, XYZ> = z.strictObject({
235
+ x: z.number().finite(),
236
+ y: z.number().finite(),
237
+ z: z.number().finite(),
238
+ })
239
+
240
+ /** One boundary curve of a profile record. See {@linkcode CurveRecord}. */
241
+ export const CurveRecord: z.ZodType<CurveRecord, CurveRecord> = z.discriminatedUnion("type", [
242
+ z.strictObject({ type: z.literal("line"), start: XYZ, end: XYZ }),
243
+ z.strictObject({ type: z.literal("arc"), start: XYZ, end: XYZ, centre: XYZ, axis: XYZ }),
244
+ z.strictObject({
245
+ type: z.literal("circle"),
246
+ centre: XYZ,
247
+ axis: XYZ,
248
+ radius: z.number().finite().positive(),
249
+ }),
250
+ z.strictObject({
251
+ type: z.literal("splineThrough"),
252
+ fitVersion: z.literal(1),
253
+ throughPoints: z.array(XYZ).min(2).max(MAX_SPLINE_THROUGH_POINTS),
254
+ }),
255
+ z.strictObject({
256
+ type: z.literal("splinePoles"),
257
+ degree: z.number().int().positive(),
258
+ knots: z.array(z.number().finite()).min(2),
259
+ mults: z.array(z.number().int().positive()).min(2),
260
+ poles: z.array(XYZ).min(2).max(MAX_SPLINE_POLES),
261
+ }),
262
+ ])
263
+
264
+ /** A closed boundary loop. See {@linkcode ProfileRecord}. */
265
+ export const ProfileRecord: z.ZodType<ProfileRecord, ProfileRecord> = z.strictObject({
266
+ curves: z.array(CurveRecord).min(1).max(MAX_PROFILE_CURVES),
267
+ })
268
+
269
+ /** An outer loop plus its holes. See {@linkcode ContourRecord}. */
270
+ export const ContourRecord: z.ZodType<ContourRecord, ContourRecord> = z.strictObject({
271
+ outer: ProfileRecord,
272
+ holes: z.array(ProfileRecord).max(MAX_CONTOUR_HOLES),
273
+ })
274
+
275
+ /** Optional loft behaviour switches. See {@linkcode LoftOptions}. */
276
+ export const LoftOptions: z.ZodType<LoftOptions, LoftOptions> = z.strictObject({
277
+ compatibility: z.enum(["strict", "auto"]).optional(),
278
+ seamAlignment: z.enum(["authored", "auto"]).optional(),
279
+ smoothing: z.enum(["ruled", "smooth"]).optional(),
280
+ })
281
+
282
+ /** See {@linkcode SweepAlongCurveRecordOptions}. */
283
+ export const SweepAlongCurveRecordOptions: z.ZodType<
284
+ SweepAlongCurveRecordOptions,
285
+ SweepAlongCurveRecordOptions
286
+ > = z.strictObject({
287
+ orientation: z.enum(["frenet", "fixed", "upright"]).optional(),
288
+ })
289
+
290
+ /** Optional sweep scale law and corner transition. See {@linkcode SweepOptions}. */
291
+ export const SweepOptions: z.ZodType<SweepOptions, SweepOptions> = z.strictObject({
292
+ startScale: z.number().finite().optional(),
293
+ endScale: z.number().finite().optional(),
294
+ scales: z.array(z.number().finite()).optional(),
295
+ transition: z
296
+ .union([
297
+ z.literal("miter"),
298
+ z.literal("round"),
299
+ z.strictObject({ bevel: z.number().finite() }),
300
+ ])
301
+ .optional(),
302
+ })
303
+
304
+ // `operations` rides beside `values` on every kind — additive and optional, so
305
+ // `version` stays 1. An older reader that predates `operations` fails
306
+ // `safeParse` on a record carrying it and degrades the mass to non-parametric;
307
+ // it never blocks a load.
308
+ // No `.min(1)`: `design.update.parameters` documents `{ operations: [] }` as the
309
+ // drop-every-operation idiom, and the whole record you read back — edited to an
310
+ // empty list — must patch the same way. The host normalises `[]` to an absent
311
+ // key before storing, so a stored record never carries one.
312
+ const RecordOperations = z.array(OperationRecord).max(MAX_OPERATIONS).optional()
313
+
314
+ /**
315
+ * A mass's creation recipe. See {@linkcode MassParametersRecord}.
316
+ *
317
+ * `version` is a literal `1`: a restore that reads an unknown version fails
318
+ * `safeParse` and the mass degrades to non-parametric — editability is lost,
319
+ * geometry never is, and load is never blocked. Future versions add a migration
320
+ * at the restore site.
321
+ */
322
+ export const MassParametersRecord: z.ZodType<MassParametersRecord, MassParametersRecord> = z.discriminatedUnion("kind", [
323
+ z.strictObject({
324
+ kind: z.literal("sphere"),
325
+ version: z.literal(1),
326
+ values: z.strictObject({ centre: XYZ, radius: z.number().finite().positive() }),
327
+ operations: RecordOperations,
328
+ }),
329
+ z.strictObject({
330
+ kind: z.literal("cylinder"),
331
+ version: z.literal(1),
332
+ values: z.strictObject({
333
+ base: XYZ,
334
+ axis: XYZ,
335
+ radius: z.number().finite().positive(),
336
+ height: z.number().finite().positive(),
337
+ }),
338
+ operations: RecordOperations,
339
+ }),
340
+ z.strictObject({
341
+ kind: z.literal("cone"),
342
+ version: z.literal(1),
343
+ values: z.strictObject({
344
+ base: XYZ,
345
+ axis: XYZ,
346
+ baseRadius: z.number().finite().positive(),
347
+ topRadius: z.number().finite().nonnegative(),
348
+ height: z.number().finite().positive(),
349
+ }),
350
+ operations: RecordOperations,
351
+ }),
352
+ z.strictObject({
353
+ kind: z.literal("torus"),
354
+ version: z.literal(1),
355
+ values: z.strictObject({
356
+ centre: XYZ,
357
+ axis: XYZ,
358
+ majorRadius: z.number().finite().positive(),
359
+ minorRadius: z.number().finite().positive(),
360
+ }),
361
+ operations: RecordOperations,
362
+ }),
363
+ z.strictObject({
364
+ kind: z.literal("extrusion"),
365
+ version: z.literal(1),
366
+ values: z.strictObject({
367
+ contour: ContourRecord,
368
+ direction: XYZ,
369
+ amount: z.number().finite(),
370
+ twistInDegrees: z.number().finite().optional(),
371
+ topScale: z.number().finite().positive().optional(),
372
+ levels: z.number().int().min(2).max(MAX_TWIST_LEVELS).optional(),
373
+ }),
374
+ operations: RecordOperations,
375
+ }),
376
+ z.strictObject({
377
+ kind: z.literal("revolution"),
378
+ version: z.literal(1),
379
+ values: z.strictObject({
380
+ contour: ContourRecord,
381
+ axisOrigin: XYZ,
382
+ axisDirection: XYZ,
383
+ angleInDegrees: z.number().finite().positive().max(360),
384
+ }),
385
+ operations: RecordOperations,
386
+ }),
387
+ z.strictObject({
388
+ kind: z.literal("loft"),
389
+ version: z.literal(1),
390
+ values: z.strictObject({
391
+ sections: z.array(ContourRecord).min(2).max(MAX_LOFT_SECTIONS),
392
+ options: LoftOptions.optional(),
393
+ }),
394
+ operations: RecordOperations,
395
+ }),
396
+ z.strictObject({
397
+ kind: z.literal("sweep"),
398
+ version: z.literal(1),
399
+ values: z.strictObject({
400
+ profile: ContourRecord,
401
+ path: z.array(XYZ).min(2).max(MAX_SWEEP_PATH_POINTS),
402
+ options: SweepOptions.optional(),
403
+ }),
404
+ operations: RecordOperations,
405
+ }),
406
+ z.strictObject({
407
+ kind: z.literal("sweepAlongCurve"),
408
+ version: z.literal(1),
409
+ values: z.strictObject({
410
+ profile: ContourRecord,
411
+ path: z.array(CurveRecord).min(1).max(MAX_PATH_CURVES),
412
+ options: SweepAlongCurveRecordOptions.optional(),
413
+ }),
414
+ operations: RecordOperations,
415
+ }),
416
+ ])
417
+
418
+ /**
419
+ * The argument of `design.update.parameters`. See {@linkcode MassParametersPatch}.
420
+ * The full-record form is recognised by carrying both `kind` and `values`;
421
+ * which keys a kind actually has is checked host-side, where the error can name
422
+ * them.
423
+ */
424
+ export const MassParametersPatch: z.ZodType<MassParametersPatch, MassParametersPatch> = z.union([
425
+ MassParametersRecord,
426
+ z.record(z.string(), ParameterPatchValue),
427
+ ])