Skip to content
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

Exp: Integration producing EncodedResponse interface #2226

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3e19dc9
Deprecating splitResponse, always do it.
RobinTail Dec 1, 2024
f281ff0
rm redundant condition.
RobinTail Dec 1, 2024
492451f
Splitting positive response further to the status codes.
RobinTail Dec 1, 2024
51d0dba
Removing the prop from readme.
RobinTail Dec 1, 2024
7bb9263
Changelog: 21.3.0.
RobinTail Dec 1, 2024
d19f61c
Merge branch 'always-split-response' into emphasise-status-code
RobinTail Dec 1, 2024
d41869c
Ref: organizing ids, shortening pushes.
RobinTail Dec 1, 2024
e93b65c
Ref: combining makeCleanId() calls.
RobinTail Dec 1, 2024
15d5032
Merge branch 'always-split-response' into emphasise-status-code
RobinTail Dec 1, 2024
2458fe3
Fix making dict once.
RobinTail Dec 1, 2024
789757c
Making right order.
RobinTail Dec 1, 2024
7bd61aa
Ref: less repeats.
RobinTail Dec 1, 2024
de4aea2
Ref: moving ctx creation outta walker.
RobinTail Dec 1, 2024
d688ac2
Merge branch 'always-split-response' into emphasise-status-code
RobinTail Dec 1, 2024
32dc29a
Minor: naming.
RobinTail Dec 1, 2024
e66a28e
mv: ids making to top.
RobinTail Dec 1, 2024
94d1369
Merge branch 'always-split-response' into emphasise-status-code
RobinTail Dec 1, 2024
02b911b
Merge branch 'master' into always-split-response
RobinTail Dec 2, 2024
8f841e8
Merge branch 'always-split-response' into emphasise-status-code
RobinTail Dec 2, 2024
339e94a
Merge branch 'master' into emphasise-status-code
RobinTail Dec 2, 2024
5c9098b
Merge branch 'master' into emphasise-status-code
RobinTail Dec 2, 2024
831bd86
Merge branch 'master' into emphasise-status-code
RobinTail Dec 2, 2024
6ec5d4e
Reusing makeKeyOf().
RobinTail Dec 2, 2024
5968fee
Introducing SomeOf<> helper type for readability.
RobinTail Dec 2, 2024
6a21cfc
Handling both positive and negative response.
RobinTail Dec 2, 2024
4278e03
Ref: no extra method.
RobinTail Dec 2, 2024
00020ac
Minor: naming.
RobinTail Dec 2, 2024
bf82247
Ref: enumerating variants from 1.
RobinTail Dec 2, 2024
911e185
Merge branch 'master' into emphasise-status-code
RobinTail Dec 2, 2024
507da7d
Merge branch 'master' into emphasise-status-code
RobinTail Dec 3, 2024
415e47d
todo.
RobinTail Dec 3, 2024
eca992a
Merge branch 'master' into emphasise-status-code
RobinTail Dec 3, 2024
a68397f
Merge branch 'master' into emphasise-status-code
RobinTail Dec 3, 2024
7d4e601
Accept string in makePublicInterface.
RobinTail Dec 3, 2024
a50bafa
mv: makeInterface, no only public.
RobinTail Dec 3, 2024
330ea2e
Merge branch 'master' into emphasise-status-code
RobinTail Dec 3, 2024
9b9fdf9
Introducing encoded response types.
RobinTail Dec 3, 2024
c93f6af
FEAT: exposing EncodedResponse interface.
RobinTail Dec 3, 2024
5d86398
Ref: extracting const for readability.
RobinTail Dec 3, 2024
0ce05c0
Merge branch 'master' into emphasise-status-code
RobinTail Dec 3, 2024
1728b98
Merge branch 'master' into emphasise-status-code
RobinTail Dec 4, 2024
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
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default tsPlugin.config(
},
{
selector: "Identifier[name='createInterfaceDeclaration']",
message: "use makePublicInterface() helper",
message: "use makeInterface() helper",
},
{
selector: "Identifier[name='createClassDeclaration']",
Expand Down
225 changes: 200 additions & 25 deletions example/example.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ type Type1 = {
features: Type1;
}[];

export type SomeOf<T> = T[keyof T];

type GetV1UserRetrieveInput = {
/** a numeric string containing the id of the user */
id: string;
};

type GetV1UserRetrievePositiveResponse = {
type GetV1UserRetrievePositiveVariant1 = {
status: "success";
data: {
id: number;
Expand All @@ -20,13 +22,31 @@ type GetV1UserRetrievePositiveResponse = {
};
};

type GetV1UserRetrieveNegativeResponse = {
interface GetV1UserRetrievePositiveResponseVariants {
200: GetV1UserRetrievePositiveVariant1;
}

type GetV1UserRetrievePositiveResponse =
SomeOf<GetV1UserRetrievePositiveResponseVariants>;

type GetV1UserRetrieveNegativeVariant1 = {
status: "error";
error: {
message: string;
};
};

interface GetV1UserRetrieveNegativeResponseVariants {
400: GetV1UserRetrieveNegativeVariant1;
}

type GetV1UserRetrieveNegativeResponse =
SomeOf<GetV1UserRetrieveNegativeResponseVariants>;

type GetV1UserRetrieveEncodedResponse =
GetV1UserRetrievePositiveResponseVariants &
GetV1UserRetrieveNegativeResponseVariants;

type GetV1UserRetrieveResponse =
| GetV1UserRetrievePositiveResponse
| GetV1UserRetrieveNegativeResponse;
Expand All @@ -36,9 +56,27 @@ type DeleteV1UserIdRemoveInput = {
id: string;
};

type DeleteV1UserIdRemovePositiveResponse = undefined;
type DeleteV1UserIdRemovePositiveVariant1 = undefined;

interface DeleteV1UserIdRemovePositiveResponseVariants {
204: DeleteV1UserIdRemovePositiveVariant1;
}

type DeleteV1UserIdRemovePositiveResponse =
SomeOf<DeleteV1UserIdRemovePositiveResponseVariants>;

type DeleteV1UserIdRemoveNegativeVariant1 = undefined;

interface DeleteV1UserIdRemoveNegativeResponseVariants {
404: DeleteV1UserIdRemoveNegativeVariant1;
}

type DeleteV1UserIdRemoveNegativeResponse = undefined;
type DeleteV1UserIdRemoveNegativeResponse =
SomeOf<DeleteV1UserIdRemoveNegativeResponseVariants>;

type DeleteV1UserIdRemoveEncodedResponse =
DeleteV1UserIdRemovePositiveResponseVariants &
DeleteV1UserIdRemoveNegativeResponseVariants;

type DeleteV1UserIdRemoveResponse =
| DeleteV1UserIdRemovePositiveResponse
Expand All @@ -51,21 +89,38 @@ type PatchV1UserIdInput = {
birthday: string;
};

type PatchV1UserIdPositiveResponse = {
type PatchV1UserIdPositiveVariant1 = {
status: "success";
data: {
name: string;
createdAt: string;
};
};

type PatchV1UserIdNegativeResponse = {
interface PatchV1UserIdPositiveResponseVariants {
200: PatchV1UserIdPositiveVariant1;
}

type PatchV1UserIdPositiveResponse =
SomeOf<PatchV1UserIdPositiveResponseVariants>;

type PatchV1UserIdNegativeVariant1 = {
status: "error";
error: {
message: string;
};
};

interface PatchV1UserIdNegativeResponseVariants {
400: PatchV1UserIdNegativeVariant1;
}

type PatchV1UserIdNegativeResponse =
SomeOf<PatchV1UserIdNegativeResponseVariants>;

type PatchV1UserIdEncodedResponse = PatchV1UserIdPositiveResponseVariants &
PatchV1UserIdNegativeResponseVariants;

type PatchV1UserIdResponse =
| PatchV1UserIdPositiveResponse
| PatchV1UserIdNegativeResponse;
Expand All @@ -74,34 +129,72 @@ type PostV1UserCreateInput = {
name: string;
};

type PostV1UserCreatePositiveResponse = {
type PostV1UserCreatePositiveVariant1 = {
status: "created";
data: {
id: number;
};
};

interface PostV1UserCreatePositiveResponseVariants {
201: PostV1UserCreatePositiveVariant1;
202: PostV1UserCreatePositiveVariant1;
}

type PostV1UserCreatePositiveResponse =
SomeOf<PostV1UserCreatePositiveResponseVariants>;

type PostV1UserCreateNegativeVariant1 = {
status: "exists";
id: number;
};

type PostV1UserCreateNegativeVariant2 = {
status: "error";
reason: string;
};

interface PostV1UserCreateNegativeResponseVariants {
409: PostV1UserCreateNegativeVariant1;
400: PostV1UserCreateNegativeVariant2;
500: PostV1UserCreateNegativeVariant2;
}

type PostV1UserCreateNegativeResponse =
| {
status: "exists";
id: number;
}
| {
status: "error";
reason: string;
};
SomeOf<PostV1UserCreateNegativeResponseVariants>;

type PostV1UserCreateEncodedResponse =
PostV1UserCreatePositiveResponseVariants &
PostV1UserCreateNegativeResponseVariants;

type PostV1UserCreateResponse =
| PostV1UserCreatePositiveResponse
| PostV1UserCreateNegativeResponse;

type GetV1UserListInput = {};

type GetV1UserListPositiveResponse = {
type GetV1UserListPositiveVariant1 = {
name: string;
}[];

type GetV1UserListNegativeResponse = string;
interface GetV1UserListPositiveResponseVariants {
200: GetV1UserListPositiveVariant1;
}

type GetV1UserListPositiveResponse =
SomeOf<GetV1UserListPositiveResponseVariants>;

type GetV1UserListNegativeVariant1 = string;

interface GetV1UserListNegativeResponseVariants {
400: GetV1UserListNegativeVariant1;
}

type GetV1UserListNegativeResponse =
SomeOf<GetV1UserListNegativeResponseVariants>;

type GetV1UserListEncodedResponse = GetV1UserListPositiveResponseVariants &
GetV1UserListNegativeResponseVariants;

type GetV1UserListResponse =
| GetV1UserListPositiveResponse
Expand All @@ -111,9 +204,26 @@ type GetV1AvatarSendInput = {
userId: string;
};

type GetV1AvatarSendPositiveResponse = string;
type GetV1AvatarSendPositiveVariant1 = string;

interface GetV1AvatarSendPositiveResponseVariants {
200: GetV1AvatarSendPositiveVariant1;
}

type GetV1AvatarSendPositiveResponse =
SomeOf<GetV1AvatarSendPositiveResponseVariants>;

type GetV1AvatarSendNegativeVariant1 = string;

type GetV1AvatarSendNegativeResponse = string;
interface GetV1AvatarSendNegativeResponseVariants {
400: GetV1AvatarSendNegativeVariant1;
}

type GetV1AvatarSendNegativeResponse =
SomeOf<GetV1AvatarSendNegativeResponseVariants>;

type GetV1AvatarSendEncodedResponse = GetV1AvatarSendPositiveResponseVariants &
GetV1AvatarSendNegativeResponseVariants;

type GetV1AvatarSendResponse =
| GetV1AvatarSendPositiveResponse
Expand All @@ -123,9 +233,27 @@ type GetV1AvatarStreamInput = {
userId: string;
};

type GetV1AvatarStreamPositiveResponse = Buffer;
type GetV1AvatarStreamPositiveVariant1 = Buffer;

interface GetV1AvatarStreamPositiveResponseVariants {
200: GetV1AvatarStreamPositiveVariant1;
}

type GetV1AvatarStreamPositiveResponse =
SomeOf<GetV1AvatarStreamPositiveResponseVariants>;

type GetV1AvatarStreamNegativeVariant1 = string;

interface GetV1AvatarStreamNegativeResponseVariants {
400: GetV1AvatarStreamNegativeVariant1;
}

type GetV1AvatarStreamNegativeResponse = string;
type GetV1AvatarStreamNegativeResponse =
SomeOf<GetV1AvatarStreamNegativeResponseVariants>;

type GetV1AvatarStreamEncodedResponse =
GetV1AvatarStreamPositiveResponseVariants &
GetV1AvatarStreamNegativeResponseVariants;

type GetV1AvatarStreamResponse =
| GetV1AvatarStreamPositiveResponse
Expand All @@ -135,7 +263,7 @@ type PostV1AvatarUploadInput = {
avatar: any;
};

type PostV1AvatarUploadPositiveResponse = {
type PostV1AvatarUploadPositiveVariant1 = {
status: "success";
data: {
name: string;
Expand All @@ -146,33 +274,68 @@ type PostV1AvatarUploadPositiveResponse = {
};
};

type PostV1AvatarUploadNegativeResponse = {
interface PostV1AvatarUploadPositiveResponseVariants {
200: PostV1AvatarUploadPositiveVariant1;
}

type PostV1AvatarUploadPositiveResponse =
SomeOf<PostV1AvatarUploadPositiveResponseVariants>;

type PostV1AvatarUploadNegativeVariant1 = {
status: "error";
error: {
message: string;
};
};

interface PostV1AvatarUploadNegativeResponseVariants {
400: PostV1AvatarUploadNegativeVariant1;
}

type PostV1AvatarUploadNegativeResponse =
SomeOf<PostV1AvatarUploadNegativeResponseVariants>;

type PostV1AvatarUploadEncodedResponse =
PostV1AvatarUploadPositiveResponseVariants &
PostV1AvatarUploadNegativeResponseVariants;

type PostV1AvatarUploadResponse =
| PostV1AvatarUploadPositiveResponse
| PostV1AvatarUploadNegativeResponse;

type PostV1AvatarRawInput = Buffer;

type PostV1AvatarRawPositiveResponse = {
type PostV1AvatarRawPositiveVariant1 = {
status: "success";
data: {
length: number;
};
};

type PostV1AvatarRawNegativeResponse = {
interface PostV1AvatarRawPositiveResponseVariants {
200: PostV1AvatarRawPositiveVariant1;
}

type PostV1AvatarRawPositiveResponse =
SomeOf<PostV1AvatarRawPositiveResponseVariants>;

type PostV1AvatarRawNegativeVariant1 = {
status: "error";
error: {
message: string;
};
};

interface PostV1AvatarRawNegativeResponseVariants {
400: PostV1AvatarRawNegativeVariant1;
}

type PostV1AvatarRawNegativeResponse =
SomeOf<PostV1AvatarRawNegativeResponseVariants>;

type PostV1AvatarRawEncodedResponse = PostV1AvatarRawPositiveResponseVariants &
PostV1AvatarRawNegativeResponseVariants;

type PostV1AvatarRawResponse =
| PostV1AvatarRawPositiveResponse
| PostV1AvatarRawNegativeResponse;
Expand Down Expand Up @@ -226,6 +389,18 @@ export interface NegativeResponse {
"post /v1/avatar/raw": PostV1AvatarRawNegativeResponse;
}

export interface EncodedResponse {
"get /v1/user/retrieve": GetV1UserRetrieveEncodedResponse;
"delete /v1/user/:id/remove": DeleteV1UserIdRemoveEncodedResponse;
"patch /v1/user/:id": PatchV1UserIdEncodedResponse;
"post /v1/user/create": PostV1UserCreateEncodedResponse;
"get /v1/user/list": GetV1UserListEncodedResponse;
"get /v1/avatar/send": GetV1AvatarSendEncodedResponse;
"get /v1/avatar/stream": GetV1AvatarStreamEncodedResponse;
"post /v1/avatar/upload": PostV1AvatarUploadEncodedResponse;
"post /v1/avatar/raw": PostV1AvatarRawEncodedResponse;
}

export interface Response {
"get /v1/user/retrieve": GetV1UserRetrieveResponse;
"delete /v1/user/:id/remove": DeleteV1UserIdRemoveResponse;
Expand Down
Loading
Loading