-
Notifications
You must be signed in to change notification settings - Fork 1
/
githubds.datasource.ts
66 lines (63 loc) · 1.74 KB
/
githubds.datasource.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';
const config = {
name: 'githubds',
connector: 'rest',
baseURL: 'https://api.github.ibm.com',
crud: false,
options: {
headers: {
accept: 'application/json',
Authorization: process.env.TOKEN,
'User-Agent': 'loopback4-example-github',
'X-RateLimit-Limit': 5000,
'content-type': 'application/json'
}
},
operations: [
{
template: {
method: 'GET',
fullResponse: true,
url: 'https://api.github.com/search/issues?q=repo:{repo}+label:"{label}"'
},
functions: {
getIssuesByLabel: ['repo','label']
}
}, {
template: {
method: 'GET',
fullResponse: true,
url: '{url}'
},
functions: {
getIssuesByURL: ['url']
}
}, {
template: {
method: 'GET',
fullResponse: true,
url: 'https://api.github.com/search/issues?q=repo:{repo}+{querystring}'
},
functions: {
getIssuesWithQueryString: ['repo','querystring']
}
}
]
};
// Observe application's life cycle to disconnect the datasource when
// application is stopped. This allows the application to be shut down
// gracefully. The `stop()` method is inherited from `juggler.DataSource`.
// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
@lifeCycleObserver('datasource')
export class GithubdsDataSource extends juggler.DataSource
implements LifeCycleObserver {
static dataSourceName = 'githubds';
static readonly defaultConfig = config;
constructor(
@inject('datasources.config.githubds', {optional: true})
dsConfig: object = config,
) {
super(dsConfig);
}
}