@effect/sql-libsql 4.0.0-beta.7 → 4.0.0-beta.71

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,51 +1,98 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL adapter for Effect SQL, backed by `@libsql/client`.
3
+ *
4
+ * Use this module to provide a {@link LibsqlClient} and the generic SQL client
5
+ * service for Turso-hosted libSQL databases, local `file:` databases, embedded
6
+ * replicas, migrations, tests, and server code that wants SQLite-compatible SQL
7
+ * through Effect layers. The client uses Effect SQL's SQLite compiler and
8
+ * classifies libSQL and SQLite failures as `SqlError`s.
9
+ *
10
+ * ## Mental model
11
+ *
12
+ * {@link make} and {@link layer} either create a scoped libSQL SDK client from
13
+ * connection options or wrap a caller-owned client supplied with `liveClient`.
14
+ * The Effect client serializes access to the underlying client because a libSQL
15
+ * transaction is tied to that client. A top-level `withTransaction` opens a
16
+ * write transaction, and nested transactions use SQLite savepoints.
17
+ *
18
+ * ## Common tasks
19
+ *
20
+ * - Use {@link layer} with concrete connection options, or {@link layerConfig}
21
+ * when the options should come from `Config`.
22
+ * - Use a `file:` URL for local SQLite-compatible storage, a remote libSQL or
23
+ * Turso URL for hosted databases, and `syncUrl` for embedded replicas.
24
+ * - Use `liveClient` when another component owns the `@libsql/client` instance
25
+ * and its lifetime.
26
+ * - Use `transformQueryNames` and `transformResultNames` to map between Effect
27
+ * field names and database column names.
28
+ *
29
+ * ## Gotchas
30
+ *
31
+ * Direct calls made through the raw SDK client are not coordinated with Effect
32
+ * SQL transactions. Remote transactions should stay short because they reserve
33
+ * the client until commit or rollback. Row streaming is not implemented by this
34
+ * adapter.
35
+ *
36
+ * @since 4.0.0
3
37
  */
4
38
  import * as Libsql from "@libsql/client";
5
39
  import * as Config from "effect/Config";
40
+ import * as Context from "effect/Context";
6
41
  import * as Effect from "effect/Effect";
7
42
  import * as Layer from "effect/Layer";
8
43
  import * as Redacted from "effect/Redacted";
9
44
  import * as Scope from "effect/Scope";
10
- import * as ServiceMap from "effect/ServiceMap";
11
45
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
12
46
  import * as Client from "effect/unstable/sql/SqlClient";
13
47
  /**
14
- * @category type ids
15
- * @since 1.0.0
48
+ * Runtime type identifier used to mark `LibsqlClient` values.
49
+ *
50
+ * @category type IDs
51
+ * @since 4.0.0
16
52
  */
17
53
  export declare const TypeId: TypeId;
18
54
  /**
19
- * @category type ids
20
- * @since 1.0.0
55
+ * Type-level identifier used to mark `LibsqlClient` values.
56
+ *
57
+ * @category type IDs
58
+ * @since 4.0.0
21
59
  */
22
60
  export type TypeId = "~@effect/sql-libsql/LibsqlClient";
23
61
  /**
62
+ * libSQL-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
63
+ *
24
64
  * @category models
25
- * @since 1.0.0
65
+ * @since 4.0.0
26
66
  */
27
67
  export interface LibsqlClient extends Client.SqlClient {
28
68
  readonly [TypeId]: TypeId;
29
69
  readonly config: LibsqlClientConfig;
30
70
  }
31
71
  /**
72
+ * Context tag used to access the `LibsqlClient` service.
73
+ *
32
74
  * @category tags
33
- * @since 1.0.0
75
+ * @since 4.0.0
34
76
  */
35
- export declare const LibsqlClient: ServiceMap.Service<LibsqlClient, LibsqlClient>;
77
+ export declare const LibsqlClient: Context.Service<LibsqlClient, LibsqlClient>;
36
78
  /**
79
+ * Configuration for a libSQL client, either by supplying connection options or an existing live libSQL client.
80
+ *
37
81
  * @category models
38
- * @since 1.0.0
82
+ * @since 4.0.0
39
83
  */
40
84
  export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live;
41
85
  /**
42
- * @category models
43
- * @since 1.0.0
86
+ * Namespace containing the configuration variants for `LibsqlClient`.
87
+ *
88
+ * @since 4.0.0
44
89
  */
45
90
  export declare namespace LibsqlClientConfig {
46
91
  /**
92
+ * Shared libSQL client options for span attributes and query/result name transformations.
93
+ *
47
94
  * @category models
48
- * @since 1.0.0
95
+ * @since 4.0.0
49
96
  */
50
97
  interface Base {
51
98
  readonly spanAttributes?: Record<string, unknown> | undefined;
@@ -53,11 +100,16 @@ export declare namespace LibsqlClientConfig {
53
100
  readonly transformQueryNames?: ((str: string) => string) | undefined;
54
101
  }
55
102
  /**
103
+ * Connection-based libSQL configuration used to create a managed client, including URL, credentials, sync, integer mode, TLS, and concurrency options.
104
+ *
56
105
  * @category models
57
- * @since 1.0.0
106
+ * @since 4.0.0
58
107
  */
59
108
  interface Full extends Base {
60
- /** The database URL.
109
+ /**
110
+ * The database URL.
111
+ *
112
+ * **Details**
61
113
  *
62
114
  * The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
63
115
  * please refer to the project README:
@@ -73,12 +125,18 @@ export declare namespace LibsqlClientConfig {
73
125
  readonly syncUrl?: string | URL | undefined;
74
126
  /** Sync interval in seconds. */
75
127
  readonly syncInterval?: number | undefined;
76
- /** Enables or disables TLS for `libsql:` URLs.
128
+ /**
129
+ * Enables or disables TLS for `libsql:` URLs.
130
+ *
131
+ * **Details**
77
132
  *
78
133
  * By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
79
134
  */
80
135
  readonly tls?: boolean | undefined;
81
- /** How to convert SQLite integers to JavaScript values:
136
+ /**
137
+ * How to convert SQLite integers to JavaScript values.
138
+ *
139
+ * **Details**
82
140
  *
83
141
  * - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
84
142
  * `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
@@ -88,7 +146,10 @@ export declare namespace LibsqlClientConfig {
88
146
  * - `"string"`: returns SQLite integers as strings.
89
147
  */
90
148
  readonly intMode?: "number" | "bigint" | "string" | undefined;
91
- /** Concurrency limit.
149
+ /**
150
+ * Concurrency limit.
151
+ *
152
+ * **Details**
92
153
  *
93
154
  * By default, the client performs up to 20 concurrent requests. You can set this option to a higher
94
155
  * number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
@@ -96,26 +157,34 @@ export declare namespace LibsqlClientConfig {
96
157
  readonly concurrency?: number | undefined;
97
158
  }
98
159
  /**
160
+ * Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
161
+ *
99
162
  * @category models
100
- * @since 1.0.0
163
+ * @since 4.0.0
101
164
  */
102
165
  interface Live extends Base {
103
166
  readonly liveClient: Libsql.Client;
104
167
  }
105
168
  }
106
169
  /**
107
- * @category constructor
108
- * @since 1.0.0
170
+ * Creates a scoped libSQL SQL client with transaction support. When given connection options it creates and closes the SDK client; when given `liveClient`, the caller retains ownership.
171
+ *
172
+ * @category constructors
173
+ * @since 4.0.0
109
174
  */
110
175
  export declare const make: (options: LibsqlClientConfig) => Effect.Effect<LibsqlClient, never, Scope.Scope | Reactivity.Reactivity>;
111
176
  /**
177
+ * Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
178
+ *
112
179
  * @category layers
113
- * @since 1.0.0
180
+ * @since 4.0.0
114
181
  */
115
182
  export declare const layerConfig: (config: Config.Wrap<LibsqlClientConfig>) => Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError>;
116
183
  /**
184
+ * Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
185
+ *
117
186
  * @category layers
118
- * @since 1.0.0
187
+ * @since 4.0.0
119
188
  */
120
189
  export declare const layer: (config: LibsqlClientConfig) => Layer.Layer<LibsqlClient | Client.SqlClient>;
121
190
  //# sourceMappingURL=LibsqlClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LibsqlClient.d.ts","sourceRoot":"","sources":["../src/LibsqlClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAA;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OA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AAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAY3B,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,QAAQ,kBAAkB,KACzB,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAML,CAAA"}
@@ -1,35 +1,79 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL adapter for Effect SQL, backed by `@libsql/client`.
3
+ *
4
+ * Use this module to provide a {@link LibsqlClient} and the generic SQL client
5
+ * service for Turso-hosted libSQL databases, local `file:` databases, embedded
6
+ * replicas, migrations, tests, and server code that wants SQLite-compatible SQL
7
+ * through Effect layers. The client uses Effect SQL's SQLite compiler and
8
+ * classifies libSQL and SQLite failures as `SqlError`s.
9
+ *
10
+ * ## Mental model
11
+ *
12
+ * {@link make} and {@link layer} either create a scoped libSQL SDK client from
13
+ * connection options or wrap a caller-owned client supplied with `liveClient`.
14
+ * The Effect client serializes access to the underlying client because a libSQL
15
+ * transaction is tied to that client. A top-level `withTransaction` opens a
16
+ * write transaction, and nested transactions use SQLite savepoints.
17
+ *
18
+ * ## Common tasks
19
+ *
20
+ * - Use {@link layer} with concrete connection options, or {@link layerConfig}
21
+ * when the options should come from `Config`.
22
+ * - Use a `file:` URL for local SQLite-compatible storage, a remote libSQL or
23
+ * Turso URL for hosted databases, and `syncUrl` for embedded replicas.
24
+ * - Use `liveClient` when another component owns the `@libsql/client` instance
25
+ * and its lifetime.
26
+ * - Use `transformQueryNames` and `transformResultNames` to map between Effect
27
+ * field names and database column names.
28
+ *
29
+ * ## Gotchas
30
+ *
31
+ * Direct calls made through the raw SDK client are not coordinated with Effect
32
+ * SQL transactions. Remote transactions should stay short because they reserve
33
+ * the client until commit or rollback. Row streaming is not implemented by this
34
+ * adapter.
35
+ *
36
+ * @since 4.0.0
3
37
  */
4
38
  import * as Libsql from "@libsql/client";
5
39
  import * as Config from "effect/Config";
40
+ import * as Context from "effect/Context";
6
41
  import * as Effect from "effect/Effect";
7
42
  import * as Layer from "effect/Layer";
8
43
  import * as Option from "effect/Option";
9
44
  import * as Redacted from "effect/Redacted";
10
45
  import * as Scope from "effect/Scope";
11
46
  import * as Semaphore from "effect/Semaphore";
12
- import * as ServiceMap from "effect/ServiceMap";
13
47
  import * as Stream from "effect/Stream";
14
48
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
15
49
  import * as Client from "effect/unstable/sql/SqlClient";
16
- import { SqlError } from "effect/unstable/sql/SqlError";
50
+ import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
17
51
  import * as Statement from "effect/unstable/sql/Statement";
18
52
  const ATTR_DB_SYSTEM_NAME = "db.system.name";
53
+ const classifyError = (cause, message, operation) => classifySqliteError(cause, {
54
+ message,
55
+ operation
56
+ });
19
57
  /**
20
- * @category type ids
21
- * @since 1.0.0
58
+ * Runtime type identifier used to mark `LibsqlClient` values.
59
+ *
60
+ * @category type IDs
61
+ * @since 4.0.0
22
62
  */
23
63
  export const TypeId = "~@effect/sql-libsql/LibsqlClient";
24
64
  /**
65
+ * Context tag used to access the `LibsqlClient` service.
66
+ *
25
67
  * @category tags
26
- * @since 1.0.0
68
+ * @since 4.0.0
27
69
  */
28
- export const LibsqlClient = /*#__PURE__*/ServiceMap.Service("@effect/sql-libsql/LibsqlClient");
29
- const LibsqlTransaction = /*#__PURE__*/ServiceMap.Service("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
70
+ export const LibsqlClient = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient");
71
+ const LibsqlTransaction = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
30
72
  /**
31
- * @category constructor
32
- * @since 1.0.0
73
+ * Creates a scoped libSQL SQL client with transaction support. When given connection options it creates and closes the SDK client; when given `liveClient`, the caller retains ownership.
74
+ *
75
+ * @category constructors
76
+ * @since 4.0.0
33
77
  */
34
78
  export const make = options => Effect.gen(function* () {
35
79
  const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
@@ -47,8 +91,7 @@ export const make = options => Effect.gen(function* () {
47
91
  args: params
48
92
  }),
49
93
  catch: cause => new SqlError({
50
- cause,
51
- message: "Failed to execute statement"
94
+ reason: classifyError(cause, "Failed to execute statement", "execute")
52
95
  })
53
96
  }), results => results.rows);
54
97
  }
@@ -59,8 +102,7 @@ export const make = options => Effect.gen(function* () {
59
102
  args: params
60
103
  }),
61
104
  catch: cause => new SqlError({
62
- cause,
63
- message: "Failed to execute statement"
105
+ reason: classifyError(cause, "Failed to execute statement", "execute")
64
106
  })
65
107
  });
66
108
  }
@@ -83,8 +125,7 @@ export const make = options => Effect.gen(function* () {
83
125
  return Effect.map(Effect.tryPromise({
84
126
  try: () => this.sdk.transaction("write"),
85
127
  catch: cause => new SqlError({
86
- cause,
87
- message: "Failed to begin transaction"
128
+ reason: classifyError(cause, "Failed to begin transaction", "beginTransaction")
88
129
  })
89
130
  }), tx => new LibsqlConnectionImpl(tx));
90
131
  }
@@ -92,8 +133,7 @@ export const make = options => Effect.gen(function* () {
92
133
  return Effect.tryPromise({
93
134
  try: () => this.sdk.commit(),
94
135
  catch: cause => new SqlError({
95
- cause,
96
- message: "Failed to commit transaction"
136
+ reason: classifyError(cause, "Failed to commit transaction", "commitTransaction")
97
137
  })
98
138
  });
99
139
  }
@@ -101,8 +141,7 @@ export const make = options => Effect.gen(function* () {
101
141
  return Effect.tryPromise({
102
142
  try: () => this.sdk.rollback(),
103
143
  catch: cause => new SqlError({
104
- cause,
105
- message: "Failed to rollback transaction"
144
+ reason: classifyError(cause, "Failed to rollback transaction", "rollbackTransaction")
106
145
  })
107
146
  });
108
147
  }
@@ -149,13 +188,17 @@ export const make = options => Effect.gen(function* () {
149
188
  });
150
189
  });
151
190
  /**
191
+ * Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
192
+ *
152
193
  * @category layers
153
- * @since 1.0.0
194
+ * @since 4.0.0
154
195
  */
155
- export const layerConfig = config => Layer.effectServices(Config.unwrap(config).asEffect().pipe(Effect.flatMap(make), Effect.map(client => ServiceMap.make(LibsqlClient, client).pipe(ServiceMap.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
196
+ export const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(LibsqlClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
156
197
  /**
198
+ * Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
199
+ *
157
200
  * @category layers
158
- * @since 1.0.0
201
+ * @since 4.0.0
159
202
  */
160
- export const layer = config => Layer.effectServices(Effect.map(make(config), client => ServiceMap.make(LibsqlClient, client).pipe(ServiceMap.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
203
+ export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(LibsqlClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
161
204
  //# sourceMappingURL=LibsqlClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LibsqlClient.js","names":["Libsql","Config","Effect","Layer","Option","Redacted","Scope","Semaphore","ServiceMap","Stream","Reactivity","Client","SqlError","Statement","ATTR_DB_SYSTEM_NAME","TypeId","LibsqlClient","Service","LibsqlTransaction","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","spanAttributes","Object","entries","LibsqlConnectionImpl","sdk","constructor","run","sql","params","map","tryPromise","try","execute","args","catch","cause","message","results","rows","runRaw","executeRaw","executeValues","row","Array","from","executeUnprepared","executeStream","die","beginTransaction","transaction","tx","commit","rollback","connection","liveClient","acquireRelease","sync","createClient","authToken","isRedacted","value","encryptionKey","url","toString","syncUrl","close","semaphore","withTransaction","makeWithTransaction","transactionService","acquireConnection","uninterruptibleMask","fnUntraced","restore","scope","makeUnsafe","take","addFinalizer","release","conn","begin","void","savepoint","id","rollbackSavepoint","acquirer","flatMap","serviceOption","match","onNone","withPermits","succeed","onSome","assign","config","layerConfig","effectServices","unwrap","asEffect","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/LibsqlClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,MAAM,MAAM,gBAAgB;AACxC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,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,OAAO,KAAKC,SAAS,MAAM,+BAA+B;AAE1D,MAAMC,mBAAmB,GAAG,gBAAgB;AAE5C;;;;AAIA,OAAO,MAAMC,MAAM,GAAW,kCAAkC;AAiBhE;;;;AAIA,OAAO,MAAMC,YAAY,gBAAGR,UAAU,CAACS,OAAO,CAAe,iCAAiC,CAAC;AAE/F,MAAMC,iBAAiB,gBAAGV,UAAU,CAACS,OAAO,CAC1C,mDAAmD,CACpD;AAkFD;;;;AAIA,OAAO,MAAME,IAAI,GACfC,OAA2B,IAE3BlB,MAAM,CAACmB,GAAG,CAAC,aAAS;EAClB,MAAMC,QAAQ,GAAGT,SAAS,CAACU,kBAAkB,CAACH,OAAO,CAACI,mBAAmB,CAAC;EAC1E,MAAMC,aAAa,GAAGL,OAAO,CAACM,oBAAoB,GAChDb,SAAS,CAACc,iBAAiB,CACzB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AACwG,KAAK,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"LibsqlClient.js","names":["Libsql","Config","Context","Effect","Layer","Option","Redacted","Scope","Semaphore","Stream","Reactivity","Client","classifySqliteError","SqlError","Statement","ATTR_DB_SYSTEM_NAME","classifyError","cause","message","operation","TypeId","LibsqlClient","Service","LibsqlTransaction","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","spanAttributes","Object","entries","LibsqlConnectionImpl","sdk","constructor","run","sql","params","map","tryPromise","try","execute","args","catch","reason","results","rows","runRaw","executeRaw","executeValues","row","Array","from","executeUnprepared","executeStream","die","beginTransaction","transaction","tx","commit","rollback","connection","liveClient","acquireRelease","sync","createClient","authToken","isRedacted","value","encryptionKey","url","toString","syncUrl","close","semaphore","withTransaction","makeWithTransaction","transactionService","acquireConnection","uninterruptibleMask","fnUntraced","restore","scope","makeUnsafe","take","addFinalizer","release","conn","begin","void","savepoint","id","rollbackSavepoint","acquirer","flatMap","serviceOption","match","onNone","withPermits","succeed","onSome","assign","config","layerConfig","effectContext","unwrap","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/LibsqlClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,OAAO,KAAKA,MAAM,MAAM,gBAAgB;AACxC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAA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EnF,OAAO;IACfwD,eAAe;IACf1C,GAAG,EAAE4B,UAAU,CAAC5B;GACjB,CACF;AACH,CAAC,CAAC;AAEJ;;;;;;AAMA,OAAO,MAAMsE,WAAW,GAGtBD,MAAuC,IAEvCxG,KAAK,CAAC0G,aAAa,CACjB7G,MAAM,CAAC8G,MAAM,CAACH,MAAM,CAAC,CAACI,IAAI,CACxB7G,MAAM,CAACiG,OAAO,CAAC5E,IAAI,CAAC,EACpBrB,MAAM,CAACyC,GAAG,CAAEqE,MAAM,IAChB/G,OAAO,CAACsB,IAAI,CAACH,YAAY,EAAE4F,MAAM,CAAC,CAACD,IAAI,CACrC9G,OAAO,CAACgH,GAAG,CAACvG,MAAM,CAACwG,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF,CAACD,IAAI,CAAC5G,KAAK,CAACgH,OAAO,CAAC1G,UAAU,CAAC2G,KAAK,CAAC,CAAC;AAEzC;;;;;;AAMA,OAAO,MAAMA,KAAK,GAChBT,MAA0B,IAE1BxG,KAAK,CAAC0G,aAAa,CACjB3G,MAAM,CAACyC,GAAG,CAACpB,IAAI,CAACoF,MAAM,CAAC,EAAGK,MAAM,IAC9B/G,OAAO,CAACsB,IAAI,CAACH,YAAY,EAAE4F,MAAM,CAAC,CAACD,IAAI,CACrC9G,OAAO,CAACgH,GAAG,CAACvG,MAAM,CAACwG,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAACD,IAAI,CAAC5G,KAAK,CAACgH,OAAO,CAAC1G,UAAU,CAAC2G,KAAK,CAAC,CAAC","ignoreList":[]}
@@ -1,5 +1,36 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL migration support for Effect SQL applications.
3
+ *
4
+ * This module adapts the shared SQL migrator to libSQL and Turso databases. It
5
+ * re-exports the common migration loaders and errors, then provides {@link run}
6
+ * and {@link layer} helpers that apply pending migrations with the current
7
+ * libSQL-backed `SqlClient`.
8
+ *
9
+ * **Mental model**
10
+ *
11
+ * Migrations are numbered operations loaded from files, records, or bundler
12
+ * glob results. The runner ensures the migrations table exists, reads the
13
+ * latest recorded id, and runs only migrations with a greater id through the
14
+ * configured libSQL client.
15
+ *
16
+ * **Common tasks**
17
+ *
18
+ * Use {@link run} during application startup, deployment, or setup scripts when
19
+ * migrations should be executed explicitly. Use {@link layer} in a layer graph
20
+ * when dependent services should be acquired only after the schema is prepared.
21
+ * Reuse the shared loaders from this module for file-based or in-memory
22
+ * migration definitions.
23
+ *
24
+ * **Gotchas**
25
+ *
26
+ * libSQL uses SQLite-compatible SQL, so avoid dialect features unsupported by
27
+ * libSQL or the configured Turso deployment. Remote Turso databases, local
28
+ * `file:` databases, and embedded replicas can observe different state until
29
+ * replication catches up. Run schema-changing migrations against the intended
30
+ * writer, coordinate concurrent migrators, and do not rely on
31
+ * `schemaDirectory` for libSQL schema dumps.
32
+ *
33
+ * @since 4.0.0
3
34
  */
4
35
  import type * as Effect from "effect/Effect";
5
36
  import * as Layer from "effect/Layer";
@@ -7,17 +38,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
7
38
  import type * as Client from "effect/unstable/sql/SqlClient";
8
39
  import type { SqlError } from "effect/unstable/sql/SqlError";
9
40
  /**
10
- * @since 1.0.0
41
+ * @since 4.0.0
11
42
  */
12
43
  export * from "effect/unstable/sql/Migrator";
13
44
  /**
14
- * @category constructor
15
- * @since 1.0.0
45
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
46
+ *
47
+ * @category constructors
48
+ * @since 4.0.0
16
49
  */
17
50
  export declare const run: <R2 = never>(options: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
18
51
  /**
19
- * @category constructor
20
- * @since 1.0.0
52
+ * Creates a layer that runs the configured SQL migrations during layer construction.
53
+ *
54
+ * @category constructors
55
+ * @since 4.0.0
21
56
  */
22
57
  export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
23
58
  //# sourceMappingURL=LibsqlMigrator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LibsqlMigrator.d.ts","sourceRoot":"","sources":["../src/LibsqlMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAClC,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,CACF,CAAA;AAErB;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAAE,MAAM,CAAC,SAAS,GAAG,CAAC,CAAsC,CAAA"}
1
+ {"version":3,"file":"LibsqlMigrator.d.ts","sourceRoot":"","sources":["../src/LibsqlMigrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAClC,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,CACF,CAAA;AAErB;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAAE,MAAM,CAAC,SAAS,GAAG,CAAC,CAAsC,CAAA"}
@@ -1,17 +1,21 @@
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
  /**
13
- * @category constructor
14
- * @since 1.0.0
15
+ * Creates a layer that runs the configured SQL migrations during layer construction.
16
+ *
17
+ * @category constructors
18
+ * @since 4.0.0
15
19
  */
16
20
  export const layer = options => Layer.effectDiscard(run(options));
17
21
  //# sourceMappingURL=LibsqlMigrator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LibsqlMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/LibsqlMigrator.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,EAAE,CAAC;AAErB;;;;AAIA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAC6CL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"LibsqlMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/LibsqlMigrator.ts"],"sourcesContent":[null],"mappings":"AAmCA,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,EAAE,CAAC;AAErB;;;;;;AAMA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAC6CL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  /**
5
- * @since 1.0.0
5
+ * @since 4.0.0
6
6
  */
7
7
  export * as LibsqlClient from "./LibsqlClient.ts";
8
8
  /**
9
- * @since 1.0.0
9
+ * @since 4.0.0
10
10
  */
11
11
  export * as LibsqlMigrator from "./LibsqlMigrator.ts";
12
12
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
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
+ * @since 4.0.0
7
7
  */
8
8
  export * as LibsqlClient from "./LibsqlClient.js";
9
9
  /**
10
- * @since 1.0.0
10
+ * @since 4.0.0
11
11
  */
12
12
  export * as LibsqlMigrator from "./LibsqlMigrator.js";
13
13
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/sql-libsql",
3
- "version": "4.0.0-beta.7",
3
+ "version": "4.0.0-beta.71",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A libSQL toolkit for Effect",
@@ -45,14 +45,14 @@
45
45
  "provenance": true
46
46
  },
47
47
  "devDependencies": {
48
- "testcontainers": "^11.11.0",
49
- "effect": "^4.0.0-beta.7"
48
+ "testcontainers": "^11.14.0",
49
+ "effect": "^4.0.0-beta.71"
50
50
  },
51
51
  "peerDependencies": {
52
- "effect": "^4.0.0-beta.7"
52
+ "effect": "^4.0.0-beta.71"
53
53
  },
54
54
  "dependencies": {
55
- "@libsql/client": "^0.17.0"
55
+ "@libsql/client": "^0.17.3"
56
56
  },
57
57
  "scripts": {
58
58
  "codegen": "effect-utils codegen",
@@ -1,39 +1,82 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL adapter for Effect SQL, backed by `@libsql/client`.
3
+ *
4
+ * Use this module to provide a {@link LibsqlClient} and the generic SQL client
5
+ * service for Turso-hosted libSQL databases, local `file:` databases, embedded
6
+ * replicas, migrations, tests, and server code that wants SQLite-compatible SQL
7
+ * through Effect layers. The client uses Effect SQL's SQLite compiler and
8
+ * classifies libSQL and SQLite failures as `SqlError`s.
9
+ *
10
+ * ## Mental model
11
+ *
12
+ * {@link make} and {@link layer} either create a scoped libSQL SDK client from
13
+ * connection options or wrap a caller-owned client supplied with `liveClient`.
14
+ * The Effect client serializes access to the underlying client because a libSQL
15
+ * transaction is tied to that client. A top-level `withTransaction` opens a
16
+ * write transaction, and nested transactions use SQLite savepoints.
17
+ *
18
+ * ## Common tasks
19
+ *
20
+ * - Use {@link layer} with concrete connection options, or {@link layerConfig}
21
+ * when the options should come from `Config`.
22
+ * - Use a `file:` URL for local SQLite-compatible storage, a remote libSQL or
23
+ * Turso URL for hosted databases, and `syncUrl` for embedded replicas.
24
+ * - Use `liveClient` when another component owns the `@libsql/client` instance
25
+ * and its lifetime.
26
+ * - Use `transformQueryNames` and `transformResultNames` to map between Effect
27
+ * field names and database column names.
28
+ *
29
+ * ## Gotchas
30
+ *
31
+ * Direct calls made through the raw SDK client are not coordinated with Effect
32
+ * SQL transactions. Remote transactions should stay short because they reserve
33
+ * the client until commit or rollback. Row streaming is not implemented by this
34
+ * adapter.
35
+ *
36
+ * @since 4.0.0
3
37
  */
4
38
  import * as Libsql from "@libsql/client"
5
39
  import * as Config from "effect/Config"
40
+ import * as Context from "effect/Context"
6
41
  import * as Effect from "effect/Effect"
7
42
  import * as Layer from "effect/Layer"
8
43
  import * as Option from "effect/Option"
9
44
  import * as Redacted from "effect/Redacted"
10
45
  import * as Scope from "effect/Scope"
11
46
  import * as Semaphore from "effect/Semaphore"
12
- import * as ServiceMap from "effect/ServiceMap"
13
47
  import * as Stream from "effect/Stream"
14
48
  import * as Reactivity from "effect/unstable/reactivity/Reactivity"
15
49
  import * as Client from "effect/unstable/sql/SqlClient"
16
50
  import type { Connection } from "effect/unstable/sql/SqlConnection"
17
- import { SqlError } from "effect/unstable/sql/SqlError"
51
+ import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
18
52
  import * as Statement from "effect/unstable/sql/Statement"
19
53
 
20
54
  const ATTR_DB_SYSTEM_NAME = "db.system.name"
21
55
 
56
+ const classifyError = (cause: unknown, message: string, operation: string) =>
57
+ classifySqliteError(cause, { message, operation })
58
+
22
59
  /**
23
- * @category type ids
24
- * @since 1.0.0
60
+ * Runtime type identifier used to mark `LibsqlClient` values.
61
+ *
62
+ * @category type IDs
63
+ * @since 4.0.0
25
64
  */
26
65
  export const TypeId: TypeId = "~@effect/sql-libsql/LibsqlClient"
27
66
 
28
67
  /**
29
- * @category type ids
30
- * @since 1.0.0
68
+ * Type-level identifier used to mark `LibsqlClient` values.
69
+ *
70
+ * @category type IDs
71
+ * @since 4.0.0
31
72
  */
32
73
  export type TypeId = "~@effect/sql-libsql/LibsqlClient"
33
74
 
34
75
  /**
76
+ * libSQL-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
77
+ *
35
78
  * @category models
36
- * @since 1.0.0
79
+ * @since 4.0.0
37
80
  */
38
81
  export interface LibsqlClient extends Client.SqlClient {
39
82
  readonly [TypeId]: TypeId
@@ -41,29 +84,36 @@ export interface LibsqlClient extends Client.SqlClient {
41
84
  }
42
85
 
43
86
  /**
87
+ * Context tag used to access the `LibsqlClient` service.
88
+ *
44
89
  * @category tags
45
- * @since 1.0.0
90
+ * @since 4.0.0
46
91
  */
47
- export const LibsqlClient = ServiceMap.Service<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
92
+ export const LibsqlClient = Context.Service<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
48
93
 
49
- const LibsqlTransaction = ServiceMap.Service<readonly [LibsqlConnection, counter: number]>(
94
+ const LibsqlTransaction = Context.Service<readonly [LibsqlConnection, counter: number]>(
50
95
  "@effect/sql-libsql/LibsqlClient/LibsqlTransaction"
51
96
  )
52
97
 
53
98
  /**
99
+ * Configuration for a libSQL client, either by supplying connection options or an existing live libSQL client.
100
+ *
54
101
  * @category models
55
- * @since 1.0.0
102
+ * @since 4.0.0
56
103
  */
57
104
  export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live
58
105
 
59
106
  /**
60
- * @category models
61
- * @since 1.0.0
107
+ * Namespace containing the configuration variants for `LibsqlClient`.
108
+ *
109
+ * @since 4.0.0
62
110
  */
63
111
  export declare namespace LibsqlClientConfig {
64
112
  /**
113
+ * Shared libSQL client options for span attributes and query/result name transformations.
114
+ *
65
115
  * @category models
66
- * @since 1.0.0
116
+ * @since 4.0.0
67
117
  */
68
118
  export interface Base {
69
119
  readonly spanAttributes?: Record<string, unknown> | undefined
@@ -72,11 +122,16 @@ export declare namespace LibsqlClientConfig {
72
122
  }
73
123
 
74
124
  /**
125
+ * Connection-based libSQL configuration used to create a managed client, including URL, credentials, sync, integer mode, TLS, and concurrency options.
126
+ *
75
127
  * @category models
76
- * @since 1.0.0
128
+ * @since 4.0.0
77
129
  */
78
130
  export interface Full extends Base {
79
- /** The database URL.
131
+ /**
132
+ * The database URL.
133
+ *
134
+ * **Details**
80
135
  *
81
136
  * The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
82
137
  * please refer to the project README:
@@ -92,12 +147,18 @@ export declare namespace LibsqlClientConfig {
92
147
  readonly syncUrl?: string | URL | undefined
93
148
  /** Sync interval in seconds. */
94
149
  readonly syncInterval?: number | undefined
95
- /** Enables or disables TLS for `libsql:` URLs.
150
+ /**
151
+ * Enables or disables TLS for `libsql:` URLs.
152
+ *
153
+ * **Details**
96
154
  *
97
155
  * By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
98
156
  */
99
157
  readonly tls?: boolean | undefined
100
- /** How to convert SQLite integers to JavaScript values:
158
+ /**
159
+ * How to convert SQLite integers to JavaScript values.
160
+ *
161
+ * **Details**
101
162
  *
102
163
  * - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
103
164
  * `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
@@ -107,7 +168,10 @@ export declare namespace LibsqlClientConfig {
107
168
  * - `"string"`: returns SQLite integers as strings.
108
169
  */
109
170
  readonly intMode?: "number" | "bigint" | "string" | undefined
110
- /** Concurrency limit.
171
+ /**
172
+ * Concurrency limit.
173
+ *
174
+ * **Details**
111
175
  *
112
176
  * By default, the client performs up to 20 concurrent requests. You can set this option to a higher
113
177
  * number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
@@ -116,8 +180,10 @@ export declare namespace LibsqlClientConfig {
116
180
  }
117
181
 
118
182
  /**
183
+ * Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
184
+ *
119
185
  * @category models
120
- * @since 1.0.0
186
+ * @since 4.0.0
121
187
  */
122
188
  export interface Live extends Base {
123
189
  readonly liveClient: Libsql.Client
@@ -131,8 +197,10 @@ interface LibsqlConnection extends Connection {
131
197
  }
132
198
 
133
199
  /**
134
- * @category constructor
135
- * @since 1.0.0
200
+ * Creates a scoped libSQL SQL client with transaction support. When given connection options it creates and closes the SDK client; when given `liveClient`, the caller retains ownership.
201
+ *
202
+ * @category constructors
203
+ * @since 4.0.0
136
204
  */
137
205
  export const make = (
138
206
  options: LibsqlClientConfig
@@ -163,7 +231,7 @@ export const make = (
163
231
  return Effect.map(
164
232
  Effect.tryPromise({
165
233
  try: () => this.sdk.execute({ sql, args: params as Array<any> }),
166
- catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
234
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
167
235
  }),
168
236
  (results) => results.rows
169
237
  )
@@ -175,7 +243,7 @@ export const make = (
175
243
  ) {
176
244
  return Effect.tryPromise({
177
245
  try: () => this.sdk.execute({ sql, args: params as Array<any> }),
178
- catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
246
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
179
247
  })
180
248
  }
181
249
 
@@ -208,7 +276,8 @@ export const make = (
208
276
  return Effect.map(
209
277
  Effect.tryPromise({
210
278
  try: () => (this.sdk as Libsql.Client).transaction("write"),
211
- catch: (cause) => new SqlError({ cause, message: "Failed to begin transaction" })
279
+ catch: (cause) =>
280
+ new SqlError({ reason: classifyError(cause, "Failed to begin transaction", "beginTransaction") })
212
281
  }),
213
282
  (tx) => new LibsqlConnectionImpl(tx)
214
283
  )
@@ -216,13 +285,15 @@ export const make = (
216
285
  get commit() {
217
286
  return Effect.tryPromise({
218
287
  try: () => (this.sdk as Libsql.Transaction).commit(),
219
- catch: (cause) => new SqlError({ cause, message: "Failed to commit transaction" })
288
+ catch: (cause) =>
289
+ new SqlError({ reason: classifyError(cause, "Failed to commit transaction", "commitTransaction") })
220
290
  })
221
291
  }
222
292
  get rollback() {
223
293
  return Effect.tryPromise({
224
294
  try: () => (this.sdk as Libsql.Transaction).rollback(),
225
- catch: (cause) => new SqlError({ cause, message: "Failed to rollback transaction" })
295
+ catch: (cause) =>
296
+ new SqlError({ reason: classifyError(cause, "Failed to rollback transaction", "rollbackTransaction") })
226
297
  })
227
298
  }
228
299
  }
@@ -294,35 +365,39 @@ export const make = (
294
365
  })
295
366
 
296
367
  /**
368
+ * Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
369
+ *
297
370
  * @category layers
298
- * @since 1.0.0
371
+ * @since 4.0.0
299
372
  */
300
373
  export const layerConfig: (
301
374
  config: Config.Wrap<LibsqlClientConfig>
302
375
  ) => Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError> = (
303
376
  config: Config.Wrap<LibsqlClientConfig>
304
377
  ): Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError> =>
305
- Layer.effectServices(
306
- Config.unwrap(config).asEffect().pipe(
378
+ Layer.effectContext(
379
+ Config.unwrap(config).pipe(
307
380
  Effect.flatMap(make),
308
381
  Effect.map((client) =>
309
- ServiceMap.make(LibsqlClient, client).pipe(
310
- ServiceMap.add(Client.SqlClient, client)
382
+ Context.make(LibsqlClient, client).pipe(
383
+ Context.add(Client.SqlClient, client)
311
384
  )
312
385
  )
313
386
  )
314
387
  ).pipe(Layer.provide(Reactivity.layer))
315
388
 
316
389
  /**
390
+ * Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
391
+ *
317
392
  * @category layers
318
- * @since 1.0.0
393
+ * @since 4.0.0
319
394
  */
320
395
  export const layer = (
321
396
  config: LibsqlClientConfig
322
397
  ): Layer.Layer<LibsqlClient | Client.SqlClient> =>
323
- Layer.effectServices(
398
+ Layer.effectContext(
324
399
  Effect.map(make(config), (client) =>
325
- ServiceMap.make(LibsqlClient, client).pipe(
326
- ServiceMap.add(Client.SqlClient, client)
400
+ Context.make(LibsqlClient, client).pipe(
401
+ Context.add(Client.SqlClient, client)
327
402
  ))
328
403
  ).pipe(Layer.provide(Reactivity.layer))
@@ -1,5 +1,36 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL migration support for Effect SQL applications.
3
+ *
4
+ * This module adapts the shared SQL migrator to libSQL and Turso databases. It
5
+ * re-exports the common migration loaders and errors, then provides {@link run}
6
+ * and {@link layer} helpers that apply pending migrations with the current
7
+ * libSQL-backed `SqlClient`.
8
+ *
9
+ * **Mental model**
10
+ *
11
+ * Migrations are numbered operations loaded from files, records, or bundler
12
+ * glob results. The runner ensures the migrations table exists, reads the
13
+ * latest recorded id, and runs only migrations with a greater id through the
14
+ * configured libSQL client.
15
+ *
16
+ * **Common tasks**
17
+ *
18
+ * Use {@link run} during application startup, deployment, or setup scripts when
19
+ * migrations should be executed explicitly. Use {@link layer} in a layer graph
20
+ * when dependent services should be acquired only after the schema is prepared.
21
+ * Reuse the shared loaders from this module for file-based or in-memory
22
+ * migration definitions.
23
+ *
24
+ * **Gotchas**
25
+ *
26
+ * libSQL uses SQLite-compatible SQL, so avoid dialect features unsupported by
27
+ * libSQL or the configured Turso deployment. Remote Turso databases, local
28
+ * `file:` databases, and embedded replicas can observe different state until
29
+ * replication catches up. Run schema-changing migrations against the intended
30
+ * writer, coordinate concurrent migrators, and do not rely on
31
+ * `schemaDirectory` for libSQL schema dumps.
32
+ *
33
+ * @since 4.0.0
3
34
  */
4
35
  import type * as Effect from "effect/Effect"
5
36
  import * as Layer from "effect/Layer"
@@ -8,13 +39,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
8
39
  import type { SqlError } from "effect/unstable/sql/SqlError"
9
40
 
10
41
  /**
11
- * @since 1.0.0
42
+ * @since 4.0.0
12
43
  */
13
44
  export * from "effect/unstable/sql/Migrator"
14
45
 
15
46
  /**
16
- * @category constructor
17
- * @since 1.0.0
47
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
48
+ *
49
+ * @category constructors
50
+ * @since 4.0.0
18
51
  */
19
52
  export const run: <R2 = never>(
20
53
  options: Migrator.MigratorOptions<R2>
@@ -25,8 +58,10 @@ export const run: <R2 = never>(
25
58
  > = Migrator.make({})
26
59
 
27
60
  /**
28
- * @category constructor
29
- * @since 1.0.0
61
+ * Creates a layer that runs the configured SQL migrations during layer construction.
62
+ *
63
+ * @category constructors
64
+ * @since 4.0.0
30
65
  */
31
66
  export const layer = <R>(
32
67
  options: Migrator.MigratorOptions<R>
package/src/index.ts CHANGED
@@ -1,15 +1,15 @@
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
+ * @since 4.0.0
9
9
  */
10
10
  export * as LibsqlClient from "./LibsqlClient.ts"
11
11
 
12
12
  /**
13
- * @since 1.0.0
13
+ * @since 4.0.0
14
14
  */
15
15
  export * as LibsqlMigrator from "./LibsqlMigrator.ts"