dbgate-rest 7.1.3-alpha.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/README.md +7 -0
- package/lib/arrayify.d.ts +3 -0
- package/lib/arrayify.js +81 -0
- package/lib/graphQlDriver.d.ts +2 -0
- package/lib/graphQlDriver.js +55 -0
- package/lib/graphQlQueryParser.d.ts +5 -0
- package/lib/graphQlQueryParser.js +204 -0
- package/lib/graphQlVariables.d.ts +6 -0
- package/lib/graphQlVariables.js +123 -0
- package/lib/graphqlExplorer.d.ts +26 -0
- package/lib/graphqlExplorer.js +125 -0
- package/lib/graphqlIntrospection.d.ts +56 -0
- package/lib/graphqlIntrospection.js +409 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +29 -0
- package/lib/oDataAdapter.d.ts +33 -0
- package/lib/oDataAdapter.js +358 -0
- package/lib/oDataAdapter.test.d.ts +2 -0
- package/lib/oDataAdapter.test.js +61 -0
- package/lib/oDataDriver.d.ts +2 -0
- package/lib/oDataDriver.js +85 -0
- package/lib/oDataMetadataParser.d.ts +2 -0
- package/lib/oDataMetadataParser.js +137 -0
- package/lib/openApiAdapter.d.ts +7 -0
- package/lib/openApiAdapter.js +254 -0
- package/lib/openApiDriver.d.ts +2 -0
- package/lib/openApiDriver.js +90 -0
- package/lib/restApiDef.d.ts +55 -0
- package/lib/restApiDef.js +2 -0
- package/lib/restApiExecutor.d.ts +4 -0
- package/lib/restApiExecutor.js +292 -0
- package/lib/restApiExecutor.test.d.ts +16 -0
- package/lib/restApiExecutor.test.js +99 -0
- package/lib/restAuthTools.d.ts +2 -0
- package/lib/restAuthTools.js +20 -0
- package/lib/restDriverBase.d.ts +61 -0
- package/lib/restDriverBase.js +49 -0
- package/package.json +42 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeODataApiEndpoint = exports.executeRestApiEndpointOpenApi = void 0;
|
|
4
|
+
function hasValue(value) {
|
|
5
|
+
if (value === null || value === undefined)
|
|
6
|
+
return false;
|
|
7
|
+
if (typeof value === 'string')
|
|
8
|
+
return value.trim() !== '';
|
|
9
|
+
if (Array.isArray(value))
|
|
10
|
+
return value.length > 0;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
function normalizeValueForRequest(value, parameter) {
|
|
14
|
+
if (!hasValue(value))
|
|
15
|
+
return undefined;
|
|
16
|
+
if (parameter.isStringList) {
|
|
17
|
+
if (Array.isArray(value))
|
|
18
|
+
return value.filter(item => item != null && String(item).trim() !== '');
|
|
19
|
+
return [String(value)];
|
|
20
|
+
}
|
|
21
|
+
if (parameter.in === 'body' && typeof value === 'string') {
|
|
22
|
+
const trimmed = value.trim();
|
|
23
|
+
if (!trimmed)
|
|
24
|
+
return undefined;
|
|
25
|
+
if ((parameter.contentType || '').includes('json') || parameter.dataType === 'object') {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(trimmed);
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function splitPathAndQuery(path) {
|
|
37
|
+
const value = String(path || '');
|
|
38
|
+
const index = value.indexOf('?');
|
|
39
|
+
if (index < 0) {
|
|
40
|
+
return {
|
|
41
|
+
pathOnly: value,
|
|
42
|
+
queryString: '',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
pathOnly: value.slice(0, index),
|
|
47
|
+
queryString: value.slice(index + 1),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function addAuthHeaders(headers, auth) {
|
|
51
|
+
if (!auth)
|
|
52
|
+
return;
|
|
53
|
+
if (auth.type === 'basic') {
|
|
54
|
+
const basicAuth = Buffer.from(`${auth.user}:${auth.password}`).toString('base64');
|
|
55
|
+
headers['Authorization'] = `Basic ${basicAuth}`;
|
|
56
|
+
}
|
|
57
|
+
else if (auth.type === 'bearer') {
|
|
58
|
+
headers['Authorization'] = `Bearer ${auth.token}`;
|
|
59
|
+
}
|
|
60
|
+
else if (auth.type === 'apikey') {
|
|
61
|
+
headers[auth.header] = auth.value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function findEndpointDefinition(definition, endpoint, method) {
|
|
65
|
+
return definition.categories
|
|
66
|
+
.flatMap(category => category.endpoints)
|
|
67
|
+
.find(ep => ep.path === endpoint && ep.method === method);
|
|
68
|
+
}
|
|
69
|
+
function buildRequestUrl(server, pathOnly) {
|
|
70
|
+
const normalizedServer = String(server || '').trim();
|
|
71
|
+
const normalizedPath = String(pathOnly || '').trim();
|
|
72
|
+
if (!normalizedServer) {
|
|
73
|
+
return normalizedPath;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const baseUrl = normalizedServer.endsWith('/') ? normalizedServer : `${normalizedServer}/`;
|
|
77
|
+
const relativePath = normalizedPath.replace(/^\//, '');
|
|
78
|
+
return new URL(relativePath, baseUrl).toString();
|
|
79
|
+
}
|
|
80
|
+
catch (_a) {
|
|
81
|
+
return normalizedServer + normalizedPath;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function appendQueryAndCookies(url, query, cookies, headers) {
|
|
85
|
+
const queryStringValue = query.toString();
|
|
86
|
+
if (queryStringValue) {
|
|
87
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
88
|
+
url += separator + queryStringValue;
|
|
89
|
+
}
|
|
90
|
+
if (cookies.length > 0) {
|
|
91
|
+
headers['Cookie'] = cookies.join('; ');
|
|
92
|
+
}
|
|
93
|
+
return url;
|
|
94
|
+
}
|
|
95
|
+
const ODATA_SYSTEM_QUERY_OPTIONS = new Set([
|
|
96
|
+
'$filter',
|
|
97
|
+
'$select',
|
|
98
|
+
'$expand',
|
|
99
|
+
'$orderby',
|
|
100
|
+
'$top',
|
|
101
|
+
'$skip',
|
|
102
|
+
'$count',
|
|
103
|
+
'$search',
|
|
104
|
+
'$format',
|
|
105
|
+
]);
|
|
106
|
+
const ODATA_SYSTEM_QUERY_ALIASES = {
|
|
107
|
+
filter: '$filter',
|
|
108
|
+
select: '$select',
|
|
109
|
+
expand: '$expand',
|
|
110
|
+
orderby: '$orderby',
|
|
111
|
+
top: '$top',
|
|
112
|
+
skip: '$skip',
|
|
113
|
+
count: '$count',
|
|
114
|
+
search: '$search',
|
|
115
|
+
format: '$format',
|
|
116
|
+
};
|
|
117
|
+
function resolveODataQueryOptionKey(rawKey) {
|
|
118
|
+
const key = String(rawKey || '').trim();
|
|
119
|
+
if (!key)
|
|
120
|
+
return null;
|
|
121
|
+
const keyLower = key.toLowerCase();
|
|
122
|
+
if (ODATA_SYSTEM_QUERY_OPTIONS.has(keyLower)) {
|
|
123
|
+
return keyLower;
|
|
124
|
+
}
|
|
125
|
+
return ODATA_SYSTEM_QUERY_ALIASES[keyLower] || null;
|
|
126
|
+
}
|
|
127
|
+
function normalizeODataQueryOptionValue(optionKey, value) {
|
|
128
|
+
if (!hasValue(value))
|
|
129
|
+
return null;
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
const items = value.filter(item => hasValue(item)).map(item => String(item).trim()).filter(Boolean);
|
|
132
|
+
if (items.length === 0)
|
|
133
|
+
return null;
|
|
134
|
+
return items.join(',');
|
|
135
|
+
}
|
|
136
|
+
if (optionKey === '$count') {
|
|
137
|
+
if (typeof value === 'boolean')
|
|
138
|
+
return value ? 'true' : 'false';
|
|
139
|
+
const lowered = String(value).trim().toLowerCase();
|
|
140
|
+
if (lowered === 'true' || lowered === 'false')
|
|
141
|
+
return lowered;
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (optionKey === '$top' || optionKey === '$skip') {
|
|
145
|
+
const numeric = Number(value);
|
|
146
|
+
if (Number.isFinite(numeric) && numeric >= 0) {
|
|
147
|
+
return String(Math.trunc(numeric));
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
return String(value).trim();
|
|
152
|
+
}
|
|
153
|
+
function applyODataSystemQueryOptions(query, parameterValues) {
|
|
154
|
+
for (const [rawKey, rawValue] of Object.entries(parameterValues || {})) {
|
|
155
|
+
const optionKey = resolveODataQueryOptionKey(rawKey);
|
|
156
|
+
if (!optionKey)
|
|
157
|
+
continue;
|
|
158
|
+
const normalizedValue = normalizeODataQueryOptionValue(optionKey, rawValue);
|
|
159
|
+
if (!hasValue(normalizedValue))
|
|
160
|
+
continue;
|
|
161
|
+
query.set(optionKey, String(normalizedValue));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function executeRestApiEndpointOpenApi(definition, endpoint, method, parameterValues, server, auth, axios) {
|
|
165
|
+
const endpointDef = findEndpointDefinition(definition, endpoint, method);
|
|
166
|
+
if (!endpointDef) {
|
|
167
|
+
throw new Error(`Endpoint ${method} ${endpoint} not found in definition.`);
|
|
168
|
+
}
|
|
169
|
+
const { pathOnly, queryString } = splitPathAndQuery(endpointDef.path);
|
|
170
|
+
let url = buildRequestUrl(server, pathOnly);
|
|
171
|
+
const headers = {};
|
|
172
|
+
const query = new URLSearchParams(queryString);
|
|
173
|
+
const cookies = [];
|
|
174
|
+
let body = undefined;
|
|
175
|
+
for (const param of endpointDef.parameters) {
|
|
176
|
+
const value = normalizeValueForRequest(parameterValues[param.name], param);
|
|
177
|
+
if (!hasValue(value) && param.in !== 'path') {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (param.in === 'path') {
|
|
181
|
+
url = url.replace(`{${param.name}}`, encodeURIComponent(value));
|
|
182
|
+
}
|
|
183
|
+
else if (param.in === 'query') {
|
|
184
|
+
if (Array.isArray(value)) {
|
|
185
|
+
for (const item of value) {
|
|
186
|
+
query.append(param.name, String(item));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
query.append(param.name, String(value));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (param.in === 'header') {
|
|
194
|
+
headers[param.name] = Array.isArray(value) ? value.map(item => String(item)).join(',') : String(value);
|
|
195
|
+
}
|
|
196
|
+
else if (param.in === 'cookie') {
|
|
197
|
+
if (Array.isArray(value)) {
|
|
198
|
+
for (const item of value) {
|
|
199
|
+
cookies.push(`${encodeURIComponent(param.name)}=${encodeURIComponent(String(item))}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
cookies.push(`${encodeURIComponent(param.name)}=${encodeURIComponent(String(value))}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (param.in === 'body') {
|
|
207
|
+
body = value;
|
|
208
|
+
if (param.contentType && !headers['Content-Type']) {
|
|
209
|
+
headers['Content-Type'] = param.contentType;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
url = appendQueryAndCookies(url, query, cookies, headers);
|
|
214
|
+
addAuthHeaders(headers, auth);
|
|
215
|
+
const resp = await axios({
|
|
216
|
+
method,
|
|
217
|
+
url,
|
|
218
|
+
headers,
|
|
219
|
+
data: body,
|
|
220
|
+
});
|
|
221
|
+
return resp;
|
|
222
|
+
}
|
|
223
|
+
exports.executeRestApiEndpointOpenApi = executeRestApiEndpointOpenApi;
|
|
224
|
+
async function executeODataApiEndpoint(definition, endpoint, method, parameterValues, server, auth, axios) {
|
|
225
|
+
const endpointDef = findEndpointDefinition(definition, endpoint, method);
|
|
226
|
+
if (!endpointDef) {
|
|
227
|
+
throw new Error(`Endpoint ${method} ${endpoint} not found in definition.`);
|
|
228
|
+
}
|
|
229
|
+
const { pathOnly, queryString } = splitPathAndQuery(endpointDef.path);
|
|
230
|
+
const metadataPath = pathOnly.replace(/\/+$/, '') === '/$metadata';
|
|
231
|
+
let url = buildRequestUrl(server, pathOnly);
|
|
232
|
+
const headers = {
|
|
233
|
+
Accept: 'application/json',
|
|
234
|
+
'OData-Version': '4.0',
|
|
235
|
+
};
|
|
236
|
+
const query = metadataPath ? new URLSearchParams() : new URLSearchParams(queryString);
|
|
237
|
+
const cookies = [];
|
|
238
|
+
let body = undefined;
|
|
239
|
+
for (const param of endpointDef.parameters) {
|
|
240
|
+
const value = normalizeValueForRequest(parameterValues[param.name], param);
|
|
241
|
+
if (!hasValue(value) && param.in !== 'path') {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (param.in === 'path') {
|
|
245
|
+
url = url.replace(`{${param.name}}`, encodeURIComponent(value));
|
|
246
|
+
}
|
|
247
|
+
else if (param.in === 'query') {
|
|
248
|
+
if (metadataPath)
|
|
249
|
+
continue;
|
|
250
|
+
if (Array.isArray(value)) {
|
|
251
|
+
for (const item of value) {
|
|
252
|
+
query.append(param.name, String(item));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
query.append(param.name, String(value));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (param.in === 'header') {
|
|
260
|
+
headers[param.name] = Array.isArray(value) ? value.map(item => String(item)).join(',') : String(value);
|
|
261
|
+
}
|
|
262
|
+
else if (param.in === 'cookie') {
|
|
263
|
+
if (Array.isArray(value)) {
|
|
264
|
+
for (const item of value) {
|
|
265
|
+
cookies.push(`${encodeURIComponent(param.name)}=${encodeURIComponent(String(item))}`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
cookies.push(`${encodeURIComponent(param.name)}=${encodeURIComponent(String(value))}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else if (param.in === 'body') {
|
|
273
|
+
body = value;
|
|
274
|
+
if (param.contentType && !headers['Content-Type']) {
|
|
275
|
+
headers['Content-Type'] = param.contentType;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (!metadataPath) {
|
|
280
|
+
applyODataSystemQueryOptions(query, parameterValues);
|
|
281
|
+
}
|
|
282
|
+
url = appendQueryAndCookies(url, query, cookies, headers);
|
|
283
|
+
addAuthHeaders(headers, auth);
|
|
284
|
+
const resp = await axios({
|
|
285
|
+
method,
|
|
286
|
+
url,
|
|
287
|
+
headers,
|
|
288
|
+
data: body,
|
|
289
|
+
});
|
|
290
|
+
return resp;
|
|
291
|
+
}
|
|
292
|
+
exports.executeODataApiEndpoint = executeODataApiEndpoint;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const executeODataApiEndpoint: any;
|
|
2
|
+
declare function createDefinition(): {
|
|
3
|
+
categories: {
|
|
4
|
+
name: string;
|
|
5
|
+
endpoints: {
|
|
6
|
+
method: string;
|
|
7
|
+
path: string;
|
|
8
|
+
parameters: {
|
|
9
|
+
name: string;
|
|
10
|
+
in: string;
|
|
11
|
+
dataType: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
}[];
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const { executeODataApiEndpoint } = require('./restApiExecutor');
|
|
2
|
+
function createDefinition() {
|
|
3
|
+
return {
|
|
4
|
+
categories: [
|
|
5
|
+
{
|
|
6
|
+
name: 'EntitySet',
|
|
7
|
+
endpoints: [
|
|
8
|
+
{
|
|
9
|
+
method: 'GET',
|
|
10
|
+
path: '/customers',
|
|
11
|
+
parameters: [
|
|
12
|
+
{
|
|
13
|
+
name: 'company',
|
|
14
|
+
in: 'query',
|
|
15
|
+
dataType: 'string',
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
method: 'GET',
|
|
22
|
+
path: '/$metadata',
|
|
23
|
+
parameters: [],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
test('adds OData system query options from parameterValues', async () => {
|
|
31
|
+
const calls = [];
|
|
32
|
+
const axios = async (args) => {
|
|
33
|
+
calls.push(args);
|
|
34
|
+
return { status: 200, data: {} };
|
|
35
|
+
};
|
|
36
|
+
await executeODataApiEndpoint(createDefinition(), '/customers', 'GET', {
|
|
37
|
+
company: '123',
|
|
38
|
+
'$top': 50,
|
|
39
|
+
'$skip': '10',
|
|
40
|
+
'$count': true,
|
|
41
|
+
'$select': ['id', 'displayName'],
|
|
42
|
+
'$orderby': 'displayName asc',
|
|
43
|
+
'$filter': 'displayName ne null',
|
|
44
|
+
'$search': 'dino',
|
|
45
|
+
'$expand': 'addresses',
|
|
46
|
+
'$format': 'application/json',
|
|
47
|
+
}, 'https://example.test/odata', null, axios);
|
|
48
|
+
expect(calls).toHaveLength(1);
|
|
49
|
+
const requestUrl = String(calls[0].url);
|
|
50
|
+
const parsed = new URL(requestUrl);
|
|
51
|
+
expect(parsed.pathname).toBe('/odata/customers');
|
|
52
|
+
expect(parsed.searchParams.get('company')).toBe('123');
|
|
53
|
+
expect(parsed.searchParams.get('$top')).toBe('50');
|
|
54
|
+
expect(parsed.searchParams.get('$skip')).toBe('10');
|
|
55
|
+
expect(parsed.searchParams.get('$count')).toBe('true');
|
|
56
|
+
expect(parsed.searchParams.get('$select')).toBe('id,displayName');
|
|
57
|
+
expect(parsed.searchParams.get('$orderby')).toBe('displayName asc');
|
|
58
|
+
expect(parsed.searchParams.get('$filter')).toBe('displayName ne null');
|
|
59
|
+
expect(parsed.searchParams.get('$search')).toBe('dino');
|
|
60
|
+
expect(parsed.searchParams.get('$expand')).toBe('addresses');
|
|
61
|
+
expect(parsed.searchParams.get('$format')).toBe('application/json');
|
|
62
|
+
});
|
|
63
|
+
test('accepts non-dollar aliases and ignores invalid system option values', async () => {
|
|
64
|
+
const calls = [];
|
|
65
|
+
const axios = async (args) => {
|
|
66
|
+
calls.push(args);
|
|
67
|
+
return { status: 200, data: {} };
|
|
68
|
+
};
|
|
69
|
+
await executeODataApiEndpoint(createDefinition(), '/customers', 'GET', {
|
|
70
|
+
company: '123',
|
|
71
|
+
top: 'abc',
|
|
72
|
+
skip: -1,
|
|
73
|
+
count: 'yes',
|
|
74
|
+
select: ['id'],
|
|
75
|
+
filter: 'id ne null',
|
|
76
|
+
}, 'https://example.test/odata', null, axios);
|
|
77
|
+
expect(calls).toHaveLength(1);
|
|
78
|
+
const parsed = new URL(String(calls[0].url));
|
|
79
|
+
expect(parsed.searchParams.get('$top')).toBeNull();
|
|
80
|
+
expect(parsed.searchParams.get('$skip')).toBeNull();
|
|
81
|
+
expect(parsed.searchParams.get('$count')).toBeNull();
|
|
82
|
+
expect(parsed.searchParams.get('$select')).toBe('id');
|
|
83
|
+
expect(parsed.searchParams.get('$filter')).toBe('id ne null');
|
|
84
|
+
});
|
|
85
|
+
test('does not add OData system query options to $metadata endpoint', async () => {
|
|
86
|
+
const calls = [];
|
|
87
|
+
const axios = async (args) => {
|
|
88
|
+
calls.push(args);
|
|
89
|
+
return { status: 200, data: {} };
|
|
90
|
+
};
|
|
91
|
+
await executeODataApiEndpoint(createDefinition(), '/$metadata', 'GET', {
|
|
92
|
+
'$top': 10,
|
|
93
|
+
'$count': true,
|
|
94
|
+
}, 'https://example.test/odata', null, axios);
|
|
95
|
+
expect(calls).toHaveLength(1);
|
|
96
|
+
const parsed = new URL(String(calls[0].url));
|
|
97
|
+
expect(parsed.pathname).toBe('/odata/$metadata');
|
|
98
|
+
expect(parsed.search).toBe('');
|
|
99
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildRestAuthHeaders = void 0;
|
|
4
|
+
function buildRestAuthHeaders(auth) {
|
|
5
|
+
const headers = {};
|
|
6
|
+
if (!auth)
|
|
7
|
+
return headers;
|
|
8
|
+
if (auth.type === 'basic') {
|
|
9
|
+
const basicAuth = Buffer.from(`${auth.user}:${auth.password}`).toString('base64');
|
|
10
|
+
headers['Authorization'] = `Basic ${basicAuth}`;
|
|
11
|
+
}
|
|
12
|
+
else if (auth.type === 'bearer') {
|
|
13
|
+
headers['Authorization'] = `Bearer ${auth.token}`;
|
|
14
|
+
}
|
|
15
|
+
else if (auth.type === 'apikey') {
|
|
16
|
+
headers[auth.header] = auth.value;
|
|
17
|
+
}
|
|
18
|
+
return headers;
|
|
19
|
+
}
|
|
20
|
+
exports.buildRestAuthHeaders = buildRestAuthHeaders;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const apiDriverBase: {
|
|
2
|
+
supportExecuteQuery: boolean;
|
|
3
|
+
getAuthTypes(): {
|
|
4
|
+
title: string;
|
|
5
|
+
name: string;
|
|
6
|
+
}[];
|
|
7
|
+
showAuthConnectionField: (field: any, values: any) => boolean;
|
|
8
|
+
analyserClass: any;
|
|
9
|
+
dumperClass: typeof import("dbgate-tools").SqlDumper;
|
|
10
|
+
dialect: {
|
|
11
|
+
limitSelect: boolean;
|
|
12
|
+
rangeSelect: boolean;
|
|
13
|
+
topRecords: boolean;
|
|
14
|
+
offsetFetchRangeSyntax: boolean;
|
|
15
|
+
stringEscapeChar: string;
|
|
16
|
+
fallbackDataType: string;
|
|
17
|
+
quoteIdentifier(s: any): any;
|
|
18
|
+
columnProperties: {
|
|
19
|
+
isSparse: boolean;
|
|
20
|
+
isPersisted: boolean;
|
|
21
|
+
};
|
|
22
|
+
defaultSchemaName: any;
|
|
23
|
+
};
|
|
24
|
+
databaseEngineTypes: string[];
|
|
25
|
+
supportedCreateDatabase: boolean;
|
|
26
|
+
analyseFull(pool: any, version: any): Promise<any>;
|
|
27
|
+
analyseSingleObject(pool: any, name: any, typeField?: string): Promise<any>;
|
|
28
|
+
analyseSingleTable(pool: any, name: any): any;
|
|
29
|
+
analyseIncremental(pool: any, structure: any, version: any): Promise<any>;
|
|
30
|
+
createDumper(options?: any): import("dbgate-tools").SqlDumper;
|
|
31
|
+
script(pool: any, sql: any, options: import("dbgate-types").RunScriptOptions): Promise<void>;
|
|
32
|
+
operation(pool: any, operation: any, options: import("dbgate-types").RunScriptOptions): Promise<void>;
|
|
33
|
+
getNewObjectTemplates(): {
|
|
34
|
+
label: string;
|
|
35
|
+
sql: string;
|
|
36
|
+
}[];
|
|
37
|
+
loadFieldValues(pool: any, name: any, columnName: any, search: any, dataType: any): Promise<any>;
|
|
38
|
+
readJsonQuery(pool: any, select: any, structure: any): any;
|
|
39
|
+
showConnectionField: (field: any, values: any) => boolean;
|
|
40
|
+
showConnectionTab: (field: any) => boolean;
|
|
41
|
+
getAccessTokenFromAuth: (connection: any, req: any) => Promise<any>;
|
|
42
|
+
getFilterBehaviour(dataType: string, standardFilterBehaviours: any): import("dbgate-types").FilterBehaviour;
|
|
43
|
+
getCollectionExportQueryScript(collection: string, condition: any, sort: any): any;
|
|
44
|
+
getCollectionExportQueryJson(collection: string, condition: any, sort: any): any;
|
|
45
|
+
getScriptTemplates(objectTypeField: any): any[];
|
|
46
|
+
getScriptTemplateContent(scriptTemplate: any, props: any): any;
|
|
47
|
+
dataEditorTypesBehaviour: {
|
|
48
|
+
parseSqlNull: boolean;
|
|
49
|
+
parseHexAsBuffer: boolean;
|
|
50
|
+
};
|
|
51
|
+
createSaveChangeSetScript(changeSet: any, dbinfo: any, defaultCreator: any): any;
|
|
52
|
+
adaptDataType(dataType: string): string;
|
|
53
|
+
adaptTableInfo(table: any): any;
|
|
54
|
+
listSchemas(pool: any): Promise<any>;
|
|
55
|
+
writeQueryFromStream(dbhan: any, sql: any): Promise<any>;
|
|
56
|
+
getLogDbInfo(dbhan: any): {
|
|
57
|
+
database: any;
|
|
58
|
+
engine: any;
|
|
59
|
+
conid: any;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apiDriverBase = void 0;
|
|
4
|
+
const dbgate_tools_1 = require("dbgate-tools");
|
|
5
|
+
exports.apiDriverBase = {
|
|
6
|
+
...dbgate_tools_1.driverBase,
|
|
7
|
+
supportExecuteQuery: false,
|
|
8
|
+
getAuthTypes() {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
title: 'No Authentication',
|
|
12
|
+
name: 'none',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
title: 'Basic Authentication',
|
|
16
|
+
name: 'basic',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: 'Bearer Token Authentication',
|
|
20
|
+
name: 'bearer',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: 'API Key Authentication',
|
|
24
|
+
name: 'apikey',
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
},
|
|
28
|
+
showAuthConnectionField: (field, values) => {
|
|
29
|
+
if (field === 'authType')
|
|
30
|
+
return true;
|
|
31
|
+
if ((values === null || values === void 0 ? void 0 : values.authType) === 'basic') {
|
|
32
|
+
if (field === 'user')
|
|
33
|
+
return true;
|
|
34
|
+
if (field === 'password')
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if ((values === null || values === void 0 ? void 0 : values.authType) === 'bearer') {
|
|
38
|
+
if (field === 'authToken')
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if ((values === null || values === void 0 ? void 0 : values.authType) === 'apikey') {
|
|
42
|
+
if (field === 'apiKeyHeader')
|
|
43
|
+
return true;
|
|
44
|
+
if (field === 'apiKeyValue')
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
},
|
|
49
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "7.1.3-alpha.2",
|
|
3
|
+
"name": "dbgate-rest",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"typings": "lib/index.d.ts",
|
|
6
|
+
"homepage": "https://www.dbgate.io/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dbgate/dbgate.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "Jan Prochazka",
|
|
12
|
+
"license": "GPL-3.0",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"sql",
|
|
15
|
+
"dbgate"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"start": "tsc --watch",
|
|
20
|
+
"prepublishOnly": "yarn build",
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"test:ci": "jest --json --outputFile=result.json --testLocationInResults"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib"
|
|
26
|
+
],
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^13.7.0",
|
|
29
|
+
"dbgate-types": "7.1.3-alpha.2",
|
|
30
|
+
"jest": "^28.1.3",
|
|
31
|
+
"ts-jest": "^28.0.7",
|
|
32
|
+
"typescript": "^4.4.3"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"dbgate-tools": "7.1.3-alpha.2",
|
|
36
|
+
"lodash": "^4.17.21",
|
|
37
|
+
"openapi-types": "^12.1.3",
|
|
38
|
+
"pinomin": "^1.0.5",
|
|
39
|
+
"uuid": "^3.4.0",
|
|
40
|
+
"js-yaml": "^4.1.0"
|
|
41
|
+
}
|
|
42
|
+
}
|