@snaptrude/plugin-core 0.2.1 → 0.2.3

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.
@@ -0,0 +1,277 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+
4
+ /**
5
+ * Buildable Envelope management — create and update parametric zoning envelopes.
6
+ *
7
+ * A **buildable envelope** is the regulated volume inside which a building may
8
+ * be massed. The host owns envelope identity: {@linkcode PluginBuildableEnvelopeApi.create create}
9
+ * mints a `buildableEnvelopeId` and returns it; {@linkcode PluginBuildableEnvelopeApi.update update}
10
+ * requires that id to target the existing envelope.
11
+ *
12
+ * Accessed via `snaptrude.entity.buildableEnvelope`.
13
+ */
14
+ export abstract class PluginBuildableEnvelopeApi {
15
+ constructor() {}
16
+
17
+ /**
18
+ * Create a new parametric buildable envelope.
19
+ *
20
+ * @param args - A {@linkcode PluginBuildableEnvelopeCreateArgs} object.
21
+ * @returns A {@linkcode PluginBuildableEnvelopeCreateResult} with the
22
+ * `buildableEnvelopeId` of the created envelope.
23
+ * @throws If validation fails or generation produces no renderable geometry.
24
+ *
25
+ * # Example
26
+ * ```ts
27
+ * const { buildableEnvelopeId } = await snaptrude.entity.buildableEnvelope.create({
28
+ * sitePolygon: [
29
+ * { x: 0, z: 0 },
30
+ * { x: 100, z: 0 },
31
+ * { x: 100, z: 80 },
32
+ * { x: 0, z: 80 },
33
+ * ],
34
+ * lengthUnit: "ft",
35
+ * setbacks: [
36
+ * { aboveHeight: 0, front: 10, side: 5, rear: 10 },
37
+ * { aboveHeight: 100, front: 20, side: 10, rear: 20 },
38
+ * ],
39
+ * verticalCap: { kind: "max_height", maxHeight: 150 },
40
+ * floorToFloor: 12,
41
+ * })
42
+ * ```
43
+ */
44
+ public abstract create(
45
+ args: PluginBuildableEnvelopeCreateArgs
46
+ ): PluginApiReturn<PluginBuildableEnvelopeCreateResult>
47
+
48
+ /**
49
+ * Update an existing parametric buildable envelope.
50
+ *
51
+ * @param args - A {@linkcode PluginBuildableEnvelopeUpdateArgs} object.
52
+ * `buildableEnvelopeId` is required and must match an existing envelope on
53
+ * the canvas.
54
+ * @returns A {@linkcode PluginBuildableEnvelopeUpdateResult} with the
55
+ * `buildableEnvelopeId` of the updated envelope.
56
+ * @throws If validation fails, the envelope does not exist, or generation
57
+ * produces no renderable geometry.
58
+ *
59
+ * # Example
60
+ * ```ts
61
+ * const { buildableEnvelopeId } = await snaptrude.entity.buildableEnvelope.update({
62
+ * buildableEnvelopeId: existingId,
63
+ * sitePolygon: [
64
+ * { x: 0, z: 0 },
65
+ * { x: 100, z: 0 },
66
+ * { x: 100, z: 80 },
67
+ * { x: 0, z: 80 },
68
+ * ],
69
+ * lengthUnit: "ft",
70
+ * setbacks: [{ aboveHeight: 0, front: 10, side: 5, rear: 10 }],
71
+ * verticalCap: { kind: "max_height", maxHeight: 175 },
72
+ * floorToFloor: 12,
73
+ * })
74
+ * ```
75
+ */
76
+ public abstract update(
77
+ args: PluginBuildableEnvelopeUpdateArgs
78
+ ): PluginApiReturn<PluginBuildableEnvelopeUpdateResult>
79
+ }
80
+
81
+ /**
82
+ * Site polygon vertex in the request `lengthUnit`.
83
+ *
84
+ * Vertices may be passed as `{x, z}` objects or `[x, z]` tuples. Numeric
85
+ * values must be finite (no `NaN` or `±Infinity`).
86
+ */
87
+ export const PluginBuildableEnvelopePolygonVertex = z.union([
88
+ z.object({ x: z.number().finite(), z: z.number().finite() }).strict(),
89
+ z.tuple([z.number().finite(), z.number().finite()]),
90
+ ])
91
+
92
+ export type PluginBuildableEnvelopePolygonVertex = z.infer<
93
+ typeof PluginBuildableEnvelopePolygonVertex
94
+ >
95
+
96
+ /**
97
+ * Vertical cap for a buildable envelope.
98
+ *
99
+ * Use exactly one shape:
100
+ * - `{ kind: "max_height", maxHeight }`
101
+ * - `{ kind: "max_floors", maxFloors }`
102
+ *
103
+ * Floor-to-floor height is not nested here; it is always supplied as the
104
+ * top-level `floorToFloor` argument.
105
+ */
106
+ export const PluginBuildableEnvelopeVerticalCap = z.discriminatedUnion("kind", [
107
+ z.object({
108
+ kind: z.literal("max_height"),
109
+ maxHeight: z.number().finite().positive(),
110
+ }).strict(),
111
+ z.object({
112
+ kind: z.literal("max_floors"),
113
+ maxFloors: z.number().finite().int().positive(),
114
+ }).strict(),
115
+ ])
116
+
117
+ export type PluginBuildableEnvelopeVerticalCap = z.infer<
118
+ typeof PluginBuildableEnvelopeVerticalCap
119
+ >
120
+
121
+ /**
122
+ * One tier of a buildable envelope's setback profile.
123
+ *
124
+ * Tiers are ordered by `aboveHeight`. The first tier (index 0) must have
125
+ * `aboveHeight: 0` and describes the ground footprint; each subsequent tier
126
+ * describes the complete setback at a strictly greater height. Each tier
127
+ * carries its own `front`, `side`, and `rear` values — there is no
128
+ * inheritance from earlier tiers.
129
+ *
130
+ * All numeric values must be finite and nonnegative, in the request
131
+ * `lengthUnit`.
132
+ *
133
+ * | Property | Type | Description |
134
+ * |---|---|---|
135
+ * | `aboveHeight` | `number` | Height at or above which this tier applies; the ground tier uses `0` |
136
+ * | `front` | `number` | Front setback for this tier |
137
+ * | `side` | `number` | Side setback for this tier |
138
+ * | `rear` | `number` | Rear setback for this tier |
139
+ */
140
+ export const PluginBuildableEnvelopeSetbackTier = z.object({
141
+ aboveHeight: z.number().finite().nonnegative(),
142
+ front: z.number().finite().nonnegative(),
143
+ side: z.number().finite().nonnegative(),
144
+ rear: z.number().finite().nonnegative(),
145
+ }).strict()
146
+
147
+ export type PluginBuildableEnvelopeSetbackTier = z.infer<
148
+ typeof PluginBuildableEnvelopeSetbackTier
149
+ >
150
+
151
+ // Enforces setback tier ordering invariants on the parsed args shape:
152
+ // - setbacks[0].aboveHeight === 0
153
+ // - aboveHeight strictly increasing thereafter
154
+ // Length >= 1 is enforced earlier by z.array(...).min(1).
155
+ function refineSetbackTiers(
156
+ args: { setbacks: PluginBuildableEnvelopeSetbackTier[] },
157
+ ctx: z.RefinementCtx
158
+ ): void {
159
+ const tiers = args.setbacks
160
+ if (tiers.length === 0) return
161
+ if (tiers[0].aboveHeight !== 0) {
162
+ ctx.addIssue({
163
+ code: z.ZodIssueCode.custom,
164
+ path: ["setbacks", 0, "aboveHeight"],
165
+ message: "Ground tier required: setbacks[0].aboveHeight must be 0.",
166
+ })
167
+ }
168
+ for (let i = 1; i < tiers.length; i++) {
169
+ if (!(tiers[i].aboveHeight > tiers[i - 1].aboveHeight)) {
170
+ ctx.addIssue({
171
+ code: z.ZodIssueCode.custom,
172
+ path: ["setbacks", i, "aboveHeight"],
173
+ message:
174
+ "Setback tiers must be ordered by strictly increasing aboveHeight.",
175
+ })
176
+ }
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Arguments for {@linkcode PluginBuildableEnvelopeApi.create}.
182
+ *
183
+ * Strict schema. The host owns identity — no `buildableEnvelopeId` is accepted
184
+ * on create; the id is minted by the host and returned in
185
+ * {@linkcode PluginBuildableEnvelopeCreateResult}.
186
+ *
187
+ * | Property | Type | Description |
188
+ * |---|---|---|
189
+ * | `sitePolygon` | {@linkcode PluginBuildableEnvelopePolygonVertex}`[]` | Site polygon vertices in `lengthUnit`; minimum 3 vertices |
190
+ * | `lengthUnit` | `"ft" \| "m"` | Unit used by all length fields |
191
+ * | `setbacks` | {@linkcode PluginBuildableEnvelopeSetbackTier}`[]` | Setback profile, ground tier first; minimum 1 tier |
192
+ * | `verticalCap` | {@linkcode PluginBuildableEnvelopeVerticalCap} | Maximum height or floor count |
193
+ * | `floorToFloor` | `number` | Required floor-to-floor height in `lengthUnit` |
194
+ * | `farRatio` | `number?` | Optional FAR value, positive when provided |
195
+ * | `lotCoverageMaxPct` | `number?` | Optional lot coverage cap, `0..100` |
196
+ */
197
+ export const PluginBuildableEnvelopeCreateArgs = z
198
+ .object({
199
+ sitePolygon: z.array(PluginBuildableEnvelopePolygonVertex).min(3),
200
+ lengthUnit: z.union([z.literal("ft"), z.literal("m")]),
201
+ setbacks: z.array(PluginBuildableEnvelopeSetbackTier).min(1),
202
+ verticalCap: PluginBuildableEnvelopeVerticalCap,
203
+ floorToFloor: z.number().finite().positive(),
204
+ farRatio: z.number().finite().positive().optional(),
205
+ lotCoverageMaxPct: z.number().finite().min(0).max(100).optional(),
206
+ })
207
+ .strict()
208
+ .superRefine(refineSetbackTiers)
209
+
210
+ export type PluginBuildableEnvelopeCreateArgs = z.infer<
211
+ typeof PluginBuildableEnvelopeCreateArgs
212
+ >
213
+
214
+ /**
215
+ * Result of {@linkcode PluginBuildableEnvelopeApi.create}.
216
+ *
217
+ * | Property | Type | Description |
218
+ * |---|---|---|
219
+ * | `buildableEnvelopeId` | `string` | Non-empty unique ID of the created buildable envelope |
220
+ */
221
+ export const PluginBuildableEnvelopeCreateResult = z.object({
222
+ buildableEnvelopeId: z.string().min(1),
223
+ }).strict()
224
+
225
+ export type PluginBuildableEnvelopeCreateResult = z.infer<
226
+ typeof PluginBuildableEnvelopeCreateResult
227
+ >
228
+
229
+ /**
230
+ * Arguments for {@linkcode PluginBuildableEnvelopeApi.update}.
231
+ *
232
+ * Strict schema. `buildableEnvelopeId` is required and identifies the prior
233
+ * envelope on the canvas to update.
234
+ *
235
+ * | Property | Type | Description |
236
+ * |---|---|---|
237
+ * | `buildableEnvelopeId` | `string` | Existing envelope ID to update; non-empty |
238
+ * | `sitePolygon` | {@linkcode PluginBuildableEnvelopePolygonVertex}`[]` | Site polygon vertices in `lengthUnit`; minimum 3 vertices |
239
+ * | `lengthUnit` | `"ft" \| "m"` | Unit used by all length fields |
240
+ * | `setbacks` | {@linkcode PluginBuildableEnvelopeSetbackTier}`[]` | Setback profile, ground tier first; minimum 1 tier |
241
+ * | `verticalCap` | {@linkcode PluginBuildableEnvelopeVerticalCap} | Maximum height or floor count |
242
+ * | `floorToFloor` | `number` | Required floor-to-floor height in `lengthUnit` |
243
+ * | `farRatio` | `number?` | Optional FAR value, positive when provided |
244
+ * | `lotCoverageMaxPct` | `number?` | Optional lot coverage cap, `0..100` |
245
+ */
246
+ export const PluginBuildableEnvelopeUpdateArgs = z
247
+ .object({
248
+ buildableEnvelopeId: z.string().min(1),
249
+ sitePolygon: z.array(PluginBuildableEnvelopePolygonVertex).min(3),
250
+ lengthUnit: z.union([z.literal("ft"), z.literal("m")]),
251
+ setbacks: z.array(PluginBuildableEnvelopeSetbackTier).min(1),
252
+ verticalCap: PluginBuildableEnvelopeVerticalCap,
253
+ floorToFloor: z.number().finite().positive(),
254
+ farRatio: z.number().finite().positive().optional(),
255
+ lotCoverageMaxPct: z.number().finite().min(0).max(100).optional(),
256
+ })
257
+ .strict()
258
+ .superRefine(refineSetbackTiers)
259
+
260
+ export type PluginBuildableEnvelopeUpdateArgs = z.infer<
261
+ typeof PluginBuildableEnvelopeUpdateArgs
262
+ >
263
+
264
+ /**
265
+ * Result of {@linkcode PluginBuildableEnvelopeApi.update}.
266
+ *
267
+ * | Property | Type | Description |
268
+ * |---|---|---|
269
+ * | `buildableEnvelopeId` | `string` | Non-empty unique ID of the updated buildable envelope |
270
+ */
271
+ export const PluginBuildableEnvelopeUpdateResult = z.object({
272
+ buildableEnvelopeId: z.string().min(1),
273
+ }).strict()
274
+
275
+ export type PluginBuildableEnvelopeUpdateResult = z.infer<
276
+ typeof PluginBuildableEnvelopeUpdateResult
277
+ >
@@ -1,3 +1,4 @@
1
+ import { PluginBuildableEnvelopeApi } from "./buildableEnvelope"
1
2
  import { PluginDepartmentApi } from "./department"
2
3
  import { PluginReferenceLineApi } from "./referenceLine"
3
4
  import { PluginSpaceApi } from "./space"
@@ -10,6 +11,7 @@ import { PluginStoryApi } from "./story"
10
11
  * - {@linkcode PluginEntityApi.story} — Create, query, and update stories (floors)
11
12
  * - {@linkcode PluginEntityApi.referenceLine} — Create, query, and delete reference lines
12
13
  * - {@linkcode PluginEntityApi.department} — Create and query departments
14
+ * - {@linkcode PluginEntityApi.buildableEnvelope} — Create or update parametric buildable envelopes
13
15
  */
14
16
  export abstract class PluginEntityApi {
15
17
  /** Space (room/mass) operations. See {@linkcode PluginSpaceApi}. */
@@ -20,10 +22,13 @@ export abstract class PluginEntityApi {
20
22
  public abstract referenceLine: PluginReferenceLineApi
21
23
  /** Department operations. See {@linkcode PluginDepartmentApi}. */
22
24
  public abstract department: PluginDepartmentApi
25
+ /** Buildable Envelope operations. See {@linkcode PluginBuildableEnvelopeApi}. */
26
+ public abstract buildableEnvelope: PluginBuildableEnvelopeApi
23
27
 
24
28
  constructor() {}
25
29
  }
26
30
 
31
+ export * from "./buildableEnvelope"
27
32
  export * from "./department"
28
33
  export * from "./referenceLine"
29
34
  export * from "./space"