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/lib/model-loaders | |
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/lib/model-loaders')
-rw-r--r-- | server/lib/model-loaders/actor.ts | 17 | ||||
-rw-r--r-- | server/lib/model-loaders/index.ts | 2 | ||||
-rw-r--r-- | server/lib/model-loaders/video.ts | 66 |
3 files changed, 0 insertions, 85 deletions
diff --git a/server/lib/model-loaders/actor.ts b/server/lib/model-loaders/actor.ts deleted file mode 100644 index 1355d8ee2..000000000 --- a/server/lib/model-loaders/actor.ts +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | |||
2 | import { ActorModel } from '../../models/actor/actor' | ||
3 | import { MActorAccountChannelId, MActorFull } from '../../types/models' | ||
4 | |||
5 | type ActorLoadByUrlType = 'all' | 'association-ids' | ||
6 | |||
7 | function loadActorByUrl (url: string, fetchType: ActorLoadByUrlType): Promise<MActorFull | MActorAccountChannelId> { | ||
8 | if (fetchType === 'all') return ActorModel.loadByUrlAndPopulateAccountAndChannel(url) | ||
9 | |||
10 | if (fetchType === 'association-ids') return ActorModel.loadByUrl(url) | ||
11 | } | ||
12 | |||
13 | export { | ||
14 | ActorLoadByUrlType, | ||
15 | |||
16 | loadActorByUrl | ||
17 | } | ||
diff --git a/server/lib/model-loaders/index.ts b/server/lib/model-loaders/index.ts deleted file mode 100644 index 9e5152cb2..000000000 --- a/server/lib/model-loaders/index.ts +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | export * from './actor' | ||
2 | export * from './video' | ||
diff --git a/server/lib/model-loaders/video.ts b/server/lib/model-loaders/video.ts deleted file mode 100644 index 91057d405..000000000 --- a/server/lib/model-loaders/video.ts +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | ||
2 | import { | ||
3 | MVideoAccountLightBlacklistAllFiles, | ||
4 | MVideoFormattableDetails, | ||
5 | MVideoFullLight, | ||
6 | MVideoId, | ||
7 | MVideoImmutable, | ||
8 | MVideoThumbnail | ||
9 | } from '@server/types/models' | ||
10 | |||
11 | type VideoLoadType = 'for-api' | 'all' | 'only-video' | 'id' | 'none' | 'only-immutable-attributes' | ||
12 | |||
13 | function loadVideo (id: number | string, fetchType: 'for-api', userId?: number): Promise<MVideoFormattableDetails> | ||
14 | function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> | ||
15 | function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
16 | function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> | ||
17 | function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoId> | ||
18 | function loadVideo ( | ||
19 | id: number | string, | ||
20 | fetchType: VideoLoadType, | ||
21 | userId?: number | ||
22 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> | ||
23 | function loadVideo ( | ||
24 | id: number | string, | ||
25 | fetchType: VideoLoadType, | ||
26 | userId?: number | ||
27 | ): Promise<MVideoFullLight | MVideoThumbnail | MVideoId | MVideoImmutable> { | ||
28 | |||
29 | if (fetchType === 'for-api') return VideoModel.loadForGetAPI({ id, userId }) | ||
30 | |||
31 | if (fetchType === 'all') return VideoModel.loadFull(id, undefined, userId) | ||
32 | |||
33 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadImmutableAttributes(id) | ||
34 | |||
35 | if (fetchType === 'only-video') return VideoModel.load(id) | ||
36 | |||
37 | if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) | ||
38 | } | ||
39 | |||
40 | type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' | ||
41 | |||
42 | function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> | ||
43 | function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> | ||
44 | function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> | ||
45 | function loadVideoByUrl ( | ||
46 | url: string, | ||
47 | fetchType: VideoLoadByUrlType | ||
48 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> | ||
49 | function loadVideoByUrl ( | ||
50 | url: string, | ||
51 | fetchType: VideoLoadByUrlType | ||
52 | ): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { | ||
53 | if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) | ||
54 | |||
55 | if (fetchType === 'only-immutable-attributes') return VideoModel.loadByUrlImmutableAttributes(url) | ||
56 | |||
57 | if (fetchType === 'only-video') return VideoModel.loadByUrl(url) | ||
58 | } | ||
59 | |||
60 | export { | ||
61 | VideoLoadType, | ||
62 | VideoLoadByUrlType, | ||
63 | |||
64 | loadVideo, | ||
65 | loadVideoByUrl | ||
66 | } | ||