@hyper-fetch/core 7.5.2 → 7.5.3

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 (54) hide show
  1. package/__tests__/features/adapter/adapter.base.spec.ts +387 -0
  2. package/__tests__/features/adapter/adapter.bindings.spec.ts +1023 -0
  3. package/__tests__/features/adapter/adapter.browser.spec.ts +103 -0
  4. package/__tests__/features/adapter/adapter.server.spec.ts +177 -0
  5. package/__tests__/features/adapter/adapter.utils.spec.ts +165 -0
  6. package/__tests__/features/cache/cache.base.spec.ts +358 -0
  7. package/__tests__/features/cache/cache.events.spec.ts +215 -0
  8. package/__tests__/features/cache/cache.garbage-collector.spec.ts +172 -0
  9. package/__tests__/features/cache/cache.lazy-storage.spec.ts +129 -0
  10. package/__tests__/features/cache/cache.utils.spec.ts +119 -0
  11. package/__tests__/features/client/client.auth.spec.ts +125 -0
  12. package/__tests__/features/client/client.base.spec.ts +149 -0
  13. package/__tests__/features/client/client.hydration.spec.ts +171 -0
  14. package/__tests__/features/client/client.interceptor.spec.ts +225 -0
  15. package/__tests__/features/client/client.methods.spec.ts +188 -0
  16. package/__tests__/features/client/client.middleware.spec.ts +118 -0
  17. package/__tests__/features/client/client.utils.spec.ts +292 -0
  18. package/__tests__/features/dispatcher/dispatcher.base.spec.ts +123 -0
  19. package/__tests__/features/dispatcher/dispatcher.events.spec.ts +304 -0
  20. package/__tests__/features/dispatcher/dispatcher.queue.spec.ts +462 -0
  21. package/__tests__/features/dispatcher/dispatcher.requests.spec.ts +241 -0
  22. package/__tests__/features/dispatcher/dispatcher.utils.spec.ts +125 -0
  23. package/__tests__/features/managers/app/app.manager.base.spec.ts +235 -0
  24. package/__tests__/features/managers/app/app.manager.ssr.spec.ts +40 -0
  25. package/__tests__/features/managers/logger/logger.base.spec.ts +107 -0
  26. package/__tests__/features/managers/logger/logger.utils.spec.ts +100 -0
  27. package/__tests__/features/managers/request/request.manager.base.spec.ts +222 -0
  28. package/__tests__/features/managers/request/request.manager.events.spec.ts +280 -0
  29. package/__tests__/features/mocker/mocker.base.spec.ts +567 -0
  30. package/__tests__/features/plugin/plugin.base.spec.ts +255 -0
  31. package/__tests__/features/request/request.base.spec.ts +199 -0
  32. package/__tests__/features/request/request.cloning.spec.ts +47 -0
  33. package/__tests__/features/request/request.sending.spec.ts +272 -0
  34. package/__tests__/features/request/request.setters.spec.ts +157 -0
  35. package/__tests__/features/request/request.typescript.spec.ts +423 -0
  36. package/__tests__/features/request/request.utils.spec.ts +77 -0
  37. package/__tests__/features/sdk/sdk.base.spec.ts +130 -0
  38. package/__tests__/global.d.ts +1 -0
  39. package/__tests__/jest.setup.ts +13 -0
  40. package/__tests__/shared/callbacks.shared.ts +9 -0
  41. package/__tests__/shared/index.ts +2 -0
  42. package/__tests__/shared/progress.shared.ts +35 -0
  43. package/__tests__/tsconfig.json +13 -0
  44. package/__tests__/utils/adapter.utils.ts +38 -0
  45. package/__tests__/utils/cache.utils.ts +19 -0
  46. package/__tests__/utils/callbacks.utils.ts +47 -0
  47. package/__tests__/utils/dispatcher.utils.ts +6 -0
  48. package/__tests__/utils/index.ts +4 -0
  49. package/dist/index.js +12 -1
  50. package/dist/index.js.map +2 -2
  51. package/jest.config.ts +6 -0
  52. package/package.json +1 -1
  53. package/project.json +4 -0
  54. package/src/http-adapter/http-adapter.server.ts +15 -1
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "noEmit": true,
5
+ "baseUrl": "../src",
6
+ "moduleResolution": "node",
7
+ "esModuleInterop": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "paths": {
10
+ "@hyper-fetch/core": ["../src"]
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,38 @@
1
+ import { sleep } from "@hyper-fetch/testing";
2
+
3
+ import { RequestInstance } from "request";
4
+ import { Adapter } from "adapter";
5
+ import { HttpAdapter, HttpAdapterType } from "http-adapter";
6
+ import { LoggerManager } from "managers";
7
+
8
+ export const createAdapter = (props?: {
9
+ sleepTime?: number;
10
+ callback: (request: RequestInstance, requestId: string) => void;
11
+ }): HttpAdapterType => {
12
+ const { sleepTime, callback } = props || {};
13
+
14
+ const httpAdapter = HttpAdapter();
15
+
16
+ const adapter = new Adapter({
17
+ name: "test",
18
+ defaultMethod: "GET",
19
+ defaultExtra: {},
20
+ systemErrorStatus: 0,
21
+ systemErrorExtra: {},
22
+ });
23
+
24
+ adapter.logger = new LoggerManager().initialize({ debug: false }, "Adapter");
25
+ httpAdapter.logger = new LoggerManager().initialize({ debug: false }, "Adapter");
26
+
27
+ adapter.unstable_fetcher = httpAdapter.unstable_fetcher as any;
28
+ adapter.fetch = async (request, requestId) => {
29
+ if (sleepTime) {
30
+ await sleep(sleepTime);
31
+ }
32
+
33
+ callback?.(request, requestId);
34
+ return httpAdapter.fetch(request as any, requestId);
35
+ };
36
+
37
+ return httpAdapter as unknown as HttpAdapterType;
38
+ };
@@ -0,0 +1,19 @@
1
+ import { Cache, CacheAsyncStorageType, CacheOptionsType } from "cache";
2
+ import { ClientInstance } from "client";
3
+
4
+ export const createCache = (client: ClientInstance, options?: CacheOptionsType) => {
5
+ return new Cache(options).initialize(client);
6
+ };
7
+
8
+ export const createLazyCacheAdapter = (storage: Map<any, any>): CacheAsyncStorageType => {
9
+ return {
10
+ get: async (key) => storage.get(key),
11
+ set: async (key, value) => {
12
+ storage.set(key, value);
13
+ },
14
+ keys: async () => storage.keys(),
15
+ delete: async (key) => {
16
+ storage.delete(key);
17
+ },
18
+ };
19
+ };
@@ -0,0 +1,47 @@
1
+ import { sleep } from "@hyper-fetch/testing";
2
+
3
+ import { ResponseType } from "adapter";
4
+ import { RequestInstance } from "request";
5
+ import { ClientInstance, ResponseInterceptorType } from "client";
6
+ import { HttpAdapterType, xhrExtra } from "http-adapter";
7
+
8
+ export const interceptorCallback = (props?: {
9
+ sleepTime?: number;
10
+ callback: () => void;
11
+ }): ResponseInterceptorType<ClientInstance> => {
12
+ const { sleepTime, callback } = props || {};
13
+
14
+ return async (
15
+ response?: ResponseType<null, null, HttpAdapterType>,
16
+ ): Promise<ResponseType<null, null, HttpAdapterType>> => {
17
+ if (sleepTime) {
18
+ await sleep(sleepTime);
19
+ }
20
+
21
+ callback?.();
22
+ return (
23
+ response || {
24
+ data: null,
25
+ error: null,
26
+ success: true,
27
+ status: 200,
28
+ extra: xhrExtra,
29
+ requestTimestamp: 0,
30
+ responseTimestamp: 0,
31
+ }
32
+ );
33
+ };
34
+ };
35
+
36
+ export const middlewareCallback = (props?: { sleepTime?: number; callback: () => void }) => {
37
+ const { sleepTime, callback } = props || {};
38
+
39
+ return async (request: RequestInstance): Promise<RequestInstance> => {
40
+ if (sleepTime) {
41
+ await sleep(sleepTime);
42
+ }
43
+
44
+ callback?.();
45
+ return request;
46
+ };
47
+ };
@@ -0,0 +1,6 @@
1
+ import { Dispatcher, DispatcherOptionsType } from "dispatcher";
2
+ import { ClientInstance } from "client";
3
+
4
+ export const createDispatcher = (client: ClientInstance, options?: DispatcherOptionsType) => {
5
+ return new Dispatcher(options).initialize(client);
6
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./adapter.utils";
2
+ export * from "./dispatcher.utils";
3
+ export * from "./callbacks.utils";
4
+ export * from "./cache.utils";
package/dist/index.js CHANGED
@@ -3079,7 +3079,18 @@ var getAdapter2 = () => new Adapter({
3079
3079
  }
3080
3080
  onBeforeRequest();
3081
3081
  if (payload) {
3082
- options.headers["Content-Length"] = Buffer.byteLength(JSON.stringify(payload));
3082
+ const payloadAsAny = payload;
3083
+ const isString = typeof payloadAsAny === "string";
3084
+ const isBuffer = Buffer.isBuffer(payloadAsAny);
3085
+ let contentLength;
3086
+ if (isString) {
3087
+ contentLength = Buffer.byteLength(payloadAsAny);
3088
+ } else if (isBuffer) {
3089
+ contentLength = payloadAsAny.length;
3090
+ } else {
3091
+ contentLength = Buffer.byteLength(JSON.stringify(payloadAsAny));
3092
+ }
3093
+ options.headers["Content-Length"] = contentLength;
3083
3094
  }
3084
3095
  const queryString = queryParams ? stringifyQueryParams(queryParams) : "";
3085
3096
  const fullUrl = `${url}${endpoint}${queryString}`;