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

🚧 feat: endpoint #37

Merged
merged 23 commits into from
Oct 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9daf7bc
docs(endpoint): README from https://github.com/octokit/endpoint.js/tr…
gr2m Sep 15, 2021
5ce02b7
docs(endpoint): updates for `@octokit-next/` and docs.github.com
gr2m Sep 15, 2021
1ed9b70
replace `require` with `import`
gr2m Sep 15, 2021
14dc347
test: original `.ts` Jest tests from `@octokit/endpoint`
gr2m Sep 16, 2021
8a89053
build(release): add `packages/endpoint` to `@semantic-release/npm` co…
gr2m Sep 16, 2021
0f519c1
test: run tests in workspaces as part of `npm test` in root
gr2m Sep 16, 2021
96aa0eb
build(endpoint): package.json
gr2m Sep 16, 2021
e697e99
build(package): lock file
gr2m Sep 16, 2021
016adfe
code & tests
gr2m Sep 16, 2021
bc91550
fix `test` script
gr2m Sep 16, 2021
317594a
feat: add `RequestHeaders` to `Octokit.ApiVersions[version]` keys
gr2m Sep 16, 2021
eebaf96
wip
gr2m Sep 16, 2021
ec28511
docs: update ToC for packages/endpoint/README.md
prettier-toc-me[bot] Sep 16, 2021
5138a8e
build(package): lock file
gr2m Oct 5, 2021
f40a627
test(endpoint): test types when running `npm test`
gr2m Oct 5, 2021
43a3e44
test(endpoint): fix types tests
gr2m Oct 5, 2021
b17bd9c
test(endpoint): `requestOptions.data`
gr2m Oct 5, 2021
4e4d83f
types(endpoint): adapt to new type system
gr2m Oct 5, 2021
c95105e
types(endpoint): fixies
gr2m Oct 5, 2021
e19c7a8
build(package): lock file
gr2m Oct 6, 2021
2449833
build(endpoint): add `type-fest` as dependency
gr2m Oct 6, 2021
c737af2
types(endpoint): make type tests pass
gr2m Oct 6, 2021
f62eefa
feat(core): `octokit.endpoint`
gr2m Oct 6, 2021
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
Prev Previous commit
Next Next commit
types(endpoint): make type tests pass
gr2m committed Oct 6, 2021

Verified

This commit was signed with the committer’s verified signature.
folke Folke Lemaitre
commit c737af2474c125013c26fc1ecd6c397ea99a908b
4 changes: 3 additions & 1 deletion packages/endpoint/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -40,5 +40,7 @@ export function ghesExample() {
expectType<string>(requestOptions.headers["user-agent"]);
expectType<string | undefined>(requestOptions.headers["authorization"]);

expectType<Record<string, string>>(requestOptions.data);
expectType<{
login: string;
}>(requestOptions.data);
}
22 changes: 16 additions & 6 deletions packages/types-rest-api/operation.d.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ type KnownJsonResponseTypes =
| "text/html"
| "text/plain"; // GET /zen

type ReadOnlyMethods = "get" | "head";

export type Operation<
paths extends Record<string, any>,
Method extends keyof paths[Url],
@@ -20,12 +22,20 @@ export type Operation<
parameters: Simplify<
ToOctokitParameters<paths[Url][Method]> & RequiredPreview<preview>
>;
request: {
method: Method extends string ? Uppercase<Method> : never;
url: Url;
headers: Octokit.RequestHeaders;
request: Octokit.RequestOptions;
};
request: Method extends ReadOnlyMethods
? {
method: Method extends string ? Uppercase<Method> : never;
url: Url;
headers: Octokit.RequestHeaders;
request: Octokit.RequestOptions;
}
: {
method: Method extends string ? Uppercase<Method> : never;
url: Url;
headers: Octokit.RequestHeaders;
request: Octokit.RequestOptions;
data: ExtractRequestBody<paths[Url][Method]>;
};
response: ExtractOctokitResponse<paths[Url][Method]>;
};

8 changes: 6 additions & 2 deletions packages/types/endpoint.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SetRequired } from "type-fest";

import { Octokit } from "./index.js";

/**
@@ -169,7 +171,7 @@ type ParametersByVersionAndRoute = {
[Version in keyof EndpointsByVersion]: {
[Route in keyof EndpointsByVersion[Version]]: "parameters" extends keyof EndpointsByVersion[Version][Route]
? EndpointsByVersion[Version][Route]["parameters"] & {
headers: Octokit.ApiVersions[Version]["RequestHeaders"];
headers?: Octokit.RequestHeaders;
}
: never;
};
@@ -191,7 +193,9 @@ type ParametersByVersionAndRoute = {
type RequestByVersionAndRoute = {
[Version in keyof EndpointsByVersion]: {
[Route in keyof EndpointsByVersion[Version]]: "request" extends keyof EndpointsByVersion[Version][Route]
? EndpointsByVersion[Version][Route]["request"]
? EndpointsByVersion[Version][Route]["request"] & {
headers: SetRequired<Octokit.RequestHeaders, "accept" | "user-agent">;
}
: never;
};
};