@archilogic/extension-sdk 0.2.4 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @archilogic/extension-sdk
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 52c9e56: feat(sdk): use space-graph-core query method types
8
+
9
+ ## 0.2.5
10
+
11
+ ### Patch Changes
12
+
13
+ - eddf6b6: fix: bump space-graph-core to fix custom attribute undo / redo
14
+
3
15
  ## 0.2.4
4
16
 
5
17
  ### Patch Changes
@@ -34,11 +34,11 @@ var Pe = class extends Error {
34
34
  f(this, B, Se);
35
35
  this.value = e, this.transferables = t == null ? void 0 : t.transferables;
36
36
  }
37
- }, B = new WeakMap(), ae), me = Ce, M = "penpal", W = (e) => typeof e == "object" && e !== null, de = (e) => typeof e == "function", Re = (e) => W(e) && e.namespace === M, j = (e) => e.type === "SYN", X = (e) => e.type === "ACK1", g = (e) => e.type === "ACK2", ce = (e) => e.type === "CALL", le = (e) => e.type === "REPLY", Ne = (e) => e.type === "DESTROY", ue = (e, t = []) => {
37
+ }, B = new WeakMap(), ae), me = Ce, M = "penpal", W = (e) => typeof e == "object" && e !== null, ce = (e) => typeof e == "function", Re = (e) => W(e) && e.namespace === M, j = (e) => e.type === "SYN", X = (e) => e.type === "ACK1", z = (e) => e.type === "ACK2", de = (e) => e.type === "CALL", le = (e) => e.type === "REPLY", Ne = (e) => e.type === "DESTROY", ue = (e, t = []) => {
38
38
  const r = [];
39
39
  for (const a of Object.keys(e)) {
40
40
  const n = e[a];
41
- de(n) ? r.push([...t, a]) : W(n) && r.push(
41
+ ce(n) ? r.push([...t, a]) : W(n) && r.push(
42
42
  ...ue(n, [...t, a])
43
43
  );
44
44
  }
@@ -48,7 +48,7 @@ var Pe = class extends Error {
48
48
  (a, n) => W(a) ? a[n] : void 0,
49
49
  t
50
50
  );
51
- return de(r) ? r : void 0;
51
+ return ce(r) ? r : void 0;
52
52
  }, C = (e) => e.join("."), ee = (e, t, r) => ({
53
53
  namespace: M,
54
54
  channel: e,
@@ -58,8 +58,8 @@ var Pe = class extends Error {
58
58
  ...r instanceof Error ? { value: Ie(r), isSerializedErrorInstance: !0 } : { value: r }
59
59
  }), Te = (e, t, r, a) => {
60
60
  let n = !1;
61
- const c = async (l) => {
62
- if (n || !ce(l))
61
+ const d = async (l) => {
62
+ if (n || !de(l))
63
63
  return;
64
64
  a == null || a(`Received ${C(l.methodPath)}() call`, l);
65
65
  const { methodPath: v, args: h, id: o } = l;
@@ -89,8 +89,8 @@ var Pe = class extends Error {
89
89
  throw u.name === "DataCloneError" && (i = ee(r, o, u), a == null || a(`Sending ${C(v)}() reply`, i), e.sendMessage(i)), u;
90
90
  }
91
91
  };
92
- return e.addMessageHandler(c), () => {
93
- n = !0, e.removeMessageHandler(c);
92
+ return e.addMessageHandler(d), () => {
93
+ n = !0, e.removeMessageHandler(d);
94
94
  };
95
95
  }, De = Te, se, he = ((se = crypto.randomUUID) == null ? void 0 : se.bind(crypto)) ?? (() => new Array(4).fill(0).map(
96
96
  () => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)
@@ -112,8 +112,8 @@ var Pe = class extends Error {
112
112
  if (n !== "then")
113
113
  return r.length && Oe.has(n) ? Reflect.get(a, n) : pe(e, t, [...r, n]);
114
114
  },
115
- apply(a, n, c) {
116
- return e(r, c);
115
+ apply(a, n, d) {
116
+ return e(r, d);
117
117
  }
118
118
  }
119
119
  ), te = (e) => new w(
@@ -123,7 +123,7 @@ var Pe = class extends Error {
123
123
  )}() failed due to destroyed connection`
124
124
  ), He = (e, t, r) => {
125
125
  let a = !1;
126
- const n = /* @__PURE__ */ new Map(), c = (h) => {
126
+ const n = /* @__PURE__ */ new Map(), d = (h) => {
127
127
  if (!le(h))
128
128
  return;
129
129
  const { callId: o, value: i, isError: E, isSerializedErrorInstance: u } = h, p = n.get(o);
@@ -134,13 +134,13 @@ var Pe = class extends Error {
134
134
  u ? Ae(i) : i
135
135
  ) : p.resolve(i));
136
136
  };
137
- return e.addMessageHandler(c), {
137
+ return e.addMessageHandler(d), {
138
138
  remoteProxy: pe((h, o) => {
139
139
  if (a)
140
140
  throw te(h);
141
- const i = he(), E = o[o.length - 1], u = E instanceof be, { timeout: p, transferables: K } = u ? E : {}, F = u ? o.slice(0, -1) : o;
141
+ const i = he(), E = o[o.length - 1], u = E instanceof be, { timeout: p, transferables: g } = u ? E : {}, F = u ? o.slice(0, -1) : o;
142
142
  return new Promise((Y, O) => {
143
- const z = p !== void 0 ? window.setTimeout(() => {
143
+ const K = p !== void 0 ? window.setTimeout(() => {
144
144
  n.delete(i), O(
145
145
  new w(
146
146
  "METHOD_CALL_TIMEOUT",
@@ -150,7 +150,7 @@ var Pe = class extends Error {
150
150
  )
151
151
  );
152
152
  }, p) : void 0;
153
- n.set(i, { methodPath: h, resolve: Y, reject: O, timeoutId: z });
153
+ n.set(i, { methodPath: h, resolve: Y, reject: O, timeoutId: K });
154
154
  try {
155
155
  const T = {
156
156
  namespace: M,
@@ -160,7 +160,7 @@ var Pe = class extends Error {
160
160
  methodPath: h,
161
161
  args: F
162
162
  };
163
- r == null || r(`Sending ${C(h)}() call`, T), e.sendMessage(T, K);
163
+ r == null || r(`Sending ${C(h)}() call`, T), e.sendMessage(T, g);
164
164
  } catch (T) {
165
165
  O(
166
166
  new w("TRANSMISSION_FAILED", T.message)
@@ -169,7 +169,7 @@ var Pe = class extends Error {
169
169
  });
170
170
  }, r),
171
171
  destroy: () => {
172
- a = !0, e.removeMessageHandler(c);
172
+ a = !0, e.removeMessageHandler(d);
173
173
  for (const { methodPath: h, reject: o, timeoutId: i } of n.values())
174
174
  clearTimeout(i), o(te(h));
175
175
  n.clear();
@@ -245,7 +245,7 @@ var Pe = class extends Error {
245
245
  penpal: "synAck",
246
246
  methodNames: e.methodPaths.map(re)
247
247
  };
248
- if (ce(e))
248
+ if (de(e))
249
249
  return {
250
250
  penpal: "call",
251
251
  // Actually converting the ID to a number would break communication.
@@ -271,14 +271,14 @@ var Pe = class extends Error {
271
271
  returnValue: e.value
272
272
  };
273
273
  throw fe(e);
274
- }, Ke = ({
274
+ }, ge = ({
275
275
  messenger: e,
276
276
  methods: t,
277
277
  timeout: r,
278
278
  channel: a,
279
279
  log: n
280
280
  }) => {
281
- const c = he();
281
+ const d = he();
282
282
  let l;
283
283
  const v = [];
284
284
  let h = !1;
@@ -289,34 +289,34 @@ var Pe = class extends Error {
289
289
  `Connection timed out after ${r}ms`
290
290
  )
291
291
  );
292
- }, r) : void 0, K = () => {
293
- for (const d of v)
294
- d();
292
+ }, r) : void 0, g = () => {
293
+ for (const c of v)
294
+ c();
295
295
  }, F = () => {
296
296
  if (h)
297
297
  return;
298
298
  v.push(De(e, t, a, n));
299
- const { remoteProxy: d, destroy: m } = xe(e, a, n);
299
+ const { remoteProxy: c, destroy: m } = xe(e, a, n);
300
300
  v.push(m), clearTimeout(p), h = !0, E({
301
- remoteProxy: d,
302
- destroy: K
301
+ remoteProxy: c,
302
+ destroy: g
303
303
  });
304
304
  }, Y = () => {
305
- const d = {
305
+ const c = {
306
306
  namespace: M,
307
307
  type: "SYN",
308
308
  channel: a,
309
- participantId: c
309
+ participantId: d
310
310
  };
311
- n == null || n("Sending handshake SYN", d);
311
+ n == null || n("Sending handshake SYN", c);
312
312
  try {
313
- e.sendMessage(d);
313
+ e.sendMessage(c);
314
314
  } catch (m) {
315
315
  u(new w("TRANSMISSION_FAILED", m.message));
316
316
  }
317
- }, O = (d) => {
318
- if (n == null || n("Received handshake SYN", d), d.participantId === l && // TODO: Used for backward-compatibility. Remove in next major version.
319
- l !== G || (l = d.participantId, Y(), !(c > l || // TODO: Used for backward-compatibility. Remove in next major version.
317
+ }, O = (c) => {
318
+ if (n == null || n("Received handshake SYN", c), c.participantId === l && // TODO: Used for backward-compatibility. Remove in next major version.
319
+ l !== G || (l = c.participantId, Y(), !(d > l || // TODO: Used for backward-compatibility. Remove in next major version.
320
320
  l === G)))
321
321
  return;
322
322
  const $ = {
@@ -332,8 +332,8 @@ var Pe = class extends Error {
332
332
  u(new w("TRANSMISSION_FAILED", Me.message));
333
333
  return;
334
334
  }
335
- }, z = (d) => {
336
- n == null || n("Received handshake ACK1", d);
335
+ }, K = (c) => {
336
+ n == null || n("Received handshake ACK1", c);
337
337
  const m = {
338
338
  namespace: M,
339
339
  channel: a,
@@ -347,16 +347,16 @@ var Pe = class extends Error {
347
347
  return;
348
348
  }
349
349
  F();
350
- }, T = (d) => {
351
- n == null || n("Received handshake ACK2", d), F();
352
- }, q = (d) => {
353
- j(d) && O(d), X(d) && z(d), g(d) && T(d);
350
+ }, T = (c) => {
351
+ n == null || n("Received handshake ACK2", c), F();
352
+ }, q = (c) => {
353
+ j(c) && O(c), X(c) && K(c), z(c) && T(c);
354
354
  };
355
355
  return e.addMessageHandler(q), v.push(() => e.removeMessageHandler(q)), Y(), i;
356
- }, ze = Ke, ge = (e) => {
356
+ }, Ke = ge, ze = (e) => {
357
357
  let t = !1, r;
358
358
  return (...a) => (t || (t = !0, r = e(...a)), r);
359
- }, Ge = ge, ne = /* @__PURE__ */ new WeakSet(), Be = ({
359
+ }, Ge = ze, ne = /* @__PURE__ */ new WeakSet(), Be = ({
360
360
  messenger: e,
361
361
  methods: t = {},
362
362
  timeout: r,
@@ -371,7 +371,7 @@ var Pe = class extends Error {
371
371
  "A messenger can only be used for a single connection"
372
372
  );
373
373
  ne.add(e);
374
- const c = [e.destroy], l = Ge((o) => {
374
+ const d = [e.destroy], l = Ge((o) => {
375
375
  if (o) {
376
376
  const i = {
377
377
  namespace: M,
@@ -383,7 +383,7 @@ var Pe = class extends Error {
383
383
  } catch {
384
384
  }
385
385
  }
386
- for (const i of c)
386
+ for (const i of d)
387
387
  i();
388
388
  n == null || n("Connection destroyed");
389
389
  }), v = (o) => Re(o) && o.channel === a;
@@ -393,14 +393,14 @@ var Pe = class extends Error {
393
393
  e.initialize({ log: n, validateReceivedMessage: v }), e.addMessageHandler((E) => {
394
394
  Ne(E) && l(!1);
395
395
  });
396
- const { remoteProxy: o, destroy: i } = await ze({
396
+ const { remoteProxy: o, destroy: i } = await Ke({
397
397
  messenger: e,
398
398
  methods: t,
399
399
  timeout: r,
400
400
  channel: a,
401
401
  log: n
402
402
  });
403
- return c.push(i), o;
403
+ return d.push(i), o;
404
404
  } catch (o) {
405
405
  throw l(!0), o;
406
406
  }
@@ -448,12 +448,12 @@ var Pe = class extends Error {
448
448
  });
449
449
  return;
450
450
  }
451
- if (g(e)) {
451
+ if (z(e)) {
452
452
  const { port1: r, port2: a } = new MessageChannel();
453
453
  I(this, y, r), r.addEventListener("message", s(this, b)), r.start();
454
- const n = [a, ...t || []], c = s(this, k).call(this, e);
454
+ const n = [a, ...t || []], d = s(this, k).call(this, e);
455
455
  s(this, A).postMessage(e, {
456
- targetOrigin: c,
456
+ targetOrigin: d,
457
457
  transfer: n
458
458
  });
459
459
  return;
@@ -495,11 +495,11 @@ var Pe = class extends Error {
495
495
  ports: r,
496
496
  data: a
497
497
  }) => {
498
- var n, c, l;
498
+ var n, d, l;
499
499
  if (e === s(this, A) && (je(a) && ((n = s(this, D)) == null || n.call(
500
500
  this,
501
501
  "Please upgrade the child window to the latest version of Penpal."
502
- ), I(this, _, !0), a = Ve(a)), !!((c = s(this, L)) != null && c.call(this, a)))) {
502
+ ), I(this, _, !0), a = Ve(a)), !!((d = s(this, L)) != null && d.call(this, a)))) {
503
503
  if (!s(this, V).call(this, t)) {
504
504
  (l = s(this, D)) == null || l.call(
505
505
  this,
@@ -507,7 +507,7 @@ var Pe = class extends Error {
507
507
  );
508
508
  return;
509
509
  }
510
- if (j(a) && (s(this, H).call(this), I(this, N, t)), g(a) && // Previous versions of Penpal don't use MessagePorts and do all
510
+ if (j(a) && (s(this, H).call(this), I(this, N, t)), z(a) && // Previous versions of Penpal don't use MessagePorts and do all
511
511
  // communication through the window.
512
512
  !s(this, _)) {
513
513
  if (I(this, y, r[0]), !s(this, y))
@@ -533,7 +533,11 @@ const Qe = (e, t) => {
533
533
  const r = new ye({
534
534
  remoteWindow: e.contentWindow,
535
535
  // Defaults to the current origin.
536
- allowedOrigins: [/^http:\/\/localhost(:\d+)/, "https://extensions.archilogic.io"]
536
+ allowedOrigins: [
537
+ /^http:\/\/localhost(:\d+)/,
538
+ "https://extensions.archilogic.io",
539
+ "https://testing-extensions.archilogic.io"
540
+ ]
537
541
  // Alternatively,
538
542
  // allowedOrigins: [new Url(iframe.src).origin]
539
543
  });
@@ -572,8 +576,8 @@ const Qe = (e, t) => {
572
576
  return new Proxy(
573
577
  {},
574
578
  {
575
- get(n, c) {
576
- return async (...l) => (await r.promise)[c](...l);
579
+ get(n, d) {
580
+ return async (...l) => (await r.promise)[d](...l);
577
581
  }
578
582
  }
579
583
  );
package/dist/index.d.ts CHANGED
@@ -74,7 +74,7 @@ declare interface BaseData {
74
74
  name: string;
75
75
  type: string;
76
76
  customId: string;
77
- customAttributes: Record<string, string | number | boolean>;
77
+ customAttributes: SpaceGraphCustomAttributeValue;
78
78
  /** dimensions in meters */
79
79
  dimensions: {
80
80
  width: number;
@@ -99,6 +99,34 @@ declare interface BaseData {
99
99
  boundingBoxContour: Vector2[];
100
100
  }
101
101
 
102
+ declare interface BaseFilter {
103
+ id?: StringComparator;
104
+ type?: StringComparator;
105
+ name?: StringComparator;
106
+ customId?: StringComparator;
107
+ customAttributes?: Record<string, StringComparator | NumberComparator | BooleanComparator>;
108
+ dimensions?: {
109
+ width?: NumberComparator;
110
+ length?: NumberComparator;
111
+ height?: NumberComparator;
112
+ };
113
+ }
114
+
115
+ declare interface BaseSelect {
116
+ id?: boolean;
117
+ type?: boolean;
118
+ name?: boolean;
119
+ customId?: boolean;
120
+ customAttributes?: boolean | Record<string, boolean>;
121
+ dimensions?: boolean | {
122
+ width?: boolean;
123
+ length?: boolean;
124
+ height?: boolean;
125
+ };
126
+ boundingBox?: boolean;
127
+ boundingBoxContour?: boolean;
128
+ }
129
+
102
130
  declare interface BaseShape {
103
131
  type: string;
104
132
  style?: ShapeStyle;
@@ -109,6 +137,12 @@ declare interface BezierCurve extends BaseShape {
109
137
  points: Polygon;
110
138
  }
111
139
 
140
+ declare type BooleanComparator = boolean | {
141
+ eq: boolean;
142
+ } | {
143
+ neq: boolean;
144
+ };
145
+
112
146
  declare type BoundingBox3d = {
113
147
  min: Vector3;
114
148
  max: Vector3;
@@ -354,6 +388,11 @@ declare type CustomStairsParametersJson = Partial<CustomStairsParameters>;
354
388
 
355
389
  declare type CustomStairsType = 'custom';
356
390
 
391
+ declare type DefaultSelect = {
392
+ id: true;
393
+ type: true;
394
+ };
395
+
357
396
  declare type DimensionParameters = {
358
397
  /** @minimum 0.01 */
359
398
  length: number;
@@ -552,7 +591,7 @@ declare class ElementCreate extends OperationBase {
552
591
  type: typeof ElementCreateTypeValue;
553
592
  value: LayoutElementJson;
554
593
  parentId?: string;
555
- constructor(value: LayoutElementJson, parentId?: string);
594
+ constructor(value: Partial<LayoutElementJson>, parentId?: string);
556
595
  do(layout: SpaceGraphLayout): void;
557
596
  undo(layout: SpaceGraphLayout): void;
558
597
  }
@@ -563,11 +602,24 @@ declare const ElementCreateTypeValue: "operation:elementCreate";
563
602
 
564
603
  export declare interface ElementData extends BaseData {
565
604
  type: LayoutElementJson['type'];
605
+ isExternal: boolean;
566
606
  parameters: LayoutElementJson['parameters'];
567
607
  product: ProductData;
608
+ position: Vector3;
609
+ rotation: number;
568
610
  elements: ElementData[];
569
611
  }
570
612
 
613
+ export declare interface ElementFilter extends BaseFilter {
614
+ product?: ProductFilter;
615
+ isExternal?: BooleanComparator;
616
+ }
617
+
618
+ declare type ElementQuery = {
619
+ select?: ElementSelect;
620
+ where?: ElementFilter;
621
+ };
622
+
571
623
  declare class ElementRemove extends OperationBase {
572
624
  type: typeof ElementRemoveTypeValue;
573
625
  previousValue: LayoutElementJson;
@@ -582,6 +634,13 @@ declare type ElementRemoveOperationJson = Pick<ElementRemove, 'nodeId' | 'type'>
582
634
 
583
635
  declare const ElementRemoveTypeValue: "operation:elementRemove";
584
636
 
637
+ export declare interface ElementSelect extends BaseSelect {
638
+ product?: ProductSelect | boolean;
639
+ isExternal?: boolean;
640
+ position?: boolean;
641
+ rotation?: boolean;
642
+ }
643
+
585
644
  declare class ElementUpdate extends OperationBase {
586
645
  type: typeof ElementUpdateTypeValue;
587
646
  value: ElementUpdateValue;
@@ -600,11 +659,9 @@ declare type ElementUpdateValue = Partial<LayoutElementJson> & {
600
659
  parameters?: Partial<LayoutElementJson['parameters']>;
601
660
  };
602
661
 
603
- declare interface EntityResponse extends HostResponse {
604
- data: {
605
- id: string;
606
- };
607
- }
662
+ declare type EntityResult = {
663
+ id: string;
664
+ };
608
665
 
609
666
  export declare type ExtensionApi = {
610
667
  onPluginConnect({ floorMetaData }: {
@@ -667,7 +724,7 @@ declare type FloorPlanTheme = {
667
724
  /** show the area information in room stamps */
668
725
  roomStampDisplay?: ('usage' | 'area' | 'customId' | 'name' | 'id' | ['customAttribute', string])[];
669
726
  /** text color for room stamps */
670
- text?: Rgb;
727
+ text?: Rgb_2;
671
728
  /** whether the room stamp text should have an outline to assist with contrast issues */
672
729
  textOutline?: boolean;
673
730
  };
@@ -909,189 +966,139 @@ declare type HingeSide = 'left' | 'right';
909
966
  export declare type HostApi = {
910
967
  /**
911
968
  * @example
912
- * const { data: element } = await hostApi.getElementsById({ id, include: ['name', 'type', 'dimensions']})
969
+ * const element = await hostApi.getElementsById({ id, select: { type: true, dimensions: { length: true }}})
913
970
  */
914
- getElementById: <K extends keyof ElementData>(args: {
971
+ getElementById: <S extends ElementSelect = DefaultSelect>(args: {
915
972
  id: string;
916
- include: K[];
917
- }) => Promise<{
918
- data?: Pick<ElementData, K>;
919
- error?: string;
920
- ok: boolean;
921
- }>;
922
- /**
923
- * @example
924
- * const { data: elements } = await hostApi.getElements({ include: ['id', 'name', 'type']})
925
- */
926
- getElements: <K extends keyof ElementData>(args: {
927
- include: K[];
928
- }) => Promise<{
929
- data: Pick<ElementData, K>[];
930
- error?: string;
931
- ok: boolean;
932
- }>;
973
+ select?: S;
974
+ }) => Promise<QueryPick<ElementData, S> | null>;
933
975
  /**
934
976
  * @example
935
- * const { data: elementsByType } = await hostApi.getElementsByType({ type, include: ['id', 'name', 'dimensions']})
977
+ * const elements = await hostApi.getElements({ where: { customAttributes: { broken: true }}})
936
978
  */
937
- getElementsByType: <K extends keyof ElementData>(args: {
938
- type: LayoutElementJson['type'];
939
- include: K[];
940
- }) => Promise<{
941
- data: Pick<ElementData, K>[];
942
- error?: string;
943
- ok: boolean;
944
- }>;
945
- getSpaceById: <K extends keyof SpaceData>(args: {
979
+ getElements: <S extends ElementSelect = DefaultSelect>(args?: {
980
+ select?: S;
981
+ where?: ElementFilter;
982
+ }) => Promise<QueryPick<ElementData, S>[]>;
983
+ getSpaceById: <S extends SpaceSelect = DefaultSelect>(args: {
946
984
  id: string;
947
- include: K[];
948
- }) => Promise<{
949
- data?: Pick<SpaceData, K>;
950
- error?: string;
951
- ok: boolean;
952
- }>;
953
- getSpaces: <K extends keyof SpaceData>(args: {
954
- include: K[];
955
- }) => Promise<{
956
- data: Pick<SpaceData, K>[];
957
- error?: string;
958
- ok: boolean;
959
- }>;
960
- getSpaceGraphJson: () => Promise<{
961
- data: SpaceGraphJson;
962
- error?: string;
963
- }>;
985
+ select?: S;
986
+ }) => Promise<QueryPick<SpaceData, S> | null>;
987
+ getSpaces: <S extends SpaceSelect = DefaultSelect>(args?: {
988
+ select?: S;
989
+ where?: SpaceFilter;
990
+ }) => Promise<QueryPick<SpaceData, S>[]>;
991
+ getProductById: <S extends ProductSelect = DefaultSelect>(args: {
992
+ id: string;
993
+ select?: S;
994
+ }) => Promise<QueryPick<ProductData, S> | null>;
995
+ getProducts: <S extends ProductSelect = DefaultSelect>(args?: {
996
+ select?: S;
997
+ where?: ProductFilter;
998
+ }) => Promise<QueryPick<ProductData, S>[]>;
964
999
  runOperations: (args: {
965
1000
  operations: OperationJson[];
966
- }) => Promise<HostResponse>;
1001
+ }) => Promise<OperationsResult>;
967
1002
  setPlanConfig: (config: {
968
1003
  theme: FloorPlanTheme;
969
- }) => Promise<HostResponse>;
1004
+ }) => Promise<boolean>;
970
1005
  addPlanLayer: (args: {
971
1006
  id?: string;
972
1007
  baseLayer?: string;
973
- }) => Promise<EntityResponse>;
1008
+ }) => Promise<EntityResult>;
974
1009
  addPlanGraphic: (args: {
975
1010
  shapes: Shape[];
976
1011
  isHandler?: boolean;
977
1012
  layerId?: string;
978
1013
  id?: string;
979
1014
  clearLayer?: boolean;
980
- }) => Promise<EntityResponse>;
1015
+ }) => Promise<EntityResult>;
981
1016
  zoomToNode: (args: {
982
1017
  nodeId: string;
983
1018
  margin?: number;
984
1019
  animate?: number | boolean;
985
- }) => Promise<HostResponse>;
1020
+ }) => Promise<boolean>;
986
1021
  zoomExtents: (args?: {
987
1022
  margin?: number;
988
1023
  animate?: number | boolean;
989
- }) => Promise<HostResponse>;
1024
+ }) => Promise<boolean>;
990
1025
  drawNodeUpdate: (args: {
991
1026
  nodeId: string;
992
1027
  style: 'selected' | ShapeStyle | false;
993
- }) => Promise<HostResponse>;
1028
+ }) => Promise<boolean>;
994
1029
  selectNodes: (args: {
995
1030
  nodeIds: string[];
996
- }) => Promise<SelectionResponse>;
1031
+ }) => Promise<NodeResult[]>;
997
1032
  };
998
1033
 
999
1034
  export declare type HostApiSync = {
1000
1035
  /**
1001
1036
  * @example
1002
- * const { data: element } = await hostApi.getElementsById({ id, include: ['name', 'type', 'dimensions']})
1037
+ * const element = await hostApi.getElementsById({ id, select: { type: true, dimensions: { length: true }}})
1003
1038
  */
1004
- getElementById: <K extends keyof ElementData>(args: {
1039
+ getElementById: <S extends ElementSelect = DefaultSelect>(args: {
1005
1040
  id: string;
1006
- include: K[];
1007
- }) => {
1008
- data?: Pick<ElementData, K>;
1009
- error?: string;
1010
- ok: boolean;
1011
- };
1041
+ select?: S;
1042
+ }) => QueryPick<ElementData, S> | null;
1012
1043
  /**
1013
1044
  * @example
1014
- * const { data: elements } = await hostApi.getElements({ include: ['id', 'name', 'type']})
1045
+ * const elements = await hostApi.getElements({ where: { customAttributes: { broken: true }}})
1015
1046
  */
1016
- getElements: <K extends keyof ElementData>(args: {
1017
- include: K[];
1018
- }) => {
1019
- data: Pick<ElementData, K>[];
1020
- error?: string;
1021
- ok: boolean;
1022
- };
1023
- /**
1024
- * @example
1025
- * const { data: elementsByType } = await hostApi.getElementsByType({ type, include: ['id', 'name', 'dimensions']})
1026
- */
1027
- getElementsByType: <K extends keyof ElementData>(args: {
1028
- type: LayoutElementJson['type'];
1029
- include: K[];
1030
- }) => {
1031
- data: Pick<ElementData, K>[];
1032
- error?: string;
1033
- ok: boolean;
1034
- };
1035
- getSpaceById: <K extends keyof SpaceData>(args: {
1047
+ getElements: <S extends ElementSelect = DefaultSelect>(args?: {
1048
+ select?: S;
1049
+ where?: ElementFilter;
1050
+ }) => QueryPick<ElementData, S>[];
1051
+ getSpaceById: <S extends SpaceSelect = DefaultSelect>(args: {
1036
1052
  id: string;
1037
- include: K[];
1038
- }) => {
1039
- data?: Pick<SpaceData, K>;
1040
- error?: string;
1041
- ok: boolean;
1042
- };
1043
- getSpaces: <K extends keyof SpaceData>(args: {
1044
- include: K[];
1045
- }) => {
1046
- data: Pick<SpaceData, K>[];
1047
- error?: string;
1048
- ok: boolean;
1049
- };
1050
- getSpaceGraphJson: () => {
1051
- data: SpaceGraphJson;
1052
- error?: string;
1053
- };
1053
+ select?: S;
1054
+ }) => QueryPick<SpaceData, S> | null;
1055
+ getSpaces: <S extends SpaceSelect = DefaultSelect>(args?: {
1056
+ select?: S;
1057
+ where?: SpaceFilter;
1058
+ }) => QueryPick<SpaceData, S>[];
1059
+ getProductById: <S extends ProductSelect = DefaultSelect>(args: {
1060
+ id: string;
1061
+ select?: S;
1062
+ }) => QueryPick<ProductData, S> | null;
1063
+ getProducts: <S extends ProductSelect = DefaultSelect>(args?: {
1064
+ select?: S;
1065
+ where?: ProductFilter;
1066
+ }) => QueryPick<ProductData, S>[];
1054
1067
  runOperations: (args: {
1055
1068
  operations: OperationJson[];
1056
- }) => HostResponse;
1069
+ }) => OperationsResult;
1057
1070
  setPlanConfig: (config: {
1058
1071
  theme: FloorPlanTheme;
1059
- }) => HostResponse;
1072
+ }) => boolean;
1060
1073
  addPlanLayer: (args: {
1061
1074
  id?: string;
1062
1075
  baseLayer?: string;
1063
- }) => EntityResponse;
1076
+ }) => EntityResult;
1064
1077
  addPlanGraphic: (args: {
1065
1078
  shapes: Shape[];
1066
1079
  isHandler?: boolean;
1067
1080
  layerId?: string;
1068
1081
  id?: string;
1069
1082
  clearLayer?: boolean;
1070
- }) => EntityResponse;
1083
+ }) => EntityResult;
1071
1084
  zoomToNode: (args: {
1072
1085
  nodeId: string;
1073
1086
  margin?: number;
1074
1087
  animate?: number | boolean;
1075
- }) => HostResponse;
1088
+ }) => boolean;
1076
1089
  zoomExtents: (args?: {
1077
1090
  margin?: number;
1078
1091
  animate?: number | boolean;
1079
- }) => HostResponse;
1092
+ }) => boolean;
1080
1093
  drawNodeUpdate: (args: {
1081
1094
  nodeId: string;
1082
1095
  style: 'selected' | ShapeStyle | false;
1083
- }) => HostResponse;
1096
+ }) => boolean;
1084
1097
  selectNodes: (args: {
1085
1098
  nodeIds: string[];
1086
- }) => SelectionResponse;
1099
+ }) => NodeResult[];
1087
1100
  };
1088
1101
 
1089
- export declare interface HostResponse {
1090
- ok: boolean;
1091
- data?: unknown;
1092
- error?: string;
1093
- }
1094
-
1095
1102
  declare type IndexRange = {
1096
1103
  type: 'index:range';
1097
1104
  start: number;
@@ -2281,17 +2288,33 @@ declare type Methods = {
2281
2288
  [index: string]: Methods | Function;
2282
2289
  };
2283
2290
 
2291
+ declare type NodeResult = {
2292
+ id: string;
2293
+ type: string;
2294
+ };
2295
+
2284
2296
  declare type NodesByType<NodeMap extends NodeTypeMap = {}> = {
2285
2297
  -readonly [K in keyof NodeMap]: InstanceType<NodeMap[K]>[];
2286
2298
  };
2287
2299
 
2288
- declare type NodeSelection = {
2289
- id: string;
2290
- type: string;
2291
- }[];
2292
-
2293
2300
  declare type NodeTypeMap = Record<string, any>;
2294
2301
 
2302
+ declare type NumberComparator = number | {
2303
+ eq: number;
2304
+ } | {
2305
+ neq: number;
2306
+ } | {
2307
+ in: number[];
2308
+ } | {
2309
+ gt: number;
2310
+ } | {
2311
+ gte: number;
2312
+ } | {
2313
+ lt: number;
2314
+ } | {
2315
+ lte: number;
2316
+ };
2317
+
2295
2318
  declare interface NumberList extends SpaceGraphTypedValueJson {
2296
2319
  type: 'number:list';
2297
2320
  list: number[];
@@ -2328,6 +2351,13 @@ declare class OperationBase {
2328
2351
  */
2329
2352
  declare type OperationJson = VertexCreateOperationJson | EdgeCreateOperationJson | SpaceCreateOperationJson | ElementCreateOperationJson | AnnotationCreateOperationJson | ViewCreateOperationJson | ProductCreateOperationJson | RelationCreateOperationJson | MaterialCreateOperationJson | CustomAttributeCreateOperationJson | VertexRemoveOperationJson | VertexUpdateOperationJson | VertexReplaceOperationJson | EdgeConnectOperationJson | EdgeRemoveOperationJson | EdgeReplaceOperationJson | EdgeMergeOperationJson | EdgeSplitOperationJson | EdgeUpdateOperationJson | SpaceUpdateOperationJson | SpaceRemoveOperationJson | ElementUpdateOperationJson | ElementRemoveOperationJson | AnnotationUpdateOperationJson | AnnotationRemoveOperationJson | ViewUpdateOperationJson | ViewRemoveOperationJson | ProductUpdateOperationJson | ProductRemoveOperationJson | RelationUpdateOperationJson | RelationRemoveOperationJson | RelationInsertNodesOperationJson | RelationRemoveNodesOperationJson | MaterialUpdateOperationJson | MaterialRemoveOperationJson | LayoutUpdateOperationJson | CustomAttributeUpdateOperationJson | CustomAttributeRemoveOperationJson;
2330
2353
 
2354
+ declare type OperationsResult = {
2355
+ created: NodeResult[];
2356
+ removed: NodeResult[];
2357
+ updated: NodeResult[];
2358
+ errors: string[];
2359
+ };
2360
+
2331
2361
  declare type OrthogonalStairsParameters = {
2332
2362
  stairsType: OrthogonalStairsType;
2333
2363
  /** @minimum 0.01 */
@@ -2455,10 +2485,13 @@ declare type ProductCreateValue = SpaceGraphProductJson;
2455
2485
 
2456
2486
  export declare interface ProductData extends BaseData {
2457
2487
  type: SpaceGraphProduct['type'];
2458
- attributes: {
2459
- category: string;
2460
- subCategory: string;
2461
- };
2488
+ category: string;
2489
+ subCategory: string;
2490
+ }
2491
+
2492
+ declare interface ProductFilter extends BaseFilter {
2493
+ category?: StringComparator;
2494
+ subCategory?: StringComparator;
2462
2495
  }
2463
2496
 
2464
2497
  declare class ProductRemove extends OperationBase {
@@ -2476,6 +2509,11 @@ declare const ProductRemoveTypeValue: "operation:productRemove";
2476
2509
 
2477
2510
  declare type ProductRemoveValue = SpaceGraphProductJson;
2478
2511
 
2512
+ declare interface ProductSelect extends BaseSelect {
2513
+ category?: boolean;
2514
+ subCategory?: boolean;
2515
+ }
2516
+
2479
2517
  declare class ProductUpdate extends OperationBase {
2480
2518
  type: typeof ProductUpdateTypeValue;
2481
2519
  value: ProductUpdateValue;
@@ -2491,6 +2529,10 @@ declare const ProductUpdateTypeValue: "operation:productUpdate";
2491
2529
 
2492
2530
  declare type ProductUpdateValue = Partial<SpaceGraphProductJson>;
2493
2531
 
2532
+ declare type QueryPick<T, S> = {
2533
+ [K in keyof S as S[K] extends false | undefined ? never : K]: K extends keyof T ? S[K] extends true ? T[K] : S[K] extends ElementQuery ? QueryPick<ElementData, S[K]['select'] extends undefined ? DefaultSelect : NonNullable<S[K]['select']>>[] : S[K] extends object ? T[K] extends any[] ? QueryPick<T[K][number], S[K]>[] : QueryPick<T[K], S[K]> : never : never;
2534
+ };
2535
+
2494
2536
  declare interface RectangleCurve extends CurveBase {
2495
2537
  type: RectangleCurveType;
2496
2538
  dimensions: Vector2;
@@ -2600,16 +2642,12 @@ declare class Reply<T = unknown> {
2600
2642
 
2601
2643
  declare type Rgb = [number, number, number];
2602
2644
 
2645
+ declare type Rgb_2 = [number, number, number];
2646
+
2603
2647
  declare type RgbA = [number, number, number, number];
2604
2648
 
2605
2649
  declare type RotationEntry = number | NumberList | NumberRange;
2606
2650
 
2607
- declare interface SelectionResponse extends HostResponse {
2608
- data: {
2609
- selectedNodes: NodeSelection;
2610
- };
2611
- }
2612
-
2613
2651
  declare type Shape = PolygonCurve_2 | PolygonWithHolesCurve_2 | PolylineCurve_2 | RectangleCurve_2 | CircleCurve_2 | LineCurve_2 | GroupShape | TextShape | ArcCurve_2 | BezierCurve | CompositeCurve_2;
2614
2652
 
2615
2653
  declare interface ShapeStyle {
@@ -2638,16 +2676,22 @@ declare type SpaceCreateValue = LayoutSpaceJson;
2638
2676
 
2639
2677
  export declare interface SpaceData extends BaseData {
2640
2678
  type: LayoutSpaceJson['type'];
2641
- attributes: {
2642
- category: string;
2643
- subCategory: string;
2644
- };
2679
+ isExternal: boolean;
2680
+ category: string;
2681
+ subCategory: string;
2645
2682
  area: number;
2646
2683
  labelPoint: Vector2;
2647
2684
  polygons: PolygonWithHoles;
2648
2685
  elements: ElementData[];
2649
2686
  }
2650
2687
 
2688
+ export declare interface SpaceFilter extends BaseFilter {
2689
+ category?: StringComparator;
2690
+ subCategory?: StringComparator;
2691
+ isExternal?: BooleanComparator;
2692
+ area?: NumberComparator;
2693
+ }
2694
+
2651
2695
  declare class SpaceGraph {
2652
2696
  spatialStructure: SpaceGraphSpatialStructure;
2653
2697
  products: SpaceGraphProduct[];
@@ -3142,6 +3186,7 @@ declare class SpaceGraphProductBase extends SpaceGraphNodeWithCustomAttributesBa
3142
3186
  constructor(id: string, type: SpaceGraphProductType);
3143
3187
  copyForClone(product: SpaceGraphProductStatic | SpaceGraphProductComponent): void;
3144
3188
  setAttributes(attributesJson: SpaceGraphProductAttributesJson): void;
3189
+ getBoundingBox(): BoundingBox3d;
3145
3190
  toJSON(): SpaceGraphProductJson;
3146
3191
  }
3147
3192
 
@@ -3271,6 +3316,16 @@ declare const SpaceRemoveTypeValue: "operation:spaceRemove";
3271
3316
 
3272
3317
  declare type SpaceRemoveValue = LayoutSpaceJson;
3273
3318
 
3319
+ export declare interface SpaceSelect extends BaseSelect {
3320
+ category?: boolean;
3321
+ subCategory?: boolean;
3322
+ isExternal?: boolean;
3323
+ area?: boolean;
3324
+ labelPoint?: boolean;
3325
+ polygons?: boolean;
3326
+ elements?: ElementQuery;
3327
+ }
3328
+
3274
3329
  declare interface SpaceShapeStyle extends ShapeStyle {
3275
3330
  usage?: {
3276
3331
  [key: string]: ShapeStyle;
@@ -3414,6 +3469,14 @@ declare type StraightStairsParametersJson = Partial<StraightStairsParameters>;
3414
3469
 
3415
3470
  declare type StraightStairsType = 'straight' | 'straightLanding';
3416
3471
 
3472
+ declare type StringComparator = string | {
3473
+ eq: string;
3474
+ } | {
3475
+ neq: string;
3476
+ } | {
3477
+ in: string[];
3478
+ };
3479
+
3417
3480
  declare interface SurfaceMaterials {
3418
3481
  [surface: string]: SpaceGraphMaterial;
3419
3482
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@archilogic/extension-sdk",
3
3
  "description": "",
4
- "version": "0.2.4",
4
+ "version": "0.3.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -32,7 +32,7 @@
32
32
  "penpal": "^7.0.4"
33
33
  },
34
34
  "devDependencies": {
35
- "@archilogic/space-graph-core": "^0.22.3"
35
+ "@archilogic/space-graph-core": "^0.23.0"
36
36
  },
37
37
  "nx": {}
38
38
  }