aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/typings
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-09 08:17:16 +0200
committerChocobozzz <me@florianbigard.com>2019-08-09 08:17:16 +0200
commit5224c394b3bbac6ec1543e41fa0ec6db436e84fa (patch)
tree36eaecfe095547aca903a8a43fb6e0b0b01899a9 /server/typings
parent511765c9f86fb07d5d856decd9dbf0ec2092f4fe (diff)
downloadPeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.tar.gz
PeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.tar.zst
PeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.zip
Stronger actor association typing in AP functions
Diffstat (limited to 'server/typings')
-rw-r--r--server/typings/activitypub-processor.model.ts3
-rw-r--r--server/typings/express.ts3
-rw-r--r--server/typings/models/actor-follow.ts8
-rw-r--r--server/typings/models/actor.ts22
-rw-r--r--server/typings/models/index.d.ts1
-rw-r--r--server/typings/models/video-share.ts3
-rw-r--r--server/typings/utils.ts3
7 files changed, 41 insertions, 2 deletions
diff --git a/server/typings/activitypub-processor.model.ts b/server/typings/activitypub-processor.model.ts
index 7c70251ca..37b2859de 100644
--- a/server/typings/activitypub-processor.model.ts
+++ b/server/typings/activitypub-processor.model.ts
@@ -1,9 +1,10 @@
1import { Activity } from '../../shared/models/activitypub' 1import { Activity } from '../../shared/models/activitypub'
2import { ActorModel } from '../models/activitypub/actor' 2import { ActorModel } from '../models/activitypub/actor'
3import { SignatureActorModel } from './models'
3 4
4export type APProcessorOptions<T extends Activity> = { 5export type APProcessorOptions<T extends Activity> = {
5 activity: T 6 activity: T
6 byActor: ActorModel 7 byActor: SignatureActorModel
7 inboxActor?: ActorModel 8 inboxActor?: ActorModel
8 fromFetch?: boolean 9 fromFetch?: boolean
9} 10}
diff --git a/server/typings/express.ts b/server/typings/express.ts
index 3bffc1e9a..f7da55ab0 100644
--- a/server/typings/express.ts
+++ b/server/typings/express.ts
@@ -22,6 +22,7 @@ import { VideoCaptionModel } from '../models/video/video-caption'
22import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' 22import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
23import { RegisteredPlugin } from '../lib/plugins/plugin-manager' 23import { RegisteredPlugin } from '../lib/plugins/plugin-manager'
24import { PluginModel } from '../models/server/plugin' 24import { PluginModel } from '../models/server/plugin'
25import { SignatureActorModel } from './models'
25 26
26declare module 'express' { 27declare module 'express' {
27 28
@@ -75,7 +76,7 @@ declare module 'express' {
75 } 76 }
76 77
77 signature?: { 78 signature?: {
78 actor: ActorModel 79 actor: SignatureActorModel
79 } 80 }
80 81
81 authenticated?: boolean 82 authenticated?: boolean
diff --git a/server/typings/models/actor-follow.ts b/server/typings/models/actor-follow.ts
new file mode 100644
index 000000000..952ef877b
--- /dev/null
+++ b/server/typings/models/actor-follow.ts
@@ -0,0 +1,8 @@
1import { ActorFollowModel } from '../../models/activitypub/actor-follow'
2import { ActorModelOnly } from './actor'
3
4export type ActorFollowModelOnly = Omit<ActorFollowModel, 'ActorFollower' | 'ActorFollowing'>
5export type ActorFollowModelLight = ActorFollowModelOnly & {
6 ActorFollower: ActorModelOnly
7 ActorFollowing: ActorModelOnly
8}
diff --git a/server/typings/models/actor.ts b/server/typings/models/actor.ts
new file mode 100644
index 000000000..2656c7b66
--- /dev/null
+++ b/server/typings/models/actor.ts
@@ -0,0 +1,22 @@
1import { ActorModel } from '../../models/activitypub/actor'
2import { VideoChannelModel } from '../../models/video/video-channel'
3import { AccountModel } from '../../models/account/account'
4import { FunctionProperties } from '../utils'
5
6export type VideoChannelModelId = FunctionProperties<VideoChannelModel>
7export type AccountModelId = FunctionProperties<AccountModel> | Pick<AccountModel, 'id'>
8
9export type VideoChannelModelIdActor = VideoChannelModelId & Pick<VideoChannelModel, 'Actor'>
10export type AccountModelIdActor = AccountModelId & Pick<AccountModel, 'Actor'>
11
12export type ActorModelUrl = Pick<ActorModel, 'url'>
13export type ActorModelOnly = Omit<ActorModel, 'Account' | 'VideoChannel' | 'ActorFollowing' | 'Avatar' | 'ActorFollowers' | 'Server'>
14export type ActorModelId = Pick<ActorModelOnly, 'id'>
15
16export type SignatureActorModel = ActorModelOnly & {
17 VideoChannel: VideoChannelModelIdActor
18
19 Account: AccountModelIdActor
20}
21
22export type ActorFollowerException = Pick<ActorModel, 'sharedInboxUrl' | 'inboxUrl'>
diff --git a/server/typings/models/index.d.ts b/server/typings/models/index.d.ts
new file mode 100644
index 000000000..c90656965
--- /dev/null
+++ b/server/typings/models/index.d.ts
@@ -0,0 +1 @@
export * from './actor'
diff --git a/server/typings/models/video-share.ts b/server/typings/models/video-share.ts
new file mode 100644
index 000000000..1406749d2
--- /dev/null
+++ b/server/typings/models/video-share.ts
@@ -0,0 +1,3 @@
1import { VideoShareModel } from '../../models/video/video-share'
2
3export type VideoShareModelOnly = Omit<VideoShareModel, 'Actor' | 'Video'>
diff --git a/server/typings/utils.ts b/server/typings/utils.ts
new file mode 100644
index 000000000..a86b05be2
--- /dev/null
+++ b/server/typings/utils.ts
@@ -0,0 +1,3 @@
1export type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]
2
3export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>