Skip to content

Commit 2ff79e8

Browse files
authored
chore: remove all possible as any (#2580)
1 parent 24cc4ac commit 2ff79e8

File tree

61 files changed

+312
-290
lines changed

Some content is hidden

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

61 files changed

+312
-290
lines changed

packages/@liexp/backend/src/entities/Area.entity.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BlockNoteDocument } from "@liexp/shared/lib/io/http/Common/BlockNoteDocument.js";
12
import {
23
type Geometry,
34
type UUID,
@@ -46,7 +47,7 @@ export class AreaEntity {
4647
geometry: Geometry.Geometry;
4748

4849
@Column({ type: "json", nullable: true })
49-
body: Record<string, any> | null;
50+
body: BlockNoteDocument | null;
5051

5152
@ManyToOne(() => MediaEntity, (v) => v.featuredInAreas, {
5253
eager: true,
@@ -63,7 +64,7 @@ export class AreaEntity {
6364
events: EventV2Entity[];
6465

6566
// admin props
66-
socialPosts?: SocialPostEntity[];
67+
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;
6768

6869
@CreateDateColumn()
6970
createdAt: Date;

packages/@liexp/backend/src/entities/Event.v2.entity.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ export class EventV2Entity {
6565
nullable: true,
6666
})
6767
@JoinTable()
68-
links: Relation<LinkEntity[]>;
68+
links: Relation<LinkEntity[] | UUID[]>;
6969

7070
@ManyToMany(() => MediaEntity, (a) => a.events, {
7171
cascade: ["insert"],
7272
nullable: true,
7373
})
7474
@JoinTable()
75-
media: Relation<MediaEntity[]>;
75+
media: Relation<MediaEntity[] | UUID[]>;
7676

7777
@ManyToMany(() => KeywordEntity, (a) => a.events, {
7878
cascade: ["insert"],
7979
nullable: true,
8080
})
8181
@JoinTable()
82-
keywords: Relation<KeywordEntity[]>;
82+
keywords: Relation<KeywordEntity[] | UUID[]>;
8383

8484
@ManyToOne(() => AreaEntity, (a) => a.events, {
8585
cascade: ["insert"],
@@ -96,7 +96,7 @@ export class EventV2Entity {
9696

9797
actors: ActorEntity[];
9898
groups: GroupEntity[];
99-
socialPosts?: SocialPostEntity[];
99+
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;
100100

101101
@CreateDateColumn()
102102
createdAt: Date;

packages/@liexp/backend/src/entities/Group.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class GroupEntity {
4747
nullable: true,
4848
})
4949
@JoinColumn()
50-
avatar: Relation<MediaEntity> | UUID | null;
50+
avatar: Relation<MediaEntity> | null;
5151

5252
@Column({
5353
enum: io.http.Group.GroupKind.members.map((t) => t.literals[0]),

packages/@liexp/backend/src/entities/Keyword.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class KeywordEntity {
5252
media: Relation<MediaEntity[]>;
5353

5454
// admin props
55-
socialPosts?: SocialPostEntity[];
55+
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;
5656

5757
@CreateDateColumn()
5858
createdAt: Date;

packages/@liexp/backend/src/entities/Link.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class LinkEntity {
6464
})
6565
keywords: Relation<KeywordEntity[]>;
6666

67-
socialPosts?: SocialPostEntity[];
67+
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;
6868

6969
@CreateDateColumn()
7070
createdAt: Date;

packages/@liexp/backend/src/entities/Page.entity.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BlockNoteDocument } from "@liexp/shared/lib/io/http/Common/BlockNoteDocument.js";
12
import { type UUID } from "@liexp/shared/lib/io/http/Common/index.js";
23
import {
34
Column,
@@ -24,13 +25,13 @@ export class PageEntity {
2425
path: string;
2526

2627
@Column({ type: "json", nullable: true })
27-
excerpt: Record<string, unknown> | null;
28+
excerpt: BlockNoteDocument;
2829

2930
@Column({ type: "varchar", nullable: true })
3031
body: string | null;
3132

3233
@Column({ type: "json", nullable: true })
33-
body2: Record<string, unknown> | null;
34+
body2: BlockNoteDocument | null;
3435

3536
@CreateDateColumn()
3637
createdAt: Date;

packages/@liexp/backend/src/entities/Story.entity.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BlockNoteDocument } from "@liexp/shared/lib/io/http/Common/BlockNoteDocument.js";
12
import { UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
23
import {
34
Column,
@@ -43,7 +44,7 @@ export class StoryEntity {
4344
nullable: true,
4445
onDelete: "NO ACTION",
4546
})
46-
featuredImage: Relation<MediaEntity | null>;
47+
featuredImage: Relation<MediaEntity | UUID | null>;
4748

4849
@Column({ type: "varchar", nullable: true })
4950
excerpt: string | null;
@@ -52,13 +53,13 @@ export class StoryEntity {
5253
body: string;
5354

5455
@Column({ type: "json", nullable: true })
55-
body2: any[] | null;
56+
body2: BlockNoteDocument | null;
5657

5758
@ManyToOne(() => UserEntity, (u) => u.stories, {
5859
cascade: false,
5960
nullable: true,
6061
})
61-
creator: Relation<UserEntity | null>;
62+
creator: Relation<UserEntity | UUID | null>;
6263

6364
@ManyToMany(() => KeywordEntity, (k) => k.stories, {
6465
cascade: false,

packages/@liexp/backend/src/flows/media/admin/build-image/buildImageWithSharp.flow.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
import { toColorHash } from "@liexp/shared/lib/utils/colors.js";
1010
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
1111
import {
12-
type OverlayOptions,
13-
type GravityEnum,
1412
type Blend,
1513
type Gravity,
14+
type GravityEnum,
15+
type OverlayOptions,
1616
} from "sharp";
1717
import { type ConfigContext } from "../../../../context/config.context.js";
1818
import {
@@ -113,9 +113,9 @@ const addMediaImageLayer =
113113
? fp.TE.right<ImgProcError, ExifReader.Tags>({
114114
"Image Width": { value: parent.width },
115115
"Image Height": { value: parent.width },
116-
} as any)
116+
} as ExifReader.Tags)
117117
: pipe(
118-
ctx.imgProc.readExif(buf as any, {}),
118+
ctx.imgProc.readExif(buf as unknown as File, {}),
119119
fp.TE.mapLeft(toImgProcError),
120120
),
121121
fp.TE.map((exif) => ({ exif, buf })),

packages/@liexp/backend/src/flows/media/thumbnails/extractThumbnailFromPDF.flow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const extractThumbnailFromPDFPage = (
3939
: undefined;
4040

4141
const renderContext: RenderParameters = {
42-
canvasContext: context as any,
42+
canvasContext: context as unknown as CanvasRenderingContext2D,
4343
transform,
4444
viewport,
4545
};

packages/@liexp/backend/src/flows/tg/MessageParser/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getPlatform,
66
} from "@liexp/shared/lib/helpers/media.helper.js";
77
import { type URL } from "@liexp/shared/lib/io/http/Common/URL.js";
8-
import { type UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
8+
import { uuid, type UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
99
import { isNonEmpty } from "@liexp/shared/lib/utils/array.utils.js";
1010
import { sanitizeURL } from "@liexp/shared/lib/utils/url.utils.js";
1111
import * as E from "fp-ts/lib/Either.js";
@@ -190,8 +190,9 @@ export const MessageParser = <
190190
(v) =>
191191
parseVideo(
192192
message.caption ??
193-
(message.video as any)?.file_name ??
194-
message.video?.file_id,
193+
message.video?.file_unique_id ??
194+
message.video?.file_id ??
195+
uuid(),
195196
v,
196197
)(ctx),
197198
),

packages/@liexp/backend/src/flows/tg/parseDocument.flow.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,17 @@ export const parseDocument =
5252
() => ServerError.fromUnknown(new Error("Invalid file type")),
5353
),
5454
TE.chain((f) => {
55-
ctx.logger.debug.log("File downloaded %s", messageDocument.file_name);
55+
ctx.logger.debug.log(
56+
"File downloaded %s (%s)",
57+
messageDocument.file_name,
58+
messageDocument.mime_type ?? "unknown",
59+
);
5660

57-
const contentType =
58-
(messageDocument.mime_type as any) ?? PDFType.literals[0];
61+
const contentType = pipe(
62+
messageDocument.mime_type,
63+
Schema.decodeUnknownOption(PDFType),
64+
fp.O.getOrElse(() => PDFType.literals[0]),
65+
);
5966

6067
return createAndUpload(
6168
{

packages/@liexp/backend/src/io/event/eventV2.io.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
DecodeError,
55
} from "@liexp/shared/lib/io/http/Error/DecodeError.js";
66
import { EVENT_TYPES } from "@liexp/shared/lib/io/http/Events/EventType.js";
7+
import { type Event } from "@liexp/shared/lib/io/http/Events/index.js";
78
import * as io from "@liexp/shared/lib/io/index.js";
89
import { IOError } from "@ts-endpoint/core";
910
import { Schema } from "effect";
@@ -19,7 +20,7 @@ const decodeEvent = (
1920
): E.Either<_DecodeError, io.http.Events.Event> => {
2021
return pipe(
2122
E.Do,
22-
E.bind("eventSpecs", () => {
23+
E.bind("eventSpecs", (): E.Either<_DecodeError, Event | EventV2Entity> => {
2324
if (event.type === EVENT_TYPES.QUOTE) {
2425
return QuoteIO.decodeSingle(event);
2526
}
@@ -29,7 +30,7 @@ const decodeEvent = (
2930
if (event.type === EVENT_TYPES.BOOK) {
3031
return BookIO.decodeSingle(event);
3132
}
32-
return E.right(event as any);
33+
return E.right(event);
3334
}),
3435
E.chain(({ eventSpecs }) =>
3536
pipe(

packages/@liexp/backend/src/io/group.io.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ const encodeGroupIO = (
2727
"avatar",
2828
(): E.Either<_DecodeError, io.http.Media.Media | undefined> =>
2929
avatar
30-
? Schema.is(UUID)(avatar)
31-
? E.right({ id: avatar } as any)
32-
: pipe(MediaIO.decodeSingle(avatar, spaceEndpoint))
30+
? pipe(MediaIO.decodeSingle(avatar, spaceEndpoint))
3331
: E.right(undefined),
3432
),
3533
E.map(({ avatar }) => ({
@@ -42,7 +40,7 @@ const encodeGroupIO = (
4240
(group.body && isValidValue(group.body)
4341
? toInitialValue(group.body)
4442
: null) ?? null,
45-
avatar: avatar,
43+
avatar,
4644
subGroups: [],
4745
username: group.username ?? undefined,
4846
startDate: group.startDate ?? undefined,

packages/@liexp/backend/src/io/story.io.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { pipe } from "@liexp/core/lib/fp/index.js";
2+
import { UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
23
import {
34
type _DecodeError,
45
DecodeError,
@@ -27,23 +28,25 @@ const toStoryIO = ({
2728
actors: story.actors ?? [],
2829
groups: story.groups ?? [],
2930
events: story.events ?? [],
30-
featuredImage: story.featuredImage
31-
? {
32-
...story.featuredImage,
33-
label: story.featuredImage.label ?? undefined,
34-
description: story.featuredImage.description ?? undefined,
35-
thumbnail: story.featuredImage.thumbnail ?? undefined,
36-
createdAt: story.featuredImage.createdAt?.toISOString(),
37-
updatedAt: story.featuredImage.updatedAt?.toISOString(),
38-
deletedAt: story.featuredImage.deletedAt?.toISOString(),
39-
extra: story.featuredImage.extra ?? undefined,
40-
keywords: [],
41-
events: [],
42-
links: [],
43-
areas: [],
44-
featuredInStories: [],
45-
}
46-
: undefined,
31+
featuredImage: Schema.is(UUID)(story.featuredImage)
32+
? story.featuredImage
33+
: story.featuredImage
34+
? {
35+
...story.featuredImage,
36+
label: story.featuredImage.label ?? undefined,
37+
description: story.featuredImage.description ?? undefined,
38+
thumbnail: story.featuredImage.thumbnail ?? undefined,
39+
createdAt: story.featuredImage.createdAt?.toISOString(),
40+
updatedAt: story.featuredImage.updatedAt?.toISOString(),
41+
deletedAt: story.featuredImage.deletedAt?.toISOString(),
42+
extra: story.featuredImage.extra ?? undefined,
43+
keywords: [],
44+
events: [],
45+
links: [],
46+
areas: [],
47+
featuredInStories: [],
48+
}
49+
: undefined,
4750
date: story.date?.toISOString() ?? new Date().toISOString(),
4851
createdAt: story.createdAt.toISOString(),
4952
updatedAt: story.updatedAt.toISOString(),

packages/@liexp/backend/src/providers/ffmpeg/ffmpeg.provider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ const toError = (e: unknown): Error => {
2424
export type GetFFMPEGProvider = (ff: typeof ffmpeg) => FFMPEGProvider;
2525

2626
export const GetFFMPEGProvider: GetFFMPEGProvider = (ffmpeg) => {
27+
const ffprobeTE = TE.taskify<string, Error, ffmpeg.FfprobeData>(
28+
ffmpeg.ffprobe.bind(ffmpeg.ffprobe),
29+
);
2730
return {
28-
ffprobe: (file) =>
29-
TE.taskify<string, Error, ffmpeg.FfprobeData>(
30-
ffmpeg.ffprobe.bind(ffmpeg.ffprobe),
31-
)(file as any),
31+
ffprobe: (file) => ffprobeTE(file as string),
3232
runCommand: (f) => {
3333
return TE.tryCatch(() => {
3434
return new Promise((resolve, reject) => {

packages/@liexp/backend/src/providers/puppeteer.provider.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface PuppeteerProvider {
109109
) => (
110110
page: puppeteer.Page,
111111
) => TE.TaskEither<PuppeteerError, puppeteer.HTTPResponse>;
112-
download: (url: string) => TE.TaskEither<PuppeteerError, any>;
112+
download: (url: string) => TE.TaskEither<PuppeteerError, void>;
113113
getBrowserFirstPage: (
114114
url: string,
115115
opts: BrowserLaunchOpts,
@@ -300,12 +300,12 @@ export const $safeEvalOrUndefined =
300300
// > = puppeteer.EvaluateFuncWith<puppeteer.NodeFor<Selector>, Params>,
301301
>(
302302
sel: Selector,
303-
onEval: (el: puppeteer.NodeFor<Selector>, ...args: Params) => Promise<any>,
303+
onEval: (el: puppeteer.NodeFor<Selector>) => Promise<string>,
304304
): Promise<string | undefined> => {
305-
let ret: any;
305+
let ret: string | undefined;
306306
const el = await p.$(sel);
307307
if (el) {
308-
ret = await p.$eval(sel, onEval as any);
308+
ret = await p.$eval(sel, onEval);
309309
}
310310
return ret;
311311
};
@@ -321,15 +321,15 @@ export const $evalManyOrUndefined =
321321
(p: puppeteer.Page) =>
322322
async <Selector extends string, Params extends unknown[]>(
323323
sel: Selector[],
324-
onEval: (el: puppeteer.NodeFor<Selector>, ...args: Params) => Promise<any>,
324+
onEval: (el: puppeteer.NodeFor<Selector>) => Promise<any>,
325325
): Promise<string | undefined> => {
326326
let ret: string | undefined;
327327
const evall = $safeEvalOrUndefined(p);
328328
for (const s of sel) {
329329
if (ret) {
330330
break;
331331
}
332-
ret = await evall(s, onEval as any);
332+
ret = await evall(s, onEval);
333333
}
334334

335335
return ret;

packages/@liexp/backend/src/providers/space/local-space.provider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ const GetLocalSpaceProvider: Reader<LocalSpaceProviderCtx, SpaceProvider> = ({
3535
logger.debug.log(`Getting file path %s`, params.Key);
3636
return client.get<unknown, AxiosResponse<Body>>(params.Key ?? "");
3737
}, toError),
38-
TE.chain((content) => TE.tryCatch(() => content.data.text(), toError)),
39-
TE.map((content) => ({ Body: content as any, $metadata: {} })),
38+
TE.chain((content) =>
39+
TE.tryCatch(() => content.data.blob() as Promise<any>, toError),
40+
),
41+
TE.map((content) => ({ Body: content, $metadata: {} })),
4042
);
4143
},
4244
deleteObject: (params) => {

0 commit comments

Comments
 (0)