mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 16:38:20 +01:00
93 lines
2.6 KiB
TypeScript
93 lines
2.6 KiB
TypeScript
/**
|
|
* Polls extension
|
|
* @module federation/schemas/extensions/polls
|
|
* @see module:federation/schemas/base
|
|
* @see https://lysand.org/extensions/polls
|
|
*/
|
|
import { z } from "zod";
|
|
import { Extension } from "../base";
|
|
import { ContentFormat } from "../content_format";
|
|
|
|
/**
|
|
* @description Poll extension entity
|
|
* @see https://lysand.org/extensions/polls
|
|
* @example
|
|
* {
|
|
* "type": "Extension",
|
|
* "id": "d6eb84ea-cd13-43f9-9c54-01244da8e5e3",
|
|
* "extension_type": "org.lysand:polls/Poll",
|
|
* "uri": "https://example.com/polls/d6eb84ea-cd13-43f9-9c54-01244da8e5e3",
|
|
* "options": [
|
|
* {
|
|
* "text/plain": {
|
|
* "content": "Red"
|
|
* }
|
|
* },
|
|
* {
|
|
* "text/plain": {
|
|
* "content": "Blue"
|
|
* }
|
|
* },
|
|
* {
|
|
* "text/plain": {
|
|
* "content": "Green"
|
|
* }
|
|
* }
|
|
* ],
|
|
* "votes": [
|
|
* 9,
|
|
* 5,
|
|
* 0
|
|
* ],
|
|
* "multiple_choice": false,
|
|
* "expires_at": "2021-01-04T00:00:00.000Z"
|
|
* }
|
|
*/
|
|
export const Poll = Extension.extend({
|
|
extension_type: z.literal("org.lysand:polls/Poll"),
|
|
options: z.array(ContentFormat),
|
|
votes: z.array(z.number().int().nonnegative()),
|
|
multiple_choice: z.boolean().optional(),
|
|
expires_at: z.string(),
|
|
});
|
|
|
|
/**
|
|
* @description Vote extension entity
|
|
* @see https://lysand.org/extensions/polls
|
|
* @example
|
|
* {
|
|
* "type": "Extension",
|
|
* "id": "31c4de70-e266-4f61-b0f7-3767d3ccf565",
|
|
* "created_at": "2021-01-01T00:00:00.000Z",
|
|
* "uri": "https://example.com/votes/31c4de70-e266-4f61-b0f7-3767d3ccf565",
|
|
* "extension_type": "org.lysand:polls/Vote",
|
|
* "poll": "https://example.com/polls/31c4de70-e266-4f61-b0f7-3767d3ccf565",
|
|
* "option": 1
|
|
* }
|
|
*/
|
|
export const Vote = Extension.extend({
|
|
extension_type: z.literal("org.lysand:polls/Vote"),
|
|
poll: z.string().url(),
|
|
option: z.number(),
|
|
});
|
|
|
|
/**
|
|
* @description Vote result extension entity
|
|
* @see https://lysand.org/extensions/polls
|
|
* @example
|
|
* {
|
|
* "type": "Extension",
|
|
* "id": "c6d5755b-f42c-418f-ab53-2ee3705d6628",
|
|
* "created_at": "2021-01-01T00:00:00.000Z",
|
|
* "uri": "https://example.com/polls/c6d5755b-f42c-418f-ab53-2ee3705d6628/result",
|
|
* "extension_type": "org.lysand:polls/VoteResult",
|
|
* "poll": "https://example.com/polls/c6d5755b-f42c-418f-ab53-2ee3705d6628",
|
|
* "votes": [9, 5, 0]
|
|
* }
|
|
*/
|
|
export const VoteResult = Extension.extend({
|
|
extension_type: z.literal("org.lysand:polls/VoteResult"),
|
|
poll: z.string().url(),
|
|
votes: z.array(z.number().int().nonnegative()),
|
|
});
|