getta 1.0.16 → 1.0.17

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "getta",
3
3
  "description": "An isomorphic rest client based on the Fetch API.",
4
- "version": "1.0.16",
4
+ "version": "1.0.17",
5
5
  "author": "miami-man",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/getta",
@@ -11,6 +11,9 @@
11
11
  "main": "./dist/cjs/index.cjs",
12
12
  "module": "./dist/esm/index.mjs",
13
13
  "types": "./dist/types/cjs/index.d.cts",
14
+ "imports": {
15
+ "#*": "./src/*"
16
+ },
14
17
  "exports": {
15
18
  ".": {
16
19
  "types": {
@@ -26,50 +29,50 @@
26
29
  },
27
30
  "dependencies": {
28
31
  "@types/lodash-es": "^4.17.12",
29
- "cacheability": "^4.0.27",
30
- "core-js": "^3.39.0",
32
+ "cacheability": "^4.0.30",
33
+ "core-js": "^3.43.0",
31
34
  "lodash-es": "^4.17.21",
32
- "query-string": "^9.1.1",
35
+ "query-string": "^9.2.0",
33
36
  "ts-md5": "^1.3.1",
34
- "type-fest": "^4.26.1"
37
+ "type-fest": "^4.41.0"
35
38
  },
36
39
  "devDependencies": {
37
- "@cachemap/core": "^5.2.2",
38
- "@cachemap/map": "^5.0.8",
39
- "@commitlint/cli": "^19.5.0",
40
+ "@cachemap/core": "^5.2.8",
41
+ "@cachemap/map": "^5.0.10",
42
+ "@commitlint/cli": "^19.8.1",
40
43
  "@jest/globals": "^29.7.0",
41
- "@repodog/cli": "^1.6.36",
42
- "@repodog/commitlint-config": "^19.0.3",
43
- "@repodog/eslint-config": "^9.0.7",
44
- "@repodog/eslint-config-jest": "^9.0.3",
45
- "@repodog/jest-config": "^29.0.3",
46
- "@repodog/markdownlint-config": "^1.2.4",
47
- "@repodog/prettier-config": "^3.0.2",
48
- "@repodog/rollup-config": "^4.0.3",
49
- "@repodog/swc-config": "^1.0.3",
50
- "@repodog/syncpack-config": "^13.0.2",
51
- "@repodog/ts-config": "^5.0.4",
44
+ "@repodog/cli": "^1.6.44",
45
+ "@repodog/commitlint-config": "^19.0.4",
46
+ "@repodog/eslint-config": "^9.0.16",
47
+ "@repodog/eslint-config-jest": "^9.0.5",
48
+ "@repodog/jest-config": "^29.0.5",
49
+ "@repodog/markdownlint-config": "^1.2.5",
50
+ "@repodog/prettier-config": "^3.0.3",
51
+ "@repodog/rollup-config": "^4.0.10",
52
+ "@repodog/swc-config": "^1.0.11",
53
+ "@repodog/syncpack-config": "^13.0.4",
54
+ "@repodog/ts-config": "^5.0.5",
52
55
  "@rollup/plugin-swc": "^0.3.0",
53
- "@swc/core": "^1.7.26",
54
- "@swc/jest": "^0.2.36",
56
+ "@swc/core": "^1.12.1",
57
+ "@swc/jest": "^0.2.38",
55
58
  "@types/jest": "^29.5.13",
56
- "@types/node": "^22.8.7",
57
- "cts-types": "^0.0.7",
59
+ "@types/node": "^24.0.1",
60
+ "cts-types": "^0.0.10",
58
61
  "del-cli": "^6.0.0",
59
- "eslint": "^9.11.0",
60
- "fetch-mocked": "^0.0.26",
62
+ "eslint": "^9.29.0",
63
+ "fetch-mocked": "^0.0.29",
61
64
  "generate-changelog": "^1.8.0",
62
- "husky": "^9.1.6",
65
+ "husky": "^9.1.7",
63
66
  "jest": "^29.7.0",
64
67
  "jest-environment-jsdom": "^29.7.0",
65
68
  "jest-environment-node": "^29.7.0",
66
- "markdownlint-cli2": "^0.14.0",
67
- "prettier": "^3.3.3",
68
- "rollup": "^4.22.4",
69
+ "markdownlint-cli2": "^0.18.1",
70
+ "prettier": "^3.5.3",
71
+ "rollup": "^4.43.0",
69
72
  "suppress-experimental-warnings": "^2.0.0",
70
- "syncpack": "^13.0.0",
71
- "typescript": "^5.6.2",
72
- "zod": "^3.23.8"
73
+ "syncpack": "^13.0.4",
74
+ "typescript": "^5.8.3",
75
+ "zod": "^3.25.64"
73
76
  },
74
77
  "keywords": [
75
78
  "api-client",
@@ -82,8 +85,8 @@
82
85
  "clean:deps": "del-cli ./node_modules",
83
86
  "clean:dist": "del-cli ./dist",
84
87
  "compile": "pnpm run /^compile:.*/",
85
- "compile:cjs": "MODULE_SYSTEM=cjs rollup -c ./rollup.config.cjs",
86
- "compile:esm": "rollup -c ./rollup.config.cjs",
88
+ "compile:cjs": "MODULE_SYSTEM=cjs rollup -c ./rollup.config.mjs",
89
+ "compile:esm": "rollup -c ./rollup.config.mjs",
87
90
  "compile:types": "tsc --project ./tsconfig.build.json && cts-types build dist/types/esm dist/types/cjs",
88
91
  "cut:changelog": "changelog",
89
92
  "installActivateMise": "sh shellScripts/installActivateMise.sh",
@@ -1,4 +1,6 @@
1
+ import { omitBy } from 'lodash-es';
1
2
  import queryString from 'query-string';
3
+ import { type PlainObject } from '#types.ts';
2
4
  import { type BuildEndpointOptions } from './types.ts';
3
5
 
4
6
  export const buildEndpoint = (
@@ -9,7 +11,7 @@ export const buildEndpoint = (
9
11
  pathTemplateCallback,
10
12
  pathTemplateData,
11
13
  pathTemplateRegExp,
12
- queryParams,
14
+ queryParams = {},
13
15
  }: BuildEndpointOptions,
14
16
  ) => {
15
17
  const pathJoiner = basePath.endsWith('/') || path.startsWith('/') ? '' : '/';
@@ -25,9 +27,11 @@ export const buildEndpoint = (
25
27
  endpoint = endpoint.slice(0, Math.max(0, endpoint.length - 1));
26
28
  }
27
29
 
28
- if (queryParams && Object.keys(queryParams).length > 0) {
30
+ const sanitisedSearchParams = omitBy<PlainObject>(queryParams, entry => !entry);
31
+
32
+ if (Object.keys(sanitisedSearchParams).length > 0) {
29
33
  const queryJoin = queryString.extract(endpoint) ? '&' : '?';
30
- endpoint = `${endpoint}${queryJoin}${queryString.stringify(queryParams)}`;
34
+ endpoint = `${endpoint}${queryJoin}${queryString.stringify(sanitisedSearchParams)}`;
31
35
  }
32
36
 
33
37
  return endpoint;
package/src/main.ts CHANGED
@@ -49,7 +49,7 @@ export class Getta {
49
49
  private _rateLimitCount = 0;
50
50
  private _rateLimitedRequestQueue: RequestQueue = [];
51
51
  private _rateLimitPerSecond: number;
52
- private _rateLimitTimer: NodeJS.Timer | undefined = undefined;
52
+ private _rateLimitTimer: NodeJS.Timeout | undefined = undefined;
53
53
  private _requestRetryWait: number;
54
54
  private _requestTracker: RequestTracker = { active: [], pending: new Map() };
55
55
  private _streamReader: StreamReader;
@@ -299,7 +299,7 @@ export class Getta {
299
299
  try {
300
300
  Object.defineProperty(res, 'data', {
301
301
  enumerable: true,
302
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
302
+
303
303
  value: body ? this._bodyParser(await res[this._streamReader]()) : undefined,
304
304
  writable: true,
305
305
  });
@@ -423,11 +423,7 @@ export class Getta {
423
423
  if (status === consts.NOT_FOUND_STATUS_CODE) {
424
424
  void this._cacheEntryDelete(requestHash);
425
425
  let { errors } = res;
426
-
427
- if (!errors) {
428
- errors = [];
429
- }
430
-
426
+ errors ??= [];
431
427
  errors.push(new Error(consts.RESOURCE_NOT_FOUND_ERROR));
432
428
  res.errors = errors;
433
429
  } else if (status === consts.NOT_MODIFIED_STATUS_CODE) {
@@ -524,22 +520,20 @@ export class Getta {
524
520
 
525
521
  private _setPendingRequest(requestHash: string, resolver: PendingRequestResolvers) {
526
522
  let pending = this._requestTracker.pending.get(requestHash);
527
- if (!pending) pending = [];
523
+ pending ??= [];
528
524
  pending.push(resolver);
529
525
  this._requestTracker.pending.set(requestHash, pending);
530
526
  }
531
527
 
532
528
  private _startRateLimit() {
533
- if (!this._rateLimitTimer) {
534
- this._rateLimitTimer = setTimeout(() => {
535
- this._rateLimitTimer = undefined;
536
- this._rateLimitCount = 0;
537
-
538
- if (this._rateLimitedRequestQueue.length > 0) {
539
- void this._releaseRateLimitedRequestQueue();
540
- }
541
- }, 1000);
542
- }
529
+ this._rateLimitTimer ??= setTimeout(() => {
530
+ this._rateLimitTimer = undefined;
531
+ this._rateLimitCount = 0;
532
+
533
+ if (this._rateLimitedRequestQueue.length > 0) {
534
+ void this._releaseRateLimitedRequestQueue();
535
+ }
536
+ }, 1000);
543
537
 
544
538
  this._rateLimitCount += 1;
545
539
  }