qlcodes 1.1.4 → 1.2.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
@@ -8,9 +8,9 @@ The module is built from authoritative vendor documentation (IBM, PostgreSQL, Or
8
8
 
9
9
  The project aims to cover sql states for most of RDBMS [drivers supported by **Typeorm** such as Google Spanner](https://typeorm.io/docs/drivers/google-spanner).
10
10
  Find bellow the actual coverage:
11
-
12
- 🕓 MySQL | 🕓 MariaDB | ✅ PostgreSQL | 🕓 CockroachDB (Postgres-compatible)
13
- 🕓 Microsoft SQL Server | ✅ Oracle | 🕓 SQLite | 🕓 SAP HANA | 🕓 Google Spanner | ✅ IBM*
11
+
12
+ 🕓 MySQL | ✅ MariaDB | ✅ PostgreSQL | 🕓 CockroachDB (Postgres-compatible)
13
+ 🕓 Microsoft SQL Server | ✅ Oracle | 🕓 SQLite | ✅ SAP HANA | ✅ Google Spanner | ✅ IBM*
14
14
  >( \* ) IBM defines and publishes SQLSTATE codes as part of the SQL standard, so their The codes should covere IBM products such as DB2, IBM Informix, IBM Netezza, IBM i (AS/400) .
15
15
 
16
16
  ## Installation
@@ -23,9 +23,9 @@ $ npm install qlcodes
23
23
 
24
24
  ```js
25
25
  import { lens } from "qlcodes";
26
-
26
+
27
27
  const state = lens("42501");
28
-
28
+
29
29
  console.log(state);
30
30
  ```
31
31
 
@@ -33,11 +33,25 @@ Output :
33
33
 
34
34
  ```js
35
35
  {
36
- code: "42501",
37
- keys: [ "insufficient_privilege" ],
38
- use: [ "ibm", "postgres" ],
39
- reason: "The authorization ID does not have the privilege to perform the specified operation on the identified object.",
40
- qlcs: "qlcodes_sucess"
36
+ "code": "42501",
37
+ "qlcs": "qlcodes_success",
38
+ "matches": [
39
+ {
40
+ "code": "42501",
41
+ "keys": [
42
+ "insufficient_privilege",
43
+ "authorization_id_does_not_have_privilege_to_perform_specified_operation_on_identified_object"
44
+ ],
45
+ "reasons": [
46
+ "The authorization ID does not have the privilege to perform the specified operation on the identified object."
47
+ ],
48
+ "use": [
49
+ "pgsql",
50
+ "ibm"
51
+ ],
52
+ "class": "42 - Syntax Error or Access Rule Violation"
53
+ }
54
+ ]
41
55
  }
42
56
  ```
43
57
 
@@ -49,7 +63,7 @@ This guarantees that lens() always returns a predictable object shape.
49
63
  There are three mismatch levels that we detect.
50
64
 
51
65
  **Format** : The provided code is malformed and is not validate the expression /[0-9A-Z]{5}/
52
-
66
+
53
67
  > â„šī¸ ["SQLSTATE values are comprised of a two-character class code value, followed by a three-character subclass code value. (ISO/IEC 9075:1992)"](https://www.ibm.com/docs/en/db2-for-zos/12.0.0?topic=codes-sqlstate-values-common-error)
54
68
 
55
69
  ```js
@@ -60,28 +74,9 @@ Output:
60
74
 
61
75
  ```js
62
76
  {
63
- code: "123456",
64
- keys: [],
65
- qlcs: "qlcodes_malformed",
66
- use: [],
67
- r
68
- ```
69
-
70
- **Class** : The provided code matches no code class
71
-
72
- ```js
73
- console.log(lens("ABCDE"));
74
- ```
75
-
76
- Output:
77
-
78
- ```js
79
- {
80
- code: "ABCDE",
81
- keys: [],
82
- qlcs: "qlcodes_no_class_found",
83
- use: [],
84
- reason: "The code 'ABCDE' does not match any entries in qlcodes. This may be a qlcode issue only to provide you with the correct information"
77
+ "code": "123456",
78
+ "qlcs": "qlcodes_malformed",
79
+ "matches": []
85
80
  }
86
81
  ```
87
82
 
@@ -95,11 +90,9 @@ Output:
95
90
 
96
91
  ```js
97
92
  {
98
- code: "2000U",
99
- keys: [],
100
- qlcs: "qlcodes_no_code_found",
101
- use: [],
102
- reason: "The code '2000U' does not match any entries in qlcodes. This may be a qlcode issue only to provide you with the correct information"
93
+ "code": "ABCDE",
94
+ "qlcs": "qlcodes_no_code_found",
95
+ "matches": []
103
96
  }
104
97
  ```
105
98
 
@@ -115,14 +108,11 @@ Output:
115
108
  || **code** — normalized SQLSTATE, or `-1` if not found
116
109
  || **keys** — semantic identifiers
117
110
  || **use** — `DBMS` where the code is applicable
118
- || **reason** — human-readable explanation
111
+ || **reasons** — human-readable explanations
119
112
  || **qlcs** — 'qlcode status', shows the lens call status
120
113
 
121
114
  ## Customization & Rebuild (Contributors)
122
115
 
123
- > âš ī¸ Do not modify files inside node_modules.
124
- > Changes will be lost on reinstall.
125
-
126
116
  If you want to extend or adjust the reference data:
127
117
 
128
118
  1) Clone the repository
@@ -133,32 +123,37 @@ $ cd qlcodes
133
123
  $ npm install
134
124
  ```
135
125
 
136
- 2) Modify files:
126
+ 2) Adapt the column (headers) configuration.
127
+ - `.qlCodes` file (root) : gives the configuration of CSVs headers/columns (with their format and aliases)
128
+ - `src/constants.mjs` : gives the configuration of the options passed throught `@maze014/domFetch` to fetch the documentation table of codes for the matching RDBMs.
129
+
130
+ 3) Run the dev script to set everything up.
131
+ ```bash
132
+ $ npm run dev
133
+ ```
134
+ This action will generate the folowing resources folders :
135
+ - HTML : files from which a DOM can be fetched via domFetch.
136
+ - CSV : CSVs files generated from the build script. These files can be modified according updated info.
137
137
 
138
- - under references/
139
- -> CSV files generated from vendor documentation
140
- - under src/
141
- -> transformation and normalization logic
142
138
 
143
- > âš ī¸ follow the data modification pipeline describe by the `build.sh` script.
144
- > unless you know what you know what you are doing.
139
+ 4) Rebuild the module
145
140
 
146
- 3) Rebuild the module
147
141
 
148
142
  ```bash
149
- $ npm run build
143
+ # generate the qlCodes.json
144
+ $ npm run build -- --prod
150
145
  ```
151
146
 
152
147
  ### Quality of life
153
148
 
154
- You may pass argument to the build script to enforce a few behaviours to help you seing through the process...
149
+ By default, the build script has no flag passed but
150
+ You may pass flag argument to the build script to enforce a few behaviours to help you seing through the processor...
155
151
 
156
152
  |argument|effect|
157
153
  |-|-|
158
154
  |`--debug`|prevents the cleanup of middle stage file created during the data processing|
159
- |`--make-keys`|allows the creation of keys when a description is given...through the 'generate' step (`generate.cjs`)|
155
+ |`--prod`|will destroy the resources folder in order to keep things clean|
160
156
 
161
- Use your customized build via a local dependency or a forked package.
162
157
 
163
158
  ---
164
159
 
@@ -182,6 +177,15 @@ Use your customized build via a local dependency or a forked package.
182
177
  [Oracle appendix](https://docs.oracle.com/cd/E15817_01/appdev.111/b31228/appd.htm)
183
178
  11g Release 1 (11.1)
184
179
 
180
+ - MariaDb
181
+ [MariaDB Error Code Reference](https://mariadb.com/docs/server/reference/error-codes/mariadb-error-code-reference)
182
+
183
+ - Google Spanner
184
+ [Spanner error codes](https://docs.cloud.google.com/spanner/docs/error-codes)
185
+
186
+ - SAP Hana
187
+ [SAP HANA SQL Reference Guide for SAP HANA Platform](https://help.sap.com/docs/SAP_HANA_PLATFORM/4fe29514fd584807ac9f2a04f6754767/20a78d3275191014b41bae7c4a46d835.html) V2.0 SPS 08
188
+
185
189
  ---
186
190
 
187
191
  ## License
package/dist/index.mjs ADDED
@@ -0,0 +1,70 @@
1
+ import { readFileSync } from "fs";
2
+
3
+ const data = JSON.parse(readFileSync("./qlCodes.json"));
4
+
5
+ export const lens = (code) => {
6
+ let response = {
7
+ code,
8
+ qlcs: "",
9
+ matches: [],
10
+ };
11
+
12
+ try {
13
+ // ---- validation ----
14
+ if (
15
+ code === "" ||
16
+ (!code && code !== "0") ||
17
+ !/^[A-Z0-9]{5}$/.test(`${code}`.padStart(5, "0"))
18
+ ) {
19
+ throw "qlcodes_malformed";
20
+ }
21
+
22
+ const paddedCode = `${code}`.padStart(5, "0");
23
+
24
+ // ---- find matching class ----
25
+ const classEntry = Object.entries(data).find(([id]) =>
26
+ paddedCode.startsWith(id)
27
+ );
28
+
29
+ const classesToSearch = [];
30
+
31
+ if (classEntry) {
32
+ classesToSearch.push({
33
+ id: classEntry[0],
34
+ data: classEntry[1],
35
+ });
36
+ }
37
+
38
+ // Always include NA as fallback / collision source
39
+ if (data["NA"]) {
40
+ classesToSearch.push({
41
+ id: "NA",
42
+ data: data["NA"],
43
+ });
44
+ }
45
+
46
+ // ---- collect all matches ----
47
+ for (const cls of classesToSearch) {
48
+ const hits = cls.data.messageSet.filter(
49
+ (x) => x.code === paddedCode || x.code === code
50
+ );
51
+
52
+ for (const hit of hits) {
53
+ response.matches.push({
54
+ ...hit,
55
+ class: `${cls.id} - ${cls.data.label}`,
56
+ });
57
+ }
58
+ }
59
+
60
+ if (response.matches.length === 0) {
61
+ throw "qlcodes_no_code_found";
62
+ }
63
+
64
+ response.qlcs = "qlcodes_success";
65
+ } catch (err) {
66
+ response.qlcs = typeof err === "string" ? err : "qlcodes_unexpected_error";
67
+ }
68
+
69
+ return response;
70
+ };