Commit iniziale
This commit is contained in:
10
node_modules/@tediousjs/connection-string/lib/parser/connection-string.d.ts
generated
vendored
Normal file
10
node_modules/@tediousjs/connection-string/lib/parser/connection-string.d.ts
generated
vendored
Normal 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): object;
|
||||
//# sourceMappingURL=connection-string.d.ts.map
|
||||
1
node_modules/@tediousjs/connection-string/lib/parser/connection-string.d.ts.map
generated
vendored
Normal file
1
node_modules/@tediousjs/connection-string/lib/parser/connection-string.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"connection-string.d.ts","sourceRoot":"","sources":["../../src/parser/connection-string.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,CAiHpH"}
|
||||
135
node_modules/@tediousjs/connection-string/lib/parser/connection-string.js
generated
vendored
Normal file
135
node_modules/@tediousjs/connection-string/lib/parser/connection-string.js
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
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;
|
||||
}
|
||||
exports.default = connectionStringParser;
|
||||
//# sourceMappingURL=connection-string.js.map
|
||||
1
node_modules/@tediousjs/connection-string/lib/parser/connection-string.js.map
generated
vendored
Normal file
1
node_modules/@tediousjs/connection-string/lib/parser/connection-string.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"connection-string.js","sourceRoot":"","sources":["../../src/parser/connection-string.ts"],"names":[],"mappings":";;AAUA,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,GAAG,EAAE,G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,OAAO,CAAC,CAAC;wBACd,OAAO,EAAE,CAAC;qBACb;yBAAM;wBACH,MAAM,EAAE,CAAC;qBACZ;iBACJ;qBAAM,IAAI,CAAC,MAAM,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE;oBACzC,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;oBAClD,IAAI,OAAO,KAAK,IAAI,EAAE;wBAClB,IAAI,CAAC,OAAO,CAAC,CAAC;wBACd,OAAO,EAAE,CAAC;qBACb;yBAAM;wBACH,OAAO,EAAE,CAAC;qBACb;iBACJ;qBAAM;oBACH,IAAI,CAAC,OAAO,CAAC,CAAC;iBACjB;aACJ;SACJ;aAAM,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE;YAC9B,OAAO,EAAE,CAAC;SACb;aAAM,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAClD;QACD,OAAO,EAAE,CAAC;KACb;IACD,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAChE;SAAM;QACH,OAAO,EAAE,CAAC;KACb;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAjHD,yCAiHC"}
|
||||
23
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.d.ts
generated
vendored
Normal file
23
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
export declare enum SchemaTypes {
|
||||
BOOL = 0,
|
||||
STRING = 1,
|
||||
NUMBER = 2
|
||||
}
|
||||
type Coercer = (val: string) => string | number | boolean | null;
|
||||
type Validator = (val: string | number | boolean) => boolean;
|
||||
export interface SchemaItem {
|
||||
type: SchemaTypes;
|
||||
allowedValues?: (string | number | boolean)[];
|
||||
default?: string | number | boolean;
|
||||
aliases?: string[];
|
||||
canonical?: string;
|
||||
coerce?: Coercer;
|
||||
validator?: Validator;
|
||||
}
|
||||
export interface SchemaDefinition {
|
||||
[name: string]: SchemaItem;
|
||||
}
|
||||
export declare const SCHEMA: SchemaDefinition;
|
||||
export default function parseSqlConnectionString(connectionString: string, canonicalProps?: boolean, allowUnknown?: boolean, strict?: boolean, schema?: SchemaDefinition): Record<string, string | number | boolean>;
|
||||
export {};
|
||||
//# sourceMappingURL=sql-connection-string.d.ts.map
|
||||
1
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.d.ts.map
generated
vendored
Normal file
1
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sql-connection-string.d.ts","sourceRoot":"","sources":["../../src/parser/sql-connection-string.ts"],"names":[],"mappings":"AAEA,oBAAY,WAAW;IACnB,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,MAAM,IAAA;CACT;AAED,KAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AACjE,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,KAAK,OAAO,CAAC;AAE7D,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAC9C,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,SAAS,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;CAC9B;AAGD,eAAO,MAAM,MAAM,EAAE,gBAqMpB,CAAC;AAmDF,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,gBAAgB,EAAE,MAAM,EAAE,cAAc,UAAQ,EAAE,YAAY,UAAQ,EAAE,MAAM,UAAQ,EAAE,MAAM,GAAE,gBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CA6BrN"}
|
||||
290
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.js
generated
vendored
Normal file
290
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.js
generated
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SCHEMA = exports.SchemaTypes = void 0;
|
||||
const connection_string_1 = __importDefault(require("./connection-string"));
|
||||
var SchemaTypes;
|
||||
(function (SchemaTypes) {
|
||||
SchemaTypes[SchemaTypes["BOOL"] = 0] = "BOOL";
|
||||
SchemaTypes[SchemaTypes["STRING"] = 1] = "STRING";
|
||||
SchemaTypes[SchemaTypes["NUMBER"] = 2] = "NUMBER";
|
||||
})(SchemaTypes = exports.SchemaTypes || (exports.SchemaTypes = {}));
|
||||
// schema for MSSQL connection strings (https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring)
|
||||
exports.SCHEMA = {
|
||||
'Application Name': {
|
||||
type: SchemaTypes.STRING,
|
||||
aliases: ['App'],
|
||||
validator(val) {
|
||||
return typeof val === 'string' && val.length <= 128;
|
||||
},
|
||||
},
|
||||
'ApplicationIntent': {
|
||||
type: SchemaTypes.STRING,
|
||||
allowedValues: ['ReadOnly', 'ReadWrite'],
|
||||
default: 'ReadWrite',
|
||||
},
|
||||
'Asynchronous Processing': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
aliases: ['Async'],
|
||||
},
|
||||
'AttachDBFilename': {
|
||||
type: SchemaTypes.STRING,
|
||||
aliases: ['Extended Properties', 'Initial File Name'],
|
||||
},
|
||||
'Authentication': {
|
||||
type: SchemaTypes.STRING,
|
||||
allowedValues: ['Active Directory Integrated', 'Active Directory Password', 'Sql Password'],
|
||||
},
|
||||
'Column Encryption Setting': {
|
||||
type: SchemaTypes.STRING,
|
||||
},
|
||||
'Connection Timeout': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
aliases: ['Connect Timeout', 'Timeout'],
|
||||
default: 15,
|
||||
},
|
||||
'Connection Lifetime': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
aliases: ['Load Balance Timeout'],
|
||||
default: 0,
|
||||
},
|
||||
'ConnectRetryCount': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
default: 1,
|
||||
validator(val) {
|
||||
return val > 0 && val <= 255;
|
||||
},
|
||||
},
|
||||
'ConnectRetryInterval': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
default: 10,
|
||||
},
|
||||
'Context Connection': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
},
|
||||
'Current Language': {
|
||||
aliases: ['Language'],
|
||||
type: SchemaTypes.STRING,
|
||||
validator(val) {
|
||||
return typeof val === 'string' && val.length <= 128;
|
||||
},
|
||||
},
|
||||
'Data Source': {
|
||||
aliases: ['Addr', 'Address', 'Server', 'Network Address'],
|
||||
type: SchemaTypes.STRING,
|
||||
},
|
||||
'Encrypt': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
},
|
||||
'Enlist': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: true,
|
||||
},
|
||||
'Failover Partner': {
|
||||
type: SchemaTypes.STRING,
|
||||
},
|
||||
'Initial Catalog': {
|
||||
type: SchemaTypes.STRING,
|
||||
aliases: ['Database'],
|
||||
validator(val) {
|
||||
return typeof val === 'string' && val.length <= 128;
|
||||
},
|
||||
},
|
||||
'Integrated Security': {
|
||||
type: SchemaTypes.BOOL,
|
||||
aliases: ['Trusted_Connection'],
|
||||
coerce(val) {
|
||||
return val === 'sspi' || null;
|
||||
},
|
||||
},
|
||||
'Max Pool Size': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
default: 100,
|
||||
validator(val) {
|
||||
return val >= 1;
|
||||
},
|
||||
},
|
||||
'Min Pool Size': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
default: 0,
|
||||
validator(val) {
|
||||
return val >= 0;
|
||||
},
|
||||
},
|
||||
'MultipleActiveResultSets': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
},
|
||||
'MultiSubnetFailover': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
},
|
||||
'Network Library': {
|
||||
type: SchemaTypes.STRING,
|
||||
aliases: ['Network', 'Net'],
|
||||
allowedValues: ['dbnmpntw', 'dbmsrpcn', 'dbmsadsn', 'dbmsgnet', 'dbmslpcn', 'dbmsspxn', 'dbmssocn', 'Dbmsvinn'],
|
||||
},
|
||||
'Packet Size': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
default: 8000,
|
||||
validator(val) {
|
||||
return val >= 512 && val <= 32768;
|
||||
},
|
||||
},
|
||||
'Password': {
|
||||
type: SchemaTypes.STRING,
|
||||
aliases: ['PWD'],
|
||||
validator(val) {
|
||||
return typeof val === 'string' && val.length <= 128;
|
||||
},
|
||||
},
|
||||
'Persist Security Info': {
|
||||
type: SchemaTypes.BOOL,
|
||||
aliases: ['PersistSecurityInfo'],
|
||||
default: false,
|
||||
},
|
||||
'PoolBlockingPeriod': {
|
||||
type: SchemaTypes.NUMBER,
|
||||
default: 0,
|
||||
coerce(val) {
|
||||
if (typeof val !== 'string') {
|
||||
return null;
|
||||
}
|
||||
switch (val.toLowerCase()) {
|
||||
case 'alwaysblock':
|
||||
return 1;
|
||||
case 'auto':
|
||||
return 0;
|
||||
case 'neverblock':
|
||||
return 2;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
},
|
||||
'Pooling': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: true,
|
||||
},
|
||||
'Replication': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
},
|
||||
'Transaction Binding': {
|
||||
type: SchemaTypes.STRING,
|
||||
allowedValues: ['Implicit Unbind', 'Explicit Unbind'],
|
||||
default: 'Implicit Unbind',
|
||||
},
|
||||
'TransparentNetworkIPResolution': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: true,
|
||||
},
|
||||
'TrustServerCertificate': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
},
|
||||
'Type System Version': {
|
||||
type: SchemaTypes.STRING,
|
||||
allowedValues: ['SQL Server 2012', 'SQL Server 2008', 'SQL Server 2005', 'Latest'],
|
||||
},
|
||||
'User ID': {
|
||||
type: SchemaTypes.STRING,
|
||||
aliases: ['UID'],
|
||||
validator(val) {
|
||||
return typeof val === 'string' && val.length <= 128;
|
||||
},
|
||||
},
|
||||
'User Instance': {
|
||||
type: SchemaTypes.BOOL,
|
||||
default: false,
|
||||
},
|
||||
'Workstation ID': {
|
||||
type: SchemaTypes.STRING,
|
||||
aliases: ['WSID'],
|
||||
validator(val) {
|
||||
return typeof val === 'string' && val.length <= 128;
|
||||
},
|
||||
},
|
||||
};
|
||||
function guessType(value) {
|
||||
if (value.trim() === '') {
|
||||
return SchemaTypes.STRING;
|
||||
}
|
||||
const asNum = parseInt(value, 10);
|
||||
if (!Number.isNaN(asNum) && asNum.toString() === value) {
|
||||
return SchemaTypes.NUMBER;
|
||||
}
|
||||
if (['true', 'false', 'yes', 'no'].includes(value.toLowerCase())) {
|
||||
return SchemaTypes.BOOL;
|
||||
}
|
||||
return SchemaTypes.STRING;
|
||||
}
|
||||
function coerce(value, type, coercer) {
|
||||
if (coercer) {
|
||||
const coerced = coercer(value);
|
||||
if (coerced !== null) {
|
||||
return coerced;
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case SchemaTypes.BOOL:
|
||||
if (['true', 'yes', '1'].includes(value.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
if (['false', 'no', '0'].includes(value.toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
return value;
|
||||
case SchemaTypes.NUMBER:
|
||||
return parseInt(value, 10);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function validate(value, allowedValues, validator) {
|
||||
let valid = true;
|
||||
if (validator) {
|
||||
valid = validator(value);
|
||||
}
|
||||
if (valid) {
|
||||
valid = (allowedValues === null || allowedValues === void 0 ? void 0 : allowedValues.includes(value)) || false;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function parseSqlConnectionString(connectionString, canonicalProps = false, allowUnknown = false, strict = false, schema = exports.SCHEMA) {
|
||||
const flattenedSchema = Object.entries(schema).reduce((flattened, [key, item]) => {
|
||||
var _a;
|
||||
Object.assign(flattened, {
|
||||
[key.toLowerCase()]: item,
|
||||
});
|
||||
return ((_a = item.aliases) === null || _a === void 0 ? void 0 : _a.reduce((accum, alias) => {
|
||||
return Object.assign(accum, {
|
||||
[alias.toLowerCase()]: {
|
||||
...item,
|
||||
canonical: key.toLowerCase(),
|
||||
},
|
||||
});
|
||||
}, flattened)) || flattened;
|
||||
}, {});
|
||||
return Object.entries((0, connection_string_1.default)(connectionString)).reduce((config, [prop, value]) => {
|
||||
if (!Object.prototype.hasOwnProperty.call(flattenedSchema, prop)) {
|
||||
return Object.assign(config, {
|
||||
[prop]: coerce(value, guessType(value)),
|
||||
});
|
||||
}
|
||||
let coercedValue = coerce(value, flattenedSchema[prop].type, flattenedSchema[prop].coerce);
|
||||
if (strict && !validate(coercedValue, flattenedSchema[prop].allowedValues, flattenedSchema[prop].validator)) {
|
||||
coercedValue = flattenedSchema[prop].default;
|
||||
}
|
||||
const propName = canonicalProps ? flattenedSchema[prop].canonical || prop : prop;
|
||||
return Object.assign(config, {
|
||||
[propName]: coercedValue,
|
||||
});
|
||||
}, {});
|
||||
}
|
||||
exports.default = parseSqlConnectionString;
|
||||
//# sourceMappingURL=sql-connection-string.js.map
|
||||
1
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.js.map
generated
vendored
Normal file
1
node_modules/@tediousjs/connection-string/lib/parser/sql-connection-string.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user