@uidu/client 3.22.0 → 3.23.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 +7 -0
- package/dist/declarations/src/comments.d.ts +47 -0
- package/dist/declarations/src/contracts.d.ts +2 -0
- package/dist/declarations/src/decisions.d.ts +58 -0
- package/dist/declarations/src/generated/index.d.ts +6745 -2112
- package/dist/declarations/src/index.d.ts +9 -3
- package/dist/declarations/src/models.d.ts +28 -1
- package/dist/declarations/src/mutations.d.ts +156 -1
- package/dist/declarations/src/votes.d.ts +114 -0
- package/dist/uidu-client.cjs.dev.js +284 -1
- package/dist/uidu-client.cjs.prod.js +284 -1
- package/dist/uidu-client.esm.js +270 -2
- package/package.json +1 -1
- package/src/comments.ts +44 -0
- package/src/decisions.test.ts +275 -0
- package/src/decisions.ts +135 -0
- package/src/generated/index.ts +1182 -32
- package/src/index.ts +25 -0
- package/src/models.ts +50 -0
- package/src/mutations.ts +72 -0
- package/src/queries/comments/Comments.graphql +65 -0
- package/src/queries/contacts/AddressMutations.graphql +41 -0
- package/src/queries/contacts/EmailAddressMutations.graphql +39 -0
- package/src/queries/contacts/PhoneNumberMutations.graphql +39 -0
- package/src/queries/decisions/DecisionFields.graphql +83 -0
- package/src/queries/decisions/DecisionMutations.graphql +59 -0
- package/src/queries/decisions/DecisionQueries.graphql +32 -0
- package/src/queries/models/ModelFields.graphql +2 -0
- package/src/queries/models/ModelQueries.graphql +33 -0
- package/src/queries/votes/Votes.graphql +60 -0
- package/src/votes.ts +38 -0
package/src/votes.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { UiduClient } from './client';
|
|
2
|
+
import {
|
|
3
|
+
CreateVoteDocument,
|
|
4
|
+
DeleteVoteDocument,
|
|
5
|
+
type VoteFieldsFragment,
|
|
6
|
+
} from './generated';
|
|
7
|
+
|
|
8
|
+
// Votes and reactions on a record — for a custom app, one of its ModelItems
|
|
9
|
+
// (Votes::Vote::Create, which covers taking one back too). The voter is always
|
|
10
|
+
// the contact of the token's user, and only one's own vote can be taken back.
|
|
11
|
+
|
|
12
|
+
export type Vote = VoteFieldsFragment;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Vote on a record as the token's user: an upvote by default, `voteFlag:
|
|
16
|
+
* false` for a downvote, or a reaction with `emoji`. Returns the payload: the
|
|
17
|
+
* vote at `vote.node`, the record's new `votable.votesCount`, and `errors`.
|
|
18
|
+
*/
|
|
19
|
+
export async function vote(
|
|
20
|
+
client: UiduClient,
|
|
21
|
+
variables: { votableId: string; voteFlag?: boolean; emoji?: string },
|
|
22
|
+
) {
|
|
23
|
+
const { votableId, voteFlag = true, emoji } = variables;
|
|
24
|
+
const result = await client.mutate(CreateVoteDocument, {
|
|
25
|
+
input: { votableId, attributes: { voteFlag, emoji } },
|
|
26
|
+
});
|
|
27
|
+
return result.createVote ?? null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Take back one's own vote (`id` of a vote whose `mine` is true). Someone
|
|
32
|
+
* else's comes back as an error, not thrown. Returns the payload with the
|
|
33
|
+
* record's new `votable.votesCount`.
|
|
34
|
+
*/
|
|
35
|
+
export async function unvote(client: UiduClient, variables: { id: string }) {
|
|
36
|
+
const result = await client.mutate(DeleteVoteDocument, { input: variables });
|
|
37
|
+
return result.deleteVote ?? null;
|
|
38
|
+
}
|