@foundation0/git 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/api.ts CHANGED
@@ -1,69 +1,69 @@
1
- import {
2
- GIT_API_VERSION,
3
- buildGitApiMockResponse,
4
- GitApiHeaders,
5
- GitApiMockResponse,
6
- GitApiPath,
7
- GitApiQuery,
8
- MockInvocation,
9
- } from './spec-mock'
10
-
11
- export type GitApiInvocationPath = GitApiPath
12
- export type GitApiInvocationQuery = GitApiQuery
13
- export type GitApiInvocationHeaders = GitApiHeaders
14
-
15
- export interface GitApiInvocation {
16
- path: GitApiInvocationPath
17
- method?: string
18
- query?: GitApiInvocationQuery
19
- headers?: GitApiInvocationHeaders
20
- }
21
-
22
- export interface GitApiClientOptions {
23
- apiBase?: string
24
- apiVersion?: string
25
- defaultMethod?: string
26
- }
27
-
28
- export class RemoteGitApiClient {
29
- private readonly apiBase: string
30
- private readonly apiVersion: string
31
- private readonly defaultMethod: string
32
-
33
- public constructor(options: GitApiClientOptions = {}) {
34
- this.apiBase = options.apiBase ?? 'https://api.github.com'
35
- this.apiVersion = options.apiVersion ?? GIT_API_VERSION
36
- this.defaultMethod = options.defaultMethod ?? 'GET'
37
- }
38
-
39
- public buildInvocation(invocation: GitApiInvocation): MockInvocation {
40
- return {
41
- path: invocation.path,
42
- method: invocation.method ?? this.defaultMethod,
43
- query: invocation.query,
44
- headers: invocation.headers,
45
- apiBase: this.apiBase,
46
- apiVersion: this.apiVersion,
47
- }
48
- }
49
-
50
- public request(invocation: GitApiInvocation): GitApiMockResponse {
51
- return buildGitApiMockResponse(this.buildInvocation(invocation))
52
- }
53
-
54
- public requestAsync(invocation: GitApiInvocation): Promise<GitApiMockResponse> {
55
- return Promise.resolve(this.request(invocation))
56
- }
57
-
58
- public get metadata() {
59
- return {
60
- apiBase: this.apiBase,
61
- apiVersion: this.apiVersion,
62
- defaultMethod: this.defaultMethod,
63
- }
64
- }
65
- }
66
-
67
- export function createRemoteGitApiClient(options: GitApiClientOptions = {}): RemoteGitApiClient {
68
- return new RemoteGitApiClient(options)
69
- }
1
+ import {
2
+ GIT_API_VERSION,
3
+ buildGitApiMockResponse,
4
+ GitApiHeaders,
5
+ GitApiMockResponse,
6
+ GitApiPath,
7
+ GitApiQuery,
8
+ MockInvocation,
9
+ } from './spec-mock'
10
+
11
+ export type GitApiInvocationPath = GitApiPath
12
+ export type GitApiInvocationQuery = GitApiQuery
13
+ export type GitApiInvocationHeaders = GitApiHeaders
14
+
15
+ export interface GitApiInvocation {
16
+ path: GitApiInvocationPath
17
+ method?: string
18
+ query?: GitApiInvocationQuery
19
+ headers?: GitApiInvocationHeaders
20
+ }
21
+
22
+ export interface GitApiClientOptions {
23
+ apiBase?: string
24
+ apiVersion?: string
25
+ defaultMethod?: string
26
+ }
27
+
28
+ export class RemoteGitApiClient {
29
+ private readonly apiBase: string
30
+ private readonly apiVersion: string
31
+ private readonly defaultMethod: string
32
+
33
+ public constructor(options: GitApiClientOptions = {}) {
34
+ this.apiBase = options.apiBase ?? 'https://api.github.com'
35
+ this.apiVersion = options.apiVersion ?? GIT_API_VERSION
36
+ this.defaultMethod = options.defaultMethod ?? 'GET'
37
+ }
38
+
39
+ public buildInvocation(invocation: GitApiInvocation): MockInvocation {
40
+ return {
41
+ path: invocation.path,
42
+ method: invocation.method ?? this.defaultMethod,
43
+ query: invocation.query,
44
+ headers: invocation.headers,
45
+ apiBase: this.apiBase,
46
+ apiVersion: this.apiVersion,
47
+ }
48
+ }
49
+
50
+ public request(invocation: GitApiInvocation): GitApiMockResponse {
51
+ return buildGitApiMockResponse(this.buildInvocation(invocation))
52
+ }
53
+
54
+ public requestAsync(invocation: GitApiInvocation): Promise<GitApiMockResponse> {
55
+ return Promise.resolve(this.request(invocation))
56
+ }
57
+
58
+ public get metadata() {
59
+ return {
60
+ apiBase: this.apiBase,
61
+ apiVersion: this.apiVersion,
62
+ defaultMethod: this.defaultMethod,
63
+ }
64
+ }
65
+ }
66
+
67
+ export function createRemoteGitApiClient(options: GitApiClientOptions = {}): RemoteGitApiClient {
68
+ return new RemoteGitApiClient(options)
69
+ }