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 /server/models/user/user-notification-setting.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 'server/models/user/user-notification-setting.ts')
-rw-r--r-- | server/models/user/user-notification-setting.ts | 232 |
1 files changed, 0 insertions, 232 deletions
diff --git a/server/models/user/user-notification-setting.ts b/server/models/user/user-notification-setting.ts deleted file mode 100644 index 394494c0c..000000000 --- a/server/models/user/user-notification-setting.ts +++ /dev/null | |||
@@ -1,232 +0,0 @@ | |||
1 | import { | ||
2 | AfterDestroy, | ||
3 | AfterUpdate, | ||
4 | AllowNull, | ||
5 | BelongsTo, | ||
6 | Column, | ||
7 | CreatedAt, | ||
8 | Default, | ||
9 | ForeignKey, | ||
10 | Is, | ||
11 | Model, | ||
12 | Table, | ||
13 | UpdatedAt | ||
14 | } from 'sequelize-typescript' | ||
15 | import { TokensCache } from '@server/lib/auth/tokens-cache' | ||
16 | import { MNotificationSettingFormattable } from '@server/types/models' | ||
17 | import { AttributesOnly } from '@shared/typescript-utils' | ||
18 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' | ||
19 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | ||
20 | import { throwIfNotValid } from '../shared' | ||
21 | import { UserModel } from './user' | ||
22 | |||
23 | @Table({ | ||
24 | tableName: 'userNotificationSetting', | ||
25 | indexes: [ | ||
26 | { | ||
27 | fields: [ 'userId' ], | ||
28 | unique: true | ||
29 | } | ||
30 | ] | ||
31 | }) | ||
32 | export class UserNotificationSettingModel extends Model<Partial<AttributesOnly<UserNotificationSettingModel>>> { | ||
33 | |||
34 | @AllowNull(false) | ||
35 | @Default(null) | ||
36 | @Is( | ||
37 | 'UserNotificationSettingNewVideoFromSubscription', | ||
38 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription') | ||
39 | ) | ||
40 | @Column | ||
41 | newVideoFromSubscription: UserNotificationSettingValue | ||
42 | |||
43 | @AllowNull(false) | ||
44 | @Default(null) | ||
45 | @Is( | ||
46 | 'UserNotificationSettingNewCommentOnMyVideo', | ||
47 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo') | ||
48 | ) | ||
49 | @Column | ||
50 | newCommentOnMyVideo: UserNotificationSettingValue | ||
51 | |||
52 | @AllowNull(false) | ||
53 | @Default(null) | ||
54 | @Is( | ||
55 | 'UserNotificationSettingAbuseAsModerator', | ||
56 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseAsModerator') | ||
57 | ) | ||
58 | @Column | ||
59 | abuseAsModerator: UserNotificationSettingValue | ||
60 | |||
61 | @AllowNull(false) | ||
62 | @Default(null) | ||
63 | @Is( | ||
64 | 'UserNotificationSettingVideoAutoBlacklistAsModerator', | ||
65 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator') | ||
66 | ) | ||
67 | @Column | ||
68 | videoAutoBlacklistAsModerator: UserNotificationSettingValue | ||
69 | |||
70 | @AllowNull(false) | ||
71 | @Default(null) | ||
72 | @Is( | ||
73 | 'UserNotificationSettingBlacklistOnMyVideo', | ||
74 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo') | ||
75 | ) | ||
76 | @Column | ||
77 | blacklistOnMyVideo: UserNotificationSettingValue | ||
78 | |||
79 | @AllowNull(false) | ||
80 | @Default(null) | ||
81 | @Is( | ||
82 | 'UserNotificationSettingMyVideoPublished', | ||
83 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoPublished') | ||
84 | ) | ||
85 | @Column | ||
86 | myVideoPublished: UserNotificationSettingValue | ||
87 | |||
88 | @AllowNull(false) | ||
89 | @Default(null) | ||
90 | @Is( | ||
91 | 'UserNotificationSettingMyVideoImportFinished', | ||
92 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoImportFinished') | ||
93 | ) | ||
94 | @Column | ||
95 | myVideoImportFinished: UserNotificationSettingValue | ||
96 | |||
97 | @AllowNull(false) | ||
98 | @Default(null) | ||
99 | @Is( | ||
100 | 'UserNotificationSettingNewUserRegistration', | ||
101 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newUserRegistration') | ||
102 | ) | ||
103 | @Column | ||
104 | newUserRegistration: UserNotificationSettingValue | ||
105 | |||
106 | @AllowNull(false) | ||
107 | @Default(null) | ||
108 | @Is( | ||
109 | 'UserNotificationSettingNewInstanceFollower', | ||
110 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newInstanceFollower') | ||
111 | ) | ||
112 | @Column | ||
113 | newInstanceFollower: UserNotificationSettingValue | ||
114 | |||
115 | @AllowNull(false) | ||
116 | @Default(null) | ||
117 | @Is( | ||
118 | 'UserNotificationSettingNewInstanceFollower', | ||
119 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'autoInstanceFollowing') | ||
120 | ) | ||
121 | @Column | ||
122 | autoInstanceFollowing: UserNotificationSettingValue | ||
123 | |||
124 | @AllowNull(false) | ||
125 | @Default(null) | ||
126 | @Is( | ||
127 | 'UserNotificationSettingNewFollow', | ||
128 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newFollow') | ||
129 | ) | ||
130 | @Column | ||
131 | newFollow: UserNotificationSettingValue | ||
132 | |||
133 | @AllowNull(false) | ||
134 | @Default(null) | ||
135 | @Is( | ||
136 | 'UserNotificationSettingCommentMention', | ||
137 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'commentMention') | ||
138 | ) | ||
139 | @Column | ||
140 | commentMention: UserNotificationSettingValue | ||
141 | |||
142 | @AllowNull(false) | ||
143 | @Default(null) | ||
144 | @Is( | ||
145 | 'UserNotificationSettingAbuseStateChange', | ||
146 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseStateChange') | ||
147 | ) | ||
148 | @Column | ||
149 | abuseStateChange: UserNotificationSettingValue | ||
150 | |||
151 | @AllowNull(false) | ||
152 | @Default(null) | ||
153 | @Is( | ||
154 | 'UserNotificationSettingAbuseNewMessage', | ||
155 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'abuseNewMessage') | ||
156 | ) | ||
157 | @Column | ||
158 | abuseNewMessage: UserNotificationSettingValue | ||
159 | |||
160 | @AllowNull(false) | ||
161 | @Default(null) | ||
162 | @Is( | ||
163 | 'UserNotificationSettingNewPeerTubeVersion', | ||
164 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPeerTubeVersion') | ||
165 | ) | ||
166 | @Column | ||
167 | newPeerTubeVersion: UserNotificationSettingValue | ||
168 | |||
169 | @AllowNull(false) | ||
170 | @Default(null) | ||
171 | @Is( | ||
172 | 'UserNotificationSettingNewPeerPluginVersion', | ||
173 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'newPluginVersion') | ||
174 | ) | ||
175 | @Column | ||
176 | newPluginVersion: UserNotificationSettingValue | ||
177 | |||
178 | @AllowNull(false) | ||
179 | @Default(null) | ||
180 | @Is( | ||
181 | 'UserNotificationSettingMyVideoStudioEditionFinished', | ||
182 | value => throwIfNotValid(value, isUserNotificationSettingValid, 'myVideoStudioEditionFinished') | ||
183 | ) | ||
184 | @Column | ||
185 | myVideoStudioEditionFinished: UserNotificationSettingValue | ||
186 | |||
187 | @ForeignKey(() => UserModel) | ||
188 | @Column | ||
189 | userId: number | ||
190 | |||
191 | @BelongsTo(() => UserModel, { | ||
192 | foreignKey: { | ||
193 | allowNull: false | ||
194 | }, | ||
195 | onDelete: 'cascade' | ||
196 | }) | ||
197 | User: UserModel | ||
198 | |||
199 | @CreatedAt | ||
200 | createdAt: Date | ||
201 | |||
202 | @UpdatedAt | ||
203 | updatedAt: Date | ||
204 | |||
205 | @AfterUpdate | ||
206 | @AfterDestroy | ||
207 | static removeTokenCache (instance: UserNotificationSettingModel) { | ||
208 | return TokensCache.Instance.clearCacheByUserId(instance.userId) | ||
209 | } | ||
210 | |||
211 | toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting { | ||
212 | return { | ||
213 | newCommentOnMyVideo: this.newCommentOnMyVideo, | ||
214 | newVideoFromSubscription: this.newVideoFromSubscription, | ||
215 | abuseAsModerator: this.abuseAsModerator, | ||
216 | videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator, | ||
217 | blacklistOnMyVideo: this.blacklistOnMyVideo, | ||
218 | myVideoPublished: this.myVideoPublished, | ||
219 | myVideoImportFinished: this.myVideoImportFinished, | ||
220 | newUserRegistration: this.newUserRegistration, | ||
221 | commentMention: this.commentMention, | ||
222 | newFollow: this.newFollow, | ||
223 | newInstanceFollower: this.newInstanceFollower, | ||
224 | autoInstanceFollowing: this.autoInstanceFollowing, | ||
225 | abuseNewMessage: this.abuseNewMessage, | ||
226 | abuseStateChange: this.abuseStateChange, | ||
227 | newPeerTubeVersion: this.newPeerTubeVersion, | ||
228 | myVideoStudioEditionFinished: this.myVideoStudioEditionFinished, | ||
229 | newPluginVersion: this.newPluginVersion | ||
230 | } | ||
231 | } | ||
232 | } | ||