Skip to content

Commit 73d32d9

Browse files
authored
Release 1.1.0 (#6)
* Make types required & update docs & refactor (#3) * Add types & docs for actors * Add type field to documents * Move APArticle to documents * Type for APArticle * Move APNote * Set type to APCollection(Page) * Refactor APOrderedCollection(Page) * Missed actor docs * Add types (simple activities) * Added docs to Activity * Rename ./common to ./objects * Object types * Fix APQuestion * Add APRoot and remove context field from object (#5) * docs & chore 1.1.0
1 parent fddc5cb commit 73d32d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+628
-174
lines changed

README.md

+62-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ActivityPub Types
2-
Extracted types and refactor from [activitypub-models](https://github.com/SiranWeb/activitypub-models) repo.
2+
TypeScript typings for ActivityPub
33

44
## Installation
55
```bash
@@ -8,20 +8,72 @@ npm i activitypub-types
88
yarn add activitypub-types
99
```
1010

11-
## Available types
11+
## How to use
1212
Implemented and documented every structure from [specification](https://www.w3.org/TR/activitystreams-vocabulary).
13-
You can use interfaces and extend them by yourself, or you can use specified fields types:
13+
You can use interfaces and extend them by yourself, or you can use specified fields types.
14+
15+
To specify object use correct type:
16+
```ts
17+
import { APAdd } from 'activitypub-types';
18+
const addActivity: APAdd = {
19+
type: 'Add',
20+
actor: 'https://actor.example.org',
21+
// ...
22+
}
23+
```
24+
Fields in types are pretty flexible, so you can pass different variations:
25+
```ts
26+
import { APAdd, APActor } from 'activitypub-types';
27+
28+
const actor1 = 'https://actor.example.org';
29+
30+
const actor2: APActor = {
31+
type: 'Person',
32+
id: 'https://actor2.example.org',
33+
summary: 'Another actor',
34+
inbox: 'https://actor2.example.org/inbox',
35+
outbox: 'https://actor2.example.org/outbox',
36+
};
37+
38+
const addActivity: APAdd = {
39+
type: 'Add',
40+
actor: [actor1, actor2],
41+
// ...
42+
};
43+
```
44+
45+
To provide `@context` field use `APRoot`:
1446
```typescript
15-
// All models interfaces starts with AP
16-
import { APObject, APNote, ContextField, ContentMapField } from 'activitypub-types';
47+
import { APAdd, APRoot } from 'activitypub-types';
48+
49+
const addActivity: APRoot<APAdd> = {
50+
'@context': 'https://www.w3.org/ns/activitystreams',
51+
type: 'Add',
52+
// ...
53+
}
54+
```
55+
56+
If you need field types themselves, you can import as well:
57+
```typescript
58+
import { TypeField, NameField } from 'activitypub-types';
59+
60+
interface APExample {
61+
type: TypeField;
62+
name?: NameField;
63+
// ...
64+
}
1765
```
1866

1967
## Changelog
20-
### v1.0.3
21-
- Use `orderedItems` instead of `items` in `OrderedCollection` ([#1](https://github.com/siranweb/activitypub-types/pull/1), thanks [@RangerMauve](https://github.com/RangerMauve))
68+
### v1.1.0
69+
- Update activities and documents types ([#3](https://github.com/siranweb/activitypub-types/pull/3), by [@Saiv46](https://github.com/Saiv46))
70+
- Add `APRoot` type and removed `@context` from `APObject` ([#5](https://github.com/siranweb/activitypub-types/pull/5))
71+
- Improve AP documentation ([#3](https://github.com/siranweb/activitypub-types/pull/3), by [@Saiv46](https://github.com/Saiv46))
72+
- Update README docs
73+
- Refactor ([#3](https://github.com/siranweb/activitypub-types/pull/3), by [@Saiv46](https://github.com/Saiv46))
2274

23-
## Contact
24-
You can contact me via [matrix](https://matrix.to/#/@siranweb:matrix.org) or [telegram](https://t.me/siranweb)
75+
### v1.0.3
76+
- Use `orderedItems` instead of `items` in `OrderedCollection` ([#1](https://github.com/siranweb/activitypub-types/pull/1), by [@RangerMauve](https://github.com/RangerMauve))
2577

2678
## License
27-
[MIT](LICENSE)
79+
[MIT](LICENSE)

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "activitypub-types",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "ActivityPub Typescript types",
55
"main": "./dist/index.js",
66
"scripts": {
@@ -23,8 +23,6 @@
2323
],
2424
"files": [
2525
"dist",
26-
"LICENSE",
27-
"README.md",
2826
"package.json",
2927
"package-lock.json"
3028
],

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './fields';
2-
export * from './model-interfaces';
2+
export * from './model-interfaces';
3+
export * from './utils';
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APAccept = APActivity
3+
/**
4+
* Indicates that the `actor` accepts the `object`.
5+
* The `target` property can be used in certain circumstances
6+
* to indicate the context into which the `object` has been accepted.
7+
*
8+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accept Docs}
9+
*/
10+
export interface APAccept extends APActivity {
11+
type: 'Accept';
12+
}

src/model-interfaces/activities/activity.interface.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { APObject } from '../common/object.interface';
1+
import { APObject } from '../objects/object.interface';
22
import {
33
ActorField,
44
InstrumentField,
@@ -8,6 +8,17 @@ import {
88
TargetField
99
} from '../../fields';
1010

11+
/**
12+
* An `Activity` is a subtype of [Object](../objects/object.interface.ts)
13+
* that describes some form of action that may happen,
14+
* is currently happening, or has already happened.
15+
* The `Activity` type itself serves as an abstract base
16+
* type for all types of activities.
17+
* It is important to note that the `Activity` type itself does not
18+
* carry any specific semantics about the kind of action being taken.
19+
*
20+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-activity Docs}
21+
*/
1122
export interface APActivity extends APObject {
1223

1324
/**
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APAdd = APActivity
3+
/**
4+
* Indicates that the `actor` has added the `object` to the `target`.
5+
* If the `target` property is not explicitly specified,
6+
* the target would need to be determined implicitly by context.
7+
* The origin can be used to identify the `context` from which the `object` originated.
8+
*
9+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-add Docs}
10+
*/
11+
export interface APAdd extends APActivity {
12+
type: 'Add';
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APAnnounce = APActivity
3+
/**
4+
* Indicates that the `actor` is calling the `target`'s attention the `object`.
5+
* The `origin` typically has no defined meaning.
6+
*
7+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce Docs}
8+
*/
9+
export interface APAnnounce extends APActivity {
10+
type: 'Announce';
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
import { APIntransitiveActivity } from './intransitive-activity.interface';
22

3-
export type APArrive = APIntransitiveActivity
3+
/**
4+
* An [IntransitiveActivity](https://www.w3.org/TR/activitystreams-vocabulary/#dfn-intransitiveactivity)
5+
* that indicates that the actor has arrived at the `location`.
6+
* The `origin` can be used to identify the `context` from which the actor originated.
7+
* The `target` typically has no defined meaning.
8+
*
9+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-arrive Docs}
10+
*/
11+
export interface APArrive extends APIntransitiveActivity {
12+
type: 'Arrive';
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
import { APIgnore } from './ignore.interface';
22

3-
export type APBlock = APIgnore
3+
/**
4+
* Indicates that the `actor` is blocking the `object`.
5+
* Blocking is a stronger form of [Ignore](./ignore.interface.ts).
6+
* The typical use is to support social systems that allow
7+
* one user to block activities or content of other users.
8+
* The `target` and `origin` typically have no defined meaning.
9+
*
10+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-block Docs}
11+
*/
12+
export interface APBlock extends Omit<APIgnore, 'type'> {
13+
type: 'Block';
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APCreate = APActivity
3+
/**
4+
* Indicates that the `actor` has created the `object`.
5+
*
6+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-create Docs}
7+
*/
8+
export interface APCreate extends APActivity {
9+
type: 'Create';
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APDelete = APActivity
3+
/**
4+
* Indicates that the `actor` has deleted the object.
5+
* If specified, the `origin` indicates the context
6+
* from which the object was deleted.
7+
*
8+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-delete Docs}
9+
*/
10+
export interface APDelete extends APActivity {
11+
type: 'Delete';
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APDislike = APActivity
3+
/**
4+
* Indicates that the `actor` dislikes the `object`.
5+
*
6+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-dislike Docs}
7+
*/
8+
export interface APDislike extends APActivity {
9+
type: 'Dislike';
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APFlag = APActivity
3+
/**
4+
* Indicates that the `actor` is "flagging" the `object`.
5+
* Flagging is defined in the sense common to many social platforms
6+
* as reporting content as being inappropriate for any number of reasons.
7+
*
8+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-flag Docs}
9+
*/
10+
export interface APFlag extends APActivity {
11+
type: 'Flag';
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APFollow = APActivity
3+
/**
4+
* Indicates that the `actor` is "following" the `object`.
5+
* Following is defined in the sense typically used within
6+
* Social systems in which the actor is interested in any
7+
* activity performed by or on the object.
8+
* The `target` and `origin` typically have no defined meaning.
9+
*
10+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-follow Docs}
11+
*/
12+
export interface APFollow extends APActivity {
13+
type: 'Follow';
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APIgnore = APActivity
3+
/**
4+
* Indicates that the `actor` is ignoring the `object`.
5+
* The `target` and `origin` typically have no defined meaning.
6+
*
7+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-ignore Docs}
8+
*/
9+
export interface APIgnore extends APActivity {
10+
type: 'Ignore';
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APIntransitiveActivity = Omit<APActivity, 'object'>
3+
/**
4+
* Instances of `IntransitiveActivity` are a subtype of `Activity` representing intransitive actions.
5+
* The `object` property is therefore inappropriate for these activities.
6+
*
7+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-intransitiveactivity Docs}
8+
*/
9+
export type APIntransitiveActivity = Omit<APActivity, 'object'>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
import { APOffer } from './offer.interface';
22

3-
export type APInvite = APOffer
3+
/**
4+
* A specialization of [Offer](./offer.interface.ts)
5+
* in which the `actor` is extending an invitation
6+
* for the `object` to the `target`.
7+
*
8+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-invite Docs}
9+
*/
10+
export interface APInvite extends Omit<APOffer, 'type'> {
11+
type: 'Invite';
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APJoin = APActivity
3+
/**
4+
* Indicates that the `actor` has joined the `object`.
5+
* The `target` and `origin` typically have no defined meaning.
6+
*
7+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-join Docs}
8+
*/
9+
export interface APJoin extends APActivity {
10+
type: 'Join';
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APLeave = APActivity
3+
/**
4+
* Indicates that the `actor` has left the `object`.
5+
* The `target` and `origin` typically have no meaning.
6+
*
7+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-leave Docs}
8+
*/
9+
export interface APLeave extends APActivity {
10+
type: 'Leave';
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APLike = APActivity
3+
/**
4+
* Indicates that the `actor` likes, recommends or endorses the `object`.
5+
* The `target` and `origin` typically have no defined meaning.
6+
*
7+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-like Docs}
8+
*/
9+
export interface APLike extends APActivity {
10+
type: 'Like';
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APListen = APActivity
3+
/**
4+
* Indicates that the `actor` has listened to the `object`.
5+
*
6+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-listen Docs}
7+
*/
8+
export interface APListen extends APActivity {
9+
type: 'Listen';
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
import { APActivity } from './activity.interface';
22

3-
export type APMove = APActivity
3+
/**
4+
* Indicates that the `actor` has moved `object` from `origin` to `target`.
5+
* If the `origin` or `target` are not specified, either can be determined by context.
6+
*
7+
* {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-move Docs}
8+
*/
9+
export interface APMove extends APActivity {
10+
type: 'Move';
11+
}

0 commit comments

Comments
 (0)