@granular-software/sdk 0.4.31 → 0.4.32

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.
@@ -3985,7 +3985,11 @@ var WSClient = class {
3985
3985
  return null;
3986
3986
  }
3987
3987
  try {
3988
- const payloadRaw = this.decodeBase64Url(parts[1]);
3988
+ const payloadSegment = parts[1];
3989
+ if (!payloadSegment) {
3990
+ return null;
3991
+ }
3992
+ const payloadRaw = this.decodeBase64Url(payloadSegment);
3989
3993
  const payload = JSON.parse(payloadRaw);
3990
3994
  if (typeof payload.exp !== "number" || !Number.isFinite(payload.exp)) {
3991
3995
  return null;
@@ -5062,6 +5066,7 @@ import { ${allImports} } from "./sandbox-tools";
5062
5066
  this.eventListeners.set(event, []);
5063
5067
  }
5064
5068
  this.eventListeners.get(event).push(handler);
5069
+ return () => this.off(event, handler);
5065
5070
  }
5066
5071
  /**
5067
5072
  * Unsubscribe from session events
@@ -5518,6 +5523,16 @@ var JobImplementation = class {
5518
5523
  handler(message);
5519
5524
  }
5520
5525
  }
5526
+ return () => {
5527
+ const handlers = this.eventListeners.get(event);
5528
+ if (!handlers) {
5529
+ return;
5530
+ }
5531
+ this.eventListeners.set(
5532
+ event,
5533
+ handlers.filter((current) => current !== handler)
5534
+ );
5535
+ };
5521
5536
  }
5522
5537
  replayAgentMessage(message) {
5523
5538
  this.captureAgentMessage(message);
@@ -12064,7 +12079,9 @@ var Environment = class {
12064
12079
  }
12065
12080
  );
12066
12081
  if (result.errors?.length) {
12067
- throw new Error(`defineRelationship failed: ${result.errors[0].message}`);
12082
+ throw new Error(
12083
+ `defineRelationship failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`
12084
+ );
12068
12085
  }
12069
12086
  return result.data.at.define_relationship;
12070
12087
  }
@@ -12100,7 +12117,9 @@ var Environment = class {
12100
12117
  { path: modelPath }
12101
12118
  );
12102
12119
  if (result.errors?.length) {
12103
- throw new Error(`getRelationships failed: ${result.errors[0].message}`);
12120
+ throw new Error(
12121
+ `getRelationships failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`
12122
+ );
12104
12123
  }
12105
12124
  return result.data?.model?.relationships || [];
12106
12125
  }
@@ -12139,7 +12158,7 @@ var Environment = class {
12139
12158
  { target: targetPath }
12140
12159
  );
12141
12160
  if (result.errors?.length) {
12142
- throw new Error(`attach failed: ${result.errors[0].message}`);
12161
+ throw new Error(`attach failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`);
12143
12162
  }
12144
12163
  }
12145
12164
  /**
@@ -12174,7 +12193,7 @@ var Environment = class {
12174
12193
  }`
12175
12194
  );
12176
12195
  if (result.errors?.length) {
12177
- throw new Error(`detach failed: ${result.errors[0].message}`);
12196
+ throw new Error(`detach failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`);
12178
12197
  }
12179
12198
  }
12180
12199
  /**
@@ -12201,7 +12220,9 @@ var Environment = class {
12201
12220
  }`
12202
12221
  );
12203
12222
  if (result.errors?.length) {
12204
- throw new Error(`listRelated failed: ${result.errors[0].message}`);
12223
+ throw new Error(
12224
+ `listRelated failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`
12225
+ );
12205
12226
  }
12206
12227
  return result.data?.at?.at?.list_related || [];
12207
12228
  }
@@ -12294,7 +12315,7 @@ var Environment = class {
12294
12315
  async _runGraphql(query, label) {
12295
12316
  const result = await this.graphql(query);
12296
12317
  if (result.errors?.length) {
12297
- throw new Error(`${label}: ${result.errors[0].message}`);
12318
+ throw new Error(`${label}: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`);
12298
12319
  }
12299
12320
  return result.data;
12300
12321
  }
@@ -12639,7 +12660,11 @@ var Environment = class {
12639
12660
  */
12640
12661
  async recordObject(options) {
12641
12662
  const results = await this.recordObjects([options]);
12642
- return results[0];
12663
+ const result = results[0];
12664
+ if (!result) {
12665
+ throw new Error("recordObject: no result returned for record");
12666
+ }
12667
+ return result;
12643
12668
  }
12644
12669
  /**
12645
12670
  * Batch version of `recordObject()`.
@@ -12691,7 +12716,13 @@ var Environment = class {
12691
12716
  );
12692
12717
  }
12693
12718
  for (let index = 0; index < items.length; index += 1) {
12694
- results[plan.offset + index] = items[index];
12719
+ const item = items[index];
12720
+ if (!item) {
12721
+ throw new Error(
12722
+ `recordObjects: chunk ${plan.chunkIndex + 1} returned an empty result at index ${index}`
12723
+ );
12724
+ }
12725
+ results[plan.offset + index] = item;
12695
12726
  }
12696
12727
  if (onChunk) {
12697
12728
  const info = {