diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /packages/models/src/activitypub/activity.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'packages/models/src/activitypub/activity.ts')
-rw-r--r-- | packages/models/src/activitypub/activity.ts | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/packages/models/src/activitypub/activity.ts b/packages/models/src/activitypub/activity.ts new file mode 100644 index 000000000..78a3ab33b --- /dev/null +++ b/packages/models/src/activitypub/activity.ts | |||
@@ -0,0 +1,135 @@ | |||
1 | import { ActivityPubActor } from './activitypub-actor.js' | ||
2 | import { ActivityPubSignature } from './activitypub-signature.js' | ||
3 | import { | ||
4 | ActivityFlagReasonObject, | ||
5 | ActivityObject, | ||
6 | APObjectId, | ||
7 | CacheFileObject, | ||
8 | PlaylistObject, | ||
9 | VideoCommentObject, | ||
10 | VideoObject, | ||
11 | WatchActionObject | ||
12 | } from './objects/index.js' | ||
13 | |||
14 | export type ActivityUpdateObject = | ||
15 | Extract<ActivityObject, VideoObject | CacheFileObject | PlaylistObject | ActivityPubActor | string> | ActivityPubActor | ||
16 | |||
17 | // Cannot Extract from Activity because of circular reference | ||
18 | export type ActivityUndoObject = | ||
19 | ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate<CacheFileObject | string> | ActivityAnnounce | ||
20 | |||
21 | export type ActivityCreateObject = | ||
22 | Extract<ActivityObject, VideoObject | CacheFileObject | WatchActionObject | VideoCommentObject | PlaylistObject | string> | ||
23 | |||
24 | export type Activity = | ||
25 | ActivityCreate<ActivityCreateObject> | | ||
26 | ActivityUpdate<ActivityUpdateObject> | | ||
27 | ActivityDelete | | ||
28 | ActivityFollow | | ||
29 | ActivityAccept | | ||
30 | ActivityAnnounce | | ||
31 | ActivityUndo<ActivityUndoObject> | | ||
32 | ActivityLike | | ||
33 | ActivityReject | | ||
34 | ActivityView | | ||
35 | ActivityDislike | | ||
36 | ActivityFlag | ||
37 | |||
38 | export type ActivityType = | ||
39 | 'Create' | | ||
40 | 'Update' | | ||
41 | 'Delete' | | ||
42 | 'Follow' | | ||
43 | 'Accept' | | ||
44 | 'Announce' | | ||
45 | 'Undo' | | ||
46 | 'Like' | | ||
47 | 'Reject' | | ||
48 | 'View' | | ||
49 | 'Dislike' | | ||
50 | 'Flag' | ||
51 | |||
52 | export interface ActivityAudience { | ||
53 | to: string[] | ||
54 | cc: string[] | ||
55 | } | ||
56 | |||
57 | export interface BaseActivity { | ||
58 | '@context'?: any[] | ||
59 | id: string | ||
60 | to?: string[] | ||
61 | cc?: string[] | ||
62 | actor: string | ActivityPubActor | ||
63 | type: ActivityType | ||
64 | signature?: ActivityPubSignature | ||
65 | } | ||
66 | |||
67 | export interface ActivityCreate <T extends ActivityCreateObject> extends BaseActivity { | ||
68 | type: 'Create' | ||
69 | object: T | ||
70 | } | ||
71 | |||
72 | export interface ActivityUpdate <T extends ActivityUpdateObject> extends BaseActivity { | ||
73 | type: 'Update' | ||
74 | object: T | ||
75 | } | ||
76 | |||
77 | export interface ActivityDelete extends BaseActivity { | ||
78 | type: 'Delete' | ||
79 | object: APObjectId | ||
80 | } | ||
81 | |||
82 | export interface ActivityFollow extends BaseActivity { | ||
83 | type: 'Follow' | ||
84 | object: string | ||
85 | } | ||
86 | |||
87 | export interface ActivityAccept extends BaseActivity { | ||
88 | type: 'Accept' | ||
89 | object: ActivityFollow | ||
90 | } | ||
91 | |||
92 | export interface ActivityReject extends BaseActivity { | ||
93 | type: 'Reject' | ||
94 | object: ActivityFollow | ||
95 | } | ||
96 | |||
97 | export interface ActivityAnnounce extends BaseActivity { | ||
98 | type: 'Announce' | ||
99 | object: APObjectId | ||
100 | } | ||
101 | |||
102 | export interface ActivityUndo <T extends ActivityUndoObject> extends BaseActivity { | ||
103 | type: 'Undo' | ||
104 | object: T | ||
105 | } | ||
106 | |||
107 | export interface ActivityLike extends BaseActivity { | ||
108 | type: 'Like' | ||
109 | object: APObjectId | ||
110 | } | ||
111 | |||
112 | export interface ActivityView extends BaseActivity { | ||
113 | type: 'View' | ||
114 | actor: string | ||
115 | object: APObjectId | ||
116 | |||
117 | // If sending a "viewer" event | ||
118 | expires?: string | ||
119 | } | ||
120 | |||
121 | export interface ActivityDislike extends BaseActivity { | ||
122 | id: string | ||
123 | type: 'Dislike' | ||
124 | actor: string | ||
125 | object: APObjectId | ||
126 | } | ||
127 | |||
128 | export interface ActivityFlag extends BaseActivity { | ||
129 | type: 'Flag' | ||
130 | content: string | ||
131 | object: APObjectId | APObjectId[] | ||
132 | tag?: ActivityFlagReasonObject[] | ||
133 | startAt?: number | ||
134 | endAt?: number | ||
135 | } | ||