@effect/sql-sqlite-node 4.0.0-beta.98 → 4.0.0-rc.108

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.
Files changed (87) hide show
  1. package/AGENTS.md +381 -0
  2. package/CLAUDE.md +381 -0
  3. package/README.md +10 -3
  4. package/ai-docs/README.md +44 -0
  5. package/ai-docs/package.json +36 -0
  6. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  7. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
  8. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  9. package/ai-docs/src/01_effect/01_basics/index.md +5 -0
  10. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  11. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  12. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  13. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  14. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  15. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  16. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  17. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  18. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  19. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  20. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  21. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  22. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  23. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  24. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  25. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  26. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  27. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  28. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  29. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  30. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  31. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  32. package/ai-docs/src/03_stream/30_encoding.ts +165 -0
  33. package/ai-docs/src/03_stream/index.md +4 -0
  34. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  35. package/ai-docs/src/04_integration/index.md +5 -0
  36. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  37. package/ai-docs/src/05_batching/index.md +3 -0
  38. package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
  39. package/ai-docs/src/06_schedule/index.md +3 -0
  40. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  41. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  42. package/ai-docs/src/07_datetime/index.md +5 -0
  43. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  44. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  45. package/ai-docs/src/08_observability/index.md +7 -0
  46. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  47. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  48. package/ai-docs/src/09_testing/index.md +1 -0
  49. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  50. package/ai-docs/src/10_predicate/index.md +9 -0
  51. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  52. package/ai-docs/src/50_http-client/index.md +3 -0
  53. package/ai-docs/src/51_http-server/10_basics.ts +116 -0
  54. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  55. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  56. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  57. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
  58. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
  59. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  60. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
  61. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
  62. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
  63. package/ai-docs/src/51_http-server/index.md +3 -0
  64. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  65. package/ai-docs/src/60_child-process/index.md +3 -0
  66. package/ai-docs/src/70_cli/10_basics.ts +136 -0
  67. package/ai-docs/src/70_cli/index.md +5 -0
  68. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  69. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  70. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  71. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  72. package/ai-docs/src/71_ai/index.md +5 -0
  73. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  74. package/ai-docs/src/80_cluster/index.md +4 -0
  75. package/ai-docs/src/index.md +10 -0
  76. package/ai-docs/tsconfig.json +24 -0
  77. package/dist/SqliteClient.d.ts +9 -3
  78. package/dist/SqliteClient.d.ts.map +1 -1
  79. package/dist/SqliteClient.js +13 -4
  80. package/dist/SqliteClient.js.map +1 -1
  81. package/dist/SqliteMigrator.d.ts +2 -2
  82. package/dist/SqliteMigrator.js +2 -2
  83. package/dist/SqliteMigrator.js.map +1 -1
  84. package/dist/index.js.map +1 -1
  85. package/package.json +13 -11
  86. package/src/SqliteClient.ts +24 -6
  87. package/src/SqliteMigrator.ts +2 -2
@@ -3,9 +3,14 @@
3
3
  *
4
4
  * This module opens a SQLite database and exposes it as both `SqliteClient` and
5
5
  * the generic Effect SQL client. It serializes access through one connection,
6
- * caches prepared statements, enables WAL mode unless disabled, and supports
7
- * database backup, and extension loading. Streaming queries and
8
- * `updateValues` are not supported by this driver.
6
+ * caches prepared statements, enables WAL mode unless disabled, and waits up
7
+ * to five seconds for busy databases by default. Explicit transactions on
8
+ * writable connections use `BEGIN IMMEDIATE` to avoid read-to-write lock
9
+ * upgrades, which serializes them behind other writers even when they only
10
+ * read. Clients opened with `readonly: true` are unaffected. Busy waits block
11
+ * the Node.js event loop because `node:sqlite` is synchronous. Database backup
12
+ * and extension loading are supported; streaming queries and `updateValues`
13
+ * are not.
9
14
  *
10
15
  * @since 4.0.0
11
16
  */
@@ -29,6 +34,7 @@ import { backup as backupDatabase, DatabaseSync } from "node:sqlite"
29
34
  import type { StatementSync } from "node:sqlite"
30
35
 
31
36
  const ATTR_DB_SYSTEM_NAME = "db.system.name"
37
+ const MAX_BUSY_TIMEOUT = 2_147_483_647
32
38
 
33
39
  /**
34
40
  * Runtime type identifier used to mark Node `SqliteClient` values.
@@ -49,7 +55,7 @@ export type TypeId = "~@effect/sql-sqlite-node/SqliteClient"
49
55
  /**
50
56
  * Node SQLite client service, extending `SqlClient` with database export, backup, and extension loading helpers. `updateValues` is not supported.
51
57
  *
52
- * @category models
58
+ * @category services
53
59
  * @since 4.0.0
54
60
  */
55
61
  export interface SqliteClient extends Client.SqlClient {
@@ -82,7 +88,7 @@ export interface BackupMetadata {
82
88
  export const SqliteClient = Context.Service<SqliteClient>("@effect/sql-sqlite-node/SqliteClient")
83
89
 
84
90
  /**
85
- * Configuration for a node SQLite client backed by `node:sqlite`, including the database filename, read-only mode, statement cache settings, WAL behavior, span attributes, and query/result name transforms.
91
+ * Configuration for a node SQLite client backed by `node:sqlite`, including the database filename, read-only mode, statement cache settings, WAL and busy timeout behavior, span attributes, and query/result name transforms.
86
92
  *
87
93
  * @category models
88
94
  * @since 4.0.0
@@ -93,6 +99,12 @@ export interface SqliteClientConfig {
93
99
  readonly prepareCacheSize?: number | undefined
94
100
  readonly prepareCacheTTL?: Duration.Input | undefined
95
101
  readonly disableWAL?: boolean | undefined
102
+ /**
103
+ * How long SQLite waits when the database is busy. Defaults to 5 seconds.
104
+ * `Duration.infinity` is clamped to SQLite's maximum timeout.
105
+ * Waiting blocks the Node.js event loop because `node:sqlite` is synchronous.
106
+ */
107
+ readonly busyTimeout?: Duration.Input | undefined
96
108
  readonly spanAttributes?: Record<string, unknown> | undefined
97
109
 
98
110
  readonly transformResultNames?: ((str: string) => string) | undefined
@@ -105,7 +117,7 @@ interface SqliteConnection extends Connection {
105
117
  }
106
118
 
107
119
  /**
108
- * Creates a scoped node SQLite client from the supplied configuration, using a single serialized connection with WAL enabled by default and exposing SQLite-specific `export`, `backup`, and `loadExtension` operations.
120
+ * Creates a scoped node SQLite client from the supplied configuration, using a single serialized connection with WAL and a 5-second busy timeout enabled by default. Explicit transactions on writable connections take the write lock for their duration, even when they only read; clients opened with `readonly: true` are unaffected.
109
121
  *
110
122
  * @category constructors
111
123
  * @since 4.0.0
@@ -129,6 +141,11 @@ export const make = (
129
141
  })
130
142
  yield* Scope.addFinalizer(scope, Effect.sync(() => db.close()))
131
143
  db.enableLoadExtension(false)
144
+ const busyTimeout = Math.min(
145
+ MAX_BUSY_TIMEOUT,
146
+ Math.max(0, Math.round(Duration.toMillis(options.busyTimeout ?? Duration.seconds(5))))
147
+ )
148
+ db.exec(`PRAGMA busy_timeout = ${busyTimeout}`)
132
149
 
133
150
  if (options.disableWAL !== true) {
134
151
  db.exec("PRAGMA journal_mode = WAL")
@@ -303,6 +320,7 @@ export const make = (
303
320
  acquirer,
304
321
  compiler,
305
322
  transactionAcquirer,
323
+ beginTransaction: "BEGIN IMMEDIATE",
306
324
  spanAttributes: [
307
325
  ...(options.spanAttributes ? Object.entries(options.spanAttributes) : []),
308
326
  [ATTR_DB_SYSTEM_NAME, "sqlite"]
@@ -22,7 +22,7 @@ export * from "effect/unstable/sql/Migrator"
22
22
  /**
23
23
  * Runs SQL migrations for a SQLite database using the shared `Migrator` implementation and the current `SqlClient`.
24
24
  *
25
- * @category constructors
25
+ * @category running
26
26
  * @since 4.0.0
27
27
  */
28
28
  export const run: <R2 = never>(
@@ -78,7 +78,7 @@ export const run: <R2 = never>(
78
78
  /**
79
79
  * Creates a layer that runs the configured SQLite migrations during layer construction and provides no services.
80
80
  *
81
- * @category constructors
81
+ * @category layers
82
82
  * @since 4.0.0
83
83
  */
84
84
  export const layer = <R>(