diff --git a/src/components/project/Card.tsx b/src/components/project/Card.tsx index 8ceec75..30bf48c 100644 --- a/src/components/project/Card.tsx +++ b/src/components/project/Card.tsx @@ -21,11 +21,11 @@ export function ProjectCard({ project }: { project: Project }): ReactElement { const swrProjectAbout = useSWRImmutable(key, async () => ( await ResultAsync.combine([ - project.resolveRelations(), + project.resolveRelation(), project.resolveReferenced(), ]) - .map(([resolved, referenced]) => ({ - resolved, + .map(([relation, referenced]) => ({ + relation, referenced, })) .mapErr(notifyTableErrorInToast("swrProjectAbout")) diff --git a/src/lib/classes/project.ts b/src/lib/classes/project.ts index 83986ce..7859d0c 100644 --- a/src/lib/classes/project.ts +++ b/src/lib/classes/project.ts @@ -24,12 +24,12 @@ const config = { } as const satisfies TableConfig; type Schema = Table2schema; -type SchemaResolvedData = Schema & { +type SchemaRelationData = Schema & { category: TableSchemaOf; territory: TableSchemaOf; }; -type SchemaResolved = Override< - SchemaResolvedData, +type SchemaRelation = Override< + SchemaRelationData, { category: Category; territory: Territory; @@ -49,7 +49,7 @@ type ProjectStatus = "wakaba" | "tsubomi" | "hana"; export class Project extends Table< typeof config, Schema, - SchemaResolved, + SchemaRelation, SchemaReferenced > { constructor(data: Schema) { @@ -75,16 +75,16 @@ export class Project extends Table< public calcStatus = Project.calcStatus; - public override resolveRelations(): TableResult { + public override resolveRelation(): TableResult { return ResultAsync.fromSafePromise( supabase .from("projects") .select("*, category:categories(*), territory:territories(*)") .eq(config.primaryKeyName, this.data.project_id) - .returns() + .returns() .single(), ) - .andThen(this.transform) + .andThen(this.transform) .map((data) => ({ ...data, category: new Category(data.category), diff --git a/src/lib/classes/project/comment.ts b/src/lib/classes/project/comment.ts index ba9a278..2b66110 100644 --- a/src/lib/classes/project/comment.ts +++ b/src/lib/classes/project/comment.ts @@ -17,30 +17,30 @@ const config = { } as const satisfies TableConfig; type Schema = Table2schema; -type SchemaResolvedData = Schema & { +type SchemaRelationData = Schema & { project: TableSchemaOf; }; -type SchemaResolved = Schema & { +type SchemaRelation = Schema & { project: Project; }; -export class Comment extends Table { +export class Comment extends Table { constructor(data: Schema) { super(data, config); } static factories = Table.getFactories(Comment, config); - public override resolveRelations(): TableResult { + public override resolveRelation(): TableResult { return ResultAsync.fromSafePromise( supabase .from("comments") .select("*, project:projects(*)") .eq(config.primaryKeyName, this.data.comment_id) - .returns() + .returns() .single(), ) - .andThen(this.transform) + .andThen(this.transform) .map((data) => ({ ...data, project: new Project(data.project), diff --git a/src/lib/classes/project/fruit.ts b/src/lib/classes/project/fruit.ts index 1b207cf..b3880fd 100644 --- a/src/lib/classes/project/fruit.ts +++ b/src/lib/classes/project/fruit.ts @@ -18,32 +18,32 @@ const config = { } as const satisfies TableConfig; type Schema = Table2schema; -type SchemaResolvedData = Schema & { +type SchemaRelationData = Schema & { project: TableSchemaOf; sponsor: TableSchemaOf; }; -type SchemaResolved = Schema & { +type SchemaRelation = Schema & { project: Project; sponsor: Sponsor; }; -export class Fruit extends Table { +export class Fruit extends Table { constructor(data: Schema) { super(data, config); } static factories = Table.getFactories(Fruit, config); - public override resolveRelations(): TableResult { + public override resolveRelation(): TableResult { return ResultAsync.fromSafePromise( supabase .from(config.tableName) .select("*, project:projects(*), sponsor:sponsors(*)") .eq(config.primaryKeyName, this.data.fruit_id) - .returns() + .returns() .single(), ) - .andThen(this.transform) + .andThen(this.transform) .map((data) => ({ ...data, project: new Project(data.project), diff --git a/src/lib/classes/project/pledge.ts b/src/lib/classes/project/pledge.ts index 723fc3f..c507940 100644 --- a/src/lib/classes/project/pledge.ts +++ b/src/lib/classes/project/pledge.ts @@ -18,32 +18,32 @@ const config = { } as const satisfies TableConfig; type Schema = Table2schema; -type SchemaResolvedData = Schema & { +type SchemaRelationData = Schema & { project: TableSchemaOf; sower: TableSchemaOf; }; -type SchemaResolved = Schema & { +type SchemaRelation = Schema & { project: Project; sower: Sower; }; -export class Pledge extends Table { +export class Pledge extends Table { constructor(data: Schema) { super(data, config); } static factories = this.getFactories(Pledge, config); - public override resolveRelations(): TableResult { + public override resolveRelation(): TableResult { return ResultAsync.fromSafePromise( supabase .from(config.tableName) .select("*, project:projects(*), sower:sowers(*)") .eq(config.primaryKeyName, this.data.pledges_id) - .returns() + .returns() .single(), ) - .andThen(this.transform) + .andThen(this.transform) .map((data) => ({ ...data, project: new Project(data.project), diff --git a/src/lib/classes/project/report.ts b/src/lib/classes/project/report.ts index 7cc7fdf..8f2028d 100644 --- a/src/lib/classes/project/report.ts +++ b/src/lib/classes/project/report.ts @@ -18,32 +18,32 @@ const config = { } as const satisfies TableConfig; type Schema = Table2schema; -type SchemaResolvedData = Schema & { +type SchemaRelationData = Schema & { project: TableSchemaOf; sponsor: TableSchemaOf; }; -type SchemaResolved = Schema & { +type SchemaRelation = Schema & { project: Project; sponsor: Sponsor; }; -export class Report extends Table { +export class Report extends Table { constructor(data: Schema) { super(data, config); } static factories = Table.getFactories(Report, config); - public override resolveRelations(): TableResult { + public override resolveRelation(): TableResult { return ResultAsync.fromSafePromise( supabase .from(config.tableName) .select("*, project:projects(*), sponsor:sponsors(*)") .eq(config.primaryKeyName, this.data.report_id) - .returns() + .returns() .single(), ) - .andThen(this.transform) + .andThen(this.transform) .map((data) => ({ ...data, project: new Project(data.project), diff --git a/src/lib/classes/project/sponsor-data.ts b/src/lib/classes/project/sponsor-data.ts index e0eea6f..fbe0f93 100644 --- a/src/lib/classes/project/sponsor-data.ts +++ b/src/lib/classes/project/sponsor-data.ts @@ -20,32 +20,32 @@ const config = { } as const satisfies TableConfig; type Schema = Override, { location: Location }>; -type SchemaResolvedData = Schema & { +type SchemaRelationData = Schema & { project: TableSchemaOf; sponsor: TableSchemaOf; }; -type SchemaResolved = Schema & { +type SchemaRelation = Schema & { project: Project; sponsor: Sponsor; }; -export class SponsorData extends Table { +export class SponsorData extends Table { constructor(data: Schema) { super(data, config); } static factories = this.getFactories(SponsorData, config); - public override resolveRelations(): TableResult { + public override resolveRelation(): TableResult { return ResultAsync.fromSafePromise( supabase .from(config.tableName) .select("*, project:projects(*), sponsor:sponsors(*)") .eq(config.primaryKeyName, this.data.project_id) - .returns() + .returns() .single(), ) - .andThen(this.transform) + .andThen(this.transform) .map((data) => ({ ...data, project: new Project(data.project), diff --git a/src/lib/classes/seed.ts b/src/lib/classes/seed.ts index 632020e..1adbbee 100644 --- a/src/lib/classes/seed.ts +++ b/src/lib/classes/seed.ts @@ -22,35 +22,35 @@ const config = { } as const satisfies TableConfig; type Schema = Override, { location: Location }>; -type SchemaResolvedData = Schema & { +type SchemaRelationData = Schema & { sower: TableSchemaOf; category: TableSchemaOf; }; -type SchemaResolved = Override< - SchemaResolvedData, +type SchemaRelation = Override< + SchemaRelationData, { sower: Sower; category: Category; } >; -export class Seed extends Table { +export class Seed extends Table { constructor(data: Schema) { super(data, config); } static factories = Table.getFactories(Seed, config); - public override resolveRelations(): TableResult { + public override resolveRelation(): TableResult { return ResultAsync.fromSafePromise( supabase .from("seeds") .select("*, category:categories(*), sower:sowers(*)") .eq(config.primaryKeyName, this.data.seed_id) - .returns() + .returns() .single(), ) - .andThen(this.transform) + .andThen(this.transform) .map((data) => ({ ...data, sower: new Sower(data.sower), diff --git a/src/lib/utils/table.ts b/src/lib/utils/table.ts index 1ac06b9..17e6396 100644 --- a/src/lib/utils/table.ts +++ b/src/lib/utils/table.ts @@ -27,7 +27,7 @@ export const queryErrorCode = { export abstract class Table< Config extends TableConfig, Schema extends object, - SchemaResolved extends object = Schema, + SchemaRelation extends object = Schema, SchemaReferenced extends object = Schema, > { constructor( @@ -35,7 +35,7 @@ export abstract class Table< protected config: Config, ) {} - public resolveRelations?(): TableResult; + public resolveRelation?(): TableResult; public resolveReferenced?(): TableResult; static transformError( diff --git a/src/routes/_auth/seeds/-components/SownSeed.tsx b/src/routes/_auth/seeds/-components/SownSeed.tsx index e87b450..83b65ca 100644 --- a/src/routes/_auth/seeds/-components/SownSeed.tsx +++ b/src/routes/_auth/seeds/-components/SownSeed.tsx @@ -13,7 +13,7 @@ export function SownSeed({ seed }: { seed: Seed }): ReactElement { const swrSeedAbout = useSWRImmutable(`seed-${seed.data.seed_id}`, async () => ( await seed - .resolveRelations() + .resolveRelation() .mapErr(notifyTableErrorInToast("swrSeedAbout")) )._unsafeUnwrap(), ); diff --git a/src/routes/_auth/seeds/-components/SownSeedInline.tsx b/src/routes/_auth/seeds/-components/SownSeedInline.tsx index 24540a0..3593e00 100644 --- a/src/routes/_auth/seeds/-components/SownSeedInline.tsx +++ b/src/routes/_auth/seeds/-components/SownSeedInline.tsx @@ -11,7 +11,7 @@ export function SownSeedInline({ seed }: { seed: Seed }): ReactElement { const swrSeedAbout = useSWRImmutable(`seed-${seed.data.seed_id}`, async () => ( await seed - .resolveRelations() + .resolveRelation() .mapErr(notifyTableErrorInToast("swrSeedAbout")) )._unsafeUnwrap(), ); diff --git a/src/routes/projects/$uuid.tsx b/src/routes/projects/$uuid.tsx index da642a9..e89ce26 100644 --- a/src/routes/projects/$uuid.tsx +++ b/src/routes/projects/$uuid.tsx @@ -30,13 +30,13 @@ import { type TableBrandedId, type TableError, type TableSchemaReferencedOf, - type TableSchemaResolvedOf, + type TableSchemaRelationOf, } from "@/types/table"; import { type Nullable } from "@/types/utils"; type ProjectData = { project: T; - resolved: TableSchemaResolvedOf; + relation: TableSchemaRelationOf; referenced: TableSchemaReferencedOf; }; type ProjectStatus = ReturnType; @@ -129,7 +129,7 @@ function SponsorInfo({ if (sponsorData == null) return undefined; return ( await sponsorData - .resolveRelations() + .resolveRelation() .mapErr(notifyTableErrorInToast("swrSponsor")) )._unsafeUnwrap(); }, @@ -225,7 +225,7 @@ function GridDetailInfo({ }: { projectData: ProjectData; }): ReactElement { - const { project, resolved, referenced } = projectData; + const { project, relation, referenced } = projectData; const progress = svaProgress(); const swrAddr = useSWRImmutable( @@ -392,7 +392,7 @@ function GridDetailInfo({ 以下の意見が集まって生成されました - + - ResultAsync.combine([ - pj.resolveRelations(), - pj.resolveReferenced(), - ]).map(([resolved, referenced]) => ({ - project: pj, - resolved, - referenced, - })), + ResultAsync.combine([pj.resolveRelation(), pj.resolveReferenced()]).map( + ([relation, referenced]) => ({ + project: pj, + relation, + referenced, + }), + ), ) ).match( (d) => d, diff --git a/src/types/table.ts b/src/types/table.ts index f572d3a..d22bee2 100644 --- a/src/types/table.ts +++ b/src/types/table.ts @@ -56,7 +56,7 @@ export type TableConfigOf = T extends Table ? C : never; export type TableSchemaOf = T extends Table ? S : never; -export type TableSchemaResolvedOf = +export type TableSchemaRelationOf = T extends Table ? S : never; export type TableSchemaReferencedOf = T extends Table ? S : never;