@effect/sql-sqlite-do 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/SqliteClient.d.ts +48 -14
- package/dist/SqliteClient.d.ts.map +1 -1
- package/dist/SqliteClient.js +29 -17
- package/dist/SqliteClient.js.map +1 -1
- package/dist/SqliteMigrator.d.ts +31 -6
- package/dist/SqliteMigrator.d.ts.map +1 -1
- package/dist/SqliteMigrator.js +9 -5
- package/dist/SqliteMigrator.js.map +1 -1
- package/dist/index.d.ts +42 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/SqliteClient.ts +62 -25
- package/src/SqliteMigrator.ts +31 -6
- package/src/index.ts +42 -3
package/dist/SqliteClient.d.ts
CHANGED
|
@@ -1,27 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides an Effect SQL client for Cloudflare Durable Object SQLite storage.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts a Durable Object `SqlStorage` handle into both the
|
|
5
|
+
* Durable Object-specific `SqliteClient` service and the generic Effect
|
|
6
|
+
* `SqlClient` service. Use it from inside a Durable Object to run local
|
|
7
|
+
* per-object queries, repositories, migrations, transactional read/write
|
|
8
|
+
* workflows, and tests that exercise Cloudflare's SQLite-backed storage API.
|
|
9
|
+
*
|
|
10
|
+
* Durable Object SQLite storage is scoped to one object id, so each object
|
|
11
|
+
* instance has its own database and callers should pass the same `SqlStorage`
|
|
12
|
+
* handle that the object uses for normal reads and writes. This adapter
|
|
13
|
+
* serializes Effect SQL access through one connection; a transaction holds that
|
|
14
|
+
* permit for the lifetime of its scope, so keep transactions short, avoid
|
|
15
|
+
* suspending them across unrelated work, and use them when multi-statement
|
|
16
|
+
* writes must commit atomically. `SqlStorage.exec` returns `ArrayBuffer` values
|
|
17
|
+
* for SQLite blobs, which this client normalizes to `Uint8Array`, and SQLite
|
|
18
|
+
* does not support `updateValues`.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import type { SqlStorage } from "@cloudflare/workers-types";
|
|
5
23
|
import * as Config from "effect/Config";
|
|
24
|
+
import * as Context from "effect/Context";
|
|
6
25
|
import * as Effect from "effect/Effect";
|
|
7
26
|
import * as Layer from "effect/Layer";
|
|
8
27
|
import * as Scope from "effect/Scope";
|
|
9
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
10
28
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
11
29
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
12
30
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
31
|
+
* Runtime type identifier used to mark Cloudflare Durable Object `SqliteClient` values.
|
|
32
|
+
*
|
|
33
|
+
* @category type IDs
|
|
34
|
+
* @since 4.0.0
|
|
15
35
|
*/
|
|
16
36
|
export declare const TypeId: TypeId;
|
|
17
37
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
38
|
+
* Type-level identifier used to mark Cloudflare Durable Object `SqliteClient` values.
|
|
39
|
+
*
|
|
40
|
+
* @category type IDs
|
|
41
|
+
* @since 4.0.0
|
|
20
42
|
*/
|
|
21
43
|
export type TypeId = "~@effect/sql-sqlite-do/SqliteClient";
|
|
22
44
|
/**
|
|
45
|
+
* Cloudflare Durable Object SQLite client service, extending `SqlClient` with its configuration. `updateValues` is not supported.
|
|
46
|
+
*
|
|
23
47
|
* @category models
|
|
24
|
-
* @since
|
|
48
|
+
* @since 4.0.0
|
|
25
49
|
*/
|
|
26
50
|
export interface SqliteClient extends Client.SqlClient {
|
|
27
51
|
readonly [TypeId]: TypeId;
|
|
@@ -30,13 +54,17 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
30
54
|
readonly updateValues: never;
|
|
31
55
|
}
|
|
32
56
|
/**
|
|
57
|
+
* Context tag used to access the Cloudflare Durable Object `SqliteClient` service.
|
|
58
|
+
*
|
|
33
59
|
* @category tags
|
|
34
|
-
* @since
|
|
60
|
+
* @since 4.0.0
|
|
35
61
|
*/
|
|
36
|
-
export declare const SqliteClient:
|
|
62
|
+
export declare const SqliteClient: Context.Service<SqliteClient, SqliteClient>;
|
|
37
63
|
/**
|
|
64
|
+
* Configuration for a Cloudflare Durable Object SQLite client, including the `SqlStorage` handle, span attributes, and query/result name transforms.
|
|
65
|
+
*
|
|
38
66
|
* @category models
|
|
39
|
-
* @since
|
|
67
|
+
* @since 4.0.0
|
|
40
68
|
*/
|
|
41
69
|
export interface SqliteClientConfig {
|
|
42
70
|
readonly db: SqlStorage;
|
|
@@ -45,18 +73,24 @@ export interface SqliteClientConfig {
|
|
|
45
73
|
readonly transformQueryNames?: ((str: string) => string) | undefined;
|
|
46
74
|
}
|
|
47
75
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
76
|
+
* Creates a scoped Cloudflare Durable Object SQLite client around `SqlStorage`, serializing access and converting returned `ArrayBuffer` values to `Uint8Array`.
|
|
77
|
+
*
|
|
78
|
+
* @category constructors
|
|
79
|
+
* @since 4.0.0
|
|
50
80
|
*/
|
|
51
81
|
export declare const make: (options: SqliteClientConfig) => Effect.Effect<SqliteClient, never, Scope.Scope | Reactivity.Reactivity>;
|
|
52
82
|
/**
|
|
83
|
+
* Creates a layer from a `Config`-wrapped Durable Object SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
84
|
+
*
|
|
53
85
|
* @category layers
|
|
54
|
-
* @since
|
|
86
|
+
* @since 4.0.0
|
|
55
87
|
*/
|
|
56
88
|
export declare const layerConfig: (config: Config.Wrap<SqliteClientConfig>) => Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError>;
|
|
57
89
|
/**
|
|
90
|
+
* Creates a layer from a concrete Durable Object SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
91
|
+
*
|
|
58
92
|
* @category layers
|
|
59
|
-
* @since
|
|
93
|
+
* @since 4.0.0
|
|
60
94
|
*/
|
|
61
95
|
export declare const layer: (config: SqliteClientConfig) => Layer.Layer<SqliteClient | Client.SqlClient>;
|
|
62
96
|
//# sourceMappingURL=SqliteClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../src/SqliteClient.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"SqliteClient.d.ts","sourceRoot":"","sources":["../src/SqliteClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAUvD;;;;;GAKG;AACH,eAAO,MAAM,MAAM,EAAE,MAA8C,CAAA;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,qCAAqC,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,SAAS;IACpD,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;IAEnC,8BAA8B;IAC9B,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAA;CAC7B;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,6CAAsE,CAAA;AAE/F;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,UAAU,CAAA;IACvB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAE7D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;IACrE,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GACf,SAAS,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAmHrE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,KACtC,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAUzB,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,QAAQ,kBAAkB,KACzB,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAML,CAAA"}
|
package/dist/SqliteClient.js
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
1
|
import * as Config from "effect/Config";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import * as Fiber from "effect/Fiber";
|
|
4
5
|
import { identity } from "effect/Function";
|
|
5
6
|
import * as Layer from "effect/Layer";
|
|
6
7
|
import * as Scope from "effect/Scope";
|
|
7
8
|
import * as Semaphore from "effect/Semaphore";
|
|
8
|
-
import * as ServiceMap from "effect/ServiceMap";
|
|
9
9
|
import * as Stream from "effect/Stream";
|
|
10
10
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
11
11
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
12
|
-
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
12
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError";
|
|
13
13
|
import * as Statement from "effect/unstable/sql/Statement";
|
|
14
14
|
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
15
|
+
const classifyError = (cause, message, operation) => classifySqliteError(cause, {
|
|
16
|
+
message,
|
|
17
|
+
operation
|
|
18
|
+
});
|
|
15
19
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* Runtime type identifier used to mark Cloudflare Durable Object `SqliteClient` values.
|
|
21
|
+
*
|
|
22
|
+
* @category type IDs
|
|
23
|
+
* @since 4.0.0
|
|
18
24
|
*/
|
|
19
25
|
export const TypeId = "~@effect/sql-sqlite-do/SqliteClient";
|
|
20
26
|
/**
|
|
27
|
+
* Context tag used to access the Cloudflare Durable Object `SqliteClient` service.
|
|
28
|
+
*
|
|
21
29
|
* @category tags
|
|
22
|
-
* @since
|
|
30
|
+
* @since 4.0.0
|
|
23
31
|
*/
|
|
24
|
-
export const SqliteClient = /*#__PURE__*/
|
|
32
|
+
export const SqliteClient = /*#__PURE__*/Context.Service("@effect/sql-sqlite-do/SqliteClient");
|
|
25
33
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
34
|
+
* Creates a scoped Cloudflare Durable Object SQLite client around `SqlStorage`, serializing access and converting returned `ArrayBuffer` values to `Uint8Array`.
|
|
35
|
+
*
|
|
36
|
+
* @category constructors
|
|
37
|
+
* @since 4.0.0
|
|
28
38
|
*/
|
|
29
39
|
export const make = options => Effect.gen(function* () {
|
|
30
40
|
const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
|
|
@@ -46,8 +56,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
46
56
|
const runStatement = (sql, params = []) => Effect.try({
|
|
47
57
|
try: () => Array.from(runIterator(sql, params)),
|
|
48
58
|
catch: cause => new SqlError({
|
|
49
|
-
cause,
|
|
50
|
-
message: `Failed to execute statement`
|
|
59
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
51
60
|
})
|
|
52
61
|
});
|
|
53
62
|
const runValues = (sql, params = []) => Effect.try({
|
|
@@ -61,8 +70,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
61
70
|
return row;
|
|
62
71
|
}),
|
|
63
72
|
catch: cause => new SqlError({
|
|
64
|
-
cause,
|
|
65
|
-
message: `Failed to execute statement`
|
|
73
|
+
reason: classifyError(cause, "Failed to execute statement", "execute")
|
|
66
74
|
})
|
|
67
75
|
});
|
|
68
76
|
return identity({
|
|
@@ -91,7 +99,7 @@ export const make = options => Effect.gen(function* () {
|
|
|
91
99
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection));
|
|
92
100
|
const transactionAcquirer = Effect.uninterruptibleMask(restore => {
|
|
93
101
|
const fiber = Fiber.getCurrent();
|
|
94
|
-
const scope =
|
|
102
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope);
|
|
95
103
|
return Effect.as(Effect.tap(restore(semaphore.take(1)), () => Scope.addFinalizer(scope, semaphore.release(1))), connection);
|
|
96
104
|
});
|
|
97
105
|
return Object.assign(yield* Client.make({
|
|
@@ -106,13 +114,17 @@ export const make = options => Effect.gen(function* () {
|
|
|
106
114
|
});
|
|
107
115
|
});
|
|
108
116
|
/**
|
|
117
|
+
* Creates a layer from a `Config`-wrapped Durable Object SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
118
|
+
*
|
|
109
119
|
* @category layers
|
|
110
|
-
* @since
|
|
120
|
+
* @since 4.0.0
|
|
111
121
|
*/
|
|
112
|
-
export const layerConfig = config => Layer.
|
|
122
|
+
export const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
|
|
113
123
|
/**
|
|
124
|
+
* Creates a layer from a concrete Durable Object SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
125
|
+
*
|
|
114
126
|
* @category layers
|
|
115
|
-
* @since
|
|
127
|
+
* @since 4.0.0
|
|
116
128
|
*/
|
|
117
|
-
export const layer = config => Layer.
|
|
129
|
+
export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(SqliteClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
|
|
118
130
|
//# sourceMappingURL=SqliteClient.js.map
|
package/dist/SqliteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteClient.js","names":["Config","Effect","Fiber","identity","Layer","Scope","Semaphore","
|
|
1
|
+
{"version":3,"file":"SqliteClient.js","names":["Config","Context","Effect","Fiber","identity","Layer","Scope","Semaphore","Stream","Reactivity","Client","classifySqliteError","SqlError","Statement","ATTR_DB_SYSTEM_NAME","classifyError","cause","message","operation","TypeId","SqliteClient","Service","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","runIterator","sql","params","cursor","exec","columns","columnNames","result","raw","obj","i","length","value","ArrayBuffer","Uint8Array","runStatement","try","Array","from","catch","reason","runValues","row","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","suspend","iterator","fromIteratorSucceed","pipe","mapArray","chunk","semaphore","connection","acquirer","withPermits","succeed","transactionAcquirer","uninterruptibleMask","restore","fiber","getCurrent","scope","getUnsafe","context","as","tap","take","addFinalizer","release","Object","assign","spanAttributes","entries","config","layerConfig","effectContext","unwrap","flatMap","client","add","SqlClient","provide","layer"],"sources":["../src/SqliteClient.ts"],"sourcesContent":[null],"mappings":"AAsBA,OAAO,KAAKA,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,SAASC,QAAQ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ACH,CAAC,CAAC;AAEJ;;;;;;AAMA,OAAO,MAAMsE,WAAW,GACtBD,MAAuC,IAEvCvF,KAAK,CAACyF,aAAa,CACjB9F,MAAM,CAAC+F,MAAM,CAACH,MAAM,CAAC,CAACzB,IAAI,CACxBjE,MAAM,CAAC8F,OAAO,CAAC1E,IAAI,CAAC,EACpBpB,MAAM,CAACyD,GAAG,CAAEsC,MAAM,IAChBhG,OAAO,CAACqB,IAAI,CAACF,YAAY,EAAE6E,MAAM,CAAC,CAAC9B,IAAI,CACrClE,OAAO,CAACiG,GAAG,CAACxF,MAAM,CAACyF,SAAS,EAAEF,MAAM,CAAC,CACtC,CACF,CACF,CACF,CAAC9B,IAAI,CAAC9D,KAAK,CAAC+F,OAAO,CAAC3F,UAAU,CAAC4F,KAAK,CAAC,CAAC;AAEzC;;;;;;AAMA,OAAO,MAAMA,KAAK,GAChBT,MAA0B,IAE1BvF,KAAK,CAACyF,aAAa,CACjB5F,MAAM,CAACyD,GAAG,CAACrC,IAAI,CAACsE,MAAM,CAAC,EAAGK,MAAM,IAC9BhG,OAAO,CAACqB,IAAI,CAACF,YAAY,EAAE6E,MAAM,CAAC,CAAC9B,IAAI,CACrClE,OAAO,CAACiG,GAAG,CAACxF,MAAM,CAACyF,SAAS,EAAEF,MAAM,CAAC,CACtC,CAAC,CACL,CAAC9B,IAAI,CAAC9D,KAAK,CAAC+F,OAAO,CAAC3F,UAAU,CAAC4F,KAAK,CAAC,CAAC","ignoreList":[]}
|
package/dist/SqliteMigrator.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for applying Effect SQL migrations to Cloudflare Durable Object SQLite storage.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
5
|
+
* provides `run` and `layer` helpers that execute ordered migrations through the
|
|
6
|
+
* current Durable Object `SqlStorage`-backed `SqlClient`. Use it when a Durable
|
|
7
|
+
* Object needs to create or upgrade its local schema during construction, before
|
|
8
|
+
* repositories or request handlers use the object storage, or in tests that
|
|
9
|
+
* exercise Durable Object persistence.
|
|
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. The underlying
|
|
13
|
+
* storage is scoped to a Durable Object id, so running migrations for one object
|
|
14
|
+
* does not update any other object instance; run the migrator against the same
|
|
15
|
+
* `SqlStorage` handle that the object uses for normal queries. These SQL
|
|
16
|
+
* migrations are separate from Cloudflare's Durable Object class migrations, and
|
|
17
|
+
* the Durable Object must already be configured with SQLite storage before this
|
|
18
|
+
* module can apply schema changes. Repeated startup runs are expected and are
|
|
19
|
+
* guarded by the migrations table, but request handling should wait until the
|
|
20
|
+
* migration layer has finished. This adapter does not currently write SQLite
|
|
21
|
+
* schema dumps for `schemaDirectory`.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import type * as Effect from "effect/Effect";
|
|
5
26
|
import * as Layer from "effect/Layer";
|
|
@@ -7,17 +28,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
|
|
|
7
28
|
import type * as Client from "effect/unstable/sql/SqlClient";
|
|
8
29
|
import type { SqlError } from "effect/unstable/sql/SqlError";
|
|
9
30
|
/**
|
|
10
|
-
* @since
|
|
31
|
+
* @since 4.0.0
|
|
11
32
|
*/
|
|
12
33
|
export * from "effect/unstable/sql/Migrator";
|
|
13
34
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
35
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
36
|
+
*
|
|
37
|
+
* @category constructors
|
|
38
|
+
* @since 4.0.0
|
|
16
39
|
*/
|
|
17
40
|
export declare const run: <R2 = never>({ loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
|
|
18
41
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
42
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
43
|
+
*
|
|
44
|
+
* @category constructors
|
|
45
|
+
* @since 4.0.0
|
|
21
46
|
*/
|
|
22
47
|
export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
|
|
23
48
|
//# sourceMappingURL=SqliteMigrator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteMigrator.d.ts","sourceRoot":"","sources":["../src/SqliteMigrator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"SqliteMigrator.d.ts","sourceRoot":"","sources":["../src/SqliteMigrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;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,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAC7D,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,EAAE,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/SqliteMigrator.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=SqliteMigrator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"SqliteMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":"AAyBA,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,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Provides an Effect SQL client for Cloudflare Durable Object SQLite storage.
|
|
6
|
+
*
|
|
7
|
+
* This module adapts a Durable Object `SqlStorage` handle into both the
|
|
8
|
+
* Durable Object-specific `SqliteClient` service and the generic Effect
|
|
9
|
+
* `SqlClient` service. Use it from inside a Durable Object to run local
|
|
10
|
+
* per-object queries, repositories, migrations, transactional read/write
|
|
11
|
+
* workflows, and tests that exercise Cloudflare's SQLite-backed storage API.
|
|
12
|
+
*
|
|
13
|
+
* Durable Object SQLite storage is scoped to one object id, so each object
|
|
14
|
+
* instance has its own database and callers should pass the same `SqlStorage`
|
|
15
|
+
* handle that the object uses for normal reads and writes. This adapter
|
|
16
|
+
* serializes Effect SQL access through one connection; a transaction holds that
|
|
17
|
+
* permit for the lifetime of its scope, so keep transactions short, avoid
|
|
18
|
+
* suspending them across unrelated work, and use them when multi-statement
|
|
19
|
+
* writes must commit atomically. `SqlStorage.exec` returns `ArrayBuffer` values
|
|
20
|
+
* for SQLite blobs, which this client normalizes to `Uint8Array`, and SQLite
|
|
21
|
+
* does not support `updateValues`.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
6
24
|
*/
|
|
7
25
|
export * as SqliteClient from "./SqliteClient.ts";
|
|
8
26
|
/**
|
|
9
|
-
*
|
|
27
|
+
* Utilities for applying Effect SQL migrations to Cloudflare Durable Object SQLite storage.
|
|
28
|
+
*
|
|
29
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
30
|
+
* provides `run` and `layer` helpers that execute ordered migrations through the
|
|
31
|
+
* current Durable Object `SqlStorage`-backed `SqlClient`. Use it when a Durable
|
|
32
|
+
* Object needs to create or upgrade its local schema during construction, before
|
|
33
|
+
* repositories or request handlers use the object storage, or in tests that
|
|
34
|
+
* exercise Durable Object persistence.
|
|
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. The underlying
|
|
38
|
+
* storage is scoped to a Durable Object id, so running migrations for one object
|
|
39
|
+
* does not update any other object instance; run the migrator against the same
|
|
40
|
+
* `SqlStorage` handle that the object uses for normal queries. These SQL
|
|
41
|
+
* migrations are separate from Cloudflare's Durable Object class migrations, and
|
|
42
|
+
* the Durable Object must already be configured with SQLite storage before this
|
|
43
|
+
* module can apply schema changes. Repeated startup runs are expected and are
|
|
44
|
+
* guarded by the migrations table, but request handling should wait until the
|
|
45
|
+
* migration layer has finished. This adapter does not currently write SQLite
|
|
46
|
+
* schema dumps for `schemaDirectory`.
|
|
47
|
+
*
|
|
48
|
+
* @since 4.0.0
|
|
10
49
|
*/
|
|
11
50
|
export * as SqliteMigrator from "./SqliteMigrator.ts";
|
|
12
51
|
//# 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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
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
|
+
* Provides an Effect SQL client for Cloudflare Durable Object SQLite storage.
|
|
7
|
+
*
|
|
8
|
+
* This module adapts a Durable Object `SqlStorage` handle into both the
|
|
9
|
+
* Durable Object-specific `SqliteClient` service and the generic Effect
|
|
10
|
+
* `SqlClient` service. Use it from inside a Durable Object to run local
|
|
11
|
+
* per-object queries, repositories, migrations, transactional read/write
|
|
12
|
+
* workflows, and tests that exercise Cloudflare's SQLite-backed storage API.
|
|
13
|
+
*
|
|
14
|
+
* Durable Object SQLite storage is scoped to one object id, so each object
|
|
15
|
+
* instance has its own database and callers should pass the same `SqlStorage`
|
|
16
|
+
* handle that the object uses for normal reads and writes. This adapter
|
|
17
|
+
* serializes Effect SQL access through one connection; a transaction holds that
|
|
18
|
+
* permit for the lifetime of its scope, so keep transactions short, avoid
|
|
19
|
+
* suspending them across unrelated work, and use them when multi-statement
|
|
20
|
+
* writes must commit atomically. `SqlStorage.exec` returns `ArrayBuffer` values
|
|
21
|
+
* for SQLite blobs, which this client normalizes to `Uint8Array`, and SQLite
|
|
22
|
+
* does not support `updateValues`.
|
|
23
|
+
*
|
|
24
|
+
* @since 4.0.0
|
|
7
25
|
*/
|
|
8
26
|
export * as SqliteClient from "./SqliteClient.js";
|
|
9
27
|
/**
|
|
10
|
-
*
|
|
28
|
+
* Utilities for applying Effect SQL migrations to Cloudflare Durable Object SQLite storage.
|
|
29
|
+
*
|
|
30
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
31
|
+
* provides `run` and `layer` helpers that execute ordered migrations through the
|
|
32
|
+
* current Durable Object `SqlStorage`-backed `SqlClient`. Use it when a Durable
|
|
33
|
+
* Object needs to create or upgrade its local schema during construction, before
|
|
34
|
+
* repositories or request handlers use the object storage, or in tests that
|
|
35
|
+
* exercise Durable Object persistence.
|
|
36
|
+
*
|
|
37
|
+
* Migrations are recorded in `effect_sql_migrations` by default and are loaded
|
|
38
|
+
* using the shared `<id>_<name>` file or record-key convention. The underlying
|
|
39
|
+
* storage is scoped to a Durable Object id, so running migrations for one object
|
|
40
|
+
* does not update any other object instance; run the migrator against the same
|
|
41
|
+
* `SqlStorage` handle that the object uses for normal queries. These SQL
|
|
42
|
+
* migrations are separate from Cloudflare's Durable Object class migrations, and
|
|
43
|
+
* the Durable Object must already be configured with SQLite storage before this
|
|
44
|
+
* module can apply schema changes. Repeated startup runs are expected and are
|
|
45
|
+
* guarded by the migrations table, but request handling should wait until the
|
|
46
|
+
* migration layer has finished. This adapter does not currently write SQLite
|
|
47
|
+
* schema dumps for `schemaDirectory`.
|
|
48
|
+
*
|
|
49
|
+
* @since 4.0.0
|
|
11
50
|
*/
|
|
12
51
|
export * as SqliteMigrator from "./SqliteMigrator.js";
|
|
13
52
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SqliteClient","SqliteMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA
|
|
1
|
+
{"version":3,"file":"index.js","names":["SqliteClient","SqliteMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,KAAKA,YAAY,MAAM,mBAAmB;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,KAAKC,cAAc,MAAM,qBAAqB","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-sqlite-do",
|
|
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 SQLite toolkit for Effect",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"provenance": true
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@cloudflare/workers-types": "^4.
|
|
47
|
-
"effect": "^4.0.0-beta.
|
|
46
|
+
"@cloudflare/workers-types": "^4.20260511.1",
|
|
47
|
+
"effect": "^4.0.0-beta.70"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"effect": "^4.0.0-beta.
|
|
50
|
+
"effect": "^4.0.0-beta.70"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"codegen": "effect-utils codegen",
|
package/src/SqliteClient.ts
CHANGED
|
@@ -1,39 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides an Effect SQL client for Cloudflare Durable Object SQLite storage.
|
|
3
|
+
*
|
|
4
|
+
* This module adapts a Durable Object `SqlStorage` handle into both the
|
|
5
|
+
* Durable Object-specific `SqliteClient` service and the generic Effect
|
|
6
|
+
* `SqlClient` service. Use it from inside a Durable Object to run local
|
|
7
|
+
* per-object queries, repositories, migrations, transactional read/write
|
|
8
|
+
* workflows, and tests that exercise Cloudflare's SQLite-backed storage API.
|
|
9
|
+
*
|
|
10
|
+
* Durable Object SQLite storage is scoped to one object id, so each object
|
|
11
|
+
* instance has its own database and callers should pass the same `SqlStorage`
|
|
12
|
+
* handle that the object uses for normal reads and writes. This adapter
|
|
13
|
+
* serializes Effect SQL access through one connection; a transaction holds that
|
|
14
|
+
* permit for the lifetime of its scope, so keep transactions short, avoid
|
|
15
|
+
* suspending them across unrelated work, and use them when multi-statement
|
|
16
|
+
* writes must commit atomically. `SqlStorage.exec` returns `ArrayBuffer` values
|
|
17
|
+
* for SQLite blobs, which this client normalizes to `Uint8Array`, and SQLite
|
|
18
|
+
* does not support `updateValues`.
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
import type { SqlStorage } from "@cloudflare/workers-types"
|
|
5
23
|
import * as Config from "effect/Config"
|
|
24
|
+
import * as Context from "effect/Context"
|
|
6
25
|
import * as Effect from "effect/Effect"
|
|
7
26
|
import * as Fiber from "effect/Fiber"
|
|
8
27
|
import { identity } from "effect/Function"
|
|
9
28
|
import * as Layer from "effect/Layer"
|
|
10
29
|
import * as Scope from "effect/Scope"
|
|
11
30
|
import * as Semaphore from "effect/Semaphore"
|
|
12
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
13
31
|
import * as Stream from "effect/Stream"
|
|
14
32
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity"
|
|
15
33
|
import * as Client from "effect/unstable/sql/SqlClient"
|
|
16
34
|
import type { Connection } from "effect/unstable/sql/SqlConnection"
|
|
17
|
-
import { SqlError } from "effect/unstable/sql/SqlError"
|
|
35
|
+
import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
|
|
18
36
|
import * as Statement from "effect/unstable/sql/Statement"
|
|
19
37
|
|
|
20
38
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
21
39
|
|
|
40
|
+
const classifyError = (cause: unknown, message: string, operation: string) =>
|
|
41
|
+
classifySqliteError(cause, { message, operation })
|
|
42
|
+
|
|
22
43
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
44
|
+
* Runtime type identifier used to mark Cloudflare Durable Object `SqliteClient` values.
|
|
45
|
+
*
|
|
46
|
+
* @category type IDs
|
|
47
|
+
* @since 4.0.0
|
|
25
48
|
*/
|
|
26
49
|
export const TypeId: TypeId = "~@effect/sql-sqlite-do/SqliteClient"
|
|
27
50
|
|
|
28
51
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
52
|
+
* Type-level identifier used to mark Cloudflare Durable Object `SqliteClient` values.
|
|
53
|
+
*
|
|
54
|
+
* @category type IDs
|
|
55
|
+
* @since 4.0.0
|
|
31
56
|
*/
|
|
32
57
|
export type TypeId = "~@effect/sql-sqlite-do/SqliteClient"
|
|
33
58
|
|
|
34
59
|
/**
|
|
60
|
+
* Cloudflare Durable Object SQLite client service, extending `SqlClient` with its configuration. `updateValues` is not supported.
|
|
61
|
+
*
|
|
35
62
|
* @category models
|
|
36
|
-
* @since
|
|
63
|
+
* @since 4.0.0
|
|
37
64
|
*/
|
|
38
65
|
export interface SqliteClient extends Client.SqlClient {
|
|
39
66
|
readonly [TypeId]: TypeId
|
|
@@ -44,14 +71,18 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
/**
|
|
74
|
+
* Context tag used to access the Cloudflare Durable Object `SqliteClient` service.
|
|
75
|
+
*
|
|
47
76
|
* @category tags
|
|
48
|
-
* @since
|
|
77
|
+
* @since 4.0.0
|
|
49
78
|
*/
|
|
50
|
-
export const SqliteClient =
|
|
79
|
+
export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-do/SqliteClient")
|
|
51
80
|
|
|
52
81
|
/**
|
|
82
|
+
* Configuration for a Cloudflare Durable Object SQLite client, including the `SqlStorage` handle, span attributes, and query/result name transforms.
|
|
83
|
+
*
|
|
53
84
|
* @category models
|
|
54
|
-
* @since
|
|
85
|
+
* @since 4.0.0
|
|
55
86
|
*/
|
|
56
87
|
export interface SqliteClientConfig {
|
|
57
88
|
readonly db: SqlStorage
|
|
@@ -62,8 +93,10 @@ export interface SqliteClientConfig {
|
|
|
62
93
|
}
|
|
63
94
|
|
|
64
95
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
96
|
+
* Creates a scoped Cloudflare Durable Object SQLite client around `SqlStorage`, serializing access and converting returned `ArrayBuffer` values to `Uint8Array`.
|
|
97
|
+
*
|
|
98
|
+
* @category constructors
|
|
99
|
+
* @since 4.0.0
|
|
67
100
|
*/
|
|
68
101
|
export const make = (
|
|
69
102
|
options: SqliteClientConfig
|
|
@@ -99,7 +132,7 @@ export const make = (
|
|
|
99
132
|
): Effect.Effect<ReadonlyArray<any>, SqlError, never> =>
|
|
100
133
|
Effect.try({
|
|
101
134
|
try: () => Array.from(runIterator(sql, params)),
|
|
102
|
-
catch: (cause) => new SqlError({ cause,
|
|
135
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
|
|
103
136
|
})
|
|
104
137
|
|
|
105
138
|
const runValues = (
|
|
@@ -117,7 +150,7 @@ export const make = (
|
|
|
117
150
|
}
|
|
118
151
|
return row
|
|
119
152
|
}),
|
|
120
|
-
catch: (cause) => new SqlError({ cause,
|
|
153
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
|
|
121
154
|
})
|
|
122
155
|
|
|
123
156
|
return identity<Connection>({
|
|
@@ -156,7 +189,7 @@ export const make = (
|
|
|
156
189
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
157
190
|
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
158
191
|
const fiber = Fiber.getCurrent()!
|
|
159
|
-
const scope =
|
|
192
|
+
const scope = Context.getUnsafe(fiber.context, Scope.Scope)
|
|
160
193
|
return Effect.as(
|
|
161
194
|
Effect.tap(
|
|
162
195
|
restore(semaphore.take(1)),
|
|
@@ -185,33 +218,37 @@ export const make = (
|
|
|
185
218
|
})
|
|
186
219
|
|
|
187
220
|
/**
|
|
221
|
+
* Creates a layer from a `Config`-wrapped Durable Object SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
222
|
+
*
|
|
188
223
|
* @category layers
|
|
189
|
-
* @since
|
|
224
|
+
* @since 4.0.0
|
|
190
225
|
*/
|
|
191
226
|
export const layerConfig = (
|
|
192
227
|
config: Config.Wrap<SqliteClientConfig>
|
|
193
228
|
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError> =>
|
|
194
|
-
Layer.
|
|
195
|
-
Config.unwrap(config).
|
|
229
|
+
Layer.effectContext(
|
|
230
|
+
Config.unwrap(config).pipe(
|
|
196
231
|
Effect.flatMap(make),
|
|
197
232
|
Effect.map((client) =>
|
|
198
|
-
|
|
199
|
-
|
|
233
|
+
Context.make(SqliteClient, client).pipe(
|
|
234
|
+
Context.add(Client.SqlClient, client)
|
|
200
235
|
)
|
|
201
236
|
)
|
|
202
237
|
)
|
|
203
238
|
).pipe(Layer.provide(Reactivity.layer))
|
|
204
239
|
|
|
205
240
|
/**
|
|
241
|
+
* Creates a layer from a concrete Durable Object SQLite client configuration, providing both `SqliteClient` and `SqlClient`.
|
|
242
|
+
*
|
|
206
243
|
* @category layers
|
|
207
|
-
* @since
|
|
244
|
+
* @since 4.0.0
|
|
208
245
|
*/
|
|
209
246
|
export const layer = (
|
|
210
247
|
config: SqliteClientConfig
|
|
211
248
|
): Layer.Layer<SqliteClient | Client.SqlClient> =>
|
|
212
|
-
Layer.
|
|
249
|
+
Layer.effectContext(
|
|
213
250
|
Effect.map(make(config), (client) =>
|
|
214
|
-
|
|
215
|
-
|
|
251
|
+
Context.make(SqliteClient, client).pipe(
|
|
252
|
+
Context.add(Client.SqlClient, client)
|
|
216
253
|
))
|
|
217
254
|
).pipe(Layer.provide(Reactivity.layer))
|
package/src/SqliteMigrator.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Utilities for applying Effect SQL migrations to Cloudflare Durable Object SQLite storage.
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
5
|
+
* provides `run` and `layer` helpers that execute ordered migrations through the
|
|
6
|
+
* current Durable Object `SqlStorage`-backed `SqlClient`. Use it when a Durable
|
|
7
|
+
* Object needs to create or upgrade its local schema during construction, before
|
|
8
|
+
* repositories or request handlers use the object storage, or in tests that
|
|
9
|
+
* exercise Durable Object persistence.
|
|
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. The underlying
|
|
13
|
+
* storage is scoped to a Durable Object id, so running migrations for one object
|
|
14
|
+
* does not update any other object instance; run the migrator against the same
|
|
15
|
+
* `SqlStorage` handle that the object uses for normal queries. These SQL
|
|
16
|
+
* migrations are separate from Cloudflare's Durable Object class migrations, and
|
|
17
|
+
* the Durable Object must already be configured with SQLite storage before this
|
|
18
|
+
* module can apply schema changes. Repeated startup runs are expected and are
|
|
19
|
+
* guarded by the migrations table, but request handling should wait until the
|
|
20
|
+
* migration layer has finished. This adapter does not currently write SQLite
|
|
21
|
+
* schema dumps for `schemaDirectory`.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import type * as Effect from "effect/Effect"
|
|
5
26
|
import * as Layer from "effect/Layer"
|
|
@@ -8,13 +29,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
|
|
|
8
29
|
import type { SqlError } from "effect/unstable/sql/SqlError"
|
|
9
30
|
|
|
10
31
|
/**
|
|
11
|
-
* @since
|
|
32
|
+
* @since 4.0.0
|
|
12
33
|
*/
|
|
13
34
|
export * from "effect/unstable/sql/Migrator"
|
|
14
35
|
|
|
15
36
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
37
|
+
* Runs SQL migrations using the configured `SqlClient`, returning the migrations that were applied.
|
|
38
|
+
*
|
|
39
|
+
* @category constructors
|
|
40
|
+
* @since 4.0.0
|
|
18
41
|
*/
|
|
19
42
|
export const run: <R2 = never>(
|
|
20
43
|
{ loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>
|
|
@@ -25,8 +48,10 @@ export const run: <R2 = never>(
|
|
|
25
48
|
> = Migrator.make({})
|
|
26
49
|
|
|
27
50
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
51
|
+
* Creates a layer that runs the configured SQL migrations during layer construction.
|
|
52
|
+
*
|
|
53
|
+
* @category constructors
|
|
54
|
+
* @since 4.0.0
|
|
30
55
|
*/
|
|
31
56
|
export const layer = <R>(
|
|
32
57
|
options: Migrator.MigratorOptions<R>
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,54 @@
|
|
|
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
|
+
* Provides an Effect SQL client for Cloudflare Durable Object SQLite storage.
|
|
9
|
+
*
|
|
10
|
+
* This module adapts a Durable Object `SqlStorage` handle into both the
|
|
11
|
+
* Durable Object-specific `SqliteClient` service and the generic Effect
|
|
12
|
+
* `SqlClient` service. Use it from inside a Durable Object to run local
|
|
13
|
+
* per-object queries, repositories, migrations, transactional read/write
|
|
14
|
+
* workflows, and tests that exercise Cloudflare's SQLite-backed storage API.
|
|
15
|
+
*
|
|
16
|
+
* Durable Object SQLite storage is scoped to one object id, so each object
|
|
17
|
+
* instance has its own database and callers should pass the same `SqlStorage`
|
|
18
|
+
* handle that the object uses for normal reads and writes. This adapter
|
|
19
|
+
* serializes Effect SQL access through one connection; a transaction holds that
|
|
20
|
+
* permit for the lifetime of its scope, so keep transactions short, avoid
|
|
21
|
+
* suspending them across unrelated work, and use them when multi-statement
|
|
22
|
+
* writes must commit atomically. `SqlStorage.exec` returns `ArrayBuffer` values
|
|
23
|
+
* for SQLite blobs, which this client normalizes to `Uint8Array`, and SQLite
|
|
24
|
+
* does not support `updateValues`.
|
|
25
|
+
*
|
|
26
|
+
* @since 4.0.0
|
|
9
27
|
*/
|
|
10
28
|
export * as SqliteClient from "./SqliteClient.ts"
|
|
11
29
|
|
|
12
30
|
/**
|
|
13
|
-
*
|
|
31
|
+
* Utilities for applying Effect SQL migrations to Cloudflare Durable Object SQLite storage.
|
|
32
|
+
*
|
|
33
|
+
* This module re-exports the shared `Migrator` loaders and error types, then
|
|
34
|
+
* provides `run` and `layer` helpers that execute ordered migrations through the
|
|
35
|
+
* current Durable Object `SqlStorage`-backed `SqlClient`. Use it when a Durable
|
|
36
|
+
* Object needs to create or upgrade its local schema during construction, before
|
|
37
|
+
* repositories or request handlers use the object storage, or in tests that
|
|
38
|
+
* exercise Durable Object persistence.
|
|
39
|
+
*
|
|
40
|
+
* Migrations are recorded in `effect_sql_migrations` by default and are loaded
|
|
41
|
+
* using the shared `<id>_<name>` file or record-key convention. The underlying
|
|
42
|
+
* storage is scoped to a Durable Object id, so running migrations for one object
|
|
43
|
+
* does not update any other object instance; run the migrator against the same
|
|
44
|
+
* `SqlStorage` handle that the object uses for normal queries. These SQL
|
|
45
|
+
* migrations are separate from Cloudflare's Durable Object class migrations, and
|
|
46
|
+
* the Durable Object must already be configured with SQLite storage before this
|
|
47
|
+
* module can apply schema changes. Repeated startup runs are expected and are
|
|
48
|
+
* guarded by the migrations table, but request handling should wait until the
|
|
49
|
+
* migration layer has finished. This adapter does not currently write SQLite
|
|
50
|
+
* schema dumps for `schemaDirectory`.
|
|
51
|
+
*
|
|
52
|
+
* @since 4.0.0
|
|
14
53
|
*/
|
|
15
54
|
export * as SqliteMigrator from "./SqliteMigrator.ts"
|