@20baht/elysia-idempotency 0.1.2 → 0.1.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/CHANGELOG.md +9 -0
- package/README.md +6 -1
- package/dist/index.js +28 -22
- package/dist/index.js.map +3 -3
- package/dist/plugin.d.ts +13 -146
- package/dist/plugin.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @20baht/elysia-idempotency changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
An `idempotent` route keeps the handler's response type: the macro's `beforeHandle` is typed as returning
|
|
6
|
+
nothing, so Eden Treaty, `@20baht/ngx-eden` and `typedLive` no longer read `Response | <the body>` as the 200.
|
|
7
|
+
What is sent is unchanged (20baht-ecosystem#75).
|
|
8
|
+
|
|
9
|
+
A `console.warn` when the plugin is made without a `scope` (every caller then shares one set of keys). The README
|
|
10
|
+
says so, and that a `scope` returning `undefined` falls back to the shared set (20baht-ecosystem#40).
|
|
11
|
+
|
|
3
12
|
## 0.1.2
|
|
4
13
|
|
|
5
14
|
The fingerprint reads multipart file parts (name, type, size, SHA-256 of the bytes): the same key with a different
|
package/README.md
CHANGED
|
@@ -49,6 +49,9 @@ a SHA-256 of them is kept, never the body itself.
|
|
|
49
49
|
- **A streamed answer** (a generator, a `ReadableStream`) is not kept: a retry runs again. Return a value from a
|
|
50
50
|
route you mark `idempotent`.
|
|
51
51
|
- Only `content-type` and `location` are replayed (`replayHeaders` to choose); never a `set-cookie`.
|
|
52
|
+
- **The route's types stay the handler's.** The option adds no response to the route: an Eden client
|
|
53
|
+
(`@20baht/ngx-eden`, `typedLive`) reads the handler's body as the 200, not `Response | <body>`. The 400, 409
|
|
54
|
+
and 422 above are not in the route's types either; a client that wants them reads the status.
|
|
52
55
|
|
|
53
56
|
## Whose key
|
|
54
57
|
|
|
@@ -61,7 +64,9 @@ idempotency({ store, scope: ({ caller }) => (caller as Caller).subject });
|
|
|
61
64
|
|
|
62
65
|
`scope` is handed the route's context after every `resolve` has run: the `caller` that `auth` / `scope` from
|
|
63
66
|
`@20baht/elysia-resource-server` resolve is there, whatever their order on the route. Without `scope`, every caller
|
|
64
|
-
shares one set of keys, and one who sends another's key and the same request gets the other's answer.
|
|
67
|
+
shares one set of keys, and one who sends another's key and the same request gets the other's answer. The plugin
|
|
68
|
+
logs a `console.warn` once, when it is made without a `scope`. A `scope` that returns `undefined` for a request
|
|
69
|
+
falls back to the same shared set for that request, and logs nothing, so make it return something for every caller.
|
|
65
70
|
|
|
66
71
|
## How long a key holds
|
|
67
72
|
|
package/dist/index.js
CHANGED
|
@@ -159,14 +159,17 @@ var replay = (response) => {
|
|
|
159
159
|
};
|
|
160
160
|
var refusal = (status, error) => Response.json(error, { status });
|
|
161
161
|
var idempotency = (options) => {
|
|
162
|
+
if (options.scope === undefined) {
|
|
163
|
+
console.warn("@20baht/elysia-idempotency: no `scope` option, so every caller shares one set of keys: " + "a caller who sends another's key and the same request gets the other's answer. " + "Pass `scope: ({ caller }) => caller.subject`.");
|
|
164
|
+
}
|
|
162
165
|
const keys = createIdempotency(options);
|
|
163
166
|
const header = (options.header ?? "idempotency-key").toLowerCase();
|
|
164
167
|
const maxKeyLength = options.maxKeyLength ?? 255;
|
|
165
168
|
const keep = (options.replayHeaders ?? ["content-type", "location"]).map((name) => name.toLowerCase());
|
|
166
169
|
const running = new WeakMap;
|
|
167
170
|
return new Elysia({ name: "@20baht/elysia-idempotency", seed: header }).macro({
|
|
168
|
-
idempotent: (mode) =>
|
|
169
|
-
async
|
|
171
|
+
idempotent: (mode) => {
|
|
172
|
+
const beforeHandle = async (context) => {
|
|
170
173
|
if (mode === false)
|
|
171
174
|
return;
|
|
172
175
|
const key = context.headers[header];
|
|
@@ -203,26 +206,29 @@ var idempotency = (options) => {
|
|
|
203
206
|
message: `a request with this ${header} is still running`
|
|
204
207
|
});
|
|
205
208
|
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
beforeHandle,
|
|
212
|
+
async afterHandle({ request, responseValue, set }) {
|
|
213
|
+
const run = running.get(request);
|
|
214
|
+
if (!run)
|
|
215
|
+
return;
|
|
216
|
+
running.delete(request);
|
|
217
|
+
const response = await stored(responseValue, set, keep);
|
|
218
|
+
if (!response || response.status >= 500)
|
|
219
|
+
await run.abandon();
|
|
220
|
+
else
|
|
221
|
+
await run.complete(response);
|
|
222
|
+
},
|
|
223
|
+
async error({ request }) {
|
|
224
|
+
const run = running.get(request);
|
|
225
|
+
if (!run)
|
|
226
|
+
return;
|
|
227
|
+
running.delete(request);
|
|
214
228
|
await run.abandon();
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
async error({ request }) {
|
|
219
|
-
const run = running.get(request);
|
|
220
|
-
if (!run)
|
|
221
|
-
return;
|
|
222
|
-
running.delete(request);
|
|
223
|
-
await run.abandon();
|
|
224
|
-
}
|
|
225
|
-
})
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
226
232
|
});
|
|
227
233
|
};
|
|
228
234
|
export {
|
|
@@ -233,5 +239,5 @@ export {
|
|
|
233
239
|
createIdempotency
|
|
234
240
|
};
|
|
235
241
|
|
|
236
|
-
//# debugId=
|
|
242
|
+
//# debugId=749D70E57AB148C264756E2164756E21
|
|
237
243
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/core.ts", "../src/plugin.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"// An `Idempotency-Key` (IETF draft-ietf-httpapi-idempotency-key-header) worked out without a web\n// framework: the first request with a key reserves it and runs; its response is kept; a retry with the\n// same key and the same request gets that response back instead of a second write. The same key with a\n// different request, or while the first is still running, is a conflict.\n\n/** A response as it is kept, to be sent again for a retry. */\nexport interface StoredResponse {\n status: number;\n /** The headers worth sending again (`content-type`, `location`), lower case. */\n headers: Record<string, string>;\n /** The body as text, or base64 when `base64` is set (a body that is not text). */\n body: string;\n base64?: true;\n}\n\n/** A key as a store keeps it. */\nexport interface IdempotencyRecord {\n key: string;\n /** What the first request was: a retry with another one is refused. */\n fingerprint: string;\n status: 'pending' | 'completed';\n /** With `completed`. */\n response?: StoredResponse;\n createdAt: Date;\n}\n\n/**\n * Where keys are kept: `memoryStore()` for one process and tests, `pgStore` (`/pg`) and `sqliteStore`\n * (`/sqlite`, D1 too) for drizzle. Each call is one statement; `reserve` must be atomic, which an\n * insert on the primary key is.\n */\nexport interface IdempotencyStore {\n get(key: string): Promise<IdempotencyRecord | undefined>;\n /** Insert a `pending` record; `false` when the key is there already. */\n reserve(key: string, fingerprint: string, createdAt: Date): Promise<boolean>;\n /** The response of the key reserved at `createdAt`: it is `completed`. A key reserved since is left alone. */\n complete(key: string, createdAt: Date, response: StoredResponse): Promise<void>;\n /** Delete the key, only if it is still the record made at `createdAt` (not one reserved since). */\n remove(key: string, createdAt: Date): Promise<void>;\n /** Delete every record made before `before`; how many went. */\n purge(before: Date): Promise<number>;\n}\n\nexport interface IdempotencyOptions {\n store: IdempotencyStore;\n /** How long a key's response is sent again, in milliseconds. Default 24 hours. */\n ttl?: number;\n /**\n * How long a `pending` key holds before it counts as a request that died (a process killed mid-write\n * never releases its key), in milliseconds. Default 5 minutes. A handler running longer than this can\n * run twice.\n */\n pendingTimeout?: number;\n /** The clock. */\n now?: () => Date;\n}\n\n/** Why a request with a key does not run. */\nexport type IdempotencyConflict =\n /** The first request with the key has not finished. Retry later. */\n | 'in-progress'\n /** The key was used for a different request. A client bug, not a retry. */\n | 'mismatch';\n\n/** What a request with a key is to do. */\nexport type Begun =\n | {\n kind: 'run';\n /** Keep the response, for a retry. */\n complete(response: StoredResponse): Promise<void>;\n /** Give the key up (the handler threw): a retry runs again. */\n abandon(): Promise<void>;\n }\n | { kind: 'replay'; response: StoredResponse }\n | { kind: 'conflict'; reason: IdempotencyConflict };\n\nexport interface BeginInput {\n /** The client's key. */\n key: string;\n /**\n * Whose key it is (a user, a client): two callers' keys never meet. Without one, a caller who sends\n * another's key and the same request gets the other's response.\n */\n scope?: string | undefined;\n /** What the request is: `fingerprint(method, path, body)`. */\n fingerprint: string;\n}\n\nconst HOUR = 3_600_000;\n\n/** The key a store keeps: the scope's length first, so no scope and key run into another pair. */\nexport const storeKey = (scope: string | undefined, key: string): string =>\n scope === undefined ? `:${key}` : `${String(scope.length)}:${scope}:${key}`;\n\nconst hex = (bytes: ArrayBuffer): string =>\n [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, '0')).join('');\n\n/** A file part as its identity: name, type, size and the SHA-256 of its bytes (a `File` has no JSON form). */\nconst describeBlobs = async (value: unknown, depth = 0): Promise<unknown> => {\n if (value instanceof Blob)\n return {\n $blob: true,\n name: value instanceof File ? value.name : null,\n type: value.type,\n size: value.size,\n sha256: hex(await crypto.subtle.digest('SHA-256', await value.arrayBuffer())),\n };\n if (depth > 8 || value === null || typeof value !== 'object') return value;\n if (Array.isArray(value)) return Promise.all(value.map((item) => describeBlobs(item, depth + 1)));\n const out: Record<string, unknown> = {};\n for (const [name, item] of Object.entries(value))\n out[name] = await describeBlobs(item, depth + 1);\n return out;\n};\n\n/**\n * SHA-256 of the request: its method, its path with the query, and its body as JSON. A multipart\n * file part counts by its name, type, size and the hash of its bytes.\n */\nexport const fingerprint = async (method: string, path: string, body: unknown): Promise<string> => {\n const json = JSON.stringify([method.toUpperCase(), path, (await describeBlobs(body)) ?? null]);\n return hex(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(json)));\n};\n\n/** Keys worked out against a store. */\nexport interface Idempotency {\n begin(input: BeginInput): Promise<Begun>;\n /** Delete the keys past `ttl`: for a job that runs now and then. How many went. */\n purge(): Promise<number>;\n}\n\nexport const createIdempotency = (options: IdempotencyOptions): Idempotency => {\n const { store } = options;\n const ttl = options.ttl ?? 24 * HOUR;\n const pendingTimeout = options.pendingTimeout ?? HOUR / 12;\n const now = options.now ?? (() => new Date());\n\n /** A record that no longer counts: past `ttl`, or a pending one past `pendingTimeout`. */\n const lapsed = (record: IdempotencyRecord, at: number): boolean => {\n const age = at - record.createdAt.getTime();\n return age >= ttl || (record.status === 'pending' && age >= pendingTimeout);\n };\n\n const begin = async ({ key, scope, fingerprint }: BeginInput): Promise<Begun> => {\n const id = storeKey(scope, key);\n const at = now();\n const found = await store.get(id);\n if (found && lapsed(found, at.getTime())) await store.remove(id, found.createdAt);\n else if (found) {\n if (found.fingerprint !== fingerprint) return { kind: 'conflict', reason: 'mismatch' };\n if (found.status === 'completed' && found.response)\n return { kind: 'replay', response: found.response };\n return { kind: 'conflict', reason: 'in-progress' };\n }\n // two requests may both have found nothing: the insert lets one through\n if (!(await store.reserve(id, fingerprint, at)))\n return { kind: 'conflict', reason: 'in-progress' };\n return {\n kind: 'run',\n complete: (response) => store.complete(id, at, response),\n abandon: () => store.remove(id, at),\n };\n };\n\n return {\n begin,\n purge: () => store.purge(new Date(now().getTime() - ttl)),\n };\n};\n\n/** Keys kept in this process's memory: for tests, and a single process that may lose them on restart. */\nexport const memoryStore = (): IdempotencyStore & { readonly size: number } => {\n const records = new Map<string, IdempotencyRecord>();\n const copy = (record: IdempotencyRecord): IdempotencyRecord => structuredClone(record);\n return {\n get size() {\n return records.size;\n },\n get: (key) =>\n Promise.resolve(records.has(key) ? copy(records.get(key) as IdempotencyRecord) : undefined),\n reserve: (key, fingerprint, createdAt) => {\n if (records.has(key)) return Promise.resolve(false);\n records.set(key, { key, fingerprint, status: 'pending', createdAt: new Date(createdAt) });\n return Promise.resolve(true);\n },\n complete: (key, createdAt, response) => {\n const record = records.get(key);\n if (record?.createdAt.getTime() === createdAt.getTime())\n records.set(key, { ...record, status: 'completed', response: structuredClone(response) });\n return Promise.resolve();\n },\n remove: (key, createdAt) => {\n if (records.get(key)?.createdAt.getTime() === createdAt.getTime()) records.delete(key);\n return Promise.resolve();\n },\n purge: (before) => {\n let n = 0;\n for (const [key, record] of records)\n if (record.createdAt.getTime() < before.getTime()) {\n records.delete(key);\n n++;\n }\n return Promise.resolve(n);\n },\n };\n};\n",
|
|
6
|
-
"// `Idempotency-Key` on Elysia routes: the route option `idempotent` makes a route take the header.\n// The work is `createIdempotency`'s; this file reads the request and keeps the response.\nimport { Elysia, ElysiaCustomStatusResponse } from 'elysia';\nimport {\n createIdempotency,\n fingerprint,\n type Begun,\n type IdempotencyOptions,\n type StoredResponse,\n} from './core.ts';\n\n/** What `scope` is handed: the route's context, with whatever earlier plugins put on it (a `caller`). */\nexport type ScopeContext = Readonly<Record<string, unknown>> & {\n readonly request: Request;\n readonly headers: Readonly<Record<string, string | undefined>>;\n};\n\nexport interface IdempotencyPluginOptions extends IdempotencyOptions {\n /** The header the key comes in. Default `idempotency-key`. */\n header?: string;\n /** The longest key taken. Default 255. */\n maxKeyLength?: number;\n /**\n * Whose key it is: the signed-in caller (`({ caller }) => caller.subject`), so two callers' keys\n * never meet. It is handed the route's context after every `resolve` (an `auth` or `scope` option\n * included, whatever their order on the route). Without one, every caller shares one set of keys.\n */\n scope?: (context: ScopeContext) => string | undefined | Promise<string | undefined>;\n /** The response headers kept and sent again. Default `content-type` and `location`. */\n replayHeaders?: readonly string[];\n}\n\n/** The body of a refusal: a code to branch on, and a sentence. */\nexport interface IdempotencyError {\n code:\n | 'IDEMPOTENCY_KEY_MISSING'\n | 'IDEMPOTENCY_KEY_INVALID'\n | 'IDEMPOTENCY_KEY_REUSED'\n | 'IDEMPOTENCY_IN_PROGRESS';\n message: string;\n}\n\nconst TEXT = /^(text\\/|application\\/([\\w.+-]*\\+)?(json|xml|javascript|x-www-form-urlencoded))/i;\n\nconst base64 = (bytes: Uint8Array): string => {\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return btoa(binary);\n};\n\nconst fromBase64 = (text: string): Uint8Array =>\n Uint8Array.from(atob(text), (char) => char.charCodeAt(0));\n\n/** A `Response` as it is kept: its body as text, or base64 when its type is not text. */\nconst storedResponse = async (\n value: Response,\n keep: readonly string[],\n): Promise<StoredResponse> => {\n const headers: Record<string, string> = {};\n for (const name of keep) {\n const header = value.headers.get(name);\n if (header !== null) headers[name] = header;\n }\n const bytes = new Uint8Array(await value.clone().arrayBuffer());\n return TEXT.test(headers['content-type'] ?? 'text/plain')\n ? { status: value.status, headers, body: new TextDecoder().decode(bytes) }\n : { status: value.status, headers, body: base64(bytes), base64: true };\n};\n\n/** A value's body, as Elysia sends it: an object as JSON, a Blob as its bytes, anything else as text. */\nconst storedBody = async (\n body: unknown,\n headers: Record<string, string>,\n typed: boolean,\n): Promise<Pick<StoredResponse, 'body' | 'base64'>> => {\n if (body === undefined || body === null) return { body: '' };\n if (body instanceof Blob) {\n if (typed && body.type) headers['content-type'] ??= body.type;\n return { body: base64(new Uint8Array(await body.arrayBuffer())), base64: true };\n }\n if (typeof body === 'object') {\n if (typed) headers['content-type'] ??= 'application/json;charset=utf-8';\n return { body: JSON.stringify(body) };\n }\n if (typeof body === 'number' || typeof body === 'boolean' || typeof body === 'bigint')\n return { body: body.toString() };\n return { body: typeof body === 'string' ? body : '' };\n};\n\nconst isStream = (body: unknown): boolean =>\n typeof body === 'object' &&\n body !== null &&\n (Symbol.asyncIterator in body || body instanceof ReadableStream);\n\n/** The parts of a response kept for a retry, as Elysia would have sent it; `undefined` for a stream. */\nconst stored = async (\n value: unknown,\n set: { status?: number | string; headers: Record<string, unknown> },\n keep: readonly string[],\n): Promise<StoredResponse | undefined> => {\n if (value instanceof Response) return storedResponse(value, keep);\n const custom = value instanceof ElysiaCustomStatusResponse;\n const body: unknown = custom ? value.response : value;\n if (isStream(body)) return undefined;\n const status = custom ? Number(value.code) : typeof set.status === 'number' ? set.status : 200;\n const headers: Record<string, string> = {};\n for (const name of keep) {\n const header = set.headers[name];\n if (typeof header === 'string') headers[name] = header;\n }\n return { status, headers, ...(await storedBody(body, headers, keep.includes('content-type'))) };\n};\n\nconst replay = (response: StoredResponse): Response => {\n const headers = new Headers(response.headers);\n headers.set('idempotent-replayed', 'true');\n const body = response.base64 ? fromBase64(response.body) : response.body;\n // a 204 or a 304 has no body at all, not an empty one\n const empty =\n response.status === 204 ||\n response.status === 304 ||\n (response.body === '' && !response.base64);\n return new Response(empty ? null : (body as BodyInit), { status: response.status, headers });\n};\n\nconst refusal = (status: number, error: IdempotencyError): Response =>\n Response.json(error, { status });\n\n/**\n * The route option `idempotent`: `true` takes an `Idempotency-Key` when one is sent, `'required'`\n * refuses a request without one (400). A retry with the same key and request gets the first response\n * again (`Idempotent-Replayed: true`); the same key with another request is a 422, and while the first\n * is running a 409. A handler that throws, or answers 5xx, gives its key up so a retry runs again.\n */\nexport const idempotency = (options: IdempotencyPluginOptions) => {\n const keys = createIdempotency(options);\n const header = (options.header ?? 'idempotency-key').toLowerCase();\n const maxKeyLength = options.maxKeyLength ?? 255;\n const keep = (options.replayHeaders ?? ['content-type', 'location']).map((name) =>\n name.toLowerCase(),\n );\n /** The run a request is part of, from `beforeHandle` to the response. */\n const running = new WeakMap<Request, Extract<Begun, { kind: 'run' }>>();\n\n return new Elysia({ name: '@20baht/elysia-idempotency', seed: header }).macro({\n idempotent: (mode: boolean | 'required') =>
|
|
6
|
+
"// `Idempotency-Key` on Elysia routes: the route option `idempotent` makes a route take the header.\n// The work is `createIdempotency`'s; this file reads the request and keeps the response.\nimport { Elysia, ElysiaCustomStatusResponse } from 'elysia';\nimport {\n createIdempotency,\n fingerprint,\n type Begun,\n type IdempotencyOptions,\n type StoredResponse,\n} from './core.ts';\n\n/** What `scope` is handed: the route's context, with whatever earlier plugins put on it (a `caller`). */\nexport type ScopeContext = Readonly<Record<string, unknown>> & {\n readonly request: Request;\n readonly headers: Readonly<Record<string, string | undefined>>;\n};\n\nexport interface IdempotencyPluginOptions extends IdempotencyOptions {\n /** The header the key comes in. Default `idempotency-key`. */\n header?: string;\n /** The longest key taken. Default 255. */\n maxKeyLength?: number;\n /**\n * Whose key it is: the signed-in caller (`({ caller }) => caller.subject`), so two callers' keys\n * never meet. It is handed the route's context after every `resolve` (an `auth` or `scope` option\n * included, whatever their order on the route). Without one, every caller shares one set of keys.\n */\n scope?: (context: ScopeContext) => string | undefined | Promise<string | undefined>;\n /** The response headers kept and sent again. Default `content-type` and `location`. */\n replayHeaders?: readonly string[];\n}\n\n/** The body of a refusal: a code to branch on, and a sentence. */\nexport interface IdempotencyError {\n code:\n | 'IDEMPOTENCY_KEY_MISSING'\n | 'IDEMPOTENCY_KEY_INVALID'\n | 'IDEMPOTENCY_KEY_REUSED'\n | 'IDEMPOTENCY_IN_PROGRESS';\n message: string;\n}\n\nconst TEXT = /^(text\\/|application\\/([\\w.+-]*\\+)?(json|xml|javascript|x-www-form-urlencoded))/i;\n\nconst base64 = (bytes: Uint8Array): string => {\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return btoa(binary);\n};\n\nconst fromBase64 = (text: string): Uint8Array =>\n Uint8Array.from(atob(text), (char) => char.charCodeAt(0));\n\n/** A `Response` as it is kept: its body as text, or base64 when its type is not text. */\nconst storedResponse = async (\n value: Response,\n keep: readonly string[],\n): Promise<StoredResponse> => {\n const headers: Record<string, string> = {};\n for (const name of keep) {\n const header = value.headers.get(name);\n if (header !== null) headers[name] = header;\n }\n const bytes = new Uint8Array(await value.clone().arrayBuffer());\n return TEXT.test(headers['content-type'] ?? 'text/plain')\n ? { status: value.status, headers, body: new TextDecoder().decode(bytes) }\n : { status: value.status, headers, body: base64(bytes), base64: true };\n};\n\n/** A value's body, as Elysia sends it: an object as JSON, a Blob as its bytes, anything else as text. */\nconst storedBody = async (\n body: unknown,\n headers: Record<string, string>,\n typed: boolean,\n): Promise<Pick<StoredResponse, 'body' | 'base64'>> => {\n if (body === undefined || body === null) return { body: '' };\n if (body instanceof Blob) {\n if (typed && body.type) headers['content-type'] ??= body.type;\n return { body: base64(new Uint8Array(await body.arrayBuffer())), base64: true };\n }\n if (typeof body === 'object') {\n if (typed) headers['content-type'] ??= 'application/json;charset=utf-8';\n return { body: JSON.stringify(body) };\n }\n if (typeof body === 'number' || typeof body === 'boolean' || typeof body === 'bigint')\n return { body: body.toString() };\n return { body: typeof body === 'string' ? body : '' };\n};\n\nconst isStream = (body: unknown): boolean =>\n typeof body === 'object' &&\n body !== null &&\n (Symbol.asyncIterator in body || body instanceof ReadableStream);\n\n/** The parts of a response kept for a retry, as Elysia would have sent it; `undefined` for a stream. */\nconst stored = async (\n value: unknown,\n set: { status?: number | string; headers: Record<string, unknown> },\n keep: readonly string[],\n): Promise<StoredResponse | undefined> => {\n if (value instanceof Response) return storedResponse(value, keep);\n const custom = value instanceof ElysiaCustomStatusResponse;\n const body: unknown = custom ? value.response : value;\n if (isStream(body)) return undefined;\n const status = custom ? Number(value.code) : typeof set.status === 'number' ? set.status : 200;\n const headers: Record<string, string> = {};\n for (const name of keep) {\n const header = set.headers[name];\n if (typeof header === 'string') headers[name] = header;\n }\n return { status, headers, ...(await storedBody(body, headers, keep.includes('content-type'))) };\n};\n\nconst replay = (response: StoredResponse): Response => {\n const headers = new Headers(response.headers);\n headers.set('idempotent-replayed', 'true');\n const body = response.base64 ? fromBase64(response.body) : response.body;\n // a 204 or a 304 has no body at all, not an empty one\n const empty =\n response.status === 204 ||\n response.status === 304 ||\n (response.body === '' && !response.base64);\n return new Response(empty ? null : (body as BodyInit), { status: response.status, headers });\n};\n\n/**\n * A `beforeHandle` whose answers stay out of the route's types. Elysia adds what a macro's\n * `beforeHandle` may return to the route's 200 (here a `Response`: a replay or a refusal), so every\n * Eden client would read `Response | <the handler's body>`. Typed as returning `void`, it adds\n * nothing; at run time the function is the same one, so the `Response` is still sent.\n */\ntype UntypedBeforeHandle = (context: ScopeContext & { readonly body: unknown }) => void;\n\nconst refusal = (status: number, error: IdempotencyError): Response =>\n Response.json(error, { status });\n\n/**\n * The route option `idempotent`: `true` takes an `Idempotency-Key` when one is sent, `'required'`\n * refuses a request without one (400). A retry with the same key and request gets the first response\n * again (`Idempotent-Replayed: true`); the same key with another request is a 422, and while the first\n * is running a 409. A handler that throws, or answers 5xx, gives its key up so a retry runs again.\n */\nexport const idempotency = (options: IdempotencyPluginOptions) => {\n if (options.scope === undefined) {\n console.warn(\n '@20baht/elysia-idempotency: no `scope` option, so every caller shares one set of keys: ' +\n \"a caller who sends another's key and the same request gets the other's answer. \" +\n 'Pass `scope: ({ caller }) => caller.subject`.',\n );\n }\n const keys = createIdempotency(options);\n const header = (options.header ?? 'idempotency-key').toLowerCase();\n const maxKeyLength = options.maxKeyLength ?? 255;\n const keep = (options.replayHeaders ?? ['content-type', 'location']).map((name) =>\n name.toLowerCase(),\n );\n /** The run a request is part of, from `beforeHandle` to the response. */\n const running = new WeakMap<Request, Extract<Begun, { kind: 'run' }>>();\n\n return new Elysia({ name: '@20baht/elysia-idempotency', seed: header }).macro({\n idempotent: (mode: boolean | 'required') => {\n // declared, not wrapped: the route reads this type, the bundle carries no helper\n // eslint-disable-next-line @typescript-eslint/no-misused-promises -- Elysia awaits beforeHandle; `void` only keeps its Response out of the route's types\n const beforeHandle: UntypedBeforeHandle = async (context) => {\n if (mode === false) return undefined;\n const key = context.headers[header];\n if (key === undefined || key === '') {\n return mode === 'required'\n ? refusal(400, {\n code: 'IDEMPOTENCY_KEY_MISSING',\n message: `this request needs an ${header} header`,\n })\n : undefined;\n }\n if (key.length > maxKeyLength)\n return refusal(400, {\n code: 'IDEMPOTENCY_KEY_INVALID',\n message: `an ${header} is at most ${String(maxKeyLength)} characters`,\n });\n const url = new URL(context.request.url);\n const scope = await options.scope?.(context);\n const begun = await keys.begin({\n key,\n scope,\n fingerprint: await fingerprint(\n context.request.method,\n url.pathname + url.search,\n context.body,\n ),\n });\n switch (begun.kind) {\n case 'run':\n running.set(context.request, begun);\n return undefined;\n case 'replay':\n return replay(begun.response);\n case 'conflict':\n return begun.reason === 'mismatch'\n ? refusal(422, {\n code: 'IDEMPOTENCY_KEY_REUSED',\n message: `this ${header} was used for a different request`,\n })\n : refusal(409, {\n code: 'IDEMPOTENCY_IN_PROGRESS',\n message: `a request with this ${header} is still running`,\n });\n }\n };\n return {\n beforeHandle,\n async afterHandle({ request, responseValue, set }) {\n const run = running.get(request);\n if (!run) return;\n running.delete(request);\n const response = await stored(responseValue, set, keep);\n if (!response || response.status >= 500) await run.abandon();\n else await run.complete(response);\n },\n async error({ request }) {\n const run = running.get(request);\n if (!run) return;\n running.delete(request);\n await run.abandon();\n },\n };\n },\n });\n};\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;AAwFA,IAAM,OAAO;AAGN,IAAM,WAAW,CAAC,OAA2B,QAClD,UAAU,YAAY,IAAI,QAAQ,GAAG,OAAO,MAAM,MAAM,KAAK,SAAS;AAExE,IAAM,MAAM,CAAC,UACX,CAAC,GAAG,IAAI,WAAW,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAGtF,IAAM,gBAAgB,OAAO,OAAgB,QAAQ,MAAwB;AAAA,EAC3E,IAAI,iBAAiB;AAAA,IACnB,OAAO;AAAA,MACL,OAAO;AAAA,MACP,MAAM,iBAAiB,OAAO,MAAM,OAAO;AAAA,MAC3C,MAAM,MAAM;AAAA,MACZ,MAAM,MAAM;AAAA,MACZ,QAAQ,IAAI,MAAM,OAAO,OAAO,OAAO,WAAW,MAAM,MAAM,YAAY,CAAC,CAAC;AAAA,IAC9E;AAAA,EACF,IAAI,QAAQ,KAAK,UAAU,QAAQ,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACrE,IAAI,MAAM,QAAQ,KAAK;AAAA,IAAG,OAAO,QAAQ,IAAI,MAAM,IAAI,CAAC,SAAS,cAAc,MAAM,QAAQ,CAAC,CAAC,CAAC;AAAA,EAChG,MAAM,MAA+B,CAAC;AAAA,EACtC,YAAY,MAAM,SAAS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W,MAAM,OAAO,eAAe,KAAK,IAAI;AAAA,UACtD,IAAI,CAAC,YAAY,SAAS,UAAU;AAAA,YAAK,MAAM,IAAI,QAAQ;AAAA,UACtD;AAAA,kBAAM,IAAI,SAAS,QAAQ;AAAA;AAAA,aAE5B,MAAK,GAAG,WAAW;AAAA,UACvB,MAAM,MAAM,QAAQ,IAAI,OAAO;AAAA,UAC/B,IAAI,CAAC;AAAA,YAAK;AAAA,UACV,QAAQ,OAAO,OAAO;AAAA,UACtB,MAAM,IAAI,QAAQ;AAAA;AAAA,MAEtB;AAAA;AAAA,EAEJ,CAAC;AAAA;",
|
|
9
|
+
"debugId": "749D70E57AB148C264756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -24,6 +24,15 @@ export interface IdempotencyError {
|
|
|
24
24
|
code: 'IDEMPOTENCY_KEY_MISSING' | 'IDEMPOTENCY_KEY_INVALID' | 'IDEMPOTENCY_KEY_REUSED' | 'IDEMPOTENCY_IN_PROGRESS';
|
|
25
25
|
message: string;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* A `beforeHandle` whose answers stay out of the route's types. Elysia adds what a macro's
|
|
29
|
+
* `beforeHandle` may return to the route's 200 (here a `Response`: a replay or a refusal), so every
|
|
30
|
+
* Eden client would read `Response | <the handler's body>`. Typed as returning `void`, it adds
|
|
31
|
+
* nothing; at run time the function is the same one, so the `Response` is still sent.
|
|
32
|
+
*/
|
|
33
|
+
type UntypedBeforeHandle = (context: ScopeContext & {
|
|
34
|
+
readonly body: unknown;
|
|
35
|
+
}) => void;
|
|
27
36
|
/**
|
|
28
37
|
* The route option `idempotent`: `true` takes an `Idempotency-Key` when one is sent, `'required'`
|
|
29
38
|
* refuses a request without one (400). A retry with the same key and request gets the first response
|
|
@@ -46,150 +55,7 @@ export declare const idempotency: (options: IdempotencyPluginOptions) => Elysia<
|
|
|
46
55
|
}>;
|
|
47
56
|
macroFn: {
|
|
48
57
|
readonly idempotent: (mode: boolean | "required") => {
|
|
49
|
-
readonly beforeHandle:
|
|
50
|
-
body: unknown;
|
|
51
|
-
query: Record<string, string>;
|
|
52
|
-
params: {};
|
|
53
|
-
headers: Record<string, string | undefined>;
|
|
54
|
-
cookie: Record<string, import("elysia").Cookie<unknown>>;
|
|
55
|
-
server: import("elysia/universal/server").Server | null;
|
|
56
|
-
redirect: import("elysia").redirect;
|
|
57
|
-
set: {
|
|
58
|
-
headers: import("elysia").HTTPHeaders;
|
|
59
|
-
status?: number | keyof import("elysia").StatusMap;
|
|
60
|
-
redirect?: string;
|
|
61
|
-
cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
|
|
62
|
-
};
|
|
63
|
-
path: string;
|
|
64
|
-
route: string;
|
|
65
|
-
request: Request;
|
|
66
|
-
store: {};
|
|
67
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 | 400 | 422 | 409 | 100 | 101 | 102 | 103 | 201 | 202 | 203 | 205 | 206 | 207 | 208 | 300 | 301 | 302 | 303 | 307 | 308 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
|
|
68
|
-
readonly 100: "Continue";
|
|
69
|
-
readonly 101: "Switching Protocols";
|
|
70
|
-
readonly 102: "Processing";
|
|
71
|
-
readonly 103: "Early Hints";
|
|
72
|
-
readonly 200: "OK";
|
|
73
|
-
readonly 201: "Created";
|
|
74
|
-
readonly 202: "Accepted";
|
|
75
|
-
readonly 203: "Non-Authoritative Information";
|
|
76
|
-
readonly 204: "No Content";
|
|
77
|
-
readonly 205: "Reset Content";
|
|
78
|
-
readonly 206: "Partial Content";
|
|
79
|
-
readonly 207: "Multi-Status";
|
|
80
|
-
readonly 208: "Already Reported";
|
|
81
|
-
readonly 300: "Multiple Choices";
|
|
82
|
-
readonly 301: "Moved Permanently";
|
|
83
|
-
readonly 302: "Found";
|
|
84
|
-
readonly 303: "See Other";
|
|
85
|
-
readonly 304: "Not Modified";
|
|
86
|
-
readonly 307: "Temporary Redirect";
|
|
87
|
-
readonly 308: "Permanent Redirect";
|
|
88
|
-
readonly 400: "Bad Request";
|
|
89
|
-
readonly 401: "Unauthorized";
|
|
90
|
-
readonly 402: "Payment Required";
|
|
91
|
-
readonly 403: "Forbidden";
|
|
92
|
-
readonly 404: "Not Found";
|
|
93
|
-
readonly 405: "Method Not Allowed";
|
|
94
|
-
readonly 406: "Not Acceptable";
|
|
95
|
-
readonly 407: "Proxy Authentication Required";
|
|
96
|
-
readonly 408: "Request Timeout";
|
|
97
|
-
readonly 409: "Conflict";
|
|
98
|
-
readonly 410: "Gone";
|
|
99
|
-
readonly 411: "Length Required";
|
|
100
|
-
readonly 412: "Precondition Failed";
|
|
101
|
-
readonly 413: "Payload Too Large";
|
|
102
|
-
readonly 414: "URI Too Long";
|
|
103
|
-
readonly 415: "Unsupported Media Type";
|
|
104
|
-
readonly 416: "Range Not Satisfiable";
|
|
105
|
-
readonly 417: "Expectation Failed";
|
|
106
|
-
readonly 418: "I'm a teapot";
|
|
107
|
-
readonly 420: "Enhance Your Calm";
|
|
108
|
-
readonly 421: "Misdirected Request";
|
|
109
|
-
readonly 422: "Unprocessable Content";
|
|
110
|
-
readonly 423: "Locked";
|
|
111
|
-
readonly 424: "Failed Dependency";
|
|
112
|
-
readonly 425: "Too Early";
|
|
113
|
-
readonly 426: "Upgrade Required";
|
|
114
|
-
readonly 428: "Precondition Required";
|
|
115
|
-
readonly 429: "Too Many Requests";
|
|
116
|
-
readonly 431: "Request Header Fields Too Large";
|
|
117
|
-
readonly 451: "Unavailable For Legal Reasons";
|
|
118
|
-
readonly 500: "Internal Server Error";
|
|
119
|
-
readonly 501: "Not Implemented";
|
|
120
|
-
readonly 502: "Bad Gateway";
|
|
121
|
-
readonly 503: "Service Unavailable";
|
|
122
|
-
readonly 504: "Gateway Timeout";
|
|
123
|
-
readonly 505: "HTTP Version Not Supported";
|
|
124
|
-
readonly 506: "Variant Also Negotiates";
|
|
125
|
-
readonly 507: "Insufficient Storage";
|
|
126
|
-
readonly 508: "Loop Detected";
|
|
127
|
-
readonly 510: "Not Extended";
|
|
128
|
-
readonly 511: "Network Authentication Required";
|
|
129
|
-
}[Code] : Code>(code: Code, response?: T) => ElysiaCustomStatusResponse<Code, T, Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
|
|
130
|
-
readonly Continue: 100;
|
|
131
|
-
readonly "Switching Protocols": 101;
|
|
132
|
-
readonly Processing: 102;
|
|
133
|
-
readonly "Early Hints": 103;
|
|
134
|
-
readonly OK: 200;
|
|
135
|
-
readonly Created: 201;
|
|
136
|
-
readonly Accepted: 202;
|
|
137
|
-
readonly "Non-Authoritative Information": 203;
|
|
138
|
-
readonly "No Content": 204;
|
|
139
|
-
readonly "Reset Content": 205;
|
|
140
|
-
readonly "Partial Content": 206;
|
|
141
|
-
readonly "Multi-Status": 207;
|
|
142
|
-
readonly "Already Reported": 208;
|
|
143
|
-
readonly "Multiple Choices": 300;
|
|
144
|
-
readonly "Moved Permanently": 301;
|
|
145
|
-
readonly Found: 302;
|
|
146
|
-
readonly "See Other": 303;
|
|
147
|
-
readonly "Not Modified": 304;
|
|
148
|
-
readonly "Temporary Redirect": 307;
|
|
149
|
-
readonly "Permanent Redirect": 308;
|
|
150
|
-
readonly "Bad Request": 400;
|
|
151
|
-
readonly Unauthorized: 401;
|
|
152
|
-
readonly "Payment Required": 402;
|
|
153
|
-
readonly Forbidden: 403;
|
|
154
|
-
readonly "Not Found": 404;
|
|
155
|
-
readonly "Method Not Allowed": 405;
|
|
156
|
-
readonly "Not Acceptable": 406;
|
|
157
|
-
readonly "Proxy Authentication Required": 407;
|
|
158
|
-
readonly "Request Timeout": 408;
|
|
159
|
-
readonly Conflict: 409;
|
|
160
|
-
readonly Gone: 410;
|
|
161
|
-
readonly "Length Required": 411;
|
|
162
|
-
readonly "Precondition Failed": 412;
|
|
163
|
-
readonly "Payload Too Large": 413;
|
|
164
|
-
readonly "URI Too Long": 414;
|
|
165
|
-
readonly "Unsupported Media Type": 415;
|
|
166
|
-
readonly "Range Not Satisfiable": 416;
|
|
167
|
-
readonly "Expectation Failed": 417;
|
|
168
|
-
readonly "I'm a teapot": 418;
|
|
169
|
-
readonly "Enhance Your Calm": 420;
|
|
170
|
-
readonly "Misdirected Request": 421;
|
|
171
|
-
readonly "Unprocessable Content": 422;
|
|
172
|
-
readonly Locked: 423;
|
|
173
|
-
readonly "Failed Dependency": 424;
|
|
174
|
-
readonly "Too Early": 425;
|
|
175
|
-
readonly "Upgrade Required": 426;
|
|
176
|
-
readonly "Precondition Required": 428;
|
|
177
|
-
readonly "Too Many Requests": 429;
|
|
178
|
-
readonly "Request Header Fields Too Large": 431;
|
|
179
|
-
readonly "Unavailable For Legal Reasons": 451;
|
|
180
|
-
readonly "Internal Server Error": 500;
|
|
181
|
-
readonly "Not Implemented": 501;
|
|
182
|
-
readonly "Bad Gateway": 502;
|
|
183
|
-
readonly "Service Unavailable": 503;
|
|
184
|
-
readonly "Gateway Timeout": 504;
|
|
185
|
-
readonly "HTTP Version Not Supported": 505;
|
|
186
|
-
readonly "Variant Also Negotiates": 506;
|
|
187
|
-
readonly "Insufficient Storage": 507;
|
|
188
|
-
readonly "Loop Detected": 508;
|
|
189
|
-
readonly "Not Extended": 510;
|
|
190
|
-
readonly "Network Authentication Required": 511;
|
|
191
|
-
}[Code] : Code>;
|
|
192
|
-
}) => Promise<Response | undefined>;
|
|
58
|
+
readonly beforeHandle: UntypedBeforeHandle;
|
|
193
59
|
readonly afterHandle: ({ request, responseValue, set }: {
|
|
194
60
|
body: unknown;
|
|
195
61
|
query: Record<string, string>;
|
|
@@ -208,7 +74,7 @@ export declare const idempotency: (options: IdempotencyPluginOptions) => Elysia<
|
|
|
208
74
|
route: string;
|
|
209
75
|
request: Request;
|
|
210
76
|
store: {};
|
|
211
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 |
|
|
77
|
+
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 | 100 | 101 | 102 | 103 | 201 | 202 | 203 | 205 | 206 | 207 | 208 | 300 | 301 | 302 | 303 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
|
|
212
78
|
readonly 100: "Continue";
|
|
213
79
|
readonly 101: "Switching Protocols";
|
|
214
80
|
readonly 102: "Processing";
|
|
@@ -351,7 +217,7 @@ export declare const idempotency: (options: IdempotencyPluginOptions) => Elysia<
|
|
|
351
217
|
redirect?: string;
|
|
352
218
|
cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
|
|
353
219
|
};
|
|
354
|
-
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 |
|
|
220
|
+
status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 | 100 | 101 | 102 | 103 | 201 | 202 | 203 | 205 | 206 | 207 | 208 | 300 | 301 | 302 | 303 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
|
|
355
221
|
readonly 100: "Continue";
|
|
356
222
|
readonly 101: "Switching Protocols";
|
|
357
223
|
readonly 102: "Processing";
|
|
@@ -538,4 +404,5 @@ export declare const idempotency: (options: IdempotencyPluginOptions) => Elysia<
|
|
|
538
404
|
standaloneSchema: {};
|
|
539
405
|
response: {};
|
|
540
406
|
}>;
|
|
407
|
+
export {};
|
|
541
408
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,WAAW,CAAC;AAEnB,yGAAyG;AACzG,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG;IAC7D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAA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Elysia routes: a retried POST gets the first response back instead of writing twice. Keys kept in memory, Postgres or SQLite (D1) through drizzle-orm, or a store of your own.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|