@effect/sql-d1 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.
@@ -1,28 +1,55 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
3
+ *
4
+ * This module adapts a Cloudflare D1 database binding into both the
5
+ * D1-specific `D1Client` service and the generic Effect `SqlClient` service.
6
+ * Use it in Workers, Pages Functions, and tests that provide a D1 binding to
7
+ * run SQLite-compatible queries through Effect services and layers, including
8
+ * repositories, migrations, request handlers, and local development against
9
+ * Wrangler or Miniflare-backed D1 databases.
10
+ *
11
+ * The client prepares statements with D1, caches them by SQL string, and uses
12
+ * the SQLite statement compiler for query and result name transforms. D1
13
+ * commits individual statements automatically, and native `D1Database.batch`
14
+ * is the D1 API for sequential, transactional multi-statement work; this
15
+ * adapter does not expose Effect SQL transactions because it cannot map
16
+ * `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
17
+ * serverless SQLite storage with platform limits and single-database serialized
18
+ * execution, so keep queries small and indexed, batch large maintenance work
19
+ * at the D1 API level, and use D1 sessions outside this client when an
20
+ * application needs bookmark-based sequential consistency or read replicas.
21
+ * Streaming queries and `updateValues` are not supported.
22
+ *
23
+ * @since 4.0.0
3
24
  */
4
25
  import type { D1Database } from "@cloudflare/workers-types";
5
26
  import * as Config from "effect/Config";
27
+ import * as Context from "effect/Context";
6
28
  import * as Duration from "effect/Duration";
7
29
  import * as Effect from "effect/Effect";
8
30
  import * as Layer from "effect/Layer";
9
31
  import type * as Scope from "effect/Scope";
10
- import * as ServiceMap from "effect/ServiceMap";
11
32
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
12
33
  import * as Client from "effect/unstable/sql/SqlClient";
13
34
  /**
14
- * @category type ids
15
- * @since 1.0.0
35
+ * Unique runtime identifier used to tag `D1Client` values.
36
+ *
37
+ * @category type IDs
38
+ * @since 4.0.0
16
39
  */
17
40
  export declare const TypeId: TypeId;
18
41
  /**
19
- * @category type ids
20
- * @since 1.0.0
42
+ * Type-level literal for the `D1Client` runtime identifier.
43
+ *
44
+ * @category type IDs
45
+ * @since 4.0.0
21
46
  */
22
47
  export type TypeId = "~@effect/sql-d1/D1Client";
23
48
  /**
49
+ * Cloudflare D1 SQL client service, extending `SqlClient` with its D1 configuration and no `updateValues` support.
50
+ *
24
51
  * @category models
25
- * @since 1.0.0
52
+ * @since 4.0.0
26
53
  */
27
54
  export interface D1Client extends Client.SqlClient {
28
55
  readonly [TypeId]: TypeId;
@@ -31,13 +58,17 @@ export interface D1Client extends Client.SqlClient {
31
58
  readonly updateValues: never;
32
59
  }
33
60
  /**
61
+ * Context tag used to access the `D1Client` service.
62
+ *
34
63
  * @category tags
35
- * @since 1.0.0
64
+ * @since 4.0.0
36
65
  */
37
- export declare const D1Client: ServiceMap.Service<D1Client, D1Client>;
66
+ export declare const D1Client: Context.Service<D1Client, D1Client>;
38
67
  /**
68
+ * Configuration for a Cloudflare D1 client, including the `D1Database`, prepared statement cache settings, span attributes, and query/result name transforms.
69
+ *
39
70
  * @category models
40
- * @since 1.0.0
71
+ * @since 4.0.0
41
72
  */
42
73
  export interface D1ClientConfig {
43
74
  readonly db: D1Database;
@@ -48,18 +79,24 @@ export interface D1ClientConfig {
48
79
  readonly transformQueryNames?: ((str: string) => string) | undefined;
49
80
  }
50
81
  /**
51
- * @category constructor
52
- * @since 1.0.0
82
+ * Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.
83
+ *
84
+ * @category constructors
85
+ * @since 4.0.0
53
86
  */
54
87
  export declare const make: (options: D1ClientConfig) => Effect.Effect<D1Client, never, Scope.Scope | Reactivity.Reactivity>;
55
88
  /**
89
+ * Creates a layer from a `Config`-wrapped D1 client configuration, providing both `D1Client` and `SqlClient`.
90
+ *
56
91
  * @category layers
57
- * @since 1.0.0
92
+ * @since 4.0.0
58
93
  */
59
94
  export declare const layerConfig: (config: Config.Wrap<D1ClientConfig>) => Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError>;
60
95
  /**
96
+ * Creates a layer from a concrete D1 client configuration, providing both `D1Client` and `SqlClient`.
97
+ *
61
98
  * @category layers
62
- * @since 1.0.0
99
+ * @since 4.0.0
63
100
  */
64
101
  export declare const layer: (config: D1ClientConfig) => Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError>;
65
102
  //# sourceMappingURL=D1Client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"D1Client.d.ts","sourceRoot":"","sources":["../src/D1Client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,2BAA2B,CAAA;AAEhF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAOvD;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAAmC,CAAA;AAExD;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,0BAA0B,CAAA;AAE/C;;;GAGG;AACH,MAAM,WAAW,QAAS,SAAQ,MAAM,CAAC,SAAS;IAChD,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;IAE/B,0BAA0B;IAC1B,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAA;CAC7B;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,wCAA0D,CAAA;AAE/E;;;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K,MAAM,CAAC,GAAG,SAAS,CAAA;CACrE;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GACf,SAAS,cAAc,KACtB,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAgHjE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,KAClC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAUrB,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,QAAQ,cAAc,KACrB,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAMrB,CAAA"}
package/dist/D1Client.js CHANGED
@@ -1,29 +1,40 @@
1
1
  import * as Cache from "effect/Cache";
2
2
  import * as Config from "effect/Config";
3
+ import * as Context from "effect/Context";
3
4
  import * as Duration from "effect/Duration";
4
5
  import * as Effect from "effect/Effect";
5
6
  import { identity } from "effect/Function";
6
7
  import * as Layer from "effect/Layer";
7
- import * as ServiceMap from "effect/ServiceMap";
8
8
  import * as Stream from "effect/Stream";
9
9
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
10
10
  import * as Client from "effect/unstable/sql/SqlClient";
11
- import { SqlError } from "effect/unstable/sql/SqlError";
11
+ import { SqlError, UnknownError } from "effect/unstable/sql/SqlError";
12
12
  import * as Statement from "effect/unstable/sql/Statement";
13
13
  const ATTR_DB_SYSTEM_NAME = "db.system.name";
14
+ const classifyError = (cause, message, operation) => new UnknownError({
15
+ cause,
16
+ message,
17
+ operation
18
+ });
14
19
  /**
15
- * @category type ids
16
- * @since 1.0.0
20
+ * Unique runtime identifier used to tag `D1Client` values.
21
+ *
22
+ * @category type IDs
23
+ * @since 4.0.0
17
24
  */
18
25
  export const TypeId = "~@effect/sql-d1/D1Client";
19
26
  /**
27
+ * Context tag used to access the `D1Client` service.
28
+ *
20
29
  * @category tags
21
- * @since 1.0.0
30
+ * @since 4.0.0
22
31
  */
23
- export const D1Client = /*#__PURE__*/ServiceMap.Service("@effect/sql-d1/D1Client");
32
+ export const D1Client = /*#__PURE__*/Context.Service("@effect/sql-d1/D1Client");
24
33
  /**
25
- * @category constructor
26
- * @since 1.0.0
34
+ * Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.
35
+ *
36
+ * @category constructors
37
+ * @since 4.0.0
27
38
  */
28
39
  export const make = options => Effect.gen(function* () {
29
40
  const compiler = Statement.makeCompilerSqlite(options.transformQueryNames);
@@ -36,8 +47,7 @@ export const make = options => Effect.gen(function* () {
36
47
  lookup: sql => Effect.try({
37
48
  try: () => db.prepare(sql),
38
49
  catch: cause => new SqlError({
39
- cause,
40
- message: `Failed to prepare statement`
50
+ reason: classifyError(cause, "Failed to prepare statement", "prepare")
41
51
  })
42
52
  })
43
53
  });
@@ -50,8 +60,7 @@ export const make = options => Effect.gen(function* () {
50
60
  return response.results || [];
51
61
  },
52
62
  catch: cause => new SqlError({
53
- cause,
54
- message: `Failed to execute statement`
63
+ reason: classifyError(cause, "Failed to execute statement", "execute")
55
64
  })
56
65
  });
57
66
  const runRaw = (sql, params = []) => runStatement(db.prepare(sql), params);
@@ -62,8 +71,7 @@ export const make = options => Effect.gen(function* () {
62
71
  return statement.bind(...params).raw();
63
72
  },
64
73
  catch: cause => new SqlError({
65
- cause,
66
- message: `Failed to execute statement`
74
+ reason: classifyError(cause, "Failed to execute statement", "execute")
67
75
  })
68
76
  }));
69
77
  return identity({
@@ -99,13 +107,17 @@ export const make = options => Effect.gen(function* () {
99
107
  });
100
108
  });
101
109
  /**
110
+ * Creates a layer from a `Config`-wrapped D1 client configuration, providing both `D1Client` and `SqlClient`.
111
+ *
102
112
  * @category layers
103
- * @since 1.0.0
113
+ * @since 4.0.0
104
114
  */
105
- export const layerConfig = config => Layer.effectServices(Config.unwrap(config).asEffect().pipe(Effect.flatMap(make), Effect.map(client => ServiceMap.make(D1Client, client).pipe(ServiceMap.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
115
+ export const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(D1Client, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
106
116
  /**
117
+ * Creates a layer from a concrete D1 client configuration, providing both `D1Client` and `SqlClient`.
118
+ *
107
119
  * @category layers
108
- * @since 1.0.0
120
+ * @since 4.0.0
109
121
  */
110
- export const layer = config => Layer.effectServices(Effect.map(make(config), client => ServiceMap.make(D1Client, client).pipe(ServiceMap.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
122
+ export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(D1Client, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
111
123
  //# sourceMappingURL=D1Client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"D1Client.js","names":["Cache","Config","Duration","Effect","identity","Layer","ServiceMap","Stream","Reactivity","Client","SqlError","Statement","ATTR_DB_SYSTEM_NAME","TypeId","D1Client","Service","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","prepareCache","capacity","prepareCacheSize","timeToLive","prepareCacheTTL","minutes","lookup","sql","try","prepare","catch","cause","message","runStatement","statement","params","tryPromise","response","bind","all","error","results","runRaw","runCached","flatMap","get","s","runUncached","runValues","raw","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","_sql","_params","die","connection","acquirer","succeed","transactionAcquirer","Object","assign","spanAttributes","entries","config","layerConfig","effectServices","unwrap","asEffect","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/D1Client.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KA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IAC9B5E,UAAU,CAACU,IAAI,CAACF,QAAQ,EAAEoE,MAAM,CAAC,CAACD,IAAI,CACpC3E,UAAU,CAAC6E,GAAG,CAAC1E,MAAM,CAAC2E,SAAS,EAAEF,MAAM,CAAC,CACzC,CAAC,CACL,CAACD,IAAI,CAAC5E,KAAK,CAACgF,OAAO,CAAC7E,UAAU,CAAC8E,KAAK,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"D1Client.js","names":["Cache","Config","Context","Duration","Effect","identity","Layer","Stream","Reactivity","Client","SqlError","UnknownError","Statement","ATTR_DB_SYSTEM_NAME","classifyError","cause","message","operation","TypeId","D1Client","Service","make","options","gen","compiler","makeCompilerSqlite","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","makeConnection","db","prepareCache","capacity","prepareCacheSize","timeToLive","prepareCacheTTL","minutes","lookup","sql","try","prepare","catch","reason","runStatement","statement","params","tryPromise","response","bind","all","error","results","runRaw","runCached","flatMap","get","s","runUncached","runValues","raw","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","_sql","_params","die","connection","acquirer","succeed","transactionAcquirer","Object","assign","spanAttributes","entries","config","layerConfig","effectContext","unwrap","pipe","client","add","SqlClient","provide","layer"],"sources":["../src/D1Client.ts"],"sourcesContent":[null],"mappings":"AAyBA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,SAASC,QAAQ,QAAQ,iBAAiB;AAC1C,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SAASC,QAAQ,EAAEC,YAAY,QAAQ,8BAA8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I,CAAC9E,KAAK,CAACkF,OAAO,CAAChF,UAAU,CAACiF,KAAK,CAAC,CAAC","ignoreList":[]}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,29 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  /**
5
- * @since 1.0.0
5
+ * Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
6
+ *
7
+ * This module adapts a Cloudflare D1 database binding into both the
8
+ * D1-specific `D1Client` service and the generic Effect `SqlClient` service.
9
+ * Use it in Workers, Pages Functions, and tests that provide a D1 binding to
10
+ * run SQLite-compatible queries through Effect services and layers, including
11
+ * repositories, migrations, request handlers, and local development against
12
+ * Wrangler or Miniflare-backed D1 databases.
13
+ *
14
+ * The client prepares statements with D1, caches them by SQL string, and uses
15
+ * the SQLite statement compiler for query and result name transforms. D1
16
+ * commits individual statements automatically, and native `D1Database.batch`
17
+ * is the D1 API for sequential, transactional multi-statement work; this
18
+ * adapter does not expose Effect SQL transactions because it cannot map
19
+ * `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
20
+ * serverless SQLite storage with platform limits and single-database serialized
21
+ * execution, so keep queries small and indexed, batch large maintenance work
22
+ * at the D1 API level, and use D1 sessions outside this client when an
23
+ * application needs bookmark-based sequential consistency or read replicas.
24
+ * Streaming queries and `updateValues` are not supported.
25
+ *
26
+ * @since 4.0.0
6
27
  */
7
28
  export * as D1Client from "./D1Client.ts";
8
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA"}
package/dist/index.js CHANGED
@@ -1,9 +1,30 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  // @barrel: Auto-generated exports. Do not edit manually.
5
5
  /**
6
- * @since 1.0.0
6
+ * Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
7
+ *
8
+ * This module adapts a Cloudflare D1 database binding into both the
9
+ * D1-specific `D1Client` service and the generic Effect `SqlClient` service.
10
+ * Use it in Workers, Pages Functions, and tests that provide a D1 binding to
11
+ * run SQLite-compatible queries through Effect services and layers, including
12
+ * repositories, migrations, request handlers, and local development against
13
+ * Wrangler or Miniflare-backed D1 databases.
14
+ *
15
+ * The client prepares statements with D1, caches them by SQL string, and uses
16
+ * the SQLite statement compiler for query and result name transforms. D1
17
+ * commits individual statements automatically, and native `D1Database.batch`
18
+ * is the D1 API for sequential, transactional multi-statement work; this
19
+ * adapter does not expose Effect SQL transactions because it cannot map
20
+ * `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
21
+ * serverless SQLite storage with platform limits and single-database serialized
22
+ * execution, so keep queries small and indexed, batch large maintenance work
23
+ * at the D1 API level, and use D1 sessions outside this client when an
24
+ * application needs bookmark-based sequential consistency or read replicas.
25
+ * Streaming queries and `updateValues` are not supported.
26
+ *
27
+ * @since 4.0.0
7
28
  */
8
29
  export * as D1Client from "./D1Client.js";
9
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["D1Client"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;AAGA,OAAO,KAAKA,QAAQ,MAAM,eAAe","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["D1Client"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,KAAKA,QAAQ,MAAM,eAAe","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/sql-d1",
3
- "version": "4.0.0-beta.7",
3
+ "version": "4.0.0-beta.70",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A Cloudflare D1 integration for Effect",
@@ -47,14 +47,14 @@
47
47
  "provenance": true
48
48
  },
49
49
  "devDependencies": {
50
- "miniflare": "^4.20260128.0",
51
- "effect": "^4.0.0-beta.7"
50
+ "miniflare": "^4.20260507.1",
51
+ "effect": "^4.0.0-beta.70"
52
52
  },
53
53
  "peerDependencies": {
54
- "effect": "^4.0.0-beta.7"
54
+ "effect": "^4.0.0-beta.70"
55
55
  },
56
56
  "dependencies": {
57
- "@cloudflare/workers-types": "^4.20260131.0"
57
+ "@cloudflare/workers-types": "^4.20260511.1"
58
58
  },
59
59
  "scripts": {
60
60
  "codegen": "effect-utils codegen",
package/src/D1Client.ts CHANGED
@@ -1,39 +1,69 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
3
+ *
4
+ * This module adapts a Cloudflare D1 database binding into both the
5
+ * D1-specific `D1Client` service and the generic Effect `SqlClient` service.
6
+ * Use it in Workers, Pages Functions, and tests that provide a D1 binding to
7
+ * run SQLite-compatible queries through Effect services and layers, including
8
+ * repositories, migrations, request handlers, and local development against
9
+ * Wrangler or Miniflare-backed D1 databases.
10
+ *
11
+ * The client prepares statements with D1, caches them by SQL string, and uses
12
+ * the SQLite statement compiler for query and result name transforms. D1
13
+ * commits individual statements automatically, and native `D1Database.batch`
14
+ * is the D1 API for sequential, transactional multi-statement work; this
15
+ * adapter does not expose Effect SQL transactions because it cannot map
16
+ * `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
17
+ * serverless SQLite storage with platform limits and single-database serialized
18
+ * execution, so keep queries small and indexed, batch large maintenance work
19
+ * at the D1 API level, and use D1 sessions outside this client when an
20
+ * application needs bookmark-based sequential consistency or read replicas.
21
+ * Streaming queries and `updateValues` are not supported.
22
+ *
23
+ * @since 4.0.0
3
24
  */
4
25
  import type { D1Database, D1PreparedStatement } from "@cloudflare/workers-types"
5
26
  import * as Cache from "effect/Cache"
6
27
  import * as Config from "effect/Config"
28
+ import * as Context from "effect/Context"
7
29
  import * as Duration from "effect/Duration"
8
30
  import * as Effect from "effect/Effect"
9
31
  import { identity } from "effect/Function"
10
32
  import * as Layer from "effect/Layer"
11
33
  import type * as Scope from "effect/Scope"
12
- import * as ServiceMap from "effect/ServiceMap"
13
34
  import * as Stream from "effect/Stream"
14
35
  import * as Reactivity from "effect/unstable/reactivity/Reactivity"
15
36
  import * as Client from "effect/unstable/sql/SqlClient"
16
37
  import type { Connection } from "effect/unstable/sql/SqlConnection"
17
- import { SqlError } from "effect/unstable/sql/SqlError"
38
+ import { SqlError, UnknownError } from "effect/unstable/sql/SqlError"
18
39
  import * as Statement from "effect/unstable/sql/Statement"
19
40
 
20
41
  const ATTR_DB_SYSTEM_NAME = "db.system.name"
21
42
 
43
+ const classifyError = (cause: unknown, message: string, operation: string) =>
44
+ new UnknownError({ cause, message, operation })
45
+
22
46
  /**
23
- * @category type ids
24
- * @since 1.0.0
47
+ * Unique runtime identifier used to tag `D1Client` values.
48
+ *
49
+ * @category type IDs
50
+ * @since 4.0.0
25
51
  */
26
52
  export const TypeId: TypeId = "~@effect/sql-d1/D1Client"
27
53
 
28
54
  /**
29
- * @category type ids
30
- * @since 1.0.0
55
+ * Type-level literal for the `D1Client` runtime identifier.
56
+ *
57
+ * @category type IDs
58
+ * @since 4.0.0
31
59
  */
32
60
  export type TypeId = "~@effect/sql-d1/D1Client"
33
61
 
34
62
  /**
63
+ * Cloudflare D1 SQL client service, extending `SqlClient` with its D1 configuration and no `updateValues` support.
64
+ *
35
65
  * @category models
36
- * @since 1.0.0
66
+ * @since 4.0.0
37
67
  */
38
68
  export interface D1Client extends Client.SqlClient {
39
69
  readonly [TypeId]: TypeId
@@ -44,14 +74,18 @@ export interface D1Client extends Client.SqlClient {
44
74
  }
45
75
 
46
76
  /**
77
+ * Context tag used to access the `D1Client` service.
78
+ *
47
79
  * @category tags
48
- * @since 1.0.0
80
+ * @since 4.0.0
49
81
  */
50
- export const D1Client = ServiceMap.Service<D1Client>("@effect/sql-d1/D1Client")
82
+ export const D1Client = Context.Service<D1Client>("@effect/sql-d1/D1Client")
51
83
 
52
84
  /**
85
+ * Configuration for a Cloudflare D1 client, including the `D1Database`, prepared statement cache settings, span attributes, and query/result name transforms.
86
+ *
53
87
  * @category models
54
- * @since 1.0.0
88
+ * @since 4.0.0
55
89
  */
56
90
  export interface D1ClientConfig {
57
91
  readonly db: D1Database
@@ -64,8 +98,10 @@ export interface D1ClientConfig {
64
98
  }
65
99
 
66
100
  /**
67
- * @category constructor
68
- * @since 1.0.0
101
+ * Creates a scoped Cloudflare D1 SQL client. Prepared statements are cached, while transactions and streaming queries are not supported by this driver.
102
+ *
103
+ * @category constructors
104
+ * @since 4.0.0
69
105
  */
70
106
  export const make = (
71
107
  options: D1ClientConfig
@@ -85,7 +121,7 @@ export const make = (
85
121
  lookup: (sql: string) =>
86
122
  Effect.try({
87
123
  try: () => db.prepare(sql),
88
- catch: (cause) => new SqlError({ cause, message: `Failed to prepare statement` })
124
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to prepare statement", "prepare") })
89
125
  })
90
126
  })
91
127
 
@@ -101,7 +137,7 @@ export const make = (
101
137
  }
102
138
  return response.results || []
103
139
  },
104
- catch: (cause) => new SqlError({ cause, message: `Failed to execute statement` })
140
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
105
141
  })
106
142
 
107
143
  const runRaw = (
@@ -134,7 +170,7 @@ export const make = (
134
170
  >
135
171
  >
136
172
  },
137
- catch: (cause) => new SqlError({ cause, message: `Failed to execute statement` })
173
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
138
174
  })
139
175
  )
140
176
 
@@ -184,33 +220,37 @@ export const make = (
184
220
  })
185
221
 
186
222
  /**
223
+ * Creates a layer from a `Config`-wrapped D1 client configuration, providing both `D1Client` and `SqlClient`.
224
+ *
187
225
  * @category layers
188
- * @since 1.0.0
226
+ * @since 4.0.0
189
227
  */
190
228
  export const layerConfig = (
191
229
  config: Config.Wrap<D1ClientConfig>
192
230
  ): Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError> =>
193
- Layer.effectServices(
194
- Config.unwrap(config).asEffect().pipe(
231
+ Layer.effectContext(
232
+ Config.unwrap(config).pipe(
195
233
  Effect.flatMap(make),
196
234
  Effect.map((client) =>
197
- ServiceMap.make(D1Client, client).pipe(
198
- ServiceMap.add(Client.SqlClient, client)
235
+ Context.make(D1Client, client).pipe(
236
+ Context.add(Client.SqlClient, client)
199
237
  )
200
238
  )
201
239
  )
202
240
  ).pipe(Layer.provide(Reactivity.layer))
203
241
 
204
242
  /**
243
+ * Creates a layer from a concrete D1 client configuration, providing both `D1Client` and `SqlClient`.
244
+ *
205
245
  * @category layers
206
- * @since 1.0.0
246
+ * @since 4.0.0
207
247
  */
208
248
  export const layer = (
209
249
  config: D1ClientConfig
210
250
  ): Layer.Layer<D1Client | Client.SqlClient, Config.ConfigError> =>
211
- Layer.effectServices(
251
+ Layer.effectContext(
212
252
  Effect.map(make(config), (client) =>
213
- ServiceMap.make(D1Client, client).pipe(
214
- ServiceMap.add(Client.SqlClient, client)
253
+ Context.make(D1Client, client).pipe(
254
+ Context.add(Client.SqlClient, client)
215
255
  ))
216
256
  ).pipe(Layer.provide(Reactivity.layer))
package/src/index.ts CHANGED
@@ -1,10 +1,31 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * Cloudflare D1 client implementation for Effect SQL, backed by a Workers `D1Database` binding.
9
+ *
10
+ * This module adapts a Cloudflare D1 database binding into both the
11
+ * D1-specific `D1Client` service and the generic Effect `SqlClient` service.
12
+ * Use it in Workers, Pages Functions, and tests that provide a D1 binding to
13
+ * run SQLite-compatible queries through Effect services and layers, including
14
+ * repositories, migrations, request handlers, and local development against
15
+ * Wrangler or Miniflare-backed D1 databases.
16
+ *
17
+ * The client prepares statements with D1, caches them by SQL string, and uses
18
+ * the SQLite statement compiler for query and result name transforms. D1
19
+ * commits individual statements automatically, and native `D1Database.batch`
20
+ * is the D1 API for sequential, transactional multi-statement work; this
21
+ * adapter does not expose Effect SQL transactions because it cannot map
22
+ * `withTransaction` onto a connection-scoped D1 transaction. D1 databases are
23
+ * serverless SQLite storage with platform limits and single-database serialized
24
+ * execution, so keep queries small and indexed, batch large maintenance work
25
+ * at the D1 API level, and use D1 sessions outside this client when an
26
+ * application needs bookmark-based sequential consistency or read replicas.
27
+ * Streaming queries and `updateValues` are not supported.
28
+ *
29
+ * @since 4.0.0
9
30
  */
10
31
  export * as D1Client from "./D1Client.ts"