Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octokit-next/types

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit-next/types - npm Package Compare versions

Comparing version 1.12.0 to 1.13.0

108

index.d.ts

@@ -157,55 +157,56 @@ import { RequestInterface } from "./request";

* Do not extend this interface in order to use it with GitHub Enterprise Server or AE. Extend ApiVersions[version] instead.
*
* @example
*
* ```ts
* "GET /": {
* parameters: {};
* request: {
* method: "GET";
* url: "/";
* headers: Octokit.RequestHeaders;
* request: Octokit.RequestOptions;
* };
* response: Octokit.Response<
* {
* current_user_url: string;
* current_user_authorizations_html_url: string;
* authorizations_url: string;
* code_search_url: string;
* commit_search_url: string;
* emails_url: string;
* emojis_url: string;
* events_url: string;
* feeds_url: string;
* followers_url: string;
* following_url: string;
* gists_url: string;
* hub_url: string;
* issue_search_url: string;
* issues_url: string;
* keys_url: string;
* label_search_url: string;
* notifications_url: string;
* organization_url: string;
* organization_repositories_url: string;
* organization_teams_url: string;
* public_gists_url: string;
* rate_limit_url: string;
* repository_url: string;
* repository_search_url: string;
* current_user_repositories_url: string;
* starred_url: string;
* starred_gists_url: string;
* topic_search_url?: string;
* user_url: string;
* user_organizations_url: string;
* user_repositories_url: string;
* user_search_url: string;
* },
* 200
* >;
* };
* ```
*/
interface Endpoints {
/**
* GitHub's root api endpoint. If this is the only endpoint you see, install and import one of the `@octokit-next/types-rest-api-*` packages.
*/
"GET /": {
parameters: {};
request: {
method: "GET";
url: "/";
headers: Octokit.RequestHeaders;
request: Octokit.RequestOptions;
};
response: Octokit.Response<
{
current_user_url: string;
current_user_authorizations_html_url: string;
authorizations_url: string;
code_search_url: string;
commit_search_url: string;
emails_url: string;
emojis_url: string;
events_url: string;
feeds_url: string;
followers_url: string;
following_url: string;
gists_url: string;
hub_url: string;
issue_search_url: string;
issues_url: string;
keys_url: string;
label_search_url: string;
notifications_url: string;
organization_url: string;
organization_repositories_url: string;
organization_teams_url: string;
public_gists_url: string;
rate_limit_url: string;
repository_url: string;
repository_search_url: string;
current_user_repositories_url: string;
starred_url: string;
starred_gists_url: string;
topic_search_url?: string;
user_url: string;
user_organizations_url: string;
user_repositories_url: string;
user_search_url: string;
},
200
>;
};
}
interface Endpoints {}

@@ -387,3 +388,4 @@ /**

OctokitClass & ApplyPlugins<OctokitExtensions["plugins"]>,
OrObject<OctokitClass["options"], unknown>
OrObject<OctokitClass["options"], unknown>,
OctokitClass["options"]["version"]
> &

@@ -390,0 +392,0 @@ ApplyPlugins<OctokitExtensions["plugins"]> & {

@@ -7,3 +7,3 @@ {

"type": "module",
"version": "1.12.0",
"version": "1.13.0",
"description": "Shared TypeScript definitions for upcoming Octokit SDK",

@@ -10,0 +10,0 @@ "types": "./index.d.ts",

@@ -1,2 +0,1 @@

import { ConditionalKeys } from "type-fest";
import { Octokit } from "./index.js";

@@ -43,17 +42,8 @@

/**
* ⚠️🚫 Known endpoint, but not supported by the selected version.
* Send a request to a known endpoint for the version specified in `request.version`.
*
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
* @param {object} parameters URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
*
* @deprecated not really deprecated, but it's the only way to give a visual hint that you cannot use `request` with this route and version
*/
<
RVersion extends keyof Octokit.ApiVersions,
Route extends ConditionalKeys<
Octokit.ApiVersions[RVersion]["Endpoints"],
never
>,
Endpoint = Octokit.ApiVersions[RVersion]["Endpoints"][Route]
>(
<Route extends AllKnownRoutes, RVersion extends VersionsByRoute[Route]>(
route: Route,

@@ -64,7 +54,11 @@ options: {

};
} & Record<string, unknown>
): never;
} & (Route extends keyof ParametersByVersionAndRoute[RVersion]
? ParametersByVersionAndRoute[RVersion][Route]
: never)
): Route extends keyof ResponseByVersionAndRoute[RVersion]
? ResponseByVersionAndRoute[RVersion][Route]
: never;
/**
* Send a request to a known endpoint using a version specified in `request.version`.
* Send a request to a known endpoint
*

@@ -74,23 +68,32 @@ * @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`

*/
<
RVersion extends keyof Octokit.ApiVersions,
Route extends ConditionalKeysOmit<
Octokit.ApiVersions[RVersion]["Endpoints"],
never
>,
Endpoint = Octokit.ApiVersions[RVersion]["Endpoints"][Route]
>(
route: Route,
options: {
request: {
version: RVersion;
};
} & ("parameters" extends keyof Endpoint
? Endpoint["parameters"] & EndpointParameters<RVersion>
: Record<string, unknown>)
): "response" extends keyof Endpoint ? Promise<Endpoint["response"]> : never;
<Route extends AllKnownRoutes>(
...options: ArgumentsTypesForRoute<
Route,
// if given route is supported by current version
TVersion extends keyof ParametersByVersionAndRoute
? // then set parameter types based on version and route
Route extends keyof ParametersByVersionAndRoute[TVersion]
? ParametersByVersionAndRoute[TVersion][Route]
: // otherwise set parameter types to { request: { version } } where
// version must be set to one of the supported versions for the route.
// Once that happened, the above override will take over and require
// the types for the remaining options.
{
request: {
version: VersionsByRoute[Route];
};
}
: never
>
): Route extends keyof ResponseByVersionAndRoute[TVersion]
? ResponseByVersionAndRoute[TVersion][Route]
: never;
/**
* Send a request to an unknown endpoint
* It looks like you haven't imported any `@octokit-next/types-rest-api*` packages yet.
* You are missing out!
*
* Install `@octokit-next/types-rest-api` and import the types to give it a try.
* Learn more at https://github.com/octokit/types-rest-api.ts
*
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`

@@ -100,58 +103,136 @@ * @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.

<Route extends string>(
route: Route extends keyof Octokit.ApiVersions[TVersion]["Endpoints"]
? never
: Route,
options?: Record<string, unknown>
...options: keyof Octokit.Endpoints extends never
? [Route, Record<string, unknown>?]
: []
): Promise<UnknownResponse>;
}
/**
* ⚠️🚫 Known endpoint, but not supported by the selected version.
*
* @param {string} unsupportedRoute Request method + URL. Example: `'GET /orgs/{org}'`
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
*
* @deprecated not really deprecated, but it's the only way to give a visual hint that you cannot use `request` with this route and version
*/
<
Route extends ConditionalKeys<
Octokit.ApiVersions[TVersion]["Endpoints"],
never
>
>(
unsupportedRoute: Route,
options?: never
): never;
/**
* optimized type to lookup all known routes and the versions they are supported in.
*
* @example
*
* ```ts
* // import REST API types for github.com, GHES 3.2 and GHES 3.1
* import "@octokit-next/types-rest-api-ghes-3.1";
* ```
*
* The `Octokit.ApiVersions` interface is now looking like this (simplified)
*
* ```ts
* {
* "github.com": { "GET /": { … } },
* "ghes-3.1": { "GET /": { … }, "GET /admin/tokens": { … } },
* "ghes-3.2": { "GET /": { … }, "GET /admin/tokens": { … } }
* }
* ```
*
* The `VersionsByRoute` as a result looks like this
*
* ```ts
* {
* "GET /": "github.com" | "ghes-3.1" | "ghes-3.2",
* "GET /admin/tokens": "ghes-3.1" | "ghes-3.2"
* }
* ```
*/
type VersionsByRoute = Remap<EndpointsByVersion>;
/**
* Send a request to a known endpoint
*
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
*/
<
Route extends ConditionalKeysOmit<
Octokit.ApiVersions[TVersion]["Endpoints"],
never
>,
Endpoint = Octokit.ApiVersions[TVersion]["Endpoints"][Route]
>(
route: Route,
options?: "parameters" extends keyof Endpoint
? Endpoint["parameters"] & EndpointParameters<TVersion>
: Record<string, unknown>
): "response" extends keyof Endpoint ? Promise<Endpoint["response"]> : never;
}
// types to improve performance of type lookups
type ConditionalKeysOmit<Base, Condition> = NonNullable<
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
{
// Map through all the keys of the given base type.
[Key in keyof Base]: Base[Key] extends Condition // Omit keys with types extending the given `Condition` type.
? // Discard this key since the condition passes.
never
: // Retain this key since the condition fails.
Key;
/**
* All known routes across all defined API versions for fast lookup
*/
type AllKnownRoutes = keyof VersionsByRoute;
// Convert the produced object into a union type of the keys which passed the conditional test.
}[keyof Base]
>;
/**
* turn
*
* ```ts
* { [version]: { Endpoints: { [route]: Endpoint } } }
* ```
*
* into
*
* ```ts
* { [version]: { [route]: Endpoint } }
* ```
*/
type EndpointsByVersion = {
[Version in keyof Octokit.ApiVersions]: "Endpoints" extends keyof Octokit.ApiVersions[Version]
? Octokit.ApiVersions[Version]["Endpoints"]
: never;
};
/**
* turn
*
* ```ts
* { [version]: { [route]: { parameters: Parameters } } }
* ```
*
* into
*
* ```ts
* { [version]: { [route]: Parameters } }
* ```
*/
type ParametersByVersionAndRoute = {
[Version in keyof EndpointsByVersion]: {
[Route in keyof EndpointsByVersion[Version]]: "parameters" extends keyof EndpointsByVersion[Version][Route]
? EndpointsByVersion[Version][Route]["parameters"]
: never;
};
};
/**
* turn
*
* ```ts
* { [version]: { [route]: { response: Response } } }
* ```
*
* into
*
* ```ts
* { [version]: { [route]: Response } }
* ```
*/
type ResponseByVersionAndRoute = {
[Version in keyof EndpointsByVersion]: {
[Route in keyof EndpointsByVersion[Version]]: "response" extends keyof EndpointsByVersion[Version][Route]
? EndpointsByVersion[Version][Route]["response"]
: never;
};
};
// helpers
/**
* Generic type to remap
*
* ```ts
* { k1: { k2: v }}
* ```
*
* ```ts
* { k2: k1[]}
* ```
*/
type Remap<T extends EndpointsByVersion> = {
[P in keyof T as keyof T[P]]: P;
};
/**
* Generic to find out if an object type has any required keys
*/
type NonOptionalKeys<Obj> = {
[K in keyof Obj]: {} extends Pick<Obj, K> ? undefined : K;
}[keyof Obj];
type ArgumentsTypesForRoute<
Route extends string,
Parameters extends Record<string, unknown>
> = NonOptionalKeys<Parameters> extends undefined
? [Route, Parameters?]
: [Route, Parameters];
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc