@effect/sql-libsql 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.
- package/dist/LibsqlClient.d.ts +75 -23
- package/dist/LibsqlClient.d.ts.map +1 -1
- package/dist/LibsqlClient.js +50 -24
- package/dist/LibsqlClient.js.map +1 -1
- package/dist/LibsqlMigrator.d.ts +30 -6
- package/dist/LibsqlMigrator.d.ts.map +1 -1
- package/dist/LibsqlMigrator.js +9 -5
- package/dist/LibsqlMigrator.js.map +1 -1
- package/dist/index.d.ts +40 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/LibsqlClient.ts +95 -37
- package/src/LibsqlMigrator.ts +30 -6
- package/src/index.ts +40 -3
package/dist/LibsqlClient.d.ts
CHANGED
|
@@ -1,51 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* libSQL client implementation for Effect SQL, backed by `@libsql/client`.
|
|
3
|
+
*
|
|
4
|
+
* This module creates or wraps a libSQL SDK client and exposes it as both the
|
|
5
|
+
* libSQL-specific `LibsqlClient` service and the generic Effect `SqlClient`.
|
|
6
|
+
* Use it for Turso-hosted libSQL databases, local `file:` databases, embedded
|
|
7
|
+
* replicas configured with `syncUrl`, migrations, tests, and application code
|
|
8
|
+
* that wants SQLite-compatible SQL through Effect services and layers.
|
|
9
|
+
*
|
|
10
|
+
* When connection options are supplied the SDK client is scoped and closed by
|
|
11
|
+
* the layer; when `liveClient` is supplied ownership stays with the caller.
|
|
12
|
+
* Top-level `withTransaction` blocks open a libSQL write transaction, nested
|
|
13
|
+
* transactions use SQLite savepoints, and only statements run through the same
|
|
14
|
+
* Effect client participate in that transaction. Keep Turso or remote libSQL
|
|
15
|
+
* transactions short, because the transaction holds the client reservation
|
|
16
|
+
* until commit or rollback; direct SDK calls made outside this service are not
|
|
17
|
+
* coordinated with Effect SQL transactions. Row streaming is not implemented.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import * as Libsql from "@libsql/client";
|
|
5
22
|
import * as Config from "effect/Config";
|
|
23
|
+
import * as Context from "effect/Context";
|
|
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 * as 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
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
31
|
+
* Runtime type identifier used to mark `LibsqlClient` values.
|
|
32
|
+
*
|
|
33
|
+
* @category type IDs
|
|
34
|
+
* @since 4.0.0
|
|
16
35
|
*/
|
|
17
36
|
export declare const TypeId: TypeId;
|
|
18
37
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
38
|
+
* Type-level identifier used to mark `LibsqlClient` values.
|
|
39
|
+
*
|
|
40
|
+
* @category type IDs
|
|
41
|
+
* @since 4.0.0
|
|
21
42
|
*/
|
|
22
43
|
export type TypeId = "~@effect/sql-libsql/LibsqlClient";
|
|
23
44
|
/**
|
|
45
|
+
* libSQL-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
|
|
46
|
+
*
|
|
24
47
|
* @category models
|
|
25
|
-
* @since
|
|
48
|
+
* @since 4.0.0
|
|
26
49
|
*/
|
|
27
50
|
export interface LibsqlClient extends Client.SqlClient {
|
|
28
51
|
readonly [TypeId]: TypeId;
|
|
29
52
|
readonly config: LibsqlClientConfig;
|
|
30
53
|
}
|
|
31
54
|
/**
|
|
55
|
+
* Context tag used to access the `LibsqlClient` service.
|
|
56
|
+
*
|
|
32
57
|
* @category tags
|
|
33
|
-
* @since
|
|
58
|
+
* @since 4.0.0
|
|
34
59
|
*/
|
|
35
|
-
export declare const LibsqlClient:
|
|
60
|
+
export declare const LibsqlClient: Context.Service<LibsqlClient, LibsqlClient>;
|
|
36
61
|
/**
|
|
62
|
+
* Configuration for a libSQL client, either by supplying connection options or an existing live libSQL client.
|
|
63
|
+
*
|
|
37
64
|
* @category models
|
|
38
|
-
* @since
|
|
65
|
+
* @since 4.0.0
|
|
39
66
|
*/
|
|
40
67
|
export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live;
|
|
41
68
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
69
|
+
* Namespace containing the configuration variants for `LibsqlClient`.
|
|
70
|
+
*
|
|
71
|
+
* @since 4.0.0
|
|
44
72
|
*/
|
|
45
73
|
export declare namespace LibsqlClientConfig {
|
|
46
74
|
/**
|
|
75
|
+
* Shared libSQL client options for span attributes and query/result name transformations.
|
|
76
|
+
*
|
|
47
77
|
* @category models
|
|
48
|
-
* @since
|
|
78
|
+
* @since 4.0.0
|
|
49
79
|
*/
|
|
50
80
|
interface Base {
|
|
51
81
|
readonly spanAttributes?: Record<string, unknown> | undefined;
|
|
@@ -53,11 +83,16 @@ export declare namespace LibsqlClientConfig {
|
|
|
53
83
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
54
84
|
}
|
|
55
85
|
/**
|
|
86
|
+
* Connection-based libSQL configuration used to create a managed client, including URL, credentials, sync, integer mode, TLS, and concurrency options.
|
|
87
|
+
*
|
|
56
88
|
* @category models
|
|
57
|
-
* @since
|
|
89
|
+
* @since 4.0.0
|
|
58
90
|
*/
|
|
59
91
|
interface Full extends Base {
|
|
60
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* The database URL.
|
|
94
|
+
*
|
|
95
|
+
* **Details**
|
|
61
96
|
*
|
|
62
97
|
* The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
|
|
63
98
|
* please refer to the project README:
|
|
@@ -73,12 +108,18 @@ export declare namespace LibsqlClientConfig {
|
|
|
73
108
|
readonly syncUrl?: string | URL | undefined;
|
|
74
109
|
/** Sync interval in seconds. */
|
|
75
110
|
readonly syncInterval?: number | undefined;
|
|
76
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Enables or disables TLS for `libsql:` URLs.
|
|
113
|
+
*
|
|
114
|
+
* **Details**
|
|
77
115
|
*
|
|
78
116
|
* By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
|
|
79
117
|
*/
|
|
80
118
|
readonly tls?: boolean | undefined;
|
|
81
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* How to convert SQLite integers to JavaScript values.
|
|
121
|
+
*
|
|
122
|
+
* **Details**
|
|
82
123
|
*
|
|
83
124
|
* - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
|
|
84
125
|
* `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
|
|
@@ -88,7 +129,10 @@ export declare namespace LibsqlClientConfig {
|
|
|
88
129
|
* - `"string"`: returns SQLite integers as strings.
|
|
89
130
|
*/
|
|
90
131
|
readonly intMode?: "number" | "bigint" | "string" | undefined;
|
|
91
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Concurrency limit.
|
|
134
|
+
*
|
|
135
|
+
* **Details**
|
|
92
136
|
*
|
|
93
137
|
* By default, the client performs up to 20 concurrent requests. You can set this option to a higher
|
|
94
138
|
* number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
|
|
@@ -96,26 +140,34 @@ export declare namespace LibsqlClientConfig {
|
|
|
96
140
|
readonly concurrency?: number | undefined;
|
|
97
141
|
}
|
|
98
142
|
/**
|
|
143
|
+
* Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
|
|
144
|
+
*
|
|
99
145
|
* @category models
|
|
100
|
-
* @since
|
|
146
|
+
* @since 4.0.0
|
|
101
147
|
*/
|
|
102
148
|
interface Live extends Base {
|
|
103
149
|
readonly liveClient: Libsql.Client;
|
|
104
150
|
}
|
|
105
151
|
}
|
|
106
152
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
153
|
+
* 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.
|
|
154
|
+
*
|
|
155
|
+
* @category constructors
|
|
156
|
+
* @since 4.0.0
|
|
109
157
|
*/
|
|
110
158
|
export declare const make: (options: LibsqlClientConfig) => Effect.Effect<LibsqlClient, never, Scope.Scope | Reactivity.Reactivity>;
|
|
111
159
|
/**
|
|
160
|
+
* Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
161
|
+
*
|
|
112
162
|
* @category layers
|
|
113
|
-
* @since
|
|
163
|
+
* @since 4.0.0
|
|
114
164
|
*/
|
|
115
165
|
export declare const layerConfig: (config: Config.Wrap<LibsqlClientConfig>) => Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError>;
|
|
116
166
|
/**
|
|
167
|
+
* Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
168
|
+
*
|
|
117
169
|
* @category layers
|
|
118
|
-
* @since
|
|
170
|
+
* @since 4.0.0
|
|
119
171
|
*/
|
|
120
172
|
export declare const layer: (config: LibsqlClientConfig) => Layer.Layer<LibsqlClient | Client.SqlClient>;
|
|
121
173
|
//# sourceMappingURL=LibsqlClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibsqlClient.d.ts","sourceRoot":"","sources":["../src/LibsqlClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"LibsqlClient.d.ts","sourceRoot":"","sources":["../src/LibsqlClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAA;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAg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G,MAAM,CAAC,SAAS,CAML,CAAA"}
|
package/dist/LibsqlClient.js
CHANGED
|
@@ -1,35 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* libSQL client implementation for Effect SQL, backed by `@libsql/client`.
|
|
3
|
+
*
|
|
4
|
+
* This module creates or wraps a libSQL SDK client and exposes it as both the
|
|
5
|
+
* libSQL-specific `LibsqlClient` service and the generic Effect `SqlClient`.
|
|
6
|
+
* Use it for Turso-hosted libSQL databases, local `file:` databases, embedded
|
|
7
|
+
* replicas configured with `syncUrl`, migrations, tests, and application code
|
|
8
|
+
* that wants SQLite-compatible SQL through Effect services and layers.
|
|
9
|
+
*
|
|
10
|
+
* When connection options are supplied the SDK client is scoped and closed by
|
|
11
|
+
* the layer; when `liveClient` is supplied ownership stays with the caller.
|
|
12
|
+
* Top-level `withTransaction` blocks open a libSQL write transaction, nested
|
|
13
|
+
* transactions use SQLite savepoints, and only statements run through the same
|
|
14
|
+
* Effect client participate in that transaction. Keep Turso or remote libSQL
|
|
15
|
+
* transactions short, because the transaction holds the client reservation
|
|
16
|
+
* until commit or rollback; direct SDK calls made outside this service are not
|
|
17
|
+
* coordinated with Effect SQL transactions. Row streaming is not implemented.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import * as Libsql from "@libsql/client";
|
|
5
22
|
import * as Config from "effect/Config";
|
|
23
|
+
import * as Context from "effect/Context";
|
|
6
24
|
import * as Effect from "effect/Effect";
|
|
7
25
|
import * as Layer from "effect/Layer";
|
|
8
26
|
import * as Option from "effect/Option";
|
|
9
27
|
import * as Redacted from "effect/Redacted";
|
|
10
28
|
import * as Scope from "effect/Scope";
|
|
11
29
|
import * as Semaphore from "effect/Semaphore";
|
|
12
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
13
30
|
import * as Stream from "effect/Stream";
|
|
14
31
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
15
32
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
16
|
-
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
33
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
|
|
17
34
|
import * as Statement from "effect/unstable/sql/Statement";
|
|
18
35
|
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
36
|
+
const classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
37
|
+
message,
|
|
38
|
+
operation
|
|
39
|
+
});
|
|
19
40
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
41
|
+
* Runtime type identifier used to mark `LibsqlClient` values.
|
|
42
|
+
*
|
|
43
|
+
* @category type IDs
|
|
44
|
+
* @since 4.0.0
|
|
22
45
|
*/
|
|
23
46
|
export const TypeId = "~@effect/sql-libsql/LibsqlClient";
|
|
24
47
|
/**
|
|
48
|
+
* Context tag used to access the `LibsqlClient` service.
|
|
49
|
+
*
|
|
25
50
|
* @category tags
|
|
26
|
-
* @since
|
|
51
|
+
* @since 4.0.0
|
|
27
52
|
*/
|
|
28
|
-
export const LibsqlClient = /*#__PURE__*/
|
|
29
|
-
const LibsqlTransaction = /*#__PURE__*/
|
|
53
|
+
export const LibsqlClient = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient");
|
|
54
|
+
const LibsqlTransaction = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
|
|
30
55
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
56
|
+
* 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.
|
|
57
|
+
*
|
|
58
|
+
* @category constructors
|
|
59
|
+
* @since 4.0.0
|
|
33
60
|
*/
|
|
34
61
|
export const make = options => Effect.gen(function* () {
|
|
35
62
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
@@ -47,8 +74,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
47
74
|
args: params
|
|
48
75
|
}),
|
|
49
76
|
catch: cause => new SqlError({
|
|
50
|
-
cause,
|
|
51
|
-
message: "Failed to execute statement"
|
|
77
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
52
78
|
})
|
|
53
79
|
}), results => results.rows);
|
|
54
80
|
}
|
|
@@ -59,8 +85,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
59
85
|
args: params
|
|
60
86
|
}),
|
|
61
87
|
catch: cause => new SqlError({
|
|
62
|
-
cause,
|
|
63
|
-
message: "Failed to execute statement"
|
|
88
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
64
89
|
})
|
|
65
90
|
});
|
|
66
91
|
}
|
|
@@ -83,8 +108,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
83
108
|
return Effect.map(Effect.tryPromise({
|
|
84
109
|
try: () => this.sdk.transaction("write"),
|
|
85
110
|
catch: cause => new SqlError({
|
|
86
|
-
cause,
|
|
87
|
-
message: "Failed to begin transaction"
|
|
111
|
+
reason: classifyError(cause, "Failed to begin transaction", "beginTransaction")
|
|
88
112
|
})
|
|
89
113
|
}), tx => new LibsqlConnectionImpl(tx));
|
|
90
114
|
}
|
|
@@ -92,8 +116,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
92
116
|
return Effect.tryPromise({
|
|
93
117
|
try: () => this.sdk.commit(),
|
|
94
118
|
catch: cause => new SqlError({
|
|
95
|
-
cause,
|
|
96
|
-
message: "Failed to commit transaction"
|
|
119
|
+
reason: classifyError(cause, "Failed to commit transaction", "commitTransaction")
|
|
97
120
|
})
|
|
98
121
|
});
|
|
99
122
|
}
|
|
@@ -101,8 +124,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
101
124
|
return Effect.tryPromise({
|
|
102
125
|
try: () => this.sdk.rollback(),
|
|
103
126
|
catch: cause => new SqlError({
|
|
104
|
-
cause,
|
|
105
|
-
message: "Failed to rollback transaction"
|
|
127
|
+
reason: classifyError(cause, "Failed to rollback transaction", "rollbackTransaction")
|
|
106
128
|
})
|
|
107
129
|
});
|
|
108
130
|
}
|
|
@@ -149,13 +171,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
149
171
|
});
|
|
150
172
|
});
|
|
151
173
|
/**
|
|
174
|
+
* Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
175
|
+
*
|
|
152
176
|
* @category layers
|
|
153
|
-
* @since
|
|
177
|
+
* @since 4.0.0
|
|
154
178
|
*/
|
|
155
|
-
export const layerConfig = config => Layer.
|
|
179
|
+
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
180
|
/**
|
|
181
|
+
* Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
182
|
+
*
|
|
157
183
|
* @category layers
|
|
158
|
-
* @since
|
|
184
|
+
* @since 4.0.0
|
|
159
185
|
*/
|
|
160
|
-
export const layer = config => Layer.
|
|
186
|
+
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
187
|
//# sourceMappingURL=LibsqlClient.js.map
|
package/dist/LibsqlClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibsqlClient.js","names":["Libsql","Config","Effect","Layer","Option","Redacted","Scope","Semaphore","
|
|
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;;;;;;;;;;;;;;;;;;;;AAoBA,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,OAA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,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":[]}
|
package/dist/LibsqlMigrator.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for applying Effect SQL migrations to libSQL and Turso databases.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
5
|
+
* provides `run` and `layer` helpers for applying ordered migrations through the
|
|
6
|
+
* current libSQL-backed `SqlClient`. It is typically used at application
|
|
7
|
+
* startup, in deployment or setup scripts for Turso databases, in tests that
|
|
8
|
+
* create temporary `file:` databases, or in layer graphs that must ensure the
|
|
9
|
+
* schema exists before dependent services are acquired.
|
|
10
|
+
*
|
|
11
|
+
* Migrations are recorded in `effect_sql_migrations` by default and are loaded
|
|
12
|
+
* using the shared `<id>_<name>` file or record-key convention. Because libSQL
|
|
13
|
+
* uses SQLite-compatible SQL, migrations should avoid dialect features that are
|
|
14
|
+
* not supported by libSQL or the configured Turso deployment. Remote Turso
|
|
15
|
+
* databases, local `file:` databases, and embedded replicas can each observe
|
|
16
|
+
* different state until replication has caught up, so run schema-changing
|
|
17
|
+
* migrations against the intended writer and wait for replicas to sync before
|
|
18
|
+
* serving code that depends on the new schema. Concurrent migrators rely on the
|
|
19
|
+
* migrations table primary key to detect races, and this adapter does not
|
|
20
|
+
* currently write schema dumps for `schemaDirectory`.
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
3
23
|
*/
|
|
4
24
|
import type * as Effect from "effect/Effect";
|
|
5
25
|
import * as Layer from "effect/Layer";
|
|
@@ -7,17 +27,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
|
|
|
7
27
|
import type * as Client from "effect/unstable/sql/SqlClient";
|
|
8
28
|
import type { SqlError } from "effect/unstable/sql/SqlError";
|
|
9
29
|
/**
|
|
10
|
-
* @since
|
|
30
|
+
* @since 4.0.0
|
|
11
31
|
*/
|
|
12
32
|
export * from "effect/unstable/sql/Migrator";
|
|
13
33
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
34
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
35
|
+
*
|
|
36
|
+
* @category constructors
|
|
37
|
+
* @since 4.0.0
|
|
16
38
|
*/
|
|
17
39
|
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
40
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
41
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
42
|
+
*
|
|
43
|
+
* @category constructors
|
|
44
|
+
* @since 4.0.0
|
|
21
45
|
*/
|
|
22
46
|
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
|
|
23
47
|
//# sourceMappingURL=LibsqlMigrator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LibsqlMigrator.d.ts","sourceRoot":"","sources":["../src/LibsqlMigrator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"LibsqlMigrator.d.ts","sourceRoot":"","sources":["../src/LibsqlMigrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;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"}
|
package/dist/LibsqlMigrator.js
CHANGED
|
@@ -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
|
|
4
|
+
* @since 4.0.0
|
|
5
5
|
*/
|
|
6
6
|
export * from "effect/unstable/sql/Migrator";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
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":"
|
|
1
|
+
{"version":3,"file":"LibsqlMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/LibsqlMigrator.ts"],"sourcesContent":[null],"mappings":"AAwBA,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,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* libSQL client implementation for Effect SQL, backed by `@libsql/client`.
|
|
6
|
+
*
|
|
7
|
+
* This module creates or wraps a libSQL SDK client and exposes it as both the
|
|
8
|
+
* libSQL-specific `LibsqlClient` service and the generic Effect `SqlClient`.
|
|
9
|
+
* Use it for Turso-hosted libSQL databases, local `file:` databases, embedded
|
|
10
|
+
* replicas configured with `syncUrl`, migrations, tests, and application code
|
|
11
|
+
* that wants SQLite-compatible SQL through Effect services and layers.
|
|
12
|
+
*
|
|
13
|
+
* When connection options are supplied the SDK client is scoped and closed by
|
|
14
|
+
* the layer; when `liveClient` is supplied ownership stays with the caller.
|
|
15
|
+
* Top-level `withTransaction` blocks open a libSQL write transaction, nested
|
|
16
|
+
* transactions use SQLite savepoints, and only statements run through the same
|
|
17
|
+
* Effect client participate in that transaction. Keep Turso or remote libSQL
|
|
18
|
+
* transactions short, because the transaction holds the client reservation
|
|
19
|
+
* until commit or rollback; direct SDK calls made outside this service are not
|
|
20
|
+
* coordinated with Effect SQL transactions. Row streaming is not implemented.
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
6
23
|
*/
|
|
7
24
|
export * as LibsqlClient from "./LibsqlClient.ts";
|
|
8
25
|
/**
|
|
9
|
-
*
|
|
26
|
+
* Utilities for applying Effect SQL migrations to libSQL and Turso databases.
|
|
27
|
+
*
|
|
28
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
29
|
+
* provides `run` and `layer` helpers for applying ordered migrations through the
|
|
30
|
+
* current libSQL-backed `SqlClient`. It is typically used at application
|
|
31
|
+
* startup, in deployment or setup scripts for Turso databases, in tests that
|
|
32
|
+
* create temporary `file:` databases, or in layer graphs that must ensure the
|
|
33
|
+
* schema exists before dependent services are acquired.
|
|
34
|
+
*
|
|
35
|
+
* Migrations are recorded in `effect_sql_migrations` by default and are loaded
|
|
36
|
+
* using the shared `<id>_<name>` file or record-key convention. Because libSQL
|
|
37
|
+
* uses SQLite-compatible SQL, migrations should avoid dialect features that are
|
|
38
|
+
* not supported by libSQL or the configured Turso deployment. Remote Turso
|
|
39
|
+
* databases, local `file:` databases, and embedded replicas can each observe
|
|
40
|
+
* different state until replication has caught up, so run schema-changing
|
|
41
|
+
* migrations against the intended writer and wait for replicas to sync before
|
|
42
|
+
* serving code that depends on the new schema. Concurrent migrators rely on the
|
|
43
|
+
* migrations table primary key to detect races, and this adapter does not
|
|
44
|
+
* currently write schema dumps for `schemaDirectory`.
|
|
45
|
+
*
|
|
46
|
+
* @since 4.0.0
|
|
10
47
|
*/
|
|
11
48
|
export * as LibsqlMigrator from "./LibsqlMigrator.ts";
|
|
12
49
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* libSQL client implementation for Effect SQL, backed by `@libsql/client`.
|
|
7
|
+
*
|
|
8
|
+
* This module creates or wraps a libSQL SDK client and exposes it as both the
|
|
9
|
+
* libSQL-specific `LibsqlClient` service and the generic Effect `SqlClient`.
|
|
10
|
+
* Use it for Turso-hosted libSQL databases, local `file:` databases, embedded
|
|
11
|
+
* replicas configured with `syncUrl`, migrations, tests, and application code
|
|
12
|
+
* that wants SQLite-compatible SQL through Effect services and layers.
|
|
13
|
+
*
|
|
14
|
+
* When connection options are supplied the SDK client is scoped and closed by
|
|
15
|
+
* the layer; when `liveClient` is supplied ownership stays with the caller.
|
|
16
|
+
* Top-level `withTransaction` blocks open a libSQL write transaction, nested
|
|
17
|
+
* transactions use SQLite savepoints, and only statements run through the same
|
|
18
|
+
* Effect client participate in that transaction. Keep Turso or remote libSQL
|
|
19
|
+
* transactions short, because the transaction holds the client reservation
|
|
20
|
+
* until commit or rollback; direct SDK calls made outside this service are not
|
|
21
|
+
* coordinated with Effect SQL transactions. Row streaming is not implemented.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
7
24
|
*/
|
|
8
25
|
export * as LibsqlClient from "./LibsqlClient.js";
|
|
9
26
|
/**
|
|
10
|
-
*
|
|
27
|
+
* Utilities for applying Effect SQL migrations to libSQL and Turso databases.
|
|
28
|
+
*
|
|
29
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
30
|
+
* provides `run` and `layer` helpers for applying ordered migrations through the
|
|
31
|
+
* current libSQL-backed `SqlClient`. It is typically used at application
|
|
32
|
+
* startup, in deployment or setup scripts for Turso databases, in tests that
|
|
33
|
+
* create temporary `file:` databases, or in layer graphs that must ensure the
|
|
34
|
+
* schema exists before dependent services are acquired.
|
|
35
|
+
*
|
|
36
|
+
* Migrations are recorded in `effect_sql_migrations` by default and are loaded
|
|
37
|
+
* using the shared `<id>_<name>` file or record-key convention. Because libSQL
|
|
38
|
+
* uses SQLite-compatible SQL, migrations should avoid dialect features that are
|
|
39
|
+
* not supported by libSQL or the configured Turso deployment. Remote Turso
|
|
40
|
+
* databases, local `file:` databases, and embedded replicas can each observe
|
|
41
|
+
* different state until replication has caught up, so run schema-changing
|
|
42
|
+
* migrations against the intended writer and wait for replicas to sync before
|
|
43
|
+
* serving code that depends on the new schema. Concurrent migrators rely on the
|
|
44
|
+
* migrations table primary key to detect races, and this adapter does not
|
|
45
|
+
* currently write schema dumps for `schemaDirectory`.
|
|
46
|
+
*
|
|
47
|
+
* @since 4.0.0
|
|
11
48
|
*/
|
|
12
49
|
export * as LibsqlMigrator from "./LibsqlMigrator.js";
|
|
13
50
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["LibsqlClient","LibsqlMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA
|
|
1
|
+
{"version":3,"file":"index.js","names":["LibsqlClient","LibsqlMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;;;;;;;;;;;;;;;;;;AAoBA,OAAO,KAAKA,YAAY,MAAM,mBAAmB;AAEjD;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,KAAKC,cAAc,MAAM,qBAAqB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-libsql",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.70",
|
|
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.
|
|
49
|
-
"effect": "^4.0.0-beta.
|
|
48
|
+
"testcontainers": "^11.14.0",
|
|
49
|
+
"effect": "^4.0.0-beta.70"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"effect": "^4.0.0-beta.
|
|
52
|
+
"effect": "^4.0.0-beta.70"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@libsql/client": "^0.17.
|
|
55
|
+
"@libsql/client": "^0.17.3"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"codegen": "effect-utils codegen",
|
package/src/LibsqlClient.ts
CHANGED
|
@@ -1,39 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* libSQL client implementation for Effect SQL, backed by `@libsql/client`.
|
|
3
|
+
*
|
|
4
|
+
* This module creates or wraps a libSQL SDK client and exposes it as both the
|
|
5
|
+
* libSQL-specific `LibsqlClient` service and the generic Effect `SqlClient`.
|
|
6
|
+
* Use it for Turso-hosted libSQL databases, local `file:` databases, embedded
|
|
7
|
+
* replicas configured with `syncUrl`, migrations, tests, and application code
|
|
8
|
+
* that wants SQLite-compatible SQL through Effect services and layers.
|
|
9
|
+
*
|
|
10
|
+
* When connection options are supplied the SDK client is scoped and closed by
|
|
11
|
+
* the layer; when `liveClient` is supplied ownership stays with the caller.
|
|
12
|
+
* Top-level `withTransaction` blocks open a libSQL write transaction, nested
|
|
13
|
+
* transactions use SQLite savepoints, and only statements run through the same
|
|
14
|
+
* Effect client participate in that transaction. Keep Turso or remote libSQL
|
|
15
|
+
* transactions short, because the transaction holds the client reservation
|
|
16
|
+
* until commit or rollback; direct SDK calls made outside this service are not
|
|
17
|
+
* coordinated with Effect SQL transactions. Row streaming is not implemented.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
import * as Libsql from "@libsql/client"
|
|
5
22
|
import * as Config from "effect/Config"
|
|
23
|
+
import * as Context from "effect/Context"
|
|
6
24
|
import * as Effect from "effect/Effect"
|
|
7
25
|
import * as Layer from "effect/Layer"
|
|
8
26
|
import * as Option from "effect/Option"
|
|
9
27
|
import * as Redacted from "effect/Redacted"
|
|
10
28
|
import * as Scope from "effect/Scope"
|
|
11
29
|
import * as Semaphore from "effect/Semaphore"
|
|
12
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
13
30
|
import * as Stream from "effect/Stream"
|
|
14
31
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity"
|
|
15
32
|
import * as Client from "effect/unstable/sql/SqlClient"
|
|
16
33
|
import type { Connection } from "effect/unstable/sql/SqlConnection"
|
|
17
|
-
import { SqlError } from "effect/unstable/sql/SqlError"
|
|
34
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
|
|
18
35
|
import * as Statement from "effect/unstable/sql/Statement"
|
|
19
36
|
|
|
20
37
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
21
38
|
|
|
39
|
+
const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
40
|
+
classifySqliteError(cause, { message, operation })
|
|
41
|
+
|
|
22
42
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
43
|
+
* Runtime type identifier used to mark `LibsqlClient` values.
|
|
44
|
+
*
|
|
45
|
+
* @category type IDs
|
|
46
|
+
* @since 4.0.0
|
|
25
47
|
*/
|
|
26
48
|
export const TypeId: TypeId = "~@effect/sql-libsql/LibsqlClient"
|
|
27
49
|
|
|
28
50
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
51
|
+
* Type-level identifier used to mark `LibsqlClient` values.
|
|
52
|
+
*
|
|
53
|
+
* @category type IDs
|
|
54
|
+
* @since 4.0.0
|
|
31
55
|
*/
|
|
32
56
|
export type TypeId = "~@effect/sql-libsql/LibsqlClient"
|
|
33
57
|
|
|
34
58
|
/**
|
|
59
|
+
* libSQL-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
|
|
60
|
+
*
|
|
35
61
|
* @category models
|
|
36
|
-
* @since
|
|
62
|
+
* @since 4.0.0
|
|
37
63
|
*/
|
|
38
64
|
export interface LibsqlClient extends Client.SqlClient {
|
|
39
65
|
readonly [TypeId]: TypeId
|
|
@@ -41,29 +67,36 @@ export interface LibsqlClient extends Client.SqlClient {
|
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
/**
|
|
70
|
+
* Context tag used to access the `LibsqlClient` service.
|
|
71
|
+
*
|
|
44
72
|
* @category tags
|
|
45
|
-
* @since
|
|
73
|
+
* @since 4.0.0
|
|
46
74
|
*/
|
|
47
|
-
export const LibsqlClient =
|
|
75
|
+
export const LibsqlClient = Context.Service<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
|
|
48
76
|
|
|
49
|
-
const LibsqlTransaction =
|
|
77
|
+
const LibsqlTransaction = Context.Service<readonly [LibsqlConnection, counter: number]>(
|
|
50
78
|
"@effect/sql-libsql/LibsqlClient/LibsqlTransaction"
|
|
51
79
|
)
|
|
52
80
|
|
|
53
81
|
/**
|
|
82
|
+
* Configuration for a libSQL client, either by supplying connection options or an existing live libSQL client.
|
|
83
|
+
*
|
|
54
84
|
* @category models
|
|
55
|
-
* @since
|
|
85
|
+
* @since 4.0.0
|
|
56
86
|
*/
|
|
57
87
|
export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live
|
|
58
88
|
|
|
59
89
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
90
|
+
* Namespace containing the configuration variants for `LibsqlClient`.
|
|
91
|
+
*
|
|
92
|
+
* @since 4.0.0
|
|
62
93
|
*/
|
|
63
94
|
export declare namespace LibsqlClientConfig {
|
|
64
95
|
/**
|
|
96
|
+
* Shared libSQL client options for span attributes and query/result name transformations.
|
|
97
|
+
*
|
|
65
98
|
* @category models
|
|
66
|
-
* @since
|
|
99
|
+
* @since 4.0.0
|
|
67
100
|
*/
|
|
68
101
|
export interface Base {
|
|
69
102
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
@@ -72,11 +105,16 @@ export declare namespace LibsqlClientConfig {
|
|
|
72
105
|
}
|
|
73
106
|
|
|
74
107
|
/**
|
|
108
|
+
* Connection-based libSQL configuration used to create a managed client, including URL, credentials, sync, integer mode, TLS, and concurrency options.
|
|
109
|
+
*
|
|
75
110
|
* @category models
|
|
76
|
-
* @since
|
|
111
|
+
* @since 4.0.0
|
|
77
112
|
*/
|
|
78
113
|
export interface Full extends Base {
|
|
79
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* The database URL.
|
|
116
|
+
*
|
|
117
|
+
* **Details**
|
|
80
118
|
*
|
|
81
119
|
* The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation,
|
|
82
120
|
* please refer to the project README:
|
|
@@ -92,12 +130,18 @@ export declare namespace LibsqlClientConfig {
|
|
|
92
130
|
readonly syncUrl?: string | URL | undefined
|
|
93
131
|
/** Sync interval in seconds. */
|
|
94
132
|
readonly syncInterval?: number | undefined
|
|
95
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Enables or disables TLS for `libsql:` URLs.
|
|
135
|
+
*
|
|
136
|
+
* **Details**
|
|
96
137
|
*
|
|
97
138
|
* By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.
|
|
98
139
|
*/
|
|
99
140
|
readonly tls?: boolean | undefined
|
|
100
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* How to convert SQLite integers to JavaScript values.
|
|
143
|
+
*
|
|
144
|
+
* **Details**
|
|
101
145
|
*
|
|
102
146
|
* - `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats).
|
|
103
147
|
* `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read
|
|
@@ -107,7 +151,10 @@ export declare namespace LibsqlClientConfig {
|
|
|
107
151
|
* - `"string"`: returns SQLite integers as strings.
|
|
108
152
|
*/
|
|
109
153
|
readonly intMode?: "number" | "bigint" | "string" | undefined
|
|
110
|
-
/**
|
|
154
|
+
/**
|
|
155
|
+
* Concurrency limit.
|
|
156
|
+
*
|
|
157
|
+
* **Details**
|
|
111
158
|
*
|
|
112
159
|
* By default, the client performs up to 20 concurrent requests. You can set this option to a higher
|
|
113
160
|
* number to increase the concurrency limit or set it to 0 to disable concurrency limits completely.
|
|
@@ -116,8 +163,10 @@ export declare namespace LibsqlClientConfig {
|
|
|
116
163
|
}
|
|
117
164
|
|
|
118
165
|
/**
|
|
166
|
+
* Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
|
|
167
|
+
*
|
|
119
168
|
* @category models
|
|
120
|
-
* @since
|
|
169
|
+
* @since 4.0.0
|
|
121
170
|
*/
|
|
122
171
|
export interface Live extends Base {
|
|
123
172
|
readonly liveClient: Libsql.Client
|
|
@@ -131,8 +180,10 @@ interface LibsqlConnection extends Connection {
|
|
|
131
180
|
}
|
|
132
181
|
|
|
133
182
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
183
|
+
* 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.
|
|
184
|
+
*
|
|
185
|
+
* @category constructors
|
|
186
|
+
* @since 4.0.0
|
|
136
187
|
*/
|
|
137
188
|
export const make = (
|
|
138
189
|
options: LibsqlClientConfig
|
|
@@ -163,7 +214,7 @@ export const make = (
|
|
|
163
214
|
return Effect.map(
|
|
164
215
|
Effect.tryPromise({
|
|
165
216
|
try: () => this.sdk.execute({ sql, args: params as Array<any> }),
|
|
166
|
-
catch: (cause) => new SqlError({ cause,
|
|
217
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
|
|
167
218
|
}),
|
|
168
219
|
(results) => results.rows
|
|
169
220
|
)
|
|
@@ -175,7 +226,7 @@ export const make = (
|
|
|
175
226
|
) {
|
|
176
227
|
return Effect.tryPromise({
|
|
177
228
|
try: () => this.sdk.execute({ sql, args: params as Array<any> }),
|
|
178
|
-
catch: (cause) => new SqlError({ cause,
|
|
229
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
|
|
179
230
|
})
|
|
180
231
|
}
|
|
181
232
|
|
|
@@ -208,7 +259,8 @@ export const make = (
|
|
|
208
259
|
return Effect.map(
|
|
209
260
|
Effect.tryPromise({
|
|
210
261
|
try: () => (this.sdk as Libsql.Client).transaction("write"),
|
|
211
|
-
catch: (cause) =>
|
|
262
|
+
catch: (cause) =>
|
|
263
|
+
new SqlError({ reason: classifyError(cause, "Failed to begin transaction", "beginTransaction") })
|
|
212
264
|
}),
|
|
213
265
|
(tx) => new LibsqlConnectionImpl(tx)
|
|
214
266
|
)
|
|
@@ -216,13 +268,15 @@ export const make = (
|
|
|
216
268
|
get commit() {
|
|
217
269
|
return Effect.tryPromise({
|
|
218
270
|
try: () => (this.sdk as Libsql.Transaction).commit(),
|
|
219
|
-
catch: (cause) =>
|
|
271
|
+
catch: (cause) =>
|
|
272
|
+
new SqlError({ reason: classifyError(cause, "Failed to commit transaction", "commitTransaction") })
|
|
220
273
|
})
|
|
221
274
|
}
|
|
222
275
|
get rollback() {
|
|
223
276
|
return Effect.tryPromise({
|
|
224
277
|
try: () => (this.sdk as Libsql.Transaction).rollback(),
|
|
225
|
-
catch: (cause) =>
|
|
278
|
+
catch: (cause) =>
|
|
279
|
+
new SqlError({ reason: classifyError(cause, "Failed to rollback transaction", "rollbackTransaction") })
|
|
226
280
|
})
|
|
227
281
|
}
|
|
228
282
|
}
|
|
@@ -294,35 +348,39 @@ export const make = (
|
|
|
294
348
|
})
|
|
295
349
|
|
|
296
350
|
/**
|
|
351
|
+
* Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
352
|
+
*
|
|
297
353
|
* @category layers
|
|
298
|
-
* @since
|
|
354
|
+
* @since 4.0.0
|
|
299
355
|
*/
|
|
300
356
|
export const layerConfig: (
|
|
301
357
|
config: Config.Wrap<LibsqlClientConfig>
|
|
302
358
|
) => Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError> = (
|
|
303
359
|
config: Config.Wrap<LibsqlClientConfig>
|
|
304
360
|
): Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError> =>
|
|
305
|
-
Layer.
|
|
306
|
-
Config.unwrap(config).
|
|
361
|
+
Layer.effectContext(
|
|
362
|
+
Config.unwrap(config).pipe(
|
|
307
363
|
Effect.flatMap(make),
|
|
308
364
|
Effect.map((client) =>
|
|
309
|
-
|
|
310
|
-
|
|
365
|
+
Context.make(LibsqlClient, client).pipe(
|
|
366
|
+
Context.add(Client.SqlClient, client)
|
|
311
367
|
)
|
|
312
368
|
)
|
|
313
369
|
)
|
|
314
370
|
).pipe(Layer.provide(Reactivity.layer))
|
|
315
371
|
|
|
316
372
|
/**
|
|
373
|
+
* Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
374
|
+
*
|
|
317
375
|
* @category layers
|
|
318
|
-
* @since
|
|
376
|
+
* @since 4.0.0
|
|
319
377
|
*/
|
|
320
378
|
export const layer = (
|
|
321
379
|
config: LibsqlClientConfig
|
|
322
380
|
): Layer.Layer<LibsqlClient | Client.SqlClient> =>
|
|
323
|
-
Layer.
|
|
381
|
+
Layer.effectContext(
|
|
324
382
|
Effect.map(make(config), (client) =>
|
|
325
|
-
|
|
326
|
-
|
|
383
|
+
Context.make(LibsqlClient, client).pipe(
|
|
384
|
+
Context.add(Client.SqlClient, client)
|
|
327
385
|
))
|
|
328
386
|
).pipe(Layer.provide(Reactivity.layer))
|
package/src/LibsqlMigrator.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for applying Effect SQL migrations to libSQL and Turso databases.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
5
|
+
* provides `run` and `layer` helpers for applying ordered migrations through the
|
|
6
|
+
* current libSQL-backed `SqlClient`. It is typically used at application
|
|
7
|
+
* startup, in deployment or setup scripts for Turso databases, in tests that
|
|
8
|
+
* create temporary `file:` databases, or in layer graphs that must ensure the
|
|
9
|
+
* schema exists before dependent services are acquired.
|
|
10
|
+
*
|
|
11
|
+
* Migrations are recorded in `effect_sql_migrations` by default and are loaded
|
|
12
|
+
* using the shared `<id>_<name>` file or record-key convention. Because libSQL
|
|
13
|
+
* uses SQLite-compatible SQL, migrations should avoid dialect features that are
|
|
14
|
+
* not supported by libSQL or the configured Turso deployment. Remote Turso
|
|
15
|
+
* databases, local `file:` databases, and embedded replicas can each observe
|
|
16
|
+
* different state until replication has caught up, so run schema-changing
|
|
17
|
+
* migrations against the intended writer and wait for replicas to sync before
|
|
18
|
+
* serving code that depends on the new schema. Concurrent migrators rely on the
|
|
19
|
+
* migrations table primary key to detect races, and this adapter does not
|
|
20
|
+
* currently write schema dumps for `schemaDirectory`.
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
3
23
|
*/
|
|
4
24
|
import type * as Effect from "effect/Effect"
|
|
5
25
|
import * as Layer from "effect/Layer"
|
|
@@ -8,13 +28,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
|
|
|
8
28
|
import type { SqlError } from "effect/unstable/sql/SqlError"
|
|
9
29
|
|
|
10
30
|
/**
|
|
11
|
-
* @since
|
|
31
|
+
* @since 4.0.0
|
|
12
32
|
*/
|
|
13
33
|
export * from "effect/unstable/sql/Migrator"
|
|
14
34
|
|
|
15
35
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
36
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
37
|
+
*
|
|
38
|
+
* @category constructors
|
|
39
|
+
* @since 4.0.0
|
|
18
40
|
*/
|
|
19
41
|
export const run: <R2 = never>(
|
|
20
42
|
options: Migrator.MigratorOptions<R2>
|
|
@@ -25,8 +47,10 @@ export const run: <R2 = never>(
|
|
|
25
47
|
> = Migrator.make({})
|
|
26
48
|
|
|
27
49
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
50
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
51
|
+
*
|
|
52
|
+
* @category constructors
|
|
53
|
+
* @since 4.0.0
|
|
30
54
|
*/
|
|
31
55
|
export const layer = <R>(
|
|
32
56
|
options: Migrator.MigratorOptions<R>
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* libSQL client implementation for Effect SQL, backed by `@libsql/client`.
|
|
9
|
+
*
|
|
10
|
+
* This module creates or wraps a libSQL SDK client and exposes it as both the
|
|
11
|
+
* libSQL-specific `LibsqlClient` service and the generic Effect `SqlClient`.
|
|
12
|
+
* Use it for Turso-hosted libSQL databases, local `file:` databases, embedded
|
|
13
|
+
* replicas configured with `syncUrl`, migrations, tests, and application code
|
|
14
|
+
* that wants SQLite-compatible SQL through Effect services and layers.
|
|
15
|
+
*
|
|
16
|
+
* When connection options are supplied the SDK client is scoped and closed by
|
|
17
|
+
* the layer; when `liveClient` is supplied ownership stays with the caller.
|
|
18
|
+
* Top-level `withTransaction` blocks open a libSQL write transaction, nested
|
|
19
|
+
* transactions use SQLite savepoints, and only statements run through the same
|
|
20
|
+
* Effect client participate in that transaction. Keep Turso or remote libSQL
|
|
21
|
+
* transactions short, because the transaction holds the client reservation
|
|
22
|
+
* until commit or rollback; direct SDK calls made outside this service are not
|
|
23
|
+
* coordinated with Effect SQL transactions. Row streaming is not implemented.
|
|
24
|
+
*
|
|
25
|
+
* @since 4.0.0
|
|
9
26
|
*/
|
|
10
27
|
export * as LibsqlClient from "./LibsqlClient.ts"
|
|
11
28
|
|
|
12
29
|
/**
|
|
13
|
-
*
|
|
30
|
+
* Utilities for applying Effect SQL migrations to libSQL and Turso databases.
|
|
31
|
+
*
|
|
32
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
33
|
+
* provides `run` and `layer` helpers for applying ordered migrations through the
|
|
34
|
+
* current libSQL-backed `SqlClient`. It is typically used at application
|
|
35
|
+
* startup, in deployment or setup scripts for Turso databases, in tests that
|
|
36
|
+
* create temporary `file:` databases, or in layer graphs that must ensure the
|
|
37
|
+
* schema exists before dependent services are acquired.
|
|
38
|
+
*
|
|
39
|
+
* Migrations are recorded in `effect_sql_migrations` by default and are loaded
|
|
40
|
+
* using the shared `<id>_<name>` file or record-key convention. Because libSQL
|
|
41
|
+
* uses SQLite-compatible SQL, migrations should avoid dialect features that are
|
|
42
|
+
* not supported by libSQL or the configured Turso deployment. Remote Turso
|
|
43
|
+
* databases, local `file:` databases, and embedded replicas can each observe
|
|
44
|
+
* different state until replication has caught up, so run schema-changing
|
|
45
|
+
* migrations against the intended writer and wait for replicas to sync before
|
|
46
|
+
* serving code that depends on the new schema. Concurrent migrators rely on the
|
|
47
|
+
* migrations table primary key to detect races, and this adapter does not
|
|
48
|
+
* currently write schema dumps for `schemaDirectory`.
|
|
49
|
+
*
|
|
50
|
+
* @since 4.0.0
|
|
14
51
|
*/
|
|
15
52
|
export * as LibsqlMigrator from "./LibsqlMigrator.ts"
|