web_plsql 0.3.2 → 0.5.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/.editorconfig +8 -8
- package/.eslintignore +3 -3
- package/.eslintrc.js +347 -273
- package/CHANGELOG.md +127 -106
- package/LICENSE +21 -21
- package/README.md +165 -164
- package/examples/apex.js +70 -70
- package/examples/credentials.js +22 -22
- package/examples/oracledb_example.js +30 -30
- package/examples/sample.js +101 -84
- package/examples/sql/doc_table.sql +13 -13
- package/examples/sql/install.sql +31 -31
- package/examples/sql/sample.pkb +223 -223
- package/examples/sql/sample.pks +24 -24
- package/examples/sql/uninstall.sql +5 -5
- package/examples/static/sample.css +25 -25
- package/jest.config.js +204 -0
- package/package.json +85 -109
- package/src/cgi.ts +95 -95
- package/src/config.ts +97 -97
- package/src/errorPage.ts +286 -286
- package/src/fileUpload.ts +126 -132
- package/src/index.ts +65 -66
- package/src/page.ts +275 -277
- package/src/procedure.ts +360 -359
- package/src/procedureError.ts +27 -27
- package/src/request.ts +139 -139
- package/src/requestError.ts +19 -19
- package/src/stream.ts +26 -26
- package/src/trace.ts +194 -193
- package/test/.eslintrc.json +5 -5
- package/test/{cgi.ts → __tests__/cgi.ts} +96 -95
- package/test/{config.ts → __tests__/config.ts} +41 -41
- package/test/__tests__/errorPage.ts +101 -0
- package/test/{oracledb_mock.ts → __tests__/oracledb_mock.ts} +98 -98
- package/test/{server.ts → __tests__/server.ts} +495 -498
- package/test/{stream.ts → __tests__/stream.ts} +21 -21
- package/test/mock/oracledb.ts +85 -85
- package/test/static/static.html +1 -1
- package/tsconfig.json +24 -23
- package/tsconfig.src.json +23 -22
- package/test/errorPage.ts +0 -101
- package/test/mocha.opts +0 -7
- package/tsconfig.test.json +0 -19
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {validate} from '
|
|
3
|
-
|
|
4
|
-
describe('configuration options', () => {
|
|
5
|
-
it('should allow the following options', () => {
|
|
6
|
-
[
|
|
7
|
-
undefined, // eslint-disable-line no-undefined
|
|
8
|
-
{},
|
|
9
|
-
{cgi: {fast: 'on'}},
|
|
10
|
-
{pathAlias: {alias: 'r', procedure: 'p'}},
|
|
11
|
-
{errorStyle: 'debug'}
|
|
12
|
-
].forEach(options => {
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('configuration errors', () => {
|
|
19
|
-
[
|
|
20
|
-
{config: null, error: 'Invalid configuration object was given'},
|
|
21
|
-
{config: {invalid: ''}, error: 'Invalid configuration options "invalid"'},
|
|
22
|
-
{config: {defaultPage: 1}, error: 'The option "defaultPage" must be of type string and cannot be empty'},
|
|
23
|
-
{config: {defaultPage: ''}, error: 'The option "defaultPage" must be of type string and cannot be empty'},
|
|
24
|
-
{config: {doctable: 1}, error: 'The option "doctable" must be of type string and cannot be empty'},
|
|
25
|
-
{config: {doctable: ''}, error: 'The option "doctable" must be of type string and cannot be empty'},
|
|
26
|
-
{config: {cgi: ''}, error: 'The option "cgi" must be an object where all keys and values are of type string'},
|
|
27
|
-
{config: {cgi: {a: 1}}, error: 'The option "cgi" must be an object where all keys and values are of type string'},
|
|
28
|
-
{config: {pathAlias: {alias: 'r', procedure: ''}}, error: 'The option "pathAlias" must be an object with the non-empty string properties "alias" and "procedure"'},
|
|
29
|
-
{config: {errorStyle: ''}, error: 'The optional option "errorStyle" must be "basic" or "debug"'},
|
|
30
|
-
{config: {errorStyle: 'on'}, error: 'The optional option "errorStyle" must be "basic" or "debug"'},
|
|
31
|
-
{config: {trace: true}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
32
|
-
{config: {trace: ''}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
33
|
-
{config: {trace: 'enabled'}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
34
|
-
].forEach(test => {
|
|
35
|
-
it(`should throw the exception "${test.error}"`, () => {
|
|
36
|
-
|
|
37
|
-
validate(test.config);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
1
|
+
import {describe, it, expect} from '@jest/globals';
|
|
2
|
+
import {validate} from '../../src/config';
|
|
3
|
+
|
|
4
|
+
describe('configuration options', () => {
|
|
5
|
+
it('should allow the following options', () => {
|
|
6
|
+
[
|
|
7
|
+
undefined, // eslint-disable-line no-undefined
|
|
8
|
+
{},
|
|
9
|
+
{cgi: {fast: 'on'}},
|
|
10
|
+
{pathAlias: {alias: 'r', procedure: 'p'}},
|
|
11
|
+
{errorStyle: 'debug'}
|
|
12
|
+
].forEach(options => {
|
|
13
|
+
expect(typeof validate(options as unknown as Record<string, unknown>)).toBe('object');
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('configuration errors', () => {
|
|
19
|
+
[
|
|
20
|
+
{config: null, error: 'Invalid configuration object was given'},
|
|
21
|
+
{config: {invalid: ''}, error: 'Invalid configuration options "invalid"'},
|
|
22
|
+
{config: {defaultPage: 1}, error: 'The option "defaultPage" must be of type string and cannot be empty'},
|
|
23
|
+
{config: {defaultPage: ''}, error: 'The option "defaultPage" must be of type string and cannot be empty'},
|
|
24
|
+
{config: {doctable: 1}, error: 'The option "doctable" must be of type string and cannot be empty'},
|
|
25
|
+
{config: {doctable: ''}, error: 'The option "doctable" must be of type string and cannot be empty'},
|
|
26
|
+
{config: {cgi: ''}, error: 'The option "cgi" must be an object where all keys and values are of type string'},
|
|
27
|
+
{config: {cgi: {a: 1}}, error: 'The option "cgi" must be an object where all keys and values are of type string'},
|
|
28
|
+
{config: {pathAlias: {alias: 'r', procedure: ''}}, error: 'The option "pathAlias" must be an object with the non-empty string properties "alias" and "procedure"'},
|
|
29
|
+
{config: {errorStyle: ''}, error: 'The optional option "errorStyle" must be "basic" or "debug"'},
|
|
30
|
+
{config: {errorStyle: 'on'}, error: 'The optional option "errorStyle" must be "basic" or "debug"'},
|
|
31
|
+
{config: {trace: true}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
32
|
+
{config: {trace: ''}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
33
|
+
{config: {trace: 'enabled'}, error: 'The optional option "trace" must be "on" or "off"'},
|
|
34
|
+
].forEach(test => {
|
|
35
|
+
it(`should throw the exception "${test.error}"`, () => {
|
|
36
|
+
expect(() => {
|
|
37
|
+
validate(test.config as unknown as Record<string, unknown>);
|
|
38
|
+
}).toThrow(test.error);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {describe, beforeAll, afterAll, it, expect} from '@jest/globals';
|
|
2
|
+
import {errorPage} from '../../src/errorPage';
|
|
3
|
+
import {RequestError} from '../../src/requestError';
|
|
4
|
+
import {ProcedureError} from '../../src/procedureError';
|
|
5
|
+
import {oracleExpressMiddleware$options} from '../../src/config';
|
|
6
|
+
|
|
7
|
+
describe('errorPage', () => {
|
|
8
|
+
let errorSave: any;
|
|
9
|
+
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
errorSave = console.error;
|
|
12
|
+
console.error = () => {}; // eslint-disable-line @typescript-eslint/no-empty-function
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
console.error = errorSave;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
let errorText = '';
|
|
20
|
+
let errorHtml = '';
|
|
21
|
+
|
|
22
|
+
const options: oracleExpressMiddleware$options = {
|
|
23
|
+
errorStyle: 'debug',
|
|
24
|
+
trace: 'off'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const req: any = {};
|
|
28
|
+
const res: any = {
|
|
29
|
+
status() {
|
|
30
|
+
return this;
|
|
31
|
+
},
|
|
32
|
+
send(error: string) {
|
|
33
|
+
errorHtml = error;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const trace: any = {
|
|
38
|
+
write(error: string) {
|
|
39
|
+
errorText = error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
it('should report a "error message" in text and html format', () => {
|
|
44
|
+
errorPage(req, res, options, trace, new Error('error message'));
|
|
45
|
+
|
|
46
|
+
expect(/error message/.test(errorText)).toBeTruthy();
|
|
47
|
+
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
48
|
+
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
49
|
+
expect(/error message/.test(errorHtml)).toBeTruthy();
|
|
50
|
+
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
51
|
+
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should report a "Error" in text and html format', () => {
|
|
55
|
+
errorPage(req, res, options, trace, new Error('throw Error'));
|
|
56
|
+
|
|
57
|
+
expect(/throw Error/.test(errorText)).toBeTruthy();
|
|
58
|
+
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
59
|
+
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
60
|
+
expect(/throw Error/.test(errorHtml)).toBeTruthy();
|
|
61
|
+
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
62
|
+
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should report a "RequestError" in text and html format', () => {
|
|
66
|
+
errorPage(req, res, options, trace, new RequestError('throw RequestError'));
|
|
67
|
+
|
|
68
|
+
expect(/throw RequestError/.test(errorText)).toBeTruthy();
|
|
69
|
+
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
70
|
+
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
71
|
+
expect(/throw RequestError/.test(errorHtml)).toBeTruthy();
|
|
72
|
+
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
73
|
+
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should report a "ProcedureError" in text and html format', () => {
|
|
77
|
+
const environment = {dad: 'dad'};
|
|
78
|
+
const sql = 'sql';
|
|
79
|
+
const bind = {p1: '1'};
|
|
80
|
+
|
|
81
|
+
errorPage(req, res, options, trace, new ProcedureError('throw ProcedureError', environment, sql, bind));
|
|
82
|
+
|
|
83
|
+
expect(/throw ProcedureError/.test(errorText)).toBeTruthy();
|
|
84
|
+
expect(/ERROR/.test(errorText)).toBeTruthy();
|
|
85
|
+
expect(/REQUEST/.test(errorText)).toBeTruthy();
|
|
86
|
+
expect(/PROCEDURE/.test(errorText)).toBeTruthy();
|
|
87
|
+
expect(/ENVIRONMENT/.test(errorText)).toBeTruthy();
|
|
88
|
+
expect(/throw ProcedureError/.test(errorHtml)).toBeTruthy();
|
|
89
|
+
expect(/TIMESTAMP/.test(errorHtml)).toBeTruthy();
|
|
90
|
+
expect(/ERROR/.test(errorHtml)).toBeTruthy();
|
|
91
|
+
expect(/PROCEDURE/.test(errorHtml)).toBeTruthy();
|
|
92
|
+
expect(/ENVIRONMENT/.test(errorHtml)).toBeTruthy();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should only report a "404" error when in basic mode', () => {
|
|
96
|
+
options.errorStyle = 'basic';
|
|
97
|
+
errorPage(req, res, options, trace, new Error('error message'));
|
|
98
|
+
|
|
99
|
+
expect(/error message/.test(errorText)).toBeTruthy();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {setExecuteCallback, createPool, Connection, getConnection, ConnectionPool, Lob, BLOB} from '
|
|
3
|
-
|
|
4
|
-
describe('oracledb', () => {
|
|
5
|
-
it('createPool', async () => {
|
|
6
|
-
const connectionPool = await _createPool();
|
|
7
|
-
|
|
8
|
-
return connectionPool;
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('getConnection', async () => {
|
|
12
|
-
const connection = await _getConnection();
|
|
13
|
-
|
|
14
|
-
return connection;
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('ConnectionPool', () => {
|
|
19
|
-
it('getConnection', async () => {
|
|
20
|
-
const connectionPool = await _createPool();
|
|
21
|
-
const connection = await connectionPool.getConnection();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return connection;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('close', async () => {
|
|
29
|
-
const connectionPool = await _createPool();
|
|
30
|
-
await connectionPool.close();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('Connection', () => {
|
|
35
|
-
it('getConnection', async () => {
|
|
36
|
-
const connection = await _getConnection();
|
|
37
|
-
|
|
38
|
-
return connection;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('createLob', async () => {
|
|
42
|
-
const connection = await _getConnection();
|
|
43
|
-
const lob = await connection.createLob(BLOB);
|
|
44
|
-
|
|
45
|
-
return lob;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('release', async () => {
|
|
49
|
-
const connection = await _getConnection();
|
|
50
|
-
return connection.release();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('Connection.execute', () => {
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
setExecuteCallback();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('execute', async () => {
|
|
60
|
-
const connection = await _getConnection();
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('execute with execution callback', async () => {
|
|
65
|
-
const connection = await _getConnection();
|
|
66
|
-
const SQL = 'select * from dual';
|
|
67
|
-
|
|
68
|
-
// register an execute callback
|
|
69
|
-
setExecuteCallback((sql: string) => {
|
|
70
|
-
|
|
71
|
-
return {sql: SQL};
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
/*
|
|
79
|
-
* get connection pool
|
|
80
|
-
*/
|
|
81
|
-
function _createPool() {
|
|
82
|
-
return createPool({
|
|
83
|
-
user: 'sample',
|
|
84
|
-
password: 'sample',
|
|
85
|
-
connectString: 'localhost:1521/TEST'
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/*
|
|
90
|
-
* get connection
|
|
91
|
-
*/
|
|
92
|
-
function _getConnection() {
|
|
93
|
-
return getConnection({
|
|
94
|
-
user: 'sample',
|
|
95
|
-
password: 'sample',
|
|
96
|
-
connectString: 'localhost:1521/TEST'
|
|
97
|
-
});
|
|
98
|
-
}
|
|
1
|
+
import {describe, beforeEach, it, expect} from '@jest/globals';
|
|
2
|
+
import {setExecuteCallback, createPool, Connection, getConnection, ConnectionPool, Lob, BLOB} from '../mock/oracledb';
|
|
3
|
+
|
|
4
|
+
describe('oracledb', () => {
|
|
5
|
+
it('createPool', async () => {
|
|
6
|
+
const connectionPool = await _createPool();
|
|
7
|
+
expect(connectionPool).toBeInstanceOf(ConnectionPool);
|
|
8
|
+
return connectionPool;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('getConnection', async () => {
|
|
12
|
+
const connection = await _getConnection();
|
|
13
|
+
expect(connection).toBeInstanceOf(Connection);
|
|
14
|
+
return connection;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('ConnectionPool', () => {
|
|
19
|
+
it('getConnection', async () => {
|
|
20
|
+
const connectionPool = await _createPool();
|
|
21
|
+
const connection = await connectionPool.getConnection();
|
|
22
|
+
|
|
23
|
+
expect(connection).toBeInstanceOf(Connection);
|
|
24
|
+
|
|
25
|
+
return connection;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('close', async () => {
|
|
29
|
+
const connectionPool = await _createPool();
|
|
30
|
+
await connectionPool.close();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('Connection', () => {
|
|
35
|
+
it('getConnection', async () => {
|
|
36
|
+
const connection = await _getConnection();
|
|
37
|
+
expect(connection).toBeInstanceOf(Connection);
|
|
38
|
+
return connection;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('createLob', async () => {
|
|
42
|
+
const connection = await _getConnection();
|
|
43
|
+
const lob = await connection.createLob(BLOB);
|
|
44
|
+
expect(lob).toBeInstanceOf(Lob);
|
|
45
|
+
return lob;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('release', async () => {
|
|
49
|
+
const connection = await _getConnection();
|
|
50
|
+
return connection.release();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('Connection.execute', () => {
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
setExecuteCallback();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('execute', async () => {
|
|
60
|
+
const connection = await _getConnection();
|
|
61
|
+
expect(await connection.execute('select * from dual')).toStrictEqual({});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('execute with execution callback', async () => {
|
|
65
|
+
const connection = await _getConnection();
|
|
66
|
+
const SQL = 'select * from dual';
|
|
67
|
+
|
|
68
|
+
// register an execute callback
|
|
69
|
+
setExecuteCallback((sql: string) => {
|
|
70
|
+
expect(sql).toBe(SQL);
|
|
71
|
+
return {sql: SQL};
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(await connection.execute(SQL)).toStrictEqual({sql: SQL});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
* get connection pool
|
|
80
|
+
*/
|
|
81
|
+
function _createPool() {
|
|
82
|
+
return createPool({
|
|
83
|
+
user: 'sample',
|
|
84
|
+
password: 'sample',
|
|
85
|
+
connectString: 'localhost:1521/TEST'
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* get connection
|
|
91
|
+
*/
|
|
92
|
+
function _getConnection() {
|
|
93
|
+
return getConnection({
|
|
94
|
+
user: 'sample',
|
|
95
|
+
password: 'sample',
|
|
96
|
+
connectString: 'localhost:1521/TEST'
|
|
97
|
+
});
|
|
98
|
+
}
|