@ngxsp/adapter-http-fetch 0.0.1-next.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.
package/index.cjs ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ // src/index.ts
4
+ function createFetchHttpAdapter(opts = {}) {
5
+ const timeoutMs = opts.timeoutMs ?? 15e3;
6
+ const reqInts = opts.requestInterceptors ?? [];
7
+ const resInts = opts.responseInterceptors ?? [];
8
+ const fetchFn = async (input, init = {}) => {
9
+ let reqInput = input;
10
+ let reqInit = { ...init };
11
+ for (const fn of reqInts) {
12
+ const out = await fn(reqInput, reqInit);
13
+ reqInput = out[0];
14
+ reqInit = out[1];
15
+ }
16
+ const controller = new AbortController();
17
+ const t = setTimeout(() => controller.abort(), timeoutMs);
18
+ try {
19
+ const resp = await fetch(reqInput, { ...reqInit, signal: controller.signal });
20
+ let r = resp;
21
+ for (const fn of resInts) r = await fn(r);
22
+ return r;
23
+ } finally {
24
+ clearTimeout(t);
25
+ }
26
+ };
27
+ return { fetch: fetchFn };
28
+ }
29
+
30
+ exports.createFetchHttpAdapter = createFetchHttpAdapter;
31
+ //# sourceMappingURL=index.cjs.map
32
+ //# sourceMappingURL=index.cjs.map
package/index.cjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAgBO,SAAS,sBAAA,CAAuB,IAAA,GAA2B,EAAC,EAAG;AACpE,EAAA,MAAM,SAAA,GAAY,KAAK,SAAA,IAAa,IAAA;AACpC,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,mBAAA,IAAuB,EAAC;AAC7C,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,oBAAA,IAAwB,EAAC;AAE9C,EAAA,MAAM,OAAA,GAAqB,OAAO,KAAA,EAAO,IAAA,GAAO,EAAC,KAAM;AACrD,IAAA,IAAI,QAAA,GAA8B,KAAA;AAClC,IAAA,IAAI,OAAA,GAAuB,EAAE,GAAG,IAAA,EAAK;AAErC,IAAA,KAAA,MAAW,MAAM,OAAA,EAAS;AACxB,MAAA,MAAM,GAAA,GAAM,MAAM,EAAA,CAAG,QAAA,EAAU,OAAO,CAAA;AACtC,MAAA,QAAA,GAAW,IAAI,CAAC,CAAA;AAChB,MAAA,OAAA,GAAU,IAAI,CAAC,CAAA;AAAA,IACjB;AAEA,IAAA,MAAM,UAAA,GAAa,IAAI,eAAA,EAAgB;AACvC,IAAA,MAAM,IAAI,UAAA,CAAW,MAAM,UAAA,CAAW,KAAA,IAAS,SAAS,CAAA;AACxD,IAAA,IAAI;AACF,MAAA,MAAM,IAAA,GAAO,MAAM,KAAA,CAAM,QAAA,EAAU,EAAE,GAAG,OAAA,EAAS,MAAA,EAAQ,UAAA,CAAW,MAAA,EAAQ,CAAA;AAC5E,MAAA,IAAI,CAAA,GAAI,IAAA;AACR,MAAA,KAAA,MAAW,EAAA,IAAM,OAAA,EAAS,CAAA,GAAI,MAAM,GAAG,CAAC,CAAA;AACxC,MAAA,OAAO,CAAA;AAAA,IACT,CAAA,SAAE;AACA,MAAA,YAAA,CAAa,CAAC,CAAA;AAAA,IAChB;AAAA,EACF,CAAA;AAEA,EAAA,OAAO,EAAE,OAAO,OAAA,EAAQ;AAC1B","file":"index.cjs","sourcesContent":["export type FetchLike = typeof fetch;\n\nexport interface HttpRequestInterceptor {\n (input: RequestInfo | URL, init: RequestInit): Promise<[RequestInfo | URL, RequestInit]> | [RequestInfo | URL, RequestInit];\n}\n\nexport interface HttpResponseInterceptor {\n (response: Response): Promise<Response> | Response;\n}\n\nexport interface HttpAdapterOptions {\n timeoutMs?: number;\n requestInterceptors?: HttpRequestInterceptor[];\n responseInterceptors?: HttpResponseInterceptor[];\n}\n\nexport function createFetchHttpAdapter(opts: HttpAdapterOptions = {}) {\n const timeoutMs = opts.timeoutMs ?? 15000;\n const reqInts = opts.requestInterceptors ?? [];\n const resInts = opts.responseInterceptors ?? [];\n\n const fetchFn: FetchLike = async (input, init = {}) => {\n let reqInput: RequestInfo | URL = input;\n let reqInit: RequestInit = { ...init };\n\n for (const fn of reqInts) {\n const out = await fn(reqInput, reqInit);\n reqInput = out[0];\n reqInit = out[1];\n }\n\n const controller = new AbortController();\n const t = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const resp = await fetch(reqInput, { ...reqInit, signal: controller.signal });\n let r = resp;\n for (const fn of resInts) r = await fn(r);\n return r;\n } finally {\n clearTimeout(t);\n }\n };\n\n return { fetch: fetchFn };\n}\n"]}
package/index.d.cts ADDED
@@ -0,0 +1,17 @@
1
+ type FetchLike = typeof fetch;
2
+ interface HttpRequestInterceptor {
3
+ (input: RequestInfo | URL, init: RequestInit): Promise<[RequestInfo | URL, RequestInit]> | [RequestInfo | URL, RequestInit];
4
+ }
5
+ interface HttpResponseInterceptor {
6
+ (response: Response): Promise<Response> | Response;
7
+ }
8
+ interface HttpAdapterOptions {
9
+ timeoutMs?: number;
10
+ requestInterceptors?: HttpRequestInterceptor[];
11
+ responseInterceptors?: HttpResponseInterceptor[];
12
+ }
13
+ declare function createFetchHttpAdapter(opts?: HttpAdapterOptions): {
14
+ fetch: typeof fetch;
15
+ };
16
+
17
+ export { type FetchLike, type HttpAdapterOptions, type HttpRequestInterceptor, type HttpResponseInterceptor, createFetchHttpAdapter };
package/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ type FetchLike = typeof fetch;
2
+ interface HttpRequestInterceptor {
3
+ (input: RequestInfo | URL, init: RequestInit): Promise<[RequestInfo | URL, RequestInit]> | [RequestInfo | URL, RequestInit];
4
+ }
5
+ interface HttpResponseInterceptor {
6
+ (response: Response): Promise<Response> | Response;
7
+ }
8
+ interface HttpAdapterOptions {
9
+ timeoutMs?: number;
10
+ requestInterceptors?: HttpRequestInterceptor[];
11
+ responseInterceptors?: HttpResponseInterceptor[];
12
+ }
13
+ declare function createFetchHttpAdapter(opts?: HttpAdapterOptions): {
14
+ fetch: typeof fetch;
15
+ };
16
+
17
+ export { type FetchLike, type HttpAdapterOptions, type HttpRequestInterceptor, type HttpResponseInterceptor, createFetchHttpAdapter };
package/index.js ADDED
@@ -0,0 +1,30 @@
1
+ // src/index.ts
2
+ function createFetchHttpAdapter(opts = {}) {
3
+ const timeoutMs = opts.timeoutMs ?? 15e3;
4
+ const reqInts = opts.requestInterceptors ?? [];
5
+ const resInts = opts.responseInterceptors ?? [];
6
+ const fetchFn = async (input, init = {}) => {
7
+ let reqInput = input;
8
+ let reqInit = { ...init };
9
+ for (const fn of reqInts) {
10
+ const out = await fn(reqInput, reqInit);
11
+ reqInput = out[0];
12
+ reqInit = out[1];
13
+ }
14
+ const controller = new AbortController();
15
+ const t = setTimeout(() => controller.abort(), timeoutMs);
16
+ try {
17
+ const resp = await fetch(reqInput, { ...reqInit, signal: controller.signal });
18
+ let r = resp;
19
+ for (const fn of resInts) r = await fn(r);
20
+ return r;
21
+ } finally {
22
+ clearTimeout(t);
23
+ }
24
+ };
25
+ return { fetch: fetchFn };
26
+ }
27
+
28
+ export { createFetchHttpAdapter };
29
+ //# sourceMappingURL=index.js.map
30
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAgBO,SAAS,sBAAA,CAAuB,IAAA,GAA2B,EAAC,EAAG;AACpE,EAAA,MAAM,SAAA,GAAY,KAAK,SAAA,IAAa,IAAA;AACpC,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,mBAAA,IAAuB,EAAC;AAC7C,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,oBAAA,IAAwB,EAAC;AAE9C,EAAA,MAAM,OAAA,GAAqB,OAAO,KAAA,EAAO,IAAA,GAAO,EAAC,KAAM;AACrD,IAAA,IAAI,QAAA,GAA8B,KAAA;AAClC,IAAA,IAAI,OAAA,GAAuB,EAAE,GAAG,IAAA,EAAK;AAErC,IAAA,KAAA,MAAW,MAAM,OAAA,EAAS;AACxB,MAAA,MAAM,GAAA,GAAM,MAAM,EAAA,CAAG,QAAA,EAAU,OAAO,CAAA;AACtC,MAAA,QAAA,GAAW,IAAI,CAAC,CAAA;AAChB,MAAA,OAAA,GAAU,IAAI,CAAC,CAAA;AAAA,IACjB;AAEA,IAAA,MAAM,UAAA,GAAa,IAAI,eAAA,EAAgB;AACvC,IAAA,MAAM,IAAI,UAAA,CAAW,MAAM,UAAA,CAAW,KAAA,IAAS,SAAS,CAAA;AACxD,IAAA,IAAI;AACF,MAAA,MAAM,IAAA,GAAO,MAAM,KAAA,CAAM,QAAA,EAAU,EAAE,GAAG,OAAA,EAAS,MAAA,EAAQ,UAAA,CAAW,MAAA,EAAQ,CAAA;AAC5E,MAAA,IAAI,CAAA,GAAI,IAAA;AACR,MAAA,KAAA,MAAW,EAAA,IAAM,OAAA,EAAS,CAAA,GAAI,MAAM,GAAG,CAAC,CAAA;AACxC,MAAA,OAAO,CAAA;AAAA,IACT,CAAA,SAAE;AACA,MAAA,YAAA,CAAa,CAAC,CAAA;AAAA,IAChB;AAAA,EACF,CAAA;AAEA,EAAA,OAAO,EAAE,OAAO,OAAA,EAAQ;AAC1B","file":"index.js","sourcesContent":["export type FetchLike = typeof fetch;\n\nexport interface HttpRequestInterceptor {\n (input: RequestInfo | URL, init: RequestInit): Promise<[RequestInfo | URL, RequestInit]> | [RequestInfo | URL, RequestInit];\n}\n\nexport interface HttpResponseInterceptor {\n (response: Response): Promise<Response> | Response;\n}\n\nexport interface HttpAdapterOptions {\n timeoutMs?: number;\n requestInterceptors?: HttpRequestInterceptor[];\n responseInterceptors?: HttpResponseInterceptor[];\n}\n\nexport function createFetchHttpAdapter(opts: HttpAdapterOptions = {}) {\n const timeoutMs = opts.timeoutMs ?? 15000;\n const reqInts = opts.requestInterceptors ?? [];\n const resInts = opts.responseInterceptors ?? [];\n\n const fetchFn: FetchLike = async (input, init = {}) => {\n let reqInput: RequestInfo | URL = input;\n let reqInit: RequestInit = { ...init };\n\n for (const fn of reqInts) {\n const out = await fn(reqInput, reqInit);\n reqInput = out[0];\n reqInit = out[1];\n }\n\n const controller = new AbortController();\n const t = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const resp = await fetch(reqInput, { ...reqInit, signal: controller.signal });\n let r = resp;\n for (const fn of resInts) r = await fn(r);\n return r;\n } finally {\n clearTimeout(t);\n }\n };\n\n return { fetch: fetchFn };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@ngxsp/adapter-http-fetch",
3
+ "version": "0.0.1-next.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ }
15
+ }