@ecosy/core 0.4.0 → 0.6.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 (132) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/dist/cache/disk.d.ts +44 -0
  3. package/dist/cache/disk.js +1 -0
  4. package/dist/cache/disk.mjs +1 -0
  5. package/dist/cache/index.d.ts +17 -0
  6. package/dist/cache/index.js +1 -0
  7. package/dist/cache/index.mjs +1 -0
  8. package/dist/cache/memory.d.ts +19 -0
  9. package/dist/cache/memory.js +1 -0
  10. package/dist/cache/memory.mjs +1 -0
  11. package/dist/cache/redis.d.ts +65 -0
  12. package/dist/cache/redis.js +1 -0
  13. package/dist/cache/redis.mjs +1 -0
  14. package/dist/cache/types.d.ts +51 -0
  15. package/dist/cache/types.js +1 -0
  16. package/dist/cache/types.mjs +1 -0
  17. package/dist/ecosy-core.umd.js +1 -1
  18. package/dist/ecosy-core.umd.js.map +1 -1
  19. package/dist/index.d.ts +0 -9
  20. package/dist/index.js +1 -1
  21. package/dist/index.mjs +1 -1
  22. package/dist/serialize/index.d.ts +62 -0
  23. package/dist/serialize/index.js +1 -0
  24. package/dist/serialize/index.mjs +1 -0
  25. package/dist/serialize/interpolate.d.ts +10 -0
  26. package/dist/serialize/interpolate.js +1 -0
  27. package/dist/serialize/interpolate.mjs +1 -0
  28. package/dist/serialize/json.d.ts +3 -0
  29. package/dist/serialize/json.js +1 -0
  30. package/dist/serialize/json.mjs +1 -0
  31. package/dist/serialize/primitive.d.ts +3 -0
  32. package/dist/serialize/primitive.js +1 -0
  33. package/dist/serialize/primitive.mjs +1 -0
  34. package/dist/serialize/query-string.d.ts +3 -0
  35. package/dist/serialize/query-string.js +1 -0
  36. package/dist/serialize/query-string.mjs +1 -0
  37. package/dist/serialize/types.d.ts +42 -0
  38. package/dist/serialize/url.d.ts +3 -0
  39. package/dist/serialize/url.js +1 -0
  40. package/dist/serialize/url.mjs +1 -0
  41. package/dist/syhemo/collectors.d.ts +25 -0
  42. package/dist/syhemo/collectors.js +1 -0
  43. package/dist/syhemo/collectors.mjs +1 -0
  44. package/dist/syhemo/exposition.d.ts +15 -0
  45. package/dist/syhemo/exposition.js +1 -0
  46. package/dist/syhemo/exposition.mjs +1 -0
  47. package/dist/syhemo/index.d.ts +50 -0
  48. package/dist/syhemo/index.js +1 -0
  49. package/dist/syhemo/index.mjs +1 -0
  50. package/dist/{logger.d.ts → syhemo/logger.d.ts} +23 -11
  51. package/dist/syhemo/logger.js +1 -0
  52. package/dist/{logger.mjs → syhemo/logger.mjs} +1 -1
  53. package/dist/syhemo/types.d.ts +114 -0
  54. package/dist/utilities/index.d.ts +2 -0
  55. package/dist/utilities/index.js +1 -1
  56. package/dist/utilities/index.mjs +1 -1
  57. package/dist/{searchify.d.ts → utilities/searchify.d.ts} +1 -1
  58. package/dist/utilities/searchify.js +1 -0
  59. package/dist/utilities/searchify.mjs +1 -0
  60. package/package.json +35 -37
  61. package/agents/skills/ecosy-core-fetcher/SKILL.md +0 -93
  62. package/dist/env.d.ts +0 -26
  63. package/dist/env.js +0 -1
  64. package/dist/env.mjs +0 -1
  65. package/dist/http/array.d.ts +0 -2
  66. package/dist/http/array.js +0 -1
  67. package/dist/http/array.mjs +0 -1
  68. package/dist/http/client.d.ts +0 -38
  69. package/dist/http/client.js +0 -1
  70. package/dist/http/client.mjs +0 -1
  71. package/dist/http/endpoint.d.ts +0 -8
  72. package/dist/http/endpoint.js +0 -1
  73. package/dist/http/endpoint.mjs +0 -1
  74. package/dist/http/fetcher.d.ts +0 -84
  75. package/dist/http/fetcher.js +0 -1
  76. package/dist/http/fetcher.mjs +0 -1
  77. package/dist/http/http-core.d.ts +0 -5
  78. package/dist/http/http-core.js +0 -1
  79. package/dist/http/http-core.mjs +0 -1
  80. package/dist/http/http-static.d.ts +0 -20
  81. package/dist/http/http-static.js +0 -1
  82. package/dist/http/http-static.mjs +0 -1
  83. package/dist/http/http.d.ts +0 -56
  84. package/dist/http/http.js +0 -1
  85. package/dist/http/http.mjs +0 -1
  86. package/dist/http/index.d.ts +0 -14
  87. package/dist/http/index.js +0 -1
  88. package/dist/http/index.mjs +0 -1
  89. package/dist/http/init.d.ts +0 -83
  90. package/dist/http/init.js +0 -1
  91. package/dist/http/init.mjs +0 -1
  92. package/dist/http/method.d.ts +0 -15
  93. package/dist/http/method.js +0 -1
  94. package/dist/http/method.mjs +0 -1
  95. package/dist/http/plugins/cache.d.ts +0 -13
  96. package/dist/http/plugins/cache.js +0 -1
  97. package/dist/http/plugins/cache.mjs +0 -1
  98. package/dist/http/plugins/dedupe.d.ts +0 -7
  99. package/dist/http/plugins/dedupe.js +0 -1
  100. package/dist/http/plugins/dedupe.mjs +0 -1
  101. package/dist/http/plugins/index.d.ts +0 -3
  102. package/dist/http/plugins/index.js +0 -1
  103. package/dist/http/plugins/index.mjs +0 -1
  104. package/dist/http/plugins/logger.d.ts +0 -24
  105. package/dist/http/plugins/logger.js +0 -1
  106. package/dist/http/plugins/logger.mjs +0 -1
  107. package/dist/http/request.d.ts +0 -26
  108. package/dist/http/response.d.ts +0 -9
  109. package/dist/http/utils.d.ts +0 -21
  110. package/dist/http/utils.js +0 -1
  111. package/dist/http/utils.mjs +0 -1
  112. package/dist/http/xml.d.ts +0 -24
  113. package/dist/http/xml.js +0 -1
  114. package/dist/http/xml.mjs +0 -1
  115. package/dist/logger.js +0 -1
  116. package/dist/node_modules/tslib/tslib.es6.js +0 -1
  117. package/dist/node_modules/tslib/tslib.es6.mjs +0 -1
  118. package/dist/searchify.js +0 -1
  119. package/dist/searchify.mjs +0 -1
  120. package/dist/serialize.d.ts +0 -80
  121. package/dist/serialize.js +0 -1
  122. package/dist/serialize.mjs +0 -1
  123. package/dist/syhemo.d.ts +0 -102
  124. package/dist/syhemo.js +0 -1
  125. package/dist/syhemo.mjs +0 -1
  126. /package/dist/{http/request.js → serialize/types.js} +0 -0
  127. /package/dist/{http/request.mjs → serialize/types.mjs} +0 -0
  128. /package/dist/{http/response.js → syhemo/types.js} +0 -0
  129. /package/dist/{http/response.mjs → syhemo/types.mjs} +0 -0
  130. /package/dist/{slugify.d.ts → utilities/slugify.d.ts} +0 -0
  131. /package/dist/{slugify.js → utilities/slugify.js} +0 -0
  132. /package/dist/{slugify.mjs → utilities/slugify.mjs} +0 -0
@@ -1 +1 @@
1
- "use strict";var e=require("./clone.js"),r=require("./defer.js"),t=require("./filelist.js"),s=require("./flatten.js"),i=require("./freeze.js"),o=require("./get.js"),a=require("./is-equal.js"),p=require("./is-function.js"),x=require("./object.js"),c=require("./merge.js"),j=require("./formdata.js"),n=require("./sanitize-mime.js"),l=require("./string.js");exports.clone=e.clone,exports.defer=r.defer,exports.deferAsync=r.deferAsync,exports.isFileList=t.isFileList,exports.escapeRegexKey=s.escapeRegexKey,exports.flatten=s.flatten,exports.flattenToArray=s.flattenToArray,exports.freeze=i.freeze,exports.get=o.get,exports.isEqual=a.isEqual,exports.isFunction=p.isFunction,exports.hasOwnProperty=x.hasOwnProperty,exports.isComplexObject=x.isComplexObject,exports.isLiteralObject=x.isLiteralObject,exports.isObject=x.isObject,exports.isObjectable=x.isObjectable,exports.merge=c.merge,exports.isFormData=j.isFormData,exports.objectToFormData=j.objectToFormData,exports.MIME_REGEX=n.MIME_REGEX,exports.sanitizeMime=n.sanitizeMime,exports.pascalToKebab=l.pascalToKebab,exports.toString=l.toString,exports.ucfirst=l.ucfirst;
1
+ "use strict";var e=require("./clone.js"),r=require("./defer.js"),s=require("./filelist.js"),t=require("./flatten.js"),i=require("./freeze.js"),o=require("./get.js"),a=require("./is-equal.js"),p=require("./is-function.js"),x=require("./object.js"),c=require("./merge.js"),u=require("./formdata.js"),j=require("./sanitize-mime.js"),l=require("./searchify.js"),f=require("./slugify.js"),n=require("./string.js");exports.clone=e.clone,exports.defer=r.defer,exports.deferAsync=r.deferAsync,exports.isFileList=s.isFileList,exports.escapeRegexKey=t.escapeRegexKey,exports.flatten=t.flatten,exports.flattenToArray=t.flattenToArray,exports.freeze=i.freeze,exports.get=o.get,exports.isEqual=a.isEqual,exports.isFunction=p.isFunction,exports.hasOwnProperty=x.hasOwnProperty,exports.isComplexObject=x.isComplexObject,exports.isLiteralObject=x.isLiteralObject,exports.isObject=x.isObject,exports.isObjectable=x.isObjectable,exports.merge=c.merge,exports.isFormData=u.isFormData,exports.objectToFormData=u.objectToFormData,exports.MIME_REGEX=j.MIME_REGEX,exports.sanitizeMime=j.sanitizeMime,exports.searchify=l.searchify,exports.DEFAULT_TRANSFORMER=f.DEFAULT_TRANSFORMER,exports.slugify=f.slugify,exports.pascalToKebab=n.pascalToKebab,exports.toString=n.toString,exports.ucfirst=n.ucfirst;
@@ -1 +1 @@
1
- export{clone}from"./clone.mjs";export{defer,deferAsync}from"./defer.mjs";export{isFileList}from"./filelist.mjs";export{escapeRegexKey,flatten,flattenToArray}from"./flatten.mjs";export{freeze}from"./freeze.mjs";export{get}from"./get.mjs";export{isEqual}from"./is-equal.mjs";export{isFunction}from"./is-function.mjs";export{hasOwnProperty,isComplexObject,isLiteralObject,isObject,isObjectable}from"./object.mjs";export{merge}from"./merge.mjs";export{isFormData,objectToFormData}from"./formdata.mjs";export{MIME_REGEX,sanitizeMime}from"./sanitize-mime.mjs";export{pascalToKebab,toString,ucfirst}from"./string.mjs";
1
+ export{clone}from"./clone.mjs";export{defer,deferAsync}from"./defer.mjs";export{isFileList}from"./filelist.mjs";export{escapeRegexKey,flatten,flattenToArray}from"./flatten.mjs";export{freeze}from"./freeze.mjs";export{get}from"./get.mjs";export{isEqual}from"./is-equal.mjs";export{isFunction}from"./is-function.mjs";export{hasOwnProperty,isComplexObject,isLiteralObject,isObject,isObjectable}from"./object.mjs";export{merge}from"./merge.mjs";export{isFormData,objectToFormData}from"./formdata.mjs";export{MIME_REGEX,sanitizeMime}from"./sanitize-mime.mjs";export{searchify}from"./searchify.mjs";export{DEFAULT_TRANSFORMER,slugify}from"./slugify.mjs";export{pascalToKebab,toString,ucfirst}from"./string.mjs";
@@ -32,4 +32,4 @@ export interface SearchResult {
32
32
  * // { matches: ["Brûlée"], positions: [{ start: 6, length: 6 }] }
33
33
  * ```
34
34
  */
35
- export default function searchify(original: string, searchStr: string): SearchResult;
35
+ export declare function searchify(original: string, searchStr: string): SearchResult;
@@ -0,0 +1 @@
1
+ "use strict";var t=require("./slugify.js");const e={separator:"",silent:!0,transformer:Object.assign({},t.DEFAULT_TRANSFORMER)};exports.searchify=function(i,s){const n=t.slugify(s,e),r=n.length,o={matches:[],positions:[]};if(!r)return o;const g=new Map,l=[...i.split("")].map((i,s)=>{let n=g.get(i);return void 0===n&&(n=t.slugify(i,e),g.set(i,n)),{originIndex:s,slugified:n,char:i}}).filter((t,e,i)=>0===e||(" "!==t.char||" "!==i[e-1].char));if(l.length<r)return o;for(let t=0;t<l.length;){const e=l[t];if(""===e.slugified){t++;continue}let s="",g=t,f=!0;for(;s.length<r&&g<l.length;){const t=l[g];if(""!==t.slugified&&(s+=t.slugified,!n.startsWith(s))){f=!1;break}g++}if(f&&s===n){const s=l[g-1],n=i.substring(e.originIndex,s.originIndex+1);o.matches.push(n),o.positions.push({start:e.originIndex,length:n.length}),t=g}else t++}return o};
@@ -0,0 +1 @@
1
+ import{DEFAULT_TRANSFORMER as t,slugify as e}from"./slugify.mjs";const i={separator:"",silent:!0,transformer:Object.assign({},t)};function n(t,n){const s=e(n,i),r=s.length,o={matches:[],positions:[]};if(!r)return o;const g=new Map,l=[...t.split("")].map((t,n)=>{let s=g.get(t);return void 0===s&&(s=e(t,i),g.set(t,s)),{originIndex:n,slugified:s,char:t}}).filter((t,e,i)=>0===e||(" "!==t.char||" "!==i[e-1].char));if(l.length<r)return o;for(let e=0;e<l.length;){const i=l[e];if(""===i.slugified){e++;continue}let n="",g=e,f=!0;for(;n.length<r&&g<l.length;){const t=l[g];if(""!==t.slugified&&(n+=t.slugified,!s.startsWith(n))){f=!1;break}g++}if(f&&n===s){const n=l[g-1],s=t.substring(i.originIndex,n.originIndex+1);o.matches.push(s),o.positions.push({start:i.originIndex,length:s.length}),e=g}else e++}return o}export{n as searchify};
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@ecosy/core",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "A modular, tree-shakable collection of essential utilities, serialization primitives, and event-driven patterns for modern TypeScript applications",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
- "type": "module",
10
9
  "main": "./dist/index.js",
11
10
  "module": "./dist/index.mjs",
12
11
  "unpkg": "./dist/ecosy-core.umd.js",
@@ -34,53 +33,53 @@
34
33
  "import": "./dist/utilities/index.mjs",
35
34
  "require": "./dist/utilities/index.js"
36
35
  },
36
+ "./cache": {
37
+ "source": "./src/cache/index.ts",
38
+ "types": "./dist/cache/index.d.ts",
39
+ "import": "./dist/cache/index.mjs",
40
+ "require": "./dist/cache/index.js"
41
+ },
37
42
  "./subscriber": {
38
43
  "source": "./src/subscriber.ts",
39
44
  "types": "./dist/subscriber.d.ts",
40
45
  "import": "./dist/subscriber.mjs",
41
46
  "require": "./dist/subscriber.js"
42
47
  },
43
- "./http": {
44
- "source": "./src/http/index.ts",
45
- "types": "./dist/http/index.d.ts",
46
- "import": "./dist/http/index.mjs",
47
- "require": "./dist/http/index.js"
48
- },
49
- "./http/plugins": {
50
- "source": "./src/http/plugins/index.ts",
51
- "types": "./dist/http/plugins/index.d.ts",
52
- "import": "./dist/http/plugins/index.mjs",
53
- "require": "./dist/http/plugins/index.js"
54
- },
55
- "./logger": {
56
- "source": "./src/logger.ts",
57
- "types": "./dist/logger.d.ts",
58
- "import": "./dist/logger.mjs",
59
- "require": "./dist/logger.js"
60
- },
61
48
  "./syhemo": {
62
- "source": "./src/syhemo.ts",
63
- "types": "./dist/syhemo.d.ts",
64
- "import": "./dist/syhemo.mjs",
65
- "require": "./dist/syhemo.js"
49
+ "source": "./src/syhemo/index.ts",
50
+ "types": "./dist/syhemo/index.d.ts",
51
+ "import": "./dist/syhemo/index.mjs",
52
+ "require": "./dist/syhemo/index.js"
53
+ },
54
+ "./syhemo/logger": {
55
+ "source": "./src/syhemo/logger.ts",
56
+ "types": "./dist/syhemo/logger.d.ts",
57
+ "import": "./dist/syhemo/logger.mjs",
58
+ "require": "./dist/syhemo/logger.js"
66
59
  },
67
60
  "./serialize": {
68
- "source": "./src/serialize.ts",
69
- "types": "./dist/serialize.d.ts",
70
- "import": "./dist/serialize.mjs",
71
- "require": "./dist/serialize.js"
61
+ "source": "./src/serialize/index.ts",
62
+ "types": "./dist/serialize/index.d.ts",
63
+ "import": "./dist/serialize/index.mjs",
64
+ "require": "./dist/serialize/index.js"
65
+ },
66
+ "./serialize/*": {
67
+ "source": "./src/serialize/*.ts",
68
+ "types": "./dist/serialize/*.d.ts",
69
+ "import": "./dist/serialize/*.mjs",
70
+ "require": "./dist/serialize/*.js"
72
71
  },
73
72
  "./slugify": {
74
- "source": "./src/slugify.ts",
75
- "types": "./dist/slugify.d.ts",
76
- "import": "./dist/slugify.mjs",
77
- "require": "./dist/slugify.js"
73
+ "source": "./src/utilities/slugify.ts",
74
+ "types": "./dist/utilities/slugify.d.ts",
75
+ "import": "./dist/utilities/slugify.mjs",
76
+ "require": "./dist/utilities/slugify.js"
78
77
  },
79
78
  "./searchify": {
80
- "source": "./src/searchify.ts",
81
- "types": "./dist/searchify.d.ts",
82
- "import": "./dist/searchify.mjs",
83
- "require": "./dist/searchify.js"
79
+ "source": "./src/utilities/searchify.ts",
80
+ "types": "./dist/utilities/searchify.d.ts",
81
+ "import": "./dist/utilities/searchify.mjs",
82
+ "require": "./dist/utilities/searchify.js"
84
83
  }
85
84
  },
86
85
  "scripts": {
@@ -129,7 +128,6 @@
129
128
  },
130
129
  "agents": {
131
130
  "skills": [
132
- "$this://agents/skills/ecosy-core-fetcher/SKILL.md",
133
131
  "$this://agents/skills/ecosy-core-subscriber/SKILL.md",
134
132
  "$this://agents/skills/ecosy-core-serialize/SKILL.md"
135
133
  ]
@@ -1,93 +0,0 @@
1
- ---
2
- name: ecosy-core-fetcher
3
- description: Guides the AI on using the Fetcher Builder (Mutable Chaining) from @ecosy/core instead of using axios/fetch directly, along with plugin integration (logger, dedupe, cache).
4
- ---
5
-
6
- # `ecosy-core-fetcher` Skill
7
-
8
- When asked to implement API calls (HTTP Requests) in a project that has `@ecosy/core` installed, you must **NEVER** use `fetch`, `axios`, or `ky` directly. Instead, you must always use the **Fetcher Builder** architecture provided by `@ecosy/core`.
9
-
10
- ## 1. Initialization Principle (Builder)
11
-
12
- The `Fetcher` is a **Mutable Chaining Builder**. It acts as a configuration builder, a callable factory, and an executor simultaneously.
13
-
14
- ```typescript
15
- import { Fetcher } from "@ecosy/core";
16
-
17
- // Initialize the root Fetcher for the application
18
- export const api = Fetcher({
19
- baseURL: "https://api.example.com/v1"
20
- });
21
- ```
22
-
23
- ## 2. Attaching Plugins (Middleware)
24
-
25
- `@ecosy/core` utilizes a Middleware architecture (Koa-style). There are 3 built-in plugins that you should use when appropriate:
26
- - `loggerPlugin()`: Automatically logs execution time and payload.
27
- - `dedupePlugin()`: Prevents request duplication (mitigates the Thundering Herd problem).
28
- - `cachePlugin({ ttl })`: Provides an in-memory cache with expiration.
29
-
30
- ```typescript
31
- import { Fetcher, loggerPlugin, dedupePlugin, cachePlugin } from "@ecosy/core";
32
-
33
- export const api = Fetcher({ baseURL: "https://api.example.com" })
34
- .use(loggerPlugin())
35
- .use(dedupePlugin())
36
- .use(cachePlugin({ ttl: 60000 }));
37
- ```
38
-
39
- ## 3. Late-Binding Auth Configuration (Retry Hook)
40
-
41
- Never embed Domain logic (like retrieving tokens from LocalStorage or calling a refresh token API) directly inside the Fetcher's core initialization code. Use the Late-Binding mechanism via `.request()` and `.retry()` hooks.
42
-
43
- **CRITICAL**: The `.retry()` hook supports returning a Promise, so you must apply a Debouncing technique (e.g., using a shared `refreshing` flag/promise) to prevent multiple concurrent requests from triggering the refresh token logic simultaneously.
44
-
45
- ```typescript
46
- import { api } from "./api-client";
47
- import { authStore } from "./auth-store";
48
-
49
- let refreshing: Promise<boolean> | null = null;
50
-
51
- // Inject the Token before sending
52
- api.request(async (options) => {
53
- const token = authStore.getState().accessToken;
54
- if (token) {
55
- options.headers = { ...options.headers, Authorization: `Bearer ${token}` };
56
- }
57
- return options;
58
- });
59
-
60
- // Automatically handle Token Refresh on 401 errors
61
- api.retry(async (res, key) => {
62
- if (res.status === 401) {
63
- if (!refreshing) {
64
- refreshing = authStore.refreshToken().then(() => true).catch(() => false);
65
- }
66
- const success = await refreshing;
67
- refreshing = null;
68
- return success; // Return true to instruct the Fetcher to retry the failed request
69
- }
70
- return false;
71
- });
72
- ```
73
-
74
- ## 4. Executing API Calls
75
-
76
- There are two ways to use the Fetcher:
77
- 1. **Using `.execute()` or `.fetcher()`**: Ideal for direct execution.
78
- 2. **Callable mapping**: Pass a `key` into `api("users.get")` to generate an unexecuted `HttpAction` descriptor, which is highly useful for integrating with tools like React Query or SWR.
79
-
80
- ```typescript
81
- // 1. Direct execution via execute
82
- const action = api<User, [string]>("users.getUser", "GET");
83
- const res = await api.execute(action, ["userId123"]);
84
-
85
- // 2. Quick execution via fetcher (no array required for args)
86
- const res2 = await api.fetcher(action, "userId123");
87
-
88
- if (res.success) {
89
- console.log(res.data);
90
- } else {
91
- console.error(res.error);
92
- }
93
- ```
package/dist/env.d.ts DELETED
@@ -1,26 +0,0 @@
1
- export type EnvSource = Record<string, string | undefined>;
2
- /**
3
- * Returns an env source object for the current runtime.
4
- * Called once per `getEnv` invocation to resolve the global source.
5
- */
6
- export type EnvGetter = () => EnvSource;
7
- /**
8
- * Read an environment variable across runtimes.
9
- *
10
- * @example
11
- * ```ts
12
- * // Basic — uses getter (default: process.env → import.meta.env)
13
- * getEnv("API_URL", "/api")
14
- *
15
- * // Per-call source (e.g. Hono ctx.env)
16
- * getEnv("API_URL", "/api", ctx.env)
17
- *
18
- * // Custom getter for a specific runtime
19
- * getEnv.getter(() => Deno.env.toObject());
20
- * ```
21
- */
22
- export declare function getEnv(key: string, defaultValue?: string, ...sources: Array<EnvSource | undefined>): string | undefined;
23
- export declare namespace getEnv {
24
- var _getter: EnvGetter;
25
- var getter: (fn: EnvGetter) => void;
26
- }
package/dist/env.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var e=require("./utilities/object.js");function t(e,n,...i){for(const t of i)if(t&&e in t&&void 0!==t[e])return t[e];const r=t._getter();return e in r&&void 0!==r[e]?r[e]:n}t._getter=function(){if("undefined"!=typeof globalThis&&"process"in globalThis){const t=globalThis.process;if((null==t?void 0:t.env)&&e.isLiteralObject(t.env))return t.env}try{const t=new Function("return import.meta")();if((null==t?void 0:t.env)&&e.isLiteralObject(t.env))return t.env}catch(e){}return{}},t.getter=e=>{t._getter=e},exports.getEnv=t;
package/dist/env.mjs DELETED
@@ -1 +0,0 @@
1
- import{isLiteralObject as t}from"./utilities/object.mjs";function e(t,n,...o){for(const e of o)if(e&&t in e&&void 0!==e[t])return e[t];const r=e._getter();return t in r&&void 0!==r[t]?r[t]:n}e._getter=function(){if("undefined"!=typeof globalThis&&"process"in globalThis){const e=globalThis.process;if((null==e?void 0:e.env)&&t(e.env))return e.env}try{const e=new Function("return import.meta")();if((null==e?void 0:e.env)&&t(e.env))return e.env}catch(t){}return{}},e.getter=t=>{e._getter=t};export{e as getEnv};
@@ -1,2 +0,0 @@
1
- export type MaybeArray<T> = T | T[];
2
- export declare function asArray<T>(data: T | T[]): T[];
@@ -1 +0,0 @@
1
- "use strict";exports.asArray=function(r){return Array.isArray(r)?r:[r]};
@@ -1 +0,0 @@
1
- function r(r){return Array.isArray(r)?r:[r]}export{r as asArray};
@@ -1,38 +0,0 @@
1
- import { Http } from "./http";
2
- import type { HttpResponse } from "./response";
3
- import { type HttpMethod } from "./method";
4
- /**
5
- * Configuration options for initializing a base HTTP client.
6
- */
7
- export interface HttpClientOptions {
8
- /** The base URL for all requests (e.g. "https://api.example.com") */
9
- baseURL?: string;
10
- /** An existing Http instance to reuse, if any. */
11
- http?: Http;
12
- /** A dictionary of endpoints, or a function returning one. Used to map action keys to URLs. */
13
- endpoint?: Record<string, unknown> | (() => Record<string, unknown>);
14
- }
15
- /**
16
- * Represents an unexecuted HTTP action (descriptor).
17
- * Contains the mapped endpoint key and a lazy function to execute the request.
18
- */
19
- export interface HttpAction<T = unknown, Args extends any[] = [], E = unknown> {
20
- key: string;
21
- fn: (...args: Args) => Promise<HttpResponse<T, E>>;
22
- }
23
- /**
24
- * Creates a client that generates typed endpoint actions.
25
- * Each action has a `key` (useful for caching keys like React Query) and an async `fn`.
26
- *
27
- * @example
28
- * ```ts
29
- * const api = createClient({
30
- * baseURL: "https://api.example.com",
31
- * endpoint: { users: { list: "/users", create: "/users" } },
32
- * });
33
- *
34
- * const getUsers = api<User[]>("users.list");
35
- * const { data } = await getUsers.fn();
36
- * ```
37
- */
38
- export declare function createClient(options?: HttpClientOptions): <T, Args extends any[] = [], E = unknown>(key: string, method?: HttpMethod | "upload" | "related") => HttpAction<T, Args, E>;
@@ -1 +0,0 @@
1
- "use strict";var t=require("../utilities/flatten.js"),e=require("./http.js"),a=require("./method.js");exports.createClient=function(r={}){const n=r.http||new e.Http(r.baseURL);return function(e,s){const i=t.flatten("function"==typeof r.endpoint?r.endpoint():r.endpoint||{})[e];return{key:e,fn:async(...t)=>{switch(s){case a.Methods.POST:return await n.post(i,...t);case a.Methods.PUT:return await n.put(i,...t);case a.Methods.PATCH:return await n.patch(i,...t);case a.Methods.DELETE:return await n.delete(i,...t);case a.Methods.HEAD:return await n.head(i,...t);case a.Methods.OPTIONS:return await n.options(i,...t);case"upload":return await n.upload(i,...t);case"related":return await n.related(i,...t);default:return await n.get(i,...t)}}}}};
@@ -1 +0,0 @@
1
- import{flatten as t}from"../utilities/flatten.mjs";import{Http as e}from"./http.mjs";import{Methods as a}from"./method.mjs";function r(r={}){const n=r.http||new e(r.baseURL);return function(e,i){const o=t("function"==typeof r.endpoint?r.endpoint():r.endpoint||{})[e];return{key:e,fn:async(...t)=>{switch(i){case a.POST:return await n.post(o,...t);case a.PUT:return await n.put(o,...t);case a.PATCH:return await n.patch(o,...t);case a.DELETE:return await n.delete(o,...t);case a.HEAD:return await n.head(o,...t);case a.OPTIONS:return await n.options(o,...t);case"upload":return await n.upload(o,...t);case"related":return await n.related(o,...t);default:return await n.get(o,...t)}}}}}export{r as createClient};
@@ -1,8 +0,0 @@
1
- /** Central registry for grouping endpoint URLs by service name. */
2
- export declare class Endpoint {
3
- private static registered;
4
- static register(service: string, endpoints: Record<string, string>): typeof Endpoint;
5
- static all(): {
6
- [x: string]: Record<string, string>;
7
- };
8
- }
@@ -1 +0,0 @@
1
- "use strict";class t{static register(t,s){return this.registered[t]=Object.assign({},s),this}static all(){return Object.assign({},this.registered)}}t.registered={},exports.Endpoint=t;
@@ -1 +0,0 @@
1
- class e{static register(e,t){return this.registered[e]=Object.assign({},t),this}static all(){return Object.assign({},this.registered)}}e.registered={};export{e as Endpoint};
@@ -1,84 +0,0 @@
1
- import { type HttpClientOptions, type HttpAction } from "./client";
2
- import { Http } from "./http";
3
- import type { HttpResponse } from "./response";
4
- import type { HttpInitInterceptors } from "./init";
5
- import { type HttpMethod } from "./method";
6
- /**
7
- * Result structure returned by a Fetcher execution.
8
- * Contains the raw HttpResponse along with the action key and arguments.
9
- */
10
- export type FetcherResult<DataType = unknown, Args extends any[] = any[], Err = unknown> = HttpResponse<DataType, Err> & {
11
- args: Args;
12
- key: string;
13
- };
14
- /**
15
- * Middleware function for intercepting and transforming Fetcher execution pipeline.
16
- */
17
- export type FetcherMiddleware = (action: HttpAction<any, any, any>, args: any[], next: () => Promise<HttpResponse<any, any>>) => Promise<HttpResponse<any, any>>;
18
- /**
19
- * Configuration options for initializing a Fetcher builder.
20
- */
21
- export interface FetcherOptions extends HttpClientOptions {
22
- request?: HttpInitInterceptors["request"] | HttpInitInterceptors["request"][];
23
- response?: HttpInitInterceptors["response"] | HttpInitInterceptors["response"][];
24
- transform?: HttpInitInterceptors["transform"] | HttpInitInterceptors["transform"][];
25
- error?: HttpInitInterceptors["error"] | HttpInitInterceptors["error"][];
26
- shouldRetry?: (res: HttpResponse<any, any>, key: string) => boolean | Promise<boolean>;
27
- onRetry?: (res: HttpResponse<any, any>, key: string) => boolean | Promise<boolean>;
28
- onResult?: (result: FetcherResult<any, any, any>, config: FetcherOptions) => void | Promise<void>;
29
- middlewares?: FetcherMiddleware[];
30
- retryLimit?: number;
31
- }
32
- /**
33
- * A mutable chaining builder that constructs HTTP clients and pipelines.
34
- * Acts as both a configuration builder and an action factory/executor.
35
- */
36
- export interface IFetcherBuilder {
37
- /**
38
- * Creates an unexecuted RAW action descriptor for a given endpoint key.
39
- * Useful for mapping endpoints before executing them later.
40
- */
41
- <T = unknown, Args extends any[] = [], E = unknown>(key: string, method?: HttpMethod | "upload" | "related"): HttpAction<T, Args, E>;
42
- /**
43
- * Immediately executes an action through the middleware pipeline with arguments as an array.
44
- */
45
- execute<T, Args extends any[] = [], E = unknown>(action: HttpAction<T, Args, E>, args: Args, overrideConfig?: Partial<FetcherOptions>): Promise<FetcherResult<T, Args, E>>;
46
- /**
47
- * Immediately executes an action through the middleware pipeline with rest arguments.
48
- */
49
- fetcher<T, Args extends any[] = [], E = unknown>(action: HttpAction<T, Args, E>, ...args: Args): Promise<FetcherResult<T, Args, E>>;
50
- /** Adds a request interceptor to the underlying Http instance. */
51
- request(fn: HttpInitInterceptors["request"]): IFetcherBuilder;
52
- /** Adds a response interceptor to the underlying Http instance. */
53
- response(fn: HttpInitInterceptors["response"]): IFetcherBuilder;
54
- /** Adds a transform interceptor to the underlying Http instance. */
55
- transform(fn: HttpInitInterceptors["transform"]): IFetcherBuilder;
56
- /** Adds an error interceptor to the underlying Http instance. */
57
- error(fn: HttpInitInterceptors["error"]): IFetcherBuilder;
58
- /** Appends one or more middlewares to the execution pipeline. */
59
- use(...middlewares: FetcherMiddleware[]): IFetcherBuilder;
60
- /** Configures the condition to check if a response should trigger a retry. */
61
- shouldRetry(fn: (res: HttpResponse<any, any>, key: string) => boolean | Promise<boolean>): IFetcherBuilder;
62
- /** Configures the actual retry handler (e.g. refreshing a token). Returns true to retry. */
63
- retry(fn: (res: HttpResponse<any, any>, key: string) => boolean | Promise<boolean>): IFetcherBuilder;
64
- /** Global hook invoked when an execution completes (e.g. for persisting to a store). */
65
- onResult(fn: (result: FetcherResult<any, any, any>, config: FetcherOptions) => void | Promise<void>): IFetcherBuilder;
66
- /** Overrides or extends the builder's internal configuration. */
67
- config(options: Partial<FetcherOptions>): IFetcherBuilder;
68
- /** The underlying HTTP instance associated with this builder. */
69
- readonly http: Http;
70
- }
71
- /**
72
- * Initializes a new Fetcher Builder.
73
- *
74
- * @example
75
- * ```ts
76
- * const api = Fetcher({ baseURL: "https://api.example.com" })
77
- * .use(loggerPlugin())
78
- * .retry(async (res, key) => await handleAuth(res));
79
- *
80
- * const userAction = api("users.me");
81
- * const res = await api.execute(userAction, []);
82
- * ```
83
- */
84
- export declare function Fetcher(initialOptions?: FetcherOptions): IFetcherBuilder;
@@ -1 +0,0 @@
1
- "use strict";var e=require("./client.js"),t=require("./http.js");exports.Fetcher=function(r={}){const n=Object.assign({},r);n.middlewares=[...n.middlewares||[]];const s=n.http||new t.Http(n.baseURL),o=(e,t)=>{if(!e)return;(Array.isArray(e)?e:[e]).forEach(t)};o(n.request,e=>s.on("request",e)),o(n.response,e=>s.on("response",e)),o(n.transform,e=>s.on("transform",e)),o(n.error,e=>s.on("error",e));const a=function(t,r){return e.createClient({http:s,baseURL:n.baseURL,endpoint:n.endpoint})(t,r)};return a.execute=async function(e,t,r={}){var s;const o=Object.assign(Object.assign({},n),r);let a=-1;const i=o.middlewares||[],c=async r=>{if(r<=a)throw new Error("next() called multiple times");a=r;let n=i[r];if(r===i.length&&(n=async(e,t)=>await e.fn(...t)),n)return await n(e,t,()=>c(r+1))};let u=await c(0),l=0;const y=null!==(s=o.retryLimit)&&void 0!==s?s:1;for(;l<y&&o.shouldRetry&&await o.shouldRetry(u,e.key);){if(!(!o.onRetry||await o.onRetry(u,e.key)))break;l++,u=await e.fn(...t)}const f=Object.assign(Object.assign({},u),{args:t,key:e.key});return o.onResult&&await o.onResult(f,o),f},a.fetcher=async function(e,...t){return a.execute(e,t)},a.use=(...e)=>(n.middlewares.push(...e),a),a.request=e=>(s.on("request",e),a),a.response=e=>(s.on("response",e),a),a.transform=e=>(s.on("transform",e),a),a.error=e=>(s.on("error",e),a),a.shouldRetry=e=>(n.shouldRetry=e,a),a.retry=e=>(n.onRetry=e,a),a.onResult=e=>(n.onResult=e,a),a.config=e=>(Object.assign(n,e),a),Object.defineProperty(a,"http",{get:()=>s}),a};
@@ -1 +0,0 @@
1
- import{createClient as e}from"./client.mjs";import{Http as t}from"./http.mjs";function r(r={}){const n=Object.assign({},r);n.middlewares=[...n.middlewares||[]];const s=n.http||new t(n.baseURL),o=(e,t)=>{if(!e)return;(Array.isArray(e)?e:[e]).forEach(t)};o(n.request,e=>s.on("request",e)),o(n.response,e=>s.on("response",e)),o(n.transform,e=>s.on("transform",e)),o(n.error,e=>s.on("error",e));const a=function(t,r){return e({http:s,baseURL:n.baseURL,endpoint:n.endpoint})(t,r)};return a.execute=async function(e,t,r={}){var s;const o=Object.assign(Object.assign({},n),r);let a=-1;const i=o.middlewares||[],c=async r=>{if(r<=a)throw new Error("next() called multiple times");a=r;let n=i[r];if(r===i.length&&(n=async(e,t)=>await e.fn(...t)),n)return await n(e,t,()=>c(r+1))};let u=await c(0),l=0;const f=null!==(s=o.retryLimit)&&void 0!==s?s:1;for(;l<f&&o.shouldRetry&&await o.shouldRetry(u,e.key);){if(!(!o.onRetry||await o.onRetry(u,e.key)))break;l++,u=await e.fn(...t)}const y=Object.assign(Object.assign({},u),{args:t,key:e.key});return o.onResult&&await o.onResult(y,o),y},a.fetcher=async function(e,...t){return a.execute(e,t)},a.use=(...e)=>(n.middlewares.push(...e),a),a.request=e=>(s.on("request",e),a),a.response=e=>(s.on("response",e),a),a.transform=e=>(s.on("transform",e),a),a.error=e=>(s.on("error",e),a),a.shouldRetry=e=>(n.shouldRetry=e,a),a.retry=e=>(n.onRetry=e,a),a.onResult=e=>(n.onResult=e,a),a.config=e=>(Object.assign(n,e),a),Object.defineProperty(a,"http",{get:()=>s}),a}export{r as Fetcher};
@@ -1,5 +0,0 @@
1
- import { type HttpInit } from "./init";
2
- import type { HttpResponse } from "./response";
3
- export declare abstract class HttpCore {
4
- static request<DataType = unknown, Err = unknown>(init: HttpInit): Promise<HttpResponse<DataType, Err>>;
5
- }
@@ -1 +0,0 @@
1
- "use strict";var t=require("../node_modules/tslib/tslib.es6.js"),s=require("../utilities/formdata.js"),r=require("./array.js"),e=require("./init.js"),o=require("./method.js"),a=require("./utils.js");exports.HttpCore=class{static async request(i){var n,l,c,u,d;const f=e.getHttpInitSlice(i),{interceptors:p}=f,h=t.__rest(f,["interceptors"]);try{let t=Object.assign({},h);const e=r.asArray(null!==(n=null==p?void 0:p.request)&&void 0!==n?n:[]);for(const s of e)t=await s(t);const i=a.HttpUtils.normalizeURL(t),d=a.HttpUtils.normalizeHeaders(t.headers||{},s.isFormData(t.body)),f=await fetch(i,Object.assign(Object.assign({},a.HttpUtils.extractFetchOptions(t)),{method:t.method||o.Methods.GET,headers:d,body:a.HttpUtils.normalizeBody(t),signal:t.signal}));a.HttpUtils.assertSameOriginResponse(i,f,d);const v=f.headers.get("Content-Type")||"";let y=null;y=v.includes("application/json")?await f.json():await f.text();const j=r.asArray(null!==(l=null==p?void 0:p.transform)&&void 0!==l?l:[]);let m=y;for(const t of j)m=await t(m);const g=r.asArray(null!==(c=null==p?void 0:p.response)&&void 0!==c?c:[]);let w=f;for(const t of g)w=await t(w);const q={};w.headers.forEach((t,s)=>{q[s]=t});const H=w.ok;let b=null;if(!H){b=y.error||y;const t=r.asArray(null!==(u=null==p?void 0:p.error)&&void 0!==u?u:[]);for(const s of t)b=await s(b)}return{data:m,success:H,error:H?null:b,status:w.status,statusText:w.statusText,headers:q}}catch(t){let s=t instanceof Error?t:new Error(String(t));const e=r.asArray(null!==(d=null==p?void 0:p.error)&&void 0!==d?d:[]);for(const t of e)s=await t(s);return{data:null,status:0,statusText:"Error",headers:{},error:s,success:!1}}}};
@@ -1 +0,0 @@
1
- import{__rest as t}from"../node_modules/tslib/tslib.es6.mjs";import{isFormData as o}from"../utilities/formdata.mjs";import{asArray as s}from"./array.mjs";import{getHttpInitSlice as r}from"./init.mjs";import{Methods as e}from"./method.mjs";import{HttpUtils as n}from"./utils.mjs";class a{static async request(a){var i,l,c,u,d;const m=r(a),{interceptors:f}=m,p=t(m,["interceptors"]);try{let t=Object.assign({},p);const r=s(null!==(i=null==f?void 0:f.request)&&void 0!==i?i:[]);for(const o of r)t=await o(t);const a=n.normalizeURL(t),d=n.normalizeHeaders(t.headers||{},o(t.body)),m=await fetch(a,Object.assign(Object.assign({},n.extractFetchOptions(t)),{method:t.method||e.GET,headers:d,body:n.normalizeBody(t),signal:t.signal}));n.assertSameOriginResponse(a,m,d);const h=m.headers.get("Content-Type")||"";let j=null;j=h.includes("application/json")?await m.json():await m.text();const v=s(null!==(l=null==f?void 0:f.transform)&&void 0!==l?l:[]);let w=j;for(const t of v)w=await t(w);const g=s(null!==(c=null==f?void 0:f.response)&&void 0!==c?c:[]);let b=m;for(const t of g)b=await t(b);const y={};b.headers.forEach((t,o)=>{y[o]=t});const x=b.ok;let E=null;if(!x){E=j.error||j;const t=s(null!==(u=null==f?void 0:f.error)&&void 0!==u?u:[]);for(const o of t)E=await o(E)}return{data:w,success:x,error:x?null:E,status:b.status,statusText:b.statusText,headers:y}}catch(t){let o=t instanceof Error?t:new Error(String(t));const r=s(null!==(d=null==f?void 0:f.error)&&void 0!==d?d:[]);for(const t of r)o=await t(o);return{data:null,status:0,statusText:"Error",headers:{},error:o,success:!1}}}}export{a as HttpCore};
@@ -1,20 +0,0 @@
1
- import { HttpXML } from "./xml";
2
- import type { HttpInit } from "./init";
3
- export declare abstract class HttpStatic extends HttpXML {
4
- static method: {
5
- readonly GET: "GET";
6
- readonly POST: "POST";
7
- readonly PUT: "PUT";
8
- readonly DELETE: "DELETE";
9
- readonly PATCH: "PATCH";
10
- readonly HEAD: "HEAD";
11
- readonly OPTIONS: "OPTIONS";
12
- };
13
- static get<DataType = unknown, Err = unknown>(url: string, init?: Omit<HttpInit, "url" | "method">): Promise<import("./response").HttpResponse<DataType, Err>>;
14
- static post<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<import("./response").HttpResponse<DataType, Err>>;
15
- static put<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<import("./response").HttpResponse<DataType, Err>>;
16
- static patch<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<import("./response").HttpResponse<DataType, Err>>;
17
- static delete<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<import("./response").HttpResponse<DataType, Err>>;
18
- static head<DataType = unknown, Err = unknown>(url: string, init?: Omit<HttpInit, "url" | "method">): Promise<import("./response").HttpResponse<DataType, Err>>;
19
- static options<DataType = unknown, Err = unknown>(url: string, init?: Omit<HttpInit, "url" | "method">): Promise<import("./response").HttpResponse<DataType, Err>>;
20
- }
@@ -1 +0,0 @@
1
- "use strict";var t=require("./method.js"),s=require("./xml.js");class e extends s.HttpXML{static get(s,e){return this.request(Object.assign(Object.assign({},e),{url:s,method:t.Methods.GET}))}static post(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.Methods.POST,body:e}))}static put(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.Methods.PUT,body:e}))}static patch(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.Methods.PATCH,body:e}))}static delete(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.Methods.DELETE,body:e}))}static head(s,e){return this.request(Object.assign(Object.assign({},e),{url:s,method:t.Methods.HEAD}))}static options(s,e){return this.request(Object.assign(Object.assign({},e),{url:s,method:t.Methods.OPTIONS}))}}e.method=t.Methods,exports.HttpStatic=e;
@@ -1 +0,0 @@
1
- import{Methods as t}from"./method.mjs";import{HttpXML as s}from"./xml.mjs";class e extends s{static get(s,e){return this.request(Object.assign(Object.assign({},e),{url:s,method:t.GET}))}static post(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.POST,body:e}))}static put(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.PUT,body:e}))}static patch(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.PATCH,body:e}))}static delete(s,e,r){return this.request(Object.assign(Object.assign({},r),{url:s,method:t.DELETE,body:e}))}static head(s,e){return this.request(Object.assign(Object.assign({},e),{url:s,method:t.HEAD}))}static options(s,e){return this.request(Object.assign(Object.assign({},e),{url:s,method:t.OPTIONS}))}}e.method=t;export{e as HttpStatic};
@@ -1,56 +0,0 @@
1
- import { HttpStatic } from "./http-static";
2
- import { Endpoint } from "./endpoint";
3
- import type { HttpInit } from "./init";
4
- import type { HttpResponse } from "./response";
5
- import type { HttpUploadOptions, HttpRelatedOptions } from "./xml";
6
- import type { HttpInterceptorParameters } from "./init";
7
- import type { FileListLike } from "../utilities/filelist";
8
- export interface HttpOptions {
9
- baseURL?: string;
10
- allowedOrigins?: ReadonlyArray<string>;
11
- configs?: Record<string, unknown>;
12
- }
13
- export declare class Http extends HttpStatic {
14
- static readonly method: {
15
- readonly GET: "GET";
16
- readonly POST: "POST";
17
- readonly PUT: "PUT";
18
- readonly DELETE: "DELETE";
19
- readonly PATCH: "PATCH";
20
- readonly HEAD: "HEAD";
21
- readonly OPTIONS: "OPTIONS";
22
- };
23
- static readonly Endpoint: typeof Endpoint;
24
- private static interceptors;
25
- readonly method: {
26
- readonly GET: "GET";
27
- readonly POST: "POST";
28
- readonly PUT: "PUT";
29
- readonly DELETE: "DELETE";
30
- readonly PATCH: "PATCH";
31
- readonly HEAD: "HEAD";
32
- readonly OPTIONS: "OPTIONS";
33
- };
34
- readonly baseURL: string;
35
- private readonly allowedOrigins;
36
- private readonly defaultConfigs;
37
- private defaultHeaders;
38
- private interceptors;
39
- constructor(init?: string | HttpOptions);
40
- static on(...params: HttpInterceptorParameters): void;
41
- static off(...params: HttpInterceptorParameters): void;
42
- on(...params: HttpInterceptorParameters): this;
43
- off(...params: HttpInterceptorParameters): this;
44
- addHeaders(headers: Record<string, string>): void;
45
- private mergeConfig;
46
- request<DataType = unknown, Err = unknown>(init: HttpInit): Promise<HttpResponse<DataType, Err>>;
47
- get<DataType = unknown, Err = unknown>(url: string, init?: Omit<HttpInit, "url" | "method">): Promise<HttpResponse<DataType, Err>>;
48
- post<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<HttpResponse<DataType, Err>>;
49
- put<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<HttpResponse<DataType, Err>>;
50
- patch<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<HttpResponse<DataType, Err>>;
51
- delete<DataType = unknown, Err = unknown>(url: string, body?: unknown, init?: Omit<HttpInit, "url" | "method" | "body">): Promise<HttpResponse<DataType, Err>>;
52
- head<DataType = unknown, Err = unknown>(url: string, init?: Omit<HttpInit, "url" | "method">): Promise<HttpResponse<DataType, Err>>;
53
- options<DataType = unknown, Err = unknown>(url: string, init?: Omit<HttpInit, "url" | "method">): Promise<HttpResponse<DataType, Err>>;
54
- upload<DataType = unknown, Err = unknown>(url: string, file: File | File[] | FileListLike, options?: HttpUploadOptions & Omit<HttpInit, "url" | "method" | "body">): Promise<HttpResponse<DataType, Err>>;
55
- related<DataType = unknown, Err = unknown>(url: string, fileData: ArrayBuffer | Uint8Array, options: HttpRelatedOptions & Omit<HttpInit, "url" | "method" | "body">): Promise<HttpResponse<DataType, Err>>;
56
- }
package/dist/http/http.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var e=require("./method.js"),t=require("./http-static.js"),s=require("./xml.js"),r=require("./endpoint.js"),i=require("./utils.js");class o extends t.HttpStatic{constructor(e){var t,s,r;super(),this.method=o.method,this.defaultHeaders={},this.interceptors={request:[],response:[],transform:[],error:[]};const n="string"==typeof e||void 0===e?{baseURL:null!=e?e:"/"}:e;this.baseURL=null!==(s=null!==(t=n.baseURL)&&void 0!==t?t:"/")&&void 0!==s?s:"/";const a=new Set;for(const e of null!==(r=n.allowedOrigins)&&void 0!==r?r:[]){const t=i.HttpUtils.safeOrigin(e);if(!t)throw new Error(`Http: invalid allowedOrigins entry: ${e}`);a.add(t)}const d=i.HttpUtils.safeOrigin(this.baseURL);d&&a.add(d),this.allowedOrigins=a,this.defaultConfigs=n.configs||{},a.forEach(e=>i.HttpUtils.AllowedOrigins.add(e))}static on(...e){const[t,s]=e,r=o.interceptors[t];r.includes(s)||r.push(s),o.interceptors[t]=r}static off(...e){const[t,s]=e,r=o.interceptors[t];o.interceptors[t]=r.filter(e=>e!==s)}on(...e){const[t,s]=e,r=this.interceptors[t];return r.includes(s)||r.push(s),this.interceptors[t]=r,this}off(...e){const[t,s]=e,r=this.interceptors[t];return this.interceptors[t]=r.filter(e=>e!==s),this}addHeaders(e){this.defaultHeaders=Object.assign(Object.assign({},this.defaultHeaders),e)}mergeConfig(t){const s=[...o.interceptors.request,...this.interceptors.request,...t.request?Array.isArray(t.request)?t.request:[t.request]:[]],r=[...o.interceptors.transform,...this.interceptors.transform,...t.transform?Array.isArray(t.transform)?t.transform:[t.transform]:[]],i=[...o.interceptors.response,...this.interceptors.response,...t.response?Array.isArray(t.response)?t.response:[t.response]:[]],n=[...o.interceptors.error,...this.interceptors.error,...t.error?Array.isArray(t.error)?t.error:[t.error]:[]];let a=t.url;if(a.startsWith("//"))throw new Error(`Http: protocol-relative URLs are not allowed: ${a}`);if(!/^[a-z][a-z0-9+.-]*:/i.test(a)){const e=this.baseURL.replace(/\/+$/,""),t=a.replace(/^\/+/,"");a=e?`${e}/${t}`:`/${t}`}const d=Object.assign(Object.assign({},this.defaultHeaders),t.headers);return Object.assign(Object.assign(Object.assign({},this.defaultConfigs),t),{url:a,headers:d,request:s,transform:r,response:i,error:n,method:t.method||e.Methods.GET})}request(e){return t.HttpStatic.request(this.mergeConfig(e))}get(t,s){return this.request(Object.assign(Object.assign({},s),{url:t,method:e.Methods.GET}))}post(t,s,r){return this.request(Object.assign(Object.assign({},r),{url:t,method:e.Methods.POST,body:s}))}put(t,s,r){return this.request(Object.assign(Object.assign({},r),{url:t,method:e.Methods.PUT,body:s}))}patch(t,s,r){return this.request(Object.assign(Object.assign({},r),{url:t,method:e.Methods.PATCH,body:s}))}delete(t,s,r){return this.request(Object.assign(Object.assign({},r),{url:t,method:e.Methods.DELETE,body:s}))}head(t,s){return this.request(Object.assign(Object.assign({},s),{url:t,method:e.Methods.HEAD}))}options(t,s){return this.request(Object.assign(Object.assign({},s),{url:t,method:e.Methods.OPTIONS}))}upload(t,r,i){return s.HttpXML.upload(t,r,this.mergeConfig(Object.assign(Object.assign({},i),{url:t,method:e.Methods.POST})))}related(t,r,i){return s.HttpXML.related(t,r,this.mergeConfig(Object.assign(Object.assign({},i),{url:t,method:e.Methods.POST})))}}o.method=e.Methods,o.Endpoint=r.Endpoint,o.interceptors={request:[],response:[],transform:[],error:[]},exports.Http=o;
@@ -1 +0,0 @@
1
- import{Methods as e}from"./method.mjs";import{HttpStatic as r}from"./http-static.mjs";import{HttpXML as t}from"./xml.mjs";import{Endpoint as s}from"./endpoint.mjs";import{HttpUtils as o}from"./utils.mjs";class i extends r{constructor(e){var r,t,s;super(),this.method=i.method,this.defaultHeaders={},this.interceptors={request:[],response:[],transform:[],error:[]};const n="string"==typeof e||void 0===e?{baseURL:null!=e?e:"/"}:e;this.baseURL=null!==(t=null!==(r=n.baseURL)&&void 0!==r?r:"/")&&void 0!==t?t:"/";const a=new Set;for(const e of null!==(s=n.allowedOrigins)&&void 0!==s?s:[]){const r=o.safeOrigin(e);if(!r)throw new Error(`Http: invalid allowedOrigins entry: ${e}`);a.add(r)}const c=o.safeOrigin(this.baseURL);c&&a.add(c),this.allowedOrigins=a,this.defaultConfigs=n.configs||{},a.forEach(e=>o.AllowedOrigins.add(e))}static on(...e){const[r,t]=e,s=i.interceptors[r];s.includes(t)||s.push(t),i.interceptors[r]=s}static off(...e){const[r,t]=e,s=i.interceptors[r];i.interceptors[r]=s.filter(e=>e!==t)}on(...e){const[r,t]=e,s=this.interceptors[r];return s.includes(t)||s.push(t),this.interceptors[r]=s,this}off(...e){const[r,t]=e,s=this.interceptors[r];return this.interceptors[r]=s.filter(e=>e!==t),this}addHeaders(e){this.defaultHeaders=Object.assign(Object.assign({},this.defaultHeaders),e)}mergeConfig(r){const t=[...i.interceptors.request,...this.interceptors.request,...r.request?Array.isArray(r.request)?r.request:[r.request]:[]],s=[...i.interceptors.transform,...this.interceptors.transform,...r.transform?Array.isArray(r.transform)?r.transform:[r.transform]:[]],o=[...i.interceptors.response,...this.interceptors.response,...r.response?Array.isArray(r.response)?r.response:[r.response]:[]],n=[...i.interceptors.error,...this.interceptors.error,...r.error?Array.isArray(r.error)?r.error:[r.error]:[]];let a=r.url;if(a.startsWith("//"))throw new Error(`Http: protocol-relative URLs are not allowed: ${a}`);if(!/^[a-z][a-z0-9+.-]*:/i.test(a)){const e=this.baseURL.replace(/\/+$/,""),r=a.replace(/^\/+/,"");a=e?`${e}/${r}`:`/${r}`}const c=Object.assign(Object.assign({},this.defaultHeaders),r.headers);return Object.assign(Object.assign(Object.assign({},this.defaultConfigs),r),{url:a,headers:c,request:t,transform:s,response:o,error:n,method:r.method||e.GET})}request(e){return r.request(this.mergeConfig(e))}get(r,t){return this.request(Object.assign(Object.assign({},t),{url:r,method:e.GET}))}post(r,t,s){return this.request(Object.assign(Object.assign({},s),{url:r,method:e.POST,body:t}))}put(r,t,s){return this.request(Object.assign(Object.assign({},s),{url:r,method:e.PUT,body:t}))}patch(r,t,s){return this.request(Object.assign(Object.assign({},s),{url:r,method:e.PATCH,body:t}))}delete(r,t,s){return this.request(Object.assign(Object.assign({},s),{url:r,method:e.DELETE,body:t}))}head(r,t){return this.request(Object.assign(Object.assign({},t),{url:r,method:e.HEAD}))}options(r,t){return this.request(Object.assign(Object.assign({},t),{url:r,method:e.OPTIONS}))}upload(r,s,o){return t.upload(r,s,this.mergeConfig(Object.assign(Object.assign({},o),{url:r,method:e.POST})))}related(r,s,o){return t.related(r,s,this.mergeConfig(Object.assign(Object.assign({},o),{url:r,method:e.POST})))}}i.method=e,i.Endpoint=s,i.interceptors={request:[],response:[],transform:[],error:[]};export{i as Http};
@@ -1,14 +0,0 @@
1
- export * from "./array";
2
- export * from "./client";
3
- export * from "./endpoint";
4
- export * from "./fetcher";
5
- export * from "./http-static";
6
- export * from "./http";
7
- export * from "./init";
8
- export * from "./method";
9
- export * from "./plugins";
10
- export * from "./request";
11
- export * from "./response";
12
- export * from "./utils";
13
- export * from "./xml";
14
- export * from "./http-core";
@@ -1 +0,0 @@
1
- "use strict";var e=require("./array.js"),t=require("./client.js"),r=require("./endpoint.js"),s=require("./fetcher.js"),i=require("./http-static.js"),p=require("./http.js"),o=require("./init.js"),u=require("./method.js"),l=require("./plugins/logger.js"),n=require("./plugins/dedupe.js"),c=require("./plugins/cache.js"),a=require("./utils.js"),g=require("./xml.js"),x=require("./http-core.js");exports.asArray=e.asArray,exports.createClient=t.createClient,exports.Endpoint=r.Endpoint,exports.Fetcher=s.Fetcher,exports.HttpStatic=i.HttpStatic,exports.Http=p.Http,exports.getHttpInitSlice=o.getHttpInitSlice,exports.Methods=u.Methods,exports.Uploads=u.Uploads,exports.loggerPlugin=l.loggerPlugin,exports.dedupePlugin=n.dedupePlugin,exports.cachePlugin=c.cachePlugin,exports.HttpUtils=a.HttpUtils,exports.HttpXML=g.HttpXML,exports.HttpCore=x.HttpCore;
@@ -1 +0,0 @@
1
- export{asArray}from"./array.mjs";export{createClient}from"./client.mjs";export{Endpoint}from"./endpoint.mjs";export{Fetcher}from"./fetcher.mjs";export{HttpStatic}from"./http-static.mjs";export{Http}from"./http.mjs";export{getHttpInitSlice}from"./init.mjs";export{Methods,Uploads}from"./method.mjs";export{loggerPlugin}from"./plugins/logger.mjs";export{dedupePlugin}from"./plugins/dedupe.mjs";export{cachePlugin}from"./plugins/cache.mjs";export{HttpUtils}from"./utils.mjs";export{HttpXML}from"./xml.mjs";export{HttpCore}from"./http-core.mjs";