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
package/examples/apex.js CHANGED
@@ -1,70 +1,70 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const express = require('express');
4
- const bodyParser = require('body-parser');
5
- const multipart = require('connect-multiparty');
6
- const cookieParser = require('cookie-parser');
7
- const compression = require('compression');
8
- const morgan = require('morgan');
9
-
10
- const oracledb = require('oracledb');
11
- const webplsql = require('../lib');
12
-
13
- /*
14
- * Allocate the Oracle database pool
15
- */
16
-
17
- const connectionPool = oracledb.createPool({
18
- user: 'APEX_PUBLIC_USER',
19
- password: 'manager',
20
- connectString: 'localhost:1521/TEST',
21
- poolMin: 10,
22
- poolMax: 1000,
23
- poolIncrement: 10,
24
- queueRequests: false,
25
- queueTimeout: 1000
26
- });
27
-
28
- connectionPool.catch(e => {
29
- console.error(`Unable to create database pool.\n${e.message}`);
30
- process.exit(1);
31
- });
32
-
33
- /*
34
- * Start the server
35
- */
36
-
37
- const PORT = 8000;
38
- const PATH = '/apex';
39
- const OPTIONS = {
40
- trace: 'on',
41
- defaultPage: 'apex',
42
- doctable: 'wwv_flow_file_objects$',
43
- pathAlias: {
44
- alias: 'r',
45
- procedure: 'wwv_flow.resolve_friendly_url'
46
- },
47
- errorStyle: 'debug'
48
- };
49
-
50
- // create express app
51
- const app = express();
52
-
53
- // add middleware
54
- app.use(multipart());
55
- app.use(bodyParser.json());
56
- app.use(bodyParser.urlencoded({extended: true}));
57
- app.use(cookieParser());
58
- app.use(compression());
59
- app.use(morgan('combined', {stream: fs.createWriteStream(path.join(process.cwd(), 'access.log'), {flags: 'a'})}));
60
-
61
- // add the oracle pl/sql express middleware
62
- app.use(PATH + '/:name?', webplsql(connectionPool, OPTIONS));
63
-
64
- // serving static files
65
- const staticFilesPath = path.resolve('/Middleware/apex/images/');
66
- app.use('/i/', express.static(staticFilesPath));
67
-
68
- // listen on port
69
- console.log(`Listening on http://localhost:${PORT}${PATH}`);
70
- app.listen(PORT);
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const express = require('express');
4
+ const bodyParser = require('body-parser');
5
+ const multipart = require('connect-multiparty');
6
+ const cookieParser = require('cookie-parser');
7
+ const compression = require('compression');
8
+ const morgan = require('morgan');
9
+
10
+ const oracledb = require('oracledb');
11
+ const webplsql = require('../lib');
12
+
13
+ /*
14
+ * Allocate the Oracle database pool
15
+ */
16
+
17
+ const connectionPool = oracledb.createPool({
18
+ user: 'APEX_PUBLIC_USER',
19
+ password: 'manager',
20
+ connectString: 'localhost:1521/TEST',
21
+ poolMin: 10,
22
+ poolMax: 1000,
23
+ poolIncrement: 10,
24
+ queueRequests: false,
25
+ queueTimeout: 1000
26
+ });
27
+
28
+ connectionPool.catch(e => {
29
+ console.error(`Unable to create database pool.\n${e.message}`);
30
+ process.exit(1);
31
+ });
32
+
33
+ /*
34
+ * Start the server
35
+ */
36
+
37
+ const PORT = 8000;
38
+ const PATH = '/apex';
39
+ const OPTIONS = {
40
+ trace: 'on',
41
+ defaultPage: 'apex',
42
+ doctable: 'wwv_flow_file_objects$',
43
+ pathAlias: {
44
+ alias: 'r',
45
+ procedure: 'wwv_flow.resolve_friendly_url'
46
+ },
47
+ errorStyle: 'debug'
48
+ };
49
+
50
+ // create express app
51
+ const app = express();
52
+
53
+ // add middleware
54
+ app.use(multipart());
55
+ app.use(bodyParser.json());
56
+ app.use(bodyParser.urlencoded({extended: true}));
57
+ app.use(cookieParser());
58
+ app.use(compression());
59
+ app.use(morgan('combined', {stream: fs.createWriteStream(path.join(process.cwd(), 'access.log'), {flags: 'a'})}));
60
+
61
+ // add the oracle pl/sql express middleware
62
+ app.use(PATH + '/:name?', webplsql(connectionPool, OPTIONS));
63
+
64
+ // serving static files
65
+ const staticFilesPath = path.resolve('/Middleware/apex/images/');
66
+ app.use('/i/', express.static(staticFilesPath));
67
+
68
+ // listen on port
69
+ console.log(`Listening on http://localhost:${PORT}${PATH}`);
70
+ app.listen(PORT);
@@ -1,22 +1,22 @@
1
- /*
2
- * Holds the credentials used to connect to the database.
3
- */
4
-
5
- module.exports = {
6
- user : process.env.NODE_ORACLEDB_USER || 'sample',
7
-
8
- // Get the password from the environment variable
9
- // NODE_ORACLEDB_PASSWORD. The password could also be a hard coded
10
- // string (not recommended), or it could be prompted for.
11
- // Alternatively use External Authentication so that no password is
12
- // needed.
13
- password : process.env.NODE_ORACLEDB_PASSWORD || 'sample',
14
-
15
- // For information on connection strings see:
16
- // https://oracle.github.io/node-oracledb/doc/api.html#connectionstrings
17
- connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || 'localhost:1521/test',
18
-
19
- // Setting externalAuth is optional. It defaults to false. See:
20
- // https://oracle.github.io/node-oracledb/doc/api.html#extauth
21
- externalAuth : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
22
- };
1
+ /*
2
+ * Holds the credentials used to connect to the database.
3
+ */
4
+
5
+ module.exports = {
6
+ user : process.env.NODE_ORACLEDB_USER || 'sample',
7
+
8
+ // Get the password from the environment variable
9
+ // NODE_ORACLEDB_PASSWORD. The password could also be a hard coded
10
+ // string (not recommended), or it could be prompted for.
11
+ // Alternatively use External Authentication so that no password is
12
+ // needed.
13
+ password : process.env.NODE_ORACLEDB_PASSWORD || 'sample',
14
+
15
+ // For information on connection strings see:
16
+ // https://oracle.github.io/node-oracledb/doc/api.html#connectionstrings
17
+ connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || 'localhost:1521/test',
18
+
19
+ // Setting externalAuth is optional. It defaults to false. See:
20
+ // https://oracle.github.io/node-oracledb/doc/api.html#extauth
21
+ externalAuth : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
22
+ };
@@ -1,30 +1,30 @@
1
- const oracledb = require('oracledb');
2
- const dbConfig = require('./credentials.js');
3
-
4
- async function run() {
5
- let connection;
6
-
7
- try {
8
- // Connect to database
9
- connection = await oracledb.getConnection(dbConfig);
10
-
11
- // Select some data
12
- binds = {};
13
- result = await connection.execute('SELECT sysdate FROM dual', binds, {});
14
- console.log('metadata: ', result.metaData);
15
- console.log('results: ');
16
- console.log(result.rows);
17
- } catch (err) {
18
- console.error(err);
19
- } finally {
20
- if (connection) {
21
- try {
22
- await connection.close();
23
- } catch (err) {
24
- console.error(err);
25
- }
26
- }
27
- }
28
- }
29
-
30
- run();
1
+ const oracledb = require('oracledb');
2
+ const dbConfig = require('./credentials.js');
3
+
4
+ async function run() {
5
+ let connection;
6
+
7
+ try {
8
+ // Connect to database
9
+ connection = await oracledb.getConnection(dbConfig);
10
+
11
+ // Select some data
12
+ binds = {};
13
+ result = await connection.execute('SELECT sysdate FROM dual', binds, {});
14
+ console.log('metadata: ', result.metaData);
15
+ console.log('results: ');
16
+ console.log(result.rows);
17
+ } catch (err) {
18
+ console.error(err);
19
+ } finally {
20
+ if (connection) {
21
+ try {
22
+ await connection.close();
23
+ } catch (err) {
24
+ console.error(err);
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ run();
@@ -1,84 +1,101 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const express = require('express');
4
- const bodyParser = require('body-parser');
5
- const multipart = require('connect-multiparty');
6
- const cookieParser = require('cookie-parser');
7
- const compression = require('compression');
8
- const morgan = require('morgan');
9
-
10
- const oracledb = require('oracledb');
11
- const webplsql = require('../lib');
12
-
13
-
14
- /*
15
- * Holds the credentials used by node-oracledb examples to connect
16
- * to the database. Production applications should consider using
17
- * External Authentication to avoid hard coded credentials.
18
- */
19
- const dbConfig = require('./credentials.js');
20
-
21
- /*
22
- * Allocate the Oracle database pool
23
- */
24
-
25
- const connectionPool = oracledb.createPool({
26
- user: dbConfig.user, // The database user name.
27
- password: dbConfig.password, // The password of the database user.
28
- connectString: dbConfig.connectString, // The Oracle database instance to connect to. The string can be an Easy Connect string, or a Net Service Name from a tnsnames.ora file, or the name of a local Oracle database instance.
29
- poolMin: 10, // The minimum number of connections a connection pool maintains, even when there is no activity to the target database.
30
- poolMax: 1000, // The maximum number of connections to which a connection pool can grow.
31
- poolIncrement: 10, // The number of connections that are opened whenever a connection request exceeds the number of currently open connections.
32
- queueRequests: false, // If this property is false and a request for a connection is made from a pool where the number of “checked out” connections has reached poolMax, then an ORA-24418 error indicating that further sessions cannot be opened will be returned.
33
- queueTimeout: 1000 // The number of milliseconds after which connection requests waiting in the connection request queue are terminated. If queueTimeout is 0, then queued connection requests are never terminated.
34
- });
35
-
36
- connectionPool.catch(e => {
37
- console.error(`Unable to create database pool.\n${e.message}`);
38
- process.exit(1);
39
- });
40
-
41
- /*
42
- * Start the server
43
- */
44
-
45
- const PORT = 8000;
46
- const PATH = '/base';
47
- const OPTIONS = {
48
- trace: 'on',
49
- defaultPage: 'sample.pageIndex',
50
- doctable: 'docTable',
51
- pathAlias: {
52
- alias: 'myalias',
53
- procedure: 'sample.pagePathAlias'
54
- },
55
- errorStyle: 'debug'
56
- };
57
-
58
- // Welcome message
59
- console.log(`Welcome to web_plsql version ${webplsql.version}!`);
60
-
61
- // create express app
62
- const app = express();
63
-
64
- // add middleware
65
- app.use(multipart());
66
- app.use(bodyParser.json());
67
- app.use(bodyParser.urlencoded({extended: true}));
68
- app.use(cookieParser());
69
- app.use(compression());
70
- app.use(morgan('combined', {stream: fs.createWriteStream(path.join(process.cwd(), 'access.log'), {flags: 'a'})}));
71
-
72
- // add express status monitor
73
- app.use(require('express-status-monitor')());
74
- console.log(`Express status monitor is listening on http://localhost:${PORT}/status`);
75
-
76
- // add the oracle pl/sql express middleware
77
- app.use(PATH + '/:name?', webplsql(connectionPool, OPTIONS));
78
-
79
- // serving static files
80
- app.use('/static', express.static(path.join(process.cwd(), 'examples/static')));
81
-
82
- // listen on port
83
- console.log(`Sample app is listening on http://localhost:${PORT}${PATH}`);
84
- app.listen(PORT);
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const express = require('express');
4
+ const bodyParser = require('body-parser');
5
+ const multipart = require('connect-multiparty');
6
+ const cookieParser = require('cookie-parser');
7
+ const compression = require('compression');
8
+ const morgan = require('morgan');
9
+
10
+ const oracledb = require('oracledb');
11
+ const webplsql = require('../lib');
12
+
13
+
14
+ /*
15
+ * Holds the credentials used by node-oracledb examples to connect
16
+ * to the database. Production applications should consider using
17
+ * External Authentication to avoid hard coded credentials.
18
+ */
19
+ const dbConfig = require('./credentials.js');
20
+
21
+ /*
22
+ * Allocate the Oracle database pool
23
+ */
24
+
25
+ const connectionPool = oracledb.createPool({
26
+ user: dbConfig.user, // The database user name.
27
+ password: dbConfig.password, // The password of the database user.
28
+ connectString: dbConfig.connectString, // The Oracle database instance to connect to. The string can be an Easy Connect string, or a Net Service Name from a tnsnames.ora file, or the name of a local Oracle database instance.
29
+ poolMin: 10, // The minimum number of connections a connection pool maintains, even when there is no activity to the target database.
30
+ poolMax: 1000, // The maximum number of connections to which a connection pool can grow.
31
+ poolIncrement: 10, // The number of connections that are opened whenever a connection request exceeds the number of currently open connections.
32
+ queueRequests: false, // If this property is false and a request for a connection is made from a pool where the number of “checked out” connections has reached poolMax, then an ORA-24418 error indicating that further sessions cannot be opened will be returned.
33
+ queueTimeout: 1000 // The number of milliseconds after which connection requests waiting in the connection request queue are terminated. If queueTimeout is 0, then queued connection requests are never terminated.
34
+ });
35
+
36
+ connectionPool.catch(e => {
37
+ console.error(`Unable to create database pool.\n${e.message}`);
38
+ process.exit(1);
39
+ });
40
+
41
+ /*
42
+ * Start the server
43
+ */
44
+
45
+ const PORT = 8000;
46
+ const PATH = '/base';
47
+ const OPTIONS = {
48
+ trace: 'on',
49
+ defaultPage: 'sample.pageIndex',
50
+ doctable: 'docTable',
51
+ pathAlias: {
52
+ alias: 'myalias',
53
+ procedure: 'sample.pagePathAlias'
54
+ },
55
+ errorStyle: 'debug'
56
+ };
57
+
58
+ // Welcome message
59
+ console.log(`Welcome to web_plsql version ${webplsql.version}!`);
60
+
61
+ // create express app
62
+ const app = express();
63
+
64
+ // add middleware
65
+ app.use(multipart());
66
+ app.use(bodyParser.json());
67
+ app.use(bodyParser.urlencoded({extended: true}));
68
+ app.use(cookieParser());
69
+ app.use(compression());
70
+ app.use(morgan('combined', {stream: fs.createWriteStream(path.join(process.cwd(), 'access.log'), {flags: 'a'})}));
71
+
72
+ // add express status monitor
73
+ app.use(require('express-status-monitor')());
74
+ console.log(`Express status monitor is listening on http://localhost:${PORT}/status`);
75
+
76
+ // add the oracle pl/sql express middleware
77
+ app.use(PATH + '/:name?', webplsql(connectionPool, OPTIONS));
78
+
79
+ // serving static files
80
+ app.use('/static', express.static(path.join(process.cwd(), 'examples/static')));
81
+
82
+ // shutdown
83
+ process.on('SIGTERM', shutDown);
84
+ process.on('SIGINT', shutDown);
85
+
86
+ // listen on port
87
+ console.log(`Sample app is listening on http://localhost:${PORT}${PATH}`);
88
+ const server = app.listen(PORT);
89
+
90
+ function shutDown() {
91
+ console.log('Received kill signal, shutting down gracefully');
92
+ server.close(() => {
93
+ console.log('Closed out remaining connections');
94
+ process.exit(0);
95
+ });
96
+
97
+ setTimeout(() => {
98
+ console.error('Could not close connections in time, forcefully shutting down');
99
+ process.exit(1);
100
+ }, 10000);
101
+ }
@@ -1,13 +1,13 @@
1
- DROP TABLE docTable;
2
-
3
- CREATE TABLE docTable
4
- (
5
- NAME VARCHAR(128) UNIQUE NOT NULL,
6
- MIME_TYPE VARCHAR(128),
7
- DOC_SIZE NUMBER,
8
- DAD_CHARSET VARCHAR(128),
9
- LAST_UPDATED DATE,
10
- CONTENT_TYPE VARCHAR(128),
11
- CONTENT LONG RAW,
12
- BLOB_CONTENT BLOB
13
- );
1
+ DROP TABLE docTable;
2
+
3
+ CREATE TABLE docTable
4
+ (
5
+ NAME VARCHAR(128) UNIQUE NOT NULL,
6
+ MIME_TYPE VARCHAR(128),
7
+ DOC_SIZE NUMBER,
8
+ DAD_CHARSET VARCHAR(128),
9
+ LAST_UPDATED DATE,
10
+ CONTENT_TYPE VARCHAR(128),
11
+ CONTENT LONG RAW,
12
+ BLOB_CONTENT BLOB
13
+ );
@@ -1,31 +1,31 @@
1
- -- set the username
2
- define SAMPLE_USER=sample
3
-
4
- -- create user
5
- CREATE USER &&SAMPLE_USER IDENTIFIED BY &&SAMPLE_USER;
6
-
7
- -- assign privileges
8
- GRANT create session TO &&SAMPLE_USER;
9
- GRANT unlimited tablespace TO &&SAMPLE_USER;
10
- GRANT create table TO &&SAMPLE_USER;
11
- GRANT create view TO &&SAMPLE_USER;
12
- GRANT create sequence TO &&SAMPLE_USER;
13
- GRANT create procedure TO &&SAMPLE_USER;
14
- GRANT execute on dbms_lob TO &&SAMPLE_USER;
15
- GRANT execute on dbms_output TO &&SAMPLE_USER;
16
- GRANT execute on dbms_lock TO &&SAMPLE_USER;
17
-
18
- -- change schema
19
- ALTER SESSION SET CURRENT_SCHEMA=&&SAMPLE_USER;
20
-
21
- -- install document table
22
- @doc_table.sql
23
-
24
- -- install demo
25
- @sample.pks
26
- show errors
27
- @sample.pkb
28
- show errors
29
-
30
- -- show errors
31
- select * from user_errors;
1
+ -- set the username
2
+ define SAMPLE_USER=sample
3
+
4
+ -- create user
5
+ CREATE USER &&SAMPLE_USER IDENTIFIED BY &&SAMPLE_USER;
6
+
7
+ -- assign privileges
8
+ GRANT create session TO &&SAMPLE_USER;
9
+ GRANT unlimited tablespace TO &&SAMPLE_USER;
10
+ GRANT create table TO &&SAMPLE_USER;
11
+ GRANT create view TO &&SAMPLE_USER;
12
+ GRANT create sequence TO &&SAMPLE_USER;
13
+ GRANT create procedure TO &&SAMPLE_USER;
14
+ GRANT execute on dbms_lob TO &&SAMPLE_USER;
15
+ GRANT execute on dbms_output TO &&SAMPLE_USER;
16
+ GRANT execute on dbms_lock TO &&SAMPLE_USER;
17
+
18
+ -- change schema
19
+ ALTER SESSION SET CURRENT_SCHEMA=&&SAMPLE_USER;
20
+
21
+ -- install document table
22
+ @doc_table.sql
23
+
24
+ -- install demo
25
+ @sample.pks
26
+ show errors
27
+ @sample.pkb
28
+ show errors
29
+
30
+ -- show errors
31
+ select * from user_errors;