@fedify/vocab 2.0.0-dev.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/LICENSE +20 -0
- package/deno.json +31 -0
- package/dist/accept.yaml +15 -0
- package/dist/activity.yaml +98 -0
- package/dist/actor.test.d.ts +2 -0
- package/dist/actor.test.js +6095 -0
- package/dist/add.yaml +16 -0
- package/dist/announce.yaml +30 -0
- package/dist/application.yaml +324 -0
- package/dist/arrive.yaml +15 -0
- package/dist/article.yaml +46 -0
- package/dist/audio.yaml +11 -0
- package/dist/block.yaml +16 -0
- package/dist/chatmessage.yaml +50 -0
- package/dist/collection.yaml +154 -0
- package/dist/collectionpage.yaml +55 -0
- package/dist/create.yaml +28 -0
- package/dist/dataintegrityproof.yaml +56 -0
- package/dist/delete.yaml +27 -0
- package/dist/deno-B-ypIMwF.js +1282 -0
- package/dist/didservice.yaml +22 -0
- package/dist/dislike.yaml +14 -0
- package/dist/document.yaml +31 -0
- package/dist/emoji.yaml +12 -0
- package/dist/emojireact.yaml +17 -0
- package/dist/endpoints.yaml +85 -0
- package/dist/event.yaml +11 -0
- package/dist/export.yaml +9 -0
- package/dist/flag.yaml +15 -0
- package/dist/follow.yaml +19 -0
- package/dist/group.yaml +324 -0
- package/dist/hashtag.yaml +14 -0
- package/dist/ignore.yaml +14 -0
- package/dist/image.yaml +9 -0
- package/dist/intransitiveactivity.yaml +15 -0
- package/dist/invite.yaml +14 -0
- package/dist/join.yaml +14 -0
- package/dist/key.yaml +28 -0
- package/dist/leave.yaml +14 -0
- package/dist/like.yaml +16 -0
- package/dist/link.yaml +101 -0
- package/dist/listen.yaml +12 -0
- package/dist/lookup.test.d.ts +2 -0
- package/dist/lookup.test.js +690 -0
- package/dist/mention.yaml +9 -0
- package/dist/mod.cjs +42036 -0
- package/dist/mod.d.cts +15329 -0
- package/dist/mod.d.ts +15330 -0
- package/dist/mod.js +41936 -0
- package/dist/move.yaml +15 -0
- package/dist/multikey.yaml +36 -0
- package/dist/note.yaml +48 -0
- package/dist/object.yaml +404 -0
- package/dist/offer.yaml +15 -0
- package/dist/orderedcollection.yaml +39 -0
- package/dist/orderedcollectionpage.yaml +50 -0
- package/dist/organization.yaml +324 -0
- package/dist/page.yaml +11 -0
- package/dist/person.yaml +324 -0
- package/dist/place.yaml +75 -0
- package/dist/profile.yaml +26 -0
- package/dist/propertyvalue.yaml +32 -0
- package/dist/question.yaml +103 -0
- package/dist/read.yaml +13 -0
- package/dist/reject.yaml +14 -0
- package/dist/relationship.yaml +52 -0
- package/dist/remove.yaml +14 -0
- package/dist/service.yaml +324 -0
- package/dist/source.yaml +26 -0
- package/dist/tentativeaccept.yaml +14 -0
- package/dist/tentativereject.yaml +14 -0
- package/dist/tombstone.yaml +24 -0
- package/dist/travel.yaml +16 -0
- package/dist/type-CNuABalk.js +13 -0
- package/dist/type.test.d.ts +2 -0
- package/dist/type.test.js +24 -0
- package/dist/undo.yaml +26 -0
- package/dist/update.yaml +58 -0
- package/dist/utils-BSWXlrig.js +13 -0
- package/dist/video.yaml +11 -0
- package/dist/view.yaml +13 -0
- package/dist/vocab-DBispxj5.js +41603 -0
- package/dist/vocab.test.d.ts +2 -0
- package/dist/vocab.test.js +1304 -0
- package/package.json +79 -0
- package/scripts/codegen.ts +20 -0
- package/src/__snapshots__/vocab.test.ts.snap +7903 -0
- package/src/accept.yaml +15 -0
- package/src/activity.yaml +98 -0
- package/src/actor.test.ts +263 -0
- package/src/actor.ts +293 -0
- package/src/add.yaml +16 -0
- package/src/announce.yaml +30 -0
- package/src/application.yaml +324 -0
- package/src/arrive.yaml +15 -0
- package/src/article.yaml +46 -0
- package/src/audio.yaml +11 -0
- package/src/block.yaml +16 -0
- package/src/chatmessage.yaml +50 -0
- package/src/collection.yaml +154 -0
- package/src/collectionpage.yaml +55 -0
- package/src/constants.ts +11 -0
- package/src/create.yaml +28 -0
- package/src/dataintegrityproof.yaml +56 -0
- package/src/delete.yaml +27 -0
- package/src/didservice.yaml +22 -0
- package/src/dislike.yaml +14 -0
- package/src/document.yaml +31 -0
- package/src/emoji.yaml +12 -0
- package/src/emojireact.yaml +17 -0
- package/src/endpoints.yaml +85 -0
- package/src/event.yaml +11 -0
- package/src/export.yaml +9 -0
- package/src/flag.yaml +15 -0
- package/src/follow.yaml +19 -0
- package/src/group.yaml +324 -0
- package/src/handle.ts +104 -0
- package/src/hashtag.yaml +14 -0
- package/src/ignore.yaml +14 -0
- package/src/image.yaml +9 -0
- package/src/intransitiveactivity.yaml +15 -0
- package/src/invite.yaml +14 -0
- package/src/join.yaml +14 -0
- package/src/key.yaml +28 -0
- package/src/keys.ts +50 -0
- package/src/leave.yaml +14 -0
- package/src/like.yaml +16 -0
- package/src/link.yaml +101 -0
- package/src/listen.yaml +12 -0
- package/src/lookup.test.ts +681 -0
- package/src/lookup.ts +318 -0
- package/src/mention.yaml +9 -0
- package/src/mod.ts +57 -0
- package/src/move.yaml +15 -0
- package/src/multikey.yaml +36 -0
- package/src/note.yaml +48 -0
- package/src/object.yaml +404 -0
- package/src/offer.yaml +15 -0
- package/src/orderedcollection.yaml +39 -0
- package/src/orderedcollectionpage.yaml +50 -0
- package/src/organization.yaml +324 -0
- package/src/page.yaml +11 -0
- package/src/person.yaml +324 -0
- package/src/place.yaml +75 -0
- package/src/profile.yaml +26 -0
- package/src/propertyvalue.yaml +32 -0
- package/src/question.yaml +103 -0
- package/src/read.yaml +13 -0
- package/src/reject.yaml +14 -0
- package/src/relationship.yaml +52 -0
- package/src/remove.yaml +14 -0
- package/src/service.yaml +324 -0
- package/src/source.yaml +26 -0
- package/src/tentativeaccept.yaml +14 -0
- package/src/tentativereject.yaml +14 -0
- package/src/tombstone.yaml +24 -0
- package/src/travel.yaml +16 -0
- package/src/type.test.ts +20 -0
- package/src/type.ts +102 -0
- package/src/undo.yaml +26 -0
- package/src/update.yaml +58 -0
- package/src/utils.ts +9 -0
- package/src/video.yaml +11 -0
- package/src/view.yaml +13 -0
- package/src/vocab.bench.ts +204 -0
- package/src/vocab.test.ts +2014 -0
- package/tsdown.config.ts +65 -0
package/src/lookup.ts
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import type { GetUserAgentOptions } from "@fedify/vocab-runtime";
|
|
2
|
+
import {
|
|
3
|
+
type DocumentLoader,
|
|
4
|
+
getDocumentLoader,
|
|
5
|
+
type RemoteDocument,
|
|
6
|
+
} from "@fedify/vocab-runtime";
|
|
7
|
+
import { lookupWebFinger } from "@fedify/webfinger";
|
|
8
|
+
import { getLogger } from "@logtape/logtape";
|
|
9
|
+
import { SpanStatusCode, trace, type TracerProvider } from "@opentelemetry/api";
|
|
10
|
+
import { delay } from "es-toolkit";
|
|
11
|
+
import metadata from "../deno.json" with { type: "json" };
|
|
12
|
+
import { toAcctUrl } from "./handle.ts";
|
|
13
|
+
import { getTypeId } from "./type.ts";
|
|
14
|
+
import { type Collection, type Link, Object } from "./vocab.ts";
|
|
15
|
+
|
|
16
|
+
const logger = getLogger(["fedify", "vocab", "lookup"]);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options for the {@link lookupObject} function.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.2.0
|
|
22
|
+
*/
|
|
23
|
+
export interface LookupObjectOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The document loader for loading remote JSON-LD documents.
|
|
26
|
+
*/
|
|
27
|
+
documentLoader?: DocumentLoader;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The context loader for loading remote JSON-LD contexts.
|
|
31
|
+
* @since 0.8.0
|
|
32
|
+
*/
|
|
33
|
+
contextLoader?: DocumentLoader;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether to allow fetching an object with an `@id` having a different
|
|
37
|
+
* origin than the object's URL. This is not recommended, as it may
|
|
38
|
+
* lead to security issues. Only use this option if you know what you
|
|
39
|
+
* are doing.
|
|
40
|
+
*
|
|
41
|
+
* How to handle the case when an object's `@id` has a different origin
|
|
42
|
+
* than the object's URL:
|
|
43
|
+
*
|
|
44
|
+
* - `"ignore"` (default): Do not return the object, and log a warning.
|
|
45
|
+
* - `"throw"`: Throw an error.
|
|
46
|
+
* - `"trust"`: Bypass the check and return the object anyway. This
|
|
47
|
+
* is not recommended, as it may lead to security issues. Only use
|
|
48
|
+
* this option if you know what you are doing.
|
|
49
|
+
*
|
|
50
|
+
* @since 1.9.0
|
|
51
|
+
*/
|
|
52
|
+
crossOrigin?: "ignore" | "throw" | "trust";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The options for making `User-Agent` header.
|
|
56
|
+
* If a string is given, it is used as the `User-Agent` header value.
|
|
57
|
+
* If an object is given, it is passed to {@link getUserAgent} to generate
|
|
58
|
+
* the `User-Agent` header value.
|
|
59
|
+
* @since 1.3.0
|
|
60
|
+
*/
|
|
61
|
+
userAgent?: GetUserAgentOptions | string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The OpenTelemetry tracer provider. If omitted, the global tracer provider
|
|
65
|
+
* is used.
|
|
66
|
+
* @since 1.3.0
|
|
67
|
+
*/
|
|
68
|
+
tracerProvider?: TracerProvider;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* AbortSignal for cancelling the request.
|
|
72
|
+
* @since 1.8.0
|
|
73
|
+
*/
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Looks up an ActivityStreams object by its URI (including `acct:` URIs)
|
|
79
|
+
* or a fediverse handle (e.g., `@user@server` or `user@server`).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ``` typescript
|
|
83
|
+
* // Look up an actor by its fediverse handle:
|
|
84
|
+
* await lookupObject("@hongminhee@fosstodon.org");
|
|
85
|
+
* // returning a `Person` object.
|
|
86
|
+
*
|
|
87
|
+
* // A fediverse handle can omit the leading '@':
|
|
88
|
+
* await lookupObject("hongminhee@fosstodon.org");
|
|
89
|
+
* // returning a `Person` object.
|
|
90
|
+
*
|
|
91
|
+
* // A `acct:` URI can be used as well:
|
|
92
|
+
* await lookupObject("acct:hongminhee@fosstodon.org");
|
|
93
|
+
* // returning a `Person` object.
|
|
94
|
+
*
|
|
95
|
+
* // Look up an object by its URI:
|
|
96
|
+
* await lookupObject("https://todon.eu/@hongminhee/112060633798771581");
|
|
97
|
+
* // returning a `Note` object.
|
|
98
|
+
*
|
|
99
|
+
* // It can be a `URL` object as well:
|
|
100
|
+
* await lookupObject(new URL("https://todon.eu/@hongminhee/112060633798771581"));
|
|
101
|
+
* // returning a `Note` object.
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @param identifier The URI or fediverse handle to look up.
|
|
105
|
+
* @param options Lookup options.
|
|
106
|
+
* @returns The object, or `null` if not found.
|
|
107
|
+
* @since 0.2.0
|
|
108
|
+
*/
|
|
109
|
+
export async function lookupObject(
|
|
110
|
+
identifier: string | URL,
|
|
111
|
+
options: LookupObjectOptions = {},
|
|
112
|
+
): Promise<Object | null> {
|
|
113
|
+
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
|
114
|
+
const tracer = tracerProvider.getTracer(
|
|
115
|
+
metadata.name,
|
|
116
|
+
metadata.version,
|
|
117
|
+
);
|
|
118
|
+
return await tracer.startActiveSpan(
|
|
119
|
+
"activitypub.lookup_object",
|
|
120
|
+
async (span) => {
|
|
121
|
+
try {
|
|
122
|
+
const result = await lookupObjectInternal(identifier, options);
|
|
123
|
+
if (result == null) span.setStatus({ code: SpanStatusCode.ERROR });
|
|
124
|
+
else {
|
|
125
|
+
if (result.id != null) {
|
|
126
|
+
span.setAttribute("activitypub.object.id", result.id.href);
|
|
127
|
+
}
|
|
128
|
+
span.setAttribute("activitypub.object.type", getTypeId(result).href);
|
|
129
|
+
if (result.replyTargetIds.length > 0) {
|
|
130
|
+
span.setAttribute(
|
|
131
|
+
"activitypub.object.in_reply_to",
|
|
132
|
+
result.replyTargetIds.map((id) => id.href),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Record the fetched object details
|
|
137
|
+
span.addEvent("activitypub.object.fetched", {
|
|
138
|
+
"activitypub.object.type": getTypeId(result).href,
|
|
139
|
+
"activitypub.object.json": JSON.stringify(
|
|
140
|
+
await result.toJsonLd(options),
|
|
141
|
+
),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
span.recordException(error as Error);
|
|
147
|
+
span.setStatus({
|
|
148
|
+
code: SpanStatusCode.ERROR,
|
|
149
|
+
message: String(error),
|
|
150
|
+
});
|
|
151
|
+
throw error;
|
|
152
|
+
} finally {
|
|
153
|
+
span.end();
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function lookupObjectInternal(
|
|
160
|
+
identifier: string | URL,
|
|
161
|
+
options: LookupObjectOptions = {},
|
|
162
|
+
): Promise<Object | null> {
|
|
163
|
+
const documentLoader = options.documentLoader ??
|
|
164
|
+
getDocumentLoader({ userAgent: options.userAgent });
|
|
165
|
+
if (typeof identifier === "string") {
|
|
166
|
+
identifier = toAcctUrl(identifier) ?? new URL(identifier);
|
|
167
|
+
}
|
|
168
|
+
let remoteDoc: RemoteDocument | null = null;
|
|
169
|
+
if (identifier.protocol === "http:" || identifier.protocol === "https:") {
|
|
170
|
+
try {
|
|
171
|
+
remoteDoc = await documentLoader(identifier.href, {
|
|
172
|
+
signal: options.signal,
|
|
173
|
+
});
|
|
174
|
+
} catch (error) {
|
|
175
|
+
logger.debug("Failed to fetch remote document:\n{error}", { error });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (remoteDoc == null) {
|
|
179
|
+
const jrd = await lookupWebFinger(identifier, {
|
|
180
|
+
userAgent: options.userAgent,
|
|
181
|
+
tracerProvider: options.tracerProvider,
|
|
182
|
+
allowPrivateAddress: "allowPrivateAddress" in options &&
|
|
183
|
+
options.allowPrivateAddress === true,
|
|
184
|
+
signal: options.signal,
|
|
185
|
+
});
|
|
186
|
+
if (jrd?.links == null) return null;
|
|
187
|
+
for (const l of jrd.links) {
|
|
188
|
+
if (
|
|
189
|
+
l.type !== "application/activity+json" &&
|
|
190
|
+
!l.type?.match(
|
|
191
|
+
/application\/ld\+json;\s*profile="https:\/\/www.w3.org\/ns\/activitystreams"/,
|
|
192
|
+
) || l.rel !== "self" || l.href == null
|
|
193
|
+
) continue;
|
|
194
|
+
try {
|
|
195
|
+
remoteDoc = await documentLoader(l.href, {
|
|
196
|
+
signal: options.signal,
|
|
197
|
+
});
|
|
198
|
+
break;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
logger.debug("Failed to fetch remote document:\n{error}", { error });
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (remoteDoc == null) return null;
|
|
206
|
+
let object: Object;
|
|
207
|
+
try {
|
|
208
|
+
object = await Object.fromJsonLd(remoteDoc.document, {
|
|
209
|
+
documentLoader,
|
|
210
|
+
contextLoader: options.contextLoader,
|
|
211
|
+
tracerProvider: options.tracerProvider,
|
|
212
|
+
baseUrl: new URL(remoteDoc.documentUrl),
|
|
213
|
+
});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (error instanceof TypeError) {
|
|
216
|
+
logger.debug(
|
|
217
|
+
"Failed to parse JSON-LD document: {error}\n{document}",
|
|
218
|
+
{ ...remoteDoc, error },
|
|
219
|
+
);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
if (
|
|
225
|
+
options.crossOrigin !== "trust" && object.id != null &&
|
|
226
|
+
object.id.origin !== new URL(remoteDoc.documentUrl).origin
|
|
227
|
+
) {
|
|
228
|
+
if (options.crossOrigin === "throw") {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`The object's @id (${object.id.href}) has a different origin than ` +
|
|
231
|
+
`the document URL (${remoteDoc.documentUrl}); refusing to return ` +
|
|
232
|
+
`the object. If you want to bypass this check and are aware of ` +
|
|
233
|
+
`the security implications, set the crossOrigin option to "trust".`,
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
logger.warn(
|
|
237
|
+
"The object's @id ({objectId}) has a different origin than the document " +
|
|
238
|
+
"URL ({documentUrl}); refusing to return the object. If you want to " +
|
|
239
|
+
"bypass this check and are aware of the security implications, " +
|
|
240
|
+
'set the crossOrigin option to "trust".',
|
|
241
|
+
{ ...remoteDoc, objectId: object.id.href },
|
|
242
|
+
);
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
return object;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Options for the {@link traverseCollection} function.
|
|
250
|
+
* @since 1.1.0
|
|
251
|
+
*/
|
|
252
|
+
export interface TraverseCollectionOptions {
|
|
253
|
+
/**
|
|
254
|
+
* The document loader for loading remote JSON-LD documents.
|
|
255
|
+
*/
|
|
256
|
+
documentLoader?: DocumentLoader;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The context loader for loading remote JSON-LD contexts.
|
|
260
|
+
*/
|
|
261
|
+
contextLoader?: DocumentLoader;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Whether to suppress errors when fetching pages. If `true`,
|
|
265
|
+
* errors will be logged but not thrown. Defaults to `false`.
|
|
266
|
+
*/
|
|
267
|
+
suppressError?: boolean;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The interval to wait between fetching pages. Zero or negative
|
|
271
|
+
* values will disable the interval. Disabled by default.
|
|
272
|
+
*
|
|
273
|
+
* @default `{ seconds: 0 }`
|
|
274
|
+
*/
|
|
275
|
+
interval?: Temporal.Duration | Temporal.DurationLike;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Traverses a collection, yielding each item in the collection.
|
|
280
|
+
* If the collection is paginated, it will fetch the next page
|
|
281
|
+
* automatically.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ``` typescript
|
|
285
|
+
* const collection = await lookupObject(collectionUrl);
|
|
286
|
+
* if (collection instanceof Collection) {
|
|
287
|
+
* for await (const item of traverseCollection(collection)) {
|
|
288
|
+
* console.log(item.id?.href);
|
|
289
|
+
* }
|
|
290
|
+
* }
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @param collection The collection to traverse.
|
|
294
|
+
* @param options Options for traversing the collection.
|
|
295
|
+
* @returns An async iterable of each item in the collection.
|
|
296
|
+
* @since 1.1.0
|
|
297
|
+
*/
|
|
298
|
+
export async function* traverseCollection(
|
|
299
|
+
collection: Collection,
|
|
300
|
+
options: TraverseCollectionOptions = {},
|
|
301
|
+
): AsyncIterable<Object | Link> {
|
|
302
|
+
if (collection.firstId == null) {
|
|
303
|
+
for await (const item of collection.getItems(options)) {
|
|
304
|
+
yield item;
|
|
305
|
+
}
|
|
306
|
+
} else {
|
|
307
|
+
const interval = Temporal.Duration.from(options.interval ?? { seconds: 0 })
|
|
308
|
+
.total("millisecond");
|
|
309
|
+
let page = await collection.getFirst(options);
|
|
310
|
+
while (page != null) {
|
|
311
|
+
for await (const item of page.getItems(options)) {
|
|
312
|
+
yield item;
|
|
313
|
+
}
|
|
314
|
+
if (interval > 0) await delay(interval);
|
|
315
|
+
page = await page.getNext(options);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
package/src/mention.yaml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
$schema: ../../vocab-tools/schema.yaml
|
|
2
|
+
name: Mention
|
|
3
|
+
compactName: Mention
|
|
4
|
+
uri: "https://www.w3.org/ns/activitystreams#Mention"
|
|
5
|
+
extends: "https://www.w3.org/ns/activitystreams#Link"
|
|
6
|
+
entity: false
|
|
7
|
+
description: A specialized {@link Link} that represents an @mention.
|
|
8
|
+
defaultContext: "https://www.w3.org/ns/activitystreams"
|
|
9
|
+
properties: []
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of type-safe object mappings for the [Activity
|
|
3
|
+
* Vocabulary](https://www.w3.org/TR/activitystreams-vocabulary/).
|
|
4
|
+
*
|
|
5
|
+
* Each class in this module represents a type of object in the Activity
|
|
6
|
+
* Vocabulary. For example, the {@link Note} class represents the
|
|
7
|
+
* [`Note` type](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note)
|
|
8
|
+
* in the Activity Vocabulary.
|
|
9
|
+
*
|
|
10
|
+
* There are two ways to instantiate an object of a class in this module.
|
|
11
|
+
* The first way is to use the constructor of the class. For example:
|
|
12
|
+
*
|
|
13
|
+
* ``` typescript
|
|
14
|
+
* const note = new Note({
|
|
15
|
+
* attributedTo: new URL("https://example.com/user"),
|
|
16
|
+
* content: "Hello, world!",
|
|
17
|
+
* });
|
|
18
|
+
* const create = new Create({
|
|
19
|
+
* actor: new URL("https://example.com/user"),
|
|
20
|
+
* object: note,
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The second way is to deserialize an object from a JSON-LD document using
|
|
25
|
+
* the `fromJsonLd()` method of the class. For example:
|
|
26
|
+
*
|
|
27
|
+
* ``` typescript
|
|
28
|
+
* const create = await Create.fromJsonLd({
|
|
29
|
+
* "@context": "https://www.w3.org/ns/activitystreams",
|
|
30
|
+
* "type": "Create",
|
|
31
|
+
* "actor": "https://example.com/user",
|
|
32
|
+
* "object": {
|
|
33
|
+
* "type": "Note",
|
|
34
|
+
* "attributedTo": "https://example.com/user",
|
|
35
|
+
* "content": "Hello, world!",
|
|
36
|
+
* },
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* In order to serialize an object to a JSON-LD document, use the `toJsonLd()`
|
|
41
|
+
* method of the object. For example:
|
|
42
|
+
*
|
|
43
|
+
* ``` typescript
|
|
44
|
+
* const jsonLd = await create.toJsonLd();
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Note that both `fromJsonLd()` and `toJsonLd()` are asynchronous methods
|
|
48
|
+
* that return a `Promise`.
|
|
49
|
+
*
|
|
50
|
+
* @module
|
|
51
|
+
*/
|
|
52
|
+
export * from "./actor.ts";
|
|
53
|
+
export * from "./constants.ts";
|
|
54
|
+
export * from "./handle.ts";
|
|
55
|
+
export * from "./lookup.ts";
|
|
56
|
+
export * from "./type.ts";
|
|
57
|
+
export * from "./vocab.ts";
|
package/src/move.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
$schema: ../../vocab-tools/schema.yaml
|
|
2
|
+
name: Move
|
|
3
|
+
compactName: Move
|
|
4
|
+
uri: "https://www.w3.org/ns/activitystreams#Move"
|
|
5
|
+
extends: "https://www.w3.org/ns/activitystreams#Activity"
|
|
6
|
+
entity: true
|
|
7
|
+
description: |
|
|
8
|
+
Indicates that the `actor` has moved `object` from `origin` to `target`.
|
|
9
|
+
If the `origin` or `target` are not specified,
|
|
10
|
+
either can be determined by context.
|
|
11
|
+
defaultContext:
|
|
12
|
+
- "https://w3id.org/identity/v1"
|
|
13
|
+
- "https://www.w3.org/ns/activitystreams"
|
|
14
|
+
- "https://w3id.org/security/data-integrity/v1"
|
|
15
|
+
properties: []
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
$schema: ../../vocab-tools/schema.yaml
|
|
2
|
+
name: Multikey
|
|
3
|
+
compactName: Multikey
|
|
4
|
+
uri: "https://w3id.org/security#Multikey"
|
|
5
|
+
entity: true
|
|
6
|
+
description: |
|
|
7
|
+
Represents a key owned by an actor according to [FEP-521a: Representing
|
|
8
|
+
actor's public keys.][1]
|
|
9
|
+
|
|
10
|
+
[1]: https://w3id.org/fep/521a
|
|
11
|
+
defaultContext: "https://w3id.org/security/multikey/v1"
|
|
12
|
+
|
|
13
|
+
properties:
|
|
14
|
+
- singularName: controller
|
|
15
|
+
functional: true
|
|
16
|
+
compactName: controller
|
|
17
|
+
uri: "https://w3id.org/security#controller"
|
|
18
|
+
description: An actor who owns this key.
|
|
19
|
+
range:
|
|
20
|
+
- "https://www.w3.org/ns/activitystreams#Application"
|
|
21
|
+
- "https://www.w3.org/ns/activitystreams#Group"
|
|
22
|
+
- "https://www.w3.org/ns/activitystreams#Organization"
|
|
23
|
+
- "https://www.w3.org/ns/activitystreams#Person"
|
|
24
|
+
- "https://www.w3.org/ns/activitystreams#Service"
|
|
25
|
+
|
|
26
|
+
- singularName: publicKey
|
|
27
|
+
functional: true
|
|
28
|
+
compactName: publicKeyMultibase
|
|
29
|
+
uri: "https://w3id.org/security#publicKeyMultibase"
|
|
30
|
+
description: |
|
|
31
|
+
A [Multibase]-encoded value of a [Multicodec] prefix and the key.
|
|
32
|
+
|
|
33
|
+
[Multibase]: https://www.w3.org/TR/vc-data-integrity/#multibase-0
|
|
34
|
+
[Multicodec]: https://github.com/multiformats/multicodec/
|
|
35
|
+
range:
|
|
36
|
+
- "fedify:multibaseKey"
|
package/src/note.yaml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
$schema: ../../vocab-tools/schema.yaml
|
|
2
|
+
name: Note
|
|
3
|
+
compactName: Note
|
|
4
|
+
uri: "https://www.w3.org/ns/activitystreams#Note"
|
|
5
|
+
extends: "https://www.w3.org/ns/activitystreams#Object"
|
|
6
|
+
entity: true
|
|
7
|
+
description: |
|
|
8
|
+
Represents a short written work typically less than a single paragraph in
|
|
9
|
+
length.
|
|
10
|
+
defaultContext:
|
|
11
|
+
- "https://www.w3.org/ns/activitystreams"
|
|
12
|
+
- "https://w3id.org/security/data-integrity/v1"
|
|
13
|
+
- toot: "http://joinmastodon.org/ns#"
|
|
14
|
+
misskey: "https://misskey-hub.net/ns#"
|
|
15
|
+
fedibird: "http://fedibird.com/ns#"
|
|
16
|
+
sensitive: "as:sensitive"
|
|
17
|
+
Emoji: "toot:Emoji"
|
|
18
|
+
Hashtag: "as:Hashtag"
|
|
19
|
+
quoteUrl: "as:quoteUrl"
|
|
20
|
+
_misskey_quote: "misskey:_misskey_quote"
|
|
21
|
+
quoteUri: "fedibird:quoteUri"
|
|
22
|
+
emojiReactions:
|
|
23
|
+
"@id": "fedibird:emojiReactions"
|
|
24
|
+
"@type": "@id"
|
|
25
|
+
|
|
26
|
+
properties:
|
|
27
|
+
- singularName: quoteUrl
|
|
28
|
+
functional: true
|
|
29
|
+
compactName: quoteUrl
|
|
30
|
+
uri: "https://www.w3.org/ns/activitystreams#quoteUrl"
|
|
31
|
+
redundantProperties:
|
|
32
|
+
- compactName: _misskey_quote
|
|
33
|
+
uri: "https://misskey-hub.net/ns#_misskey_quote"
|
|
34
|
+
- compactName: quoteUri
|
|
35
|
+
uri: "http://fedibird.com/ns#quoteUri"
|
|
36
|
+
description: |
|
|
37
|
+
The URI of the ActivityStreams object that this object quotes.
|
|
38
|
+
|
|
39
|
+
This property sets three JSON-LD properties at once under the hood:
|
|
40
|
+
|
|
41
|
+
1. https://www.w3.org/ns/activitystreams#quoteUrl
|
|
42
|
+
2. https://misskey-hub.net/ns#_misskey_quote
|
|
43
|
+
3. http://fedibird.com/ns#quoteUri
|
|
44
|
+
|
|
45
|
+
When a JSON-LD object is parsed, this property is filled with one of
|
|
46
|
+
the values of those three properties in order.
|
|
47
|
+
range:
|
|
48
|
+
- "fedify:url"
|