@snaptrude/plugin-core 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/api/entity/space.d.ts +680 -0
- package/dist/api/entity/space.d.ts.map +1 -1
- package/dist/index.cjs +80 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/entity/space.ts +277 -0
package/package.json
CHANGED
package/src/api/entity/space.ts
CHANGED
|
@@ -266,6 +266,112 @@ export abstract class PluginSpaceApi {
|
|
|
266
266
|
public abstract update(
|
|
267
267
|
args: PluginSpaceUpdateArgs,
|
|
268
268
|
): PluginApiReturn<PluginSpaceUpdateResult>
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Create many spaces in a single undoable operation.
|
|
272
|
+
*
|
|
273
|
+
* Each item is either a rectangular box (`kind: "rectangular"`) or an
|
|
274
|
+
* extruded profile (`kind: "profile"`), and may optionally set `room_type`,
|
|
275
|
+
* `spaceType`, `massType`, and `departmentId`. All creations — and the
|
|
276
|
+
* optional property assignments — are batched into **one** command, so the
|
|
277
|
+
* entire batch is undone/redone in a single step.
|
|
278
|
+
*
|
|
279
|
+
* All items are validated first; if any item is invalid the call **throws**
|
|
280
|
+
* and no spaces are created (nothing is applied) — consistent with the
|
|
281
|
+
* single-item create methods.
|
|
282
|
+
*
|
|
283
|
+
* @param args - {@linkcode PluginSpaceBulkCreateArgs} with an `items` array
|
|
284
|
+
* @returns A {@linkcode PluginSpaceBulkCreateResult} with the `spaceIds` of
|
|
285
|
+
* the created spaces, in input order
|
|
286
|
+
* @throws If any item has invalid dimensions, height, or profile
|
|
287
|
+
*
|
|
288
|
+
* # Example
|
|
289
|
+
* ```ts
|
|
290
|
+
* const { vec3 } = snaptrude.core.math
|
|
291
|
+
*
|
|
292
|
+
* const { spaceIds } = await snaptrude.entity.space.bulkCreate({
|
|
293
|
+
* items: [
|
|
294
|
+
* {
|
|
295
|
+
* kind: "rectangular",
|
|
296
|
+
* position: vec3.new(0, 0, 0),
|
|
297
|
+
* dimensions: { width: 5, height: 3, depth: 4 },
|
|
298
|
+
* spaceType: "Room",
|
|
299
|
+
* departmentId: "CORE",
|
|
300
|
+
* },
|
|
301
|
+
* {
|
|
302
|
+
* kind: "profile",
|
|
303
|
+
* profile: await snaptrude.core.geom.profile.fromLinePoints({
|
|
304
|
+
* points: [vec3.new(0, 0, 0), vec3.new(8, 0, 0), vec3.new(8, 0, 6), vec3.new(0, 0, 6)],
|
|
305
|
+
* }),
|
|
306
|
+
* extrudeHeight: 3,
|
|
307
|
+
* position: vec3.new(10, 0, 0),
|
|
308
|
+
* massType: "Room",
|
|
309
|
+
* },
|
|
310
|
+
* ],
|
|
311
|
+
* })
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
public abstract bulkCreate(
|
|
315
|
+
args: PluginSpaceBulkCreateArgs,
|
|
316
|
+
): PluginApiReturn<PluginSpaceBulkCreateResult>
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Update many existing spaces in a single undoable operation.
|
|
320
|
+
*
|
|
321
|
+
* Each item targets an existing space by `spaceId` and may change its
|
|
322
|
+
* geometry (`profile` + `extrudeHeight`, which must be supplied together) and/or
|
|
323
|
+
* its `properties` (`room_type`, `massType`, `spaceType`, `departmentId` —
|
|
324
|
+
* nested under `properties`, mirroring {@linkcode PluginSpaceApi.update}). All
|
|
325
|
+
* changes are batched into **one** command, so the entire batch is
|
|
326
|
+
* undone/redone in a single step.
|
|
327
|
+
*
|
|
328
|
+
* All items are validated first; if any item is invalid — an unknown
|
|
329
|
+
* `spaceId`, a non-positive height, or supplying only one of
|
|
330
|
+
* `profile`/`extrudeHeight` — the call **throws** and no changes are applied.
|
|
331
|
+
*
|
|
332
|
+
* @param args - {@linkcode PluginSpaceBulkUpdateArgs} with an `items` array
|
|
333
|
+
* @returns A {@linkcode PluginSpaceBulkUpdateResult} echoing one
|
|
334
|
+
* {@linkcode PluginSpaceUpdateResult} per item in `spaces`, in input order
|
|
335
|
+
* @throws If any item targets an unknown space, has a non-positive height, or
|
|
336
|
+
* supplies only one of `profile`/`extrudeHeight`
|
|
337
|
+
*
|
|
338
|
+
* # Example
|
|
339
|
+
* ```ts
|
|
340
|
+
* const { spaces } = await snaptrude.entity.space.bulkUpdate({
|
|
341
|
+
* items: [
|
|
342
|
+
* { spaceId: "space-a", properties: { room_type: "Kitchen", spaceType: "Room" } },
|
|
343
|
+
* { spaceId: "space-b", profile, extrudeHeight: 4 },
|
|
344
|
+
* ],
|
|
345
|
+
* })
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
public abstract bulkUpdate(
|
|
349
|
+
args: PluginSpaceBulkUpdateArgs,
|
|
350
|
+
): PluginApiReturn<PluginSpaceBulkUpdateResult>
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Delete many spaces in a single undoable operation.
|
|
354
|
+
*
|
|
355
|
+
* All deletions are batched into **one** command, so the entire batch is
|
|
356
|
+
* undone/redone in a single step.
|
|
357
|
+
*
|
|
358
|
+
* All IDs are validated first; if any ID is unknown or is not a space the
|
|
359
|
+
* call **throws** and no spaces are deleted — consistent with the single-item
|
|
360
|
+
* {@linkcode PluginSpaceApi.delete}.
|
|
361
|
+
*
|
|
362
|
+
* @param args - {@linkcode PluginSpaceBulkDeleteArgs} with a `spaceIds` array
|
|
363
|
+
* @returns A {@linkcode PluginSpaceBulkDeleteResult} with `deletedSpaceIds`
|
|
364
|
+
* (the removed IDs, in input order)
|
|
365
|
+
* @throws If any ID does not resolve to an existing space
|
|
366
|
+
*
|
|
367
|
+
* # Example
|
|
368
|
+
* ```ts
|
|
369
|
+
* await snaptrude.entity.space.bulkDelete({ spaceIds: ["space-a", "space-b"] })
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
public abstract bulkDelete(
|
|
373
|
+
args: PluginSpaceBulkDeleteArgs,
|
|
374
|
+
): PluginApiReturn<PluginSpaceBulkDeleteResult>
|
|
269
375
|
}
|
|
270
376
|
|
|
271
377
|
/**
|
|
@@ -438,6 +544,8 @@ export const PluginSpaceGetProperty = z.enum([
|
|
|
438
544
|
// Derived from brep
|
|
439
545
|
"planPoints",
|
|
440
546
|
"profile",
|
|
547
|
+
// Derived from adjacency manager
|
|
548
|
+
"adjacency",
|
|
441
549
|
])
|
|
442
550
|
|
|
443
551
|
/**
|
|
@@ -518,6 +626,11 @@ export const PluginSpaceGetResult = z
|
|
|
518
626
|
// Derived from brep
|
|
519
627
|
planPoints: z.array(PVec3),
|
|
520
628
|
profile: PProfile,
|
|
629
|
+
// Derived from adjacency manager
|
|
630
|
+
adjacency: z.array(z.object({
|
|
631
|
+
spaceId: z.string(),
|
|
632
|
+
value: z.number(),
|
|
633
|
+
})),
|
|
521
634
|
})
|
|
522
635
|
.partial()
|
|
523
636
|
|
|
@@ -659,3 +772,167 @@ export const PluginSpaceUpdateResult = z.object({
|
|
|
659
772
|
})
|
|
660
773
|
|
|
661
774
|
export type PluginSpaceUpdateResult = z.infer<typeof PluginSpaceUpdateResult>
|
|
775
|
+
|
|
776
|
+
// ---------------------------------------------------------------------------
|
|
777
|
+
// Bulk operations
|
|
778
|
+
// ---------------------------------------------------------------------------
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* A single item for {@linkcode PluginSpaceApi.bulkCreate}.
|
|
782
|
+
*
|
|
783
|
+
* Discriminated on `kind`:
|
|
784
|
+
* - `"rectangular"` — a box defined by `position` + `dimensions` (mirrors
|
|
785
|
+
* {@linkcode PluginSpaceCreateRectangularArgs})
|
|
786
|
+
* - `"profile"` — an extruded `profile` (with optional `innerProfiles`) by
|
|
787
|
+
* `extrudeHeight` at `position` (mirrors {@linkcode PluginSpaceCreateFromProfileArgs})
|
|
788
|
+
*
|
|
789
|
+
* Every item may optionally set `room_type`, `spaceType`, `massType`, and
|
|
790
|
+
* `departmentId`; these are applied within the same single undo step as the
|
|
791
|
+
* creation.
|
|
792
|
+
*/
|
|
793
|
+
export const PluginSpaceBulkCreateItem = z.discriminatedUnion("kind", [
|
|
794
|
+
z.object({
|
|
795
|
+
kind: z.literal("rectangular"),
|
|
796
|
+
position: PVec3,
|
|
797
|
+
dimensions: z.object({
|
|
798
|
+
width: z.number(),
|
|
799
|
+
height: z.number(),
|
|
800
|
+
depth: z.number(),
|
|
801
|
+
}),
|
|
802
|
+
room_type: z.string().optional(),
|
|
803
|
+
spaceType: PluginSpaceType.optional(),
|
|
804
|
+
massType: PluginMassType.optional(),
|
|
805
|
+
departmentId: PluginDepartmentId.optional(),
|
|
806
|
+
}),
|
|
807
|
+
z.object({
|
|
808
|
+
kind: z.literal("profile"),
|
|
809
|
+
profile: PProfile,
|
|
810
|
+
innerProfiles: z.array(PProfile).optional(),
|
|
811
|
+
extrudeHeight: z.number(),
|
|
812
|
+
position: PVec3,
|
|
813
|
+
room_type: z.string().optional(),
|
|
814
|
+
spaceType: PluginSpaceType.optional(),
|
|
815
|
+
massType: PluginMassType.optional(),
|
|
816
|
+
departmentId: PluginDepartmentId.optional(),
|
|
817
|
+
}),
|
|
818
|
+
])
|
|
819
|
+
|
|
820
|
+
export type PluginSpaceBulkCreateItem = z.infer<typeof PluginSpaceBulkCreateItem>
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Arguments for {@linkcode PluginSpaceApi.bulkCreate}.
|
|
824
|
+
*
|
|
825
|
+
* | Property | Type | Description |
|
|
826
|
+
* |---|---|---|
|
|
827
|
+
* | `items` | {@linkcode PluginSpaceBulkCreateItem}`[]` | Spaces to create |
|
|
828
|
+
*/
|
|
829
|
+
export const PluginSpaceBulkCreateArgs = z.object({
|
|
830
|
+
items: z.array(PluginSpaceBulkCreateItem),
|
|
831
|
+
})
|
|
832
|
+
|
|
833
|
+
export type PluginSpaceBulkCreateArgs = z.infer<typeof PluginSpaceBulkCreateArgs>
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Result of {@linkcode PluginSpaceApi.bulkCreate}.
|
|
837
|
+
*
|
|
838
|
+
* | Property | Type | Description |
|
|
839
|
+
* |---|---|---|
|
|
840
|
+
* | `spaceIds` | `string[]` | IDs of the created spaces, in input order |
|
|
841
|
+
*/
|
|
842
|
+
export const PluginSpaceBulkCreateResult = z.object({
|
|
843
|
+
spaceIds: z.array(z.string()),
|
|
844
|
+
})
|
|
845
|
+
|
|
846
|
+
export type PluginSpaceBulkCreateResult = z.infer<
|
|
847
|
+
typeof PluginSpaceBulkCreateResult
|
|
848
|
+
>
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* A single item for {@linkcode PluginSpaceApi.bulkUpdate}.
|
|
852
|
+
*
|
|
853
|
+
* Targets an existing space by `spaceId`. Geometry fields `profile` and
|
|
854
|
+
* `extrudeHeight` must be supplied **together** (mirrors
|
|
855
|
+
* {@linkcode PluginSpaceUpdateGeometryFromProfileArgs}). Property changes are
|
|
856
|
+
* nested under `properties`, mirroring {@linkcode PluginSpaceUpdateArgs}.
|
|
857
|
+
*
|
|
858
|
+
* | Property | Type | Description |
|
|
859
|
+
* |---|---|---|
|
|
860
|
+
* | `spaceId` | `string` | The space to update |
|
|
861
|
+
* | `profile` | {@linkcode PProfile}`?` | New floor shape (requires `extrudeHeight`) |
|
|
862
|
+
* | `extrudeHeight` | `number?` | New extrusion height (requires `profile`) |
|
|
863
|
+
* | `properties` | `object?` | Property changes (same shape as {@linkcode PluginSpaceUpdateArgs.properties}) |
|
|
864
|
+
*/
|
|
865
|
+
export const PluginSpaceBulkUpdateItem = z.object({
|
|
866
|
+
spaceId: z.string(),
|
|
867
|
+
profile: PProfile.optional(),
|
|
868
|
+
extrudeHeight: z.number().optional(),
|
|
869
|
+
properties: z
|
|
870
|
+
.object({
|
|
871
|
+
room_type: z.string().optional(),
|
|
872
|
+
massType: PluginMassType.optional(),
|
|
873
|
+
spaceType: PluginSpaceType.optional(),
|
|
874
|
+
departmentId: PluginDepartmentId.optional(),
|
|
875
|
+
})
|
|
876
|
+
.optional(),
|
|
877
|
+
})
|
|
878
|
+
|
|
879
|
+
export type PluginSpaceBulkUpdateItem = z.infer<typeof PluginSpaceBulkUpdateItem>
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Arguments for {@linkcode PluginSpaceApi.bulkUpdate}.
|
|
883
|
+
*
|
|
884
|
+
* | Property | Type | Description |
|
|
885
|
+
* |---|---|---|
|
|
886
|
+
* | `items` | {@linkcode PluginSpaceBulkUpdateItem}`[]` | Spaces to update |
|
|
887
|
+
*/
|
|
888
|
+
export const PluginSpaceBulkUpdateArgs = z.object({
|
|
889
|
+
items: z.array(PluginSpaceBulkUpdateItem),
|
|
890
|
+
})
|
|
891
|
+
|
|
892
|
+
export type PluginSpaceBulkUpdateArgs = z.infer<typeof PluginSpaceBulkUpdateArgs>
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Result of {@linkcode PluginSpaceApi.bulkUpdate}.
|
|
896
|
+
*
|
|
897
|
+
* Echoes one {@linkcode PluginSpaceUpdateResult} per item, in input order —
|
|
898
|
+
* the same per-space shape returned by {@linkcode PluginSpaceApi.update}.
|
|
899
|
+
*
|
|
900
|
+
* | Property | Type | Description |
|
|
901
|
+
* |---|---|---|
|
|
902
|
+
* | `spaces` | {@linkcode PluginSpaceUpdateResult}`[]` | Per-item updated values, in input order |
|
|
903
|
+
*/
|
|
904
|
+
export const PluginSpaceBulkUpdateResult = z.object({
|
|
905
|
+
spaces: z.array(PluginSpaceUpdateResult),
|
|
906
|
+
})
|
|
907
|
+
|
|
908
|
+
export type PluginSpaceBulkUpdateResult = z.infer<
|
|
909
|
+
typeof PluginSpaceBulkUpdateResult
|
|
910
|
+
>
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Arguments for {@linkcode PluginSpaceApi.bulkDelete}.
|
|
914
|
+
*
|
|
915
|
+
* | Property | Type | Description |
|
|
916
|
+
* |---|---|---|
|
|
917
|
+
* | `spaceIds` | `string[]` | The space IDs to delete |
|
|
918
|
+
*/
|
|
919
|
+
export const PluginSpaceBulkDeleteArgs = z.object({
|
|
920
|
+
spaceIds: z.array(z.string()),
|
|
921
|
+
})
|
|
922
|
+
|
|
923
|
+
export type PluginSpaceBulkDeleteArgs = z.infer<typeof PluginSpaceBulkDeleteArgs>
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Result of {@linkcode PluginSpaceApi.bulkDelete}.
|
|
927
|
+
*
|
|
928
|
+
* | Property | Type | Description |
|
|
929
|
+
* |---|---|---|
|
|
930
|
+
* | `deletedSpaceIds` | `string[]` | The space IDs that were removed |
|
|
931
|
+
*/
|
|
932
|
+
export const PluginSpaceBulkDeleteResult = z.object({
|
|
933
|
+
deletedSpaceIds: z.array(z.string()),
|
|
934
|
+
})
|
|
935
|
+
|
|
936
|
+
export type PluginSpaceBulkDeleteResult = z.infer<
|
|
937
|
+
typeof PluginSpaceBulkDeleteResult
|
|
938
|
+
>
|