web_plsql 0.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web_plsql",
3
- "version": "0.10.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",
@@ -84,12 +84,12 @@
84
84
  "@types/oracledb": "6.9.1",
85
85
  "@types/supertest": "6.0.3",
86
86
  "eslint": "9.33.0",
87
- "eslint-plugin-jsdoc": "54.1.0",
87
+ "eslint-plugin-jsdoc": "54.1.1",
88
88
  "prettier": "3.6.2",
89
89
  "rimraf": "6.0.1",
90
90
  "shx": "0.4.0",
91
91
  "supertest": "7.1.4",
92
92
  "typescript": "5.9.2",
93
- "typescript-eslint": "8.39.1"
93
+ "typescript-eslint": "8.40.0"
94
94
  }
95
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
- };
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/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
  /**