Skip to content

Commit

Permalink
codegenしてもdiffが発生しないようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
kgtkr committed Jan 17, 2024
1 parent 3bc0e30 commit 9c32166
Show file tree
Hide file tree
Showing 27 changed files with 120 additions and 116 deletions.
52 changes: 28 additions & 24 deletions packages/server/src/entities/res/res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,45 @@ export type IResAPI =
| IResForkAPI
| IResDeleteAPI;

export interface IResBaseAPI<T extends ResAPIType> {
readonly id: string;
readonly topicID: string;
readonly date: Date;
readonly self: boolean | null;
readonly uv: number;
readonly dv: number;
readonly hash: string;
readonly replyCount: number;
readonly voteFlag: VoteFlag | null;
readonly type: T;
// --
// typescript-resolver-files がinterfaceのextendsをサポートしていないので、classとして定義するがinterfaceとして使う
export class IResBaseAPI<T extends ResAPIType> {
readonly id!: string;
readonly topicID!: string;
readonly date!: Date;
readonly self!: boolean | null;
readonly uv!: number;
readonly dv!: number;
readonly hash!: string;
readonly replyCount!: number;
readonly voteFlag!: VoteFlag | null;
readonly type!: T;
}

export interface IResNormalAPI extends IResBaseAPI<"normal"> {
readonly name: string | null;
readonly text: string;
readonly replyID: string | null;
readonly profileID: string | null;
readonly isReply: boolean | null;
export class IResNormalAPI extends IResBaseAPI<"normal"> {
readonly name!: string | null;
readonly text!: string;
readonly replyID!: string | null;
readonly profileID!: string | null;
readonly isReply!: boolean | null;
}

export interface IResHistoryAPI extends IResBaseAPI<"history"> {
readonly historyID: string;
export class IResHistoryAPI extends IResBaseAPI<"history"> {
readonly historyID!: string;
}

export type IResTopicAPI = IResBaseAPI<"topic">;
export class IResTopicAPI extends IResBaseAPI<"topic"> {}

export interface IResForkAPI extends IResBaseAPI<"fork"> {
readonly forkID: string;
export class IResForkAPI extends IResBaseAPI<"fork"> {
readonly forkID!: string;
}

export interface IResDeleteAPI extends IResBaseAPI<"delete"> {
readonly flag: "self" | "freeze";
export class IResDeleteAPI extends IResBaseAPI<"delete"> {
readonly flag!: "self" | "freeze";
}

// --

export type VoteFlag = "uv" | "dv" | "not";
export type ResDeleteFlag = "active" | "self" | "freeze";
export interface IReply {
Expand Down
25 changes: 14 additions & 11 deletions packages/server/src/entities/token/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@ export interface ITokenReq {
readonly active: boolean;
}

export interface ITokenReqAPI {
readonly token: string;
readonly key: string;
export class ITokenReqAPI {
readonly token!: string;
readonly key!: string;
}

export type TokenType = "master" | "general";

export type ITokenAPI = ITokenGeneralAPI | ITokenMasterAPI;

export interface ITokenBaseAPI<T extends TokenType> {
readonly id: string;
readonly key: string;
readonly date: string;
readonly type: T;
// --
// typescript-resolver-files がinterfaceのextendsをサポートしていないので、classとして定義するがinterfaceとして使う
export class ITokenBaseAPI<T extends TokenType> {
readonly id!: string;
readonly key!: string;
readonly date!: string;
readonly type!: T;
}

export type ITokenMasterAPI = ITokenBaseAPI<"master">;
export class ITokenMasterAPI extends ITokenBaseAPI<"master"> {}

export interface ITokenGeneralAPI extends ITokenBaseAPI<"general"> {
readonly clientID: string;
export class ITokenGeneralAPI extends ITokenBaseAPI<"general"> {
readonly clientID!: string;
}
// --

export type Token = TokenMaster | TokenGeneral;

Expand Down
36 changes: 20 additions & 16 deletions packages/server/src/entities/topic/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,33 @@ export interface ITagsAPI {
export type ITopicAPI = ITopicOneAPI | ITopicNormalAPI | ITopicForkAPI;
export type ITopicSearchAPI = ITopicOneAPI | ITopicNormalAPI;

export interface ITopicBaseAPI<T extends TopicType> {
readonly id: string;
readonly title: string;
readonly update: string;
readonly date: string;
readonly resCount: number;
readonly type: T;
readonly active: boolean;
// --
// typescript-resolver-files がinterfaceのextendsをサポートしていないので、classとして定義するがinterfaceとして使う
export class ITopicBaseAPI<T extends TopicType> {
readonly id!: string;
readonly title!: string;
readonly update!: string;
readonly date!: string;
readonly resCount!: number;
readonly type!: T;
readonly active!: boolean;
}

export interface ITopicSearchBaseAPI<T extends TopicSearchType>
extends ITopicBaseAPI<T> {
readonly tags: Array<string>;
readonly text: string;
export class ITopicSearchBaseAPI<
T extends TopicSearchType
> extends ITopicBaseAPI<T> {
readonly tags!: Array<string>;
readonly text!: string;
}

export type ITopicNormalAPI = ITopicSearchBaseAPI<"normal">;
export class ITopicNormalAPI extends ITopicSearchBaseAPI<"normal"> {}

export type ITopicOneAPI = ITopicSearchBaseAPI<"one">;
export class ITopicOneAPI extends ITopicSearchBaseAPI<"one"> {}

export interface ITopicForkAPI extends ITopicBaseAPI<"fork"> {
readonly parentID: string;
export class ITopicForkAPI extends ITopicBaseAPI<"fork"> {
readonly parentID!: string;
}
// --

export type TopicSearchType = "one" | "normal";
export type TopicType = TopicSearchType | "fork";
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/schema/res/resolvers/ResDelete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ResDeleteResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";
import { base_Res } from "./base_Res";

export const ResDelete: ResDeleteResolvers = {
...ResBase,
topic: base_Res.topic,
};
4 changes: 2 additions & 2 deletions packages/server/src/schema/res/resolvers/ResFork.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getTopic } from "../../../usecases";
import type { ResForkResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";
import { base_Res } from "./base_Res";

export const ResFork: ResForkResolvers = {
...ResBase,
topic: base_Res.topic,
fork: async (res, _args, context, _info) => {
const fork = await getTopic({ id: res.forkID }, context.ports);
if (fork.type !== "fork") {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/schema/res/resolvers/ResHistory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getHistory } from "../../../usecases";
import type { ResHistoryResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";
import { base_Res } from "./base_Res";

export const ResHistory: ResHistoryResolvers = {
...ResBase,
topic: base_Res.topic,
history: async (res, _args, context, _info) => {
const history = await getHistory({ id: res.historyID }, context.ports);
return history;
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/schema/res/resolvers/ResNormal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getProfile, getRes } from "../../../usecases";
import type { ResNormalResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";
import { base_Res } from "./base_Res";

export const ResNormal: ResNormalResolvers = {
...ResBase,
topic: base_Res.topic,
reply: async (res, _args, context, _info) => {
if (res.replyID !== null) {
const reply = await getRes({ id: res.replyID }, context.ports);
Expand Down
16 changes: 8 additions & 8 deletions packages/server/src/schema/res/resolvers/ResSubscript.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ResSubscriptResolvers } from './../../types.generated';
export const ResSubscript: ResSubscriptResolvers = {
/* Implement ResSubscript resolver logic here */
res: ({ res }) => {
/* ResSubscript.res resolver is required because ResSubscript.res and ResSubscriptMapper.res are not compatible */
return res
}
};
import type { ResSubscriptResolvers } from "./../../types.generated";
export const ResSubscript: ResSubscriptResolvers = {
/* Implement ResSubscript resolver logic here */
res: ({ res }) => {
/* ResSubscript.res resolver is required because ResSubscript.res and ResSubscriptMapper.res are not compatible */
return res;
},
};
4 changes: 2 additions & 2 deletions packages/server/src/schema/res/resolvers/ResTopic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ResTopicResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";
import { base_Res } from "./base_Res";

export const ResTopic: ResTopicResolvers = {
...ResBase,
topic: base_Res.topic,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getTopic } from "../../../usecases";
import type { ResResolvers } from "./../../types.generated";

export const ResBase: Omit<ResResolvers, "__resolveType"> = {
export const base_Res: Required<Pick<ResResolvers, "topic">> = {
topic: async (res, _args, context, _info) => {
const topic = await getTopic({ id: res.topicID }, context.ports);
return topic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SetStoragesPayloadResolvers } from './../../types.generated';
export const SetStoragesPayload: SetStoragesPayloadResolvers = {
/* Implement SetStoragesPayload resolver logic here */
};
import type { SetStoragesPayloadResolvers } from "./../../types.generated";
export const SetStoragesPayload: SetStoragesPayloadResolvers = {
/* Implement SetStoragesPayload resolver logic here */
};
8 changes: 4 additions & 4 deletions packages/server/src/schema/storage/resolvers/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StorageResolvers } from './../../types.generated';
export const Storage: StorageResolvers = {
/* Implement Storage resolver logic here */
};
import type { StorageResolvers } from "./../../types.generated";
export const Storage: StorageResolvers = {
/* Implement Storage resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { CreateTokenGeneralResponseResolvers } from "./../../types.generated";
export const CreateTokenGeneralResponse: CreateTokenGeneralResponseResolvers =
{
};
{};
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AtNotFoundError } from "../../../../at-error";
import type { MutationResolvers } from "./../../../types.generated";

export const authTokenReq: NonNullable<MutationResolvers['authTokenReq']> = async (_obj, args, context, _info) => {
export const authTokenReq: NonNullable<
MutationResolvers["authTokenReq"]
> = async (_obj, args, context, _info) => {
const token = await context.ports.tokenRepo.findOne(args.id);
if (token.type !== "general") {
throw new AtNotFoundError("トークンが見つかりません");
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/schema/token/resolvers/Query/token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { QueryResolvers } from "./../../../types.generated";
export const token: NonNullable<QueryResolvers['token']> = async (
export const token: NonNullable<QueryResolvers["token"]> = async (
_obj,
_args,
context,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/schema/token/resolvers/Query/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { QueryResolvers } from "./../../../types.generated";
export const tokens: NonNullable<QueryResolvers['tokens']> = async (
export const tokens: NonNullable<QueryResolvers["tokens"]> = async (
_obj,
_args,
context,
Expand Down
3 changes: 1 addition & 2 deletions packages/server/src/schema/token/resolvers/TokenMaster.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import type { TokenMasterResolvers } from "./../../types.generated";
export const TokenMaster: TokenMasterResolvers = {
};
export const TokenMaster: TokenMasterResolvers = {};
3 changes: 1 addition & 2 deletions packages/server/src/schema/token/resolvers/TokenReq.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import type { TokenReqResolvers } from "./../../types.generated";
export const TokenReq: TokenReqResolvers = {
};
export const TokenReq: TokenReqResolvers = {};
8 changes: 4 additions & 4 deletions packages/server/src/schema/topic/resolvers/Tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TagsResolvers } from './../../types.generated';
export const Tags: TagsResolvers = {
/* Implement Tags resolver logic here */
};
import type { TagsResolvers } from "./../../types.generated";
export const Tags: TagsResolvers = {
/* Implement Tags resolver logic here */
};
4 changes: 2 additions & 2 deletions packages/server/src/schema/topic/resolvers/TopicFork.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getTopic } from "../../../usecases";
import type { TopicForkResolvers } from "./../../types.generated";
import { TopicBase } from "./TopicBase";
import { base_Topic } from "./base_Topic";

export const TopicFork: TopicForkResolvers = {
...TopicBase,
subscribe: base_Topic.subscribe,
parent: async (token, _args, context, _info) => {
const parent = await getTopic({ id: token.parentID }, context.ports);
if (parent.type !== "normal") {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/schema/topic/resolvers/TopicNormal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TopicNormalResolvers } from "./../../types.generated";
import { TopicSearchBase } from "./TopicSearchBase";
import { base_Topic } from "./base_Topic";

export const TopicNormal: TopicNormalResolvers = {
...TopicSearchBase,
subscribe: base_Topic.subscribe,
};
4 changes: 2 additions & 2 deletions packages/server/src/schema/topic/resolvers/TopicOne.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TopicOneResolvers } from "./../../types.generated";
import { TopicSearchBase } from "./TopicSearchBase";
import { base_Topic } from "./base_Topic";

export const TopicOne: TopicOneResolvers = {
...TopicSearchBase,
subscribe: base_Topic.subscribe,
};
6 changes: 0 additions & 6 deletions packages/server/src/schema/topic/resolvers/TopicSearchBase.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TopicResolvers } from "./../../types.generated";
import * as O from "fp-ts/lib/Option";

export const TopicBase: Omit<TopicResolvers, "__resolveType"> = {
export const base_Topic: Required<Pick<TopicResolvers, "subscribe">> = {
subscribe: async (topic, _args, context, _info) => {
// TODO: N+1
const token = context.ports.authContainer.getTokenOrNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreateUserResponseResolvers } from './../../types.generated';
export const CreateUserResponse: CreateUserResponseResolvers = {
/* Implement CreateUserResponse resolver logic here */
};
import type { CreateUserResponseResolvers } from "./../../types.generated";
export const CreateUserResponse: CreateUserResponseResolvers = {
/* Implement CreateUserResponse resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UpdateUserResponseResolvers } from './../../types.generated';
export const UpdateUserResponse: UpdateUserResponseResolvers = {
/* Implement UpdateUserResponse resolver logic here */
};
import type { UpdateUserResponseResolvers } from "./../../types.generated";
export const UpdateUserResponse: UpdateUserResponseResolvers = {
/* Implement UpdateUserResponse resolver logic here */
};
8 changes: 4 additions & 4 deletions packages/server/src/schema/user/resolvers/User.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserResolvers } from './../../types.generated';
export const User: UserResolvers = {
/* Implement User resolver logic here */
};
import type { UserResolvers } from "./../../types.generated";
export const User: UserResolvers = {
/* Implement User resolver logic here */
};

0 comments on commit 9c32166

Please sign in to comment.