Skip to content

Commit 7141807

Browse files
authored
Merge pull request #81 from dhensby/pulls/v2
feat!: upgrade node and rewrite approach
2 parents d49c300 + e0915fe commit 7141807

25 files changed

+2725
-1590
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/nodejs.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Setup Node.js
2626
uses: actions/setup-node@v3
2727
with:
28-
node-version: 18.x
28+
node-version-file: '.nvmrc'
2929
cache: 'npm'
3030
- name: Install dependencies
3131
run: npm clean-install
@@ -46,7 +46,7 @@ jobs:
4646
- name: Setup Node.js
4747
uses: actions/setup-node@v3
4848
with:
49-
node-version: 18.x
49+
node-version-file: '.nvmrc'
5050
cache: 'npm'
5151
- name: Install dependencies
5252
run: npm clean-install
@@ -60,7 +60,7 @@ jobs:
6060
- codelint
6161
strategy:
6262
matrix:
63-
node-version: [18.x, 20.x, 22.x]
63+
node-version: [20.x, 22.x, 24.x]
6464
steps:
6565
- name: Checkout code
6666
uses: actions/checkout@v3
@@ -85,19 +85,19 @@ jobs:
8585
- uses: actions/checkout@v3
8686
with:
8787
persist-credentials: false
88-
- name: Use Node.js 20.x
88+
- name: Use Node.js
8989
uses: actions/setup-node@v3
9090
with:
91-
node-version: 20.x
91+
node-version-file: '.nvmrc'
9292
cache: 'npm'
9393
- name: Install deps
9494
run: npm ci
9595
- name: Test code
96-
run: npm run test:coverage --silent -- npm run test:workflow
96+
run: npm run test:coverage
9797
- name: Report coverage
9898
run: |
9999
echo "# Code coverage" >> $GITHUB_STEP_SUMMARY
100-
npx nyc report | sed --expression='1d;$d' >> $GITHUB_STEP_SUMMARY
100+
npx c8 report | sed --expression='1d;$d' >> $GITHUB_STEP_SUMMARY
101101
if: ${{ !cancelled() }}
102102
release:
103103
name: Release
@@ -121,7 +121,7 @@ jobs:
121121
- name: Setup Node.js
122122
uses: actions/setup-node@v3
123123
with:
124-
node-version: "lts/*"
124+
node-version-file: '.nvmrc'
125125
cache: 'npm'
126126
- name: Install dependencies
127127
run: npm clean-install

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

.nycrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"extends": "@istanbuljs/nyc-config-typescript",
32
"include": ["src"],
43
"all": true
54
}

README.md

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,108 @@ The library also provides the ability to parse SQL Connection Strings.
1111

1212
## Parsing connection strings
1313

14-
The library comes with a generic connection string parser that will parse through valid connections strings and produce a key-value
15-
map of the entries in that string. No additional validation is performed.
14+
The library comes with a generic connection string parser that will parse through valid connection strings and produce a key-value
15+
readonly Map of the entries in that string. No additional validation is performed.
1616

1717
```js
18-
const { parseConnectionString } = require('@tediousjs/connection-string');
18+
const { parse } = require('@tediousjs/connection-string');
1919

2020
const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';
2121

22-
const parsed = parseConnectionString(connectionString);
22+
const parsed = parse(connectionString);
2323

2424
console.log(parsed);
2525
```
2626

2727
Output to the console will be:
2828

29-
```json
30-
{
31-
"User id": "user",
32-
"password": "password",
33-
"initial catalog": "AdventureWorks",
34-
"server": "MySqlServer"
29+
```
30+
Map(4) {
31+
'user id' => 'user',
32+
'password' => 'password',
33+
'initial catalog' => 'AdventureWorks',
34+
'server' => 'MySqlServer'
3535
}
3636
```
3737

3838
## Parsing SQL connection strings
3939

40-
There is a specific helper for parsing SQL connection strings and this comes with a value normaliser and validation. It also has an
41-
option to "canonicalise" the properties. For many properties in an SQL connections string, there are aliases, when canonical properties
42-
are being used, these aliases will be returned as the canonical property.
40+
SQL connection strings can be parsed to a JSON object using the `toSchema()` method and the provided
41+
`MSSQL_SCHEMA`.
4342

4443
```js
45-
const { parseSqlConnectionString } = require('@tediousjs/connection-string');
44+
const { parse, MSSQL_SCHEMA } = require('@tediousjs/connection-string');
4645

4746
const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';
4847

49-
const parsed = parseSqlConnectionString(connectionString, true);
48+
const parsed = parse(connectionString);
5049

51-
console.log(parsed);
50+
console.log(parsed.toSchema(MSSQL_SCHEMA));
5251
```
5352

5453
Output to console will be:
5554

5655
```json
5756
{
58-
"user id": "user",
59-
"password": "password",
57+
"data source": "MySqlServer",
6058
"initial catalog": "AdventureWorks",
61-
"data source": "MySqlServer"
59+
"password": "password",
60+
"user id":"user"
6261
}
6362
```
6463

6564
NB: The `Server` property from the connection string has been re-written to the value `Data Source`
65+
66+
## Custom schemas
67+
68+
If you need to parse a connection string into a custom schema, the format is as follows:
69+
70+
```ts
71+
import { parse } from '@tediousjs/connection-string';
72+
73+
// a keyed map of name => config
74+
const schema = {
75+
'a string': {
76+
type: 'string',
77+
default: 'a default value',
78+
aliases: ['other', 'allowed', 'names'],
79+
},
80+
'a number': {
81+
type: 'number',
82+
default: 123,
83+
},
84+
'a boolean': {
85+
type: 'boolean',
86+
default: true,
87+
},
88+
};
89+
90+
const parsed = parse('a string=test;a number=987;a boolean=false;other value=missing');
91+
console.log(parsed.toSchema(schema));
92+
```
93+
94+
Output:
95+
96+
```json
97+
{
98+
"a string": "test",
99+
"a number": 987,
100+
"a boolean": false
101+
}
102+
```
103+
104+
## Accessing properties
105+
106+
The parsed connection string object is a readonly `Map` with an overloadded `get()` method allowing
107+
coercion of the value:
108+
109+
```ts
110+
import { parse } from '@tediousjs/connection-string';
111+
const parsed = parse('a string=test;a number=987;a boolean=false;other value=missing');
112+
// all values are strings by default
113+
console.log(parsed.get('a number')); // "987"
114+
// values can be coersed to an expected type
115+
console.log(parsed.get('a number', 'number')); // 987
116+
// coersion will be permissive in its type coersion
117+
console.log(parsed.get('a number', 'boolean')); // true
118+
```

eslint.config.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import eslint from '@eslint/js';
2+
import stylistic from '@stylistic/eslint-plugin';
3+
import tslint from 'typescript-eslint';
4+
5+
export default tslint.config(
6+
{
7+
plugins: {
8+
'@stylistic': stylistic,
9+
},
10+
},
11+
eslint.configs.recommended,
12+
...tslint.configs.recommendedTypeChecked,
13+
stylistic.configs.customize({
14+
indent: 4,
15+
quotes: 'single',
16+
semi: true,
17+
braceStyle: '1tbs',
18+
arrowParens: true,
19+
quoteProps: 'consistent-as-needed',
20+
commaDangle: 'only-multiline',
21+
}),
22+
{
23+
languageOptions: {
24+
parserOptions: {
25+
projectService: true,
26+
tsconfigRootDir: import.meta.dirname,
27+
},
28+
},
29+
},
30+
{
31+
files: ['./test/**'],
32+
rules: {
33+
'@typescript-eslint/no-floating-promises': ['off'],
34+
'@typescript-eslint/no-unsafe-assignment': ['off'],
35+
},
36+
},
37+
);

0 commit comments

Comments
 (0)