@octokit/core
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -11,3 +11,3 @@ 'use strict'; | ||
const VERSION = "2.1.0"; | ||
const VERSION = "2.1.1"; | ||
@@ -86,8 +86,9 @@ class Octokit { | ||
static defaults(defaults) { | ||
return class OctokitWithDefaults extends this { | ||
constructor(options = {}) { | ||
super(Object.assign({}, defaults, options)); | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
super(Object.assign({}, defaults, args[0] || {})); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
} | ||
@@ -94,0 +95,0 @@ |
@@ -80,7 +80,8 @@ import { getUserAgent } from "universal-user-agent"; | ||
static defaults(defaults) { | ||
return class OctokitWithDefaults extends this { | ||
constructor(options = {}) { | ||
super(Object.assign({}, defaults, options)); | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
super(Object.assign({}, defaults, args[0] || {})); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
} | ||
@@ -87,0 +88,0 @@ static plugin(pluginOrPlugins) { |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "2.1.0"; | ||
export const VERSION = "2.1.1"; |
@@ -7,73 +7,16 @@ import { HookCollection } from "before-after-hook"; | ||
export declare class Octokit { | ||
static defaults(defaults: OctokitOptions): { | ||
new (options?: OctokitOptions): { | ||
request: import("@octokit/types").RequestInterface; | ||
graphql: import("@octokit/graphql/dist-types/types").graphql; | ||
log: { | ||
[key: string]: any; | ||
debug: (message: string, additionalInfo?: object | undefined) => any; | ||
info: (message: string, additionalInfo?: object | undefined) => any; | ||
warn: (message: string, additionalInfo?: object | undefined) => any; | ||
error: (message: string, additionalInfo?: object | undefined) => any; | ||
}; | ||
hook: HookCollection; | ||
auth: (...args: unknown[]) => Promise<unknown>; | ||
static defaults<S extends Constructor<any>>(this: S, defaults: OctokitOptions): { | ||
new (...args: any[]): { | ||
[x: string]: any; | ||
}; | ||
defaults(defaults: OctokitOptions): any; | ||
plugins: OctokitPlugin[]; | ||
plugin<T extends OctokitPlugin | OctokitPlugin[]>(pluginOrPlugins: T): { | ||
new (options?: OctokitOptions): { | ||
request: import("@octokit/types").RequestInterface; | ||
graphql: import("@octokit/graphql/dist-types/types").graphql; | ||
log: { | ||
[key: string]: any; | ||
debug: (message: string, additionalInfo?: object | undefined) => any; | ||
info: (message: string, additionalInfo?: object | undefined) => any; | ||
warn: (message: string, additionalInfo?: object | undefined) => any; | ||
error: (message: string, additionalInfo?: object | undefined) => any; | ||
}; | ||
hook: HookCollection; | ||
auth: (...args: unknown[]) => Promise<unknown>; | ||
}; | ||
plugins: OctokitPlugin[]; | ||
defaults(defaults: OctokitOptions): any; | ||
plugin<T extends OctokitPlugin | OctokitPlugin[]>(pluginOrPlugins: T): any & Constructor<ReturnTypeOf<T>>; | ||
} & Constructor<ReturnTypeOf<T>>; | ||
}; | ||
} & S; | ||
static plugins: OctokitPlugin[]; | ||
static plugin<T extends OctokitPlugin | OctokitPlugin[]>(pluginOrPlugins: T): { | ||
new (options?: OctokitOptions): { | ||
request: import("@octokit/types").RequestInterface; | ||
graphql: import("@octokit/graphql/dist-types/types").graphql; | ||
log: { | ||
[key: string]: any; | ||
debug: (message: string, additionalInfo?: object | undefined) => any; | ||
info: (message: string, additionalInfo?: object | undefined) => any; | ||
warn: (message: string, additionalInfo?: object | undefined) => any; | ||
error: (message: string, additionalInfo?: object | undefined) => any; | ||
}; | ||
hook: HookCollection; | ||
auth: (...args: unknown[]) => Promise<unknown>; | ||
static plugin<S extends Constructor<any> & { | ||
plugins: any[]; | ||
}, T extends OctokitPlugin | OctokitPlugin[]>(this: S, pluginOrPlugins: T): { | ||
new (...args: any[]): { | ||
[x: string]: any; | ||
}; | ||
plugins: OctokitPlugin[]; | ||
defaults(defaults: OctokitOptions): { | ||
new (options?: OctokitOptions): { | ||
request: import("@octokit/types").RequestInterface; | ||
graphql: import("@octokit/graphql/dist-types/types").graphql; | ||
log: { | ||
[key: string]: any; | ||
debug: (message: string, additionalInfo?: object | undefined) => any; | ||
info: (message: string, additionalInfo?: object | undefined) => any; | ||
warn: (message: string, additionalInfo?: object | undefined) => any; | ||
error: (message: string, additionalInfo?: object | undefined) => any; | ||
}; | ||
hook: HookCollection; | ||
auth: (...args: unknown[]) => Promise<unknown>; | ||
}; | ||
defaults(defaults: OctokitOptions): any; | ||
plugins: OctokitPlugin[]; | ||
plugin<T_1 extends OctokitPlugin | OctokitPlugin[]>(pluginOrPlugins: T): any & Constructor<ReturnTypeOf<T>>; | ||
}; | ||
plugin<T_1 extends OctokitPlugin | OctokitPlugin[]>(pluginOrPlugins: T): any & Constructor<ReturnTypeOf<T>>; | ||
} & Constructor<ReturnTypeOf<T>>; | ||
plugins: any[]; | ||
} & S & Constructor<ReturnTypeOf<T>>; | ||
constructor(options?: OctokitOptions); | ||
@@ -80,0 +23,0 @@ request: typeof request; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "2.1.0"; | ||
export declare const VERSION = "2.1.1"; |
@@ -7,3 +7,3 @@ import { getUserAgent } from 'universal-user-agent'; | ||
const VERSION = "2.1.0"; | ||
const VERSION = "2.1.1"; | ||
@@ -83,7 +83,8 @@ class Octokit { | ||
static defaults(defaults) { | ||
return class OctokitWithDefaults extends this { | ||
constructor(options = {}) { | ||
super(Object.assign({}, defaults, options)); | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
super(Object.assign({}, defaults, args[0] || {})); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
} | ||
@@ -90,0 +91,0 @@ static plugin(pluginOrPlugins) { |
{ | ||
"name": "@octokit/core", | ||
"description": "Extendable client for GitHub's REST & GraphQL APIs", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "files": [ |
@@ -21,3 +21,2 @@ # core.js | ||
- [Build your own Octokit with Plugins and Defaults](#build-your-own-octokit-with-plugins-and-defaults) | ||
- [⚠️ A note on TypeScript](#%E2%9A%A0%EF%B8%8F-a-note-on-typescript) | ||
- [LICENSE](#license) | ||
@@ -380,55 +379,4 @@ | ||
<a name="a-note-on-typescript"></a> | ||
### ⚠️ A note on TypeScript | ||
When creating a new Octokit class using `.plugin()`, the TypeScript definitions `octokit` API extensions will get last when `.plugin()` or `.defaults()` is called on the new class again to derive yet another class. To workaround that, an intermediade class needs to be defined. For the example above, the code would look like this | ||
```js | ||
import { Octokit, OctokitOptions, OctokitPlugin, ReturnTypeOf, Constructor } from '@octokit/core' | ||
const CoreWithPlugins = Octokit | ||
.plugin([ | ||
paginate, | ||
throttle, | ||
retry | ||
]) | ||
class CoreWithPluginsWorkaround extends CoreWithPlugins { | ||
static plugin<T extends OctokitPlugin | OctokitPlugin[]>(pluginOrPlugins: T) { | ||
const currentPlugins = this.plugins; | ||
const newPlugins = Array.isArray(pluginOrPlugins) | ||
? pluginOrPlugins | ||
: [pluginOrPlugins]; | ||
const NewOctokit = class extends this { | ||
static plugins = currentPlugins.concat( | ||
newPlugins.filter(plugin => !currentPlugins.includes(plugin)) | ||
); | ||
}; | ||
return NewOctokit as typeof NewOctokit & Constructor<ReturnTypeOf<T>>; | ||
} | ||
static defaults(defaults: OctokitOptions) { | ||
return class OctokitWithDefaults extends this { | ||
constructor(options: OctokitOptions = {}) { | ||
super(Object.assign({}, defaults, options)); | ||
} | ||
}; | ||
} | ||
} | ||
const MyActionOctokit = CoreWithPluginsWorkaround | ||
.defaults({ | ||
authStrategy: require("@octokit/auth-action"), | ||
userAgent: `my-octokit-action/v1.2.3` | ||
}); | ||
const octokit = new MyActionOctokit(); | ||
const installations = await octokit.paginate("GET /app/installations"); | ||
``` | ||
## LICENSE | ||
[MIT](LICENSE) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41136
346
381