@effect/sql-pglite 4.0.0-rc.112 → 4.0.0-rc.114
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/AGENTS.md +24 -9
- package/CLAUDE.md +24 -9
- package/README.md +19 -0
- package/ai-docs/package.json +2 -2
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +18 -5
- package/ai-docs/src/01_effect/01_basics/index.md +5 -3
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +1 -1
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +2 -2
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +2 -2
- package/ai-docs/src/03_stream/30_encoding.ts +5 -7
- package/ai-docs/src/08_observability/10_logging.ts +1 -1
- package/ai-docs/src/70_cli/10_basics.ts +7 -7
- package/ai-docs/src/71_ai/10_language-model.ts +2 -2
- package/ai-docs/src/71_ai/20_tools.ts +1 -1
- package/ai-docs/src/71_ai/30_chat.ts +1 -1
- package/dist/PgliteClient.d.ts +11 -2
- package/dist/PgliteClient.d.ts.map +1 -1
- package/dist/PgliteClient.js +17 -11
- package/dist/PgliteClient.js.map +1 -1
- package/package.json +4 -4
- package/src/PgliteClient.ts +32 -20
package/AGENTS.md
CHANGED
|
@@ -11,9 +11,11 @@ purposes. In practice, you would not include these comments in your code.
|
|
|
11
11
|
|
|
12
12
|
## Writing `Effect` code
|
|
13
13
|
|
|
14
|
-
Prefer
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Prefer `Effect.gen` for inline Effect code. For reusable functions, prefer
|
|
15
|
+
`Effect.fn("name")` when tracing is useful and `Effect.fnUntraced` when it is not,
|
|
16
|
+
particularly in library implementations and hot paths. Avoid functions that only
|
|
17
|
+
wrap and return `Effect.gen`. Attach additional behaviour with combinators; this
|
|
18
|
+
style is more readable and easier to maintain than using combinators alone.
|
|
17
19
|
|
|
18
20
|
### Using Effect.gen
|
|
19
21
|
|
|
@@ -46,13 +48,16 @@ export class FileProcessingError extends Schema.TaggedError<FileProcessingError>
|
|
|
46
48
|
}) {}
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
### Using Effect.fn
|
|
51
|
+
### Using Effect.fn and Effect.fnUntraced
|
|
50
52
|
|
|
51
|
-
When writing functions that return an Effect, use `Effect.fn`
|
|
52
|
-
generator syntax.
|
|
53
|
+
When writing reusable functions that return an Effect, use `Effect.fn` or
|
|
54
|
+
`Effect.fnUntraced` to use the generator syntax.
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
Use `Effect.fn("name")` when the function should create a tracing span. Prefer
|
|
57
|
+
`Effect.fnUntraced` when tracing is not needed, particularly for library
|
|
58
|
+
implementations and hot paths.
|
|
59
|
+
|
|
60
|
+
**Avoid creating functions that only wrap and return an `Effect.gen`**.
|
|
56
61
|
|
|
57
62
|
```ts
|
|
58
63
|
import { Effect, Schema } from "effect"
|
|
@@ -80,6 +85,16 @@ export const effectFunction = Effect.fn("effectFunction")(
|
|
|
80
85
|
})
|
|
81
86
|
)
|
|
82
87
|
|
|
88
|
+
// Effect.fnUntraced avoids tracing and stack-frame capture while still reusing
|
|
89
|
+
// the generator body. This is preferred for library functions that do not
|
|
90
|
+
// represent a useful tracing boundary.
|
|
91
|
+
export const validateBatchSize = Effect.fnUntraced(function*(size: number): Effect.fn.Return<number, SomeError> {
|
|
92
|
+
if (!Number.isInteger(size) || size <= 0) {
|
|
93
|
+
return yield* new SomeError({ message: "Batch size must be a positive integer" })
|
|
94
|
+
}
|
|
95
|
+
return size
|
|
96
|
+
})
|
|
97
|
+
|
|
83
98
|
// Use Schema.TaggedError to define a custom error
|
|
84
99
|
export class SomeError extends Schema.TaggedError<SomeError>()("SomeError", {
|
|
85
100
|
message: Schema.String
|
|
@@ -247,7 +262,7 @@ They let you model finite or infinite data sources.
|
|
|
247
262
|
- `NodeStream.fromReadable` for Node.js readable streams
|
|
248
263
|
- **[Consuming and transforming streams](./ai-docs/src/03_stream/20_consuming-streams.ts)**: How to transform and consume streams using operators like `map`, `flatMap`, `filter`, `mapEffect`, and various `run*` methods.
|
|
249
264
|
- **[Decoding and encoding streams](./ai-docs/src/03_stream/30_encoding.ts)**:
|
|
250
|
-
Use `Stream.pipeThroughChannel` with the `Ndjson`
|
|
265
|
+
Use `Stream.pipeThroughChannel` with the `Ndjson` and `SchemaBinary` modules to
|
|
251
266
|
decode and encode streams of structured data.
|
|
252
267
|
|
|
253
268
|
## Integrating Effect into existing applications
|
package/CLAUDE.md
CHANGED
|
@@ -11,9 +11,11 @@ purposes. In practice, you would not include these comments in your code.
|
|
|
11
11
|
|
|
12
12
|
## Writing `Effect` code
|
|
13
13
|
|
|
14
|
-
Prefer
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Prefer `Effect.gen` for inline Effect code. For reusable functions, prefer
|
|
15
|
+
`Effect.fn("name")` when tracing is useful and `Effect.fnUntraced` when it is not,
|
|
16
|
+
particularly in library implementations and hot paths. Avoid functions that only
|
|
17
|
+
wrap and return `Effect.gen`. Attach additional behaviour with combinators; this
|
|
18
|
+
style is more readable and easier to maintain than using combinators alone.
|
|
17
19
|
|
|
18
20
|
### Using Effect.gen
|
|
19
21
|
|
|
@@ -46,13 +48,16 @@ export class FileProcessingError extends Schema.TaggedError<FileProcessingError>
|
|
|
46
48
|
}) {}
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
### Using Effect.fn
|
|
51
|
+
### Using Effect.fn and Effect.fnUntraced
|
|
50
52
|
|
|
51
|
-
When writing functions that return an Effect, use `Effect.fn`
|
|
52
|
-
generator syntax.
|
|
53
|
+
When writing reusable functions that return an Effect, use `Effect.fn` or
|
|
54
|
+
`Effect.fnUntraced` to use the generator syntax.
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
Use `Effect.fn("name")` when the function should create a tracing span. Prefer
|
|
57
|
+
`Effect.fnUntraced` when tracing is not needed, particularly for library
|
|
58
|
+
implementations and hot paths.
|
|
59
|
+
|
|
60
|
+
**Avoid creating functions that only wrap and return an `Effect.gen`**.
|
|
56
61
|
|
|
57
62
|
```ts
|
|
58
63
|
import { Effect, Schema } from "effect"
|
|
@@ -80,6 +85,16 @@ export const effectFunction = Effect.fn("effectFunction")(
|
|
|
80
85
|
})
|
|
81
86
|
)
|
|
82
87
|
|
|
88
|
+
// Effect.fnUntraced avoids tracing and stack-frame capture while still reusing
|
|
89
|
+
// the generator body. This is preferred for library functions that do not
|
|
90
|
+
// represent a useful tracing boundary.
|
|
91
|
+
export const validateBatchSize = Effect.fnUntraced(function*(size: number): Effect.fn.Return<number, SomeError> {
|
|
92
|
+
if (!Number.isInteger(size) || size <= 0) {
|
|
93
|
+
return yield* new SomeError({ message: "Batch size must be a positive integer" })
|
|
94
|
+
}
|
|
95
|
+
return size
|
|
96
|
+
})
|
|
97
|
+
|
|
83
98
|
// Use Schema.TaggedError to define a custom error
|
|
84
99
|
export class SomeError extends Schema.TaggedError<SomeError>()("SomeError", {
|
|
85
100
|
message: Schema.String
|
|
@@ -247,7 +262,7 @@ They let you model finite or infinite data sources.
|
|
|
247
262
|
- `NodeStream.fromReadable` for Node.js readable streams
|
|
248
263
|
- **[Consuming and transforming streams](./ai-docs/src/03_stream/20_consuming-streams.ts)**: How to transform and consume streams using operators like `map`, `flatMap`, `filter`, `mapEffect`, and various `run*` methods.
|
|
249
264
|
- **[Decoding and encoding streams](./ai-docs/src/03_stream/30_encoding.ts)**:
|
|
250
|
-
Use `Stream.pipeThroughChannel` with the `Ndjson`
|
|
265
|
+
Use `Stream.pipeThroughChannel` with the `Ndjson` and `SchemaBinary` modules to
|
|
251
266
|
decode and encode streams of structured data.
|
|
252
267
|
|
|
253
268
|
## Integrating Effect into existing applications
|
package/README.md
CHANGED
|
@@ -8,6 +8,25 @@ An Effect SQL client for [PGlite](https://pglite.dev), a WASM build of PostgreSQ
|
|
|
8
8
|
npm install effect@rc @effect/sql-pglite@rc
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## LISTEN / NOTIFY
|
|
12
|
+
|
|
13
|
+
`listen` is a scoped subscription that returns after the listener is installed.
|
|
14
|
+
It exposes notifications through a queue and keeps the subscription active for
|
|
15
|
+
the surrounding scope:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { PgliteClient } from "@effect/sql-pglite"
|
|
19
|
+
import { Effect, Queue } from "effect"
|
|
20
|
+
|
|
21
|
+
const program = Effect.gen(function*() {
|
|
22
|
+
const sql = yield* PgliteClient.PgliteClient
|
|
23
|
+
const notifications = yield* sql.listen("events")
|
|
24
|
+
|
|
25
|
+
yield* sql.notify("events", "ready")
|
|
26
|
+
return yield* Queue.take(notifications)
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
11
30
|
## Documentation
|
|
12
31
|
|
|
13
32
|
- [Effect website](https://effect.website)
|
package/ai-docs/package.json
CHANGED
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@effect/sql-sqlite-wasm": "workspace:*",
|
|
28
28
|
"@effect/vitest": "workspace:*",
|
|
29
29
|
"effect": "workspace:*",
|
|
30
|
-
"hono": "^4.13.
|
|
31
|
-
"nodemailer": "^
|
|
30
|
+
"hono": "^4.13.7",
|
|
31
|
+
"nodemailer": "^10.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/nodemailer": "^8.0.1"
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @title Using Effect.fn
|
|
2
|
+
* @title Using Effect.fn and Effect.fnUntraced
|
|
3
3
|
*
|
|
4
|
-
* When writing functions that return an Effect, use `Effect.fn`
|
|
5
|
-
* generator syntax.
|
|
4
|
+
* When writing reusable functions that return an Effect, use `Effect.fn` or
|
|
5
|
+
* `Effect.fnUntraced` to use the generator syntax.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Use `Effect.fn("name")` when the function should create a tracing span. Prefer
|
|
8
|
+
* `Effect.fnUntraced` when tracing is not needed, particularly for library
|
|
9
|
+
* implementations and hot paths.
|
|
10
|
+
*
|
|
11
|
+
* **Avoid creating functions that only wrap and return an `Effect.gen`**.
|
|
9
12
|
*/
|
|
10
13
|
|
|
11
14
|
import { Effect, Schema } from "effect"
|
|
@@ -33,6 +36,16 @@ export const effectFunction = Effect.fn("effectFunction")(
|
|
|
33
36
|
})
|
|
34
37
|
)
|
|
35
38
|
|
|
39
|
+
// Effect.fnUntraced avoids tracing and stack-frame capture while still reusing
|
|
40
|
+
// the generator body. This is preferred for library functions that do not
|
|
41
|
+
// represent a useful tracing boundary.
|
|
42
|
+
export const validateBatchSize = Effect.fnUntraced(function*(size: number): Effect.fn.Return<number, SomeError> {
|
|
43
|
+
if (!Number.isInteger(size) || size <= 0) {
|
|
44
|
+
return yield* new SomeError({ message: "Batch size must be a positive integer" })
|
|
45
|
+
}
|
|
46
|
+
return size
|
|
47
|
+
})
|
|
48
|
+
|
|
36
49
|
// Use Schema.TaggedError to define a custom error
|
|
37
50
|
export class SomeError extends Schema.TaggedError<SomeError>()("SomeError", {
|
|
38
51
|
message: Schema.String
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
## Writing `Effect` code
|
|
2
2
|
|
|
3
|
-
Prefer
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Prefer `Effect.gen` for inline Effect code. For reusable functions, prefer
|
|
4
|
+
`Effect.fn("name")` when tracing is useful and `Effect.fnUntraced` when it is not,
|
|
5
|
+
particularly in library implementations and hot paths. Avoid functions that only
|
|
6
|
+
wrap and return `Effect.gen`. Attach additional behaviour with combinators; this
|
|
7
|
+
style is more readable and easier to maintain than using combinators alone.
|
|
@@ -14,7 +14,7 @@ export const SqlClientLayer: Layer.Layer<
|
|
|
14
14
|
PgClient.PgClient | SqlClient.SqlClient,
|
|
15
15
|
Config.ConfigError | SqlError.SqlError
|
|
16
16
|
> = PgClient.layerConfig({
|
|
17
|
-
url: Config.
|
|
17
|
+
url: Config.Redacted("DATABASE_URL")
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
export class UserRespositoryError extends Schema.TaggedError<UserRespositoryError>()("UserRespositoryError", {
|
|
@@ -51,7 +51,7 @@ export class MessageStore extends Context.Service<MessageStore, {
|
|
|
51
51
|
static readonly layer = Layer.unwrap(
|
|
52
52
|
Effect.gen(function*() {
|
|
53
53
|
// Read config inside an Effect, then choose which concrete layer to use.
|
|
54
|
-
const useInMemory = yield* Config.
|
|
54
|
+
const useInMemory = yield* Config.Boolean("MESSAGE_STORE_IN_MEMORY").pipe(
|
|
55
55
|
Config.withDefault(false)
|
|
56
56
|
)
|
|
57
57
|
|
|
@@ -59,7 +59,7 @@ export class MessageStore extends Context.Service<MessageStore, {
|
|
|
59
59
|
return MessageStore.layerInMemory
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const remoteUrl = yield* Config.
|
|
62
|
+
const remoteUrl = yield* Config.URL("MESSAGE_STORE_URL")
|
|
63
63
|
return MessageStore.layerRemote(remoteUrl)
|
|
64
64
|
})
|
|
65
65
|
)
|
|
@@ -22,8 +22,8 @@ export class Smtp extends Context.Service<Smtp, {
|
|
|
22
22
|
static readonly layer = Layer.effect(
|
|
23
23
|
Smtp,
|
|
24
24
|
Effect.gen(function*() {
|
|
25
|
-
const user = yield* Config.
|
|
26
|
-
const pass = yield* Config.
|
|
25
|
+
const user = yield* Config.String("SMTP_USER")
|
|
26
|
+
const pass = yield* Config.Redacted("SMTP_PASS")
|
|
27
27
|
|
|
28
28
|
// Use `Effect.acquireRelease` to manage the lifecycle of the SMTP
|
|
29
29
|
// transporter.
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @title Decoding and encoding streams
|
|
3
3
|
*
|
|
4
|
-
* Use `Stream.pipeThroughChannel` with the `Ndjson`
|
|
4
|
+
* Use `Stream.pipeThroughChannel` with the `Ndjson` and `SchemaBinary` modules to
|
|
5
5
|
* decode and encode streams of structured data.
|
|
6
6
|
*/
|
|
7
7
|
import { DateTime, Schema, Stream } from "effect"
|
|
8
|
-
import {
|
|
8
|
+
import { Ndjson, SchemaBinary } from "effect/unstable/encoding"
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
// `Msgpack.encode()`, etc.).
|
|
13
|
-
export const msgpackDecoder = Msgpack.decodeSchema(Schema.Struct({
|
|
10
|
+
// SchemaBinary derives a framed binary decoder directly from a schema.
|
|
11
|
+
export const schemaBinaryDecoder = SchemaBinary.decode(Schema.Struct({
|
|
14
12
|
id: Schema.Int,
|
|
15
13
|
name: Schema.String
|
|
16
|
-
}))
|
|
14
|
+
}))()
|
|
17
15
|
|
|
18
16
|
// ---------------------------------------------------------------------------
|
|
19
17
|
// Domain
|
|
@@ -41,7 +41,7 @@ export const AppLoggerLayer = Logger.layer([appLogger]).pipe(
|
|
|
41
41
|
// Create a logger layer that uses the default logger for development, and the
|
|
42
42
|
// custom logger for production
|
|
43
43
|
export const LoggerLayer = Layer.unwrap(Effect.gen(function*() {
|
|
44
|
-
const env = yield* Config.
|
|
44
|
+
const env = yield* Config.String("NODE_ENV").pipe(Config.withDefault("development"))
|
|
45
45
|
if (env === "production") {
|
|
46
46
|
return AppLoggerLayer
|
|
47
47
|
}
|
|
@@ -10,7 +10,7 @@ import { Argument, Command, Flag } from "effect/unstable/cli"
|
|
|
10
10
|
|
|
11
11
|
// You can define flags outside of commands and reuse them across multiple
|
|
12
12
|
// commands.
|
|
13
|
-
const workspace = Flag.
|
|
13
|
+
const workspace = Flag.String("workspace").pipe(
|
|
14
14
|
Flag.withAlias("w"),
|
|
15
15
|
Flag.withDescription("Workspace to operate on"),
|
|
16
16
|
Flag.withDefault("personal")
|
|
@@ -21,7 +21,7 @@ const workspace = Flag.string("workspace").pipe(
|
|
|
21
21
|
const tasks = Command.make("tasks").pipe(
|
|
22
22
|
Command.withSharedFlags({
|
|
23
23
|
workspace,
|
|
24
|
-
verbose: Flag.
|
|
24
|
+
verbose: Flag.Boolean("verbose").pipe(
|
|
25
25
|
Flag.withAlias("v"),
|
|
26
26
|
Flag.withDescription("Print diagnostic output"),
|
|
27
27
|
Flag.withDefault(false)
|
|
@@ -41,17 +41,17 @@ const Email = Schema.String.pipe(
|
|
|
41
41
|
const create = Command.make(
|
|
42
42
|
"create",
|
|
43
43
|
{
|
|
44
|
-
title: Argument.
|
|
44
|
+
title: Argument.String("title").pipe(
|
|
45
45
|
Argument.withDescription("Task title"),
|
|
46
46
|
// Reject empty titles at parse time, so the handler only ever sees
|
|
47
47
|
// valid input
|
|
48
48
|
Argument.withSchema(Schema.NonEmptyString)
|
|
49
49
|
),
|
|
50
|
-
priority: Flag.
|
|
50
|
+
priority: Flag.Literals("priority", ["low", "normal", "high"]).pipe(
|
|
51
51
|
Flag.withDescription("Priority for the new task"),
|
|
52
52
|
Flag.withDefault("normal")
|
|
53
53
|
),
|
|
54
|
-
assignee: Flag.
|
|
54
|
+
assignee: Flag.String("assignee").pipe(
|
|
55
55
|
Flag.withDescription("Email address of the person to assign"),
|
|
56
56
|
Flag.withSchema(Email),
|
|
57
57
|
Flag.optional
|
|
@@ -88,11 +88,11 @@ const create = Command.make(
|
|
|
88
88
|
const list = Command.make(
|
|
89
89
|
"list",
|
|
90
90
|
{
|
|
91
|
-
status: Flag.
|
|
91
|
+
status: Flag.Literals("status", ["open", "done", "all"]).pipe(
|
|
92
92
|
Flag.withDescription("Filter tasks by status"),
|
|
93
93
|
Flag.withDefault("open")
|
|
94
94
|
),
|
|
95
|
-
json: Flag.
|
|
95
|
+
json: Flag.Boolean("json").pipe(
|
|
96
96
|
Flag.withDescription("Print machine-readable output"),
|
|
97
97
|
Flag.withDefault(false)
|
|
98
98
|
)
|
|
@@ -13,7 +13,7 @@ import { LaunchPlan } from "./fixtures/domain/LaunchPlan.ts"
|
|
|
13
13
|
|
|
14
14
|
// You can use Config to create ai clients
|
|
15
15
|
const AnthropicClientLayer = AnthropicClient.layerConfig({
|
|
16
|
-
apiKey: Config.
|
|
16
|
+
apiKey: Config.Redacted("ANTHROPIC_API_KEY")
|
|
17
17
|
}).pipe(
|
|
18
18
|
// Providers typically require an HttpClient, but you can choose which one to
|
|
19
19
|
// use.
|
|
@@ -21,7 +21,7 @@ const AnthropicClientLayer = AnthropicClient.layerConfig({
|
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
const OpenAiClientLayer = OpenAiClient.layerConfig({
|
|
24
|
-
apiKey: Config.
|
|
24
|
+
apiKey: Config.Redacted("OPENAI_API_KEY")
|
|
25
25
|
}).pipe(
|
|
26
26
|
Layer.provide(FetchHttpClient.layer)
|
|
27
27
|
)
|
|
@@ -101,7 +101,7 @@ const ProductToolkitLayer = ProductToolkit.toLayer(Effect.gen(function*() {
|
|
|
101
101
|
|
|
102
102
|
// Provider setup (same pattern as the language-model example).
|
|
103
103
|
const OpenAiClientLayer = OpenAiClient.layerConfig({
|
|
104
|
-
apiKey: Config.
|
|
104
|
+
apiKey: Config.Redacted("OPENAI_API_KEY")
|
|
105
105
|
}).pipe(Layer.provide(FetchHttpClient.layer))
|
|
106
106
|
|
|
107
107
|
export class ProductAssistantError extends Schema.TaggedError<ProductAssistantError>()(
|
|
@@ -14,7 +14,7 @@ import { FetchHttpClient } from "effect/unstable/http"
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
|
|
16
16
|
const OpenAiClientLayer = OpenAiClient.layerConfig({
|
|
17
|
-
apiKey: Config.
|
|
17
|
+
apiKey: Config.Redacted("OPENAI_API_KEY")
|
|
18
18
|
}).pipe(Layer.provide(FetchHttpClient.layer))
|
|
19
19
|
|
|
20
20
|
// ---------------------------------------------------------------------------
|
package/dist/PgliteClient.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ import * as Config from "effect/Config";
|
|
|
16
16
|
import * as Context from "effect/Context";
|
|
17
17
|
import * as Effect from "effect/Effect";
|
|
18
18
|
import * as Layer from "effect/Layer";
|
|
19
|
+
import * as Queue from "effect/Queue";
|
|
19
20
|
import * as Scope from "effect/Scope";
|
|
20
|
-
import * as Stream from "effect/Stream";
|
|
21
21
|
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
22
22
|
import * as Client from "effect/unstable/sql/SqlClient";
|
|
23
23
|
import { SqlError } from "effect/unstable/sql/SqlError";
|
|
@@ -48,7 +48,16 @@ export interface PgliteClient extends Client.SqlClient {
|
|
|
48
48
|
readonly config: PgliteClientConfig;
|
|
49
49
|
readonly pglite: PGliteInterface;
|
|
50
50
|
readonly json: (_: unknown) => Fragment;
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Subscribes to a PGlite notification channel.
|
|
53
|
+
*
|
|
54
|
+
* **Details**
|
|
55
|
+
*
|
|
56
|
+
* The effect completes after the listener is installed. Notifications are
|
|
57
|
+
* buffered in the returned dequeue, and the subscription remains active
|
|
58
|
+
* until the required scope closes.
|
|
59
|
+
*/
|
|
60
|
+
readonly listen: (channel: string) => Effect.Effect<Queue.Dequeue<string>, SqlError, Scope.Scope>;
|
|
52
61
|
readonly notify: (channel: string, payload: string) => Effect.Effect<void, SqlError>;
|
|
53
62
|
readonly dumpDataDir: (compression?: "none" | "gzip" | "auto") => Effect.Effect<File | Blob, SqlError>;
|
|
54
63
|
readonly refreshArrayTypes: Effect.Effect<void, SqlError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PgliteClient.d.ts","sourceRoot":"","sources":["../src/PgliteClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAU,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACvF,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"PgliteClient.d.ts","sourceRoot":"","sources":["../src/PgliteClient.ts"],"names":[],"m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KACtC,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,QAAQ,CAA4B,CAAA;AAEpF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,eACX,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,8BAEhC,SAAS,CAAC,QAqCZ,CAAA;AAKD;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAE7B;;;GAGG;AACH,UAAU,MAAO,SAAQ,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC;CAAG;AACrD,QAAA,MAAM,MAAM,yDAAqC,CAAA"}
|
package/dist/PgliteClient.js
CHANGED
|
@@ -99,16 +99,21 @@ export const fromClient = options => Effect.gen(function* () {
|
|
|
99
99
|
config,
|
|
100
100
|
pglite,
|
|
101
101
|
json: _ => Statement.fragment([PgJson(_)]),
|
|
102
|
-
listen:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
listen: Effect.fnUntraced(function* (channel) {
|
|
103
|
+
const queue = yield* Queue.unbounded();
|
|
104
|
+
yield* Effect.acquireRelease(Effect.tryPromise({
|
|
105
|
+
try: () => pglite.listen(channel, payload => {
|
|
106
|
+
Queue.offerUnsafe(queue, payload);
|
|
107
|
+
}),
|
|
108
|
+
catch: cause => new SqlError({
|
|
109
|
+
reason: classifyError(cause, "Failed to listen", "listen")
|
|
110
|
+
})
|
|
111
|
+
}), unlisten => Effect.promise(() => unlisten()), {
|
|
112
|
+
interruptible: true
|
|
113
|
+
});
|
|
114
|
+
yield* Effect.addFinalizer(() => Queue.shutdown(queue));
|
|
115
|
+
return queue;
|
|
116
|
+
}),
|
|
112
117
|
notify: (channel, payload) => Effect.tryPromise({
|
|
113
118
|
try: () => pglite.exec(`NOTIFY ${escape(channel)}, ${escapeLiteral(payload)}`),
|
|
114
119
|
catch: cause => new SqlError({
|
|
@@ -225,7 +230,8 @@ export const makeCompiler = (transform, transformJson = true) => {
|
|
|
225
230
|
switch (type.kind) {
|
|
226
231
|
case "PgJson":
|
|
227
232
|
{
|
|
228
|
-
|
|
233
|
+
const value = withoutTransform || transformValue === undefined ? type.paramA : transformValue(type.paramA);
|
|
234
|
+
return [placeholder(undefined), [typeof value === "string" ? JSON.stringify(value) : value]];
|
|
229
235
|
}
|
|
230
236
|
}
|
|
231
237
|
}
|
package/dist/PgliteClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PgliteClient.js","names":[],"sources":["../src/PgliteClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;AAaA,SAAS,MAAM,QAAkD,sBAAsB;AACvF,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B;AAEvD,SACE,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,YAAY,QACP,8BAA8B;AAErC,OAAO,KAAK,SAAS,MAAM,+BAA+B;AAE1D;;;;;;AAMA,OAAO,MAAM,MAAM,GAAW,kCAAkC;
|
|
1
|
+
{"version":3,"file":"PgliteClient.js","names":[],"sources":["../src/PgliteClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;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B,CAAC,KAAK,CAAC;IACpC;IACA,IAAI,IAAI,KAAK,OAAO,EAAE;MACpB,OAAO,IAAI,qBAAqB,CAAC,KAAK,CAAC;IACzC;EACF;EACA,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC;AAChC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/sql-pglite",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.114",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A PGlite toolkit for Effect",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"provenance": true
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"effect": "^4.0.0-rc.
|
|
54
|
+
"effect": "^4.0.0-rc.114"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"effect": "^4.0.0-rc.
|
|
57
|
+
"effect": "^4.0.0-rc.114"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@electric-sql/pglite": "^0.5.
|
|
60
|
+
"@electric-sql/pglite": "^0.5.8"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"codegen": "effect-utils codegen",
|
package/src/PgliteClient.ts
CHANGED
|
@@ -68,7 +68,18 @@ export interface PgliteClient extends Client.SqlClient {
|
|
|
68
68
|
readonly config: PgliteClientConfig
|
|
69
69
|
readonly pglite: PGliteInterface
|
|
70
70
|
readonly json: (_: unknown) => Fragment
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Subscribes to a PGlite notification channel.
|
|
73
|
+
*
|
|
74
|
+
* **Details**
|
|
75
|
+
*
|
|
76
|
+
* The effect completes after the listener is installed. Notifications are
|
|
77
|
+
* buffered in the returned dequeue, and the subscription remains active
|
|
78
|
+
* until the required scope closes.
|
|
79
|
+
*/
|
|
80
|
+
readonly listen: (
|
|
81
|
+
channel: string
|
|
82
|
+
) => Effect.Effect<Queue.Dequeue<string>, SqlError, Scope.Scope>
|
|
72
83
|
readonly notify: (channel: string, payload: string) => Effect.Effect<void, SqlError>
|
|
73
84
|
readonly dumpDataDir: (compression?: "none" | "gzip" | "auto") => Effect.Effect<File | Blob, SqlError>
|
|
74
85
|
readonly refreshArrayTypes: Effect.Effect<void, SqlError>
|
|
@@ -229,20 +240,22 @@ export const fromClient = (
|
|
|
229
240
|
config,
|
|
230
241
|
pglite,
|
|
231
242
|
json: (_: unknown) => Statement.fragment([PgJson(_)]),
|
|
232
|
-
listen: (channel: string)
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
)
|
|
243
|
+
listen: Effect.fnUntraced(function*(channel: string) {
|
|
244
|
+
const queue = yield* Queue.unbounded<string>()
|
|
245
|
+
yield* Effect.acquireRelease(
|
|
246
|
+
Effect.tryPromise({
|
|
247
|
+
try: () =>
|
|
248
|
+
pglite.listen(channel, (payload) => {
|
|
249
|
+
Queue.offerUnsafe(queue, payload)
|
|
250
|
+
}),
|
|
251
|
+
catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to listen", "listen") })
|
|
252
|
+
}),
|
|
253
|
+
(unlisten) => Effect.promise(() => unlisten()),
|
|
254
|
+
{ interruptible: true }
|
|
255
|
+
)
|
|
256
|
+
yield* Effect.addFinalizer(() => Queue.shutdown(queue))
|
|
257
|
+
return queue
|
|
258
|
+
}),
|
|
246
259
|
notify: (channel: string, payload: string) =>
|
|
247
260
|
Effect.tryPromise({
|
|
248
261
|
try: () => pglite.exec(`NOTIFY ${escape(channel)}, ${escapeLiteral(payload)}`),
|
|
@@ -416,13 +429,12 @@ export const makeCompiler = (
|
|
|
416
429
|
onCustom(type, placeholder, withoutTransform) {
|
|
417
430
|
switch (type.kind) {
|
|
418
431
|
case "PgJson": {
|
|
432
|
+
const value = withoutTransform || transformValue === undefined
|
|
433
|
+
? type.paramA
|
|
434
|
+
: transformValue(type.paramA)
|
|
419
435
|
return [
|
|
420
436
|
placeholder(undefined),
|
|
421
|
-
[
|
|
422
|
-
withoutTransform || transformValue === undefined
|
|
423
|
-
? type.paramA
|
|
424
|
-
: transformValue(type.paramA)
|
|
425
|
-
]
|
|
437
|
+
[typeof value === "string" ? JSON.stringify(value) : value]
|
|
426
438
|
]
|
|
427
439
|
}
|
|
428
440
|
}
|