@vllnt/convex-reactions 0.1.0 → 0.1.1-canary.1efeefa
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 +100 -0
- package/README.md +133 -44
- package/dist/component/_generated/api.d.ts +2 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/mutations.d.ts +6 -1
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +33 -4
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts +2 -9
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +16 -20
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.d.ts +11 -3
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +6 -4
- package/dist/component/schema.js.map +1 -1
- package/dist/component/tally.d.ts +4 -0
- package/dist/component/tally.d.ts.map +1 -0
- package/dist/component/tally.js +44 -0
- package/dist/component/tally.js.map +1 -0
- package/docs/API.md +118 -0
- package/llms.txt +33 -0
- package/package.json +40 -20
- package/src/component/_generated/api.ts +2 -0
- package/src/component/mutations.ts +38 -4
- package/src/component/queries.ts +25 -23
- package/src/component/schema.ts +6 -4
- package/src/component/tally.ts +58 -0
- package/src/test.ts +13 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
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
|
|
5
|
+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.1.1] - Unreleased
|
|
8
|
+
|
|
9
|
+
### Upgrading
|
|
10
|
+
|
|
11
|
+
- Downgrading to 0.1.0 is not supported once 0.1.1 has written `reactionCounts`
|
|
12
|
+
tally rows: 0.1.0 writes edges without updating tallies, so upgrading again
|
|
13
|
+
would leave stale counts.
|
|
14
|
+
- Edges with an empty `authorRef`, `resourceRef`, or `kind` stored under 0.1.0
|
|
15
|
+
can no longer be removed through `react` or `unreact` (they now throw
|
|
16
|
+
`INVALID_REF` or `INVALID_KIND` first). If you have such rows, remove them
|
|
17
|
+
yourself; a resource that holds one keeps counting from edges.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- `react` and `unreact` now throw `ConvexError` `INVALID_REF` for an empty
|
|
22
|
+
`authorRef` or `resourceRef` and `INVALID_KIND` for an empty `kind`, instead
|
|
23
|
+
of storing an edge no real subject, resource, or kind can address. Previously
|
|
24
|
+
accepted input that could never be valid.
|
|
25
|
+
- `@vllnt/convex-reactions/test` now type-checks for consumers using
|
|
26
|
+
`moduleResolution` `nodenext` as well as `bundler` (explicit `.js` relative
|
|
27
|
+
imports, Vite client types reference).
|
|
28
|
+
- `register(t)` from `@vllnt/convex-reactions/test` accepts a `convexTest`
|
|
29
|
+
instance built from the host app's own schema; it was typed for the
|
|
30
|
+
component's schema only, so a host schema with its own tables failed to
|
|
31
|
+
type-check (TS2345). No runtime change.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- `counts` reads one `reactionCounts` tally row per kind instead of every edge
|
|
36
|
+
on the resource: O(kinds) reads instead of O(edges). Tallies cover every
|
|
37
|
+
resource whose first reaction came after upgrade; a resource with earlier
|
|
38
|
+
edges keeps the edge scan (no migration, and writes never scan legacy edges).
|
|
39
|
+
A tally row is deleted when its count reaches zero.
|
|
40
|
+
- `myReactions` uses the `by_author_resource_kind` prefix; the redundant
|
|
41
|
+
`by_author_resource` index is removed (one less index write per
|
|
42
|
+
`react`/`unreact`).
|
|
43
|
+
- Development and test toolchain: pnpm 10 with a seven-day release-age gate,
|
|
44
|
+
`convex` 1.51, `convex-test` 0.0.73, Vitest 5.1.1, ESLint 10, and
|
|
45
|
+
`@vllnt/typescript` 3 (stricter type-check flags for this repo's own build;
|
|
46
|
+
emitted JavaScript and `.d.ts` files are identical to a build with the 2.0.0
|
|
47
|
+
flags). The `convex` peer range stays `^1.45.0`.
|
|
48
|
+
- Pin GitHub Actions to commit SHAs, scope workflow permissions, and publish
|
|
49
|
+
`@latest` only from a `vX.Y.Z` tag on `main` through npm trusted publishing
|
|
50
|
+
with provenance. CI now also type-checks the component and every test file and
|
|
51
|
+
checks formatting.
|
|
52
|
+
|
|
53
|
+
### Documentation
|
|
54
|
+
|
|
55
|
+
- The npm package now ships `docs/API.md`, `CHANGELOG.md`, and `llms.txt` next
|
|
56
|
+
to `README.md`, so the docs under `node_modules/@vllnt/convex-reactions/`
|
|
57
|
+
match the installed version. `llms.txt` links shipped files relatively and
|
|
58
|
+
repository-only files by URL; `docs/API.md` lists every entry point and the
|
|
59
|
+
component's tables. `pnpm lint` fails when a required doc is missing from the
|
|
60
|
+
tarball, a contributor file, internal doc, or test ships, or an `llms.txt`
|
|
61
|
+
link points outside it.
|
|
62
|
+
- `reactors` docs no longer claim the 1000-row `maximumRowsRead` cap covers
|
|
63
|
+
reactive cursor ranges: with an `endCursor`, Convex returns the whole range
|
|
64
|
+
between the cursors and ignores `maximumRowsRead` (only its transaction read
|
|
65
|
+
limits apply), so the README states the limit as `numItems` 1 to 1000.
|
|
66
|
+
Behavior is unchanged.
|
|
67
|
+
- README gains a self-contained "Testing your app" snippet; the error table
|
|
68
|
+
lists the new codes.
|
|
69
|
+
- The npm `homepage` now points to
|
|
70
|
+
<https://oss.vllnt.com/packages/convex-reactions>.
|
|
71
|
+
|
|
72
|
+
## [0.1.0] - 2026-09-01
|
|
73
|
+
|
|
74
|
+
### Added
|
|
75
|
+
|
|
76
|
+
- First release of `@vllnt/convex-reactions` — reactions, votes, and likes on
|
|
77
|
+
any resource, modeled as the opaque edge `(authorRef, resourceRef, kind)`.
|
|
78
|
+
- `react(authorRef, resourceRef, kind)` toggles the edge in one transaction (add
|
|
79
|
+
if absent, remove if present), returning `{ reacted, action }`. One edge per
|
|
80
|
+
subject per kind per resource is enforced inside the mutation transaction.
|
|
81
|
+
- `unreact(authorRef, resourceRef, kind)` removes the edge; removing one that
|
|
82
|
+
does not exist is an idempotent no-op returning `false`.
|
|
83
|
+
- `counts(resourceRef)` tallies edges per kind (sorted by kind);
|
|
84
|
+
`reactors( resourceRef, kind, paginationOpts)` pages the subjects who reacted
|
|
85
|
+
oldest-first via the standard Convex pagination envelope.
|
|
86
|
+
- `hasReacted(authorRef, resourceRef, kind)` and
|
|
87
|
+
`myReactions(authorRef, resourceRef)` expose a subject's own reaction state.
|
|
88
|
+
- Configurable reaction vocabulary: `new Reactions(component, { allowedKinds })`
|
|
89
|
+
rejects an unknown `kind` at the client boundary before the component is
|
|
90
|
+
called.
|
|
91
|
+
- Server-sourced time: `createdAt` is stamped from `Date.now()` inside the
|
|
92
|
+
mutation — no caller-supplied clock.
|
|
93
|
+
- Opaque refs: `authorRef`, `resourceRef`, and `kind` are plain strings the
|
|
94
|
+
component never de-references; it never reads host or sibling tables.
|
|
95
|
+
- Mount-safe: correct under multiple `app.use(component, { name })` mounts —
|
|
96
|
+
each instance is sandboxed.
|
|
97
|
+
- `reactors` bounds pagination: `numItems` must be an integer from 1 through
|
|
98
|
+
1000 (otherwise it throws `ConvexError` `INVALID_PAGE_SIZE`), and
|
|
99
|
+
`maximumRowsRead` is validated and capped at 1000 for reactive cursor ranges.
|
|
100
|
+
- Requires `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-reactions)
|
|
4
5
|
[](https://github.com/vllnt/convex-reactions/actions/workflows/ci.yml)
|
|
@@ -11,35 +12,54 @@ Reactions, votes, and likes on any resource, as a Convex component.
|
|
|
11
12
|
```ts
|
|
12
13
|
const reactions = new Reactions(components.reactions);
|
|
13
14
|
await reactions.react(ctx, authorRef, resourceRef, "up"); // toggle the edge in one transaction
|
|
14
|
-
await reactions.counts(ctx, resourceRef);
|
|
15
|
+
await reactions.counts(ctx, resourceRef); // [{ kind, count }], reactive
|
|
15
16
|
await reactions.hasReacted(ctx, authorRef, resourceRef, "up");
|
|
16
17
|
```
|
|
17
18
|
|
|
18
|
-
A reaction is the opaque edge `(authorRef, resourceRef, kind)`. `react` toggles
|
|
19
|
-
remove if present); `counts` tallies a resource per kind;
|
|
20
|
-
|
|
21
|
-
correct under
|
|
19
|
+
A reaction is the opaque edge `(authorRef, resourceRef, kind)`. `react` toggles
|
|
20
|
+
it (add if absent, remove if present); `counts` tallies a resource per kind;
|
|
21
|
+
`reactors` pages who reacted. One edge per subject per kind per resource is
|
|
22
|
+
enforced in the mutation transaction, so toggles and counts stay correct under
|
|
23
|
+
concurrency.
|
|
22
24
|
|
|
23
25
|
## Features
|
|
24
26
|
|
|
25
|
-
- **Toggle** — `react(authorRef, resourceRef, kind)` adds the edge if absent and
|
|
26
|
-
|
|
27
|
-
- **
|
|
28
|
-
|
|
29
|
-
- **
|
|
30
|
-
|
|
31
|
-
- **
|
|
32
|
-
|
|
27
|
+
- **Toggle** — `react(authorRef, resourceRef, kind)` adds the edge if absent and
|
|
28
|
+
removes it if present in one transaction, returning `{ reacted, action }`.
|
|
29
|
+
- **Idempotent remove** — `unreact(authorRef, resourceRef, kind)` deletes the
|
|
30
|
+
edge; removing an absent one is a safe no-op (`false`).
|
|
31
|
+
- **Count by kind** — `counts(resourceRef)` returns `[{ kind, count }, ...]`
|
|
32
|
+
sorted by kind; no reactions returns `[]`.
|
|
33
|
+
- **List reactors** — `reactors(resourceRef, kind, paginationOpts)` pages who
|
|
34
|
+
reacted with one kind, oldest first. `numItems` must be an integer from 1
|
|
35
|
+
through 1000 and `maximumRowsRead` is capped at 1000. A reactive re-run with
|
|
36
|
+
an `endCursor` returns the whole range between its cursors: Convex ignores
|
|
37
|
+
`maximumRowsRead` there, and only its transaction read limits apply.
|
|
38
|
+
- **Per-subject state** — `hasReacted` and `myReactions` give the host the
|
|
39
|
+
subject's own reaction state for rendering controls.
|
|
40
|
+
- **Configurable vocabulary** — `allowedKinds` pins the reaction set
|
|
41
|
+
(`["up", "down"]`, a fixed emoji list); an unknown kind is rejected at the
|
|
42
|
+
boundary. Omit for freeform.
|
|
43
|
+
- **Server-sourced time** — `createdAt` is stamped from the server clock; a
|
|
44
|
+
caller can't supply a timestamp.
|
|
45
|
+
- **Mount-safe** — correct under multiple named `app.use` mounts; each instance
|
|
46
|
+
is an isolated sandbox.
|
|
33
47
|
|
|
34
48
|
## Installation
|
|
35
49
|
|
|
36
50
|
```bash
|
|
37
|
-
pnpm add @vllnt/convex-reactions
|
|
51
|
+
pnpm add @vllnt/convex-reactions convex@^1.45.0
|
|
38
52
|
```
|
|
39
53
|
|
|
40
|
-
Peer dependency: `convex@^1.45.0`.
|
|
54
|
+
Peer dependency: `convex@^1.45.0`. The command installs the latest stable
|
|
55
|
+
release; use `@vllnt/convex-reactions@canary` for the newest pre-release build
|
|
56
|
+
from `main`, and pin a resolved canary version for reproducible installs.
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
41
59
|
|
|
42
|
-
|
|
60
|
+
After mounting, run `pnpm exec convex dev` to generate `components.reactions`.
|
|
61
|
+
The example exports internal functions for trusted server callers. Public
|
|
62
|
+
wrappers must resolve identity and authorize resource access.
|
|
43
63
|
|
|
44
64
|
```ts
|
|
45
65
|
// convex/convex.config.ts
|
|
@@ -54,8 +74,7 @@ export default app;
|
|
|
54
74
|
```ts
|
|
55
75
|
// convex/reactions.ts — host owns auth; pass opaque refs in.
|
|
56
76
|
import { components } from "./_generated/api";
|
|
57
|
-
import {
|
|
58
|
-
import { paginationOptsValidator } from "convex/server";
|
|
77
|
+
import { internalMutation, internalQuery } from "./_generated/server";
|
|
59
78
|
import { v } from "convex/values";
|
|
60
79
|
import { Reactions } from "@vllnt/convex-reactions";
|
|
61
80
|
|
|
@@ -63,15 +82,13 @@ const reactions = new Reactions(components.reactions, {
|
|
|
63
82
|
allowedKinds: ["up", "down"], // pin the vocabulary (optional)
|
|
64
83
|
});
|
|
65
84
|
|
|
66
|
-
export const vote =
|
|
67
|
-
args: {
|
|
68
|
-
handler:
|
|
69
|
-
|
|
70
|
-
return reactions.react(ctx, userId, postId, kind);
|
|
71
|
-
},
|
|
85
|
+
export const vote = internalMutation({
|
|
86
|
+
args: { authorRef: v.string(), resourceRef: v.string(), kind: v.string() },
|
|
87
|
+
handler: (ctx, { authorRef, resourceRef, kind }) =>
|
|
88
|
+
reactions.react(ctx, authorRef, resourceRef, kind),
|
|
72
89
|
});
|
|
73
90
|
|
|
74
|
-
export const tally =
|
|
91
|
+
export const tally = internalQuery({
|
|
75
92
|
args: { postId: v.string() },
|
|
76
93
|
handler: (ctx, { postId }) => reactions.counts(ctx, postId),
|
|
77
94
|
});
|
|
@@ -79,28 +96,52 @@ export const tally = query({
|
|
|
79
96
|
|
|
80
97
|
## API Reference
|
|
81
98
|
|
|
82
|
-
| Method
|
|
83
|
-
|
|
84
|
-
| `react(ctx, authorRef, resourceRef, kind)`
|
|
85
|
-
| `unreact(ctx, authorRef, resourceRef, kind)`
|
|
86
|
-
| `counts(ctx, resourceRef)`
|
|
87
|
-
| `hasReacted(ctx, authorRef, resourceRef, kind)`
|
|
88
|
-
| `myReactions(ctx, authorRef, resourceRef)`
|
|
89
|
-
| `reactors(ctx, resourceRef, kind, paginationOpts)` | query
|
|
90
|
-
|
|
91
|
-
Invalid numeric pagination options throw `
|
|
99
|
+
| Method | Kind | Result |
|
|
100
|
+
| -------------------------------------------------- | -------- | -------------------------------------------------------- |
|
|
101
|
+
| `react(ctx, authorRef, resourceRef, kind)` | mutation | `{ reacted, action }` (`action`: `"added" \| "removed"`) |
|
|
102
|
+
| `unreact(ctx, authorRef, resourceRef, kind)` | mutation | `boolean` (true if an edge was removed) |
|
|
103
|
+
| `counts(ctx, resourceRef)` | query | `{ kind, count }[]` (sorted by kind) |
|
|
104
|
+
| `hasReacted(ctx, authorRef, resourceRef, kind)` | query | `boolean` |
|
|
105
|
+
| `myReactions(ctx, authorRef, resourceRef)` | query | `string[]` (kinds the subject placed) |
|
|
106
|
+
| `reactors(ctx, resourceRef, kind, paginationOpts)` | query | `PaginationResult<ReactionView>`; `numItems` 1 to 1000 |
|
|
107
|
+
|
|
108
|
+
Invalid numeric pagination options throw coded `ConvexError`
|
|
109
|
+
`INVALID_PAGE_SIZE`; empty `authorRef`/`resourceRef` in `react`/`unreact` throw
|
|
110
|
+
`INVALID_REF` and an empty `kind` throws `INVALID_KIND`. Disallowed kinds in
|
|
111
|
+
`react`/`unreact` throw a plain client-side `Error`, not a component error code;
|
|
112
|
+
query methods do not apply the allowlist.
|
|
92
113
|
|
|
93
114
|
Full reference: [docs/API.md](docs/API.md).
|
|
94
115
|
|
|
95
|
-
##
|
|
116
|
+
## Options and limitations
|
|
96
117
|
|
|
97
|
-
|
|
118
|
+
- `allowedKinds?: readonly string[]` is the sole constructor option. Omit it for
|
|
119
|
+
freeform kinds; an empty list rejects every write kind.
|
|
120
|
+
- `counts` reads one stored tally per kind, kept in step by `react` and
|
|
121
|
+
`unreact`, for every resource whose first reaction came after tallies existed.
|
|
122
|
+
A resource that already had reactions before then keeps being counted from its
|
|
123
|
+
edges (subject to Convex read limits) until all its edges are removed. Every
|
|
124
|
+
write on a resource updates its tally row, so very high write rates on one
|
|
125
|
+
`(resource, kind)` contend on that row. `myReactions` collects the subject's
|
|
126
|
+
edges on the resource.
|
|
127
|
+
- `react` is a toggle, not an idempotent retry operation: calling twice removes
|
|
128
|
+
the edge. Use `unreact` to ensure absence.
|
|
129
|
+
- Mount another isolated instance with `app.use(reactions, { name: "votes" })`
|
|
130
|
+
and `new Reactions(components.votes)`.
|
|
131
|
+
|
|
132
|
+
## Integrations
|
|
133
|
+
|
|
134
|
+
Backend-only — no `./react` entry. A reaction tally or reactor list is an
|
|
135
|
+
ordinary reactive `useQuery` over the host's own re-exported `counts` /
|
|
136
|
+
`reactors` refs.
|
|
98
137
|
|
|
99
138
|
## Security
|
|
100
139
|
|
|
101
140
|
- Auth-agnostic — the host resolves identity and decides who may react.
|
|
102
|
-
- Tables sandboxed — reached only through the exported functions; never touches
|
|
103
|
-
|
|
141
|
+
- Tables sandboxed — reached only through the exported functions; never touches
|
|
142
|
+
host or sibling tables.
|
|
143
|
+
- Uniqueness is transactional + time is server-sourced; refs and `kind` stay
|
|
144
|
+
opaque to the component.
|
|
104
145
|
|
|
105
146
|
See [docs/API.md](docs/API.md).
|
|
106
147
|
|
|
@@ -111,20 +152,68 @@ pnpm test # single run
|
|
|
111
152
|
pnpm test:coverage # enforced 100% on covered files
|
|
112
153
|
```
|
|
113
154
|
|
|
114
|
-
Tests run against the real component runtime via `convex-test`
|
|
155
|
+
Tests run against the real component runtime via `convex-test`
|
|
156
|
+
(`@edge-runtime/vm`), not mocks.
|
|
157
|
+
|
|
158
|
+
### Testing your app
|
|
159
|
+
|
|
160
|
+
`@vllnt/convex-reactions/test` exports `register(t, name = "reactions")` to
|
|
161
|
+
mount the component in a `convex-test` instance. It needs `convex-test` and
|
|
162
|
+
`vitest` (with Vite's `import.meta.glob`) in the consuming app:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
/// <reference types="vite/client" />
|
|
166
|
+
import { convexTest } from "convex-test";
|
|
167
|
+
import { register } from "@vllnt/convex-reactions/test";
|
|
168
|
+
import schema from "./schema";
|
|
169
|
+
|
|
170
|
+
const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
171
|
+
register(t);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Documentation
|
|
175
|
+
|
|
176
|
+
[API reference](docs/API.md) · [LLM index](llms.txt) · [Changelog](CHANGELOG.md)
|
|
177
|
+
·
|
|
178
|
+
[Security policy](https://github.com/vllnt/convex-reactions/blob/main/SECURITY.md)
|
|
179
|
+
|
|
180
|
+
`llms.txt` is the maintained discovery index. `pnpm generate:llms` checks its
|
|
181
|
+
heading and local links without generating a source bundle.
|
|
182
|
+
|
|
183
|
+
### For coding agents
|
|
184
|
+
|
|
185
|
+
The docs are bundled at `node_modules/@vllnt/convex-reactions/docs/` and match
|
|
186
|
+
the installed version, as do `README.md`, `CHANGELOG.md`, `llms.txt`, and the
|
|
187
|
+
TypeScript source in `src/`. Read them before writing code.
|
|
188
|
+
|
|
189
|
+
## Related packages
|
|
190
|
+
|
|
191
|
+
- [`@vllnt/convex-comments`](https://oss.vllnt.com/packages/convex-comments) —
|
|
192
|
+
threaded comments on a resource. Use it for written replies; use reactions for
|
|
193
|
+
one-tap votes, likes, and emoji.
|
|
194
|
+
- [`@vllnt/convex-notifications`](https://oss.vllnt.com/packages/convex-notifications)
|
|
195
|
+
— per-subject inbox. Use it to tell an author someone reacted; reactions only
|
|
196
|
+
stores and counts the edge.
|
|
197
|
+
- [`@vllnt/convex-events`](https://oss.vllnt.com/packages/convex-events) —
|
|
198
|
+
append-only activity feed. Use it to keep a history of who did what; reactions
|
|
199
|
+
keeps only the current toggle state.
|
|
115
200
|
|
|
116
201
|
## Contributing
|
|
117
202
|
|
|
118
|
-
See
|
|
203
|
+
See
|
|
204
|
+
[CONTRIBUTING.md](https://github.com/vllnt/convex-reactions/blob/main/CONTRIBUTING.md).
|
|
119
205
|
|
|
120
206
|
## Author
|
|
121
207
|
|
|
122
|
-
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
123
|
-
|
|
124
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
208
|
+
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
209
|
+
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
125
210
|
|
|
126
211
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
127
212
|
|
|
128
213
|
## License
|
|
129
214
|
|
|
130
215
|
MIT — see [LICENSE](LICENSE).
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
Part of vllnt oss: https://oss.vllnt.com
|
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type * as mutations from "../mutations.js";
|
|
10
10
|
import type * as queries from "../queries.js";
|
|
11
|
+
import type * as tally from "../tally.js";
|
|
11
12
|
import type * as validators from "../validators.js";
|
|
12
13
|
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
13
14
|
declare const fullApi: ApiFromModules<{
|
|
14
15
|
mutations: typeof mutations;
|
|
15
16
|
queries: typeof queries;
|
|
17
|
+
tally: typeof tally;
|
|
16
18
|
validators: typeof validators;
|
|
17
19
|
}>;
|
|
18
20
|
/**
|
|
@@ -1 +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"}
|
|
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,KAAK,MAAM,aAAa,CAAC;AAC1C,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,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAYH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAKR,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"}
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* `createdAt` is stamped from the server clock (`Date.now()` inside the handler
|
|
10
10
|
* — never caller-supplied). `kind` vocabulary and any allowlist are the host's
|
|
11
11
|
* concern, enforced at the client boundary before this call.
|
|
12
|
+
*
|
|
13
|
+
* @throws `ConvexError({ code: "INVALID_REF" })` when `authorRef` or `resourceRef`
|
|
14
|
+
* is empty.
|
|
15
|
+
* @throws `ConvexError({ code: "INVALID_KIND" })` when `kind` is empty.
|
|
12
16
|
*/
|
|
13
17
|
export declare const react: import("convex/server").RegisteredMutation<"public", {
|
|
14
18
|
authorRef: string;
|
|
@@ -25,7 +29,8 @@ export declare const react: import("convex/server").RegisteredMutation<"public",
|
|
|
25
29
|
* Remove a subject's `(authorRef, resourceRef, kind)` reaction edge. Idempotent:
|
|
26
30
|
* removing an edge that does not exist is a no-op that returns `false`, so a
|
|
27
31
|
* duplicate or replayed `unreact` is safe. Returns `true` only when an edge was
|
|
28
|
-
* actually deleted.
|
|
32
|
+
* actually deleted. Throws the same `INVALID_REF` / `INVALID_KIND` errors as
|
|
33
|
+
* {@link react} for empty arguments.
|
|
29
34
|
*/
|
|
30
35
|
export declare const unreact: import("convex/server").RegisteredMutation<"public", {
|
|
31
36
|
authorRef: string;
|
|
@@ -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":"AA4BA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,KAAK;;;;;;YAsBqB,SAAS;;;YAUZ,OAAO;GAEzC,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,OAAO;;;;oBAyBlB,CAAC"}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
|
-
import { v } from "convex/values";
|
|
2
|
-
import { mutation } from "./_generated/server";
|
|
3
|
-
import { reactResult } from "./validators";
|
|
1
|
+
import { ConvexError, v } from "convex/values";
|
|
2
|
+
import { mutation } from "./_generated/server.js";
|
|
3
|
+
import { reactResult } from "./validators.js";
|
|
4
|
+
import { adjustCount } from "./tally.js";
|
|
5
|
+
/**
|
|
6
|
+
* Reject empty refs and kind. An empty ref or kind is never a valid edge key and
|
|
7
|
+
* would silently create rows no real subject, resource, or kind can address.
|
|
8
|
+
*/
|
|
9
|
+
function assertEdgeKey(args) {
|
|
10
|
+
if (args.authorRef === "" || args.resourceRef === "") {
|
|
11
|
+
throw new ConvexError({
|
|
12
|
+
code: "INVALID_REF",
|
|
13
|
+
message: "authorRef and resourceRef must be non-empty",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (args.kind === "") {
|
|
17
|
+
throw new ConvexError({
|
|
18
|
+
code: "INVALID_KIND",
|
|
19
|
+
message: "kind must be non-empty",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
4
23
|
/**
|
|
5
24
|
* Toggle a reaction edge in one transaction. If the subject has no
|
|
6
25
|
* `(authorRef, resourceRef, kind)` edge it is inserted (`action: "added"`,
|
|
@@ -12,6 +31,10 @@ import { reactResult } from "./validators";
|
|
|
12
31
|
* `createdAt` is stamped from the server clock (`Date.now()` inside the handler
|
|
13
32
|
* — never caller-supplied). `kind` vocabulary and any allowlist are the host's
|
|
14
33
|
* concern, enforced at the client boundary before this call.
|
|
34
|
+
*
|
|
35
|
+
* @throws `ConvexError({ code: "INVALID_REF" })` when `authorRef` or `resourceRef`
|
|
36
|
+
* is empty.
|
|
37
|
+
* @throws `ConvexError({ code: "INVALID_KIND" })` when `kind` is empty.
|
|
15
38
|
*/
|
|
16
39
|
export const react = mutation({
|
|
17
40
|
args: {
|
|
@@ -21,6 +44,7 @@ export const react = mutation({
|
|
|
21
44
|
},
|
|
22
45
|
returns: reactResult,
|
|
23
46
|
handler: async (ctx, args) => {
|
|
47
|
+
assertEdgeKey(args);
|
|
24
48
|
const existing = await ctx.db
|
|
25
49
|
.query("reactions")
|
|
26
50
|
.withIndex("by_author_resource_kind", (q) => q
|
|
@@ -29,9 +53,11 @@ export const react = mutation({
|
|
|
29
53
|
.eq("kind", args.kind))
|
|
30
54
|
.unique();
|
|
31
55
|
if (existing !== null) {
|
|
56
|
+
await adjustCount(ctx, args.resourceRef, args.kind, -1);
|
|
32
57
|
await ctx.db.delete("reactions", existing._id);
|
|
33
58
|
return { reacted: false, action: "removed" };
|
|
34
59
|
}
|
|
60
|
+
await adjustCount(ctx, args.resourceRef, args.kind, 1);
|
|
35
61
|
await ctx.db.insert("reactions", {
|
|
36
62
|
authorRef: args.authorRef,
|
|
37
63
|
resourceRef: args.resourceRef,
|
|
@@ -45,7 +71,8 @@ export const react = mutation({
|
|
|
45
71
|
* Remove a subject's `(authorRef, resourceRef, kind)` reaction edge. Idempotent:
|
|
46
72
|
* removing an edge that does not exist is a no-op that returns `false`, so a
|
|
47
73
|
* duplicate or replayed `unreact` is safe. Returns `true` only when an edge was
|
|
48
|
-
* actually deleted.
|
|
74
|
+
* actually deleted. Throws the same `INVALID_REF` / `INVALID_KIND` errors as
|
|
75
|
+
* {@link react} for empty arguments.
|
|
49
76
|
*/
|
|
50
77
|
export const unreact = mutation({
|
|
51
78
|
args: {
|
|
@@ -55,6 +82,7 @@ export const unreact = mutation({
|
|
|
55
82
|
},
|
|
56
83
|
returns: v.boolean(),
|
|
57
84
|
handler: async (ctx, args) => {
|
|
85
|
+
assertEdgeKey(args);
|
|
58
86
|
const existing = await ctx.db
|
|
59
87
|
.query("reactions")
|
|
60
88
|
.withIndex("by_author_resource_kind", (q) => q
|
|
@@ -65,6 +93,7 @@ export const unreact = mutation({
|
|
|
65
93
|
if (existing === null) {
|
|
66
94
|
return false;
|
|
67
95
|
}
|
|
96
|
+
await adjustCount(ctx, args.resourceRef, args.kind, -1);
|
|
68
97
|
await ctx.db.delete("reactions", existing._id);
|
|
69
98
|
return true;
|
|
70
99
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;GAGG;AACH,SAAS,aAAa,CAAC,IAItB;IACC,IAAI,IAAI,CAAC,SAAS,KAAK,EAAE,IAAI,IAAI,CAAC,WAAW,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,WAAW,CAAC;YACpB,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,6CAA6C;SACvD,CAAC,CAAC;IACL,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,WAAW,CAAC;YACpB,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE,wBAAwB;SAClC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE;QACJ,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,WAAW,EAAE,CAAC,CAA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,EAAE,OAAgB,EAAE,CAAC;IACrD,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC9B,IAAI,EAAE;QACJ,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;QACvB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;KACjB;IACD,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,aAAa,CAAC,IAAI,CAAC,CAAC;QACpB,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE;aAC1B,KAAK,CAAC,WAAW,CAAC;aAClB,SAAS,CAAC,yBAAyB,EAAE,CAAC,CAAC,EAAE,EAAE,CAC1C,CAAC;aACE,EAAE,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC;aAC/B,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC;aACnC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CACzB;aACA,MAAM,EAAE,CAAC;QACZ,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACxD,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tally reaction edges per `kind` on one resource. Reads every edge for
|
|
3
|
-
* `resourceRef` via the `by_resource_kind` index (which is prefixed by
|
|
4
|
-
* `resourceRef`, so a `resourceRef`-only range spans all kinds) and groups them
|
|
5
|
-
* into `{ kind, count }` rows, sorted by `kind` for a stable order. A resource
|
|
6
|
-
* with no reactions returns an empty array.
|
|
7
|
-
*/
|
|
8
1
|
export declare const counts: import("convex/server").RegisteredQuery<"public", {
|
|
9
2
|
resourceRef: string;
|
|
10
3
|
}, Promise<{
|
|
@@ -23,8 +16,8 @@ export declare const hasReacted: import("convex/server").RegisteredQuery<"public
|
|
|
23
16
|
}, Promise<boolean>>;
|
|
24
17
|
/**
|
|
25
18
|
* Every reaction kind a subject placed on one resource (their own reaction
|
|
26
|
-
* state across kinds), via the `
|
|
27
|
-
* `kind` strings; empty when the subject has not reacted to the resource.
|
|
19
|
+
* state across kinds), via the `by_author_resource_kind` prefix. Returns the
|
|
20
|
+
* list of `kind` strings; empty when the subject has not reacted to the resource.
|
|
28
21
|
*/
|
|
29
22
|
export declare const myReactions: import("convex/server").RegisteredQuery<"public", {
|
|
30
23
|
authorRef: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAqDA,eAAO,MAAM,MAAM;;;;;KAyBjB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;;oBAmBrB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;qBAYtB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;GA8BnB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ConvexError, v } from "convex/values";
|
|
2
2
|
import { paginationOptsValidator } from "convex/server";
|
|
3
|
-
import { query } from "./_generated/server";
|
|
4
|
-
import {
|
|
3
|
+
import { query } from "./_generated/server.js";
|
|
4
|
+
import { tallyEdges } from "./tally.js";
|
|
5
|
+
import { kindCount, reactionView } from "./validators.js";
|
|
5
6
|
const MAX_PAGE_SIZE = 1000;
|
|
6
7
|
function boundedPaginationOptions(paginationOpts) {
|
|
7
8
|
const { numItems, maximumRowsRead } = paginationOpts;
|
|
@@ -37,29 +38,24 @@ function view(row) {
|
|
|
37
38
|
createdAt: row.createdAt,
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Tally reaction edges per `kind` on one resource. Reads every edge for
|
|
42
|
-
* `resourceRef` via the `by_resource_kind` index (which is prefixed by
|
|
43
|
-
* `resourceRef`, so a `resourceRef`-only range spans all kinds) and groups them
|
|
44
|
-
* into `{ kind, count }` rows, sorted by `kind` for a stable order. A resource
|
|
45
|
-
* with no reactions returns an empty array.
|
|
46
|
-
*/
|
|
47
41
|
export const counts = query({
|
|
48
42
|
args: { resourceRef: v.string() },
|
|
49
43
|
returns: v.array(kindCount),
|
|
50
44
|
handler: async (ctx, args) => {
|
|
51
|
-
const
|
|
52
|
-
.query("
|
|
45
|
+
const tallies = await ctx.db
|
|
46
|
+
.query("reactionCounts")
|
|
53
47
|
.withIndex("by_resource_kind", (q) => q.eq("resourceRef", args.resourceRef))
|
|
54
48
|
.collect();
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const rows = tallies.length > 0
|
|
50
|
+
? tallies
|
|
51
|
+
: [...(await tallyEdges(ctx, args.resourceRef))].map(([kind, count]) => ({
|
|
52
|
+
kind,
|
|
53
|
+
count,
|
|
54
|
+
}));
|
|
59
55
|
// Sort by kind for a stable, deterministic order. `localeCompare` is a
|
|
60
56
|
// single expression (no comparator branch), so coverage stays exact.
|
|
61
|
-
return
|
|
62
|
-
.map((
|
|
57
|
+
return rows
|
|
58
|
+
.map(({ kind, count }) => ({ kind, count }))
|
|
63
59
|
.sort((a, b) => a.kind.localeCompare(b.kind));
|
|
64
60
|
},
|
|
65
61
|
});
|
|
@@ -88,8 +84,8 @@ export const hasReacted = query({
|
|
|
88
84
|
});
|
|
89
85
|
/**
|
|
90
86
|
* Every reaction kind a subject placed on one resource (their own reaction
|
|
91
|
-
* state across kinds), via the `
|
|
92
|
-
* `kind` strings; empty when the subject has not reacted to the resource.
|
|
87
|
+
* state across kinds), via the `by_author_resource_kind` prefix. Returns the
|
|
88
|
+
* list of `kind` strings; empty when the subject has not reacted to the resource.
|
|
93
89
|
*/
|
|
94
90
|
export const myReactions = query({
|
|
95
91
|
args: { authorRef: v.string(), resourceRef: v.string() },
|
|
@@ -97,7 +93,7 @@ export const myReactions = query({
|
|
|
97
93
|
handler: async (ctx, args) => {
|
|
98
94
|
const rows = await ctx.db
|
|
99
95
|
.query("reactions")
|
|
100
|
-
.withIndex("
|
|
96
|
+
.withIndex("by_author_resource_kind", (q) => q.eq("authorRef", args.authorRef).eq("resourceRef", args.resourceRef))
|
|
101
97
|
.collect();
|
|
102
98
|
return rows.map((row) => row.kind);
|
|
103
99
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG1D,MAAM,aAAa,GAAG,I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