@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.
package/dist/index.mjs CHANGED
@@ -3983,7 +3983,11 @@ var WSClient = class {
3983
3983
  return null;
3984
3984
  }
3985
3985
  try {
3986
- const payloadRaw = this.decodeBase64Url(parts[1]);
3986
+ const payloadSegment = parts[1];
3987
+ if (!payloadSegment) {
3988
+ return null;
3989
+ }
3990
+ const payloadRaw = this.decodeBase64Url(payloadSegment);
3987
3991
  const payload = JSON.parse(payloadRaw);
3988
3992
  if (typeof payload.exp !== "number" || !Number.isFinite(payload.exp)) {
3989
3993
  return null;
@@ -5060,6 +5064,7 @@ import { ${allImports} } from "./sandbox-tools";
5060
5064
  this.eventListeners.set(event, []);
5061
5065
  }
5062
5066
  this.eventListeners.get(event).push(handler);
5067
+ return () => this.off(event, handler);
5063
5068
  }
5064
5069
  /**
5065
5070
  * Unsubscribe from session events
@@ -5516,6 +5521,16 @@ var JobImplementation = class {
5516
5521
  handler(message);
5517
5522
  }
5518
5523
  }
5524
+ return () => {
5525
+ const handlers = this.eventListeners.get(event);
5526
+ if (!handlers) {
5527
+ return;
5528
+ }
5529
+ this.eventListeners.set(
5530
+ event,
5531
+ handlers.filter((current) => current !== handler)
5532
+ );
5533
+ };
5519
5534
  }
5520
5535
  replayAgentMessage(message) {
5521
5536
  this.captureAgentMessage(message);
@@ -12062,7 +12077,9 @@ var Environment = class {
12062
12077
  }
12063
12078
  );
12064
12079
  if (result.errors?.length) {
12065
- throw new Error(`defineRelationship failed: ${result.errors[0].message}`);
12080
+ throw new Error(
12081
+ `defineRelationship failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`
12082
+ );
12066
12083
  }
12067
12084
  return result.data.at.define_relationship;
12068
12085
  }
@@ -12098,7 +12115,9 @@ var Environment = class {
12098
12115
  { path: modelPath }
12099
12116
  );
12100
12117
  if (result.errors?.length) {
12101
- throw new Error(`getRelationships failed: ${result.errors[0].message}`);
12118
+ throw new Error(
12119
+ `getRelationships failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`
12120
+ );
12102
12121
  }
12103
12122
  return result.data?.model?.relationships || [];
12104
12123
  }
@@ -12137,7 +12156,7 @@ var Environment = class {
12137
12156
  { target: targetPath }
12138
12157
  );
12139
12158
  if (result.errors?.length) {
12140
- throw new Error(`attach failed: ${result.errors[0].message}`);
12159
+ throw new Error(`attach failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`);
12141
12160
  }
12142
12161
  }
12143
12162
  /**
@@ -12172,7 +12191,7 @@ var Environment = class {
12172
12191
  }`
12173
12192
  );
12174
12193
  if (result.errors?.length) {
12175
- throw new Error(`detach failed: ${result.errors[0].message}`);
12194
+ throw new Error(`detach failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`);
12176
12195
  }
12177
12196
  }
12178
12197
  /**
@@ -12199,7 +12218,9 @@ var Environment = class {
12199
12218
  }`
12200
12219
  );
12201
12220
  if (result.errors?.length) {
12202
- throw new Error(`listRelated failed: ${result.errors[0].message}`);
12221
+ throw new Error(
12222
+ `listRelated failed: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`
12223
+ );
12203
12224
  }
12204
12225
  return result.data?.at?.at?.list_related || [];
12205
12226
  }
@@ -12292,7 +12313,7 @@ var Environment = class {
12292
12313
  async _runGraphql(query, label) {
12293
12314
  const result = await this.graphql(query);
12294
12315
  if (result.errors?.length) {
12295
- throw new Error(`${label}: ${result.errors[0].message}`);
12316
+ throw new Error(`${label}: ${result.errors[0]?.message ?? "Unknown GraphQL error"}`);
12296
12317
  }
12297
12318
  return result.data;
12298
12319
  }
@@ -12637,7 +12658,11 @@ var Environment = class {
12637
12658
  */
12638
12659
  async recordObject(options) {
12639
12660
  const results = await this.recordObjects([options]);
12640
- return results[0];
12661
+ const result = results[0];
12662
+ if (!result) {
12663
+ throw new Error("recordObject: no result returned for record");
12664
+ }
12665
+ return result;
12641
12666
  }
12642
12667
  /**
12643
12668
  * Batch version of `recordObject()`.
@@ -12689,7 +12714,13 @@ var Environment = class {
12689
12714
  );
12690
12715
  }
12691
12716
  for (let index = 0; index < items.length; index += 1) {
12692
- results[plan.offset + index] = items[index];
12717
+ const item = items[index];
12718
+ if (!item) {
12719
+ throw new Error(
12720
+ `recordObjects: chunk ${plan.chunkIndex + 1} returned an empty result at index ${index}`
12721
+ );
12722
+ }
12723
+ results[plan.offset + index] = item;
12693
12724
  }
12694
12725
  if (onChunk) {
12695
12726
  const info = {