mostly comments allowing
This commit is contained in:
parent
e895dec8cc
commit
b7f5c65013
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2018",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ESNext",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2018",
|
||||
|
|
|
@ -4,7 +4,19 @@ import type { StringReferenceMap } from '../util/values';
|
|||
import type { ImageReference } from '../Extended/ExtendedObject';
|
||||
import type { LinkReference } from './Link';
|
||||
import type { CollectionReference, OrderedCollectionReference } from '../Extended/Collection';
|
||||
/**
|
||||
* A union of all Core Object types.
|
||||
*/
|
||||
export type AnyCoreObjectType = (typeof CoreObjectTypes)[keyof typeof CoreObjectTypes];
|
||||
/**
|
||||
* Properties common to all Core Objects.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*
|
||||
* @note The `sensitive` property is not included in the spec, but it is
|
||||
* included because it is common to all ActivityPub objects in practice
|
||||
* by way of an extension to the spec.
|
||||
*/
|
||||
export type CoreObjectProperties = {
|
||||
attachment?: OrArray<EntityReference>;
|
||||
attributedTo?: OrArray<EntityReference>;
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
/// <reference types="node" />
|
||||
import { TypeOrArrayWithType, AnyType, OrArray } from '../util';
|
||||
/**
|
||||
* A base ActivityStreams Entity is a plain object that has at least a `type`
|
||||
* property.
|
||||
*
|
||||
* @todo Add better support for the `@context` property.
|
||||
*/
|
||||
export type BaseEntity<T extends AnyType> = {
|
||||
'@context'?: OrArray<URL | Record<string, URL>>;
|
||||
id?: URL | null;
|
||||
|
|
|
@ -2,7 +2,13 @@
|
|||
import { BaseEntity } from './Entity';
|
||||
import { LinkTypes, OrArray, StringReferenceMap } from '../util';
|
||||
import { EntityReference } from '.';
|
||||
/**
|
||||
* A union of all Link types.
|
||||
*/
|
||||
export type AnyLinkType = (typeof LinkTypes)[keyof typeof LinkTypes];
|
||||
/**
|
||||
* Properties common to all Link types.
|
||||
*/
|
||||
export type LinkProperties = {
|
||||
height?: number;
|
||||
href?: URL;
|
||||
|
@ -14,8 +20,52 @@ export type LinkProperties = {
|
|||
rel?: OrArray<string>;
|
||||
width?: number;
|
||||
};
|
||||
/**
|
||||
* The base type for all Link types.
|
||||
*
|
||||
* @note This differs from Link, which is the type for a Link entity
|
||||
* specifically. This is the base type for all Link types, including the Link
|
||||
* and Mention types.
|
||||
*
|
||||
* @extends BaseEntity
|
||||
*
|
||||
* @instance Link
|
||||
* @instance Mention
|
||||
*/
|
||||
export type BaseLink<T extends AnyLinkType> = BaseEntity<T> & LinkProperties;
|
||||
/**
|
||||
* A Link entity.
|
||||
*
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > A Link is an indirect, qualified reference to a resource identified by a
|
||||
* > URL. The fundamental model for links is established by [RFC5988]. Many of
|
||||
* > the properties defined by the Activity Vocabulary allow values that are
|
||||
* > either instances of Object or Link. When a Link is used, it establishes a
|
||||
* > qualified relation connecting the subject (the containing object) to the
|
||||
* > resource identified by the href. Properties of the Link are properties of
|
||||
* > the reference as opposed to properties of the resource.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link
|
||||
*/
|
||||
export type LinkEntity = BaseLink<typeof LinkTypes.LINK>;
|
||||
/**
|
||||
* A Mention entity.
|
||||
*
|
||||
* Per the ActivityPub spec:
|
||||
*
|
||||
* > A Mention is a specialization of Link that represents an @mention.
|
||||
*
|
||||
* @extends Link
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#mention
|
||||
*/
|
||||
export type Mention = BaseLink<typeof LinkTypes.MENTION>;
|
||||
/**
|
||||
* A Link entity or Mention entity.
|
||||
*/
|
||||
export type Link = LinkEntity | Mention;
|
||||
/**
|
||||
* Either a Link or a URL reference to a Link.
|
||||
*/
|
||||
export type LinkReference = URL | Link;
|
||||
|
|
|
@ -6,7 +6,45 @@ import { AnyCollectionOrCollectionPage } from '../Extended/Collection';
|
|||
import { ExtendedObject } from '../Extended';
|
||||
export { CoreObjectProperties } from './CoreObject';
|
||||
export type { Link, LinkReference, Mention } from './Link';
|
||||
/**
|
||||
* The base type for all ActivityPub Object Types, including Actors, Activities,
|
||||
* Collections, and Extended Objects.
|
||||
*
|
||||
* @note This type is named `CoreObject` instead of `Object` to avoid collision
|
||||
* with the JavaScript `Object` type. Further, this avoids confusion with what
|
||||
* the spec refers to as "Objects", which are called "Entities" in this library.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*
|
||||
* @extends Entity
|
||||
*
|
||||
* @instance ExtendedObject
|
||||
* @instance Actor
|
||||
* @instance Activity
|
||||
* @instance Collection
|
||||
*/
|
||||
export type CoreObject = ExtendedObject | Actor | Activity | AnyCollectionOrCollectionPage;
|
||||
/**
|
||||
* Either a CoreObject or a URL reference to a CoreObject.
|
||||
*/
|
||||
export type CoreObjectReference = URL | CoreObject;
|
||||
/**
|
||||
* The base type for all ActivityPub objects, including Core Object and Link
|
||||
* types.
|
||||
*
|
||||
* @note The spec does not specify a base type, but this library does for
|
||||
* convenience and easier type checking. Instead, the spec refers to all
|
||||
* ActivityPub documents as "Objects". This library uses the term "Entity" to
|
||||
* refer to all ActivityPub documents, including both Core Objects and Links.
|
||||
*
|
||||
* @note The spec allows the type property to be optional, but it is required by
|
||||
* this library in order to differentiate between different types of objects.
|
||||
*
|
||||
* @instance CoreObject
|
||||
* @instance Link
|
||||
*/
|
||||
export type Entity = CoreObject | Link | Mention;
|
||||
/**
|
||||
* Either an Entity or a URL reference to an Entity.
|
||||
*/
|
||||
export type EntityReference = URL | Entity;
|
||||
|
|
|
@ -2,9 +2,21 @@
|
|||
import { ActivityTypes, OrArray, TransitiveActivityTypes, IntransitiveActivityTypes } from '../util';
|
||||
import { CoreObjectProperties, EntityReference } from '../Core';
|
||||
import { BaseEntity } from '../Core/Entity';
|
||||
/**
|
||||
* A union of all Activity types.
|
||||
*/
|
||||
export type AnyActivityType = (typeof ActivityTypes)[keyof typeof ActivityTypes];
|
||||
/**
|
||||
* A union of all Transitive Activity types.
|
||||
*/
|
||||
export type AnyTransitiveActivityType = (typeof TransitiveActivityTypes)[keyof typeof TransitiveActivityTypes];
|
||||
/**
|
||||
* A union of all Intransitive Activity types.
|
||||
*/
|
||||
export type AnyIntransitiveActivityType = (typeof IntransitiveActivityTypes)[keyof typeof IntransitiveActivityTypes];
|
||||
/**
|
||||
* Properties common to all Activity types.
|
||||
*/
|
||||
export type ActivityProperties = {
|
||||
actor: OrArray<EntityReference>;
|
||||
object?: OrArray<EntityReference>;
|
||||
|
@ -13,44 +25,430 @@ export type ActivityProperties = {
|
|||
origin?: OrArray<EntityReference>;
|
||||
instrument?: OrArray<EntityReference>;
|
||||
};
|
||||
/**
|
||||
* The base type for all Activity entities.
|
||||
*
|
||||
* @extends CoreObject
|
||||
*/
|
||||
type BaseActivity<T extends AnyActivityType> = BaseEntity<T> & CoreObjectProperties & ActivityProperties;
|
||||
/**
|
||||
* Properties common to all TransitiveActivity types.
|
||||
*/
|
||||
type TransitiveActivityProperties = {
|
||||
object: OrArray<EntityReference>;
|
||||
};
|
||||
/**
|
||||
* The base type for all TransitiveActivity entities, meaning those that have an
|
||||
* `object` property.
|
||||
*
|
||||
* @note This is not in the spec, but it is useful for type checking.
|
||||
*
|
||||
* Inversing the definition of IntransitiveActivity from the ActivityStreams
|
||||
* Vocabulary spec:
|
||||
*
|
||||
* > Instances of TransitiveActivity are a subtype of Activity representing
|
||||
* > transitive actions. The object property is therefore required for these
|
||||
* > activities.
|
||||
*
|
||||
* @extends Activity
|
||||
*/
|
||||
export type TransitiveActivity<T extends AnyTransitiveActivityType> = BaseActivity<T> & TransitiveActivityProperties;
|
||||
/**
|
||||
* The base type for all IntransitiveActivity entities, meaning those that do
|
||||
* not have an `object` property.
|
||||
*
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Instances of IntransitiveActivity are a subtype of Activity representing
|
||||
* > intransitive actions. The object property is therefore inappropriate for
|
||||
* > these activities.
|
||||
*
|
||||
* @extends Activity
|
||||
*/
|
||||
export type IntransitiveActivity<T extends AnyIntransitiveActivityType> = BaseActivity<T>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has accepted the object. The target property can
|
||||
* > be used in certain circumstances to indicate the context into which the
|
||||
* > object has been accepted.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accept
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Accept = TransitiveActivity<typeof ActivityTypes.ACCEPT>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is tentatively accepting the object. The target
|
||||
* > property can be used in certain circumstances to indicate the context into
|
||||
* > which the object has been accepted.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tentative-accept
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type TentativeAccept = TransitiveActivity<typeof ActivityTypes.TENTATIVE_ACCEPT>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has added the object to the target. If the target
|
||||
* > property is not explicitly specified, the target would need to be
|
||||
* > determined implicitly by context. The origin can be used to identify the
|
||||
* > context from which the object originated.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-add
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Add = TransitiveActivity<typeof ActivityTypes.ADD>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has arrived at the location. The origin can be
|
||||
* > used to identify the context from which the actor originated. The target
|
||||
* > typically has no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-arrive
|
||||
*
|
||||
* @type IntransitiveActivity
|
||||
*/
|
||||
export type Arrive = IntransitiveActivity<typeof ActivityTypes.ARRIVE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has created the object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-create
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Create = TransitiveActivity<typeof ActivityTypes.CREATE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has deleted the object. If specified, the origin
|
||||
* > indicates the context from which the object was deleted.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-delete
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Delete = TransitiveActivity<typeof ActivityTypes.DELETE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is "following" the object. Following is defined in
|
||||
* > the sense typically used within Social systems in which the actor is
|
||||
* > interested in any activity performed by or on the object. The target and
|
||||
* > origin typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-follow
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Follow = TransitiveActivity<typeof ActivityTypes.FOLLOW>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is ignoring the object. The target and origin
|
||||
* > typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-ignore
|
||||
*/
|
||||
export type Ignore = TransitiveActivity<typeof ActivityTypes.IGNORE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has joined the object. The target and origin
|
||||
* > typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-join
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Join = TransitiveActivity<typeof ActivityTypes.JOIN>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is leaving the object. If specified, the origin
|
||||
* > indicates the context from which the actor is leaving.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-leave
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Leave = TransitiveActivity<typeof ActivityTypes.LEAVE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor likes, recommends or endorses the object. The
|
||||
* > target and origin typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-like
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Like = TransitiveActivity<typeof ActivityTypes.LIKE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is offering the object. If specified, the target
|
||||
* > indicates the entity to which the object is being offered.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-offer
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Offer = TransitiveActivity<typeof ActivityTypes.OFFER>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is inviting the object to target. If the origin
|
||||
* > property is not specified, the target is notified directly. For instance,
|
||||
* > Alice can invite Joe to an event by posting an Invite object to her
|
||||
* > personal stream or by mentioning him, effectively inviting him to the
|
||||
* > event.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-invite
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Invite = TransitiveActivity<typeof ActivityTypes.INVITE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is rejecting the object. The target and origin
|
||||
* > typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-reject
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Reject = TransitiveActivity<typeof ActivityTypes.REJECT>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is tentatively rejecting the object. The target
|
||||
* > and origin typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tentative-reject
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type TentativeReject = TransitiveActivity<typeof ActivityTypes.TENTATIVE_REJECT>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has removed the object. If specified, the origin
|
||||
* > indicates the context from which the object was removed.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-remove
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Remove = TransitiveActivity<typeof ActivityTypes.REMOVE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is undoing the object. In most cases, the object
|
||||
* > will be an Activity describing some previously performed action (for
|
||||
* > instance, a person may have previously "liked" an article but, for whatever
|
||||
* > reason, might choose to undo that like at some later point in time).
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-undo
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Undo = TransitiveActivity<typeof ActivityTypes.UNDO>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has updated the object. Note, however, that this
|
||||
* > vocabulary does not define a mechanism for describing the actual set of
|
||||
* > modifications made to object. The target and origin typically have no
|
||||
* > defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-update
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Update = TransitiveActivity<typeof ActivityTypes.UPDATE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has viewed the object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-view
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type View = TransitiveActivity<typeof ActivityTypes.VIEW>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has listened to the object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-listen
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Listen = TransitiveActivity<typeof ActivityTypes.LISTEN>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has read the object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-read
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Read = TransitiveActivity<typeof ActivityTypes.READ>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has moved object from origin to target. If the
|
||||
* > origin or target are not specified, either can be determined by context.
|
||||
* > The origin SHOULD NOT be used to express hierarchical or containment
|
||||
* > relationships. For example, when moving an object from one folder to
|
||||
* > another, leave origin out (instead of making the origin the containing
|
||||
* > folder).
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-move
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Move = TransitiveActivity<typeof ActivityTypes.MOVE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is traveling to target from origin. Travel is an
|
||||
* > IntransitiveObject whose actor specifies the direct object. If the target
|
||||
* > or origin are not specified, either can be determined by context. Travel
|
||||
* > indicates that the actor is moving to the target from the origin. The
|
||||
* > duration and distance properties can be used to indicate the time or
|
||||
* > distance of the travel, but they are not necessary. If a matching
|
||||
* > IntransitiveActivity object exists, then the Travel object is considered an
|
||||
* > alternate view of the same activity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-travel
|
||||
*
|
||||
* @type IntransitiveActivity
|
||||
*/
|
||||
export type Travel = IntransitiveActivity<typeof ActivityTypes.TRAVEL>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor has announced an object to the target. The
|
||||
* > origin typically has no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Announce = TransitiveActivity<typeof ActivityTypes.ANNOUNCE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is blocking the object. Blocking is a stronger
|
||||
* > form of Ignore. The typical use is to support social systems that allow
|
||||
* > one user to block activities or content of other users. The target and
|
||||
* > origin typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-block
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Block = TransitiveActivity<typeof ActivityTypes.BLOCK>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor is "flagging" the object. Flagging is defined in
|
||||
* > the sense common to many social platforms as reporting content as being
|
||||
* > inappropriate for any number of reasons.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-flag
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Flag = TransitiveActivity<typeof ActivityTypes.FLAG>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > Indicates that the actor dislikes the object. The target and origin
|
||||
* > typically have no defined meaning.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-dislike
|
||||
*
|
||||
* @type TransitiveActivity
|
||||
*/
|
||||
export type Dislike = TransitiveActivity<typeof ActivityTypes.DISLIKE>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > A Question is an IntransitiveActivity that indicates that the actor is
|
||||
* > asking the target a question. Question objects are an extension of
|
||||
* > IntransitiveActivity. That is, the Question object is an Activity, but the
|
||||
* > direct object is the question itself and therefore it would not 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.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-question
|
||||
*
|
||||
* @type IntransitiveActivity
|
||||
*/
|
||||
export type Question = IntransitiveActivity<typeof ActivityTypes.QUESTION> & {
|
||||
oneOf: OrArray<EntityReference>;
|
||||
anyOf: OrArray<EntityReference>;
|
||||
closed: EntityReference | Date | boolean;
|
||||
};
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > An Activity is a subtype of Object that describes some form of action that
|
||||
* > may happen, is currently happening, or has already happened. The Activity
|
||||
* > type itself serves as an abstract base type for all types of activities.
|
||||
* > It is important to note that the Activity type itself does not carry any
|
||||
* > specific semantics about the kind of action being taken.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#activities
|
||||
*
|
||||
* @extends CoreObject
|
||||
*
|
||||
* @instance Accept
|
||||
* @instance TentativeAccept
|
||||
* @instance Add
|
||||
* @instance Arrive
|
||||
* @instance Create
|
||||
* @instance Delete
|
||||
* @instance Follow
|
||||
* @instance Ignore
|
||||
* @instance Join
|
||||
* @instance Leave
|
||||
* @instance Like
|
||||
* @instance Offer
|
||||
* @instance Invite
|
||||
* @instance Reject
|
||||
* @instance TentativeReject
|
||||
* @instance Remove
|
||||
* @instance Undo
|
||||
* @instance Update
|
||||
* @instance View
|
||||
* @instance Listen
|
||||
* @instance Read
|
||||
* @instance Move
|
||||
* @instance Travel
|
||||
* @instance Announce
|
||||
* @instance Block
|
||||
* @instance Flag
|
||||
* @instance Dislike
|
||||
* @instance Question
|
||||
*/
|
||||
export type Activity = Accept | Follow | Delete | Create | Arrive | Add | Offer | Like | Leave | Ignore | Join | Reject | Invite | TentativeReject | TentativeAccept | View | Update | Undo | Remove | Read | Listen | Move | Travel | Announce | Block | Flag | Dislike | Question;
|
||||
/**
|
||||
* Either an Activity or a URL reference to an Activity.
|
||||
*/
|
||||
export type ActivityReference = URL | Activity;
|
||||
export {};
|
||||
|
|
|
@ -4,7 +4,19 @@ import { CoreObjectProperties } from '../Core/CoreObject';
|
|||
import { ActorTypes } from '../util/const';
|
||||
import { CollectionReference, EitherCollectionReference, OrderedCollectionReference } from './Collection';
|
||||
import { StringReferenceMap } from '../util';
|
||||
/**
|
||||
* A union of all Actor types.
|
||||
*/
|
||||
export type AnyActorType = (typeof ActorTypes)[keyof typeof ActorTypes];
|
||||
/**
|
||||
* Properties common to all Actor types.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#actors
|
||||
*
|
||||
* @note The `manuallyApprovesFollowers` property is not included in the spec,
|
||||
* but it is included because it is common to all ActivityPub objects in
|
||||
* practice by way of an extension to the spec.
|
||||
*/
|
||||
export type ActorProperties = {
|
||||
inbox: OrderedCollectionReference;
|
||||
outbox: OrderedCollectionReference;
|
||||
|
@ -30,12 +42,76 @@ export type ActorProperties = {
|
|||
};
|
||||
manuallyApprovesFollowers?: boolean;
|
||||
};
|
||||
/**
|
||||
* The base type for all Actor entities.
|
||||
*
|
||||
* @extends BaseEntity
|
||||
*
|
||||
* @instance Application
|
||||
* @instance Group
|
||||
* @instance Organization
|
||||
* @instance Person
|
||||
* @instance Service
|
||||
*/
|
||||
type BaseActor<T extends AnyActorType> = BaseEntity<T> & CoreObjectProperties & ActorProperties;
|
||||
/**
|
||||
* Per the ActivitySteams spec:
|
||||
*
|
||||
* > Describes a software application.
|
||||
*
|
||||
* @type Actor
|
||||
*/
|
||||
export type Application = BaseActor<typeof ActorTypes.APPLICATION>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents an individual person.
|
||||
*
|
||||
* @type Actor
|
||||
*/
|
||||
export type Person = BaseActor<typeof ActorTypes.PERSON>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents a formal or informal collective of Actors.
|
||||
*
|
||||
* @type Actor
|
||||
*/
|
||||
export type Group = BaseActor<typeof ActorTypes.GROUP>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents a service of any kind.
|
||||
*
|
||||
* @type Actor
|
||||
*/
|
||||
export type Service = BaseActor<typeof ActorTypes.SERVICE>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents an organization.
|
||||
*
|
||||
* @type Actor
|
||||
*/
|
||||
export type Organization = BaseActor<typeof ActorTypes.ORGANIZATION>;
|
||||
/**
|
||||
* Per the ActivityStreams Vocabulary spec:
|
||||
*
|
||||
* > An Entity that either performed or is expected to perform an Activity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-actor
|
||||
*
|
||||
* @extends CoreObject
|
||||
*
|
||||
* @instance Application
|
||||
* @instance Group
|
||||
* @instance Organization
|
||||
* @instance Person
|
||||
* @instance Service
|
||||
*/
|
||||
export type Actor = Application | Service | Group | Organization | Person;
|
||||
/**
|
||||
* Either an Actor or a URL reference to an Actor.
|
||||
*/
|
||||
export type ActorReference = URL | Actor;
|
||||
export {};
|
||||
|
|
|
@ -4,9 +4,17 @@ import { CoreObjectProperties } from '../Core/CoreObject';
|
|||
import { EntityReference } from '../Core';
|
||||
import { Link } from '../Core/Link';
|
||||
import { BaseEntity } from '../Core/Entity';
|
||||
/** A union of all Collection types. */
|
||||
export type AnyCollectionType = (typeof CollectionTypes)[keyof typeof CollectionTypes];
|
||||
/** A union of all CollectionPage types. */
|
||||
export type AnyCollectionPageType = (typeof CollectionPageTypes)[keyof typeof CollectionPageTypes];
|
||||
/**
|
||||
* A union of all Collection and CollectionPage types.
|
||||
*/
|
||||
export type AnyCollectionOrCollectionPageType = AnyCollectionType | AnyCollectionPageType;
|
||||
/**
|
||||
* Properties common to all Collection types.
|
||||
*/
|
||||
type CollectionProperties = {
|
||||
totalItems?: number;
|
||||
items?: OrArray<EntityReference>;
|
||||
|
@ -16,25 +24,164 @@ type CollectionProperties = {
|
|||
first?: URL | CollectionPage | Link;
|
||||
last?: URL | CollectionPage | Link;
|
||||
};
|
||||
/**
|
||||
* The base type for all Collection and CollectionPage entities.
|
||||
*
|
||||
* Per the ActivityPub spec:
|
||||
*
|
||||
* > A Collection is a subtype of Object that represents ordered or unordered
|
||||
* > sets of Object or Link instances.
|
||||
*
|
||||
* Per the Activity Streams 2.0 Core spec:
|
||||
*
|
||||
* > Collection objects are a specialization of the base Object that serve as a
|
||||
* > container for other Objects or Links.
|
||||
*
|
||||
* @extends BaseEntity
|
||||
* @extends CoreObjectProperties
|
||||
* @extends CollectionProperties
|
||||
*
|
||||
* @instance Collection
|
||||
* @instance OrderedCollection
|
||||
* @instance CollectionPage
|
||||
* @instance OrderedCollectionPage
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#collection
|
||||
*/
|
||||
export type BaseCollection<T extends AnyCollectionOrCollectionPageType> = BaseEntity<T> & CoreObjectProperties & CollectionProperties;
|
||||
/**
|
||||
* This type indicates a Collection object with a type of `Collection`.
|
||||
*
|
||||
* @note Although use of "orderedItems" with "Collection" is not prohibited by
|
||||
* the spec, it is not recommended. Use "OrderedCollection" instead.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collection
|
||||
*
|
||||
* @type Collection
|
||||
*/
|
||||
export type Collection = BaseCollection<typeof CollectionTypes.COLLECTION>;
|
||||
/**
|
||||
* This type indicates a Collection object with a type of `OrderedCollection`.
|
||||
*
|
||||
* @note Although use of "items" with "OrderedCollection" is not prohibited by
|
||||
* the spec, it is not recommended. Use "Collection" instead.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-orderedcollection
|
||||
*
|
||||
* @extends Collection
|
||||
*/
|
||||
export type OrderedCollection = BaseCollection<typeof CollectionTypes.ORDERED_COLLECTION>;
|
||||
/**
|
||||
* Properties common to all CollectionPage types.
|
||||
*/
|
||||
type CollectionPageProperties = {
|
||||
partOf?: URL | EitherCollection | Link;
|
||||
next?: URL | CollectionPage | Link;
|
||||
prev?: URL | CollectionPage | Link;
|
||||
};
|
||||
/**
|
||||
* The base type for all CollectionPage entities.
|
||||
*
|
||||
* @extends Collection
|
||||
*
|
||||
* @instance CollectionPage
|
||||
* @instance OrderedCollectionPage
|
||||
*/
|
||||
type BaseCollectionPage<T extends AnyCollectionPageType> = BaseCollection<T> & CollectionPageProperties;
|
||||
/**
|
||||
* This type indicates a CollectionPage object with a type of `CollectionPage`.
|
||||
*
|
||||
* Per the ActivityStreams 2.0 Core spec:
|
||||
*
|
||||
* > A CollectionPage is a subtype of Collection that represents a subset of
|
||||
* > items from another Collection. CollectionPage instances are typically
|
||||
* > used to represent the items on a single page of a multi-page
|
||||
* > Collection. They typically have a shorter lifespan than the Collection
|
||||
* > instances that contain them. While a Collection indicates the entire
|
||||
* > set of items a CollectionPage MAY be used to represent a subset of
|
||||
* > those items. For example, an Activity MAY be associated with a
|
||||
* > Collection of likes. The Collection might represent all of the likes
|
||||
* > that the activity has received. A CollectionPage with a `partOf`
|
||||
* > property of the Activity MAY be used to represent a subset of those
|
||||
* > likes from a single page.
|
||||
*
|
||||
* @extends Collection
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#collectionpage
|
||||
* @see https://www.w3.org/TR/activitypub/#collectionpage
|
||||
*/
|
||||
export type CollectionPage = BaseCollectionPage<typeof CollectionPageTypes.COLLECTION_PAGE>;
|
||||
/**
|
||||
* This type indicates a CollectionPage object with a type of
|
||||
* `OrderedCollectionPage`.
|
||||
*
|
||||
* Per the ActivityPub spec:
|
||||
*
|
||||
* > Used to represent ordered subsets of items from an OrderedCollection.
|
||||
*
|
||||
* This is typically used to represent pages of items in a collection that
|
||||
* maintain a specific order.
|
||||
*
|
||||
* @extends CollectionPage
|
||||
*
|
||||
* @see CollectionPage
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-orderedcollectionpage
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#orderedcollectionpage
|
||||
* @see https://www.w3.org/TR/activitypub/#orderedcollectionpage
|
||||
*/
|
||||
export type OrderedCollectionPage = BaseCollectionPage<typeof CollectionPageTypes.ORDERED_COLLECTION_PAGE>;
|
||||
/**
|
||||
* A reference to a Collection object or a URL reference to a Collection object.
|
||||
*/
|
||||
export type CollectionReference = URL | Collection;
|
||||
/**
|
||||
* A reference to an OrderedCollection object or a URL reference to an
|
||||
* OrderedCollection object.
|
||||
*/
|
||||
export type OrderedCollectionReference = URL | OrderedCollection;
|
||||
/**
|
||||
* A reference to a CollectionPage object or a URL reference to a CollectionPage
|
||||
* object.
|
||||
*/
|
||||
export type CollectionPageReference = URL | CollectionPage;
|
||||
/**
|
||||
* A reference to an OrderedCollectionPage object or a URL reference to an
|
||||
* OrderedCollectionPage object.
|
||||
*/
|
||||
export type OrderedCollectionPageReference = URL | OrderedCollectionPage;
|
||||
/**
|
||||
* Either a Collection or OrderedCollection object.
|
||||
*/
|
||||
export type EitherCollection = Collection | OrderedCollection;
|
||||
/**
|
||||
* Either a CollectionPage or OrderedCollectionPage object or a URL reference to
|
||||
* a CollectionPage or OrderedCollectionPage object.
|
||||
*/
|
||||
export type EitherCollectionPage = CollectionPage | OrderedCollectionPage;
|
||||
/**
|
||||
* A reference to a Collection or OrderedCollection object or a URL reference to
|
||||
* a Collection or OrderedCollection object.
|
||||
*/
|
||||
export type EitherCollectionReference = URL | EitherCollection;
|
||||
/**
|
||||
* A reference to a CollectionPage or OrderedCollectionPage object or a URL
|
||||
* reference to a CollectionPage or OrderedCollectionPage object.
|
||||
*/
|
||||
export type EitherCollectionPageReference = URL | EitherCollectionPage;
|
||||
/**
|
||||
* Any among a Collection, OrderedCollection, CollectionPage, or
|
||||
* OrderedCollectionPage object.
|
||||
*
|
||||
* @note This is useful for functions that accept any type that descends
|
||||
* from BaseCollection.
|
||||
*/
|
||||
export type AnyCollectionOrCollectionPage = EitherCollection | EitherCollectionPage;
|
||||
/**
|
||||
* Any among a Collection, OrderedCollection, CollectionPage, or
|
||||
* OrderedCollectionPage object or a URL reference to a Collection,
|
||||
* OrderedCollection, CollectionPage, or OrderedCollectionPage object.
|
||||
*/
|
||||
export type AnyCollectionOrCollectionPageReference = URL | AnyCollectionOrCollectionPage;
|
||||
export {};
|
||||
|
|
|
@ -3,21 +3,131 @@ import { ExtendedObjectTypes, OrArray, AnyType, TypeOrArrayWithType } from '../u
|
|||
import { CoreObjectProperties } from '../Core/CoreObject';
|
||||
import { EntityReference, CoreObjectReference } from '../Core';
|
||||
import { BaseEntity } from '../Core/Entity';
|
||||
/**
|
||||
* A union of all Extended Object types.
|
||||
*/
|
||||
export type AnyExtendedObjectType = (typeof ExtendedObjectTypes)[keyof typeof ExtendedObjectTypes];
|
||||
/**
|
||||
* The base type for all Extended Object entities.
|
||||
*
|
||||
* @extends BaseEntity
|
||||
* @extends CoreObjectProperties
|
||||
*
|
||||
* @instance Article
|
||||
* @instance Event
|
||||
* @instance Note
|
||||
* @instance Page
|
||||
* @instance Place
|
||||
* @instance Relationship
|
||||
* @instance Tombstone
|
||||
* @instance Profile
|
||||
* @instance Video
|
||||
* @instance Document
|
||||
* @instance Audio
|
||||
* @instance Image
|
||||
* @instance Hashtag
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#extended-types
|
||||
*/
|
||||
export type BaseExtendedObject<T extends AnyExtendedObjectType> = BaseEntity<T> & CoreObjectProperties;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > A Tombstone is a special kind of Object that represents a content object
|
||||
* > that has been deleted. It can be used in Collections to signify that there
|
||||
* > used to be an object at this position, but it has been deleted.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-tombstone
|
||||
*/
|
||||
export type Tombstone = BaseExtendedObject<typeof ExtendedObjectTypes.TOMBSTONE> & {
|
||||
formerType?: TypeOrArrayWithType<AnyType>;
|
||||
deleted?: Date;
|
||||
};
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > A Relationship is an indirect Entity that describes a relationship between
|
||||
* > two individuals. The subject and object properties are used to identify the
|
||||
* > connected individuals.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-relationship
|
||||
*/
|
||||
export type Relationship = BaseExtendedObject<typeof ExtendedObjectTypes.RELATIONSHIP> & {
|
||||
subject?: EntityReference;
|
||||
object?: OrArray<EntityReference>;
|
||||
relationship?: CoreObjectReference;
|
||||
};
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > A Profile is a content object that describes another Object, typically used
|
||||
* > to describe Actor Type objects. The describes property is used to reference
|
||||
* > the object being described by the profile.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-profile
|
||||
*/
|
||||
export type Article = BaseExtendedObject<typeof ExtendedObjectTypes.ARTICLE>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents a short written work typically less than a single paragraph in
|
||||
* > length.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note
|
||||
*/
|
||||
export type Note = BaseExtendedObject<typeof ExtendedObjectTypes.NOTE>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents a Web Page.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @note Technically this extends Document, but Document has no special
|
||||
* properties.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-page
|
||||
*/
|
||||
export type Page = BaseExtendedObject<typeof ExtendedObjectTypes.PAGE>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents any kind of event.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||
*/
|
||||
export type Event = BaseExtendedObject<typeof ExtendedObjectTypes.EVENT>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents a logical or physical location.
|
||||
*
|
||||
* Additionally, per the spec:
|
||||
*
|
||||
* > The Place object is used to represent both physical and logical locations.
|
||||
* > While numerous existing vocabularies exist for describing locations in a
|
||||
* > variety of ways, inconsistencies and incompatibilities between those
|
||||
* > vocabularies make it difficult to achieve appropriate interoperability
|
||||
* > between implementations. The Place object is included within the Activity
|
||||
* > vocabulary to provide a minimal, interoperable starting point for
|
||||
* > describing locations consistently across Activity Streams 2.0
|
||||
* > implementations.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-place
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#places
|
||||
*/
|
||||
export type Place = BaseExtendedObject<typeof ExtendedObjectTypes.PLACE> & {
|
||||
accuracy?: number;
|
||||
altitude?: number;
|
||||
|
@ -26,14 +136,98 @@ export type Place = BaseExtendedObject<typeof ExtendedObjectTypes.PLACE> & {
|
|||
radius?: number;
|
||||
units?: string;
|
||||
};
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > A Document is a content object that represents another resource, typically
|
||||
* > used to describe things that are capable of being embedded or attached to
|
||||
* > other content.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @note Technically several other types extend Document, but Document has no
|
||||
* special properties. The types include: Image, Audio, Video, and Profile.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-document
|
||||
*/
|
||||
export type Document = BaseExtendedObject<typeof ExtendedObjectTypes.DOCUMENT>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > An image document of any kind.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @note Technically this extends Document, but Document has no special
|
||||
* properties.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image
|
||||
*/
|
||||
export type Image = BaseExtendedObject<typeof ExtendedObjectTypes.IMAGE>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents an audio document of any kind.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @note Technically this extends Document, but Document has no special
|
||||
* properties.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-audio
|
||||
*/
|
||||
export type Audio = BaseExtendedObject<typeof ExtendedObjectTypes.AUDIO>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > Represents a video document of any kind.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @note Technically this extends Document, but Document has no special
|
||||
* properties.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-video
|
||||
*/
|
||||
export type Video = BaseExtendedObject<typeof ExtendedObjectTypes.VIDEO>;
|
||||
/**
|
||||
* Per the ActivityStreams spec:
|
||||
*
|
||||
* > A Profile is a content object that describes another Object, typically used
|
||||
* > to describe Actor Type objects. The describes property is used to reference
|
||||
* > the object being described by the profile.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-profile
|
||||
*/
|
||||
export type Profile = BaseExtendedObject<typeof ExtendedObjectTypes.PROFILE> & {
|
||||
describes?: CoreObjectReference;
|
||||
};
|
||||
/**
|
||||
* A Hashtag.
|
||||
*
|
||||
* @type ExtendedObject
|
||||
*
|
||||
* @note This is not part of the ActivityPub spec, but it is common in practice
|
||||
* by way of extensions to the spec.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-hashtag
|
||||
*/
|
||||
export type Hashtag = BaseExtendedObject<typeof ExtendedObjectTypes.HASHTAG>;
|
||||
/**
|
||||
* A union of all Extended Object types.
|
||||
*
|
||||
* @extends CoreObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#extendedtypes
|
||||
*/
|
||||
export type ExtendedObject = Article | Event | Note | Page | Place | Relationship | Tombstone | Profile | Video | Document | Audio | Image | Hashtag;
|
||||
/**
|
||||
* An Extended Object or a URL reference to an Extended Object.
|
||||
*/
|
||||
export type ExtendedObjectReference = URL | ExtendedObject;
|
||||
/**
|
||||
* An Image or a URL reference to an Image.
|
||||
*/
|
||||
export type ImageReference = URL | Image;
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
/**
|
||||
* An object containing all the types of ExtendedObjects.
|
||||
*
|
||||
* @see ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#extendedtypes
|
||||
*/
|
||||
export declare const ExtendedObjectTypes: {
|
||||
readonly ARTICLE: "Article";
|
||||
readonly AUDIO: "Audio";
|
||||
|
@ -13,10 +20,24 @@ export declare const ExtendedObjectTypes: {
|
|||
readonly VIDEO: "Video";
|
||||
readonly HASHTAG: "Hashtag";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Links.
|
||||
*
|
||||
* @see Link
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#links
|
||||
*/
|
||||
export declare const LinkTypes: {
|
||||
readonly LINK: "Link";
|
||||
readonly MENTION: "Mention";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Actors.
|
||||
*
|
||||
* @see Actor
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#actors
|
||||
*/
|
||||
export declare const ActorTypes: {
|
||||
readonly APPLICATION: "Application";
|
||||
readonly GROUP: "Group";
|
||||
|
@ -24,6 +45,13 @@ export declare const ActorTypes: {
|
|||
readonly PERSON: "Person";
|
||||
readonly SERVICE: "Service";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Transitive Activities.
|
||||
*
|
||||
* @see TransitiveActivity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#transitive-activity-types
|
||||
*/
|
||||
export declare const TransitiveActivityTypes: {
|
||||
readonly ACCEPT: "Accept";
|
||||
readonly ADD: "Add";
|
||||
|
@ -51,11 +79,25 @@ export declare const TransitiveActivityTypes: {
|
|||
readonly UPDATE: "Update";
|
||||
readonly VIEW: "View";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Intransitive Activities.
|
||||
*
|
||||
* @see IntransitiveActivity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#intransitive-activity-types
|
||||
*/
|
||||
export declare const IntransitiveActivityTypes: {
|
||||
readonly ARRIVE: "Arrive";
|
||||
readonly TRAVEL: "Travel";
|
||||
readonly QUESTION: "Question";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Activities.
|
||||
*
|
||||
* @see Activity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
||||
*/
|
||||
export declare const ActivityTypes: {
|
||||
readonly ARRIVE: "Arrive";
|
||||
readonly TRAVEL: "Travel";
|
||||
|
@ -86,14 +128,35 @@ export declare const ActivityTypes: {
|
|||
readonly UPDATE: "Update";
|
||||
readonly VIEW: "View";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Collections.
|
||||
*
|
||||
* @see Collection
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collection
|
||||
*/
|
||||
export declare const CollectionTypes: {
|
||||
readonly COLLECTION: "Collection";
|
||||
readonly ORDERED_COLLECTION: "OrderedCollection";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of CollectionPages.
|
||||
*
|
||||
* @see CollectionPage
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage
|
||||
*/
|
||||
export declare const CollectionPageTypes: {
|
||||
readonly COLLECTION_PAGE: "CollectionPage";
|
||||
readonly ORDERED_COLLECTION_PAGE: "OrderedCollectionPage";
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of CoreObjects.
|
||||
*
|
||||
* @see CoreObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*/
|
||||
export declare const CoreObjectTypes: {
|
||||
readonly COLLECTION_PAGE: "CollectionPage";
|
||||
readonly ORDERED_COLLECTION_PAGE: "OrderedCollectionPage";
|
||||
|
@ -146,6 +209,19 @@ export declare const CoreObjectTypes: {
|
|||
readonly VIDEO: "Video";
|
||||
readonly HASHTAG: "Hashtag";
|
||||
};
|
||||
/**
|
||||
* All the types of Entities.
|
||||
*
|
||||
* @see Entity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object
|
||||
* @see https://www.w3.org/TR/activitypub/#object
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link
|
||||
* @see https://www.w3.org/TR/activitypub/#link
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#link
|
||||
*/
|
||||
export declare const AllTypes: {
|
||||
readonly LINK: "Link";
|
||||
readonly MENTION: "Mention";
|
||||
|
@ -200,5 +276,34 @@ export declare const AllTypes: {
|
|||
readonly VIDEO: "Video";
|
||||
readonly HASHTAG: "Hashtag";
|
||||
};
|
||||
/**
|
||||
* A union of all Entity types.
|
||||
*/
|
||||
export type AnyType = (typeof AllTypes)[keyof typeof AllTypes];
|
||||
/**
|
||||
* A type alias representing the provided ActivityPub type or an array of
|
||||
* ActivityPub types which includes the provided type.
|
||||
*
|
||||
* @param T The type to be used. The type must be a valid ActivityPub type.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // A single type.
|
||||
* const a: TypeOrArrayWithType<'Article'> = 'Article';
|
||||
*
|
||||
* // An array of types.
|
||||
* const b: TypeOrArrayWithType<'Article'> = ['Article', 'Note'];
|
||||
* ```
|
||||
*
|
||||
* @note This type is used to represent the `type` property of an ActivityPub
|
||||
* object. The `type` property can be a single type or an array of types.
|
||||
*
|
||||
* @note Having multiple types in the `type` property is permitted in JSON-LD,
|
||||
* however some ActivityPub implementations may not support it. For this reason,
|
||||
* it is recommended to only use a single type. Internally, the first type in
|
||||
* the array will be used as the primary type.
|
||||
*
|
||||
* @note Additional non-ActivityPub types may be included in the array, but
|
||||
* they will not be validated.
|
||||
*/
|
||||
export type TypeOrArrayWithType<T extends AnyType> = T | [T, ...Array<AnyType>];
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AllTypes = exports.CoreObjectTypes = exports.CollectionPageTypes = exports.CollectionTypes = exports.ActivityTypes = exports.IntransitiveActivityTypes = exports.TransitiveActivityTypes = exports.ActorTypes = exports.LinkTypes = exports.ExtendedObjectTypes = void 0;
|
||||
/**
|
||||
* An object containing all the types of ExtendedObjects.
|
||||
*
|
||||
* @see ExtendedObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#extendedtypes
|
||||
*/
|
||||
exports.ExtendedObjectTypes = {
|
||||
ARTICLE: 'Article',
|
||||
AUDIO: 'Audio',
|
||||
|
@ -14,12 +21,26 @@ exports.ExtendedObjectTypes = {
|
|||
RELATIONSHIP: 'Relationship',
|
||||
TOMBSTONE: 'Tombstone',
|
||||
VIDEO: 'Video',
|
||||
HASHTAG: 'Hashtag',
|
||||
HASHTAG: 'Hashtag', // Extension
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Links.
|
||||
*
|
||||
* @see Link
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#links
|
||||
*/
|
||||
exports.LinkTypes = {
|
||||
LINK: 'Link',
|
||||
MENTION: 'Mention',
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Actors.
|
||||
*
|
||||
* @see Actor
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#actors
|
||||
*/
|
||||
exports.ActorTypes = {
|
||||
APPLICATION: 'Application',
|
||||
GROUP: 'Group',
|
||||
|
@ -27,6 +48,13 @@ exports.ActorTypes = {
|
|||
PERSON: 'Person',
|
||||
SERVICE: 'Service',
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Transitive Activities.
|
||||
*
|
||||
* @see TransitiveActivity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#transitive-activity-types
|
||||
*/
|
||||
exports.TransitiveActivityTypes = {
|
||||
ACCEPT: 'Accept',
|
||||
ADD: 'Add',
|
||||
|
@ -54,23 +82,58 @@ exports.TransitiveActivityTypes = {
|
|||
UPDATE: 'Update',
|
||||
VIEW: 'View',
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Intransitive Activities.
|
||||
*
|
||||
* @see IntransitiveActivity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#intransitive-activity-types
|
||||
*/
|
||||
exports.IntransitiveActivityTypes = {
|
||||
ARRIVE: 'Arrive',
|
||||
TRAVEL: 'Travel',
|
||||
QUESTION: 'Question',
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Activities.
|
||||
*
|
||||
* @see Activity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
|
||||
*/
|
||||
exports.ActivityTypes = {
|
||||
...exports.TransitiveActivityTypes,
|
||||
...exports.IntransitiveActivityTypes,
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of Collections.
|
||||
*
|
||||
* @see Collection
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collection
|
||||
*/
|
||||
exports.CollectionTypes = {
|
||||
COLLECTION: 'Collection',
|
||||
ORDERED_COLLECTION: 'OrderedCollection',
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of CollectionPages.
|
||||
*
|
||||
* @see CollectionPage
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage
|
||||
*/
|
||||
exports.CollectionPageTypes = {
|
||||
COLLECTION_PAGE: 'CollectionPage',
|
||||
ORDERED_COLLECTION_PAGE: 'OrderedCollectionPage',
|
||||
};
|
||||
/**
|
||||
* An object containing all the types of CoreObjects.
|
||||
*
|
||||
* @see CoreObject
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*/
|
||||
exports.CoreObjectTypes = {
|
||||
...exports.ExtendedObjectTypes,
|
||||
...exports.ActorTypes,
|
||||
|
@ -78,6 +141,19 @@ exports.CoreObjectTypes = {
|
|||
...exports.CollectionTypes,
|
||||
...exports.CollectionPageTypes,
|
||||
};
|
||||
/**
|
||||
* All the types of Entities.
|
||||
*
|
||||
* @see Entity
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object
|
||||
* @see https://www.w3.org/TR/activitypub/#object
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link
|
||||
* @see https://www.w3.org/TR/activitypub/#link
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#link
|
||||
*/
|
||||
exports.AllTypes = {
|
||||
...exports.CoreObjectTypes,
|
||||
...exports.LinkTypes,
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../src/util/const.ts"],"names":[],"mappings":";;;AAOa,QAAA,mBAAmB,GAAG;IACjC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,cAAc;IAC5B,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;CACV,CAAC;AASE,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;CACV,CAAC;AASE,QAAA,UAAU,GAAG;IACxB,WAAW,EAAE,aAAa;IAC1B,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,cAAc;IAC5B,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC;AASE,QAAA,uBAAuB,GAAG;IACrC,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,gBAAgB,EAAE,iBAAiB;IACnC,gBAAgB,EAAE,iBAAiB;IACnC,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AASE,QAAA,yBAAyB,GAAG;IACvC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;CACZ,CAAC;AASE,QAAA,aAAa,GAAG;IAC3B,GAAG,+BAAuB;IAC1B,GAAG,iCAAyB;CACpB,CAAC;AASE,QAAA,eAAe,GAAG;IAC7B,UAAU,EAAE,YAAY;IACxB,kBAAkB,EAAE,mBAAmB;CAC/B,CAAC;AASE,QAAA,mBAAmB,GAAG;IACjC,eAAe,EAAE,gBAAgB;IACjC,uBAAuB,EAAE,uBAAuB;CACxC,CAAC;AASE,QAAA,eAAe,GAAG;IAC7B,GAAG,2BAAmB;IACtB,GAAG,kBAAU;IACb,GAAG,qBAAa;IAChB,GAAG,uBAAe;IAClB,GAAG,2BAAmB;CACd,CAAC;AAeE,QAAA,QAAQ,GAAG;IACtB,GAAG,uBAAe;IAClB,GAAG,iBAAS;CACJ,CAAC"}
|
||||
{"version":3,"file":"const.js","sourceRoot":"","sources":["../../src/util/const.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACU,QAAA,mBAAmB,GAAG;IACjC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,cAAc;IAC5B,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS,EAAE,YAAY;CACxB,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;CACV,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,UAAU,GAAG;IACxB,WAAW,EAAE,aAAa;IAC1B,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,cAAc;IAC5B,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,uBAAuB,GAAG;IACrC,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,gBAAgB,EAAE,iBAAiB;IACnC,gBAAgB,EAAE,iBAAiB;IACnC,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,yBAAyB,GAAG;IACvC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,aAAa,GAAG;IAC3B,GAAG,+BAAuB;IAC1B,GAAG,iCAAyB;CACpB,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,eAAe,GAAG;IAC7B,UAAU,EAAE,YAAY;IACxB,kBAAkB,EAAE,mBAAmB;CAC/B,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,mBAAmB,GAAG;IACjC,eAAe,EAAE,gBAAgB;IACjC,uBAAuB,EAAE,uBAAuB;CACxC,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,eAAe,GAAG;IAC7B,GAAG,2BAAmB;IACtB,GAAG,kBAAU;IACb,GAAG,qBAAa;IAChB,GAAG,uBAAe;IAClB,GAAG,2BAAmB;CACd,CAAC;AAEX;;;;;;;;;;;;GAYG;AACU,QAAA,QAAQ,GAAG;IACtB,GAAG,uBAAe;IAClB,GAAG,iBAAS;CACJ,CAAC"}
|
|
@ -1,2 +1,22 @@
|
|||
/**
|
||||
* Shorthand for a plain object with string keys and string values.
|
||||
*/
|
||||
export type StringReferenceMap = Record<string, string>;
|
||||
/**
|
||||
* Shorthand for a value of a given type or array of values that all conform
|
||||
* to that type.
|
||||
*
|
||||
* This is useful internally to represent many ActivityPub properties.
|
||||
*
|
||||
* @param T The type of the value to be mapped.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // A string or array of strings.
|
||||
* type StringOrArrayOfStrings = OrArray<string>;
|
||||
*
|
||||
* const a: StringOrArrayOfStrings = 'foo';
|
||||
* const b: StringOrArrayOfStrings = ['foo', 'bar'];
|
||||
* ```
|
||||
*/
|
||||
export type OrArray<T> = T | T[];
|
||||
|
|
|
@ -7,18 +7,16 @@ export { CoreObjectProperties } from './CoreObject';
|
|||
export type { Link, LinkReference, Mention } from './Link';
|
||||
|
||||
/**
|
||||
* The base type for all ActivityPub Objects (including Extended Objects).
|
||||
* The base type for all ActivityPub Object Types, including Actors, Activities,
|
||||
* Collections, and Extended Objects.
|
||||
*
|
||||
* @note This type is named `CoreObject` instead of `Object` because of the
|
||||
* following concerns:
|
||||
* - All ActivityPub Objects are objects, but not all objects are
|
||||
* ActivityPub Objects. In particular, Links are not ActivityPub Objects.
|
||||
* - There are a set of Extended Objects that inherit from this type.
|
||||
* - `Object` is a reserved keyword in JavaScript.
|
||||
* @note This type is named `CoreObject` instead of `Object` to avoid collision
|
||||
* with the JavaScript `Object` type. Further, this avoids confusion with what
|
||||
* the spec refers to as "Objects", which are called "Entities" in this library.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-core/#object
|
||||
*
|
||||
* @extends BaseEntity
|
||||
* @extends Entity
|
||||
*
|
||||
* @instance ExtendedObject
|
||||
* @instance Actor
|
||||
|
@ -37,13 +35,16 @@ export type CoreObject =
|
|||
export type CoreObjectReference = URL | CoreObject;
|
||||
|
||||
/**
|
||||
* The base type for all ActivityPub Entities, including Object and Link types.
|
||||
* The base type for all ActivityPub objects, including Core Object and Link
|
||||
* types.
|
||||
*
|
||||
* @note The spec does not specify a base type, but this library does for
|
||||
* convenience and easier type checking.
|
||||
* convenience and easier type checking. Instead, the spec refers to all
|
||||
* ActivityPub documents as "Objects". This library uses the term "Entity" to
|
||||
* refer to all ActivityPub documents, including both Core Objects and Links.
|
||||
*
|
||||
* @note The spec allows the type to be optional, but it is required by this
|
||||
* library in order to differentiate between different types of Entities.
|
||||
* @note The spec allows the type property to be optional, but it is required by
|
||||
* this library in order to differentiate between different types of objects.
|
||||
*
|
||||
* @instance CoreObject
|
||||
* @instance Link
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2018",
|
||||
|
|
|
@ -1,27 +1,20 @@
|
|||
import * as AP from '@activity-kit/types';
|
||||
import { guard } from '@activity-kit/type-utilities';
|
||||
import { ACTIVITYSTREAMS_CONTEXT, W3ID_SECURITY_CONTEXT } from './globals';
|
||||
import { DEFAULT_CONTEXT_AS_URLS } from './globals';
|
||||
|
||||
/**
|
||||
* Applies the ActivityStreams context to an Entity.
|
||||
* Applies the ActivityStreams context to an Entity. If the Entity already has a
|
||||
* JSON-LD context, it will not be overwritten.
|
||||
*
|
||||
* This is useful when creating an Entity from scratch, as it ensures that the
|
||||
* Entity has the proper context.
|
||||
*
|
||||
* @returns The Entity with the context applied.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#the-context
|
||||
*/
|
||||
export function applyContext(entity: AP.Entity): AP.Entity {
|
||||
if (!entity['@context']) {
|
||||
if (guard.isApActor(entity)) {
|
||||
entity['@context'] = [
|
||||
new URL(ACTIVITYSTREAMS_CONTEXT),
|
||||
new URL(W3ID_SECURITY_CONTEXT),
|
||||
{
|
||||
'schema:PropertyValue': new URL('https://schema.org/PropertyValue'),
|
||||
'schema:value': new URL('https://schema.org/value'),
|
||||
'schema:name': new URL('https://schema.org/name'),
|
||||
},
|
||||
];
|
||||
} else {
|
||||
entity['@context'] = new URL(ACTIVITYSTREAMS_CONTEXT);
|
||||
}
|
||||
entity['@context'] = DEFAULT_CONTEXT_AS_URLS;
|
||||
}
|
||||
|
||||
return entity;
|
||||
|
|
|
@ -4,7 +4,17 @@ import * as AP from '@activity-kit/types';
|
|||
* Removes the private `bto` and `bcc` properties from Entities so they don't
|
||||
* leak out upon delivery.
|
||||
*
|
||||
* From the ActivityPub spec:
|
||||
*
|
||||
* > `bto` and `bcc` already must be removed for delivery, but servers are free
|
||||
* > to decide how to represent the object in their own storage systems.
|
||||
* > However, since bto and bcc are only intended to be known/seen by the
|
||||
* > original author of the object/activity, servers should omit these
|
||||
* > properties during display as well.
|
||||
*
|
||||
* @returns The Entity with the private properties removed.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#security-not-displaying-bto-bcc
|
||||
**/
|
||||
export function cleanProps(entity: AP.Entity): AP.Entity {
|
||||
const cleanedEntity = { ...entity };
|
||||
|
|
|
@ -4,6 +4,14 @@ import { cast, guard } from '@activity-kit/type-utilities';
|
|||
/**
|
||||
* Compresses an Entity by replacing all nested Entities with their URLs.
|
||||
*
|
||||
* This is useful for storing Entities in a database, as it removes the need to
|
||||
* store the entire Entity, or for sending Entities over the network, as it
|
||||
* reduces the size of the payload.
|
||||
*
|
||||
* @note This follows rules similar to JSON-LD compaction, but it does not
|
||||
* follow the JSON-LD spec exactly. For example, it does not use the `@context`
|
||||
* property to determine the full URL of a property.
|
||||
*
|
||||
* @returns The compressed Entity, or null if not an Entity.
|
||||
*/
|
||||
export function compressEntity(entity: AP.Entity): AP.Entity | null {
|
||||
|
|
|
@ -4,7 +4,13 @@ import { cast, guard } from '@activity-kit/type-utilities';
|
|||
/**
|
||||
* Converts an Entity to a plain JSON object.
|
||||
*
|
||||
* This is needed to store the Entity in a database or send it over the network,
|
||||
* as the Entity may contain URLs, Dates, and other non-JSON values.
|
||||
*
|
||||
* @returns The plain object.
|
||||
*
|
||||
* @todo The fallthrough case for objects relies on the `toString()` method.
|
||||
* This is not ideal, as it may not always produce the desired result.
|
||||
*/
|
||||
export function convertEntityToJson(
|
||||
object: AP.Entity,
|
||||
|
|
|
@ -2,20 +2,70 @@ import * as AP from '@activity-kit/types';
|
|||
import * as jsonld from 'jsonld';
|
||||
// See types/jsonldDocumentLoader.d.ts
|
||||
import getNodeDocumentLoader from 'jsonld/lib/documentLoaders/node';
|
||||
import { RemoteDocument } from 'jsonld/jsonld-spec';
|
||||
import { ACTIVITYSTREAMS_CONTEXT, CONTEXT_DEFINITIONS } from './globals';
|
||||
import { RemoteDocument, Context } from 'jsonld/jsonld-spec';
|
||||
import { CONTEXT_DEFINITIONS, DEFAULT_CONTEXT } from './globals';
|
||||
import { convertJsonToEntity } from './convertJsonToEntity';
|
||||
import { applyContext } from './applyContext';
|
||||
|
||||
/**
|
||||
* Converts a JSON object to an ActivityPub entity.
|
||||
* Converts a JSON-LD object to a compacted ActivityPub entity.
|
||||
*
|
||||
* First, the JSON-LD object is compacted using the ActivityStreams context.
|
||||
* Then, the compacted object is converted to an ActivityPub Entity. Finally,
|
||||
* an updated context is applied to the Entity.
|
||||
*
|
||||
* @note This does follow the rules of JSON-LD compaction, as it utilizes the
|
||||
* `jsonld` library to compact the JSON-LD object.
|
||||
*
|
||||
* @returns The ActivityPub entity.
|
||||
*
|
||||
* @see https://www.w3.org/TR/json-ld11/#compacted-document-form
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const jsonLd = {
|
||||
* '@context': {
|
||||
* "schema": 'https://schema.org/',
|
||||
* "as": "https://www.w3.org/ns/activitystreams",
|
||||
* },
|
||||
* '@id': 'https://example.com/note/1',
|
||||
* '@type': ['as:Note', 'schema:CreativeWork'],
|
||||
* 'schema:PropertyValue': {
|
||||
* 'schema:name': 'Location',
|
||||
* 'schema:value': 'Earth',
|
||||
* },
|
||||
* 'schema:name': 'My First Note',
|
||||
* 'ap:summary': 'My First Note',
|
||||
* };
|
||||
*
|
||||
* const entity = await convertJsonLdToEntity(jsonLd);
|
||||
*
|
||||
* console.log(entity);
|
||||
* // {
|
||||
* // '@context': [
|
||||
* // 'https://www.w3.org/ns/activitystreams',
|
||||
* // 'https://w3id.org/security/v1',
|
||||
* // {
|
||||
* // 'schema:PropertyValue': 'https://schema.org/PropertyValue',
|
||||
* // 'schema:value': 'https://schema.org/value',
|
||||
* // 'schema:name': 'https://schema.org/name',
|
||||
* // },
|
||||
* // ],
|
||||
* // type: 'Person',
|
||||
* // id: 'https://example.com/note/1',
|
||||
* // name: 'My First Note',
|
||||
* // summary: 'My First Note',
|
||||
* // 'schema:propertyValue': {
|
||||
* // 'schema:name': 'Location',
|
||||
* // 'schema:value': 'Earth',
|
||||
* // },
|
||||
* // }
|
||||
* ```
|
||||
*/
|
||||
export async function convertJsonLdToEntity(
|
||||
document: jsonld.JsonLdDocument,
|
||||
): Promise<AP.Entity | null> {
|
||||
const ctx = CONTEXT_DEFINITIONS[ACTIVITYSTREAMS_CONTEXT];
|
||||
const ctx = DEFAULT_CONTEXT;
|
||||
const result = await jsonld.compact(document, ctx, {
|
||||
documentLoader: customLoader,
|
||||
});
|
||||
|
|
|
@ -70,10 +70,6 @@ export const W3ID_SECURITY_CONTEXT = 'https://w3id.org/security/v1';
|
|||
/**
|
||||
* The JSON-LD context for the Schema.org vocabulary.
|
||||
*
|
||||
* Used to provide additional information about an Entity via its `@type`,
|
||||
* however some servers do not accept multiple types, so this is not used
|
||||
* by default.
|
||||
*
|
||||
* @see https://schema.org/
|
||||
*/
|
||||
export const SCHEMA_ORG_CONTEXT = 'https://schema.org/';
|
||||
|
@ -201,6 +197,19 @@ export const HTML_CONTENT_TYPE = 'text/html';
|
|||
*/
|
||||
export const USERNAME_REGEXP = /^[\w\d]{3,12}$/;
|
||||
|
||||
/**
|
||||
* The default JSON-LD context for ActivityPub Entities.
|
||||
*/
|
||||
export const DEFAULT_CONTEXT = {
|
||||
'@vocab': ACTIVITYSTREAMS_CONTEXT,
|
||||
sec: W3ID_SECURITY_CONTEXT,
|
||||
schema: SCHEMA_ORG_CONTEXT,
|
||||
};
|
||||
|
||||
export const DEFAULT_CONTEXT_AS_URLS = Object.fromEntries(
|
||||
Object.entries(DEFAULT_CONTEXT).map(([key, value]) => [key, new URL(value)]),
|
||||
);
|
||||
|
||||
/**
|
||||
* Express-style route parameters.
|
||||
*/
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"removeComments": false,
|
||||
"noLib": false,
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2018",
|
||||
|
|
Loading…
Reference in New Issue