qcobjectsnewapp 2.5.24-ts → 2.5.25-ts

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.
@@ -1 +0,0 @@
1
- export {};
@@ -1,213 +0,0 @@
1
- /* eslint-disable prefer-rest-params */
2
- "use strict";
3
- import { Package, JSONService, Service, logger } from "qcobjects";
4
-
5
- type Project = {
6
- id: string;
7
- description: string;
8
- name: string;
9
- html_url: string;
10
- owner: { avatar_url: string },
11
- forks_count:number,
12
- stargazers_count:number,
13
- watchers_count:number,
14
- size:number
15
- }
16
-
17
- type StandardResponse = {
18
- request: XMLHttpRequest;
19
- service: Service;
20
- };
21
-
22
- type GitHubTagServiceResponse = {
23
- total_count:number;
24
- incomplete_results: boolean;
25
- items:Array<Project>
26
- };
27
- type ItemProject = {
28
- id:string;
29
- description:string;
30
- title:string;
31
- url:string;
32
- image?:string;
33
- };
34
- type ItemsProject = Array<ItemProject>;
35
-
36
- export class GitHubService extends JSONService {
37
- /**
38
- * Name of the service
39
- * @date 18/04/2023 - 22:30:07
40
- *
41
- * @type {string}
42
- */
43
- name = "myservice";
44
-
45
- /**
46
- * It specifies if the service has a external url. If true, you can pass absolute urls in url property
47
- * @date 18/04/2023 - 22:30:37
48
- *
49
- * @type {boolean}
50
- */
51
- external = true;
52
-
53
- /**
54
- * If it is true, the service call will be cached
55
- * @date 18/04/2023 - 22:31:41
56
- *
57
- * @type {boolean}
58
- */
59
- cached = false;
60
-
61
- /**
62
- * It can be GET, POST, PUT
63
- * @date 18/04/2023 - 22:32:29
64
- *
65
- * @type {string}
66
- */
67
- method = "GET";
68
-
69
- /**
70
- * You can add special headers using this property
71
- * @date 18/04/2023 - 22:33:20
72
- *
73
- * @type {{ "Content-Type": string; }}
74
- */
75
- headers = { "Content-Type": "application/json", "charset": "utf-8" };
76
-
77
- /**
78
- * URL for the service call
79
- * @date 18/04/2023 - 22:34:09
80
- *
81
- * @type {string}
82
- */
83
- url = "https://api.github.com/orgs/QuickCorp/repos";
84
-
85
- /**
86
- * This is used internally for XHR requests. Default value is false.
87
- * @date 18/04/2023 - 22:34:29
88
- *
89
- * @type {boolean}
90
- */
91
- withCredentials = false;
92
-
93
- constructor() {
94
- super();
95
- // Remove charset header to avoid CORS preflight issues with external APIs
96
- // (charset is not a CORS-safelisted request header)
97
- delete this.headers.charset;
98
- }
99
-
100
- /**
101
- * It is called once the service call is done
102
- * @param param0 this param has two properties, one is the native request call (XHR or Fetch object). The second property is the service object.
103
- * @returns Promise
104
- */
105
- done({ request, service }: StandardResponse) {
106
-
107
- const result:ItemsProject = (JSON.parse(service.template as string) as Array<Project>)
108
- .reverse().map(function (project: Project) {
109
- return {
110
- id: project.id,
111
- description: project.description,
112
- title: project.name,
113
- url: project.html_url,
114
- repo_stargazers_count: project.stargazers_count,
115
- repo_watchers_count: project.watchers_count
116
- };
117
- });
118
-
119
- service.template = JSON.stringify({
120
- result
121
- });
122
- return super.done({ request, service });
123
- }
124
- }
125
-
126
- export class GitHubTagService extends JSONService {
127
- name = "myservice";
128
- external = true;
129
- cached = false;
130
- method = "GET";
131
- headers = { "Content-Type": "application/json", "charset": "utf-8" };
132
- url = "https://api.github.com/search/repositories?q=qcobjects";
133
- withCredentials = false;
134
-
135
- constructor() {
136
- super();
137
- delete this.headers.charset;
138
- }
139
-
140
- done({ request, service }: StandardResponse) {
141
- logger.debug(String(request));
142
- const result:ItemsProject = (JSON.parse(service.template as string) as GitHubTagServiceResponse)
143
- .items.map(function (project: Project) {
144
- return {
145
- id: project.id,
146
- description: project.description,
147
- title: project.name,
148
- url: project.html_url,
149
- repo_stargazers_count: project.stargazers_count,
150
- repo_watchers_count: project.watchers_count
151
- };
152
- });
153
-
154
- service.template = JSON.stringify({
155
- result
156
- });
157
- return super.done({ request, service });
158
- }
159
- }
160
-
161
- export class QCObjectsVersionService extends Service {
162
- name = "qcobjects_version_service";
163
- external = true;
164
- cached = false;
165
- method = "GET";
166
- headers = { "Content-Type": "application/json", "charset": "utf-8" };
167
- url = "https://api.github.com/repos/QuickCorp/QCObjects/tags";
168
- withCredentials = false;
169
-
170
- constructor() {
171
- super();
172
- delete this.headers.charset;
173
- }
174
-
175
- done({ service }: StandardResponse) {
176
- const latest = JSON.parse(service.template as string)[0];
177
- service.template = {
178
- version: latest.name
179
- };
180
- }
181
- }
182
-
183
- export class QCObjectsStarsForksService extends Service {
184
- name = "qcobjects_stars_forks_service";
185
- external = true;
186
- cached = false;
187
- method = "GET";
188
- headers = { "Content-Type": "application/json", "charset": "utf-8" };
189
- url = "https://api.github.com/repos/QuickCorp/QCObjects";
190
- withCredentials = false;
191
-
192
- constructor() {
193
- super();
194
- delete this.headers.charset;
195
- }
196
-
197
- done({ service }: StandardResponse) {
198
- const repo:Project = (JSON.parse(service.template as string) as Project);
199
- service.template = {
200
- forks: repo.forks_count,
201
- stars: repo.stargazers_count,
202
- watchers: repo.watchers_count,
203
- size: Math.round(repo.size / 1000)
204
- };
205
- }
206
- }
207
-
208
- Package("com.qcobjects.services.github", [
209
- GitHubService,
210
- GitHubTagService,
211
- QCObjectsVersionService,
212
- QCObjectsStarsForksService
213
- ]);