Skip to content

Commit

Permalink
Add voters prop to Question class
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Jul 26, 2024
1 parent 4c30151 commit fdc60db
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Version 0.13.0

To be released.

- Added `voters` property to `Question` class in Activity Vocabulary API.

- Added `Question.voters` property.
- `new Question()` constructor now accepts `voters` option.
- `Question.clone()` method now accepts `voters` option.

- Removed the singular actor key pair dispatcher APIs which were deprecated
in version 0.10.0.

Expand Down
102 changes: 93 additions & 9 deletions src/codegen/__snapshots__/class.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10730,7 +10730,7 @@ instruments?: (Object | URL)[];}
);
}
const docContext = options.context ??
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\"}];
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\"}];
const compacted = await jsonld.compact(
values,
docContext,
Expand Down Expand Up @@ -17041,7 +17041,7 @@ instruments?: (Object | URL)[];}
);
}
const docContext = options.context ??
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\"}];
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\"}];
const compacted = await jsonld.compact(
values,
docContext,
Expand Down Expand Up @@ -17272,7 +17272,7 @@ instruments?: (Object | URL)[];}
);
}
const docContext = options.context ??
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\"}];
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\"}];
const compacted = await jsonld.compact(
values,
docContext,
Expand Down Expand Up @@ -32656,7 +32656,7 @@ proofs?: (DataIntegrityProof | URL)[];describes?: Object | URL | null;}
* contain an \`object\` property.
*
* Either of the \`anyOf\` and \`oneOf\` properties *may* be used to express possible
* answers, but a Question object *must not* have both properties.
* answers, but a Question object *must not* have both properties.
*
*/
export class Question extends IntransitiveActivity {
Expand All @@ -32669,6 +32669,7 @@ export class Question extends IntransitiveActivity {
}
#_2N5scKaVEcdYHFmfKYYacAwUhUgQ: (Object | URL)[] = [];
#_2mV6isMTPRKbWdLCjcpiEysq5dAY: (Object | URL)[] = [];
#_3H4RdST7dxfmghccvE3rKD3KgcxG: (number)[] = [];

/**
* Constructs a new instance of Question with the given values.
Expand Down Expand Up @@ -32701,7 +32702,7 @@ objects?: (Object | URL)[];target?: Object | URL | null;
targets?: (Object | URL)[];result?: Object | URL | null;
results?: (Object | URL)[];origin?: Object | URL | null;
origins?: (Object | URL)[];instrument?: Object | URL | null;
instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOptions?: (Object | URL)[];}
instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOptions?: (Object | URL)[];voters?: number | null;}
,
{
documentLoader,
Expand Down Expand Up @@ -32739,6 +32740,18 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti
);
}
}

if (\\"voters\\" in values && values.voters != null) {
if (typeof values.voters === \\"number\\" && Number.isInteger(values.voters) && values.voters >= 0) {
// @ts-ignore: type is checked above.
this.#_3H4RdST7dxfmghccvE3rKD3KgcxG = [values.voters];
} else {
throw new TypeError(
\\"The voters must be of type \\" +
\\"number\\" + \\".\\",
);
}
}
}

/**
Expand Down Expand Up @@ -32773,7 +32786,7 @@ objects?: (Object | URL)[];target?: Object | URL | null;
targets?: (Object | URL)[];result?: Object | URL | null;
results?: (Object | URL)[];origin?: Object | URL | null;
origins?: (Object | URL)[];instrument?: Object | URL | null;
instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOptions?: (Object | URL)[];}
instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOptions?: (Object | URL)[];voters?: number | null;}

= {},
options: {
Expand Down Expand Up @@ -32809,6 +32822,18 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti
);
}
}
clone.#_3H4RdST7dxfmghccvE3rKD3KgcxG = this.#_3H4RdST7dxfmghccvE3rKD3KgcxG;
if (\\"voters\\" in values && values.voters != null) {
if (typeof values.voters === \\"number\\" && Number.isInteger(values.voters) && values.voters >= 0) {
// @ts-ignore: type is checked above.
clone.#_3H4RdST7dxfmghccvE3rKD3KgcxG = [values.voters];
} else {
throw new TypeError(
\\"The voters must be of type \\" +
\\"number\\" + \\".\\",
);
}
}

return clone;
}
Expand Down Expand Up @@ -32866,7 +32891,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti

/** Identifies an exclusive option for a Question. Use of \`exclusiveOptions\`
* implies that the Question can have only a single answer. To indicate that
* a Question can have multiple answers, use \`inclusiveOptions\`.
* a Question can have multiple answers, use \`inclusiveOptions\`.
*
*/

Expand Down Expand Up @@ -32973,6 +32998,15 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti
}
}

/** How many people have voted in the poll. Distinct from how many votes have
* been cast (in the case of multiple-choice polls).
*
*/
get voters(): (number | null) {
if (this.#_3H4RdST7dxfmghccvE3rKD3KgcxG.length < 1) return null;
return this.#_3H4RdST7dxfmghccvE3rKD3KgcxG[0];
}

/**
* Converts this object to a JSON-LD structure.
* @returns The JSON-LD representation of this object.
Expand Down Expand Up @@ -33024,6 +33058,22 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti
);
}

array = [];
for (const v of this.#_3H4RdST7dxfmghccvE3rKD3KgcxG) {
const element = (
{
\\"@type\\": \\"http://www.w3.org/2001/XMLSchema#nonNegativeInteger\\",
\\"@value\\": v,
}
);
array.push(element);;
}
if (array.length > 0) {
values[\\"http://joinmastodon.org/ns#votersCount\\"] = (
array
);
}

values[\\"@type\\"] = [\\"https://www.w3.org/ns/activitystreams#Question\\"];
if (this.id) values[\\"@id\\"] = this.id.href;
if (options.expand) {
Expand All @@ -33033,7 +33083,7 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti
);
}
const docContext = options.context ??
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\"}];
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\"}];
const compacted = await jsonld.compact(
values,
docContext,
Expand Down Expand Up @@ -33145,6 +33195,20 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti
v, options))
}
instance.#_2mV6isMTPRKbWdLCjcpiEysq5dAY = _2mV6isMTPRKbWdLCjcpiEysq5dAY;
const _3H4RdST7dxfmghccvE3rKD3KgcxG: (number)[] = [];

const _3H4RdST7dxfmghccvE3rKD3KgcxG__array = values[\\"http://joinmastodon.org/ns#votersCount\\"];
for (
const v of _3H4RdST7dxfmghccvE3rKD3KgcxG__array == null
? []
: _3H4RdST7dxfmghccvE3rKD3KgcxG__array.length === 1 && \\"@list\\" in _3H4RdST7dxfmghccvE3rKD3KgcxG__array[0]
? _3H4RdST7dxfmghccvE3rKD3KgcxG__array[0][\\"@list\\"]
: _3H4RdST7dxfmghccvE3rKD3KgcxG__array
) {
if (v == null) continue;
_3H4RdST7dxfmghccvE3rKD3KgcxG.push(v[\\"@value\\"])
}
instance.#_3H4RdST7dxfmghccvE3rKD3KgcxG = _3H4RdST7dxfmghccvE3rKD3KgcxG;

return instance;
}
Expand Down Expand Up @@ -33195,6 +33259,26 @@ instruments?: (Object | URL)[];exclusiveOptions?: (Object | URL)[];inclusiveOpti
proxy.inclusiveOptions = _2mV6isMTPRKbWdLCjcpiEysq5dAY;
}

const _3H4RdST7dxfmghccvE3rKD3KgcxG = this.#_3H4RdST7dxfmghccvE3rKD3KgcxG
// deno-lint-ignore no-explicit-any
.map((v: any) => v instanceof URL
? {
[Symbol.for(\\"Deno.customInspect\\")]: (
inspect: typeof Deno.inspect,
options: Deno.InspectOptions,
): string => \\"URL \\" + inspect(v.href, options),
[Symbol.for(\\"nodejs.util.inspect.custom\\")]: (
_depth: number,
options: unknown,
inspect: (value: unknown, options: unknown) => string,
): string => \\"URL \\" + inspect(v.href, options),
}
: v);

if (_3H4RdST7dxfmghccvE3rKD3KgcxG.length == 1) {
proxy.voters = _3H4RdST7dxfmghccvE3rKD3KgcxG[0];
}

return proxy;
}

Expand Down Expand Up @@ -38795,7 +38879,7 @@ instruments?: (Object | URL)[];}
);
}
const docContext = options.context ??
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\"}];
[\\"https://www.w3.org/ns/activitystreams\\",\\"https://w3id.org/security/data-integrity/v1\\",{\\"toot\\":\\"http://joinmastodon.org/ns#\\",\\"sensitive\\":\\"as:sensitive\\",\\"votersCount\\":\\"toot:votersCount\\",\\"Emoji\\":\\"toot:Emoji\\",\\"Hashtag\\":\\"as:Hashtag\\",\\"ChatMessage\\":\\"http://litepub.social/ns#ChatMessage\\"}];
const compacted = await jsonld.compact(
values,
docContext,
Expand Down
4 changes: 2 additions & 2 deletions src/sig/proof.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ test("createProof()", async () => {
assertEquals(
proof.proofValue,
decodeHex(
"ebea8d8f81181a6e3ef5c2455da00a2773bd94231e558b7ff0dd46566e6d0a94" +
"549264a9b3e435e136fb5f100f07bb0dbbb25566d5deea83dfd1be6a3104b202",
"0bc7df9f6a0a7998d31b9ba140eb0d40508edf47a20ed403770a4e6224af619c" +
"633411e38322f175c2a74e3f1d6f44cc99f1ed3485cdd819586ec43a33bf1206",
),
);
assertEquals(proof.created, created);
Expand Down
9 changes: 6 additions & 3 deletions src/vocab/__snapshots__/vocab.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5177,7 +5177,8 @@ snapshot[`Deno.inspect(Question) [auto] 1`] = `
origin: Object {},
instrument: Object {},
exclusiveOptions: [ Object {} ],
inclusiveOptions: [ Object {} ]
inclusiveOptions: [ Object {} ],
voters: 123
}'
`;

Expand Down Expand Up @@ -5219,7 +5220,8 @@ snapshot[`Deno.inspect(Question) [auto] 2`] = `
origin: URL "https://example.com/",
instrument: URL "https://example.com/",
exclusiveOptions: [ URL "https://example.com/" ],
inclusiveOptions: [ URL "https://example.com/" ]
inclusiveOptions: [ URL "https://example.com/" ],
voters: 123
}'
`;

Expand Down Expand Up @@ -5261,7 +5263,8 @@ snapshot[`Deno.inspect(Question) [auto] 3`] = `
origins: [ Object {}, Object {} ],
instruments: [ Object {}, Object {} ],
exclusiveOptions: [ Object {}, Object {} ],
inclusiveOptions: [ Object {}, Object {} ]
inclusiveOptions: [ Object {}, Object {} ],
voters: 123
}'
`;

Expand Down
1 change: 1 addition & 0 deletions src/vocab/announce.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defaultContext:
- "https://w3id.org/security/data-integrity/v1"
- toot: "http://joinmastodon.org/ns#"
sensitive: "as:sensitive"
votersCount: "toot:votersCount"
Emoji: "toot:Emoji"
Hashtag: "as:Hashtag"
properties: []
1 change: 1 addition & 0 deletions src/vocab/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defaultContext:
- "https://w3id.org/security/data-integrity/v1"
- toot: "http://joinmastodon.org/ns#"
sensitive: "as:sensitive"
votersCount: "toot:votersCount"
Emoji: "toot:Emoji"
Hashtag: "as:Hashtag"
ChatMessage: "http://litepub.social/ns#ChatMessage"
Expand Down
7 changes: 6 additions & 1 deletion src/vocab/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ description: |
defaultContext:
- "https://www.w3.org/ns/activitystreams"
- "https://w3id.org/security/data-integrity/v1"
- ChatMessage: "http://litepub.social/ns#ChatMessage"
- toot: "http://joinmastodon.org/ns#"
sensitive: "as:sensitive"
votersCount: "toot:votersCount"
Emoji: "toot:Emoji"
Hashtag: "as:Hashtag"
ChatMessage: "http://litepub.social/ns#ChatMessage"
properties: []
14 changes: 12 additions & 2 deletions src/vocab/question.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ description: |
contain an `object` property.
Either of the `anyOf` and `oneOf` properties *may* be used to express possible
answers, but a Question object *must not* have both properties.
answers, but a Question object *must not* have both properties.
defaultContext:
- "https://www.w3.org/ns/activitystreams"
- "https://w3id.org/security/data-integrity/v1"
- toot: "http://joinmastodon.org/ns#"
sensitive: "as:sensitive"
votersCount: "toot:votersCount"
Emoji: "toot:Emoji"
Hashtag: "as:Hashtag"

Expand All @@ -27,7 +28,7 @@ properties:
description: |
Identifies an exclusive option for a Question. Use of `exclusiveOptions`
implies that the Question can have only a single answer. To indicate that
a Question can have multiple answers, use `inclusiveOptions`.
a Question can have multiple answers, use `inclusiveOptions`.
range:
- "https://www.w3.org/ns/activitystreams#Object"

Expand All @@ -41,3 +42,12 @@ properties:
a Question can have only one answer, use `exclusiveOptions`.
range:
- "https://www.w3.org/ns/activitystreams#Object"

- singularName: voters
functional: true
uri: "http://joinmastodon.org/ns#votersCount"
description: |
How many people have voted in the poll. Distinct from how many votes have
been cast (in the case of multiple-choice polls).
range:
- "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
1 change: 1 addition & 0 deletions src/vocab/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defaultContext:
- "https://w3id.org/security/data-integrity/v1"
- toot: "http://joinmastodon.org/ns#"
sensitive: "as:sensitive"
votersCount: "toot:votersCount"
Emoji: "toot:Emoji"
Hashtag: "as:Hashtag"
ChatMessage: "http://litepub.social/ns#ChatMessage"
Expand Down

0 comments on commit fdc60db

Please sign in to comment.