@vllnt/convex-quota 0.1.0 → 0.1.1-canary.0f19804
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 +21 -0
- package/README.md +28 -13
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/component/mutations.d.ts +2 -2
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +5 -4
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts +1 -1
- package/dist/component/validators.d.ts +2 -2
- package/docs/API.md +13 -0
- package/llms.txt +18 -4
- package/package.json +14 -12
- package/src/client/index.ts +1 -1
- package/src/component/mutations.ts +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,27 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.1.1] - 2026-11-28
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- The npm package's `llms.txt` and README tell coding agents that the docs are
|
|
14
|
+
bundled at `node_modules/@vllnt/convex-quota/docs/` (with `README.md`,
|
|
15
|
+
`CHANGELOG.md` and `llms.txt` in the package root) and match the installed
|
|
16
|
+
version. `llms.txt` links shipped files with relative paths and adds an
|
|
17
|
+
Ecosystem link; the README adds Related packages. `docs/API.md` lists the
|
|
18
|
+
package entry points and exported types.
|
|
19
|
+
- `pnpm check:pack` fails when a required file is missing from the tarball or a
|
|
20
|
+
relative `llms.txt` link does not resolve inside it.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- `homepage` points to https://oss.vllnt.com/packages/convex-quota.
|
|
25
|
+
- Every push to `main` that touches the package or its shipped docs publishes a
|
|
26
|
+
`canary`, with no repository-variable gate.
|
|
27
|
+
- `refund` skips the write when the allowance's `used` would not change (already
|
|
28
|
+
zero), so a no-op refund no longer re-runs `remaining` subscribers.
|
|
29
|
+
|
|
9
30
|
## [0.1.0] - 2026-11-23
|
|
10
31
|
|
|
11
32
|
First stable release.
|
package/README.md
CHANGED
|
@@ -16,12 +16,8 @@ Daily/weekly play caps, free-tier slots, Codex-style limits.
|
|
|
16
16
|
|
|
17
17
|
Use it for allowances that reset on a schedule and that your UI needs to read:
|
|
18
18
|
"3 plays left today", a weekly cap in the subject's own timezone, free-tier
|
|
19
|
-
slots, a refund when an action is cancelled.
|
|
20
|
-
|
|
21
|
-
- General throttling (token buckets, fixed windows, React hooks): use the
|
|
22
|
-
official `@convex-dev/rate-limiter`.
|
|
23
|
-
- Billable usage records: use `@vllnt/convex-metering`.
|
|
24
|
-
- Balances that persist and are spent down: use `@vllnt/convex-wallet`.
|
|
19
|
+
slots, a refund when an action is cancelled. For other needs, see
|
|
20
|
+
[Related packages](#related-packages).
|
|
25
21
|
|
|
26
22
|
```ts
|
|
27
23
|
const quota = new Quota(components.quota);
|
|
@@ -39,7 +35,7 @@ if (!r.allowed) throw new Error(`try again at ${r.resetsAt}`);
|
|
|
39
35
|
`{ used, remaining, limit, periodKey, resetsAt }`; only `consume` includes
|
|
40
36
|
`allowed`.
|
|
41
37
|
- **Window kinds** — calendar (`day` / `week` / `month` + IANA timezone),
|
|
42
|
-
rolling (from first consume), epoch (`floor(now / durationMs)`).
|
|
38
|
+
rolling (from first allowed consume), epoch (`floor(now / durationMs)`).
|
|
43
39
|
- **Server-sourced time** — window math uses `Date.now()` inside the component.
|
|
44
40
|
- **Opaque refs** — `subjectRef`, `key`, and `scope` are host strings (1..256
|
|
45
41
|
UTF-16 code units).
|
|
@@ -47,6 +43,13 @@ if (!r.allowed) throw new Error(`try again at ${r.resetsAt}`);
|
|
|
47
43
|
clean.
|
|
48
44
|
- **Scopes** — default `"global"`, or namespace per tenant / product.
|
|
49
45
|
|
|
46
|
+
## For coding agents
|
|
47
|
+
|
|
48
|
+
The docs are bundled in the npm package at
|
|
49
|
+
`node_modules/@vllnt/convex-quota/docs/`, with `README.md`, `CHANGELOG.md` and
|
|
50
|
+
`llms.txt` in the package root and the TypeScript sources in `src/`. They match
|
|
51
|
+
the installed version. Read them before writing code.
|
|
52
|
+
|
|
50
53
|
## Installation
|
|
51
54
|
|
|
52
55
|
```bash
|
|
@@ -280,8 +283,8 @@ export const refundPlay = internalMutation({
|
|
|
280
283
|
```
|
|
281
284
|
|
|
282
285
|
This exact pattern is exercised in
|
|
283
|
-
[`example/convex/idempotency.test.ts`](example/convex/idempotency.test.ts):
|
|
284
|
-
duplicate `requestId` replays the stored result and consumes once, a new
|
|
286
|
+
[`example/convex/idempotency.test.ts`](https://github.com/vllnt/convex-quota/blob/main/example/convex/idempotency.test.ts):
|
|
287
|
+
a duplicate `requestId` replays the stored result and consumes once, a new
|
|
285
288
|
`requestId` consumes again, the caller `scope` isolates identical request ids, a
|
|
286
289
|
host failure after `consume` rolls back both the allowance and the claim, and a
|
|
287
290
|
refund event deduplicated by `requestId` refunds once.
|
|
@@ -362,20 +365,32 @@ const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
|
362
365
|
register(t);
|
|
363
366
|
```
|
|
364
367
|
|
|
368
|
+
## Related packages
|
|
369
|
+
|
|
370
|
+
| Package | Use it when |
|
|
371
|
+
| --------------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
372
|
+
| `@convex-dev/rate-limiter` | You need general throttling (token buckets, fixed windows, React hooks), not a readable allowance. |
|
|
373
|
+
| `@vllnt/convex-idempotency` | Retries must not double-count `consume` or `refund` (see [Retries and idempotency](#retries-and-idempotency)). |
|
|
374
|
+
| `@vllnt/convex-metering` | You need billable usage records rolled up per billing period. |
|
|
375
|
+
| `@vllnt/convex-wallet` | You need a balance that persists and is spent down, not reset on a schedule. |
|
|
376
|
+
| `@vllnt/convex-api-keys` | You issue API keys; pass a validated key's ID as `subjectRef` to cap that key's usage per window. |
|
|
377
|
+
|
|
365
378
|
## Contributing
|
|
366
379
|
|
|
367
|
-
See
|
|
380
|
+
See
|
|
381
|
+
[CONTRIBUTING.md](https://github.com/vllnt/convex-quota/blob/main/CONTRIBUTING.md).
|
|
368
382
|
|
|
369
383
|
## Author
|
|
370
384
|
|
|
371
385
|
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
372
386
|
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
373
387
|
|
|
374
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet —
|
|
375
|
-
[vllnt.com](https://vllnt.com)
|
|
376
|
-
|
|
377
388
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
378
389
|
|
|
379
390
|
## License
|
|
380
391
|
|
|
381
392
|
MIT — see [LICENSE](LICENSE).
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
Part of vllnt oss: https://oss.vllnt.com
|
package/dist/client/index.js
CHANGED
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA2E7C;;;;;GAKG;AACH,MAAM,OAAO,KAAK;IAIG,SAAS;IAHX,YAAY,CAAS;IAEtC,YACmB,SAAyB,EAC1C,OAAO,GAAiB,EAAE;yBADT,SAAS;QAG1B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC;IAC5D,CAAC;IAEO,OAAO,CAAC,KAAc;QAC5B,OAAO,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC;IACpC,CAAC;IAED,OAAO,CACL,GAAmB,EACnB,UAAkB,EAClB,GAAW,EACX,KAAa,EACb,MAAkB,EAClB,OAAO,GAAmB,EAAE;QAE5B,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE;YACvD,MAAM,EAAE,OAAO,CAAC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AS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YACzC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,UAAU;SACX,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -8,7 +8,7 @@ export declare const consume: import("convex/server").RegisteredMutation<"public
|
|
|
8
8
|
kind: "calendar";
|
|
9
9
|
period: "day" | "month" | "week";
|
|
10
10
|
timeZone: string;
|
|
11
|
-
weekStartsOn?: "monday" | "sunday"
|
|
11
|
+
weekStartsOn?: "monday" | "sunday";
|
|
12
12
|
} | {
|
|
13
13
|
durationMs: number;
|
|
14
14
|
kind: "rolling";
|
|
@@ -36,7 +36,7 @@ export declare const refund: import("convex/server").RegisteredMutation<"public"
|
|
|
36
36
|
used: number;
|
|
37
37
|
}>>;
|
|
38
38
|
export declare const eraseSubject: import("convex/server").RegisteredMutation<"public", {
|
|
39
|
-
batch?: number
|
|
39
|
+
batch?: number;
|
|
40
40
|
scope: string;
|
|
41
41
|
subjectRef: string;
|
|
42
42
|
}, Promise<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":"AAuFA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;GAyClB,CAAC;AAEH,eAAO,MAAM,MAAM;;;;;;;;;;GAyCjB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;mBA+BvB,CAAC"}
|
|
@@ -37,6 +37,9 @@ async function saveAllowance(ctx, existing, row) {
|
|
|
37
37
|
? ctx.db.insert("allowances", row)
|
|
38
38
|
: ctx.db.patch("allowances", existing._id, row));
|
|
39
39
|
}
|
|
40
|
+
async function saveUsed(ctx, id, used) {
|
|
41
|
+
await ctx.db.patch("allowances", id, { updatedAt: Date.now(), used });
|
|
42
|
+
}
|
|
40
43
|
export const consume = mutation({
|
|
41
44
|
args: {
|
|
42
45
|
amount: v.number(),
|
|
@@ -100,10 +103,8 @@ export const refund = mutation({
|
|
|
100
103
|
};
|
|
101
104
|
}
|
|
102
105
|
const used = Math.max(existing.used - arguments_.amount, 0);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
used,
|
|
106
|
-
});
|
|
106
|
+
if (used !== existing.used)
|
|
107
|
+
await saveUsed(ctx, existing._id, used);
|
|
107
108
|
return {
|
|
108
109
|
refunded: true,
|
|
109
110
|
remaining: Math.max(existing.limit - used, 0),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,OAAO,EACL,mBAAmB,EACnB,eAAe,EAEf,eAAe,GAEhB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAoB,MAAM,wBAAwB,CAAC;AACpE,OAAO,EACL,aAAa,EACb,aAAa,EACb,IAAI,EACJ,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC;AAEzB,KAAK,UAAU,aAAa,CAC1B,GAAgB,EAChB,EACE,GAAG,EACH,KAAK,EACL,UAAU,GACyC;IAErD,OAAO,GAAG,CAAC,EAAE;SACV,KAAK,CAAC,YAAY,CAAC;SACnB,SAAS,CAAC,sBAAsB,EAAE,CAAC,CAAC,EAAE,EAAE,CACvC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CACjE;SACA,KAAK,EAAE,CAAC;AACb,CAAC;AAED,S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ACD,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC"}
|
|
@@ -7,7 +7,7 @@ export declare const remaining: import("convex/server").RegisteredQuery<"public"
|
|
|
7
7
|
kind: "calendar";
|
|
8
8
|
period: "day" | "month" | "week";
|
|
9
9
|
timeZone: string;
|
|
10
|
-
weekStartsOn?: "monday" | "sunday"
|
|
10
|
+
weekStartsOn?: "monday" | "sunday";
|
|
11
11
|
} | {
|
|
12
12
|
durationMs: number;
|
|
13
13
|
kind: "rolling";
|
|
@@ -16,7 +16,7 @@ export declare const windowSpec: import("convex/values").VUnion<{
|
|
|
16
16
|
kind: "calendar";
|
|
17
17
|
period: "day" | "month" | "week";
|
|
18
18
|
timeZone: string;
|
|
19
|
-
weekStartsOn?: "monday" | "sunday"
|
|
19
|
+
weekStartsOn?: "monday" | "sunday";
|
|
20
20
|
} | {
|
|
21
21
|
durationMs: number;
|
|
22
22
|
kind: "rolling";
|
|
@@ -27,7 +27,7 @@ export declare const windowSpec: import("convex/values").VUnion<{
|
|
|
27
27
|
kind: "calendar";
|
|
28
28
|
period: "day" | "month" | "week";
|
|
29
29
|
timeZone: string;
|
|
30
|
-
weekStartsOn?: "monday" | "sunday"
|
|
30
|
+
weekStartsOn?: "monday" | "sunday";
|
|
31
31
|
}, {
|
|
32
32
|
kind: import("convex/values").VLiteral<"calendar", "required">;
|
|
33
33
|
period: import("convex/values").VUnion<"day" | "month" | "week", [import("convex/values").VLiteral<"day", "required">, import("convex/values").VLiteral<"week", "required">, import("convex/values").VLiteral<"month", "required">], "required", never>;
|
package/docs/API.md
CHANGED
|
@@ -14,6 +14,19 @@ at most 256 UTF-16 code units (`INVALID_REF`). Amounts and limits must be
|
|
|
14
14
|
positive safe integers (`INVALID_AMOUNT`, `INVALID_LIMIT`). Scope defaults to
|
|
15
15
|
`"global"`. All component errors use `ConvexError({ code, message })`.
|
|
16
16
|
|
|
17
|
+
## Entry points
|
|
18
|
+
|
|
19
|
+
| Import | Exports |
|
|
20
|
+
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `@vllnt/convex-quota` | `Quota` class; types `QuotaComponent`, `QuotaOptions`, `ConsumeOptions`, `ConsumeResult`, `RemainingState`, `RefundResult`, `WindowSpec` |
|
|
22
|
+
| `@vllnt/convex-quota/convex.config` | the component definition, for `app.use(quota)` |
|
|
23
|
+
| `@vllnt/convex-quota/test` | `register(t, name = "quota")` for `convex-test` (needs `convex-test` and Vite's `import.meta.glob`) |
|
|
24
|
+
| `@vllnt/convex-quota/_generated/component.js` | type `ComponentApi` |
|
|
25
|
+
|
|
26
|
+
`./convex.config.js` and `./_generated/component` are aliases of the
|
|
27
|
+
`./convex.config` and `./_generated/component.js` entries; `./package.json` is
|
|
28
|
+
also exported.
|
|
29
|
+
|
|
17
30
|
## Windows
|
|
18
31
|
|
|
19
32
|
- `{ kind: "calendar", period: "day" | "week" | "month", timeZone: string, weekStartsOn?: "monday" | "sunday" }`
|
package/llms.txt
CHANGED
|
@@ -32,13 +32,27 @@ to the `latest` dist-tag with npm provenance, unreleased builds from main go to
|
|
|
32
32
|
`canary`. The sole client option is `defaultScope` (default `"global"`); consume
|
|
33
33
|
amount defaults to 1.
|
|
34
34
|
|
|
35
|
+
## For coding agents
|
|
36
|
+
|
|
37
|
+
The docs are bundled in the npm package at
|
|
38
|
+
`node_modules/@vllnt/convex-quota/docs/`, with `README.md`, `CHANGELOG.md` and
|
|
39
|
+
`llms.txt` in the package root and the TypeScript sources in `src/`. They match
|
|
40
|
+
the installed version. Read them before writing code.
|
|
41
|
+
|
|
35
42
|
## Docs
|
|
36
43
|
|
|
37
|
-
- [README](
|
|
38
|
-
- [API Reference](
|
|
39
|
-
- [Changelog](
|
|
44
|
+
- [README](./README.md): Setup, behavior, security, multi-mount and limitations
|
|
45
|
+
- [API Reference](./docs/API.md): Exact signatures, results and error semantics
|
|
46
|
+
- [Changelog](./CHANGELOG.md): Release notes
|
|
47
|
+
- [License](./LICENSE): MIT
|
|
48
|
+
|
|
49
|
+
## Repository (not in the npm package)
|
|
50
|
+
|
|
40
51
|
- [Contributing](https://github.com/vllnt/convex-quota/blob/main/CONTRIBUTING.md): Development workflow
|
|
41
52
|
- [Example wrapper](https://github.com/vllnt/convex-quota/blob/main/example/convex/example.ts): Unauthenticated test fixtures, not production endpoints
|
|
42
53
|
- [Tests](https://github.com/vllnt/convex-quota/blob/main/example/convex/example.test.ts): convex-test mock integration tests, not real OCC proof
|
|
43
54
|
- [Security Policy](https://github.com/vllnt/convex-quota/blob/main/SECURITY.md): Reporting
|
|
44
|
-
|
|
55
|
+
|
|
56
|
+
## Ecosystem
|
|
57
|
+
|
|
58
|
+
- [vllnt oss](https://oss.vllnt.com/llms.txt): Index of vllnt open-source packages
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/convex-quota",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-canary.0f19804",
|
|
4
4
|
"description": "Scheduled-reset per-subject allowances as a Convex component — calendar, rolling, or epoch windows with readable remaining",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"packageManager": "pnpm@10.34.
|
|
7
|
+
"packageManager": "pnpm@10.34.9",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"src",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"CHANGELOG.md",
|
|
13
13
|
"llms.txt",
|
|
14
14
|
"!src/**/*.test.*",
|
|
15
|
-
"!src/**/*.spec.*"
|
|
15
|
+
"!src/**/*.spec.*"
|
|
16
|
+
],
|
|
16
17
|
"exports": {
|
|
17
18
|
"./package.json": "./package.json",
|
|
18
19
|
".": {
|
|
@@ -60,17 +61,17 @@
|
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@edge-runtime/vm": "^5.0.0",
|
|
62
63
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
63
|
-
"@vitest/coverage-v8": "^5.
|
|
64
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
64
65
|
"@vllnt/convex-idempotency": "^0.1.0",
|
|
65
|
-
"@vllnt/eslint-config": "2.
|
|
66
|
-
"@vllnt/typescript": "
|
|
67
|
-
"convex": "^1.
|
|
68
|
-
"convex-test": "^0.0.
|
|
66
|
+
"@vllnt/eslint-config": "2.1.0",
|
|
67
|
+
"@vllnt/typescript": "3.0.0",
|
|
68
|
+
"convex": "^1.51.0",
|
|
69
|
+
"convex-test": "^0.0.73",
|
|
69
70
|
"eslint": "^9.39.5",
|
|
70
|
-
"prettier": "^3.
|
|
71
|
+
"prettier": "^3.10.1",
|
|
71
72
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
72
|
-
"vite": "^8.3.
|
|
73
|
-
"vitest": "^5.
|
|
73
|
+
"vite": "^8.3.8",
|
|
74
|
+
"vitest": "^5.1.1"
|
|
74
75
|
},
|
|
75
76
|
"pnpm": {
|
|
76
77
|
"minimumReleaseAge": 10080,
|
|
@@ -81,11 +82,12 @@
|
|
|
81
82
|
"esbuild"
|
|
82
83
|
],
|
|
83
84
|
"overrides": {
|
|
85
|
+
"minimatch@>=7.0.0 <11.0.1": "11.0.9",
|
|
84
86
|
"deepmerge-ts@<8.0.0": "^8.0.2",
|
|
85
87
|
"handlebars@<4.7.10": "^4.7.10"
|
|
86
88
|
}
|
|
87
89
|
},
|
|
88
|
-
"homepage": "https://
|
|
90
|
+
"homepage": "https://oss.vllnt.com/packages/convex-quota",
|
|
89
91
|
"bugs": {
|
|
90
92
|
"url": "https://github.com/vllnt/convex-quota/issues"
|
|
91
93
|
},
|
package/src/client/index.ts
CHANGED
|
@@ -77,6 +77,14 @@ async function saveAllowance(
|
|
|
77
77
|
: ctx.db.patch("allowances", existing._id, row));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
async function saveUsed(
|
|
81
|
+
ctx: MutationCtx,
|
|
82
|
+
id: Document_<"allowances">["_id"],
|
|
83
|
+
used: number,
|
|
84
|
+
) {
|
|
85
|
+
await ctx.db.patch("allowances", id, { updatedAt: Date.now(), used });
|
|
86
|
+
}
|
|
87
|
+
|
|
80
88
|
export const consume = mutation({
|
|
81
89
|
args: {
|
|
82
90
|
amount: v.number(),
|
|
@@ -149,10 +157,7 @@ export const refund = mutation({
|
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
const used = Math.max(existing.used - arguments_.amount, 0);
|
|
152
|
-
await ctx
|
|
153
|
-
updatedAt: Date.now(),
|
|
154
|
-
used,
|
|
155
|
-
});
|
|
160
|
+
if (used !== existing.used) await saveUsed(ctx, existing._id, used);
|
|
156
161
|
return {
|
|
157
162
|
refunded: true,
|
|
158
163
|
remaining: Math.max(existing.limit - used, 0),
|