@prisma/adapter-mssql 7.4.0-dev.22 → 7.4.0-dev.24

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 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 extractSchemaFromConnectionString(connectionString) {
67
- const withoutProtocol = connectionString.replace(/^sqlserver:\/\//, "");
68
- const parts = withoutProtocol.split(";");
69
- for (const part of parts) {
70
- const [key, value] = part.split("=", 2);
71
- if (key?.trim() === "schema") {
72
- return value?.trim();
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
- return void 0;
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 [hostPart, ...paramParts] = withoutProtocol.split(";");
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, value] = part.split("=", 2);
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
- parameters[trimmedKey] = value.trim();
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
- return config;
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",
@@ -755,11 +799,11 @@ var PrismaMssqlAdapterFactory = class {
755
799
  #options;
756
800
  constructor(configOrString, options) {
757
801
  if (typeof configOrString === "string") {
758
- this.#config = parseConnectionString(configOrString);
759
- const extractedSchema = extractSchemaFromConnectionString(configOrString);
802
+ const { config, schema } = parseConnectionString(configOrString);
803
+ this.#config = config;
760
804
  this.#options = {
761
805
  ...options,
762
- schema: options?.schema ?? extractedSchema
806
+ schema: options?.schema ?? schema
763
807
  };
764
808
  } else {
765
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 extractSchemaFromConnectionString(connectionString) {
34
- const withoutProtocol = connectionString.replace(/^sqlserver:\/\//, "");
35
- const parts = withoutProtocol.split(";");
36
- for (const part of parts) {
37
- const [key, value] = part.split("=", 2);
38
- if (key?.trim() === "schema") {
39
- return value?.trim();
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
- return void 0;
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 [hostPart, ...paramParts] = withoutProtocol.split(";");
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, value] = part.split("=", 2);
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
- parameters[trimmedKey] = value.trim();
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
- return config;
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",
@@ -725,11 +769,11 @@ var PrismaMssqlAdapterFactory = class {
725
769
  #options;
726
770
  constructor(configOrString, options) {
727
771
  if (typeof configOrString === "string") {
728
- this.#config = parseConnectionString(configOrString);
729
- const extractedSchema = extractSchemaFromConnectionString(configOrString);
772
+ const { config, schema } = parseConnectionString(configOrString);
773
+ this.#config = config;
730
774
  this.#options = {
731
775
  ...options,
732
- schema: options?.schema ?? extractedSchema
776
+ schema: options?.schema ?? schema
733
777
  };
734
778
  } else {
735
779
  this.#config = configOrString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/adapter-mssql",
3
- "version": "7.4.0-dev.22",
3
+ "version": "7.4.0-dev.24",
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.4.0-dev.22"
36
+ "@prisma/driver-adapter-utils": "7.4.0-dev.24"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/mssql": "9.1.8"