Estructura inicial del proyecto

This commit is contained in:
2026-06-02 16:57:08 +00:00
commit 8b306b9afc
9864 changed files with 1435687 additions and 0 deletions

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Daniel Hensby
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,118 @@
# Connection String Parser
[![npm version](https://badge.fury.io/js/@tediousjs%2Fconnection-string.svg)](https://www.npmjs.com/package/@tediousjs/connection-string)
[![Lint, Test & Release](https://github.com/tediousjs/connection-string/actions/workflows/nodejs.yml/badge.svg)](https://github.com/tediousjs/connection-string/actions/workflows/nodejs.yml)
This node library is designed to allow the parsing of Connection Strings see https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring
The library also provides the ability to parse SQL Connection Strings.
# Usage
## Parsing connection strings
The library comes with a generic connection string parser that will parse through valid connection strings and produce a key-value
readonly Map of the entries in that string. No additional validation is performed.
```js
const { parse } = require('@tediousjs/connection-string');
const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';
const parsed = parse(connectionString);
console.log(parsed);
```
Output to the console will be:
```
Map(4) {
'user id' => 'user',
'password' => 'password',
'initial catalog' => 'AdventureWorks',
'server' => 'MySqlServer'
}
```
## Parsing SQL connection strings
SQL connection strings can be parsed to a JSON object using the `toSchema()` method and the provided
`MSSQL_SCHEMA`.
```js
const { parse, MSSQL_SCHEMA } = require('@tediousjs/connection-string');
const connectionString = 'User ID=user;Password=password;Initial Catalog=AdventureWorks;Server=MySqlServer';
const parsed = parse(connectionString);
console.log(parsed.toSchema(MSSQL_SCHEMA));
```
Output to console will be:
```json
{
"data source": "MySqlServer",
"initial catalog": "AdventureWorks",
"password": "password",
"user id":"user"
}
```
NB: The `Server` property from the connection string has been re-written to the value `Data Source`
## Custom schemas
If you need to parse a connection string into a custom schema, the format is as follows:
```ts
import { parse } from '@tediousjs/connection-string';
// a keyed map of name => config
const schema = {
'a string': {
type: 'string',
default: 'a default value',
aliases: ['other', 'allowed', 'names'],
},
'a number': {
type: 'number',
default: 123,
},
'a boolean': {
type: 'boolean',
default: true,
},
};
const parsed = parse('a string=test;a number=987;a boolean=false;other value=missing');
console.log(parsed.toSchema(schema));
```
Output:
```json
{
"a string": "test",
"a number": 987,
"a boolean": false
}
```
## Accessing properties
The parsed connection string object is a readonly `Map` with an overloadded `get()` method allowing
coercion of the value:
```ts
import { parse } from '@tediousjs/connection-string';
const parsed = parse('a string=test;a number=987;a boolean=false;other value=missing');
// all values are strings by default
console.log(parsed.get('a number')); // "987"
// values can be coersed to an expected type
console.log(parsed.get('a number', 'number')); // 987
// coersion will be permissive in its type coersion
console.log(parsed.get('a number', 'boolean')); // true
```

View File

@ -0,0 +1,6 @@
type ValidDataTypes = string | boolean | number | null | undefined | {
toString(): string;
};
export declare function build(data: Record<string, ValidDataTypes>): string;
export {};
//# sourceMappingURL=index.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/builder/index.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG;IAAE,QAAQ,IAAI,MAAM,CAAA;CAAE,CAAC;AA4C5F,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,MAAM,CAIlE"}

View File

@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.build = build;
function isQuoted(val) {
if (val[0] !== '{') {
return false;
}
for (let i = 1; i < val.length; i++) {
if (val[i] === '}') {
if (i + 1 === val.length) {
// if last char, then it's quoted properly
return true;
}
else if (val[i + 1] !== '}') {
// the next char is no a `}` so there is no valid escaping here
return false;
}
else {
// we are seeing an escaped `}`, so skip ahead
i++;
}
}
}
return false;
}
function needsQuotes(val) {
return !isQuoted(val) && !!val.match(/\[|]|{|}|\|\(|\)|,|;|\?|\*|=|!|@/)?.length;
}
function encodeTuple(key, value) {
if (value === null || value === undefined) {
return [key, ''];
}
switch (typeof value) {
case 'boolean':
return [key, value ? 'Yes' : 'No'];
default: {
const strVal = value.toString();
if (needsQuotes(strVal)) {
return [key, `{${strVal.replace(/}/g, '}}')}}`];
}
return [key, strVal];
}
}
}
function build(data) {
return Object.entries(data).map(([key, value]) => {
return encodeTuple(key.trim(), value).join('=');
}).join(';');
}
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/builder/index.ts"],"names":[],"mappings":";;AA4CA,sBAIC;AA9CD,SAAS,QAAQ,CAAC,GAAW;IACzB,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YACjB,IAAI,CAAC,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AI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC7C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC"}

View File

@ -0,0 +1,35 @@
import { inspect } from 'node:util';
interface CoerceTypeMap {
string: string;
number: number;
boolean: boolean;
}
export type CoerceType = keyof CoerceTypeMap;
type InferSchema<T extends SchemaDefinition> = {
[K in keyof T]: T[K]['type'] extends CoerceType ? CoerceTypeMap[T[K]['type']] : string;
};
export interface SchemaItem<T extends CoerceType = 'string'> {
type?: T;
default?: CoerceTypeMap[T];
aliases?: string[];
}
export type SchemaDefinition = Record<string, SchemaItem<any>>;
export declare class ConnectionString implements ReadonlyMap<string, string> {
#private;
constructor(connectionString: string);
[inspect.custom](): ReadonlyMap<string, string>;
get size(): number;
get<T extends CoerceType = 'string'>(key: string, coerceType?: T): CoerceTypeMap[T] | undefined;
keys(): MapIterator<string>;
values(): MapIterator<string>;
[Symbol.iterator](): MapIterator<[string, string]>;
entries(): MapIterator<[string, string]>;
toString(): string;
has(key: string): boolean;
forEach(callbackfn: (value: string, key: string, map: ReadonlyMap<string, string>) => void, thisArg?: any): void;
toSchema<T extends SchemaDefinition>(schema: T, { includeMissing }?: {
includeMissing?: boolean;
}): InferSchema<T>;
}
export {};
//# sourceMappingURL=connection-string.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"connection-string.d.ts","sourceRoot":"","sources":["../src/connection-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,UAAU,aAAa;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,UAAU,G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,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,IAAI;IAOhH,QAAQ,CAAC,CAAC,SAAS,gBAAgB,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,cAAc,EAAE,GAAE;QAAE,cAAc,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,WAAW,CAAC,CAAC,CAAC;CAUzH"}

View File

@ -0,0 +1,77 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectionString = void 0;
const node_util_1 = require("node:util");
const connection_string_parser_1 = __importDefault(require("./parser/connection-string-parser"));
class ConnectionString {
#connectionString;
#parsed;
constructor(connectionString) {
this.#connectionString = connectionString.toString();
const parsed = (0, connection_string_parser_1.default)(this.#connectionString);
this.#parsed = new Map(Object.entries(parsed));
}
[node_util_1.inspect.custom]() {
return this.#parsed;
}
get size() {
return this.#parsed.size;
}
// it would be really nice to be able to make this a generice (eg: get<string>) and that would then coerce the value
// see typia library for an example of something similar
get(key, coerceType) {
const val = this.#parsed.get(key.toLowerCase());
const actualType = coerceType ?? 'string';
if (typeof val === 'undefined' || actualType === 'string') {
return val;
}
switch (actualType) {
case 'boolean':
return (['false', 'no', '0'].includes(val.toLowerCase()) ? false : !!val);
case 'number':
return parseInt(val, 10);
default:
throw new TypeError('Coerce type not supported');
}
}
keys() {
return this.#parsed.keys();
}
values() {
return this.#parsed.values();
}
[Symbol.iterator]() {
return this.#parsed[Symbol.iterator]();
}
entries() {
return this.#parsed.entries();
}
toString() {
return this.#connectionString;
}
has(key) {
return this.#parsed.has(key.toLowerCase());
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
forEach(callbackfn, thisArg) {
this.#parsed.forEach((value, key) => {
callbackfn.call(thisArg ?? this, value, key, this);
});
}
// a way to extract a formatted object from the connection string
toSchema(schema, { includeMissing } = {}) {
return Object.fromEntries(Object.entries(schema).reduce((props, [key, { type, default: defaultValue, aliases }]) => {
// try to find the property
const prop = [key, ...aliases ?? []].find((k) => this.has(k));
if (prop || includeMissing) {
props.push([key, prop ? this.get(prop.toLowerCase(), type) : defaultValue]);
}
return props;
}, []));
}
}
exports.ConnectionString = ConnectionString;
//# sourceMappingURL=connection-string.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"connection-string.js","sourceRoot":"","sources":["../src/connection-string.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,iGAAuE;AAyBvE,MAAa,gBAAgB;IAChB,iBAAiB,CAAS;IAC1B,OAAO,CAA8B;IAC9C,YAAY,gBAAwB;QAChC,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QACrD,MAAM,MAAM,GAAG,IAAA,kCAAsB,EAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAiB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,CAAC,mBAAO,CAAC,MAAM,CAAC;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED,oHAAoH;IACpH,wDAAwD;IACxD,GAAG,CAAkC,GAAW,EAAE,UAAc;QAC5D,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,UAAU,IAAI,QAAQ,CAAC;QAC1C,IAAI,OAAO,GAAG,KAAK,WAAW,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;YACxD,OAAO,GAAuB,CAAC;QACnC,CAAC;QACD,QAAQ,UAAU,EAAE,CAAC;YACjB,KAAK,SAAS;gBACV,OAAO,CAAC,CAAC,OAAO,EAAE,IAAI,EAA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C,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;YAC/G,2BAA2B;YAC3B,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9D,IAAI,IAAI,IAAI,cAAc,EAAE,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAA0B,CAAC,CAAC;YACzG,CAAC;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,EAAE,EAA6B,CAAC,CAAmB,CAAC;IACzD,CAAC;CACJ;AA7ED,4CA6EC"}

View File

@ -0,0 +1,6 @@
import { CoerceType, ConnectionString, SchemaDefinition, SchemaItem } from './connection-string';
import { build } from './builder';
import MSSQL_SCHEMA from './schema/mssql-schema';
export declare function parse(connectionString: string): Readonly<ConnectionString>;
export { build, CoerceType, SchemaDefinition, SchemaItem, MSSQL_SCHEMA };
//# sourceMappingURL=index.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,wBAAgB,KAAK,CAAC,gBAAgB,EAAE,MAAM,8BAE7C;AAED,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC"}

View File

@ -0,0 +1,16 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MSSQL_SCHEMA = exports.build = void 0;
exports.parse = parse;
const connection_string_1 = require("./connection-string");
const builder_1 = require("./builder");
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return builder_1.build; } });
const mssql_schema_1 = __importDefault(require("./schema/mssql-schema"));
exports.MSSQL_SCHEMA = mssql_schema_1.default;
function parse(connectionString) {
return Object.freeze(new connection_string_1.ConnectionString(connectionString));
}
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AASA,sBAEC;AAXD,2DAK6B;AAC7B,uCAAkC;AAOzB,sFAPA,eAAK,OAOA;AANd,yEAAiD;AAMS,uBANnD,sBAAY,CAMmD;AAJtE,SAAgB,KAAK,CAAC,gBAAwB;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,oCAAgB,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACjE,CAAC"}

View File

@ -0,0 +1,10 @@
export interface CollectionConfig {
terminator: string;
quotes: Record<string, string>;
}
export interface ParserConfig {
key: CollectionConfig;
value: CollectionConfig;
}
export default function connectionStringParser(connectionString: string, parserConfig?: ParserConfig): Record<string, string>;
//# sourceMappingURL=connection-string-parser.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"connection-string-parser.d.ts","sourceRoot":"","sources":["../../src/parser/connection-string-parser.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IACzB,GAAG,EAAE,gBAAgB,CAAC;IACtB,KAAK,EAAE,gBAAgB,CAAC;CAC3B;AAsBD,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,gBAAgB,EAAE,MAAM,EAAE,YAAY,GAAE,YAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiHpI"}

View File

@ -0,0 +1,135 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = connectionStringParser;
var CollectionMode;
(function (CollectionMode) {
CollectionMode[CollectionMode["key"] = 0] = "key";
CollectionMode[CollectionMode["value"] = 1] = "value";
})(CollectionMode || (CollectionMode = {}));
const CONFIG = Object.freeze({
key: {
terminator: '=',
quotes: {},
},
value: {
terminator: ';',
quotes: {
'"': '"',
'\'': '\'',
'{': '}',
},
},
});
function connectionStringParser(connectionString, parserConfig = CONFIG) {
const parsed = {};
let collectionMode = CollectionMode.key;
let started = false;
let finished = false;
let quoted = false;
let quote = '';
let buffer = '';
let currentKey = '';
let pointer = 0;
function start() {
started = true;
}
function finish() {
finished = true;
}
function reset() {
started = false;
finished = false;
quoted = false;
quote = '';
buffer = '';
}
function config() {
return collectionMode === CollectionMode.key ? parserConfig.key : parserConfig.value;
}
function isTerminator(char) {
return config().terminator === char;
}
function isStartQuote(char) {
return Object.keys(config().quotes).some((val) => char === val);
}
function isEndQuote(char) {
return quoted && char === config().quotes[quote];
}
function push(char) {
buffer += char;
}
function collect() {
if (!quoted) {
buffer = buffer.trim();
}
switch (collectionMode) {
case CollectionMode.key:
currentKey = buffer.toLowerCase();
collectionMode = CollectionMode.value;
break;
case CollectionMode.value:
collectionMode = CollectionMode.key;
parsed[currentKey] = buffer;
currentKey = '';
break;
}
reset();
}
while (pointer < connectionString.length) {
const current = connectionString.charAt(pointer);
if (!finished) {
if (!started) {
if (current.trim()) {
start();
if (isStartQuote(current)) {
quoted = true;
quote = current;
}
else {
push(current);
}
}
}
else {
if (quoted && isEndQuote(current)) {
const next = connectionString.charAt(pointer + 1);
if (current === next) {
push(current);
pointer++;
}
else {
finish();
}
}
else if (!quoted && isTerminator(current)) {
const next = connectionString.charAt(pointer + 1);
if (current === next) {
push(current);
pointer++;
}
else {
collect();
}
}
else {
push(current);
}
}
}
else if (isTerminator(current)) {
collect();
}
else if (current.trim()) {
throw new Error('Malformed connection string');
}
pointer++;
}
if (quoted && !finished) {
throw new Error('Connection string terminated unexpectedly');
}
else {
collect();
}
return parsed;
}
//# sourceMappingURL=connection-string-parser.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"connection-string-parser.js","sourceRoot":"","sources":["../../src/parser/connection-string-parser.ts"],"names":[],"mappings":";;AA8BA,yCAiHC;AArID,IAAK,cAGJ;AAHD,WAAK,cAAc;IACf,iDAAG,CAAA;IACH,qDAAK,CAAA;AACT,CAAC,EAHI,cAAc,KAAd,cAAc,QAGlB;AAED,MAAM,MAAM,GAAiB,MAAM,CAAC,MAAM,CAAC;IACvC,GAAG,EAAE;QACD,UAAU,EAAE,GAAG;QACf,MAAM,EAAE,EAAE;KACb;IACD,KAAK,EAAE;QACH,UAAU,EAAE,GAAG;QACf,MAAM,EAAE;YACJ,GAAG,EAAE,GAAG;YACR,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,GAAG;SACX;KACJ;CACJ,CAAC,CAAC;AAEH,SAAwB,sBAAsB,CAAC,gBAAwB,EAAE,eAA6B,MAAM;IACxG,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,IAAI,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC;IACxC,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,SAAS,KAAK;QACV,OAAO,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,SAAS,MAAM;QAC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,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,IAAI,CAAC,OAAO,CAAC,CAAC;gBAClB,CAAC;YACL,CAAC;QACL,CAAC;aAAM,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,OAAO,EAAE,CAAC;QACd,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;IACD,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACjE,CAAC;SAAM,CAAC;QACJ,OAAO,EAAE,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}

View File

@ -0,0 +1,4 @@
import { SchemaDefinition } from '../connection-string';
declare const mssqlSchema: SchemaDefinition;
export default mssqlSchema;
//# sourceMappingURL=mssql-schema.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"mssql-schema.d.ts","sourceRoot":"","sources":["../../src/schema/mssql-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,QAAA,MAAM,WAAW,EAAE,gBAiJlB,CAAC;AAEF,eAAe,WAAW,CAAC"}

View File

@ -0,0 +1,150 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mssqlSchema = {
'application name': {
type: 'string',
aliases: ['app'],
},
'applicationintent': {
type: 'string',
default: 'ReadWrite',
},
'asynchronous processing': {
type: 'boolean',
default: false,
aliases: ['Async'],
},
'attachdbfilename': {
type: 'string',
aliases: ['extended properties', 'initial file name'],
},
'authentication': {
type: 'string',
},
'column encryption setting': {
type: 'string',
},
'connection timeout': {
type: 'number',
aliases: ['connect timeout', 'timeout'],
default: 15,
},
'connection lifetime': {
type: 'number',
aliases: ['load balance timeout'],
default: 0,
},
'connectretrycount': {
type: 'number',
default: 1,
},
'connectretryinterval': {
type: 'number',
default: 10,
},
'context connection': {
type: 'boolean',
default: false,
},
'current language': {
aliases: ['language'],
type: 'string',
},
'data source': {
aliases: ['addr', 'address', 'server', 'network address'],
type: 'string',
},
'encrypt': {
type: 'boolean',
default: false,
},
'enlist': {
type: 'boolean',
default: true,
},
'failover partner': {
type: 'string',
},
'initial catalog': {
type: 'string',
aliases: ['database'],
},
'integrated security': {
type: 'boolean',
aliases: ['trusted_connection'],
},
'max pool size': {
type: 'number',
default: 100,
},
'min pool size': {
type: 'number',
default: 0,
},
'multipleactiveresultsets': {
type: 'boolean',
default: false,
},
'multisubnetfailover': {
type: 'boolean',
default: false,
},
'network library': {
type: 'string',
aliases: ['network', 'net'],
},
'packet size': {
type: 'number',
default: 8000,
},
'password': {
type: 'string',
aliases: ['pwd'],
},
'persist security info': {
type: 'boolean',
aliases: ['persistsecurityinfo'],
default: false,
},
'poolblockingperiod': {
type: 'number',
default: 0,
},
'pooling': {
type: 'boolean',
default: true,
},
'replication': {
type: 'boolean',
default: false,
},
'transaction binding': {
type: 'string',
default: 'Implicit Unbind',
},
'transparentnetworkipresolution': {
type: 'boolean',
default: true,
},
'trustservercertificate': {
type: 'boolean',
default: false,
},
'type system version': {
type: 'string',
},
'user id': {
type: 'string',
aliases: ['uid'],
},
'user instance': {
type: 'boolean',
default: false,
},
'workstation id': {
type: 'string',
aliases: ['wsid'],
},
};
exports.default = mssqlSchema;
//# sourceMappingURL=mssql-schema.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"mssql-schema.js","sourceRoot":"","sources":["../../src/schema/mssql-schema.ts"],"names":[],"mappings":";;AAEA,MAAM,WAAW,GAAqB;IAClC,kBAAkB,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,KAAK,CAAC;KACnB;IACD,mBAAmB,EAAE;QACjB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,WAAW;KACvB;IACD,y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ACP,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,KAAK,CAAC;KACnB;IACD,eAAe,EAAE;QACb,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,KAAK;KACjB;IACD,gBAAgB,EAAE;QACd,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,MAAM,CAAC;KACpB;CACJ,CAAC;AAEF,kBAAe,WAAW,CAAC"}

View File

@ -0,0 +1,62 @@
{
"name": "@tediousjs/connection-string",
"version": "1.1.0",
"description": "SQL ConnectionString parser",
"repository": {
"type": "git",
"url": "https://github.com/tediousjs/connection-string"
},
"bugs": {
"url": "https://github.com/tediousjs/connection-string/issues"
},
"homepage": "https://github.com/tediousjs/connection-string#readme",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"scripts": {
"prepare": "tsc",
"build": "tsc",
"lint": "eslint ./src ./test",
"test": "tsx --test test/**/*.test.ts",
"test:coverage": "c8 --reporter=cobertura -- tsx --test test/**/*.test.ts test/*.test.ts",
"test:workflow": "npm run test --silent"
},
"keywords": [
"mssql",
"tsql",
"connectionstring"
],
"author": "Dan Hensby <git@hens.by>",
"license": "MIT",
"files": [
"/lib/**"
],
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@commitlint/cli": "^20.5.0",
"@commitlint/config-conventional": "^20.5.0",
"@eslint/js": "^10.0.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^13.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^12.0.6",
"@semantic-release/npm": "^13.1.5",
"@semantic-release/release-notes-generator": "^14.1.0",
"@stylistic/eslint-plugin": "^5.0.0",
"@tsconfig/node22": "^22.0.5",
"@types/node": "^20.19.0",
"c8": "^11.0.0",
"eslint": "^10.0.2",
"semantic-release": "^25.0.3",
"tsx": "^4.19.4",
"typescript": "^6.0.2",
"typescript-eslint": "^8.33.1"
}
}