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.
Files changed (44) hide show
  1. package/.editorconfig +8 -8
  2. package/.eslintignore +3 -3
  3. package/.eslintrc.js +347 -273
  4. package/CHANGELOG.md +127 -106
  5. package/LICENSE +21 -21
  6. package/README.md +165 -164
  7. package/examples/apex.js +70 -70
  8. package/examples/credentials.js +22 -22
  9. package/examples/oracledb_example.js +30 -30
  10. package/examples/sample.js +101 -84
  11. package/examples/sql/doc_table.sql +13 -13
  12. package/examples/sql/install.sql +31 -31
  13. package/examples/sql/sample.pkb +223 -223
  14. package/examples/sql/sample.pks +24 -24
  15. package/examples/sql/uninstall.sql +5 -5
  16. package/examples/static/sample.css +25 -25
  17. package/jest.config.js +204 -0
  18. package/package.json +85 -109
  19. package/src/cgi.ts +95 -95
  20. package/src/config.ts +97 -97
  21. package/src/errorPage.ts +286 -286
  22. package/src/fileUpload.ts +126 -132
  23. package/src/index.ts +65 -66
  24. package/src/page.ts +275 -277
  25. package/src/procedure.ts +360 -359
  26. package/src/procedureError.ts +27 -27
  27. package/src/request.ts +139 -139
  28. package/src/requestError.ts +19 -19
  29. package/src/stream.ts +26 -26
  30. package/src/trace.ts +194 -193
  31. package/test/.eslintrc.json +5 -5
  32. package/test/{cgi.ts → __tests__/cgi.ts} +96 -95
  33. package/test/{config.ts → __tests__/config.ts} +41 -41
  34. package/test/__tests__/errorPage.ts +101 -0
  35. package/test/{oracledb_mock.ts → __tests__/oracledb_mock.ts} +98 -98
  36. package/test/{server.ts → __tests__/server.ts} +495 -498
  37. package/test/{stream.ts → __tests__/stream.ts} +21 -21
  38. package/test/mock/oracledb.ts +85 -85
  39. package/test/static/static.html +1 -1
  40. package/tsconfig.json +24 -23
  41. package/tsconfig.src.json +23 -22
  42. package/test/errorPage.ts +0 -101
  43. package/test/mocha.opts +0 -7
  44. package/tsconfig.test.json +0 -19
@@ -1,41 +1,41 @@
1
- import {assert} from 'chai';
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
- assert.strictEqual(typeof validate(options), 'object', JSON.stringify(options));
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
- assert.throws(() => {
37
- validate(test.config);
38
- }, test.error);
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 {assert} from 'chai';
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
- assert.isTrue(connectionPool instanceof ConnectionPool);
8
- return connectionPool;
9
- });
10
-
11
- it('getConnection', async () => {
12
- const connection = await _getConnection();
13
- assert.isTrue(connection instanceof 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
- assert.isTrue(connection instanceof 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
- assert.isTrue(connection instanceof Connection);
38
- return connection;
39
- });
40
-
41
- it('createLob', async () => {
42
- const connection = await _getConnection();
43
- const lob = await connection.createLob(BLOB);
44
- assert.isTrue(lob instanceof 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
- assert.deepEqual(await connection.execute('select * from dual'), {});
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
- assert.strictEqual(sql, SQL);
71
- return {sql: SQL};
72
- });
73
-
74
- assert.deepEqual(await connection.execute(SQL), {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
- }
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
+ }