@vllnt/convex-idempotency 0.1.0 → 0.1.1-canary.28c3e26
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 +90 -0
- package/README.md +128 -42
- package/dist/client/index.d.ts +7 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +7 -6
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +5 -3
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/crons.js +1 -1
- package/dist/component/crons.js.map +1 -1
- package/dist/component/mutations.d.ts +15 -9
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +29 -13
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.js +2 -2
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.js +1 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +3 -2
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +3 -2
- package/dist/component/validators.js.map +1 -1
- package/docs/API.md +178 -0
- package/llms.txt +32 -0
- package/package.json +41 -19
- package/src/client/index.ts +7 -6
- package/src/client/types.ts +5 -3
- package/src/component/crons.ts +1 -1
- package/src/component/mutations.ts +30 -13
- package/src/component/queries.ts +2 -2
- package/src/component/schema.ts +1 -1
- package/src/component/validators.ts +3 -2
- package/src/test.ts +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based on
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.1.1] - Unreleased
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- `begin` and `complete` reject an empty `key` or `scope` with
|
|
12
|
+
`ConvexError({ code: "INVALID_KEY" | "INVALID_SCOPE" })` instead of storing an unusable row.
|
|
13
|
+
- `@vllnt/convex-idempotency/test` and the component sources now use explicit `.js` relative
|
|
14
|
+
imports and reference `vite/client`, so they type-check for consumers under both `bundler` and
|
|
15
|
+
`nodenext` module resolution.
|
|
16
|
+
|
|
17
|
+
### Documentation
|
|
18
|
+
|
|
19
|
+
- Document the error codes in `docs/API.md` and how to use `/test` in a consuming app.
|
|
20
|
+
- The npm package now ships `docs/API.md`, `CHANGELOG.md` and `llms.txt`, so coding agents can
|
|
21
|
+
read docs that match the installed version under `node_modules/@vllnt/convex-idempotency/`.
|
|
22
|
+
`llms.txt` links the bundled files relatively and adds a "For coding agents" note and an
|
|
23
|
+
ecosystem link; the README adds the same note and a "Related packages" section.
|
|
24
|
+
- `docs/API.md` lists the package entry points and notes that `get` returns an expired row until
|
|
25
|
+
it is purged or re-minted, and that a future `purge` `before` cutoff also deletes live keys.
|
|
26
|
+
TSDoc no longer suggests a `convex/values` `.parse` for `resultValidator` and lists the
|
|
27
|
+
`superseded` completion reason. The package description says "lease-based" instead of
|
|
28
|
+
"exactly-once", matching the README's side-effect caveat.
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- Releases run only from `.github/workflows/publish.yml` (npm trusted publishing with provenance,
|
|
33
|
+
stable `@latest` from a `vX.Y.Z` tag on `main`); local publish scripts were removed.
|
|
34
|
+
- Move to pnpm 10 with a seven-day release-age gate, and add low-memory dev defaults.
|
|
35
|
+
- Canary builds publish on every push to `main` that changes the package or its shipped docs,
|
|
36
|
+
under the `canary` dist-tag only; the repository-variable gate was removed.
|
|
37
|
+
- `pnpm test:package` (run in CI) fails when a required file is missing from the npm tarball, a
|
|
38
|
+
contributor or test file would ship, or an `llms.txt` link does not resolve inside it.
|
|
39
|
+
- `package.json` `homepage` points to `https://oss.vllnt.com/packages/convex-idempotency`, with
|
|
40
|
+
more keywords.
|
|
41
|
+
|
|
42
|
+
## [0.1.0] - 2026-09-01
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
|
|
46
|
+
- First release of `@vllnt/convex-idempotency`.
|
|
47
|
+
- Server-sourced time: `begin`/`complete`/`purge` read `Date.now()` inside each
|
|
48
|
+
handler — no caller-supplied `now` — so a hostile clock cannot force a key to
|
|
49
|
+
look live or expired.
|
|
50
|
+
- Optional host `resultValidator` on the client, narrowing the opaque stored
|
|
51
|
+
`result` to `TResult` at the boundary on `complete` (write), `begin`/`get`
|
|
52
|
+
(read). Removes the previous unchecked `as TResult` cast.
|
|
53
|
+
- Split TTLs: a short inflight lease (`inflightTtlMs`, default 60s) so a crashed
|
|
54
|
+
worker's claim self-heals fast, and a longer done grace (`doneTtlMs`, default
|
|
55
|
+
24h). `begin` returns `expiresAt`/`retryAfterMs` on the `inflight` branch.
|
|
56
|
+
- `complete` now returns a discriminated `{ recorded: true } | { recorded: false,
|
|
57
|
+
reason: "missing" | "expired" | "already_done" }`, plus an `upsertOnMissing`
|
|
58
|
+
option to record finished work whose inflight row had vanished.
|
|
59
|
+
- Expired keys are re-minted in place (`db.patch`, reusing the row id) instead of
|
|
60
|
+
delete-and-insert.
|
|
61
|
+
- Bounded, self-rescheduling `purge` (`take(batch)` + scheduler) and a built-in
|
|
62
|
+
daily prune cron (`crons.ts`); idempotent.
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- `begin` and `complete` now reject a TTL argument that is ≤ 0 or non-finite with
|
|
67
|
+
`ConvexError({ code: "INVALID_TTL" })`. A zero or negative `inflightTtlMs` would
|
|
68
|
+
have produced `expiresAt ≤ now`, immediately expiring the key on creation and
|
|
69
|
+
breaking the dedup claim window. Same guard added for `doneTtlMs` in `complete`.
|
|
70
|
+
|
|
71
|
+
### Documented
|
|
72
|
+
|
|
73
|
+
- Expiry check order asymmetry between `begin` and `complete` is now documented in
|
|
74
|
+
TSDoc on both mutations. `begin` checks expiry before the done-state (an expired
|
|
75
|
+
done key re-mints fresh — the grace window elapsed, the operation may re-run).
|
|
76
|
+
`complete` checks the done-state before expiry (an expired done key returns
|
|
77
|
+
`already_done` — a prior winner's recorded outcome must not be overwritten).
|
|
78
|
+
|
|
79
|
+
### Fixed (since the first canary)
|
|
80
|
+
|
|
81
|
+
- Fence re-minted leases with opaque claim IDs so a stale worker cannot overwrite the newer
|
|
82
|
+
claim's result, including when lost-claim upsert is enabled.
|
|
83
|
+
- Reject invalid purge batches and non-finite cutoffs before they can create scheduler loops or
|
|
84
|
+
oversized transactions.
|
|
85
|
+
|
|
86
|
+
### Changed (since the first canary)
|
|
87
|
+
|
|
88
|
+
- Treat Convex `_generated` output as CLI-owned, exclude it from formatting, and expose a
|
|
89
|
+
dedicated codegen script.
|
|
90
|
+
- Require `convex@^1.45.0`.
|
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<!-- Badges -->
|
|
2
|
+
|
|
2
3
|
[](https://www.convex.dev/components)
|
|
3
4
|
[](https://www.npmjs.com/package/@vllnt/convex-idempotency)
|
|
4
5
|
[](https://github.com/vllnt/convex-idempotency/actions/workflows/ci.yml)
|
|
@@ -6,31 +7,51 @@
|
|
|
6
7
|
|
|
7
8
|
# @vllnt/convex-idempotency
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
Lease-based idempotency key ledger for retried operations, as a Convex
|
|
11
|
+
component.
|
|
10
12
|
|
|
11
13
|
```ts
|
|
12
14
|
const idem = new Idempotency(components.idempotency);
|
|
13
|
-
const claim = await idem.begin(ctx, requestId);
|
|
14
|
-
if (claim.state === "done") return claim.result;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const claim = await idem.begin(ctx, requestId); // mints a claim, or short-circuits a replay
|
|
16
|
+
if (claim.state === "done") return claim.result; // replayed — skip the work
|
|
17
|
+
if (claim.state === "inflight") throw new Error("Retry later");
|
|
18
|
+
// ... run the work only for a fresh claim ...
|
|
19
|
+
const completion = await idem.complete(ctx, requestId, result, {
|
|
20
|
+
claimId: claim.claimId,
|
|
21
|
+
});
|
|
22
|
+
if (!completion.recorded) throw new Error(`Claim lost: ${completion.reason}`);
|
|
17
23
|
```
|
|
18
24
|
|
|
19
|
-
Record an idempotency `key` with a grace TTL; on a replay short-circuit and
|
|
20
|
-
instead of re-running the work. Domain-neutral: payment
|
|
21
|
-
|
|
25
|
+
Record an idempotency `key` with a grace TTL; on a replay short-circuit and
|
|
26
|
+
return the prior outcome instead of re-running the work. Domain-neutral: payment
|
|
27
|
+
intents, webhook deliveries, queue consumers, double-submit guards. The ledger
|
|
28
|
+
fences completion of replaced leases; it does not guarantee exactly-once
|
|
29
|
+
external side effects. A worker can finish an external operation and crash
|
|
30
|
+
before recording it. Use the provider's idempotency key too.
|
|
22
31
|
|
|
23
32
|
## Features
|
|
24
33
|
|
|
25
|
-
- **
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- **
|
|
29
|
-
|
|
30
|
-
- **
|
|
31
|
-
|
|
34
|
+
- **Exclusive live claim** per `(scope, key)` — `begin` mints an inflight claim
|
|
35
|
+
that rides the mutation transaction; a concurrent retry sees `inflight` with a
|
|
36
|
+
`retryAfterMs` backoff hint.
|
|
37
|
+
- **Replay** — once `complete` records an outcome, a later `begin` returns
|
|
38
|
+
`{ state: "done", result }` for a short-circuit.
|
|
39
|
+
- **Split TTLs** — a short **inflight lease** (default 60s) so a crashed
|
|
40
|
+
worker's claim self-heals, and a longer **done grace** (default 24h) after
|
|
41
|
+
which a key may be re-minted.
|
|
42
|
+
- **Lost-claim detection** — `complete` returns
|
|
43
|
+
`{ recorded: true } | { recorded: false, reason }` so a host knows when its
|
|
44
|
+
work finished but the row was gone. Opt into `upsertOnMissing`.
|
|
45
|
+
- **Server-sourced time** — expiry is read from the server clock; a caller can't
|
|
46
|
+
supply `now`, so an adversarial clock can't force a key to look live or
|
|
47
|
+
expired.
|
|
48
|
+
- **Input validation** — empty keys or scopes and non-positive or infinite TTLs
|
|
49
|
+
throw `INVALID_KEY` / `INVALID_SCOPE` / `INVALID_TTL` before any write.
|
|
50
|
+
- **Typed result** — `Idempotency<TResult>` types the stored outcome; a
|
|
51
|
+
`resultValidator` narrows it at the boundary.
|
|
32
52
|
- **Scopes** — global by default, or namespace per tenant / operation type.
|
|
33
|
-
- **Bounded purge + cron** — a daily cron sweeps expired keys in batches and
|
|
53
|
+
- **Bounded purge + cron** — a daily cron sweeps expired keys in batches and
|
|
54
|
+
self-reschedules until clean.
|
|
34
55
|
|
|
35
56
|
## Installation
|
|
36
57
|
|
|
@@ -38,7 +59,14 @@ double-submit guards — any operation that must run **at most once** per key.
|
|
|
38
59
|
pnpm add @vllnt/convex-idempotency
|
|
39
60
|
```
|
|
40
61
|
|
|
41
|
-
|
|
62
|
+
Requires `convex@^1.45.0`.
|
|
63
|
+
|
|
64
|
+
### For coding agents
|
|
65
|
+
|
|
66
|
+
The docs are bundled in the npm package:
|
|
67
|
+
`node_modules/@vllnt/convex-idempotency/docs/API.md`, with `README.md`,
|
|
68
|
+
`CHANGELOG.md`, `llms.txt` and the typed `src/` at the package root. They match
|
|
69
|
+
the installed version. Read them before writing code.
|
|
42
70
|
|
|
43
71
|
## Usage
|
|
44
72
|
|
|
@@ -53,51 +81,76 @@ export default app;
|
|
|
53
81
|
```
|
|
54
82
|
|
|
55
83
|
```ts
|
|
56
|
-
// convex/
|
|
84
|
+
// convex/requests.ts — record a result in one authenticated mutation.
|
|
57
85
|
import { components } from "./_generated/api";
|
|
58
86
|
import { mutation } from "./_generated/server";
|
|
59
87
|
import { v } from "convex/values";
|
|
60
88
|
import { Idempotency } from "@vllnt/convex-idempotency";
|
|
61
89
|
|
|
62
|
-
const idem = new Idempotency<{
|
|
63
|
-
resultValidator:
|
|
90
|
+
const idem = new Idempotency<{ accepted: boolean }>(components.idempotency, {
|
|
91
|
+
resultValidator: (value) => {
|
|
92
|
+
if (
|
|
93
|
+
typeof value !== "object" ||
|
|
94
|
+
value === null ||
|
|
95
|
+
!("accepted" in value) ||
|
|
96
|
+
typeof value.accepted !== "boolean"
|
|
97
|
+
) {
|
|
98
|
+
throw new Error("Invalid stored result");
|
|
99
|
+
}
|
|
100
|
+
return { accepted: value.accepted };
|
|
101
|
+
},
|
|
64
102
|
});
|
|
65
103
|
|
|
66
|
-
export const
|
|
67
|
-
args: { requestId: v.string()
|
|
68
|
-
handler: async (ctx, { requestId
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
104
|
+
export const accept = mutation({
|
|
105
|
+
args: { requestId: v.string() },
|
|
106
|
+
handler: async (ctx, { requestId }) => {
|
|
107
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
108
|
+
if (!identity) throw new Error("Unauthenticated");
|
|
109
|
+
const scope = identity.tokenIdentifier;
|
|
110
|
+
const claim = await idem.begin(ctx, requestId, { scope });
|
|
111
|
+
if (claim.state === "done") return claim.result;
|
|
71
112
|
if (claim.state === "inflight")
|
|
72
|
-
throw new Error(`
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
113
|
+
throw new Error(`Retry in ${claim.retryAfterMs}ms`);
|
|
114
|
+
// Put transactional host database writes here, not external network calls.
|
|
115
|
+
const result = { accepted: true };
|
|
116
|
+
const done = await idem.complete(ctx, requestId, result, {
|
|
117
|
+
scope,
|
|
118
|
+
claimId: claim.claimId,
|
|
119
|
+
});
|
|
120
|
+
if (!done.recorded) throw new Error(`Claim lost: ${done.reason}`);
|
|
76
121
|
return result;
|
|
77
122
|
},
|
|
78
123
|
});
|
|
79
124
|
```
|
|
80
125
|
|
|
126
|
+
For external work, use a host action with separate claim/completion mutations;
|
|
127
|
+
carry the same `scope` and `claimId` through both. Do not execute work for an
|
|
128
|
+
`inflight` response, and handle a failed completion without blindly repeating
|
|
129
|
+
the side effect. After either TTL expires, the key can be claimed again.
|
|
130
|
+
|
|
81
131
|
## API Reference
|
|
82
132
|
|
|
83
|
-
| Method
|
|
84
|
-
|
|
85
|
-
| `begin(ctx, key, opts?)`
|
|
133
|
+
| Method | Kind | Result |
|
|
134
|
+
| ------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------- |
|
|
135
|
+
| `begin(ctx, key, opts?)` | mutation | `{ state: "fresh"; claimId } \| { state: "inflight"; expiresAt; retryAfterMs } \| { state: "done"; result? }` |
|
|
86
136
|
| `complete(ctx, key, result?, opts?)` | mutation | `{ recorded: true } \| { recorded: false; reason: "missing" \| "expired" \| "superseded" \| "already_done" }` |
|
|
87
|
-
| `get(ctx, key, scope?)`
|
|
88
|
-
| `purge(ctx, opts?)`
|
|
137
|
+
| `get(ctx, key, scope?)` | query | `{ status, result?, expiresAt } \| null` |
|
|
138
|
+
| `purge(ctx, opts?)` | mutation | `number` (keys removed in the first bounded pass) |
|
|
89
139
|
|
|
90
140
|
Full reference: [docs/API.md](docs/API.md).
|
|
91
141
|
|
|
92
142
|
## React
|
|
93
143
|
|
|
94
|
-
Backend-only — no `./react` entry. Pure infra dedup with no user-facing reactive
|
|
144
|
+
Backend-only — no `./react` entry. Pure infra dedup with no user-facing reactive
|
|
145
|
+
surface.
|
|
95
146
|
|
|
96
147
|
## Security
|
|
97
148
|
|
|
98
|
-
- Auth-agnostic — the host resolves identity and decides who may run an
|
|
149
|
+
- Auth-agnostic — the host resolves identity and decides who may run an
|
|
150
|
+
operation.
|
|
99
151
|
- Tables sandboxed — reached only through the exported functions.
|
|
100
|
-
- Server-sourced expiry — a skewed client clock can't hijack a replay or bypass
|
|
152
|
+
- Server-sourced expiry — a skewed client clock can't hijack a replay or bypass
|
|
153
|
+
dedup; `key` / `scope` / `result` stay opaque.
|
|
101
154
|
|
|
102
155
|
See [docs/API.md](docs/API.md).
|
|
103
156
|
|
|
@@ -108,20 +161,53 @@ pnpm test # single run
|
|
|
108
161
|
pnpm test:coverage # enforced 100% on covered files
|
|
109
162
|
```
|
|
110
163
|
|
|
111
|
-
Tests run against the real component runtime via `convex-test`
|
|
164
|
+
Tests run against the real component runtime via `convex-test`
|
|
165
|
+
(`@edge-runtime/vm`), not mocks.
|
|
166
|
+
|
|
167
|
+
### Testing your app
|
|
168
|
+
|
|
169
|
+
`@vllnt/convex-idempotency/test` exports `register(t, name = "idempotency")` to
|
|
170
|
+
mount the component in a `convex-test` instance. It needs `convex-test` and
|
|
171
|
+
`vitest` (with Vite's `import.meta.glob`) in the consuming app:
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
/// <reference types="vite/client" />
|
|
175
|
+
import { convexTest } from "convex-test";
|
|
176
|
+
import { register } from "@vllnt/convex-idempotency/test";
|
|
177
|
+
import schema from "./schema";
|
|
178
|
+
|
|
179
|
+
const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
180
|
+
register(t);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Related packages
|
|
184
|
+
|
|
185
|
+
These components dedup their own writes with a built-in idempotency key. Use
|
|
186
|
+
them for their domain; use this ledger for any other retried operation.
|
|
187
|
+
|
|
188
|
+
- [`@vllnt/convex-email`](https://oss.vllnt.com/packages/convex-email) —
|
|
189
|
+
outbound email queue; its `idempotencyKey` dedups a re-enqueued message.
|
|
190
|
+
- [`@vllnt/convex-metering`](https://oss.vllnt.com/packages/convex-metering) —
|
|
191
|
+
metered usage; its `idempotencyKey` stops a retry from double-counting.
|
|
192
|
+
- [`@vllnt/convex-wallet`](https://oss.vllnt.com/packages/convex-wallet) —
|
|
193
|
+
balances; `grant` / `spend` credit or debit once per `idempotencyKey`.
|
|
112
194
|
|
|
113
195
|
## Contributing
|
|
114
196
|
|
|
115
|
-
See
|
|
197
|
+
See
|
|
198
|
+
[CONTRIBUTING.md](https://github.com/vllnt/convex-idempotency/blob/main/CONTRIBUTING.md).
|
|
116
199
|
|
|
117
200
|
## Author
|
|
118
201
|
|
|
119
|
-
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
120
|
-
|
|
121
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
202
|
+
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
203
|
+
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
122
204
|
|
|
123
205
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
124
206
|
|
|
125
207
|
## License
|
|
126
208
|
|
|
127
209
|
MIT — see [LICENSE](LICENSE).
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
Part of vllnt oss: https://oss.vllnt.com
|
package/dist/client/index.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ interface CompleteOptions {
|
|
|
73
73
|
upsertOnMissing?: boolean;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Consumer-facing client for the
|
|
76
|
+
* Consumer-facing client for the lease-based idempotency key ledger. The host
|
|
77
77
|
* owns meaning and auth; it passes an opaque `key` and an optional `scope`, and
|
|
78
78
|
* stores an arbitrary `TResult` outcome that replays return verbatim. Pass a
|
|
79
79
|
* `resultValidator` to narrow the opaque stored value to `TResult` at the
|
|
@@ -84,7 +84,7 @@ interface CompleteOptions {
|
|
|
84
84
|
* @example
|
|
85
85
|
* ```ts
|
|
86
86
|
* const idem = new Idempotency(components.idempotency, {
|
|
87
|
-
* resultValidator:
|
|
87
|
+
* resultValidator: ChargeResult.parse, // e.g. a Zod schema, or a hand-written guard
|
|
88
88
|
* });
|
|
89
89
|
* const r = await idem.begin(ctx, requestId);
|
|
90
90
|
* if (r.state === "done") return r.result; // typed replay
|
|
@@ -119,16 +119,17 @@ export declare class Idempotency<TResult = unknown> {
|
|
|
119
119
|
* Mark `key` `done`, recording `result` and extending the done grace window.
|
|
120
120
|
* Returns a discriminated outcome: `recorded: true` on success, or
|
|
121
121
|
* `recorded: false` with a `reason` when the claim was lost (missing, expired,
|
|
122
|
-
* or already done) so the host can react to dropped work.
|
|
123
|
-
* against the host validator before it is stored.
|
|
122
|
+
* superseded, or already done) so the host can react to dropped work.
|
|
123
|
+
* `result` is validated against the host validator before it is stored.
|
|
124
124
|
*/
|
|
125
125
|
complete(ctx: RunMutationCtx, key: string, result?: TResult, opts?: CompleteOptions): Promise<CompleteResult>;
|
|
126
126
|
/** The stored state for `key`, or `null` if no key is held in the scope. */
|
|
127
127
|
get(ctx: RunQueryCtx, key: string, scope?: string): Promise<KeyState<TResult> | null>;
|
|
128
128
|
/**
|
|
129
129
|
* Delete expired keys in bounded batches, oldest first. `before` defaults to
|
|
130
|
-
* the server clock
|
|
131
|
-
*
|
|
130
|
+
* the server clock (a future `before` also deletes live keys); `batch` caps
|
|
131
|
+
* each pass and the sweep self-reschedules until the tail is clean. Returns
|
|
132
|
+
* the count removed in the first pass.
|
|
132
133
|
*/
|
|
133
134
|
purge(ctx: RunMutationCtx, opts?: {
|
|
134
135
|
before?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACb,MAAM,YAAY,CAAC;AAQpB;;;;GAIG;AACH,KAAK,QAAQ,GACT;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC9D;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAExC;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE;QACT,KAAK,EAAE,iBAAiB,CACtB,UAAU,EACV,UAAU,EACV;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,aAAa,EAAE,MAAM,CAAA;SAAE,EACrD,QAAQ,CACT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the
|
|
3
|
+
* Consumer-facing client for the lease-based idempotency key ledger. The host
|
|
4
4
|
* owns meaning and auth; it passes an opaque `key` and an optional `scope`, and
|
|
5
5
|
* stores an arbitrary `TResult` outcome that replays return verbatim. Pass a
|
|
6
6
|
* `resultValidator` to narrow the opaque stored value to `TResult` at the
|
|
@@ -11,7 +11,7 @@ import { DEFAULT_DONE_TTL_MS, DEFAULT_INFLIGHT_TTL_MS, DEFAULT_PURGE_BATCH, DEFA
|
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
13
|
* const idem = new Idempotency(components.idempotency, {
|
|
14
|
-
* resultValidator:
|
|
14
|
+
* resultValidator: ChargeResult.parse, // e.g. a Zod schema, or a hand-written guard
|
|
15
15
|
* });
|
|
16
16
|
* const r = await idem.begin(ctx, requestId);
|
|
17
17
|
* if (r.state === "done") return r.result; // typed replay
|
|
@@ -74,8 +74,8 @@ export class Idempotency {
|
|
|
74
74
|
* Mark `key` `done`, recording `result` and extending the done grace window.
|
|
75
75
|
* Returns a discriminated outcome: `recorded: true` on success, or
|
|
76
76
|
* `recorded: false` with a `reason` when the claim was lost (missing, expired,
|
|
77
|
-
* or already done) so the host can react to dropped work.
|
|
78
|
-
* against the host validator before it is stored.
|
|
77
|
+
* superseded, or already done) so the host can react to dropped work.
|
|
78
|
+
* `result` is validated against the host validator before it is stored.
|
|
79
79
|
*/
|
|
80
80
|
complete(ctx, key, result, opts = {}) {
|
|
81
81
|
const validated = result === undefined ? undefined : this.parseResult(result);
|
|
@@ -105,8 +105,9 @@ export class Idempotency {
|
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* Delete expired keys in bounded batches, oldest first. `before` defaults to
|
|
108
|
-
* the server clock
|
|
109
|
-
*
|
|
108
|
+
* the server clock (a future `before` also deletes live keys); `batch` caps
|
|
109
|
+
* each pass and the sweep self-reschedules until the tail is clean. Returns
|
|
110
|
+
* the count removed in the first pass.
|
|
110
111
|
*/
|
|
111
112
|
purge(ctx, opts = {}) {
|
|
112
113
|
return ctx.runMutation(this.component.mutations.purge, {
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,GACd,MAAM,cAAc,CAAC;AAyFtB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,WAAW;IAQH,SAAS;IAPX,YAAY,CAAS;IACrB,oBAAoB,CAAS;IAC7B,gBAAgB,CAAS;IACzB,sBAAsB,CAAU;IAChC,eAAe,CAAoC;IAEpE,YACmB,SAA+B,EAChD,OAAO,GAAgC,EAAE;yBADxB,SAAS;QAG1B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC;QAC1D,IAAI,CAAC,oBAAoB;YACvB,OAAO,CAAC,oBAAoB,IAAI,uBAAuB,CAAC;QAC1D,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,mBAAmB,CAAC;QACxE,IAAI,CAAC,sBAAsB,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC;QAC/D,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IACjD,CAAC;IAEO,OAAO,CAAC,KAAyB;QACvC,OAAO,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,KAAc;QAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACvC,OAAO,KAAgB,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,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EAAE,SAAS;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,gBAAgB;YAClD,eAAe,EAAE,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,sBAAsB;SACrE,CAAC,CAAC;IACL,CAAC;IAED,4EAA4E;IAC5E,KAAK,CAAC,GAAG,CACP,GAAgB,EAChB,GAAW,EACX,KAAc;QAEd,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE;YACzD,GAAG;YACH,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SAC3B,CAAC,CAAC;QACH,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC;YACpC,SAAS,EAAE,GAAG,CAAC,SAAS;SACzB,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CACH,GAAmB,EACnB,IAAI,GAAwC,EAAE;QAE9C,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE;YACrD,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,mBAAmB;SACzC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/client/types.d.ts
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Validates and narrows an opaque stored `result` to the host's `TResult` at the
|
|
4
4
|
* client boundary. Receives the raw value the component replayed (`unknown`) and
|
|
5
|
-
* MUST return a typed `TResult` or throw. A
|
|
6
|
-
* (
|
|
5
|
+
* MUST return a typed `TResult` or throw. A Zod `.parse` or a hand-written type
|
|
6
|
+
* guard fits directly (`convex/values` validators have no `.parse`); omit it to
|
|
7
|
+
* keep results unvalidated.
|
|
7
8
|
*
|
|
8
9
|
* @typeParam TResult - The host's stored outcome type.
|
|
9
10
|
*/
|
|
@@ -36,7 +37,8 @@ export type CompleteResult = {
|
|
|
36
37
|
recorded: false;
|
|
37
38
|
/**
|
|
38
39
|
* `missing` — no key for this id/scope. `expired` — the inflight lease
|
|
39
|
-
* lapsed before completion. `
|
|
40
|
+
* lapsed before completion. `superseded` — a newer claim replaced this
|
|
41
|
+
* worker's lease. `already_done` — a prior attempt won the race.
|
|
40
42
|
*/
|
|
41
43
|
reason: "missing" | "expired" | "superseded" | "already_done";
|
|
42
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CAAC,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAEhE,sDAAsD;AACtD,MAAM,MAAM,WAAW,CAAC,OAAO,IAC3B;IACE,kEAAkE;IAClE,KAAK,EAAE,OAAO,CAAC;IACf,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,oDAAoD;IACpD,KAAK,EAAE,UAAU,CAAC;IAClB,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,YAAY,EAAE,MAAM,CAAC;CACtB,GACD;IACE,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEN,6FAA6F;AAC7F,MAAM,MAAM,cAAc,GACtB;IACE,6CAA6C;IAC7C,QAAQ,EAAE,IAAI,CAAC;CAChB,GACD;IACE,oEAAoE;IACpE,QAAQ,EAAE,KAAK,CAAC;IAChB;;;;OAIG;IACH,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,CAAC;CAC/D,CAAC;AAEN,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB,CAAC,OAAO;IACzC,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;CACzC;AAED,oEAAoE;AACpE,MAAM,WAAW,QAAQ,CAAC,OAAO;IAC/B,wEAAwE;IACxE,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC;IAC5B,kEAAkE;IAClE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/component/crons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cronJobs } from "convex/server";
|
|
2
|
-
import { api } from "./_generated/api";
|
|
2
|
+
import { api } from "./_generated/api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Default sweep cadence and page size for the built-in prune cron. The cron is
|
|
5
5
|
* the component's own self-healing safety net — a host that wants a different
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,KAAK,EAAE,EAAE,EAAW,CAAC;AAErD,uEAAuE;AACvE,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;AAEzB,KAAK,CAAC,QAAQ,CAAC,mBAAmB,EAAE,cAAc,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE;IACvE,KAAK,EAAE,WAAW;CACnB,CAAC,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* correct recovery path — the done grace exists precisely to replay within the
|
|
12
12
|
* window; outside it the operation may safely re-run.
|
|
13
13
|
*
|
|
14
|
+
* @throws `ConvexError({ code: "INVALID_KEY" | "INVALID_SCOPE" })` when `key` or
|
|
15
|
+
* `scope` is the empty string.
|
|
14
16
|
* @throws `ConvexError({ code: "INVALID_TTL" })` when `inflightTtlMs` is not a
|
|
15
17
|
* positive finite number (≤ 0 or non-finite would produce `expiresAt ≤ now`,
|
|
16
18
|
* immediately expiring the claim and breaking the dedup window).
|
|
@@ -42,10 +44,11 @@ export declare const begin: import("convex/server").RegisteredMutation<"public",
|
|
|
42
44
|
* Mark `key` `done`, recording `result` and extending the grace window by
|
|
43
45
|
* `doneTtlMs`. Returns a discriminated outcome so the host can detect a lost
|
|
44
46
|
* claim: `recorded: false` with `missing` (key never existed), `expired` (the
|
|
45
|
-
* inflight lease lapsed before completion),
|
|
46
|
-
*
|
|
47
|
-
* `
|
|
48
|
-
*
|
|
47
|
+
* inflight lease lapsed before completion), `superseded` (a newer claim replaced
|
|
48
|
+
* this worker's lease), or `already_done` (a prior attempt won). When
|
|
49
|
+
* `upsertOnMissing` is set, a `missing`/`expired` key is written as `done`
|
|
50
|
+
* anyway — for hosts that would rather record the finished work than drop it.
|
|
51
|
+
* Time is server-sourced.
|
|
49
52
|
*
|
|
50
53
|
* **Expiry check order (intentional asymmetry):** `complete` checks the
|
|
51
54
|
* done-state BEFORE expiry. An expired done key therefore returns
|
|
@@ -55,6 +58,8 @@ export declare const begin: import("convex/server").RegisteredMutation<"public",
|
|
|
55
58
|
* The `expired` reason is reserved for inflight keys whose lease lapsed before
|
|
56
59
|
* the holder could complete; it does not apply to keys already marked done.
|
|
57
60
|
*
|
|
61
|
+
* @throws `ConvexError({ code: "INVALID_KEY" | "INVALID_SCOPE" })` when `key` or
|
|
62
|
+
* `scope` is the empty string.
|
|
58
63
|
* @throws `ConvexError({ code: "INVALID_TTL" })` when `doneTtlMs` is not a
|
|
59
64
|
* positive finite number (≤ 0 or non-finite would produce `expiresAt ≤ now`,
|
|
60
65
|
* immediately expiring the done grace window on creation).
|
|
@@ -85,11 +90,12 @@ export declare const complete: import("convex/server").RegisteredMutation<"publi
|
|
|
85
90
|
/**
|
|
86
91
|
* Delete up to `batch` keys whose `expiresAt < before`, oldest first via the
|
|
87
92
|
* `by_expires` index. `before` defaults to the server clock (`Date.now()`) when
|
|
88
|
-
* omitted, so the built-in cron sweeps exactly the keys expired as of the run
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
+
* omitted, so the built-in cron sweeps exactly the keys expired as of the run.
|
|
94
|
+
* An explicit `before` is trusted as given: a future cutoff also deletes live
|
|
95
|
+
* keys, so never derive it from untrusted input. If a full batch was removed
|
|
96
|
+
* there may be more, so the sweep self-reschedules through `ctx.scheduler` until
|
|
97
|
+
* a short batch signals the tail is clean. Idempotent for a past cutoff:
|
|
98
|
+
* re-running it removes nothing new.
|
|
93
99
|
*/
|
|
94
100
|
export declare const purge: import("convex/server").RegisteredMutation<"public", {
|
|
95
101
|
batch: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,KAAK;;;;;WAoCI,OAAO;;;;;;;WAiBP,MAAM;;;;;;;WAIf,UAAU;;;GAKrB,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;YA0C4B,SAAS;;;YAIT,cAAc;;;YAOd,YAAY;;;YAYZ,SAAS;GAUxD,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK;;;mBAwBhB,CAAC"}
|