@effect/sql-mysql2 4.0.0-beta.7 → 4.0.0-beta.70

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.
@@ -1,44 +1,71 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL client implementation for Effect SQL, backed by the `mysql2` driver.
3
+ *
4
+ * This module exposes constructors and layers for providing both the MySQL-specific
5
+ * `MysqlClient` service and the generic `SqlClient` service. It is intended for server
6
+ * applications, background workers, migrations, and tests that need Effect SQL query
7
+ * compilation, scoped resource management, streaming queries, and consistent `SqlError`
8
+ * classification for MySQL driver failures.
9
+ *
10
+ * Each client owns a scoped mysql2 pool, validates connectivity with `SELECT 1` during
11
+ * acquisition, and closes the pool when the surrounding scope is released. You can configure
12
+ * the pool from a connection URI or discrete connection fields; when `url` is supplied it
13
+ * takes precedence over the host, port, database, username, and password fields. Regular
14
+ * queries run through the shared pool, while transactions acquire a dedicated pooled
15
+ * connection for their lifetime, so long-running transactions and streams can occupy pool
16
+ * capacity. Size `maxConnections`, `connectionTTL`, and any mysql2 `poolConfig` with that in
17
+ * mind.
18
+ *
19
+ * @since 4.0.0
3
20
  */
4
21
  import * as Config from "effect/Config";
22
+ import * as Context from "effect/Context";
5
23
  import * as Duration from "effect/Duration";
6
24
  import * as Effect from "effect/Effect";
7
25
  import * as Layer from "effect/Layer";
8
26
  import * as Redacted from "effect/Redacted";
9
27
  import type { Scope } from "effect/Scope";
10
- import * as ServiceMap from "effect/ServiceMap";
11
28
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
12
29
  import * as Client from "effect/unstable/sql/SqlClient";
13
30
  import { SqlError } from "effect/unstable/sql/SqlError";
14
31
  import * as Statement from "effect/unstable/sql/Statement";
15
32
  import * as Mysql from "mysql2";
16
33
  /**
17
- * @category type ids
18
- * @since 1.0.0
34
+ * Runtime type identifier used to mark `MysqlClient` values.
35
+ *
36
+ * @category type IDs
37
+ * @since 4.0.0
19
38
  */
20
39
  export declare const TypeId: TypeId;
21
40
  /**
22
- * @category type ids
23
- * @since 1.0.0
41
+ * Type-level identifier used to mark `MysqlClient` values.
42
+ *
43
+ * @category type IDs
44
+ * @since 4.0.0
24
45
  */
25
46
  export type TypeId = "~@effect/sql-mysql2/MysqlClient";
26
47
  /**
48
+ * mysql2-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
49
+ *
27
50
  * @category models
28
- * @since 1.0.0
51
+ * @since 4.0.0
29
52
  */
30
53
  export interface MysqlClient extends Client.SqlClient {
31
54
  readonly [TypeId]: TypeId;
32
55
  readonly config: MysqlClientConfig;
33
56
  }
34
57
  /**
58
+ * Context tag used to access the `MysqlClient` service.
59
+ *
35
60
  * @category tags
36
- * @since 1.0.0
61
+ * @since 4.0.0
37
62
  */
38
- export declare const MysqlClient: ServiceMap.Service<MysqlClient, MysqlClient>;
63
+ export declare const MysqlClient: Context.Service<MysqlClient, MysqlClient>;
39
64
  /**
65
+ * Configuration for a mysql2 client, including connection URI or connection fields, pool options, span attributes, and query/result name transforms.
66
+ *
40
67
  * @category models
41
- * @since 1.0.0
68
+ * @since 4.0.0
42
69
  */
43
70
  export interface MysqlClientConfig {
44
71
  /**
@@ -58,23 +85,31 @@ export interface MysqlClientConfig {
58
85
  readonly transformQueryNames?: ((str: string) => string) | undefined;
59
86
  }
60
87
  /**
88
+ * Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
89
+ *
61
90
  * @category constructors
62
- * @since 1.0.0
91
+ * @since 4.0.0
63
92
  */
64
93
  export declare const make: (options: MysqlClientConfig) => Effect.Effect<MysqlClient, SqlError, Scope | Reactivity.Reactivity>;
65
94
  /**
95
+ * Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
96
+ *
66
97
  * @category layers
67
- * @since 1.0.0
98
+ * @since 4.0.0
68
99
  */
69
100
  export declare const layerConfig: (config: Config.Wrap<MysqlClientConfig>) => Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError>;
70
101
  /**
102
+ * Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
103
+ *
71
104
  * @category layers
72
- * @since 1.0.0
105
+ * @since 4.0.0
73
106
  */
74
107
  export declare const layer: (config: MysqlClientConfig) => Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError>;
75
108
  /**
109
+ * Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
110
+ *
76
111
  * @category compiler
77
- * @since 1.0.0
112
+ * @since 4.0.0
78
113
  */
79
114
  export declare const makeCompiler: (transform?: (_: string) => string) => Statement.Compiler;
80
115
  //# sourceMappingURL=MysqlClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlClient.d.ts","sourceRoot":"","sources":["../src/MysqlClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAEvD,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAC1D,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAA;AAO/B;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAA0C,CAAA;AAE/D;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,iCAAiC,CAAA;AAEtD;;;GAGG;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;IACrE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GACf,SAAS,iBAAiB,KACzB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,EAAE,KAAK,GAAG,UAAU,CAAC,UAAU,CAkMjE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,KACrC,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAUnC,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,QAAQ,iBAAiB,KACxB,KAAK,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAMnC,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,YAAY,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,uBAiB1D,CAAA"}
@@ -1,16 +1,33 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL client implementation for Effect SQL, backed by the `mysql2` driver.
3
+ *
4
+ * This module exposes constructors and layers for providing both the MySQL-specific
5
+ * `MysqlClient` service and the generic `SqlClient` service. It is intended for server
6
+ * applications, background workers, migrations, and tests that need Effect SQL query
7
+ * compilation, scoped resource management, streaming queries, and consistent `SqlError`
8
+ * classification for MySQL driver failures.
9
+ *
10
+ * Each client owns a scoped mysql2 pool, validates connectivity with `SELECT 1` during
11
+ * acquisition, and closes the pool when the surrounding scope is released. You can configure
12
+ * the pool from a connection URI or discrete connection fields; when `url` is supplied it
13
+ * takes precedence over the host, port, database, username, and password fields. Regular
14
+ * queries run through the shared pool, while transactions acquire a dedicated pooled
15
+ * connection for their lifetime, so long-running transactions and streams can occupy pool
16
+ * capacity. Size `maxConnections`, `connectionTTL`, and any mysql2 `poolConfig` with that in
17
+ * mind.
18
+ *
19
+ * @since 4.0.0
3
20
  */
4
21
  import * as Config from "effect/Config";
22
+ import * as Context from "effect/Context";
5
23
  import * as Duration from "effect/Duration";
6
24
  import * as Effect from "effect/Effect";
7
25
  import * as Layer from "effect/Layer";
8
26
  import * as Redacted from "effect/Redacted";
9
- import * as ServiceMap from "effect/ServiceMap";
10
27
  import * as Stream from "effect/Stream";
11
28
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
12
29
  import * as Client from "effect/unstable/sql/SqlClient";
13
- import { SqlError } from "effect/unstable/sql/SqlError";
30
+ import { AuthenticationError, AuthorizationError, ConnectionError, ConstraintError, DeadlockError, LockTimeoutError, SqlError, SqlSyntaxError, StatementTimeoutError, UniqueViolation, UnknownError } from "effect/unstable/sql/SqlError";
14
31
  import { asyncPauseResume } from "effect/unstable/sql/SqlStream";
15
32
  import * as Statement from "effect/unstable/sql/Statement";
16
33
  import * as Mysql from "mysql2";
@@ -18,19 +35,109 @@ const ATTR_DB_SYSTEM_NAME = "db.system.name";
18
35
  const ATTR_DB_NAMESPACE = "db.namespace";
19
36
  const ATTR_SERVER_ADDRESS = "server.address";
20
37
  const ATTR_SERVER_PORT = "server.port";
38
+ const mysqlErrnoFromCause = cause => {
39
+ if (typeof cause !== "object" || cause === null || !("errno" in cause)) {
40
+ return undefined;
41
+ }
42
+ const errno = cause.errno;
43
+ return typeof errno === "number" ? errno : undefined;
44
+ };
45
+ const mysqlConnectionErrorCodes = /*#__PURE__*/new Set([1040, 1042, 1043, 1129, 1130, 1203]);
46
+ const mysqlAuthorizationErrorCodes = /*#__PURE__*/new Set([1044, 1142, 1143, 1227]);
47
+ const mysqlSyntaxErrorCodes = /*#__PURE__*/new Set([1054, 1064, 1146]);
48
+ const mysqlConstraintErrorCodes = /*#__PURE__*/new Set([1022, 1048, 1169, 1216, 1217, 1451, 1452, 1557]);
49
+ const UNKNOWN_CONSTRAINT = "unknown";
50
+ const normalizeConstraintIdentifier = identifier => {
51
+ if (typeof identifier !== "string") {
52
+ return UNKNOWN_CONSTRAINT;
53
+ }
54
+ const trimmed = identifier.trim();
55
+ return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed;
56
+ };
57
+ const mysqlCauseProperty = (cause, property) => {
58
+ if (typeof cause !== "object" || cause === null || !(property in cause)) {
59
+ return undefined;
60
+ }
61
+ return cause[property];
62
+ };
63
+ const mysqlDuplicateEntryConstraintFromMessage = message => {
64
+ if (typeof message !== "string") {
65
+ return UNKNOWN_CONSTRAINT;
66
+ }
67
+ const match = /\bfor key\s+(?:'([^']*)'|\x60([^\x60]*)\x60|([^\s'\x60]+))/i.exec(message);
68
+ return match === null ? UNKNOWN_CONSTRAINT : normalizeConstraintIdentifier(match[1] ?? match[2] ?? match[3]);
69
+ };
70
+ const mysqlDuplicateEntryConstraintFromCause = cause => {
71
+ const constraint = normalizeConstraintIdentifier(mysqlCauseProperty(cause, "constraint"));
72
+ if (constraint !== UNKNOWN_CONSTRAINT) {
73
+ return constraint;
74
+ }
75
+ const sqlMessageConstraint = mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "sqlMessage"));
76
+ if (sqlMessageConstraint !== UNKNOWN_CONSTRAINT) {
77
+ return sqlMessageConstraint;
78
+ }
79
+ return mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "message"));
80
+ };
81
+ const classifyError = (cause, message, operation) => {
82
+ const props = {
83
+ cause,
84
+ message,
85
+ operation
86
+ };
87
+ const errno = mysqlErrnoFromCause(cause);
88
+ if (errno !== undefined) {
89
+ if (mysqlConnectionErrorCodes.has(errno)) {
90
+ return new ConnectionError(props);
91
+ }
92
+ if (errno === 1045) {
93
+ return new AuthenticationError(props);
94
+ }
95
+ if (mysqlAuthorizationErrorCodes.has(errno)) {
96
+ return new AuthorizationError(props);
97
+ }
98
+ if (mysqlSyntaxErrorCodes.has(errno)) {
99
+ return new SqlSyntaxError(props);
100
+ }
101
+ if (errno === 1062) {
102
+ return new UniqueViolation({
103
+ ...props,
104
+ constraint: mysqlDuplicateEntryConstraintFromCause(cause)
105
+ });
106
+ }
107
+ if (mysqlConstraintErrorCodes.has(errno)) {
108
+ return new ConstraintError(props);
109
+ }
110
+ if (errno === 1213) {
111
+ return new DeadlockError(props);
112
+ }
113
+ if (errno === 1205) {
114
+ return new LockTimeoutError(props);
115
+ }
116
+ if (errno === 3024) {
117
+ return new StatementTimeoutError(props);
118
+ }
119
+ }
120
+ return new UnknownError(props);
121
+ };
21
122
  /**
22
- * @category type ids
23
- * @since 1.0.0
123
+ * Runtime type identifier used to mark `MysqlClient` values.
124
+ *
125
+ * @category type IDs
126
+ * @since 4.0.0
24
127
  */
25
128
  export const TypeId = "~@effect/sql-mysql2/MysqlClient";
26
129
  /**
130
+ * Context tag used to access the `MysqlClient` service.
131
+ *
27
132
  * @category tags
28
- * @since 1.0.0
133
+ * @since 4.0.0
29
134
  */
30
- export const MysqlClient = /*#__PURE__*/ServiceMap.Service("@effect/sql-mysql2/MysqlClient");
135
+ export const MysqlClient = /*#__PURE__*/Context.Service("@effect/sql-mysql2/MysqlClient");
31
136
  /**
137
+ * Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
138
+ *
32
139
  * @category constructors
33
- * @since 1.0.0
140
+ * @since 4.0.0
34
141
  */
35
142
  export const make = options => Effect.gen(function* () {
36
143
  const compiler = makeCompiler(options.transformQueryNames);
@@ -42,7 +149,7 @@ export const make = options => Effect.gen(function* () {
42
149
  }
43
150
  runRaw(sql, values, rowsAsArray = false, method = "execute") {
44
151
  return Effect.callback(resume => {
45
- ;
152
+ const operation = method === "query" ? "executeUnprepared" : "execute";
46
153
  this.conn[method]({
47
154
  sql,
48
155
  values,
@@ -50,8 +157,7 @@ export const make = options => Effect.gen(function* () {
50
157
  }, (cause, results, _fields) => {
51
158
  if (cause) {
52
159
  resume(Effect.fail(new SqlError({
53
- cause,
54
- message: "Failed to execute statement"
160
+ reason: classifyError(cause, "Failed to execute statement", operation)
55
161
  })));
56
162
  } else {
57
163
  resume(Effect.succeed(results));
@@ -102,8 +208,7 @@ export const make = options => Effect.gen(function* () {
102
208
  pool.query("SELECT 1", cause => {
103
209
  if (cause) {
104
210
  resume(Effect.fail(new SqlError({
105
- cause,
106
- message: "MysqlClient: Failed to connect"
211
+ reason: classifyError(cause, "MysqlClient: Failed to connect", "connect")
107
212
  })));
108
213
  } else {
109
214
  resume(Effect.void);
@@ -113,9 +218,12 @@ export const make = options => Effect.gen(function* () {
113
218
  pool.end(() => resume(Effect.void));
114
219
  })).pipe(Effect.timeoutOrElse({
115
220
  duration: Duration.seconds(5),
116
- onTimeout: () => Effect.fail(new SqlError({
117
- message: "MysqlClient: Connection timeout",
118
- cause: new Error("connection timeout")
221
+ orElse: () => Effect.fail(new SqlError({
222
+ reason: new ConnectionError({
223
+ message: "MysqlClient: Connection timeout",
224
+ cause: new Error("connection timeout"),
225
+ operation: "connect"
226
+ })
119
227
  }))
120
228
  }));
121
229
  const poolConnection = new ConnectionImpl(pool);
@@ -123,8 +231,7 @@ export const make = options => Effect.gen(function* () {
123
231
  pool.getConnection((cause, conn) => {
124
232
  if (cause) {
125
233
  resume(Effect.fail(new SqlError({
126
- cause,
127
- message: "Failed to acquire connection"
234
+ reason: classifyError(cause, "Failed to acquire connection", "acquireConnection")
128
235
  })));
129
236
  } else {
130
237
  resume(Effect.succeed(conn));
@@ -148,18 +255,24 @@ export const make = options => Effect.gen(function* () {
148
255
  });
149
256
  });
150
257
  /**
258
+ * Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
259
+ *
151
260
  * @category layers
152
- * @since 1.0.0
261
+ * @since 4.0.0
153
262
  */
154
- export const layerConfig = config => Layer.effectServices(Config.unwrap(config).asEffect().pipe(Effect.flatMap(make), Effect.map(client => ServiceMap.make(MysqlClient, client).pipe(ServiceMap.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
263
+ export const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(MysqlClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
155
264
  /**
265
+ * Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
266
+ *
156
267
  * @category layers
157
- * @since 1.0.0
268
+ * @since 4.0.0
158
269
  */
159
- export const layer = config => Layer.effectServices(Effect.map(make(config), client => ServiceMap.make(MysqlClient, client).pipe(ServiceMap.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
270
+ export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(MysqlClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
160
271
  /**
272
+ * Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
273
+ *
161
274
  * @category compiler
162
- * @since 1.0.0
275
+ * @since 4.0.0
163
276
  */
164
277
  export const makeCompiler = transform => Statement.makeCompiler({
165
278
  dialect: "mysql",
@@ -184,8 +297,7 @@ function queryStream(conn, sql, params) {
184
297
  let buffer = [];
185
298
  let taskPending = false;
186
299
  query.on("error", cause => emit.fail(new SqlError({
187
- cause,
188
- message: "Failed to stream statement"
300
+ reason: classifyError(cause, "Failed to stream statement", "stream")
189
301
  })));
190
302
  query.on("data", row => {
191
303
  buffer.push(row);
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlClient.js","names":["Config","Duration","Effect","Layer","Redacted","ServiceMap","Stream","Reactivity","Client","SqlError","asyncPauseResume","Statement","Mysql","ATTR_DB_SYSTEM_NAME","ATTR_DB_NAMESPACE","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","TypeId","MysqlClient","Service","make","options","gen","compiler","makeCompiler","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","ConnectionImpl","conn","constructor","runRaw","sql","values","rowsAsArray","method","callback","resume","cause","results","_fields","fail","message","succeed","run","pipe","map","Array","isArray","execute","params","executeRaw","executeValues","executeUnprepared","executeStream","stream","queryStream","mapArray","_","pool","url","createPool","uri","value","multipleStatements","supportBigNumbers","connectionLimit","maxConnections","idleTimeout","connectionTTL","toMillis","fromInputUnsafe","poolConfig","host","port","database","user","username","password","acquireRelease","query","void","end","timeoutOrElse","duration","seconds","onTimeout","Error","poolConnection","acquireConn","getConnection","sync","release","transactionAcquirer","spanAttributes","Object","entries","push","assign","acquirer","config","layerConfig","effectServices","unwrap","asEffect","flatMap","client","add","SqlClient","provide","layer","transform","dialect","placeholder","onIdentifier","withoutTransform","escape","onCustom","onRecordUpdate","defaultEscape","fnUntraced","emit","addFinalizer","destroy","buffer","taskPending","on","row","queueMicrotask","items","length","onPause","pause","onResume"],"sources":["../src/MysqlClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAE3C,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SAASC,QAAQ,QAAQ,8BAA8B;AACvD,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,OAAO,KAAKC,SAAS,MAAM,+BAA+B;AAC1D,OAAO,KAAKC,KAAK,MAAM,QAAQ;AAE/B,MAAMC,mBAAmB,GAAG,gBAAgB;AAC5C,MAAMC,iBAAiB,GAAG,cAAc;AACxC,MAAMC,mBAAmB,GAAG,gBAAgB;AAC5C,MAAMC,gBAAgB,GAAG,aAAa;AAEtC;;;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rD,KAAK,CAAC3C,MAAM,EAAE;MAChB;KACD;EACH,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"MysqlClient.js","names":["Config","Context","Duration","Effect","Layer","Redacted","Stream","Reactivity","Client","AuthenticationError","AuthorizationError","ConnectionError","ConstraintError","DeadlockError","LockTimeoutError","SqlError","SqlSyntaxError","StatementTimeoutError","UniqueViolation","UnknownError","asyncPauseResume","Statement","Mysql","ATTR_DB_SYSTEM_NAME","ATTR_DB_NAMESPACE","ATTR_SERVER_ADDRESS","ATTR_SERVER_PORT","mysqlErrnoFromCause","cause","undefined","errno","mysqlConnectionErrorCodes","Set","mysqlAuthorizationErrorCodes","mysqlSyntaxErrorCodes","mysqlConstraintErrorCodes","UNKNOWN_CONSTRAINT","normalizeConstraintIdentifier","identifier","trimmed","trim","length","mysqlCauseProperty","property","mysqlDuplicateEntryConstraintFromMessage","message","match","exec","mysqlDuplicateEntryConstraintFromCause","constraint","sqlMessageConstraint","classifyError","operation","props","has","TypeId","MysqlClient","Service","make","options","gen","compiler","makeCompiler","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","ConnectionImpl","conn","constructor","runRaw","sql","values","rowsAsArray","method","callback","resume","results","_fields","fail","reason","succeed","run","pipe","map","Array","isArray","execute","params","executeRaw","executeValues","executeUnprepared","executeStream","stream","queryStream","mapArray","_","pool","url","createPool","uri","value","multipleStatements","supportBigNumbers","connectionLimit","maxConnections","idleTimeout","connectionTTL","toMillis","fromInputUnsafe","poolConfig","host","port","database","user","username","password","acquireRelease","query","void","end","timeoutOrElse","duration","seconds","orElse","Error","poolConnection","acquireConn","getConnection","sync","release","transactionAcquirer","spanAttributes","Object","entries","push","assign","acquirer","config","layerConfig","effectContext","unwrap","flatMap","client","add","SqlClient","provide","layer","transform","dialect","placeholder","onIdentifier","withoutTransform","escape","onCustom","onRecordUpdate","defaultEscape","fnUntraced","emit","addFinalizer","destroy","buffer","taskPending","on","row","queueMicrotask","items","onPause","pause","onRes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NxI,KAAc,IACbmI,IAAI,CAAC/E,IAAI,CAAC,IAAIjE,QAAQ,CAAC;MAAEkE,MAAM,EAAE9B,aAAa,CAACvB,KAAK,EAAE,4BAA4B,EAAE,QAAQ;IAAC,CAAE,CAAC,CAAC,CACpG;IACD2F,KAAK,CAAC6C,EAAE,CAAC,MAAM,EAAGC,GAAQ,IAAI;MAC5BH,MAAM,CAAC1B,IAAI,CAAC6B,GAAG,CAAC;MAChB,IAAI,CAACF,WAAW,EAAE;QAChBA,WAAW,GAAG,IAAI;QAClBG,cAAc,CAAC,MAAK;UAClB,MAAMC,KAAK,GAAGL,MAAM;UACpBA,MAAM,GAAG,EAAE;UACXH,IAAI,CAAC5F,KAAK,CAACoG,KAAK,CAAC;UACjBJ,WAAW,GAAG,KAAK;QACrB,CAAC,CAAC;MACJ;IACF,CAAC,CAAC;IACF5C,KAAK,CAAC6C,EAAE,CAAC,KAAK,EAAE,MAAK;MACnB,IAAIF,MAAM,CAACzH,MAAM,GAAG,CAAC,EAAE;QACrBsH,IAAI,CAAC5F,KAAK,CAAC+F,MAAM,CAAC;QAClBA,MAAM,GAAG,EAAE;MACb;MACAH,IAAI,CAACtC,GAAG,EAAE;IACZ,CAAC,CAAC;IAEF,OAAO;MACL+C,OAAOA,CAAA;QACLjD,KAAK,CAACkD,KAAK,EAAE;MACf,CAAC;MACDC,QAAQA,CAAA;QACNnD,KAAK,CAAC1C,MAAM,EAAE;MAChB;KACD;EACH,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Utilities for applying Effect SQL migrations to MySQL databases through the
3
+ * mysql2-backed `SqlClient`.
4
+ *
5
+ * This module re-exports the shared `Migrator` loaders and error types, then
6
+ * provides `run` and `layer` helpers for applying ordered migrations using the
7
+ * currently configured MySQL `SqlClient`. It is commonly used during application
8
+ * startup, in integration tests that provision a temporary schema, or in layer
9
+ * graphs where dependent services should not start until the database schema is
10
+ * current.
11
+ *
12
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
13
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
14
+ * than the latest recorded id are run. MySQL DDL can cause implicit commits, and
15
+ * this adapter relies on migration table constraints to detect concurrent
16
+ * runners, so coordinate startup runners and write migrations to tolerate
17
+ * MySQL's transactional semantics. Schema dump support is not enabled in this
18
+ * adapter, so `schemaDirectory` does not emit a MySQL dump.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import type * as Effect from "effect/Effect";
5
23
  import * as Layer from "effect/Layer";
@@ -7,17 +25,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
7
25
  import type * as Client from "effect/unstable/sql/SqlClient";
8
26
  import type { SqlError } from "effect/unstable/sql/SqlError";
9
27
  /**
10
- * @since 1.0.0
28
+ * @since 4.0.0
11
29
  */
12
30
  export * from "effect/unstable/sql/Migrator";
13
31
  /**
14
- * @category constructor
15
- * @since 1.0.0
32
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
33
+ *
34
+ * @category constructors
35
+ * @since 4.0.0
16
36
  */
17
37
  export declare const run: <R2 = never>({ loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
18
38
  /**
39
+ * Creates a layer that runs the configured SQL migrations during layer construction.
40
+ *
19
41
  * @category layers
20
- * @since 1.0.0
42
+ * @since 4.0.0
21
43
  */
22
44
  export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
23
45
  //# sourceMappingURL=MysqlMigrator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlMigrator.d.ts","sourceRoot":"","sources":["../src/MysqlMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,M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GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAC7D,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,EAAE,CAsDrB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CACZ,KAAK,EACL,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACgB,CAAA"}
@@ -1,12 +1,14 @@
1
1
  import * as Layer from "effect/Layer";
2
2
  import * as Migrator from "effect/unstable/sql/Migrator";
3
3
  /**
4
- * @since 1.0.0
4
+ * @since 4.0.0
5
5
  */
6
6
  export * from "effect/unstable/sql/Migrator";
7
7
  /**
8
- * @category constructor
9
- * @since 1.0.0
8
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
9
+ *
10
+ * @category constructors
11
+ * @since 4.0.0
10
12
  */
11
13
  export const run = /*#__PURE__*/Migrator.make({
12
14
  // TODO: re-add when Command module is available
@@ -63,8 +65,10 @@ export const run = /*#__PURE__*/Migrator.make({
63
65
  // }
64
66
  });
65
67
  /**
68
+ * Creates a layer that runs the configured SQL migrations during layer construction.
69
+ *
66
70
  * @category layers
67
- * @since 1.0.0
71
+ * @since 4.0.0
68
72
  */
69
73
  export const layer = options => Layer.effectDiscard(run(options));
70
74
  //# sourceMappingURL=MysqlMigrator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MysqlMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/MysqlMigrator.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;AAIA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AAAA,CACD,CAAC;AAEF;;;;AAIA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"MysqlMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/MysqlMigrator.ts"],"sourcesContent":[null],"mappings":"AAsBA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;;;AAMA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC;EAChB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AAAA,CACD,CAAC;AAEF;;;;;;AAMA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,47 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  /**
5
- * @since 1.0.0
5
+ * MySQL client implementation for Effect SQL, backed by the `mysql2` driver.
6
+ *
7
+ * This module exposes constructors and layers for providing both the MySQL-specific
8
+ * `MysqlClient` service and the generic `SqlClient` service. It is intended for server
9
+ * applications, background workers, migrations, and tests that need Effect SQL query
10
+ * compilation, scoped resource management, streaming queries, and consistent `SqlError`
11
+ * classification for MySQL driver failures.
12
+ *
13
+ * Each client owns a scoped mysql2 pool, validates connectivity with `SELECT 1` during
14
+ * acquisition, and closes the pool when the surrounding scope is released. You can configure
15
+ * the pool from a connection URI or discrete connection fields; when `url` is supplied it
16
+ * takes precedence over the host, port, database, username, and password fields. Regular
17
+ * queries run through the shared pool, while transactions acquire a dedicated pooled
18
+ * connection for their lifetime, so long-running transactions and streams can occupy pool
19
+ * capacity. Size `maxConnections`, `connectionTTL`, and any mysql2 `poolConfig` with that in
20
+ * mind.
21
+ *
22
+ * @since 4.0.0
6
23
  */
7
24
  export * as MysqlClient from "./MysqlClient.ts";
8
25
  /**
9
- * @since 1.0.0
26
+ * Utilities for applying Effect SQL migrations to MySQL databases through the
27
+ * mysql2-backed `SqlClient`.
28
+ *
29
+ * This module re-exports the shared `Migrator` loaders and error types, then
30
+ * provides `run` and `layer` helpers for applying ordered migrations using the
31
+ * currently configured MySQL `SqlClient`. It is commonly used during application
32
+ * startup, in integration tests that provision a temporary schema, or in layer
33
+ * graphs where dependent services should not start until the database schema is
34
+ * current.
35
+ *
36
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
37
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
38
+ * than the latest recorded id are run. MySQL DDL can cause implicit commits, and
39
+ * this adapter relies on migration table constraints to detect concurrent
40
+ * runners, so coordinate startup runners and write migrations to tolerate
41
+ * MySQL's transactional semantics. Schema dump support is not enabled in this
42
+ * adapter, so `schemaDirectory` does not emit a MySQL dump.
43
+ *
44
+ * @since 4.0.0
10
45
  */
11
46
  export * as MysqlMigrator from "./MysqlMigrator.ts";
12
47
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA"}
package/dist/index.js CHANGED
@@ -1,13 +1,48 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  // @barrel: Auto-generated exports. Do not edit manually.
5
5
  /**
6
- * @since 1.0.0
6
+ * MySQL client implementation for Effect SQL, backed by the `mysql2` driver.
7
+ *
8
+ * This module exposes constructors and layers for providing both the MySQL-specific
9
+ * `MysqlClient` service and the generic `SqlClient` service. It is intended for server
10
+ * applications, background workers, migrations, and tests that need Effect SQL query
11
+ * compilation, scoped resource management, streaming queries, and consistent `SqlError`
12
+ * classification for MySQL driver failures.
13
+ *
14
+ * Each client owns a scoped mysql2 pool, validates connectivity with `SELECT 1` during
15
+ * acquisition, and closes the pool when the surrounding scope is released. You can configure
16
+ * the pool from a connection URI or discrete connection fields; when `url` is supplied it
17
+ * takes precedence over the host, port, database, username, and password fields. Regular
18
+ * queries run through the shared pool, while transactions acquire a dedicated pooled
19
+ * connection for their lifetime, so long-running transactions and streams can occupy pool
20
+ * capacity. Size `maxConnections`, `connectionTTL`, and any mysql2 `poolConfig` with that in
21
+ * mind.
22
+ *
23
+ * @since 4.0.0
7
24
  */
8
25
  export * as MysqlClient from "./MysqlClient.js";
9
26
  /**
10
- * @since 1.0.0
27
+ * Utilities for applying Effect SQL migrations to MySQL databases through the
28
+ * mysql2-backed `SqlClient`.
29
+ *
30
+ * This module re-exports the shared `Migrator` loaders and error types, then
31
+ * provides `run` and `layer` helpers for applying ordered migrations using the
32
+ * currently configured MySQL `SqlClient`. It is commonly used during application
33
+ * startup, in integration tests that provision a temporary schema, or in layer
34
+ * graphs where dependent services should not start until the database schema is
35
+ * current.
36
+ *
37
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
38
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
39
+ * than the latest recorded id are run. MySQL DDL can cause implicit commits, and
40
+ * this adapter relies on migration table constraints to detect concurrent
41
+ * runners, so coordinate startup runners and write migrations to tolerate
42
+ * MySQL's transactional semantics. Schema dump support is not enabled in this
43
+ * adapter, so `schemaDirectory` does not emit a MySQL dump.
44
+ *
45
+ * @since 4.0.0
11
46
  */
12
47
  export * as MysqlMigrator from "./MysqlMigrator.js";
13
48
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["MysqlClient","MysqlMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;AAGA,OAAO,KAAKA,WAAW,MAAM,kBAAkB;AAE/C;;;AAGA,OAAO,KAAKC,aAAa,MAAM,oBAAoB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["MysqlClient","MysqlMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;;;;;;;;;;;;;;;;;;AAoBA,OAAO,KAAKA,WAAW,MAAM,kBAAkB;AAE/C;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,KAAKC,aAAa,MAAM,oBAAoB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/sql-mysql2",
3
- "version": "4.0.0-beta.7",
3
+ "version": "4.0.0-beta.70",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A MySQL toolkit for Effect",
@@ -43,14 +43,14 @@
43
43
  "provenance": true
44
44
  },
45
45
  "devDependencies": {
46
- "@testcontainers/mysql": "^11.11.0",
47
- "effect": "^4.0.0-beta.7"
46
+ "@testcontainers/mysql": "^11.14.0",
47
+ "effect": "^4.0.0-beta.70"
48
48
  },
49
49
  "peerDependencies": {
50
- "effect": "^4.0.0-beta.7"
50
+ "effect": "^4.0.0-beta.70"
51
51
  },
52
52
  "dependencies": {
53
- "mysql2": "^3.16.2"
53
+ "mysql2": "^3.22.3"
54
54
  },
55
55
  "scripts": {
56
56
  "codegen": "effect-utils codegen",
@@ -1,18 +1,47 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * MySQL client implementation for Effect SQL, backed by the `mysql2` driver.
3
+ *
4
+ * This module exposes constructors and layers for providing both the MySQL-specific
5
+ * `MysqlClient` service and the generic `SqlClient` service. It is intended for server
6
+ * applications, background workers, migrations, and tests that need Effect SQL query
7
+ * compilation, scoped resource management, streaming queries, and consistent `SqlError`
8
+ * classification for MySQL driver failures.
9
+ *
10
+ * Each client owns a scoped mysql2 pool, validates connectivity with `SELECT 1` during
11
+ * acquisition, and closes the pool when the surrounding scope is released. You can configure
12
+ * the pool from a connection URI or discrete connection fields; when `url` is supplied it
13
+ * takes precedence over the host, port, database, username, and password fields. Regular
14
+ * queries run through the shared pool, while transactions acquire a dedicated pooled
15
+ * connection for their lifetime, so long-running transactions and streams can occupy pool
16
+ * capacity. Size `maxConnections`, `connectionTTL`, and any mysql2 `poolConfig` with that in
17
+ * mind.
18
+ *
19
+ * @since 4.0.0
3
20
  */
4
21
  import * as Config from "effect/Config"
22
+ import * as Context from "effect/Context"
5
23
  import * as Duration from "effect/Duration"
6
24
  import * as Effect from "effect/Effect"
7
25
  import * as Layer from "effect/Layer"
8
26
  import * as Redacted from "effect/Redacted"
9
27
  import type { Scope } from "effect/Scope"
10
- import * as ServiceMap from "effect/ServiceMap"
11
28
  import * as Stream from "effect/Stream"
12
29
  import * as Reactivity from "effect/unstable/reactivity/Reactivity"
13
30
  import * as Client from "effect/unstable/sql/SqlClient"
14
31
  import type { Connection } from "effect/unstable/sql/SqlConnection"
15
- import { SqlError } from "effect/unstable/sql/SqlError"
32
+ import {
33
+ AuthenticationError,
34
+ AuthorizationError,
35
+ ConnectionError,
36
+ ConstraintError,
37
+ DeadlockError,
38
+ LockTimeoutError,
39
+ SqlError,
40
+ SqlSyntaxError,
41
+ StatementTimeoutError,
42
+ UniqueViolation,
43
+ UnknownError
44
+ } from "effect/unstable/sql/SqlError"
16
45
  import { asyncPauseResume } from "effect/unstable/sql/SqlStream"
17
46
  import * as Statement from "effect/unstable/sql/Statement"
18
47
  import * as Mysql from "mysql2"
@@ -22,21 +51,118 @@ const ATTR_DB_NAMESPACE = "db.namespace"
22
51
  const ATTR_SERVER_ADDRESS = "server.address"
23
52
  const ATTR_SERVER_PORT = "server.port"
24
53
 
54
+ const mysqlErrnoFromCause = (cause: unknown): number | undefined => {
55
+ if (typeof cause !== "object" || cause === null || !("errno" in cause)) {
56
+ return undefined
57
+ }
58
+ const errno = cause.errno
59
+ return typeof errno === "number" ? errno : undefined
60
+ }
61
+
62
+ const mysqlConnectionErrorCodes = new Set([1040, 1042, 1043, 1129, 1130, 1203])
63
+ const mysqlAuthorizationErrorCodes = new Set([1044, 1142, 1143, 1227])
64
+ const mysqlSyntaxErrorCodes = new Set([1054, 1064, 1146])
65
+ const mysqlConstraintErrorCodes = new Set([1022, 1048, 1169, 1216, 1217, 1451, 1452, 1557])
66
+
67
+ const UNKNOWN_CONSTRAINT = "unknown"
68
+
69
+ const normalizeConstraintIdentifier = (identifier: unknown): string => {
70
+ if (typeof identifier !== "string") {
71
+ return UNKNOWN_CONSTRAINT
72
+ }
73
+ const trimmed = identifier.trim()
74
+ return trimmed.length === 0 ? UNKNOWN_CONSTRAINT : trimmed
75
+ }
76
+
77
+ const mysqlCauseProperty = (cause: unknown, property: "constraint" | "message" | "sqlMessage"): unknown => {
78
+ if (typeof cause !== "object" || cause === null || !(property in cause)) {
79
+ return undefined
80
+ }
81
+ return (cause as Record<string, unknown>)[property]
82
+ }
83
+
84
+ const mysqlDuplicateEntryConstraintFromMessage = (message: unknown): string => {
85
+ if (typeof message !== "string") {
86
+ return UNKNOWN_CONSTRAINT
87
+ }
88
+ const match = /\bfor key\s+(?:'([^']*)'|\x60([^\x60]*)\x60|([^\s'\x60]+))/i.exec(message)
89
+ return match === null ?
90
+ UNKNOWN_CONSTRAINT :
91
+ normalizeConstraintIdentifier(match[1] ?? match[2] ?? match[3])
92
+ }
93
+
94
+ const mysqlDuplicateEntryConstraintFromCause = (cause: unknown): string => {
95
+ const constraint = normalizeConstraintIdentifier(mysqlCauseProperty(cause, "constraint"))
96
+ if (constraint !== UNKNOWN_CONSTRAINT) {
97
+ return constraint
98
+ }
99
+ const sqlMessageConstraint = mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "sqlMessage"))
100
+ if (sqlMessageConstraint !== UNKNOWN_CONSTRAINT) {
101
+ return sqlMessageConstraint
102
+ }
103
+ return mysqlDuplicateEntryConstraintFromMessage(mysqlCauseProperty(cause, "message"))
104
+ }
105
+
106
+ const classifyError = (
107
+ cause: unknown,
108
+ message: string,
109
+ operation: string
110
+ ) => {
111
+ const props = { cause, message, operation }
112
+ const errno = mysqlErrnoFromCause(cause)
113
+ if (errno !== undefined) {
114
+ if (mysqlConnectionErrorCodes.has(errno)) {
115
+ return new ConnectionError(props)
116
+ }
117
+ if (errno === 1045) {
118
+ return new AuthenticationError(props)
119
+ }
120
+ if (mysqlAuthorizationErrorCodes.has(errno)) {
121
+ return new AuthorizationError(props)
122
+ }
123
+ if (mysqlSyntaxErrorCodes.has(errno)) {
124
+ return new SqlSyntaxError(props)
125
+ }
126
+ if (errno === 1062) {
127
+ return new UniqueViolation({ ...props, constraint: mysqlDuplicateEntryConstraintFromCause(cause) })
128
+ }
129
+ if (mysqlConstraintErrorCodes.has(errno)) {
130
+ return new ConstraintError(props)
131
+ }
132
+ if (errno === 1213) {
133
+ return new DeadlockError(props)
134
+ }
135
+ if (errno === 1205) {
136
+ return new LockTimeoutError(props)
137
+ }
138
+ if (errno === 3024) {
139
+ return new StatementTimeoutError(props)
140
+ }
141
+ }
142
+ return new UnknownError(props)
143
+ }
144
+
25
145
  /**
26
- * @category type ids
27
- * @since 1.0.0
146
+ * Runtime type identifier used to mark `MysqlClient` values.
147
+ *
148
+ * @category type IDs
149
+ * @since 4.0.0
28
150
  */
29
151
  export const TypeId: TypeId = "~@effect/sql-mysql2/MysqlClient"
30
152
 
31
153
  /**
32
- * @category type ids
33
- * @since 1.0.0
154
+ * Type-level identifier used to mark `MysqlClient` values.
155
+ *
156
+ * @category type IDs
157
+ * @since 4.0.0
34
158
  */
35
159
  export type TypeId = "~@effect/sql-mysql2/MysqlClient"
36
160
 
37
161
  /**
162
+ * mysql2-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
163
+ *
38
164
  * @category models
39
- * @since 1.0.0
165
+ * @since 4.0.0
40
166
  */
41
167
  export interface MysqlClient extends Client.SqlClient {
42
168
  readonly [TypeId]: TypeId
@@ -44,14 +170,18 @@ export interface MysqlClient extends Client.SqlClient {
44
170
  }
45
171
 
46
172
  /**
173
+ * Context tag used to access the `MysqlClient` service.
174
+ *
47
175
  * @category tags
48
- * @since 1.0.0
176
+ * @since 4.0.0
49
177
  */
50
- export const MysqlClient = ServiceMap.Service<MysqlClient>("@effect/sql-mysql2/MysqlClient")
178
+ export const MysqlClient = Context.Service<MysqlClient>("@effect/sql-mysql2/MysqlClient")
51
179
 
52
180
  /**
181
+ * Configuration for a mysql2 client, including connection URI or connection fields, pool options, span attributes, and query/result name transforms.
182
+ *
53
183
  * @category models
54
- * @since 1.0.0
184
+ * @since 4.0.0
55
185
  */
56
186
  export interface MysqlClientConfig {
57
187
  /**
@@ -77,8 +207,10 @@ export interface MysqlClientConfig {
77
207
  }
78
208
 
79
209
  /**
210
+ * Creates a scoped MySQL client backed by a managed mysql2 pool, verifying connectivity and supporting streaming queries through mysql2 query streams.
211
+ *
80
212
  * @category constructors
81
- * @since 1.0.0
213
+ * @since 4.0.0
82
214
  */
83
215
  export const make = (
84
216
  options: MysqlClientConfig
@@ -104,13 +236,16 @@ export const make = (
104
236
  method: "execute" | "query" = "execute"
105
237
  ) {
106
238
  return Effect.callback<unknown, SqlError>((resume) => {
239
+ const operation = method === "query" ? "executeUnprepared" : "execute"
107
240
  ;(this.conn as any)[method]({
108
241
  sql,
109
242
  values,
110
243
  rowsAsArray
111
244
  }, (cause: unknown | null, results: unknown, _fields: any) => {
112
245
  if (cause) {
113
- resume(Effect.fail(new SqlError({ cause, message: "Failed to execute statement" })))
246
+ resume(
247
+ Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to execute statement", operation) }))
248
+ )
114
249
  } else {
115
250
  resume(Effect.succeed(results))
116
251
  }
@@ -198,8 +333,7 @@ export const make = (
198
333
  if (cause) {
199
334
  resume(Effect.fail(
200
335
  new SqlError({
201
- cause,
202
- message: "MysqlClient: Failed to connect"
336
+ reason: classifyError(cause, "MysqlClient: Failed to connect", "connect")
203
337
  })
204
338
  ))
205
339
  } else {
@@ -214,11 +348,14 @@ export const make = (
214
348
  ).pipe(
215
349
  Effect.timeoutOrElse({
216
350
  duration: Duration.seconds(5),
217
- onTimeout: () =>
351
+ orElse: () =>
218
352
  Effect.fail(
219
353
  new SqlError({
220
- message: "MysqlClient: Connection timeout",
221
- cause: new Error("connection timeout")
354
+ reason: new ConnectionError({
355
+ message: "MysqlClient: Connection timeout",
356
+ cause: new Error("connection timeout"),
357
+ operation: "connect"
358
+ })
222
359
  })
223
360
  )
224
361
  })
@@ -230,7 +367,13 @@ export const make = (
230
367
  Effect.callback<Mysql.PoolConnection, SqlError>((resume) => {
231
368
  pool.getConnection((cause, conn) => {
232
369
  if (cause) {
233
- resume(Effect.fail(new SqlError({ cause, message: "Failed to acquire connection" })))
370
+ resume(
371
+ Effect.fail(
372
+ new SqlError({
373
+ reason: classifyError(cause, "Failed to acquire connection", "acquireConnection")
374
+ })
375
+ )
376
+ )
234
377
  } else {
235
378
  resume(Effect.succeed(conn))
236
379
  }
@@ -268,40 +411,46 @@ export const make = (
268
411
  })
269
412
 
270
413
  /**
414
+ * Creates a layer from a `Config`-wrapped MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
415
+ *
271
416
  * @category layers
272
- * @since 1.0.0
417
+ * @since 4.0.0
273
418
  */
274
419
  export const layerConfig = (
275
420
  config: Config.Wrap<MysqlClientConfig>
276
421
  ): Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError> =>
277
- Layer.effectServices(
278
- Config.unwrap(config).asEffect().pipe(
422
+ Layer.effectContext(
423
+ Config.unwrap(config).pipe(
279
424
  Effect.flatMap(make),
280
425
  Effect.map((client) =>
281
- ServiceMap.make(MysqlClient, client).pipe(
282
- ServiceMap.add(Client.SqlClient, client)
426
+ Context.make(MysqlClient, client).pipe(
427
+ Context.add(Client.SqlClient, client)
283
428
  )
284
429
  )
285
430
  )
286
431
  ).pipe(Layer.provide(Reactivity.layer))
287
432
 
288
433
  /**
434
+ * Creates a layer from a concrete MySQL client configuration, providing both `MysqlClient` and `SqlClient`.
435
+ *
289
436
  * @category layers
290
- * @since 1.0.0
437
+ * @since 4.0.0
291
438
  */
292
439
  export const layer = (
293
440
  config: MysqlClientConfig
294
441
  ): Layer.Layer<MysqlClient | Client.SqlClient, Config.ConfigError | SqlError> =>
295
- Layer.effectServices(
442
+ Layer.effectContext(
296
443
  Effect.map(make(config), (client) =>
297
- ServiceMap.make(MysqlClient, client).pipe(
298
- ServiceMap.add(Client.SqlClient, client)
444
+ Context.make(MysqlClient, client).pipe(
445
+ Context.add(Client.SqlClient, client)
299
446
  ))
300
447
  ).pipe(Layer.provide(Reactivity.layer))
301
448
 
302
449
  /**
450
+ * Creates the MySQL statement compiler, using `?` placeholders and backtick-escaped identifiers.
451
+ *
303
452
  * @category compiler
304
- * @since 1.0.0
453
+ * @since 4.0.0
305
454
  */
306
455
  export const makeCompiler = (transform?: (_: string) => string) =>
307
456
  Statement.makeCompiler({
@@ -331,11 +480,15 @@ function queryStream(
331
480
  ) {
332
481
  return asyncPauseResume<any, SqlError>(Effect.fnUntraced(function*(emit) {
333
482
  const query = (conn as any).query(sql, params).stream()
334
- yield* Effect.addFinalizer(() => Effect.sync(() => query.destroy()))
483
+ yield* Effect.addFinalizer(() => Effect.sync(() => query.destroy() as void))
335
484
 
336
485
  let buffer: Array<any> = []
337
486
  let taskPending = false
338
- query.on("error", (cause: unknown) => emit.fail(new SqlError({ cause, message: "Failed to stream statement" })))
487
+ query.on(
488
+ "error",
489
+ (cause: unknown) =>
490
+ emit.fail(new SqlError({ reason: classifyError(cause, "Failed to stream statement", "stream") }))
491
+ )
339
492
  query.on("data", (row: any) => {
340
493
  buffer.push(row)
341
494
  if (!taskPending) {
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Utilities for applying Effect SQL migrations to MySQL databases through the
3
+ * mysql2-backed `SqlClient`.
4
+ *
5
+ * This module re-exports the shared `Migrator` loaders and error types, then
6
+ * provides `run` and `layer` helpers for applying ordered migrations using the
7
+ * currently configured MySQL `SqlClient`. It is commonly used during application
8
+ * startup, in integration tests that provision a temporary schema, or in layer
9
+ * graphs where dependent services should not start until the database schema is
10
+ * current.
11
+ *
12
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
13
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
14
+ * than the latest recorded id are run. MySQL DDL can cause implicit commits, and
15
+ * this adapter relies on migration table constraints to detect concurrent
16
+ * runners, so coordinate startup runners and write migrations to tolerate
17
+ * MySQL's transactional semantics. Schema dump support is not enabled in this
18
+ * adapter, so `schemaDirectory` does not emit a MySQL dump.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import type * as Effect from "effect/Effect"
5
23
  import * as Layer from "effect/Layer"
@@ -8,13 +26,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
8
26
  import type { SqlError } from "effect/unstable/sql/SqlError"
9
27
 
10
28
  /**
11
- * @since 1.0.0
29
+ * @since 4.0.0
12
30
  */
13
31
  export * from "effect/unstable/sql/Migrator"
14
32
 
15
33
  /**
16
- * @category constructor
17
- * @since 1.0.0
34
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
35
+ *
36
+ * @category constructors
37
+ * @since 4.0.0
18
38
  */
19
39
  export const run: <R2 = never>(
20
40
  { loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>
@@ -78,8 +98,10 @@ export const run: <R2 = never>(
78
98
  })
79
99
 
80
100
  /**
101
+ * Creates a layer that runs the configured SQL migrations during layer construction.
102
+ *
81
103
  * @category layers
82
- * @since 1.0.0
104
+ * @since 4.0.0
83
105
  */
84
106
  export const layer = <R>(
85
107
  options: Migrator.MigratorOptions<R>
package/src/index.ts CHANGED
@@ -1,15 +1,50 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * MySQL client implementation for Effect SQL, backed by the `mysql2` driver.
9
+ *
10
+ * This module exposes constructors and layers for providing both the MySQL-specific
11
+ * `MysqlClient` service and the generic `SqlClient` service. It is intended for server
12
+ * applications, background workers, migrations, and tests that need Effect SQL query
13
+ * compilation, scoped resource management, streaming queries, and consistent `SqlError`
14
+ * classification for MySQL driver failures.
15
+ *
16
+ * Each client owns a scoped mysql2 pool, validates connectivity with `SELECT 1` during
17
+ * acquisition, and closes the pool when the surrounding scope is released. You can configure
18
+ * the pool from a connection URI or discrete connection fields; when `url` is supplied it
19
+ * takes precedence over the host, port, database, username, and password fields. Regular
20
+ * queries run through the shared pool, while transactions acquire a dedicated pooled
21
+ * connection for their lifetime, so long-running transactions and streams can occupy pool
22
+ * capacity. Size `maxConnections`, `connectionTTL`, and any mysql2 `poolConfig` with that in
23
+ * mind.
24
+ *
25
+ * @since 4.0.0
9
26
  */
10
27
  export * as MysqlClient from "./MysqlClient.ts"
11
28
 
12
29
  /**
13
- * @since 1.0.0
30
+ * Utilities for applying Effect SQL migrations to MySQL databases through the
31
+ * mysql2-backed `SqlClient`.
32
+ *
33
+ * This module re-exports the shared `Migrator` loaders and error types, then
34
+ * provides `run` and `layer` helpers for applying ordered migrations using the
35
+ * currently configured MySQL `SqlClient`. It is commonly used during application
36
+ * startup, in integration tests that provision a temporary schema, or in layer
37
+ * graphs where dependent services should not start until the database schema is
38
+ * current.
39
+ *
40
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
41
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
42
+ * than the latest recorded id are run. MySQL DDL can cause implicit commits, and
43
+ * this adapter relies on migration table constraints to detect concurrent
44
+ * runners, so coordinate startup runners and write migrations to tolerate
45
+ * MySQL's transactional semantics. Schema dump support is not enabled in this
46
+ * adapter, so `schemaDirectory` does not emit a MySQL dump.
47
+ *
48
+ * @since 4.0.0
14
49
  */
15
50
  export * as MysqlMigrator from "./MysqlMigrator.ts"