@snaptrude/plugin-core 0.9.7 → 0.9.9

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 (39) hide show
  1. package/AGENTS.md +4 -0
  2. package/CHANGELOG.md +11 -0
  3. package/api-manifest.json +222 -4
  4. package/dist/api/core/tags.d.ts +81 -0
  5. package/dist/api/core/tags.d.ts.map +1 -1
  6. package/dist/api/design/create/bulk-items.d.ts +14 -6
  7. package/dist/api/design/create/bulk-items.d.ts.map +1 -1
  8. package/dist/api/design/create/index.d.ts +41 -18
  9. package/dist/api/design/create/index.d.ts.map +1 -1
  10. package/dist/api/design/create/opening-fields.d.ts +10 -2
  11. package/dist/api/design/create/opening-fields.d.ts.map +1 -1
  12. package/dist/api/design/doors/index.d.ts +20 -13
  13. package/dist/api/design/doors/index.d.ts.map +1 -1
  14. package/dist/api/program/departments.d.ts +58 -2
  15. package/dist/api/program/departments.d.ts.map +1 -1
  16. package/dist/api/program/index.d.ts +16 -6
  17. package/dist/api/program/index.d.ts.map +1 -1
  18. package/dist/api/program/labels.d.ts +355 -0
  19. package/dist/api/program/labels.d.ts.map +1 -0
  20. package/dist/api/program/metadata.d.ts +328 -0
  21. package/dist/api/program/metadata.d.ts.map +1 -0
  22. package/dist/api/program/spreadsheet.d.ts +263 -0
  23. package/dist/api/program/spreadsheet.d.ts.map +1 -1
  24. package/dist/index.cjs +1084 -833
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.js +1039 -833
  27. package/dist/index.js.map +1 -1
  28. package/package.json +13 -13
  29. package/src/api/core/tags.ts +76 -0
  30. package/src/api/design/create/bulk-items.ts +10 -6
  31. package/src/api/design/create/index.ts +43 -24
  32. package/src/api/design/create/opening-fields.ts +10 -2
  33. package/src/api/design/doors/index.ts +20 -13
  34. package/src/api/program/departments.ts +54 -2
  35. package/src/api/program/index.ts +16 -6
  36. package/src/api/program/labels.ts +332 -0
  37. package/src/api/program/metadata.ts +364 -0
  38. package/src/api/program/spreadsheet.ts +282 -0
  39. package/api-manifest.full.json +0 -8442
@@ -0,0 +1,332 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+ import { PluginAreaUnit } from "./metrics"
4
+
5
+ /**
6
+ * Program labels — the **program rows** of the active program: each label is a
7
+ * named space type (e.g. "Exam Room", "Nurse Station") inside a department,
8
+ * carrying an area **target** and a unit **count** target.
9
+ *
10
+ * Labels are the non-department planning entities of program mode. A
11
+ * department groups labels; a label groups the spaces (masses) that realize it.
12
+ * Target areas live on **departments** ({@linkcode PluginProgramDepartmentsApi.setTargetArea})
13
+ * and on **labels** (this namespace) — an individual space carries no target of
14
+ * its own; it inherits its label's `targetArea / targetCount`. Program Blocks
15
+ * (spaces whose space type is "Program Block") are likewise targeted through
16
+ * their label.
17
+ *
18
+ * `targetArea` is the label's **total** target (all units), in the response's
19
+ * `units`; the per-unit target is `targetArea / targetCount`.
20
+ *
21
+ * Reads never throw for a miss (`get` returns `null`, `list` returns `[]`).
22
+ * Writes are undoable and autosaved; when the project has proposals they write
23
+ * the **active proposal's** targets.
24
+ *
25
+ * Accessed via `snaptrude.program.labels`.
26
+ */
27
+ export abstract class PluginProgramLabelsApi {
28
+ constructor() {}
29
+
30
+ /**
31
+ * List the labels (program rows) of the active program.
32
+ *
33
+ * @returns A {@linkcode PluginProgramLabelsListResult} with `units` and a
34
+ * `labels` array (empty when the project has none).
35
+ *
36
+ * @examplePrompt List all the program rows with their target areas
37
+ * @examplePrompt What space labels are in the program and how many of each?
38
+ * @examplePrompt Show every label with its department and target
39
+ *
40
+ * # Example
41
+ * ```ts
42
+ * const { units, labels } = await snaptrude.program.labels.list()
43
+ * for (const l of labels) console.log(l.name, l.targetArea, units, l.targetCount)
44
+ * ```
45
+ */
46
+ public abstract list(): PluginApiReturn<PluginProgramLabelsListResult>
47
+
48
+ /**
49
+ * Get a single label by id.
50
+ *
51
+ * @param labelId - The id of the label to read.
52
+ * @returns The matching {@linkcode PluginProgramLabelRecord} (with `units`), or
53
+ * `null` if no label has that id.
54
+ *
55
+ * @examplePrompt Get the label with id lbl_12
56
+ * @examplePrompt What is the target area of this program row?
57
+ *
58
+ * # Example
59
+ * ```ts
60
+ * const label = await snaptrude.program.labels.get("lbl_12")
61
+ * if (label) console.log(label.name, label.targetArea, label.units)
62
+ * ```
63
+ */
64
+ public abstract get(
65
+ labelId: string,
66
+ ): PluginApiReturn<PluginProgramLabelsGetResult>
67
+
68
+ /**
69
+ * Create labels (program rows), optionally creating their spaces too.
70
+ *
71
+ * Each item names a label and its targets. A label is unique per
72
+ * (`name`, department); an item matching an existing label **updates** that
73
+ * label's targets instead of duplicating it. Unknown departments are created
74
+ * by name when `departmentName` is given; omit both department fields for the
75
+ * Default department.
76
+ *
77
+ * By default only the program rows are created (targets to plan against).
78
+ * Pass `createSpaces: true` to also instantiate `targetCount` massing spaces
79
+ * per label on the canvas, laid out automatically — the same path Program
80
+ * Mode's CSV/Interpret import uses.
81
+ *
82
+ * @param items - The labels to create (1–500).
83
+ * @param options - Optional `units` for every `targetArea` (defaults to the
84
+ * project's area units) and `createSpaces` (default `false`).
85
+ * @returns A {@linkcode PluginProgramLabelsCreateResult} with the created or
86
+ * updated label ids, in input order.
87
+ * @throws If an item's `departmentId` does not exist.
88
+ *
89
+ * @examplePrompt Add program rows for 4 exam rooms of 120 sqft each
90
+ * @examplePrompt Create the labels from this interpreted program
91
+ * @examplePrompt Add an Office label with a 2000 sqft target to the Admin department
92
+ * @examplePrompt Create program rows and their spaces on the canvas
93
+ *
94
+ * # Example
95
+ * ```ts
96
+ * const { labelIds } = await snaptrude.program.labels.create(
97
+ * [{ name: "Exam Room", targetArea: 480, targetCount: 4, departmentName: "Clinic" }],
98
+ * { units: "ft2" },
99
+ * )
100
+ * ```
101
+ */
102
+ public abstract create(
103
+ items: PluginProgramLabelCreateItem[],
104
+ options?: { units?: PluginAreaUnit; createSpaces?: boolean },
105
+ ): PluginApiReturn<PluginProgramLabelsCreateResult>
106
+
107
+ /**
108
+ * Set a label's total target area.
109
+ *
110
+ * The goal the program metrics compare the label's allocated area against.
111
+ * Pass `units` to say what unit `targetArea` is in; it defaults to the
112
+ * project's area units. Read it back with {@linkcode PluginProgramLabelsApi.get}.
113
+ *
114
+ * @param labelId - The id of the label whose target to set.
115
+ * @param targetArea - The total target area (all units), in `units`.
116
+ * @param units - Unit of `targetArea` (defaults to the project's area units).
117
+ * @returns The updated {@linkcode PluginProgramLabelRecord} with its `units`.
118
+ * @throws If no label has the given id.
119
+ *
120
+ * @examplePrompt Set the Exam Room target area to 480 sqft
121
+ * @examplePrompt Give the Corridor program row a 150 sqm target
122
+ * @examplePrompt Update the area target for label lbl_12
123
+ *
124
+ * # Example
125
+ * ```ts
126
+ * await snaptrude.program.labels.setTargetArea("lbl_12", 480, "ft2")
127
+ * ```
128
+ */
129
+ public abstract setTargetArea(
130
+ labelId: string,
131
+ targetArea: number,
132
+ units?: PluginAreaUnit,
133
+ ): PluginApiReturn<PluginProgramLabelsSetTargetAreaResult>
134
+
135
+ /**
136
+ * Set a label's target unit count (how many of this space the program calls for).
137
+ *
138
+ * @param labelId - The id of the label whose count to set.
139
+ * @param targetCount - The target number of units (a non-negative integer).
140
+ * @returns The updated {@linkcode PluginProgramLabelRecord} with its `units`.
141
+ * @throws If no label has the given id.
142
+ *
143
+ * @examplePrompt Set the Exam Room count to 6
144
+ * @examplePrompt The program needs 12 patient rooms — update the count
145
+ *
146
+ * # Example
147
+ * ```ts
148
+ * await snaptrude.program.labels.setTargetCount("lbl_12", 6)
149
+ * ```
150
+ */
151
+ public abstract setTargetCount(
152
+ labelId: string,
153
+ targetCount: number,
154
+ ): PluginApiReturn<PluginProgramLabelsSetTargetCountResult>
155
+ }
156
+
157
+ /**
158
+ * A label (program row) in the active program. `targetArea` is the label's
159
+ * **total** target in the enclosing response's `units`.
160
+ *
161
+ * | Property | Type | Description |
162
+ * |---|---|---|
163
+ * | `id` | `string` | Stable label id |
164
+ * | `name` | `string` | Label (space type) name |
165
+ * | `color` | `string` | CSS hex color string |
166
+ * | `departmentId` | `string` | Id of the department the label belongs to |
167
+ * | `targetArea` | `number \| null` | Total target area (all units), or `null` when no target is set |
168
+ * | `targetCount` | `number` | Target number of units (`0` when unset) |
169
+ * | `storey` | `number \| null` | Default storey new spaces of this label are placed on |
170
+ */
171
+ export const PluginProgramLabel = z.object({
172
+ id: z.string(),
173
+ name: z.string(),
174
+ color: z.string(),
175
+ departmentId: z.string(),
176
+ targetArea: z.number().nullable(),
177
+ targetCount: z.number(),
178
+ storey: z.number().nullable(),
179
+ })
180
+ export type PluginProgramLabel = z.infer<typeof PluginProgramLabel>
181
+
182
+ /** A bare label record carrying its area `units` (per the area-units convention). */
183
+ export const PluginProgramLabelRecord = PluginProgramLabel.extend({
184
+ units: PluginAreaUnit,
185
+ })
186
+ export type PluginProgramLabelRecord = z.infer<typeof PluginProgramLabelRecord>
187
+
188
+ /**
189
+ * Result of {@linkcode PluginProgramLabelsApi.list}.
190
+ *
191
+ * | Property | Type | Description |
192
+ * |---|---|---|
193
+ * | `units` | `"ft2" \| "m2"` | The unit every `targetArea` below is reported in |
194
+ * | `labels` | {@linkcode PluginProgramLabel}`[]` | All labels in the active program |
195
+ */
196
+ export const PluginProgramLabelsListResult = z.object({
197
+ units: PluginAreaUnit,
198
+ labels: z.array(PluginProgramLabel),
199
+ })
200
+ export type PluginProgramLabelsListResult = z.infer<
201
+ typeof PluginProgramLabelsListResult
202
+ >
203
+
204
+ /** Arguments for {@linkcode PluginProgramLabelsApi.get}. */
205
+ export const PluginProgramLabelsGetArgs = z.object({
206
+ labelId: z.string(),
207
+ })
208
+ export type PluginProgramLabelsGetArgs = z.infer<
209
+ typeof PluginProgramLabelsGetArgs
210
+ >
211
+
212
+ /** Result of {@linkcode PluginProgramLabelsApi.get} — the record with `units`, or `null`. */
213
+ export const PluginProgramLabelsGetResult = PluginProgramLabelRecord.nullable()
214
+ export type PluginProgramLabelsGetResult = z.infer<
215
+ typeof PluginProgramLabelsGetResult
216
+ >
217
+
218
+ /**
219
+ * One label to create via {@linkcode PluginProgramLabelsApi.create}.
220
+ *
221
+ * | Property | Type | Description |
222
+ * |---|---|---|
223
+ * | `name` | `string` | Label (space type) name |
224
+ * | `targetArea` | `number?` | Total target area (all units), in the call's `units` |
225
+ * | `targetCount` | `number?` | Target number of units (default `1`) |
226
+ * | `departmentId` | `string?` | Existing department to file the label under |
227
+ * | `departmentName` | `string?` | Department by name — created when it does not exist (ignored when `departmentId` is given) |
228
+ * | `color` | `string?` | CSS hex color (a light color is generated when omitted) |
229
+ * | `storey` | `number?` | Storey for spaces of this label (default `1`) |
230
+ * | `height` | `number?` | Space height in project length units (for `createSpaces`) |
231
+ * | `width` | `number?` | Space width in project length units (for `createSpaces`) |
232
+ */
233
+ export const PluginProgramLabelCreateItem = z.object({
234
+ name: z.string().trim().min(1),
235
+ targetArea: z.number().finite().nonnegative().optional(),
236
+ targetCount: z.number().int().nonnegative().optional(),
237
+ departmentId: z.string().optional(),
238
+ departmentName: z.string().optional(),
239
+ color: z.string().optional(),
240
+ storey: z.number().int().optional(),
241
+ height: z.number().finite().positive().optional(),
242
+ width: z.number().finite().positive().optional(),
243
+ })
244
+ export type PluginProgramLabelCreateItem = z.infer<
245
+ typeof PluginProgramLabelCreateItem
246
+ >
247
+
248
+ /** Maximum items per {@linkcode PluginProgramLabelsApi.create} call. */
249
+ export const PLUGIN_PROGRAM_LABELS_BATCH_LIMIT = 500
250
+
251
+ /**
252
+ * Arguments for {@linkcode PluginProgramLabelsApi.create}.
253
+ *
254
+ * | Property | Type | Description |
255
+ * |---|---|---|
256
+ * | `items` | {@linkcode PluginProgramLabelCreateItem}`[]` | 1–500 labels |
257
+ * | `units` | `"ft2" \| "m2"?` | Unit of every `targetArea` (defaults to the project's area units) |
258
+ * | `createSpaces` | `boolean?` | Also create `targetCount` spaces per label on the canvas (default `false`) |
259
+ */
260
+ export const PluginProgramLabelsCreateArgs = z.object({
261
+ items: z
262
+ .array(PluginProgramLabelCreateItem)
263
+ .min(1)
264
+ .max(PLUGIN_PROGRAM_LABELS_BATCH_LIMIT),
265
+ units: PluginAreaUnit.optional(),
266
+ createSpaces: z.boolean().optional(),
267
+ })
268
+ export type PluginProgramLabelsCreateArgs = z.infer<
269
+ typeof PluginProgramLabelsCreateArgs
270
+ >
271
+
272
+ /**
273
+ * Result of {@linkcode PluginProgramLabelsApi.create}.
274
+ *
275
+ * | Property | Type | Description |
276
+ * |---|---|---|
277
+ * | `labelIds` | `string[]` | The created (or updated) label ids, in input order |
278
+ * | `createdSpaces` | `boolean` | Whether spaces were also created on the canvas |
279
+ */
280
+ export const PluginProgramLabelsCreateResult = z.object({
281
+ labelIds: z.array(z.string()),
282
+ createdSpaces: z.boolean(),
283
+ })
284
+ export type PluginProgramLabelsCreateResult = z.infer<
285
+ typeof PluginProgramLabelsCreateResult
286
+ >
287
+
288
+ /**
289
+ * Arguments for {@linkcode PluginProgramLabelsApi.setTargetArea}.
290
+ *
291
+ * | Property | Type | Description |
292
+ * |---|---|---|
293
+ * | `labelId` | `string` | The label whose target to set |
294
+ * | `targetArea` | `number` | Total target area, in `units` |
295
+ * | `units` | `"ft2" \| "m2"?` | Unit of `targetArea` (defaults to the project's area units) |
296
+ */
297
+ export const PluginProgramLabelsSetTargetAreaArgs = z.object({
298
+ labelId: z.string(),
299
+ targetArea: z.number().finite().nonnegative(),
300
+ units: PluginAreaUnit.optional(),
301
+ })
302
+ export type PluginProgramLabelsSetTargetAreaArgs = z.infer<
303
+ typeof PluginProgramLabelsSetTargetAreaArgs
304
+ >
305
+
306
+ /** Result of {@linkcode PluginProgramLabelsApi.setTargetArea} — the updated record with `units`. */
307
+ export const PluginProgramLabelsSetTargetAreaResult = PluginProgramLabelRecord
308
+ export type PluginProgramLabelsSetTargetAreaResult = z.infer<
309
+ typeof PluginProgramLabelsSetTargetAreaResult
310
+ >
311
+
312
+ /**
313
+ * Arguments for {@linkcode PluginProgramLabelsApi.setTargetCount}.
314
+ *
315
+ * | Property | Type | Description |
316
+ * |---|---|---|
317
+ * | `labelId` | `string` | The label whose count to set |
318
+ * | `targetCount` | `number` | Target number of units (non-negative integer) |
319
+ */
320
+ export const PluginProgramLabelsSetTargetCountArgs = z.object({
321
+ labelId: z.string(),
322
+ targetCount: z.number().int().nonnegative(),
323
+ })
324
+ export type PluginProgramLabelsSetTargetCountArgs = z.infer<
325
+ typeof PluginProgramLabelsSetTargetCountArgs
326
+ >
327
+
328
+ /** Result of {@linkcode PluginProgramLabelsApi.setTargetCount} — the updated record with `units`. */
329
+ export const PluginProgramLabelsSetTargetCountResult = PluginProgramLabelRecord
330
+ export type PluginProgramLabelsSetTargetCountResult = z.infer<
331
+ typeof PluginProgramLabelsSetTargetCountResult
332
+ >
@@ -0,0 +1,364 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+ import { ComponentHandle } from "../../handles"
4
+ import { PluginSpreadsheetCell } from "./spreadsheet"
5
+
6
+ /**
7
+ * Program metadata — the user-defined **custom columns** of the Program Data
8
+ * sheet and their per-space values.
9
+ *
10
+ * In program mode a **metadata header** is a custom column (e.g. "Department
11
+ * Code", "Occupancy", "Finish Level") added to the Program Data sheet; every
12
+ * space can then carry one **value** per header. This is the same store the
13
+ * Program tab reads and writes — values set here appear in the default Program
14
+ * Data sheet and in every custom sheet that shows the column, and values typed
15
+ * into the sheet are read back here. The store lives in the editor, so **no
16
+ * method in this namespace needs the Program tab open**.
17
+ *
18
+ * Headers are identified by a stable `headerId`. Values are plain cells
19
+ * (`string | number | boolean | null`); `null` clears a value. Departments and
20
+ * labels also carry metadata in the engine, but this namespace covers **spaces**
21
+ * (Mass/Floor components) — the per-space case plugins asked for.
22
+ *
23
+ * Reads never throw for a miss (`get` returns `null`, `list*` return `[]`).
24
+ * Writes are undoable and autosaved.
25
+ *
26
+ * Accessed via `snaptrude.program.metadata`.
27
+ */
28
+ export abstract class PluginProgramMetadataApi {
29
+ constructor() {}
30
+
31
+ /**
32
+ * List the metadata headers (custom columns) of the Program Data sheet.
33
+ *
34
+ * @returns A {@linkcode PluginProgramMetadataListHeadersResult} with a
35
+ * `headers` array (empty when the project has no custom columns).
36
+ *
37
+ * @examplePrompt List the custom metadata columns in program mode
38
+ * @examplePrompt What metadata headers does the program sheet have?
39
+ * @examplePrompt Show every custom column with its id
40
+ *
41
+ * # Example
42
+ * ```ts
43
+ * const { headers } = await snaptrude.program.metadata.listHeaders()
44
+ * for (const h of headers) console.log(h.headerId, h.name)
45
+ * ```
46
+ */
47
+ public abstract listHeaders(): PluginApiReturn<PluginProgramMetadataListHeadersResult>
48
+
49
+ /**
50
+ * Create a metadata header (a custom column on the Program Data sheet).
51
+ *
52
+ * Header names are unique per sheet: when a header with the same name already
53
+ * exists it is **reused** and returned (no duplicate column is created), so
54
+ * re-running a plugin is safe. The new column is appended after the sheet's
55
+ * existing custom columns.
56
+ *
57
+ * @param name - Column header text (non-empty).
58
+ * @param options - Optional `description` shown in the column's description
59
+ * row.
60
+ * @returns The created (or reused) {@linkcode PluginProgramMetadataHeader}.
61
+ * @throws If `name` is blank.
62
+ *
63
+ * @examplePrompt Add a custom column called Occupancy to the program sheet
64
+ * @examplePrompt Create a metadata header named Department Code
65
+ * @examplePrompt Make a new program-mode column for Finish Level
66
+ *
67
+ * # Example
68
+ * ```ts
69
+ * const header = await snaptrude.program.metadata.createHeader("Occupancy", {
70
+ * description: "People per room",
71
+ * })
72
+ * ```
73
+ */
74
+ public abstract createHeader(
75
+ name: string,
76
+ options?: { description?: string },
77
+ ): PluginApiReturn<PluginProgramMetadataCreateHeaderResult>
78
+
79
+ /**
80
+ * Get one space's metadata values, keyed by header id.
81
+ *
82
+ * @param spaceId - The space (component id) to read.
83
+ * @returns A {@linkcode PluginProgramMetadataRecord} — `values` holds one entry
84
+ * per header the space has a value for — or `null` when no space has that id.
85
+ *
86
+ * @examplePrompt Get the metadata on this space
87
+ * @examplePrompt Read the custom column values for space sp_12
88
+ * @examplePrompt What is this room's Occupancy metadata?
89
+ *
90
+ * # Example
91
+ * ```ts
92
+ * const record = await snaptrude.program.metadata.get("sp_12")
93
+ * if (record) console.log(record.values)
94
+ * ```
95
+ */
96
+ public abstract get(
97
+ spaceId: ComponentHandle,
98
+ ): PluginApiReturn<PluginProgramMetadataGetResult>
99
+
100
+ /**
101
+ * List metadata values for many spaces at once.
102
+ *
103
+ * Pass `spaceIds` to read specific spaces (unknown ids are skipped), or omit
104
+ * it to read every space in the project. One host round-trip regardless of
105
+ * the number of spaces — prefer this over calling
106
+ * {@linkcode PluginProgramMetadataApi.get} in a loop.
107
+ *
108
+ * @param spaceIds - Optional space ids to read; omit for all spaces.
109
+ * @returns A {@linkcode PluginProgramMetadataListResult} with one
110
+ * {@linkcode PluginProgramMetadataRecord} per space.
111
+ *
112
+ * @performance One round-trip for any number of spaces — use this instead of a `get` loop.
113
+ *
114
+ * @examplePrompt List the metadata of every space
115
+ * @examplePrompt Read the custom column values for all rooms
116
+ * @examplePrompt Get the metadata for these three spaces in one call
117
+ *
118
+ * # Example
119
+ * ```ts
120
+ * const { records } = await snaptrude.program.metadata.list()
121
+ * const byId = Object.fromEntries(records.map((r) => [r.spaceId, r.values]))
122
+ * ```
123
+ */
124
+ public abstract list(
125
+ spaceIds?: ComponentHandle[],
126
+ ): PluginApiReturn<PluginProgramMetadataListResult>
127
+
128
+ /**
129
+ * Update a space's metadata values (sparse).
130
+ *
131
+ * Only the headers present in `values` change; `null` clears a value. Every
132
+ * key must be an existing `headerId` (create columns first with
133
+ * {@linkcode PluginProgramMetadataApi.createHeader}). Undoable as one step.
134
+ *
135
+ * @param spaceId - The space (component id) to write.
136
+ * @param values - Header id → new cell value (`null` clears).
137
+ * @returns The space's full {@linkcode PluginProgramMetadataRecord} after the
138
+ * write.
139
+ * @throws If the space or any header id does not exist.
140
+ *
141
+ * @examplePrompt Set the Occupancy metadata of this space to 4
142
+ * @examplePrompt Store a department code on the selected rooms
143
+ * @examplePrompt Write custom column values onto space sp_12
144
+ * @examplePrompt Clear the Finish Level metadata on this space
145
+ *
146
+ * # Example
147
+ * ```ts
148
+ * const header = await snaptrude.program.metadata.createHeader("Occupancy")
149
+ * await snaptrude.program.metadata.update("sp_12", { [header.headerId]: 4 })
150
+ * ```
151
+ */
152
+ public abstract update(
153
+ spaceId: ComponentHandle,
154
+ values: Record<string, PluginSpreadsheetCell>,
155
+ ): PluginApiReturn<PluginProgramMetadataUpdateResult>
156
+
157
+ /**
158
+ * Update metadata values on many spaces in one undoable step.
159
+ *
160
+ * The plural of {@linkcode PluginProgramMetadataApi.update}: each item names a
161
+ * space and its sparse `values`. Results are in input order. Capped at 1000
162
+ * items per call.
163
+ *
164
+ * @param items - The spaces and the values to write on each.
165
+ * @returns A {@linkcode PluginProgramMetadataUpdateManyResult} with one record
166
+ * per item, in input order.
167
+ * @throws If any space or header id does not exist (nothing is written).
168
+ *
169
+ * @performance One round-trip and one undo step for up to 1000 spaces — use this instead of an `update` loop.
170
+ *
171
+ * @examplePrompt Fill the Occupancy column for all bedrooms
172
+ * @examplePrompt Write metadata onto every selected space at once
173
+ * @examplePrompt Bulk-update custom column values
174
+ *
175
+ * # Example
176
+ * ```ts
177
+ * await snaptrude.program.metadata.updateMany([
178
+ * { spaceId: "sp_12", values: { [headerId]: 4 } },
179
+ * { spaceId: "sp_13", values: { [headerId]: 2 } },
180
+ * ])
181
+ * ```
182
+ */
183
+ public abstract updateMany(
184
+ items: PluginProgramMetadataUpdateItem[],
185
+ ): PluginApiReturn<PluginProgramMetadataUpdateManyResult>
186
+ }
187
+
188
+ /**
189
+ * A metadata header — one custom column of the Program Data sheet.
190
+ *
191
+ * | Property | Type | Description |
192
+ * |---|---|---|
193
+ * | `headerId` | `string` | Stable header id (the key used in metadata `values`) |
194
+ * | `name` | `string` | Column header text |
195
+ * | `description` | `string` | Column description (`""` when none) |
196
+ * | `columnIndex` | `number` | Zero-based column index on the Program Data sheet |
197
+ */
198
+ export const PluginProgramMetadataHeader = z.object({
199
+ headerId: z.string(),
200
+ name: z.string(),
201
+ description: z.string(),
202
+ columnIndex: z.number(),
203
+ })
204
+ export type PluginProgramMetadataHeader = z.infer<
205
+ typeof PluginProgramMetadataHeader
206
+ >
207
+
208
+ /**
209
+ * Result of {@linkcode PluginProgramMetadataApi.listHeaders}.
210
+ *
211
+ * | Property | Type | Description |
212
+ * |---|---|---|
213
+ * | `headers` | {@linkcode PluginProgramMetadataHeader}`[]` | Every custom column, in sheet column order |
214
+ */
215
+ export const PluginProgramMetadataListHeadersResult = z.object({
216
+ headers: z.array(PluginProgramMetadataHeader),
217
+ })
218
+ export type PluginProgramMetadataListHeadersResult = z.infer<
219
+ typeof PluginProgramMetadataListHeadersResult
220
+ >
221
+
222
+ /**
223
+ * Arguments for {@linkcode PluginProgramMetadataApi.createHeader}.
224
+ *
225
+ * | Property | Type | Description |
226
+ * |---|---|---|
227
+ * | `name` | `string` | Column header text (non-empty) |
228
+ * | `description` | `string?` | Column description |
229
+ */
230
+ export const PluginProgramMetadataCreateHeaderArgs = z.object({
231
+ name: z.string().trim().min(1),
232
+ description: z.string().optional(),
233
+ })
234
+ export type PluginProgramMetadataCreateHeaderArgs = z.infer<
235
+ typeof PluginProgramMetadataCreateHeaderArgs
236
+ >
237
+
238
+ /** Result of {@linkcode PluginProgramMetadataApi.createHeader} — the created or reused header. */
239
+ export const PluginProgramMetadataCreateHeaderResult = PluginProgramMetadataHeader
240
+ export type PluginProgramMetadataCreateHeaderResult = z.infer<
241
+ typeof PluginProgramMetadataCreateHeaderResult
242
+ >
243
+
244
+ /**
245
+ * One space's metadata values.
246
+ *
247
+ * | Property | Type | Description |
248
+ * |---|---|---|
249
+ * | `spaceId` | `ComponentHandle` | The space's component id |
250
+ * | `values` | `Record<string, cell>` | Header id → value, one entry per header the space has a value for |
251
+ */
252
+ export const PluginProgramMetadataRecord = z.object({
253
+ spaceId: ComponentHandle,
254
+ values: z.record(z.string(), PluginSpreadsheetCell),
255
+ })
256
+ export type PluginProgramMetadataRecord = z.infer<
257
+ typeof PluginProgramMetadataRecord
258
+ >
259
+
260
+ /** Arguments for {@linkcode PluginProgramMetadataApi.get}. */
261
+ export const PluginProgramMetadataGetArgs = z.object({
262
+ spaceId: ComponentHandle,
263
+ })
264
+ export type PluginProgramMetadataGetArgs = z.infer<
265
+ typeof PluginProgramMetadataGetArgs
266
+ >
267
+
268
+ /** Result of {@linkcode PluginProgramMetadataApi.get} — the record, or `null` when the space does not exist. */
269
+ export const PluginProgramMetadataGetResult = PluginProgramMetadataRecord.nullable()
270
+ export type PluginProgramMetadataGetResult = z.infer<
271
+ typeof PluginProgramMetadataGetResult
272
+ >
273
+
274
+ /**
275
+ * Arguments for {@linkcode PluginProgramMetadataApi.list}.
276
+ *
277
+ * | Property | Type | Description |
278
+ * |---|---|---|
279
+ * | `spaceIds` | `ComponentHandle[]?` | Spaces to read; omit for every space |
280
+ */
281
+ export const PluginProgramMetadataListArgs = z.object({
282
+ spaceIds: z.array(ComponentHandle).optional(),
283
+ })
284
+ export type PluginProgramMetadataListArgs = z.infer<
285
+ typeof PluginProgramMetadataListArgs
286
+ >
287
+
288
+ /**
289
+ * Result of {@linkcode PluginProgramMetadataApi.list}.
290
+ *
291
+ * | Property | Type | Description |
292
+ * |---|---|---|
293
+ * | `records` | {@linkcode PluginProgramMetadataRecord}`[]` | One record per space (unknown ids skipped) |
294
+ */
295
+ export const PluginProgramMetadataListResult = z.object({
296
+ records: z.array(PluginProgramMetadataRecord),
297
+ })
298
+ export type PluginProgramMetadataListResult = z.infer<
299
+ typeof PluginProgramMetadataListResult
300
+ >
301
+
302
+ /**
303
+ * Arguments for {@linkcode PluginProgramMetadataApi.update}.
304
+ *
305
+ * | Property | Type | Description |
306
+ * |---|---|---|
307
+ * | `spaceId` | `ComponentHandle` | The space to write |
308
+ * | `values` | `Record<string, cell>` | Header id → new value (`null` clears); at least one entry |
309
+ */
310
+ export const PluginProgramMetadataUpdateArgs = z.object({
311
+ spaceId: ComponentHandle,
312
+ values: z
313
+ .record(z.string(), PluginSpreadsheetCell)
314
+ .refine((v) => Object.keys(v).length > 0, "values must not be empty"),
315
+ })
316
+ export type PluginProgramMetadataUpdateArgs = z.infer<
317
+ typeof PluginProgramMetadataUpdateArgs
318
+ >
319
+
320
+ /** Result of {@linkcode PluginProgramMetadataApi.update} — the space's record after the write. */
321
+ export const PluginProgramMetadataUpdateResult = PluginProgramMetadataRecord
322
+ export type PluginProgramMetadataUpdateResult = z.infer<
323
+ typeof PluginProgramMetadataUpdateResult
324
+ >
325
+
326
+ /** One item of {@linkcode PluginProgramMetadataApi.updateMany} — mirrors the `update` args. */
327
+ export const PluginProgramMetadataUpdateItem = PluginProgramMetadataUpdateArgs
328
+ export type PluginProgramMetadataUpdateItem = z.infer<
329
+ typeof PluginProgramMetadataUpdateItem
330
+ >
331
+
332
+ /** Maximum items per {@linkcode PluginProgramMetadataApi.updateMany} call. */
333
+ export const PLUGIN_PROGRAM_METADATA_BATCH_LIMIT = 1000
334
+
335
+ /**
336
+ * Arguments for {@linkcode PluginProgramMetadataApi.updateMany}.
337
+ *
338
+ * | Property | Type | Description |
339
+ * |---|---|---|
340
+ * | `items` | {@linkcode PluginProgramMetadataUpdateItem}`[]` | 1–1000 space updates |
341
+ */
342
+ export const PluginProgramMetadataUpdateManyArgs = z.object({
343
+ items: z
344
+ .array(PluginProgramMetadataUpdateItem)
345
+ .min(1)
346
+ .max(PLUGIN_PROGRAM_METADATA_BATCH_LIMIT),
347
+ })
348
+ export type PluginProgramMetadataUpdateManyArgs = z.infer<
349
+ typeof PluginProgramMetadataUpdateManyArgs
350
+ >
351
+
352
+ /**
353
+ * Result of {@linkcode PluginProgramMetadataApi.updateMany}.
354
+ *
355
+ * | Property | Type | Description |
356
+ * |---|---|---|
357
+ * | `records` | {@linkcode PluginProgramMetadataRecord}`[]` | One record per item, in input order |
358
+ */
359
+ export const PluginProgramMetadataUpdateManyResult = z.object({
360
+ records: z.array(PluginProgramMetadataRecord),
361
+ })
362
+ export type PluginProgramMetadataUpdateManyResult = z.infer<
363
+ typeof PluginProgramMetadataUpdateManyResult
364
+ >