@effect/sql-sqlite-wasm 4.0.0-beta.10 → 4.0.0-beta.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Utilities for applying Effect SQL migrations to SQLite WASM databases.
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 SQLite WASM `SqlClient`. Use it when a browser, worker, or test
7
+ * runtime needs to create or upgrade a local SQLite schema before repositories,
8
+ * caches, sync services, or other database-backed services start.
9
+ *
10
+ * The migrator operates on whichever WASM client is in the environment. With
11
+ * `SqliteClient.makeMemory`, migrations update an in-memory database, so the
12
+ * resulting schema is transient unless you persist it with the client's
13
+ * `export` and `import` operations. With worker-backed OPFS databases, run the
14
+ * migrator against the same worker configuration and OPFS database name used by
15
+ * the rest of the application, and coordinate startup across tabs or workers so
16
+ * only one migrator upgrades a given database at a time. OPFS availability is
17
+ * browser- and origin-dependent, and this adapter does not currently write
18
+ * SQLite schema dumps for `schemaDirectory`.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import type * as Effect from "effect/Effect";
5
23
  import * as Layer from "effect/Layer";
@@ -7,17 +25,21 @@ import * as Migrator from "effect/unstable/sql/Migrator";
7
25
  import type * as Client from "effect/unstable/sql/SqlClient";
8
26
  import type { SqlError } from "effect/unstable/sql/SqlError";
9
27
  /**
10
- * @since 1.0.0
28
+ * @since 4.0.0
11
29
  */
12
30
  export * from "effect/unstable/sql/Migrator";
13
31
  /**
14
- * @category constructor
15
- * @since 1.0.0
32
+ * Runs SQL migrations for a SQLite WASM database using the shared `Migrator` implementation and the current `SqlClient`.
33
+ *
34
+ * @category constructors
35
+ * @since 4.0.0
16
36
  */
17
37
  export declare const run: <R>(options: Migrator.MigratorOptions<R>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, SqlError | Migrator.MigrationError, Client.SqlClient | R>;
18
38
  /**
19
- * @category constructor
20
- * @since 1.0.0
39
+ * Creates a layer that runs the configured SQLite WASM migrations during layer construction and provides no services.
40
+ *
41
+ * @category constructors
42
+ * @since 4.0.0
21
43
  */
22
44
  export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, SqlError | Migrator.MigrationError, R | Client.SqlClient>;
23
45
  //# sourceMappingURL=SqliteMigrator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SqliteMigrator.d.ts","sourceRoot":"","sources":["../src/SqliteMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,CAAC,EAClB,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACjC,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACD,CAAA;AAErB;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAsC,CAAA"}
1
+ {"version":3,"file":"SqliteMigrator.d.ts","sourceRoot":"","sources":["../src/SqliteMigrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;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,CAAC,EAClB,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACjC,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACD,CAAA;AAErB;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,WACZ,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAsC,CAAA"}
@@ -1,17 +1,21 @@
1
1
  import * as Layer from "effect/Layer";
2
2
  import * as Migrator from "effect/unstable/sql/Migrator";
3
3
  /**
4
- * @since 1.0.0
4
+ * @since 4.0.0
5
5
  */
6
6
  export * from "effect/unstable/sql/Migrator";
7
7
  /**
8
- * @category constructor
9
- * @since 1.0.0
8
+ * Runs SQL migrations for a SQLite WASM database using the shared `Migrator` implementation and the current `SqlClient`.
9
+ *
10
+ * @category constructors
11
+ * @since 4.0.0
10
12
  */
11
13
  export const run = /*#__PURE__*/Migrator.make({});
12
14
  /**
13
- * @category constructor
14
- * @since 1.0.0
15
+ * Creates a layer that runs the configured SQLite WASM migrations during layer construction and provides no services.
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":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;AAIA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC,EAAE,CAAC;AAErB;;;;AAIA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAC6CL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"SqliteMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/SqliteMigrator.ts"],"sourcesContent":[null],"mappings":"AAsBA,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,13 +1,13 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  export * as OpfsWorker from "./OpfsWorker.ts";
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * as SqliteClient from "./SqliteClient.ts";
9
9
  /**
10
- * @since 1.0.0
10
+ * @since 4.0.0
11
11
  */
12
12
  export * as SqliteMigrator from "./SqliteMigrator.ts";
13
13
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  export * as OpfsWorker from "./OpfsWorker.js";
5
5
  /**
6
- * @since 1.0.0
6
+ * @since 4.0.0
7
7
  */
8
8
  export * as SqliteClient from "./SqliteClient.js";
9
9
  /**
10
- * @since 1.0.0
10
+ * @since 4.0.0
11
11
  */
12
12
  export * as SqliteMigrator from "./SqliteMigrator.js";
13
13
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@effect/sql-sqlite-wasm",
3
- "version": "4.0.0-beta.10",
3
+ "version": "4.0.0-beta.100",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A SQLite toolkit for Effect",
7
7
  "homepage": "https://effect.website",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/Effect-TS/effect-smol.git",
10
+ "url": "https://github.com/Effect-TS/effect.git",
11
11
  "directory": "packages/sql/sqlite-wasm"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/Effect-TS/effect-smol/issues"
14
+ "url": "https://github.com/Effect-TS/effect/issues"
15
15
  },
16
16
  "tags": [
17
17
  "typescript",
@@ -44,16 +44,15 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@effect/wa-sqlite": "^0.2.1",
47
- "effect": "^4.0.0-beta.10"
47
+ "effect": "^4.0.0-beta.100"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@effect/wa-sqlite": "^0.1.2",
51
- "effect": "^4.0.0-beta.10"
51
+ "effect": "^4.0.0-beta.100"
52
52
  },
53
53
  "scripts": {
54
54
  "codegen": "effect-utils codegen",
55
55
  "build": "tsc -b tsconfig.json && pnpm babel",
56
- "build:tsgo": "tsgo -b tsconfig.json && pnpm babel",
57
56
  "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
58
57
  "check": "tsc -b tsconfig.json",
59
58
  "test": "vitest",
package/src/OpfsWorker.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Runs the worker side of the browser SQLite WASM client that stores data in
3
+ * OPFS.
4
+ *
5
+ * This module opens `@effect/wa-sqlite` with the OPFS access-handle VFS, then
6
+ * listens on a `MessagePort`-compatible port for the protocol used by
7
+ * `SqliteClient`. It sends a ready message, executes SQL messages, imports and
8
+ * exports database bytes, forwards update-hook notifications, and closes when
9
+ * requested. It is meant to run in a dedicated worker or a `SharedWorker`.
10
+ *
11
+ * @since 4.0.0
3
12
  */
4
13
  /// <reference lib="webworker" />
5
14
  // oxlint-disable-next-line effect/no-import-from-barrel-package
@@ -7,12 +16,17 @@ import * as WaSqlite from "@effect/wa-sqlite"
7
16
  import SQLiteESMFactory from "@effect/wa-sqlite/dist/wa-sqlite.mjs"
8
17
  import { AccessHandlePoolVFS } from "@effect/wa-sqlite/src/examples/AccessHandlePoolVFS.js"
9
18
  import * as Effect from "effect/Effect"
10
- import { SqlError } from "effect/unstable/sql/SqlError"
19
+ import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
11
20
  import type { OpfsWorkerMessage } from "./internal/opfsWorker.ts"
12
21
 
22
+ const classifyError = (cause: unknown, message: string, operation: string) =>
23
+ classifySqliteError(cause, { message, operation })
24
+
13
25
  /**
26
+ * Configuration for the SQLite OPFS worker, including the message port used for the client protocol and the OPFS database name to open.
27
+ *
14
28
  * @category models
15
- * @since 1.0.0
29
+ * @since 4.0.0
16
30
  */
17
31
  export interface OpfsWorkerConfig {
18
32
  readonly port: EventTarget & Pick<MessagePort, "postMessage" | "close">
@@ -20,8 +34,10 @@ export interface OpfsWorkerConfig {
20
34
  }
21
35
 
22
36
  /**
23
- * @category constructor
24
- * @since 1.0.0
37
+ * Runs the SQLite OPFS worker loop, opening the configured database, posting a ready message, handling query/import/export/update-hook messages, and closing when a close message is received.
38
+ *
39
+ * @category constructors
40
+ * @since 4.0.0
25
41
  */
26
42
  export const run = (
27
43
  options: OpfsWorkerConfig
@@ -34,7 +50,7 @@ export const run = (
34
50
  const db = yield* Effect.acquireRelease(
35
51
  Effect.try({
36
52
  try: () => sqlite3.open_v2(options.dbName, undefined, "opfs"),
37
- catch: (cause) => new SqlError({ cause, message: "Failed to open database" })
53
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to open database", "openDatabase") })
38
54
  }),
39
55
  (db) => Effect.sync(() => sqlite3.close(db))
40
56
  )
@@ -1,11 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Connects Effect SQL to SQLite compiled to WebAssembly with
3
+ * `@effect/wa-sqlite`.
4
+ *
5
+ * This module can create an in-memory SQLite database in the current runtime or
6
+ * connect to a worker-backed database, such as the OPFS worker from
7
+ * `OpfsWorker`. Both clients are exposed as `SqliteClient` and the generic
8
+ * Effect SQL client, serialize access, support database import and export, and
9
+ * can install reactivity hooks from SQLite update notifications. In-memory
10
+ * clients can stream query rows; worker-backed clients cannot. `updateValues`
11
+ * is not supported by this driver.
12
+ *
13
+ * @since 4.0.0
3
14
  */
4
15
  // oxlint-disable-next-line effect/no-import-from-barrel-package
5
16
  import * as WaSqlite from "@effect/wa-sqlite"
6
17
  import SQLiteESMFactory from "@effect/wa-sqlite/dist/wa-sqlite.mjs"
7
18
  import { MemoryVFS } from "@effect/wa-sqlite/src/examples/MemoryVFS.js"
8
19
  import * as Config from "effect/Config"
20
+ import * as Context from "effect/Context"
9
21
  import * as Deferred from "effect/Deferred"
10
22
  import * as Effect from "effect/Effect"
11
23
  import * as Exit from "effect/Exit"
@@ -15,32 +27,40 @@ import * as Layer from "effect/Layer"
15
27
  import * as Scope from "effect/Scope"
16
28
  import * as ScopedRef from "effect/ScopedRef"
17
29
  import * as Semaphore from "effect/Semaphore"
18
- import * as ServiceMap from "effect/ServiceMap"
19
30
  import * as Stream from "effect/Stream"
20
31
  import * as Reactivity from "effect/unstable/reactivity/Reactivity"
21
32
  import * as Client from "effect/unstable/sql/SqlClient"
22
33
  import type { Connection } from "effect/unstable/sql/SqlConnection"
23
- import { SqlError } from "effect/unstable/sql/SqlError"
34
+ import { classifySqliteError, SqlError } from "effect/unstable/sql/SqlError"
24
35
  import * as Statement from "effect/unstable/sql/Statement"
25
36
  import type { OpfsWorkerMessage } from "./internal/opfsWorker.ts"
26
37
 
27
38
  const ATTR_DB_SYSTEM_NAME = "db.system.name"
28
39
 
40
+ const classifyError = (cause: unknown, message: string, operation: string) =>
41
+ classifySqliteError(cause, { message, operation })
42
+
29
43
  /**
30
- * @category type ids
31
- * @since 1.0.0
44
+ * Runtime identifier attached to SQLite WASM client values.
45
+ *
46
+ * @category type IDs
47
+ * @since 4.0.0
32
48
  */
33
49
  export const TypeId: TypeId = "~@effect/sql-sqlite-wasm/SqliteClient"
34
50
 
35
51
  /**
36
- * @category type ids
37
- * @since 1.0.0
52
+ * Type-level identifier for SQLite WASM client values.
53
+ *
54
+ * @category type IDs
55
+ * @since 4.0.0
38
56
  */
39
57
  export type TypeId = "~@effect/sql-sqlite-wasm/SqliteClient"
40
58
 
41
59
  /**
60
+ * SQLite WASM client service interface, extending `SqlClient` with database `export` and `import` operations and marking `updateValues` as unsupported for SQLite.
61
+ *
42
62
  * @category models
43
- * @since 1.0.0
63
+ * @since 4.0.0
44
64
  */
45
65
  export interface SqliteClient extends Client.SqlClient {
46
66
  readonly [TypeId]: TypeId
@@ -53,14 +73,18 @@ export interface SqliteClient extends Client.SqlClient {
53
73
  }
54
74
 
55
75
  /**
56
- * @category tags
57
- * @since 1.0.0
76
+ * Service tag for the SQLite WASM client.
77
+ *
78
+ * @category services
79
+ * @since 4.0.0
58
80
  */
59
- export const SqliteClient = ServiceMap.Service<SqliteClient>("@effect/sql-sqlite-wasm/SqliteClient")
81
+ export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-wasm/SqliteClient")
60
82
 
61
83
  /**
84
+ * Configuration for an in-memory SQLite WASM client, including optional reactivity hooks, span attributes, and query/result name transforms.
85
+ *
62
86
  * @category models
63
- * @since 1.0.0
87
+ * @since 4.0.0
64
88
  */
65
89
  export interface SqliteClientMemoryConfig {
66
90
  readonly installReactivityHooks?: boolean
@@ -70,8 +94,10 @@ export interface SqliteClientMemoryConfig {
70
94
  }
71
95
 
72
96
  /**
97
+ * Configuration for a worker-backed SQLite WASM client, including the scoped worker or message port, optional reactivity hooks, span attributes, and query/result name transforms.
98
+ *
73
99
  * @category models
74
- * @since 1.0.0
100
+ * @since 4.0.0
75
101
  */
76
102
  export interface SqliteClientConfig {
77
103
  readonly worker: Effect.Effect<Worker | SharedWorker | MessagePort, never, Scope.Scope>
@@ -97,8 +123,10 @@ const initEffect = Effect.runSync(
97
123
  const registered = new Set<string>()
98
124
 
99
125
  /**
100
- * @category constructor
101
- * @since 1.0.0
126
+ * Creates a scoped in-memory SQLite WASM client using the memory VFS, serializing access through a semaphore and exposing database `export` and `import` operations.
127
+ *
128
+ * @category constructors
129
+ * @since 4.0.0
102
130
  */
103
131
  export const makeMemory = (
104
132
  options: SqliteClientMemoryConfig
@@ -125,7 +153,7 @@ export const makeMemory = (
125
153
  const db = yield* Effect.acquireRelease(
126
154
  Effect.try({
127
155
  try: () => sqlite3.open_v2(":memory:", undefined, "memory-vfs"),
128
- catch: (cause) => new SqlError({ cause, message: "Failed to open database" })
156
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to open database", "openDatabase") })
129
157
  }),
130
158
  (db) => Effect.sync(() => sqlite3.close(db))
131
159
  )
@@ -165,7 +193,7 @@ export const makeMemory = (
165
193
  }
166
194
  return results
167
195
  },
168
- catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" })
196
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
169
197
  })
170
198
 
171
199
  return identity<SqliteConnection>({
@@ -180,6 +208,9 @@ export const makeMemory = (
180
208
  executeValues(sql, params) {
181
209
  return run(sql, params, "array")
182
210
  },
211
+ executeValuesUnprepared(sql, params) {
212
+ return run(sql, params, "array")
213
+ },
183
214
  executeUnprepared(sql, params, transformRows) {
184
215
  return this.execute(sql, params, transformRows)
185
216
  },
@@ -203,17 +234,19 @@ export const makeMemory = (
203
234
  transformRows
204
235
  ? Stream.mapArray((chunk) => transformRows(chunk) as any)
205
236
  : identity,
206
- Stream.mapError((cause) => new SqlError({ cause, message: "Failed to execute statement" }))
237
+ Stream.mapError((cause) =>
238
+ new SqlError({ reason: classifyError(cause, "Failed to execute statement", "stream") })
239
+ )
207
240
  )
208
241
  },
209
242
  export: Effect.try({
210
243
  try: () => sqlite3.serialize(db, "main"),
211
- catch: (cause) => new SqlError({ cause, message: "Failed to export database" })
244
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to export database", "export") })
212
245
  }),
213
246
  import(data) {
214
247
  return Effect.try({
215
248
  try: () => sqlite3.deserialize(db, "main", data, data.length, data.length, 1 | 2),
216
- catch: (cause) => new SqlError({ cause, message: "Failed to import database" })
249
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to import database", "import") })
217
250
  })
218
251
  }
219
252
  })
@@ -225,7 +258,7 @@ export const makeMemory = (
225
258
  const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
226
259
  const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
227
260
  const fiber = Fiber.getCurrent()!
228
- const scope = ServiceMap.getUnsafe(fiber.services, Scope.Scope)
261
+ const scope = Context.getUnsafe(fiber.context, Scope.Scope)
229
262
  return Effect.as(
230
263
  Effect.tap(
231
264
  restore(semaphore.take(1)),
@@ -258,8 +291,10 @@ export const makeMemory = (
258
291
  })
259
292
 
260
293
  /**
261
- * @category constructor
262
- * @since 1.0.0
294
+ * Creates a scoped worker-backed SQLite WASM client, communicating with the configured worker or message port, restarting the scoped connection on worker errors, and exposing database `export` and `import` operations.
295
+ *
296
+ * @category constructors
297
+ * @since 4.0.0
263
298
  */
264
299
  export const make = (
265
300
  options: SqliteClientConfig
@@ -297,7 +332,11 @@ export const make = (
297
332
  if (!resume) return
298
333
  pending.delete(id)
299
334
  if (error) {
300
- resume(Exit.fail(new SqlError({ cause: error as string, message: "Failed to execute statement" })))
335
+ resume(
336
+ Exit.fail(
337
+ new SqlError({ reason: classifyError(error as string, "Failed to execute statement", "execute") })
338
+ )
339
+ )
301
340
  } else {
302
341
  resume(Exit.succeed(results))
303
342
  }
@@ -358,6 +397,9 @@ export const make = (
358
397
  executeValues(sql, params) {
359
398
  return run(sql, params, "array")
360
399
  },
400
+ executeValuesUnprepared(sql, params) {
401
+ return run(sql, params, "array")
402
+ },
361
403
  executeUnprepared(sql, params, transformRows) {
362
404
  return this.execute(sql, params, transformRows)
363
405
  },
@@ -383,7 +425,7 @@ export const make = (
383
425
  const acquirer = semaphore.withPermits(1)(ScopedRef.get(connectionRef))
384
426
  const transactionAcquirer = Effect.uninterruptibleMask(Effect.fnUntraced(function*(restore) {
385
427
  const fiber = Fiber.getCurrent()!
386
- const scope = ServiceMap.getUnsafe(fiber.services, Scope.Scope)
428
+ const scope = Context.getUnsafe(fiber.context, Scope.Scope)
387
429
  yield* restore(semaphore.take(1))
388
430
  yield* Scope.addFinalizer(scope, semaphore.release(1))
389
431
  return yield* ScopedRef.get(connectionRef)
@@ -422,81 +464,93 @@ const extractObject = (rows: [Array<string>, Array<any>]) => rows[1].map((row) =
422
464
  const extractRows = (rows: [Array<string>, Array<any>]) => rows[1]
423
465
 
424
466
  /**
425
- * @category tranferables
426
- * @since 1.0.0
467
+ * Fiber reference that stores transferables to include with worker-backed SQLite WASM query messages.
468
+ *
469
+ * @category transferables
470
+ * @since 4.0.0
427
471
  */
428
- export const Transferables = ServiceMap.Reference<ReadonlyArray<Transferable>>(
472
+ export const Transferables = Context.Reference<ReadonlyArray<Transferable>>(
429
473
  "@effect/sql-sqlite-wasm/currentTransferables",
430
474
  { defaultValue: () => [] }
431
475
  )
432
476
 
433
477
  /**
434
- * @category tranferables
435
- * @since 1.0.0
478
+ * Runs an effect with the supplied transferables attached to worker-backed SQLite WASM query messages.
479
+ *
480
+ * @category transferables
481
+ * @since 4.0.0
436
482
  */
437
483
  export const withTransferables =
438
484
  (transferables: ReadonlyArray<Transferable>) => <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
439
485
  Effect.provideService(effect, Transferables, transferables)
440
486
 
441
487
  /**
488
+ * Builds a layer from an Effect `Config` value, providing both the in-memory SQLite WASM `SqliteClient` service and the generic `SqlClient` service.
489
+ *
442
490
  * @category layers
443
- * @since 1.0.0
491
+ * @since 4.0.0
444
492
  */
445
493
  export const layerMemoryConfig = (
446
494
  config: Config.Wrap<SqliteClientMemoryConfig>
447
495
  ): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError | SqlError> =>
448
- Layer.effectServices(
449
- Config.unwrap(config).asEffect().pipe(
496
+ Layer.effectContext(
497
+ Config.unwrap(config).pipe(
450
498
  Effect.flatMap(makeMemory),
451
499
  Effect.map((client) =>
452
- ServiceMap.make(SqliteClient, client).pipe(
453
- ServiceMap.add(Client.SqlClient, client)
500
+ Context.make(SqliteClient, client).pipe(
501
+ Context.add(Client.SqlClient, client)
454
502
  )
455
503
  )
456
504
  )
457
505
  ).pipe(Layer.provide(Reactivity.layer))
458
506
 
459
507
  /**
508
+ * Builds a layer from an in-memory SQLite WASM client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
509
+ *
460
510
  * @category layers
461
- * @since 1.0.0
511
+ * @since 4.0.0
462
512
  */
463
513
  export const layerMemory = (
464
514
  config: SqliteClientMemoryConfig
465
515
  ): Layer.Layer<SqliteClient | Client.SqlClient, SqlError> =>
466
- Layer.effectServices(
516
+ Layer.effectContext(
467
517
  Effect.map(makeMemory(config), (client) =>
468
- ServiceMap.make(SqliteClient, client).pipe(
469
- ServiceMap.add(Client.SqlClient, client)
518
+ Context.make(SqliteClient, client).pipe(
519
+ Context.add(Client.SqlClient, client)
470
520
  ))
471
521
  ).pipe(Layer.provide(Reactivity.layer))
472
522
 
473
523
  /**
524
+ * Builds a layer from a worker-backed SQLite WASM client configuration, providing both `SqliteClient` and the generic `SqlClient` service.
525
+ *
474
526
  * @category layers
475
- * @since 1.0.0
527
+ * @since 4.0.0
476
528
  */
477
529
  export const layer = (
478
530
  config: SqliteClientConfig
479
531
  ): Layer.Layer<SqliteClient | Client.SqlClient, SqlError> =>
480
- Layer.effectServices(
532
+ Layer.effectContext(
481
533
  Effect.map(make(config), (client) =>
482
- ServiceMap.make(SqliteClient, client).pipe(
483
- ServiceMap.add(Client.SqlClient, client)
534
+ Context.make(SqliteClient, client).pipe(
535
+ Context.add(Client.SqlClient, client)
484
536
  ))
485
537
  ).pipe(Layer.provide(Reactivity.layer))
486
538
 
487
539
  /**
540
+ * Builds a layer from an Effect `Config` value, providing both the worker-backed SQLite WASM `SqliteClient` service and the generic `SqlClient` service.
541
+ *
488
542
  * @category layers
489
- * @since 1.0.0
543
+ * @since 4.0.0
490
544
  */
491
545
  export const layerConfig = (
492
546
  config: Config.Wrap<SqliteClientConfig>
493
547
  ): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError | SqlError> =>
494
- Layer.effectServices(
495
- Config.unwrap(config).asEffect().pipe(
548
+ Layer.effectContext(
549
+ Config.unwrap(config).pipe(
496
550
  Effect.flatMap(make),
497
551
  Effect.map((client) =>
498
- ServiceMap.make(SqliteClient, client).pipe(
499
- ServiceMap.add(Client.SqlClient, client)
552
+ Context.make(SqliteClient, client).pipe(
553
+ Context.add(Client.SqlClient, client)
500
554
  )
501
555
  )
502
556
  )
@@ -1,5 +1,23 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Utilities for applying Effect SQL migrations to SQLite WASM databases.
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 SQLite WASM `SqlClient`. Use it when a browser, worker, or test
7
+ * runtime needs to create or upgrade a local SQLite schema before repositories,
8
+ * caches, sync services, or other database-backed services start.
9
+ *
10
+ * The migrator operates on whichever WASM client is in the environment. With
11
+ * `SqliteClient.makeMemory`, migrations update an in-memory database, so the
12
+ * resulting schema is transient unless you persist it with the client's
13
+ * `export` and `import` operations. With worker-backed OPFS databases, run the
14
+ * migrator against the same worker configuration and OPFS database name used by
15
+ * the rest of the application, and coordinate startup across tabs or workers so
16
+ * only one migrator upgrades a given database at a time. OPFS availability is
17
+ * browser- and origin-dependent, and this adapter does not currently write
18
+ * SQLite schema dumps for `schemaDirectory`.
19
+ *
20
+ * @since 4.0.0
3
21
  */
4
22
  import type * as Effect from "effect/Effect"
5
23
  import * as Layer from "effect/Layer"
@@ -8,13 +26,15 @@ import type * as Client from "effect/unstable/sql/SqlClient"
8
26
  import type { SqlError } from "effect/unstable/sql/SqlError"
9
27
 
10
28
  /**
11
- * @since 1.0.0
29
+ * @since 4.0.0
12
30
  */
13
31
  export * from "effect/unstable/sql/Migrator"
14
32
 
15
33
  /**
16
- * @category constructor
17
- * @since 1.0.0
34
+ * Runs SQL migrations for a SQLite WASM database using the shared `Migrator` implementation and the current `SqlClient`.
35
+ *
36
+ * @category constructors
37
+ * @since 4.0.0
18
38
  */
19
39
  export const run: <R>(
20
40
  options: Migrator.MigratorOptions<R>
@@ -25,8 +45,10 @@ export const run: <R>(
25
45
  > = Migrator.make({})
26
46
 
27
47
  /**
28
- * @category constructor
29
- * @since 1.0.0
48
+ * Creates a layer that runs the configured SQLite WASM migrations during layer construction and provides no services.
49
+ *
50
+ * @category constructors
51
+ * @since 4.0.0
30
52
  */
31
53
  export const layer = <R>(
32
54
  options: Migrator.MigratorOptions<R>
package/src/index.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  export * as OpfsWorker from "./OpfsWorker.ts"
5
5
 
6
6
  /**
7
- * @since 1.0.0
7
+ * @since 4.0.0
8
8
  */
9
9
  export * as SqliteClient from "./SqliteClient.ts"
10
10
 
11
11
  /**
12
- * @since 1.0.0
12
+ * @since 4.0.0
13
13
  */
14
14
  export * as SqliteMigrator from "./SqliteMigrator.ts"