@warmhub/sdk-ts 0.61.0 → 0.62.1

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.
@@ -8311,6 +8311,14 @@ function resolveRetryPolicy(retry) {
8311
8311
  };
8312
8312
  }
8313
8313
  var DEFINITE_CLIENT_REJECT_CODES = /* @__PURE__ */ new Set([
8314
+ "BAD_REQUEST",
8315
+ "METHOD_NOT_SUPPORTED",
8316
+ "PARSE_ERROR",
8317
+ "PAYLOAD_TOO_LARGE",
8318
+ "PRECONDITION_FAILED",
8319
+ "UNAUTHORIZED",
8320
+ "UNPROCESSABLE_CONTENT",
8321
+ "UNSUPPORTED_MEDIA_TYPE",
8314
8322
  "UNAUTHENTICATED",
8315
8323
  "FORBIDDEN",
8316
8324
  "VALIDATION_ERROR",
@@ -8327,6 +8335,7 @@ var DEFINITE_CLIENT_REJECT_CODES = /* @__PURE__ */ new Set([
8327
8335
  // first-chunk wrapper would discard structured retry/validation detail
8328
8336
  // (retryAfter, the failing token, etc.).
8329
8337
  "RATE_LIMITED",
8338
+ "TOO_MANY_REQUESTS",
8330
8339
  "UNRESOLVED_TOKEN"
8331
8340
  ]);
8332
8341
  function extractErrorCode(cause) {
@@ -8340,9 +8349,21 @@ function extractErrorCode(cause) {
8340
8349
  if (typeof dc === "string") return dc;
8341
8350
  return void 0;
8342
8351
  }
8352
+ function extractHttpStatus(cause) {
8353
+ if (!cause || typeof cause !== "object") return void 0;
8354
+ const status = cause.data?.httpStatus;
8355
+ if (typeof status === "number") return status;
8356
+ const warmhubStatus = cause.data?.warmhub?.status;
8357
+ if (typeof warmhubStatus === "number") return warmhubStatus;
8358
+ const direct = cause.status;
8359
+ return typeof direct === "number" ? direct : void 0;
8360
+ }
8361
+ function isDefiniteClientRejectionStatus(status) {
8362
+ return status !== void 0 && status >= 400 && status < 500 && status !== 408;
8363
+ }
8343
8364
  function isDefiniteClientError(cause) {
8344
8365
  const code = extractErrorCode(cause);
8345
- return code !== void 0 && DEFINITE_CLIENT_REJECT_CODES.has(code);
8366
+ return code !== void 0 && DEFINITE_CLIENT_REJECT_CODES.has(code) || isDefiniteClientRejectionStatus(extractHttpStatus(cause));
8346
8367
  }
8347
8368
  function isTransientStreamFailure(cause) {
8348
8369
  if (isDefiniteClientError(cause)) return false;
@@ -8979,7 +9000,7 @@ var OperationBuilder = class {
8979
9000
  * Set `kind: 'thing'` explicitly for hierarchical thing names that would otherwise look like assertion paths.
8980
9001
  */
8981
9002
  add(op) {
8982
- this.assertNotSubmitted();
9003
+ this.assertCanModify();
8983
9004
  const normalized = { ...op };
8984
9005
  delete normalized.operation;
8985
9006
  const shapeWref = inferShapeForAdd(normalized);
@@ -9025,7 +9046,7 @@ var OperationBuilder = class {
9025
9046
  * The target can be supplied as `name` or `wref`. When shape definitions were provided to the constructor, revise data is validated locally before the operation is queued.
9026
9047
  */
9027
9048
  revise(op) {
9028
- this.assertNotSubmitted();
9049
+ this.assertCanModify();
9029
9050
  const normalized = { ...op };
9030
9051
  delete normalized.operation;
9031
9052
  const target = normalized.name ?? normalized.wref;
@@ -9066,7 +9087,7 @@ var OperationBuilder = class {
9066
9087
  * Pass a wref string shorthand or an object with a target name, optional kind safety hint, and optional reason.
9067
9088
  */
9068
9089
  retract(target) {
9069
- this.assertNotSubmitted();
9090
+ this.assertCanModify();
9070
9091
  const op = typeof target === "string" ? Object.freeze({ operation: "retract", name: target }) : Object.freeze({
9071
9092
  operation: "retract",
9072
9093
  name: target.name,
@@ -9083,7 +9104,7 @@ var OperationBuilder = class {
9083
9104
  * The returned array is read-only; use `add`, `revise`, and `retract` to modify the builder.
9084
9105
  */
9085
9106
  get operations() {
9086
- return this.ops;
9107
+ return Object.freeze([...this.ops]);
9087
9108
  }
9088
9109
  /**
9089
9110
  * Return the number of queued operations.
@@ -9268,6 +9289,14 @@ var OperationBuilder = class {
9268
9289
  throw new Error("OperationBuilder: already submitted, cannot modify");
9269
9290
  }
9270
9291
  }
9292
+ assertCanModify() {
9293
+ this.assertNotSubmitted();
9294
+ if (this.inFlight) {
9295
+ throw new Error(
9296
+ "OperationBuilder: stream submission already in flight, cannot modify"
9297
+ );
9298
+ }
9299
+ }
9271
9300
  };
9272
9301
 
9273
9302
  // src/index.ts
@@ -9298,7 +9327,7 @@ function validateWarmHubClientOptions(options) {
9298
9327
  throw new TypeError(`Unknown WarmHubClient option "${key}"${hint}`);
9299
9328
  }
9300
9329
  }
9301
- var SDK_VERSION = "0.61.0" ;
9330
+ var SDK_VERSION = "0.62.1" ;
9302
9331
  var DEFAULT_API_URL = "https://api.warmhub.ai";
9303
9332
  var UNBATCHED_TRPC_PATHS = /* @__PURE__ */ new Set([
9304
9333
  "repo.shapeInstanceCounts",
@@ -9420,6 +9449,42 @@ function sanitizeSubscriptionUpdateInput(input) {
9420
9449
  function resolveFunctionLogMode(mode) {
9421
9450
  return mode ?? "off";
9422
9451
  }
9452
+ function trpcClientCodeToWarmHubCode(code) {
9453
+ switch (code) {
9454
+ case "BAD_REQUEST":
9455
+ case "PARSE_ERROR":
9456
+ case "PAYLOAD_TOO_LARGE":
9457
+ case "UNPROCESSABLE_CONTENT":
9458
+ case "UNSUPPORTED_MEDIA_TYPE":
9459
+ return "VALIDATION_ERROR";
9460
+ case "METHOD_NOT_SUPPORTED":
9461
+ return "NOT_FOUND";
9462
+ case "UNAUTHORIZED":
9463
+ return "UNAUTHENTICATED";
9464
+ case "FORBIDDEN":
9465
+ return "FORBIDDEN";
9466
+ case "NOT_FOUND":
9467
+ return "NOT_FOUND";
9468
+ case "CONFLICT":
9469
+ return "CONFLICT";
9470
+ case "PRECONDITION_FAILED":
9471
+ return "PRECONDITION_FAILED";
9472
+ case "TOO_MANY_REQUESTS":
9473
+ return "RATE_LIMITED";
9474
+ default:
9475
+ return void 0;
9476
+ }
9477
+ }
9478
+ function trpcHttpStatusToWarmHubCode(status) {
9479
+ if (status === void 0 || status === 408) return void 0;
9480
+ if (status === 405) return "NOT_FOUND";
9481
+ if (status === 412) return "PRECONDITION_FAILED";
9482
+ if (status === 422) return "VALIDATION_ERROR";
9483
+ const mapped = httpStatusToWarmHubCode(status);
9484
+ if (mapped !== "BACKEND") return mapped;
9485
+ if (status >= 400 && status < 500) return "VALIDATION_ERROR";
9486
+ return mapped;
9487
+ }
9423
9488
  var INTERNAL_PATTERNS = [
9424
9489
  /\bselect\b.+?\bfrom\b/i,
9425
9490
  /\binsert\b.+?\binto\b/i,
@@ -9511,13 +9576,15 @@ function toWarmHubError(error) {
9511
9576
  }
9512
9577
  const data = error.data;
9513
9578
  const wireCode = data?.warmhub?.code;
9579
+ const trpcCode = typeof data?.code === "string" ? trpcClientCodeToWarmHubCode(data.code) : void 0;
9580
+ const trpcStatus = trpcHttpStatusToWarmHubCode(data?.httpStatus);
9514
9581
  const message = data?.warmhub?.message ?? sanitizeErrorMessage(error.message);
9515
9582
  return new WarmHubError(
9516
- wireCode ?? "BACKEND",
9583
+ wireCode ?? trpcCode ?? trpcStatus ?? "BACKEND",
9517
9584
  message,
9518
- data?.warmhub?.status,
9585
+ data?.warmhub?.status ?? data?.httpStatus,
9519
9586
  data?.warmhub?.hint,
9520
- data?.warmhub?.retryAfter,
9587
+ data?.warmhub?.retryAfter ?? data?.retryAfter,
9521
9588
  wireCode,
9522
9589
  data?.warmhub?.details
9523
9590
  );
@@ -12515,5 +12582,5 @@ re2js/build/index.js:
12515
12582
  */
12516
12583
 
12517
12584
  export { AllStreamOperationsFailedError, CLI_INSTALL_REPO_HEADER, CLI_SIGNATURE_HEADER, CLI_TIMESTAMP_HEADER, CONTENT_FIELD_LIMIT_ERROR, CliCallVerificationError, DEFAULT_API_URL, DEFAULT_STREAM_CHUNK_SIZE, MAX_CONTENT_FIELD_BYTES, MAX_STREAM_APPEND_OPERATION_COUNT2 as MAX_STREAM_APPEND_OPERATION_COUNT, OperationBuilder, PartialStreamSubmissionError, SDK_VERSION, WarmHubClient, WarmHubError, connectionErrorMessage, contentFieldLimitError, countStreamAppendResultStatuses, isConnectionError, isRetryable, isWarmHubError, normalizeWref, resolveFunctionLogMode, sanitizeErrorMessage, sdkVersionIsBelowMinimum, streamAppendResultStatus, submitOperationsViaStream, toWarmHubError, validateAgainstShape, verifyCliCall };
12518
- //# sourceMappingURL=chunk-QS6ABKPJ.js.map
12519
- //# sourceMappingURL=chunk-QS6ABKPJ.js.map
12585
+ //# sourceMappingURL=chunk-XMQSHDUV.js.map
12586
+ //# sourceMappingURL=chunk-XMQSHDUV.js.map