web_plsql 0.5.1 → 0.8.0
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 +128 -111
- package/examples/server_apex.js +26 -0
- package/examples/server_sample.js +30 -0
- package/examples/sql/{doc_table.sql → doctable.sql} +1 -1
- package/examples/sql/install.sql +6 -9
- package/examples/sql/sample_package.sql +27 -0
- package/examples/sql/sample_package_body.sql +245 -0
- package/examples/static/sample.css +11 -10
- package/package.json +92 -83
- package/src/cgi.js +127 -0
- package/src/error.js +24 -0
- package/src/errorPage.js +296 -0
- package/src/file.js +95 -0
- package/src/handlerLogger.js +21 -0
- package/src/handlerMetrics.js +46 -0
- package/src/handlerPlSql.js +65 -0
- package/src/handlerUpload.js +32 -0
- package/src/index.js +17 -0
- package/src/oracle.js +80 -0
- package/src/parsePage.js +193 -0
- package/src/procedure.js +260 -0
- package/src/procedureError.js +40 -0
- package/src/procedureNamed.js +233 -0
- package/src/procedureSanitize.js +215 -0
- package/src/procedureVariable.js +57 -0
- package/src/request.js +103 -0
- package/src/{requestError.ts → requestError.js} +8 -4
- package/src/sendResponse.js +104 -0
- package/src/server.js +185 -0
- package/src/shutdown.js +53 -0
- package/src/stream.js +28 -0
- package/src/trace.js +74 -0
- package/src/tty.js +48 -0
- package/src/types.js +146 -0
- package/src/upload.js +92 -0
- package/src/version.js +38 -0
- package/types/cgi.d.ts +4 -0
- package/types/error.d.ts +1 -0
- package/types/errorPage.d.ts +10 -0
- package/types/file.d.ts +6 -0
- package/types/handlerLogger.d.ts +2 -0
- package/types/handlerMetrics.d.ts +4 -0
- package/types/handlerPlSql.d.ts +8 -0
- package/types/handlerUpload.d.ts +7 -0
- package/types/index.d.ts +10 -0
- package/types/oracle.d.ts +5 -0
- package/types/parsePage.d.ts +3 -0
- package/types/procedure.d.ts +10 -0
- package/types/procedureError.d.ts +23 -0
- package/types/procedureNamed.d.ts +14 -0
- package/types/procedureSanitize.d.ts +14 -0
- package/types/procedureVariable.d.ts +9 -0
- package/types/request.d.ts +7 -0
- package/types/requestError.d.ts +8 -0
- package/types/sendResponse.d.ts +4 -0
- package/types/server.d.ts +11 -0
- package/types/shutdown.d.ts +2 -0
- package/types/stream.d.ts +1 -0
- package/types/trace.d.ts +5 -0
- package/types/tty.d.ts +4 -0
- package/types/types.d.ts +251 -0
- package/types/upload.d.ts +5 -0
- package/types/version.d.ts +8 -0
- package/.editorconfig +0 -8
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -347
- package/CHANGELOG.md +0 -133
- package/examples/apex.js +0 -70
- package/examples/credentials.js +0 -22
- package/examples/oracledb_example.js +0 -30
- package/examples/sample.js +0 -101
- package/examples/sql/sample.pkb +0 -223
- package/examples/sql/sample.pks +0 -24
- package/jest.config.js +0 -207
- package/src/cgi.ts +0 -95
- package/src/config.ts +0 -97
- package/src/errorPage.ts +0 -286
- package/src/fileUpload.ts +0 -126
- package/src/index.ts +0 -65
- package/src/page.ts +0 -275
- package/src/procedure.ts +0 -360
- package/src/procedureError.ts +0 -27
- package/src/request.ts +0 -139
- package/src/stream.ts +0 -26
- package/src/trace.ts +0 -194
- package/test/.eslintrc.json +0 -5
- package/test/__tests__/cgi.ts +0 -96
- package/test/__tests__/config.ts +0 -41
- package/test/__tests__/errorPage.ts +0 -101
- package/test/__tests__/oracledb_mock.ts +0 -98
- package/test/__tests__/server.ts +0 -495
- package/test/__tests__/stream.ts +0 -21
- package/test/mock/oracledb.ts +0 -85
- package/test/static/static.html +0 -1
- package/tsconfig.json +0 -24
- package/tsconfig.src.json +0 -23
package/test/__tests__/server.ts
DELETED
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
import {describe, beforeAll, afterAll, beforeEach, it, expect} from '@jest/globals';
|
|
2
|
-
import util from 'util';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import http from 'http';
|
|
5
|
-
import oracledb from 'oracledb';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import bodyParser from 'body-parser';
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
import multipart from 'connect-multiparty';
|
|
10
|
-
import cookieParser from 'cookie-parser';
|
|
11
|
-
import compression from 'compression';
|
|
12
|
-
import request from 'supertest';
|
|
13
|
-
import {setExecuteCallback, createPool} from '../mock/oracledb';
|
|
14
|
-
|
|
15
|
-
const webplsql = require('../../src/index'); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
16
|
-
|
|
17
|
-
const PORT = 8765;
|
|
18
|
-
const PATH = '/base';
|
|
19
|
-
const DEFAULT_PAGE = 'sample.pageIndex';
|
|
20
|
-
const DOC_TABLE = 'docTable';
|
|
21
|
-
|
|
22
|
-
type serverConfigType = {
|
|
23
|
-
app: express.Application;
|
|
24
|
-
server: http.Server;
|
|
25
|
-
connectionPool: oracledb.Pool;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe('server utilities', () => {
|
|
29
|
-
it('should start a server', async () => {
|
|
30
|
-
const serverConfig = await serverStart();
|
|
31
|
-
|
|
32
|
-
expect(Object.prototype.toString.call(serverConfig)).toBe('[object Object]');
|
|
33
|
-
expect(Object.prototype.toString.call(serverConfig.app.listen)).toBe('[object Function]');
|
|
34
|
-
expect(Object.prototype.toString.call(serverConfig.server)).toBe('[object Object]');
|
|
35
|
-
//expect(serverConfig.connectionPool).toBeInstanceOf(oracledb.Pool);
|
|
36
|
-
|
|
37
|
-
await serverStop(serverConfig);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('server static', () => {
|
|
42
|
-
let serverConfig: any;
|
|
43
|
-
|
|
44
|
-
beforeAll(async () => {
|
|
45
|
-
serverConfig = await serverStart();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
afterAll(async () => {
|
|
49
|
-
await serverStop(serverConfig);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
setExecuteCallback();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('get a static file', () =>
|
|
57
|
-
request(serverConfig.app).get('/static/static.html')
|
|
58
|
-
.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*')));
|
|
59
|
-
|
|
60
|
-
it('report a 404 error on a missing static file', () =>
|
|
61
|
-
request(serverConfig.app).get('/static/file_does_not_exist.html')
|
|
62
|
-
.expect(404));
|
|
63
|
-
|
|
64
|
-
it('get default page', () =>
|
|
65
|
-
request(serverConfig.app).get(PATH)
|
|
66
|
-
.expect(302, `Found. Redirecting to ${PATH}/${DEFAULT_PAGE}`));
|
|
67
|
-
|
|
68
|
-
it('get page', () => {
|
|
69
|
-
sqlExecuteProxy({
|
|
70
|
-
proc: 'sample.pageIndex();',
|
|
71
|
-
lines: [
|
|
72
|
-
'Content-type: text/html; charset=UTF-8\n',
|
|
73
|
-
'X-ORACLE-IGNORE: IGNORE\n',
|
|
74
|
-
'Custom-header: important\n',
|
|
75
|
-
'\n',
|
|
76
|
-
'<html><body><p>static</p></body></html>\n'
|
|
77
|
-
]
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return request(serverConfig.app).get(`${PATH}/${DEFAULT_PAGE}`)
|
|
81
|
-
.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('get page with query string', () => {
|
|
85
|
-
sqlExecuteProxy({
|
|
86
|
-
proc: 'sample.pageIndex(a=>:p_a,b=>:p_b);',
|
|
87
|
-
para: [
|
|
88
|
-
{name: 'a', value: '1'},
|
|
89
|
-
{name: 'b', value: '2'}
|
|
90
|
-
],
|
|
91
|
-
lines: [
|
|
92
|
-
'Content-type: text/html; charset=UTF-8\n',
|
|
93
|
-
'\n',
|
|
94
|
-
'<html><body><p>static</p></body></html>\n'
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return request(serverConfig.app).get(`${PATH}/${DEFAULT_PAGE}?a=1&b=2`)
|
|
99
|
-
.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('get page with query string containing duplicate names', () => {
|
|
103
|
-
sqlExecuteProxy({
|
|
104
|
-
proc: 'sample.pageIndex(a=>:p_a);',
|
|
105
|
-
para: [
|
|
106
|
-
{name: 'a', value: ['1', '2']}
|
|
107
|
-
],
|
|
108
|
-
lines: [
|
|
109
|
-
'Content-type: text/html; charset=UTF-8\n',
|
|
110
|
-
'\n',
|
|
111
|
-
'<html><body><p>static</p></body></html>\n'
|
|
112
|
-
]
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return request(serverConfig.app).get(`${PATH}/${DEFAULT_PAGE}?a=1&a=2`)
|
|
116
|
-
.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('get page with flexible parameters', () => {
|
|
120
|
-
sqlExecuteProxy({
|
|
121
|
-
proc: 'sample.pageIndex(:argnames, :argvalues);',
|
|
122
|
-
para: [
|
|
123
|
-
{name: 'argnames', value: ['a', 'b']},
|
|
124
|
-
{name: 'argvalues', value: ['1', '2']}
|
|
125
|
-
],
|
|
126
|
-
lines: [
|
|
127
|
-
'Content-type: text/html; charset=UTF-8\n',
|
|
128
|
-
'\n',
|
|
129
|
-
'<html><body><p>static</p></body></html>\n'
|
|
130
|
-
]
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
return request(serverConfig.app).get(`${PATH}/!${DEFAULT_PAGE}?a=1&b=2`)
|
|
134
|
-
.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('get page with cookies', () => {
|
|
138
|
-
sqlExecuteProxy({
|
|
139
|
-
proc: 'sample.pageIndex();',
|
|
140
|
-
lines: [
|
|
141
|
-
'Content-type: text/html; charset=UTF-8\n',
|
|
142
|
-
'Set-Cookie: C1=V1; path=/apex; Domain=mozilla.org; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly\n',
|
|
143
|
-
'\n',
|
|
144
|
-
'<html><body><p>static</p></body></html>\n'
|
|
145
|
-
]
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return request(serverConfig.app).get(`${PATH}/${DEFAULT_PAGE}`)
|
|
149
|
-
.expect(200)
|
|
150
|
-
.expect('set-cookie', 'C1=V1; Domain=mozilla.org; Path=/apex; Expires=Wed, 21 Oct 2015 07:28:00 GMT; HttpOnly')
|
|
151
|
-
.expect(new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('redirect to a new url', () => {
|
|
155
|
-
sqlExecuteProxy({
|
|
156
|
-
proc: 'sample.pageIndex();',
|
|
157
|
-
lines: ['Location: www.google.com\n']
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return request(serverConfig.app).get(`${PATH}/${DEFAULT_PAGE}`)
|
|
161
|
-
.expect(302);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('get json', () => {
|
|
165
|
-
sqlExecuteProxy({
|
|
166
|
-
proc: 'sample.pageJson();',
|
|
167
|
-
lines: [
|
|
168
|
-
'Content-type: application/json\n',
|
|
169
|
-
'\n',
|
|
170
|
-
'{"name":"johndoe"}'
|
|
171
|
-
]
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return request(serverConfig.app).get(`${PATH}/sample.pageJson`)
|
|
175
|
-
.expect(200, '{"name":"johndoe"}');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('get application/x-www-form-urlencoded', () => {
|
|
179
|
-
sqlExecuteProxy({
|
|
180
|
-
proc: 'sample.pageForm(name=>:p_name);',
|
|
181
|
-
para: [
|
|
182
|
-
{name: 'name', value: 'johndoe'}
|
|
183
|
-
],
|
|
184
|
-
lines: [
|
|
185
|
-
'Content-Type: text/html\n',
|
|
186
|
-
'\n',
|
|
187
|
-
'<html><body><p>static</p></body></html>\n'
|
|
188
|
-
]
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
return request(serverConfig.app)
|
|
192
|
-
.get(`${PATH}/sample.pageForm`)
|
|
193
|
-
.set('Content-Type', 'application/x-www-form-urlencoded')
|
|
194
|
-
.send('name=johndoe')
|
|
195
|
-
.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('get application/x-www-form-urlencoded with file', () => {
|
|
199
|
-
sqlExecuteProxy({
|
|
200
|
-
proc: 'sample.pageForm(',
|
|
201
|
-
para: [
|
|
202
|
-
{name: 'user_name', value: 'Tobi'}
|
|
203
|
-
],
|
|
204
|
-
lines: [
|
|
205
|
-
'Content-Type: text/html\n',
|
|
206
|
-
'\n',
|
|
207
|
-
'<html><body><p>static</p></body></html>\n'
|
|
208
|
-
]
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
const test = request(serverConfig.app).post(`${PATH}/sample.pageForm`);
|
|
212
|
-
test.set('Content-Type', 'multipart/form-data; boundary=foo');
|
|
213
|
-
test.write('--foo\r\n');
|
|
214
|
-
test.write('Content-Disposition: form-data; name="user_name"\r\n');
|
|
215
|
-
test.write('\r\n');
|
|
216
|
-
test.write('Tobi');
|
|
217
|
-
test.write('\r\n--foo\r\n');
|
|
218
|
-
test.write('Content-Disposition: form-data; name="text"; filename="test/server.js"\r\n');
|
|
219
|
-
test.write('\r\n');
|
|
220
|
-
test.write('some text here');
|
|
221
|
-
test.write('\r\n--foo--');
|
|
222
|
-
|
|
223
|
-
return test.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('set status', () => {
|
|
227
|
-
sqlExecuteProxy({
|
|
228
|
-
proc: 'sample.pageIndex();',
|
|
229
|
-
lines: [
|
|
230
|
-
'Status: 302 status\n'
|
|
231
|
-
]
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
return request(serverConfig.app).get(`${PATH}/${DEFAULT_PAGE}`)
|
|
235
|
-
.expect(302);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('set x-db-content-length header', () => {
|
|
239
|
-
sqlExecuteProxy({
|
|
240
|
-
proc: 'sample.pageJson();',
|
|
241
|
-
lines: [
|
|
242
|
-
'x-db-content-length: 0\n',
|
|
243
|
-
]
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
return request(serverConfig.app).get(`${PATH}/sample.pageJson`)
|
|
247
|
-
.expect(200);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it('use the pathAlias configuration setting', () => {
|
|
251
|
-
sqlExecuteProxy({
|
|
252
|
-
proc: 'pathAlias(p_path=>:p_path);',
|
|
253
|
-
lines: [
|
|
254
|
-
'Content-type: text/html; charset=UTF-8\n',
|
|
255
|
-
'\n',
|
|
256
|
-
'<html><body><p>static</p></body></html>\n'
|
|
257
|
-
]
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
return request(serverConfig.app).get(`${PATH}/alias`)
|
|
261
|
-
.expect(200, new RegExp('.*<html><body><p>static</p></body></html>.*'));
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
/*
|
|
265
|
-
|
|
266
|
-
it('GET /sampleRoute/cgi should validate the cgi', () => {
|
|
267
|
-
request(application.expressApplication).get('/sampleRoute/cgi')
|
|
268
|
-
.expect(200, 'cgi', done);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('GET /basicRoute/basicPage should generate a 401 error', () => {
|
|
272
|
-
request(application.expressApplication)
|
|
273
|
-
.get('/basicRoute/basicPage')
|
|
274
|
-
.expect(401, 'Access denied', done);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('GET /basicRoute/basicPage should authorize', () => {
|
|
278
|
-
request(application.expressApplication)
|
|
279
|
-
.get('/basicRoute/basicPage')
|
|
280
|
-
.auth('myusername', 'mypassword')
|
|
281
|
-
.expect(200, done);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it('should upload files', () => {
|
|
285
|
-
const FILENAME = 'temp/index.html';
|
|
286
|
-
const CONTENT = 'content of index.html';
|
|
287
|
-
let test;
|
|
288
|
-
|
|
289
|
-
// create a static file
|
|
290
|
-
mkdirp.sync('temp');
|
|
291
|
-
fs.writeFileSync(FILENAME, CONTENT);
|
|
292
|
-
|
|
293
|
-
// test the upload
|
|
294
|
-
test = request(application.expressApplication).post('/sampleRoute/fileUpload');
|
|
295
|
-
test.attach('file', FILENAME);
|
|
296
|
-
test.expect(200, done);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it('should respond with 404', () => {
|
|
300
|
-
let test = request(application.expressApplication).get('/invalidRoute');
|
|
301
|
-
|
|
302
|
-
test.expect(404, new RegExp('.*404 Not Found.*'), done);
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it('should respond with 404', () => {
|
|
306
|
-
let test = request(application.expressApplication).get('/sampleRoute/errorInPLSQL');
|
|
307
|
-
|
|
308
|
-
test.expect(404, new RegExp('.*Failed to parse target procedure.*'), done);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('should respond with 500', () => {
|
|
312
|
-
let test = request(application.expressApplication).get('/sampleRoute/internalError');
|
|
313
|
-
|
|
314
|
-
test.expect(500, done);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('does stop', () => {
|
|
318
|
-
server.stop(application, () => {
|
|
319
|
-
application = null;
|
|
320
|
-
assert.ok(true);
|
|
321
|
-
done();
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
it('does not start', () => {
|
|
327
|
-
server.start().then(() => {
|
|
328
|
-
}, function (err) {
|
|
329
|
-
assert.strictEqual(err, 'Configuration object must be an object');
|
|
330
|
-
done();
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
*/
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
/*
|
|
338
|
-
* Start server
|
|
339
|
-
*/
|
|
340
|
-
async function serverStart(): Promise<serverConfigType> {
|
|
341
|
-
// create connection pool
|
|
342
|
-
const connectionPool = await createPool({
|
|
343
|
-
user: 'sample',
|
|
344
|
-
password: 'sample',
|
|
345
|
-
connectString: 'localhost:1521/TEST'
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
// create express app
|
|
349
|
-
const app = express();
|
|
350
|
-
|
|
351
|
-
// add middleware
|
|
352
|
-
app.use(multipart());
|
|
353
|
-
app.use(bodyParser.json());
|
|
354
|
-
app.use(bodyParser.urlencoded({extended: true}));
|
|
355
|
-
app.use(cookieParser());
|
|
356
|
-
app.use(compression());
|
|
357
|
-
|
|
358
|
-
// add the oracle pl/sql express middleware
|
|
359
|
-
app.use(PATH + '/:name?', webplsql(connectionPool, {
|
|
360
|
-
trace: 'test',
|
|
361
|
-
defaultPage: DEFAULT_PAGE,
|
|
362
|
-
doctable: DOC_TABLE,
|
|
363
|
-
pathAlias: {
|
|
364
|
-
alias: 'alias',
|
|
365
|
-
procedure: 'pathAlias'
|
|
366
|
-
}
|
|
367
|
-
}));
|
|
368
|
-
|
|
369
|
-
// serving static files
|
|
370
|
-
const staticResourcesPath = path.join(process.cwd(), 'test', 'static');
|
|
371
|
-
app.use('/static', express.static(staticResourcesPath));
|
|
372
|
-
|
|
373
|
-
// listen on port
|
|
374
|
-
const server = app.listen(PORT);
|
|
375
|
-
|
|
376
|
-
return {app, server, connectionPool: connectionPool as unknown as oracledb.Pool};
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/*
|
|
380
|
-
* Stop server
|
|
381
|
-
*/
|
|
382
|
-
async function serverStop(config: serverConfigType) {
|
|
383
|
-
await config.server.close();
|
|
384
|
-
await config.connectionPool.close();
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/*
|
|
388
|
-
* Set the proxy for the next sql procedure to be executed
|
|
389
|
-
*/
|
|
390
|
-
function sqlExecuteProxy(config: {proc: string; para?: Array<{name: string; value: string | Array<string>}>; lines: Array<string>}) {
|
|
391
|
-
setExecuteCallback((sql: string, bind: any) => {
|
|
392
|
-
if (sql.indexOf('dbms_utility.name_resolve') !== -1) {
|
|
393
|
-
const noPara: {outBinds: {names: Array<string>; types: Array<string>}} = {
|
|
394
|
-
outBinds: {
|
|
395
|
-
names: [],
|
|
396
|
-
types: []
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
return typeof config.para === 'undefined' ? noPara : config.para.reduce((accumulator, currentValue) => {
|
|
401
|
-
accumulator.outBinds.names.push(currentValue.name);
|
|
402
|
-
accumulator.outBinds.types.push('VARCHAR2');
|
|
403
|
-
return accumulator;
|
|
404
|
-
}, noPara);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
if (sql.indexOf(config.proc) !== -1) {
|
|
408
|
-
if (typeof config.para !== 'undefined') {
|
|
409
|
-
if (!parameterEqual(sql, bind, config.para)) {
|
|
410
|
-
console.error(`===> Parameter mismatch\n${'-'.repeat(30)}\n${util.inspect(bind)}\n${'-'.repeat(30)}`);
|
|
411
|
-
return {};
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return {
|
|
416
|
-
outBinds: {
|
|
417
|
-
fileType: null,
|
|
418
|
-
fileSize: null,
|
|
419
|
-
fileBlob: null,
|
|
420
|
-
lines: config.lines,
|
|
421
|
-
irows: config.lines.length
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (sql.indexOf('INSERT INTO') === 0) {
|
|
427
|
-
return {
|
|
428
|
-
rowsAffected: 1
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
console.error(`===> sql statement cannot be identified\n${'-'.repeat(30)}\n${sql}\n${'-'.repeat(30)}`);
|
|
433
|
-
|
|
434
|
-
return {};
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function parameterEqual(sql: string, bind: any, parameters: Array<{name: string; value: string | Array<string>}>): boolean {
|
|
439
|
-
return sql.indexOf('(:argnames, :argvalues)') === -1 ? parameterFixedEqual(bind, parameters) : parameterFlexibleEqual(bind, parameters);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function parameterFixedEqual(bind: any, parameters: Array<{name: string; value: string | Array<string>}>): boolean {
|
|
443
|
-
return parameters.every(para => {
|
|
444
|
-
if (!bind.hasOwnProperty('p_' + para.name)) {
|
|
445
|
-
console.error(`===> The parameter "${para.name}" is missing`);
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (Array.isArray(para.value)) {
|
|
450
|
-
return para.value.every((v, i) => {
|
|
451
|
-
const equal = v === bind['p_' + para.name].val[i];
|
|
452
|
-
if (!equal) {
|
|
453
|
-
console.error(`===> The value "${v}" of parameter "${para.name}" is different`);
|
|
454
|
-
}
|
|
455
|
-
return equal;
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return para.value === bind['p_' + para.name].val;
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
function parameterFlexibleEqual(bind: any, parameters: Array<{name: string; value: string | Array<string>}>): boolean {
|
|
464
|
-
if (parameters.length !== 2) {
|
|
465
|
-
console.error('===> Invalid number of parameters');
|
|
466
|
-
return false;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
if (!parameters.every(para => ['argnames', 'argvalues'].indexOf(para.name) !== -1)) {
|
|
470
|
-
console.error('===> Invalid parameter names');
|
|
471
|
-
return false;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
if (!bind.hasOwnProperty('argnames') || !bind.hasOwnProperty('argvalues')) {
|
|
475
|
-
console.error('===> Missing bindings');
|
|
476
|
-
return false;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return parameters.every(para => Array.isArray(para.value) && arrayEqual(para.value, bind[para.name].val));
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/*
|
|
483
|
-
* Compare two arrays
|
|
484
|
-
*/
|
|
485
|
-
function arrayEqual(array1: Array<any>, array2: Array<any>): boolean {
|
|
486
|
-
if (!array1 || !array2) {
|
|
487
|
-
return false;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (array1.length !== array2.length) {
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
return array1.every((e, i) => e === array2[i]);
|
|
495
|
-
}
|
package/test/__tests__/stream.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {describe, it, expect} from '@jest/globals';
|
|
2
|
-
import {streamToBuffer} from '../../src/stream';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
|
|
5
|
-
describe('stream', () => {
|
|
6
|
-
it('should convert a stream to a buffer', async () => {
|
|
7
|
-
const buffer = Buffer.from('Hey there', 'utf8');
|
|
8
|
-
|
|
9
|
-
const filename = 'file.tmp';
|
|
10
|
-
const file = fs.openSync(filename, 'w+');
|
|
11
|
-
fs.writeSync(file, buffer, 0, buffer.length, 0);
|
|
12
|
-
fs.closeSync(file);
|
|
13
|
-
|
|
14
|
-
const readStream = fs.createReadStream('file.tmp');
|
|
15
|
-
const readBuffer = await streamToBuffer(readStream);
|
|
16
|
-
|
|
17
|
-
expect(buffer.equals(readBuffer)).toBeTruthy();
|
|
18
|
-
|
|
19
|
-
fs.unlinkSync(filename);
|
|
20
|
-
});
|
|
21
|
-
});
|
package/test/mock/oracledb.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/* eslint-disable class-methods-use-this, @typescript-eslint/no-unused-vars */
|
|
2
|
-
|
|
3
|
-
type executeCallbackType = (sql: string, bindParams?: any) => any;
|
|
4
|
-
|
|
5
|
-
let _executeCallback: executeCallbackType | null = null;
|
|
6
|
-
|
|
7
|
-
export function setExecuteCallback(callback: executeCallbackType | null = null): void {
|
|
8
|
-
_executeCallback = callback;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class Lob {
|
|
12
|
-
type: number;
|
|
13
|
-
|
|
14
|
-
constructor(type: number) {
|
|
15
|
-
this.type = type;
|
|
16
|
-
}
|
|
17
|
-
close(): Promise<void> {
|
|
18
|
-
return Promise.resolve();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class Connection {
|
|
23
|
-
execute(sql: string, bindParams?: Record<string, unknown>, options?: Record<string, unknown>): Promise<any> {
|
|
24
|
-
return Promise.resolve(_executeCallback ? _executeCallback(sql, bindParams) : {});
|
|
25
|
-
}
|
|
26
|
-
createLob(type: number): Promise<Lob> {
|
|
27
|
-
const lob = new Lob(type);
|
|
28
|
-
return Promise.resolve(lob);
|
|
29
|
-
}
|
|
30
|
-
release(): Promise<void> {
|
|
31
|
-
return Promise.resolve();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class ConnectionPool {
|
|
36
|
-
onExecuteCallback: ((sql: string, bindParams: any) => any) | null;
|
|
37
|
-
|
|
38
|
-
constructor() {
|
|
39
|
-
this.onExecuteCallback = null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getConnection(): Promise<Connection> {
|
|
43
|
-
const connection = new Connection();
|
|
44
|
-
|
|
45
|
-
return Promise.resolve(connection);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
close(): Promise<void> {
|
|
49
|
-
return Promise.resolve();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function createPool(options: Record<string, unknown>): Promise<ConnectionPool> {
|
|
54
|
-
const connectionPool = new ConnectionPool();
|
|
55
|
-
|
|
56
|
-
return Promise.resolve(connectionPool);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function getConnection(options: Record<string, unknown>): Promise<Connection> {
|
|
60
|
-
const connection = new Connection();
|
|
61
|
-
|
|
62
|
-
return Promise.resolve(connection);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const BIND_IN = 1;
|
|
66
|
-
export const BIND_INOUT = 2;
|
|
67
|
-
export const BIND_OUT = 3;
|
|
68
|
-
|
|
69
|
-
export const STRING = 4;
|
|
70
|
-
export const NUMBER = 5;
|
|
71
|
-
export const DATE = 6;
|
|
72
|
-
export const CURSOR = 7;
|
|
73
|
-
export const BUFFER = 8;
|
|
74
|
-
export const CLOB = 9;
|
|
75
|
-
export const BLOB = 10;
|
|
76
|
-
|
|
77
|
-
export const poolMin = 1;
|
|
78
|
-
export const poolMax = 1;
|
|
79
|
-
export const poolIncrement = 1;
|
|
80
|
-
export const poolTimeout = 1;
|
|
81
|
-
export const prefetchRows = 1;
|
|
82
|
-
export const stmtCacheSize = 1;
|
|
83
|
-
|
|
84
|
-
export const version = 0;
|
|
85
|
-
export const oracleClientVersion = 0;
|
package/test/static/static.html
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<html><body><p>static</p></body></html>
|
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"skipLibCheck": true,
|
|
4
|
-
"moduleResolution": "node",
|
|
5
|
-
"baseUrl": ".",
|
|
6
|
-
"outDir": "lib",
|
|
7
|
-
"target": "es6",
|
|
8
|
-
"lib": [
|
|
9
|
-
"es2015",
|
|
10
|
-
"es2016",
|
|
11
|
-
"es2017",
|
|
12
|
-
"es2018"
|
|
13
|
-
],
|
|
14
|
-
"module": "commonjs",
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"strict": true,
|
|
17
|
-
"alwaysStrict": true,
|
|
18
|
-
"esModuleInterop": true
|
|
19
|
-
},
|
|
20
|
-
"include": [
|
|
21
|
-
"src/**/*",
|
|
22
|
-
"test/**/*"
|
|
23
|
-
]
|
|
24
|
-
}
|
package/tsconfig.src.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"skipLibCheck": true,
|
|
4
|
-
"moduleResolution": "node",
|
|
5
|
-
"baseUrl": ".",
|
|
6
|
-
"outDir": "lib",
|
|
7
|
-
"target": "es6",
|
|
8
|
-
"lib": [
|
|
9
|
-
"es2015",
|
|
10
|
-
"es2016",
|
|
11
|
-
"es2017",
|
|
12
|
-
"es2018"
|
|
13
|
-
],
|
|
14
|
-
"module": "commonjs",
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"strict": true,
|
|
17
|
-
"alwaysStrict": true,
|
|
18
|
-
"esModuleInterop": true
|
|
19
|
-
},
|
|
20
|
-
"include": [
|
|
21
|
-
"src/**/*"
|
|
22
|
-
]
|
|
23
|
-
}
|