web_plsql 0.5.0 → 0.6.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 (96) hide show
  1. package/README.md +123 -110
  2. package/examples/server_apex.js +28 -0
  3. package/examples/server_sample.js +30 -0
  4. package/examples/sql/{doc_table.sql → doctable.sql} +1 -1
  5. package/examples/sql/install.sql +6 -9
  6. package/examples/sql/sample_package.sql +27 -0
  7. package/examples/sql/sample_package_body.sql +245 -0
  8. package/examples/static/sample.css +11 -10
  9. package/package.json +90 -83
  10. package/src/cgi.js +127 -0
  11. package/src/error.js +24 -0
  12. package/src/errorPage.js +296 -0
  13. package/src/file.js +77 -0
  14. package/src/handlerLogger.js +21 -0
  15. package/src/handlerMetrics.js +46 -0
  16. package/src/handlerPlSql.js +65 -0
  17. package/src/handlerUpload.js +32 -0
  18. package/src/index.js +17 -0
  19. package/src/oracle.js +80 -0
  20. package/src/parsePage.js +193 -0
  21. package/src/procedure.js +260 -0
  22. package/src/procedureError.js +40 -0
  23. package/src/procedureNamed.js +233 -0
  24. package/src/procedureSanitize.js +215 -0
  25. package/src/procedureVariable.js +57 -0
  26. package/src/request.js +103 -0
  27. package/src/{requestError.ts → requestError.js} +8 -4
  28. package/src/sendResponse.js +104 -0
  29. package/src/server.js +106 -0
  30. package/src/shutdown.js +53 -0
  31. package/src/stream.js +28 -0
  32. package/src/trace.js +74 -0
  33. package/src/tty.js +48 -0
  34. package/src/types.js +146 -0
  35. package/src/upload.js +92 -0
  36. package/src/version.js +23 -0
  37. package/types/cgi.d.ts +4 -0
  38. package/types/error.d.ts +1 -0
  39. package/types/errorPage.d.ts +10 -0
  40. package/types/file.d.ts +5 -0
  41. package/types/handlerLogger.d.ts +2 -0
  42. package/types/handlerMetrics.d.ts +4 -0
  43. package/types/handlerPlSql.d.ts +8 -0
  44. package/types/handlerUpload.d.ts +7 -0
  45. package/types/index.d.ts +10 -0
  46. package/types/oracle.d.ts +5 -0
  47. package/types/parsePage.d.ts +3 -0
  48. package/types/procedure.d.ts +10 -0
  49. package/types/procedureError.d.ts +23 -0
  50. package/types/procedureNamed.d.ts +14 -0
  51. package/types/procedureSanitize.d.ts +14 -0
  52. package/types/procedureVariable.d.ts +9 -0
  53. package/types/request.d.ts +7 -0
  54. package/types/requestError.d.ts +8 -0
  55. package/types/sendResponse.d.ts +4 -0
  56. package/types/server.d.ts +7 -0
  57. package/types/shutdown.d.ts +2 -0
  58. package/types/stream.d.ts +1 -0
  59. package/types/trace.d.ts +5 -0
  60. package/types/tty.d.ts +4 -0
  61. package/types/types.d.ts +251 -0
  62. package/types/upload.d.ts +5 -0
  63. package/types/version.d.ts +7 -0
  64. package/.editorconfig +0 -8
  65. package/.eslintignore +0 -3
  66. package/.eslintrc.js +0 -347
  67. package/CHANGELOG.md +0 -127
  68. package/examples/apex.js +0 -70
  69. package/examples/credentials.js +0 -22
  70. package/examples/oracledb_example.js +0 -30
  71. package/examples/sample.js +0 -101
  72. package/examples/sql/sample.pkb +0 -223
  73. package/examples/sql/sample.pks +0 -24
  74. package/jest.config.js +0 -204
  75. package/src/cgi.ts +0 -95
  76. package/src/config.ts +0 -97
  77. package/src/errorPage.ts +0 -286
  78. package/src/fileUpload.ts +0 -126
  79. package/src/index.ts +0 -65
  80. package/src/page.ts +0 -275
  81. package/src/procedure.ts +0 -360
  82. package/src/procedureError.ts +0 -27
  83. package/src/request.ts +0 -139
  84. package/src/stream.ts +0 -26
  85. package/src/trace.ts +0 -194
  86. package/test/.eslintrc.json +0 -5
  87. package/test/__tests__/cgi.ts +0 -96
  88. package/test/__tests__/config.ts +0 -41
  89. package/test/__tests__/errorPage.ts +0 -101
  90. package/test/__tests__/oracledb_mock.ts +0 -98
  91. package/test/__tests__/server.ts +0 -495
  92. package/test/__tests__/stream.ts +0 -21
  93. package/test/mock/oracledb.ts +0 -85
  94. package/test/static/static.html +0 -1
  95. package/tsconfig.json +0 -24
  96. package/tsconfig.src.json +0 -23
package/jest.config.js DELETED
@@ -1,204 +0,0 @@
1
- /*
2
- * For a detailed explanation regarding each configuration property, visit:
3
- * https://jestjs.io/docs/configuration
4
- */
5
-
6
- module.exports = {
7
- // All imported modules in your tests should be mocked automatically
8
- // automock: false,
9
-
10
- // Stop running tests after `n` failures
11
- // bail: 0,
12
-
13
- // The directory where Jest should store its cached dependency information
14
- // cacheDirectory: "/private/var/folders/2y/kvrr5nws6xz4nx9vnwjxj17w0000gn/T/jest_dx",
15
-
16
- // Automatically clear mock calls, instances, contexts and results before every test
17
- // clearMocks: false,
18
-
19
- // Indicates whether the coverage information should be collected while executing the test
20
- collectCoverage: true,
21
-
22
- // An array of glob patterns indicating a set of files for which coverage information should be collected
23
- // collectCoverageFrom: undefined,
24
- collectCoverageFrom: ['./src/**/*.{ts,js}'],
25
-
26
- // The directory where Jest should output its coverage files
27
- coverageDirectory: "coverage",
28
-
29
- // An array of regexp pattern strings used to skip coverage collection
30
- // coveragePathIgnorePatterns: [
31
- // "/node_modules/"
32
- // ],
33
-
34
- // Indicates which provider should be used to instrument code for coverage
35
- coverageProvider: "v8",
36
-
37
- // A list of reporter names that Jest uses when writing coverage reports
38
- // coverageReporters: [
39
- // "json",
40
- // "text",
41
- // "lcov",
42
- // "clover"
43
- // ],
44
-
45
- // An object that configures minimum threshold enforcement for coverage results
46
- // coverageThreshold: undefined,
47
-
48
- // A path to a custom dependency extractor
49
- // dependencyExtractor: undefined,
50
-
51
- // Make calling deprecated APIs throw helpful error messages
52
- // errorOnDeprecated: false,
53
-
54
- // The default configuration for fake timers
55
- // fakeTimers: {
56
- // "enableGlobally": false
57
- // },
58
-
59
- // Force coverage collection from ignored files using an array of glob patterns
60
- // forceCoverageMatch: [],
61
-
62
- // A path to a module which exports an async function that is triggered once before all test suites
63
- // globalSetup: undefined,
64
-
65
- // A path to a module which exports an async function that is triggered once after all test suites
66
- // globalTeardown: undefined,
67
-
68
- // A set of global variables that need to be available in all test environments
69
- // globals: {},
70
- globals: {
71
- 'ts-jest': {
72
- tsconfig: 'tsconfig.src.json',
73
- diagnostics: true,
74
- useESM: true,
75
- }
76
- },
77
-
78
- // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
79
- // maxWorkers: "50%",
80
-
81
- // An array of directory names to be searched recursively up from the requiring module's location
82
- // moduleDirectories: [
83
- // "node_modules"
84
- // ],
85
-
86
- // An array of file extensions your modules use
87
- // moduleFileExtensions: [
88
- // "js",
89
- // "mjs",
90
- // "cjs",
91
- // "jsx",
92
- // "ts",
93
- // "tsx",
94
- // "json",
95
- // "node"
96
- // ],
97
-
98
- // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
99
- // moduleNameMapper: {},
100
-
101
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
102
- // modulePathIgnorePatterns: [],
103
-
104
- // Activates notifications for test results
105
- // notify: false,
106
-
107
- // An enum that specifies notification mode. Requires { notify: true }
108
- // notifyMode: "failure-change",
109
-
110
- // A preset that is used as a base for Jest's configuration
111
- // preset: undefined,
112
- preset: 'ts-jest',
113
-
114
- // Run tests from one or more projects
115
- // projects: undefined,
116
-
117
- // Use this configuration option to add custom reporters to Jest
118
- // reporters: undefined,
119
-
120
- // Automatically reset mock state before every test
121
- // resetMocks: false,
122
-
123
- // Reset the module registry before running each individual test
124
- // resetModules: false,
125
-
126
- // A path to a custom resolver
127
- // resolver: undefined,
128
-
129
- // Automatically restore mock state and implementation before every test
130
- // restoreMocks: false,
131
-
132
- // The root directory that Jest should scan for tests and modules within
133
- // rootDir: undefined,
134
-
135
- // A list of paths to directories that Jest should use to search for files in
136
- // roots: [
137
- // "<rootDir>"
138
- // ],
139
-
140
- // Allows you to use a custom runner instead of Jest's default test runner
141
- // runner: "jest-runner",
142
-
143
- // The paths to modules that run some code to configure or set up the testing environment before each test
144
- // setupFiles: [],
145
-
146
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
147
- // setupFilesAfterEnv: [],
148
-
149
- // The number of seconds after which a test is considered as slow and reported as such in the results.
150
- // slowTestThreshold: 5,
151
-
152
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
153
- // snapshotSerializers: [],
154
-
155
- // The test environment that will be used for testing
156
- // testEnvironment: "jest-environment-node",
157
-
158
- // Options that will be passed to the testEnvironment
159
- // testEnvironmentOptions: {},
160
-
161
- // Adds a location field to test results
162
- // testLocationInResults: false,
163
-
164
- // The glob patterns Jest uses to detect test files
165
- // testMatch: [
166
- // "**/__tests__/**/*.[jt]s?(x)",
167
- // "**/?(*.)+(spec|test).[tj]s?(x)"
168
- // ],
169
-
170
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
171
- // testPathIgnorePatterns: [
172
- // "/node_modules/"
173
- // ],
174
-
175
- // The regexp pattern or array of patterns that Jest uses to detect test files
176
- // testRegex: [],
177
-
178
- // This option allows the use of a custom results processor
179
- // testResultsProcessor: undefined,
180
-
181
- // This option allows use of a custom test runner
182
- // testRunner: "jest-circus/runner",
183
-
184
- // A map from regular expressions to paths to transformers
185
- // transform: undefined,
186
-
187
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
188
- // transformIgnorePatterns: [
189
- // "/node_modules/",
190
- // "\\.pnp\\.[^\\/]+$"
191
- // ],
192
-
193
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
194
- // unmockedModulePathPatterns: undefined,
195
-
196
- // Indicates whether each individual test should be reported during the run
197
- // verbose: undefined,
198
-
199
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
200
- // watchPathIgnorePatterns: [],
201
-
202
- // Whether to use watchman for file crawling
203
- // watchman: true,
204
- };
package/src/cgi.ts DELETED
@@ -1,95 +0,0 @@
1
- /*
2
- * Prepare the CGI information
3
- */
4
-
5
- import os from 'os';
6
- import {URL} from 'url';
7
- import express from 'express';
8
- export type environmentType = {[key: string]: string};
9
- import type {oracleExpressMiddleware$options} from './config';
10
-
11
- /**
12
- * Create a CGI object
13
- *
14
- * @param {express.Request} req - The req object represents the HTTP request.
15
- * @param {oracleExpressMiddleware$options} options - the options for the middleware.
16
- * @returns {string} CGI object
17
- */
18
- export function getCGI(req: express.Request, options: oracleExpressMiddleware$options): environmentType {
19
- const PROTOCOL = req.protocol ? req.protocol.toUpperCase() : '';
20
- const CHARSET = 'UTF8';
21
- const IANA_CHARSET = 'UTF-8';
22
- const PATH = getPath(req);
23
-
24
- const DEFAULT_CGI: environmentType = {
25
- 'PLSQL_GATEWAY': 'WebDb',
26
- 'GATEWAY_IVERSION': '2',
27
- 'SERVER_SOFTWARE': 'web_plsql',
28
- 'GATEWAY_INTERFACE': 'CGI/1.1',
29
- 'SERVER_PORT': typeof req.socket.localPort === 'number' ? req.socket.localPort.toString() : '',
30
- 'SERVER_NAME': os.hostname(),
31
- 'REQUEST_METHOD': req.method,
32
- 'PATH_INFO': req.params.name,
33
- 'SCRIPT_NAME': PATH.script,
34
- 'REMOTE_ADDR': (req.ip || '').replace('::ffff:', ''),
35
- 'SERVER_PROTOCOL': PROTOCOL + '/' + req.httpVersion,
36
- 'REQUEST_PROTOCOL': PROTOCOL,
37
- 'REMOTE_USER': '',
38
- 'HTTP_COOKIE': getCookieString(req),
39
- 'HTTP_USER_AGENT': req.get('user-agent') || '',
40
- 'HTTP_HOST': req.get('host') || '',
41
- 'HTTP_ACCEPT': req.get('accept') || '',
42
- 'HTTP_ACCEPT_ENCODING': req.get('accept-encoding') || '',
43
- 'HTTP_ACCEPT_LANGUAGE': req.get('accept-language') || '',
44
- 'HTTP_REFERER': req.get('referer') || '',
45
- 'HTTP_X_FORWARDED_FOR': req.get('x-forwarded-for') || '',
46
- 'WEB_AUTHENT_PREFIX': '',
47
- 'DAD_NAME': PATH.dad,
48
- 'DOC_ACCESS_PATH': 'doc',
49
- 'DOCUMENT_TABLE': options.doctable || '',
50
- 'PATH_ALIAS': '',
51
- 'REQUEST_CHARSET': CHARSET,
52
- 'REQUEST_IANA_CHARSET': IANA_CHARSET,
53
- 'SCRIPT_PREFIX': PATH.prefix
54
- };
55
-
56
- return Object.assign(DEFAULT_CGI, options.cgi);
57
- }
58
-
59
- /*
60
- * Create the HTTP_COOKIE string
61
- */
62
- function getCookieString(req: express.Request): string {
63
- let cookieString = '';
64
-
65
- for (const propName in req.cookies) {
66
- cookieString += propName + '=' + req.cookies[propName] + ';';
67
- }
68
-
69
- return cookieString;
70
- }
71
-
72
- /*
73
- * Get the script name and DAD name from a URL
74
- */
75
- function getPath(req: express.Request): {script: string; prefix: string; dad: string} {
76
- // create a valid url
77
- const validUrl = req.protocol + '://' + os.hostname() + req.originalUrl;
78
-
79
- // get the pathname from the url (new URL('https://example.org/abc/xyz?123').pathname => /abc/xyz)
80
- const pathname = new URL(validUrl).pathname;
81
-
82
- const tmp = trimPath(pathname.substr(0, pathname.lastIndexOf('/') + 1));
83
- const script = '/' + tmp;
84
- const prefix = '/' + tmp.substr(0, tmp.lastIndexOf('/'));
85
- const dad = tmp.substr(tmp.indexOf('/') + 1);
86
-
87
- return {script, prefix, dad};
88
- }
89
-
90
- /*
91
- * Get a path that is not enclodes in slashes
92
- */
93
- function trimPath(value: string): string {
94
- return value.replace(/^\/+|\/+$/g, '');
95
- }
package/src/config.ts DELETED
@@ -1,97 +0,0 @@
1
- /*
2
- * Configuration
3
- */
4
-
5
- import {environmentType} from './cgi';
6
- export type oracleExpressMiddleware$options = {
7
- defaultPage?: string;
8
- doctable?: string;
9
- cgi?: environmentType;
10
- pathAlias?: {
11
- alias: string;
12
- procedure: string;
13
- };
14
- errorStyle: 'basic' | 'debug';
15
- trace: 'on' | 'off' | 'test';
16
- };
17
-
18
- /**
19
- * Validation the configuration options.
20
- *
21
- * @param {Object} options - The configuration options.
22
- * @returns {oracleExpressMiddleware$options} - The validated configuration options.
23
- */
24
- export function validate(options: Record<string, any>): oracleExpressMiddleware$options {
25
- const validOptions: oracleExpressMiddleware$options = {
26
- errorStyle: 'basic',
27
- trace: 'off'
28
- };
29
-
30
- if (typeof options !== 'undefined') {
31
- if (arguments.length !== 1 || typeof options !== 'object' || options === null) {
32
- throw new TypeError('Invalid configuration object was given');
33
- }
34
- Object.keys(options).forEach(option => {
35
- if (['defaultPage', 'doctable', 'cgi', 'pathAlias', 'errorStyle', 'trace'].indexOf(option) === -1) {
36
- throw new TypeError(`Invalid configuration options "${option}"`);
37
- }
38
- });
39
- } else {
40
- return validOptions;
41
- }
42
-
43
- if (typeof options.defaultPage !== 'undefined') {
44
- if (typeof options.defaultPage === 'string' && options.defaultPage.length > 0) {
45
- validOptions.defaultPage = options.defaultPage;
46
- } else {
47
- throw new TypeError('The option "defaultPage" must be of type string and cannot be empty');
48
- }
49
- }
50
-
51
- if (typeof options.doctable !== 'undefined') {
52
- if (typeof options.doctable === 'string' && options.doctable.length > 0) {
53
- validOptions.doctable = options.doctable;
54
- } else {
55
- throw new TypeError('The option "doctable" must be of type string and cannot be empty');
56
- }
57
- }
58
-
59
- if (typeof options.cgi !== 'undefined') {
60
- if (typeof options.cgi === 'object' && Object.keys(options.cgi).every(key => typeof key === 'string') && Object.values(options.cgi).every(value => typeof value === 'string')) {
61
- validOptions.cgi = Object.assign({}, options.cgi);
62
- } else {
63
- throw new TypeError('The option "cgi" must be an object where all keys and values are of type string');
64
- }
65
- }
66
-
67
- if (typeof options.pathAlias !== 'undefined') {
68
- if (typeof options.pathAlias === 'object' &&
69
- typeof options.pathAlias.alias === 'string' && options.pathAlias.alias.length > 0 &&
70
- typeof options.pathAlias.procedure === 'string' && options.pathAlias.procedure.length > 0) {
71
- validOptions.pathAlias = {
72
- alias: options.pathAlias.alias,
73
- procedure: options.pathAlias.procedure
74
- };
75
- } else {
76
- throw new TypeError('The option "pathAlias" must be an object with the non-empty string properties "alias" and "procedure"');
77
- }
78
- }
79
-
80
- if (typeof options.errorStyle !== 'undefined') {
81
- if (typeof options.errorStyle !== 'string' || ['basic', 'debug'].indexOf(options.errorStyle) === -1) {
82
- throw new TypeError('The optional option "errorStyle" must be "basic" or "debug"');
83
- } else {
84
- validOptions.errorStyle = options.errorStyle as 'basic' | 'debug';
85
- }
86
- }
87
-
88
- if (typeof options.trace !== 'undefined') {
89
- if (typeof options.trace !== 'string' || ['on', 'off', 'test'].indexOf(options.trace.toLowerCase()) === -1) {
90
- throw new TypeError('The optional option "trace" must be "on" or "off"');
91
- } else {
92
- validOptions.trace = options.trace.toLowerCase() as 'on' | 'off' | 'test';
93
- }
94
- }
95
-
96
- return validOptions;
97
- }
package/src/errorPage.ts DELETED
@@ -1,286 +0,0 @@
1
- /*
2
- * Error handling
3
- */
4
-
5
- import util from 'util';
6
- import escape from 'escape-html';
7
- import {ProcedureError} from './procedureError';
8
- import {RequestError} from './requestError';
9
- import express from 'express';
10
- import {Trace} from './trace';
11
- import {oracleExpressMiddleware$options} from './config';
12
- import {environmentType} from './cgi';
13
- type outputType = {html: string; text: string};
14
-
15
- /**
16
- * Show an error page
17
- *
18
- * @param {express.Request} req - The req object represents the HTTP request.
19
- * @param {express.Response} res - The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
20
- * @param {Object} options - The configuration options.
21
- * @param {Trace} trace - Tracing object.
22
- * @param {Error} error - The error.
23
- */
24
- export function errorPage(req: express.Request, res: express.Response, options: oracleExpressMiddleware$options, trace: Trace, error: unknown): void {
25
- let output = {
26
- html: '',
27
- text: ''
28
- };
29
-
30
- // get the error description
31
- try {
32
- output = getError(req, error);
33
- } catch (err) {
34
- /* istanbul ignore next */
35
- const header = 'ERROR';
36
-
37
- /* istanbul ignore next */
38
- const message = err instanceof Error ? `${err.message}\n${err.stack}` : JSON.stringify(err);
39
-
40
- /* istanbul ignore next */
41
- output.html += getHeaderHtml(header) + getHtml(message);
42
-
43
- /* istanbul ignore next */
44
- output.text += getHeaderHtml(header) + getHtml(message);
45
- }
46
-
47
- // trace to file
48
- trace.write(output.text);
49
-
50
- // console
51
- console.error(output.text);
52
-
53
- // show page
54
- if (options.errorStyle === 'basic') {
55
- res.status(404).send('Page not found');
56
- } else {
57
- res.status(404).send(getHtmlPage(output.html));
58
- }
59
- }
60
-
61
- /*
62
- * Show an error page
63
- */
64
- function getError(req: express.Request, error: unknown): outputType {
65
- let timestamp: Date = new Date();
66
- let message: string = '';
67
- let environment: environmentType | null = null;
68
- let sql: string | null = null;
69
- let bind: any | null = null;
70
-
71
- // what type of Error did we receive
72
- if (error instanceof ProcedureError) {
73
- timestamp = error.timestamp;
74
- /* istanbul ignore next */
75
- message = error.stack || '';
76
- environment = error.environment;
77
- sql = error.sql;
78
- bind = error.bind;
79
- } else if (error instanceof RequestError) {
80
- timestamp = error.timestamp;
81
- /* istanbul ignore next */
82
- message = error.stack || '';
83
- } else if (error instanceof Error) {
84
- /* istanbul ignore next */
85
- message = error.stack || '';
86
- } else {
87
- if (typeof error === 'string') {
88
- /* istanbul ignore next */
89
- message = error + '\n';
90
- }
91
- try {
92
- /* istanbul ignore next */
93
- new Error(); // eslint-disable-line no-new
94
- } catch (err) {
95
- /* istanbul ignore next */
96
- message += err instanceof Error ? err.stack : '';
97
- }
98
- }
99
-
100
- const output: outputType = {
101
- html: '',
102
- text: ''
103
- };
104
-
105
- // timestamp
106
- let header = 'TIMESTAMP';
107
- output.html += getHeaderHtml(header);
108
- output.html += getHtml(timestamp.toUTCString());
109
-
110
- // error
111
- header = 'ERROR';
112
- output.html += getHeaderHtml(header);
113
- output.html += getHtml(message);
114
- output.text += getHeaderText(header);
115
- output.text += getText(message);
116
-
117
- // request
118
- header = 'REQUEST';
119
- output.text += getHeaderText(header);
120
- output.text += getText(Trace.inspectRequest(req));
121
-
122
- // parameters
123
- if (typeof sql === 'string' && bind) {
124
- header = 'PROCEDURE';
125
- output.html += getHeaderHtml(header);
126
- output.text += getHeaderText(header);
127
- getProcedure(output, sql, bind);
128
- }
129
-
130
- // environment
131
- if (environment) {
132
- header = 'ENVIRONMENT';
133
- output.html += getHeaderHtml(header);
134
- output.text += getHeaderText(header);
135
- getEnvironment(output, environment);
136
- }
137
-
138
- return output;
139
- }
140
-
141
- /*
142
- * get procedure
143
- */
144
- function getProcedure(output: outputType, sql: string, bind: any) {
145
- let html = '<table>';
146
- let text = '';
147
-
148
- text += 'PROCEDURE: ' + sql + '\n';
149
- html += `<tr><td>PROCEDURE:</td><td>${sql}</td></tr>`;
150
-
151
- try {
152
- /* istanbul ignore else */
153
- if (sql.indexOf('(:argnames, :argvalues)') < 0) {
154
- for (const key in bind) {
155
- const value = inspect(bind[key].val);
156
-
157
- html += `<tr><td>${key}:</td><td>${value}</td></tr>`;
158
- text += key + ': ' + value + '\n';
159
- }
160
- } else {
161
- bind.argnames.val.forEach((name: string, index: number) => {
162
- const value = inspect(bind.argvalues.val[index]);
163
-
164
- html += `<tr><td>${name}:</td><td>${value}</td></tr>`;
165
- text += name + ': ' + value + '\n';
166
- });
167
- }
168
- } catch (err) {
169
- /* istanbul ignore next */
170
- output.html += err instanceof Error ? err.toString() : 'ERROR';
171
-
172
- /* istanbul ignore next */
173
- output.text += err instanceof Error ? err.toString() : 'ERROR';
174
- /* istanbul ignore next */
175
- return;
176
- }
177
-
178
- html += '</table>';
179
-
180
- output.html += html;
181
- output.text += text;
182
- }
183
-
184
- /*
185
- * get evnironment
186
- */
187
- function getEnvironment(output: outputType, environment: environmentType) {
188
- let html = '<table>';
189
- let text = '';
190
-
191
- try {
192
- for (const key in environment) {
193
- html += `<tr><td>${key}:</td><td>${environment[key]}</td></tr>`;
194
- text += key + '=' + environment[key] + '\n';
195
- }
196
- } catch (err) {
197
- /* istanbul ignore next */
198
- output.html += err instanceof Error ? err.toString() : 'ERROR';
199
-
200
- /* istanbul ignore next */
201
- output.text += err instanceof Error ? err.toString() : 'ERROR';
202
-
203
- /* istanbul ignore next */
204
- return;
205
- }
206
-
207
- html += '</table>';
208
-
209
- output.html += html;
210
- output.text += text;
211
- }
212
-
213
- /*
214
- * get text header
215
- */
216
- function getHeaderText(text: string): string {
217
- return `\n${text}\n${'='.repeat(text.length)}\n`;
218
- }
219
-
220
- /*
221
- * get html header
222
- */
223
- function getHeaderHtml(text: string): string {
224
- return `<h1>${text}</h1>`;
225
- }
226
-
227
- /*
228
- * get text
229
- */
230
- function getText(text: string): string {
231
- return text + '\n';
232
- }
233
-
234
- /*
235
- * get html
236
- */
237
- function getHtml(text: string): string {
238
- return `<p>${convertToHtml(text)}</p>`;
239
- }
240
-
241
- /*
242
- * convert value to string
243
- */
244
- function inspect(value: any): string {
245
- return util.inspect(value, {showHidden: false, depth: null, colors: false});
246
- }
247
-
248
- /*
249
- * convert LF and/or CR to <br>
250
- */
251
- function convertToHtml(text: string): string {
252
- let html = escape(text);
253
-
254
- html = html.replace(/(?:\r\n|\r|\n)/g, '<br />');
255
- html = html.replace(/\t/g, '&nbsp;&nbsp;&nbsp;');
256
-
257
- return html;
258
- }
259
-
260
- /*
261
- * getHtmlPage
262
- */
263
- function getHtmlPage(body: string): string {
264
- return `<!DOCTYPE html>
265
- <html lang="en">
266
- <head>
267
- <meta charset="utf-8">
268
- <title>web_plsql error page</title>
269
- <style type="text/css">
270
- html {
271
- font-family: monospace, sans-serif;
272
- font-size: 12px;
273
- }
274
- h1 {
275
- font-size: 16px;
276
- padding: 2px;
277
- background-color: #cc0000;
278
- }
279
- </style>
280
- </head>
281
- <body>
282
- ` + body + `
283
- </body>
284
- </html>
285
- `;
286
- }