@web-ts-toolkit/access-router-client 0.28.0 → 0.29.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.
Files changed (3) hide show
  1. package/index.js +22 -4
  2. package/index.mjs +22 -4
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -451,6 +451,20 @@ var CustomHeaders = /* @__PURE__ */ ((CustomHeaders2) => {
451
451
  })(CustomHeaders || {});
452
452
 
453
453
  // src/services/shared.ts
454
+ var toResultError = (result) => ({
455
+ success: false,
456
+ raw: result.raw ?? null,
457
+ data: result.data ?? null,
458
+ message: result.message ?? "",
459
+ status: result.status ?? 0,
460
+ headers: result.headers ?? {}
461
+ });
462
+ var isLegacyListPayload = (value) => {
463
+ if (!value || typeof value !== "object") {
464
+ return false;
465
+ }
466
+ return "count" in value && typeof value.count === "number" && "rows" in value && Array.isArray(value.rows);
467
+ };
454
468
  var setDefaultObjectProp = (obj, key, value) => {
455
469
  if (!(0, import_utils4.get)(obj, key)) {
456
470
  (0, import_utils4.set)(obj, key, value);
@@ -466,7 +480,7 @@ var createResponseHandler = (onSuccess, onFailure, throwOnError) => {
466
480
  }
467
481
  failureHandler(res);
468
482
  if (shouldThrowOnError) {
469
- throw new ServiceError(res);
483
+ throw new ServiceError(toResultError(res));
470
484
  }
471
485
  return res;
472
486
  };
@@ -490,9 +504,13 @@ function processListResult(result, { includeCount, includeExtraHeaders }, wrapIt
490
504
  const totalCount = (0, import_utils4.get)(result, `headers.${"wtt-total-count" /* TotalCount */}`, 0);
491
505
  result.totalCount = Number(totalCount);
492
506
  } else {
493
- const listData = result.raw;
494
- result.totalCount = listData.count;
495
- result.raw = listData.rows;
507
+ if (isLegacyListPayload(result.raw)) {
508
+ result.totalCount = result.raw.count;
509
+ result.raw = result.raw.rows;
510
+ } else {
511
+ result.totalCount = 0;
512
+ result.raw = [];
513
+ }
496
514
  }
497
515
  }
498
516
  result.data = wrapItem ? result.raw.map(wrapItem) : result.raw;
package/index.mjs CHANGED
@@ -407,6 +407,20 @@ var CustomHeaders = /* @__PURE__ */ ((CustomHeaders2) => {
407
407
  })(CustomHeaders || {});
408
408
 
409
409
  // src/services/shared.ts
410
+ var toResultError = (result) => ({
411
+ success: false,
412
+ raw: result.raw ?? null,
413
+ data: result.data ?? null,
414
+ message: result.message ?? "",
415
+ status: result.status ?? 0,
416
+ headers: result.headers ?? {}
417
+ });
418
+ var isLegacyListPayload = (value) => {
419
+ if (!value || typeof value !== "object") {
420
+ return false;
421
+ }
422
+ return "count" in value && typeof value.count === "number" && "rows" in value && Array.isArray(value.rows);
423
+ };
410
424
  var setDefaultObjectProp = (obj, key, value) => {
411
425
  if (!get(obj, key)) {
412
426
  set2(obj, key, value);
@@ -422,7 +436,7 @@ var createResponseHandler = (onSuccess, onFailure, throwOnError) => {
422
436
  }
423
437
  failureHandler(res);
424
438
  if (shouldThrowOnError) {
425
- throw new ServiceError(res);
439
+ throw new ServiceError(toResultError(res));
426
440
  }
427
441
  return res;
428
442
  };
@@ -446,9 +460,13 @@ function processListResult(result, { includeCount, includeExtraHeaders }, wrapIt
446
460
  const totalCount = get(result, `headers.${"wtt-total-count" /* TotalCount */}`, 0);
447
461
  result.totalCount = Number(totalCount);
448
462
  } else {
449
- const listData = result.raw;
450
- result.totalCount = listData.count;
451
- result.raw = listData.rows;
463
+ if (isLegacyListPayload(result.raw)) {
464
+ result.totalCount = result.raw.count;
465
+ result.raw = result.raw.rows;
466
+ } else {
467
+ result.totalCount = 0;
468
+ result.raw = [];
469
+ }
452
470
  }
453
471
  }
454
472
  result.data = wrapItem ? result.raw.map(wrapItem) : result.raw;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@web-ts-toolkit/access-router-client",
3
3
  "description": "Typed client utilities for @web-ts-toolkit/access-router APIs",
4
4
  "homepage": "https://web-ts-toolkit.pages.dev/docs/packages/access-router-client",
5
- "version": "0.28.0",
5
+ "version": "0.29.0",
6
6
  "sideEffects": false,
7
7
  "keywords": [
8
8
  "axios",
@@ -26,7 +26,7 @@
26
26
  "node": ">=20"
27
27
  },
28
28
  "dependencies": {
29
- "@web-ts-toolkit/utils": "0.28.0",
29
+ "@web-ts-toolkit/utils": "0.29.0",
30
30
  "axios": "^1.18.1"
31
31
  },
32
32
  "files": [