@vllnt/convex-quota 0.1.0-canary.0
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 +29 -0
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/client/index.d.ts +59 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +58 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +32 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +3 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +38 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +100 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +133 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +80 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +4 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/mutations.d.ts +43 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +164 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +25 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +52 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +34 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +22 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +101 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +61 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/shared.d.ts +66 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +208 -0
- package/dist/shared.js.map +1 -0
- package/docs/API.md +94 -0
- package/llms-full.txt +1324 -0
- package/llms.txt +43 -0
- package/package.json +90 -0
- package/src/client/index.ts +179 -0
- package/src/client/types.ts +37 -0
- package/src/component/_generated/api.ts +54 -0
- package/src/component/_generated/component.ts +114 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +169 -0
- package/src/component/convex.config.ts +5 -0
- package/src/component/mutations.ts +219 -0
- package/src/component/queries.ts +72 -0
- package/src/component/schema.ts +22 -0
- package/src/component/validators.ts +89 -0
- package/src/shared.ts +324 -0
- package/src/test.ts +16 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Initial implementation of `@vllnt/convex-quota` (not yet released).
|
|
12
|
+
- Calendar (day / week / month), rolling, and epoch windows.
|
|
13
|
+
- `consume`, `remaining`, `refund`, `eraseSubject` (batched).
|
|
14
|
+
- Ref length limits (1..256). Server-sourced window math.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Reject unsafe numeric allowance values, invalid query inputs, unbounded scopes,
|
|
19
|
+
and overflowing or sub-millisecond durations.
|
|
20
|
+
- Bind each allowance to its window policy and reject policy reinterpretation.
|
|
21
|
+
- Resolve skipped/repeated civil midnights and reject refunds of expired rows.
|
|
22
|
+
- Correct mock-backend testing claims and document refund deduplication,
|
|
23
|
+
subscription expiry, erasure races, and multi-mount behavior.
|
|
24
|
+
|
|
25
|
+
### Migration note
|
|
26
|
+
|
|
27
|
+
- The unreleased allowance schema now requires `policyKey`. Existing development
|
|
28
|
+
rows must be cleared in an isolated development deployment before updating;
|
|
29
|
+
no production migration has been performed.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bntvllnt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<!-- Badges -->
|
|
2
|
+
[](https://www.convex.dev/components)
|
|
3
|
+
[](https://www.npmjs.com/package/@vllnt/convex-quota)
|
|
4
|
+
[](https://github.com/vllnt/convex-quota/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
# @vllnt/convex-quota
|
|
8
|
+
|
|
9
|
+
Scheduled-reset per-subject allowances as a Convex component.
|
|
10
|
+
|
|
11
|
+
Readable remaining in a window — calendar day/week/month, rolling, or epoch.
|
|
12
|
+
Daily/weekly play caps, free-tier slots, Codex-style limits.
|
|
13
|
+
|
|
14
|
+
The official `@convex-dev/rate-limiter` already supports fixed windows, token
|
|
15
|
+
buckets, readable status and React hooks. Prefer it for general throttling.
|
|
16
|
+
This experimental component explores the narrower calendar/timezone reset and
|
|
17
|
+
privileged allowance-refund surface. It is not billable metering or a persistent
|
|
18
|
+
balance. Publication remains blocked on demonstrated independent consumers and
|
|
19
|
+
justification of this boundary; readable remaining alone is not a distinction.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const quota = new Quota(components.quota);
|
|
23
|
+
const r = await quota.consume(ctx, subjectRef, "plays", 3, {
|
|
24
|
+
kind: "calendar",
|
|
25
|
+
period: "day",
|
|
26
|
+
timeZone: "Europe/Paris",
|
|
27
|
+
});
|
|
28
|
+
if (!r.allowed) throw new Error(`try again at ${r.resetsAt}`);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Readable remaining** — both return `{ used, remaining, limit, periodKey, resetsAt }`; only `consume` includes `allowed`.
|
|
34
|
+
- **Window kinds** — calendar (`day` / `week` / `month` + IANA timezone), rolling (from first consume), epoch (`floor(now / durationMs)`).
|
|
35
|
+
- **Server-sourced time** — window math uses `Date.now()` inside the component.
|
|
36
|
+
- **Opaque refs** — `subjectRef`, `key`, and `scope` are host strings (1..256 UTF-16 code units).
|
|
37
|
+
- **Bounded erase** — `eraseSubject` deletes in batches and reschedules until clean.
|
|
38
|
+
- **Scopes** — default `"global"`, or namespace per tenant / product.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm add @vllnt/convex-quota
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Node.js >=22.12.0; peer dependency: `convex@^1.45.0`.
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// convex/convex.config.ts
|
|
52
|
+
import { defineApp } from "convex/server";
|
|
53
|
+
import quota from "@vllnt/convex-quota/convex.config";
|
|
54
|
+
|
|
55
|
+
const app = defineApp();
|
|
56
|
+
app.use(quota);
|
|
57
|
+
export default app;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { components } from "./_generated/api";
|
|
62
|
+
import { mutation } from "./_generated/server";
|
|
63
|
+
import { Quota } from "@vllnt/convex-quota";
|
|
64
|
+
|
|
65
|
+
const quota = new Quota(components.quota);
|
|
66
|
+
|
|
67
|
+
export const play = mutation({
|
|
68
|
+
args: {},
|
|
69
|
+
handler: async (ctx) => {
|
|
70
|
+
const subjectRef = /* host-resolved identity */ "user_1";
|
|
71
|
+
const r = await quota.consume(ctx, subjectRef, "plays", 5, {
|
|
72
|
+
kind: "calendar",
|
|
73
|
+
period: "day",
|
|
74
|
+
timeZone: "Europe/Paris",
|
|
75
|
+
});
|
|
76
|
+
if (!r.allowed) throw new Error("daily cap reached");
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Host rules:**
|
|
82
|
+
|
|
83
|
+
- Never take `limit` or `amount` from the end-user. The host supplies them.
|
|
84
|
+
- `consume` is not idempotent. Wrap retries with `@vllnt/convex-idempotency`.
|
|
85
|
+
- `refund` is privileged and **not idempotent**. Deduplicate refund events in the host transaction; `periodKey` is a window label, not a receipt or replay token.
|
|
86
|
+
- Keep window policy fixed for each `(scope, subjectRef, key)`; changes throw `POLICY_MISMATCH`. Use a new key for a new policy. Limits may change without resetting usage.
|
|
87
|
+
- Stop new consumes before erasing a subject and keep them stopped until scheduled passes drain. Erasure is not a tombstone; concurrent writes can survive or be swept.
|
|
88
|
+
- The example wrappers are unauthenticated test fixtures, not production endpoints.
|
|
89
|
+
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
| Method | Kind | Result |
|
|
93
|
+
|--------|------|--------|
|
|
94
|
+
| `consume(ctx, subjectRef, key, limit, window, opts?)` | mutation | `{ allowed, remaining, used, limit, periodKey, resetsAt }` |
|
|
95
|
+
| `remaining(ctx, subjectRef, key, limit, window, scope?)` | query | same fields without `allowed` |
|
|
96
|
+
| `refund(ctx, subjectRef, key, amount, periodKey, scope?)` | mutation | `{ refunded, used, remaining }` |
|
|
97
|
+
| `eraseSubject(ctx, subjectRef, scope?, batch?)` | mutation | `number` deleted this pass |
|
|
98
|
+
|
|
99
|
+
Full reference: [docs/API.md](docs/API.md).
|
|
100
|
+
|
|
101
|
+
## Multiple mounts
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
app.use(quota, { name: "webQuota" });
|
|
105
|
+
app.use(quota, { name: "mobileQuota" });
|
|
106
|
+
// new Quota(components.webQuota), new Quota(components.mobileQuota)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Each mount has independent sandboxed tables. Use `scope` for runtime namespaces.
|
|
110
|
+
|
|
111
|
+
## Operational behavior
|
|
112
|
+
|
|
113
|
+
`remaining` is a snapshot when its query executes: **time passing alone does not
|
|
114
|
+
invalidate a Convex subscription**. Treat `resetsAt` as an expiry hint, not a
|
|
115
|
+
scheduled notification; `consume` always rechecks server time. Rolling windows
|
|
116
|
+
start on the first **allowed** consume. No history or audit events are retained.
|
|
117
|
+
Hosts should record denied decisions and privileged refunds in their own audit
|
|
118
|
+
system without logging sensitive refs. A hot allowance is one contended row;
|
|
119
|
+
different indexed keys remain independent. Monitor Convex OCC retries and
|
|
120
|
+
scheduled-function failures. Erasure returns only its first pass count.
|
|
121
|
+
|
|
122
|
+
## React
|
|
123
|
+
|
|
124
|
+
Backend-only — no `./react` entry. Remaining is typically shown through the host's own query.
|
|
125
|
+
|
|
126
|
+
## Security
|
|
127
|
+
|
|
128
|
+
- Auth-agnostic — the host resolves identity and passes an opaque `subjectRef`.
|
|
129
|
+
- Tables sandboxed — reached only through the exported functions.
|
|
130
|
+
- Server-sourced windows — a skewed client clock cannot pick the period.
|
|
131
|
+
|
|
132
|
+
See [docs/API.md](docs/API.md).
|
|
133
|
+
|
|
134
|
+
## Testing
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pnpm test
|
|
138
|
+
pnpm test:coverage
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Unit/integration tests use the **mock backend** `convex-test` (`@edge-runtime/vm`).
|
|
142
|
+
They do not establish real-backend OCC or scheduler guarantees.
|
|
143
|
+
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
147
|
+
|
|
148
|
+
## Author
|
|
149
|
+
|
|
150
|
+
Built by [bntvllnt](https://github.com/bntvllnt) · [bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
151
|
+
|
|
152
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
153
|
+
|
|
154
|
+
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { FunctionArgs, FunctionReference, FunctionReturnType } from "convex/server";
|
|
2
|
+
import type { ConsumeOptions, ConsumeResult, QuotaOptions, RefundResult, RemainingState, WindowSpec } from "./types.js";
|
|
3
|
+
export type QuotaComponent = {
|
|
4
|
+
mutations: {
|
|
5
|
+
consume: FunctionReference<"mutation", "internal", {
|
|
6
|
+
amount: number;
|
|
7
|
+
key: string;
|
|
8
|
+
limit: number;
|
|
9
|
+
scope: string;
|
|
10
|
+
subjectRef: string;
|
|
11
|
+
window: WindowSpec;
|
|
12
|
+
}, ConsumeResult>;
|
|
13
|
+
eraseSubject: FunctionReference<"mutation", "internal", {
|
|
14
|
+
batch?: number;
|
|
15
|
+
scope: string;
|
|
16
|
+
subjectRef: string;
|
|
17
|
+
}, number>;
|
|
18
|
+
refund: FunctionReference<"mutation", "internal", {
|
|
19
|
+
amount: number;
|
|
20
|
+
key: string;
|
|
21
|
+
periodKey: string;
|
|
22
|
+
scope: string;
|
|
23
|
+
subjectRef: string;
|
|
24
|
+
}, RefundResult>;
|
|
25
|
+
};
|
|
26
|
+
queries: {
|
|
27
|
+
remaining: FunctionReference<"query", "internal", {
|
|
28
|
+
key: string;
|
|
29
|
+
limit: number;
|
|
30
|
+
scope: string;
|
|
31
|
+
subjectRef: string;
|
|
32
|
+
window: WindowSpec;
|
|
33
|
+
}, RemainingState>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
type RunQueryCtx = {
|
|
37
|
+
runQuery<TQuery extends FunctionReference<"query", "internal">>(reference: TQuery, arguments_: FunctionArgs<TQuery>): Promise<FunctionReturnType<TQuery>>;
|
|
38
|
+
};
|
|
39
|
+
type RunMutationCtx = {
|
|
40
|
+
runMutation<TMutation extends FunctionReference<"mutation", "internal">>(reference: TMutation, arguments_: FunctionArgs<TMutation>): Promise<FunctionReturnType<TMutation>>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Consumer-facing client for the scheduled-reset quota ledger. The host owns
|
|
44
|
+
* auth and meaning; it passes an opaque `subjectRef` + `key` and a window spec.
|
|
45
|
+
* Never take `limit` from an end-user. Time is server-sourced. Consume is not
|
|
46
|
+
* idempotent — wrap with `@vllnt/convex-idempotency` if retries must not double-count.
|
|
47
|
+
*/
|
|
48
|
+
export declare class Quota {
|
|
49
|
+
private readonly component;
|
|
50
|
+
private readonly defaultScope;
|
|
51
|
+
constructor(component: QuotaComponent, options?: QuotaOptions);
|
|
52
|
+
private scopeOf;
|
|
53
|
+
consume(ctx: RunMutationCtx, subjectRef: string, key: string, limit: number, window: WindowSpec, options?: ConsumeOptions): Promise<ConsumeResult>;
|
|
54
|
+
remaining(ctx: RunQueryCtx, subjectRef: string, key: string, limit: number, window: WindowSpec, scope?: string): Promise<RemainingState>;
|
|
55
|
+
refund(ctx: RunMutationCtx, subjectRef: string, key: string, amount: number, periodKey: string, scope?: string): Promise<RefundResult>;
|
|
56
|
+
eraseSubject(ctx: RunMutationCtx, subjectRef: string, scope?: string, batch?: number): Promise<number>;
|
|
57
|
+
}
|
|
58
|
+
export { type ConsumeOptions, type ConsumeResult, type QuotaOptions, type RefundResult, type RemainingState, type WindowSpec, } from "./types.js";
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DEFAULT_SCOPE } from "../shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Consumer-facing client for the scheduled-reset quota ledger. The host owns
|
|
4
|
+
* auth and meaning; it passes an opaque `subjectRef` + `key` and a window spec.
|
|
5
|
+
* Never take `limit` from an end-user. Time is server-sourced. Consume is not
|
|
6
|
+
* idempotent — wrap with `@vllnt/convex-idempotency` if retries must not double-count.
|
|
7
|
+
*/
|
|
8
|
+
export class Quota {
|
|
9
|
+
component;
|
|
10
|
+
defaultScope;
|
|
11
|
+
constructor(component, options = {}) {
|
|
12
|
+
this.component = component;
|
|
13
|
+
this.defaultScope = options.defaultScope ?? DEFAULT_SCOPE;
|
|
14
|
+
}
|
|
15
|
+
scopeOf(scope) {
|
|
16
|
+
return scope ?? this.defaultScope;
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line max-params -- Preserve the published positional client contract.
|
|
19
|
+
consume(ctx, subjectRef, key, limit, window, options = {}) {
|
|
20
|
+
return ctx.runMutation(this.component.mutations.consume, {
|
|
21
|
+
amount: options.amount ?? 1,
|
|
22
|
+
key,
|
|
23
|
+
limit,
|
|
24
|
+
scope: this.scopeOf(options.scope),
|
|
25
|
+
subjectRef,
|
|
26
|
+
window,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line max-params -- Preserve the published positional client contract.
|
|
30
|
+
remaining(ctx, subjectRef, key, limit, window, scope) {
|
|
31
|
+
return ctx.runQuery(this.component.queries.remaining, {
|
|
32
|
+
key,
|
|
33
|
+
limit,
|
|
34
|
+
scope: this.scopeOf(scope),
|
|
35
|
+
subjectRef,
|
|
36
|
+
window,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line max-params -- Preserve the published positional client contract.
|
|
40
|
+
refund(ctx, subjectRef, key, amount, periodKey, scope) {
|
|
41
|
+
return ctx.runMutation(this.component.mutations.refund, {
|
|
42
|
+
amount,
|
|
43
|
+
key,
|
|
44
|
+
periodKey,
|
|
45
|
+
scope: this.scopeOf(scope),
|
|
46
|
+
subjectRef,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line max-params -- Preserve the published positional client contract.
|
|
50
|
+
eraseSubject(ctx, subjectRef, scope, batch) {
|
|
51
|
+
return ctx.runMutation(this.component.mutations.eraseSubject, {
|
|
52
|
+
batch,
|
|
53
|
+
scope: this.scopeOf(scope),
|
|
54
|
+
subjectRef,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,4FAA4F;IAC5F,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,MAAM,IAAI,CAAC;YAC3B,GAAG;YACH,KAAK;YACL,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;YAClC,UAAU;YACV,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,4FAA4F;IAC5F,SAAS,CACP,GAAgB,EAChB,UAAkB,EAClB,GAAW,EACX,KAAa,EACb,MAAkB,EAClB,KAAc;QAEd,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE;YACpD,GAAG;YACH,KAAK;YACL,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,UAAU;YACV,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,4FAA4F;IAC5F,MAAM,CACJ,GAAmB,EACnB,UAAkB,EAClB,GAAW,EACX,MAAc,EACd,SAAiB,EACjB,KAAc;QAEd,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE;YACtD,MAAM;YACN,GAAG;YACH,SAAS;YACT,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,4FAA4F;IAC5F,YAAY,CACV,GAAmB,EACnB,UAAkB,EAClB,KAAc,EACd,KAAc;QAEd,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,YAAY,EAAE;YAC5D,KAAK;YACL,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAC1B,UAAU;SACX,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Public TypeScript surface for the quota client. */
|
|
2
|
+
export type ConsumeResult = {
|
|
3
|
+
allowed: boolean;
|
|
4
|
+
limit: number;
|
|
5
|
+
periodKey: string;
|
|
6
|
+
remaining: number;
|
|
7
|
+
resetsAt: number;
|
|
8
|
+
used: number;
|
|
9
|
+
};
|
|
10
|
+
export type RemainingState = {
|
|
11
|
+
limit: number;
|
|
12
|
+
periodKey: string;
|
|
13
|
+
remaining: number;
|
|
14
|
+
resetsAt: number;
|
|
15
|
+
used: number;
|
|
16
|
+
};
|
|
17
|
+
export type RefundResult = {
|
|
18
|
+
refunded: boolean;
|
|
19
|
+
remaining: number;
|
|
20
|
+
used: number;
|
|
21
|
+
};
|
|
22
|
+
export type QuotaOptions = {
|
|
23
|
+
/** Namespace applied when a call omits `scope`. Default `"global"`. */
|
|
24
|
+
defaultScope?: string;
|
|
25
|
+
};
|
|
26
|
+
export type ConsumeOptions = {
|
|
27
|
+
/** Units to consume. Default `1`. */
|
|
28
|
+
amount?: number;
|
|
29
|
+
scope?: string;
|
|
30
|
+
};
|
|
31
|
+
export { type WindowSpec } from "../shared.js";
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,sDAAsD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `api` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type * as mutations from "../mutations.js";
|
|
10
|
+
import type * as queries from "../queries.js";
|
|
11
|
+
import type * as validators from "../validators.js";
|
|
12
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
13
|
+
declare const fullApi: ApiFromModules<{
|
|
14
|
+
mutations: typeof mutations;
|
|
15
|
+
queries: typeof queries;
|
|
16
|
+
validators: typeof validators;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* ```js
|
|
23
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
27
|
+
/**
|
|
28
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
29
|
+
*
|
|
30
|
+
* Usage:
|
|
31
|
+
* ```js
|
|
32
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
36
|
+
export declare const components: {};
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,KAAK,OAAO,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,UAAU,EAAE,OAAO,UAAU,CAAC;CAC/B,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
11
|
+
const fullApi = anyApi;
|
|
12
|
+
/**
|
|
13
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```js
|
|
17
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const api = anyApi;
|
|
21
|
+
/**
|
|
22
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* ```js
|
|
26
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const internal = anyApi;
|
|
30
|
+
export const components = componentsGeneric();
|
|
31
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAWH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAIR,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAmB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `ComponentApi` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FunctionReference } from "convex/server";
|
|
10
|
+
/**
|
|
11
|
+
* A utility for referencing a Convex component's exposed API.
|
|
12
|
+
*
|
|
13
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
17
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
22
|
+
mutations: {
|
|
23
|
+
consume: FunctionReference<"mutation", "internal", {
|
|
24
|
+
amount: number;
|
|
25
|
+
key: string;
|
|
26
|
+
limit: number;
|
|
27
|
+
scope: string;
|
|
28
|
+
subjectRef: string;
|
|
29
|
+
window: {
|
|
30
|
+
kind: "calendar";
|
|
31
|
+
period: "day" | "week" | "month";
|
|
32
|
+
timeZone: string;
|
|
33
|
+
weekStartsOn?: "monday" | "sunday";
|
|
34
|
+
} | {
|
|
35
|
+
durationMs: number;
|
|
36
|
+
kind: "rolling";
|
|
37
|
+
} | {
|
|
38
|
+
durationMs: number;
|
|
39
|
+
kind: "epoch";
|
|
40
|
+
};
|
|
41
|
+
}, {
|
|
42
|
+
allowed: true;
|
|
43
|
+
limit: number;
|
|
44
|
+
periodKey: string;
|
|
45
|
+
remaining: number;
|
|
46
|
+
resetsAt: number;
|
|
47
|
+
used: number;
|
|
48
|
+
} | {
|
|
49
|
+
allowed: false;
|
|
50
|
+
limit: number;
|
|
51
|
+
periodKey: string;
|
|
52
|
+
remaining: number;
|
|
53
|
+
resetsAt: number;
|
|
54
|
+
used: number;
|
|
55
|
+
}, Name>;
|
|
56
|
+
eraseSubject: FunctionReference<"mutation", "internal", {
|
|
57
|
+
batch?: number;
|
|
58
|
+
scope: string;
|
|
59
|
+
subjectRef: string;
|
|
60
|
+
}, number, Name>;
|
|
61
|
+
refund: FunctionReference<"mutation", "internal", {
|
|
62
|
+
amount: number;
|
|
63
|
+
key: string;
|
|
64
|
+
periodKey: string;
|
|
65
|
+
scope: string;
|
|
66
|
+
subjectRef: string;
|
|
67
|
+
}, {
|
|
68
|
+
refunded: boolean;
|
|
69
|
+
remaining: number;
|
|
70
|
+
used: number;
|
|
71
|
+
}, Name>;
|
|
72
|
+
};
|
|
73
|
+
queries: {
|
|
74
|
+
remaining: FunctionReference<"query", "internal", {
|
|
75
|
+
key: string;
|
|
76
|
+
limit: number;
|
|
77
|
+
scope: string;
|
|
78
|
+
subjectRef: string;
|
|
79
|
+
window: {
|
|
80
|
+
kind: "calendar";
|
|
81
|
+
period: "day" | "week" | "month";
|
|
82
|
+
timeZone: string;
|
|
83
|
+
weekStartsOn?: "monday" | "sunday";
|
|
84
|
+
} | {
|
|
85
|
+
durationMs: number;
|
|
86
|
+
kind: "rolling";
|
|
87
|
+
} | {
|
|
88
|
+
durationMs: number;
|
|
89
|
+
kind: "epoch";
|
|
90
|
+
};
|
|
91
|
+
}, {
|
|
92
|
+
limit: number;
|
|
93
|
+
periodKey: string;
|
|
94
|
+
remaining: number;
|
|
95
|
+
resetsAt: number;
|
|
96
|
+
used: number;
|
|
97
|
+
}, Name>;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated data model types.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { DataModelFromSchemaDefinition, DocumentByName, TableNamesInDataModel, SystemTableNames } from "convex/server";
|
|
10
|
+
import type { GenericId } from "convex/values";
|
|
11
|
+
import schema from "../schema.js";
|
|
12
|
+
/**
|
|
13
|
+
* The names of all of your Convex tables.
|
|
14
|
+
*/
|
|
15
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
16
|
+
/**
|
|
17
|
+
* The type of a document stored in Convex.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
20
|
+
*/
|
|
21
|
+
export type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
22
|
+
/**
|
|
23
|
+
* An identifier for a document in Convex.
|
|
24
|
+
*
|
|
25
|
+
* Convex documents are uniquely identified by their `Id`, which is accessible
|
|
26
|
+
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
|
|
27
|
+
*
|
|
28
|
+
* Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
|
|
29
|
+
*
|
|
30
|
+
* IDs are just strings at runtime, but this type can be used to distinguish them from other
|
|
31
|
+
* strings when type checking.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
34
|
+
*/
|
|
35
|
+
export type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
36
|
+
/**
|
|
37
|
+
* A type describing your Convex data model.
|
|
38
|
+
*
|
|
39
|
+
* This type includes information about what tables you have, the type of
|
|
40
|
+
* documents stored in those tables, and the indexes defined on them.
|
|
41
|
+
*
|
|
42
|
+
* This type is used to parameterize methods like `queryGeneric` and
|
|
43
|
+
* `mutationGeneric` to make them type-safe.
|
|
44
|
+
*/
|
|
45
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
|
|
46
|
+
//# sourceMappingURL=dataModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataModel.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,6BAA6B,EAC7B,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,MAAM,GAAG,CAAC,SAAS,SAAS,UAAU,IAAI,cAAc,CAC5D,SAAS,EACT,SAAS,CACV,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,EAAE,CAAC,SAAS,SAAS,UAAU,GAAG,gBAAgB,IAC5D,SAAS,CAAC,SAAS,CAAC,CAAC;AAEvB;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,6BAA6B,CAAC,OAAO,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataModel.js","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG"}
|