Skip to content

chore: remove all possible as any #2580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@liexp/backend/src/entities/Area.entity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BlockNoteDocument } from "@liexp/shared/lib/io/http/Common/BlockNoteDocument.js";
import {
type Geometry,
type UUID,
Expand Down Expand Up @@ -46,7 +47,7 @@ export class AreaEntity {
geometry: Geometry.Geometry;

@Column({ type: "json", nullable: true })
body: Record<string, any> | null;
body: BlockNoteDocument | null;

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

// admin props
socialPosts?: SocialPostEntity[];
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;

@CreateDateColumn()
createdAt: Date;
Expand Down
8 changes: 4 additions & 4 deletions packages/@liexp/backend/src/entities/Event.v2.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ export class EventV2Entity {
nullable: true,
})
@JoinTable()
links: Relation<LinkEntity[]>;
links: Relation<LinkEntity[] | UUID[]>;

@ManyToMany(() => MediaEntity, (a) => a.events, {
cascade: ["insert"],
nullable: true,
})
@JoinTable()
media: Relation<MediaEntity[]>;
media: Relation<MediaEntity[] | UUID[]>;

@ManyToMany(() => KeywordEntity, (a) => a.events, {
cascade: ["insert"],
nullable: true,
})
@JoinTable()
keywords: Relation<KeywordEntity[]>;
keywords: Relation<KeywordEntity[] | UUID[]>;

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

actors: ActorEntity[];
groups: GroupEntity[];
socialPosts?: SocialPostEntity[];
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;

@CreateDateColumn()
createdAt: Date;
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/entities/Group.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class GroupEntity {
nullable: true,
})
@JoinColumn()
avatar: Relation<MediaEntity> | UUID | null;
avatar: Relation<MediaEntity> | null;

@Column({
enum: io.http.Group.GroupKind.members.map((t) => t.literals[0]),
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/entities/Keyword.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class KeywordEntity {
media: Relation<MediaEntity[]>;

// admin props
socialPosts?: SocialPostEntity[];
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;

@CreateDateColumn()
createdAt: Date;
Expand Down
2 changes: 1 addition & 1 deletion packages/@liexp/backend/src/entities/Link.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class LinkEntity {
})
keywords: Relation<KeywordEntity[]>;

socialPosts?: SocialPostEntity[];
socialPosts?: Relation<SocialPostEntity[] | UUID[]>;

@CreateDateColumn()
createdAt: Date;
Expand Down
5 changes: 3 additions & 2 deletions packages/@liexp/backend/src/entities/Page.entity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BlockNoteDocument } from "@liexp/shared/lib/io/http/Common/BlockNoteDocument.js";
import { type UUID } from "@liexp/shared/lib/io/http/Common/index.js";
import {
Column,
Expand All @@ -24,13 +25,13 @@ export class PageEntity {
path: string;

@Column({ type: "json", nullable: true })
excerpt: Record<string, unknown> | null;
excerpt: BlockNoteDocument;

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

@Column({ type: "json", nullable: true })
body2: Record<string, unknown> | null;
body2: BlockNoteDocument | null;

@CreateDateColumn()
createdAt: Date;
Expand Down
7 changes: 4 additions & 3 deletions packages/@liexp/backend/src/entities/Story.entity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BlockNoteDocument } from "@liexp/shared/lib/io/http/Common/BlockNoteDocument.js";
import { UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
import {
Column,
Expand Down Expand Up @@ -43,7 +44,7 @@ export class StoryEntity {
nullable: true,
onDelete: "NO ACTION",
})
featuredImage: Relation<MediaEntity | null>;
featuredImage: Relation<MediaEntity | UUID | null>;

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

@Column({ type: "json", nullable: true })
body2: any[] | null;
body2: BlockNoteDocument | null;

@ManyToOne(() => UserEntity, (u) => u.stories, {
cascade: false,
nullable: true,
})
creator: Relation<UserEntity | null>;
creator: Relation<UserEntity | UUID | null>;

@ManyToMany(() => KeywordEntity, (k) => k.stories, {
cascade: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
import { toColorHash } from "@liexp/shared/lib/utils/colors.js";
import { type ReaderTaskEither } from "fp-ts/lib/ReaderTaskEither.js";
import {
type OverlayOptions,
type GravityEnum,
type Blend,
type Gravity,
type GravityEnum,
type OverlayOptions,
} from "sharp";
import { type ConfigContext } from "../../../../context/config.context.js";
import {
Expand Down Expand Up @@ -113,9 +113,9 @@ const addMediaImageLayer =
? fp.TE.right<ImgProcError, ExifReader.Tags>({
"Image Width": { value: parent.width },
"Image Height": { value: parent.width },
} as any)
} as ExifReader.Tags)
: pipe(
ctx.imgProc.readExif(buf as any, {}),
ctx.imgProc.readExif(buf as unknown as File, {}),
fp.TE.mapLeft(toImgProcError),
),
fp.TE.map((exif) => ({ exif, buf })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const extractThumbnailFromPDFPage = (
: undefined;

const renderContext: RenderParameters = {
canvasContext: context as any,
canvasContext: context as unknown as CanvasRenderingContext2D,
transform,
viewport,
};
Expand Down
7 changes: 4 additions & 3 deletions packages/@liexp/backend/src/flows/tg/MessageParser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getPlatform,
} from "@liexp/shared/lib/helpers/media.helper.js";
import { type URL } from "@liexp/shared/lib/io/http/Common/URL.js";
import { type UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
import { uuid, type UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
import { isNonEmpty } from "@liexp/shared/lib/utils/array.utils.js";
import { sanitizeURL } from "@liexp/shared/lib/utils/url.utils.js";
import * as E from "fp-ts/lib/Either.js";
Expand Down Expand Up @@ -190,8 +190,9 @@ export const MessageParser = <
(v) =>
parseVideo(
message.caption ??
(message.video as any)?.file_name ??
message.video?.file_id,
message.video?.file_unique_id ??
message.video?.file_id ??
uuid(),
v,
)(ctx),
),
Expand Down
13 changes: 10 additions & 3 deletions packages/@liexp/backend/src/flows/tg/parseDocument.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ export const parseDocument =
() => ServerError.fromUnknown(new Error("Invalid file type")),
),
TE.chain((f) => {
ctx.logger.debug.log("File downloaded %s", messageDocument.file_name);
ctx.logger.debug.log(
"File downloaded %s (%s)",
messageDocument.file_name,
messageDocument.mime_type ?? "unknown",
);

const contentType =
(messageDocument.mime_type as any) ?? PDFType.literals[0];
const contentType = pipe(
messageDocument.mime_type,
Schema.decodeUnknownOption(PDFType),
fp.O.getOrElse(() => PDFType.literals[0]),
);

return createAndUpload(
{
Expand Down
5 changes: 3 additions & 2 deletions packages/@liexp/backend/src/io/event/eventV2.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DecodeError,
} from "@liexp/shared/lib/io/http/Error/DecodeError.js";
import { EVENT_TYPES } from "@liexp/shared/lib/io/http/Events/EventType.js";
import { type Event } from "@liexp/shared/lib/io/http/Events/index.js";
import * as io from "@liexp/shared/lib/io/index.js";
import { IOError } from "@ts-endpoint/core";
import { Schema } from "effect";
Expand All @@ -19,7 +20,7 @@ const decodeEvent = (
): E.Either<_DecodeError, io.http.Events.Event> => {
return pipe(
E.Do,
E.bind("eventSpecs", () => {
E.bind("eventSpecs", (): E.Either<_DecodeError, Event | EventV2Entity> => {
if (event.type === EVENT_TYPES.QUOTE) {
return QuoteIO.decodeSingle(event);
}
Expand All @@ -29,7 +30,7 @@ const decodeEvent = (
if (event.type === EVENT_TYPES.BOOK) {
return BookIO.decodeSingle(event);
}
return E.right(event as any);
return E.right(event);
}),
E.chain(({ eventSpecs }) =>
pipe(
Expand Down
6 changes: 2 additions & 4 deletions packages/@liexp/backend/src/io/group.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const encodeGroupIO = (
"avatar",
(): E.Either<_DecodeError, io.http.Media.Media | undefined> =>
avatar
? Schema.is(UUID)(avatar)
? E.right({ id: avatar } as any)
: pipe(MediaIO.decodeSingle(avatar, spaceEndpoint))
? pipe(MediaIO.decodeSingle(avatar, spaceEndpoint))
: E.right(undefined),
),
E.map(({ avatar }) => ({
Expand All @@ -42,7 +40,7 @@ const encodeGroupIO = (
(group.body && isValidValue(group.body)
? toInitialValue(group.body)
: null) ?? null,
avatar: avatar,
avatar,
subGroups: [],
username: group.username ?? undefined,
startDate: group.startDate ?? undefined,
Expand Down
37 changes: 20 additions & 17 deletions packages/@liexp/backend/src/io/story.io.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pipe } from "@liexp/core/lib/fp/index.js";
import { UUID } from "@liexp/shared/lib/io/http/Common/UUID.js";
import {
type _DecodeError,
DecodeError,
Expand Down Expand Up @@ -27,23 +28,25 @@ const toStoryIO = ({
actors: story.actors ?? [],
groups: story.groups ?? [],
events: story.events ?? [],
featuredImage: story.featuredImage
? {
...story.featuredImage,
label: story.featuredImage.label ?? undefined,
description: story.featuredImage.description ?? undefined,
thumbnail: story.featuredImage.thumbnail ?? undefined,
createdAt: story.featuredImage.createdAt?.toISOString(),
updatedAt: story.featuredImage.updatedAt?.toISOString(),
deletedAt: story.featuredImage.deletedAt?.toISOString(),
extra: story.featuredImage.extra ?? undefined,
keywords: [],
events: [],
links: [],
areas: [],
featuredInStories: [],
}
: undefined,
featuredImage: Schema.is(UUID)(story.featuredImage)
? story.featuredImage
: story.featuredImage
? {
...story.featuredImage,
label: story.featuredImage.label ?? undefined,
description: story.featuredImage.description ?? undefined,
thumbnail: story.featuredImage.thumbnail ?? undefined,
createdAt: story.featuredImage.createdAt?.toISOString(),
updatedAt: story.featuredImage.updatedAt?.toISOString(),
deletedAt: story.featuredImage.deletedAt?.toISOString(),
extra: story.featuredImage.extra ?? undefined,
keywords: [],
events: [],
links: [],
areas: [],
featuredInStories: [],
}
: undefined,
date: story.date?.toISOString() ?? new Date().toISOString(),
createdAt: story.createdAt.toISOString(),
updatedAt: story.updatedAt.toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const toError = (e: unknown): Error => {
export type GetFFMPEGProvider = (ff: typeof ffmpeg) => FFMPEGProvider;

export const GetFFMPEGProvider: GetFFMPEGProvider = (ffmpeg) => {
const ffprobeTE = TE.taskify<string, Error, ffmpeg.FfprobeData>(
ffmpeg.ffprobe.bind(ffmpeg.ffprobe),
);
return {
ffprobe: (file) =>
TE.taskify<string, Error, ffmpeg.FfprobeData>(
ffmpeg.ffprobe.bind(ffmpeg.ffprobe),
)(file as any),
ffprobe: (file) => ffprobeTE(file as string),
runCommand: (f) => {
return TE.tryCatch(() => {
return new Promise((resolve, reject) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/@liexp/backend/src/providers/puppeteer.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export interface PuppeteerProvider {
) => (
page: puppeteer.Page,
) => TE.TaskEither<PuppeteerError, puppeteer.HTTPResponse>;
download: (url: string) => TE.TaskEither<PuppeteerError, any>;
download: (url: string) => TE.TaskEither<PuppeteerError, void>;
getBrowserFirstPage: (
url: string,
opts: BrowserLaunchOpts,
Expand Down Expand Up @@ -300,12 +300,12 @@ export const $safeEvalOrUndefined =
// > = puppeteer.EvaluateFuncWith<puppeteer.NodeFor<Selector>, Params>,
>(
sel: Selector,
onEval: (el: puppeteer.NodeFor<Selector>, ...args: Params) => Promise<any>,
onEval: (el: puppeteer.NodeFor<Selector>) => Promise<string>,
): Promise<string | undefined> => {
let ret: any;
let ret: string | undefined;
const el = await p.$(sel);
if (el) {
ret = await p.$eval(sel, onEval as any);
ret = await p.$eval(sel, onEval);
}
return ret;
};
Expand All @@ -321,15 +321,15 @@ export const $evalManyOrUndefined =
(p: puppeteer.Page) =>
async <Selector extends string, Params extends unknown[]>(
sel: Selector[],
onEval: (el: puppeteer.NodeFor<Selector>, ...args: Params) => Promise<any>,
onEval: (el: puppeteer.NodeFor<Selector>) => Promise<any>,
): Promise<string | undefined> => {
let ret: string | undefined;
const evall = $safeEvalOrUndefined(p);
for (const s of sel) {
if (ret) {
break;
}
ret = await evall(s, onEval as any);
ret = await evall(s, onEval);
}

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ const GetLocalSpaceProvider: Reader<LocalSpaceProviderCtx, SpaceProvider> = ({
logger.debug.log(`Getting file path %s`, params.Key);
return client.get<unknown, AxiosResponse<Body>>(params.Key ?? "");
}, toError),
TE.chain((content) => TE.tryCatch(() => content.data.text(), toError)),
TE.map((content) => ({ Body: content as any, $metadata: {} })),
TE.chain((content) =>
TE.tryCatch(() => content.data.blob() as Promise<any>, toError),
),
TE.map((content) => ({ Body: content, $metadata: {} })),
);
},
deleteObject: (params) => {
Expand Down
Loading
Loading