diff --git a/CHANGES.md b/CHANGES.md index 36d63683..0b01ac3f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/src/codegen/__snapshots__/class.test.ts.snap b/src/codegen/__snapshots__/class.test.ts.snap index a12a4371..e99f6928 100644 --- a/src/codegen/__snapshots__/class.test.ts.snap +++ b/src/codegen/__snapshots__/class.test.ts.snap @@ -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, @@ -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, @@ -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, @@ -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 { @@ -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. @@ -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, @@ -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\\" + \\".\\", + ); + } + } } /** @@ -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: { @@ -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; } @@ -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\`. * */ @@ -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. @@ -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) { @@ -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, @@ -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; } @@ -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; } @@ -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, diff --git a/src/sig/proof.test.ts b/src/sig/proof.test.ts index 68a8218e..b3993fa1 100644 --- a/src/sig/proof.test.ts +++ b/src/sig/proof.test.ts @@ -84,8 +84,8 @@ test("createProof()", async () => { assertEquals( proof.proofValue, decodeHex( - "ebea8d8f81181a6e3ef5c2455da00a2773bd94231e558b7ff0dd46566e6d0a94" + - "549264a9b3e435e136fb5f100f07bb0dbbb25566d5deea83dfd1be6a3104b202", + "0bc7df9f6a0a7998d31b9ba140eb0d40508edf47a20ed403770a4e6224af619c" + + "633411e38322f175c2a74e3f1d6f44cc99f1ed3485cdd819586ec43a33bf1206", ), ); assertEquals(proof.created, created); diff --git a/src/vocab/__snapshots__/vocab.test.ts.snap b/src/vocab/__snapshots__/vocab.test.ts.snap index 8e0c4a11..cfc97f1f 100644 --- a/src/vocab/__snapshots__/vocab.test.ts.snap +++ b/src/vocab/__snapshots__/vocab.test.ts.snap @@ -5177,7 +5177,8 @@ snapshot[`Deno.inspect(Question) [auto] 1`] = ` origin: Object {}, instrument: Object {}, exclusiveOptions: [ Object {} ], - inclusiveOptions: [ Object {} ] + inclusiveOptions: [ Object {} ], + voters: 123 }' `; @@ -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 }' `; @@ -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 }' `; diff --git a/src/vocab/announce.yaml b/src/vocab/announce.yaml index 30576d04..bf38d84b 100644 --- a/src/vocab/announce.yaml +++ b/src/vocab/announce.yaml @@ -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: [] diff --git a/src/vocab/create.yaml b/src/vocab/create.yaml index a44da904..249249e8 100644 --- a/src/vocab/create.yaml +++ b/src/vocab/create.yaml @@ -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" diff --git a/src/vocab/delete.yaml b/src/vocab/delete.yaml index bbe8c2fd..6fdebc90 100644 --- a/src/vocab/delete.yaml +++ b/src/vocab/delete.yaml @@ -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: [] diff --git a/src/vocab/question.yaml b/src/vocab/question.yaml index bd1142f2..0f749bd0 100644 --- a/src/vocab/question.yaml +++ b/src/vocab/question.yaml @@ -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" @@ -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" @@ -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" diff --git a/src/vocab/update.yaml b/src/vocab/update.yaml index 74575447..307ea4a8 100644 --- a/src/vocab/update.yaml +++ b/src/vocab/update.yaml @@ -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"