@effect/sql-libsql 4.0.0-beta.1 → 4.0.0-beta.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@effect/sql-libsql`
2
2
 
3
- An `@effect/sql` implementation using the `@libsql/client` library.
3
+ An Effect SQL implementation using the `@libsql/client` library.
4
4
 
5
5
  ## Documentation
6
6
 
@@ -1,51 +1,76 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL adapter for Effect SQL, backed by `@libsql/client`.
3
+ *
4
+ * This module provides a {@link LibsqlClient} and the generic SQL client
5
+ * service for `@libsql/client`. It uses Effect SQL's SQLite compiler, supports
6
+ * managed SDK clients or caller-owned live clients, classifies libSQL and
7
+ * SQLite failures as `SqlError`s, and provides transaction support with
8
+ * savepoints. Streaming queries are not implemented by this driver.
9
+ *
10
+ * @since 4.0.0
3
11
  */
4
12
  import * as Libsql from "@libsql/client";
5
13
  import * as Config from "effect/Config";
14
+ import * as Context from "effect/Context";
6
15
  import * as Effect from "effect/Effect";
7
16
  import * as Layer from "effect/Layer";
8
17
  import * as Redacted from "effect/Redacted";
9
18
  import * as Scope from "effect/Scope";
10
- import * as ServiceMap from "effect/ServiceMap";
11
19
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
12
20
  import * as Client from "effect/unstable/sql/SqlClient";
13
21
  /**
14
- * @category type ids
15
- * @since 1.0.0
22
+ * Runtime type identifier used to mark `LibsqlClient` values.
23
+ *
24
+ * @category type IDs
25
+ * @since 4.0.0
16
26
  */
17
27
  export declare const TypeId: TypeId;
18
28
  /**
19
- * @category type ids
20
- * @since 1.0.0
29
+ * Type-level identifier used to mark `LibsqlClient` values.
30
+ *
31
+ * @category type IDs
32
+ * @since 4.0.0
21
33
  */
22
34
  export type TypeId = "~@effect/sql-libsql/LibsqlClient";
23
35
  /**
36
+ * libSQL-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
37
+ *
24
38
  * @category models
25
- * @since 1.0.0
39
+ * @since 4.0.0
26
40
  */
27
41
  export interface LibsqlClient extends Client.SqlClient {
28
42
  readonly [TypeId]: TypeId;
29
43
  readonly config: LibsqlClientConfig;
30
44
  }
31
45
  /**
32
- * @category tags
33
- * @since 1.0.0
46
+ * Service tag for the libSQL client service.
47
+ *
48
+ * **When to use**
49
+ *
50
+ * Use to access or provide a libSQL client through the Effect context.
51
+ *
52
+ * @category services
53
+ * @since 4.0.0
34
54
  */
35
- export declare const LibsqlClient: ServiceMap.Service<LibsqlClient, LibsqlClient>;
55
+ export declare const LibsqlClient: Context.Service<LibsqlClient, LibsqlClient>;
36
56
  /**
57
+ * Configuration for a libSQL client, either by supplying connection options or an existing live libSQL client.
58
+ *
37
59
  * @category models
38
- * @since 1.0.0
60
+ * @since 4.0.0
39
61
  */
40
62
  export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live;
41
63
  /**
42
- * @category models
43
- * @since 1.0.0
64
+ * Namespace containing the configuration variants for `LibsqlClient`.
65
+ *
66
+ * @since 4.0.0
44
67
  */
45
68
  export declare namespace LibsqlClientConfig {
46
69
  /**
70
+ * Shared libSQL client options for span attributes and query/result name transformations.
71
+ *
47
72
  * @category models
48
- * @since 1.0.0
73
+ * @since 4.0.0
49
74
  */
50
75
  interface Base {
51
76
  readonly spanAttributes?: Record<string, unknown> | undefined;
@@ -53,11 +78,16 @@ export declare namespace LibsqlClientConfig {
53
78
  readonly transformQueryNames?: ((str: string) => string) | undefined;
54
79
  }
55
80
  /**
81
+ * Connection-based libSQL configuration used to create a managed client, including URL, credentials, sync, integer mode, TLS, and concurrency options.
82
+ *
56
83
  * @category models
57
- * @since 1.0.0
84
+ * @since 4.0.0
58
85
  */
59
86
  interface Full extends Base {
60
- /** The database URL.
87
+ /**
88
+ * The database URL.
89
+ *
90
+ * **Details**
61
91
  *
62
92
  * The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
63
93
  * please refer to the project README:
@@ -73,12 +103,18 @@ export declare namespace LibsqlClientConfig {
73
103
  readonly syncUrl?: string | URL | undefined;
74
104
  /** Sync interval in seconds. */
75
105
  readonly syncInterval?: number | undefined;
76
- /** Enables or disables TLS for `libsql:` URLs.
106
+ /**
107
+ * Enables or disables TLS for `libsql:` URLs.
108
+ *
109
+ * **Details**
77
110
  *
78
111
  * By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
79
112
  */
80
113
  readonly tls?: boolean | undefined;
81
- /** How to convert SQLite integers to JavaScript values:
114
+ /**
115
+ * How to convert SQLite integers to JavaScript values.
116
+ *
117
+ * **Details**
82
118
  *
83
119
  * - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
84
120
  * `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
@@ -88,7 +124,10 @@ export declare namespace LibsqlClientConfig {
88
124
  * - `"string"`: returns SQLite integers as strings.
89
125
  */
90
126
  readonly intMode?: "number" | "bigint" | "string" | undefined;
91
- /** Concurrency limit.
127
+ /**
128
+ * Concurrency limit.
129
+ *
130
+ * **Details**
92
131
  *
93
132
  * By default, the client performs up to 20 concurrent requests. You can set this option to a higher
94
133
  * number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
@@ -96,26 +135,34 @@ export declare namespace LibsqlClientConfig {
96
135
  readonly concurrency?: number | undefined;
97
136
  }
98
137
  /**
138
+ * Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
139
+ *
99
140
  * @category models
100
- * @since 1.0.0
141
+ * @since 4.0.0
101
142
  */
102
143
  interface Live extends Base {
103
144
  readonly liveClient: Libsql.Client;
104
145
  }
105
146
  }
106
147
  /**
107
- * @category constructor
108
- * @since 1.0.0
148
+ * 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.
149
+ *
150
+ * @category constructors
151
+ * @since 4.0.0
109
152
  */
110
153
  export declare const make: (options: LibsqlClientConfig) => Effect.Effect<LibsqlClient, never, Scope.Scope | Reactivity.Reactivity>;
111
154
  /**
155
+ * Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
156
+ *
112
157
  * @category layers
113
- * @since 1.0.0
158
+ * @since 4.0.0
114
159
  */
115
160
  export declare const layerConfig: (config: Config.Wrap<LibsqlClientConfig>) => Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError>;
116
161
  /**
162
+ * Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
163
+ *
117
164
  * @category layers
118
- * @since 1.0.0
165
+ * @since 4.0.0
119
166
  */
120
167
  export declare const layer: (config: LibsqlClientConfig) => Layer.Layer<LibsqlClient | Client.SqlClient>;
121
168
  //# 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,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAOvD;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAA2C,CAAA;AAEhE;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,kCAAkC,CAAA;AAEvD;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,SAAS;IACpD,QAAQ,CAAC,CAAC,MAAM,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,GAAG,GAAG,SAAS,CAAA;QAC3C,gCAAgC;QAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC1C;;;;;;WAMG;QACH,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;QAClC;;;;;;;;;;;WAWG;QACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;QAC7D;;;;;;;WAOG;QACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC1C;IAED;;;;;OAKG;IACH,UAAiB,IAAK,SAAQ,IAAI;QAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAA;KACnC;CACF;AAQD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,YACN,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAiKrE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,CACxB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,KACpC,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAY3B,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,WACR,kBAAkB,KACzB,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAML,CAAA"}
@@ -1,34 +1,57 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL adapter for Effect SQL, backed by `@libsql/client`.
3
+ *
4
+ * This module provides a {@link LibsqlClient} and the generic SQL client
5
+ * service for `@libsql/client`. It uses Effect SQL's SQLite compiler, supports
6
+ * managed SDK clients or caller-owned live clients, classifies libSQL and
7
+ * SQLite failures as `SqlError`s, and provides transaction support with
8
+ * savepoints. Streaming queries are not implemented by this driver.
9
+ *
10
+ * @since 4.0.0
3
11
  */
4
12
  import * as Libsql from "@libsql/client";
5
13
  import * as Config from "effect/Config";
14
+ import * as Context from "effect/Context";
6
15
  import * as Effect from "effect/Effect";
7
16
  import * as Layer from "effect/Layer";
8
17
  import * as Option from "effect/Option";
9
18
  import * as Redacted from "effect/Redacted";
10
19
  import * as Scope from "effect/Scope";
11
- import * as ServiceMap from "effect/ServiceMap";
20
+ import * as Semaphore from "effect/Semaphore";
12
21
  import * as Stream from "effect/Stream";
13
22
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
14
23
  import * as Client from "effect/unstable/sql/SqlClient";
15
- import { SqlError } from "effect/unstable/sql/SqlError";
24
+ import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
16
25
  import * as Statement from "effect/unstable/sql/Statement";
17
26
  const ATTR_DB_SYSTEM_NAME = "db.system.name";
27
+ const classifyError = (cause, message, operation) => classifySqliteError(cause, {
28
+ message,
29
+ operation
30
+ });
18
31
  /**
19
- * @category type ids
20
- * @since 1.0.0
32
+ * Runtime type identifier used to mark `LibsqlClient` values.
33
+ *
34
+ * @category type IDs
35
+ * @since 4.0.0
21
36
  */
22
37
  export const TypeId = "~@effect/sql-libsql/LibsqlClient";
23
38
  /**
24
- * @category tags
25
- * @since 1.0.0
39
+ * Service tag for the libSQL client service.
40
+ *
41
+ * **When to use**
42
+ *
43
+ * Use to access or provide a libSQL client through the Effect context.
44
+ *
45
+ * @category services
46
+ * @since 4.0.0
26
47
  */
27
- export const LibsqlClient = /*#__PURE__*/ServiceMap.Service("@effect/sql-libsql/LibsqlClient");
28
- const LibsqlTransaction = /*#__PURE__*/ServiceMap.Service("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
48
+ export const LibsqlClient = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient");
49
+ const LibsqlTransaction = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
29
50
  /**
30
- * @category constructor
31
- * @since 1.0.0
51
+ * 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.
52
+ *
53
+ * @category constructors
54
+ * @since 4.0.0
32
55
  */
33
56
  export const make = options => Effect.gen(function* () {
34
57
  const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
@@ -46,8 +69,7 @@ export const make = options => Effect.gen(function* () {
46
69
  args: params
47
70
  }),
48
71
  catch: cause => new SqlError({
49
- cause,
50
- message: "Failed to execute statement"
72
+ reason: classifyError(cause, "Failed to execute statement", "execute")
51
73
  })
52
74
  }), results => results.rows);
53
75
  }
@@ -58,8 +80,7 @@ export const make = options => Effect.gen(function* () {
58
80
  args: params
59
81
  }),
60
82
  catch: cause => new SqlError({
61
- cause,
62
- message: "Failed to execute statement"
83
+ reason: classifyError(cause, "Failed to execute statement", "execute")
63
84
  })
64
85
  });
65
86
  }
@@ -72,6 +93,9 @@ export const make = options => Effect.gen(function* () {
72
93
  executeValues(sql, params) {
73
94
  return Effect.map(this.run(sql, params), rows => rows.map(row => Array.from(row)));
74
95
  }
96
+ executeValuesUnprepared(sql, params) {
97
+ return this.executeValues(sql, params);
98
+ }
75
99
  executeUnprepared(sql, params, transformRows) {
76
100
  return this.execute(sql, params, transformRows);
77
101
  }
@@ -82,8 +106,7 @@ export const make = options => Effect.gen(function* () {
82
106
  return Effect.map(Effect.tryPromise({
83
107
  try: () => this.sdk.transaction("write"),
84
108
  catch: cause => new SqlError({
85
- cause,
86
- message: "Failed to begin transaction"
109
+ reason: classifyError(cause, "Failed to begin transaction", "beginTransaction")
87
110
  })
88
111
  }), tx => new LibsqlConnectionImpl(tx));
89
112
  }
@@ -91,8 +114,7 @@ export const make = options => Effect.gen(function* () {
91
114
  return Effect.tryPromise({
92
115
  try: () => this.sdk.commit(),
93
116
  catch: cause => new SqlError({
94
- cause,
95
- message: "Failed to commit transaction"
117
+ reason: classifyError(cause, "Failed to commit transaction", "commitTransaction")
96
118
  })
97
119
  });
98
120
  }
@@ -100,8 +122,7 @@ export const make = options => Effect.gen(function* () {
100
122
  return Effect.tryPromise({
101
123
  try: () => this.sdk.rollback(),
102
124
  catch: cause => new SqlError({
103
- cause,
104
- message: "Failed to rollback transaction"
125
+ reason: classifyError(cause, "Failed to rollback transaction", "rollbackTransaction")
105
126
  })
106
127
  });
107
128
  }
@@ -113,7 +134,7 @@ export const make = options => Effect.gen(function* () {
113
134
  url: options.url.toString(),
114
135
  syncUrl: options.syncUrl?.toString()
115
136
  })), sdk => Effect.sync(() => sdk.close())), sdk => new LibsqlConnectionImpl(sdk));
116
- const semaphore = yield* Effect.makeSemaphore(1);
137
+ const semaphore = yield* Semaphore.make(1);
117
138
  const withTransaction = Client.makeWithTransaction({
118
139
  transactionService: LibsqlTransaction,
119
140
  spanAttributes,
@@ -148,13 +169,17 @@ export const make = options => Effect.gen(function* () {
148
169
  });
149
170
  });
150
171
  /**
172
+ * Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
173
+ *
151
174
  * @category layers
152
- * @since 1.0.0
175
+ * @since 4.0.0
153
176
  */
154
- 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));
177
+ 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));
155
178
  /**
179
+ * Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
180
+ *
156
181
  * @category layers
157
- * @since 1.0.0
182
+ * @since 4.0.0
158
183
  */
159
- 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));
184
+ 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));
160
185
  //# sourceMappingURL=LibsqlClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LibsqlClient.js","names":["Libsql","Config","Effect","Layer","Option","Redacted","Scope","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","makeSemaphore","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,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,MAAM,MAA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AAC,EACpBhB,MAAM,CAACoC,GAAG,CAAEwE,MAAM,IAChBvG,UAAU,CAACW,IAAI,CAACH,YAAY,EAAE+F,MAAM,CAAC,CAACD,IAAI,CACxCtG,UAAU,CAACwG,GAAG,CAACrG,MAAM,CAACsG,SAAS,EAAEF,MAAM,CAAC,CACzC,CACF,CACF,CACF,CAACD,IAAI,CAAC1G,KAAK,CAAC8G,OAAO,CAACxG,UAAU,CAACyG,KAAK,CAAC,CAAC;AAEzC;;;;AAIA,OAAO,MAAMA,KAAK,GAChBV,MAA0B,IAE1BrG,KAAK,CAACuG,cAAc,CAClBxG,MAAM,CAACoC,GAAG,CAACpB,IAAI,CAACsF,MAAM,CAAC,EAAGM,MAAM,IAC9BvG,UAAU,CAACW,IAAI,CAACH,YAAY,EAAE+F,MAAM,CAAC,CAACD,IAAI,CACxCtG,UAAU,CAACwG,GAAG,CAACrG,MAAM,CAACsG,SAAS,EAAEF,MAAM,CAAC,CACzC,CAAC,CACL,CAACD,IAAI,CAAC1G,KAAK,CAAC8G,OAAO,CAACxG,UAAU,CAACyG,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","executeValuesUnprepared","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;;;;;;;;;;;AAWA,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,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SAASC,mBAAmB,EAAEC,QAAQ,QAAQ,8BAA8B;AAC5E,OAAO,KAAKC,SAAS,MAAM,+BAA+B;AAE1D,MAAMC,mBAAmB,GAAG,gBAAgB;AAE5C,MAAMC,aAAa,GAAGA,CAACC,KAAc,EAAEC,OAAe,EAAEC,SAAiB,KACvEP,mBAAmB,CAACK,KAAK,EAAE;EAAEC,OAAO;EAAEC;AAAS,CAAE,CAAC;AAEpD;;;;;;AAMA,OAAO,MAAMC,MAAM,GAAW,kCAAkC;AAqBhE;;;;;;;;;;AAUA,OAAO,MAAMC,YAAY,gBAAGnB,OAAO,CAACoB,OAAO,CAAe,iCAAiC,CAAC;AAE5F,MAAMC,iBAAiB,gBAAGrB,OAAO,CAACoB,OAAO,CACvC,mDAAmD,CACpD;AAuGD;;;;;;AAMA,OAAO,MAAME,IAAI,GACfC,OAA2B,IAE3Bt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F,CACF,CACF,CAACD,IAAI,CAAC7G,KAAK,CAACiH,OAAO,CAAC3G,UAAU,CAAC4G,KAAK,CAAC,CAAC;AAEzC;;;;;;AAMA,OAAO,MAAMA,KAAK,GAChBT,MAA0B,IAE1BzG,KAAK,CAAC2G,aAAa,CACjB5G,MAAM,CAACyC,GAAG,CAACpB,IAAI,CAACqF,MAAM,CAAC,EAAGK,MAAM,IAC9BhH,OAAO,CAACsB,IAAI,CAACH,YAAY,EAAE6F,MAAM,CAAC,CAACD,IAAI,CACrC/G,OAAO,CAACiH,GAAG,CAACxG,MAAM,CAACyG,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAACD,IAAI,CAAC7G,KAAK,CAACiH,OAAO,CAAC3G,UAAU,CAAC4G,KAAK,CAAC,CAAC","ignoreList":[]}
@@ -1,5 +1,14 @@
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. It re-exports the
5
+ * common migration loaders and errors, then provides {@link run} and
6
+ * {@link layer} helpers that apply pending migrations with the current
7
+ * libSQL-backed `SqlClient`. `run` returns the applied migration IDs and names,
8
+ * while `layer` runs migrations during layer construction and provides no
9
+ * services.
10
+ *
11
+ * @since 4.0.0
3
12
  */
4
13
  import type * as Effect from "effect/Effect";
5
14
  import * as Layer from "effect/Layer";
@@ -7,17 +16,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
7
16
  import type * as Client from "effect/unstable/sql/SqlClient";
8
17
  import type { SqlError } from "effect/unstable/sql/SqlError";
9
18
  /**
10
- * @since 1.0.0
19
+ * @since 4.0.0
11
20
  */
12
21
  export * from "effect/unstable/sql/Migrator";
13
22
  /**
14
- * @category constructor
15
- * @since 1.0.0
23
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
24
+ *
25
+ * @category constructors
26
+ * @since 4.0.0
16
27
  */
17
28
  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
29
  /**
19
- * @category constructor
20
- * @since 1.0.0
30
+ * Creates a layer that runs the configured SQL migrations during layer construction.
31
+ *
32
+ * @category constructors
33
+ * @since 4.0.0
21
34
  */
22
35
  export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
23
36
  //# 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;;;;;;;;;;;GAWG;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,WACZ,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":"AAaA,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,17 +1,17 @@
1
1
  {
2
2
  "name": "@effect/sql-libsql",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.100",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A libSQL toolkit for Effect",
7
7
  "homepage": "https://effect.website",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/Effect-TS/effect-smol.git",
10
+ "url": "https://github.com/Effect-TS/effect.git",
11
11
  "directory": "packages/sql/libsql"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/Effect-TS/effect-smol/issues"
14
+ "url": "https://github.com/Effect-TS/effect/issues"
15
15
  },
16
16
  "tags": [
17
17
  "typescript",
@@ -45,19 +45,18 @@
45
45
  "provenance": true
46
46
  },
47
47
  "devDependencies": {
48
- "testcontainers": "^11.11.0",
49
- "effect": "^4.0.0-beta.1"
48
+ "testcontainers": "^11.14.0",
49
+ "effect": "^4.0.0-beta.100"
50
50
  },
51
51
  "peerDependencies": {
52
- "effect": "^4.0.0-beta.1"
52
+ "effect": "^4.0.0-beta.100"
53
53
  },
54
54
  "dependencies": {
55
- "@libsql/client": "^0.17.0"
55
+ "@libsql/client": "^0.17.4"
56
56
  },
57
57
  "scripts": {
58
58
  "codegen": "effect-utils codegen",
59
59
  "build": "tsc -b tsconfig.json && pnpm babel",
60
- "build:tsgo": "tsgo -b tsconfig.json && pnpm babel",
61
60
  "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
62
61
  "check": "tsc -b tsconfig.json",
63
62
  "test": "vitest",
@@ -1,38 +1,56 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * libSQL adapter for Effect SQL, backed by `@libsql/client`.
3
+ *
4
+ * This module provides a {@link LibsqlClient} and the generic SQL client
5
+ * service for `@libsql/client`. It uses Effect SQL's SQLite compiler, supports
6
+ * managed SDK clients or caller-owned live clients, classifies libSQL and
7
+ * SQLite failures as `SqlError`s, and provides transaction support with
8
+ * savepoints. Streaming queries are not implemented by this driver.
9
+ *
10
+ * @since 4.0.0
3
11
  */
4
12
  import * as Libsql from "@libsql/client"
5
13
  import * as Config from "effect/Config"
14
+ import * as Context from "effect/Context"
6
15
  import * as Effect from "effect/Effect"
7
16
  import * as Layer from "effect/Layer"
8
17
  import * as Option from "effect/Option"
9
18
  import * as Redacted from "effect/Redacted"
10
19
  import * as Scope from "effect/Scope"
11
- import * as ServiceMap from "effect/ServiceMap"
20
+ import * as Semaphore from "effect/Semaphore"
12
21
  import * as Stream from "effect/Stream"
13
22
  import * as Reactivity from "effect/unstable/reactivity/Reactivity"
14
23
  import * as Client from "effect/unstable/sql/SqlClient"
15
24
  import type { Connection } from "effect/unstable/sql/SqlConnection"
16
- import { SqlError } from "effect/unstable/sql/SqlError"
25
+ import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
17
26
  import * as Statement from "effect/unstable/sql/Statement"
18
27
 
19
28
  const ATTR_DB_SYSTEM_NAME = "db.system.name"
20
29
 
30
+ const classifyError = (cause: unknown, message: string, operation: string) =>
31
+ classifySqliteError(cause, { message, operation })
32
+
21
33
  /**
22
- * @category type ids
23
- * @since 1.0.0
34
+ * Runtime type identifier used to mark `LibsqlClient` values.
35
+ *
36
+ * @category type IDs
37
+ * @since 4.0.0
24
38
  */
25
39
  export const TypeId: TypeId = "~@effect/sql-libsql/LibsqlClient"
26
40
 
27
41
  /**
28
- * @category type ids
29
- * @since 1.0.0
42
+ * Type-level identifier used to mark `LibsqlClient` values.
43
+ *
44
+ * @category type IDs
45
+ * @since 4.0.0
30
46
  */
31
47
  export type TypeId = "~@effect/sql-libsql/LibsqlClient"
32
48
 
33
49
  /**
50
+ * libSQL-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
51
+ *
34
52
  * @category models
35
- * @since 1.0.0
53
+ * @since 4.0.0
36
54
  */
37
55
  export interface LibsqlClient extends Client.SqlClient {
38
56
  readonly [TypeId]: TypeId
@@ -40,29 +58,40 @@ export interface LibsqlClient extends Client.SqlClient {
40
58
  }
41
59
 
42
60
  /**
43
- * @category tags
44
- * @since 1.0.0
61
+ * Service tag for the libSQL client service.
62
+ *
63
+ * **When to use**
64
+ *
65
+ * Use to access or provide a libSQL client through the Effect context.
66
+ *
67
+ * @category services
68
+ * @since 4.0.0
45
69
  */
46
- export const LibsqlClient = ServiceMap.Service<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
70
+ export const LibsqlClient = Context.Service<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
47
71
 
48
- const LibsqlTransaction = ServiceMap.Service<readonly [LibsqlConnection, counter: number]>(
72
+ const LibsqlTransaction = Context.Service<readonly [LibsqlConnection, counter: number]>(
49
73
  "@effect/sql-libsql/LibsqlClient/LibsqlTransaction"
50
74
  )
51
75
 
52
76
  /**
77
+ * Configuration for a libSQL client, either by supplying connection options or an existing live libSQL client.
78
+ *
53
79
  * @category models
54
- * @since 1.0.0
80
+ * @since 4.0.0
55
81
  */
56
82
  export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live
57
83
 
58
84
  /**
59
- * @category models
60
- * @since 1.0.0
85
+ * Namespace containing the configuration variants for `LibsqlClient`.
86
+ *
87
+ * @since 4.0.0
61
88
  */
62
89
  export declare namespace LibsqlClientConfig {
63
90
  /**
91
+ * Shared libSQL client options for span attributes and query/result name transformations.
92
+ *
64
93
  * @category models
65
- * @since 1.0.0
94
+ * @since 4.0.0
66
95
  */
67
96
  export interface Base {
68
97
  readonly spanAttributes?: Record<string, unknown> | undefined
@@ -71,11 +100,16 @@ export declare namespace LibsqlClientConfig {
71
100
  }
72
101
 
73
102
  /**
103
+ * Connection-based libSQL configuration used to create a managed client, including URL, credentials, sync, integer mode, TLS, and concurrency options.
104
+ *
74
105
  * @category models
75
- * @since 1.0.0
106
+ * @since 4.0.0
76
107
  */
77
108
  export interface Full extends Base {
78
- /** The database URL.
109
+ /**
110
+ * The database URL.
111
+ *
112
+ * **Details**
79
113
  *
80
114
  * The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
81
115
  * please refer to the project README:
@@ -91,12 +125,18 @@ export declare namespace LibsqlClientConfig {
91
125
  readonly syncUrl?: string | URL | undefined
92
126
  /** Sync interval in seconds. */
93
127
  readonly syncInterval?: number | undefined
94
- /** Enables or disables TLS for `libsql:` URLs.
128
+ /**
129
+ * Enables or disables TLS for `libsql:` URLs.
130
+ *
131
+ * **Details**
95
132
  *
96
133
  * By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
97
134
  */
98
135
  readonly tls?: boolean | undefined
99
- /** How to convert SQLite integers to JavaScript values:
136
+ /**
137
+ * How to convert SQLite integers to JavaScript values.
138
+ *
139
+ * **Details**
100
140
  *
101
141
  * - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
102
142
  * `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
@@ -106,7 +146,10 @@ export declare namespace LibsqlClientConfig {
106
146
  * - `"string"`: returns SQLite integers as strings.
107
147
  */
108
148
  readonly intMode?: "number" | "bigint" | "string" | undefined
109
- /** Concurrency limit.
149
+ /**
150
+ * Concurrency limit.
151
+ *
152
+ * **Details**
110
153
  *
111
154
  * By default, the client performs up to 20 concurrent requests. You can set this option to a higher
112
155
  * number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
@@ -115,8 +158,10 @@ export declare namespace LibsqlClientConfig {
115
158
  }
116
159
 
117
160
  /**
161
+ * Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
162
+ *
118
163
  * @category models
119
- * @since 1.0.0
164
+ * @since 4.0.0
120
165
  */
121
166
  export interface Live extends Base {
122
167
  readonly liveClient: Libsql.Client
@@ -130,8 +175,10 @@ interface LibsqlConnection extends Connection {
130
175
  }
131
176
 
132
177
  /**
133
- * @category constructor
134
- * @since 1.0.0
178
+ * 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.
179
+ *
180
+ * @category constructors
181
+ * @since 4.0.0
135
182
  */
136
183
  export const make = (
137
184
  options: LibsqlClientConfig
@@ -162,7 +209,7 @@ export const make = (
162
209
  return Effect.map(
163
210
  Effect.tryPromise({
164
211
  try: () => this.sdk.execute({ sql, args: params as Array<any> }),
165
- catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
212
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
166
213
  }),
167
214
  (results) => results.rows
168
215
  )
@@ -174,7 +221,7 @@ export const make = (
174
221
  ) {
175
222
  return Effect.tryPromise({
176
223
  try: () => this.sdk.execute({ sql, args: params as Array<any> }),
177
- catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
224
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
178
225
  })
179
226
  }
180
227
 
@@ -193,6 +240,9 @@ export const make = (
193
240
  executeValues(sql: string, params: ReadonlyArray<unknown>) {
194
241
  return Effect.map(this.run(sql, params), (rows) => rows.map((row) => Array.from(row) as Array<any>))
195
242
  }
243
+ executeValuesUnprepared(sql: string, params: ReadonlyArray<unknown>) {
244
+ return this.executeValues(sql, params)
245
+ }
196
246
  executeUnprepared(
197
247
  sql: string,
198
248
  params: ReadonlyArray<unknown>,
@@ -207,7 +257,8 @@ export const make = (
207
257
  return Effect.map(
208
258
  Effect.tryPromise({
209
259
  try: () => (this.sdk as Libsql.Client).transaction("write"),
210
- catch: (cause) => new SqlError({ cause, message: "Failed to begin transaction" })
260
+ catch: (cause) =>
261
+ new SqlError({ reason: classifyError(cause, "Failed to begin transaction", "beginTransaction") })
211
262
  }),
212
263
  (tx) => new LibsqlConnectionImpl(tx)
213
264
  )
@@ -215,13 +266,15 @@ export const make = (
215
266
  get commit() {
216
267
  return Effect.tryPromise({
217
268
  try: () => (this.sdk as Libsql.Transaction).commit(),
218
- catch: (cause) => new SqlError({ cause, message: "Failed to commit transaction" })
269
+ catch: (cause) =>
270
+ new SqlError({ reason: classifyError(cause, "Failed to commit transaction", "commitTransaction") })
219
271
  })
220
272
  }
221
273
  get rollback() {
222
274
  return Effect.tryPromise({
223
275
  try: () => (this.sdk as Libsql.Transaction).rollback(),
224
- catch: (cause) => new SqlError({ cause, message: "Failed to rollback transaction" })
276
+ catch: (cause) =>
277
+ new SqlError({ reason: classifyError(cause, "Failed to rollback transaction", "rollbackTransaction") })
225
278
  })
226
279
  }
227
280
  }
@@ -249,7 +302,7 @@ export const make = (
249
302
  ),
250
303
  (sdk) => new LibsqlConnectionImpl(sdk)
251
304
  )
252
- const semaphore = yield* Effect.makeSemaphore(1)
305
+ const semaphore = yield* Semaphore.make(1)
253
306
 
254
307
  const withTransaction = Client.makeWithTransaction({
255
308
  transactionService: LibsqlTransaction,
@@ -293,35 +346,39 @@ export const make = (
293
346
  })
294
347
 
295
348
  /**
349
+ * Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
350
+ *
296
351
  * @category layers
297
- * @since 1.0.0
352
+ * @since 4.0.0
298
353
  */
299
354
  export const layerConfig: (
300
355
  config: Config.Wrap<LibsqlClientConfig>
301
356
  ) => Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError> = (
302
357
  config: Config.Wrap<LibsqlClientConfig>
303
358
  ): Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError> =>
304
- Layer.effectServices(
305
- Config.unwrap(config).asEffect().pipe(
359
+ Layer.effectContext(
360
+ Config.unwrap(config).pipe(
306
361
  Effect.flatMap(make),
307
362
  Effect.map((client) =>
308
- ServiceMap.make(LibsqlClient, client).pipe(
309
- ServiceMap.add(Client.SqlClient, client)
363
+ Context.make(LibsqlClient, client).pipe(
364
+ Context.add(Client.SqlClient, client)
310
365
  )
311
366
  )
312
367
  )
313
368
  ).pipe(Layer.provide(Reactivity.layer))
314
369
 
315
370
  /**
371
+ * Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
372
+ *
316
373
  * @category layers
317
- * @since 1.0.0
374
+ * @since 4.0.0
318
375
  */
319
376
  export const layer = (
320
377
  config: LibsqlClientConfig
321
378
  ): Layer.Layer<LibsqlClient | Client.SqlClient> =>
322
- Layer.effectServices(
379
+ Layer.effectContext(
323
380
  Effect.map(make(config), (client) =>
324
- ServiceMap.make(LibsqlClient, client).pipe(
325
- ServiceMap.add(Client.SqlClient, client)
381
+ Context.make(LibsqlClient, client).pipe(
382
+ Context.add(Client.SqlClient, client)
326
383
  ))
327
384
  ).pipe(Layer.provide(Reactivity.layer))
@@ -1,5 +1,14 @@
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. It re-exports the
5
+ * common migration loaders and errors, then provides {@link run} and
6
+ * {@link layer} helpers that apply pending migrations with the current
7
+ * libSQL-backed `SqlClient`. `run` returns the applied migration IDs and names,
8
+ * while `layer` runs migrations during layer construction and provides no
9
+ * services.
10
+ *
11
+ * @since 4.0.0
3
12
  */
4
13
  import type * as Effect from "effect/Effect"
5
14
  import * as Layer from "effect/Layer"
@@ -8,13 +17,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
8
17
  import type { SqlError } from "effect/unstable/sql/SqlError"
9
18
 
10
19
  /**
11
- * @since 1.0.0
20
+ * @since 4.0.0
12
21
  */
13
22
  export * from "effect/unstable/sql/Migrator"
14
23
 
15
24
  /**
16
- * @category constructor
17
- * @since 1.0.0
25
+ * Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
26
+ *
27
+ * @category constructors
28
+ * @since 4.0.0
18
29
  */
19
30
  export const run: <R2 = never>(
20
31
  options: Migrator.MigratorOptions<R2>
@@ -25,8 +36,10 @@ export const run: <R2 = never>(
25
36
  > = Migrator.make({})
26
37
 
27
38
  /**
28
- * @category constructor
29
- * @since 1.0.0
39
+ * Creates a layer that runs the configured SQL migrations during layer construction.
40
+ *
41
+ * @category constructors
42
+ * @since 4.0.0
30
43
  */
31
44
  export const layer = <R>(
32
45
  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"