@effect/sql-libsql 4.0.0-beta.65 → 4.0.0-beta.67
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 +54 -14
- package/dist/LibsqlClient.d.ts.map +1 -1
- package/dist/LibsqlClient.js +34 -7
- package/dist/LibsqlClient.js.map +1 -1
- package/dist/LibsqlMigrator.d.ts +28 -4
- package/dist/LibsqlMigrator.d.ts.map +1 -1
- package/dist/LibsqlMigrator.js +7 -3
- package/dist/LibsqlMigrator.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +4 -4
- package/src/LibsqlClient.ts +55 -15
- package/src/LibsqlMigrator.ts +28 -4
- package/src/index.ts +3 -3
package/dist/LibsqlClient.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
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";
|
|
@@ -11,41 +28,54 @@ import * as Scope from "effect/Scope";
|
|
|
11
28
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
12
29
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
13
30
|
/**
|
|
31
|
+
* Runtime type identifier used to mark `LibsqlClient` values.
|
|
32
|
+
*
|
|
14
33
|
* @category type ids
|
|
15
|
-
* @since
|
|
34
|
+
* @since 4.0.0
|
|
16
35
|
*/
|
|
17
36
|
export declare const TypeId: TypeId;
|
|
18
37
|
/**
|
|
38
|
+
* Type-level identifier used to mark `LibsqlClient` values.
|
|
39
|
+
*
|
|
19
40
|
* @category type ids
|
|
20
|
-
* @since
|
|
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
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,8 +83,10 @@ 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
|
/** The database URL.
|
|
@@ -96,26 +128,34 @@ export declare namespace LibsqlClientConfig {
|
|
|
96
128
|
readonly concurrency?: number | undefined;
|
|
97
129
|
}
|
|
98
130
|
/**
|
|
131
|
+
* Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
|
|
132
|
+
*
|
|
99
133
|
* @category models
|
|
100
|
-
* @since
|
|
134
|
+
* @since 4.0.0
|
|
101
135
|
*/
|
|
102
136
|
interface Live extends Base {
|
|
103
137
|
readonly liveClient: Libsql.Client;
|
|
104
138
|
}
|
|
105
139
|
}
|
|
106
140
|
/**
|
|
141
|
+
* 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.
|
|
142
|
+
*
|
|
107
143
|
* @category constructor
|
|
108
|
-
* @since
|
|
144
|
+
* @since 4.0.0
|
|
109
145
|
*/
|
|
110
146
|
export declare const make: (options: LibsqlClientConfig) => Effect.Effect<LibsqlClient, never, Scope.Scope | Reactivity.Reactivity>;
|
|
111
147
|
/**
|
|
148
|
+
* Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
149
|
+
*
|
|
112
150
|
* @category layers
|
|
113
|
-
* @since
|
|
151
|
+
* @since 4.0.0
|
|
114
152
|
*/
|
|
115
153
|
export declare const layerConfig: (config: Config.Wrap<LibsqlClientConfig>) => Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError>;
|
|
116
154
|
/**
|
|
155
|
+
* Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
156
|
+
*
|
|
117
157
|
* @category layers
|
|
118
|
-
* @since
|
|
158
|
+
* @since 4.0.0
|
|
119
159
|
*/
|
|
120
160
|
export declare const layer: (config: LibsqlClientConfig) => Layer.Layer<LibsqlClient | Client.SqlClient>;
|
|
121
161
|
//# 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,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AA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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";
|
|
@@ -21,19 +38,25 @@ const classifyError = (cause, message, operation) => classifySqliteError(cause,
|
|
|
21
38
|
operation
|
|
22
39
|
});
|
|
23
40
|
/**
|
|
41
|
+
* Runtime type identifier used to mark `LibsqlClient` values.
|
|
42
|
+
*
|
|
24
43
|
* @category type ids
|
|
25
|
-
* @since
|
|
44
|
+
* @since 4.0.0
|
|
26
45
|
*/
|
|
27
46
|
export const TypeId = "~@effect/sql-libsql/LibsqlClient";
|
|
28
47
|
/**
|
|
48
|
+
* Context tag used to access the `LibsqlClient` service.
|
|
49
|
+
*
|
|
29
50
|
* @category tags
|
|
30
|
-
* @since
|
|
51
|
+
* @since 4.0.0
|
|
31
52
|
*/
|
|
32
53
|
export const LibsqlClient = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient");
|
|
33
54
|
const LibsqlTransaction = /*#__PURE__*/Context.Service("@effect/sql-libsql/LibsqlClient/LibsqlTransaction");
|
|
34
55
|
/**
|
|
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
|
+
*
|
|
35
58
|
* @category constructor
|
|
36
|
-
* @since
|
|
59
|
+
* @since 4.0.0
|
|
37
60
|
*/
|
|
38
61
|
export const make = options => Effect.gen(function* () {
|
|
39
62
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
@@ -148,13 +171,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
148
171
|
});
|
|
149
172
|
});
|
|
150
173
|
/**
|
|
174
|
+
* Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
175
|
+
*
|
|
151
176
|
* @category layers
|
|
152
|
-
* @since
|
|
177
|
+
* @since 4.0.0
|
|
153
178
|
*/
|
|
154
|
-
export const layerConfig = config => Layer.effectContext(Config.unwrap(config).
|
|
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));
|
|
155
180
|
/**
|
|
181
|
+
* Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
182
|
+
*
|
|
156
183
|
* @category layers
|
|
157
|
-
* @since
|
|
184
|
+
* @since 4.0.0
|
|
158
185
|
*/
|
|
159
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));
|
|
160
187
|
//# sourceMappingURL=LibsqlClient.js.map
|
package/dist/LibsqlClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","
|
|
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,OAAO,MAAMC,MAAM,GAAW,kCAAkC;AAqBhE;;;;;;AAMA,OAAO,MAAMC,YAAY,gBAAGnB,OAAO,CAACoB,OAAO,CAAe,iCAAiC,CAAC;AAE5F,MAAMC,iBAAiB,gBAAGrB,OAAO,CAACoB,OAAO,CACvC,mDAAmD,CACpD;AA2FD;;;;;;AAMA,OAAO,MAAME,IAAI,GACfC,OAA2B,IAE3BtB,MAAM,CAACuB,GAAG,CAAC,aAAS;EAClB,MAAMC,QAAQ,GAAGb,SAAS,CAACc,kBAAkB,CAACH,OAAO,CAACI,mBAAm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I,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
|
/**
|
|
34
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
35
|
+
*
|
|
14
36
|
* @category constructor
|
|
15
|
-
* @since
|
|
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
|
/**
|
|
41
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
42
|
+
*
|
|
19
43
|
* @category constructor
|
|
20
|
-
* @since
|
|
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
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
9
|
+
*
|
|
8
10
|
* @category constructor
|
|
9
|
-
* @since
|
|
11
|
+
* @since 4.0.0
|
|
10
12
|
*/
|
|
11
13
|
export const run = /*#__PURE__*/Migrator.make({});
|
|
12
14
|
/**
|
|
15
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
16
|
+
*
|
|
13
17
|
* @category constructor
|
|
14
|
-
* @since
|
|
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,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @since
|
|
5
|
+
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
7
|
export * as LibsqlClient from "./LibsqlClient.ts";
|
|
8
8
|
/**
|
|
9
|
-
* @since
|
|
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
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
5
5
|
/**
|
|
6
|
-
* @since
|
|
6
|
+
* @since 4.0.0
|
|
7
7
|
*/
|
|
8
8
|
export * as LibsqlClient from "./LibsqlClient.js";
|
|
9
9
|
/**
|
|
10
|
-
* @since
|
|
10
|
+
* @since 4.0.0
|
|
11
11
|
*/
|
|
12
12
|
export * as LibsqlMigrator from "./LibsqlMigrator.js";
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-libsql",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.67",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A libSQL toolkit for Effect",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"testcontainers": "^11.14.0",
|
|
49
|
-
"effect": "^4.0.0-beta.
|
|
49
|
+
"effect": "^4.0.0-beta.67"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"effect": "^4.0.0-beta.
|
|
52
|
+
"effect": "^4.0.0-beta.67"
|
|
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,5 +1,22 @@
|
|
|
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,20 +40,26 @@ const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
|
23
40
|
classifySqliteError(cause, { message, operation })
|
|
24
41
|
|
|
25
42
|
/**
|
|
43
|
+
* Runtime type identifier used to mark `LibsqlClient` values.
|
|
44
|
+
*
|
|
26
45
|
* @category type ids
|
|
27
|
-
* @since
|
|
46
|
+
* @since 4.0.0
|
|
28
47
|
*/
|
|
29
48
|
export const TypeId: TypeId = "~@effect/sql-libsql/LibsqlClient"
|
|
30
49
|
|
|
31
50
|
/**
|
|
51
|
+
* Type-level identifier used to mark `LibsqlClient` values.
|
|
52
|
+
*
|
|
32
53
|
* @category type ids
|
|
33
|
-
* @since
|
|
54
|
+
* @since 4.0.0
|
|
34
55
|
*/
|
|
35
56
|
export type TypeId = "~@effect/sql-libsql/LibsqlClient"
|
|
36
57
|
|
|
37
58
|
/**
|
|
59
|
+
* libSQL-backed SQL client service, extending `SqlClient` with its runtime type marker and client configuration.
|
|
60
|
+
*
|
|
38
61
|
* @category models
|
|
39
|
-
* @since
|
|
62
|
+
* @since 4.0.0
|
|
40
63
|
*/
|
|
41
64
|
export interface LibsqlClient extends Client.SqlClient {
|
|
42
65
|
readonly [TypeId]: TypeId
|
|
@@ -44,8 +67,10 @@ export interface LibsqlClient extends Client.SqlClient {
|
|
|
44
67
|
}
|
|
45
68
|
|
|
46
69
|
/**
|
|
70
|
+
* Context tag used to access the `LibsqlClient` service.
|
|
71
|
+
*
|
|
47
72
|
* @category tags
|
|
48
|
-
* @since
|
|
73
|
+
* @since 4.0.0
|
|
49
74
|
*/
|
|
50
75
|
export const LibsqlClient = Context.Service<LibsqlClient>("@effect/sql-libsql/LibsqlClient")
|
|
51
76
|
|
|
@@ -54,19 +79,24 @@ const LibsqlTransaction = Context.Service<readonly [LibsqlConnection, counter: n
|
|
|
54
79
|
)
|
|
55
80
|
|
|
56
81
|
/**
|
|
82
|
+
* Configuration for a libSQL client, either by supplying connection options or an existing live libSQL client.
|
|
83
|
+
*
|
|
57
84
|
* @category models
|
|
58
|
-
* @since
|
|
85
|
+
* @since 4.0.0
|
|
59
86
|
*/
|
|
60
87
|
export type LibsqlClientConfig = LibsqlClientConfig.Full | LibsqlClientConfig.Live
|
|
61
88
|
|
|
62
89
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
90
|
+
* Namespace containing the configuration variants for `LibsqlClient`.
|
|
91
|
+
*
|
|
92
|
+
* @since 4.0.0
|
|
65
93
|
*/
|
|
66
94
|
export declare namespace LibsqlClientConfig {
|
|
67
95
|
/**
|
|
96
|
+
* Shared libSQL client options for span attributes and query/result name transformations.
|
|
97
|
+
*
|
|
68
98
|
* @category models
|
|
69
|
-
* @since
|
|
99
|
+
* @since 4.0.0
|
|
70
100
|
*/
|
|
71
101
|
export interface Base {
|
|
72
102
|
readonly spanAttributes?: Record<string, unknown> | undefined
|
|
@@ -75,8 +105,10 @@ export declare namespace LibsqlClientConfig {
|
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
/**
|
|
108
|
+
* Connection-based libSQL configuration used to create a managed client, including URL, credentials, sync, integer mode, TLS, and concurrency options.
|
|
109
|
+
*
|
|
78
110
|
* @category models
|
|
79
|
-
* @since
|
|
111
|
+
* @since 4.0.0
|
|
80
112
|
*/
|
|
81
113
|
export interface Full extends Base {
|
|
82
114
|
/** The database URL.
|
|
@@ -119,8 +151,10 @@ export declare namespace LibsqlClientConfig {
|
|
|
119
151
|
}
|
|
120
152
|
|
|
121
153
|
/**
|
|
154
|
+
* Configuration that uses an existing libSQL client. The supplied `liveClient` is caller-owned and is not closed by the Effect client.
|
|
155
|
+
*
|
|
122
156
|
* @category models
|
|
123
|
-
* @since
|
|
157
|
+
* @since 4.0.0
|
|
124
158
|
*/
|
|
125
159
|
export interface Live extends Base {
|
|
126
160
|
readonly liveClient: Libsql.Client
|
|
@@ -134,8 +168,10 @@ interface LibsqlConnection extends Connection {
|
|
|
134
168
|
}
|
|
135
169
|
|
|
136
170
|
/**
|
|
171
|
+
* 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.
|
|
172
|
+
*
|
|
137
173
|
* @category constructor
|
|
138
|
-
* @since
|
|
174
|
+
* @since 4.0.0
|
|
139
175
|
*/
|
|
140
176
|
export const make = (
|
|
141
177
|
options: LibsqlClientConfig
|
|
@@ -300,8 +336,10 @@ export const make = (
|
|
|
300
336
|
})
|
|
301
337
|
|
|
302
338
|
/**
|
|
339
|
+
* Creates a layer from a `Config`-wrapped libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
340
|
+
*
|
|
303
341
|
* @category layers
|
|
304
|
-
* @since
|
|
342
|
+
* @since 4.0.0
|
|
305
343
|
*/
|
|
306
344
|
export const layerConfig: (
|
|
307
345
|
config: Config.Wrap<LibsqlClientConfig>
|
|
@@ -309,7 +347,7 @@ export const layerConfig: (
|
|
|
309
347
|
config: Config.Wrap<LibsqlClientConfig>
|
|
310
348
|
): Layer.Layer<LibsqlClient | Client.SqlClient, Config.ConfigError> =>
|
|
311
349
|
Layer.effectContext(
|
|
312
|
-
Config.unwrap(config).
|
|
350
|
+
Config.unwrap(config).pipe(
|
|
313
351
|
Effect.flatMap(make),
|
|
314
352
|
Effect.map((client) =>
|
|
315
353
|
Context.make(LibsqlClient, client).pipe(
|
|
@@ -320,8 +358,10 @@ export const layerConfig: (
|
|
|
320
358
|
).pipe(Layer.provide(Reactivity.layer))
|
|
321
359
|
|
|
322
360
|
/**
|
|
361
|
+
* Creates a layer from a concrete libSQL client configuration, providing both `LibsqlClient` and `SqlClient`.
|
|
362
|
+
*
|
|
323
363
|
* @category layers
|
|
324
|
-
* @since
|
|
364
|
+
* @since 4.0.0
|
|
325
365
|
*/
|
|
326
366
|
export const layer = (
|
|
327
367
|
config: LibsqlClientConfig
|
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
|
/**
|
|
36
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
37
|
+
*
|
|
16
38
|
* @category constructor
|
|
17
|
-
* @since
|
|
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
|
/**
|
|
50
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
51
|
+
*
|
|
28
52
|
* @category constructor
|
|
29
|
-
* @since
|
|
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,15 @@
|
|
|
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
|
-
* @since
|
|
8
|
+
* @since 4.0.0
|
|
9
9
|
*/
|
|
10
10
|
export * as LibsqlClient from "./LibsqlClient.ts"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @since
|
|
13
|
+
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export * as LibsqlMigrator from "./LibsqlMigrator.ts"
|