Skip to content

Commit 6c39741

Browse files
committed
{Article,ChatMessage,Note,Question}.quoteUrl props
1 parent 1d5990d commit 6c39741

20 files changed

+6962
-5213
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"docloader",
8080
"eddsa",
8181
"fedi",
82+
"fedibird",
8283
"fedify",
8384
"fediverse",
8485
"followable",

CHANGES.md

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ To be released.
1515
- Added `ActorCallbackSetters.mapHandle()` method.
1616
- Added `ActorHandleMapper` type.
1717

18+
- Added `quoteUrl` property to `Article`, `ChatMessage`, `Note`, and
19+
`Question` classes in Activity Vocabulary API.
20+
21+
- Added `Article.quoteUrl` property.
22+
- `new Article()` constructor now accepts `quoteUrl` option.
23+
- `Article.clone()` method now accepts `quoteUrl` option.
24+
- Added `ChatMessage.quoteUrl` property.
25+
- `new ChatMessage()` constructor now accepts `quoteUrl` option.
26+
- `ChatMessage.clone()` method now accepts `quoteUrl` option.
27+
- Added `Note.quoteUrl` property.
28+
- `new Note()` constructor now accepts `quoteUrl` option.
29+
- `Note.clone()` method now accepts `quoteUrl` option.
30+
- Added `Question.quoteUrl` property.
31+
- `new Question()` constructor now accepts `quoteUrl` option.
32+
- `Question.clone()` method now accepts `quoteUrl` option.
33+
1834
- Removed `expand` option of `Object.toJsonLd()` method, which was deprecated
1935
in version 0.14.0. Use `format: "expand"` option instead.
2036

src/codegen/__snapshots__/class.test.ts.snap

+6,591-5,183
Large diffs are not rendered by default.

src/codegen/codec.ts

+42-10
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,33 @@ export async function* generateEncoder(
104104
);
105105
compactItems.push(item);
106106
}
107+
if (compactItems.length > 0) {
107108
`;
108109
if (property.functional || property.container !== "list") {
109110
yield `
110-
if (compactItems.length > 1) {
111-
result[${JSON.stringify(property.compactName)}] = compactItems;
112-
} else if (compactItems.length === 1) {
113-
result[${JSON.stringify(property.compactName)}] = compactItems[0];
114-
}
111+
result[${JSON.stringify(property.compactName)}]
112+
= compactItems.length > 1
113+
? compactItems
114+
: compactItems[0];
115115
`;
116+
if (property.functional && property.redundantProperties != null) {
117+
for (const prop of property.redundantProperties) {
118+
yield `
119+
result[${JSON.stringify(prop.compactName)}]
120+
= compactItems.length > 1
121+
? compactItems
122+
: compactItems[0];
123+
`;
124+
}
125+
}
116126
} else {
117127
yield `
118-
if (compactItems.length > 0) {
119-
result[${JSON.stringify(property.compactName)}] = compactItems;
120-
}
128+
result[${JSON.stringify(property.compactName)}] = compactItems;
121129
`;
122130
}
131+
yield `
132+
}
133+
`;
123134
}
124135
yield `
125136
result["type"] = ${JSON.stringify(type.compactName ?? type.uri)};
@@ -171,7 +182,7 @@ export async function* generateEncoder(
171182
yield `;
172183
}
173184
if (array.length > 0) {
174-
values[${JSON.stringify(property.uri)}] = (
185+
const propValue = (
175186
`;
176187
if (!property.functional && property.container === "list") {
177188
yield `{ "@list": array }`;
@@ -180,6 +191,16 @@ export async function* generateEncoder(
180191
}
181192
yield `
182193
);
194+
values[${JSON.stringify(property.uri)}] = propValue;
195+
`;
196+
if (property.functional && property.redundantProperties != null) {
197+
for (const prop of property.redundantProperties) {
198+
yield `
199+
values[${JSON.stringify(prop.uri)}] = propValue;
200+
`;
201+
}
202+
}
203+
yield `
183204
}
184205
`;
185206
}
@@ -317,7 +338,18 @@ export async function* generateDecoder(
317338
yield await generateField(property, types, "const ");
318339
const arrayVariable = `${variable}__array`;
319340
yield `
320-
const ${arrayVariable} = values[${JSON.stringify(property.uri)}];
341+
let ${arrayVariable} = values[${JSON.stringify(property.uri)}];
342+
`;
343+
if (property.functional && property.redundantProperties != null) {
344+
for (const prop of property.redundantProperties) {
345+
yield `
346+
if (${arrayVariable} == null || ${arrayVariable}.length < 1) {
347+
${arrayVariable} = values[${JSON.stringify(prop.uri)}];
348+
}
349+
`;
350+
}
351+
}
352+
yield `
321353
for (
322354
const v of ${arrayVariable} == null
323355
? []

src/codegen/field.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export async function getFieldName(
1010
"SHA-1",
1111
new TextEncoder().encode(propertyUri),
1212
);
13-
return `${prefix}_${encodeBase58(hashedUri)}`;
13+
const match = propertyUri.match(/#([A-Za-z0-9_]+)$/);
14+
const suffix = match == null ? "" : `_${match[1]}`;
15+
return `${prefix}_${encodeBase58(hashedUri)}${suffix}`;
1416
}
1517

1618
export async function generateField(

src/codegen/schema.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export interface PropertySchemaBase {
8080
* The property name used in the compacted JSON-LD document. It is used as
8181
* the key of the property.
8282
*/
83-
compactName: string;
83+
compactName?: string;
8484

8585
/**
8686
* The qualified URI of the superproperty of the property (if any).
@@ -174,6 +174,25 @@ export type PropertySchema =
174174
* and `singularAccessor` should not be specified.
175175
*/
176176
functional: true;
177+
178+
/**
179+
* If it's present, those redundant properties are also filled with
180+
* the same value altogether when the object is serialized into
181+
* JSON-LD. When it's deserialized from JSON-LD, it tries to
182+
* parse the values of the specified properties in order.
183+
*/
184+
redundantProperties?: {
185+
/**
186+
* The qualified URI of the property.
187+
*/
188+
uri: string;
189+
190+
/**
191+
* The property name used in the compacted JSON-LD document. It is used
192+
* as the key of the property.
193+
*/
194+
compactName?: string;
195+
}[];
177196
};
178197

179198
/**

src/codegen/schema.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ $defs:
4545
functional:
4646
description: *functional-description
4747
const: true
48+
redundantProperties::
49+
description: >-
50+
If it's present, those redundant properties are also filled with
51+
the same value altogether when the object is serialized into
52+
JSON-LD. When it's deserialized from JSON-LD, it tries to
53+
parse the values of the specified properties in order.
54+
type: array
55+
items:
56+
type: object
57+
properties:
58+
uri:
59+
description: The qualified URI of the property.
60+
type: string
61+
format: uri
62+
compactName:
63+
description: >-
64+
The property name used in the compacted JSON-LD document.
65+
It is used as the key of the property.
66+
type: string
67+
required:
68+
- uri
4869
required:
4970
- functional
5071

src/codegen/type.ts

+20
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,26 @@ const scalarTypes: Record<string, ScalarType> = {
273273
return `parseLanguageTag(${v}["@value"])`;
274274
},
275275
},
276+
"fedify:url": {
277+
name: "URL",
278+
typeGuard(v) {
279+
return `${v} instanceof URL`;
280+
},
281+
encoder(v) {
282+
return `{ "@value": ${v}.href }`;
283+
},
284+
compactEncoder(v) {
285+
return `${v}.href`;
286+
},
287+
dataCheck(v) {
288+
return `typeof ${v} === "object" && "@value" in ${v}
289+
&& typeof ${v}["@value"] === "string"
290+
&& ${v}["@value"] !== "" && ${v}["@value"] !== "/"`;
291+
},
292+
decoder(v) {
293+
return `new URL(${v}["@value"])`;
294+
},
295+
},
276296
"fedify:publicKey": {
277297
name: "CryptoKey",
278298
typeGuard(v) {

src/federation/handler.test.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ test("handleObject()", async () => {
439439
Hashtag: "as:Hashtag",
440440
sensitive: "as:sensitive",
441441
toot: "http://joinmastodon.org/ns#",
442+
_misskey_quote: "misskey:_misskey_quote",
443+
fedibird: "http://fedibird.com/ns#",
444+
misskey: "https://misskey-hub.net/ns#",
445+
quoteUri: "fedibird:quoteUri",
446+
quoteUrl: "as:quoteUrl",
442447
},
443448
],
444449
id: "https://example.com/users/someone/notes/123",
@@ -534,6 +539,11 @@ test("handleObject()", async () => {
534539
Hashtag: "as:Hashtag",
535540
sensitive: "as:sensitive",
536541
toot: "http://joinmastodon.org/ns#",
542+
_misskey_quote: "misskey:_misskey_quote",
543+
fedibird: "http://fedibird.com/ns#",
544+
misskey: "https://misskey-hub.net/ns#",
545+
quoteUri: "fedibird:quoteUri",
546+
quoteUrl: "as:quoteUrl",
537547
},
538548
],
539549
id: "https://example.com/users/someone/notes/123",
@@ -719,12 +729,17 @@ test("handleCollection()", async () => {
719729
"https://www.w3.org/ns/activitystreams",
720730
"https://w3id.org/security/data-integrity/v1",
721731
{
732+
toot: "http://joinmastodon.org/ns#",
733+
misskey: "https://misskey-hub.net/ns#",
734+
fedibird: "http://fedibird.com/ns#",
722735
ChatMessage: "http://litepub.social/ns#ChatMessage",
723736
Emoji: "toot:Emoji",
724737
Hashtag: "as:Hashtag",
725738
sensitive: "as:sensitive",
726-
toot: "http://joinmastodon.org/ns#",
727739
votersCount: "toot:votersCount",
740+
_misskey_quote: "misskey:_misskey_quote",
741+
quoteUri: "fedibird:quoteUri",
742+
quoteUrl: "as:quoteUrl",
728743
},
729744
];
730745
assertEquals(await response.json(), {
@@ -1161,6 +1176,11 @@ test("respondWithObject()", async () => {
11611176
Hashtag: "as:Hashtag",
11621177
sensitive: "as:sensitive",
11631178
toot: "http://joinmastodon.org/ns#",
1179+
_misskey_quote: "misskey:_misskey_quote",
1180+
fedibird: "http://fedibird.com/ns#",
1181+
misskey: "https://misskey-hub.net/ns#",
1182+
quoteUri: "fedibird:quoteUri",
1183+
quoteUrl: "as:quoteUrl",
11641184
},
11651185
],
11661186
id: "https://example.com/notes/1",
@@ -1196,6 +1216,11 @@ test("respondWithObjectIfAcceptable", async () => {
11961216
Hashtag: "as:Hashtag",
11971217
sensitive: "as:sensitive",
11981218
toot: "http://joinmastodon.org/ns#",
1219+
_misskey_quote: "misskey:_misskey_quote",
1220+
fedibird: "http://fedibird.com/ns#",
1221+
misskey: "https://misskey-hub.net/ns#",
1222+
quoteUri: "fedibird:quoteUri",
1223+
quoteUrl: "as:quoteUrl",
11991224
},
12001225
],
12011226
id: "https://example.com/notes/1",

src/sig/proof.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ test("createProof()", async () => {
8484
assertEquals(
8585
proof.proofValue,
8686
decodeHex(
87-
"0bc7df9f6a0a7998d31b9ba140eb0d40508edf47a20ed403770a4e6224af619c" +
88-
"633411e38322f175c2a74e3f1d6f44cc99f1ed3485cdd819586ec43a33bf1206",
87+
"e8f4680c67ca538a7814fc50e8eba95d545e4cfd887e676022ea69fd255cbd2f" +
88+
"ae7ae190da409aa35d6bdad12c2cf329c9bc1450a547d61340e793fb0ce5b104",
8989
),
9090
);
9191
assertEquals(proof.created, created);

0 commit comments

Comments
 (0)