Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
e40f0800
Commit
e40f0800
authored
3 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
154e0fe9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/api.ts
+18
-11
18 additions, 11 deletions
src/api.ts
with
18 additions
and
11 deletions
src/api.ts
+
18
−
11
View file @
e40f0800
...
...
@@ -28,6 +28,12 @@ type IsNeverType<T> = [T] extends [never] ? true : false;
type
StrictExtract
<
Union
,
Cond
>
=
Cond
extends
Union
?
Union
:
never
;
type
IsCaseMatched
<
E
extends
keyof
Endpoints
,
P
extends
Endpoints
[
E
][
'
req
'
],
C
extends
number
>
=
IsNeverType
<
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
C
],
[
P
,
any
]
>>
extends
false
?
true
:
false
;
type
GetCaseResult
<
E
extends
keyof
Endpoints
,
P
extends
Endpoints
[
E
][
'
req
'
],
C
extends
number
>
=
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
C
],
[
P
,
any
]
>
[
1
];
export
class
APIClient
{
public
origin
:
string
;
public
credential
:
string
|
null
|
undefined
;
...
...
@@ -46,17 +52,18 @@ export class APIClient {
public
request
<
E
extends
keyof
Endpoints
,
P
extends
Endpoints
[
E
][
'
req
'
]
>
(
endpoint
:
E
,
params
:
P
=
{}
as
P
,
credential
?:
string
|
null
|
undefined
,
):
Promise
<
Endpoints
[
E
][
'
res
'
]
extends
{
$switch
:
{
$cases
:
[
any
,
any
][];
$default
:
any
;
};
}
?
IsNeverType
<
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
0
],
[
P
,
any
]
>>
extends
false
?
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
0
],
[
P
,
any
]
>
[
1
]
:
IsNeverType
<
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
1
],
[
P
,
any
]
>>
extends
false
?
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
1
],
[
P
,
any
]
>
[
1
]
:
IsNeverType
<
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
2
],
[
P
,
any
]
>>
extends
false
?
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
2
],
[
P
,
any
]
>
[
1
]
:
IsNeverType
<
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
3
],
[
P
,
any
]
>>
extends
false
?
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
3
],
[
P
,
any
]
>
[
1
]
:
IsNeverType
<
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
4
],
[
P
,
any
]
>>
extends
false
?
StrictExtract
<
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$cases
'
][
4
],
[
P
,
any
]
>
[
1
]
:
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$default
'
]
?
IsCaseMatched
<
E
,
P
,
0
>
extends
true
?
GetCaseResult
<
E
,
P
,
0
>
:
IsCaseMatched
<
E
,
P
,
1
>
extends
true
?
GetCaseResult
<
E
,
P
,
1
>
:
IsCaseMatched
<
E
,
P
,
2
>
extends
true
?
GetCaseResult
<
E
,
P
,
2
>
:
IsCaseMatched
<
E
,
P
,
3
>
extends
true
?
GetCaseResult
<
E
,
P
,
3
>
:
IsCaseMatched
<
E
,
P
,
4
>
extends
true
?
GetCaseResult
<
E
,
P
,
4
>
:
IsCaseMatched
<
E
,
P
,
5
>
extends
true
?
GetCaseResult
<
E
,
P
,
5
>
:
IsCaseMatched
<
E
,
P
,
6
>
extends
true
?
GetCaseResult
<
E
,
P
,
6
>
:
IsCaseMatched
<
E
,
P
,
7
>
extends
true
?
GetCaseResult
<
E
,
P
,
7
>
:
IsCaseMatched
<
E
,
P
,
8
>
extends
true
?
GetCaseResult
<
E
,
P
,
8
>
:
IsCaseMatched
<
E
,
P
,
9
>
extends
true
?
GetCaseResult
<
E
,
P
,
9
>
:
Endpoints
[
E
][
'
res
'
][
'
$switch
'
][
'
$default
'
]
:
Endpoints
[
E
][
'
res
'
]
>
{
const
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment