@web-ts-toolkit/access-router-client 0.28.0 → 0.30.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 +29 -10
  2. package/index.mjs +35 -8
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -44,7 +44,7 @@ module.exports = __toCommonJS(index_exports);
44
44
 
45
45
  // src/adapter.ts
46
46
  var import_axios8 = __toESM(require("axios"));
47
- var import_utils6 = require("@web-ts-toolkit/utils");
47
+ var import_utils7 = require("@web-ts-toolkit/utils");
48
48
 
49
49
  // src/services/model-service.ts
50
50
  var import_axios4 = require("axios");
@@ -133,7 +133,7 @@ var Model = class _Model {
133
133
  const currentKeys = Object.keys(this._data);
134
134
  for (let x = 0; x < currentKeys.length; x++) {
135
135
  const key = currentKeys[x];
136
- if (!Object.prototype.hasOwnProperty.call(nextData, key)) {
136
+ if (!(0, import_utils.hasOwn)(nextData, key)) {
137
137
  delete this._data[key];
138
138
  }
139
139
  }
@@ -189,7 +189,7 @@ var Model = class _Model {
189
189
  if (key in this) continue;
190
190
  Object.defineProperty(this, key, {
191
191
  enumerable: true,
192
- get: () => Object.prototype.hasOwnProperty.call(this._data, key) ? this._data[key] : null,
192
+ get: () => (0, import_utils.hasOwn)(this._data, key) ? this._data[key] : null,
193
193
  set: (value) => this._data[key] = value
194
194
  });
195
195
  }
@@ -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;
@@ -1615,6 +1633,7 @@ var import_axios7 = require("axios");
1615
1633
 
1616
1634
  // src/services/cache-utils.ts
1617
1635
  var import_axios6 = require("axios");
1636
+ var import_utils6 = require("@web-ts-toolkit/utils");
1618
1637
  var normalizeConfigValue = (value) => {
1619
1638
  if (value == null) return value;
1620
1639
  if (value instanceof import_axios6.AxiosHeaders) {
@@ -1624,7 +1643,7 @@ var normalizeConfigValue = (value) => {
1624
1643
  return value.map((item) => normalizeConfigValue(item));
1625
1644
  }
1626
1645
  if (typeof value === "object") {
1627
- return Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).reduce((acc, [key, item]) => {
1646
+ return Object.entries((0, import_utils6.omitBy)(value, (item) => item === void 0)).sort(([left], [right]) => left.localeCompare(right)).reduce((acc, [key, item]) => {
1628
1647
  acc[key] = normalizeConfigValue(item);
1629
1648
  return acc;
1630
1649
  }, {});
@@ -1832,7 +1851,7 @@ function createAdapter(axiosConfig, adapterOptions) {
1832
1851
  let sharedConfig;
1833
1852
  let sharedConfigKey;
1834
1853
  const defs = proms.map((prom, index) => {
1835
- if (!(0, import_utils6.isEmpty)(prom.__requestConfig)) {
1854
+ if (!(0, import_utils7.isEmpty)(prom.__requestConfig)) {
1836
1855
  const configKey = serializeRequestConfig(prom.__requestConfig);
1837
1856
  if (sharedConfigKey && sharedConfigKey !== configKey) {
1838
1857
  throw new Error("Grouped requests must share the same axios request config");
@@ -1863,7 +1882,7 @@ function createAdapter(axiosConfig, adapterOptions) {
1863
1882
  _raw = result2.data[0];
1864
1883
  _data = Model.create(result2.data[0], modelService);
1865
1884
  } else if (!["distinct", "subList"].includes(op)) {
1866
- _data = (0, import_utils6.castArray)(result2.data).map((item) => Model.create(item, modelService));
1885
+ _data = (0, import_utils7.castArray)(result2.data).map((item) => Model.create(item, modelService));
1867
1886
  }
1868
1887
  } else if (result2.kind === "single" && ["new", "read", "update", "upsert"].includes(op)) {
1869
1888
  _data = Model.create(result2.data, modelService);
package/index.mjs CHANGED
@@ -7,7 +7,15 @@ import { mergeConfig as mergeConfig3 } from "axios";
7
7
  import { set as set3 } from "@web-ts-toolkit/utils";
8
8
 
9
9
  // src/model.ts
10
- import { assign as assignObject, cloneDeep, get as getValue, omit, pick, set as setValue } from "@web-ts-toolkit/utils";
10
+ import {
11
+ assign as assignObject,
12
+ cloneDeep,
13
+ get as getValue,
14
+ hasOwn,
15
+ omit,
16
+ pick,
17
+ set as setValue
18
+ } from "@web-ts-toolkit/utils";
11
19
  var Model = class _Model {
12
20
  constructor(data, adapter) {
13
21
  this.modifiedPaths = /* @__PURE__ */ new Set();
@@ -89,7 +97,7 @@ var Model = class _Model {
89
97
  const currentKeys = Object.keys(this._data);
90
98
  for (let x = 0; x < currentKeys.length; x++) {
91
99
  const key = currentKeys[x];
92
- if (!Object.prototype.hasOwnProperty.call(nextData, key)) {
100
+ if (!hasOwn(nextData, key)) {
93
101
  delete this._data[key];
94
102
  }
95
103
  }
@@ -145,7 +153,7 @@ var Model = class _Model {
145
153
  if (key in this) continue;
146
154
  Object.defineProperty(this, key, {
147
155
  enumerable: true,
148
- get: () => Object.prototype.hasOwnProperty.call(this._data, key) ? this._data[key] : null,
156
+ get: () => hasOwn(this._data, key) ? this._data[key] : null,
149
157
  set: (value) => this._data[key] = value
150
158
  });
151
159
  }
@@ -407,6 +415,20 @@ var CustomHeaders = /* @__PURE__ */ ((CustomHeaders2) => {
407
415
  })(CustomHeaders || {});
408
416
 
409
417
  // src/services/shared.ts
418
+ var toResultError = (result) => ({
419
+ success: false,
420
+ raw: result.raw ?? null,
421
+ data: result.data ?? null,
422
+ message: result.message ?? "",
423
+ status: result.status ?? 0,
424
+ headers: result.headers ?? {}
425
+ });
426
+ var isLegacyListPayload = (value) => {
427
+ if (!value || typeof value !== "object") {
428
+ return false;
429
+ }
430
+ return "count" in value && typeof value.count === "number" && "rows" in value && Array.isArray(value.rows);
431
+ };
410
432
  var setDefaultObjectProp = (obj, key, value) => {
411
433
  if (!get(obj, key)) {
412
434
  set2(obj, key, value);
@@ -422,7 +444,7 @@ var createResponseHandler = (onSuccess, onFailure, throwOnError) => {
422
444
  }
423
445
  failureHandler(res);
424
446
  if (shouldThrowOnError) {
425
- throw new ServiceError(res);
447
+ throw new ServiceError(toResultError(res));
426
448
  }
427
449
  return res;
428
450
  };
@@ -446,9 +468,13 @@ function processListResult(result, { includeCount, includeExtraHeaders }, wrapIt
446
468
  const totalCount = get(result, `headers.${"wtt-total-count" /* TotalCount */}`, 0);
447
469
  result.totalCount = Number(totalCount);
448
470
  } else {
449
- const listData = result.raw;
450
- result.totalCount = listData.count;
451
- result.raw = listData.rows;
471
+ if (isLegacyListPayload(result.raw)) {
472
+ result.totalCount = result.raw.count;
473
+ result.raw = result.raw.rows;
474
+ } else {
475
+ result.totalCount = 0;
476
+ result.raw = [];
477
+ }
452
478
  }
453
479
  }
454
480
  result.data = wrapItem ? result.raw.map(wrapItem) : result.raw;
@@ -1571,6 +1597,7 @@ import { AxiosHeaders as AxiosHeaders3 } from "axios";
1571
1597
 
1572
1598
  // src/services/cache-utils.ts
1573
1599
  import { AxiosHeaders as AxiosHeaders2 } from "axios";
1600
+ import { omitBy } from "@web-ts-toolkit/utils";
1574
1601
  var normalizeConfigValue = (value) => {
1575
1602
  if (value == null) return value;
1576
1603
  if (value instanceof AxiosHeaders2) {
@@ -1580,7 +1607,7 @@ var normalizeConfigValue = (value) => {
1580
1607
  return value.map((item) => normalizeConfigValue(item));
1581
1608
  }
1582
1609
  if (typeof value === "object") {
1583
- return Object.entries(value).filter(([, item]) => item !== void 0).sort(([left], [right]) => left.localeCompare(right)).reduce((acc, [key, item]) => {
1610
+ return Object.entries(omitBy(value, (item) => item === void 0)).sort(([left], [right]) => left.localeCompare(right)).reduce((acc, [key, item]) => {
1584
1611
  acc[key] = normalizeConfigValue(item);
1585
1612
  return acc;
1586
1613
  }, {});
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.30.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.30.0",
30
30
  "axios": "^1.18.1"
31
31
  },
32
32
  "files": [