qlcodes 1.0.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/LICENSE +21 -0
- package/README.md +130 -0
- package/build.sh +122 -0
- package/package.json +24 -0
- package/qlCodes.json +1 -0
- package/references/IBM_errors.csv +710 -0
- package/references/ORACLE_errors.csv +171 -0
- package/references/PSQL_errors.csv +284 -0
- package/src/compose.mjs +113 -0
- package/src/fileTransformer/sanitize.mjs +10 -0
- package/src/fileTransformer/sanitize2.mjs +17 -0
- package/src/fileTransformer/stopNamedKeys.mjs +15 -0
- package/src/generate.cjs +42 -0
- package/src/index.mjs +31 -0
- package/src/pretty.mjs +18 -0
- package/src/readFile.mjs +4 -0
- package/src/regex.mjs +11 -0
- package/src/utils/args.mjs +32 -0
- package/src/utils/codeName.mjs +55 -0
- package/src/utils/io.mjs +11 -0
- package/src/utils/str.mjs +5 -0
- package/types/index.d.ts +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jean Luc Emmanuel VERHANNEMAN
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# QLCodes
|
|
2
|
+
|
|
3
|
+
A small utility that unifies SQL error codes (SQLSTATE) from different DBMS into a single, normalized structure through a curated dataset constructed at build time.
|
|
4
|
+
|
|
5
|
+
The module is built from authoritative vendor documentation (IBM, PostgreSQL, Oracle) and generates static reference data at build time. Find references bellow.
|
|
6
|
+
|
|
7
|
+
## References
|
|
8
|
+
|
|
9
|
+
- IBM
|
|
10
|
+
[Listing of SQLSTATE values](https://www.ibm.com/docs/en/i/7.6.0?topic=codes-listing-sqlstate-values#cc__classcode00)
|
|
11
|
+
(Last Updated: 2025-09-29)
|
|
12
|
+
|
|
13
|
+
- Postgres codes
|
|
14
|
+
[Appendix A. PostgreSQL Error Codes](https://www.postgresql.org/docs/10/static/errcodes-appendix.html)
|
|
15
|
+
(V.10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
- Oracle
|
|
19
|
+
[Oracle appendix](https://docs.oracle.com/cd/E15817_01/appdev.111/b31228/appd.htm)
|
|
20
|
+
11g Release 1 (11.1)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install qlcodes
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import { lens } from "qlcodes";
|
|
34
|
+
|
|
35
|
+
const error = lens("42501");
|
|
36
|
+
|
|
37
|
+
console.log(error);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Output :
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
{
|
|
44
|
+
code: "42501",
|
|
45
|
+
keys: ["insufficient_privilege"],
|
|
46
|
+
use: ["ibm", "postgres"],
|
|
47
|
+
reason: "The authorization ID does not have the privilege to perform the specified operation on the identified object."
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Mismatches
|
|
52
|
+
|
|
53
|
+
If the provided SQLSTATE does not match any known entry, we return a normalized fallback object
|
|
54
|
+
This guarantees that lens() always returns a predictable object shape.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
const error = lens("XXXXX");
|
|
58
|
+
|
|
59
|
+
console.log(error);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Output:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
{
|
|
66
|
+
code: "-1",
|
|
67
|
+
keys: ["qlcodes_not_found"],
|
|
68
|
+
use: [],
|
|
69
|
+
reason: "The code 'XXXXX' does not match any entries in qlcodes. This may be a qlcode issue only to provide you with the correct information"
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
`lens(code: string): QLLens`
|
|
78
|
+
|Parameters|Returns|
|
|
79
|
+
|-|-|
|
|
80
|
+
|**code** SQLSTATE error code | A structured error description|
|
|
81
|
+
|| **code** — normalized SQLSTATE, or `-1` if not found
|
|
82
|
+
|| **keys** — semantic identifiers
|
|
83
|
+
|| **use** — `DBMS` where the code is applicable
|
|
84
|
+
|| **reason** — human-readable explanation
|
|
85
|
+
|
|
86
|
+
## Customization & Rebuild (Contributors)
|
|
87
|
+
|
|
88
|
+
> ⚠️ Do not modify files inside node_modules.
|
|
89
|
+
> Changes will be lost on reinstall.
|
|
90
|
+
|
|
91
|
+
If you want to extend or adjust the reference data:
|
|
92
|
+
|
|
93
|
+
1) Clone the repository
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
$ git clone <repository-url>
|
|
97
|
+
$ cd qlcodes
|
|
98
|
+
$ npm install
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
2) Modify files:
|
|
102
|
+
|
|
103
|
+
- under references/
|
|
104
|
+
-> CSV files generated from vendor documentation
|
|
105
|
+
- under src/
|
|
106
|
+
-> transformation and normalization logic
|
|
107
|
+
|
|
108
|
+
> ⚠️ follow the data modification pipeline describe by the `build.sh` script.
|
|
109
|
+
> unless you know what you know what you are doing.
|
|
110
|
+
|
|
111
|
+
3) Rebuild the module
|
|
112
|
+
```bash
|
|
113
|
+
$ npm run build
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Quality of life
|
|
117
|
+
You may pass argument to the build script to enforce a few behaviours to help you seing through the process...
|
|
118
|
+
|argument|effect|
|
|
119
|
+
|-|-|
|
|
120
|
+
|--debug|prevent the cleanup of middle stage file created during the data processing|
|
|
121
|
+
|--make-keys|allow the creation of keys when a description is given...through the 'generate' step (`generate.cjs`)|
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
Use your customized build via a local dependency or a forked package.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
[MIT 2025](https://github.com/ManuUseGitHub/QLCodes?tab=MIT-1-ov-file#readme)
|
package/build.sh
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Colors
|
|
3
|
+
GREEN="\033[0;32m"
|
|
4
|
+
BLUE="\033[0;34m"
|
|
5
|
+
YELLOW="\033[1;33m"
|
|
6
|
+
RED="\033[0;31m"
|
|
7
|
+
NC="\033[0m"
|
|
8
|
+
CHECK="${GREEN}✔${NC}"
|
|
9
|
+
CROSS="${RED}✖${NC}"
|
|
10
|
+
|
|
11
|
+
DIR="$( cd "$( dirname "$0" )" && pwd )"
|
|
12
|
+
|
|
13
|
+
start_time=$(date +%s)
|
|
14
|
+
|
|
15
|
+
# ---- BOX FUNCTION -----------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
print_box () {
|
|
18
|
+
local text="$1"
|
|
19
|
+
local fixed_width="$2"
|
|
20
|
+
|
|
21
|
+
# Strip ANSI colors for measuring
|
|
22
|
+
local plain_text=$(echo -e "$text" | sed 's/\x1b\[[0-9;]*m//g')
|
|
23
|
+
local content_len=${#plain_text}
|
|
24
|
+
|
|
25
|
+
# Determine final width (content width if no fixed width)
|
|
26
|
+
local box_width
|
|
27
|
+
if [[ -n "$fixed_width" && "$fixed_width" -gt "$content_len" ]]; then
|
|
28
|
+
box_width=$fixed_width
|
|
29
|
+
else
|
|
30
|
+
box_width=$content_len
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# Compute padding for centering
|
|
34
|
+
local total_pad=$(( box_width - content_len ))
|
|
35
|
+
local left_pad=$(( total_pad / 2 ))
|
|
36
|
+
local right_pad=$(( total_pad - left_pad ))
|
|
37
|
+
|
|
38
|
+
# Generate padding spaces
|
|
39
|
+
local left_spaces=$(printf "%*s" "$left_pad" "")
|
|
40
|
+
local right_spaces=$(printf "%*s" "$right_pad" "")
|
|
41
|
+
|
|
42
|
+
# Build border
|
|
43
|
+
local border=$(printf '%*s' "$box_width" '' | tr ' ' '_')
|
|
44
|
+
local blank=$(printf '%*s' "$box_width" '' | tr ' ' ' ')
|
|
45
|
+
echo -e "${GREEN}"
|
|
46
|
+
echo " _$border""_"
|
|
47
|
+
echo "/ $blank"" \\"
|
|
48
|
+
echo " ${left_spaces}${text}${right_spaces}"
|
|
49
|
+
echo "\\_$border""_/"
|
|
50
|
+
echo -e "${NC}"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# ---- SCRIPT START -----------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
DEBUG=false
|
|
56
|
+
MAKE_KEYS=false
|
|
57
|
+
|
|
58
|
+
for arg in "$@"; do
|
|
59
|
+
case $arg in
|
|
60
|
+
--debug)
|
|
61
|
+
DEBUG=true
|
|
62
|
+
;;
|
|
63
|
+
--make-keys)
|
|
64
|
+
MAKE_KEYS=true
|
|
65
|
+
;;
|
|
66
|
+
esac
|
|
67
|
+
done
|
|
68
|
+
|
|
69
|
+
export DEBUG && export MAKE_KEYS
|
|
70
|
+
|
|
71
|
+
clear
|
|
72
|
+
print_box "$(basename "$0") execution" 64
|
|
73
|
+
|
|
74
|
+
echo -e "MODES"
|
|
75
|
+
echo -e "${YELLOW} $@ ${NC}"
|
|
76
|
+
|
|
77
|
+
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
|
|
78
|
+
echo -e "${BLUE}Creating codes from $SCRIPT_DIR/references/IBM_errors.csv ${NC}"
|
|
79
|
+
cd src
|
|
80
|
+
|
|
81
|
+
node readFile.mjs ../references/IBM_errors.csv |\
|
|
82
|
+
node fileTransformer/sanitize.mjs |\
|
|
83
|
+
node generate.cjs --flag "ibm" |\
|
|
84
|
+
node fileTransformer/stopNamedKeys.mjs> "$DIR/output1.txt"
|
|
85
|
+
|
|
86
|
+
echo -e "$CHECK done"
|
|
87
|
+
|
|
88
|
+
echo -e "${BLUE}Creating codes from $SCRIPT_DIR/references/PSQL_errors.csv ${NC}"
|
|
89
|
+
node readFile.mjs ../references/PSQL_errors.csv |\
|
|
90
|
+
node generate.cjs --flag "postgres" > "$DIR/output2.txt"
|
|
91
|
+
|
|
92
|
+
echo -e "$CHECK done"
|
|
93
|
+
|
|
94
|
+
echo -e "${BLUE}Creating codes from $SCRIPT_DIR/references/ORACLE_errors.csv ${NC}"
|
|
95
|
+
node readFile.mjs ../references/ORACLE_errors.csv |\
|
|
96
|
+
node fileTransformer/sanitize2.mjs |\
|
|
97
|
+
node generate.cjs --flag "oracle"> "$DIR/output3.txt"
|
|
98
|
+
|
|
99
|
+
echo -e "$CHECK done"
|
|
100
|
+
|
|
101
|
+
echo -e "${BLUE}Composition of the JSON file at $DIR/qlCodes.json${NC}"
|
|
102
|
+
echo {} | node compose.mjs --file "$DIR/output1.txt"|\
|
|
103
|
+
node compose.mjs --file "$DIR/output2.txt" |\
|
|
104
|
+
node compose.mjs --file "$DIR/output3.txt" |\
|
|
105
|
+
node pretty.mjs --file "$DIR/qlCodes.json"
|
|
106
|
+
|
|
107
|
+
echo -e "$CHECK deleted"
|
|
108
|
+
|
|
109
|
+
if ! $DEBUG ;
|
|
110
|
+
then
|
|
111
|
+
echo -e "${BLUE}removing processing files.${NC}"
|
|
112
|
+
cd .. ; rm "$DIR/output1.txt" ; rm "$DIR/output1.txt.debug.json"
|
|
113
|
+
cd .. ; rm "$DIR/output2.txt" ; rm "$DIR/output2.txt.debug.json"
|
|
114
|
+
cd .. ; rm "$DIR/output3.txt" ; rm "$DIR/output3.txt.debug.json"
|
|
115
|
+
echo -e "$CHECK removed"
|
|
116
|
+
fi
|
|
117
|
+
|
|
118
|
+
end_time=$(date +%s)
|
|
119
|
+
duration=$((end_time - start_time))
|
|
120
|
+
echo -ne "\nExecution complete in ${YELLOW}${duration}s${NC}$(tput el)\n"
|
|
121
|
+
|
|
122
|
+
print_box finish 64
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "qlcodes",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "src/index.mjs",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "chmod +x ./build.sh; ./build.sh"
|
|
7
|
+
},
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"author": "Jean Luc Emmanuel VERHANNEMAN",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"description": "A small utility that unifies SQL error codes (SQLSTATE) from different DBMS into a single, normalized structure through a curated dataset constructed at build time. The module is built from authoritative vendor documentation (IBM, PostgreSQL, Oracle) and generates static reference data at build time. Find references bellow.",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"postgres",
|
|
15
|
+
"ibm",
|
|
16
|
+
"sql",
|
|
17
|
+
"db",
|
|
18
|
+
"oracle",
|
|
19
|
+
"error",
|
|
20
|
+
"appendix",
|
|
21
|
+
"codes",
|
|
22
|
+
"guidance"
|
|
23
|
+
]
|
|
24
|
+
}
|