@20baht/elysia-idempotency 0.1.1 → 0.1.2
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 +5 -0
- package/dist/core.d.ts +4 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/index.js +20 -2
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# @20baht/elysia-idempotency changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
The fingerprint reads multipart file parts (name, type, size, SHA-256 of the bytes): the same key with a different
|
|
6
|
+
file is a 422, not a replay of the first answer (20baht-ecosystem#14).
|
|
7
|
+
|
|
3
8
|
## 0.1.1
|
|
4
9
|
|
|
5
10
|
Every entry has a `default` condition beside `import`, so a loader that `require`s it finds it: drizzle-kit reads a
|
package/dist/core.d.ts
CHANGED
|
@@ -79,7 +79,10 @@ export interface BeginInput {
|
|
|
79
79
|
}
|
|
80
80
|
/** The key a store keeps: the scope's length first, so no scope and key run into another pair. */
|
|
81
81
|
export declare const storeKey: (scope: string | undefined, key: string) => string;
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* SHA-256 of the request: its method, its path with the query, and its body as JSON. A multipart
|
|
84
|
+
* file part counts by its name, type, size and the hash of its bytes.
|
|
85
|
+
*/
|
|
83
86
|
export declare const fingerprint: (method: string, path: string, body: unknown) => Promise<string>;
|
|
84
87
|
/** Keys worked out against a store. */
|
|
85
88
|
export interface Idempotency {
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAKA,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAC,MAAM,EAA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IAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAEtD,MAAM,WAAW,UAAU;IACzB,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;CACrB;AAID,kGAAkG;AAClG,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,GAAG,SAAS,EAAE,KAAK,MAAM,KAAG,MACW,CAAC;AAuB9E;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAU,QAAQ,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,OAAO,KAAG,OAAO,CAAC,MAAM,CAG7F,CAAC;AAEF,uCAAuC;AACvC,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,mFAAmF;IACnF,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED,eAAO,MAAM,iBAAiB,GAAI,SAAS,kBAAkB,KAAG,WAqC/D,CAAC;AAEF,yGAAyG;AACzG,eAAO,MAAM,WAAW,QAAO,gBAAgB,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAkCxE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,26 @@
|
|
|
3
3
|
var HOUR = 3600000;
|
|
4
4
|
var storeKey = (scope, key) => scope === undefined ? `:${key}` : `${String(scope.length)}:${scope}:${key}`;
|
|
5
5
|
var hex = (bytes) => [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
6
|
+
var describeBlobs = async (value, depth = 0) => {
|
|
7
|
+
if (value instanceof Blob)
|
|
8
|
+
return {
|
|
9
|
+
$blob: true,
|
|
10
|
+
name: value instanceof File ? value.name : null,
|
|
11
|
+
type: value.type,
|
|
12
|
+
size: value.size,
|
|
13
|
+
sha256: hex(await crypto.subtle.digest("SHA-256", await value.arrayBuffer()))
|
|
14
|
+
};
|
|
15
|
+
if (depth > 8 || value === null || typeof value !== "object")
|
|
16
|
+
return value;
|
|
17
|
+
if (Array.isArray(value))
|
|
18
|
+
return Promise.all(value.map((item) => describeBlobs(item, depth + 1)));
|
|
19
|
+
const out = {};
|
|
20
|
+
for (const [name, item] of Object.entries(value))
|
|
21
|
+
out[name] = await describeBlobs(item, depth + 1);
|
|
22
|
+
return out;
|
|
23
|
+
};
|
|
6
24
|
var fingerprint = async (method, path, body) => {
|
|
7
|
-
const json = JSON.stringify([method.toUpperCase(), path, body ?? null]);
|
|
25
|
+
const json = JSON.stringify([method.toUpperCase(), path, await describeBlobs(body) ?? null]);
|
|
8
26
|
return hex(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(json)));
|
|
9
27
|
};
|
|
10
28
|
var createIdempotency = (options) => {
|
|
@@ -215,5 +233,5 @@ export {
|
|
|
215
233
|
createIdempotency
|
|
216
234
|
};
|
|
217
235
|
|
|
218
|
-
//# debugId=
|
|
236
|
+
//# debugId=73649AD9B06687D664756E2164756E21
|
|
219
237
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/core.ts", "../src/plugin.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
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/** SHA-256 of the request: its method, its path with the query, and its body as JSON. */\nexport const fingerprint = async (method: string, path: string, body: unknown): Promise<string> => {\n const json = JSON.stringify([method.toUpperCase(), path, 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",
|
|
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
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') => ({\n async beforeHandle(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 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"
|
|
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;
|
|
9
|
-
"debugId": "
|
|
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,IAA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;AAAA;AAAA,WAE5B,MAAK,GAAG,WAAW;AAAA,QACvB,MAAM,MAAM,QAAQ,IAAI,OAAO;AAAA,QAC/B,IAAI,CAAC;AAAA,UAAK;AAAA,QACV,QAAQ,OAAO,OAAO;AAAA,QACtB,MAAM,IAAI,QAAQ;AAAA;AAAA,IAEtB;AAAA,EACF,CAAC;AAAA;",
|
|
9
|
+
"debugId": "73649AD9B06687D664756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@20baht/elysia-idempotency",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Idempotency-Key for 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",
|