web_plsql 0.8.0 → 0.11.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 CHANGED
@@ -24,21 +24,28 @@ Please visit the [node-oracledb](https://node-oracledb.readthedocs.io/en/latest/
24
24
  * Create a new npm project (`npm i`)
25
25
  * Install package (`npm i --omit=dev web_plsql`)
26
26
 
27
- # Example (native)
27
+ # Example
28
+
29
+ ## Native
28
30
  * Change to the `examples/sql` directory, start SQLPLus, connect to the database as SYS specifying the SYSDBA roleInstall and install the sample schema `@examples/sql/install.sql`.
29
- * Start server using `node examples/server_sample.js` after having set the WEB_PLSQL_ORACLE_SERVER environment variable to the database where you just installed the sample schema.
31
+ * Start server using `node examples/config-native.js` after having set the WEB_PLSQL_ORACLE_SERVER environment variable to the database where you just installed the sample schema.
30
32
  * Invoke a browser and open the page `http://localhost/sample`.
31
33
 
32
- # Example (container)
33
- * Build the image using `npm run image-build`
34
- * Start the container using `./run_container.sh` after eventually modifying the `run_container.sh` script.
34
+ ## Container
35
+ * Build the image using `npm run image-build`.
36
+ * Adapt the `examples/config-docker.json` configuration file. Typically only the `connectString` property must be changed.
37
+ * Start the container using `docker compose up -d`.
38
+
39
+ # Configuration
40
+
41
+ There are 2 options on how to use the web_plsql express middleware:
42
+ - Use the predefined `startHttpServer` api in `src/server.js` like in the `examples/config-native.js` example
43
+ - Hand craft a new Express server using the `handlerWebPlSql` middleware in `src/handlerPlSql.js`
35
44
 
36
- # Running
37
- There are 2 main options on how to use the mod_plsql Express middleware:
45
+ ## Use the predefined `startHttpServer`
38
46
 
39
- ## Make a copy of the `server_sample.js` sample script and configure it accordingly to your needs.
47
+ The `startHttpServer` api uses the following configuration object:
40
48
 
41
- The the default server implemented in `src/server.js` and has the following configuration options:
42
49
  ```
43
50
  /**
44
51
  * @typedef {'basic' | 'debug'} errorStyleType
@@ -77,6 +84,12 @@ export const z$errorStyleType = z.enum(['basic', 'debug']);
77
84
  */
78
85
  ```
79
86
 
87
+ ## Hand craft a new Express server using the `handlerWebPlSql` middleware
88
+
89
+ WIP
90
+
91
+ # Compare with mod_plsql
92
+
80
93
  The following mod_plsql DAD configuration translates to the configuration options as follows:
81
94
 
82
95
  **DAD**
@@ -13,7 +13,7 @@ void startHttpServer({
13
13
  route: '/apex',
14
14
  user: 'APEX_PUBLIC_USER',
15
15
  password: 'secret',
16
- connectString: process.env.ORACLE_SERVER ?? '',
16
+ connectString: 'localhost:1521/orcl',
17
17
  defaultPage: 'apex',
18
18
  pathAlias: 'r',
19
19
  pathAliasProcedure: 'wwv_flow.resolve_friendly_url',
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ // @ts-expect-error NOTE: the following import would show an error because the path does not exist
4
+ import {startHttpServer} from './src/index.js';
5
+
6
+ void startHttpServer({
7
+ port: 8888,
8
+ routeStatic: [
9
+ {
10
+ route: '/static',
11
+ directoryPath: 'examples/static',
12
+ },
13
+ ],
14
+ routePlSql: [
15
+ {
16
+ route: '/sample',
17
+ user: 'sample', // PlsqlDatabaseUserName
18
+ password: 'sample', // PlsqlDatabasePassword
19
+ connectString: 'host.docker.internal:1521/TEST', // PlsqlDatabaseConnectString
20
+ defaultPage: 'sample_pkg.page_index', // PlsqlDefaultPage
21
+ documentTable: 'doctable', // PlsqlDocumentTablename
22
+ exclusionList: ['sample_pkg.page_exclusion_list'], // PlsqlExclusionList
23
+ requestValidationFunction: 'sample_pkg.request_validation_function', // PlsqlRequestValidationFunction
24
+ pathAlias: 'myalias', // PlsqlPathAlias
25
+ pathAliasProcedure: 'sample_pkg.page_path_alias', // PlsqlPathAliasProcedure
26
+ errorStyle: 'debug', // PlsqlErrorStyle
27
+ },
28
+ ],
29
+ loggerFilename: 'access.log', // PlsqlLogEnable and PlsqlLogDirectory
30
+ monitorConsole: false,
31
+ });
@@ -0,0 +1,26 @@
1
+ {
2
+ "port": 8888,
3
+ "routeStatic": [
4
+ {
5
+ "route": "/static",
6
+ "directoryPath": "examples/static"
7
+ }
8
+ ],
9
+ "routePlSql": [
10
+ {
11
+ "route": "/sample",
12
+ "user": "sample",
13
+ "password": "sample",
14
+ "connectString": "host.docker.internal:1521/TEST",
15
+ "defaultPage": "sample_pkg.page_index",
16
+ "documentTable": "doctable",
17
+ "exclusionList": ["sample_pkg.page_exclusion_list"],
18
+ "requestValidationFunction": "sample_pkg.request_validation_function",
19
+ "pathAlias": "myalias",
20
+ "pathAliasProcedure": "sample_pkg.page_path_alias",
21
+ "errorStyle": "debug"
22
+ }
23
+ ],
24
+ "loggerFilename": "access.log",
25
+ "monitorConsole": false
26
+ }
@@ -13,9 +13,9 @@ void startHttpServer({
13
13
  routePlSql: [
14
14
  {
15
15
  route: '/sample',
16
- user: process.env.WEB_PLSQL_ORACLE_USER ?? 'sample', // PlsqlDatabaseUserName
17
- password: process.env.WEB_PLSQL_ORACLE_PASSWORD ?? 'sample', // PlsqlDatabasePassword
18
- connectString: process.env.WEB_PLSQL_ORACLE_SERVER ?? 'localhost:1521/orcl', // PlsqlDatabaseConnectString
16
+ user: 'sample', // PlsqlDatabaseUserName
17
+ password: 'sample', // PlsqlDatabasePassword
18
+ connectString: process.env.WEB_PLSQL_ORACLE_SERVER ?? 'localhost:1521/TEST', // PlsqlDatabaseConnectString
19
19
  defaultPage: 'sample_pkg.page_index', // PlsqlDefaultPage
20
20
  documentTable: 'doctable', // PlsqlDocumentTablename
21
21
  exclusionList: ['sample_pkg.page_exclusion_list'], // PlsqlExclusionList
@@ -19,10 +19,10 @@ GRANT execute on dbms_lob TO &&SAMPLE_USER;
19
19
  ALTER SESSION SET CURRENT_SCHEMA=&&SAMPLE_USER;
20
20
 
21
21
  -- install document table
22
- @doctable.sql
22
+ @@doctable.sql
23
23
 
24
24
  -- install package
25
- @sample_package.sql
25
+ @@sample_package.sql
26
26
  show errors
27
- @sample_package_body.sql
27
+ @@sample_package_body.sql
28
28
  show errors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web_plsql",
3
- "version": "0.8.0",
3
+ "version": "0.11.0",
4
4
  "author": "Dieter Oberkofler <dieter.oberkofler@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "The Express Middleware for Oracle PL/SQL",
@@ -43,52 +43,53 @@
43
43
  "types": "./types/index.d.ts",
44
44
  "type": "module",
45
45
  "scripts": {
46
- "lint": "prettier --check . && eslint . && tsc --noEmit",
46
+ "lint": "prettier --check --experimental-cli . && eslint . && tsc --noEmit",
47
47
  "test": "node --test --test-concurrency=1 \"./tests/**/*.test.js\"",
48
- "types": "rm -rf types && tsc --noEmit false --declaration true --declarationDir types --emitDeclarationOnly true --allowJs true --target es2020 --module es2020 --moduleResolution node src/*.js",
48
+ "types": "rm -rf types && tsc --noEmit false --declaration true --declarationDir types --emitDeclarationOnly true --allowJs true --target es2020 --module es2020 --moduleResolution node --allowSyntheticDefaultImports true src/*.js",
49
49
  "clean": "shx rm -f *.tgz && shx rm -f *.log",
50
50
  "ci": "npm run clean && npm run lint && npm run test",
51
51
  "create-package": "shx rm -f *.tgz && npm pack",
52
52
  "image-build": "docker build --no-cache --progress=plain --tag=web_plsql .",
53
53
  "image-save": "docker save web_plsql | gzip > web_plsql.tar.gz"
54
54
  },
55
+ "peerDependencies": {
56
+ "oracledb": "6.9.0"
57
+ },
55
58
  "dependencies": {
56
59
  "basic-auth": "2.0.1",
57
60
  "body-parser": "2.2.0",
58
- "compression": "1.8.0",
59
- "connect-multiparty": "2.2.0",
61
+ "compression": "1.8.1",
60
62
  "cookie-parser": "1.4.7",
61
- "debug": "4.4.0",
63
+ "debug": "4.4.1",
62
64
  "escape-html": "1.0.3",
63
65
  "express": "5.1.0",
64
- "fs-extra": "11.3.0",
66
+ "fs-extra": "11.3.1",
65
67
  "http-parser-js": "0.5.10",
66
- "morgan": "1.10.0",
67
- "multer": "1.4.5-lts.2",
68
- "oracledb": "6.8.0",
68
+ "morgan": "1.10.1",
69
+ "multer": "2.0.2",
69
70
  "rotating-file-stream": "3.2.6",
70
- "zod": "3.24.2"
71
+ "zod": "4.0.17"
71
72
  },
72
73
  "devDependencies": {
73
74
  "@types/basic-auth": "1.1.8",
74
- "@types/body-parser": "1.19.5",
75
- "@types/compression": "1.7.5",
76
- "@types/cookie-parser": "1.4.8",
75
+ "@types/body-parser": "1.19.6",
76
+ "@types/compression": "1.8.1",
77
+ "@types/cookie-parser": "1.4.9",
77
78
  "@types/debug": "4.1.12",
78
79
  "@types/escape-html": "1.0.4",
79
80
  "@types/fs-extra": "11.0.4",
80
- "@types/morgan": "1.9.9",
81
- "@types/multer": "1.4.12",
82
- "@types/node": "22.14.1",
83
- "@types/oracledb": "6.6.0",
81
+ "@types/morgan": "1.9.10",
82
+ "@types/multer": "2.0.0",
83
+ "@types/node": "24.3.0",
84
+ "@types/oracledb": "6.9.1",
84
85
  "@types/supertest": "6.0.3",
85
- "eslint": "9.24.0",
86
- "eslint-plugin-jsdoc": "50.6.9",
87
- "prettier": "3.5.3",
86
+ "eslint": "9.33.0",
87
+ "eslint-plugin-jsdoc": "54.1.1",
88
+ "prettier": "3.6.2",
88
89
  "rimraf": "6.0.1",
89
90
  "shx": "0.4.0",
90
- "supertest": "7.1.0",
91
- "typescript": "5.8.3",
92
- "typescript-eslint": "8.30.1"
91
+ "supertest": "7.1.4",
92
+ "typescript": "5.9.2",
93
+ "typescript-eslint": "8.40.0"
93
94
  }
94
95
  }
package/src/procedure.js CHANGED
@@ -33,51 +33,69 @@ import {errorToString} from './error.js';
33
33
 
34
34
  /**
35
35
  * Get the SQL statement to execute when a new procedure is invoked
36
+ *
37
+ * NOTE:
38
+ * 1) dbms_session.modify_package_state(dbms_session.reinitialize) is used to ensure a stateless environment by resetting package state (dbms_session.reset_package)
39
+ *
36
40
  * @param {string} procedure - The procedure
37
41
  * @returns {string} - The SQL statement to execute
38
42
  */
39
- const getProcedureSQL = (procedure) => `DECLARE
40
- fileType VARCHAR2(32767);
41
- fileSize INTEGER;
42
- fileBlob BLOB;
43
- fileExist INTEGER := 0;
43
+ const getProcedureSQL = (procedure) => `
44
+ DECLARE
45
+ l_file_type VARCHAR2(32767);
46
+ l_file_size INTEGER;
47
+ l_file_exists INTEGER := 0;
44
48
  BEGIN
45
- -- Ensure a stateless environment by resetting package state (dbms_session.reset_package)
46
49
  dbms_session.modify_package_state(dbms_session.reinitialize);
47
-
48
- -- initialize the cgi
49
50
  owa.init_cgi_env(:cgicount, :cginames, :cgivalues);
50
-
51
- -- initialize the htp package
52
51
  htp.init;
53
-
54
- -- set the HTBUF_LEN
55
52
  htp.HTBUF_LEN := :htbuflen;
56
53
 
57
- -- execute the procedure
58
54
  BEGIN
59
55
  ${procedure}
60
56
  EXCEPTION WHEN OTHERS THEN
61
- raise_application_error(-20000, 'Error executing ${procedure}'||CHR(10)||SUBSTR(dbms_utility.format_error_stack()||CHR(10)||dbms_utility.format_error_backtrace(), 1, 2000));
57
+ raise_application_error(-20000, 'Error executing "${procedure}"', TRUE);
62
58
  END;
63
59
 
64
- -- Check for file download
65
60
  IF (wpg_docload.is_file_download()) THEN
66
- wpg_docload.get_download_file(fileType);
67
- IF (filetype = 'B') THEN
68
- fileExist := 1;
61
+ wpg_docload.get_download_file(l_file_type);
62
+ IF (l_file_type = 'B') THEN
63
+ l_file_exists := 1;
69
64
  wpg_docload.get_download_blob(:fileBlob);
70
- fileSize := dbms_lob.getlength(:fileBlob);
71
- --dbms_lob.copy(dest_lob=>:fileBlob, src_lob=>fileBlob, amount=>fileSize);
65
+ l_file_size := dbms_lob.getlength(:fileBlob);
72
66
  END IF;
73
67
  END IF;
74
- :fileExist := fileExist;
75
- :fileType := fileType;
76
- :fileSize := fileSize;
68
+ :fileExist := l_file_exists;
69
+ :fileType := l_file_type;
70
+ :fileSize := l_file_size;
77
71
 
78
- -- retrieve the page
79
72
  owa.get_page(thepage=>:lines, irows=>:irows);
80
- END;`;
73
+ END;
74
+ `;
75
+
76
+ /**
77
+ * Get the procedure and arguments to execute
78
+ * @param {string} procName - The procedure to execute
79
+ * @param {argObjType} argObj - The arguments to pass to the procedure
80
+ * @param {configPlSqlHandlerType} options - The options for the middleware
81
+ * @param {Connection} databaseConnection - The database connection
82
+ * @returns {Promise<{sql: string; bind: BindParameterConfig}>} - The SQL statement and bindings for the procedure to execute
83
+ */
84
+ const getProcedure = async (procName, argObj, options, databaseConnection) => {
85
+ if (options.pathAlias && options.pathAlias.toLowerCase() === procName.toLowerCase()) {
86
+ debug(`getProcedure: path alias "${options.pathAlias}" redirects to "${options.pathAliasProcedure}"`);
87
+ return {
88
+ sql: `${options.pathAliasProcedure}(p_path=>:p_path);`,
89
+ bind: {
90
+ p_path: {dir: oracledb.BIND_IN, type: oracledb.STRING, val: procName},
91
+ },
92
+ };
93
+ } else if (procName.startsWith('!')) {
94
+ return await getProcedureVariable(procName.substring(1), argObj, databaseConnection, options);
95
+ }
96
+
97
+ return await getProcedureNamed(procName, argObj, databaseConnection, options);
98
+ };
81
99
 
82
100
  /**
83
101
  * Invoke the Oracle procedure and return the page content
@@ -234,27 +252,3 @@ export const invokeProcedure = async (req, res, argObj, cgiObj, filesToUpload, o
234
252
 
235
253
  debug('invokeProcedure: EXIT');
236
254
  };
237
-
238
- /**
239
- * Get the procedure and arguments to execute
240
- * @param {string} procName - The procedure to execute
241
- * @param {argObjType} argObj - The arguments to pass to the procedure
242
- * @param {configPlSqlHandlerType} options - The options for the middleware
243
- * @param {Connection} databaseConnection - The database connection
244
- * @returns {Promise<{sql: string; bind: BindParameterConfig}>} - The SQL statement and bindings for the procedure to execute
245
- */
246
- const getProcedure = async (procName, argObj, options, databaseConnection) => {
247
- if (options.pathAlias && options.pathAlias.toLowerCase() === procName.toLowerCase()) {
248
- debug(`getProcedure: path alias "${options.pathAlias}" redirects to "${options.pathAliasProcedure}"`);
249
- return {
250
- sql: `${options.pathAliasProcedure}(p_path=>:p_path);`,
251
- bind: {
252
- p_path: {dir: oracledb.BIND_IN, type: oracledb.STRING, val: procName},
253
- },
254
- };
255
- } else if (procName.startsWith('!')) {
256
- return await getProcedureVariable(procName.substring(1), argObj, databaseConnection, options);
257
- }
258
-
259
- return await getProcedureNamed(procName, argObj, databaseConnection, options);
260
- };
@@ -135,7 +135,7 @@ const loadRequestValid = async (procName, requestValidationFunction, databaseCon
135
135
  }
136
136
 
137
137
  try {
138
- const data = z.object({valid: z.number()}).strict().parse(result.outBinds);
138
+ const data = z.strictObject({valid: z.number()}).parse(result.outBinds);
139
139
  return data.valid === 1;
140
140
  } catch (err) {
141
141
  debug('result', result.outBinds);
package/src/request.js CHANGED
@@ -48,9 +48,9 @@ export const processRequest = async (req, res, options, connectionPool) => {
48
48
  const argObj = {};
49
49
  Object.assign(argObj, req.query);
50
50
 
51
- // Add the files to the arguments
51
+ // For add the files that must be uploaded, we now copy the actual filename to the appropriate prameter to the invoked procedure.
52
52
  filesToUpload.reduce((aggregator, file) => {
53
- aggregator[file.fieldname] = file.originalname;
53
+ aggregator[file.fieldname] = file.filename;
54
54
  return aggregator;
55
55
  }, argObj);
56
56
 
package/src/server.js CHANGED
@@ -28,6 +28,54 @@ import {readFileSyncUtf8, getJsonFile} from './file.js';
28
28
  * @typedef {import('./types.js').configType} configType
29
29
  */
30
30
 
31
+ /**
32
+ * Show configuration.
33
+ * @param {configType} config - The config.
34
+ * @returns {void}
35
+ */
36
+ export const showConfig = (config) => {
37
+ const expressVersion = getExpressVersion();
38
+ const packageVersion = getPackageVersion();
39
+
40
+ console.log('-'.repeat(80));
41
+ console.log('NODE PL/SQL SERVER');
42
+ console.log('-'.repeat(80));
43
+
44
+ console.log(`Application version: ${packageVersion}`);
45
+ console.log(`Express version: ${expressVersion}`);
46
+ console.log(`Server port: ${config.port}`);
47
+ console.log(`Access log: ${config.loggerFilename.length > 0 ? config.loggerFilename : ''}`);
48
+ console.log(`Monitor console: ${config.monitorConsole ? 'on' : 'off'}`);
49
+
50
+ if (config.routeStatic.length > 0) {
51
+ console.log('');
52
+ config.routeStatic.forEach((e, i) => {
53
+ console.log(`Static route #${i + 1}`);
54
+ console.log(` Route: "${e.route}"`);
55
+ console.log(` Directory path: "${e.directoryPath}"`);
56
+ });
57
+ }
58
+
59
+ if (config.routePlSql.length > 0) {
60
+ console.log('');
61
+ config.routePlSql.forEach((e, i) => {
62
+ console.log(`Application route #${i + 1}`);
63
+ console.log(` Route: "http://localhost:${config.port}${e.route}"`);
64
+ console.log(` Oracle user: "${e.user}"`);
65
+ console.log(` Oracle server: "${e.connectString}"`);
66
+ console.log(` Oracle document table: "${e.documentTable}"`);
67
+ console.log(` Default page: "${e.defaultPage}"`);
68
+ console.log(` Path alias: "${e.pathAlias}"`);
69
+ console.log(` Path alias procedure: "${e.pathAliasProcedure}"`);
70
+ console.log(` Exclution list: "${e.exclusionList?.join(', ')}"`);
71
+ console.log(` Request validation function: "${e.requestValidationFunction}"`);
72
+ console.log(` Error style: "${e.errorStyle}"`);
73
+ });
74
+ }
75
+
76
+ console.log('-'.repeat(80));
77
+ };
78
+
31
79
  /**
32
80
  * Create HTTP server.
33
81
  * @param {Express} app - express application
@@ -38,7 +86,6 @@ import {readFileSyncUtf8, getJsonFile} from './file.js';
38
86
  export const createHttpServer = (app, port, connectionPools) => {
39
87
  return new Promise((resolve) => {
40
88
  // Create server
41
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
42
89
  const server = http.createServer({}, app);
43
90
 
44
91
  // Install shutdown handler
@@ -73,7 +120,6 @@ export const createHttpsServer = (app, sslKeyFilename, sslCertFilename, port, co
73
120
  const cert = readFileSyncUtf8(sslCertFilename);
74
121
 
75
122
  // Create server
76
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
77
123
  const server = https.createServer({key, cert}, app);
78
124
 
79
125
  // Install shutdown handler
@@ -100,24 +146,33 @@ export const createHttpsServer = (app, sslKeyFilename, sslCertFilename, port, co
100
146
  export const startHttpServer = async (config) => {
101
147
  debug('startHttpServer', config);
102
148
 
103
- const expressVersion = getExpressVersion();
104
- const packageVersion = getPackageVersion();
105
-
106
149
  config = z$configType.parse(config);
107
150
 
108
- console.log(`WEB_PL/SQL ${packageVersion} using express ${expressVersion}`);
151
+ showConfig(config);
109
152
 
110
153
  // Create express app
111
154
  const app = express();
112
155
 
156
+ // Debug requests
157
+ if (debug.enabled) {
158
+ app.use((req, res, next) => {
159
+ console.log(`Request: "${req.method}" "${req.url}"`);
160
+ next();
161
+ });
162
+ }
163
+
113
164
  // Metrics
114
165
  const metrics = initMetrics();
115
166
  app.use(handlerMetrics(metrics));
116
167
 
168
+ // Access log
169
+ if (config.loggerFilename.length > 0) {
170
+ app.use(handlerLogger(config.loggerFilename));
171
+ }
172
+
117
173
  // Serving static files
118
174
  for (const i of config.routeStatic) {
119
175
  app.use(i.route, express.static(i.directoryPath));
120
- console.log(`Static resources on "${i.route}" from directory ${i.directoryPath}`);
121
176
  }
122
177
 
123
178
  // Default middleware
@@ -127,12 +182,6 @@ export const startHttpServer = async (config) => {
127
182
  app.use(cookieParser());
128
183
  app.use(compression());
129
184
 
130
- // Access log
131
- if (config.loggerFilename.length > 0) {
132
- console.log(`Access log in "${config.loggerFilename}"`);
133
- app.use(handlerLogger(config.loggerFilename));
134
- }
135
-
136
185
  /** @type {Pool[]} */
137
186
  const connectionPools = [];
138
187
 
@@ -143,11 +192,6 @@ export const startHttpServer = async (config) => {
143
192
  connectionPools.push(pool);
144
193
 
145
194
  app.use([`${i.route}/:name`, i.route], handlerWebPlSql(pool, i));
146
-
147
- console.log(`Application route "http://localhost:${config.port}${i.route}"`);
148
- console.log(` Oracle user: ${i.user}`);
149
- console.log(` Oracle server: ${i.connectString}`);
150
- console.log(` Oracle document table: ${i.documentTable}`);
151
195
  }
152
196
 
153
197
  // Update metrics every second
package/src/trace.js CHANGED
@@ -10,7 +10,7 @@ import util from 'node:util';
10
10
  * Return a string representation of the value.
11
11
  *
12
12
  * @param {unknown} value - Any value.
13
- * @param {number | null} depth - Specifies the number of times to recurse while formatting object..
13
+ * @param {number | null} depth - Specifies the number of times to recurse while formatting object.
14
14
  * @returns {string} - The string representation.
15
15
  */
16
16
  export const inspect = (value, depth = null) => util.inspect(value, {showHidden: false, depth, colors: false});
package/src/types.js CHANGED
@@ -14,12 +14,10 @@ export const z$errorStyleType = z.enum(['basic', 'debug']);
14
14
  * @property {string} route - The Static route path.
15
15
  * @property {string} directoryPath - The Static directory.
16
16
  */
17
- export const z$configStaticType = z
18
- .object({
19
- route: z.string(),
20
- directoryPath: z.string(),
21
- })
22
- .strict();
17
+ export const z$configStaticType = z.strictObject({
18
+ route: z.string(),
19
+ directoryPath: z.string(),
20
+ });
23
21
 
24
22
  /**
25
23
  * @typedef {object} configPlSqlHandlerType
@@ -32,17 +30,15 @@ export const z$configStaticType = z
32
30
  * @property {Record<string, string>} [cgi] - The additional CGI.
33
31
  * @property {errorStyleType} errorStyle - The error style.
34
32
  */
35
- export const z$configPlSqlHandlerType = z
36
- .object({
37
- defaultPage: z.string(),
38
- pathAlias: z.string().optional(),
39
- pathAliasProcedure: z.string().optional(),
40
- documentTable: z.string(),
41
- exclusionList: z.array(z.string()).optional(),
42
- requestValidationFunction: z.string().optional(),
43
- errorStyle: z$errorStyleType,
44
- })
45
- .strict();
33
+ export const z$configPlSqlHandlerType = z.strictObject({
34
+ defaultPage: z.string(),
35
+ pathAlias: z.string().optional(),
36
+ pathAliasProcedure: z.string().optional(),
37
+ documentTable: z.string(),
38
+ exclusionList: z.array(z.string()).optional(),
39
+ requestValidationFunction: z.string().optional(),
40
+ errorStyle: z$errorStyleType,
41
+ });
46
42
 
47
43
  /**
48
44
  * @typedef {object} configPlSqlConfigType
@@ -51,19 +47,20 @@ export const z$configPlSqlHandlerType = z
51
47
  * @property {string} password - The Oracle password.
52
48
  * @property {string} connectString - The Oracle connect string.
53
49
  */
54
- export const z$configPlSqlConfigType = z
55
- .object({
56
- route: z.string(),
57
- user: z.string(),
58
- password: z.string(),
59
- connectString: z.string(),
60
- })
61
- .strict();
50
+ export const z$configPlSqlConfigType = z.strictObject({
51
+ route: z.string(),
52
+ user: z.string(),
53
+ password: z.string(),
54
+ connectString: z.string(),
55
+ });
62
56
 
63
57
  /**
64
58
  * @typedef {configPlSqlHandlerType & configPlSqlConfigType} configPlSqlType
65
59
  */
66
- export const z$configPlSqlType = z$configPlSqlHandlerType.merge(z$configPlSqlConfigType);
60
+ export const z$configPlSqlType = z.strictObject({
61
+ ...z$configPlSqlHandlerType.shape,
62
+ ...z$configPlSqlConfigType.shape,
63
+ });
67
64
 
68
65
  /**
69
66
  * @typedef {object} configType
@@ -73,15 +70,13 @@ export const z$configPlSqlType = z$configPlSqlHandlerType.merge(z$configPlSqlCon
73
70
  * @property {string} loggerFilename - name of the request logger filename or '' if not required.
74
71
  * @property {boolean} monitorConsole - Enable console status monitor.
75
72
  */
76
- export const z$configType = z
77
- .object({
78
- port: z.number(),
79
- routeStatic: z.array(z$configStaticType),
80
- routePlSql: z.array(z$configPlSqlType),
81
- loggerFilename: z.string(),
82
- monitorConsole: z.boolean(),
83
- })
84
- .strict();
73
+ export const z$configType = z.strictObject({
74
+ port: z.number(),
75
+ routeStatic: z.array(z$configStaticType),
76
+ routePlSql: z.array(z$configPlSqlType),
77
+ loggerFilename: z.string(),
78
+ monitorConsole: z.boolean(),
79
+ });
85
80
 
86
81
  /**
87
82
  * Environment variables as string key-value pairs
package/src/upload.js CHANGED
@@ -11,6 +11,19 @@ import {readFile, removeFile} from './file.js';
11
11
  import oracledb from 'oracledb';
12
12
  import z from 'zod';
13
13
 
14
+ const z$reqFiles = z.array(
15
+ z.looseObject({
16
+ fieldname: z.string(),
17
+ originalname: z.string(),
18
+ encoding: z.string(),
19
+ mimetype: z.string(),
20
+ destination: z.string(),
21
+ filename: z.string(),
22
+ path: z.string(),
23
+ size: z.number(),
24
+ }),
25
+ );
26
+
14
27
  /**
15
28
  * @typedef {import('express').Request} Request
16
29
  * @typedef {import('oracledb').Connection} Connection
@@ -37,22 +50,7 @@ export const getFiles = (req) => {
37
50
 
38
51
  debug('req.files=', req.files);
39
52
 
40
- // validate
41
- const reqFiles = z
42
- .object({
43
- fieldname: z.string(),
44
- originalname: z.string(),
45
- encoding: z.string(),
46
- mimetype: z.string(),
47
- destination: z.string(),
48
- filename: z.string(),
49
- path: z.string(),
50
- size: z.number(),
51
- })
52
- .array()
53
- .parse(req.files);
54
-
55
- return reqFiles;
53
+ return z$reqFiles.parse(req.files);
56
54
  };
57
55
 
58
56
  /**
package/types/server.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export function showConfig(config: configType): void;
1
2
  export function createHttpServer(app: Express, port: number, connectionPools: Pool[]): Promise<http.Server>;
2
3
  export function createHttpsServer(app: Express, sslKeyFilename: string, sslCertFilename: string, port: number, connectionPools: Pool[]): Promise<https.Server>;
3
4
  export function startHttpServer(config: configType): Promise<void>;
@@ -9,3 +10,5 @@ export type NextFunction = import("express").NextFunction;
9
10
  export type Pool = import("oracledb").Pool;
10
11
  export type environmentType = import("./types.js").environmentType;
11
12
  export type configType = import("./types.js").configType;
13
+ import http from 'node:http';
14
+ import https from 'node:https';
package/types/stream.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export function streamToBuffer(readable: stream.Readable): Promise<Buffer>;
2
+ import stream from 'node:stream';
package/types/trace.d.ts CHANGED
@@ -3,3 +3,4 @@ export function logToFile(text: string): void;
3
3
  export function inspectRequest(req: express.Request, simple?: boolean): string;
4
4
  export function getBlock(title: string, body: string): string;
5
5
  export function getTimestamp(): string;
6
+ import express from 'express';
package/types/types.d.ts CHANGED
@@ -4,13 +4,19 @@
4
4
  /**
5
5
  * @typedef {'basic' | 'debug'} errorStyleType
6
6
  */
7
- export const z$errorStyleType: any;
7
+ export const z$errorStyleType: z.ZodEnum<{
8
+ basic: "basic";
9
+ debug: "debug";
10
+ }>;
8
11
  /**
9
12
  * @typedef {object} configStaticType
10
13
  * @property {string} route - The Static route path.
11
14
  * @property {string} directoryPath - The Static directory.
12
15
  */
13
- export const z$configStaticType: any;
16
+ export const z$configStaticType: z.ZodObject<{
17
+ route: z.ZodString;
18
+ directoryPath: z.ZodString;
19
+ }, z.core.$strict>;
14
20
  /**
15
21
  * @typedef {object} configPlSqlHandlerType
16
22
  * @property {string} defaultPage - The default page.
@@ -22,7 +28,18 @@ export const z$configStaticType: any;
22
28
  * @property {Record<string, string>} [cgi] - The additional CGI.
23
29
  * @property {errorStyleType} errorStyle - The error style.
24
30
  */
25
- export const z$configPlSqlHandlerType: any;
31
+ export const z$configPlSqlHandlerType: z.ZodObject<{
32
+ defaultPage: z.ZodString;
33
+ pathAlias: z.ZodOptional<z.ZodString>;
34
+ pathAliasProcedure: z.ZodOptional<z.ZodString>;
35
+ documentTable: z.ZodString;
36
+ exclusionList: z.ZodOptional<z.ZodArray<z.ZodString>>;
37
+ requestValidationFunction: z.ZodOptional<z.ZodString>;
38
+ errorStyle: z.ZodEnum<{
39
+ basic: "basic";
40
+ debug: "debug";
41
+ }>;
42
+ }, z.core.$strict>;
26
43
  /**
27
44
  * @typedef {object} configPlSqlConfigType
28
45
  * @property {string} route - The PL/SQL route path.
@@ -30,11 +47,31 @@ export const z$configPlSqlHandlerType: any;
30
47
  * @property {string} password - The Oracle password.
31
48
  * @property {string} connectString - The Oracle connect string.
32
49
  */
33
- export const z$configPlSqlConfigType: any;
50
+ export const z$configPlSqlConfigType: z.ZodObject<{
51
+ route: z.ZodString;
52
+ user: z.ZodString;
53
+ password: z.ZodString;
54
+ connectString: z.ZodString;
55
+ }, z.core.$strict>;
34
56
  /**
35
57
  * @typedef {configPlSqlHandlerType & configPlSqlConfigType} configPlSqlType
36
58
  */
37
- export const z$configPlSqlType: any;
59
+ export const z$configPlSqlType: z.ZodObject<{
60
+ route: z.ZodString;
61
+ user: z.ZodString;
62
+ password: z.ZodString;
63
+ connectString: z.ZodString;
64
+ defaultPage: z.ZodString;
65
+ pathAlias: z.ZodOptional<z.ZodString>;
66
+ pathAliasProcedure: z.ZodOptional<z.ZodString>;
67
+ documentTable: z.ZodString;
68
+ exclusionList: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
+ requestValidationFunction: z.ZodOptional<z.ZodString>;
70
+ errorStyle: z.ZodEnum<{
71
+ basic: "basic";
72
+ debug: "debug";
73
+ }>;
74
+ }, z.core.$strict>;
38
75
  /**
39
76
  * @typedef {object} configType
40
77
  * @property {number} port - The server port number.
@@ -43,7 +80,31 @@ export const z$configPlSqlType: any;
43
80
  * @property {string} loggerFilename - name of the request logger filename or '' if not required.
44
81
  * @property {boolean} monitorConsole - Enable console status monitor.
45
82
  */
46
- export const z$configType: any;
83
+ export const z$configType: z.ZodObject<{
84
+ port: z.ZodNumber;
85
+ routeStatic: z.ZodArray<z.ZodObject<{
86
+ route: z.ZodString;
87
+ directoryPath: z.ZodString;
88
+ }, z.core.$strict>>;
89
+ routePlSql: z.ZodArray<z.ZodObject<{
90
+ route: z.ZodString;
91
+ user: z.ZodString;
92
+ password: z.ZodString;
93
+ connectString: z.ZodString;
94
+ defaultPage: z.ZodString;
95
+ pathAlias: z.ZodOptional<z.ZodString>;
96
+ pathAliasProcedure: z.ZodOptional<z.ZodString>;
97
+ documentTable: z.ZodString;
98
+ exclusionList: z.ZodOptional<z.ZodArray<z.ZodString>>;
99
+ requestValidationFunction: z.ZodOptional<z.ZodString>;
100
+ errorStyle: z.ZodEnum<{
101
+ basic: "basic";
102
+ debug: "debug";
103
+ }>;
104
+ }, z.core.$strict>>;
105
+ loggerFilename: z.ZodString;
106
+ monitorConsole: z.ZodBoolean;
107
+ }, z.core.$strict>;
47
108
  export type BindParameter = import("oracledb").BindParameter;
48
109
  export type errorStyleType = "basic" | "debug";
49
110
  export type configStaticType = {
@@ -249,3 +310,4 @@ export type metricsType = {
249
310
  */
250
311
  requestsInLastInterval: number;
251
312
  };
313
+ import z from 'zod';