qlcodes 1.1.3 → 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,10 +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
14
- ✅ IBM*
11
+
12
+ 🕓 MySQL | ✅ MariaDB | ✅ PostgreSQL | 🕓 CockroachDB (Postgres-compatible)
13
+ 🕓 Microsoft SQL Server | ✅ Oracle | 🕓 SQLite | ✅ SAP HANA | ✅ Google Spanner | ✅ IBM*
15
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) .
16
15
 
17
16
  ## Installation
@@ -24,9 +23,9 @@ $ npm install qlcodes
24
23
 
25
24
  ```js
26
25
  import { lens } from "qlcodes";
27
-
26
+
28
27
  const state = lens("42501");
29
-
28
+
30
29
  console.log(state);
31
30
  ```
32
31
 
@@ -34,11 +33,25 @@ Output :
34
33
 
35
34
  ```js
36
35
  {
37
- code: "42501",
38
- keys: [ "insufficient_privilege" ],
39
- use: [ "ibm", "postgres" ],
40
- reason: "The authorization ID does not have the privilege to perform the specified operation on the identified object.",
41
- 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
+ ]
42
55
  }
43
56
  ```
44
57
 
@@ -50,7 +63,7 @@ This guarantees that lens() always returns a predictable object shape.
50
63
  There are three mismatch levels that we detect.
51
64
 
52
65
  **Format** : The provided code is malformed and is not validate the expression /[0-9A-Z]{5}/
53
-
66
+
54
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)
55
68
 
56
69
  ```js
@@ -61,28 +74,9 @@ Output:
61
74
 
62
75
  ```js
63
76
  {
64
- code: "123456",
65
- keys: [],
66
- qlcs: "qlcodes_malformed",
67
- use: [],
68
- r
69
- ```
70
-
71
- **Class** : The provided code matches no code class
72
-
73
- ```js
74
- console.log(lens("ABCDE"));
75
- ```
76
-
77
- Output:
78
-
79
- ```js
80
- {
81
- code: "ABCDE",
82
- keys: [],
83
- qlcs: "qlcodes_no_class_found",
84
- use: [],
85
- 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": []
86
80
  }
87
81
  ```
88
82
 
@@ -96,11 +90,9 @@ Output:
96
90
 
97
91
  ```js
98
92
  {
99
- code: "2000U",
100
- keys: [],
101
- qlcs: "qlcodes_no_code_found",
102
- use: [],
103
- 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": []
104
96
  }
105
97
  ```
106
98
 
@@ -116,14 +108,11 @@ Output:
116
108
  || **code** — normalized SQLSTATE, or `-1` if not found
117
109
  || **keys** — semantic identifiers
118
110
  || **use** — `DBMS` where the code is applicable
119
- || **reason** — human-readable explanation
111
+ || **reasons** — human-readable explanations
120
112
  || **qlcs** — 'qlcode status', shows the lens call status
121
113
 
122
114
  ## Customization & Rebuild (Contributors)
123
115
 
124
- > âš ī¸ Do not modify files inside node_modules.
125
- > Changes will be lost on reinstall.
126
-
127
116
  If you want to extend or adjust the reference data:
128
117
 
129
118
  1) Clone the repository
@@ -134,32 +123,37 @@ $ cd qlcodes
134
123
  $ npm install
135
124
  ```
136
125
 
137
- 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.
138
137
 
139
- - under references/
140
- -> CSV files generated from vendor documentation
141
- - under src/
142
- -> transformation and normalization logic
143
138
 
144
- > âš ī¸ follow the data modification pipeline describe by the `build.sh` script.
145
- > unless you know what you know what you are doing.
139
+ 4) Rebuild the module
146
140
 
147
- 3) Rebuild the module
148
141
 
149
142
  ```bash
150
- $ npm run build
143
+ # generate the qlCodes.json
144
+ $ npm run build -- --prod
151
145
  ```
152
146
 
153
147
  ### Quality of life
154
148
 
155
- 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...
156
151
 
157
152
  |argument|effect|
158
153
  |-|-|
159
154
  |`--debug`|prevents the cleanup of middle stage file created during the data processing|
160
- |`--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|
161
156
 
162
- Use your customized build via a local dependency or a forked package.
163
157
 
164
158
  ---
165
159
 
@@ -183,6 +177,15 @@ Use your customized build via a local dependency or a forked package.
183
177
  [Oracle appendix](https://docs.oracle.com/cd/E15817_01/appdev.111/b31228/appd.htm)
184
178
  11g Release 1 (11.1)
185
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
+
186
189
  ---
187
190
 
188
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
+ };