klaim 1.3.0 → 1.5.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/README.md +233 -155
- package/deno.json +1 -1
- package/dist/klaim.cjs +1 -1
- package/dist/klaim.es.js +259 -110
- package/dist/klaim.umd.js +1 -1
- package/package.json +60 -60
- package/src/core/Api.ts +56 -1
- package/src/core/Cache.ts +72 -0
- package/src/core/Klaim.ts +211 -138
- package/src/core/Route.ts +288 -217
- package/src/tools/fetchWithCache.ts +30 -0
- package/src/tools/hashStr.ts +28 -0
- package/tests/05.cache.test.ts +46 -0
- package/tests/06.retry.test.ts +54 -0
- package/bun.lockb +0 -0
package/README.md
CHANGED
|
@@ -1,155 +1,233 @@
|
|
|
1
|
-
# Klaim 📦
|
|
2
|
-
|
|
3
|
-
[](https://jsr.io/@antharuu/klaim)
|
|
4
|
-
|
|
5
|
-
Klaim is a lightweight TypeScript library designed to manage APIs and record requests, optimized for an optimal user
|
|
6
|
-
experience.
|
|
7
|
-
|
|
8
|
-
## 📚 Table of Contents
|
|
9
|
-
|
|
10
|
-
- [Features](#-features)
|
|
11
|
-
- [Installation](#-installation)
|
|
12
|
-
- [Usage](#-usage)
|
|
13
|
-
- [Basic API Configuration](#basic-api-configuration)
|
|
14
|
-
- [Route Definition](#route-definition)
|
|
15
|
-
- [Request Handling](#request-handling)
|
|
16
|
-
- [Middleware Usage](#middleware-usage)
|
|
17
|
-
- [Hook Subscription](#hook-subscription)
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
30
|
-
- **
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
1
|
+
# Klaim 📦
|
|
2
|
+
|
|
3
|
+
[](https://jsr.io/@antharuu/klaim)
|
|
4
|
+
|
|
5
|
+
Klaim is a lightweight TypeScript library designed to manage APIs and record requests, optimized for an optimal user
|
|
6
|
+
experience.
|
|
7
|
+
|
|
8
|
+
## 📚 Table of Contents
|
|
9
|
+
|
|
10
|
+
- [Features](#-features)
|
|
11
|
+
- [Installation](#-installation)
|
|
12
|
+
- [Usage](#-usage)
|
|
13
|
+
- [Basic API Configuration](#basic-api-configuration)
|
|
14
|
+
- [Route Definition](#route-definition)
|
|
15
|
+
- [Request Handling](#request-handling)
|
|
16
|
+
- [Middleware Usage](#middleware-usage)
|
|
17
|
+
- [Hook Subscription](#hook-subscription)
|
|
18
|
+
- [Caching Requests](#caching-requests)
|
|
19
|
+
- [Retry Mechanism](#retry-mechanism)
|
|
20
|
+
- [Links](#-links)
|
|
21
|
+
- [Contributing](#-contributing)
|
|
22
|
+
- [License](#-license)
|
|
23
|
+
|
|
24
|
+
## 🚀 Features
|
|
25
|
+
|
|
26
|
+
- **Efficient API Management**: Easily manage multiple APIs with streamlined integration and interaction capabilities.
|
|
27
|
+
- **Request Recording**: Seamlessly track requests for debugging and monitoring.
|
|
28
|
+
- **User Experience Optimization**: Focused on performance and usability for a smooth user experience.
|
|
29
|
+
- **Lightweight**: Minimal footprint for fast load times and minimal performance impact.
|
|
30
|
+
- **Middleware Support**: Easily add middleware to modify requests and responses (`before` and `after`).
|
|
31
|
+
- **Hook System**: Subscribe to hooks to monitor and react to specific events.
|
|
32
|
+
- **Caching**: Enable caching on requests to reduce network load and improve performance.
|
|
33
|
+
- **Retry Mechanism**: Automatically retry failed requests to enhance reliability.
|
|
34
|
+
- **TypeScript Support**: Fully typed for enhanced code quality and developer experience.
|
|
35
|
+
|
|
36
|
+
## 📥 Installation
|
|
37
|
+
|
|
38
|
+
Install Klaim via npm:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
// Using npm
|
|
42
|
+
npm install klaim
|
|
43
|
+
|
|
44
|
+
// Using bun
|
|
45
|
+
bun add klaim
|
|
46
|
+
|
|
47
|
+
// Using deno
|
|
48
|
+
deno add @antharuu/klaim
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 🛠 Usage
|
|
52
|
+
|
|
53
|
+
### Basic API Configuration
|
|
54
|
+
|
|
55
|
+
First, set up the API configuration. Define the API and its base URL.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import {Api, Route} from 'klaim';
|
|
59
|
+
// For deno: import { Api, Route } from "@antharuu/klaim";
|
|
60
|
+
|
|
61
|
+
// Your simple Todo type
|
|
62
|
+
type Todo = {
|
|
63
|
+
userId: number;
|
|
64
|
+
id: number;
|
|
65
|
+
title: string;
|
|
66
|
+
completed: boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Create a new API with the name "hello" and the base URL "https://jsonplaceholder.typicode.com/"
|
|
70
|
+
Api.create("hello", "https://jsonplaceholder.typicode.com/", () => {
|
|
71
|
+
// Define routes for the API
|
|
72
|
+
Route.get<Todo[]>("listTodos", "todos");
|
|
73
|
+
Route.get<Todo>("getTodo", "todos/[id]");
|
|
74
|
+
Route.post<Todo>("addTodo", "todos");
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Route Definition
|
|
79
|
+
|
|
80
|
+
Define various routes within the API callback:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
Api.create("hello", "https://jsonplaceholder.typicode.com/", () => {
|
|
84
|
+
// Get a list of todos
|
|
85
|
+
Route.get<Todo[]>("listTodos", "todos");
|
|
86
|
+
|
|
87
|
+
// Get a specific todo by id
|
|
88
|
+
Route.get<Todo>("getTodo", "todos/[id]");
|
|
89
|
+
|
|
90
|
+
// Add a new todo
|
|
91
|
+
Route.post<Todo>("addTodo", "todos");
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Request Handling
|
|
96
|
+
|
|
97
|
+
Handle requests using the defined routes:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import {Klaim} from 'klaim';
|
|
101
|
+
// For deno: import { Klaim } from "@antharuu/klaim";
|
|
102
|
+
|
|
103
|
+
// Make a request to the "listTodos" route
|
|
104
|
+
const listOfTodos = await Klaim.hello.listTodos<Todo[]>();
|
|
105
|
+
|
|
106
|
+
// Make a request to the "getTodo" route with the parameter "id"
|
|
107
|
+
const todo = await Klaim.hello.getTodo<Todo>({id: 1});
|
|
108
|
+
|
|
109
|
+
// Make a request to the "addTodo" route
|
|
110
|
+
const newTodo = await Klaim.hello.addTodo<Todo>({}, {title: "New Todo", completed: false, userId: 1});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Middleware Usage
|
|
114
|
+
|
|
115
|
+
Add middleware to modify requests and responses. Use `before` middleware to alter requests before they are sent
|
|
116
|
+
and `after` middleware to process responses:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
Api.create("hello", "https://jsonplaceholder.typicode.com/", () => {
|
|
120
|
+
// With before middleware
|
|
121
|
+
Route.get<Todo>("getRandomTodo", "todos")
|
|
122
|
+
.before(({url}) => {
|
|
123
|
+
const random = Math.floor(Math.random() * 10) + 1;
|
|
124
|
+
return {url: `${url}/${random}`};
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// With after middleware
|
|
128
|
+
Route.get<Todo>("getFirstTodo", "todos")
|
|
129
|
+
.after(({data: [first]}) => ({data: first}));
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Hook Subscription
|
|
134
|
+
|
|
135
|
+
Subscribe to hooks to monitor specific events:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import {Hook} from 'klaim';
|
|
139
|
+
// For deno: import { Hook } from "@antharuu/klaim";
|
|
140
|
+
|
|
141
|
+
// Subscribe to the "hello.getFirstTodo" hook
|
|
142
|
+
Hook.subscribe("hello.getFirstTodo", ({url}) => {
|
|
143
|
+
console.log(`Requesting ${url}`);
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Caching Requests
|
|
148
|
+
|
|
149
|
+
Enable caching on requests to reduce network load and improve performance. By default, the cache duration is 20 seconds,
|
|
150
|
+
but you can specify a custom duration in seconds.
|
|
151
|
+
|
|
152
|
+
#### Caching Individual Routes
|
|
153
|
+
|
|
154
|
+
You can enable caching on individual routes:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
Api.create("hello", "https://jsonplaceholder.typicode.com/", () => {
|
|
158
|
+
// Get a list of todos with default cache duration (20 seconds)
|
|
159
|
+
Route.get<Todo[]>("listTodos", "todos").withCache();
|
|
160
|
+
|
|
161
|
+
// Get a specific todo by id with custom cache duration (300 seconds)
|
|
162
|
+
Route.get<Todo>("getTodo", "todos/[id]").withCache(300);
|
|
163
|
+
|
|
164
|
+
// Add a new todo (no cache)
|
|
165
|
+
Route.post<Todo>("addTodo", "todos");
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Now, when making requests, the caching feature will be applied.
|
|
170
|
+
|
|
171
|
+
#### Caching the Entire API
|
|
172
|
+
|
|
173
|
+
You can also enable caching for all routes defined within an API:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
Api.create("hello", "https://jsonplaceholder.typicode.com/", () => {
|
|
177
|
+
// Define routes for the API
|
|
178
|
+
Route.get<Todo[]>("listTodos", "todos");
|
|
179
|
+
Route.get<Todo>("getTodo", "todos/[id]");
|
|
180
|
+
Route.post<Todo>("addTodo", "todos");
|
|
181
|
+
}).withCache(); // Enable default cache duration (20 seconds) for all routes
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Retry Mechanism
|
|
185
|
+
|
|
186
|
+
Automatically retry failed requests to enhance reliability. You can specify the number of retry attempts for individual
|
|
187
|
+
routes or for the entire API.
|
|
188
|
+
|
|
189
|
+
#### Retry on Individual Routes
|
|
190
|
+
|
|
191
|
+
Enable retry on individual routes:
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
Api.create("hello", "https://jsonplaceholder.typicode.com/", () => {
|
|
195
|
+
// Get a list of todos with retry mechanism (default: 2)
|
|
196
|
+
Route.get<Todo[]>("listTodos", "todos").withRetry();
|
|
197
|
+
|
|
198
|
+
// Get a specific todo by id with retry mechanism (specified to 5)
|
|
199
|
+
Route.get<Todo>("getTodo", "todos/[id]").withRetry(5);
|
|
200
|
+
|
|
201
|
+
// Add a new todo (no retry)
|
|
202
|
+
Route.post<Todo>("addTodo", "todos");
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Retry the Entire API
|
|
207
|
+
|
|
208
|
+
Enable retry for all routes defined within an API:
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
Api.create("hello", "https://jsonplaceholder.typicode.com/", () => {
|
|
212
|
+
// Define routes for the API
|
|
213
|
+
Route.get<Todo[]>("listTodos", "todos");
|
|
214
|
+
Route.get<Todo>("getTodo", "todos/[id]");
|
|
215
|
+
Route.post<Todo>("addTodo", "todos");
|
|
216
|
+
}).withRetry();
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Now, when a request fails, it will be retried the specified number of times before ultimately failing.
|
|
220
|
+
|
|
221
|
+
## 🔗 Links
|
|
222
|
+
|
|
223
|
+
- [NPM](https://www.npmjs.com/package/klaim)
|
|
224
|
+
- [JSR](https://jsr.io/@antharuu/klaim)
|
|
225
|
+
- [GitHub](https://github.com/antharuu/klaim)
|
|
226
|
+
|
|
227
|
+
## 🤝 Contributing
|
|
228
|
+
|
|
229
|
+
Contributions are welcome! Please see the [Contributing Guide](CONTRIBUTING.md) for more details.
|
|
230
|
+
|
|
231
|
+
## 📜 License
|
|
232
|
+
|
|
233
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/deno.json
CHANGED
package/dist/klaim.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var S=Object.defineProperty;var k=(s,t,e)=>t in s?S(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var c=(s,t,e)=>k(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function E(s){return s.trim().replace(/^\/|\/$/g,"")}function P(s){return s.replace(/([-_][a-z])/gi,t=>t.toUpperCase().replace("-","").replace("_","")).replace(/(^\w)/,t=>t.toLowerCase())}const o=class o{constructor(){c(this,"cache");this.cache=new Map}static get i(){return o._instance||(o._instance=new o),o._instance}set(t,e,r){const a=Date.now()+r;this.cache.set(t,{data:e,expiry:a})}has(t){const e=this.cache.get(t);return e?Date.now()>e.expiry?(this.cache.delete(t),!1):!0:!1}get(t){return this.has(t)?this.cache.get(t).data:null}};c(o,"_instance");let f=o;function O(s){let r=2166136261;for(let n=0;n<s.length;n++)r^=s.charCodeAt(n),r*=16777619;let a=(r>>>0).toString(16).padStart(8,"0");for(;a.length<32;)r^=a.charCodeAt(a.length%a.length),r*=16777619,a+=(r>>>0).toString(16).padStart(8,"0");return a.substring(0,32)}async function _(s,t,e){const r=`${s.toString()}${JSON.stringify(t)}`,a=O(r);if(f.i.has(a))return f.i.get(a);const i=await(await fetch(s,t)).json();return f.i.set(a,i,e),i}class y{static subscribe(t,e){this._callbacks.set(t,e)}static run(t){const e=this._callbacks.get(t);e&&e()}}c(y,"_callbacks",new Map);var $=(s=>(s.GET="GET",s.POST="POST",s.PUT="PUT",s.DELETE="DELETE",s.PATCH="PATCH",s.OPTIONS="OPTIONS",s))($||{});class T{constructor(t,e,r,a="GET"){c(this,"api","undefined");c(this,"name");c(this,"url");c(this,"method");c(this,"headers");c(this,"arguments",new Set);c(this,"callbacks",{before:null,after:null,call:null});c(this,"cache",!1);c(this,"retry",!1);this.name=P(t),this.name!==t&&console.warn(`Route name "${t}" has been camelCased to "${this.name}"`),this.url=E(e),this.headers=r||{},this.method=a,this.detectArguments()}static createRoute(t,e,r,a){const n=new T(t,e,r,a);return h.i.registerRoute(n),n}static get(t,e,r={}){return this.createRoute(t,e,r,"GET")}static post(t,e,r){return this.createRoute(t,e,r,"POST")}static put(t,e,r){return this.createRoute(t,e,r,"PUT")}static delete(t,e,r){return this.createRoute(t,e,r,"DELETE")}static patch(t,e,r){return this.createRoute(t,e,r,"PATCH")}static options(t,e,r){return this.createRoute(t,e,r,"OPTIONS")}before(t){return this.callbacks.before=t,this}after(t){return this.callbacks.after=t,this}onCall(t){return this.callbacks.call=t,this}detectArguments(){const t=this.url.match(/\[([^\]]+)]/g);t&&t.forEach(e=>{const r=e.replace("[","").replace("]","");this.arguments.add(r)})}withCache(t=20){return this.cache=t,this}withRetry(t=2){return this.retry=t,this}}const b={};async function I(s,t,e={},r={}){let a=U(`${s.url}/${t.url}`,t,e),n={};r&&t.method!==$.GET&&(n.body=JSON.stringify(r)),n.headers={"Content-Type":"application/json",...s.headers,...t.headers},n.method=t.method;const{beforeRoute:i,beforeApi:u,beforeUrl:w,beforeConfig:d}=H({route:t,api:s,url:a,config:n});a=w,n=d,s=h.updateApi(u),t=h.updateRoute(i);const p=await D(s,t,a,n),{afterRoute:g,afterApi:m,afterData:A}=N({route:t,api:s,response:p,data:p});return h.updateApi(m),h.updateRoute(g),y.run(`${s.name}.${t.name}`),A}async function R(s,t,e,r){return s?await _(t,e,r.cache):await(await fetch(t,e)).json()}async function D(s,t,e,r){var p,g,m;const a=s.cache||t.cache,n=t.retry||s.retry||0;let i,u=0,w=!1;const d=((p=t.callbacks)==null?void 0:p.call)!==null?(g=t.callbacks)==null?void 0:g.call:(m=s.callbacks)==null?void 0:m.call;for(;u<=n&&!w;){d&&d();try{i=await R(a,e,r,s),w=!0}catch(A){if(u++,u>n)throw A.message=`Failed to fetch ${e} after ${n} attempts`,A}}return i}function U(s,t,e){let r=s;return t.arguments.forEach(a=>{if(e[a]===void 0)throw new Error(`Argument ${a} is missing`);r=r.replace(`[${a}]`,e[a])}),r}function H({route:s,api:t,url:e,config:r}){var n,i;const a=(i=(n=s.callbacks).before)==null?void 0:i.call(n,{route:s,api:t,url:e,config:r});return{beforeRoute:(a==null?void 0:a.route)||s,beforeApi:(a==null?void 0:a.api)||t,beforeUrl:(a==null?void 0:a.url)||e,beforeConfig:(a==null?void 0:a.config)||r}}function N({route:s,api:t,response:e,data:r}){var n,i;const a=(i=(n=s.callbacks).after)==null?void 0:i.call(n,{route:s,api:t,response:e,data:r});return{afterRoute:(a==null?void 0:a.route)||s,afterApi:(a==null?void 0:a.api)||t,afterResponse:(a==null?void 0:a.response)||e,afterData:(a==null?void 0:a.data)||r}}const l=class l{constructor(){c(this,"_apis",new Map);c(this,"_currentApi",null)}static get i(){return l._instance||(l._instance=new l),l._instance}registerApi(t){this._apis.set(t.name,t),b[t.name]={}}setCurrent(t){const e=this._apis.get(t);if(!e)throw new Error(`API ${t} not found`);this._currentApi=e}clearCurrent(){this._currentApi=null}registerRoute(t){if(!this._currentApi)throw new Error("No current API set, use Route only inside Api.create callback");t.api=this._currentApi.name,this._currentApi.routes.set(t.name,t),this.addToKlaimRoute(t.api,t)}getApi(t){return this._apis.get(t)}getRoute(t,e){const r=this._apis.get(t);if(!r)throw new Error(`API ${t} not found`);return r.routes.get(e)}static updateApi(t){return l.i._apis.has(t.name)||l.i.registerApi(t),l.i._apis.set(t.name,t),t}static updateRoute(t){const e=l.i._apis.get(t.api);if(!e)throw new Error(`API ${t.api} not found`);return e.routes.set(t.name,t),t}addToKlaimRoute(t,e){b[t][e.name]=async(r={},a={})=>{const n=l.i._apis.get(t);if(!n)throw new Error(`API ${e.api} not found`);return I(n,e,r,a)}}};c(l,"_instance");let h=l;class C{constructor(t,e,r={}){c(this,"name");c(this,"url");c(this,"headers");c(this,"routes",new Map);c(this,"callbacks",{call:null});c(this,"cache",!1);c(this,"retry",!1);this.name=t,this.url=E(e),this.headers=r}static create(t,e,r,a={}){const n=P(t);n!==t&&console.warn(`API name "${t}" has been camelCased to "${n}"`);const i=new C(n,e,a);return h.i.registerApi(i),h.i.setCurrent(n),r(),h.i.clearCurrent(),i}onCall(t){return this.callbacks.call=t,this}withCache(t=20){return this.cache=t,this}withRetry(t=2){return this.retry=t,this}}exports.Api=C;exports.Hook=y;exports.Klaim=b;exports.Registry=h;exports.Route=T;
|