@agentcash/router 1.3.1 → 1.3.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.
- package/dist/index.cjs +33 -23
- package/dist/index.js +33 -23
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -330,30 +330,40 @@ __export(upstash_rest_exports, {
|
|
|
330
330
|
function createUpstashRest(url, token) {
|
|
331
331
|
const base = url.replace(/\/+$/, "");
|
|
332
332
|
const headers = { Authorization: `Bearer ${token}` };
|
|
333
|
+
async function get(key) {
|
|
334
|
+
const res = await fetch(`${base}/get/${key}`, { headers });
|
|
335
|
+
if (!res.ok) throw new Error(`[upstash-rest] GET ${key}: ${res.status}`);
|
|
336
|
+
const { result } = await res.json();
|
|
337
|
+
return result ?? null;
|
|
338
|
+
}
|
|
339
|
+
async function set(key, value) {
|
|
340
|
+
const res = await fetch(`${base}`, {
|
|
341
|
+
method: "POST",
|
|
342
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
343
|
+
body: JSON.stringify(["SET", key, JSON.stringify(value)])
|
|
344
|
+
});
|
|
345
|
+
if (!res.ok) throw new Error(`[upstash-rest] SET ${key}: ${res.status}`);
|
|
346
|
+
return await res.json();
|
|
347
|
+
}
|
|
348
|
+
async function del(key) {
|
|
349
|
+
const res = await fetch(`${base}`, {
|
|
350
|
+
method: "POST",
|
|
351
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
352
|
+
body: JSON.stringify(["DEL", key])
|
|
353
|
+
});
|
|
354
|
+
if (!res.ok) throw new Error(`[upstash-rest] DEL ${key}: ${res.status}`);
|
|
355
|
+
return await res.json();
|
|
356
|
+
}
|
|
333
357
|
return {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
headers: { ...headers, "Content-Type": "application/json" },
|
|
344
|
-
body: JSON.stringify(["SET", key, JSON.stringify(value)])
|
|
345
|
-
});
|
|
346
|
-
if (!res.ok) throw new Error(`[upstash-rest] SET ${key}: ${res.status}`);
|
|
347
|
-
return await res.json();
|
|
348
|
-
},
|
|
349
|
-
async del(key) {
|
|
350
|
-
const res = await fetch(`${base}`, {
|
|
351
|
-
method: "POST",
|
|
352
|
-
headers: { ...headers, "Content-Type": "application/json" },
|
|
353
|
-
body: JSON.stringify(["DEL", key])
|
|
354
|
-
});
|
|
355
|
-
if (!res.ok) throw new Error(`[upstash-rest] DEL ${key}: ${res.status}`);
|
|
356
|
-
return await res.json();
|
|
358
|
+
get,
|
|
359
|
+
set,
|
|
360
|
+
del,
|
|
361
|
+
async update(key, fn) {
|
|
362
|
+
const current = await get(key);
|
|
363
|
+
const change = fn(current);
|
|
364
|
+
if (change.op === "set") await set(key, change.value);
|
|
365
|
+
if (change.op === "delete") await del(key);
|
|
366
|
+
return change.result;
|
|
357
367
|
}
|
|
358
368
|
};
|
|
359
369
|
}
|
package/dist/index.js
CHANGED
|
@@ -308,30 +308,40 @@ __export(upstash_rest_exports, {
|
|
|
308
308
|
function createUpstashRest(url, token) {
|
|
309
309
|
const base = url.replace(/\/+$/, "");
|
|
310
310
|
const headers = { Authorization: `Bearer ${token}` };
|
|
311
|
+
async function get(key) {
|
|
312
|
+
const res = await fetch(`${base}/get/${key}`, { headers });
|
|
313
|
+
if (!res.ok) throw new Error(`[upstash-rest] GET ${key}: ${res.status}`);
|
|
314
|
+
const { result } = await res.json();
|
|
315
|
+
return result ?? null;
|
|
316
|
+
}
|
|
317
|
+
async function set(key, value) {
|
|
318
|
+
const res = await fetch(`${base}`, {
|
|
319
|
+
method: "POST",
|
|
320
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
321
|
+
body: JSON.stringify(["SET", key, JSON.stringify(value)])
|
|
322
|
+
});
|
|
323
|
+
if (!res.ok) throw new Error(`[upstash-rest] SET ${key}: ${res.status}`);
|
|
324
|
+
return await res.json();
|
|
325
|
+
}
|
|
326
|
+
async function del(key) {
|
|
327
|
+
const res = await fetch(`${base}`, {
|
|
328
|
+
method: "POST",
|
|
329
|
+
headers: { ...headers, "Content-Type": "application/json" },
|
|
330
|
+
body: JSON.stringify(["DEL", key])
|
|
331
|
+
});
|
|
332
|
+
if (!res.ok) throw new Error(`[upstash-rest] DEL ${key}: ${res.status}`);
|
|
333
|
+
return await res.json();
|
|
334
|
+
}
|
|
311
335
|
return {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
headers: { ...headers, "Content-Type": "application/json" },
|
|
322
|
-
body: JSON.stringify(["SET", key, JSON.stringify(value)])
|
|
323
|
-
});
|
|
324
|
-
if (!res.ok) throw new Error(`[upstash-rest] SET ${key}: ${res.status}`);
|
|
325
|
-
return await res.json();
|
|
326
|
-
},
|
|
327
|
-
async del(key) {
|
|
328
|
-
const res = await fetch(`${base}`, {
|
|
329
|
-
method: "POST",
|
|
330
|
-
headers: { ...headers, "Content-Type": "application/json" },
|
|
331
|
-
body: JSON.stringify(["DEL", key])
|
|
332
|
-
});
|
|
333
|
-
if (!res.ok) throw new Error(`[upstash-rest] DEL ${key}: ${res.status}`);
|
|
334
|
-
return await res.json();
|
|
336
|
+
get,
|
|
337
|
+
set,
|
|
338
|
+
del,
|
|
339
|
+
async update(key, fn) {
|
|
340
|
+
const current = await get(key);
|
|
341
|
+
const change = fn(current);
|
|
342
|
+
if (change.op === "set") await set(key, change.value);
|
|
343
|
+
if (change.op === "delete") await del(key);
|
|
344
|
+
return change.result;
|
|
335
345
|
}
|
|
336
346
|
};
|
|
337
347
|
}
|