@prisma/adapter-mssql 7.4.0-integration-parameterization.22 → 7.5.0-dev.1
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/dist/index.js +77 -23
- package/dist/index.mjs +77 -23
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -63,25 +63,66 @@ function mapIsolationLevelFromString(level) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
var debug = (0, import_driver_adapter_utils.Debug)("prisma:driver-adapter:mssql:connection-string");
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
function splitRespectingBraces(str) {
|
|
67
|
+
const parts = [];
|
|
68
|
+
let current = "";
|
|
69
|
+
let braceDepth = 0;
|
|
70
|
+
let valueStartIndex = -1;
|
|
71
|
+
for (let i = 0; i < str.length; i++) {
|
|
72
|
+
const char = str[i];
|
|
73
|
+
if (char === "=") {
|
|
74
|
+
current += char;
|
|
75
|
+
if (braceDepth === 0) {
|
|
76
|
+
valueStartIndex = i + 1;
|
|
77
|
+
}
|
|
78
|
+
} else if (char === "{") {
|
|
79
|
+
const isFirstCharOfValue = i === valueStartIndex;
|
|
80
|
+
if (isFirstCharOfValue) {
|
|
81
|
+
braceDepth++;
|
|
82
|
+
} else if (braceDepth > 0) {
|
|
83
|
+
throw new Error(`Malformed connection string: nested '{' braces are not supported`);
|
|
84
|
+
}
|
|
85
|
+
current += char;
|
|
86
|
+
} else if (char === "}") {
|
|
87
|
+
if (braceDepth > 0) {
|
|
88
|
+
braceDepth--;
|
|
89
|
+
}
|
|
90
|
+
current += char;
|
|
91
|
+
} else if (char === ";" && braceDepth === 0) {
|
|
92
|
+
parts.push(current);
|
|
93
|
+
current = "";
|
|
94
|
+
valueStartIndex = -1;
|
|
95
|
+
} else {
|
|
96
|
+
current += char;
|
|
73
97
|
}
|
|
74
98
|
}
|
|
75
|
-
|
|
99
|
+
if (current) {
|
|
100
|
+
parts.push(current);
|
|
101
|
+
}
|
|
102
|
+
if (braceDepth !== 0) {
|
|
103
|
+
throw new Error(`Malformed connection string: unclosed '{' brace (braceDepth=${braceDepth})`);
|
|
104
|
+
}
|
|
105
|
+
return parts;
|
|
106
|
+
}
|
|
107
|
+
function unescapeValue(value) {
|
|
108
|
+
const trimmed = value.trim();
|
|
109
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}") && trimmed.length >= 2) {
|
|
110
|
+
return trimmed.slice(1, -1);
|
|
111
|
+
}
|
|
112
|
+
return trimmed;
|
|
76
113
|
}
|
|
77
114
|
function parseConnectionString(connectionString) {
|
|
78
115
|
const withoutProtocol = connectionString.replace(/^sqlserver:\/\//, "");
|
|
79
|
-
const
|
|
116
|
+
const parts = splitRespectingBraces(withoutProtocol);
|
|
117
|
+
const [hostPart, ...paramParts] = parts;
|
|
80
118
|
const config = {
|
|
81
119
|
server: "",
|
|
82
120
|
options: {},
|
|
83
121
|
pool: {}
|
|
84
122
|
};
|
|
123
|
+
if (!hostPart || hostPart.trim() === "") {
|
|
124
|
+
throw new Error("Server host is required in connection string");
|
|
125
|
+
}
|
|
85
126
|
const [host, portStr] = hostPart.split(":");
|
|
86
127
|
config.server = host.trim();
|
|
87
128
|
if (portStr) {
|
|
@@ -93,13 +134,14 @@ function parseConnectionString(connectionString) {
|
|
|
93
134
|
}
|
|
94
135
|
const parameters = {};
|
|
95
136
|
for (const part of paramParts) {
|
|
96
|
-
const [key,
|
|
137
|
+
const [key, ...valueParts] = part.split("=");
|
|
97
138
|
if (!key) continue;
|
|
98
139
|
const trimmedKey = key.trim();
|
|
99
140
|
if (trimmedKey in parameters) {
|
|
100
141
|
throw new Error(`Duplication configuration parameter: ${trimmedKey}`);
|
|
101
142
|
}
|
|
102
|
-
|
|
143
|
+
const value = valueParts.join("=");
|
|
144
|
+
parameters[trimmedKey] = unescapeValue(value);
|
|
103
145
|
if (!handledParameters.includes(trimmedKey)) {
|
|
104
146
|
debug(`Unknown connection string parameter: ${trimmedKey}`);
|
|
105
147
|
}
|
|
@@ -190,7 +232,8 @@ function parseConnectionString(connectionString) {
|
|
|
190
232
|
if (!config.server || config.server.trim() === "") {
|
|
191
233
|
throw new Error("Server host is required in connection string");
|
|
192
234
|
}
|
|
193
|
-
|
|
235
|
+
const schema = firstKey(parameters, "schema") ?? void 0;
|
|
236
|
+
return { config, schema };
|
|
194
237
|
}
|
|
195
238
|
function parseAuthenticationOptions(parameters, authenticationValue) {
|
|
196
239
|
switch (authenticationValue) {
|
|
@@ -284,6 +327,7 @@ var handledParameters = [
|
|
|
284
327
|
"password",
|
|
285
328
|
"poolTimeout",
|
|
286
329
|
"pwd",
|
|
330
|
+
"schema",
|
|
287
331
|
"socketTimeout",
|
|
288
332
|
"trustServerCertificate",
|
|
289
333
|
"uid",
|
|
@@ -684,17 +728,27 @@ var MssqlTransaction = class extends MssqlQueryable {
|
|
|
684
728
|
}
|
|
685
729
|
async commit() {
|
|
686
730
|
debug2(`[js::commit]`);
|
|
687
|
-
await this.
|
|
731
|
+
const release = await this.#mutex.acquire();
|
|
732
|
+
try {
|
|
733
|
+
await this.transaction.commit();
|
|
734
|
+
} finally {
|
|
735
|
+
release();
|
|
736
|
+
}
|
|
688
737
|
}
|
|
689
738
|
async rollback() {
|
|
690
739
|
debug2(`[js::rollback]`);
|
|
691
|
-
await this.
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
740
|
+
const release = await this.#mutex.acquire();
|
|
741
|
+
try {
|
|
742
|
+
await this.transaction.rollback().catch((e) => {
|
|
743
|
+
if (e.code === "EABORT") {
|
|
744
|
+
debug2(`[js::rollback] Transaction already aborted`);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
throw e;
|
|
748
|
+
});
|
|
749
|
+
} finally {
|
|
750
|
+
release();
|
|
751
|
+
}
|
|
698
752
|
}
|
|
699
753
|
};
|
|
700
754
|
var PrismaMssqlAdapter = class extends MssqlQueryable {
|
|
@@ -745,11 +799,11 @@ var PrismaMssqlAdapterFactory = class {
|
|
|
745
799
|
#options;
|
|
746
800
|
constructor(configOrString, options) {
|
|
747
801
|
if (typeof configOrString === "string") {
|
|
748
|
-
|
|
749
|
-
|
|
802
|
+
const { config, schema } = parseConnectionString(configOrString);
|
|
803
|
+
this.#config = config;
|
|
750
804
|
this.#options = {
|
|
751
805
|
...options,
|
|
752
|
-
schema: options?.schema ??
|
|
806
|
+
schema: options?.schema ?? schema
|
|
753
807
|
};
|
|
754
808
|
} else {
|
|
755
809
|
this.#config = configOrString;
|
package/dist/index.mjs
CHANGED
|
@@ -30,25 +30,66 @@ function mapIsolationLevelFromString(level) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
var debug = Debug("prisma:driver-adapter:mssql:connection-string");
|
|
33
|
-
function
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
function splitRespectingBraces(str) {
|
|
34
|
+
const parts = [];
|
|
35
|
+
let current = "";
|
|
36
|
+
let braceDepth = 0;
|
|
37
|
+
let valueStartIndex = -1;
|
|
38
|
+
for (let i = 0; i < str.length; i++) {
|
|
39
|
+
const char = str[i];
|
|
40
|
+
if (char === "=") {
|
|
41
|
+
current += char;
|
|
42
|
+
if (braceDepth === 0) {
|
|
43
|
+
valueStartIndex = i + 1;
|
|
44
|
+
}
|
|
45
|
+
} else if (char === "{") {
|
|
46
|
+
const isFirstCharOfValue = i === valueStartIndex;
|
|
47
|
+
if (isFirstCharOfValue) {
|
|
48
|
+
braceDepth++;
|
|
49
|
+
} else if (braceDepth > 0) {
|
|
50
|
+
throw new Error(`Malformed connection string: nested '{' braces are not supported`);
|
|
51
|
+
}
|
|
52
|
+
current += char;
|
|
53
|
+
} else if (char === "}") {
|
|
54
|
+
if (braceDepth > 0) {
|
|
55
|
+
braceDepth--;
|
|
56
|
+
}
|
|
57
|
+
current += char;
|
|
58
|
+
} else if (char === ";" && braceDepth === 0) {
|
|
59
|
+
parts.push(current);
|
|
60
|
+
current = "";
|
|
61
|
+
valueStartIndex = -1;
|
|
62
|
+
} else {
|
|
63
|
+
current += char;
|
|
40
64
|
}
|
|
41
65
|
}
|
|
42
|
-
|
|
66
|
+
if (current) {
|
|
67
|
+
parts.push(current);
|
|
68
|
+
}
|
|
69
|
+
if (braceDepth !== 0) {
|
|
70
|
+
throw new Error(`Malformed connection string: unclosed '{' brace (braceDepth=${braceDepth})`);
|
|
71
|
+
}
|
|
72
|
+
return parts;
|
|
73
|
+
}
|
|
74
|
+
function unescapeValue(value) {
|
|
75
|
+
const trimmed = value.trim();
|
|
76
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}") && trimmed.length >= 2) {
|
|
77
|
+
return trimmed.slice(1, -1);
|
|
78
|
+
}
|
|
79
|
+
return trimmed;
|
|
43
80
|
}
|
|
44
81
|
function parseConnectionString(connectionString) {
|
|
45
82
|
const withoutProtocol = connectionString.replace(/^sqlserver:\/\//, "");
|
|
46
|
-
const
|
|
83
|
+
const parts = splitRespectingBraces(withoutProtocol);
|
|
84
|
+
const [hostPart, ...paramParts] = parts;
|
|
47
85
|
const config = {
|
|
48
86
|
server: "",
|
|
49
87
|
options: {},
|
|
50
88
|
pool: {}
|
|
51
89
|
};
|
|
90
|
+
if (!hostPart || hostPart.trim() === "") {
|
|
91
|
+
throw new Error("Server host is required in connection string");
|
|
92
|
+
}
|
|
52
93
|
const [host, portStr] = hostPart.split(":");
|
|
53
94
|
config.server = host.trim();
|
|
54
95
|
if (portStr) {
|
|
@@ -60,13 +101,14 @@ function parseConnectionString(connectionString) {
|
|
|
60
101
|
}
|
|
61
102
|
const parameters = {};
|
|
62
103
|
for (const part of paramParts) {
|
|
63
|
-
const [key,
|
|
104
|
+
const [key, ...valueParts] = part.split("=");
|
|
64
105
|
if (!key) continue;
|
|
65
106
|
const trimmedKey = key.trim();
|
|
66
107
|
if (trimmedKey in parameters) {
|
|
67
108
|
throw new Error(`Duplication configuration parameter: ${trimmedKey}`);
|
|
68
109
|
}
|
|
69
|
-
|
|
110
|
+
const value = valueParts.join("=");
|
|
111
|
+
parameters[trimmedKey] = unescapeValue(value);
|
|
70
112
|
if (!handledParameters.includes(trimmedKey)) {
|
|
71
113
|
debug(`Unknown connection string parameter: ${trimmedKey}`);
|
|
72
114
|
}
|
|
@@ -157,7 +199,8 @@ function parseConnectionString(connectionString) {
|
|
|
157
199
|
if (!config.server || config.server.trim() === "") {
|
|
158
200
|
throw new Error("Server host is required in connection string");
|
|
159
201
|
}
|
|
160
|
-
|
|
202
|
+
const schema = firstKey(parameters, "schema") ?? void 0;
|
|
203
|
+
return { config, schema };
|
|
161
204
|
}
|
|
162
205
|
function parseAuthenticationOptions(parameters, authenticationValue) {
|
|
163
206
|
switch (authenticationValue) {
|
|
@@ -251,6 +294,7 @@ var handledParameters = [
|
|
|
251
294
|
"password",
|
|
252
295
|
"poolTimeout",
|
|
253
296
|
"pwd",
|
|
297
|
+
"schema",
|
|
254
298
|
"socketTimeout",
|
|
255
299
|
"trustServerCertificate",
|
|
256
300
|
"uid",
|
|
@@ -654,17 +698,27 @@ var MssqlTransaction = class extends MssqlQueryable {
|
|
|
654
698
|
}
|
|
655
699
|
async commit() {
|
|
656
700
|
debug2(`[js::commit]`);
|
|
657
|
-
await this.
|
|
701
|
+
const release = await this.#mutex.acquire();
|
|
702
|
+
try {
|
|
703
|
+
await this.transaction.commit();
|
|
704
|
+
} finally {
|
|
705
|
+
release();
|
|
706
|
+
}
|
|
658
707
|
}
|
|
659
708
|
async rollback() {
|
|
660
709
|
debug2(`[js::rollback]`);
|
|
661
|
-
await this.
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
710
|
+
const release = await this.#mutex.acquire();
|
|
711
|
+
try {
|
|
712
|
+
await this.transaction.rollback().catch((e) => {
|
|
713
|
+
if (e.code === "EABORT") {
|
|
714
|
+
debug2(`[js::rollback] Transaction already aborted`);
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
throw e;
|
|
718
|
+
});
|
|
719
|
+
} finally {
|
|
720
|
+
release();
|
|
721
|
+
}
|
|
668
722
|
}
|
|
669
723
|
};
|
|
670
724
|
var PrismaMssqlAdapter = class extends MssqlQueryable {
|
|
@@ -715,11 +769,11 @@ var PrismaMssqlAdapterFactory = class {
|
|
|
715
769
|
#options;
|
|
716
770
|
constructor(configOrString, options) {
|
|
717
771
|
if (typeof configOrString === "string") {
|
|
718
|
-
|
|
719
|
-
|
|
772
|
+
const { config, schema } = parseConnectionString(configOrString);
|
|
773
|
+
this.#config = config;
|
|
720
774
|
this.#options = {
|
|
721
775
|
...options,
|
|
722
|
-
schema: options?.schema ??
|
|
776
|
+
schema: options?.schema ?? schema
|
|
723
777
|
};
|
|
724
778
|
} else {
|
|
725
779
|
this.#config = configOrString;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-mssql",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.0-dev.1",
|
|
4
4
|
"description": "Prisma's driver adapter for \"mssql\"",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"mssql": "^12.2.0",
|
|
35
35
|
"async-mutex": "0.5.0",
|
|
36
|
-
"@prisma/driver-adapter-utils": "7.
|
|
36
|
+
"@prisma/driver-adapter-utils": "7.5.0-dev.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/mssql": "9.1.8"
|